atlas_btns.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/input.h>
  27. #include <linux/types.h>
  28. #include <linux/acpi.h>
  29. #include <asm/uaccess.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, u64 *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 = AE_OK;
  55. } else {
  56. pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
  57. function, (unsigned long)address, (u32)*value);
  58. status = AE_BAD_PARAMETER;
  59. }
  60. return status;
  61. }
  62. static int atlas_acpi_button_add(struct acpi_device *device)
  63. {
  64. acpi_status status;
  65. int i;
  66. int err;
  67. input_dev = input_allocate_device();
  68. if (!input_dev) {
  69. pr_err("unable to allocate input device\n");
  70. return -ENOMEM;
  71. }
  72. input_dev->name = "Atlas ACPI button driver";
  73. input_dev->phys = "ASIM0000/atlas/input0";
  74. input_dev->id.bustype = BUS_HOST;
  75. input_dev->keycode = atlas_keymap;
  76. input_dev->keycodesize = sizeof(unsigned short);
  77. input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
  78. input_set_capability(input_dev, EV_MSC, MSC_SCAN);
  79. __set_bit(EV_KEY, input_dev->evbit);
  80. for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
  81. if (i < 9) {
  82. atlas_keymap[i] = KEY_F1 + i;
  83. __set_bit(KEY_F1 + i, input_dev->keybit);
  84. } else
  85. atlas_keymap[i] = KEY_RESERVED;
  86. }
  87. err = input_register_device(input_dev);
  88. if (err) {
  89. pr_err("couldn't register input device\n");
  90. input_free_device(input_dev);
  91. return err;
  92. }
  93. /* hookup button handler */
  94. status = acpi_install_address_space_handler(device->handle,
  95. 0x81, &acpi_atlas_button_handler,
  96. &acpi_atlas_button_setup, device);
  97. if (ACPI_FAILURE(status)) {
  98. pr_err("error installing addr spc handler\n");
  99. input_unregister_device(input_dev);
  100. err = -EINVAL;
  101. }
  102. return err;
  103. }
  104. static int atlas_acpi_button_remove(struct acpi_device *device)
  105. {
  106. acpi_status status;
  107. status = acpi_remove_address_space_handler(device->handle,
  108. 0x81, &acpi_atlas_button_handler);
  109. if (ACPI_FAILURE(status))
  110. pr_err("error removing addr spc handler\n");
  111. input_unregister_device(input_dev);
  112. return 0;
  113. }
  114. static const struct acpi_device_id atlas_device_ids[] = {
  115. {"ASIM0000", 0},
  116. {"", 0},
  117. };
  118. MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
  119. static struct acpi_driver atlas_acpi_driver = {
  120. .name = ACPI_ATLAS_NAME,
  121. .class = ACPI_ATLAS_CLASS,
  122. .owner = THIS_MODULE,
  123. .ids = atlas_device_ids,
  124. .ops = {
  125. .add = atlas_acpi_button_add,
  126. .remove = atlas_acpi_button_remove,
  127. },
  128. };
  129. module_acpi_driver(atlas_acpi_driver);
  130. MODULE_AUTHOR("Jaya Kumar");
  131. MODULE_LICENSE("GPL");
  132. MODULE_DESCRIPTION("Atlas button driver");