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. #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 struct input_dev *input_dev;
  33. /* button handling code */
  34. static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
  35. u32 function, void *handler_context, void **return_context)
  36. {
  37. *return_context =
  38. (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
  39. return AE_OK;
  40. }
  41. static acpi_status acpi_atlas_button_handler(u32 function,
  42. acpi_physical_address address,
  43. u32 bit_width, acpi_integer *value,
  44. void *handler_context, void *region_context)
  45. {
  46. acpi_status status;
  47. int keycode;
  48. if (function == ACPI_WRITE) {
  49. keycode = KEY_F1 + (address & 0x0F);
  50. input_report_key(input_dev, keycode, !(address & 0x10));
  51. input_sync(input_dev);
  52. status = 0;
  53. } else {
  54. printk(KERN_WARNING "atlas: shrugged on unexpected function"
  55. ":function=%x,address=%lx,value=%x\n",
  56. function, (unsigned long)address, (u32)*value);
  57. status = -EINVAL;
  58. }
  59. return status;
  60. }
  61. static int atlas_acpi_button_add(struct acpi_device *device)
  62. {
  63. acpi_status status;
  64. int err;
  65. input_dev = input_allocate_device();
  66. if (!input_dev) {
  67. printk(KERN_ERR "atlas: unable to allocate input device\n");
  68. return -ENOMEM;
  69. }
  70. input_dev->name = "Atlas ACPI button driver";
  71. input_dev->phys = "ASIM0000/atlas/input0";
  72. input_dev->id.bustype = BUS_HOST;
  73. input_dev->evbit[BIT_WORD(EV_KEY)] = BIT_MASK(EV_KEY);
  74. set_bit(KEY_F1, input_dev->keybit);
  75. set_bit(KEY_F2, input_dev->keybit);
  76. set_bit(KEY_F3, input_dev->keybit);
  77. set_bit(KEY_F4, input_dev->keybit);
  78. set_bit(KEY_F5, input_dev->keybit);
  79. set_bit(KEY_F6, input_dev->keybit);
  80. set_bit(KEY_F7, input_dev->keybit);
  81. set_bit(KEY_F8, input_dev->keybit);
  82. set_bit(KEY_F9, input_dev->keybit);
  83. err = input_register_device(input_dev);
  84. if (err) {
  85. printk(KERN_ERR "atlas: couldn't register input device\n");
  86. input_free_device(input_dev);
  87. return err;
  88. }
  89. /* hookup button handler */
  90. status = acpi_install_address_space_handler(device->handle,
  91. 0x81, &acpi_atlas_button_handler,
  92. &acpi_atlas_button_setup, device);
  93. if (ACPI_FAILURE(status)) {
  94. printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
  95. input_unregister_device(input_dev);
  96. status = -EINVAL;
  97. }
  98. return status;
  99. }
  100. static int atlas_acpi_button_remove(struct acpi_device *device, int type)
  101. {
  102. acpi_status status;
  103. status = acpi_remove_address_space_handler(device->handle,
  104. 0x81, &acpi_atlas_button_handler);
  105. if (ACPI_FAILURE(status)) {
  106. printk(KERN_ERR "Atlas: Error removing addr spc handler\n");
  107. status = -EINVAL;
  108. }
  109. input_unregister_device(input_dev);
  110. return status;
  111. }
  112. static const struct acpi_device_id atlas_device_ids[] = {
  113. {"ASIM0000", 0},
  114. {"", 0},
  115. };
  116. MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
  117. static struct acpi_driver atlas_acpi_driver = {
  118. .name = ACPI_ATLAS_NAME,
  119. .class = ACPI_ATLAS_CLASS,
  120. .ids = atlas_device_ids,
  121. .ops = {
  122. .add = atlas_acpi_button_add,
  123. .remove = atlas_acpi_button_remove,
  124. },
  125. };
  126. static int __init atlas_acpi_init(void)
  127. {
  128. int result;
  129. if (acpi_disabled)
  130. return -ENODEV;
  131. result = acpi_bus_register_driver(&atlas_acpi_driver);
  132. if (result < 0) {
  133. printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
  134. return -ENODEV;
  135. }
  136. return 0;
  137. }
  138. static void __exit atlas_acpi_exit(void)
  139. {
  140. acpi_bus_unregister_driver(&atlas_acpi_driver);
  141. }
  142. module_init(atlas_acpi_init);
  143. module_exit(atlas_acpi_exit);
  144. MODULE_AUTHOR("Jaya Kumar");
  145. MODULE_LICENSE("GPL");
  146. MODULE_DESCRIPTION("Atlas button driver");