via-pmu-event.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * via-pmu event device for reporting some events that come through the PMU
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  14. * NON INFRINGEMENT. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #include <linux/input.h>
  23. #include <linux/adb.h>
  24. #include <linux/pmu.h>
  25. #include "via-pmu-event.h"
  26. static struct input_dev *pmu_input_dev;
  27. static int __init via_pmu_event_init(void)
  28. {
  29. int err;
  30. /* do other models report button/lid status? */
  31. if (pmu_get_model() != PMU_KEYLARGO_BASED)
  32. return -ENODEV;
  33. pmu_input_dev = input_allocate_device();
  34. if (!pmu_input_dev)
  35. return -ENOMEM;
  36. pmu_input_dev->name = "PMU";
  37. pmu_input_dev->id.bustype = BUS_HOST;
  38. pmu_input_dev->id.vendor = 0x0001;
  39. pmu_input_dev->id.product = 0x0001;
  40. pmu_input_dev->id.version = 0x0100;
  41. set_bit(EV_KEY, pmu_input_dev->evbit);
  42. set_bit(EV_SW, pmu_input_dev->evbit);
  43. set_bit(KEY_POWER, pmu_input_dev->keybit);
  44. set_bit(SW_LID, pmu_input_dev->swbit);
  45. err = input_register_device(pmu_input_dev);
  46. if (err)
  47. input_free_device(pmu_input_dev);
  48. return err;
  49. }
  50. void via_pmu_event(int key, int down)
  51. {
  52. if (unlikely(!pmu_input_dev))
  53. return;
  54. switch (key) {
  55. case PMU_EVT_POWER:
  56. input_report_key(pmu_input_dev, KEY_POWER, down);
  57. break;
  58. case PMU_EVT_LID:
  59. input_report_switch(pmu_input_dev, SW_LID, down);
  60. break;
  61. default:
  62. /* no such key handled */
  63. return;
  64. }
  65. input_sync(pmu_input_dev);
  66. }
  67. late_initcall(via_pmu_event_init);