]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
1 | From 709ee531c153038d81b30649b9eeed3c44a4d5cc Mon Sep 17 00:00:00 2001 |
2 | From: Harald Welte <laforge@gnumonks.org> | |
3 | Date: Tue, 23 Sep 2008 17:46:57 +0200 | |
4 | Subject: panasonic-laptop: add Panasonic Let's Note laptop extras driver v0.94 | |
5 | Patch-mainline: 2.6.28 | |
6 | ||
7 | This is a driver for ACPI extras such as hotkeys and backlight | |
8 | brightness control on various Panasonic "Let's Note" series laptop | |
9 | computers. | |
10 | ||
11 | It exports the backlight via the backlight class device API, | |
12 | and the hotkeys as input event device. Some more esoteric | |
13 | items like number of installed batteries are exported via sysfs | |
14 | device attributes. | |
15 | ||
16 | Hotkey events also generate old-style ACPI enents through | |
17 | /proc/acpi/event to interoperate with current versions of acpid. | |
18 | ||
19 | Signed-off-by: Harald Welte <laforge@gnumonks.org> | |
20 | Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> | |
21 | Acked-by: Matthew Garrett <mjg@redhat.com> | |
22 | Signed-off-by: Len Brown <len.brown@intel.com> | |
23 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
24 | ||
25 | --- | |
26 | MAINTAINERS | 5 | |
27 | drivers/misc/Kconfig | 11 | |
28 | drivers/misc/Makefile | 1 | |
29 | drivers/misc/panasonic-laptop.c | 767 ++++++++++++++++++++++++++++++++++++++++ | |
30 | 4 files changed, 784 insertions(+) | |
31 | ||
32 | Index: linux-2.6.27-sles11/drivers/misc/Kconfig | |
33 | =================================================================== | |
34 | --- linux-2.6.27-sles11.orig/drivers/misc/Kconfig | |
35 | +++ linux-2.6.27-sles11/drivers/misc/Kconfig | |
36 | @@ -245,6 +245,17 @@ config MSI_LAPTOP | |
37 | ||
38 | If you have an MSI S270 laptop, say Y or M here. | |
39 | ||
40 | +config PANASONIC_LAPTOP | |
41 | + tristate "Panasonic Laptop Extras" | |
42 | + depends on X86 && INPUT | |
43 | + depends on BACKLIGHT_CLASS_DEVICE | |
44 | + ---help--- | |
45 | + This driver adds support for access to backlight control and hotkeys | |
46 | + on Panasonic Let's Note laptops. | |
47 | + | |
48 | + If you have a Panasonic Let's note laptop (such as the R1(N variant), | |
49 | + R2, R3, R5, T2, W2 and Y2 series), say Y. | |
50 | + | |
51 | config COMPAL_LAPTOP | |
52 | tristate "Compal Laptop Extras" | |
53 | depends on X86 | |
54 | Index: linux-2.6.27-sles11/drivers/misc/Makefile | |
55 | =================================================================== | |
56 | --- linux-2.6.27-sles11.orig/drivers/misc/Makefile | |
57 | +++ linux-2.6.27-sles11/drivers/misc/Makefile | |
58 | @@ -23,6 +23,7 @@ obj-$(CONFIG_SGI_IOC4) += ioc4.o | |
59 | obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o | |
60 | obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o | |
61 | obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o | |
62 | +obj-$(CONFIG_PANASONIC_LAPTOP) += panasonic-laptop.o | |
63 | obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o | |
64 | obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o | |
65 | obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o | |
66 | Index: linux-2.6.27-sles11/drivers/misc/panasonic-laptop.c | |
67 | =================================================================== | |
68 | --- /dev/null | |
69 | +++ linux-2.6.27-sles11/drivers/misc/panasonic-laptop.c | |
70 | @@ -0,0 +1,767 @@ | |
71 | +/* | |
72 | + * Panasonic HotKey and LCD brightness control driver | |
73 | + * (C) 2004 Hiroshi Miura <miura@da-cha.org> | |
74 | + * (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/ | |
75 | + * (C) YOKOTA Hiroshi <yokota (at) netlab. is. tsukuba. ac. jp> | |
76 | + * (C) 2004 David Bronaugh <dbronaugh> | |
77 | + * (C) 2006-2008 Harald Welte <laforge@gnumonks.org> | |
78 | + * | |
79 | + * derived from toshiba_acpi.c, Copyright (C) 2002-2004 John Belmonte | |
80 | + * | |
81 | + * This program is free software; you can redistribute it and/or modify | |
82 | + * it under the terms of the GNU General Public License version 2 as | |
83 | + * publicshed by the Free Software Foundation. | |
84 | + * | |
85 | + * This program is distributed in the hope that it will be useful, | |
86 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
87 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
88 | + * GNU General Public License for more details. | |
89 | + * | |
90 | + * You should have received a copy of the GNU General Public License | |
91 | + * along with this program; if not, write to the Free Software | |
92 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
93 | + * | |
94 | + *--------------------------------------------------------------------------- | |
95 | + * | |
96 | + * ChangeLog: | |
97 | + * Sep.23, 2008 Harald Welte <laforge@gnumonks.org> | |
98 | + * -v0.95 rename driver from drivers/acpi/pcc_acpi.c to | |
99 | + * drivers/misc/panasonic-laptop.c | |
100 | + * | |
101 | + * Jul.04, 2008 Harald Welte <laforge@gnumonks.org> | |
102 | + * -v0.94 replace /proc interface with device attributes | |
103 | + * support {set,get}keycode on th input device | |
104 | + * | |
105 | + * Jun.27, 2008 Harald Welte <laforge@gnumonks.org> | |
106 | + * -v0.92 merge with 2.6.26-rc6 input API changes | |
107 | + * remove broken <= 2.6.15 kernel support | |
108 | + * resolve all compiler warnings | |
109 | + * various coding style fixes (checkpatch.pl) | |
110 | + * add support for backlight api | |
111 | + * major code restructuring | |
112 | + * | |
113 | + * Dac.28, 2007 Harald Welte <laforge@gnumonks.org> | |
114 | + * -v0.91 merge with 2.6.24-rc6 ACPI changes | |
115 | + * | |
116 | + * Nov.04, 2006 Hiroshi Miura <miura@da-cha.org> | |
117 | + * -v0.9 remove warning about section reference. | |
118 | + * remove acpi_os_free | |
119 | + * add /proc/acpi/pcc/brightness interface for HAL access | |
120 | + * merge dbronaugh's enhancement | |
121 | + * Aug.17, 2004 David Bronaugh (dbronaugh) | |
122 | + * - Added screen brightness setting interface | |
123 | + * Thanks to FreeBSD crew (acpi_panasonic.c) | |
124 | + * for the ideas I needed to accomplish it | |
125 | + * | |
126 | + * May.29, 2006 Hiroshi Miura <miura@da-cha.org> | |
127 | + * -v0.8.4 follow to change keyinput structure | |
128 | + * thanks Fabian Yamaguchi <fabs@cs.tu-berlin.de>, | |
129 | + * Jacob Bower <jacob.bower@ic.ac.uk> and | |
130 | + * Hiroshi Yokota for providing solutions. | |
131 | + * | |
132 | + * Oct.02, 2004 Hiroshi Miura <miura@da-cha.org> | |
133 | + * -v0.8.2 merge code of YOKOTA Hiroshi | |
134 | + * <yokota@netlab.is.tsukuba.ac.jp>. | |
135 | + * Add sticky key mode interface. | |
136 | + * Refactoring acpi_pcc_generate_keyinput(). | |
137 | + * | |
138 | + * Sep.15, 2004 Hiroshi Miura <miura@da-cha.org> | |
139 | + * -v0.8 Generate key input event on input subsystem. | |
140 | + * This is based on yet another driver written by | |
141 | + * Ryuta Nakanishi. | |
142 | + * | |
143 | + * Sep.10, 2004 Hiroshi Miura <miura@da-cha.org> | |
144 | + * -v0.7 Change proc interface functions using seq_file | |
145 | + * facility as same as other ACPI drivers. | |
146 | + * | |
147 | + * Aug.28, 2004 Hiroshi Miura <miura@da-cha.org> | |
148 | + * -v0.6.4 Fix a silly error with status checking | |
149 | + * | |
150 | + * Aug.25, 2004 Hiroshi Miura <miura@da-cha.org> | |
151 | + * -v0.6.3 replace read_acpi_int by standard function | |
152 | + * acpi_evaluate_integer | |
153 | + * some clean up and make smart copyright notice. | |
154 | + * fix return value of pcc_acpi_get_key() | |
155 | + * fix checking return value of acpi_bus_register_driver() | |
156 | + * | |
157 | + * Aug.22, 2004 David Bronaugh <dbronaugh@linuxboxen.org> | |
158 | + * -v0.6.2 Add check on ACPI data (num_sifr) | |
159 | + * Coding style cleanups, better error messages/handling | |
160 | + * Fixed an off-by-one error in memory allocation | |
161 | + * | |
162 | + * Aug.21, 2004 David Bronaugh <dbronaugh@linuxboxen.org> | |
163 | + * -v0.6.1 Fix a silly error with status checking | |
164 | + * | |
165 | + * Aug.20, 2004 David Bronaugh <dbronaugh@linuxboxen.org> | |
166 | + * - v0.6 Correct brightness controls to reflect reality | |
167 | + * based on information gleaned by Hiroshi Miura | |
168 | + * and discussions with Hiroshi Miura | |
169 | + * | |
170 | + * Aug.10, 2004 Hiroshi Miura <miura@da-cha.org> | |
171 | + * - v0.5 support LCD brightness control | |
172 | + * based on the disclosed information by MEI. | |
173 | + * | |
174 | + * Jul.25, 2004 Hiroshi Miura <miura@da-cha.org> | |
175 | + * - v0.4 first post version | |
176 | + * add function to retrive SIFR | |
177 | + * | |
178 | + * Jul.24, 2004 Hiroshi Miura <miura@da-cha.org> | |
179 | + * - v0.3 get proper status of hotkey | |
180 | + * | |
181 | + * Jul.22, 2004 Hiroshi Miura <miura@da-cha.org> | |
182 | + * - v0.2 add HotKey handler | |
183 | + * | |
184 | + * Jul.17, 2004 Hiroshi Miura <miura@da-cha.org> | |
185 | + * - v0.1 start from toshiba_acpi driver written by John Belmonte | |
186 | + * | |
187 | + */ | |
188 | + | |
189 | +#include <linux/version.h> | |
190 | +#include <linux/kernel.h> | |
191 | +#include <linux/module.h> | |
192 | +#include <linux/init.h> | |
193 | +#include <linux/types.h> | |
194 | +#include <linux/backlight.h> | |
195 | +#include <linux/ctype.h> | |
196 | +#include <linux/seq_file.h> | |
197 | +#include <linux/uaccess.h> | |
198 | +#include <acpi/acpi_bus.h> | |
199 | +#include <acpi/acpi_drivers.h> | |
200 | +#include <linux/input.h> | |
201 | + | |
202 | + | |
203 | +#ifndef ACPI_HOTKEY_COMPONENT | |
204 | +#define ACPI_HOTKEY_COMPONENT 0x10000000 | |
205 | +#endif | |
206 | + | |
207 | +#define _COMPONENT ACPI_HOTKEY_COMPONENT | |
208 | + | |
209 | +MODULE_AUTHOR("Hiroshi Miura, David Bronaugh and Harald Welte"); | |
210 | +MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops"); | |
211 | +MODULE_LICENSE("GPL"); | |
212 | + | |
213 | +#define LOGPREFIX "pcc_acpi: " | |
214 | + | |
215 | +/* Define ACPI PATHs */ | |
216 | +/* Lets note hotkeys */ | |
217 | +#define METHOD_HKEY_QUERY "HINF" | |
218 | +#define METHOD_HKEY_SQTY "SQTY" | |
219 | +#define METHOD_HKEY_SINF "SINF" | |
220 | +#define METHOD_HKEY_SSET "SSET" | |
221 | +#define HKEY_NOTIFY 0x80 | |
222 | + | |
223 | +#define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support" | |
224 | +#define ACPI_PCC_DEVICE_NAME "Hotkey" | |
225 | +#define ACPI_PCC_CLASS "pcc" | |
226 | + | |
227 | +#define ACPI_PCC_INPUT_PHYS "panasonic/hkey0" | |
228 | + | |
229 | +/* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent | |
230 | + ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00 | |
231 | +*/ | |
232 | +enum SINF_BITS { SINF_NUM_BATTERIES = 0, | |
233 | + SINF_LCD_TYPE, | |
234 | + SINF_AC_MAX_BRIGHT, | |
235 | + SINF_AC_MIN_BRIGHT, | |
236 | + SINF_AC_CUR_BRIGHT, | |
237 | + SINF_DC_MAX_BRIGHT, | |
238 | + SINF_DC_MIN_BRIGHT, | |
239 | + SINF_DC_CUR_BRIGHT, | |
240 | + SINF_MUTE, | |
241 | + SINF_RESERVED, | |
242 | + SINF_ENV_STATE, | |
243 | + SINF_STICKY_KEY = 0x80, | |
244 | + }; | |
245 | +/* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */ | |
246 | + | |
247 | +static int acpi_pcc_hotkey_add(struct acpi_device *device); | |
248 | +static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type); | |
249 | +static int acpi_pcc_hotkey_resume(struct acpi_device *device); | |
250 | + | |
251 | +static const struct acpi_device_id pcc_device_ids[] = { | |
252 | + { "MAT0012", 0}, | |
253 | + { "MAT0013", 0}, | |
254 | + { "MAT0018", 0}, | |
255 | + { "MAT0019", 0}, | |
256 | + { "", 0}, | |
257 | +}; | |
258 | + | |
259 | +static struct acpi_driver acpi_pcc_driver = { | |
260 | + .name = ACPI_PCC_DRIVER_NAME, | |
261 | + .class = ACPI_PCC_CLASS, | |
262 | + .ids = pcc_device_ids, | |
263 | + .ops = { | |
264 | + .add = acpi_pcc_hotkey_add, | |
265 | + .remove = acpi_pcc_hotkey_remove, | |
266 | + .resume = acpi_pcc_hotkey_resume, | |
267 | + }, | |
268 | +}; | |
269 | + | |
270 | +#define KEYMAP_SIZE 11 | |
271 | +static const int initial_keymap[KEYMAP_SIZE] = { | |
272 | + /* 0 */ KEY_RESERVED, | |
273 | + /* 1 */ KEY_BRIGHTNESSDOWN, | |
274 | + /* 2 */ KEY_BRIGHTNESSUP, | |
275 | + /* 3 */ KEY_DISPLAYTOGGLE, | |
276 | + /* 4 */ KEY_MUTE, | |
277 | + /* 5 */ KEY_VOLUMEDOWN, | |
278 | + /* 6 */ KEY_VOLUMEUP, | |
279 | + /* 7 */ KEY_SLEEP, | |
280 | + /* 8 */ KEY_PROG1, /* Change CPU boost */ | |
281 | + /* 9 */ KEY_BATTERY, | |
282 | + /* 10 */ KEY_SUSPEND, | |
283 | +}; | |
284 | + | |
285 | +struct pcc_acpi { | |
286 | + acpi_handle handle; | |
287 | + unsigned long num_sifr; | |
288 | + int sticky_mode; | |
289 | + u32 *sinf; | |
290 | + struct acpi_device *device; | |
291 | + struct input_dev *input_dev; | |
292 | + struct backlight_device *backlight; | |
293 | + int keymap[KEYMAP_SIZE]; | |
294 | +}; | |
295 | + | |
296 | +struct pcc_keyinput { | |
297 | + struct acpi_hotkey *hotkey; | |
298 | +}; | |
299 | + | |
300 | +/* method access functions */ | |
301 | +static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val) | |
302 | +{ | |
303 | + union acpi_object in_objs[] = { | |
304 | + { .integer.type = ACPI_TYPE_INTEGER, | |
305 | + .integer.value = func, }, | |
306 | + { .integer.type = ACPI_TYPE_INTEGER, | |
307 | + .integer.value = val, }, | |
308 | + }; | |
309 | + struct acpi_object_list params = { | |
310 | + .count = ARRAY_SIZE(in_objs), | |
311 | + .pointer = in_objs, | |
312 | + }; | |
313 | + acpi_status status = AE_OK; | |
314 | + | |
315 | + ACPI_FUNCTION_TRACE("acpi_pcc_write_sset"); | |
316 | + | |
317 | + status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET, | |
318 | + ¶ms, NULL); | |
319 | + | |
320 | + return status == AE_OK; | |
321 | +} | |
322 | + | |
323 | +static inline int acpi_pcc_get_sqty(struct acpi_device *device) | |
324 | +{ | |
325 | + unsigned long long s; | |
326 | + acpi_status status; | |
327 | + | |
328 | + ACPI_FUNCTION_TRACE("acpi_pcc_get_sqty"); | |
329 | + | |
330 | + status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY, | |
331 | + NULL, &s); | |
332 | + if (ACPI_SUCCESS(status)) | |
333 | + return s; | |
334 | + else { | |
335 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
336 | + "evaluation error HKEY.SQTY\n")); | |
337 | + return -EINVAL; | |
338 | + } | |
339 | +} | |
340 | + | |
341 | +static int acpi_pcc_retrieve_biosdata(struct pcc_acpi *pcc, u32 *sinf) | |
342 | +{ | |
343 | + acpi_status status; | |
344 | + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | |
345 | + union acpi_object *hkey = NULL; | |
346 | + int i; | |
347 | + | |
348 | + ACPI_FUNCTION_TRACE("acpi_pcc_retrieve_biosdata"); | |
349 | + | |
350 | + status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SINF, 0, | |
351 | + &buffer); | |
352 | + if (ACPI_FAILURE(status)) { | |
353 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
354 | + "evaluation error HKEY.SINF\n")); | |
355 | + return 0; | |
356 | + } | |
357 | + | |
358 | + hkey = buffer.pointer; | |
359 | + if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) { | |
360 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n")); | |
361 | + goto end; | |
362 | + } | |
363 | + | |
364 | + if (pcc->num_sifr < hkey->package.count) { | |
365 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
366 | + "SQTY reports bad SINF length\n")); | |
367 | + status = AE_ERROR; | |
368 | + goto end; | |
369 | + } | |
370 | + | |
371 | + for (i = 0; i < hkey->package.count; i++) { | |
372 | + union acpi_object *element = &(hkey->package.elements[i]); | |
373 | + if (likely(element->type == ACPI_TYPE_INTEGER)) { | |
374 | + sinf[i] = element->integer.value; | |
375 | + } else | |
376 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
377 | + "Invalid HKEY.SINF data\n")); | |
378 | + } | |
379 | + sinf[hkey->package.count] = -1; | |
380 | + | |
381 | +end: | |
382 | + kfree(buffer.pointer); | |
383 | + return status == AE_OK; | |
384 | +} | |
385 | + | |
386 | +/* backlight API interface functions */ | |
387 | + | |
388 | +/* This driver currently treats AC and DC brightness identical, | |
389 | + * since we don't need to invent an interface to the core ACPI | |
390 | + * logic to receive events in case a power supply is plugged in | |
391 | + * or removed */ | |
392 | + | |
393 | +static int bl_get(struct backlight_device *bd) | |
394 | +{ | |
395 | + struct pcc_acpi *pcc = bl_get_data(bd); | |
396 | + | |
397 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
398 | + return -EIO; | |
399 | + | |
400 | + return pcc->sinf[SINF_AC_CUR_BRIGHT]; | |
401 | +} | |
402 | + | |
403 | +static int bl_set_status(struct backlight_device *bd) | |
404 | +{ | |
405 | + struct pcc_acpi *pcc = bl_get_data(bd); | |
406 | + int bright = bd->props.brightness; | |
407 | + int rc; | |
408 | + | |
409 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
410 | + return -EIO; | |
411 | + | |
412 | + if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT]) | |
413 | + bright = pcc->sinf[SINF_AC_MIN_BRIGHT]; | |
414 | + | |
415 | + if (bright < pcc->sinf[SINF_DC_MIN_BRIGHT]) | |
416 | + bright = pcc->sinf[SINF_DC_MIN_BRIGHT]; | |
417 | + | |
418 | + if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT] || | |
419 | + bright > pcc->sinf[SINF_AC_MAX_BRIGHT]) | |
420 | + return -EINVAL; | |
421 | + | |
422 | + rc = acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, bright); | |
423 | + if (rc < 0) | |
424 | + return rc; | |
425 | + | |
426 | + return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright); | |
427 | +} | |
428 | + | |
429 | +static struct backlight_ops pcc_backlight_ops = { | |
430 | + .get_brightness = bl_get, | |
431 | + .update_status = bl_set_status, | |
432 | +}; | |
433 | + | |
434 | + | |
435 | +/* sysfs user interface functions */ | |
436 | + | |
437 | +static ssize_t show_numbatt(struct device *dev, struct device_attribute *attr, | |
438 | + char *buf) | |
439 | +{ | |
440 | + struct acpi_device *acpi = to_acpi_device(dev); | |
441 | + struct pcc_acpi *pcc = acpi_driver_data(acpi); | |
442 | + | |
443 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
444 | + return -EIO; | |
445 | + | |
446 | + return sprintf(buf, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]); | |
447 | +} | |
448 | + | |
449 | +static ssize_t show_lcdtype(struct device *dev, struct device_attribute *attr, | |
450 | + char *buf) | |
451 | +{ | |
452 | + struct acpi_device *acpi = to_acpi_device(dev); | |
453 | + struct pcc_acpi *pcc = acpi_driver_data(acpi); | |
454 | + | |
455 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
456 | + return -EIO; | |
457 | + | |
458 | + return sprintf(buf, "%u\n", pcc->sinf[SINF_LCD_TYPE]); | |
459 | +} | |
460 | + | |
461 | +static ssize_t show_mute(struct device *dev, struct device_attribute *attr, | |
462 | + char *buf) | |
463 | +{ | |
464 | + struct acpi_device *acpi = to_acpi_device(dev); | |
465 | + struct pcc_acpi *pcc = acpi_driver_data(acpi); | |
466 | + | |
467 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
468 | + return -EIO; | |
469 | + | |
470 | + return sprintf(buf, "%u\n", pcc->sinf[SINF_MUTE]); | |
471 | +} | |
472 | + | |
473 | +static ssize_t show_sticky(struct device *dev, struct device_attribute *attr, | |
474 | + char *buf) | |
475 | +{ | |
476 | + struct acpi_device *acpi = to_acpi_device(dev); | |
477 | + struct pcc_acpi *pcc = acpi_driver_data(acpi); | |
478 | + | |
479 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) | |
480 | + return -EIO; | |
481 | + | |
482 | + return sprintf(buf, "%u\n", pcc->sinf[SINF_STICKY_KEY]); | |
483 | +} | |
484 | + | |
485 | +static ssize_t set_sticky(struct device *dev, struct device_attribute *attr, | |
486 | + const char *buf, size_t count) | |
487 | +{ | |
488 | + struct acpi_device *acpi = to_acpi_device(dev); | |
489 | + struct pcc_acpi *pcc = acpi_driver_data(acpi); | |
490 | + int val; | |
491 | + | |
492 | + if (count && sscanf(buf, "%i", &val) == 1 && | |
493 | + (val == 0 || val == 1)) { | |
494 | + acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val); | |
495 | + pcc->sticky_mode = val; | |
496 | + } | |
497 | + | |
498 | + return count; | |
499 | +} | |
500 | + | |
501 | +static DEVICE_ATTR(numbatt, S_IRUGO, show_numbatt, NULL); | |
502 | +static DEVICE_ATTR(lcdtype, S_IRUGO, show_lcdtype, NULL); | |
503 | +static DEVICE_ATTR(mute, S_IRUGO, show_mute, NULL); | |
504 | +static DEVICE_ATTR(sticky_key, S_IRUGO | S_IWUSR, show_sticky, set_sticky); | |
505 | + | |
506 | +static struct attribute *pcc_sysfs_entries[] = { | |
507 | + &dev_attr_numbatt.attr, | |
508 | + &dev_attr_lcdtype.attr, | |
509 | + &dev_attr_mute.attr, | |
510 | + &dev_attr_sticky_key.attr, | |
511 | + NULL, | |
512 | +}; | |
513 | + | |
514 | +static struct attribute_group pcc_attr_group = { | |
515 | + .name = NULL, /* put in device directory */ | |
516 | + .attrs = pcc_sysfs_entries, | |
517 | +}; | |
518 | + | |
519 | + | |
520 | +/* hotkey input device driver */ | |
521 | + | |
522 | +static int pcc_getkeycode(struct input_dev *dev, int scancode, int *keycode) | |
523 | +{ | |
524 | + struct pcc_acpi *pcc = input_get_drvdata(dev); | |
525 | + | |
526 | + if (scancode >= ARRAY_SIZE(pcc->keymap)) | |
527 | + return -EINVAL; | |
528 | + | |
529 | + *keycode = pcc->keymap[scancode]; | |
530 | + | |
531 | + return 0; | |
532 | +} | |
533 | + | |
534 | +static int keymap_get_by_keycode(struct pcc_acpi *pcc, int keycode) | |
535 | +{ | |
536 | + int i; | |
537 | + | |
538 | + for (i = 0; i < ARRAY_SIZE(pcc->keymap); i++) { | |
539 | + if (pcc->keymap[i] == keycode) | |
540 | + return i+1; | |
541 | + } | |
542 | + | |
543 | + return 0; | |
544 | +} | |
545 | + | |
546 | +static int pcc_setkeycode(struct input_dev *dev, int scancode, int keycode) | |
547 | +{ | |
548 | + struct pcc_acpi *pcc = input_get_drvdata(dev); | |
549 | + int oldkeycode; | |
550 | + | |
551 | + if (scancode >= ARRAY_SIZE(pcc->keymap)) | |
552 | + return -EINVAL; | |
553 | + | |
554 | + if (keycode < 0 || keycode > KEY_MAX) | |
555 | + return -EINVAL; | |
556 | + | |
557 | + oldkeycode = pcc->keymap[scancode]; | |
558 | + pcc->keymap[scancode] = keycode; | |
559 | + | |
560 | + set_bit(keycode, dev->keybit); | |
561 | + | |
562 | + if (!keymap_get_by_keycode(pcc, oldkeycode)) | |
563 | + clear_bit(oldkeycode, dev->keybit); | |
564 | + | |
565 | + return 0; | |
566 | +} | |
567 | + | |
568 | +static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc) | |
569 | +{ | |
570 | + struct input_dev *hotk_input_dev = pcc->input_dev; | |
571 | + int rc; | |
572 | + int key_code, hkey_num; | |
573 | + unsigned long long result; | |
574 | + | |
575 | + ACPI_FUNCTION_TRACE("acpi_pcc_generate_keyinput"); | |
576 | + | |
577 | + rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY, | |
578 | + NULL, &result); | |
579 | + if (!ACPI_SUCCESS(rc)) { | |
580 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
581 | + "error getting hotkey status\n")); | |
582 | + return; | |
583 | + } | |
584 | + | |
585 | + acpi_bus_generate_proc_event(pcc->device, HKEY_NOTIFY, result); | |
586 | + | |
587 | + hkey_num = result & 0xf; | |
588 | + | |
589 | + if (hkey_num < 0 || hkey_num > ARRAY_SIZE(pcc->keymap)) { | |
590 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
591 | + "hotkey number out of range: %d\n", | |
592 | + hkey_num)); | |
593 | + return; | |
594 | + } | |
595 | + | |
596 | + key_code = pcc->keymap[hkey_num]; | |
597 | + | |
598 | + if (key_code != KEY_RESERVED) { | |
599 | + int pushed = (result & 0x80) ? TRUE : FALSE; | |
600 | + | |
601 | + input_report_key(hotk_input_dev, key_code, pushed); | |
602 | + input_sync(hotk_input_dev); | |
603 | + } | |
604 | + | |
605 | + return; | |
606 | +} | |
607 | + | |
608 | +static void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data) | |
609 | +{ | |
610 | + struct pcc_acpi *pcc = (struct pcc_acpi *) data; | |
611 | + | |
612 | + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_notify"); | |
613 | + | |
614 | + switch (event) { | |
615 | + case HKEY_NOTIFY: | |
616 | + acpi_pcc_generate_keyinput(pcc); | |
617 | + break; | |
618 | + default: | |
619 | + /* nothing to do */ | |
620 | + break; | |
621 | + } | |
622 | +} | |
623 | + | |
624 | +static int acpi_pcc_init_input(struct pcc_acpi *pcc) | |
625 | +{ | |
626 | + int i, rc; | |
627 | + | |
628 | + ACPI_FUNCTION_TRACE("acpi_pcc_init_input"); | |
629 | + | |
630 | + pcc->input_dev = input_allocate_device(); | |
631 | + if (!pcc->input_dev) { | |
632 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
633 | + "Couldn't allocate input device for hotkey")); | |
634 | + return -ENOMEM; | |
635 | + } | |
636 | + | |
637 | + pcc->input_dev->evbit[0] = BIT(EV_KEY); | |
638 | + | |
639 | + pcc->input_dev->name = ACPI_PCC_DRIVER_NAME; | |
640 | + pcc->input_dev->phys = ACPI_PCC_INPUT_PHYS; | |
641 | + pcc->input_dev->id.bustype = BUS_HOST; | |
642 | + pcc->input_dev->id.vendor = 0x0001; | |
643 | + pcc->input_dev->id.product = 0x0001; | |
644 | + pcc->input_dev->id.version = 0x0100; | |
645 | + pcc->input_dev->getkeycode = pcc_getkeycode; | |
646 | + pcc->input_dev->setkeycode = pcc_setkeycode; | |
647 | + | |
648 | + /* load initial keymap */ | |
649 | + memcpy(pcc->keymap, initial_keymap, sizeof(pcc->keymap)); | |
650 | + | |
651 | + for (i = 0; i < ARRAY_SIZE(pcc->keymap); i++) | |
652 | + __set_bit(pcc->keymap[i], pcc->input_dev->keybit); | |
653 | + __clear_bit(KEY_RESERVED, pcc->input_dev->keybit); | |
654 | + | |
655 | + input_set_drvdata(pcc->input_dev, pcc); | |
656 | + | |
657 | + rc = input_register_device(pcc->input_dev); | |
658 | + if (rc < 0) | |
659 | + input_free_device(pcc->input_dev); | |
660 | + | |
661 | + return rc; | |
662 | +} | |
663 | + | |
664 | +/* kernel module interface */ | |
665 | + | |
666 | +static int acpi_pcc_hotkey_resume(struct acpi_device *device) | |
667 | +{ | |
668 | + struct pcc_acpi *pcc = acpi_driver_data(device); | |
669 | + acpi_status status = AE_OK; | |
670 | + | |
671 | + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_resume"); | |
672 | + | |
673 | + if (device == NULL || pcc == NULL) | |
674 | + return -EINVAL; | |
675 | + | |
676 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n", | |
677 | + pcc->sticky_mode)); | |
678 | + | |
679 | + status = acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode); | |
680 | + | |
681 | + return status == AE_OK ? 0 : -EINVAL; | |
682 | +} | |
683 | + | |
684 | +static int acpi_pcc_hotkey_add(struct acpi_device *device) | |
685 | +{ | |
686 | + acpi_status status; | |
687 | + struct pcc_acpi *pcc; | |
688 | + int num_sifr, result; | |
689 | + | |
690 | + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_add"); | |
691 | + | |
692 | + if (!device) | |
693 | + return -EINVAL; | |
694 | + | |
695 | + num_sifr = acpi_pcc_get_sqty(device); | |
696 | + | |
697 | + if (num_sifr > 255) { | |
698 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr too large")); | |
699 | + return -ENODEV; | |
700 | + } | |
701 | + | |
702 | + pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL); | |
703 | + if (!pcc) { | |
704 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
705 | + "Couldn't allocate mem for pcc")); | |
706 | + return -ENOMEM; | |
707 | + } | |
708 | + | |
709 | + pcc->sinf = kzalloc(sizeof(u32) * (num_sifr + 1), GFP_KERNEL); | |
710 | + if (!pcc->sinf) { | |
711 | + result = -ENOMEM; | |
712 | + goto out_hotkey; | |
713 | + } | |
714 | + | |
715 | + pcc->device = device; | |
716 | + pcc->handle = device->handle; | |
717 | + pcc->num_sifr = num_sifr; | |
718 | + acpi_driver_data(device) = pcc; | |
719 | + strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME); | |
720 | + strcpy(acpi_device_class(device), ACPI_PCC_CLASS); | |
721 | + | |
722 | + result = acpi_pcc_init_input(pcc); | |
723 | + if (result) { | |
724 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
725 | + "Error installing keyinput handler\n")); | |
726 | + goto out_sinf; | |
727 | + } | |
728 | + | |
729 | + /* initialize hotkey input device */ | |
730 | + status = acpi_install_notify_handler(pcc->handle, ACPI_DEVICE_NOTIFY, | |
731 | + acpi_pcc_hotkey_notify, pcc); | |
732 | + | |
733 | + if (ACPI_FAILURE(status)) { | |
734 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
735 | + "Error installing notify handler\n")); | |
736 | + result = -ENODEV; | |
737 | + goto out_input; | |
738 | + } | |
739 | + | |
740 | + /* initialize backlight */ | |
741 | + pcc->backlight = backlight_device_register("panasonic", NULL, pcc, | |
742 | + &pcc_backlight_ops); | |
743 | + if (IS_ERR(pcc->backlight)) | |
744 | + goto out_notify; | |
745 | + | |
746 | + if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) { | |
747 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
748 | + "Couldn't retrieve BIOS data\n")); | |
749 | + goto out_backlight; | |
750 | + } | |
751 | + | |
752 | + /* read the initial brightness setting from the hardware */ | |
753 | + pcc->backlight->props.max_brightness = | |
754 | + pcc->sinf[SINF_AC_MAX_BRIGHT]; | |
755 | + pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT]; | |
756 | + | |
757 | + /* read the initial sticky key mode from the hardware */ | |
758 | + pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY]; | |
759 | + | |
760 | + /* add sysfs attributes */ | |
761 | + result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group); | |
762 | + if (result) | |
763 | + goto out_backlight; | |
764 | + | |
765 | + return 0; | |
766 | + | |
767 | +out_backlight: | |
768 | + backlight_device_unregister(pcc->backlight); | |
769 | +out_notify: | |
770 | + acpi_remove_notify_handler(pcc->handle, ACPI_DEVICE_NOTIFY, | |
771 | + acpi_pcc_hotkey_notify); | |
772 | +out_input: | |
773 | + input_unregister_device(pcc->input_dev); | |
774 | + /* no need to input_free_device() since core input API refcount and | |
775 | + * free()s the device */ | |
776 | +out_sinf: | |
777 | + kfree(pcc->sinf); | |
778 | +out_hotkey: | |
779 | + kfree(pcc); | |
780 | + | |
781 | + return result; | |
782 | +} | |
783 | + | |
784 | +static int __init acpi_pcc_init(void) | |
785 | +{ | |
786 | + int result = 0; | |
787 | + | |
788 | + ACPI_FUNCTION_TRACE("acpi_pcc_init"); | |
789 | + | |
790 | + if (acpi_disabled) | |
791 | + return -ENODEV; | |
792 | + | |
793 | + result = acpi_bus_register_driver(&acpi_pcc_driver); | |
794 | + if (result < 0) { | |
795 | + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
796 | + "Error registering hotkey driver\n")); | |
797 | + return -ENODEV; | |
798 | + } | |
799 | + | |
800 | + return 0; | |
801 | +} | |
802 | + | |
803 | +static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type) | |
804 | +{ | |
805 | + struct pcc_acpi *pcc = acpi_driver_data(device); | |
806 | + | |
807 | + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_remove"); | |
808 | + | |
809 | + if (!device || !pcc) | |
810 | + return -EINVAL; | |
811 | + | |
812 | + sysfs_remove_group(&device->dev.kobj, &pcc_attr_group); | |
813 | + | |
814 | + backlight_device_unregister(pcc->backlight); | |
815 | + | |
816 | + acpi_remove_notify_handler(pcc->handle, ACPI_DEVICE_NOTIFY, | |
817 | + acpi_pcc_hotkey_notify); | |
818 | + | |
819 | + input_unregister_device(pcc->input_dev); | |
820 | + /* no need to input_free_device() since core input API refcount and | |
821 | + * free()s the device */ | |
822 | + | |
823 | + kfree(pcc->sinf); | |
824 | + kfree(pcc); | |
825 | + | |
826 | + return 0; | |
827 | +} | |
828 | + | |
829 | +static void __exit acpi_pcc_exit(void) | |
830 | +{ | |
831 | + ACPI_FUNCTION_TRACE("acpi_pcc_exit"); | |
832 | + | |
833 | + acpi_bus_unregister_driver(&acpi_pcc_driver); | |
834 | +} | |
835 | + | |
836 | +module_init(acpi_pcc_init); | |
837 | +module_exit(acpi_pcc_exit); | |
838 | Index: linux-2.6.27-sles11/MAINTAINERS | |
839 | =================================================================== | |
840 | --- linux-2.6.27-sles11.orig/MAINTAINERS | |
841 | +++ linux-2.6.27-sles11/MAINTAINERS | |
842 | @@ -3147,6 +3147,11 @@ M: olof@lixom.net | |
843 | L: linux-i2c@vger.kernel.org | |
844 | S: Maintained | |
845 | ||
846 | +PANASONIC LAPTOP ACPI EXTRAS DRIVER | |
847 | +P: Harald Welte | |
848 | +M: laforge@gnumonks.org | |
849 | +S: Maintained | |
850 | + | |
851 | PARALLEL PORT SUPPORT | |
852 | L: linux-parport@lists.infradead.org (subscribers-only) | |
853 | S: Orphan |