2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007-2009 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 <linux/slab.h>
62 #include <acpi/acpi_drivers.h>
63 #include <acpi/acpi_bus.h>
64 #include <asm/uaccess.h>
65 #include <linux/sonypi.h>
66 #include <linux/sony-laptop.h>
67 #include <linux/rfkill.h>
68 #ifdef CONFIG_SONYPI_COMPAT
69 #include <linux/poll.h>
70 #include <linux/miscdevice.h>
73 #define DRV_PFX "sony-laptop: "
74 #define dprintk(msg...) do { \
76 pr_warn(DRV_PFX msg); \
79 #define SONY_LAPTOP_DRIVER_VERSION "0.6"
81 #define SONY_NC_CLASS "sony-nc"
82 #define SONY_NC_HID "SNY5001"
83 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
85 #define SONY_PIC_CLASS "sony-pic"
86 #define SONY_PIC_HID "SNY6001"
87 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
89 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
90 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
91 MODULE_LICENSE("GPL");
92 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
95 module_param(debug, int, 0);
96 MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
97 "the development of this driver");
99 static int no_spic; /* = 0 */
100 module_param(no_spic, int, 0444);
101 MODULE_PARM_DESC(no_spic,
102 "set this if you don't want to enable the SPIC device");
104 static int compat; /* = 0 */
105 module_param(compat, int, 0444);
106 MODULE_PARM_DESC(compat,
107 "set this if you want to enable backward compatibility mode");
109 static unsigned long mask = 0xffffffff;
110 module_param(mask, ulong, 0644);
111 MODULE_PARM_DESC(mask,
112 "set this to the mask of event you want to enable (see doc)");
114 static int camera; /* = 0 */
115 module_param(camera, int, 0444);
116 MODULE_PARM_DESC(camera,
117 "set this to 1 to enable Motion Eye camera controls "
118 "(only use it if you have a C1VE or C1VN model)");
120 #ifdef CONFIG_SONYPI_COMPAT
121 static int minor = -1;
122 module_param(minor, int, 0);
123 MODULE_PARM_DESC(minor,
124 "minor number of the misc device for the SPIC compatibility code, "
125 "default is -1 (automatic)");
128 static int kbd_backlight; /* = 1 */
129 module_param(kbd_backlight, int, 0444);
130 MODULE_PARM_DESC(kbd_backlight,
131 "set this to 0 to disable keyboard backlight, "
132 "1 to enable it (default: 0)");
134 static int kbd_backlight_timeout; /* = 0 */
135 module_param(kbd_backlight_timeout, int, 0444);
136 MODULE_PARM_DESC(kbd_backlight_timeout,
137 "set this to 0 to set the default 10 seconds timeout, "
138 "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout "
141 enum sony_nc_rfkill {
149 static int sony_rfkill_handle;
150 static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL];
151 static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900};
152 static void sony_nc_rfkill_update(void);
154 /*********** Input Devices ***********/
156 #define SONY_LAPTOP_BUF_SIZE 128
157 struct sony_laptop_input_s {
159 struct input_dev *jog_dev;
160 struct input_dev *key_dev;
162 spinlock_t fifo_lock;
163 struct timer_list release_key_timer;
166 static struct sony_laptop_input_s sony_laptop_input = {
167 .users = ATOMIC_INIT(0),
170 struct sony_laptop_keypress {
171 struct input_dev *dev;
175 /* Correspondance table between sonypi events
176 * and input layer indexes in the keymap
178 static int sony_laptop_input_index[] = {
180 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
181 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
182 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
183 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
184 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
185 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
186 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
187 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
188 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
189 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
190 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
191 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
192 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
193 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
194 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
195 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
196 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
197 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
198 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
199 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
200 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
201 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
202 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
203 17, /* 24 SONYPI_EVENT_FNKEY_1 */
204 18, /* 25 SONYPI_EVENT_FNKEY_2 */
205 19, /* 26 SONYPI_EVENT_FNKEY_D */
206 20, /* 27 SONYPI_EVENT_FNKEY_E */
207 21, /* 28 SONYPI_EVENT_FNKEY_F */
208 22, /* 29 SONYPI_EVENT_FNKEY_S */
209 23, /* 30 SONYPI_EVENT_FNKEY_B */
210 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
211 25, /* 32 SONYPI_EVENT_PKEY_P1 */
212 26, /* 33 SONYPI_EVENT_PKEY_P2 */
213 27, /* 34 SONYPI_EVENT_PKEY_P3 */
214 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
215 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
216 -1, /* 37 SONYPI_EVENT_LID_OPENED */
217 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
218 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
219 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
220 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
221 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
222 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
223 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
224 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
225 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
226 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
227 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
228 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
229 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
230 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
231 43, /* 52 SONYPI_EVENT_MEYE_FACE */
232 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
233 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
234 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
235 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
236 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
237 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
238 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
239 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
240 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
241 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
242 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
243 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
244 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
245 53, /* 66 SONYPI_EVENT_PKEY_P4 */
246 54, /* 67 SONYPI_EVENT_PKEY_P5 */
247 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
248 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
249 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
250 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
251 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
252 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */
255 static int sony_laptop_input_keycode_map[] = {
256 KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
257 KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
258 KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
259 KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
260 KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */
261 KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */
262 KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */
263 KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */
264 KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */
265 KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */
266 KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */
267 KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */
268 KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */
269 KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */
270 KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */
271 KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */
272 KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */
273 KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */
274 KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */
275 KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */
276 KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */
277 KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */
278 KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */
279 KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */
280 KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
281 KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */
282 KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */
283 KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */
284 KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */
285 KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
286 KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
287 KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */
288 KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */
289 KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
290 KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
291 KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
292 KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
293 KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
294 KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
295 KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
296 KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
297 KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
298 BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
299 KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */
300 KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
301 KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
302 KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
303 KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */
304 KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */
305 KEY_ZOOMIN, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
306 KEY_ZOOMOUT, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
307 KEY_EJECTCD, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
308 KEY_F13, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
309 KEY_PROG4, /* 53 SONYPI_EVENT_PKEY_P4 */
310 KEY_F14, /* 54 SONYPI_EVENT_PKEY_P5 */
311 KEY_F15, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
312 KEY_VOLUMEUP, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
313 KEY_VOLUMEDOWN, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
314 KEY_MEDIA, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
315 KEY_VENDOR, /* 59 SONYPI_EVENT_VENDOR_PRESSED */
318 /* release buttons after a short delay if pressed */
319 static void do_sony_laptop_release_key(unsigned long unused)
321 struct sony_laptop_keypress kp;
324 spin_lock_irqsave(&sony_laptop_input.fifo_lock, flags);
326 if (kfifo_out(&sony_laptop_input.fifo,
327 (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
328 input_report_key(kp.dev, kp.key, 0);
332 /* If there is something in the fifo schedule next release. */
333 if (kfifo_len(&sony_laptop_input.fifo) != 0)
334 mod_timer(&sony_laptop_input.release_key_timer,
335 jiffies + msecs_to_jiffies(10));
337 spin_unlock_irqrestore(&sony_laptop_input.fifo_lock, flags);
340 /* forward event to the input subsystem */
341 static void sony_laptop_report_input_event(u8 event)
343 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
344 struct input_dev *key_dev = sony_laptop_input.key_dev;
345 struct sony_laptop_keypress kp = { NULL };
347 if (event == SONYPI_EVENT_FNKEY_RELEASED ||
348 event == SONYPI_EVENT_ANYBUTTON_RELEASED) {
349 /* Nothing, not all VAIOs generate this event */
356 case SONYPI_EVENT_JOGDIAL_UP:
357 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
358 input_report_rel(jog_dev, REL_WHEEL, 1);
362 case SONYPI_EVENT_JOGDIAL_DOWN:
363 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
364 input_report_rel(jog_dev, REL_WHEEL, -1);
369 case SONYPI_EVENT_JOGDIAL_PRESSED:
375 if (event >= ARRAY_SIZE(sony_laptop_input_index)) {
376 dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
379 if (sony_laptop_input_index[event] != -1) {
380 kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]];
381 if (kp.key != KEY_UNKNOWN)
388 input_report_key(kp.dev, kp.key, 1);
389 /* we emit the scancode so we can always remap the key */
390 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
393 /* schedule key release */
394 kfifo_in_locked(&sony_laptop_input.fifo,
395 (unsigned char *)&kp, sizeof(kp),
396 &sony_laptop_input.fifo_lock);
397 mod_timer(&sony_laptop_input.release_key_timer,
398 jiffies + msecs_to_jiffies(10));
400 dprintk("unknown input event %.2x\n", event);
403 static int sony_laptop_setup_input(struct acpi_device *acpi_device)
405 struct input_dev *jog_dev;
406 struct input_dev *key_dev;
410 /* don't run again if already initialized */
411 if (atomic_add_return(1, &sony_laptop_input.users) > 1)
415 spin_lock_init(&sony_laptop_input.fifo_lock);
416 error = kfifo_alloc(&sony_laptop_input.fifo,
417 SONY_LAPTOP_BUF_SIZE, GFP_KERNEL);
419 pr_err(DRV_PFX "kfifo_alloc failed\n");
423 setup_timer(&sony_laptop_input.release_key_timer,
424 do_sony_laptop_release_key, 0);
427 key_dev = input_allocate_device();
433 key_dev->name = "Sony Vaio Keys";
434 key_dev->id.bustype = BUS_ISA;
435 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
436 key_dev->dev.parent = &acpi_device->dev;
438 /* Initialize the Input Drivers: special keys */
439 input_set_capability(key_dev, EV_MSC, MSC_SCAN);
441 __set_bit(EV_KEY, key_dev->evbit);
442 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
443 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
444 key_dev->keycode = &sony_laptop_input_keycode_map;
445 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++)
446 __set_bit(sony_laptop_input_keycode_map[i], key_dev->keybit);
447 __clear_bit(KEY_RESERVED, key_dev->keybit);
449 error = input_register_device(key_dev);
451 goto err_free_keydev;
453 sony_laptop_input.key_dev = key_dev;
456 jog_dev = input_allocate_device();
459 goto err_unregister_keydev;
462 jog_dev->name = "Sony Vaio Jogdial";
463 jog_dev->id.bustype = BUS_ISA;
464 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
465 key_dev->dev.parent = &acpi_device->dev;
467 input_set_capability(jog_dev, EV_KEY, BTN_MIDDLE);
468 input_set_capability(jog_dev, EV_REL, REL_WHEEL);
470 error = input_register_device(jog_dev);
472 goto err_free_jogdev;
474 sony_laptop_input.jog_dev = jog_dev;
479 input_free_device(jog_dev);
481 err_unregister_keydev:
482 input_unregister_device(key_dev);
483 /* to avoid kref underflow below at input_free_device */
487 input_free_device(key_dev);
490 kfifo_free(&sony_laptop_input.fifo);
493 atomic_dec(&sony_laptop_input.users);
497 static void sony_laptop_remove_input(void)
499 struct sony_laptop_keypress kp = { NULL };
501 /* Cleanup only after the last user has gone */
502 if (!atomic_dec_and_test(&sony_laptop_input.users))
505 del_timer_sync(&sony_laptop_input.release_key_timer);
508 * Generate key-up events for remaining keys. Note that we don't
509 * need locking since nobody is adding new events to the kfifo.
511 while (kfifo_out(&sony_laptop_input.fifo,
512 (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
513 input_report_key(kp.dev, kp.key, 0);
517 /* destroy input devs */
518 input_unregister_device(sony_laptop_input.key_dev);
519 sony_laptop_input.key_dev = NULL;
521 if (sony_laptop_input.jog_dev) {
522 input_unregister_device(sony_laptop_input.jog_dev);
523 sony_laptop_input.jog_dev = NULL;
526 kfifo_free(&sony_laptop_input.fifo);
529 /*********** Platform Device ***********/
531 static atomic_t sony_pf_users = ATOMIC_INIT(0);
532 static struct platform_driver sony_pf_driver = {
534 .name = "sony-laptop",
535 .owner = THIS_MODULE,
538 static struct platform_device *sony_pf_device;
540 static int sony_pf_add(void)
544 /* don't run again if already initialized */
545 if (atomic_add_return(1, &sony_pf_users) > 1)
548 ret = platform_driver_register(&sony_pf_driver);
552 sony_pf_device = platform_device_alloc("sony-laptop", -1);
553 if (!sony_pf_device) {
555 goto out_platform_registered;
558 ret = platform_device_add(sony_pf_device);
560 goto out_platform_alloced;
564 out_platform_alloced:
565 platform_device_put(sony_pf_device);
566 sony_pf_device = NULL;
567 out_platform_registered:
568 platform_driver_unregister(&sony_pf_driver);
570 atomic_dec(&sony_pf_users);
574 static void sony_pf_remove(void)
576 /* deregister only after the last user has gone */
577 if (!atomic_dec_and_test(&sony_pf_users))
580 platform_device_unregister(sony_pf_device);
581 platform_driver_unregister(&sony_pf_driver);
584 /*********** SNC (SNY5001) Device ***********/
586 /* the device uses 1-based values, while the backlight subsystem uses
588 #define SONY_MAX_BRIGHTNESS 8
590 #define SNC_VALIDATE_IN 0
591 #define SNC_VALIDATE_OUT 1
593 static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
595 static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
596 const char *, size_t);
597 static int boolean_validate(const int, const int);
598 static int brightness_default_validate(const int, const int);
600 struct sony_nc_value {
601 char *name; /* name of the entry */
602 char **acpiget; /* names of the ACPI get function */
603 char **acpiset; /* names of the ACPI set function */
604 int (*validate)(const int, const int); /* input/output validation */
605 int value; /* current setting */
606 int valid; /* Has ever been set */
607 int debug; /* active only in debug mode ? */
608 struct device_attribute devattr; /* sysfs attribute */
611 #define SNC_HANDLE_NAMES(_name, _values...) \
612 static char *snc_##_name[] = { _values, NULL }
614 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
616 .name = __stringify(_name), \
617 .acpiget = _getters, \
618 .acpiset = _setters, \
619 .validate = _validate, \
621 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
624 #define SNC_HANDLE_NULL { .name = NULL }
626 SNC_HANDLE_NAMES(fnkey_get, "GHKE");
628 SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
629 SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
631 SNC_HANDLE_NAMES(cdpower_get, "GCDP");
632 SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
634 SNC_HANDLE_NAMES(audiopower_get, "GAZP");
635 SNC_HANDLE_NAMES(audiopower_set, "AZPW");
637 SNC_HANDLE_NAMES(lanpower_get, "GLNP");
638 SNC_HANDLE_NAMES(lanpower_set, "LNPW");
640 SNC_HANDLE_NAMES(lidstate_get, "GLID");
642 SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
643 SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
645 SNC_HANDLE_NAMES(gainbass_get, "GMGB");
646 SNC_HANDLE_NAMES(gainbass_set, "CMGB");
648 SNC_HANDLE_NAMES(PID_get, "GPID");
650 SNC_HANDLE_NAMES(CTR_get, "GCTR");
651 SNC_HANDLE_NAMES(CTR_set, "SCTR");
653 SNC_HANDLE_NAMES(PCR_get, "GPCR");
654 SNC_HANDLE_NAMES(PCR_set, "SPCR");
656 SNC_HANDLE_NAMES(CMI_get, "GCMI");
657 SNC_HANDLE_NAMES(CMI_set, "SCMI");
659 static struct sony_nc_value sony_nc_values[] = {
660 SNC_HANDLE(brightness_default, snc_brightness_def_get,
661 snc_brightness_def_set, brightness_default_validate, 0),
662 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
663 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
664 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
665 boolean_validate, 0),
666 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
667 boolean_validate, 1),
668 SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
669 boolean_validate, 0),
670 SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
671 boolean_validate, 0),
672 SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
673 boolean_validate, 0),
674 /* unknown methods */
675 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
676 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
677 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
678 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
682 static acpi_handle sony_nc_acpi_handle;
683 static struct acpi_device *sony_nc_acpi_device = NULL;
686 * acpi_evaluate_object wrappers
688 static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
690 struct acpi_buffer output;
691 union acpi_object out_obj;
694 output.length = sizeof(out_obj);
695 output.pointer = &out_obj;
697 status = acpi_evaluate_object(handle, name, NULL, &output);
698 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
699 *result = out_obj.integer.value;
703 pr_warn(DRV_PFX "acpi_callreadfunc failed\n");
708 static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
711 struct acpi_object_list params;
712 union acpi_object in_obj;
713 struct acpi_buffer output;
714 union acpi_object out_obj;
718 params.pointer = &in_obj;
719 in_obj.type = ACPI_TYPE_INTEGER;
720 in_obj.integer.value = value;
722 output.length = sizeof(out_obj);
723 output.pointer = &out_obj;
725 status = acpi_evaluate_object(handle, name, ¶ms, &output);
726 if (status == AE_OK) {
727 if (result != NULL) {
728 if (out_obj.type != ACPI_TYPE_INTEGER) {
729 pr_warn(DRV_PFX "acpi_evaluate_object bad "
733 *result = out_obj.integer.value;
738 pr_warn(DRV_PFX "acpi_evaluate_object failed\n");
743 struct sony_nc_handles {
745 struct device_attribute devattr;
748 static struct sony_nc_handles *handles;
750 static ssize_t sony_nc_handles_show(struct device *dev,
751 struct device_attribute *attr, char *buffer)
756 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
757 len += snprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ",
760 len += snprintf(buffer + len, PAGE_SIZE - len, "\n");
765 static int sony_nc_handles_setup(struct platform_device *pd)
770 handles = kzalloc(sizeof(*handles), GFP_KERNEL);
774 sysfs_attr_init(&handles->devattr.attr);
775 handles->devattr.attr.name = "handles";
776 handles->devattr.attr.mode = S_IRUGO;
777 handles->devattr.show = sony_nc_handles_show;
779 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
780 if (!acpi_callsetfunc(sony_nc_acpi_handle,
781 "SN00", i + 0x20, &result)) {
782 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
784 handles->cap[i] = result;
788 /* allow reading capabilities via sysfs */
789 if (device_create_file(&pd->dev, &handles->devattr)) {
798 static int sony_nc_handles_cleanup(struct platform_device *pd)
801 device_remove_file(&pd->dev, &handles->devattr);
808 static int sony_find_snc_handle(int handle)
812 /* not initialized yet, return early */
816 for (i = 0; i < 0x10; i++) {
817 if (handles->cap[i] == handle) {
818 dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
823 dprintk("handle 0x%.4x not found\n", handle);
827 static int sony_call_snc_handle(int handle, int argument, int *result)
830 int offset = sony_find_snc_handle(handle);
835 ret = acpi_callsetfunc(sony_nc_acpi_handle, "SN07", offset | argument,
837 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", offset | argument,
843 * sony_nc_values input/output validate functions
846 /* brightness_default_validate:
848 * manipulate input output values to keep consistency with the
849 * backlight framework for which brightness values are 0-based.
851 static int brightness_default_validate(const int direction, const int value)
854 case SNC_VALIDATE_OUT:
856 case SNC_VALIDATE_IN:
857 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
865 * on input validate boolean values 0/1, on output just pass the
868 static int boolean_validate(const int direction, const int value)
870 if (direction == SNC_VALIDATE_IN) {
871 if (value != 0 && value != 1)
878 * Sysfs show/store common to all sony_nc_values
880 static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
884 struct sony_nc_value *item =
885 container_of(attr, struct sony_nc_value, devattr);
890 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
894 value = item->validate(SNC_VALIDATE_OUT, value);
896 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
899 static ssize_t sony_nc_sysfs_store(struct device *dev,
900 struct device_attribute *attr,
901 const char *buffer, size_t count)
904 struct sony_nc_value *item =
905 container_of(attr, struct sony_nc_value, devattr);
913 value = simple_strtoul(buffer, NULL, 10);
916 value = item->validate(SNC_VALIDATE_IN, value);
921 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
932 static int sony_backlight_update_status(struct backlight_device *bd)
934 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
935 bd->props.brightness + 1, NULL);
938 static int sony_backlight_get_brightness(struct backlight_device *bd)
942 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
944 /* brightness levels are 1-based, while backlight ones are 0-based */
948 static int sony_nc_get_brightness_ng(struct backlight_device *bd)
951 int *handle = (int *)bl_get_data(bd);
953 sony_call_snc_handle(*handle, 0x0200, &result);
955 return result & 0xff;
958 static int sony_nc_update_status_ng(struct backlight_device *bd)
961 int *handle = (int *)bl_get_data(bd);
963 value = bd->props.brightness;
964 sony_call_snc_handle(*handle, 0x0100 | (value << 16), &result);
966 return sony_nc_get_brightness_ng(bd);
969 static const struct backlight_ops sony_backlight_ops = {
970 .options = BL_CORE_SUSPENDRESUME,
971 .update_status = sony_backlight_update_status,
972 .get_brightness = sony_backlight_get_brightness,
974 static const struct backlight_ops sony_backlight_ng_ops = {
975 .options = BL_CORE_SUSPENDRESUME,
976 .update_status = sony_nc_update_status_ng,
977 .get_brightness = sony_nc_get_brightness_ng,
979 static int backlight_ng_handle;
980 static struct backlight_device *sony_backlight_device;
983 * New SNC-only Vaios event mapping to driver known keys
985 struct sony_nc_event {
990 static struct sony_nc_event sony_100_events[] = {
991 { 0x90, SONYPI_EVENT_PKEY_P1 },
992 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED },
993 { 0x91, SONYPI_EVENT_PKEY_P2 },
994 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED },
995 { 0x81, SONYPI_EVENT_FNKEY_F1 },
996 { 0x01, SONYPI_EVENT_FNKEY_RELEASED },
997 { 0x82, SONYPI_EVENT_FNKEY_F2 },
998 { 0x02, SONYPI_EVENT_FNKEY_RELEASED },
999 { 0x83, SONYPI_EVENT_FNKEY_F3 },
1000 { 0x03, SONYPI_EVENT_FNKEY_RELEASED },
1001 { 0x84, SONYPI_EVENT_FNKEY_F4 },
1002 { 0x04, SONYPI_EVENT_FNKEY_RELEASED },
1003 { 0x85, SONYPI_EVENT_FNKEY_F5 },
1004 { 0x05, SONYPI_EVENT_FNKEY_RELEASED },
1005 { 0x86, SONYPI_EVENT_FNKEY_F6 },
1006 { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
1007 { 0x87, SONYPI_EVENT_FNKEY_F7 },
1008 { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
1009 { 0x89, SONYPI_EVENT_FNKEY_F9 },
1010 { 0x09, SONYPI_EVENT_FNKEY_RELEASED },
1011 { 0x8A, SONYPI_EVENT_FNKEY_F10 },
1012 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
1013 { 0x8C, SONYPI_EVENT_FNKEY_F12 },
1014 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
1015 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED },
1016 { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED },
1017 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED },
1018 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED },
1019 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED },
1020 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED },
1021 { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED },
1022 { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED },
1023 { 0xa5, SONYPI_EVENT_VENDOR_PRESSED },
1024 { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED },
1025 { 0xa6, SONYPI_EVENT_HELP_PRESSED },
1026 { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED },
1030 static struct sony_nc_event sony_127_events[] = {
1031 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED },
1032 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED },
1033 { 0x82, SONYPI_EVENT_PKEY_P1 },
1034 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED },
1035 { 0x83, SONYPI_EVENT_PKEY_P2 },
1036 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED },
1037 { 0x84, SONYPI_EVENT_PKEY_P3 },
1038 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED },
1039 { 0x85, SONYPI_EVENT_PKEY_P4 },
1040 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED },
1041 { 0x86, SONYPI_EVENT_PKEY_P5 },
1042 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED },
1043 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED },
1044 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED },
1051 static void sony_nc_notify(struct acpi_device *device, u32 event)
1056 /* New-style event */
1061 if (sony_find_snc_handle(0x100) == ev)
1063 if (sony_find_snc_handle(0x127) == ev)
1067 struct sony_nc_event *key_event;
1069 if (sony_call_snc_handle(key_handle, 0x200, &result)) {
1070 dprintk("sony_nc_notify, unable to decode"
1071 " event 0x%.2x 0x%.2x\n", key_handle,
1073 /* restore the original event */
1078 if (key_handle == 0x100)
1079 key_event = sony_100_events;
1081 key_event = sony_127_events;
1083 for (; key_event->data; key_event++) {
1084 if (key_event->data == ev) {
1085 ev = key_event->event;
1090 if (!key_event->data)
1092 "Unknown event: 0x%x 0x%x\n",
1096 sony_laptop_report_input_event(ev);
1098 } else if (sony_find_snc_handle(sony_rfkill_handle) == ev) {
1099 sony_nc_rfkill_update();
1103 sony_laptop_report_input_event(ev);
1105 dprintk("sony_nc_notify, event: 0x%.2x\n", ev);
1106 acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev);
1109 static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
1110 void *context, void **return_value)
1112 struct acpi_device_info *info;
1114 if (ACPI_SUCCESS(acpi_get_object_info(handle, &info))) {
1115 pr_warn(DRV_PFX "method: name: %4.4s, args %X\n",
1116 (char *)&info->name, info->param_count);
1127 static int sony_nc_function_setup(struct acpi_device *device)
1131 /* Enable all events */
1132 acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0xffff, &result);
1135 sony_call_snc_handle(0x0100, 0, &result);
1136 sony_call_snc_handle(0x0101, 0, &result);
1137 sony_call_snc_handle(0x0102, 0x100, &result);
1138 sony_call_snc_handle(0x0127, 0, &result);
1143 static int sony_nc_resume(struct acpi_device *device)
1145 struct sony_nc_value *item;
1148 for (item = sony_nc_values; item->name; item++) {
1153 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
1156 pr_err(DRV_PFX "%s: %d\n", __func__, ret);
1161 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
1163 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL))
1164 dprintk("ECON Method failed\n");
1167 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
1169 dprintk("Doing SNC setup\n");
1170 sony_nc_function_setup(device);
1173 /* re-read rfkill state */
1174 sony_nc_rfkill_update();
1179 static void sony_nc_rfkill_cleanup(void)
1183 for (i = 0; i < N_SONY_RFKILL; i++) {
1184 if (sony_rfkill_devices[i]) {
1185 rfkill_unregister(sony_rfkill_devices[i]);
1186 rfkill_destroy(sony_rfkill_devices[i]);
1191 static int sony_nc_rfkill_set(void *data, bool blocked)
1194 int argument = sony_rfkill_address[(long) data] + 0x100;
1197 argument |= 0xff0000;
1199 return sony_call_snc_handle(sony_rfkill_handle, argument, &result);
1202 static const struct rfkill_ops sony_rfkill_ops = {
1203 .set_block = sony_nc_rfkill_set,
1206 static int sony_nc_setup_rfkill(struct acpi_device *device,
1207 enum sony_nc_rfkill nc_type)
1211 enum rfkill_type type;
1218 type = RFKILL_TYPE_WLAN;
1221 case SONY_BLUETOOTH:
1222 type = RFKILL_TYPE_BLUETOOTH;
1223 name = "sony-bluetooth";
1226 type = RFKILL_TYPE_WWAN;
1230 type = RFKILL_TYPE_WIMAX;
1231 name = "sony-wimax";
1237 rfk = rfkill_alloc(name, &device->dev, type,
1238 &sony_rfkill_ops, (void *)nc_type);
1242 sony_call_snc_handle(sony_rfkill_handle, 0x200, &result);
1243 hwblock = !(result & 0x1);
1244 rfkill_set_hw_state(rfk, hwblock);
1246 err = rfkill_register(rfk);
1248 rfkill_destroy(rfk);
1251 sony_rfkill_devices[nc_type] = rfk;
1255 static void sony_nc_rfkill_update(void)
1257 enum sony_nc_rfkill i;
1261 sony_call_snc_handle(sony_rfkill_handle, 0x200, &result);
1262 hwblock = !(result & 0x1);
1264 for (i = 0; i < N_SONY_RFKILL; i++) {
1265 int argument = sony_rfkill_address[i];
1267 if (!sony_rfkill_devices[i])
1271 if (rfkill_set_hw_state(sony_rfkill_devices[i], true)) {
1272 /* we already know we're blocked */
1277 sony_call_snc_handle(sony_rfkill_handle, argument, &result);
1278 rfkill_set_states(sony_rfkill_devices[i],
1279 !(result & 0xf), false);
1283 static void sony_nc_rfkill_setup(struct acpi_device *device)
1288 struct acpi_object_list params;
1289 union acpi_object in_obj;
1290 union acpi_object *device_enum;
1291 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1293 offset = sony_find_snc_handle(0x124);
1295 offset = sony_find_snc_handle(0x135);
1299 sony_rfkill_handle = 0x135;
1301 sony_rfkill_handle = 0x124;
1302 dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle);
1304 /* need to read the whole buffer returned by the acpi call to SN06
1305 * here otherwise we may miss some features
1308 params.pointer = &in_obj;
1309 in_obj.type = ACPI_TYPE_INTEGER;
1310 in_obj.integer.value = offset;
1311 status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", ¶ms,
1313 if (ACPI_FAILURE(status)) {
1314 dprintk("Radio device enumeration failed\n");
1318 device_enum = (union acpi_object *) buffer.pointer;
1320 pr_err(DRV_PFX "No SN06 return object.");
1323 if (device_enum->type != ACPI_TYPE_BUFFER) {
1324 pr_err(DRV_PFX "Invalid SN06 return object 0x%.2x\n",
1329 /* the buffer is filled with magic numbers describing the devices
1330 * available, 0xff terminates the enumeration
1332 for (i = 0; i < device_enum->buffer.length; i++) {
1334 dev_code = *(device_enum->buffer.pointer + i);
1335 if (dev_code == 0xff)
1338 dprintk("Radio devices, looking at 0x%.2x\n", dev_code);
1340 if (dev_code == 0 && !sony_rfkill_devices[SONY_WIFI])
1341 sony_nc_setup_rfkill(device, SONY_WIFI);
1343 if (dev_code == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH])
1344 sony_nc_setup_rfkill(device, SONY_BLUETOOTH);
1346 if ((0xf0 & dev_code) == 0x20 &&
1347 !sony_rfkill_devices[SONY_WWAN])
1348 sony_nc_setup_rfkill(device, SONY_WWAN);
1350 if (dev_code == 0x30 && !sony_rfkill_devices[SONY_WIMAX])
1351 sony_nc_setup_rfkill(device, SONY_WIMAX);
1355 kfree(buffer.pointer);
1359 /* Keyboard backlight feature */
1360 #define KBDBL_HANDLER 0x137
1361 #define KBDBL_PRESENT 0xB00
1362 #define SET_MODE 0xC00
1363 #define SET_TIMEOUT 0xE00
1365 struct kbd_backlight {
1368 struct device_attribute mode_attr;
1369 struct device_attribute timeout_attr;
1372 static struct kbd_backlight *kbdbl_handle;
1374 static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value)
1381 if (sony_call_snc_handle(KBDBL_HANDLER,
1382 (value << 0x10) | SET_MODE, &result))
1385 kbdbl_handle->mode = value;
1390 static ssize_t sony_nc_kbd_backlight_mode_store(struct device *dev,
1391 struct device_attribute *attr,
1392 const char *buffer, size_t count)
1395 unsigned long value;
1400 if (strict_strtoul(buffer, 10, &value))
1403 ret = __sony_nc_kbd_backlight_mode_set(value);
1410 static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev,
1411 struct device_attribute *attr, char *buffer)
1414 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->mode);
1418 static int __sony_nc_kbd_backlight_timeout_set(u8 value)
1425 if (sony_call_snc_handle(KBDBL_HANDLER,
1426 (value << 0x10) | SET_TIMEOUT, &result))
1429 kbdbl_handle->timeout = value;
1434 static ssize_t sony_nc_kbd_backlight_timeout_store(struct device *dev,
1435 struct device_attribute *attr,
1436 const char *buffer, size_t count)
1439 unsigned long value;
1444 if (strict_strtoul(buffer, 10, &value))
1447 ret = __sony_nc_kbd_backlight_timeout_set(value);
1454 static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev,
1455 struct device_attribute *attr, char *buffer)
1458 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->timeout);
1462 static int sony_nc_kbd_backlight_setup(struct platform_device *pd)
1466 if (sony_call_snc_handle(0x137, KBDBL_PRESENT, &result))
1468 if (!(result & 0x02))
1471 kbdbl_handle = kzalloc(sizeof(*kbdbl_handle), GFP_KERNEL);
1475 sysfs_attr_init(&kbdbl_handle->mode_attr.attr);
1476 kbdbl_handle->mode_attr.attr.name = "kbd_backlight";
1477 kbdbl_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR;
1478 kbdbl_handle->mode_attr.show = sony_nc_kbd_backlight_mode_show;
1479 kbdbl_handle->mode_attr.store = sony_nc_kbd_backlight_mode_store;
1481 sysfs_attr_init(&kbdbl_handle->timeout_attr.attr);
1482 kbdbl_handle->timeout_attr.attr.name = "kbd_backlight_timeout";
1483 kbdbl_handle->timeout_attr.attr.mode = S_IRUGO | S_IWUSR;
1484 kbdbl_handle->timeout_attr.show = sony_nc_kbd_backlight_timeout_show;
1485 kbdbl_handle->timeout_attr.store = sony_nc_kbd_backlight_timeout_store;
1487 if (device_create_file(&pd->dev, &kbdbl_handle->mode_attr))
1490 if (device_create_file(&pd->dev, &kbdbl_handle->timeout_attr))
1493 __sony_nc_kbd_backlight_mode_set(kbd_backlight);
1494 __sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout);
1499 device_remove_file(&pd->dev, &kbdbl_handle->mode_attr);
1501 kfree(kbdbl_handle);
1502 kbdbl_handle = NULL;
1506 static int sony_nc_kbd_backlight_cleanup(struct platform_device *pd)
1509 device_remove_file(&pd->dev, &kbdbl_handle->mode_attr);
1510 device_remove_file(&pd->dev, &kbdbl_handle->timeout_attr);
1511 kfree(kbdbl_handle);
1516 static void sony_nc_backlight_setup(void)
1519 int max_brightness = 0;
1520 const struct backlight_ops *ops = NULL;
1521 struct backlight_properties props;
1523 if (sony_find_snc_handle(0x12f) != -1) {
1524 backlight_ng_handle = 0x12f;
1525 ops = &sony_backlight_ng_ops;
1526 max_brightness = 0xff;
1528 } else if (sony_find_snc_handle(0x137) != -1) {
1529 backlight_ng_handle = 0x137;
1530 ops = &sony_backlight_ng_ops;
1531 max_brightness = 0xff;
1533 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT",
1535 ops = &sony_backlight_ops;
1536 max_brightness = SONY_MAX_BRIGHTNESS - 1;
1541 memset(&props, 0, sizeof(struct backlight_properties));
1542 props.type = BACKLIGHT_PLATFORM;
1543 props.max_brightness = max_brightness;
1544 sony_backlight_device = backlight_device_register("sony", NULL,
1545 &backlight_ng_handle,
1548 if (IS_ERR(sony_backlight_device)) {
1549 pr_warning(DRV_PFX "unable to register backlight device\n");
1550 sony_backlight_device = NULL;
1552 sony_backlight_device->props.brightness =
1553 ops->get_brightness(sony_backlight_device);
1556 static void sony_nc_backlight_cleanup(void)
1558 if (sony_backlight_device)
1559 backlight_device_unregister(sony_backlight_device);
1562 static int sony_nc_add(struct acpi_device *device)
1567 struct sony_nc_value *item;
1569 pr_info(DRV_PFX "%s v%s.\n", SONY_NC_DRIVER_NAME,
1570 SONY_LAPTOP_DRIVER_VERSION);
1572 sony_nc_acpi_device = device;
1573 strcpy(acpi_device_class(device), "sony/hotkey");
1575 sony_nc_acpi_handle = device->handle;
1577 /* read device status */
1578 result = acpi_bus_get_status(device);
1579 /* bail IFF the above call was successful and the device is not present */
1580 if (!result && !device->status.present) {
1581 dprintk("Device not present\n");
1586 result = sony_pf_add();
1591 status = acpi_walk_namespace(ACPI_TYPE_METHOD,
1592 sony_nc_acpi_handle, 1, sony_walk_callback,
1594 if (ACPI_FAILURE(status)) {
1595 pr_warn(DRV_PFX "unable to walk acpi resources\n");
1601 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
1603 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL))
1604 dprintk("ECON Method failed\n");
1607 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
1609 dprintk("Doing SNC setup\n");
1610 result = sony_nc_handles_setup(sony_pf_device);
1613 result = sony_nc_kbd_backlight_setup(sony_pf_device);
1616 sony_nc_function_setup(device);
1617 sony_nc_rfkill_setup(device);
1620 /* setup input devices and helper fifo */
1621 result = sony_laptop_setup_input(device);
1623 pr_err(DRV_PFX "Unable to create input devices.\n");
1624 goto outkbdbacklight;
1627 if (acpi_video_backlight_support()) {
1628 pr_info(DRV_PFX "brightness ignored, must be "
1629 "controlled by ACPI video driver\n");
1631 sony_nc_backlight_setup();
1634 /* create sony_pf sysfs attributes related to the SNC device */
1635 for (item = sony_nc_values; item->name; ++item) {
1637 if (!debug && item->debug)
1640 /* find the available acpiget as described in the DSDT */
1641 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
1642 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1645 dprintk("Found %s getter: %s\n",
1646 item->name, *item->acpiget);
1647 item->devattr.attr.mode |= S_IRUGO;
1652 /* find the available acpiset as described in the DSDT */
1653 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
1654 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1657 dprintk("Found %s setter: %s\n",
1658 item->name, *item->acpiset);
1659 item->devattr.attr.mode |= S_IWUSR;
1664 if (item->devattr.attr.mode != 0) {
1666 device_create_file(&sony_pf_device->dev,
1676 for (item = sony_nc_values; item->name; ++item) {
1677 device_remove_file(&sony_pf_device->dev, &item->devattr);
1679 sony_nc_backlight_cleanup();
1681 sony_laptop_remove_input();
1684 sony_nc_kbd_backlight_cleanup(sony_pf_device);
1687 sony_nc_handles_cleanup(sony_pf_device);
1693 sony_nc_rfkill_cleanup();
1697 static int sony_nc_remove(struct acpi_device *device, int type)
1699 struct sony_nc_value *item;
1701 sony_nc_backlight_cleanup();
1703 sony_nc_acpi_device = NULL;
1705 for (item = sony_nc_values; item->name; ++item) {
1706 device_remove_file(&sony_pf_device->dev, &item->devattr);
1709 sony_nc_kbd_backlight_cleanup(sony_pf_device);
1710 sony_nc_handles_cleanup(sony_pf_device);
1712 sony_laptop_remove_input();
1713 sony_nc_rfkill_cleanup();
1714 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
1719 static const struct acpi_device_id sony_device_ids[] = {
1724 MODULE_DEVICE_TABLE(acpi, sony_device_ids);
1726 static const struct acpi_device_id sony_nc_device_ids[] = {
1731 static struct acpi_driver sony_nc_driver = {
1732 .name = SONY_NC_DRIVER_NAME,
1733 .class = SONY_NC_CLASS,
1734 .ids = sony_nc_device_ids,
1735 .owner = THIS_MODULE,
1738 .remove = sony_nc_remove,
1739 .resume = sony_nc_resume,
1740 .notify = sony_nc_notify,
1744 /*********** SPIC (SNY6001) Device ***********/
1746 #define SONYPI_DEVICE_TYPE1 0x00000001
1747 #define SONYPI_DEVICE_TYPE2 0x00000002
1748 #define SONYPI_DEVICE_TYPE3 0x00000004
1750 #define SONYPI_TYPE1_OFFSET 0x04
1751 #define SONYPI_TYPE2_OFFSET 0x12
1752 #define SONYPI_TYPE3_OFFSET 0x12
1754 struct sony_pic_ioport {
1755 struct acpi_resource_io io1;
1756 struct acpi_resource_io io2;
1757 struct list_head list;
1760 struct sony_pic_irq {
1761 struct acpi_resource_irq irq;
1762 struct list_head list;
1765 struct sonypi_eventtypes {
1768 struct sonypi_event *events;
1771 struct sony_pic_dev {
1772 struct acpi_device *acpi_dev;
1773 struct sony_pic_irq *cur_irq;
1774 struct sony_pic_ioport *cur_ioport;
1775 struct list_head interrupts;
1776 struct list_head ioports;
1778 struct sonypi_eventtypes *event_types;
1779 int (*handle_irq)(const u8, const u8);
1787 static struct sony_pic_dev spic_dev = {
1788 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
1789 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
1792 static int spic_drv_registered;
1795 #define SONYPI_JOGGER_MASK 0x00000001
1796 #define SONYPI_CAPTURE_MASK 0x00000002
1797 #define SONYPI_FNKEY_MASK 0x00000004
1798 #define SONYPI_BLUETOOTH_MASK 0x00000008
1799 #define SONYPI_PKEY_MASK 0x00000010
1800 #define SONYPI_BACK_MASK 0x00000020
1801 #define SONYPI_HELP_MASK 0x00000040
1802 #define SONYPI_LID_MASK 0x00000080
1803 #define SONYPI_ZOOM_MASK 0x00000100
1804 #define SONYPI_THUMBPHRASE_MASK 0x00000200
1805 #define SONYPI_MEYE_MASK 0x00000400
1806 #define SONYPI_MEMORYSTICK_MASK 0x00000800
1807 #define SONYPI_BATTERY_MASK 0x00001000
1808 #define SONYPI_WIRELESS_MASK 0x00002000
1810 struct sonypi_event {
1815 /* The set of possible button release events */
1816 static struct sonypi_event sonypi_releaseev[] = {
1817 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
1821 /* The set of possible jogger events */
1822 static struct sonypi_event sonypi_joggerev[] = {
1823 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
1824 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
1825 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
1826 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
1827 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
1828 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
1829 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
1830 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
1831 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
1832 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
1833 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
1834 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
1835 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
1839 /* The set of possible capture button events */
1840 static struct sonypi_event sonypi_captureev[] = {
1841 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
1842 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
1843 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
1844 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
1848 /* The set of possible fnkeys events */
1849 static struct sonypi_event sonypi_fnkeyev[] = {
1850 { 0x10, SONYPI_EVENT_FNKEY_ESC },
1851 { 0x11, SONYPI_EVENT_FNKEY_F1 },
1852 { 0x12, SONYPI_EVENT_FNKEY_F2 },
1853 { 0x13, SONYPI_EVENT_FNKEY_F3 },
1854 { 0x14, SONYPI_EVENT_FNKEY_F4 },
1855 { 0x15, SONYPI_EVENT_FNKEY_F5 },
1856 { 0x16, SONYPI_EVENT_FNKEY_F6 },
1857 { 0x17, SONYPI_EVENT_FNKEY_F7 },
1858 { 0x18, SONYPI_EVENT_FNKEY_F8 },
1859 { 0x19, SONYPI_EVENT_FNKEY_F9 },
1860 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
1861 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
1862 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
1863 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
1864 { 0x21, SONYPI_EVENT_FNKEY_1 },
1865 { 0x22, SONYPI_EVENT_FNKEY_2 },
1866 { 0x31, SONYPI_EVENT_FNKEY_D },
1867 { 0x32, SONYPI_EVENT_FNKEY_E },
1868 { 0x33, SONYPI_EVENT_FNKEY_F },
1869 { 0x34, SONYPI_EVENT_FNKEY_S },
1870 { 0x35, SONYPI_EVENT_FNKEY_B },
1871 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
1875 /* The set of possible program key events */
1876 static struct sonypi_event sonypi_pkeyev[] = {
1877 { 0x01, SONYPI_EVENT_PKEY_P1 },
1878 { 0x02, SONYPI_EVENT_PKEY_P2 },
1879 { 0x04, SONYPI_EVENT_PKEY_P3 },
1880 { 0x20, SONYPI_EVENT_PKEY_P1 },
1884 /* The set of possible bluetooth events */
1885 static struct sonypi_event sonypi_blueev[] = {
1886 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
1887 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
1888 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
1892 /* The set of possible wireless events */
1893 static struct sonypi_event sonypi_wlessev[] = {
1894 { 0x59, SONYPI_EVENT_IGNORE },
1895 { 0x5a, SONYPI_EVENT_IGNORE },
1899 /* The set of possible back button events */
1900 static struct sonypi_event sonypi_backev[] = {
1901 { 0x20, SONYPI_EVENT_BACK_PRESSED },
1905 /* The set of possible help button events */
1906 static struct sonypi_event sonypi_helpev[] = {
1907 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
1912 /* The set of possible lid events */
1913 static struct sonypi_event sonypi_lidev[] = {
1914 { 0x51, SONYPI_EVENT_LID_CLOSED },
1915 { 0x50, SONYPI_EVENT_LID_OPENED },
1919 /* The set of possible zoom events */
1920 static struct sonypi_event sonypi_zoomev[] = {
1921 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
1922 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
1923 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
1924 { 0x04, SONYPI_EVENT_ZOOM_PRESSED },
1928 /* The set of possible thumbphrase events */
1929 static struct sonypi_event sonypi_thumbphraseev[] = {
1930 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
1934 /* The set of possible motioneye camera events */
1935 static struct sonypi_event sonypi_meyeev[] = {
1936 { 0x00, SONYPI_EVENT_MEYE_FACE },
1937 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
1941 /* The set of possible memorystick events */
1942 static struct sonypi_event sonypi_memorystickev[] = {
1943 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
1944 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
1948 /* The set of possible battery events */
1949 static struct sonypi_event sonypi_batteryev[] = {
1950 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
1951 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
1955 /* The set of possible volume events */
1956 static struct sonypi_event sonypi_volumeev[] = {
1957 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED },
1958 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED },
1962 /* The set of possible brightness events */
1963 static struct sonypi_event sonypi_brightnessev[] = {
1964 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED },
1968 static struct sonypi_eventtypes type1_events[] = {
1969 { 0, 0xffffffff, sonypi_releaseev },
1970 { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
1971 { 0x30, SONYPI_LID_MASK, sonypi_lidev },
1972 { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
1973 { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
1974 { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1975 { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1976 { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
1977 { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1978 { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
1981 static struct sonypi_eventtypes type2_events[] = {
1982 { 0, 0xffffffff, sonypi_releaseev },
1983 { 0x38, SONYPI_LID_MASK, sonypi_lidev },
1984 { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
1985 { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
1986 { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1987 { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1988 { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
1989 { 0x11, SONYPI_BACK_MASK, sonypi_backev },
1990 { 0x21, SONYPI_HELP_MASK, sonypi_helpev },
1991 { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
1992 { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
1993 { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1994 { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1995 { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1998 static struct sonypi_eventtypes type3_events[] = {
1999 { 0, 0xffffffff, sonypi_releaseev },
2000 { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
2001 { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
2002 { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
2003 { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
2004 { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
2005 { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
2006 { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
2007 { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
2008 { 0x05, SONYPI_PKEY_MASK, sonypi_volumeev },
2009 { 0x05, SONYPI_PKEY_MASK, sonypi_brightnessev },
2013 /* low level spic calls */
2014 #define ITERATIONS_LONG 10000
2015 #define ITERATIONS_SHORT 10
2016 #define wait_on_command(command, iterations) { \
2017 unsigned int n = iterations; \
2018 while (--n && (command)) \
2021 dprintk("command failed at %s : %s (line %d)\n", \
2022 __FILE__, __func__, __LINE__); \
2025 static u8 sony_pic_call1(u8 dev)
2029 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
2031 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
2032 v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
2033 v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
2034 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
2038 static u8 sony_pic_call2(u8 dev, u8 fn)
2042 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
2044 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
2045 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
2047 outb(fn, spic_dev.cur_ioport->io1.minimum);
2048 v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
2049 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
2053 static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
2057 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
2058 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
2059 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
2060 outb(fn, spic_dev.cur_ioport->io1.minimum);
2061 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
2062 outb(v, spic_dev.cur_ioport->io1.minimum);
2063 v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
2064 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
2070 * minidrivers for SPIC models
2072 static int type3_handle_irq(const u8 data_mask, const u8 ev)
2075 * 0x31 could mean we have to take some extra action and wait for
2076 * the next irq for some Type3 models, it will generate a new
2077 * irq and we can read new data from the device:
2078 * - 0x5c and 0x5f requires 0xA0
2079 * - 0x61 requires 0xB3
2081 if (data_mask == 0x31) {
2082 if (ev == 0x5c || ev == 0x5f)
2083 sony_pic_call1(0xA0);
2084 else if (ev == 0x61)
2085 sony_pic_call1(0xB3);
2091 static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
2093 struct pci_dev *pcidev;
2095 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
2096 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
2098 dev->model = SONYPI_DEVICE_TYPE1;
2099 dev->evport_offset = SONYPI_TYPE1_OFFSET;
2100 dev->event_types = type1_events;
2104 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
2105 PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
2107 dev->model = SONYPI_DEVICE_TYPE2;
2108 dev->evport_offset = SONYPI_TYPE2_OFFSET;
2109 dev->event_types = type2_events;
2113 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
2114 PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
2116 dev->model = SONYPI_DEVICE_TYPE3;
2117 dev->handle_irq = type3_handle_irq;
2118 dev->evport_offset = SONYPI_TYPE3_OFFSET;
2119 dev->event_types = type3_events;
2123 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
2124 PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
2126 dev->model = SONYPI_DEVICE_TYPE3;
2127 dev->handle_irq = type3_handle_irq;
2128 dev->evport_offset = SONYPI_TYPE3_OFFSET;
2129 dev->event_types = type3_events;
2133 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
2134 PCI_DEVICE_ID_INTEL_ICH9_1, NULL);
2136 dev->model = SONYPI_DEVICE_TYPE3;
2137 dev->handle_irq = type3_handle_irq;
2138 dev->evport_offset = SONYPI_TYPE3_OFFSET;
2139 dev->event_types = type3_events;
2144 dev->model = SONYPI_DEVICE_TYPE2;
2145 dev->evport_offset = SONYPI_TYPE2_OFFSET;
2146 dev->event_types = type2_events;
2150 pci_dev_put(pcidev);
2152 pr_info(DRV_PFX "detected Type%d model\n",
2153 dev->model == SONYPI_DEVICE_TYPE1 ? 1 :
2154 dev->model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
2157 /* camera tests and poweron/poweroff */
2158 #define SONYPI_CAMERA_PICTURE 5
2159 #define SONYPI_CAMERA_CONTROL 0x10
2161 #define SONYPI_CAMERA_BRIGHTNESS 0
2162 #define SONYPI_CAMERA_CONTRAST 1
2163 #define SONYPI_CAMERA_HUE 2
2164 #define SONYPI_CAMERA_COLOR 3
2165 #define SONYPI_CAMERA_SHARPNESS 4
2167 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
2168 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
2169 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
2170 #define SONYPI_CAMERA_MUTE_MASK 0x40
2172 /* the rest don't need a loop until not 0xff */
2173 #define SONYPI_CAMERA_AGC 6
2174 #define SONYPI_CAMERA_AGC_MASK 0x30
2175 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
2177 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
2178 #define SONYPI_CAMERA_CONTROL 0x10
2180 #define SONYPI_CAMERA_STATUS 7
2181 #define SONYPI_CAMERA_STATUS_READY 0x2
2182 #define SONYPI_CAMERA_STATUS_POSITION 0x4
2184 #define SONYPI_DIRECTION_BACKWARDS 0x4
2186 #define SONYPI_CAMERA_REVISION 8
2187 #define SONYPI_CAMERA_ROMVERSION 9
2189 static int __sony_pic_camera_ready(void)
2193 v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
2194 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
2197 static int __sony_pic_camera_off(void)
2200 pr_warn(DRV_PFX "camera control not enabled\n");
2204 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
2205 SONYPI_CAMERA_MUTE_MASK),
2208 if (spic_dev.camera_power) {
2209 sony_pic_call2(0x91, 0);
2210 spic_dev.camera_power = 0;
2215 static int __sony_pic_camera_on(void)
2220 pr_warn(DRV_PFX "camera control not enabled\n");
2224 if (spic_dev.camera_power)
2227 for (j = 5; j > 0; j--) {
2229 for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
2231 sony_pic_call1(0x93);
2233 for (i = 400; i > 0; i--) {
2234 if (__sony_pic_camera_ready())
2243 pr_warn(DRV_PFX "failed to power on camera\n");
2247 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
2251 spic_dev.camera_power = 1;
2255 /* External camera command (exported to the motion eye v4l driver) */
2256 int sony_pic_camera_command(int command, u8 value)
2261 mutex_lock(&spic_dev.lock);
2264 case SONY_PIC_COMMAND_SETCAMERA:
2266 __sony_pic_camera_on();
2268 __sony_pic_camera_off();
2270 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
2271 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
2274 case SONY_PIC_COMMAND_SETCAMERACONTRAST:
2275 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
2278 case SONY_PIC_COMMAND_SETCAMERAHUE:
2279 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
2282 case SONY_PIC_COMMAND_SETCAMERACOLOR:
2283 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
2286 case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
2287 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
2290 case SONY_PIC_COMMAND_SETCAMERAPICTURE:
2291 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
2294 case SONY_PIC_COMMAND_SETCAMERAAGC:
2295 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
2299 pr_err(DRV_PFX "sony_pic_camera_command invalid: %d\n",
2303 mutex_unlock(&spic_dev.lock);
2306 EXPORT_SYMBOL(sony_pic_camera_command);
2308 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
2309 static void __sony_pic_set_wwanpower(u8 state)
2312 if (spic_dev.wwan_power == state)
2314 sony_pic_call2(0xB0, state);
2315 sony_pic_call1(0x82);
2316 spic_dev.wwan_power = state;
2319 static ssize_t sony_pic_wwanpower_store(struct device *dev,
2320 struct device_attribute *attr,
2321 const char *buffer, size_t count)
2323 unsigned long value;
2327 value = simple_strtoul(buffer, NULL, 10);
2328 mutex_lock(&spic_dev.lock);
2329 __sony_pic_set_wwanpower(value);
2330 mutex_unlock(&spic_dev.lock);
2335 static ssize_t sony_pic_wwanpower_show(struct device *dev,
2336 struct device_attribute *attr, char *buffer)
2339 mutex_lock(&spic_dev.lock);
2340 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
2341 mutex_unlock(&spic_dev.lock);
2345 /* bluetooth subsystem power state */
2346 static void __sony_pic_set_bluetoothpower(u8 state)
2349 if (spic_dev.bluetooth_power == state)
2351 sony_pic_call2(0x96, state);
2352 sony_pic_call1(0x82);
2353 spic_dev.bluetooth_power = state;
2356 static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
2357 struct device_attribute *attr,
2358 const char *buffer, size_t count)
2360 unsigned long value;
2364 value = simple_strtoul(buffer, NULL, 10);
2365 mutex_lock(&spic_dev.lock);
2366 __sony_pic_set_bluetoothpower(value);
2367 mutex_unlock(&spic_dev.lock);
2372 static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
2373 struct device_attribute *attr, char *buffer)
2376 mutex_lock(&spic_dev.lock);
2377 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
2378 mutex_unlock(&spic_dev.lock);
2383 /* FAN0 information (reverse engineered from ACPI tables) */
2384 #define SONY_PIC_FAN0_STATUS 0x93
2385 static int sony_pic_set_fanspeed(unsigned long value)
2387 return ec_write(SONY_PIC_FAN0_STATUS, value);
2390 static int sony_pic_get_fanspeed(u8 *value)
2392 return ec_read(SONY_PIC_FAN0_STATUS, value);
2395 static ssize_t sony_pic_fanspeed_store(struct device *dev,
2396 struct device_attribute *attr,
2397 const char *buffer, size_t count)
2399 unsigned long value;
2403 value = simple_strtoul(buffer, NULL, 10);
2404 if (sony_pic_set_fanspeed(value))
2410 static ssize_t sony_pic_fanspeed_show(struct device *dev,
2411 struct device_attribute *attr, char *buffer)
2414 if (sony_pic_get_fanspeed(&value))
2417 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
2420 #define SPIC_ATTR(_name, _mode) \
2421 struct device_attribute spic_attr_##_name = __ATTR(_name, \
2422 _mode, sony_pic_## _name ##_show, \
2423 sony_pic_## _name ##_store)
2425 static SPIC_ATTR(bluetoothpower, 0644);
2426 static SPIC_ATTR(wwanpower, 0644);
2427 static SPIC_ATTR(fanspeed, 0644);
2429 static struct attribute *spic_attributes[] = {
2430 &spic_attr_bluetoothpower.attr,
2431 &spic_attr_wwanpower.attr,
2432 &spic_attr_fanspeed.attr,
2436 static struct attribute_group spic_attribute_group = {
2437 .attrs = spic_attributes
2440 /******** SONYPI compatibility **********/
2441 #ifdef CONFIG_SONYPI_COMPAT
2443 /* battery / brightness / temperature addresses */
2444 #define SONYPI_BAT_FLAGS 0x81
2445 #define SONYPI_LCD_LIGHT 0x96
2446 #define SONYPI_BAT1_PCTRM 0xa0
2447 #define SONYPI_BAT1_LEFT 0xa2
2448 #define SONYPI_BAT1_MAXRT 0xa4
2449 #define SONYPI_BAT2_PCTRM 0xa8
2450 #define SONYPI_BAT2_LEFT 0xaa
2451 #define SONYPI_BAT2_MAXRT 0xac
2452 #define SONYPI_BAT1_MAXTK 0xb0
2453 #define SONYPI_BAT1_FULL 0xb2
2454 #define SONYPI_BAT2_MAXTK 0xb8
2455 #define SONYPI_BAT2_FULL 0xba
2456 #define SONYPI_TEMP_STATUS 0xC1
2458 struct sonypi_compat_s {
2459 struct fasync_struct *fifo_async;
2461 spinlock_t fifo_lock;
2462 wait_queue_head_t fifo_proc_list;
2463 atomic_t open_count;
2465 static struct sonypi_compat_s sonypi_compat = {
2466 .open_count = ATOMIC_INIT(0),
2469 static int sonypi_misc_fasync(int fd, struct file *filp, int on)
2471 return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
2474 static int sonypi_misc_release(struct inode *inode, struct file *file)
2476 atomic_dec(&sonypi_compat.open_count);
2480 static int sonypi_misc_open(struct inode *inode, struct file *file)
2482 /* Flush input queue on first open */
2483 unsigned long flags;
2485 spin_lock_irqsave(&sonypi_compat.fifo_lock, flags);
2487 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
2488 kfifo_reset(&sonypi_compat.fifo);
2490 spin_unlock_irqrestore(&sonypi_compat.fifo_lock, flags);
2495 static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
2496 size_t count, loff_t *pos)
2501 if ((kfifo_len(&sonypi_compat.fifo) == 0) &&
2502 (file->f_flags & O_NONBLOCK))
2505 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
2506 kfifo_len(&sonypi_compat.fifo) != 0);
2510 while (ret < count &&
2511 (kfifo_out_locked(&sonypi_compat.fifo, &c, sizeof(c),
2512 &sonypi_compat.fifo_lock) == sizeof(c))) {
2513 if (put_user(c, buf++))
2519 struct inode *inode = file->f_path.dentry->d_inode;
2520 inode->i_atime = current_fs_time(inode->i_sb);
2526 static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
2528 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
2529 if (kfifo_len(&sonypi_compat.fifo))
2530 return POLLIN | POLLRDNORM;
2534 static int ec_read16(u8 addr, u16 *value)
2537 if (ec_read(addr, &val_lb))
2539 if (ec_read(addr + 1, &val_hb))
2541 *value = val_lb | (val_hb << 8);
2545 static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd,
2549 void __user *argp = (void __user *)arg;
2554 mutex_lock(&spic_dev.lock);
2556 case SONYPI_IOCGBRT:
2557 if (sony_backlight_device == NULL) {
2561 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
2565 val8 = ((value & 0xff) - 1) << 5;
2566 if (copy_to_user(argp, &val8, sizeof(val8)))
2569 case SONYPI_IOCSBRT:
2570 if (sony_backlight_device == NULL) {
2574 if (copy_from_user(&val8, argp, sizeof(val8))) {
2578 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
2579 (val8 >> 5) + 1, NULL)) {
2583 /* sync the backlight device status */
2584 sony_backlight_device->props.brightness =
2585 sony_backlight_get_brightness(sony_backlight_device);
2587 case SONYPI_IOCGBAT1CAP:
2588 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
2592 if (copy_to_user(argp, &val16, sizeof(val16)))
2595 case SONYPI_IOCGBAT1REM:
2596 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
2600 if (copy_to_user(argp, &val16, sizeof(val16)))
2603 case SONYPI_IOCGBAT2CAP:
2604 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
2608 if (copy_to_user(argp, &val16, sizeof(val16)))
2611 case SONYPI_IOCGBAT2REM:
2612 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
2616 if (copy_to_user(argp, &val16, sizeof(val16)))
2619 case SONYPI_IOCGBATFLAGS:
2620 if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
2625 if (copy_to_user(argp, &val8, sizeof(val8)))
2628 case SONYPI_IOCGBLUE:
2629 val8 = spic_dev.bluetooth_power;
2630 if (copy_to_user(argp, &val8, sizeof(val8)))
2633 case SONYPI_IOCSBLUE:
2634 if (copy_from_user(&val8, argp, sizeof(val8))) {
2638 __sony_pic_set_bluetoothpower(val8);
2641 case SONYPI_IOCGFAN:
2642 if (sony_pic_get_fanspeed(&val8)) {
2646 if (copy_to_user(argp, &val8, sizeof(val8)))
2649 case SONYPI_IOCSFAN:
2650 if (copy_from_user(&val8, argp, sizeof(val8))) {
2654 if (sony_pic_set_fanspeed(val8))
2657 /* GET Temperature (useful under APM) */
2658 case SONYPI_IOCGTEMP:
2659 if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
2663 if (copy_to_user(argp, &val8, sizeof(val8)))
2669 mutex_unlock(&spic_dev.lock);
2673 static const struct file_operations sonypi_misc_fops = {
2674 .owner = THIS_MODULE,
2675 .read = sonypi_misc_read,
2676 .poll = sonypi_misc_poll,
2677 .open = sonypi_misc_open,
2678 .release = sonypi_misc_release,
2679 .fasync = sonypi_misc_fasync,
2680 .unlocked_ioctl = sonypi_misc_ioctl,
2681 .llseek = noop_llseek,
2684 static struct miscdevice sonypi_misc_device = {
2685 .minor = MISC_DYNAMIC_MINOR,
2687 .fops = &sonypi_misc_fops,
2690 static void sonypi_compat_report_event(u8 event)
2692 kfifo_in_locked(&sonypi_compat.fifo, (unsigned char *)&event,
2693 sizeof(event), &sonypi_compat.fifo_lock);
2694 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
2695 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
2698 static int sonypi_compat_init(void)
2702 spin_lock_init(&sonypi_compat.fifo_lock);
2704 kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL);
2706 pr_err(DRV_PFX "kfifo_alloc failed\n");
2710 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
2713 sonypi_misc_device.minor = minor;
2714 error = misc_register(&sonypi_misc_device);
2716 pr_err(DRV_PFX "misc_register failed\n");
2717 goto err_free_kfifo;
2720 pr_info(DRV_PFX "device allocated minor is %d\n",
2721 sonypi_misc_device.minor);
2726 kfifo_free(&sonypi_compat.fifo);
2730 static void sonypi_compat_exit(void)
2732 misc_deregister(&sonypi_misc_device);
2733 kfifo_free(&sonypi_compat.fifo);
2736 static int sonypi_compat_init(void) { return 0; }
2737 static void sonypi_compat_exit(void) { }
2738 static void sonypi_compat_report_event(u8 event) { }
2739 #endif /* CONFIG_SONYPI_COMPAT */
2745 sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
2748 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
2750 switch (resource->type) {
2751 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
2753 /* start IO enumeration */
2754 struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
2758 list_add(&ioport->list, &dev->ioports);
2762 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
2763 /* end IO enumeration */
2766 case ACPI_RESOURCE_TYPE_IRQ:
2768 struct acpi_resource_irq *p = &resource->data.irq;
2769 struct sony_pic_irq *interrupt = NULL;
2770 if (!p || !p->interrupt_count) {
2772 * IRQ descriptors may have no IRQ# bits set,
2773 * particularly those those w/ _STA disabled
2775 dprintk("Blank IRQ resource\n");
2778 for (i = 0; i < p->interrupt_count; i++) {
2779 if (!p->interrupts[i]) {
2780 pr_warn(DRV_PFX "Invalid IRQ %d\n",
2784 interrupt = kzalloc(sizeof(*interrupt),
2789 list_add(&interrupt->list, &dev->interrupts);
2790 interrupt->irq.triggering = p->triggering;
2791 interrupt->irq.polarity = p->polarity;
2792 interrupt->irq.sharable = p->sharable;
2793 interrupt->irq.interrupt_count = 1;
2794 interrupt->irq.interrupts[0] = p->interrupts[i];
2798 case ACPI_RESOURCE_TYPE_IO:
2800 struct acpi_resource_io *io = &resource->data.io;
2801 struct sony_pic_ioport *ioport =
2802 list_first_entry(&dev->ioports, struct sony_pic_ioport, list);
2804 dprintk("Blank IO resource\n");
2808 if (!ioport->io1.minimum) {
2809 memcpy(&ioport->io1, io, sizeof(*io));
2810 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum,
2811 ioport->io1.address_length);
2813 else if (!ioport->io2.minimum) {
2814 memcpy(&ioport->io2, io, sizeof(*io));
2815 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum,
2816 ioport->io2.address_length);
2819 pr_err(DRV_PFX "Unknown SPIC Type, more than 2 IO Ports\n");
2825 dprintk("Resource %d isn't an IRQ nor an IO port\n",
2828 case ACPI_RESOURCE_TYPE_END_TAG:
2831 return AE_CTRL_TERMINATE;
2834 static int sony_pic_possible_resources(struct acpi_device *device)
2837 acpi_status status = AE_OK;
2842 /* get device status */
2843 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
2844 dprintk("Evaluating _STA\n");
2845 result = acpi_bus_get_status(device);
2847 pr_warn(DRV_PFX "Unable to read status\n");
2851 if (!device->status.enabled)
2852 dprintk("Device disabled\n");
2854 dprintk("Device enabled\n");
2857 * Query and parse 'method'
2859 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
2860 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
2861 sony_pic_read_possible_resource, &spic_dev);
2862 if (ACPI_FAILURE(status)) {
2863 pr_warn(DRV_PFX "Failure evaluating %s\n",
2872 * Disable the spic device by calling its _DIS method
2874 static int sony_pic_disable(struct acpi_device *device)
2876 acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL,
2879 if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND)
2882 dprintk("Device disabled\n");
2888 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
2890 * Call _SRS to set current resources
2892 static int sony_pic_enable(struct acpi_device *device,
2893 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
2897 /* Type 1 resource layout is:
2903 * Type 2 and 3 resource layout is:
2909 struct acpi_resource res1;
2910 struct acpi_resource res2;
2911 struct acpi_resource res3;
2912 struct acpi_resource res4;
2914 struct acpi_buffer buffer = { 0, NULL };
2916 if (!ioport || !irq)
2919 /* init acpi_buffer */
2920 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
2924 buffer.length = sizeof(*resource) + 1;
2925 buffer.pointer = resource;
2927 /* setup Type 1 resources */
2928 if (spic_dev.model == SONYPI_DEVICE_TYPE1) {
2930 /* setup io resources */
2931 resource->res1.type = ACPI_RESOURCE_TYPE_IO;
2932 resource->res1.length = sizeof(struct acpi_resource);
2933 memcpy(&resource->res1.data.io, &ioport->io1,
2934 sizeof(struct acpi_resource_io));
2936 resource->res2.type = ACPI_RESOURCE_TYPE_IO;
2937 resource->res2.length = sizeof(struct acpi_resource);
2938 memcpy(&resource->res2.data.io, &ioport->io2,
2939 sizeof(struct acpi_resource_io));
2941 /* setup irq resource */
2942 resource->res3.type = ACPI_RESOURCE_TYPE_IRQ;
2943 resource->res3.length = sizeof(struct acpi_resource);
2944 memcpy(&resource->res3.data.irq, &irq->irq,
2945 sizeof(struct acpi_resource_irq));
2946 /* we requested a shared irq */
2947 resource->res3.data.irq.sharable = ACPI_SHARED;
2949 resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
2952 /* setup Type 2/3 resources */
2954 /* setup io resource */
2955 resource->res1.type = ACPI_RESOURCE_TYPE_IO;
2956 resource->res1.length = sizeof(struct acpi_resource);
2957 memcpy(&resource->res1.data.io, &ioport->io1,
2958 sizeof(struct acpi_resource_io));
2960 /* setup irq resource */
2961 resource->res2.type = ACPI_RESOURCE_TYPE_IRQ;
2962 resource->res2.length = sizeof(struct acpi_resource);
2963 memcpy(&resource->res2.data.irq, &irq->irq,
2964 sizeof(struct acpi_resource_irq));
2965 /* we requested a shared irq */
2966 resource->res2.data.irq.sharable = ACPI_SHARED;
2968 resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
2971 /* Attempt to set the resource */
2972 dprintk("Evaluating _SRS\n");
2973 status = acpi_set_current_resources(device->handle, &buffer);
2975 /* check for total failure */
2976 if (ACPI_FAILURE(status)) {
2977 pr_err(DRV_PFX "Error evaluating _SRS\n");
2982 /* Necessary device initializations calls (from sonypi) */
2983 sony_pic_call1(0x82);
2984 sony_pic_call2(0x81, 0xff);
2985 sony_pic_call1(compat ? 0x92 : 0x82);
2994 * ISR: some event is available
2997 static irqreturn_t sony_pic_irq(int irq, void *dev_id)
3002 u8 device_event = 0;
3004 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
3006 ev = inb_p(dev->cur_ioport->io1.minimum);
3007 if (dev->cur_ioport->io2.minimum)
3008 data_mask = inb_p(dev->cur_ioport->io2.minimum);
3010 data_mask = inb_p(dev->cur_ioport->io1.minimum +
3011 dev->evport_offset);
3013 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
3014 ev, data_mask, dev->cur_ioport->io1.minimum,
3015 dev->evport_offset);
3017 if (ev == 0x00 || ev == 0xff)
3020 for (i = 0; dev->event_types[i].mask; i++) {
3022 if ((data_mask & dev->event_types[i].data) !=
3023 dev->event_types[i].data)
3026 if (!(mask & dev->event_types[i].mask))
3029 for (j = 0; dev->event_types[i].events[j].event; j++) {
3030 if (ev == dev->event_types[i].events[j].data) {
3032 dev->event_types[i].events[j].event;
3033 /* some events may require ignoring */
3040 /* Still not able to decode the event try to pass
3041 * it over to the minidriver
3043 if (dev->handle_irq && dev->handle_irq(data_mask, ev) == 0)
3046 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
3047 ev, data_mask, dev->cur_ioport->io1.minimum,
3048 dev->evport_offset);
3052 sony_laptop_report_input_event(device_event);
3053 acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event);
3054 sonypi_compat_report_event(device_event);
3063 static int sony_pic_remove(struct acpi_device *device, int type)
3065 struct sony_pic_ioport *io, *tmp_io;
3066 struct sony_pic_irq *irq, *tmp_irq;
3068 if (sony_pic_disable(device)) {
3069 pr_err(DRV_PFX "Couldn't disable device.\n");
3073 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
3074 release_region(spic_dev.cur_ioport->io1.minimum,
3075 spic_dev.cur_ioport->io1.address_length);
3076 if (spic_dev.cur_ioport->io2.minimum)
3077 release_region(spic_dev.cur_ioport->io2.minimum,
3078 spic_dev.cur_ioport->io2.address_length);
3080 sonypi_compat_exit();
3082 sony_laptop_remove_input();
3085 sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
3088 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
3089 list_del(&io->list);
3092 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
3093 list_del(&irq->list);
3096 spic_dev.cur_ioport = NULL;
3097 spic_dev.cur_irq = NULL;
3099 dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
3103 static int sony_pic_add(struct acpi_device *device)
3106 struct sony_pic_ioport *io, *tmp_io;
3107 struct sony_pic_irq *irq, *tmp_irq;
3109 pr_info(DRV_PFX "%s v%s.\n", SONY_PIC_DRIVER_NAME,
3110 SONY_LAPTOP_DRIVER_VERSION);
3112 spic_dev.acpi_dev = device;
3113 strcpy(acpi_device_class(device), "sony/hotkey");
3114 sony_pic_detect_device_type(&spic_dev);
3115 mutex_init(&spic_dev.lock);
3117 /* read _PRS resources */
3118 result = sony_pic_possible_resources(device);
3120 pr_err(DRV_PFX "Unable to read possible resources.\n");
3121 goto err_free_resources;
3124 /* setup input devices and helper fifo */
3125 result = sony_laptop_setup_input(device);
3127 pr_err(DRV_PFX "Unable to create input devices.\n");
3128 goto err_free_resources;
3131 if (sonypi_compat_init())
3132 goto err_remove_input;
3134 /* request io port */
3135 list_for_each_entry_reverse(io, &spic_dev.ioports, list) {
3136 if (request_region(io->io1.minimum, io->io1.address_length,
3137 "Sony Programmable I/O Device")) {
3138 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
3139 io->io1.minimum, io->io1.maximum,
3140 io->io1.address_length);
3141 /* Type 1 have 2 ioports */
3142 if (io->io2.minimum) {
3143 if (request_region(io->io2.minimum,
3144 io->io2.address_length,
3145 "Sony Programmable I/O Device")) {
3146 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
3147 io->io2.minimum, io->io2.maximum,
3148 io->io2.address_length);
3149 spic_dev.cur_ioport = io;
3153 dprintk("Unable to get I/O port2: "
3154 "0x%.4x (0x%.4x) + 0x%.2x\n",
3155 io->io2.minimum, io->io2.maximum,
3156 io->io2.address_length);
3157 release_region(io->io1.minimum,
3158 io->io1.address_length);
3162 spic_dev.cur_ioport = io;
3167 if (!spic_dev.cur_ioport) {
3168 pr_err(DRV_PFX "Failed to request_region.\n");
3170 goto err_remove_compat;
3174 list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
3175 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
3176 IRQF_DISABLED, "sony-laptop", &spic_dev)) {
3177 dprintk("IRQ: %d - triggering: %d - "
3178 "polarity: %d - shr: %d\n",
3179 irq->irq.interrupts[0],
3180 irq->irq.triggering,
3183 spic_dev.cur_irq = irq;
3187 if (!spic_dev.cur_irq) {
3188 pr_err(DRV_PFX "Failed to request_irq.\n");
3190 goto err_release_region;
3193 /* set resource status _SRS */
3194 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
3196 pr_err(DRV_PFX "Couldn't enable device.\n");
3200 spic_dev.bluetooth_power = -1;
3201 /* create device attributes */
3202 result = sony_pf_add();
3204 goto err_disable_device;
3206 result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
3216 sony_pic_disable(device);
3219 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
3222 release_region(spic_dev.cur_ioport->io1.minimum,
3223 spic_dev.cur_ioport->io1.address_length);
3224 if (spic_dev.cur_ioport->io2.minimum)
3225 release_region(spic_dev.cur_ioport->io2.minimum,
3226 spic_dev.cur_ioport->io2.address_length);
3229 sonypi_compat_exit();
3232 sony_laptop_remove_input();
3235 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
3236 list_del(&io->list);
3239 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
3240 list_del(&irq->list);
3243 spic_dev.cur_ioport = NULL;
3244 spic_dev.cur_irq = NULL;
3249 static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
3251 if (sony_pic_disable(device))
3256 static int sony_pic_resume(struct acpi_device *device)
3258 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
3262 static const struct acpi_device_id sony_pic_device_ids[] = {
3267 static struct acpi_driver sony_pic_driver = {
3268 .name = SONY_PIC_DRIVER_NAME,
3269 .class = SONY_PIC_CLASS,
3270 .ids = sony_pic_device_ids,
3271 .owner = THIS_MODULE,
3273 .add = sony_pic_add,
3274 .remove = sony_pic_remove,
3275 .suspend = sony_pic_suspend,
3276 .resume = sony_pic_resume,
3280 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
3282 .ident = "Sony Vaio",
3284 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
3285 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
3289 .ident = "Sony Vaio",
3291 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
3292 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
3298 static int __init sony_laptop_init(void)
3302 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
3303 result = acpi_bus_register_driver(&sony_pic_driver);
3305 pr_err(DRV_PFX "Unable to register SPIC driver.");
3308 spic_drv_registered = 1;
3311 result = acpi_bus_register_driver(&sony_nc_driver);
3313 pr_err(DRV_PFX "Unable to register SNC driver.");
3314 goto out_unregister_pic;
3320 if (spic_drv_registered)
3321 acpi_bus_unregister_driver(&sony_pic_driver);
3326 static void __exit sony_laptop_exit(void)
3328 acpi_bus_unregister_driver(&sony_nc_driver);
3329 if (spic_drv_registered)
3330 acpi_bus_unregister_driver(&sony_pic_driver);
3333 module_init(sony_laptop_init);
3334 module_exit(sony_laptop_exit);