/kern_oII/drivers/input/apm-power.c

http://omnia2droid.googlecode.com/ · C · 128 lines · 97 code · 20 blank · 11 comment · 7 complexity · 7ecafec56adca5d595e252d7203c1107 MD5 · raw file

  1. /*
  2. * Input Power Event -> APM Bridge
  3. *
  4. * Copyright (c) 2007 Richard Purdie
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/input.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/tty.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/apm-emulation.h>
  19. static void system_power_event(unsigned int keycode)
  20. {
  21. switch (keycode) {
  22. case KEY_SUSPEND:
  23. apm_queue_event(APM_USER_SUSPEND);
  24. printk(KERN_INFO "apm-power: Requesting system suspend...\n");
  25. break;
  26. default:
  27. break;
  28. }
  29. }
  30. static void apmpower_event(struct input_handle *handle, unsigned int type,
  31. unsigned int code, int value)
  32. {
  33. /* only react on key down events */
  34. if (value != 1)
  35. return;
  36. switch (type) {
  37. case EV_PWR:
  38. system_power_event(code);
  39. break;
  40. default:
  41. break;
  42. }
  43. }
  44. static int apmpower_connect(struct input_handler *handler,
  45. struct input_dev *dev,
  46. const struct input_device_id *id)
  47. {
  48. struct input_handle *handle;
  49. int error;
  50. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  51. if (!handle)
  52. return -ENOMEM;
  53. handle->dev = dev;
  54. handle->handler = handler;
  55. handle->name = "apm-power";
  56. error = input_register_handle(handle);
  57. if (error) {
  58. printk(KERN_ERR
  59. "apm-power: Failed to register input power handler, "
  60. "error %d\n", error);
  61. kfree(handle);
  62. return error;
  63. }
  64. error = input_open_device(handle);
  65. if (error) {
  66. printk(KERN_ERR
  67. "apm-power: Failed to open input power device, "
  68. "error %d\n", error);
  69. input_unregister_handle(handle);
  70. kfree(handle);
  71. return error;
  72. }
  73. return 0;
  74. }
  75. static void apmpower_disconnect(struct input_handle *handle)
  76. {
  77. input_close_device(handle);
  78. input_unregister_handle(handle);
  79. kfree(handle);
  80. }
  81. static const struct input_device_id apmpower_ids[] = {
  82. {
  83. .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
  84. .evbit = { BIT_MASK(EV_PWR) },
  85. },
  86. { },
  87. };
  88. MODULE_DEVICE_TABLE(input, apmpower_ids);
  89. static struct input_handler apmpower_handler = {
  90. .event = apmpower_event,
  91. .connect = apmpower_connect,
  92. .disconnect = apmpower_disconnect,
  93. .name = "apm-power",
  94. .id_table = apmpower_ids,
  95. };
  96. static int __init apmpower_init(void)
  97. {
  98. return input_register_handler(&apmpower_handler);
  99. }
  100. static void __exit apmpower_exit(void)
  101. {
  102. input_unregister_handler(&apmpower_handler);
  103. }
  104. module_init(apmpower_init);
  105. module_exit(apmpower_exit);
  106. MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
  107. MODULE_DESCRIPTION("Input Power Event -> APM Bridge");
  108. MODULE_LICENSE("GPL");