2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
10 * The SNY6001 driver part is based on the sonypi driver which includes
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
17 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/moduleparam.h>
48 #include <linux/init.h>
49 #include <linux/types.h>
50 #include <linux/backlight.h>
51 #include <linux/platform_device.h>
52 #include <linux/err.h>
53 #include <linux/dmi.h>
54 #include <linux/pci.h>
55 #include <linux/interrupt.h>
56 #include <linux/delay.h>
57 #include <linux/input.h>
58 #include <linux/kfifo.h>
59 #include <linux/workqueue.h>
60 #include <linux/acpi.h>
61 #include <acpi/acpi_drivers.h>
62 #include <acpi/acpi_bus.h>
63 #include <asm/uaccess.h>
64 #include <linux/sonypi.h>
65 #include <linux/sony-laptop.h>
66 #ifdef CONFIG_SONYPI_COMPAT
67 #include <linux/poll.h>
68 #include <linux/miscdevice.h>
71 #define DRV_PFX "sony-laptop: "
72 #define dprintk(msg...) do { \
73 if (debug) printk(KERN_WARNING DRV_PFX msg); \
76 #define SONY_LAPTOP_DRIVER_VERSION "0.5"
78 #define SONY_NC_CLASS "sony-nc"
79 #define SONY_NC_HID "SNY5001"
80 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
82 #define SONY_PIC_CLASS "sony-pic"
83 #define SONY_PIC_HID "SNY6001"
84 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
86 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
87 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
92 module_param(debug, int, 0);
93 MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
94 "the development of this driver");
96 static int no_spic; /* = 0 */
97 module_param(no_spic, int, 0444);
98 MODULE_PARM_DESC(no_spic,
99 "set this if you don't want to enable the SPIC device");
101 static int compat; /* = 0 */
102 module_param(compat, int, 0444);
103 MODULE_PARM_DESC(compat,
104 "set this if you want to enable backward compatibility mode");
106 static unsigned long mask = 0xffffffff;
107 module_param(mask, ulong, 0644);
108 MODULE_PARM_DESC(mask,
109 "set this to the mask of event you want to enable (see doc)");
111 static int camera; /* = 0 */
112 module_param(camera, int, 0444);
113 MODULE_PARM_DESC(camera,
114 "set this to 1 to enable Motion Eye camera controls "
115 "(only use it if you have a C1VE or C1VN model)");
117 #ifdef CONFIG_SONYPI_COMPAT
118 static int minor = -1;
119 module_param(minor, int, 0);
120 MODULE_PARM_DESC(minor,
121 "minor number of the misc device for the SPIC compatibility code, "
122 "default is -1 (automatic)");
125 /*********** Input Devices ***********/
127 #define SONY_LAPTOP_BUF_SIZE 128
128 struct sony_laptop_input_s {
130 struct input_dev *jog_dev;
131 struct input_dev *key_dev;
133 spinlock_t fifo_lock;
134 struct workqueue_struct *wq;
136 static struct sony_laptop_input_s sony_laptop_input = {
137 .users = ATOMIC_INIT(0),
140 struct sony_laptop_keypress {
141 struct input_dev *dev;
145 /* Correspondance table between sonypi events
146 * and input layer indexes in the keymap
148 static int sony_laptop_input_index[] = {
150 -1, /* SONYPI_EVENT_JOGDIAL_DOWN */
151 -1, /* SONYPI_EVENT_JOGDIAL_UP */
152 -1, /* SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
153 -1, /* SONYPI_EVENT_JOGDIAL_UP_PRESSED */
154 -1, /* SONYPI_EVENT_JOGDIAL_PRESSED */
155 -1, /* SONYPI_EVENT_JOGDIAL_RELEASED */
156 0, /* SONYPI_EVENT_CAPTURE_PRESSED */
157 1, /* SONYPI_EVENT_CAPTURE_RELEASED */
158 2, /* SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
159 3, /* SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
160 4, /* SONYPI_EVENT_FNKEY_ESC */
161 5, /* SONYPI_EVENT_FNKEY_F1 */
162 6, /* SONYPI_EVENT_FNKEY_F2 */
163 7, /* SONYPI_EVENT_FNKEY_F3 */
164 8, /* SONYPI_EVENT_FNKEY_F4 */
165 9, /* SONYPI_EVENT_FNKEY_F5 */
166 10, /* SONYPI_EVENT_FNKEY_F6 */
167 11, /* SONYPI_EVENT_FNKEY_F7 */
168 12, /* SONYPI_EVENT_FNKEY_F8 */
169 13, /* SONYPI_EVENT_FNKEY_F9 */
170 14, /* SONYPI_EVENT_FNKEY_F10 */
171 15, /* SONYPI_EVENT_FNKEY_F11 */
172 16, /* SONYPI_EVENT_FNKEY_F12 */
173 17, /* SONYPI_EVENT_FNKEY_1 */
174 18, /* SONYPI_EVENT_FNKEY_2 */
175 19, /* SONYPI_EVENT_FNKEY_D */
176 20, /* SONYPI_EVENT_FNKEY_E */
177 21, /* SONYPI_EVENT_FNKEY_F */
178 22, /* SONYPI_EVENT_FNKEY_S */
179 23, /* SONYPI_EVENT_FNKEY_B */
180 24, /* SONYPI_EVENT_BLUETOOTH_PRESSED */
181 25, /* SONYPI_EVENT_PKEY_P1 */
182 26, /* SONYPI_EVENT_PKEY_P2 */
183 27, /* SONYPI_EVENT_PKEY_P3 */
184 28, /* SONYPI_EVENT_BACK_PRESSED */
185 -1, /* SONYPI_EVENT_LID_CLOSED */
186 -1, /* SONYPI_EVENT_LID_OPENED */
187 29, /* SONYPI_EVENT_BLUETOOTH_ON */
188 30, /* SONYPI_EVENT_BLUETOOTH_OFF */
189 31, /* SONYPI_EVENT_HELP_PRESSED */
190 32, /* SONYPI_EVENT_FNKEY_ONLY */
191 33, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN */
192 34, /* SONYPI_EVENT_JOGDIAL_FAST_UP */
193 35, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
194 36, /* SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
195 37, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
196 38, /* SONYPI_EVENT_JOGDIAL_VFAST_UP */
197 39, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
198 40, /* SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
199 41, /* SONYPI_EVENT_ZOOM_PRESSED */
200 42, /* SONYPI_EVENT_THUMBPHRASE_PRESSED */
201 43, /* SONYPI_EVENT_MEYE_FACE */
202 44, /* SONYPI_EVENT_MEYE_OPPOSITE */
203 45, /* SONYPI_EVENT_MEMORYSTICK_INSERT */
204 46, /* SONYPI_EVENT_MEMORYSTICK_EJECT */
205 -1, /* SONYPI_EVENT_ANYBUTTON_RELEASED */
206 -1, /* SONYPI_EVENT_BATTERY_INSERT */
207 -1, /* SONYPI_EVENT_BATTERY_REMOVE */
208 -1, /* SONYPI_EVENT_FNKEY_RELEASED */
209 47, /* SONYPI_EVENT_WIRELESS_ON */
210 48, /* SONYPI_EVENT_WIRELESS_OFF */
213 static int sony_laptop_input_keycode_map[] = {
214 KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
215 KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
216 KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
217 KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
218 KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */
219 KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */
220 KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */
221 KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */
222 KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */
223 KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */
224 KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */
225 KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */
226 KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */
227 KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */
228 KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */
229 KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */
230 KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */
231 KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */
232 KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */
233 KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */
234 KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */
235 KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */
236 KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */
237 KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */
238 KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
239 KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */
240 KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */
241 KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */
242 KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */
243 KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
244 KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
245 KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */
246 KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */
247 KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
248 KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
249 KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
250 KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
251 KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
252 KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
253 KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
254 KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
255 KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
256 BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
257 KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */
258 KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
259 KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
260 KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
261 KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */
262 KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */
265 /* release buttons after a short delay if pressed */
266 static void do_sony_laptop_release_key(struct work_struct *work)
268 struct sony_laptop_keypress kp;
270 while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
271 sizeof(kp)) == sizeof(kp)) {
273 input_report_key(kp.dev, kp.key, 0);
277 static DECLARE_WORK(sony_laptop_release_key_work,
278 do_sony_laptop_release_key);
280 /* forward event to the input subsytem */
281 static void sony_laptop_report_input_event(u8 event)
283 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
284 struct input_dev *key_dev = sony_laptop_input.key_dev;
285 struct sony_laptop_keypress kp = { NULL };
287 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
288 /* Nothing, not all VAIOs generate this event */
295 case SONYPI_EVENT_JOGDIAL_UP:
296 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
297 input_report_rel(jog_dev, REL_WHEEL, 1);
301 case SONYPI_EVENT_JOGDIAL_DOWN:
302 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
303 input_report_rel(jog_dev, REL_WHEEL, -1);
308 case SONYPI_EVENT_JOGDIAL_PRESSED:
314 if (event > ARRAY_SIZE (sony_laptop_input_keycode_map)) {
315 dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
318 if (sony_laptop_input_index[event] != -1) {
319 kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]];
320 if (kp.key != KEY_UNKNOWN)
327 input_report_key(kp.dev, kp.key, 1);
328 /* we emit the scancode so we can always remap the key */
329 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
331 kfifo_put(sony_laptop_input.fifo,
332 (unsigned char *)&kp, sizeof(kp));
334 if (!work_pending(&sony_laptop_release_key_work))
335 queue_work(sony_laptop_input.wq,
336 &sony_laptop_release_key_work);
338 dprintk("unknown input event %.2x\n", event);
341 static int sony_laptop_setup_input(void)
343 struct input_dev *jog_dev;
344 struct input_dev *key_dev;
348 /* don't run again if already initialized */
349 if (atomic_add_return(1, &sony_laptop_input.users) > 1)
353 spin_lock_init(&sony_laptop_input.fifo_lock);
354 sony_laptop_input.fifo =
355 kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
356 &sony_laptop_input.fifo_lock);
357 if (IS_ERR(sony_laptop_input.fifo)) {
358 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
359 error = PTR_ERR(sony_laptop_input.fifo);
364 sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
365 if (!sony_laptop_input.wq) {
366 printk(KERN_ERR DRV_PFX
367 "Unabe to create workqueue.\n");
373 key_dev = input_allocate_device();
379 key_dev->name = "Sony Vaio Keys";
380 key_dev->id.bustype = BUS_ISA;
381 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
383 /* Initialize the Input Drivers: special keys */
384 set_bit(EV_KEY, key_dev->evbit);
385 set_bit(EV_MSC, key_dev->evbit);
386 set_bit(MSC_SCAN, key_dev->mscbit);
387 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
388 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
389 key_dev->keycode = &sony_laptop_input_keycode_map;
390 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) {
391 if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) {
392 set_bit(sony_laptop_input_keycode_map[i],
397 error = input_register_device(key_dev);
399 goto err_free_keydev;
401 sony_laptop_input.key_dev = key_dev;
404 jog_dev = input_allocate_device();
407 goto err_unregister_keydev;
410 jog_dev->name = "Sony Vaio Jogdial";
411 jog_dev->id.bustype = BUS_ISA;
412 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
414 jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
415 jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
416 jog_dev->relbit[0] = BIT(REL_WHEEL);
418 error = input_register_device(jog_dev);
420 goto err_free_jogdev;
422 sony_laptop_input.jog_dev = jog_dev;
427 input_free_device(jog_dev);
429 err_unregister_keydev:
430 input_unregister_device(key_dev);
431 /* to avoid kref underflow below at input_free_device */
435 input_free_device(key_dev);
438 destroy_workqueue(sony_laptop_input.wq);
441 kfifo_free(sony_laptop_input.fifo);
444 atomic_dec(&sony_laptop_input.users);
448 static void sony_laptop_remove_input(void)
450 /* cleanup only after the last user has gone */
451 if (!atomic_dec_and_test(&sony_laptop_input.users))
454 /* flush workqueue first */
455 flush_workqueue(sony_laptop_input.wq);
457 /* destroy input devs */
458 input_unregister_device(sony_laptop_input.key_dev);
459 sony_laptop_input.key_dev = NULL;
461 if (sony_laptop_input.jog_dev) {
462 input_unregister_device(sony_laptop_input.jog_dev);
463 sony_laptop_input.jog_dev = NULL;
466 destroy_workqueue(sony_laptop_input.wq);
467 kfifo_free(sony_laptop_input.fifo);
470 /*********** Platform Device ***********/
472 static atomic_t sony_pf_users = ATOMIC_INIT(0);
473 static struct platform_driver sony_pf_driver = {
475 .name = "sony-laptop",
476 .owner = THIS_MODULE,
479 static struct platform_device *sony_pf_device;
481 static int sony_pf_add(void)
485 /* don't run again if already initialized */
486 if (atomic_add_return(1, &sony_pf_users) > 1)
489 ret = platform_driver_register(&sony_pf_driver);
493 sony_pf_device = platform_device_alloc("sony-laptop", -1);
494 if (!sony_pf_device) {
496 goto out_platform_registered;
499 ret = platform_device_add(sony_pf_device);
501 goto out_platform_alloced;
505 out_platform_alloced:
506 platform_device_put(sony_pf_device);
507 sony_pf_device = NULL;
508 out_platform_registered:
509 platform_driver_unregister(&sony_pf_driver);
511 atomic_dec(&sony_pf_users);
515 static void sony_pf_remove(void)
517 /* deregister only after the last user has gone */
518 if (!atomic_dec_and_test(&sony_pf_users))
521 platform_device_del(sony_pf_device);
522 platform_device_put(sony_pf_device);
523 platform_driver_unregister(&sony_pf_driver);
526 /*********** SNC (SNY5001) Device ***********/
528 /* the device uses 1-based values, while the backlight subsystem uses
530 #define SONY_MAX_BRIGHTNESS 8
532 #define SNC_VALIDATE_IN 0
533 #define SNC_VALIDATE_OUT 1
535 static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
537 static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
538 const char *, size_t);
539 static int boolean_validate(const int, const int);
540 static int brightness_default_validate(const int, const int);
542 struct sony_nc_value {
543 char *name; /* name of the entry */
544 char **acpiget; /* names of the ACPI get function */
545 char **acpiset; /* names of the ACPI set function */
546 int (*validate)(const int, const int); /* input/output validation */
547 int value; /* current setting */
548 int valid; /* Has ever been set */
549 int debug; /* active only in debug mode ? */
550 struct device_attribute devattr; /* sysfs atribute */
553 #define SNC_HANDLE_NAMES(_name, _values...) \
554 static char *snc_##_name[] = { _values, NULL }
556 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
558 .name = __stringify(_name), \
559 .acpiget = _getters, \
560 .acpiset = _setters, \
561 .validate = _validate, \
563 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
566 #define SNC_HANDLE_NULL { .name = NULL }
568 SNC_HANDLE_NAMES(fnkey_get, "GHKE");
570 SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
571 SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
573 SNC_HANDLE_NAMES(cdpower_get, "GCDP");
574 SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
576 SNC_HANDLE_NAMES(audiopower_get, "GAZP");
577 SNC_HANDLE_NAMES(audiopower_set, "AZPW");
579 SNC_HANDLE_NAMES(lanpower_get, "GLNP");
580 SNC_HANDLE_NAMES(lanpower_set, "LNPW");
582 SNC_HANDLE_NAMES(lidstate_get, "GLID");
584 SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
585 SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
587 SNC_HANDLE_NAMES(gainbass_get, "GMGB");
588 SNC_HANDLE_NAMES(gainbass_set, "CMGB");
590 SNC_HANDLE_NAMES(PID_get, "GPID");
592 SNC_HANDLE_NAMES(CTR_get, "GCTR");
593 SNC_HANDLE_NAMES(CTR_set, "SCTR");
595 SNC_HANDLE_NAMES(PCR_get, "GPCR");
596 SNC_HANDLE_NAMES(PCR_set, "SPCR");
598 SNC_HANDLE_NAMES(CMI_get, "GCMI");
599 SNC_HANDLE_NAMES(CMI_set, "SCMI");
601 static struct sony_nc_value sony_nc_values[] = {
602 SNC_HANDLE(brightness_default, snc_brightness_def_get,
603 snc_brightness_def_set, brightness_default_validate, 0),
604 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
605 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
606 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
607 boolean_validate, 0),
608 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
609 boolean_validate, 1),
610 SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
611 boolean_validate, 0),
612 SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
613 boolean_validate, 0),
614 SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
615 boolean_validate, 0),
616 /* unknown methods */
617 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
618 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
619 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
620 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
624 static acpi_handle sony_nc_acpi_handle;
625 static struct acpi_device *sony_nc_acpi_device = NULL;
628 * acpi_evaluate_object wrappers
630 static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
632 struct acpi_buffer output;
633 union acpi_object out_obj;
636 output.length = sizeof(out_obj);
637 output.pointer = &out_obj;
639 status = acpi_evaluate_object(handle, name, NULL, &output);
640 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
641 *result = out_obj.integer.value;
645 printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
650 static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
653 struct acpi_object_list params;
654 union acpi_object in_obj;
655 struct acpi_buffer output;
656 union acpi_object out_obj;
660 params.pointer = &in_obj;
661 in_obj.type = ACPI_TYPE_INTEGER;
662 in_obj.integer.value = value;
664 output.length = sizeof(out_obj);
665 output.pointer = &out_obj;
667 status = acpi_evaluate_object(handle, name, ¶ms, &output);
668 if (status == AE_OK) {
669 if (result != NULL) {
670 if (out_obj.type != ACPI_TYPE_INTEGER) {
671 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
675 *result = out_obj.integer.value;
680 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
686 * sony_nc_values input/output validate functions
689 /* brightness_default_validate:
691 * manipulate input output values to keep consistency with the
692 * backlight framework for which brightness values are 0-based.
694 static int brightness_default_validate(const int direction, const int value)
697 case SNC_VALIDATE_OUT:
699 case SNC_VALIDATE_IN:
700 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
708 * on input validate boolean values 0/1, on output just pass the
711 static int boolean_validate(const int direction, const int value)
713 if (direction == SNC_VALIDATE_IN) {
714 if (value != 0 && value != 1)
721 * Sysfs show/store common to all sony_nc_values
723 static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
727 struct sony_nc_value *item =
728 container_of(attr, struct sony_nc_value, devattr);
733 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
737 value = item->validate(SNC_VALIDATE_OUT, value);
739 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
742 static ssize_t sony_nc_sysfs_store(struct device *dev,
743 struct device_attribute *attr,
744 const char *buffer, size_t count)
747 struct sony_nc_value *item =
748 container_of(attr, struct sony_nc_value, devattr);
756 value = simple_strtoul(buffer, NULL, 10);
759 value = item->validate(SNC_VALIDATE_IN, value);
764 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
775 static int sony_backlight_update_status(struct backlight_device *bd)
777 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
778 bd->props.brightness + 1, NULL);
781 static int sony_backlight_get_brightness(struct backlight_device *bd)
785 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
787 /* brightness levels are 1-based, while backlight ones are 0-based */
791 static struct backlight_device *sony_backlight_device;
792 static struct backlight_ops sony_backlight_ops = {
793 .update_status = sony_backlight_update_status,
794 .get_brightness = sony_backlight_get_brightness,
798 * New SNC-only Vaios event mapping to driver known keys
800 struct sony_nc_event {
805 static struct sony_nc_event *sony_nc_events;
807 /* Vaio C* --maybe also FE*, N* and AR* ?-- special init sequence
810 static int sony_nc_C_enable(struct dmi_system_id *id)
814 printk(KERN_NOTICE DRV_PFX "detected %s\n", id->ident);
816 sony_nc_events = id->driver_data;
818 if (acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x4, &result) < 0
819 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x2, &result) < 0
820 || acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x10, &result) < 0
821 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x0, &result) < 0
822 || acpi_callsetfunc(sony_nc_acpi_handle, "SN03", 0x2, &result) < 0
823 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x101, &result) < 0) {
824 printk(KERN_WARNING DRV_PFX "failed to initialize SNC, some "
825 "functionalities may be missing\n");
831 static struct sony_nc_event sony_C_events[] = {
832 { 0x81, SONYPI_EVENT_FNKEY_F1 },
833 { 0x01, SONYPI_EVENT_FNKEY_RELEASED },
834 { 0x85, SONYPI_EVENT_FNKEY_F5 },
835 { 0x05, SONYPI_EVENT_FNKEY_RELEASED },
836 { 0x86, SONYPI_EVENT_FNKEY_F6 },
837 { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
838 { 0x87, SONYPI_EVENT_FNKEY_F7 },
839 { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
840 { 0x8A, SONYPI_EVENT_FNKEY_F10 },
841 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
842 { 0x8C, SONYPI_EVENT_FNKEY_F12 },
843 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
847 /* SNC-only model map */
848 struct dmi_system_id sony_nc_ids[] = {
850 .ident = "Sony Vaio C Series",
851 .callback = sony_nc_C_enable,
852 .driver_data = sony_C_events,
854 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
855 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"),
864 static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
866 struct sony_nc_event *evmap;
871 /* read the key pressed from EC.GECR
872 * A call to SN07 with 0x0202 will do it as well respecting
873 * the current protocol on different OSes
875 * Note: the path for GECR may be
876 * \_SB.PCI0.LPCB.EC (C, FE, AR, N and friends)
877 * \_SB.PCI0.PIB.EC0 (VGN-FR notifications are sent directly, no GECR)
879 * TODO: we may want to do the same for the older GHKE -need
880 * dmi list- so this snippet may become one more callback.
882 if (acpi_callsetfunc(handle, "SN07", 0x0202, &result) < 0)
883 dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev);
889 for (evmap = sony_nc_events; evmap->event; evmap++) {
890 if (evmap->data == ev) {
896 dprintk("sony_acpi_notify, event: 0x%.2x\n", ev);
897 sony_laptop_report_input_event(ev);
898 acpi_bus_generate_event(sony_nc_acpi_device, 1, ev);
901 static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
902 void *context, void **return_value)
904 struct acpi_namespace_node *node;
905 union acpi_operand_object *operand;
907 node = (struct acpi_namespace_node *)handle;
908 operand = (union acpi_operand_object *)node->object;
910 printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
911 (u32) operand->method.param_count);
919 static int sony_nc_resume(struct acpi_device *device)
921 struct sony_nc_value *item;
923 for (item = sony_nc_values; item->name; item++) {
928 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
931 printk("%s: %d\n", __FUNCTION__, ret);
936 /* re-initialize models with specific requirements */
937 dmi_check_system(sony_nc_ids);
942 static int sony_nc_add(struct acpi_device *device)
947 struct sony_nc_value *item;
949 printk(KERN_INFO DRV_PFX "%s v%s.\n",
950 SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
952 sony_nc_acpi_device = device;
953 strcpy(acpi_device_class(device), "sony/hotkey");
955 sony_nc_acpi_handle = device->handle;
957 /* read device status */
958 result = acpi_bus_get_status(device);
959 /* bail IFF the above call was successful and the device is not present */
960 if (!result && !device->status.present) {
961 dprintk("Device not present\n");
967 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
968 1, sony_walk_callback, NULL, NULL);
969 if (ACPI_FAILURE(status)) {
970 printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
976 /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1
977 * should be respected as we already checked for the device presence above */
978 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) {
979 dprintk("Invoking _INI\n");
980 if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI,
982 dprintk("_INI Method failed\n");
985 /* setup input devices and helper fifo */
986 result = sony_laptop_setup_input();
988 printk(KERN_ERR DRV_PFX
989 "Unabe to create input devices.\n");
993 status = acpi_install_notify_handler(sony_nc_acpi_handle,
995 sony_acpi_notify, NULL);
996 if (ACPI_FAILURE(status)) {
997 printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status);
1002 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", &handle))) {
1003 sony_backlight_device = backlight_device_register("sony", NULL,
1005 &sony_backlight_ops);
1007 if (IS_ERR(sony_backlight_device)) {
1008 printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
1009 sony_backlight_device = NULL;
1011 sony_backlight_device->props.brightness =
1012 sony_backlight_get_brightness
1013 (sony_backlight_device);
1014 sony_backlight_device->props.max_brightness =
1015 SONY_MAX_BRIGHTNESS - 1;
1020 /* initialize models with specific requirements */
1021 dmi_check_system(sony_nc_ids);
1023 result = sony_pf_add();
1027 /* create sony_pf sysfs attributes related to the SNC device */
1028 for (item = sony_nc_values; item->name; ++item) {
1030 if (!debug && item->debug)
1033 /* find the available acpiget as described in the DSDT */
1034 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
1035 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1038 dprintk("Found %s getter: %s\n",
1039 item->name, *item->acpiget);
1040 item->devattr.attr.mode |= S_IRUGO;
1045 /* find the available acpiset as described in the DSDT */
1046 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
1047 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1050 dprintk("Found %s setter: %s\n",
1051 item->name, *item->acpiset);
1052 item->devattr.attr.mode |= S_IWUSR;
1057 if (item->devattr.attr.mode != 0) {
1059 device_create_file(&sony_pf_device->dev,
1069 for (item = sony_nc_values; item->name; ++item) {
1070 device_remove_file(&sony_pf_device->dev, &item->devattr);
1075 if (sony_backlight_device)
1076 backlight_device_unregister(sony_backlight_device);
1078 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
1081 if (ACPI_FAILURE(status))
1082 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
1085 sony_laptop_remove_input();
1091 static int sony_nc_remove(struct acpi_device *device, int type)
1094 struct sony_nc_value *item;
1096 if (sony_backlight_device)
1097 backlight_device_unregister(sony_backlight_device);
1099 sony_nc_acpi_device = NULL;
1101 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
1104 if (ACPI_FAILURE(status))
1105 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
1107 for (item = sony_nc_values; item->name; ++item) {
1108 device_remove_file(&sony_pf_device->dev, &item->devattr);
1112 sony_laptop_remove_input();
1113 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
1118 static struct acpi_driver sony_nc_driver = {
1119 .name = SONY_NC_DRIVER_NAME,
1120 .class = SONY_NC_CLASS,
1122 .owner = THIS_MODULE,
1125 .remove = sony_nc_remove,
1126 .resume = sony_nc_resume,
1130 /*********** SPIC (SNY6001) Device ***********/
1132 #define SONYPI_DEVICE_TYPE1 0x00000001
1133 #define SONYPI_DEVICE_TYPE2 0x00000002
1134 #define SONYPI_DEVICE_TYPE3 0x00000004
1136 #define SONY_PIC_EV_MASK 0xff
1138 struct sony_pic_ioport {
1139 struct acpi_resource_io io;
1140 struct list_head list;
1143 struct sony_pic_irq {
1144 struct acpi_resource_irq irq;
1145 struct list_head list;
1148 struct sony_pic_dev {
1153 struct acpi_device *acpi_dev;
1154 struct sony_pic_irq *cur_irq;
1155 struct sony_pic_ioport *cur_ioport;
1156 struct list_head interrupts;
1157 struct list_head ioports;
1161 static struct sony_pic_dev spic_dev = {
1162 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
1163 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
1167 #define SONYPI_JOGGER_MASK 0x00000001
1168 #define SONYPI_CAPTURE_MASK 0x00000002
1169 #define SONYPI_FNKEY_MASK 0x00000004
1170 #define SONYPI_BLUETOOTH_MASK 0x00000008
1171 #define SONYPI_PKEY_MASK 0x00000010
1172 #define SONYPI_BACK_MASK 0x00000020
1173 #define SONYPI_HELP_MASK 0x00000040
1174 #define SONYPI_LID_MASK 0x00000080
1175 #define SONYPI_ZOOM_MASK 0x00000100
1176 #define SONYPI_THUMBPHRASE_MASK 0x00000200
1177 #define SONYPI_MEYE_MASK 0x00000400
1178 #define SONYPI_MEMORYSTICK_MASK 0x00000800
1179 #define SONYPI_BATTERY_MASK 0x00001000
1180 #define SONYPI_WIRELESS_MASK 0x00002000
1182 struct sonypi_event {
1187 /* The set of possible button release events */
1188 static struct sonypi_event sonypi_releaseev[] = {
1189 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
1193 /* The set of possible jogger events */
1194 static struct sonypi_event sonypi_joggerev[] = {
1195 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
1196 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
1197 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
1198 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
1199 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
1200 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
1201 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
1202 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
1203 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
1204 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
1205 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
1206 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
1207 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
1211 /* The set of possible capture button events */
1212 static struct sonypi_event sonypi_captureev[] = {
1213 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
1214 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
1215 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
1219 /* The set of possible fnkeys events */
1220 static struct sonypi_event sonypi_fnkeyev[] = {
1221 { 0x10, SONYPI_EVENT_FNKEY_ESC },
1222 { 0x11, SONYPI_EVENT_FNKEY_F1 },
1223 { 0x12, SONYPI_EVENT_FNKEY_F2 },
1224 { 0x13, SONYPI_EVENT_FNKEY_F3 },
1225 { 0x14, SONYPI_EVENT_FNKEY_F4 },
1226 { 0x15, SONYPI_EVENT_FNKEY_F5 },
1227 { 0x16, SONYPI_EVENT_FNKEY_F6 },
1228 { 0x17, SONYPI_EVENT_FNKEY_F7 },
1229 { 0x18, SONYPI_EVENT_FNKEY_F8 },
1230 { 0x19, SONYPI_EVENT_FNKEY_F9 },
1231 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
1232 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
1233 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
1234 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
1235 { 0x21, SONYPI_EVENT_FNKEY_1 },
1236 { 0x22, SONYPI_EVENT_FNKEY_2 },
1237 { 0x31, SONYPI_EVENT_FNKEY_D },
1238 { 0x32, SONYPI_EVENT_FNKEY_E },
1239 { 0x33, SONYPI_EVENT_FNKEY_F },
1240 { 0x34, SONYPI_EVENT_FNKEY_S },
1241 { 0x35, SONYPI_EVENT_FNKEY_B },
1242 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
1246 /* The set of possible program key events */
1247 static struct sonypi_event sonypi_pkeyev[] = {
1248 { 0x01, SONYPI_EVENT_PKEY_P1 },
1249 { 0x02, SONYPI_EVENT_PKEY_P2 },
1250 { 0x04, SONYPI_EVENT_PKEY_P3 },
1251 { 0x5c, SONYPI_EVENT_PKEY_P1 },
1255 /* The set of possible bluetooth events */
1256 static struct sonypi_event sonypi_blueev[] = {
1257 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
1258 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
1259 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
1263 /* The set of possible wireless events */
1264 static struct sonypi_event sonypi_wlessev[] = {
1265 { 0x59, SONYPI_EVENT_WIRELESS_ON },
1266 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
1270 /* The set of possible back button events */
1271 static struct sonypi_event sonypi_backev[] = {
1272 { 0x20, SONYPI_EVENT_BACK_PRESSED },
1276 /* The set of possible help button events */
1277 static struct sonypi_event sonypi_helpev[] = {
1278 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
1283 /* The set of possible lid events */
1284 static struct sonypi_event sonypi_lidev[] = {
1285 { 0x51, SONYPI_EVENT_LID_CLOSED },
1286 { 0x50, SONYPI_EVENT_LID_OPENED },
1290 /* The set of possible zoom events */
1291 static struct sonypi_event sonypi_zoomev[] = {
1292 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
1296 /* The set of possible thumbphrase events */
1297 static struct sonypi_event sonypi_thumbphraseev[] = {
1298 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
1302 /* The set of possible motioneye camera events */
1303 static struct sonypi_event sonypi_meyeev[] = {
1304 { 0x00, SONYPI_EVENT_MEYE_FACE },
1305 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
1309 /* The set of possible memorystick events */
1310 static struct sonypi_event sonypi_memorystickev[] = {
1311 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
1312 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
1316 /* The set of possible battery events */
1317 static struct sonypi_event sonypi_batteryev[] = {
1318 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
1319 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
1323 static struct sonypi_eventtypes {
1327 struct sonypi_event * events;
1328 } sony_pic_eventtypes[] = {
1329 { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
1330 { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
1331 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
1332 { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
1333 { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
1334 { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1335 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1336 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
1337 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1338 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
1340 { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
1341 { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
1342 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
1343 { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
1344 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1345 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1346 { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
1347 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
1348 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
1349 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
1350 { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
1351 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1352 { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1353 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1355 { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
1356 { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1357 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
1358 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1359 { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1360 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1364 static int sony_pic_detect_device_type(void)
1366 struct pci_dev *pcidev;
1369 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1370 PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
1371 model = SONYPI_DEVICE_TYPE1;
1373 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1374 PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
1375 model = SONYPI_DEVICE_TYPE3;
1377 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1378 PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
1379 model = SONYPI_DEVICE_TYPE3;
1382 model = SONYPI_DEVICE_TYPE2;
1385 pci_dev_put(pcidev);
1387 printk(KERN_INFO DRV_PFX "detected Type%d model\n",
1388 model == SONYPI_DEVICE_TYPE1 ? 1 :
1389 model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
1393 #define ITERATIONS_LONG 10000
1394 #define ITERATIONS_SHORT 10
1395 #define wait_on_command(command, iterations) { \
1396 unsigned int n = iterations; \
1397 while (--n && (command)) \
1400 dprintk("command failed at %s : %s (line %d)\n", \
1401 __FILE__, __FUNCTION__, __LINE__); \
1404 static u8 sony_pic_call1(u8 dev)
1408 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1410 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1411 v1 = inb_p(spic_dev.cur_ioport->io.minimum + 4);
1412 v2 = inb_p(spic_dev.cur_ioport->io.minimum);
1413 dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
1417 static u8 sony_pic_call2(u8 dev, u8 fn)
1421 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1423 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1424 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1426 outb(fn, spic_dev.cur_ioport->io.minimum);
1427 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1428 dprintk("sony_pic_call2: 0x%.4x\n", v1);
1432 static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
1436 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1437 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1438 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1439 outb(fn, spic_dev.cur_ioport->io.minimum);
1440 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1441 outb(v, spic_dev.cur_ioport->io.minimum);
1442 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1443 dprintk("sony_pic_call3: 0x%.4x\n", v1);
1447 /* camera tests and poweron/poweroff */
1448 #define SONYPI_CAMERA_PICTURE 5
1449 #define SONYPI_CAMERA_CONTROL 0x10
1451 #define SONYPI_CAMERA_BRIGHTNESS 0
1452 #define SONYPI_CAMERA_CONTRAST 1
1453 #define SONYPI_CAMERA_HUE 2
1454 #define SONYPI_CAMERA_COLOR 3
1455 #define SONYPI_CAMERA_SHARPNESS 4
1457 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1458 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1459 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1460 #define SONYPI_CAMERA_MUTE_MASK 0x40
1462 /* the rest don't need a loop until not 0xff */
1463 #define SONYPI_CAMERA_AGC 6
1464 #define SONYPI_CAMERA_AGC_MASK 0x30
1465 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
1467 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1468 #define SONYPI_CAMERA_CONTROL 0x10
1470 #define SONYPI_CAMERA_STATUS 7
1471 #define SONYPI_CAMERA_STATUS_READY 0x2
1472 #define SONYPI_CAMERA_STATUS_POSITION 0x4
1474 #define SONYPI_DIRECTION_BACKWARDS 0x4
1476 #define SONYPI_CAMERA_REVISION 8
1477 #define SONYPI_CAMERA_ROMVERSION 9
1479 static int __sony_pic_camera_ready(void)
1483 v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
1484 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
1487 static int __sony_pic_camera_off(void)
1490 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1494 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
1495 SONYPI_CAMERA_MUTE_MASK),
1498 if (spic_dev.camera_power) {
1499 sony_pic_call2(0x91, 0);
1500 spic_dev.camera_power = 0;
1505 static int __sony_pic_camera_on(void)
1510 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1514 if (spic_dev.camera_power)
1517 for (j = 5; j > 0; j--) {
1519 for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
1521 sony_pic_call1(0x93);
1523 for (i = 400; i > 0; i--) {
1524 if (__sony_pic_camera_ready())
1533 printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
1537 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
1541 spic_dev.camera_power = 1;
1545 /* External camera command (exported to the motion eye v4l driver) */
1546 int sony_pic_camera_command(int command, u8 value)
1551 mutex_lock(&spic_dev.lock);
1554 case SONY_PIC_COMMAND_SETCAMERA:
1556 __sony_pic_camera_on();
1558 __sony_pic_camera_off();
1560 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
1561 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
1564 case SONY_PIC_COMMAND_SETCAMERACONTRAST:
1565 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
1568 case SONY_PIC_COMMAND_SETCAMERAHUE:
1569 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
1572 case SONY_PIC_COMMAND_SETCAMERACOLOR:
1573 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
1576 case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
1577 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
1580 case SONY_PIC_COMMAND_SETCAMERAPICTURE:
1581 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
1584 case SONY_PIC_COMMAND_SETCAMERAAGC:
1585 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
1589 printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
1593 mutex_unlock(&spic_dev.lock);
1596 EXPORT_SYMBOL(sony_pic_camera_command);
1598 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
1599 static void sony_pic_set_wwanpower(u8 state)
1602 mutex_lock(&spic_dev.lock);
1603 if (spic_dev.wwan_power == state) {
1604 mutex_unlock(&spic_dev.lock);
1607 sony_pic_call2(0xB0, state);
1608 spic_dev.wwan_power = state;
1609 mutex_unlock(&spic_dev.lock);
1612 static ssize_t sony_pic_wwanpower_store(struct device *dev,
1613 struct device_attribute *attr,
1614 const char *buffer, size_t count)
1616 unsigned long value;
1620 value = simple_strtoul(buffer, NULL, 10);
1621 sony_pic_set_wwanpower(value);
1626 static ssize_t sony_pic_wwanpower_show(struct device *dev,
1627 struct device_attribute *attr, char *buffer)
1630 mutex_lock(&spic_dev.lock);
1631 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
1632 mutex_unlock(&spic_dev.lock);
1636 /* bluetooth subsystem power state */
1637 static void __sony_pic_set_bluetoothpower(u8 state)
1640 if (spic_dev.bluetooth_power == state)
1642 sony_pic_call2(0x96, state);
1643 sony_pic_call1(0x82);
1644 spic_dev.bluetooth_power = state;
1647 static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
1648 struct device_attribute *attr,
1649 const char *buffer, size_t count)
1651 unsigned long value;
1655 value = simple_strtoul(buffer, NULL, 10);
1656 mutex_lock(&spic_dev.lock);
1657 __sony_pic_set_bluetoothpower(value);
1658 mutex_unlock(&spic_dev.lock);
1663 static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
1664 struct device_attribute *attr, char *buffer)
1667 mutex_lock(&spic_dev.lock);
1668 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
1669 mutex_unlock(&spic_dev.lock);
1674 /* FAN0 information (reverse engineered from ACPI tables) */
1675 #define SONY_PIC_FAN0_STATUS 0x93
1676 static int sony_pic_set_fanspeed(unsigned long value)
1678 return ec_write(SONY_PIC_FAN0_STATUS, value);
1681 static int sony_pic_get_fanspeed(u8 *value)
1683 return ec_read(SONY_PIC_FAN0_STATUS, value);
1686 static ssize_t sony_pic_fanspeed_store(struct device *dev,
1687 struct device_attribute *attr,
1688 const char *buffer, size_t count)
1690 unsigned long value;
1694 value = simple_strtoul(buffer, NULL, 10);
1695 if (sony_pic_set_fanspeed(value))
1701 static ssize_t sony_pic_fanspeed_show(struct device *dev,
1702 struct device_attribute *attr, char *buffer)
1705 if (sony_pic_get_fanspeed(&value))
1708 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
1711 #define SPIC_ATTR(_name, _mode) \
1712 struct device_attribute spic_attr_##_name = __ATTR(_name, \
1713 _mode, sony_pic_## _name ##_show, \
1714 sony_pic_## _name ##_store)
1716 static SPIC_ATTR(bluetoothpower, 0644);
1717 static SPIC_ATTR(wwanpower, 0644);
1718 static SPIC_ATTR(fanspeed, 0644);
1720 static struct attribute *spic_attributes[] = {
1721 &spic_attr_bluetoothpower.attr,
1722 &spic_attr_wwanpower.attr,
1723 &spic_attr_fanspeed.attr,
1727 static struct attribute_group spic_attribute_group = {
1728 .attrs = spic_attributes
1731 /******** SONYPI compatibility **********/
1732 #ifdef CONFIG_SONYPI_COMPAT
1734 /* battery / brightness / temperature addresses */
1735 #define SONYPI_BAT_FLAGS 0x81
1736 #define SONYPI_LCD_LIGHT 0x96
1737 #define SONYPI_BAT1_PCTRM 0xa0
1738 #define SONYPI_BAT1_LEFT 0xa2
1739 #define SONYPI_BAT1_MAXRT 0xa4
1740 #define SONYPI_BAT2_PCTRM 0xa8
1741 #define SONYPI_BAT2_LEFT 0xaa
1742 #define SONYPI_BAT2_MAXRT 0xac
1743 #define SONYPI_BAT1_MAXTK 0xb0
1744 #define SONYPI_BAT1_FULL 0xb2
1745 #define SONYPI_BAT2_MAXTK 0xb8
1746 #define SONYPI_BAT2_FULL 0xba
1747 #define SONYPI_TEMP_STATUS 0xC1
1749 struct sonypi_compat_s {
1750 struct fasync_struct *fifo_async;
1752 spinlock_t fifo_lock;
1753 wait_queue_head_t fifo_proc_list;
1754 atomic_t open_count;
1756 static struct sonypi_compat_s sonypi_compat = {
1757 .open_count = ATOMIC_INIT(0),
1760 static int sonypi_misc_fasync(int fd, struct file *filp, int on)
1764 retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
1770 static int sonypi_misc_release(struct inode *inode, struct file *file)
1772 sonypi_misc_fasync(-1, file, 0);
1773 atomic_dec(&sonypi_compat.open_count);
1777 static int sonypi_misc_open(struct inode *inode, struct file *file)
1779 /* Flush input queue on first open */
1780 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
1781 kfifo_reset(sonypi_compat.fifo);
1785 static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
1786 size_t count, loff_t *pos)
1791 if ((kfifo_len(sonypi_compat.fifo) == 0) &&
1792 (file->f_flags & O_NONBLOCK))
1795 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
1796 kfifo_len(sonypi_compat.fifo) != 0);
1800 while (ret < count &&
1801 (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
1802 if (put_user(c, buf++))
1808 struct inode *inode = file->f_path.dentry->d_inode;
1809 inode->i_atime = current_fs_time(inode->i_sb);
1815 static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
1817 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
1818 if (kfifo_len(sonypi_compat.fifo))
1819 return POLLIN | POLLRDNORM;
1823 static int ec_read16(u8 addr, u16 *value)
1826 if (ec_read(addr, &val_lb))
1828 if (ec_read(addr + 1, &val_hb))
1830 *value = val_lb | (val_hb << 8);
1834 static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1835 unsigned int cmd, unsigned long arg)
1838 void __user *argp = (void __user *)arg;
1843 mutex_lock(&spic_dev.lock);
1845 case SONYPI_IOCGBRT:
1846 if (sony_backlight_device == NULL) {
1850 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
1854 val8 = ((value & 0xff) - 1) << 5;
1855 if (copy_to_user(argp, &val8, sizeof(val8)))
1858 case SONYPI_IOCSBRT:
1859 if (sony_backlight_device == NULL) {
1863 if (copy_from_user(&val8, argp, sizeof(val8))) {
1867 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
1868 (val8 >> 5) + 1, NULL)) {
1872 /* sync the backlight device status */
1873 sony_backlight_device->props.brightness =
1874 sony_backlight_get_brightness(sony_backlight_device);
1876 case SONYPI_IOCGBAT1CAP:
1877 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
1881 if (copy_to_user(argp, &val16, sizeof(val16)))
1884 case SONYPI_IOCGBAT1REM:
1885 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
1889 if (copy_to_user(argp, &val16, sizeof(val16)))
1892 case SONYPI_IOCGBAT2CAP:
1893 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
1897 if (copy_to_user(argp, &val16, sizeof(val16)))
1900 case SONYPI_IOCGBAT2REM:
1901 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
1905 if (copy_to_user(argp, &val16, sizeof(val16)))
1908 case SONYPI_IOCGBATFLAGS:
1909 if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
1914 if (copy_to_user(argp, &val8, sizeof(val8)))
1917 case SONYPI_IOCGBLUE:
1918 val8 = spic_dev.bluetooth_power;
1919 if (copy_to_user(argp, &val8, sizeof(val8)))
1922 case SONYPI_IOCSBLUE:
1923 if (copy_from_user(&val8, argp, sizeof(val8))) {
1927 __sony_pic_set_bluetoothpower(val8);
1930 case SONYPI_IOCGFAN:
1931 if (sony_pic_get_fanspeed(&val8)) {
1935 if (copy_to_user(argp, &val8, sizeof(val8)))
1938 case SONYPI_IOCSFAN:
1939 if (copy_from_user(&val8, argp, sizeof(val8))) {
1943 if (sony_pic_set_fanspeed(val8))
1946 /* GET Temperature (useful under APM) */
1947 case SONYPI_IOCGTEMP:
1948 if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
1952 if (copy_to_user(argp, &val8, sizeof(val8)))
1958 mutex_unlock(&spic_dev.lock);
1962 static const struct file_operations sonypi_misc_fops = {
1963 .owner = THIS_MODULE,
1964 .read = sonypi_misc_read,
1965 .poll = sonypi_misc_poll,
1966 .open = sonypi_misc_open,
1967 .release = sonypi_misc_release,
1968 .fasync = sonypi_misc_fasync,
1969 .ioctl = sonypi_misc_ioctl,
1972 static struct miscdevice sonypi_misc_device = {
1973 .minor = MISC_DYNAMIC_MINOR,
1975 .fops = &sonypi_misc_fops,
1978 static void sonypi_compat_report_event(u8 event)
1980 kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
1981 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
1982 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
1985 static int sonypi_compat_init(void)
1989 spin_lock_init(&sonypi_compat.fifo_lock);
1990 sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
1991 &sonypi_compat.fifo_lock);
1992 if (IS_ERR(sonypi_compat.fifo)) {
1993 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
1994 return PTR_ERR(sonypi_compat.fifo);
1997 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
2000 sonypi_misc_device.minor = minor;
2001 error = misc_register(&sonypi_misc_device);
2003 printk(KERN_ERR DRV_PFX "misc_register failed\n");
2004 goto err_free_kfifo;
2007 printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
2008 sonypi_misc_device.minor);
2013 kfifo_free(sonypi_compat.fifo);
2017 static void sonypi_compat_exit(void)
2019 misc_deregister(&sonypi_misc_device);
2020 kfifo_free(sonypi_compat.fifo);
2023 static int sonypi_compat_init(void) { return 0; }
2024 static void sonypi_compat_exit(void) { }
2025 static void sonypi_compat_report_event(u8 event) { }
2026 #endif /* CONFIG_SONYPI_COMPAT */
2032 sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
2035 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
2037 switch (resource->type) {
2038 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
2039 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
2042 case ACPI_RESOURCE_TYPE_IRQ:
2044 struct acpi_resource_irq *p = &resource->data.irq;
2045 struct sony_pic_irq *interrupt = NULL;
2046 if (!p || !p->interrupt_count) {
2048 * IRQ descriptors may have no IRQ# bits set,
2049 * particularly those those w/ _STA disabled
2051 dprintk("Blank IRQ resource\n");
2054 for (i = 0; i < p->interrupt_count; i++) {
2055 if (!p->interrupts[i]) {
2056 printk(KERN_WARNING DRV_PFX
2061 interrupt = kzalloc(sizeof(*interrupt),
2066 list_add_tail(&interrupt->list, &dev->interrupts);
2067 interrupt->irq.triggering = p->triggering;
2068 interrupt->irq.polarity = p->polarity;
2069 interrupt->irq.sharable = p->sharable;
2070 interrupt->irq.interrupt_count = 1;
2071 interrupt->irq.interrupts[0] = p->interrupts[i];
2075 case ACPI_RESOURCE_TYPE_IO:
2077 struct acpi_resource_io *io = &resource->data.io;
2078 struct sony_pic_ioport *ioport = NULL;
2080 dprintk("Blank IO resource\n");
2084 ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
2088 list_add_tail(&ioport->list, &dev->ioports);
2089 memcpy(&ioport->io, io, sizeof(*io));
2093 dprintk("Resource %d isn't an IRQ nor an IO port\n",
2096 case ACPI_RESOURCE_TYPE_END_TAG:
2099 return AE_CTRL_TERMINATE;
2102 static int sony_pic_possible_resources(struct acpi_device *device)
2105 acpi_status status = AE_OK;
2110 /* get device status */
2111 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
2112 dprintk("Evaluating _STA\n");
2113 result = acpi_bus_get_status(device);
2115 printk(KERN_WARNING DRV_PFX "Unable to read status\n");
2119 if (!device->status.enabled)
2120 dprintk("Device disabled\n");
2122 dprintk("Device enabled\n");
2125 * Query and parse 'method'
2127 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
2128 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
2129 sony_pic_read_possible_resource, &spic_dev);
2130 if (ACPI_FAILURE(status)) {
2131 printk(KERN_WARNING DRV_PFX
2132 "Failure evaluating %s\n",
2141 * Disable the spic device by calling its _DIS method
2143 static int sony_pic_disable(struct acpi_device *device)
2145 if (ACPI_FAILURE(acpi_evaluate_object(device->handle,
2146 "_DIS", NULL, NULL)))
2149 dprintk("Device disabled\n");
2155 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
2157 * Call _SRS to set current resources
2159 static int sony_pic_enable(struct acpi_device *device,
2160 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
2165 struct acpi_resource io_res;
2166 struct acpi_resource irq_res;
2167 struct acpi_resource end;
2169 struct acpi_buffer buffer = { 0, NULL };
2171 if (!ioport || !irq)
2174 /* init acpi_buffer */
2175 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
2179 buffer.length = sizeof(*resource) + 1;
2180 buffer.pointer = resource;
2182 /* setup io resource */
2183 resource->io_res.type = ACPI_RESOURCE_TYPE_IO;
2184 resource->io_res.length = sizeof(struct acpi_resource);
2185 memcpy(&resource->io_res.data.io, &ioport->io,
2186 sizeof(struct acpi_resource_io));
2188 /* setup irq resource */
2189 resource->irq_res.type = ACPI_RESOURCE_TYPE_IRQ;
2190 resource->irq_res.length = sizeof(struct acpi_resource);
2191 memcpy(&resource->irq_res.data.irq, &irq->irq,
2192 sizeof(struct acpi_resource_irq));
2193 /* we requested a shared irq */
2194 resource->irq_res.data.irq.sharable = ACPI_SHARED;
2196 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
2198 /* Attempt to set the resource */
2199 dprintk("Evaluating _SRS\n");
2200 status = acpi_set_current_resources(device->handle, &buffer);
2202 /* check for total failure */
2203 if (ACPI_FAILURE(status)) {
2204 printk(KERN_ERR DRV_PFX "Error evaluating _SRS");
2209 /* Necessary device initializations calls (from sonypi) */
2210 sony_pic_call1(0x82);
2211 sony_pic_call2(0x81, 0xff);
2212 sony_pic_call1(compat ? 0x92 : 0x82);
2221 * ISR: some event is available
2224 static irqreturn_t sony_pic_irq(int irq, void *dev_id)
2230 u8 device_event = 0;
2232 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
2234 acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val,
2235 dev->cur_ioport->io.address_length);
2236 ev = port_val & SONY_PIC_EV_MASK;
2237 data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
2239 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
2240 port_val, ev, data_mask, dev->cur_ioport->io.minimum);
2242 if (ev == 0x00 || ev == 0xff)
2245 for (i = 0; sony_pic_eventtypes[i].model; i++) {
2247 if (spic_dev.model != sony_pic_eventtypes[i].model)
2250 if ((data_mask & sony_pic_eventtypes[i].data) !=
2251 sony_pic_eventtypes[i].data)
2254 if (!(mask & sony_pic_eventtypes[i].mask))
2257 for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
2258 if (ev == sony_pic_eventtypes[i].events[j].data) {
2260 sony_pic_eventtypes[i].events[j].event;
2268 sony_laptop_report_input_event(device_event);
2269 acpi_bus_generate_event(spic_dev.acpi_dev, 1, device_event);
2270 sonypi_compat_report_event(device_event);
2280 static int sony_pic_remove(struct acpi_device *device, int type)
2282 struct sony_pic_ioport *io, *tmp_io;
2283 struct sony_pic_irq *irq, *tmp_irq;
2285 sonypi_compat_exit();
2287 if (sony_pic_disable(device)) {
2288 printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
2292 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2293 release_region(spic_dev.cur_ioport->io.minimum,
2294 spic_dev.cur_ioport->io.address_length);
2296 sony_laptop_remove_input();
2299 sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2302 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2303 list_del(&io->list);
2306 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2307 list_del(&irq->list);
2310 spic_dev.cur_ioport = NULL;
2311 spic_dev.cur_irq = NULL;
2313 dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
2317 static int sony_pic_add(struct acpi_device *device)
2320 struct sony_pic_ioport *io, *tmp_io;
2321 struct sony_pic_irq *irq, *tmp_irq;
2323 printk(KERN_INFO DRV_PFX "%s v%s.\n",
2324 SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
2326 spic_dev.acpi_dev = device;
2327 strcpy(acpi_device_class(device), "sony/hotkey");
2328 spic_dev.model = sony_pic_detect_device_type();
2329 mutex_init(&spic_dev.lock);
2331 /* read _PRS resources */
2332 result = sony_pic_possible_resources(device);
2334 printk(KERN_ERR DRV_PFX
2335 "Unabe to read possible resources.\n");
2336 goto err_free_resources;
2339 /* setup input devices and helper fifo */
2340 result = sony_laptop_setup_input();
2342 printk(KERN_ERR DRV_PFX
2343 "Unabe to create input devices.\n");
2344 goto err_free_resources;
2347 /* request io port */
2348 list_for_each_entry(io, &spic_dev.ioports, list) {
2349 if (request_region(io->io.minimum, io->io.address_length,
2350 "Sony Programable I/O Device")) {
2351 dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
2352 io->io.minimum, io->io.maximum,
2353 io->io.address_length);
2354 spic_dev.cur_ioport = io;
2358 if (!spic_dev.cur_ioport) {
2359 printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
2361 goto err_remove_input;
2365 list_for_each_entry(irq, &spic_dev.interrupts, list) {
2366 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
2367 IRQF_SHARED, "sony-laptop", &spic_dev)) {
2368 dprintk("IRQ: %d - triggering: %d - "
2369 "polarity: %d - shr: %d\n",
2370 irq->irq.interrupts[0],
2371 irq->irq.triggering,
2374 spic_dev.cur_irq = irq;
2378 if (!spic_dev.cur_irq) {
2379 printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
2381 goto err_release_region;
2384 /* set resource status _SRS */
2385 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2387 printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
2391 spic_dev.bluetooth_power = -1;
2392 /* create device attributes */
2393 result = sony_pf_add();
2395 goto err_disable_device;
2397 result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2401 if (sonypi_compat_init())
2410 sony_pic_disable(device);
2413 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2416 release_region(spic_dev.cur_ioport->io.minimum,
2417 spic_dev.cur_ioport->io.address_length);
2420 sony_laptop_remove_input();
2423 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2424 list_del(&io->list);
2427 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2428 list_del(&irq->list);
2431 spic_dev.cur_ioport = NULL;
2432 spic_dev.cur_irq = NULL;
2437 static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
2439 if (sony_pic_disable(device))
2444 static int sony_pic_resume(struct acpi_device *device)
2446 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2450 static struct acpi_driver sony_pic_driver = {
2451 .name = SONY_PIC_DRIVER_NAME,
2452 .class = SONY_PIC_CLASS,
2453 .ids = SONY_PIC_HID,
2454 .owner = THIS_MODULE,
2456 .add = sony_pic_add,
2457 .remove = sony_pic_remove,
2458 .suspend = sony_pic_suspend,
2459 .resume = sony_pic_resume,
2463 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
2465 .ident = "Sony Vaio",
2467 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2468 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
2472 .ident = "Sony Vaio",
2474 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2475 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
2481 static int __init sony_laptop_init(void)
2485 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
2486 result = acpi_bus_register_driver(&sony_pic_driver);
2488 printk(KERN_ERR DRV_PFX
2489 "Unable to register SPIC driver.");
2494 result = acpi_bus_register_driver(&sony_nc_driver);
2496 printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
2497 goto out_unregister_pic;
2504 acpi_bus_unregister_driver(&sony_pic_driver);
2509 static void __exit sony_laptop_exit(void)
2511 acpi_bus_unregister_driver(&sony_nc_driver);
2513 acpi_bus_unregister_driver(&sony_pic_driver);
2516 module_init(sony_laptop_init);
2517 module_exit(sony_laptop_exit);