atlas_btns.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
  4. *
  5. * Copyright (C) 2006 Jaya Kumar
  6. * Based on Toshiba ACPI by John Belmonte and ASUS ACPI
  7. * This work was sponsored by CIS(M) Sdn Bhd.
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/input.h>
  13. #include <linux/types.h>
  14. #include <linux/acpi.h>
  15. #include <linux/uaccess.h>
  16. #define ACPI_ATLAS_NAME "Atlas ACPI"
  17. #define ACPI_ATLAS_CLASS "Atlas"
  18. static unsigned short atlas_keymap[16];
  19. static struct input_dev *input_dev;
  20. /* button handling code */
  21. static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
  22. u32 function, void *handler_context, void **return_context)
  23. {
  24. *return_context =
  25. (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
  26. return AE_OK;
  27. }
  28. static acpi_status acpi_atlas_button_handler(u32 function,
  29. acpi_physical_address address,
  30. u32 bit_width, u64 *value,
  31. void *handler_context, void *region_context)
  32. {
  33. acpi_status status;
  34. if (function == ACPI_WRITE) {
  35. int code = address & 0x0f;
  36. int key_down = !(address & 0x10);
  37. input_event(input_dev, EV_MSC, MSC_SCAN, code);
  38. input_report_key(input_dev, atlas_keymap[code], key_down);
  39. input_sync(input_dev);
  40. status = AE_OK;
  41. } else {
  42. pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
  43. function, (unsigned long)address, (u32)*value);
  44. status = AE_BAD_PARAMETER;
  45. }
  46. return status;
  47. }
  48. static int atlas_acpi_button_add(struct acpi_device *device)
  49. {
  50. acpi_status status;
  51. int i;
  52. int err;
  53. input_dev = input_allocate_device();
  54. if (!input_dev) {
  55. pr_err("unable to allocate input device\n");
  56. return -ENOMEM;
  57. }
  58. input_dev->name = "Atlas ACPI button driver";
  59. input_dev->phys = "ASIM0000/atlas/input0";
  60. input_dev->id.bustype = BUS_HOST;
  61. input_dev->keycode = atlas_keymap;
  62. input_dev->keycodesize = sizeof(unsigned short);
  63. input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
  64. input_set_capability(input_dev, EV_MSC, MSC_SCAN);
  65. __set_bit(EV_KEY, input_dev->evbit);
  66. for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
  67. if (i < 9) {
  68. atlas_keymap[i] = KEY_F1 + i;
  69. __set_bit(KEY_F1 + i, input_dev->keybit);
  70. } else
  71. atlas_keymap[i] = KEY_RESERVED;
  72. }
  73. err = input_register_device(input_dev);
  74. if (err) {
  75. pr_err("couldn't register input device\n");
  76. input_free_device(input_dev);
  77. return err;
  78. }
  79. /* hookup button handler */
  80. status = acpi_install_address_space_handler(device->handle,
  81. 0x81, &acpi_atlas_button_handler,
  82. &acpi_atlas_button_setup, device);
  83. if (ACPI_FAILURE(status)) {
  84. pr_err("error installing addr spc handler\n");
  85. input_unregister_device(input_dev);
  86. err = -EINVAL;
  87. }
  88. return err;
  89. }
  90. static int atlas_acpi_button_remove(struct acpi_device *device)
  91. {
  92. acpi_status status;
  93. status = acpi_remove_address_space_handler(device->handle,
  94. 0x81, &acpi_atlas_button_handler);
  95. if (ACPI_FAILURE(status))
  96. pr_err("error removing addr spc handler\n");
  97. input_unregister_device(input_dev);
  98. return 0;
  99. }
  100. static const struct acpi_device_id atlas_device_ids[] = {
  101. {"ASIM0000", 0},
  102. {"", 0},
  103. };
  104. MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
  105. static struct acpi_driver atlas_acpi_driver = {
  106. .name = ACPI_ATLAS_NAME,
  107. .class = ACPI_ATLAS_CLASS,
  108. .owner = THIS_MODULE,
  109. .ids = atlas_device_ids,
  110. .ops = {
  111. .add = atlas_acpi_button_add,
  112. .remove = atlas_acpi_button_remove,
  113. },
  114. };
  115. module_acpi_driver(atlas_acpi_driver);
  116. MODULE_AUTHOR("Jaya Kumar");
  117. MODULE_LICENSE("GPL");
  118. MODULE_DESCRIPTION("Atlas button driver");