blob: 0e77c40e1966b59e6d8822dc81f686b8f80646b8 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jaya Kumar31ea7ff2007-02-10 01:29:00 -05002/*
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.
Jaya Kumar31ea7ff2007-02-10 01:29:00 -05008 */
9
Dmitry Torokhovbf774992010-07-13 09:33:20 -070010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050012#include <linux/kernel.h>
13#include <linux/module.h>
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050014#include <linux/input.h>
15#include <linux/types.h>
Lv Zheng8b484632013-12-03 08:49:16 +080016#include <linux/acpi.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080017#include <linux/uaccess.h>
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050018
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040019#define ACPI_ATLAS_NAME "Atlas ACPI"
20#define ACPI_ATLAS_CLASS "Atlas"
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050021
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040022static unsigned short atlas_keymap[16];
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050023static struct input_dev *input_dev;
24
25/* button handling code */
26static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
27 u32 function, void *handler_context, void **return_context)
28{
29 *return_context =
30 (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
31
32 return AE_OK;
33}
34
35static acpi_status acpi_atlas_button_handler(u32 function,
36 acpi_physical_address address,
Lin Ming439913f2010-01-28 10:53:19 +080037 u32 bit_width, u64 *value,
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050038 void *handler_context, void *region_context)
39{
40 acpi_status status;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050041
42 if (function == ACPI_WRITE) {
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040043 int code = address & 0x0f;
44 int key_down = !(address & 0x10);
45
46 input_event(input_dev, EV_MSC, MSC_SCAN, code);
47 input_report_key(input_dev, atlas_keymap[code], key_down);
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050048 input_sync(input_dev);
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040049
Axel Lin02b5fac2010-07-13 09:25:12 -070050 status = AE_OK;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050051 } else {
Dmitry Torokhovbf774992010-07-13 09:33:20 -070052 pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050053 function, (unsigned long)address, (u32)*value);
Axel Lin02b5fac2010-07-13 09:25:12 -070054 status = AE_BAD_PARAMETER;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050055 }
56
57 return status;
58}
59
60static int atlas_acpi_button_add(struct acpi_device *device)
61{
62 acpi_status status;
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040063 int i;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050064 int err;
65
66 input_dev = input_allocate_device();
67 if (!input_dev) {
Dmitry Torokhovbf774992010-07-13 09:33:20 -070068 pr_err("unable to allocate input device\n");
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050069 return -ENOMEM;
70 }
71
72 input_dev->name = "Atlas ACPI button driver";
73 input_dev->phys = "ASIM0000/atlas/input0";
74 input_dev->id.bustype = BUS_HOST;
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040075 input_dev->keycode = atlas_keymap;
76 input_dev->keycodesize = sizeof(unsigned short);
77 input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050078
Dmitry Torokhov72341ee2007-11-04 00:41:30 -040079 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
80 __set_bit(EV_KEY, input_dev->evbit);
81 for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
82 if (i < 9) {
83 atlas_keymap[i] = KEY_F1 + i;
84 __set_bit(KEY_F1 + i, input_dev->keybit);
85 } else
86 atlas_keymap[i] = KEY_RESERVED;
87 }
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050088
89 err = input_register_device(input_dev);
90 if (err) {
Dmitry Torokhovbf774992010-07-13 09:33:20 -070091 pr_err("couldn't register input device\n");
Jaya Kumar31ea7ff2007-02-10 01:29:00 -050092 input_free_device(input_dev);
93 return err;
94 }
95
96 /* hookup button handler */
97 status = acpi_install_address_space_handler(device->handle,
98 0x81, &acpi_atlas_button_handler,
99 &acpi_atlas_button_setup, device);
100 if (ACPI_FAILURE(status)) {
Dmitry Torokhovbf774992010-07-13 09:33:20 -0700101 pr_err("error installing addr spc handler\n");
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500102 input_unregister_device(input_dev);
Axel Lin02b5fac2010-07-13 09:25:12 -0700103 err = -EINVAL;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500104 }
105
Axel Lin02b5fac2010-07-13 09:25:12 -0700106 return err;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500107}
108
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100109static int atlas_acpi_button_remove(struct acpi_device *device)
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500110{
111 acpi_status status;
112
113 status = acpi_remove_address_space_handler(device->handle,
114 0x81, &acpi_atlas_button_handler);
Axel Lin02b5fac2010-07-13 09:25:12 -0700115 if (ACPI_FAILURE(status))
Dmitry Torokhovbf774992010-07-13 09:33:20 -0700116 pr_err("error removing addr spc handler\n");
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500117
118 input_unregister_device(input_dev);
119
Axel Lin02b5fac2010-07-13 09:25:12 -0700120 return 0;
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500121}
122
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200123static const struct acpi_device_id atlas_device_ids[] = {
124 {"ASIM0000", 0},
125 {"", 0},
126};
127MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
128
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500129static struct acpi_driver atlas_acpi_driver = {
130 .name = ACPI_ATLAS_NAME,
131 .class = ACPI_ATLAS_CLASS,
Axel Lin07d19ff2010-07-13 09:13:23 -0700132 .owner = THIS_MODULE,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200133 .ids = atlas_device_ids,
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500134 .ops = {
135 .add = atlas_acpi_button_add,
136 .remove = atlas_acpi_button_remove,
137 },
138};
Mika Westerbergf06efcc2012-09-07 10:31:44 +0300139module_acpi_driver(atlas_acpi_driver);
Jaya Kumar31ea7ff2007-02-10 01:29:00 -0500140
141MODULE_AUTHOR("Jaya Kumar");
142MODULE_LICENSE("GPL");
143MODULE_DESCRIPTION("Atlas button driver");
144