atlas_btns.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. static unsigned short atlas_keymap[16];
  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. if (function == ACPI_WRITE) {
  49. int code = address & 0x0f;
  50. int key_down = !(address & 0x10);
  51. input_event(input_dev, EV_MSC, MSC_SCAN, code);
  52. input_report_key(input_dev, atlas_keymap[code], key_down);
  53. input_sync(input_dev);
  54. status = 0;
  55. } else {
  56. printk(KERN_WARNING "atlas: shrugged on unexpected function"
  57. ":function=%x,address=%lx,value=%x\n",
  58. function, (unsigned long)address, (u32)*value);
  59. status = -EINVAL;
  60. }
  61. return status;
  62. }
  63. static int atlas_acpi_button_add(struct acpi_device *device)
  64. {
  65. acpi_status status;
  66. int i;
  67. int err;
  68. input_dev = input_allocate_device();
  69. if (!input_dev) {
  70. printk(KERN_ERR "atlas: unable to allocate input device\n");
  71. return -ENOMEM;
  72. }
  73. input_dev->name = "Atlas ACPI button driver";
  74. input_dev->phys = "ASIM0000/atlas/input0";
  75. input_dev->id.bustype = BUS_HOST;
  76. input_dev->keycode = atlas_keymap;
  77. input_dev->keycodesize = sizeof(unsigned short);
  78. input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
  79. input_set_capability(input_dev, EV_MSC, MSC_SCAN);
  80. __set_bit(EV_KEY, input_dev->evbit);
  81. for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
  82. if (i < 9) {
  83. atlas_keymap[i] = KEY_F1 + i;
  84. __set_bit(KEY_F1 + i, input_dev->keybit);
  85. } else
  86. atlas_keymap[i] = KEY_RESERVED;
  87. }
  88. err = input_register_device(input_dev);
  89. if (err) {
  90. printk(KERN_ERR "atlas: couldn't register input device\n");
  91. input_free_device(input_dev);
  92. return err;
  93. }
  94. /* hookup button handler */
  95. status = acpi_install_address_space_handler(device->handle,
  96. 0x81, &acpi_atlas_button_handler,
  97. &acpi_atlas_button_setup, device);
  98. if (ACPI_FAILURE(status)) {
  99. printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
  100. input_unregister_device(input_dev);
  101. status = -EINVAL;
  102. }
  103. return status;
  104. }
  105. static int atlas_acpi_button_remove(struct acpi_device *device, int type)
  106. {
  107. acpi_status status;
  108. status = acpi_remove_address_space_handler(device->handle,
  109. 0x81, &acpi_atlas_button_handler);
  110. if (ACPI_FAILURE(status)) {
  111. printk(KERN_ERR "Atlas: Error removing addr spc handler\n");
  112. status = -EINVAL;
  113. }
  114. input_unregister_device(input_dev);
  115. return status;
  116. }
  117. static const struct acpi_device_id atlas_device_ids[] = {
  118. {"ASIM0000", 0},
  119. {"", 0},
  120. };
  121. MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
  122. static struct acpi_driver atlas_acpi_driver = {
  123. .name = ACPI_ATLAS_NAME,
  124. .class = ACPI_ATLAS_CLASS,
  125. .ids = atlas_device_ids,
  126. .ops = {
  127. .add = atlas_acpi_button_add,
  128. .remove = atlas_acpi_button_remove,
  129. },
  130. };
  131. static int __init atlas_acpi_init(void)
  132. {
  133. int result;
  134. if (acpi_disabled)
  135. return -ENODEV;
  136. result = acpi_bus_register_driver(&atlas_acpi_driver);
  137. if (result < 0) {
  138. printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
  139. return -ENODEV;
  140. }
  141. return 0;
  142. }
  143. static void __exit atlas_acpi_exit(void)
  144. {
  145. acpi_bus_unregister_driver(&atlas_acpi_driver);
  146. }
  147. module_init(atlas_acpi_init);
  148. module_exit(atlas_acpi_exit);
  149. MODULE_AUTHOR("Jaya Kumar");
  150. MODULE_LICENSE("GPL");
  151. MODULE_DESCRIPTION("Atlas button driver");