atlas_btns.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/input.h>
  28. #include <linux/types.h>
  29. #include <asm/uaccess.h>
  30. #include <acpi/acpi_drivers.h>
  31. #define ACPI_ATLAS_NAME "Atlas ACPI"
  32. #define ACPI_ATLAS_CLASS "Atlas"
  33. static unsigned short atlas_keymap[16];
  34. static struct input_dev *input_dev;
  35. /* button handling code */
  36. static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
  37. u32 function, void *handler_context, void **return_context)
  38. {
  39. *return_context =
  40. (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
  41. return AE_OK;
  42. }
  43. static acpi_status acpi_atlas_button_handler(u32 function,
  44. acpi_physical_address address,
  45. u32 bit_width, u64 *value,
  46. void *handler_context, void *region_context)
  47. {
  48. acpi_status status;
  49. if (function == ACPI_WRITE) {
  50. int code = address & 0x0f;
  51. int key_down = !(address & 0x10);
  52. input_event(input_dev, EV_MSC, MSC_SCAN, code);
  53. input_report_key(input_dev, atlas_keymap[code], key_down);
  54. input_sync(input_dev);
  55. status = AE_OK;
  56. } else {
  57. pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
  58. function, (unsigned long)address, (u32)*value);
  59. status = AE_BAD_PARAMETER;
  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. pr_err("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. pr_err("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. pr_err("error installing addr spc handler\n");
  100. input_unregister_device(input_dev);
  101. err = -EINVAL;
  102. }
  103. return err;
  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. pr_err("error removing addr spc handler\n");
  112. input_unregister_device(input_dev);
  113. return 0;
  114. }
  115. static const struct acpi_device_id atlas_device_ids[] = {
  116. {"ASIM0000", 0},
  117. {"", 0},
  118. };
  119. MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
  120. static struct acpi_driver atlas_acpi_driver = {
  121. .name = ACPI_ATLAS_NAME,
  122. .class = ACPI_ATLAS_CLASS,
  123. .owner = THIS_MODULE,
  124. .ids = atlas_device_ids,
  125. .ops = {
  126. .add = atlas_acpi_button_add,
  127. .remove = atlas_acpi_button_remove,
  128. },
  129. };
  130. static int __init atlas_acpi_init(void)
  131. {
  132. if (acpi_disabled)
  133. return -ENODEV;
  134. return acpi_bus_register_driver(&atlas_acpi_driver);
  135. }
  136. static void __exit atlas_acpi_exit(void)
  137. {
  138. acpi_bus_unregister_driver(&atlas_acpi_driver);
  139. }
  140. module_init(atlas_acpi_init);
  141. module_exit(atlas_acpi_exit);
  142. MODULE_AUTHOR("Jaya Kumar");
  143. MODULE_LICENSE("GPL");
  144. MODULE_DESCRIPTION("Atlas button driver");