2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-02-10 14:29:00 +08:00
|
|
|
/*
|
|
|
|
* atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jaya Kumar
|
|
|
|
* Based on Toshiba ACPI by John Belmonte and ASUS ACPI
|
|
|
|
* This work was sponsored by CIS(M) Sdn Bhd.
|
|
|
|
*/
|
|
|
|
|
2010-07-14 00:33:20 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-02-10 14:29:00 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/types.h>
|
2013-12-03 08:49:16 +08:00
|
|
|
#include <linux/acpi.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2007-02-10 14:29:00 +08:00
|
|
|
|
2007-11-04 12:41:30 +08:00
|
|
|
#define ACPI_ATLAS_NAME "Atlas ACPI"
|
|
|
|
#define ACPI_ATLAS_CLASS "Atlas"
|
2007-02-10 14:29:00 +08:00
|
|
|
|
2007-11-04 12:41:30 +08:00
|
|
|
static unsigned short atlas_keymap[16];
|
2007-02-10 14:29:00 +08:00
|
|
|
static struct input_dev *input_dev;
|
|
|
|
|
|
|
|
/* button handling code */
|
|
|
|
static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
|
|
|
|
u32 function, void *handler_context, void **return_context)
|
|
|
|
{
|
|
|
|
*return_context =
|
|
|
|
(function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
|
|
|
|
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static acpi_status acpi_atlas_button_handler(u32 function,
|
|
|
|
acpi_physical_address address,
|
2010-01-28 10:53:19 +08:00
|
|
|
u32 bit_width, u64 *value,
|
2007-02-10 14:29:00 +08:00
|
|
|
void *handler_context, void *region_context)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
if (function == ACPI_WRITE) {
|
2007-11-04 12:41:30 +08:00
|
|
|
int code = address & 0x0f;
|
|
|
|
int key_down = !(address & 0x10);
|
|
|
|
|
|
|
|
input_event(input_dev, EV_MSC, MSC_SCAN, code);
|
|
|
|
input_report_key(input_dev, atlas_keymap[code], key_down);
|
2007-02-10 14:29:00 +08:00
|
|
|
input_sync(input_dev);
|
2007-11-04 12:41:30 +08:00
|
|
|
|
2010-07-14 00:25:12 +08:00
|
|
|
status = AE_OK;
|
2007-02-10 14:29:00 +08:00
|
|
|
} else {
|
2010-07-14 00:33:20 +08:00
|
|
|
pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
|
2007-02-10 14:29:00 +08:00
|
|
|
function, (unsigned long)address, (u32)*value);
|
2010-07-14 00:25:12 +08:00
|
|
|
status = AE_BAD_PARAMETER;
|
2007-02-10 14:29:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atlas_acpi_button_add(struct acpi_device *device)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
2007-11-04 12:41:30 +08:00
|
|
|
int i;
|
2007-02-10 14:29:00 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!input_dev) {
|
2010-07-14 00:33:20 +08:00
|
|
|
pr_err("unable to allocate input device\n");
|
2007-02-10 14:29:00 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_dev->name = "Atlas ACPI button driver";
|
|
|
|
input_dev->phys = "ASIM0000/atlas/input0";
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
2007-11-04 12:41:30 +08:00
|
|
|
input_dev->keycode = atlas_keymap;
|
|
|
|
input_dev->keycodesize = sizeof(unsigned short);
|
|
|
|
input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
|
|
|
|
|
|
|
|
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
|
|
|
|
__set_bit(EV_KEY, input_dev->evbit);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
|
|
|
|
if (i < 9) {
|
|
|
|
atlas_keymap[i] = KEY_F1 + i;
|
|
|
|
__set_bit(KEY_F1 + i, input_dev->keybit);
|
|
|
|
} else
|
|
|
|
atlas_keymap[i] = KEY_RESERVED;
|
|
|
|
}
|
2007-02-10 14:29:00 +08:00
|
|
|
|
|
|
|
err = input_register_device(input_dev);
|
|
|
|
if (err) {
|
2010-07-14 00:33:20 +08:00
|
|
|
pr_err("couldn't register input device\n");
|
2007-02-10 14:29:00 +08:00
|
|
|
input_free_device(input_dev);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hookup button handler */
|
|
|
|
status = acpi_install_address_space_handler(device->handle,
|
|
|
|
0x81, &acpi_atlas_button_handler,
|
|
|
|
&acpi_atlas_button_setup, device);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2010-07-14 00:33:20 +08:00
|
|
|
pr_err("error installing addr spc handler\n");
|
2007-02-10 14:29:00 +08:00
|
|
|
input_unregister_device(input_dev);
|
2010-07-14 00:25:12 +08:00
|
|
|
err = -EINVAL;
|
2007-02-10 14:29:00 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 00:25:12 +08:00
|
|
|
return err;
|
2007-02-10 14:29:00 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 07:24:48 +08:00
|
|
|
static int atlas_acpi_button_remove(struct acpi_device *device)
|
2007-02-10 14:29:00 +08:00
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
status = acpi_remove_address_space_handler(device->handle,
|
|
|
|
0x81, &acpi_atlas_button_handler);
|
2010-07-14 00:25:12 +08:00
|
|
|
if (ACPI_FAILURE(status))
|
2010-07-14 00:33:20 +08:00
|
|
|
pr_err("error removing addr spc handler\n");
|
2007-02-10 14:29:00 +08:00
|
|
|
|
|
|
|
input_unregister_device(input_dev);
|
|
|
|
|
2010-07-14 00:25:12 +08:00
|
|
|
return 0;
|
2007-02-10 14:29:00 +08:00
|
|
|
}
|
|
|
|
|
2007-07-23 20:44:41 +08:00
|
|
|
static const struct acpi_device_id atlas_device_ids[] = {
|
|
|
|
{"ASIM0000", 0},
|
|
|
|
{"", 0},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
|
|
|
|
|
2007-02-10 14:29:00 +08:00
|
|
|
static struct acpi_driver atlas_acpi_driver = {
|
|
|
|
.name = ACPI_ATLAS_NAME,
|
|
|
|
.class = ACPI_ATLAS_CLASS,
|
2010-07-14 00:13:23 +08:00
|
|
|
.owner = THIS_MODULE,
|
2007-07-23 20:44:41 +08:00
|
|
|
.ids = atlas_device_ids,
|
2007-02-10 14:29:00 +08:00
|
|
|
.ops = {
|
|
|
|
.add = atlas_acpi_button_add,
|
|
|
|
.remove = atlas_acpi_button_remove,
|
|
|
|
},
|
|
|
|
};
|
2012-09-07 15:31:44 +08:00
|
|
|
module_acpi_driver(atlas_acpi_driver);
|
2007-02-10 14:29:00 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jaya Kumar");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Atlas button driver");
|
|
|
|
|