atlas_btns.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
  3. *
  4. * Copyright (C) 2006 Jaya Kumar
  5. * Based on Toshiba ACPI by John Belmonte and ASUS ACPI
  6. * This work was sponsored by CIS(M) Sdn Bhd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/input.h>
  27. #include <linux/types.h>
  28. #include <asm/uaccess.h>
  29. #include <acpi/acpi_drivers.h>
  30. #define ACPI_ATLAS_NAME "Atlas ACPI"
  31. #define ACPI_ATLAS_CLASS "Atlas"
  32. #define ACPI_ATLAS_BUTTON_HID "ASIM0000"
  33. static struct input_dev *input_dev;
  34. /* button handling code */
  35. static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
  36. u32 function, void *handler_context, void **return_context)
  37. {
  38. *return_context =
  39. (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
  40. return AE_OK;
  41. }
  42. static acpi_status acpi_atlas_button_handler(u32 function,
  43. acpi_physical_address address,
  44. u32 bit_width, acpi_integer *value,
  45. void *handler_context, void *region_context)
  46. {
  47. acpi_status status;
  48. int keycode;
  49. if (function == ACPI_WRITE) {
  50. keycode = KEY_F1 + (address & 0x0F);
  51. input_report_key(input_dev, keycode, !(address & 0x10));
  52. input_sync(input_dev);
  53. status = 0;
  54. } else {
  55. printk(KERN_WARNING "atlas: shrugged on unexpected function"
  56. ":function=%x,address=%lx,value=%x\n",
  57. function, (unsigned long)address, (u32)*value);
  58. status = -EINVAL;
  59. }
  60. return status;
  61. }
  62. static int atlas_acpi_button_add(struct acpi_device *device)
  63. {
  64. acpi_status status;
  65. int err;
  66. input_dev = input_allocate_device();
  67. if (!input_dev) {
  68. printk(KERN_ERR "atlas: unable to allocate input device\n");
  69. return -ENOMEM;
  70. }
  71. input_dev->name = "Atlas ACPI button driver";
  72. input_dev->phys = "ASIM0000/atlas/input0";
  73. input_dev->id.bustype = BUS_HOST;
  74. input_dev->evbit[LONG(EV_KEY)] = BIT(EV_KEY);
  75. set_bit(KEY_F1, input_dev->keybit);
  76. set_bit(KEY_F2, input_dev->keybit);
  77. set_bit(KEY_F3, input_dev->keybit);
  78. set_bit(KEY_F4, input_dev->keybit);
  79. set_bit(KEY_F5, input_dev->keybit);
  80. set_bit(KEY_F6, input_dev->keybit);
  81. set_bit(KEY_F7, input_dev->keybit);
  82. set_bit(KEY_F8, input_dev->keybit);
  83. set_bit(KEY_F9, input_dev->keybit);
  84. err = input_register_device(input_dev);
  85. if (err) {
  86. printk(KERN_ERR "atlas: couldn't register input device\n");
  87. input_free_device(input_dev);
  88. return err;
  89. }
  90. /* hookup button handler */
  91. status = acpi_install_address_space_handler(device->handle,
  92. 0x81, &acpi_atlas_button_handler,
  93. &acpi_atlas_button_setup, device);
  94. if (ACPI_FAILURE(status)) {
  95. printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
  96. input_unregister_device(input_dev);
  97. status = -EINVAL;
  98. }
  99. return status;
  100. }
  101. static int atlas_acpi_button_remove(struct acpi_device *device, int type)
  102. {
  103. acpi_status status;
  104. status = acpi_remove_address_space_handler(device->handle,
  105. 0x81, &acpi_atlas_button_handler);
  106. if (ACPI_FAILURE(status)) {
  107. printk(KERN_ERR "Atlas: Error removing addr spc handler\n");
  108. status = -EINVAL;
  109. }
  110. input_unregister_device(input_dev);
  111. return status;
  112. }
  113. static struct acpi_driver atlas_acpi_driver = {
  114. .name = ACPI_ATLAS_NAME,
  115. .class = ACPI_ATLAS_CLASS,
  116. .ids = ACPI_ATLAS_BUTTON_HID,
  117. .ops = {
  118. .add = atlas_acpi_button_add,
  119. .remove = atlas_acpi_button_remove,
  120. },
  121. };
  122. static int __init atlas_acpi_init(void)
  123. {
  124. int result;
  125. if (acpi_disabled)
  126. return -ENODEV;
  127. result = acpi_bus_register_driver(&atlas_acpi_driver);
  128. if (result < 0) {
  129. printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
  130. return -ENODEV;
  131. }
  132. return 0;
  133. }
  134. static void __exit atlas_acpi_exit(void)
  135. {
  136. acpi_bus_unregister_driver(&atlas_acpi_driver);
  137. }
  138. module_init(atlas_acpi_init);
  139. module_exit(atlas_acpi_exit);
  140. MODULE_AUTHOR("Jaya Kumar");
  141. MODULE_LICENSE("GPL");
  142. MODULE_DESCRIPTION("Atlas button driver");