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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
47 #include <linux/kernel.h>
48 #include <linux/module.h>
49 #include <linux/moduleparam.h>
50 #include <linux/init.h>
51 #include <linux/types.h>
52 #include <linux/backlight.h>
53 #include <linux/platform_device.h>
54 #include <linux/err.h>
55 #include <linux/dmi.h>
56 #include <linux/pci.h>
57 #include <linux/interrupt.h>
58 #include <linux/delay.h>
59 #include <linux/input.h>
60 #include <linux/kfifo.h>
61 #include <linux/workqueue.h>
62 #include <linux/acpi.h>
63 #include <linux/slab.h>
64 #include <acpi/acpi_drivers.h>
65 #include <acpi/acpi_bus.h>
66 #include <asm/uaccess.h>
67 #include <linux/sonypi.h>
68 #include <linux/sony-laptop.h>
69 #include <linux/rfkill.h>
70 #ifdef CONFIG_SONYPI_COMPAT
71 #include <linux/poll.h>
72 #include <linux/miscdevice.h>
75 #define dprintk(fmt, ...) \
78 pr_warn(fmt, ##__VA_ARGS__); \
81 #define SONY_LAPTOP_DRIVER_VERSION "0.6"
83 #define SONY_NC_CLASS "sony-nc"
84 #define SONY_NC_HID "SNY5001"
85 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
87 #define SONY_PIC_CLASS "sony-pic"
88 #define SONY_PIC_HID "SNY6001"
89 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
91 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
92 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
93 MODULE_LICENSE("GPL");
94 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION
);
97 module_param(debug
, int, 0);
98 MODULE_PARM_DESC(debug
, "set this to 1 (and RTFM) if you want to help "
99 "the development of this driver");
101 static int no_spic
; /* = 0 */
102 module_param(no_spic
, int, 0444);
103 MODULE_PARM_DESC(no_spic
,
104 "set this if you don't want to enable the SPIC device");
106 static int compat
; /* = 0 */
107 module_param(compat
, int, 0444);
108 MODULE_PARM_DESC(compat
,
109 "set this if you want to enable backward compatibility mode");
111 static unsigned long mask
= 0xffffffff;
112 module_param(mask
, ulong
, 0644);
113 MODULE_PARM_DESC(mask
,
114 "set this to the mask of event you want to enable (see doc)");
116 static int camera
; /* = 0 */
117 module_param(camera
, int, 0444);
118 MODULE_PARM_DESC(camera
,
119 "set this to 1 to enable Motion Eye camera controls "
120 "(only use it if you have a C1VE or C1VN model)");
122 #ifdef CONFIG_SONYPI_COMPAT
123 static int minor
= -1;
124 module_param(minor
, int, 0);
125 MODULE_PARM_DESC(minor
,
126 "minor number of the misc device for the SPIC compatibility code, "
127 "default is -1 (automatic)");
130 static int kbd_backlight
= 1;
131 module_param(kbd_backlight
, int, 0444);
132 MODULE_PARM_DESC(kbd_backlight
,
133 "set this to 0 to disable keyboard backlight, "
134 "1 to enable it (default: 0)");
136 static int kbd_backlight_timeout
; /* = 0 */
137 module_param(kbd_backlight_timeout
, int, 0444);
138 MODULE_PARM_DESC(kbd_backlight_timeout
,
139 "set this to 0 to set the default 10 seconds timeout, "
140 "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout "
143 static void sony_nc_kbd_backlight_resume(void);
144 static void sony_nc_kbd_backlight_setup(struct platform_device
*pd
);
145 static int sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
);
147 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
148 unsigned int handle
);
149 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
);
151 static int sony_nc_thermal_setup(struct platform_device
*pd
);
152 static void sony_nc_thermal_cleanup(struct platform_device
*pd
);
153 static void sony_nc_thermal_resume(void);
155 enum sony_nc_rfkill
{
163 static int sony_rfkill_handle
;
164 static struct rfkill
*sony_rfkill_devices
[N_SONY_RFKILL
];
165 static int sony_rfkill_address
[N_SONY_RFKILL
] = {0x300, 0x500, 0x700, 0x900};
166 static void sony_nc_rfkill_setup(struct acpi_device
*device
);
167 static void sony_nc_rfkill_cleanup(void);
168 static void sony_nc_rfkill_update(void);
170 /*********** Input Devices ***********/
172 #define SONY_LAPTOP_BUF_SIZE 128
173 struct sony_laptop_input_s
{
175 struct input_dev
*jog_dev
;
176 struct input_dev
*key_dev
;
178 spinlock_t fifo_lock
;
179 struct timer_list release_key_timer
;
182 static struct sony_laptop_input_s sony_laptop_input
= {
183 .users
= ATOMIC_INIT(0),
186 struct sony_laptop_keypress
{
187 struct input_dev
*dev
;
191 /* Correspondance table between sonypi events
192 * and input layer indexes in the keymap
194 static int sony_laptop_input_index
[] = {
196 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
197 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
198 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
199 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
200 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
201 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
202 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
203 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
204 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
205 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
206 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
207 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
208 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
209 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
210 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
211 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
212 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
213 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
214 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
215 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
216 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
217 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
218 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
219 17, /* 24 SONYPI_EVENT_FNKEY_1 */
220 18, /* 25 SONYPI_EVENT_FNKEY_2 */
221 19, /* 26 SONYPI_EVENT_FNKEY_D */
222 20, /* 27 SONYPI_EVENT_FNKEY_E */
223 21, /* 28 SONYPI_EVENT_FNKEY_F */
224 22, /* 29 SONYPI_EVENT_FNKEY_S */
225 23, /* 30 SONYPI_EVENT_FNKEY_B */
226 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
227 25, /* 32 SONYPI_EVENT_PKEY_P1 */
228 26, /* 33 SONYPI_EVENT_PKEY_P2 */
229 27, /* 34 SONYPI_EVENT_PKEY_P3 */
230 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
231 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
232 -1, /* 37 SONYPI_EVENT_LID_OPENED */
233 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
234 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
235 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
236 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
237 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
238 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
239 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
240 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
241 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
242 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
243 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
244 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
245 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
246 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
247 43, /* 52 SONYPI_EVENT_MEYE_FACE */
248 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
249 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
250 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
251 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
252 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
253 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
254 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
255 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
256 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
257 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
258 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
259 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
260 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
261 53, /* 66 SONYPI_EVENT_PKEY_P4 */
262 54, /* 67 SONYPI_EVENT_PKEY_P5 */
263 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
264 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
265 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
266 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
267 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
268 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */
271 static int sony_laptop_input_keycode_map
[] = {
272 KEY_CAMERA
, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
273 KEY_RESERVED
, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
274 KEY_RESERVED
, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
275 KEY_RESERVED
, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
276 KEY_FN_ESC
, /* 4 SONYPI_EVENT_FNKEY_ESC */
277 KEY_FN_F1
, /* 5 SONYPI_EVENT_FNKEY_F1 */
278 KEY_FN_F2
, /* 6 SONYPI_EVENT_FNKEY_F2 */
279 KEY_FN_F3
, /* 7 SONYPI_EVENT_FNKEY_F3 */
280 KEY_FN_F4
, /* 8 SONYPI_EVENT_FNKEY_F4 */
281 KEY_FN_F5
, /* 9 SONYPI_EVENT_FNKEY_F5 */
282 KEY_FN_F6
, /* 10 SONYPI_EVENT_FNKEY_F6 */
283 KEY_FN_F7
, /* 11 SONYPI_EVENT_FNKEY_F7 */
284 KEY_FN_F8
, /* 12 SONYPI_EVENT_FNKEY_F8 */
285 KEY_FN_F9
, /* 13 SONYPI_EVENT_FNKEY_F9 */
286 KEY_FN_F10
, /* 14 SONYPI_EVENT_FNKEY_F10 */
287 KEY_FN_F11
, /* 15 SONYPI_EVENT_FNKEY_F11 */
288 KEY_FN_F12
, /* 16 SONYPI_EVENT_FNKEY_F12 */
289 KEY_FN_F1
, /* 17 SONYPI_EVENT_FNKEY_1 */
290 KEY_FN_F2
, /* 18 SONYPI_EVENT_FNKEY_2 */
291 KEY_FN_D
, /* 19 SONYPI_EVENT_FNKEY_D */
292 KEY_FN_E
, /* 20 SONYPI_EVENT_FNKEY_E */
293 KEY_FN_F
, /* 21 SONYPI_EVENT_FNKEY_F */
294 KEY_FN_S
, /* 22 SONYPI_EVENT_FNKEY_S */
295 KEY_FN_B
, /* 23 SONYPI_EVENT_FNKEY_B */
296 KEY_BLUETOOTH
, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
297 KEY_PROG1
, /* 25 SONYPI_EVENT_PKEY_P1 */
298 KEY_PROG2
, /* 26 SONYPI_EVENT_PKEY_P2 */
299 KEY_PROG3
, /* 27 SONYPI_EVENT_PKEY_P3 */
300 KEY_BACK
, /* 28 SONYPI_EVENT_BACK_PRESSED */
301 KEY_BLUETOOTH
, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
302 KEY_BLUETOOTH
, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
303 KEY_HELP
, /* 31 SONYPI_EVENT_HELP_PRESSED */
304 KEY_FN
, /* 32 SONYPI_EVENT_FNKEY_ONLY */
305 KEY_RESERVED
, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
306 KEY_RESERVED
, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
307 KEY_RESERVED
, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
308 KEY_RESERVED
, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
309 KEY_RESERVED
, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
310 KEY_RESERVED
, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
311 KEY_RESERVED
, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
312 KEY_RESERVED
, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
313 KEY_ZOOM
, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
314 BTN_THUMB
, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
315 KEY_RESERVED
, /* 43 SONYPI_EVENT_MEYE_FACE */
316 KEY_RESERVED
, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
317 KEY_RESERVED
, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
318 KEY_RESERVED
, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
319 KEY_WLAN
, /* 47 SONYPI_EVENT_WIRELESS_ON */
320 KEY_WLAN
, /* 48 SONYPI_EVENT_WIRELESS_OFF */
321 KEY_ZOOMIN
, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
322 KEY_ZOOMOUT
, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
323 KEY_EJECTCD
, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
324 KEY_F13
, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
325 KEY_PROG4
, /* 53 SONYPI_EVENT_PKEY_P4 */
326 KEY_F14
, /* 54 SONYPI_EVENT_PKEY_P5 */
327 KEY_F15
, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
328 KEY_VOLUMEUP
, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
329 KEY_VOLUMEDOWN
, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
330 KEY_MEDIA
, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
331 KEY_VENDOR
, /* 59 SONYPI_EVENT_VENDOR_PRESSED */
334 /* release buttons after a short delay if pressed */
335 static void do_sony_laptop_release_key(unsigned long unused
)
337 struct sony_laptop_keypress kp
;
340 spin_lock_irqsave(&sony_laptop_input
.fifo_lock
, flags
);
342 if (kfifo_out(&sony_laptop_input
.fifo
,
343 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
344 input_report_key(kp
.dev
, kp
.key
, 0);
348 /* If there is something in the fifo schedule next release. */
349 if (kfifo_len(&sony_laptop_input
.fifo
) != 0)
350 mod_timer(&sony_laptop_input
.release_key_timer
,
351 jiffies
+ msecs_to_jiffies(10));
353 spin_unlock_irqrestore(&sony_laptop_input
.fifo_lock
, flags
);
356 /* forward event to the input subsystem */
357 static void sony_laptop_report_input_event(u8 event
)
359 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
360 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
361 struct sony_laptop_keypress kp
= { NULL
};
364 if (event
== SONYPI_EVENT_FNKEY_RELEASED
||
365 event
== SONYPI_EVENT_ANYBUTTON_RELEASED
) {
366 /* Nothing, not all VAIOs generate this event */
373 case SONYPI_EVENT_JOGDIAL_UP
:
374 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
375 input_report_rel(jog_dev
, REL_WHEEL
, 1);
379 case SONYPI_EVENT_JOGDIAL_DOWN
:
380 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
381 input_report_rel(jog_dev
, REL_WHEEL
, -1);
386 case SONYPI_EVENT_JOGDIAL_PRESSED
:
392 if (event
>= ARRAY_SIZE(sony_laptop_input_index
)) {
393 dprintk("sony_laptop_report_input_event, event not known: %d\n", event
);
396 if ((scancode
= sony_laptop_input_index
[event
]) != -1) {
397 kp
.key
= sony_laptop_input_keycode_map
[scancode
];
398 if (kp
.key
!= KEY_UNKNOWN
)
405 /* if we have a scancode we emit it so we can always
408 input_event(kp
.dev
, EV_MSC
, MSC_SCAN
, scancode
);
409 input_report_key(kp
.dev
, kp
.key
, 1);
412 /* schedule key release */
413 kfifo_in_locked(&sony_laptop_input
.fifo
,
414 (unsigned char *)&kp
, sizeof(kp
),
415 &sony_laptop_input
.fifo_lock
);
416 mod_timer(&sony_laptop_input
.release_key_timer
,
417 jiffies
+ msecs_to_jiffies(10));
419 dprintk("unknown input event %.2x\n", event
);
422 static int sony_laptop_setup_input(struct acpi_device
*acpi_device
)
424 struct input_dev
*jog_dev
;
425 struct input_dev
*key_dev
;
429 /* don't run again if already initialized */
430 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
434 spin_lock_init(&sony_laptop_input
.fifo_lock
);
435 error
= kfifo_alloc(&sony_laptop_input
.fifo
,
436 SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
438 pr_err("kfifo_alloc failed\n");
442 setup_timer(&sony_laptop_input
.release_key_timer
,
443 do_sony_laptop_release_key
, 0);
446 key_dev
= input_allocate_device();
452 key_dev
->name
= "Sony Vaio Keys";
453 key_dev
->id
.bustype
= BUS_ISA
;
454 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
455 key_dev
->dev
.parent
= &acpi_device
->dev
;
457 /* Initialize the Input Drivers: special keys */
458 input_set_capability(key_dev
, EV_MSC
, MSC_SCAN
);
460 __set_bit(EV_KEY
, key_dev
->evbit
);
461 key_dev
->keycodesize
= sizeof(sony_laptop_input_keycode_map
[0]);
462 key_dev
->keycodemax
= ARRAY_SIZE(sony_laptop_input_keycode_map
);
463 key_dev
->keycode
= &sony_laptop_input_keycode_map
;
464 for (i
= 0; i
< ARRAY_SIZE(sony_laptop_input_keycode_map
); i
++)
465 __set_bit(sony_laptop_input_keycode_map
[i
], key_dev
->keybit
);
466 __clear_bit(KEY_RESERVED
, key_dev
->keybit
);
468 error
= input_register_device(key_dev
);
470 goto err_free_keydev
;
472 sony_laptop_input
.key_dev
= key_dev
;
475 jog_dev
= input_allocate_device();
478 goto err_unregister_keydev
;
481 jog_dev
->name
= "Sony Vaio Jogdial";
482 jog_dev
->id
.bustype
= BUS_ISA
;
483 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
484 jog_dev
->dev
.parent
= &acpi_device
->dev
;
486 input_set_capability(jog_dev
, EV_KEY
, BTN_MIDDLE
);
487 input_set_capability(jog_dev
, EV_REL
, REL_WHEEL
);
489 error
= input_register_device(jog_dev
);
491 goto err_free_jogdev
;
493 sony_laptop_input
.jog_dev
= jog_dev
;
498 input_free_device(jog_dev
);
500 err_unregister_keydev
:
501 input_unregister_device(key_dev
);
502 /* to avoid kref underflow below at input_free_device */
506 input_free_device(key_dev
);
509 kfifo_free(&sony_laptop_input
.fifo
);
512 atomic_dec(&sony_laptop_input
.users
);
516 static void sony_laptop_remove_input(void)
518 struct sony_laptop_keypress kp
= { NULL
};
520 /* Cleanup only after the last user has gone */
521 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
524 del_timer_sync(&sony_laptop_input
.release_key_timer
);
527 * Generate key-up events for remaining keys. Note that we don't
528 * need locking since nobody is adding new events to the kfifo.
530 while (kfifo_out(&sony_laptop_input
.fifo
,
531 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
532 input_report_key(kp
.dev
, kp
.key
, 0);
536 /* destroy input devs */
537 input_unregister_device(sony_laptop_input
.key_dev
);
538 sony_laptop_input
.key_dev
= NULL
;
540 if (sony_laptop_input
.jog_dev
) {
541 input_unregister_device(sony_laptop_input
.jog_dev
);
542 sony_laptop_input
.jog_dev
= NULL
;
545 kfifo_free(&sony_laptop_input
.fifo
);
548 /*********** Platform Device ***********/
550 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
551 static struct platform_driver sony_pf_driver
= {
553 .name
= "sony-laptop",
554 .owner
= THIS_MODULE
,
557 static struct platform_device
*sony_pf_device
;
559 static int sony_pf_add(void)
563 /* don't run again if already initialized */
564 if (atomic_add_return(1, &sony_pf_users
) > 1)
567 ret
= platform_driver_register(&sony_pf_driver
);
571 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
572 if (!sony_pf_device
) {
574 goto out_platform_registered
;
577 ret
= platform_device_add(sony_pf_device
);
579 goto out_platform_alloced
;
583 out_platform_alloced
:
584 platform_device_put(sony_pf_device
);
585 sony_pf_device
= NULL
;
586 out_platform_registered
:
587 platform_driver_unregister(&sony_pf_driver
);
589 atomic_dec(&sony_pf_users
);
593 static void sony_pf_remove(void)
595 /* deregister only after the last user has gone */
596 if (!atomic_dec_and_test(&sony_pf_users
))
599 platform_device_unregister(sony_pf_device
);
600 platform_driver_unregister(&sony_pf_driver
);
603 /*********** SNC (SNY5001) Device ***********/
605 /* the device uses 1-based values, while the backlight subsystem uses
607 #define SONY_MAX_BRIGHTNESS 8
609 #define SNC_VALIDATE_IN 0
610 #define SNC_VALIDATE_OUT 1
612 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
614 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
615 const char *, size_t);
616 static int boolean_validate(const int, const int);
617 static int brightness_default_validate(const int, const int);
619 struct sony_nc_value
{
620 char *name
; /* name of the entry */
621 char **acpiget
; /* names of the ACPI get function */
622 char **acpiset
; /* names of the ACPI set function */
623 int (*validate
)(const int, const int); /* input/output validation */
624 int value
; /* current setting */
625 int valid
; /* Has ever been set */
626 int debug
; /* active only in debug mode ? */
627 struct device_attribute devattr
; /* sysfs attribute */
630 #define SNC_HANDLE_NAMES(_name, _values...) \
631 static char *snc_##_name[] = { _values, NULL }
633 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
635 .name = __stringify(_name), \
636 .acpiget = _getters, \
637 .acpiset = _setters, \
638 .validate = _validate, \
640 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
643 #define SNC_HANDLE_NULL { .name = NULL }
645 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
647 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
648 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
650 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
651 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
653 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
654 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
656 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
657 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
659 SNC_HANDLE_NAMES(lidstate_get
, "GLID");
661 SNC_HANDLE_NAMES(indicatorlamp_get
, "GILS");
662 SNC_HANDLE_NAMES(indicatorlamp_set
, "SILS");
664 SNC_HANDLE_NAMES(gainbass_get
, "GMGB");
665 SNC_HANDLE_NAMES(gainbass_set
, "CMGB");
667 SNC_HANDLE_NAMES(PID_get
, "GPID");
669 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
670 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
672 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
673 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
675 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
676 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
678 static struct sony_nc_value sony_nc_values
[] = {
679 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
680 snc_brightness_def_set
, brightness_default_validate
, 0),
681 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
682 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
683 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
684 boolean_validate
, 0),
685 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
686 boolean_validate
, 1),
687 SNC_HANDLE(lidstate
, snc_lidstate_get
, NULL
,
688 boolean_validate
, 0),
689 SNC_HANDLE(indicatorlamp
, snc_indicatorlamp_get
, snc_indicatorlamp_set
,
690 boolean_validate
, 0),
691 SNC_HANDLE(gainbass
, snc_gainbass_get
, snc_gainbass_set
,
692 boolean_validate
, 0),
693 /* unknown methods */
694 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
695 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
696 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
697 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
701 static acpi_handle sony_nc_acpi_handle
;
702 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
705 * acpi_evaluate_object wrappers
706 * all useful calls into SNC methods take one or zero parameters and return
707 * integers or arrays.
709 static union acpi_object
*__call_snc_method(acpi_handle handle
, char *method
,
712 union acpi_object
*result
= NULL
;
713 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
717 struct acpi_object_list params
;
718 union acpi_object in
;
719 in
.type
= ACPI_TYPE_INTEGER
;
720 in
.integer
.value
= *value
;
722 params
.pointer
= &in
;
723 status
= acpi_evaluate_object(handle
, method
, ¶ms
, &output
);
724 dprintk("__call_snc_method: [%s:0x%.8x%.8x]\n", method
,
725 (unsigned int)(*value
>> 32),
726 (unsigned int)*value
& 0xffffffff);
728 status
= acpi_evaluate_object(handle
, method
, NULL
, &output
);
729 dprintk("__call_snc_method: [%s]\n", method
);
732 if (ACPI_FAILURE(status
)) {
733 pr_err("Failed to evaluate [%s]\n", method
);
737 result
= (union acpi_object
*) output
.pointer
;
739 dprintk("No return object [%s]\n", method
);
744 static int sony_nc_int_call(acpi_handle handle
, char *name
, int *value
,
747 union acpi_object
*object
= NULL
;
750 object
= __call_snc_method(handle
, name
, &v
);
752 object
= __call_snc_method(handle
, name
, NULL
);
757 if (object
->type
!= ACPI_TYPE_INTEGER
) {
758 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
759 ACPI_TYPE_INTEGER
, object
->type
);
765 *result
= object
->integer
.value
;
771 #define MIN(a, b) (a > b ? b : a)
772 static int sony_nc_buffer_call(acpi_handle handle
, char *name
, u64
*value
,
773 void *buffer
, size_t buflen
)
776 union acpi_object
*object
= __call_snc_method(handle
, name
, value
);
781 if (object
->type
== ACPI_TYPE_BUFFER
)
782 len
= MIN(buflen
, object
->buffer
.length
);
784 else if (object
->type
== ACPI_TYPE_INTEGER
)
785 len
= MIN(buflen
, sizeof(object
->integer
.value
));
788 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
789 ACPI_TYPE_BUFFER
, object
->type
);
794 memcpy(buffer
, object
->buffer
.pointer
, len
);
799 struct sony_nc_handles
{
801 struct device_attribute devattr
;
804 static struct sony_nc_handles
*handles
;
806 static ssize_t
sony_nc_handles_show(struct device
*dev
,
807 struct device_attribute
*attr
, char *buffer
)
812 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
813 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "0x%.4x ",
816 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "\n");
821 static int sony_nc_handles_setup(struct platform_device
*pd
)
823 int i
, r
, result
, arg
;
825 handles
= kzalloc(sizeof(*handles
), GFP_KERNEL
);
829 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
831 r
= sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
,
834 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
836 handles
->cap
[i
] = result
;
841 sysfs_attr_init(&handles
->devattr
.attr
);
842 handles
->devattr
.attr
.name
= "handles";
843 handles
->devattr
.attr
.mode
= S_IRUGO
;
844 handles
->devattr
.show
= sony_nc_handles_show
;
846 /* allow reading capabilities via sysfs */
847 if (device_create_file(&pd
->dev
, &handles
->devattr
)) {
857 static int sony_nc_handles_cleanup(struct platform_device
*pd
)
861 device_remove_file(&pd
->dev
, &handles
->devattr
);
868 static int sony_find_snc_handle(int handle
)
872 /* not initialized yet, return early */
873 if (!handles
|| !handle
)
876 for (i
= 0; i
< 0x10; i
++) {
877 if (handles
->cap
[i
] == handle
) {
878 dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
883 dprintk("handle 0x%.4x not found\n", handle
);
887 static int sony_call_snc_handle(int handle
, int argument
, int *result
)
890 int offset
= sony_find_snc_handle(handle
);
895 arg
= offset
| argument
;
896 ret
= sony_nc_int_call(sony_nc_acpi_handle
, "SN07", &arg
, result
);
897 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", arg
, *result
);
902 * sony_nc_values input/output validate functions
905 /* brightness_default_validate:
907 * manipulate input output values to keep consistency with the
908 * backlight framework for which brightness values are 0-based.
910 static int brightness_default_validate(const int direction
, const int value
)
913 case SNC_VALIDATE_OUT
:
915 case SNC_VALIDATE_IN
:
916 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
924 * on input validate boolean values 0/1, on output just pass the
927 static int boolean_validate(const int direction
, const int value
)
929 if (direction
== SNC_VALIDATE_IN
) {
930 if (value
!= 0 && value
!= 1)
937 * Sysfs show/store common to all sony_nc_values
939 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
943 struct sony_nc_value
*item
=
944 container_of(attr
, struct sony_nc_value
, devattr
);
949 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiget
, NULL
,
955 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
957 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
960 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
961 struct device_attribute
*attr
,
962 const char *buffer
, size_t count
)
964 unsigned long value
= 0;
966 struct sony_nc_value
*item
=
967 container_of(attr
, struct sony_nc_value
, devattr
);
975 if (kstrtoul(buffer
, 10, &value
))
979 value
= item
->validate(SNC_VALIDATE_IN
, value
);
984 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
985 (int *)&value
, NULL
);
998 struct sony_backlight_props
{
999 struct backlight_device
*dev
;
1004 struct sony_backlight_props sony_bl_props
;
1006 static int sony_backlight_update_status(struct backlight_device
*bd
)
1008 int arg
= bd
->props
.brightness
+ 1;
1009 return sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &arg
, NULL
);
1012 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
1016 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
, &value
))
1018 /* brightness levels are 1-based, while backlight ones are 0-based */
1022 static int sony_nc_get_brightness_ng(struct backlight_device
*bd
)
1025 struct sony_backlight_props
*sdev
=
1026 (struct sony_backlight_props
*)bl_get_data(bd
);
1028 sony_call_snc_handle(sdev
->handle
, 0x0200, &result
);
1030 return (result
& 0xff) - sdev
->offset
;
1033 static int sony_nc_update_status_ng(struct backlight_device
*bd
)
1036 struct sony_backlight_props
*sdev
=
1037 (struct sony_backlight_props
*)bl_get_data(bd
);
1039 value
= bd
->props
.brightness
+ sdev
->offset
;
1040 if (sony_call_snc_handle(sdev
->handle
, 0x0100 | (value
<< 16), &result
))
1046 static const struct backlight_ops sony_backlight_ops
= {
1047 .options
= BL_CORE_SUSPENDRESUME
,
1048 .update_status
= sony_backlight_update_status
,
1049 .get_brightness
= sony_backlight_get_brightness
,
1051 static const struct backlight_ops sony_backlight_ng_ops
= {
1052 .options
= BL_CORE_SUSPENDRESUME
,
1053 .update_status
= sony_nc_update_status_ng
,
1054 .get_brightness
= sony_nc_get_brightness_ng
,
1058 * New SNC-only Vaios event mapping to driver known keys
1060 struct sony_nc_event
{
1065 static struct sony_nc_event sony_100_events
[] = {
1066 { 0x90, SONYPI_EVENT_PKEY_P1
},
1067 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1068 { 0x91, SONYPI_EVENT_PKEY_P2
},
1069 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1070 { 0x81, SONYPI_EVENT_FNKEY_F1
},
1071 { 0x01, SONYPI_EVENT_FNKEY_RELEASED
},
1072 { 0x82, SONYPI_EVENT_FNKEY_F2
},
1073 { 0x02, SONYPI_EVENT_FNKEY_RELEASED
},
1074 { 0x83, SONYPI_EVENT_FNKEY_F3
},
1075 { 0x03, SONYPI_EVENT_FNKEY_RELEASED
},
1076 { 0x84, SONYPI_EVENT_FNKEY_F4
},
1077 { 0x04, SONYPI_EVENT_FNKEY_RELEASED
},
1078 { 0x85, SONYPI_EVENT_FNKEY_F5
},
1079 { 0x05, SONYPI_EVENT_FNKEY_RELEASED
},
1080 { 0x86, SONYPI_EVENT_FNKEY_F6
},
1081 { 0x06, SONYPI_EVENT_FNKEY_RELEASED
},
1082 { 0x87, SONYPI_EVENT_FNKEY_F7
},
1083 { 0x07, SONYPI_EVENT_FNKEY_RELEASED
},
1084 { 0x89, SONYPI_EVENT_FNKEY_F9
},
1085 { 0x09, SONYPI_EVENT_FNKEY_RELEASED
},
1086 { 0x8A, SONYPI_EVENT_FNKEY_F10
},
1087 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED
},
1088 { 0x8C, SONYPI_EVENT_FNKEY_F12
},
1089 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED
},
1090 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED
},
1091 { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1092 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED
},
1093 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1094 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED
},
1095 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1096 { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED
},
1097 { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1098 { 0xa5, SONYPI_EVENT_VENDOR_PRESSED
},
1099 { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1100 { 0xa6, SONYPI_EVENT_HELP_PRESSED
},
1101 { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1105 static struct sony_nc_event sony_127_events
[] = {
1106 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED
},
1107 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1108 { 0x82, SONYPI_EVENT_PKEY_P1
},
1109 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1110 { 0x83, SONYPI_EVENT_PKEY_P2
},
1111 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1112 { 0x84, SONYPI_EVENT_PKEY_P3
},
1113 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1114 { 0x85, SONYPI_EVENT_PKEY_P4
},
1115 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1116 { 0x86, SONYPI_EVENT_PKEY_P5
},
1117 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1118 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED
},
1119 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1123 static int sony_nc_hotkeys_decode(u32 event
, unsigned int handle
)
1126 unsigned int result
= 0;
1127 struct sony_nc_event
*key_event
;
1129 if (sony_call_snc_handle(handle
, 0x200, &result
)) {
1130 dprintk("Unable to decode event 0x%.2x 0x%.2x\n", handle
,
1137 if (handle
== 0x0100)
1138 key_event
= sony_100_events
;
1140 key_event
= sony_127_events
;
1142 for (; key_event
->data
; key_event
++) {
1143 if (key_event
->data
== result
) {
1144 ret
= key_event
->event
;
1149 if (!key_event
->data
)
1150 pr_info("Unknown hotkey 0x%.2x/0x%.2x (handle 0x%.2x)\n",
1151 event
, result
, handle
);
1159 static void sony_nc_notify(struct acpi_device
*device
, u32 event
)
1161 u32 real_ev
= event
;
1163 dprintk("sony_nc_notify, event: 0x%.2x\n", event
);
1165 if (event
>= 0x90) {
1166 unsigned int result
= 0;
1167 unsigned int arg
= 0;
1168 unsigned int handle
= 0;
1169 unsigned int offset
= event
- 0x90;
1171 if (offset
>= ARRAY_SIZE(handles
->cap
)) {
1172 pr_err("Event 0x%x outside of capabilities list\n",
1176 handle
= handles
->cap
[offset
];
1178 /* list of handles known for generating events */
1184 real_ev
= sony_nc_hotkeys_decode(event
, handle
);
1187 sony_laptop_report_input_event(real_ev
);
1189 /* restore the original event for reporting */
1197 /* events on this handle are reported when the
1198 * switch changes position or for battery
1199 * events. We'll notify both of them but only
1200 * update the rfkill device status when the
1204 sony_call_snc_handle(handle
, 0x0100, &result
);
1205 real_ev
= result
& 0x03;
1207 /* hw switch event */
1209 sony_nc_rfkill_update();
1214 dprintk("Unknown event 0x%x for handle 0x%x\n",
1219 /* clear the event (and the event reason when present) */
1221 sony_nc_int_call(sony_nc_acpi_handle
, "SN05", &arg
, &result
);
1224 /* old style event */
1226 sony_laptop_report_input_event(real_ev
);
1229 acpi_bus_generate_proc_event(sony_nc_acpi_device
, ev_type
, real_ev
);
1231 acpi_bus_generate_netlink_event(sony_nc_acpi_device
->pnp
.device_class
,
1232 dev_name(&sony_nc_acpi_device
->dev
), ev_type
, real_ev
);
1235 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
1236 void *context
, void **return_value
)
1238 struct acpi_device_info
*info
;
1240 if (ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
1241 pr_warn("method: name: %4.4s, args %X\n",
1242 (char *)&info
->name
, info
->param_count
);
1253 static void sony_nc_function_setup(struct acpi_device
*device
,
1254 struct platform_device
*pf_device
)
1256 unsigned int i
, result
, bitmask
, arg
;
1261 /* setup found handles here */
1262 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1263 unsigned int handle
= handles
->cap
[i
];
1268 dprintk("setting up handle 0x%.4x\n", handle
);
1275 sony_call_snc_handle(handle
, 0, &result
);
1279 sony_call_snc_handle(handle
, 0x100, &result
);
1284 result
= sony_nc_battery_care_setup(pf_device
, handle
);
1286 pr_err("couldn't set up battery care function (%d)\n",
1290 result
= sony_nc_thermal_setup(pf_device
);
1292 pr_err("couldn't set up thermal profile function (%d)\n",
1297 sony_nc_rfkill_setup(device
);
1300 sony_nc_kbd_backlight_setup(pf_device
);
1307 /* Enable all events */
1309 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1310 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1314 static void sony_nc_function_cleanup(struct platform_device
*pd
)
1316 unsigned int i
, result
, bitmask
, handle
;
1318 /* get enabled events and disable them */
1319 sony_nc_int_call(sony_nc_acpi_handle
, "SN01", NULL
, &bitmask
);
1320 sony_nc_int_call(sony_nc_acpi_handle
, "SN03", &bitmask
, &result
);
1322 /* cleanup handles here */
1323 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1325 handle
= handles
->cap
[i
];
1334 sony_nc_battery_care_cleanup(pd
);
1337 sony_nc_thermal_cleanup(pd
);
1341 sony_nc_rfkill_cleanup();
1344 sony_nc_kbd_backlight_cleanup(pd
);
1351 /* finally cleanup the handles list */
1352 sony_nc_handles_cleanup(pd
);
1355 static void sony_nc_function_resume(void)
1357 unsigned int i
, result
, bitmask
, arg
;
1359 dprintk("Resuming SNC device\n");
1361 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1362 unsigned int handle
= handles
->cap
[i
];
1371 /* re-enable hotkeys */
1372 sony_call_snc_handle(handle
, 0, &result
);
1375 /* re-enable hotkeys */
1376 sony_call_snc_handle(handle
, 0x100, &result
);
1379 sony_nc_thermal_resume();
1383 sony_nc_rfkill_update();
1386 sony_nc_kbd_backlight_resume();
1393 /* Enable all events */
1395 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1396 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1400 static int sony_nc_resume(struct acpi_device
*device
)
1402 struct sony_nc_value
*item
;
1405 for (item
= sony_nc_values
; item
->name
; item
++) {
1410 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
1411 &item
->value
, NULL
);
1413 pr_err("%s: %d\n", __func__
, ret
);
1418 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1421 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
1422 dprintk("ECON Method failed\n");
1425 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1427 sony_nc_function_resume();
1432 static void sony_nc_rfkill_cleanup(void)
1436 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1437 if (sony_rfkill_devices
[i
]) {
1438 rfkill_unregister(sony_rfkill_devices
[i
]);
1439 rfkill_destroy(sony_rfkill_devices
[i
]);
1444 static int sony_nc_rfkill_set(void *data
, bool blocked
)
1447 int argument
= sony_rfkill_address
[(long) data
] + 0x100;
1450 argument
|= 0x030000;
1452 return sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1455 static const struct rfkill_ops sony_rfkill_ops
= {
1456 .set_block
= sony_nc_rfkill_set
,
1459 static int sony_nc_setup_rfkill(struct acpi_device
*device
,
1460 enum sony_nc_rfkill nc_type
)
1464 enum rfkill_type type
;
1467 bool hwblock
, swblock
;
1471 type
= RFKILL_TYPE_WLAN
;
1474 case SONY_BLUETOOTH
:
1475 type
= RFKILL_TYPE_BLUETOOTH
;
1476 name
= "sony-bluetooth";
1479 type
= RFKILL_TYPE_WWAN
;
1483 type
= RFKILL_TYPE_WIMAX
;
1484 name
= "sony-wimax";
1490 rfk
= rfkill_alloc(name
, &device
->dev
, type
,
1491 &sony_rfkill_ops
, (void *)nc_type
);
1495 if (sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
) < 0) {
1496 rfkill_destroy(rfk
);
1499 hwblock
= !(result
& 0x1);
1501 if (sony_call_snc_handle(sony_rfkill_handle
,
1502 sony_rfkill_address
[nc_type
],
1504 rfkill_destroy(rfk
);
1507 swblock
= !(result
& 0x2);
1509 rfkill_init_sw_state(rfk
, swblock
);
1510 rfkill_set_hw_state(rfk
, hwblock
);
1512 err
= rfkill_register(rfk
);
1514 rfkill_destroy(rfk
);
1517 sony_rfkill_devices
[nc_type
] = rfk
;
1521 static void sony_nc_rfkill_update(void)
1523 enum sony_nc_rfkill i
;
1527 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1528 hwblock
= !(result
& 0x1);
1530 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1531 int argument
= sony_rfkill_address
[i
];
1533 if (!sony_rfkill_devices
[i
])
1537 if (rfkill_set_hw_state(sony_rfkill_devices
[i
], true)) {
1538 /* we already know we're blocked */
1543 sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1544 rfkill_set_states(sony_rfkill_devices
[i
],
1545 !(result
& 0x2), false);
1549 static void sony_nc_rfkill_setup(struct acpi_device
*device
)
1553 unsigned char buffer
[32] = { 0 };
1555 offset
= sony_find_snc_handle(0x124);
1557 offset
= sony_find_snc_handle(0x135);
1561 sony_rfkill_handle
= 0x135;
1563 sony_rfkill_handle
= 0x124;
1564 dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle
);
1566 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
1571 /* the buffer is filled with magic numbers describing the devices
1572 * available, 0xff terminates the enumeration
1574 for (i
= 0; i
< ARRAY_SIZE(buffer
); i
++) {
1576 if (buffer
[i
] == 0xff)
1579 dprintk("Radio devices, looking at 0x%.2x\n", buffer
[i
]);
1581 if (buffer
[i
] == 0 && !sony_rfkill_devices
[SONY_WIFI
])
1582 sony_nc_setup_rfkill(device
, SONY_WIFI
);
1584 if (buffer
[i
] == 0x10 && !sony_rfkill_devices
[SONY_BLUETOOTH
])
1585 sony_nc_setup_rfkill(device
, SONY_BLUETOOTH
);
1587 if ((0xf0 & buffer
[i
]) == 0x20 &&
1588 !sony_rfkill_devices
[SONY_WWAN
])
1589 sony_nc_setup_rfkill(device
, SONY_WWAN
);
1591 if (buffer
[i
] == 0x30 && !sony_rfkill_devices
[SONY_WIMAX
])
1592 sony_nc_setup_rfkill(device
, SONY_WIMAX
);
1596 /* Keyboard backlight feature */
1597 #define KBDBL_HANDLER 0x137
1598 #define KBDBL_PRESENT 0xB00
1599 #define SET_MODE 0xC00
1600 #define SET_STATE 0xD00
1601 #define SET_TIMEOUT 0xE00
1603 struct kbd_backlight
{
1606 struct device_attribute mode_attr
;
1607 struct device_attribute timeout_attr
;
1610 static struct kbd_backlight
*kbdbl_handle
;
1612 static ssize_t
__sony_nc_kbd_backlight_mode_set(u8 value
)
1619 if (sony_call_snc_handle(KBDBL_HANDLER
,
1620 (value
<< 0x10) | SET_MODE
, &result
))
1623 /* Try to turn the light on/off immediately */
1624 sony_call_snc_handle(KBDBL_HANDLER
, (value
<< 0x10) | SET_STATE
,
1627 kbdbl_handle
->mode
= value
;
1632 static ssize_t
sony_nc_kbd_backlight_mode_store(struct device
*dev
,
1633 struct device_attribute
*attr
,
1634 const char *buffer
, size_t count
)
1637 unsigned long value
;
1642 if (kstrtoul(buffer
, 10, &value
))
1645 ret
= __sony_nc_kbd_backlight_mode_set(value
);
1652 static ssize_t
sony_nc_kbd_backlight_mode_show(struct device
*dev
,
1653 struct device_attribute
*attr
, char *buffer
)
1656 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_handle
->mode
);
1660 static int __sony_nc_kbd_backlight_timeout_set(u8 value
)
1667 if (sony_call_snc_handle(KBDBL_HANDLER
,
1668 (value
<< 0x10) | SET_TIMEOUT
, &result
))
1671 kbdbl_handle
->timeout
= value
;
1676 static ssize_t
sony_nc_kbd_backlight_timeout_store(struct device
*dev
,
1677 struct device_attribute
*attr
,
1678 const char *buffer
, size_t count
)
1681 unsigned long value
;
1686 if (kstrtoul(buffer
, 10, &value
))
1689 ret
= __sony_nc_kbd_backlight_timeout_set(value
);
1696 static ssize_t
sony_nc_kbd_backlight_timeout_show(struct device
*dev
,
1697 struct device_attribute
*attr
, char *buffer
)
1700 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_handle
->timeout
);
1704 static void sony_nc_kbd_backlight_setup(struct platform_device
*pd
)
1708 if (sony_call_snc_handle(KBDBL_HANDLER
, KBDBL_PRESENT
, &result
))
1710 if (!(result
& 0x02))
1713 kbdbl_handle
= kzalloc(sizeof(*kbdbl_handle
), GFP_KERNEL
);
1717 sysfs_attr_init(&kbdbl_handle
->mode_attr
.attr
);
1718 kbdbl_handle
->mode_attr
.attr
.name
= "kbd_backlight";
1719 kbdbl_handle
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1720 kbdbl_handle
->mode_attr
.show
= sony_nc_kbd_backlight_mode_show
;
1721 kbdbl_handle
->mode_attr
.store
= sony_nc_kbd_backlight_mode_store
;
1723 sysfs_attr_init(&kbdbl_handle
->timeout_attr
.attr
);
1724 kbdbl_handle
->timeout_attr
.attr
.name
= "kbd_backlight_timeout";
1725 kbdbl_handle
->timeout_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1726 kbdbl_handle
->timeout_attr
.show
= sony_nc_kbd_backlight_timeout_show
;
1727 kbdbl_handle
->timeout_attr
.store
= sony_nc_kbd_backlight_timeout_store
;
1729 if (device_create_file(&pd
->dev
, &kbdbl_handle
->mode_attr
))
1732 if (device_create_file(&pd
->dev
, &kbdbl_handle
->timeout_attr
))
1735 __sony_nc_kbd_backlight_mode_set(kbd_backlight
);
1736 __sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout
);
1741 device_remove_file(&pd
->dev
, &kbdbl_handle
->mode_attr
);
1743 kfree(kbdbl_handle
);
1744 kbdbl_handle
= NULL
;
1748 static int sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
)
1753 device_remove_file(&pd
->dev
, &kbdbl_handle
->mode_attr
);
1754 device_remove_file(&pd
->dev
, &kbdbl_handle
->timeout_attr
);
1756 /* restore the default hw behaviour */
1757 sony_call_snc_handle(KBDBL_HANDLER
, 0x1000 | SET_MODE
, &result
);
1758 sony_call_snc_handle(KBDBL_HANDLER
, SET_TIMEOUT
, &result
);
1760 kfree(kbdbl_handle
);
1765 static void sony_nc_kbd_backlight_resume(void)
1772 if (kbdbl_handle
->mode
== 0)
1773 sony_call_snc_handle(KBDBL_HANDLER
, SET_MODE
, &ignore
);
1775 if (kbdbl_handle
->timeout
!= 0)
1776 sony_call_snc_handle(KBDBL_HANDLER
,
1777 (kbdbl_handle
->timeout
<< 0x10) | SET_TIMEOUT
,
1781 struct battery_care_control
{
1782 struct device_attribute attrs
[2];
1783 unsigned int handle
;
1785 static struct battery_care_control
*bcare_ctl
;
1787 static ssize_t
sony_nc_battery_care_limit_store(struct device
*dev
,
1788 struct device_attribute
*attr
,
1789 const char *buffer
, size_t count
)
1791 unsigned int result
, cmd
;
1792 unsigned long value
;
1797 if (kstrtoul(buffer
, 10, &value
))
1800 /* limit values (2 bits):
1806 * bit 0: 0 disable BCL, 1 enable BCL
1807 * bit 1: 1 tell to store the battery limit (see bits 6,7) too
1808 * bits 2,3: reserved
1809 * bits 4,5: store the limit into the EC
1810 * bits 6,7: store the limit into the battery
1814 * handle 0x0115 should allow storing on battery too;
1815 * handle 0x0136 same as 0x0115 + health status;
1816 * handle 0x013f, same as 0x0136 but no storing on the battery
1818 * Store only inside the EC for now, regardless the handle number
1821 /* disable limits */
1824 else if (value
<= 50)
1827 else if (value
<= 80)
1830 else if (value
<= 100)
1836 if (sony_call_snc_handle(bcare_ctl
->handle
, (cmd
<< 0x10) | 0x0100,
1843 static ssize_t
sony_nc_battery_care_limit_show(struct device
*dev
,
1844 struct device_attribute
*attr
, char *buffer
)
1846 unsigned int result
, status
;
1848 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0000, &result
))
1851 status
= (result
& 0x01) ? ((result
& 0x30) >> 0x04) : 0;
1867 return snprintf(buffer
, PAGE_SIZE
, "%d\n", status
);
1870 static ssize_t
sony_nc_battery_care_health_show(struct device
*dev
,
1871 struct device_attribute
*attr
, char *buffer
)
1874 unsigned int health
;
1876 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0200, &health
))
1879 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", health
& 0xff);
1884 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
1885 unsigned int handle
)
1889 bcare_ctl
= kzalloc(sizeof(struct battery_care_control
), GFP_KERNEL
);
1893 bcare_ctl
->handle
= handle
;
1895 sysfs_attr_init(&bcare_ctl
->attrs
[0].attr
);
1896 bcare_ctl
->attrs
[0].attr
.name
= "battery_care_limiter";
1897 bcare_ctl
->attrs
[0].attr
.mode
= S_IRUGO
| S_IWUSR
;
1898 bcare_ctl
->attrs
[0].show
= sony_nc_battery_care_limit_show
;
1899 bcare_ctl
->attrs
[0].store
= sony_nc_battery_care_limit_store
;
1901 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
1905 /* 0x0115 is for models with no health reporting capability */
1906 if (handle
== 0x0115)
1909 sysfs_attr_init(&bcare_ctl
->attrs
[1].attr
);
1910 bcare_ctl
->attrs
[1].attr
.name
= "battery_care_health";
1911 bcare_ctl
->attrs
[1].attr
.mode
= S_IRUGO
;
1912 bcare_ctl
->attrs
[1].show
= sony_nc_battery_care_health_show
;
1914 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
1921 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
1930 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
)
1933 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
1934 if (bcare_ctl
->handle
!= 0x0115)
1935 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
1942 struct snc_thermal_ctrl
{
1944 unsigned int profiles
;
1945 struct device_attribute mode_attr
;
1946 struct device_attribute profiles_attr
;
1948 static struct snc_thermal_ctrl
*th_handle
;
1950 #define THM_PROFILE_MAX 3
1951 static const char * const snc_thermal_profiles
[] = {
1957 static int sony_nc_thermal_mode_set(unsigned short mode
)
1959 unsigned int result
;
1961 /* the thermal profile seems to be a two bit bitmask:
1963 * msb -> performance
1964 * no bit set is the normal operation and is always valid
1965 * Some vaio models only have "balanced" and "performance"
1967 if ((mode
&& !(th_handle
->profiles
& mode
)) || mode
>= THM_PROFILE_MAX
)
1970 if (sony_call_snc_handle(0x0122, mode
<< 0x10 | 0x0200, &result
))
1973 th_handle
->mode
= mode
;
1978 static int sony_nc_thermal_mode_get(void)
1980 unsigned int result
;
1982 if (sony_call_snc_handle(0x0122, 0x0100, &result
))
1985 return result
& 0xff;
1988 static ssize_t
sony_nc_thermal_profiles_show(struct device
*dev
,
1989 struct device_attribute
*attr
, char *buffer
)
1994 for (cnt
= 0; cnt
< THM_PROFILE_MAX
; cnt
++) {
1995 if (!cnt
|| (th_handle
->profiles
& cnt
))
1996 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "%s ",
1997 snc_thermal_profiles
[cnt
]);
1999 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "\n");
2004 static ssize_t
sony_nc_thermal_mode_store(struct device
*dev
,
2005 struct device_attribute
*attr
,
2006 const char *buffer
, size_t count
)
2014 /* skip the newline if present */
2015 if (buffer
[len
- 1] == '\n')
2018 for (cmd
= 0; cmd
< THM_PROFILE_MAX
; cmd
++)
2019 if (strncmp(buffer
, snc_thermal_profiles
[cmd
], len
) == 0)
2022 if (sony_nc_thermal_mode_set(cmd
))
2028 static ssize_t
sony_nc_thermal_mode_show(struct device
*dev
,
2029 struct device_attribute
*attr
, char *buffer
)
2032 unsigned int mode
= sony_nc_thermal_mode_get();
2037 count
= snprintf(buffer
, PAGE_SIZE
, "%s\n", snc_thermal_profiles
[mode
]);
2042 static int sony_nc_thermal_setup(struct platform_device
*pd
)
2045 th_handle
= kzalloc(sizeof(struct snc_thermal_ctrl
), GFP_KERNEL
);
2049 ret
= sony_call_snc_handle(0x0122, 0x0000, &th_handle
->profiles
);
2051 pr_warn("couldn't to read the thermal profiles\n");
2055 ret
= sony_nc_thermal_mode_get();
2057 pr_warn("couldn't to read the current thermal profile");
2060 th_handle
->mode
= ret
;
2062 sysfs_attr_init(&th_handle
->profiles_attr
.attr
);
2063 th_handle
->profiles_attr
.attr
.name
= "thermal_profiles";
2064 th_handle
->profiles_attr
.attr
.mode
= S_IRUGO
;
2065 th_handle
->profiles_attr
.show
= sony_nc_thermal_profiles_show
;
2067 sysfs_attr_init(&th_handle
->mode_attr
.attr
);
2068 th_handle
->mode_attr
.attr
.name
= "thermal_control";
2069 th_handle
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
2070 th_handle
->mode_attr
.show
= sony_nc_thermal_mode_show
;
2071 th_handle
->mode_attr
.store
= sony_nc_thermal_mode_store
;
2073 ret
= device_create_file(&pd
->dev
, &th_handle
->profiles_attr
);
2077 ret
= device_create_file(&pd
->dev
, &th_handle
->mode_attr
);
2084 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2091 static void sony_nc_thermal_cleanup(struct platform_device
*pd
)
2094 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2095 device_remove_file(&pd
->dev
, &th_handle
->mode_attr
);
2101 static void sony_nc_thermal_resume(void)
2103 unsigned int status
= sony_nc_thermal_mode_get();
2105 if (status
!= th_handle
->mode
)
2106 sony_nc_thermal_mode_set(th_handle
->mode
);
2109 static void sony_nc_backlight_ng_read_limits(int handle
,
2110 struct sony_backlight_props
*props
)
2114 u8 min
= 0xff, max
= 0x00;
2115 unsigned char buffer
[32] = { 0 };
2117 props
->handle
= handle
;
2119 props
->maxlvl
= 0xff;
2121 offset
= sony_find_snc_handle(handle
);
2125 /* try to read the boundaries from ACPI tables, if we fail the above
2126 * defaults should be reasonable
2128 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
2133 /* the buffer lists brightness levels available, brightness levels are
2134 * from position 0 to 8 in the array, other values are used by ALS
2137 for (i
= 0; i
< 9 && i
< ARRAY_SIZE(buffer
); i
++) {
2139 dprintk("Brightness level: %d\n", buffer
[i
]);
2144 if (buffer
[i
] > max
)
2146 if (buffer
[i
] < min
)
2149 props
->offset
= min
;
2150 props
->maxlvl
= max
;
2151 dprintk("Brightness levels: min=%d max=%d\n", props
->offset
,
2155 static void sony_nc_backlight_setup(void)
2158 int max_brightness
= 0;
2159 const struct backlight_ops
*ops
= NULL
;
2160 struct backlight_properties props
;
2162 if (sony_find_snc_handle(0x12f) != -1) {
2163 ops
= &sony_backlight_ng_ops
;
2164 sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props
);
2165 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
2167 } else if (sony_find_snc_handle(0x137) != -1) {
2168 ops
= &sony_backlight_ng_ops
;
2169 sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props
);
2170 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
2172 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "GBRT",
2174 ops
= &sony_backlight_ops
;
2175 max_brightness
= SONY_MAX_BRIGHTNESS
- 1;
2180 memset(&props
, 0, sizeof(struct backlight_properties
));
2181 props
.type
= BACKLIGHT_PLATFORM
;
2182 props
.max_brightness
= max_brightness
;
2183 sony_bl_props
.dev
= backlight_device_register("sony", NULL
,
2187 if (IS_ERR(sony_bl_props
.dev
)) {
2188 pr_warn("unable to register backlight device\n");
2189 sony_bl_props
.dev
= NULL
;
2191 sony_bl_props
.dev
->props
.brightness
=
2192 ops
->get_brightness(sony_bl_props
.dev
);
2195 static void sony_nc_backlight_cleanup(void)
2197 if (sony_bl_props
.dev
)
2198 backlight_device_unregister(sony_bl_props
.dev
);
2201 static int sony_nc_add(struct acpi_device
*device
)
2206 struct sony_nc_value
*item
;
2208 pr_info("%s v%s\n", SONY_NC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
2210 sony_nc_acpi_device
= device
;
2211 strcpy(acpi_device_class(device
), "sony/hotkey");
2213 sony_nc_acpi_handle
= device
->handle
;
2215 /* read device status */
2216 result
= acpi_bus_get_status(device
);
2217 /* bail IFF the above call was successful and the device is not present */
2218 if (!result
&& !device
->status
.present
) {
2219 dprintk("Device not present\n");
2224 result
= sony_pf_add();
2229 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
,
2230 sony_nc_acpi_handle
, 1, sony_walk_callback
,
2232 if (ACPI_FAILURE(status
)) {
2233 pr_warn("unable to walk acpi resources\n");
2239 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
2242 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
2243 dprintk("ECON Method failed\n");
2246 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
2248 dprintk("Doing SNC setup\n");
2249 /* retrieve the available handles */
2250 result
= sony_nc_handles_setup(sony_pf_device
);
2252 sony_nc_function_setup(device
, sony_pf_device
);
2255 /* setup input devices and helper fifo */
2256 result
= sony_laptop_setup_input(device
);
2258 pr_err("Unable to create input devices\n");
2262 if (acpi_video_backlight_support()) {
2263 pr_info("brightness ignored, must be controlled by ACPI video driver\n");
2265 sony_nc_backlight_setup();
2268 /* create sony_pf sysfs attributes related to the SNC device */
2269 for (item
= sony_nc_values
; item
->name
; ++item
) {
2271 if (!debug
&& item
->debug
)
2274 /* find the available acpiget as described in the DSDT */
2275 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
2276 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
2279 dprintk("Found %s getter: %s\n",
2280 item
->name
, *item
->acpiget
);
2281 item
->devattr
.attr
.mode
|= S_IRUGO
;
2286 /* find the available acpiset as described in the DSDT */
2287 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
2288 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
2291 dprintk("Found %s setter: %s\n",
2292 item
->name
, *item
->acpiset
);
2293 item
->devattr
.attr
.mode
|= S_IWUSR
;
2298 if (item
->devattr
.attr
.mode
!= 0) {
2300 device_create_file(&sony_pf_device
->dev
,
2310 for (item
= sony_nc_values
; item
->name
; ++item
) {
2311 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
2313 sony_nc_backlight_cleanup();
2315 sony_laptop_remove_input();
2318 sony_nc_function_cleanup(sony_pf_device
);
2319 sony_nc_handles_cleanup(sony_pf_device
);
2325 sony_nc_rfkill_cleanup();
2329 static int sony_nc_remove(struct acpi_device
*device
, int type
)
2331 struct sony_nc_value
*item
;
2333 sony_nc_backlight_cleanup();
2335 sony_nc_acpi_device
= NULL
;
2337 for (item
= sony_nc_values
; item
->name
; ++item
) {
2338 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
2341 sony_nc_function_cleanup(sony_pf_device
);
2342 sony_nc_handles_cleanup(sony_pf_device
);
2344 sony_laptop_remove_input();
2345 dprintk(SONY_NC_DRIVER_NAME
" removed.\n");
2350 static const struct acpi_device_id sony_device_ids
[] = {
2355 MODULE_DEVICE_TABLE(acpi
, sony_device_ids
);
2357 static const struct acpi_device_id sony_nc_device_ids
[] = {
2362 static struct acpi_driver sony_nc_driver
= {
2363 .name
= SONY_NC_DRIVER_NAME
,
2364 .class = SONY_NC_CLASS
,
2365 .ids
= sony_nc_device_ids
,
2366 .owner
= THIS_MODULE
,
2369 .remove
= sony_nc_remove
,
2370 .resume
= sony_nc_resume
,
2371 .notify
= sony_nc_notify
,
2375 /*********** SPIC (SNY6001) Device ***********/
2377 #define SONYPI_DEVICE_TYPE1 0x00000001
2378 #define SONYPI_DEVICE_TYPE2 0x00000002
2379 #define SONYPI_DEVICE_TYPE3 0x00000004
2381 #define SONYPI_TYPE1_OFFSET 0x04
2382 #define SONYPI_TYPE2_OFFSET 0x12
2383 #define SONYPI_TYPE3_OFFSET 0x12
2385 struct sony_pic_ioport
{
2386 struct acpi_resource_io io1
;
2387 struct acpi_resource_io io2
;
2388 struct list_head list
;
2391 struct sony_pic_irq
{
2392 struct acpi_resource_irq irq
;
2393 struct list_head list
;
2396 struct sonypi_eventtypes
{
2399 struct sonypi_event
*events
;
2402 struct sony_pic_dev
{
2403 struct acpi_device
*acpi_dev
;
2404 struct sony_pic_irq
*cur_irq
;
2405 struct sony_pic_ioport
*cur_ioport
;
2406 struct list_head interrupts
;
2407 struct list_head ioports
;
2409 struct sonypi_eventtypes
*event_types
;
2410 int (*handle_irq
)(const u8
, const u8
);
2418 static struct sony_pic_dev spic_dev
= {
2419 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
2420 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
2423 static int spic_drv_registered
;
2426 #define SONYPI_JOGGER_MASK 0x00000001
2427 #define SONYPI_CAPTURE_MASK 0x00000002
2428 #define SONYPI_FNKEY_MASK 0x00000004
2429 #define SONYPI_BLUETOOTH_MASK 0x00000008
2430 #define SONYPI_PKEY_MASK 0x00000010
2431 #define SONYPI_BACK_MASK 0x00000020
2432 #define SONYPI_HELP_MASK 0x00000040
2433 #define SONYPI_LID_MASK 0x00000080
2434 #define SONYPI_ZOOM_MASK 0x00000100
2435 #define SONYPI_THUMBPHRASE_MASK 0x00000200
2436 #define SONYPI_MEYE_MASK 0x00000400
2437 #define SONYPI_MEMORYSTICK_MASK 0x00000800
2438 #define SONYPI_BATTERY_MASK 0x00001000
2439 #define SONYPI_WIRELESS_MASK 0x00002000
2441 struct sonypi_event
{
2446 /* The set of possible button release events */
2447 static struct sonypi_event sonypi_releaseev
[] = {
2448 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
2452 /* The set of possible jogger events */
2453 static struct sonypi_event sonypi_joggerev
[] = {
2454 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
2455 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
2456 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
2457 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
2458 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
2459 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
2460 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
2461 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
2462 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
2463 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
2464 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
2465 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
2466 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
2470 /* The set of possible capture button events */
2471 static struct sonypi_event sonypi_captureev
[] = {
2472 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
2473 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
2474 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED
},
2475 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
2479 /* The set of possible fnkeys events */
2480 static struct sonypi_event sonypi_fnkeyev
[] = {
2481 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
2482 { 0x11, SONYPI_EVENT_FNKEY_F1
},
2483 { 0x12, SONYPI_EVENT_FNKEY_F2
},
2484 { 0x13, SONYPI_EVENT_FNKEY_F3
},
2485 { 0x14, SONYPI_EVENT_FNKEY_F4
},
2486 { 0x15, SONYPI_EVENT_FNKEY_F5
},
2487 { 0x16, SONYPI_EVENT_FNKEY_F6
},
2488 { 0x17, SONYPI_EVENT_FNKEY_F7
},
2489 { 0x18, SONYPI_EVENT_FNKEY_F8
},
2490 { 0x19, SONYPI_EVENT_FNKEY_F9
},
2491 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
2492 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
2493 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
2494 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
2495 { 0x21, SONYPI_EVENT_FNKEY_1
},
2496 { 0x22, SONYPI_EVENT_FNKEY_2
},
2497 { 0x31, SONYPI_EVENT_FNKEY_D
},
2498 { 0x32, SONYPI_EVENT_FNKEY_E
},
2499 { 0x33, SONYPI_EVENT_FNKEY_F
},
2500 { 0x34, SONYPI_EVENT_FNKEY_S
},
2501 { 0x35, SONYPI_EVENT_FNKEY_B
},
2502 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
2506 /* The set of possible program key events */
2507 static struct sonypi_event sonypi_pkeyev
[] = {
2508 { 0x01, SONYPI_EVENT_PKEY_P1
},
2509 { 0x02, SONYPI_EVENT_PKEY_P2
},
2510 { 0x04, SONYPI_EVENT_PKEY_P3
},
2511 { 0x20, SONYPI_EVENT_PKEY_P1
},
2515 /* The set of possible bluetooth events */
2516 static struct sonypi_event sonypi_blueev
[] = {
2517 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
2518 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
2519 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
2523 /* The set of possible wireless events */
2524 static struct sonypi_event sonypi_wlessev
[] = {
2525 { 0x59, SONYPI_EVENT_IGNORE
},
2526 { 0x5a, SONYPI_EVENT_IGNORE
},
2530 /* The set of possible back button events */
2531 static struct sonypi_event sonypi_backev
[] = {
2532 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
2536 /* The set of possible help button events */
2537 static struct sonypi_event sonypi_helpev
[] = {
2538 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
2543 /* The set of possible lid events */
2544 static struct sonypi_event sonypi_lidev
[] = {
2545 { 0x51, SONYPI_EVENT_LID_CLOSED
},
2546 { 0x50, SONYPI_EVENT_LID_OPENED
},
2550 /* The set of possible zoom events */
2551 static struct sonypi_event sonypi_zoomev
[] = {
2552 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
2553 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED
},
2554 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED
},
2555 { 0x04, SONYPI_EVENT_ZOOM_PRESSED
},
2559 /* The set of possible thumbphrase events */
2560 static struct sonypi_event sonypi_thumbphraseev
[] = {
2561 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
2565 /* The set of possible motioneye camera events */
2566 static struct sonypi_event sonypi_meyeev
[] = {
2567 { 0x00, SONYPI_EVENT_MEYE_FACE
},
2568 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
2572 /* The set of possible memorystick events */
2573 static struct sonypi_event sonypi_memorystickev
[] = {
2574 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
2575 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
2579 /* The set of possible battery events */
2580 static struct sonypi_event sonypi_batteryev
[] = {
2581 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
2582 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
2586 /* The set of possible volume events */
2587 static struct sonypi_event sonypi_volumeev
[] = {
2588 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED
},
2589 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED
},
2593 /* The set of possible brightness events */
2594 static struct sonypi_event sonypi_brightnessev
[] = {
2595 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED
},
2599 static struct sonypi_eventtypes type1_events
[] = {
2600 { 0, 0xffffffff, sonypi_releaseev
},
2601 { 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
2602 { 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
2603 { 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
2604 { 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
2605 { 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
2606 { 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
2607 { 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
2608 { 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
2609 { 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
2612 static struct sonypi_eventtypes type2_events
[] = {
2613 { 0, 0xffffffff, sonypi_releaseev
},
2614 { 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
2615 { 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
2616 { 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
2617 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
2618 { 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
2619 { 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
2620 { 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
2621 { 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
2622 { 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
2623 { 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
2624 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
2625 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
2626 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
2629 static struct sonypi_eventtypes type3_events
[] = {
2630 { 0, 0xffffffff, sonypi_releaseev
},
2631 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
2632 { 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
2633 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
2634 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
2635 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
2636 { 0x05, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
2637 { 0x05, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
2638 { 0x05, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
2639 { 0x05, SONYPI_PKEY_MASK
, sonypi_volumeev
},
2640 { 0x05, SONYPI_PKEY_MASK
, sonypi_brightnessev
},
2644 /* low level spic calls */
2645 #define ITERATIONS_LONG 10000
2646 #define ITERATIONS_SHORT 10
2647 #define wait_on_command(command, iterations) { \
2648 unsigned int n = iterations; \
2649 while (--n && (command)) \
2652 dprintk("command failed at %s : %s (line %d)\n", \
2653 __FILE__, __func__, __LINE__); \
2656 static u8
sony_pic_call1(u8 dev
)
2660 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
2662 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
2663 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4);
2664 v2
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
2665 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev
, (v2
<< 8) | v1
);
2669 static u8
sony_pic_call2(u8 dev
, u8 fn
)
2673 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
2675 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
2676 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
2678 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
2679 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
2680 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev
, fn
, v1
);
2684 static u8
sony_pic_call3(u8 dev
, u8 fn
, u8 v
)
2688 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
2689 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
2690 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
2691 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
2692 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
2693 outb(v
, spic_dev
.cur_ioport
->io1
.minimum
);
2694 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
2695 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
2701 * minidrivers for SPIC models
2703 static int type3_handle_irq(const u8 data_mask
, const u8 ev
)
2706 * 0x31 could mean we have to take some extra action and wait for
2707 * the next irq for some Type3 models, it will generate a new
2708 * irq and we can read new data from the device:
2709 * - 0x5c and 0x5f requires 0xA0
2710 * - 0x61 requires 0xB3
2712 if (data_mask
== 0x31) {
2713 if (ev
== 0x5c || ev
== 0x5f)
2714 sony_pic_call1(0xA0);
2715 else if (ev
== 0x61)
2716 sony_pic_call1(0xB3);
2722 static void sony_pic_detect_device_type(struct sony_pic_dev
*dev
)
2724 struct pci_dev
*pcidev
;
2726 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
2727 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
2729 dev
->model
= SONYPI_DEVICE_TYPE1
;
2730 dev
->evport_offset
= SONYPI_TYPE1_OFFSET
;
2731 dev
->event_types
= type1_events
;
2735 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
2736 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
);
2738 dev
->model
= SONYPI_DEVICE_TYPE2
;
2739 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
2740 dev
->event_types
= type2_events
;
2744 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
2745 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
);
2747 dev
->model
= SONYPI_DEVICE_TYPE3
;
2748 dev
->handle_irq
= type3_handle_irq
;
2749 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
2750 dev
->event_types
= type3_events
;
2754 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
2755 PCI_DEVICE_ID_INTEL_ICH8_4
, NULL
);
2757 dev
->model
= SONYPI_DEVICE_TYPE3
;
2758 dev
->handle_irq
= type3_handle_irq
;
2759 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
2760 dev
->event_types
= type3_events
;
2764 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
2765 PCI_DEVICE_ID_INTEL_ICH9_1
, NULL
);
2767 dev
->model
= SONYPI_DEVICE_TYPE3
;
2768 dev
->handle_irq
= type3_handle_irq
;
2769 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
2770 dev
->event_types
= type3_events
;
2775 dev
->model
= SONYPI_DEVICE_TYPE2
;
2776 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
2777 dev
->event_types
= type2_events
;
2781 pci_dev_put(pcidev
);
2783 pr_info("detected Type%d model\n",
2784 dev
->model
== SONYPI_DEVICE_TYPE1
? 1 :
2785 dev
->model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
2788 /* camera tests and poweron/poweroff */
2789 #define SONYPI_CAMERA_PICTURE 5
2790 #define SONYPI_CAMERA_CONTROL 0x10
2792 #define SONYPI_CAMERA_BRIGHTNESS 0
2793 #define SONYPI_CAMERA_CONTRAST 1
2794 #define SONYPI_CAMERA_HUE 2
2795 #define SONYPI_CAMERA_COLOR 3
2796 #define SONYPI_CAMERA_SHARPNESS 4
2798 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
2799 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
2800 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
2801 #define SONYPI_CAMERA_MUTE_MASK 0x40
2803 /* the rest don't need a loop until not 0xff */
2804 #define SONYPI_CAMERA_AGC 6
2805 #define SONYPI_CAMERA_AGC_MASK 0x30
2806 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
2808 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
2809 #define SONYPI_CAMERA_CONTROL 0x10
2811 #define SONYPI_CAMERA_STATUS 7
2812 #define SONYPI_CAMERA_STATUS_READY 0x2
2813 #define SONYPI_CAMERA_STATUS_POSITION 0x4
2815 #define SONYPI_DIRECTION_BACKWARDS 0x4
2817 #define SONYPI_CAMERA_REVISION 8
2818 #define SONYPI_CAMERA_ROMVERSION 9
2820 static int __sony_pic_camera_ready(void)
2824 v
= sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS
);
2825 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
2828 static int __sony_pic_camera_off(void)
2831 pr_warn("camera control not enabled\n");
2835 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
,
2836 SONYPI_CAMERA_MUTE_MASK
),
2839 if (spic_dev
.camera_power
) {
2840 sony_pic_call2(0x91, 0);
2841 spic_dev
.camera_power
= 0;
2846 static int __sony_pic_camera_on(void)
2851 pr_warn("camera control not enabled\n");
2855 if (spic_dev
.camera_power
)
2858 for (j
= 5; j
> 0; j
--) {
2860 for (x
= 0; x
< 100 && sony_pic_call2(0x91, 0x1); x
++)
2862 sony_pic_call1(0x93);
2864 for (i
= 400; i
> 0; i
--) {
2865 if (__sony_pic_camera_ready())
2874 pr_warn("failed to power on camera\n");
2878 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL
,
2882 spic_dev
.camera_power
= 1;
2886 /* External camera command (exported to the motion eye v4l driver) */
2887 int sony_pic_camera_command(int command
, u8 value
)
2892 mutex_lock(&spic_dev
.lock
);
2895 case SONY_PIC_COMMAND_SETCAMERA
:
2897 __sony_pic_camera_on();
2899 __sony_pic_camera_off();
2901 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS
:
2902 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS
, value
),
2905 case SONY_PIC_COMMAND_SETCAMERACONTRAST
:
2906 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST
, value
),
2909 case SONY_PIC_COMMAND_SETCAMERAHUE
:
2910 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE
, value
),
2913 case SONY_PIC_COMMAND_SETCAMERACOLOR
:
2914 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR
, value
),
2917 case SONY_PIC_COMMAND_SETCAMERASHARPNESS
:
2918 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS
, value
),
2921 case SONY_PIC_COMMAND_SETCAMERAPICTURE
:
2922 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
, value
),
2925 case SONY_PIC_COMMAND_SETCAMERAAGC
:
2926 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC
, value
),
2930 pr_err("sony_pic_camera_command invalid: %d\n", command
);
2933 mutex_unlock(&spic_dev
.lock
);
2936 EXPORT_SYMBOL(sony_pic_camera_command
);
2938 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
2939 static void __sony_pic_set_wwanpower(u8 state
)
2942 if (spic_dev
.wwan_power
== state
)
2944 sony_pic_call2(0xB0, state
);
2945 sony_pic_call1(0x82);
2946 spic_dev
.wwan_power
= state
;
2949 static ssize_t
sony_pic_wwanpower_store(struct device
*dev
,
2950 struct device_attribute
*attr
,
2951 const char *buffer
, size_t count
)
2953 unsigned long value
;
2957 if (kstrtoul(buffer
, 10, &value
))
2960 mutex_lock(&spic_dev
.lock
);
2961 __sony_pic_set_wwanpower(value
);
2962 mutex_unlock(&spic_dev
.lock
);
2967 static ssize_t
sony_pic_wwanpower_show(struct device
*dev
,
2968 struct device_attribute
*attr
, char *buffer
)
2971 mutex_lock(&spic_dev
.lock
);
2972 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.wwan_power
);
2973 mutex_unlock(&spic_dev
.lock
);
2977 /* bluetooth subsystem power state */
2978 static void __sony_pic_set_bluetoothpower(u8 state
)
2981 if (spic_dev
.bluetooth_power
== state
)
2983 sony_pic_call2(0x96, state
);
2984 sony_pic_call1(0x82);
2985 spic_dev
.bluetooth_power
= state
;
2988 static ssize_t
sony_pic_bluetoothpower_store(struct device
*dev
,
2989 struct device_attribute
*attr
,
2990 const char *buffer
, size_t count
)
2992 unsigned long value
;
2996 if (kstrtoul(buffer
, 10, &value
))
2999 mutex_lock(&spic_dev
.lock
);
3000 __sony_pic_set_bluetoothpower(value
);
3001 mutex_unlock(&spic_dev
.lock
);
3006 static ssize_t
sony_pic_bluetoothpower_show(struct device
*dev
,
3007 struct device_attribute
*attr
, char *buffer
)
3010 mutex_lock(&spic_dev
.lock
);
3011 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.bluetooth_power
);
3012 mutex_unlock(&spic_dev
.lock
);
3017 /* FAN0 information (reverse engineered from ACPI tables) */
3018 #define SONY_PIC_FAN0_STATUS 0x93
3019 static int sony_pic_set_fanspeed(unsigned long value
)
3021 return ec_write(SONY_PIC_FAN0_STATUS
, value
);
3024 static int sony_pic_get_fanspeed(u8
*value
)
3026 return ec_read(SONY_PIC_FAN0_STATUS
, value
);
3029 static ssize_t
sony_pic_fanspeed_store(struct device
*dev
,
3030 struct device_attribute
*attr
,
3031 const char *buffer
, size_t count
)
3033 unsigned long value
;
3037 if (kstrtoul(buffer
, 10, &value
))
3040 if (sony_pic_set_fanspeed(value
))
3046 static ssize_t
sony_pic_fanspeed_show(struct device
*dev
,
3047 struct device_attribute
*attr
, char *buffer
)
3050 if (sony_pic_get_fanspeed(&value
))
3053 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
3056 #define SPIC_ATTR(_name, _mode) \
3057 struct device_attribute spic_attr_##_name = __ATTR(_name, \
3058 _mode, sony_pic_## _name ##_show, \
3059 sony_pic_## _name ##_store)
3061 static SPIC_ATTR(bluetoothpower
, 0644);
3062 static SPIC_ATTR(wwanpower
, 0644);
3063 static SPIC_ATTR(fanspeed
, 0644);
3065 static struct attribute
*spic_attributes
[] = {
3066 &spic_attr_bluetoothpower
.attr
,
3067 &spic_attr_wwanpower
.attr
,
3068 &spic_attr_fanspeed
.attr
,
3072 static struct attribute_group spic_attribute_group
= {
3073 .attrs
= spic_attributes
3076 /******** SONYPI compatibility **********/
3077 #ifdef CONFIG_SONYPI_COMPAT
3079 /* battery / brightness / temperature addresses */
3080 #define SONYPI_BAT_FLAGS 0x81
3081 #define SONYPI_LCD_LIGHT 0x96
3082 #define SONYPI_BAT1_PCTRM 0xa0
3083 #define SONYPI_BAT1_LEFT 0xa2
3084 #define SONYPI_BAT1_MAXRT 0xa4
3085 #define SONYPI_BAT2_PCTRM 0xa8
3086 #define SONYPI_BAT2_LEFT 0xaa
3087 #define SONYPI_BAT2_MAXRT 0xac
3088 #define SONYPI_BAT1_MAXTK 0xb0
3089 #define SONYPI_BAT1_FULL 0xb2
3090 #define SONYPI_BAT2_MAXTK 0xb8
3091 #define SONYPI_BAT2_FULL 0xba
3092 #define SONYPI_TEMP_STATUS 0xC1
3094 struct sonypi_compat_s
{
3095 struct fasync_struct
*fifo_async
;
3097 spinlock_t fifo_lock
;
3098 wait_queue_head_t fifo_proc_list
;
3099 atomic_t open_count
;
3101 static struct sonypi_compat_s sonypi_compat
= {
3102 .open_count
= ATOMIC_INIT(0),
3105 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
3107 return fasync_helper(fd
, filp
, on
, &sonypi_compat
.fifo_async
);
3110 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
3112 atomic_dec(&sonypi_compat
.open_count
);
3116 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
3118 /* Flush input queue on first open */
3119 unsigned long flags
;
3121 spin_lock_irqsave(&sonypi_compat
.fifo_lock
, flags
);
3123 if (atomic_inc_return(&sonypi_compat
.open_count
) == 1)
3124 kfifo_reset(&sonypi_compat
.fifo
);
3126 spin_unlock_irqrestore(&sonypi_compat
.fifo_lock
, flags
);
3131 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
3132 size_t count
, loff_t
*pos
)
3137 if ((kfifo_len(&sonypi_compat
.fifo
) == 0) &&
3138 (file
->f_flags
& O_NONBLOCK
))
3141 ret
= wait_event_interruptible(sonypi_compat
.fifo_proc_list
,
3142 kfifo_len(&sonypi_compat
.fifo
) != 0);
3146 while (ret
< count
&&
3147 (kfifo_out_locked(&sonypi_compat
.fifo
, &c
, sizeof(c
),
3148 &sonypi_compat
.fifo_lock
) == sizeof(c
))) {
3149 if (put_user(c
, buf
++))
3155 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
3156 inode
->i_atime
= current_fs_time(inode
->i_sb
);
3162 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
3164 poll_wait(file
, &sonypi_compat
.fifo_proc_list
, wait
);
3165 if (kfifo_len(&sonypi_compat
.fifo
))
3166 return POLLIN
| POLLRDNORM
;
3170 static int ec_read16(u8 addr
, u16
*value
)
3173 if (ec_read(addr
, &val_lb
))
3175 if (ec_read(addr
+ 1, &val_hb
))
3177 *value
= val_lb
| (val_hb
<< 8);
3181 static long sonypi_misc_ioctl(struct file
*fp
, unsigned int cmd
,
3185 void __user
*argp
= (void __user
*)arg
;
3190 mutex_lock(&spic_dev
.lock
);
3192 case SONYPI_IOCGBRT
:
3193 if (sony_bl_props
.dev
== NULL
) {
3197 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
,
3202 val8
= ((value
& 0xff) - 1) << 5;
3203 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3206 case SONYPI_IOCSBRT
:
3207 if (sony_bl_props
.dev
== NULL
) {
3211 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3215 value
= (val8
>> 5) + 1;
3216 if (sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &value
,
3221 /* sync the backlight device status */
3222 sony_bl_props
.dev
->props
.brightness
=
3223 sony_backlight_get_brightness(sony_bl_props
.dev
);
3225 case SONYPI_IOCGBAT1CAP
:
3226 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
3230 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3233 case SONYPI_IOCGBAT1REM
:
3234 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
3238 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3241 case SONYPI_IOCGBAT2CAP
:
3242 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
3246 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3249 case SONYPI_IOCGBAT2REM
:
3250 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
3254 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3257 case SONYPI_IOCGBATFLAGS
:
3258 if (ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
3263 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3266 case SONYPI_IOCGBLUE
:
3267 val8
= spic_dev
.bluetooth_power
;
3268 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3271 case SONYPI_IOCSBLUE
:
3272 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3276 __sony_pic_set_bluetoothpower(val8
);
3279 case SONYPI_IOCGFAN
:
3280 if (sony_pic_get_fanspeed(&val8
)) {
3284 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3287 case SONYPI_IOCSFAN
:
3288 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3292 if (sony_pic_set_fanspeed(val8
))
3295 /* GET Temperature (useful under APM) */
3296 case SONYPI_IOCGTEMP
:
3297 if (ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
3301 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3307 mutex_unlock(&spic_dev
.lock
);
3311 static const struct file_operations sonypi_misc_fops
= {
3312 .owner
= THIS_MODULE
,
3313 .read
= sonypi_misc_read
,
3314 .poll
= sonypi_misc_poll
,
3315 .open
= sonypi_misc_open
,
3316 .release
= sonypi_misc_release
,
3317 .fasync
= sonypi_misc_fasync
,
3318 .unlocked_ioctl
= sonypi_misc_ioctl
,
3319 .llseek
= noop_llseek
,
3322 static struct miscdevice sonypi_misc_device
= {
3323 .minor
= MISC_DYNAMIC_MINOR
,
3325 .fops
= &sonypi_misc_fops
,
3328 static void sonypi_compat_report_event(u8 event
)
3330 kfifo_in_locked(&sonypi_compat
.fifo
, (unsigned char *)&event
,
3331 sizeof(event
), &sonypi_compat
.fifo_lock
);
3332 kill_fasync(&sonypi_compat
.fifo_async
, SIGIO
, POLL_IN
);
3333 wake_up_interruptible(&sonypi_compat
.fifo_proc_list
);
3336 static int sonypi_compat_init(void)
3340 spin_lock_init(&sonypi_compat
.fifo_lock
);
3342 kfifo_alloc(&sonypi_compat
.fifo
, SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
3344 pr_err("kfifo_alloc failed\n");
3348 init_waitqueue_head(&sonypi_compat
.fifo_proc_list
);
3351 sonypi_misc_device
.minor
= minor
;
3352 error
= misc_register(&sonypi_misc_device
);
3354 pr_err("misc_register failed\n");
3355 goto err_free_kfifo
;
3358 pr_info("device allocated minor is %d\n",
3359 sonypi_misc_device
.minor
);
3364 kfifo_free(&sonypi_compat
.fifo
);
3368 static void sonypi_compat_exit(void)
3370 misc_deregister(&sonypi_misc_device
);
3371 kfifo_free(&sonypi_compat
.fifo
);
3374 static int sonypi_compat_init(void) { return 0; }
3375 static void sonypi_compat_exit(void) { }
3376 static void sonypi_compat_report_event(u8 event
) { }
3377 #endif /* CONFIG_SONYPI_COMPAT */
3383 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
3386 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
3388 switch (resource
->type
) {
3389 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
3391 /* start IO enumeration */
3392 struct sony_pic_ioport
*ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
3396 list_add(&ioport
->list
, &dev
->ioports
);
3400 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
3401 /* end IO enumeration */
3404 case ACPI_RESOURCE_TYPE_IRQ
:
3406 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
3407 struct sony_pic_irq
*interrupt
= NULL
;
3408 if (!p
|| !p
->interrupt_count
) {
3410 * IRQ descriptors may have no IRQ# bits set,
3411 * particularly those those w/ _STA disabled
3413 dprintk("Blank IRQ resource\n");
3416 for (i
= 0; i
< p
->interrupt_count
; i
++) {
3417 if (!p
->interrupts
[i
]) {
3418 pr_warn("Invalid IRQ %d\n",
3422 interrupt
= kzalloc(sizeof(*interrupt
),
3427 list_add(&interrupt
->list
, &dev
->interrupts
);
3428 interrupt
->irq
.triggering
= p
->triggering
;
3429 interrupt
->irq
.polarity
= p
->polarity
;
3430 interrupt
->irq
.sharable
= p
->sharable
;
3431 interrupt
->irq
.interrupt_count
= 1;
3432 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
3436 case ACPI_RESOURCE_TYPE_IO
:
3438 struct acpi_resource_io
*io
= &resource
->data
.io
;
3439 struct sony_pic_ioport
*ioport
=
3440 list_first_entry(&dev
->ioports
, struct sony_pic_ioport
, list
);
3442 dprintk("Blank IO resource\n");
3446 if (!ioport
->io1
.minimum
) {
3447 memcpy(&ioport
->io1
, io
, sizeof(*io
));
3448 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport
->io1
.minimum
,
3449 ioport
->io1
.address_length
);
3451 else if (!ioport
->io2
.minimum
) {
3452 memcpy(&ioport
->io2
, io
, sizeof(*io
));
3453 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport
->io2
.minimum
,
3454 ioport
->io2
.address_length
);
3457 pr_err("Unknown SPIC Type, more than 2 IO Ports\n");
3463 dprintk("Resource %d isn't an IRQ nor an IO port\n",
3466 case ACPI_RESOURCE_TYPE_END_TAG
:
3469 return AE_CTRL_TERMINATE
;
3472 static int sony_pic_possible_resources(struct acpi_device
*device
)
3475 acpi_status status
= AE_OK
;
3480 /* get device status */
3481 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
3482 dprintk("Evaluating _STA\n");
3483 result
= acpi_bus_get_status(device
);
3485 pr_warn("Unable to read status\n");
3489 if (!device
->status
.enabled
)
3490 dprintk("Device disabled\n");
3492 dprintk("Device enabled\n");
3495 * Query and parse 'method'
3497 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
3498 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
3499 sony_pic_read_possible_resource
, &spic_dev
);
3500 if (ACPI_FAILURE(status
)) {
3501 pr_warn("Failure evaluating %s\n", METHOD_NAME__PRS
);
3509 * Disable the spic device by calling its _DIS method
3511 static int sony_pic_disable(struct acpi_device
*device
)
3513 acpi_status ret
= acpi_evaluate_object(device
->handle
, "_DIS", NULL
,
3516 if (ACPI_FAILURE(ret
) && ret
!= AE_NOT_FOUND
)
3519 dprintk("Device disabled\n");
3525 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
3527 * Call _SRS to set current resources
3529 static int sony_pic_enable(struct acpi_device
*device
,
3530 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
3534 /* Type 1 resource layout is:
3540 * Type 2 and 3 resource layout is:
3546 struct acpi_resource res1
;
3547 struct acpi_resource res2
;
3548 struct acpi_resource res3
;
3549 struct acpi_resource res4
;
3551 struct acpi_buffer buffer
= { 0, NULL
};
3553 if (!ioport
|| !irq
)
3556 /* init acpi_buffer */
3557 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
3561 buffer
.length
= sizeof(*resource
) + 1;
3562 buffer
.pointer
= resource
;
3564 /* setup Type 1 resources */
3565 if (spic_dev
.model
== SONYPI_DEVICE_TYPE1
) {
3567 /* setup io resources */
3568 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
3569 resource
->res1
.length
= sizeof(struct acpi_resource
);
3570 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
3571 sizeof(struct acpi_resource_io
));
3573 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IO
;
3574 resource
->res2
.length
= sizeof(struct acpi_resource
);
3575 memcpy(&resource
->res2
.data
.io
, &ioport
->io2
,
3576 sizeof(struct acpi_resource_io
));
3578 /* setup irq resource */
3579 resource
->res3
.type
= ACPI_RESOURCE_TYPE_IRQ
;
3580 resource
->res3
.length
= sizeof(struct acpi_resource
);
3581 memcpy(&resource
->res3
.data
.irq
, &irq
->irq
,
3582 sizeof(struct acpi_resource_irq
));
3583 /* we requested a shared irq */
3584 resource
->res3
.data
.irq
.sharable
= ACPI_SHARED
;
3586 resource
->res4
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
3589 /* setup Type 2/3 resources */
3591 /* setup io resource */
3592 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
3593 resource
->res1
.length
= sizeof(struct acpi_resource
);
3594 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
3595 sizeof(struct acpi_resource_io
));
3597 /* setup irq resource */
3598 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IRQ
;
3599 resource
->res2
.length
= sizeof(struct acpi_resource
);
3600 memcpy(&resource
->res2
.data
.irq
, &irq
->irq
,
3601 sizeof(struct acpi_resource_irq
));
3602 /* we requested a shared irq */
3603 resource
->res2
.data
.irq
.sharable
= ACPI_SHARED
;
3605 resource
->res3
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
3608 /* Attempt to set the resource */
3609 dprintk("Evaluating _SRS\n");
3610 status
= acpi_set_current_resources(device
->handle
, &buffer
);
3612 /* check for total failure */
3613 if (ACPI_FAILURE(status
)) {
3614 pr_err("Error evaluating _SRS\n");
3619 /* Necessary device initializations calls (from sonypi) */
3620 sony_pic_call1(0x82);
3621 sony_pic_call2(0x81, 0xff);
3622 sony_pic_call1(compat
? 0x92 : 0x82);
3631 * ISR: some event is available
3634 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
3639 u8 device_event
= 0;
3641 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
3643 ev
= inb_p(dev
->cur_ioport
->io1
.minimum
);
3644 if (dev
->cur_ioport
->io2
.minimum
)
3645 data_mask
= inb_p(dev
->cur_ioport
->io2
.minimum
);
3647 data_mask
= inb_p(dev
->cur_ioport
->io1
.minimum
+
3648 dev
->evport_offset
);
3650 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
3651 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
3652 dev
->evport_offset
);
3654 if (ev
== 0x00 || ev
== 0xff)
3657 for (i
= 0; dev
->event_types
[i
].mask
; i
++) {
3659 if ((data_mask
& dev
->event_types
[i
].data
) !=
3660 dev
->event_types
[i
].data
)
3663 if (!(mask
& dev
->event_types
[i
].mask
))
3666 for (j
= 0; dev
->event_types
[i
].events
[j
].event
; j
++) {
3667 if (ev
== dev
->event_types
[i
].events
[j
].data
) {
3669 dev
->event_types
[i
].events
[j
].event
;
3670 /* some events may require ignoring */
3677 /* Still not able to decode the event try to pass
3678 * it over to the minidriver
3680 if (dev
->handle_irq
&& dev
->handle_irq(data_mask
, ev
) == 0)
3683 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
3684 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
3685 dev
->evport_offset
);
3689 sony_laptop_report_input_event(device_event
);
3690 acpi_bus_generate_proc_event(dev
->acpi_dev
, 1, device_event
);
3691 sonypi_compat_report_event(device_event
);
3700 static int sony_pic_remove(struct acpi_device
*device
, int type
)
3702 struct sony_pic_ioport
*io
, *tmp_io
;
3703 struct sony_pic_irq
*irq
, *tmp_irq
;
3705 if (sony_pic_disable(device
)) {
3706 pr_err("Couldn't disable device\n");
3710 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
3711 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
3712 spic_dev
.cur_ioport
->io1
.address_length
);
3713 if (spic_dev
.cur_ioport
->io2
.minimum
)
3714 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
3715 spic_dev
.cur_ioport
->io2
.address_length
);
3717 sonypi_compat_exit();
3719 sony_laptop_remove_input();
3722 sysfs_remove_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
3725 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
3726 list_del(&io
->list
);
3729 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
3730 list_del(&irq
->list
);
3733 spic_dev
.cur_ioport
= NULL
;
3734 spic_dev
.cur_irq
= NULL
;
3736 dprintk(SONY_PIC_DRIVER_NAME
" removed.\n");
3740 static int sony_pic_add(struct acpi_device
*device
)
3743 struct sony_pic_ioport
*io
, *tmp_io
;
3744 struct sony_pic_irq
*irq
, *tmp_irq
;
3746 pr_info("%s v%s\n", SONY_PIC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
3748 spic_dev
.acpi_dev
= device
;
3749 strcpy(acpi_device_class(device
), "sony/hotkey");
3750 sony_pic_detect_device_type(&spic_dev
);
3751 mutex_init(&spic_dev
.lock
);
3753 /* read _PRS resources */
3754 result
= sony_pic_possible_resources(device
);
3756 pr_err("Unable to read possible resources\n");
3757 goto err_free_resources
;
3760 /* setup input devices and helper fifo */
3761 result
= sony_laptop_setup_input(device
);
3763 pr_err("Unable to create input devices\n");
3764 goto err_free_resources
;
3767 if (sonypi_compat_init())
3768 goto err_remove_input
;
3770 /* request io port */
3771 list_for_each_entry_reverse(io
, &spic_dev
.ioports
, list
) {
3772 if (request_region(io
->io1
.minimum
, io
->io1
.address_length
,
3773 "Sony Programmable I/O Device")) {
3774 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
3775 io
->io1
.minimum
, io
->io1
.maximum
,
3776 io
->io1
.address_length
);
3777 /* Type 1 have 2 ioports */
3778 if (io
->io2
.minimum
) {
3779 if (request_region(io
->io2
.minimum
,
3780 io
->io2
.address_length
,
3781 "Sony Programmable I/O Device")) {
3782 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
3783 io
->io2
.minimum
, io
->io2
.maximum
,
3784 io
->io2
.address_length
);
3785 spic_dev
.cur_ioport
= io
;
3789 dprintk("Unable to get I/O port2: "
3790 "0x%.4x (0x%.4x) + 0x%.2x\n",
3791 io
->io2
.minimum
, io
->io2
.maximum
,
3792 io
->io2
.address_length
);
3793 release_region(io
->io1
.minimum
,
3794 io
->io1
.address_length
);
3798 spic_dev
.cur_ioport
= io
;
3803 if (!spic_dev
.cur_ioport
) {
3804 pr_err("Failed to request_region\n");
3806 goto err_remove_compat
;
3810 list_for_each_entry_reverse(irq
, &spic_dev
.interrupts
, list
) {
3811 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
3812 0, "sony-laptop", &spic_dev
)) {
3813 dprintk("IRQ: %d - triggering: %d - "
3814 "polarity: %d - shr: %d\n",
3815 irq
->irq
.interrupts
[0],
3816 irq
->irq
.triggering
,
3819 spic_dev
.cur_irq
= irq
;
3823 if (!spic_dev
.cur_irq
) {
3824 pr_err("Failed to request_irq\n");
3826 goto err_release_region
;
3829 /* set resource status _SRS */
3830 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
3832 pr_err("Couldn't enable device\n");
3836 spic_dev
.bluetooth_power
= -1;
3837 /* create device attributes */
3838 result
= sony_pf_add();
3840 goto err_disable_device
;
3842 result
= sysfs_create_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
3852 sony_pic_disable(device
);
3855 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
3858 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
3859 spic_dev
.cur_ioport
->io1
.address_length
);
3860 if (spic_dev
.cur_ioport
->io2
.minimum
)
3861 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
3862 spic_dev
.cur_ioport
->io2
.address_length
);
3865 sonypi_compat_exit();
3868 sony_laptop_remove_input();
3871 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
3872 list_del(&io
->list
);
3875 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
3876 list_del(&irq
->list
);
3879 spic_dev
.cur_ioport
= NULL
;
3880 spic_dev
.cur_irq
= NULL
;
3885 static int sony_pic_suspend(struct acpi_device
*device
, pm_message_t state
)
3887 if (sony_pic_disable(device
))
3892 static int sony_pic_resume(struct acpi_device
*device
)
3894 sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
3898 static const struct acpi_device_id sony_pic_device_ids
[] = {
3903 static struct acpi_driver sony_pic_driver
= {
3904 .name
= SONY_PIC_DRIVER_NAME
,
3905 .class = SONY_PIC_CLASS
,
3906 .ids
= sony_pic_device_ids
,
3907 .owner
= THIS_MODULE
,
3909 .add
= sony_pic_add
,
3910 .remove
= sony_pic_remove
,
3911 .suspend
= sony_pic_suspend
,
3912 .resume
= sony_pic_resume
,
3916 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
3918 .ident
= "Sony Vaio",
3920 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
3921 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
3925 .ident
= "Sony Vaio",
3927 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
3928 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
3934 static int __init
sony_laptop_init(void)
3938 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
3939 result
= acpi_bus_register_driver(&sony_pic_driver
);
3941 pr_err("Unable to register SPIC driver\n");
3944 spic_drv_registered
= 1;
3947 result
= acpi_bus_register_driver(&sony_nc_driver
);
3949 pr_err("Unable to register SNC driver\n");
3950 goto out_unregister_pic
;
3956 if (spic_drv_registered
)
3957 acpi_bus_unregister_driver(&sony_pic_driver
);
3962 static void __exit
sony_laptop_exit(void)
3964 acpi_bus_unregister_driver(&sony_nc_driver
);
3965 if (spic_drv_registered
)
3966 acpi_bus_unregister_driver(&sony_pic_driver
);
3969 module_init(sony_laptop_init
);
3970 module_exit(sony_laptop_exit
);