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