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 #ifdef CONFIG_PM_SLEEP
144 static void sony_nc_kbd_backlight_resume(void);
145 static void sony_nc_thermal_resume(void);
147 static int sony_nc_kbd_backlight_setup(struct platform_device
*pd
,
148 unsigned int handle
);
149 static void sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
);
151 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
152 unsigned int handle
);
153 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
);
155 static int sony_nc_thermal_setup(struct platform_device
*pd
);
156 static void sony_nc_thermal_cleanup(struct platform_device
*pd
);
158 static int sony_nc_lid_resume_setup(struct platform_device
*pd
);
159 static void sony_nc_lid_resume_cleanup(struct platform_device
*pd
);
161 static int sony_nc_highspeed_charging_setup(struct platform_device
*pd
);
162 static void sony_nc_highspeed_charging_cleanup(struct platform_device
*pd
);
164 static int sony_nc_touchpad_setup(struct platform_device
*pd
,
165 unsigned int handle
);
166 static void sony_nc_touchpad_cleanup(struct platform_device
*pd
);
168 enum sony_nc_rfkill
{
176 static int sony_rfkill_handle
;
177 static struct rfkill
*sony_rfkill_devices
[N_SONY_RFKILL
];
178 static int sony_rfkill_address
[N_SONY_RFKILL
] = {0x300, 0x500, 0x700, 0x900};
179 static int sony_nc_rfkill_setup(struct acpi_device
*device
,
180 unsigned int handle
);
181 static void sony_nc_rfkill_cleanup(void);
182 static void sony_nc_rfkill_update(void);
184 /*********** Input Devices ***********/
186 #define SONY_LAPTOP_BUF_SIZE 128
187 struct sony_laptop_input_s
{
189 struct input_dev
*jog_dev
;
190 struct input_dev
*key_dev
;
192 spinlock_t fifo_lock
;
193 struct timer_list release_key_timer
;
196 static struct sony_laptop_input_s sony_laptop_input
= {
197 .users
= ATOMIC_INIT(0),
200 struct sony_laptop_keypress
{
201 struct input_dev
*dev
;
205 /* Correspondance table between sonypi events
206 * and input layer indexes in the keymap
208 static int sony_laptop_input_index
[] = {
210 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
211 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
212 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
213 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
214 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
215 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
216 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
217 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
218 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
219 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
220 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
221 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
222 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
223 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
224 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
225 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
226 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
227 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
228 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
229 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
230 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
231 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
232 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
233 17, /* 24 SONYPI_EVENT_FNKEY_1 */
234 18, /* 25 SONYPI_EVENT_FNKEY_2 */
235 19, /* 26 SONYPI_EVENT_FNKEY_D */
236 20, /* 27 SONYPI_EVENT_FNKEY_E */
237 21, /* 28 SONYPI_EVENT_FNKEY_F */
238 22, /* 29 SONYPI_EVENT_FNKEY_S */
239 23, /* 30 SONYPI_EVENT_FNKEY_B */
240 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
241 25, /* 32 SONYPI_EVENT_PKEY_P1 */
242 26, /* 33 SONYPI_EVENT_PKEY_P2 */
243 27, /* 34 SONYPI_EVENT_PKEY_P3 */
244 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
245 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
246 -1, /* 37 SONYPI_EVENT_LID_OPENED */
247 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
248 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
249 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
250 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
251 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
252 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
253 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
254 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
255 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
256 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
257 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
258 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
259 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
260 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
261 43, /* 52 SONYPI_EVENT_MEYE_FACE */
262 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
263 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
264 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
265 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
266 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
267 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
268 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
269 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
270 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
271 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
272 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
273 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
274 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
275 53, /* 66 SONYPI_EVENT_PKEY_P4 */
276 54, /* 67 SONYPI_EVENT_PKEY_P5 */
277 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
278 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
279 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
280 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
281 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
282 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */
285 static int sony_laptop_input_keycode_map
[] = {
286 KEY_CAMERA
, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
287 KEY_RESERVED
, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
288 KEY_RESERVED
, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
289 KEY_RESERVED
, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
290 KEY_FN_ESC
, /* 4 SONYPI_EVENT_FNKEY_ESC */
291 KEY_FN_F1
, /* 5 SONYPI_EVENT_FNKEY_F1 */
292 KEY_FN_F2
, /* 6 SONYPI_EVENT_FNKEY_F2 */
293 KEY_FN_F3
, /* 7 SONYPI_EVENT_FNKEY_F3 */
294 KEY_FN_F4
, /* 8 SONYPI_EVENT_FNKEY_F4 */
295 KEY_FN_F5
, /* 9 SONYPI_EVENT_FNKEY_F5 */
296 KEY_FN_F6
, /* 10 SONYPI_EVENT_FNKEY_F6 */
297 KEY_FN_F7
, /* 11 SONYPI_EVENT_FNKEY_F7 */
298 KEY_FN_F8
, /* 12 SONYPI_EVENT_FNKEY_F8 */
299 KEY_FN_F9
, /* 13 SONYPI_EVENT_FNKEY_F9 */
300 KEY_FN_F10
, /* 14 SONYPI_EVENT_FNKEY_F10 */
301 KEY_FN_F11
, /* 15 SONYPI_EVENT_FNKEY_F11 */
302 KEY_FN_F12
, /* 16 SONYPI_EVENT_FNKEY_F12 */
303 KEY_FN_F1
, /* 17 SONYPI_EVENT_FNKEY_1 */
304 KEY_FN_F2
, /* 18 SONYPI_EVENT_FNKEY_2 */
305 KEY_FN_D
, /* 19 SONYPI_EVENT_FNKEY_D */
306 KEY_FN_E
, /* 20 SONYPI_EVENT_FNKEY_E */
307 KEY_FN_F
, /* 21 SONYPI_EVENT_FNKEY_F */
308 KEY_FN_S
, /* 22 SONYPI_EVENT_FNKEY_S */
309 KEY_FN_B
, /* 23 SONYPI_EVENT_FNKEY_B */
310 KEY_BLUETOOTH
, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
311 KEY_PROG1
, /* 25 SONYPI_EVENT_PKEY_P1 */
312 KEY_PROG2
, /* 26 SONYPI_EVENT_PKEY_P2 */
313 KEY_PROG3
, /* 27 SONYPI_EVENT_PKEY_P3 */
314 KEY_BACK
, /* 28 SONYPI_EVENT_BACK_PRESSED */
315 KEY_BLUETOOTH
, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
316 KEY_BLUETOOTH
, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
317 KEY_HELP
, /* 31 SONYPI_EVENT_HELP_PRESSED */
318 KEY_FN
, /* 32 SONYPI_EVENT_FNKEY_ONLY */
319 KEY_RESERVED
, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
320 KEY_RESERVED
, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
321 KEY_RESERVED
, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
322 KEY_RESERVED
, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
323 KEY_RESERVED
, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
324 KEY_RESERVED
, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
325 KEY_RESERVED
, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
326 KEY_RESERVED
, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
327 KEY_ZOOM
, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
328 BTN_THUMB
, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
329 KEY_RESERVED
, /* 43 SONYPI_EVENT_MEYE_FACE */
330 KEY_RESERVED
, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
331 KEY_RESERVED
, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
332 KEY_RESERVED
, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
333 KEY_WLAN
, /* 47 SONYPI_EVENT_WIRELESS_ON */
334 KEY_WLAN
, /* 48 SONYPI_EVENT_WIRELESS_OFF */
335 KEY_ZOOMIN
, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
336 KEY_ZOOMOUT
, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
337 KEY_EJECTCD
, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
338 KEY_F13
, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
339 KEY_PROG4
, /* 53 SONYPI_EVENT_PKEY_P4 */
340 KEY_F14
, /* 54 SONYPI_EVENT_PKEY_P5 */
341 KEY_F15
, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
342 KEY_VOLUMEUP
, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
343 KEY_VOLUMEDOWN
, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
344 KEY_MEDIA
, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
345 KEY_VENDOR
, /* 59 SONYPI_EVENT_VENDOR_PRESSED */
348 /* release buttons after a short delay if pressed */
349 static void do_sony_laptop_release_key(unsigned long unused
)
351 struct sony_laptop_keypress kp
;
354 spin_lock_irqsave(&sony_laptop_input
.fifo_lock
, flags
);
356 if (kfifo_out(&sony_laptop_input
.fifo
,
357 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
358 input_report_key(kp
.dev
, kp
.key
, 0);
362 /* If there is something in the fifo schedule next release. */
363 if (kfifo_len(&sony_laptop_input
.fifo
) != 0)
364 mod_timer(&sony_laptop_input
.release_key_timer
,
365 jiffies
+ msecs_to_jiffies(10));
367 spin_unlock_irqrestore(&sony_laptop_input
.fifo_lock
, flags
);
370 /* forward event to the input subsystem */
371 static void sony_laptop_report_input_event(u8 event
)
373 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
374 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
375 struct sony_laptop_keypress kp
= { NULL
};
378 if (event
== SONYPI_EVENT_FNKEY_RELEASED
||
379 event
== SONYPI_EVENT_ANYBUTTON_RELEASED
) {
380 /* Nothing, not all VAIOs generate this event */
387 case SONYPI_EVENT_JOGDIAL_UP
:
388 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
389 input_report_rel(jog_dev
, REL_WHEEL
, 1);
393 case SONYPI_EVENT_JOGDIAL_DOWN
:
394 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
395 input_report_rel(jog_dev
, REL_WHEEL
, -1);
400 case SONYPI_EVENT_JOGDIAL_PRESSED
:
406 if (event
>= ARRAY_SIZE(sony_laptop_input_index
)) {
407 dprintk("sony_laptop_report_input_event, event not known: %d\n", event
);
410 if ((scancode
= sony_laptop_input_index
[event
]) != -1) {
411 kp
.key
= sony_laptop_input_keycode_map
[scancode
];
412 if (kp
.key
!= KEY_UNKNOWN
)
419 /* if we have a scancode we emit it so we can always
422 input_event(kp
.dev
, EV_MSC
, MSC_SCAN
, scancode
);
423 input_report_key(kp
.dev
, kp
.key
, 1);
426 /* schedule key release */
427 kfifo_in_locked(&sony_laptop_input
.fifo
,
428 (unsigned char *)&kp
, sizeof(kp
),
429 &sony_laptop_input
.fifo_lock
);
430 mod_timer(&sony_laptop_input
.release_key_timer
,
431 jiffies
+ msecs_to_jiffies(10));
433 dprintk("unknown input event %.2x\n", event
);
436 static int sony_laptop_setup_input(struct acpi_device
*acpi_device
)
438 struct input_dev
*jog_dev
;
439 struct input_dev
*key_dev
;
443 /* don't run again if already initialized */
444 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
448 spin_lock_init(&sony_laptop_input
.fifo_lock
);
449 error
= kfifo_alloc(&sony_laptop_input
.fifo
,
450 SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
452 pr_err("kfifo_alloc failed\n");
456 setup_timer(&sony_laptop_input
.release_key_timer
,
457 do_sony_laptop_release_key
, 0);
460 key_dev
= input_allocate_device();
466 key_dev
->name
= "Sony Vaio Keys";
467 key_dev
->id
.bustype
= BUS_ISA
;
468 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
469 key_dev
->dev
.parent
= &acpi_device
->dev
;
471 /* Initialize the Input Drivers: special keys */
472 input_set_capability(key_dev
, EV_MSC
, MSC_SCAN
);
474 __set_bit(EV_KEY
, key_dev
->evbit
);
475 key_dev
->keycodesize
= sizeof(sony_laptop_input_keycode_map
[0]);
476 key_dev
->keycodemax
= ARRAY_SIZE(sony_laptop_input_keycode_map
);
477 key_dev
->keycode
= &sony_laptop_input_keycode_map
;
478 for (i
= 0; i
< ARRAY_SIZE(sony_laptop_input_keycode_map
); i
++)
479 __set_bit(sony_laptop_input_keycode_map
[i
], key_dev
->keybit
);
480 __clear_bit(KEY_RESERVED
, key_dev
->keybit
);
482 error
= input_register_device(key_dev
);
484 goto err_free_keydev
;
486 sony_laptop_input
.key_dev
= key_dev
;
489 jog_dev
= input_allocate_device();
492 goto err_unregister_keydev
;
495 jog_dev
->name
= "Sony Vaio Jogdial";
496 jog_dev
->id
.bustype
= BUS_ISA
;
497 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
498 jog_dev
->dev
.parent
= &acpi_device
->dev
;
500 input_set_capability(jog_dev
, EV_KEY
, BTN_MIDDLE
);
501 input_set_capability(jog_dev
, EV_REL
, REL_WHEEL
);
503 error
= input_register_device(jog_dev
);
505 goto err_free_jogdev
;
507 sony_laptop_input
.jog_dev
= jog_dev
;
512 input_free_device(jog_dev
);
514 err_unregister_keydev
:
515 input_unregister_device(key_dev
);
516 /* to avoid kref underflow below at input_free_device */
520 input_free_device(key_dev
);
523 kfifo_free(&sony_laptop_input
.fifo
);
526 atomic_dec(&sony_laptop_input
.users
);
530 static void sony_laptop_remove_input(void)
532 struct sony_laptop_keypress kp
= { NULL
};
534 /* Cleanup only after the last user has gone */
535 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
538 del_timer_sync(&sony_laptop_input
.release_key_timer
);
541 * Generate key-up events for remaining keys. Note that we don't
542 * need locking since nobody is adding new events to the kfifo.
544 while (kfifo_out(&sony_laptop_input
.fifo
,
545 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
546 input_report_key(kp
.dev
, kp
.key
, 0);
550 /* destroy input devs */
551 input_unregister_device(sony_laptop_input
.key_dev
);
552 sony_laptop_input
.key_dev
= NULL
;
554 if (sony_laptop_input
.jog_dev
) {
555 input_unregister_device(sony_laptop_input
.jog_dev
);
556 sony_laptop_input
.jog_dev
= NULL
;
559 kfifo_free(&sony_laptop_input
.fifo
);
562 /*********** Platform Device ***********/
564 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
565 static struct platform_driver sony_pf_driver
= {
567 .name
= "sony-laptop",
568 .owner
= THIS_MODULE
,
571 static struct platform_device
*sony_pf_device
;
573 static int sony_pf_add(void)
577 /* don't run again if already initialized */
578 if (atomic_add_return(1, &sony_pf_users
) > 1)
581 ret
= platform_driver_register(&sony_pf_driver
);
585 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
586 if (!sony_pf_device
) {
588 goto out_platform_registered
;
591 ret
= platform_device_add(sony_pf_device
);
593 goto out_platform_alloced
;
597 out_platform_alloced
:
598 platform_device_put(sony_pf_device
);
599 sony_pf_device
= NULL
;
600 out_platform_registered
:
601 platform_driver_unregister(&sony_pf_driver
);
603 atomic_dec(&sony_pf_users
);
607 static void sony_pf_remove(void)
609 /* deregister only after the last user has gone */
610 if (!atomic_dec_and_test(&sony_pf_users
))
613 platform_device_unregister(sony_pf_device
);
614 platform_driver_unregister(&sony_pf_driver
);
617 /*********** SNC (SNY5001) Device ***********/
619 /* the device uses 1-based values, while the backlight subsystem uses
621 #define SONY_MAX_BRIGHTNESS 8
623 #define SNC_VALIDATE_IN 0
624 #define SNC_VALIDATE_OUT 1
626 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
628 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
629 const char *, size_t);
630 static int boolean_validate(const int, const int);
631 static int brightness_default_validate(const int, const int);
633 struct sony_nc_value
{
634 char *name
; /* name of the entry */
635 char **acpiget
; /* names of the ACPI get function */
636 char **acpiset
; /* names of the ACPI set function */
637 int (*validate
)(const int, const int); /* input/output validation */
638 int value
; /* current setting */
639 int valid
; /* Has ever been set */
640 int debug
; /* active only in debug mode ? */
641 struct device_attribute devattr
; /* sysfs attribute */
644 #define SNC_HANDLE_NAMES(_name, _values...) \
645 static char *snc_##_name[] = { _values, NULL }
647 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
649 .name = __stringify(_name), \
650 .acpiget = _getters, \
651 .acpiset = _setters, \
652 .validate = _validate, \
654 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
657 #define SNC_HANDLE_NULL { .name = NULL }
659 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
661 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
662 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
664 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
665 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
667 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
668 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
670 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
671 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
673 SNC_HANDLE_NAMES(lidstate_get
, "GLID");
675 SNC_HANDLE_NAMES(indicatorlamp_get
, "GILS");
676 SNC_HANDLE_NAMES(indicatorlamp_set
, "SILS");
678 SNC_HANDLE_NAMES(gainbass_get
, "GMGB");
679 SNC_HANDLE_NAMES(gainbass_set
, "CMGB");
681 SNC_HANDLE_NAMES(PID_get
, "GPID");
683 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
684 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
686 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
687 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
689 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
690 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
692 static struct sony_nc_value sony_nc_values
[] = {
693 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
694 snc_brightness_def_set
, brightness_default_validate
, 0),
695 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
696 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
697 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
698 boolean_validate
, 0),
699 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
700 boolean_validate
, 1),
701 SNC_HANDLE(lidstate
, snc_lidstate_get
, NULL
,
702 boolean_validate
, 0),
703 SNC_HANDLE(indicatorlamp
, snc_indicatorlamp_get
, snc_indicatorlamp_set
,
704 boolean_validate
, 0),
705 SNC_HANDLE(gainbass
, snc_gainbass_get
, snc_gainbass_set
,
706 boolean_validate
, 0),
707 /* unknown methods */
708 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
709 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
710 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
711 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
715 static acpi_handle sony_nc_acpi_handle
;
716 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
719 * acpi_evaluate_object wrappers
720 * all useful calls into SNC methods take one or zero parameters and return
721 * integers or arrays.
723 static union acpi_object
*__call_snc_method(acpi_handle handle
, char *method
,
726 union acpi_object
*result
= NULL
;
727 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
731 struct acpi_object_list params
;
732 union acpi_object in
;
733 in
.type
= ACPI_TYPE_INTEGER
;
734 in
.integer
.value
= *value
;
736 params
.pointer
= &in
;
737 status
= acpi_evaluate_object(handle
, method
, ¶ms
, &output
);
738 dprintk("__call_snc_method: [%s:0x%.8x%.8x]\n", method
,
739 (unsigned int)(*value
>> 32),
740 (unsigned int)*value
& 0xffffffff);
742 status
= acpi_evaluate_object(handle
, method
, NULL
, &output
);
743 dprintk("__call_snc_method: [%s]\n", method
);
746 if (ACPI_FAILURE(status
)) {
747 pr_err("Failed to evaluate [%s]\n", method
);
751 result
= (union acpi_object
*) output
.pointer
;
753 dprintk("No return object [%s]\n", method
);
758 static int sony_nc_int_call(acpi_handle handle
, char *name
, int *value
,
761 union acpi_object
*object
= NULL
;
764 object
= __call_snc_method(handle
, name
, &v
);
766 object
= __call_snc_method(handle
, name
, NULL
);
771 if (object
->type
!= ACPI_TYPE_INTEGER
) {
772 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
773 ACPI_TYPE_INTEGER
, object
->type
);
779 *result
= object
->integer
.value
;
785 #define MIN(a, b) (a > b ? b : a)
786 static int sony_nc_buffer_call(acpi_handle handle
, char *name
, u64
*value
,
787 void *buffer
, size_t buflen
)
790 union acpi_object
*object
= __call_snc_method(handle
, name
, value
);
795 if (object
->type
== ACPI_TYPE_BUFFER
)
796 len
= MIN(buflen
, object
->buffer
.length
);
798 else if (object
->type
== ACPI_TYPE_INTEGER
)
799 len
= MIN(buflen
, sizeof(object
->integer
.value
));
802 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
803 ACPI_TYPE_BUFFER
, object
->type
);
808 memcpy(buffer
, object
->buffer
.pointer
, len
);
813 struct sony_nc_handles
{
815 struct device_attribute devattr
;
818 static struct sony_nc_handles
*handles
;
820 static ssize_t
sony_nc_handles_show(struct device
*dev
,
821 struct device_attribute
*attr
, char *buffer
)
826 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
827 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "0x%.4x ",
830 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "\n");
835 static int sony_nc_handles_setup(struct platform_device
*pd
)
837 int i
, r
, result
, arg
;
839 handles
= kzalloc(sizeof(*handles
), GFP_KERNEL
);
843 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
845 r
= sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
,
848 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
850 handles
->cap
[i
] = result
;
855 sysfs_attr_init(&handles
->devattr
.attr
);
856 handles
->devattr
.attr
.name
= "handles";
857 handles
->devattr
.attr
.mode
= S_IRUGO
;
858 handles
->devattr
.show
= sony_nc_handles_show
;
860 /* allow reading capabilities via sysfs */
861 if (device_create_file(&pd
->dev
, &handles
->devattr
)) {
871 static int sony_nc_handles_cleanup(struct platform_device
*pd
)
875 device_remove_file(&pd
->dev
, &handles
->devattr
);
882 static int sony_find_snc_handle(int handle
)
886 /* not initialized yet, return early */
887 if (!handles
|| !handle
)
890 for (i
= 0; i
< 0x10; i
++) {
891 if (handles
->cap
[i
] == handle
) {
892 dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
897 dprintk("handle 0x%.4x not found\n", handle
);
901 static int sony_call_snc_handle(int handle
, int argument
, int *result
)
904 int offset
= sony_find_snc_handle(handle
);
909 arg
= offset
| argument
;
910 ret
= sony_nc_int_call(sony_nc_acpi_handle
, "SN07", &arg
, result
);
911 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", arg
, *result
);
916 * sony_nc_values input/output validate functions
919 /* brightness_default_validate:
921 * manipulate input output values to keep consistency with the
922 * backlight framework for which brightness values are 0-based.
924 static int brightness_default_validate(const int direction
, const int value
)
927 case SNC_VALIDATE_OUT
:
929 case SNC_VALIDATE_IN
:
930 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
938 * on input validate boolean values 0/1, on output just pass the
941 static int boolean_validate(const int direction
, const int value
)
943 if (direction
== SNC_VALIDATE_IN
) {
944 if (value
!= 0 && value
!= 1)
951 * Sysfs show/store common to all sony_nc_values
953 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
957 struct sony_nc_value
*item
=
958 container_of(attr
, struct sony_nc_value
, devattr
);
963 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiget
, NULL
,
969 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
971 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
974 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
975 struct device_attribute
*attr
,
976 const char *buffer
, size_t count
)
980 struct sony_nc_value
*item
=
981 container_of(attr
, struct sony_nc_value
, devattr
);
989 if (kstrtoint(buffer
, 10, &value
))
993 value
= item
->validate(SNC_VALIDATE_IN
, value
);
998 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
1003 item
->value
= value
;
1012 struct sony_backlight_props
{
1013 struct backlight_device
*dev
;
1019 struct sony_backlight_props sony_bl_props
;
1021 static int sony_backlight_update_status(struct backlight_device
*bd
)
1023 int arg
= bd
->props
.brightness
+ 1;
1024 return sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &arg
, NULL
);
1027 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
1031 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
, &value
))
1033 /* brightness levels are 1-based, while backlight ones are 0-based */
1037 static int sony_nc_get_brightness_ng(struct backlight_device
*bd
)
1040 struct sony_backlight_props
*sdev
=
1041 (struct sony_backlight_props
*)bl_get_data(bd
);
1043 sony_call_snc_handle(sdev
->handle
, sdev
->cmd_base
+ 0x100, &result
);
1045 return (result
& 0xff) - sdev
->offset
;
1048 static int sony_nc_update_status_ng(struct backlight_device
*bd
)
1051 struct sony_backlight_props
*sdev
=
1052 (struct sony_backlight_props
*)bl_get_data(bd
);
1054 value
= bd
->props
.brightness
+ sdev
->offset
;
1055 if (sony_call_snc_handle(sdev
->handle
, sdev
->cmd_base
| (value
<< 0x10),
1062 static const struct backlight_ops sony_backlight_ops
= {
1063 .options
= BL_CORE_SUSPENDRESUME
,
1064 .update_status
= sony_backlight_update_status
,
1065 .get_brightness
= sony_backlight_get_brightness
,
1067 static const struct backlight_ops sony_backlight_ng_ops
= {
1068 .options
= BL_CORE_SUSPENDRESUME
,
1069 .update_status
= sony_nc_update_status_ng
,
1070 .get_brightness
= sony_nc_get_brightness_ng
,
1074 * New SNC-only Vaios event mapping to driver known keys
1076 struct sony_nc_event
{
1081 static struct sony_nc_event sony_100_events
[] = {
1082 { 0x90, SONYPI_EVENT_PKEY_P1
},
1083 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1084 { 0x91, SONYPI_EVENT_PKEY_P2
},
1085 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1086 { 0x81, SONYPI_EVENT_FNKEY_F1
},
1087 { 0x01, SONYPI_EVENT_FNKEY_RELEASED
},
1088 { 0x82, SONYPI_EVENT_FNKEY_F2
},
1089 { 0x02, SONYPI_EVENT_FNKEY_RELEASED
},
1090 { 0x83, SONYPI_EVENT_FNKEY_F3
},
1091 { 0x03, SONYPI_EVENT_FNKEY_RELEASED
},
1092 { 0x84, SONYPI_EVENT_FNKEY_F4
},
1093 { 0x04, SONYPI_EVENT_FNKEY_RELEASED
},
1094 { 0x85, SONYPI_EVENT_FNKEY_F5
},
1095 { 0x05, SONYPI_EVENT_FNKEY_RELEASED
},
1096 { 0x86, SONYPI_EVENT_FNKEY_F6
},
1097 { 0x06, SONYPI_EVENT_FNKEY_RELEASED
},
1098 { 0x87, SONYPI_EVENT_FNKEY_F7
},
1099 { 0x07, SONYPI_EVENT_FNKEY_RELEASED
},
1100 { 0x88, SONYPI_EVENT_FNKEY_F8
},
1101 { 0x08, SONYPI_EVENT_FNKEY_RELEASED
},
1102 { 0x89, SONYPI_EVENT_FNKEY_F9
},
1103 { 0x09, SONYPI_EVENT_FNKEY_RELEASED
},
1104 { 0x8A, SONYPI_EVENT_FNKEY_F10
},
1105 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED
},
1106 { 0x8B, SONYPI_EVENT_FNKEY_F11
},
1107 { 0x0B, SONYPI_EVENT_FNKEY_RELEASED
},
1108 { 0x8C, SONYPI_EVENT_FNKEY_F12
},
1109 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED
},
1110 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED
},
1111 { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1112 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED
},
1113 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1114 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED
},
1115 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1116 { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED
},
1117 { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1118 { 0xa5, SONYPI_EVENT_VENDOR_PRESSED
},
1119 { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1120 { 0xa6, SONYPI_EVENT_HELP_PRESSED
},
1121 { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1125 static struct sony_nc_event sony_127_events
[] = {
1126 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED
},
1127 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1128 { 0x82, SONYPI_EVENT_PKEY_P1
},
1129 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1130 { 0x83, SONYPI_EVENT_PKEY_P2
},
1131 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1132 { 0x84, SONYPI_EVENT_PKEY_P3
},
1133 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1134 { 0x85, SONYPI_EVENT_PKEY_P4
},
1135 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1136 { 0x86, SONYPI_EVENT_PKEY_P5
},
1137 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1138 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED
},
1139 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1143 static int sony_nc_hotkeys_decode(u32 event
, unsigned int handle
)
1146 unsigned int result
= 0;
1147 struct sony_nc_event
*key_event
;
1149 if (sony_call_snc_handle(handle
, 0x200, &result
)) {
1150 dprintk("Unable to decode event 0x%.2x 0x%.2x\n", handle
,
1157 if (handle
== 0x0100)
1158 key_event
= sony_100_events
;
1160 key_event
= sony_127_events
;
1162 for (; key_event
->data
; key_event
++) {
1163 if (key_event
->data
== result
) {
1164 ret
= key_event
->event
;
1169 if (!key_event
->data
)
1170 pr_info("Unknown hotkey 0x%.2x/0x%.2x (handle 0x%.2x)\n",
1171 event
, result
, handle
);
1184 static void sony_nc_notify(struct acpi_device
*device
, u32 event
)
1186 u32 real_ev
= event
;
1188 dprintk("sony_nc_notify, event: 0x%.2x\n", event
);
1190 if (event
>= 0x90) {
1191 unsigned int result
= 0;
1192 unsigned int arg
= 0;
1193 unsigned int handle
= 0;
1194 unsigned int offset
= event
- 0x90;
1196 if (offset
>= ARRAY_SIZE(handles
->cap
)) {
1197 pr_err("Event 0x%x outside of capabilities list\n",
1201 handle
= handles
->cap
[offset
];
1203 /* list of handles known for generating events */
1209 real_ev
= sony_nc_hotkeys_decode(event
, handle
);
1212 sony_laptop_report_input_event(real_ev
);
1214 /* restore the original event for reporting */
1222 /* events on this handle are reported when the
1223 * switch changes position or for battery
1224 * events. We'll notify both of them but only
1225 * update the rfkill device status when the
1228 ev_type
= KILLSWITCH
;
1229 sony_call_snc_handle(handle
, 0x0100, &result
);
1230 real_ev
= result
& 0x03;
1232 /* hw switch event */
1234 sony_nc_rfkill_update();
1240 /* Hybrid GFX switching */
1241 sony_call_snc_handle(handle
, 0x0000, &result
);
1242 dprintk("GFX switch event received (reason: %s)\n",
1244 "switch change" : "unknown");
1246 /* verify the switch state
1250 sony_call_snc_handle(handle
, 0x0100, &result
);
1252 ev_type
= GFX_SWITCH
;
1253 real_ev
= result
& 0xff;
1257 dprintk("Unknown event 0x%x for handle 0x%x\n",
1262 /* clear the event (and the event reason when present) */
1264 sony_nc_int_call(sony_nc_acpi_handle
, "SN05", &arg
, &result
);
1267 /* old style event */
1269 sony_laptop_report_input_event(real_ev
);
1272 acpi_bus_generate_proc_event(sony_nc_acpi_device
, ev_type
, real_ev
);
1274 acpi_bus_generate_netlink_event(sony_nc_acpi_device
->pnp
.device_class
,
1275 dev_name(&sony_nc_acpi_device
->dev
), ev_type
, real_ev
);
1278 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
1279 void *context
, void **return_value
)
1281 struct acpi_device_info
*info
;
1283 if (ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
1284 pr_warn("method: name: %4.4s, args %X\n",
1285 (char *)&info
->name
, info
->param_count
);
1296 static void sony_nc_function_setup(struct acpi_device
*device
,
1297 struct platform_device
*pf_device
)
1299 unsigned int i
, result
, bitmask
, arg
;
1304 /* setup found handles here */
1305 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1306 unsigned int handle
= handles
->cap
[i
];
1311 dprintk("setting up handle 0x%.4x\n", handle
);
1318 sony_call_snc_handle(handle
, 0, &result
);
1322 sony_call_snc_handle(handle
, 0x100, &result
);
1326 /* touchpad enable/disable */
1327 result
= sony_nc_touchpad_setup(pf_device
, handle
);
1329 pr_err("couldn't set up touchpad control function (%d)\n",
1335 result
= sony_nc_battery_care_setup(pf_device
, handle
);
1337 pr_err("couldn't set up battery care function (%d)\n",
1341 result
= sony_nc_lid_resume_setup(pf_device
);
1343 pr_err("couldn't set up lid resume function (%d)\n",
1347 result
= sony_nc_thermal_setup(pf_device
);
1349 pr_err("couldn't set up thermal profile function (%d)\n",
1353 result
= sony_nc_highspeed_charging_setup(pf_device
);
1355 pr_err("couldn't set up high speed charging function (%d)\n",
1360 result
= sony_nc_rfkill_setup(device
, handle
);
1362 pr_err("couldn't set up rfkill support (%d)\n",
1367 result
= sony_nc_kbd_backlight_setup(pf_device
, handle
);
1369 pr_err("couldn't set up keyboard backlight function (%d)\n",
1377 /* Enable all events */
1379 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1380 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1384 static void sony_nc_function_cleanup(struct platform_device
*pd
)
1386 unsigned int i
, result
, bitmask
, handle
;
1388 /* get enabled events and disable them */
1389 sony_nc_int_call(sony_nc_acpi_handle
, "SN01", NULL
, &bitmask
);
1390 sony_nc_int_call(sony_nc_acpi_handle
, "SN03", &bitmask
, &result
);
1392 /* cleanup handles here */
1393 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1395 handle
= handles
->cap
[i
];
1403 sony_nc_touchpad_cleanup(pd
);
1408 sony_nc_battery_care_cleanup(pd
);
1411 sony_nc_lid_resume_cleanup(pd
);
1414 sony_nc_thermal_cleanup(pd
);
1417 sony_nc_highspeed_charging_cleanup(pd
);
1421 sony_nc_rfkill_cleanup();
1425 sony_nc_kbd_backlight_cleanup(pd
);
1432 /* finally cleanup the handles list */
1433 sony_nc_handles_cleanup(pd
);
1436 #ifdef CONFIG_PM_SLEEP
1437 static void sony_nc_function_resume(void)
1439 unsigned int i
, result
, bitmask
, arg
;
1441 dprintk("Resuming SNC device\n");
1443 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1444 unsigned int handle
= handles
->cap
[i
];
1453 /* re-enable hotkeys */
1454 sony_call_snc_handle(handle
, 0, &result
);
1457 /* re-enable hotkeys */
1458 sony_call_snc_handle(handle
, 0x100, &result
);
1461 sony_nc_thermal_resume();
1465 sony_nc_rfkill_update();
1469 sony_nc_kbd_backlight_resume();
1476 /* Enable all events */
1478 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1479 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1483 static int sony_nc_resume(struct device
*dev
)
1485 struct sony_nc_value
*item
;
1488 for (item
= sony_nc_values
; item
->name
; item
++) {
1493 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
1494 &item
->value
, NULL
);
1496 pr_err("%s: %d\n", __func__
, ret
);
1501 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1504 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
1505 dprintk("ECON Method failed\n");
1508 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1510 sony_nc_function_resume();
1516 static SIMPLE_DEV_PM_OPS(sony_nc_pm
, NULL
, sony_nc_resume
);
1518 static void sony_nc_rfkill_cleanup(void)
1522 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1523 if (sony_rfkill_devices
[i
]) {
1524 rfkill_unregister(sony_rfkill_devices
[i
]);
1525 rfkill_destroy(sony_rfkill_devices
[i
]);
1530 static int sony_nc_rfkill_set(void *data
, bool blocked
)
1533 int argument
= sony_rfkill_address
[(long) data
] + 0x100;
1536 argument
|= 0x030000;
1538 return sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1541 static const struct rfkill_ops sony_rfkill_ops
= {
1542 .set_block
= sony_nc_rfkill_set
,
1545 static int sony_nc_setup_rfkill(struct acpi_device
*device
,
1546 enum sony_nc_rfkill nc_type
)
1550 enum rfkill_type type
;
1553 bool hwblock
, swblock
;
1557 type
= RFKILL_TYPE_WLAN
;
1560 case SONY_BLUETOOTH
:
1561 type
= RFKILL_TYPE_BLUETOOTH
;
1562 name
= "sony-bluetooth";
1565 type
= RFKILL_TYPE_WWAN
;
1569 type
= RFKILL_TYPE_WIMAX
;
1570 name
= "sony-wimax";
1576 rfk
= rfkill_alloc(name
, &device
->dev
, type
,
1577 &sony_rfkill_ops
, (void *)nc_type
);
1581 if (sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
) < 0) {
1582 rfkill_destroy(rfk
);
1585 hwblock
= !(result
& 0x1);
1587 if (sony_call_snc_handle(sony_rfkill_handle
,
1588 sony_rfkill_address
[nc_type
],
1590 rfkill_destroy(rfk
);
1593 swblock
= !(result
& 0x2);
1595 rfkill_init_sw_state(rfk
, swblock
);
1596 rfkill_set_hw_state(rfk
, hwblock
);
1598 err
= rfkill_register(rfk
);
1600 rfkill_destroy(rfk
);
1603 sony_rfkill_devices
[nc_type
] = rfk
;
1607 static void sony_nc_rfkill_update(void)
1609 enum sony_nc_rfkill i
;
1613 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1614 hwblock
= !(result
& 0x1);
1616 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1617 int argument
= sony_rfkill_address
[i
];
1619 if (!sony_rfkill_devices
[i
])
1623 if (rfkill_set_hw_state(sony_rfkill_devices
[i
], true)) {
1624 /* we already know we're blocked */
1629 sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1630 rfkill_set_states(sony_rfkill_devices
[i
],
1631 !(result
& 0x2), false);
1635 static int sony_nc_rfkill_setup(struct acpi_device
*device
,
1636 unsigned int handle
)
1640 unsigned char buffer
[32] = { 0 };
1642 offset
= sony_find_snc_handle(handle
);
1643 sony_rfkill_handle
= handle
;
1645 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
1650 /* The buffer is filled with magic numbers describing the devices
1651 * available, 0xff terminates the enumeration.
1655 * 0x20 WWAN GPRS-EDGE
1659 * 0x25 Gobi WWAN no GPS
1660 * 0x26 Gobi WWAN + GPS
1661 * 0x28 Gobi WWAN no GPS
1662 * 0x29 Gobi WWAN + GPS
1664 * 0x50 Gobi WWAN no GPS
1665 * 0x51 Gobi WWAN + GPS
1666 * 0x70 no SIM card slot
1667 * 0x71 SIM card slot
1669 for (i
= 0; i
< ARRAY_SIZE(buffer
); i
++) {
1671 if (buffer
[i
] == 0xff)
1674 dprintk("Radio devices, found 0x%.2x\n", buffer
[i
]);
1676 if (buffer
[i
] == 0 && !sony_rfkill_devices
[SONY_WIFI
])
1677 sony_nc_setup_rfkill(device
, SONY_WIFI
);
1679 if (buffer
[i
] == 0x10 && !sony_rfkill_devices
[SONY_BLUETOOTH
])
1680 sony_nc_setup_rfkill(device
, SONY_BLUETOOTH
);
1682 if (((0xf0 & buffer
[i
]) == 0x20 ||
1683 (0xf0 & buffer
[i
]) == 0x50) &&
1684 !sony_rfkill_devices
[SONY_WWAN
])
1685 sony_nc_setup_rfkill(device
, SONY_WWAN
);
1687 if (buffer
[i
] == 0x30 && !sony_rfkill_devices
[SONY_WIMAX
])
1688 sony_nc_setup_rfkill(device
, SONY_WIMAX
);
1693 /* Keyboard backlight feature */
1694 struct kbd_backlight
{
1695 unsigned int handle
;
1698 unsigned int timeout
;
1699 struct device_attribute mode_attr
;
1700 struct device_attribute timeout_attr
;
1703 static struct kbd_backlight
*kbdbl_ctl
;
1705 static ssize_t
__sony_nc_kbd_backlight_mode_set(u8 value
)
1712 if (sony_call_snc_handle(kbdbl_ctl
->handle
,
1713 (value
<< 0x10) | (kbdbl_ctl
->base
), &result
))
1716 /* Try to turn the light on/off immediately */
1717 sony_call_snc_handle(kbdbl_ctl
->handle
,
1718 (value
<< 0x10) | (kbdbl_ctl
->base
+ 0x100), &result
);
1720 kbdbl_ctl
->mode
= value
;
1725 static ssize_t
sony_nc_kbd_backlight_mode_store(struct device
*dev
,
1726 struct device_attribute
*attr
,
1727 const char *buffer
, size_t count
)
1730 unsigned long value
;
1735 if (kstrtoul(buffer
, 10, &value
))
1738 ret
= __sony_nc_kbd_backlight_mode_set(value
);
1745 static ssize_t
sony_nc_kbd_backlight_mode_show(struct device
*dev
,
1746 struct device_attribute
*attr
, char *buffer
)
1749 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_ctl
->mode
);
1753 static int __sony_nc_kbd_backlight_timeout_set(u8 value
)
1760 if (sony_call_snc_handle(kbdbl_ctl
->handle
, (value
<< 0x10) |
1761 (kbdbl_ctl
->base
+ 0x200), &result
))
1764 kbdbl_ctl
->timeout
= value
;
1769 static ssize_t
sony_nc_kbd_backlight_timeout_store(struct device
*dev
,
1770 struct device_attribute
*attr
,
1771 const char *buffer
, size_t count
)
1774 unsigned long value
;
1779 if (kstrtoul(buffer
, 10, &value
))
1782 ret
= __sony_nc_kbd_backlight_timeout_set(value
);
1789 static ssize_t
sony_nc_kbd_backlight_timeout_show(struct device
*dev
,
1790 struct device_attribute
*attr
, char *buffer
)
1793 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_ctl
->timeout
);
1797 static int sony_nc_kbd_backlight_setup(struct platform_device
*pd
,
1798 unsigned int handle
)
1803 /* verify the kbd backlight presence, these handles are not used for
1804 * keyboard backlight only
1806 ret
= sony_call_snc_handle(handle
, handle
== 0x0137 ? 0x0B00 : 0x0100,
1811 if ((handle
== 0x0137 && !(result
& 0x02)) ||
1813 dprintk("no backlight keyboard found\n");
1817 kbdbl_ctl
= kzalloc(sizeof(*kbdbl_ctl
), GFP_KERNEL
);
1821 kbdbl_ctl
->handle
= handle
;
1822 if (handle
== 0x0137)
1823 kbdbl_ctl
->base
= 0x0C00;
1825 kbdbl_ctl
->base
= 0x4000;
1827 sysfs_attr_init(&kbdbl_ctl
->mode_attr
.attr
);
1828 kbdbl_ctl
->mode_attr
.attr
.name
= "kbd_backlight";
1829 kbdbl_ctl
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1830 kbdbl_ctl
->mode_attr
.show
= sony_nc_kbd_backlight_mode_show
;
1831 kbdbl_ctl
->mode_attr
.store
= sony_nc_kbd_backlight_mode_store
;
1833 sysfs_attr_init(&kbdbl_ctl
->timeout_attr
.attr
);
1834 kbdbl_ctl
->timeout_attr
.attr
.name
= "kbd_backlight_timeout";
1835 kbdbl_ctl
->timeout_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1836 kbdbl_ctl
->timeout_attr
.show
= sony_nc_kbd_backlight_timeout_show
;
1837 kbdbl_ctl
->timeout_attr
.store
= sony_nc_kbd_backlight_timeout_store
;
1839 ret
= device_create_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1843 ret
= device_create_file(&pd
->dev
, &kbdbl_ctl
->timeout_attr
);
1847 __sony_nc_kbd_backlight_mode_set(kbd_backlight
);
1848 __sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout
);
1853 device_remove_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1860 static void sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
)
1865 device_remove_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1866 device_remove_file(&pd
->dev
, &kbdbl_ctl
->timeout_attr
);
1868 /* restore the default hw behaviour */
1869 sony_call_snc_handle(kbdbl_ctl
->handle
,
1870 kbdbl_ctl
->base
| 0x10000, &result
);
1871 sony_call_snc_handle(kbdbl_ctl
->handle
,
1872 kbdbl_ctl
->base
+ 0x200, &result
);
1879 #ifdef CONFIG_PM_SLEEP
1880 static void sony_nc_kbd_backlight_resume(void)
1887 if (kbdbl_ctl
->mode
== 0)
1888 sony_call_snc_handle(kbdbl_ctl
->handle
, kbdbl_ctl
->base
,
1891 if (kbdbl_ctl
->timeout
!= 0)
1892 sony_call_snc_handle(kbdbl_ctl
->handle
,
1893 (kbdbl_ctl
->base
+ 0x200) |
1894 (kbdbl_ctl
->timeout
<< 0x10), &ignore
);
1898 struct battery_care_control
{
1899 struct device_attribute attrs
[2];
1900 unsigned int handle
;
1902 static struct battery_care_control
*bcare_ctl
;
1904 static ssize_t
sony_nc_battery_care_limit_store(struct device
*dev
,
1905 struct device_attribute
*attr
,
1906 const char *buffer
, size_t count
)
1908 unsigned int result
, cmd
;
1909 unsigned long value
;
1914 if (kstrtoul(buffer
, 10, &value
))
1917 /* limit values (2 bits):
1923 * bit 0: 0 disable BCL, 1 enable BCL
1924 * bit 1: 1 tell to store the battery limit (see bits 6,7) too
1925 * bits 2,3: reserved
1926 * bits 4,5: store the limit into the EC
1927 * bits 6,7: store the limit into the battery
1935 else if (value
<= 80)
1938 else if (value
<= 100)
1945 * handle 0x0115 should allow storing on battery too;
1946 * handle 0x0136 same as 0x0115 + health status;
1947 * handle 0x013f, same as 0x0136 but no storing on the battery
1949 if (bcare_ctl
->handle
!= 0x013f)
1950 cmd
= cmd
| (cmd
<< 2);
1952 cmd
= (cmd
| 0x1) << 0x10;
1955 if (sony_call_snc_handle(bcare_ctl
->handle
, cmd
| 0x0100, &result
))
1961 static ssize_t
sony_nc_battery_care_limit_show(struct device
*dev
,
1962 struct device_attribute
*attr
, char *buffer
)
1964 unsigned int result
, status
;
1966 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0000, &result
))
1969 status
= (result
& 0x01) ? ((result
& 0x30) >> 0x04) : 0;
1985 return snprintf(buffer
, PAGE_SIZE
, "%d\n", status
);
1988 static ssize_t
sony_nc_battery_care_health_show(struct device
*dev
,
1989 struct device_attribute
*attr
, char *buffer
)
1992 unsigned int health
;
1994 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0200, &health
))
1997 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", health
& 0xff);
2002 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
2003 unsigned int handle
)
2007 bcare_ctl
= kzalloc(sizeof(struct battery_care_control
), GFP_KERNEL
);
2011 bcare_ctl
->handle
= handle
;
2013 sysfs_attr_init(&bcare_ctl
->attrs
[0].attr
);
2014 bcare_ctl
->attrs
[0].attr
.name
= "battery_care_limiter";
2015 bcare_ctl
->attrs
[0].attr
.mode
= S_IRUGO
| S_IWUSR
;
2016 bcare_ctl
->attrs
[0].show
= sony_nc_battery_care_limit_show
;
2017 bcare_ctl
->attrs
[0].store
= sony_nc_battery_care_limit_store
;
2019 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2023 /* 0x0115 is for models with no health reporting capability */
2024 if (handle
== 0x0115)
2027 sysfs_attr_init(&bcare_ctl
->attrs
[1].attr
);
2028 bcare_ctl
->attrs
[1].attr
.name
= "battery_care_health";
2029 bcare_ctl
->attrs
[1].attr
.mode
= S_IRUGO
;
2030 bcare_ctl
->attrs
[1].show
= sony_nc_battery_care_health_show
;
2032 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
2039 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2048 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
)
2051 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2052 if (bcare_ctl
->handle
!= 0x0115)
2053 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
2060 struct snc_thermal_ctrl
{
2062 unsigned int profiles
;
2063 struct device_attribute mode_attr
;
2064 struct device_attribute profiles_attr
;
2066 static struct snc_thermal_ctrl
*th_handle
;
2068 #define THM_PROFILE_MAX 3
2069 static const char * const snc_thermal_profiles
[] = {
2075 static int sony_nc_thermal_mode_set(unsigned short mode
)
2077 unsigned int result
;
2079 /* the thermal profile seems to be a two bit bitmask:
2081 * msb -> performance
2082 * no bit set is the normal operation and is always valid
2083 * Some vaio models only have "balanced" and "performance"
2085 if ((mode
&& !(th_handle
->profiles
& mode
)) || mode
>= THM_PROFILE_MAX
)
2088 if (sony_call_snc_handle(0x0122, mode
<< 0x10 | 0x0200, &result
))
2091 th_handle
->mode
= mode
;
2096 static int sony_nc_thermal_mode_get(void)
2098 unsigned int result
;
2100 if (sony_call_snc_handle(0x0122, 0x0100, &result
))
2103 return result
& 0xff;
2106 static ssize_t
sony_nc_thermal_profiles_show(struct device
*dev
,
2107 struct device_attribute
*attr
, char *buffer
)
2112 for (cnt
= 0; cnt
< THM_PROFILE_MAX
; cnt
++) {
2113 if (!cnt
|| (th_handle
->profiles
& cnt
))
2114 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "%s ",
2115 snc_thermal_profiles
[cnt
]);
2117 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "\n");
2122 static ssize_t
sony_nc_thermal_mode_store(struct device
*dev
,
2123 struct device_attribute
*attr
,
2124 const char *buffer
, size_t count
)
2132 /* skip the newline if present */
2133 if (buffer
[len
- 1] == '\n')
2136 for (cmd
= 0; cmd
< THM_PROFILE_MAX
; cmd
++)
2137 if (strncmp(buffer
, snc_thermal_profiles
[cmd
], len
) == 0)
2140 if (sony_nc_thermal_mode_set(cmd
))
2146 static ssize_t
sony_nc_thermal_mode_show(struct device
*dev
,
2147 struct device_attribute
*attr
, char *buffer
)
2150 int mode
= sony_nc_thermal_mode_get();
2155 count
= snprintf(buffer
, PAGE_SIZE
, "%s\n", snc_thermal_profiles
[mode
]);
2160 static int sony_nc_thermal_setup(struct platform_device
*pd
)
2163 th_handle
= kzalloc(sizeof(struct snc_thermal_ctrl
), GFP_KERNEL
);
2167 ret
= sony_call_snc_handle(0x0122, 0x0000, &th_handle
->profiles
);
2169 pr_warn("couldn't to read the thermal profiles\n");
2173 ret
= sony_nc_thermal_mode_get();
2175 pr_warn("couldn't to read the current thermal profile");
2178 th_handle
->mode
= ret
;
2180 sysfs_attr_init(&th_handle
->profiles_attr
.attr
);
2181 th_handle
->profiles_attr
.attr
.name
= "thermal_profiles";
2182 th_handle
->profiles_attr
.attr
.mode
= S_IRUGO
;
2183 th_handle
->profiles_attr
.show
= sony_nc_thermal_profiles_show
;
2185 sysfs_attr_init(&th_handle
->mode_attr
.attr
);
2186 th_handle
->mode_attr
.attr
.name
= "thermal_control";
2187 th_handle
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
2188 th_handle
->mode_attr
.show
= sony_nc_thermal_mode_show
;
2189 th_handle
->mode_attr
.store
= sony_nc_thermal_mode_store
;
2191 ret
= device_create_file(&pd
->dev
, &th_handle
->profiles_attr
);
2195 ret
= device_create_file(&pd
->dev
, &th_handle
->mode_attr
);
2202 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2209 static void sony_nc_thermal_cleanup(struct platform_device
*pd
)
2212 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2213 device_remove_file(&pd
->dev
, &th_handle
->mode_attr
);
2219 #ifdef CONFIG_PM_SLEEP
2220 static void sony_nc_thermal_resume(void)
2222 unsigned int status
= sony_nc_thermal_mode_get();
2224 if (status
!= th_handle
->mode
)
2225 sony_nc_thermal_mode_set(th_handle
->mode
);
2229 /* resume on LID open */
2230 struct snc_lid_resume_control
{
2231 struct device_attribute attrs
[3];
2232 unsigned int status
;
2234 static struct snc_lid_resume_control
*lid_ctl
;
2236 static ssize_t
sony_nc_lid_resume_store(struct device
*dev
,
2237 struct device_attribute
*attr
,
2238 const char *buffer
, size_t count
)
2240 unsigned int result
, pos
;
2241 unsigned long value
;
2245 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2248 /* the value we have to write to SNC is a bitmask:
2254 if (strcmp(attr
->attr
.name
, "lid_resume_S3") == 0)
2256 else if (strcmp(attr
->attr
.name
, "lid_resume_S4") == 0)
2258 else if (strcmp(attr
->attr
.name
, "lid_resume_S5") == 0)
2264 value
= lid_ctl
->status
| (1 << pos
);
2266 value
= lid_ctl
->status
& ~(1 << pos
);
2268 if (sony_call_snc_handle(0x0119, value
<< 0x10 | 0x0100, &result
))
2271 lid_ctl
->status
= value
;
2276 static ssize_t
sony_nc_lid_resume_show(struct device
*dev
,
2277 struct device_attribute
*attr
, char *buffer
)
2281 if (strcmp(attr
->attr
.name
, "lid_resume_S3") == 0)
2283 else if (strcmp(attr
->attr
.name
, "lid_resume_S4") == 0)
2285 else if (strcmp(attr
->attr
.name
, "lid_resume_S5") == 0)
2290 return snprintf(buffer
, PAGE_SIZE
, "%d\n",
2291 (lid_ctl
->status
>> pos
) & 0x01);
2294 static int sony_nc_lid_resume_setup(struct platform_device
*pd
)
2296 unsigned int result
;
2299 if (sony_call_snc_handle(0x0119, 0x0000, &result
))
2302 lid_ctl
= kzalloc(sizeof(struct snc_lid_resume_control
), GFP_KERNEL
);
2306 lid_ctl
->status
= result
& 0x7;
2308 sysfs_attr_init(&lid_ctl
->attrs
[0].attr
);
2309 lid_ctl
->attrs
[0].attr
.name
= "lid_resume_S3";
2310 lid_ctl
->attrs
[0].attr
.mode
= S_IRUGO
| S_IWUSR
;
2311 lid_ctl
->attrs
[0].show
= sony_nc_lid_resume_show
;
2312 lid_ctl
->attrs
[0].store
= sony_nc_lid_resume_store
;
2314 sysfs_attr_init(&lid_ctl
->attrs
[1].attr
);
2315 lid_ctl
->attrs
[1].attr
.name
= "lid_resume_S4";
2316 lid_ctl
->attrs
[1].attr
.mode
= S_IRUGO
| S_IWUSR
;
2317 lid_ctl
->attrs
[1].show
= sony_nc_lid_resume_show
;
2318 lid_ctl
->attrs
[1].store
= sony_nc_lid_resume_store
;
2320 sysfs_attr_init(&lid_ctl
->attrs
[2].attr
);
2321 lid_ctl
->attrs
[2].attr
.name
= "lid_resume_S5";
2322 lid_ctl
->attrs
[2].attr
.mode
= S_IRUGO
| S_IWUSR
;
2323 lid_ctl
->attrs
[2].show
= sony_nc_lid_resume_show
;
2324 lid_ctl
->attrs
[2].store
= sony_nc_lid_resume_store
;
2326 for (i
= 0; i
< 3; i
++) {
2327 result
= device_create_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2336 device_remove_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2344 static void sony_nc_lid_resume_cleanup(struct platform_device
*pd
)
2349 for (i
= 0; i
< 3; i
++)
2350 device_remove_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2357 /* High speed charging function */
2358 static struct device_attribute
*hsc_handle
;
2360 static ssize_t
sony_nc_highspeed_charging_store(struct device
*dev
,
2361 struct device_attribute
*attr
,
2362 const char *buffer
, size_t count
)
2364 unsigned int result
;
2365 unsigned long value
;
2370 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2373 if (sony_call_snc_handle(0x0131, value
<< 0x10 | 0x0200, &result
))
2379 static ssize_t
sony_nc_highspeed_charging_show(struct device
*dev
,
2380 struct device_attribute
*attr
, char *buffer
)
2382 unsigned int result
;
2384 if (sony_call_snc_handle(0x0131, 0x0100, &result
))
2387 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 0x01);
2390 static int sony_nc_highspeed_charging_setup(struct platform_device
*pd
)
2392 unsigned int result
;
2394 if (sony_call_snc_handle(0x0131, 0x0000, &result
) || !(result
& 0x01)) {
2395 /* some models advertise the handle but have no implementation
2398 pr_info("No High Speed Charging capability found\n");
2402 hsc_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2406 sysfs_attr_init(&hsc_handle
->attr
);
2407 hsc_handle
->attr
.name
= "battery_highspeed_charging";
2408 hsc_handle
->attr
.mode
= S_IRUGO
| S_IWUSR
;
2409 hsc_handle
->show
= sony_nc_highspeed_charging_show
;
2410 hsc_handle
->store
= sony_nc_highspeed_charging_store
;
2412 result
= device_create_file(&pd
->dev
, hsc_handle
);
2422 static void sony_nc_highspeed_charging_cleanup(struct platform_device
*pd
)
2425 device_remove_file(&pd
->dev
, hsc_handle
);
2431 /* Touchpad enable/disable */
2432 struct touchpad_control
{
2433 struct device_attribute attr
;
2436 static struct touchpad_control
*tp_ctl
;
2438 static ssize_t
sony_nc_touchpad_store(struct device
*dev
,
2439 struct device_attribute
*attr
, const char *buffer
, size_t count
)
2441 unsigned int result
;
2442 unsigned long value
;
2447 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2450 /* sysfs: 0 disabled, 1 enabled
2451 * EC: 0 enabled, 1 disabled
2453 if (sony_call_snc_handle(tp_ctl
->handle
,
2454 (!value
<< 0x10) | 0x100, &result
))
2460 static ssize_t
sony_nc_touchpad_show(struct device
*dev
,
2461 struct device_attribute
*attr
, char *buffer
)
2463 unsigned int result
;
2465 if (sony_call_snc_handle(tp_ctl
->handle
, 0x000, &result
))
2468 return snprintf(buffer
, PAGE_SIZE
, "%d\n", !(result
& 0x01));
2471 static int sony_nc_touchpad_setup(struct platform_device
*pd
,
2472 unsigned int handle
)
2476 tp_ctl
= kzalloc(sizeof(struct touchpad_control
), GFP_KERNEL
);
2480 tp_ctl
->handle
= handle
;
2482 sysfs_attr_init(&tp_ctl
->attr
.attr
);
2483 tp_ctl
->attr
.attr
.name
= "touchpad";
2484 tp_ctl
->attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
2485 tp_ctl
->attr
.show
= sony_nc_touchpad_show
;
2486 tp_ctl
->attr
.store
= sony_nc_touchpad_store
;
2488 ret
= device_create_file(&pd
->dev
, &tp_ctl
->attr
);
2497 static void sony_nc_touchpad_cleanup(struct platform_device
*pd
)
2500 device_remove_file(&pd
->dev
, &tp_ctl
->attr
);
2506 static void sony_nc_backlight_ng_read_limits(int handle
,
2507 struct sony_backlight_props
*props
)
2511 int lvl_table_len
= 0;
2512 u8 min
= 0xff, max
= 0x00;
2513 unsigned char buffer
[32] = { 0 };
2515 props
->handle
= handle
;
2517 props
->maxlvl
= 0xff;
2519 offset
= sony_find_snc_handle(handle
);
2521 /* try to read the boundaries from ACPI tables, if we fail the above
2522 * defaults should be reasonable
2524 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
2539 /* the buffer lists brightness levels available, brightness levels are
2540 * from position 0 to 8 in the array, other values are used by ALS
2543 for (i
= 0; i
< lvl_table_len
&& i
< ARRAY_SIZE(buffer
); i
++) {
2545 dprintk("Brightness level: %d\n", buffer
[i
]);
2550 if (buffer
[i
] > max
)
2552 if (buffer
[i
] < min
)
2555 props
->offset
= min
;
2556 props
->maxlvl
= max
;
2557 dprintk("Brightness levels: min=%d max=%d\n", props
->offset
,
2561 static void sony_nc_backlight_setup(void)
2564 int max_brightness
= 0;
2565 const struct backlight_ops
*ops
= NULL
;
2566 struct backlight_properties props
;
2568 if (sony_find_snc_handle(0x12f) >= 0) {
2569 ops
= &sony_backlight_ng_ops
;
2570 sony_bl_props
.cmd_base
= 0x0100;
2571 sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props
);
2572 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
2574 } else if (sony_find_snc_handle(0x137) >= 0) {
2575 ops
= &sony_backlight_ng_ops
;
2576 sony_bl_props
.cmd_base
= 0x0100;
2577 sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props
);
2578 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
2580 } else if (sony_find_snc_handle(0x143) >= 0) {
2581 ops
= &sony_backlight_ng_ops
;
2582 sony_bl_props
.cmd_base
= 0x3000;
2583 sony_nc_backlight_ng_read_limits(0x143, &sony_bl_props
);
2584 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
2586 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "GBRT",
2588 ops
= &sony_backlight_ops
;
2589 max_brightness
= SONY_MAX_BRIGHTNESS
- 1;
2594 memset(&props
, 0, sizeof(struct backlight_properties
));
2595 props
.type
= BACKLIGHT_PLATFORM
;
2596 props
.max_brightness
= max_brightness
;
2597 sony_bl_props
.dev
= backlight_device_register("sony", NULL
,
2601 if (IS_ERR(sony_bl_props
.dev
)) {
2602 pr_warn("unable to register backlight device\n");
2603 sony_bl_props
.dev
= NULL
;
2605 sony_bl_props
.dev
->props
.brightness
=
2606 ops
->get_brightness(sony_bl_props
.dev
);
2609 static void sony_nc_backlight_cleanup(void)
2611 if (sony_bl_props
.dev
)
2612 backlight_device_unregister(sony_bl_props
.dev
);
2615 static int sony_nc_add(struct acpi_device
*device
)
2620 struct sony_nc_value
*item
;
2622 pr_info("%s v%s\n", SONY_NC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
2624 sony_nc_acpi_device
= device
;
2625 strcpy(acpi_device_class(device
), "sony/hotkey");
2627 sony_nc_acpi_handle
= device
->handle
;
2629 /* read device status */
2630 result
= acpi_bus_get_status(device
);
2631 /* bail IFF the above call was successful and the device is not present */
2632 if (!result
&& !device
->status
.present
) {
2633 dprintk("Device not present\n");
2638 result
= sony_pf_add();
2643 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
,
2644 sony_nc_acpi_handle
, 1, sony_walk_callback
,
2646 if (ACPI_FAILURE(status
)) {
2647 pr_warn("unable to walk acpi resources\n");
2653 result
= sony_laptop_setup_input(device
);
2655 pr_err("Unable to create input devices\n");
2659 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
2662 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
2663 dprintk("ECON Method failed\n");
2666 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
2668 dprintk("Doing SNC setup\n");
2669 /* retrieve the available handles */
2670 result
= sony_nc_handles_setup(sony_pf_device
);
2672 sony_nc_function_setup(device
, sony_pf_device
);
2675 /* setup input devices and helper fifo */
2676 if (acpi_video_backlight_support()) {
2677 pr_info("brightness ignored, must be controlled by ACPI video driver\n");
2679 sony_nc_backlight_setup();
2682 /* create sony_pf sysfs attributes related to the SNC device */
2683 for (item
= sony_nc_values
; item
->name
; ++item
) {
2685 if (!debug
&& item
->debug
)
2688 /* find the available acpiget as described in the DSDT */
2689 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
2690 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
2693 dprintk("Found %s getter: %s\n",
2694 item
->name
, *item
->acpiget
);
2695 item
->devattr
.attr
.mode
|= S_IRUGO
;
2700 /* find the available acpiset as described in the DSDT */
2701 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
2702 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
2705 dprintk("Found %s setter: %s\n",
2706 item
->name
, *item
->acpiset
);
2707 item
->devattr
.attr
.mode
|= S_IWUSR
;
2712 if (item
->devattr
.attr
.mode
!= 0) {
2714 device_create_file(&sony_pf_device
->dev
,
2724 for (item
= sony_nc_values
; item
->name
; ++item
) {
2725 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
2727 sony_nc_backlight_cleanup();
2728 sony_nc_function_cleanup(sony_pf_device
);
2729 sony_nc_handles_cleanup(sony_pf_device
);
2732 sony_laptop_remove_input();
2738 sony_nc_rfkill_cleanup();
2742 static int sony_nc_remove(struct acpi_device
*device
, int type
)
2744 struct sony_nc_value
*item
;
2746 sony_nc_backlight_cleanup();
2748 sony_nc_acpi_device
= NULL
;
2750 for (item
= sony_nc_values
; item
->name
; ++item
) {
2751 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
2754 sony_nc_function_cleanup(sony_pf_device
);
2755 sony_nc_handles_cleanup(sony_pf_device
);
2757 sony_laptop_remove_input();
2758 dprintk(SONY_NC_DRIVER_NAME
" removed.\n");
2763 static const struct acpi_device_id sony_device_ids
[] = {
2768 MODULE_DEVICE_TABLE(acpi
, sony_device_ids
);
2770 static const struct acpi_device_id sony_nc_device_ids
[] = {
2775 static struct acpi_driver sony_nc_driver
= {
2776 .name
= SONY_NC_DRIVER_NAME
,
2777 .class = SONY_NC_CLASS
,
2778 .ids
= sony_nc_device_ids
,
2779 .owner
= THIS_MODULE
,
2782 .remove
= sony_nc_remove
,
2783 .notify
= sony_nc_notify
,
2785 .drv
.pm
= &sony_nc_pm
,
2788 /*********** SPIC (SNY6001) Device ***********/
2790 #define SONYPI_DEVICE_TYPE1 0x00000001
2791 #define SONYPI_DEVICE_TYPE2 0x00000002
2792 #define SONYPI_DEVICE_TYPE3 0x00000004
2794 #define SONYPI_TYPE1_OFFSET 0x04
2795 #define SONYPI_TYPE2_OFFSET 0x12
2796 #define SONYPI_TYPE3_OFFSET 0x12
2798 struct sony_pic_ioport
{
2799 struct acpi_resource_io io1
;
2800 struct acpi_resource_io io2
;
2801 struct list_head list
;
2804 struct sony_pic_irq
{
2805 struct acpi_resource_irq irq
;
2806 struct list_head list
;
2809 struct sonypi_eventtypes
{
2812 struct sonypi_event
*events
;
2815 struct sony_pic_dev
{
2816 struct acpi_device
*acpi_dev
;
2817 struct sony_pic_irq
*cur_irq
;
2818 struct sony_pic_ioport
*cur_ioport
;
2819 struct list_head interrupts
;
2820 struct list_head ioports
;
2822 struct sonypi_eventtypes
*event_types
;
2823 int (*handle_irq
)(const u8
, const u8
);
2831 static struct sony_pic_dev spic_dev
= {
2832 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
2833 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
2836 static int spic_drv_registered
;
2839 #define SONYPI_JOGGER_MASK 0x00000001
2840 #define SONYPI_CAPTURE_MASK 0x00000002
2841 #define SONYPI_FNKEY_MASK 0x00000004
2842 #define SONYPI_BLUETOOTH_MASK 0x00000008
2843 #define SONYPI_PKEY_MASK 0x00000010
2844 #define SONYPI_BACK_MASK 0x00000020
2845 #define SONYPI_HELP_MASK 0x00000040
2846 #define SONYPI_LID_MASK 0x00000080
2847 #define SONYPI_ZOOM_MASK 0x00000100
2848 #define SONYPI_THUMBPHRASE_MASK 0x00000200
2849 #define SONYPI_MEYE_MASK 0x00000400
2850 #define SONYPI_MEMORYSTICK_MASK 0x00000800
2851 #define SONYPI_BATTERY_MASK 0x00001000
2852 #define SONYPI_WIRELESS_MASK 0x00002000
2854 struct sonypi_event
{
2859 /* The set of possible button release events */
2860 static struct sonypi_event sonypi_releaseev
[] = {
2861 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
2865 /* The set of possible jogger events */
2866 static struct sonypi_event sonypi_joggerev
[] = {
2867 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
2868 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
2869 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
2870 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
2871 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
2872 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
2873 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
2874 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
2875 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
2876 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
2877 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
2878 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
2879 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
2883 /* The set of possible capture button events */
2884 static struct sonypi_event sonypi_captureev
[] = {
2885 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
2886 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
2887 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED
},
2888 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
2892 /* The set of possible fnkeys events */
2893 static struct sonypi_event sonypi_fnkeyev
[] = {
2894 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
2895 { 0x11, SONYPI_EVENT_FNKEY_F1
},
2896 { 0x12, SONYPI_EVENT_FNKEY_F2
},
2897 { 0x13, SONYPI_EVENT_FNKEY_F3
},
2898 { 0x14, SONYPI_EVENT_FNKEY_F4
},
2899 { 0x15, SONYPI_EVENT_FNKEY_F5
},
2900 { 0x16, SONYPI_EVENT_FNKEY_F6
},
2901 { 0x17, SONYPI_EVENT_FNKEY_F7
},
2902 { 0x18, SONYPI_EVENT_FNKEY_F8
},
2903 { 0x19, SONYPI_EVENT_FNKEY_F9
},
2904 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
2905 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
2906 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
2907 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
2908 { 0x21, SONYPI_EVENT_FNKEY_1
},
2909 { 0x22, SONYPI_EVENT_FNKEY_2
},
2910 { 0x31, SONYPI_EVENT_FNKEY_D
},
2911 { 0x32, SONYPI_EVENT_FNKEY_E
},
2912 { 0x33, SONYPI_EVENT_FNKEY_F
},
2913 { 0x34, SONYPI_EVENT_FNKEY_S
},
2914 { 0x35, SONYPI_EVENT_FNKEY_B
},
2915 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
2919 /* The set of possible program key events */
2920 static struct sonypi_event sonypi_pkeyev
[] = {
2921 { 0x01, SONYPI_EVENT_PKEY_P1
},
2922 { 0x02, SONYPI_EVENT_PKEY_P2
},
2923 { 0x04, SONYPI_EVENT_PKEY_P3
},
2924 { 0x20, SONYPI_EVENT_PKEY_P1
},
2928 /* The set of possible bluetooth events */
2929 static struct sonypi_event sonypi_blueev
[] = {
2930 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
2931 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
2932 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
2936 /* The set of possible wireless events */
2937 static struct sonypi_event sonypi_wlessev
[] = {
2938 { 0x59, SONYPI_EVENT_IGNORE
},
2939 { 0x5a, SONYPI_EVENT_IGNORE
},
2943 /* The set of possible back button events */
2944 static struct sonypi_event sonypi_backev
[] = {
2945 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
2949 /* The set of possible help button events */
2950 static struct sonypi_event sonypi_helpev
[] = {
2951 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
2956 /* The set of possible lid events */
2957 static struct sonypi_event sonypi_lidev
[] = {
2958 { 0x51, SONYPI_EVENT_LID_CLOSED
},
2959 { 0x50, SONYPI_EVENT_LID_OPENED
},
2963 /* The set of possible zoom events */
2964 static struct sonypi_event sonypi_zoomev
[] = {
2965 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
2966 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED
},
2967 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED
},
2968 { 0x04, SONYPI_EVENT_ZOOM_PRESSED
},
2972 /* The set of possible thumbphrase events */
2973 static struct sonypi_event sonypi_thumbphraseev
[] = {
2974 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
2978 /* The set of possible motioneye camera events */
2979 static struct sonypi_event sonypi_meyeev
[] = {
2980 { 0x00, SONYPI_EVENT_MEYE_FACE
},
2981 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
2985 /* The set of possible memorystick events */
2986 static struct sonypi_event sonypi_memorystickev
[] = {
2987 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
2988 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
2992 /* The set of possible battery events */
2993 static struct sonypi_event sonypi_batteryev
[] = {
2994 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
2995 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
2999 /* The set of possible volume events */
3000 static struct sonypi_event sonypi_volumeev
[] = {
3001 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED
},
3002 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED
},
3006 /* The set of possible brightness events */
3007 static struct sonypi_event sonypi_brightnessev
[] = {
3008 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED
},
3012 static struct sonypi_eventtypes type1_events
[] = {
3013 { 0, 0xffffffff, sonypi_releaseev
},
3014 { 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
3015 { 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
3016 { 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3017 { 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
3018 { 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3019 { 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
3020 { 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3021 { 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3022 { 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3025 static struct sonypi_eventtypes type2_events
[] = {
3026 { 0, 0xffffffff, sonypi_releaseev
},
3027 { 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
3028 { 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
3029 { 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3030 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3031 { 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
3032 { 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3033 { 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
3034 { 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
3035 { 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
3036 { 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
3037 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3038 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3039 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3042 static struct sonypi_eventtypes type3_events
[] = {
3043 { 0, 0xffffffff, sonypi_releaseev
},
3044 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3045 { 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
3046 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3047 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3048 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3049 { 0x05, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3050 { 0x05, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
3051 { 0x05, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3052 { 0x05, SONYPI_PKEY_MASK
, sonypi_volumeev
},
3053 { 0x05, SONYPI_PKEY_MASK
, sonypi_brightnessev
},
3057 /* low level spic calls */
3058 #define ITERATIONS_LONG 10000
3059 #define ITERATIONS_SHORT 10
3060 #define wait_on_command(command, iterations) { \
3061 unsigned int n = iterations; \
3062 while (--n && (command)) \
3065 dprintk("command failed at %s : %s (line %d)\n", \
3066 __FILE__, __func__, __LINE__); \
3069 static u8
sony_pic_call1(u8 dev
)
3073 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3075 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3076 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3077 v2
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3078 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev
, (v2
<< 8) | v1
);
3082 static u8
sony_pic_call2(u8 dev
, u8 fn
)
3086 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3088 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3089 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3091 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
3092 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3093 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev
, fn
, v1
);
3097 static u8
sony_pic_call3(u8 dev
, u8 fn
, u8 v
)
3101 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3102 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3103 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3104 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
3105 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3106 outb(v
, spic_dev
.cur_ioport
->io1
.minimum
);
3107 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3108 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
3114 * minidrivers for SPIC models
3116 static int type3_handle_irq(const u8 data_mask
, const u8 ev
)
3119 * 0x31 could mean we have to take some extra action and wait for
3120 * the next irq for some Type3 models, it will generate a new
3121 * irq and we can read new data from the device:
3122 * - 0x5c and 0x5f requires 0xA0
3123 * - 0x61 requires 0xB3
3125 if (data_mask
== 0x31) {
3126 if (ev
== 0x5c || ev
== 0x5f)
3127 sony_pic_call1(0xA0);
3128 else if (ev
== 0x61)
3129 sony_pic_call1(0xB3);
3135 static void sony_pic_detect_device_type(struct sony_pic_dev
*dev
)
3137 struct pci_dev
*pcidev
;
3139 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3140 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
3142 dev
->model
= SONYPI_DEVICE_TYPE1
;
3143 dev
->evport_offset
= SONYPI_TYPE1_OFFSET
;
3144 dev
->event_types
= type1_events
;
3148 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3149 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
);
3151 dev
->model
= SONYPI_DEVICE_TYPE2
;
3152 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
3153 dev
->event_types
= type2_events
;
3157 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3158 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
);
3160 dev
->model
= SONYPI_DEVICE_TYPE3
;
3161 dev
->handle_irq
= type3_handle_irq
;
3162 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3163 dev
->event_types
= type3_events
;
3167 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3168 PCI_DEVICE_ID_INTEL_ICH8_4
, NULL
);
3170 dev
->model
= SONYPI_DEVICE_TYPE3
;
3171 dev
->handle_irq
= type3_handle_irq
;
3172 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3173 dev
->event_types
= type3_events
;
3177 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3178 PCI_DEVICE_ID_INTEL_ICH9_1
, NULL
);
3180 dev
->model
= SONYPI_DEVICE_TYPE3
;
3181 dev
->handle_irq
= type3_handle_irq
;
3182 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3183 dev
->event_types
= type3_events
;
3188 dev
->model
= SONYPI_DEVICE_TYPE2
;
3189 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
3190 dev
->event_types
= type2_events
;
3194 pci_dev_put(pcidev
);
3196 pr_info("detected Type%d model\n",
3197 dev
->model
== SONYPI_DEVICE_TYPE1
? 1 :
3198 dev
->model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
3201 /* camera tests and poweron/poweroff */
3202 #define SONYPI_CAMERA_PICTURE 5
3203 #define SONYPI_CAMERA_CONTROL 0x10
3205 #define SONYPI_CAMERA_BRIGHTNESS 0
3206 #define SONYPI_CAMERA_CONTRAST 1
3207 #define SONYPI_CAMERA_HUE 2
3208 #define SONYPI_CAMERA_COLOR 3
3209 #define SONYPI_CAMERA_SHARPNESS 4
3211 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
3212 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
3213 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
3214 #define SONYPI_CAMERA_MUTE_MASK 0x40
3216 /* the rest don't need a loop until not 0xff */
3217 #define SONYPI_CAMERA_AGC 6
3218 #define SONYPI_CAMERA_AGC_MASK 0x30
3219 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
3221 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
3222 #define SONYPI_CAMERA_CONTROL 0x10
3224 #define SONYPI_CAMERA_STATUS 7
3225 #define SONYPI_CAMERA_STATUS_READY 0x2
3226 #define SONYPI_CAMERA_STATUS_POSITION 0x4
3228 #define SONYPI_DIRECTION_BACKWARDS 0x4
3230 #define SONYPI_CAMERA_REVISION 8
3231 #define SONYPI_CAMERA_ROMVERSION 9
3233 static int __sony_pic_camera_ready(void)
3237 v
= sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS
);
3238 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
3241 static int __sony_pic_camera_off(void)
3244 pr_warn("camera control not enabled\n");
3248 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
,
3249 SONYPI_CAMERA_MUTE_MASK
),
3252 if (spic_dev
.camera_power
) {
3253 sony_pic_call2(0x91, 0);
3254 spic_dev
.camera_power
= 0;
3259 static int __sony_pic_camera_on(void)
3264 pr_warn("camera control not enabled\n");
3268 if (spic_dev
.camera_power
)
3271 for (j
= 5; j
> 0; j
--) {
3273 for (x
= 0; x
< 100 && sony_pic_call2(0x91, 0x1); x
++)
3275 sony_pic_call1(0x93);
3277 for (i
= 400; i
> 0; i
--) {
3278 if (__sony_pic_camera_ready())
3287 pr_warn("failed to power on camera\n");
3291 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL
,
3295 spic_dev
.camera_power
= 1;
3299 /* External camera command (exported to the motion eye v4l driver) */
3300 int sony_pic_camera_command(int command
, u8 value
)
3305 mutex_lock(&spic_dev
.lock
);
3308 case SONY_PIC_COMMAND_SETCAMERA
:
3310 __sony_pic_camera_on();
3312 __sony_pic_camera_off();
3314 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS
:
3315 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS
, value
),
3318 case SONY_PIC_COMMAND_SETCAMERACONTRAST
:
3319 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST
, value
),
3322 case SONY_PIC_COMMAND_SETCAMERAHUE
:
3323 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE
, value
),
3326 case SONY_PIC_COMMAND_SETCAMERACOLOR
:
3327 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR
, value
),
3330 case SONY_PIC_COMMAND_SETCAMERASHARPNESS
:
3331 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS
, value
),
3334 case SONY_PIC_COMMAND_SETCAMERAPICTURE
:
3335 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
, value
),
3338 case SONY_PIC_COMMAND_SETCAMERAAGC
:
3339 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC
, value
),
3343 pr_err("sony_pic_camera_command invalid: %d\n", command
);
3346 mutex_unlock(&spic_dev
.lock
);
3349 EXPORT_SYMBOL(sony_pic_camera_command
);
3351 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
3352 static void __sony_pic_set_wwanpower(u8 state
)
3355 if (spic_dev
.wwan_power
== state
)
3357 sony_pic_call2(0xB0, state
);
3358 sony_pic_call1(0x82);
3359 spic_dev
.wwan_power
= state
;
3362 static ssize_t
sony_pic_wwanpower_store(struct device
*dev
,
3363 struct device_attribute
*attr
,
3364 const char *buffer
, size_t count
)
3366 unsigned long value
;
3370 if (kstrtoul(buffer
, 10, &value
))
3373 mutex_lock(&spic_dev
.lock
);
3374 __sony_pic_set_wwanpower(value
);
3375 mutex_unlock(&spic_dev
.lock
);
3380 static ssize_t
sony_pic_wwanpower_show(struct device
*dev
,
3381 struct device_attribute
*attr
, char *buffer
)
3384 mutex_lock(&spic_dev
.lock
);
3385 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.wwan_power
);
3386 mutex_unlock(&spic_dev
.lock
);
3390 /* bluetooth subsystem power state */
3391 static void __sony_pic_set_bluetoothpower(u8 state
)
3394 if (spic_dev
.bluetooth_power
== state
)
3396 sony_pic_call2(0x96, state
);
3397 sony_pic_call1(0x82);
3398 spic_dev
.bluetooth_power
= state
;
3401 static ssize_t
sony_pic_bluetoothpower_store(struct device
*dev
,
3402 struct device_attribute
*attr
,
3403 const char *buffer
, size_t count
)
3405 unsigned long value
;
3409 if (kstrtoul(buffer
, 10, &value
))
3412 mutex_lock(&spic_dev
.lock
);
3413 __sony_pic_set_bluetoothpower(value
);
3414 mutex_unlock(&spic_dev
.lock
);
3419 static ssize_t
sony_pic_bluetoothpower_show(struct device
*dev
,
3420 struct device_attribute
*attr
, char *buffer
)
3423 mutex_lock(&spic_dev
.lock
);
3424 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.bluetooth_power
);
3425 mutex_unlock(&spic_dev
.lock
);
3430 /* FAN0 information (reverse engineered from ACPI tables) */
3431 #define SONY_PIC_FAN0_STATUS 0x93
3432 static int sony_pic_set_fanspeed(unsigned long value
)
3434 return ec_write(SONY_PIC_FAN0_STATUS
, value
);
3437 static int sony_pic_get_fanspeed(u8
*value
)
3439 return ec_read(SONY_PIC_FAN0_STATUS
, value
);
3442 static ssize_t
sony_pic_fanspeed_store(struct device
*dev
,
3443 struct device_attribute
*attr
,
3444 const char *buffer
, size_t count
)
3446 unsigned long value
;
3450 if (kstrtoul(buffer
, 10, &value
))
3453 if (sony_pic_set_fanspeed(value
))
3459 static ssize_t
sony_pic_fanspeed_show(struct device
*dev
,
3460 struct device_attribute
*attr
, char *buffer
)
3463 if (sony_pic_get_fanspeed(&value
))
3466 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
3469 #define SPIC_ATTR(_name, _mode) \
3470 struct device_attribute spic_attr_##_name = __ATTR(_name, \
3471 _mode, sony_pic_## _name ##_show, \
3472 sony_pic_## _name ##_store)
3474 static SPIC_ATTR(bluetoothpower
, 0644);
3475 static SPIC_ATTR(wwanpower
, 0644);
3476 static SPIC_ATTR(fanspeed
, 0644);
3478 static struct attribute
*spic_attributes
[] = {
3479 &spic_attr_bluetoothpower
.attr
,
3480 &spic_attr_wwanpower
.attr
,
3481 &spic_attr_fanspeed
.attr
,
3485 static struct attribute_group spic_attribute_group
= {
3486 .attrs
= spic_attributes
3489 /******** SONYPI compatibility **********/
3490 #ifdef CONFIG_SONYPI_COMPAT
3492 /* battery / brightness / temperature addresses */
3493 #define SONYPI_BAT_FLAGS 0x81
3494 #define SONYPI_LCD_LIGHT 0x96
3495 #define SONYPI_BAT1_PCTRM 0xa0
3496 #define SONYPI_BAT1_LEFT 0xa2
3497 #define SONYPI_BAT1_MAXRT 0xa4
3498 #define SONYPI_BAT2_PCTRM 0xa8
3499 #define SONYPI_BAT2_LEFT 0xaa
3500 #define SONYPI_BAT2_MAXRT 0xac
3501 #define SONYPI_BAT1_MAXTK 0xb0
3502 #define SONYPI_BAT1_FULL 0xb2
3503 #define SONYPI_BAT2_MAXTK 0xb8
3504 #define SONYPI_BAT2_FULL 0xba
3505 #define SONYPI_TEMP_STATUS 0xC1
3507 struct sonypi_compat_s
{
3508 struct fasync_struct
*fifo_async
;
3510 spinlock_t fifo_lock
;
3511 wait_queue_head_t fifo_proc_list
;
3512 atomic_t open_count
;
3514 static struct sonypi_compat_s sonypi_compat
= {
3515 .open_count
= ATOMIC_INIT(0),
3518 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
3520 return fasync_helper(fd
, filp
, on
, &sonypi_compat
.fifo_async
);
3523 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
3525 atomic_dec(&sonypi_compat
.open_count
);
3529 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
3531 /* Flush input queue on first open */
3532 unsigned long flags
;
3534 spin_lock_irqsave(&sonypi_compat
.fifo_lock
, flags
);
3536 if (atomic_inc_return(&sonypi_compat
.open_count
) == 1)
3537 kfifo_reset(&sonypi_compat
.fifo
);
3539 spin_unlock_irqrestore(&sonypi_compat
.fifo_lock
, flags
);
3544 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
3545 size_t count
, loff_t
*pos
)
3550 if ((kfifo_len(&sonypi_compat
.fifo
) == 0) &&
3551 (file
->f_flags
& O_NONBLOCK
))
3554 ret
= wait_event_interruptible(sonypi_compat
.fifo_proc_list
,
3555 kfifo_len(&sonypi_compat
.fifo
) != 0);
3559 while (ret
< count
&&
3560 (kfifo_out_locked(&sonypi_compat
.fifo
, &c
, sizeof(c
),
3561 &sonypi_compat
.fifo_lock
) == sizeof(c
))) {
3562 if (put_user(c
, buf
++))
3568 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
3569 inode
->i_atime
= current_fs_time(inode
->i_sb
);
3575 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
3577 poll_wait(file
, &sonypi_compat
.fifo_proc_list
, wait
);
3578 if (kfifo_len(&sonypi_compat
.fifo
))
3579 return POLLIN
| POLLRDNORM
;
3583 static int ec_read16(u8 addr
, u16
*value
)
3586 if (ec_read(addr
, &val_lb
))
3588 if (ec_read(addr
+ 1, &val_hb
))
3590 *value
= val_lb
| (val_hb
<< 8);
3594 static long sonypi_misc_ioctl(struct file
*fp
, unsigned int cmd
,
3598 void __user
*argp
= (void __user
*)arg
;
3603 mutex_lock(&spic_dev
.lock
);
3605 case SONYPI_IOCGBRT
:
3606 if (sony_bl_props
.dev
== NULL
) {
3610 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
,
3615 val8
= ((value
& 0xff) - 1) << 5;
3616 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3619 case SONYPI_IOCSBRT
:
3620 if (sony_bl_props
.dev
== NULL
) {
3624 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3628 value
= (val8
>> 5) + 1;
3629 if (sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &value
,
3634 /* sync the backlight device status */
3635 sony_bl_props
.dev
->props
.brightness
=
3636 sony_backlight_get_brightness(sony_bl_props
.dev
);
3638 case SONYPI_IOCGBAT1CAP
:
3639 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
3643 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3646 case SONYPI_IOCGBAT1REM
:
3647 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
3651 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3654 case SONYPI_IOCGBAT2CAP
:
3655 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
3659 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3662 case SONYPI_IOCGBAT2REM
:
3663 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
3667 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
3670 case SONYPI_IOCGBATFLAGS
:
3671 if (ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
3676 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3679 case SONYPI_IOCGBLUE
:
3680 val8
= spic_dev
.bluetooth_power
;
3681 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3684 case SONYPI_IOCSBLUE
:
3685 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3689 __sony_pic_set_bluetoothpower(val8
);
3692 case SONYPI_IOCGFAN
:
3693 if (sony_pic_get_fanspeed(&val8
)) {
3697 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3700 case SONYPI_IOCSFAN
:
3701 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
3705 if (sony_pic_set_fanspeed(val8
))
3708 /* GET Temperature (useful under APM) */
3709 case SONYPI_IOCGTEMP
:
3710 if (ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
3714 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
3720 mutex_unlock(&spic_dev
.lock
);
3724 static const struct file_operations sonypi_misc_fops
= {
3725 .owner
= THIS_MODULE
,
3726 .read
= sonypi_misc_read
,
3727 .poll
= sonypi_misc_poll
,
3728 .open
= sonypi_misc_open
,
3729 .release
= sonypi_misc_release
,
3730 .fasync
= sonypi_misc_fasync
,
3731 .unlocked_ioctl
= sonypi_misc_ioctl
,
3732 .llseek
= noop_llseek
,
3735 static struct miscdevice sonypi_misc_device
= {
3736 .minor
= MISC_DYNAMIC_MINOR
,
3738 .fops
= &sonypi_misc_fops
,
3741 static void sonypi_compat_report_event(u8 event
)
3743 kfifo_in_locked(&sonypi_compat
.fifo
, (unsigned char *)&event
,
3744 sizeof(event
), &sonypi_compat
.fifo_lock
);
3745 kill_fasync(&sonypi_compat
.fifo_async
, SIGIO
, POLL_IN
);
3746 wake_up_interruptible(&sonypi_compat
.fifo_proc_list
);
3749 static int sonypi_compat_init(void)
3753 spin_lock_init(&sonypi_compat
.fifo_lock
);
3755 kfifo_alloc(&sonypi_compat
.fifo
, SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
3757 pr_err("kfifo_alloc failed\n");
3761 init_waitqueue_head(&sonypi_compat
.fifo_proc_list
);
3764 sonypi_misc_device
.minor
= minor
;
3765 error
= misc_register(&sonypi_misc_device
);
3767 pr_err("misc_register failed\n");
3768 goto err_free_kfifo
;
3771 pr_info("device allocated minor is %d\n",
3772 sonypi_misc_device
.minor
);
3777 kfifo_free(&sonypi_compat
.fifo
);
3781 static void sonypi_compat_exit(void)
3783 misc_deregister(&sonypi_misc_device
);
3784 kfifo_free(&sonypi_compat
.fifo
);
3787 static int sonypi_compat_init(void) { return 0; }
3788 static void sonypi_compat_exit(void) { }
3789 static void sonypi_compat_report_event(u8 event
) { }
3790 #endif /* CONFIG_SONYPI_COMPAT */
3796 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
3799 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
3801 switch (resource
->type
) {
3802 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
3804 /* start IO enumeration */
3805 struct sony_pic_ioport
*ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
3809 list_add(&ioport
->list
, &dev
->ioports
);
3813 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
3814 /* end IO enumeration */
3817 case ACPI_RESOURCE_TYPE_IRQ
:
3819 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
3820 struct sony_pic_irq
*interrupt
= NULL
;
3821 if (!p
|| !p
->interrupt_count
) {
3823 * IRQ descriptors may have no IRQ# bits set,
3824 * particularly those those w/ _STA disabled
3826 dprintk("Blank IRQ resource\n");
3829 for (i
= 0; i
< p
->interrupt_count
; i
++) {
3830 if (!p
->interrupts
[i
]) {
3831 pr_warn("Invalid IRQ %d\n",
3835 interrupt
= kzalloc(sizeof(*interrupt
),
3840 list_add(&interrupt
->list
, &dev
->interrupts
);
3841 interrupt
->irq
.triggering
= p
->triggering
;
3842 interrupt
->irq
.polarity
= p
->polarity
;
3843 interrupt
->irq
.sharable
= p
->sharable
;
3844 interrupt
->irq
.interrupt_count
= 1;
3845 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
3849 case ACPI_RESOURCE_TYPE_IO
:
3851 struct acpi_resource_io
*io
= &resource
->data
.io
;
3852 struct sony_pic_ioport
*ioport
=
3853 list_first_entry(&dev
->ioports
, struct sony_pic_ioport
, list
);
3855 dprintk("Blank IO resource\n");
3859 if (!ioport
->io1
.minimum
) {
3860 memcpy(&ioport
->io1
, io
, sizeof(*io
));
3861 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport
->io1
.minimum
,
3862 ioport
->io1
.address_length
);
3864 else if (!ioport
->io2
.minimum
) {
3865 memcpy(&ioport
->io2
, io
, sizeof(*io
));
3866 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport
->io2
.minimum
,
3867 ioport
->io2
.address_length
);
3870 pr_err("Unknown SPIC Type, more than 2 IO Ports\n");
3876 dprintk("Resource %d isn't an IRQ nor an IO port\n",
3879 case ACPI_RESOURCE_TYPE_END_TAG
:
3882 return AE_CTRL_TERMINATE
;
3885 static int sony_pic_possible_resources(struct acpi_device
*device
)
3888 acpi_status status
= AE_OK
;
3893 /* get device status */
3894 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
3895 dprintk("Evaluating _STA\n");
3896 result
= acpi_bus_get_status(device
);
3898 pr_warn("Unable to read status\n");
3902 if (!device
->status
.enabled
)
3903 dprintk("Device disabled\n");
3905 dprintk("Device enabled\n");
3908 * Query and parse 'method'
3910 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
3911 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
3912 sony_pic_read_possible_resource
, &spic_dev
);
3913 if (ACPI_FAILURE(status
)) {
3914 pr_warn("Failure evaluating %s\n", METHOD_NAME__PRS
);
3922 * Disable the spic device by calling its _DIS method
3924 static int sony_pic_disable(struct acpi_device
*device
)
3926 acpi_status ret
= acpi_evaluate_object(device
->handle
, "_DIS", NULL
,
3929 if (ACPI_FAILURE(ret
) && ret
!= AE_NOT_FOUND
)
3932 dprintk("Device disabled\n");
3938 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
3940 * Call _SRS to set current resources
3942 static int sony_pic_enable(struct acpi_device
*device
,
3943 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
3947 /* Type 1 resource layout is:
3953 * Type 2 and 3 resource layout is:
3959 struct acpi_resource res1
;
3960 struct acpi_resource res2
;
3961 struct acpi_resource res3
;
3962 struct acpi_resource res4
;
3964 struct acpi_buffer buffer
= { 0, NULL
};
3966 if (!ioport
|| !irq
)
3969 /* init acpi_buffer */
3970 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
3974 buffer
.length
= sizeof(*resource
) + 1;
3975 buffer
.pointer
= resource
;
3977 /* setup Type 1 resources */
3978 if (spic_dev
.model
== SONYPI_DEVICE_TYPE1
) {
3980 /* setup io resources */
3981 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
3982 resource
->res1
.length
= sizeof(struct acpi_resource
);
3983 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
3984 sizeof(struct acpi_resource_io
));
3986 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IO
;
3987 resource
->res2
.length
= sizeof(struct acpi_resource
);
3988 memcpy(&resource
->res2
.data
.io
, &ioport
->io2
,
3989 sizeof(struct acpi_resource_io
));
3991 /* setup irq resource */
3992 resource
->res3
.type
= ACPI_RESOURCE_TYPE_IRQ
;
3993 resource
->res3
.length
= sizeof(struct acpi_resource
);
3994 memcpy(&resource
->res3
.data
.irq
, &irq
->irq
,
3995 sizeof(struct acpi_resource_irq
));
3996 /* we requested a shared irq */
3997 resource
->res3
.data
.irq
.sharable
= ACPI_SHARED
;
3999 resource
->res4
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
4002 /* setup Type 2/3 resources */
4004 /* setup io resource */
4005 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
4006 resource
->res1
.length
= sizeof(struct acpi_resource
);
4007 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
4008 sizeof(struct acpi_resource_io
));
4010 /* setup irq resource */
4011 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IRQ
;
4012 resource
->res2
.length
= sizeof(struct acpi_resource
);
4013 memcpy(&resource
->res2
.data
.irq
, &irq
->irq
,
4014 sizeof(struct acpi_resource_irq
));
4015 /* we requested a shared irq */
4016 resource
->res2
.data
.irq
.sharable
= ACPI_SHARED
;
4018 resource
->res3
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
4021 /* Attempt to set the resource */
4022 dprintk("Evaluating _SRS\n");
4023 status
= acpi_set_current_resources(device
->handle
, &buffer
);
4025 /* check for total failure */
4026 if (ACPI_FAILURE(status
)) {
4027 pr_err("Error evaluating _SRS\n");
4032 /* Necessary device initializations calls (from sonypi) */
4033 sony_pic_call1(0x82);
4034 sony_pic_call2(0x81, 0xff);
4035 sony_pic_call1(compat
? 0x92 : 0x82);
4044 * ISR: some event is available
4047 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
4052 u8 device_event
= 0;
4054 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
4056 ev
= inb_p(dev
->cur_ioport
->io1
.minimum
);
4057 if (dev
->cur_ioport
->io2
.minimum
)
4058 data_mask
= inb_p(dev
->cur_ioport
->io2
.minimum
);
4060 data_mask
= inb_p(dev
->cur_ioport
->io1
.minimum
+
4061 dev
->evport_offset
);
4063 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
4064 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
4065 dev
->evport_offset
);
4067 if (ev
== 0x00 || ev
== 0xff)
4070 for (i
= 0; dev
->event_types
[i
].mask
; i
++) {
4072 if ((data_mask
& dev
->event_types
[i
].data
) !=
4073 dev
->event_types
[i
].data
)
4076 if (!(mask
& dev
->event_types
[i
].mask
))
4079 for (j
= 0; dev
->event_types
[i
].events
[j
].event
; j
++) {
4080 if (ev
== dev
->event_types
[i
].events
[j
].data
) {
4082 dev
->event_types
[i
].events
[j
].event
;
4083 /* some events may require ignoring */
4090 /* Still not able to decode the event try to pass
4091 * it over to the minidriver
4093 if (dev
->handle_irq
&& dev
->handle_irq(data_mask
, ev
) == 0)
4096 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
4097 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
4098 dev
->evport_offset
);
4102 sony_laptop_report_input_event(device_event
);
4103 acpi_bus_generate_proc_event(dev
->acpi_dev
, 1, device_event
);
4104 sonypi_compat_report_event(device_event
);
4113 static int sony_pic_remove(struct acpi_device
*device
, int type
)
4115 struct sony_pic_ioport
*io
, *tmp_io
;
4116 struct sony_pic_irq
*irq
, *tmp_irq
;
4118 if (sony_pic_disable(device
)) {
4119 pr_err("Couldn't disable device\n");
4123 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
4124 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
4125 spic_dev
.cur_ioport
->io1
.address_length
);
4126 if (spic_dev
.cur_ioport
->io2
.minimum
)
4127 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
4128 spic_dev
.cur_ioport
->io2
.address_length
);
4130 sonypi_compat_exit();
4132 sony_laptop_remove_input();
4135 sysfs_remove_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
4138 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
4139 list_del(&io
->list
);
4142 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
4143 list_del(&irq
->list
);
4146 spic_dev
.cur_ioport
= NULL
;
4147 spic_dev
.cur_irq
= NULL
;
4149 dprintk(SONY_PIC_DRIVER_NAME
" removed.\n");
4153 static int sony_pic_add(struct acpi_device
*device
)
4156 struct sony_pic_ioport
*io
, *tmp_io
;
4157 struct sony_pic_irq
*irq
, *tmp_irq
;
4159 pr_info("%s v%s\n", SONY_PIC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
4161 spic_dev
.acpi_dev
= device
;
4162 strcpy(acpi_device_class(device
), "sony/hotkey");
4163 sony_pic_detect_device_type(&spic_dev
);
4164 mutex_init(&spic_dev
.lock
);
4166 /* read _PRS resources */
4167 result
= sony_pic_possible_resources(device
);
4169 pr_err("Unable to read possible resources\n");
4170 goto err_free_resources
;
4173 /* setup input devices and helper fifo */
4174 result
= sony_laptop_setup_input(device
);
4176 pr_err("Unable to create input devices\n");
4177 goto err_free_resources
;
4180 if (sonypi_compat_init())
4181 goto err_remove_input
;
4183 /* request io port */
4184 list_for_each_entry_reverse(io
, &spic_dev
.ioports
, list
) {
4185 if (request_region(io
->io1
.minimum
, io
->io1
.address_length
,
4186 "Sony Programmable I/O Device")) {
4187 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
4188 io
->io1
.minimum
, io
->io1
.maximum
,
4189 io
->io1
.address_length
);
4190 /* Type 1 have 2 ioports */
4191 if (io
->io2
.minimum
) {
4192 if (request_region(io
->io2
.minimum
,
4193 io
->io2
.address_length
,
4194 "Sony Programmable I/O Device")) {
4195 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
4196 io
->io2
.minimum
, io
->io2
.maximum
,
4197 io
->io2
.address_length
);
4198 spic_dev
.cur_ioport
= io
;
4202 dprintk("Unable to get I/O port2: "
4203 "0x%.4x (0x%.4x) + 0x%.2x\n",
4204 io
->io2
.minimum
, io
->io2
.maximum
,
4205 io
->io2
.address_length
);
4206 release_region(io
->io1
.minimum
,
4207 io
->io1
.address_length
);
4211 spic_dev
.cur_ioport
= io
;
4216 if (!spic_dev
.cur_ioport
) {
4217 pr_err("Failed to request_region\n");
4219 goto err_remove_compat
;
4223 list_for_each_entry_reverse(irq
, &spic_dev
.interrupts
, list
) {
4224 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
4225 0, "sony-laptop", &spic_dev
)) {
4226 dprintk("IRQ: %d - triggering: %d - "
4227 "polarity: %d - shr: %d\n",
4228 irq
->irq
.interrupts
[0],
4229 irq
->irq
.triggering
,
4232 spic_dev
.cur_irq
= irq
;
4236 if (!spic_dev
.cur_irq
) {
4237 pr_err("Failed to request_irq\n");
4239 goto err_release_region
;
4242 /* set resource status _SRS */
4243 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
4245 pr_err("Couldn't enable device\n");
4249 spic_dev
.bluetooth_power
= -1;
4250 /* create device attributes */
4251 result
= sony_pf_add();
4253 goto err_disable_device
;
4255 result
= sysfs_create_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
4265 sony_pic_disable(device
);
4268 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
4271 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
4272 spic_dev
.cur_ioport
->io1
.address_length
);
4273 if (spic_dev
.cur_ioport
->io2
.minimum
)
4274 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
4275 spic_dev
.cur_ioport
->io2
.address_length
);
4278 sonypi_compat_exit();
4281 sony_laptop_remove_input();
4284 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
4285 list_del(&io
->list
);
4288 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
4289 list_del(&irq
->list
);
4292 spic_dev
.cur_ioport
= NULL
;
4293 spic_dev
.cur_irq
= NULL
;
4298 #ifdef CONFIG_PM_SLEEP
4299 static int sony_pic_suspend(struct device
*dev
)
4301 if (sony_pic_disable(to_acpi_device(dev
)))
4306 static int sony_pic_resume(struct device
*dev
)
4308 sony_pic_enable(to_acpi_device(dev
),
4309 spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
4314 static SIMPLE_DEV_PM_OPS(sony_pic_pm
, sony_pic_suspend
, sony_pic_resume
);
4316 static const struct acpi_device_id sony_pic_device_ids
[] = {
4321 static struct acpi_driver sony_pic_driver
= {
4322 .name
= SONY_PIC_DRIVER_NAME
,
4323 .class = SONY_PIC_CLASS
,
4324 .ids
= sony_pic_device_ids
,
4325 .owner
= THIS_MODULE
,
4327 .add
= sony_pic_add
,
4328 .remove
= sony_pic_remove
,
4330 .drv
.pm
= &sony_pic_pm
,
4333 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
4335 .ident
= "Sony Vaio",
4337 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
4338 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
4342 .ident
= "Sony Vaio",
4344 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
4345 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
4351 static int __init
sony_laptop_init(void)
4355 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
4356 result
= acpi_bus_register_driver(&sony_pic_driver
);
4358 pr_err("Unable to register SPIC driver\n");
4361 spic_drv_registered
= 1;
4364 result
= acpi_bus_register_driver(&sony_nc_driver
);
4366 pr_err("Unable to register SNC driver\n");
4367 goto out_unregister_pic
;
4373 if (spic_drv_registered
)
4374 acpi_bus_unregister_driver(&sony_pic_driver
);
4379 static void __exit
sony_laptop_exit(void)
4381 acpi_bus_unregister_driver(&sony_nc_driver
);
4382 if (spic_drv_registered
)
4383 acpi_bus_unregister_driver(&sony_pic_driver
);
4386 module_init(sony_laptop_init
);
4387 module_exit(sony_laptop_exit
);