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 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 12 #include <linux/kernel.h> 13 #include <linux/module.h> 14 #include <linux/input.h> 15 #include <linux/types.h> 16 #include <linux/acpi.h> 17 #include <linux/platform_device.h> 18 #include <linux/uaccess.h> 19 20 #define ACPI_ATLAS_NAME "Atlas ACPI" 21 #define ACPI_ATLAS_CLASS "Atlas" 22 23 static unsigned short atlas_keymap[16]; 24 static struct input_dev *input_dev; 25 26 /* button handling code */ 27 static acpi_status acpi_atlas_button_setup(acpi_handle region_handle, 28 u32 function, void *handler_context, void **return_context) 29 { 30 *return_context = 31 (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL; 32 33 return AE_OK; 34 } 35 36 static acpi_status acpi_atlas_button_handler(u32 function, 37 acpi_physical_address address, 38 u32 bit_width, u64 *value, 39 void *handler_context, void *region_context) 40 { 41 acpi_status status; 42 43 if (function == ACPI_WRITE) { 44 int code = address & 0x0f; 45 int key_down = !(address & 0x10); 46 47 input_event(input_dev, EV_MSC, MSC_SCAN, code); 48 input_report_key(input_dev, atlas_keymap[code], key_down); 49 input_sync(input_dev); 50 51 status = AE_OK; 52 } else { 53 pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n", 54 function, (unsigned long)address, (u32)*value); 55 status = AE_BAD_PARAMETER; 56 } 57 58 return status; 59 } 60 61 static int atlas_acpi_button_probe(struct platform_device *pdev) 62 { 63 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 64 acpi_status status; 65 int i; 66 int err; 67 68 input_dev = input_allocate_device(); 69 if (!input_dev) { 70 pr_err("unable to allocate input device\n"); 71 return -ENOMEM; 72 } 73 74 input_dev->name = "Atlas ACPI button driver"; 75 input_dev->phys = "ASIM0000/atlas/input0"; 76 input_dev->id.bustype = BUS_HOST; 77 input_dev->keycode = atlas_keymap; 78 input_dev->keycodesize = sizeof(unsigned short); 79 input_dev->keycodemax = ARRAY_SIZE(atlas_keymap); 80 81 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 82 __set_bit(EV_KEY, input_dev->evbit); 83 for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) { 84 if (i < 9) { 85 atlas_keymap[i] = KEY_F1 + i; 86 __set_bit(KEY_F1 + i, input_dev->keybit); 87 } else 88 atlas_keymap[i] = KEY_RESERVED; 89 } 90 91 err = input_register_device(input_dev); 92 if (err) { 93 pr_err("couldn't register input device\n"); 94 input_free_device(input_dev); 95 return err; 96 } 97 98 /* hookup button handler */ 99 status = acpi_install_address_space_handler(device->handle, 100 0x81, &acpi_atlas_button_handler, 101 &acpi_atlas_button_setup, device); 102 if (ACPI_FAILURE(status)) { 103 pr_err("error installing addr spc handler\n"); 104 input_unregister_device(input_dev); 105 err = -EINVAL; 106 } 107 108 return err; 109 } 110 111 static void atlas_acpi_button_remove(struct platform_device *pdev) 112 { 113 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 114 acpi_status status; 115 116 status = acpi_remove_address_space_handler(device->handle, 117 0x81, &acpi_atlas_button_handler); 118 if (ACPI_FAILURE(status)) 119 pr_err("error removing addr spc handler\n"); 120 121 input_unregister_device(input_dev); 122 } 123 124 static const struct acpi_device_id atlas_device_ids[] = { 125 {"ASIM0000", 0}, 126 {"", 0}, 127 }; 128 MODULE_DEVICE_TABLE(acpi, atlas_device_ids); 129 130 static struct platform_driver atlas_acpi_driver = { 131 .probe = atlas_acpi_button_probe, 132 .remove = atlas_acpi_button_remove, 133 .driver = { 134 .name = ACPI_ATLAS_NAME, 135 .acpi_match_table = atlas_device_ids, 136 }, 137 }; 138 module_platform_driver(atlas_acpi_driver); 139 140 MODULE_AUTHOR("Jaya Kumar"); 141 MODULE_LICENSE("GPL"); 142 MODULE_DESCRIPTION("Atlas button driver"); 143 144