atlas_btns.c 4.2 KB
Newer Older
J
Jaya Kumar 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 *  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.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

24 25
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

J
Jaya Kumar 已提交
26 27 28 29 30 31 32 33
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/types.h>
#include <asm/uaccess.h>
#include <acpi/acpi_drivers.h>

34 35
#define ACPI_ATLAS_NAME		"Atlas ACPI"
#define ACPI_ATLAS_CLASS	"Atlas"
J
Jaya Kumar 已提交
36

37
static unsigned short atlas_keymap[16];
J
Jaya Kumar 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51
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,
L
Lin Ming 已提交
52
		      u32 bit_width, u64 *value,
J
Jaya Kumar 已提交
53 54 55 56 57
		      void *handler_context, void *region_context)
{
	acpi_status status;

	if (function == ACPI_WRITE) {
58 59 60 61 62
		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);
J
Jaya Kumar 已提交
63
		input_sync(input_dev);
64

65
		status = AE_OK;
J
Jaya Kumar 已提交
66
	} else {
67
		pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
J
Jaya Kumar 已提交
68
			function, (unsigned long)address, (u32)*value);
69
		status = AE_BAD_PARAMETER;
J
Jaya Kumar 已提交
70 71 72 73 74 75 76 77
	}

	return status;
}

static int atlas_acpi_button_add(struct acpi_device *device)
{
	acpi_status status;
78
	int i;
J
Jaya Kumar 已提交
79 80 81 82
	int err;

	input_dev = input_allocate_device();
	if (!input_dev) {
83
		pr_err("unable to allocate input device\n");
J
Jaya Kumar 已提交
84 85 86 87 88 89
		return -ENOMEM;
	}

	input_dev->name = "Atlas ACPI button driver";
	input_dev->phys = "ASIM0000/atlas/input0";
	input_dev->id.bustype = BUS_HOST;
90 91 92 93 94 95 96 97 98 99 100 101 102
	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;
	}
J
Jaya Kumar 已提交
103 104 105

	err = input_register_device(input_dev);
	if (err) {
106
		pr_err("couldn't register input device\n");
J
Jaya Kumar 已提交
107 108 109 110 111 112 113 114 115
		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)) {
116
		pr_err("error installing addr spc handler\n");
J
Jaya Kumar 已提交
117
		input_unregister_device(input_dev);
118
		err = -EINVAL;
J
Jaya Kumar 已提交
119 120
	}

121
	return err;
J
Jaya Kumar 已提交
122 123 124 125 126 127 128 129
}

static int atlas_acpi_button_remove(struct acpi_device *device, int type)
{
	acpi_status status;

	status = acpi_remove_address_space_handler(device->handle,
				0x81, &acpi_atlas_button_handler);
130
	if (ACPI_FAILURE(status))
131
		pr_err("error removing addr spc handler\n");
J
Jaya Kumar 已提交
132 133 134

	input_unregister_device(input_dev);

135
	return 0;
J
Jaya Kumar 已提交
136 137
}

138 139 140 141 142 143
static const struct acpi_device_id atlas_device_ids[] = {
	{"ASIM0000", 0},
	{"", 0},
};
MODULE_DEVICE_TABLE(acpi, atlas_device_ids);

J
Jaya Kumar 已提交
144 145 146
static struct acpi_driver atlas_acpi_driver = {
	.name	= ACPI_ATLAS_NAME,
	.class	= ACPI_ATLAS_CLASS,
147
	.owner	= THIS_MODULE,
148
	.ids	= atlas_device_ids,
J
Jaya Kumar 已提交
149 150 151 152 153
	.ops	= {
		.add	= atlas_acpi_button_add,
		.remove	= atlas_acpi_button_remove,
	},
};
154
module_acpi_driver(atlas_acpi_driver);
J
Jaya Kumar 已提交
155 156 157 158 159

MODULE_AUTHOR("Jaya Kumar");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Atlas button driver");