-
Notifications
You must be signed in to change notification settings - Fork 16
/
panasonic-hbtn.c
261 lines (214 loc) · 6.72 KB
/
panasonic-hbtn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* Panasonic Tablet Button driver
* (C) 2012 Heiher <admin@heiher.info>
*
* derived from panasonic-laptop.c, Copyright (C) 2002-2004 John Belmonte
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* publicshed by the Free Software Foundation.
*
* 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
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/acpi.h>
#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
MODULE_AUTHOR("Heiher");
MODULE_DESCRIPTION("ACPI Tablet Button driver for Panasonic CF-18/19 laptops");
MODULE_LICENSE("GPL");
/* Define ACPI PATHs */
#define METHOD_HBTN_QUERY "HINF"
#define HBTN_NOTIFY 0x80
#define ACPI_PCC_DRIVER_NAME "Panasonic Tablet Button Support"
#define ACPI_PCC_DEVICE_NAME "TabletButton"
#define ACPI_PCC_CLASS "pcc"
#define ACPI_PCC_INPUT_PHYS "panasonic/hbtn0"
static int acpi_pcc_hbtn_add(struct acpi_device *device);
static int acpi_pcc_hbtn_remove(struct acpi_device *device);
static void acpi_pcc_hbtn_notify(struct acpi_device *device, u32 event);
static const struct acpi_device_id pcc_device_ids[] = {
{ "MAT001F", 0},
{ "MAT0020", 0},
{ "", 0},
};
MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
static struct acpi_driver acpi_pcc_driver = {
.name = ACPI_PCC_DRIVER_NAME,
.class = ACPI_PCC_CLASS,
.ids = pcc_device_ids,
.ops = {
.add = acpi_pcc_hbtn_add,
.remove = acpi_pcc_hbtn_remove,
.notify = acpi_pcc_hbtn_notify,
},
};
static const struct key_entry panasonic_keymap[] = {
{ KE_KEY, 0x0, { KEY_RESERVED } },
{ KE_KEY, 0x4, { KEY_SCREENLOCK } }, /* Screen lock */
{ KE_KEY, 0x6, { KEY_DIRECTION } }, /* Screen rotate */
{ KE_KEY, 0x8, { KEY_ENTER } }, /* Enter */
{ KE_KEY, 0xA, { KEY_KEYBOARD } }, /* Soft keyboard */
{ KE_END, 0 }
};
struct pcc_acpi {
acpi_handle handle;
struct acpi_device *device;
struct input_dev *input_dev;
};
/* hbtn input device driver */
static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
{
struct input_dev *hotk_input_dev = pcc->input_dev;
int rc;
unsigned long long result;
struct key_entry *ke = NULL;
rc = acpi_evaluate_integer(pcc->handle, METHOD_HBTN_QUERY,
NULL, &result);
if (!ACPI_SUCCESS(rc)) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"error getting hbtn status\n"));
return;
}
acpi_bus_generate_netlink_event(pcc->device->pnp.device_class,
dev_name(&pcc->device->dev), HBTN_NOTIFY, result);
ke = sparse_keymap_entry_from_scancode(hotk_input_dev, result & 0xe);
if (!ke) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Unknown hbtn event: %d\n", result));
return;
}
sparse_keymap_report_entry(hotk_input_dev, ke,
(result & 0x1) ? 0 : 1, false);
}
static void acpi_pcc_hbtn_notify(struct acpi_device *device, u32 event)
{
struct pcc_acpi *pcc = acpi_driver_data(device);
switch (event) {
case HBTN_NOTIFY:
acpi_pcc_generate_keyinput(pcc);
break;
default:
/* nothing to do */
break;
}
}
static int acpi_pcc_init_input(struct pcc_acpi *pcc)
{
struct input_dev *input_dev;
int error;
input_dev = input_allocate_device();
if (!input_dev) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Couldn't allocate input device for hbtn"));
return -ENOMEM;
}
input_dev->name = ACPI_PCC_DRIVER_NAME;
input_dev->phys = ACPI_PCC_INPUT_PHYS;
input_dev->id.bustype = BUS_HOST;
input_dev->id.vendor = 0x0001;
input_dev->id.product = 0x0001;
input_dev->id.version = 0x0100;
error = sparse_keymap_setup(input_dev, panasonic_keymap, NULL);
if (error) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Unable to setup input device keymap\n"));
goto err_free_dev;
}
error = input_register_device(input_dev);
if (error) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Unable to register input device\n"));
goto err_free_keymap;
}
pcc->input_dev = input_dev;
return 0;
err_free_keymap:
sparse_keymap_free(input_dev);
err_free_dev:
input_free_device(input_dev);
return error;
}
static void acpi_pcc_destroy_input(struct pcc_acpi *pcc)
{
sparse_keymap_free(pcc->input_dev);
input_unregister_device(pcc->input_dev);
/*
* No need to input_free_device() since core input API refcounts
* and free()s the device.
*/
}
/* kernel module interface */
static int acpi_pcc_hbtn_add(struct acpi_device *device)
{
struct pcc_acpi *pcc;
int result;
if (!device)
return -EINVAL;
pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL);
if (!pcc) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Couldn't allocate mem for pcc"));
return -ENOMEM;
}
pcc->device = device;
pcc->handle = device->handle;
device->driver_data = pcc;
strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
result = acpi_pcc_init_input(pcc);
if (result) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Error installing keyinput handler\n"));
goto out_hbtn;
}
return 0;
out_hbtn:
kfree(pcc);
return result;
}
static int __init acpi_pcc_init(void)
{
int result = 0;
if (acpi_disabled)
return -ENODEV;
result = acpi_bus_register_driver(&acpi_pcc_driver);
if (result < 0) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Error registering hbtn driver\n"));
return -ENODEV;
}
return 0;
}
static int acpi_pcc_hbtn_remove(struct acpi_device *device)
{
struct pcc_acpi *pcc = acpi_driver_data(device);
if (!device || !pcc)
return -EINVAL;
acpi_pcc_destroy_input(pcc);
kfree(pcc);
return 0;
}
static void __exit acpi_pcc_exit(void)
{
acpi_bus_unregister_driver(&acpi_pcc_driver);
}
module_init(acpi_pcc_init);
module_exit(acpi_pcc_exit);