Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
0004  *
0005  *  Copyright (C) 2006 Jaya Kumar
0006  *  Based on Toshiba ACPI by John Belmonte and ASUS ACPI
0007  *  This work was sponsored by CIS(M) Sdn Bhd.
0008  */
0009 
0010 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0011 
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/input.h>
0015 #include <linux/types.h>
0016 #include <linux/acpi.h>
0017 #include <linux/uaccess.h>
0018 
0019 #define ACPI_ATLAS_NAME     "Atlas ACPI"
0020 #define ACPI_ATLAS_CLASS    "Atlas"
0021 
0022 static unsigned short atlas_keymap[16];
0023 static struct input_dev *input_dev;
0024 
0025 /* button handling code */
0026 static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
0027             u32 function, void *handler_context, void **return_context)
0028 {
0029     *return_context =
0030         (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
0031 
0032     return AE_OK;
0033 }
0034 
0035 static acpi_status acpi_atlas_button_handler(u32 function,
0036               acpi_physical_address address,
0037               u32 bit_width, u64 *value,
0038               void *handler_context, void *region_context)
0039 {
0040     acpi_status status;
0041 
0042     if (function == ACPI_WRITE) {
0043         int code = address & 0x0f;
0044         int key_down = !(address & 0x10);
0045 
0046         input_event(input_dev, EV_MSC, MSC_SCAN, code);
0047         input_report_key(input_dev, atlas_keymap[code], key_down);
0048         input_sync(input_dev);
0049 
0050         status = AE_OK;
0051     } else {
0052         pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
0053             function, (unsigned long)address, (u32)*value);
0054         status = AE_BAD_PARAMETER;
0055     }
0056 
0057     return status;
0058 }
0059 
0060 static int atlas_acpi_button_add(struct acpi_device *device)
0061 {
0062     acpi_status status;
0063     int i;
0064     int err;
0065 
0066     input_dev = input_allocate_device();
0067     if (!input_dev) {
0068         pr_err("unable to allocate input device\n");
0069         return -ENOMEM;
0070     }
0071 
0072     input_dev->name = "Atlas ACPI button driver";
0073     input_dev->phys = "ASIM0000/atlas/input0";
0074     input_dev->id.bustype = BUS_HOST;
0075     input_dev->keycode = atlas_keymap;
0076     input_dev->keycodesize = sizeof(unsigned short);
0077     input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
0078 
0079     input_set_capability(input_dev, EV_MSC, MSC_SCAN);
0080     __set_bit(EV_KEY, input_dev->evbit);
0081     for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
0082         if (i < 9) {
0083             atlas_keymap[i] = KEY_F1 + i;
0084             __set_bit(KEY_F1 + i, input_dev->keybit);
0085         } else
0086             atlas_keymap[i] = KEY_RESERVED;
0087     }
0088 
0089     err = input_register_device(input_dev);
0090     if (err) {
0091         pr_err("couldn't register input device\n");
0092         input_free_device(input_dev);
0093         return err;
0094     }
0095 
0096     /* hookup button handler */
0097     status = acpi_install_address_space_handler(device->handle,
0098                 0x81, &acpi_atlas_button_handler,
0099                 &acpi_atlas_button_setup, device);
0100     if (ACPI_FAILURE(status)) {
0101         pr_err("error installing addr spc handler\n");
0102         input_unregister_device(input_dev);
0103         err = -EINVAL;
0104     }
0105 
0106     return err;
0107 }
0108 
0109 static int atlas_acpi_button_remove(struct acpi_device *device)
0110 {
0111     acpi_status status;
0112 
0113     status = acpi_remove_address_space_handler(device->handle,
0114                 0x81, &acpi_atlas_button_handler);
0115     if (ACPI_FAILURE(status))
0116         pr_err("error removing addr spc handler\n");
0117 
0118     input_unregister_device(input_dev);
0119 
0120     return 0;
0121 }
0122 
0123 static const struct acpi_device_id atlas_device_ids[] = {
0124     {"ASIM0000", 0},
0125     {"", 0},
0126 };
0127 MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
0128 
0129 static struct acpi_driver atlas_acpi_driver = {
0130     .name   = ACPI_ATLAS_NAME,
0131     .class  = ACPI_ATLAS_CLASS,
0132     .owner  = THIS_MODULE,
0133     .ids    = atlas_device_ids,
0134     .ops    = {
0135         .add    = atlas_acpi_button_add,
0136         .remove = atlas_acpi_button_remove,
0137     },
0138 };
0139 module_acpi_driver(atlas_acpi_driver);
0140 
0141 MODULE_AUTHOR("Jaya Kumar");
0142 MODULE_LICENSE("GPL");
0143 MODULE_DESCRIPTION("Atlas button driver");
0144