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 <linux/sonypi.h>
65 #include <linux/sony-laptop.h>
66 #include <linux/rfkill.h>
67 #ifdef CONFIG_SONYPI_COMPAT
68 #include <linux/poll.h>
69 #include <linux/miscdevice.h>
71 #include <asm/uaccess.h>
73 #define dprintk(fmt, ...) \
76 pr_warn(fmt, ##__VA_ARGS__); \
79 #define SONY_NC_CLASS "sony-nc"
80 #define SONY_NC_HID "SNY5001"
81 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
83 #define SONY_PIC_CLASS "sony-pic"
84 #define SONY_PIC_HID "SNY6001"
85 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
87 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
88 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
89 MODULE_LICENSE("GPL");
92 module_param(debug
, int, 0);
93 MODULE_PARM_DESC(debug
, "set this to 1 (and RTFM) if you want to help "
94 "the development of this driver");
96 static int no_spic
; /* = 0 */
97 module_param(no_spic
, int, 0444);
98 MODULE_PARM_DESC(no_spic
,
99 "set this if you don't want to enable the SPIC device");
101 static int compat
; /* = 0 */
102 module_param(compat
, int, 0444);
103 MODULE_PARM_DESC(compat
,
104 "set this if you want to enable backward compatibility mode");
106 static unsigned long mask
= 0xffffffff;
107 module_param(mask
, ulong
, 0644);
108 MODULE_PARM_DESC(mask
,
109 "set this to the mask of event you want to enable (see doc)");
111 static int camera
; /* = 0 */
112 module_param(camera
, int, 0444);
113 MODULE_PARM_DESC(camera
,
114 "set this to 1 to enable Motion Eye camera controls "
115 "(only use it if you have a C1VE or C1VN model)");
117 #ifdef CONFIG_SONYPI_COMPAT
118 static int minor
= -1;
119 module_param(minor
, int, 0);
120 MODULE_PARM_DESC(minor
,
121 "minor number of the misc device for the SPIC compatibility code, "
122 "default is -1 (automatic)");
125 static int kbd_backlight
= -1;
126 module_param(kbd_backlight
, int, 0444);
127 MODULE_PARM_DESC(kbd_backlight
,
128 "set this to 0 to disable keyboard backlight, "
129 "1 to enable it with automatic control and 2 to have it always "
130 "on (default: no change from current value)");
132 static int kbd_backlight_timeout
= -1;
133 module_param(kbd_backlight_timeout
, int, 0444);
134 MODULE_PARM_DESC(kbd_backlight_timeout
,
135 "meaningful values vary from 0 to 3 and their meaning depends "
136 "on the model (default: no change from current value)");
138 #ifdef CONFIG_PM_SLEEP
139 static void sony_nc_thermal_resume(void);
141 static int sony_nc_kbd_backlight_setup(struct platform_device
*pd
,
142 unsigned int handle
);
143 static void sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
,
144 unsigned int handle
);
146 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
147 unsigned int handle
);
148 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
);
150 static int sony_nc_thermal_setup(struct platform_device
*pd
);
151 static void sony_nc_thermal_cleanup(struct platform_device
*pd
);
153 static int sony_nc_lid_resume_setup(struct platform_device
*pd
,
154 unsigned int handle
);
155 static void sony_nc_lid_resume_cleanup(struct platform_device
*pd
);
157 static int sony_nc_gfx_switch_setup(struct platform_device
*pd
,
158 unsigned int handle
);
159 static void sony_nc_gfx_switch_cleanup(struct platform_device
*pd
);
160 static int __sony_nc_gfx_switch_status_get(void);
162 static int sony_nc_highspeed_charging_setup(struct platform_device
*pd
);
163 static void sony_nc_highspeed_charging_cleanup(struct platform_device
*pd
);
165 static int sony_nc_lowbatt_setup(struct platform_device
*pd
);
166 static void sony_nc_lowbatt_cleanup(struct platform_device
*pd
);
168 static int sony_nc_fanspeed_setup(struct platform_device
*pd
);
169 static void sony_nc_fanspeed_cleanup(struct platform_device
*pd
);
171 static int sony_nc_usb_charge_setup(struct platform_device
*pd
);
172 static void sony_nc_usb_charge_cleanup(struct platform_device
*pd
);
174 static int sony_nc_panelid_setup(struct platform_device
*pd
);
175 static void sony_nc_panelid_cleanup(struct platform_device
*pd
);
177 static int sony_nc_smart_conn_setup(struct platform_device
*pd
);
178 static void sony_nc_smart_conn_cleanup(struct platform_device
*pd
);
180 static int sony_nc_touchpad_setup(struct platform_device
*pd
,
181 unsigned int handle
);
182 static void sony_nc_touchpad_cleanup(struct platform_device
*pd
);
184 enum sony_nc_rfkill
{
192 static int sony_rfkill_handle
;
193 static struct rfkill
*sony_rfkill_devices
[N_SONY_RFKILL
];
194 static int sony_rfkill_address
[N_SONY_RFKILL
] = {0x300, 0x500, 0x700, 0x900};
195 static int sony_nc_rfkill_setup(struct acpi_device
*device
,
196 unsigned int handle
);
197 static void sony_nc_rfkill_cleanup(void);
198 static void sony_nc_rfkill_update(void);
200 /*********** Input Devices ***********/
202 #define SONY_LAPTOP_BUF_SIZE 128
203 struct sony_laptop_input_s
{
205 struct input_dev
*jog_dev
;
206 struct input_dev
*key_dev
;
208 spinlock_t fifo_lock
;
209 struct timer_list release_key_timer
;
212 static struct sony_laptop_input_s sony_laptop_input
= {
213 .users
= ATOMIC_INIT(0),
216 struct sony_laptop_keypress
{
217 struct input_dev
*dev
;
221 /* Correspondance table between sonypi events
222 * and input layer indexes in the keymap
224 static int sony_laptop_input_index
[] = {
226 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
227 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
228 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
229 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
230 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
231 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
232 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
233 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
234 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
235 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
236 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
237 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
238 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
239 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
240 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
241 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
242 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
243 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
244 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
245 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
246 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
247 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
248 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
249 17, /* 24 SONYPI_EVENT_FNKEY_1 */
250 18, /* 25 SONYPI_EVENT_FNKEY_2 */
251 19, /* 26 SONYPI_EVENT_FNKEY_D */
252 20, /* 27 SONYPI_EVENT_FNKEY_E */
253 21, /* 28 SONYPI_EVENT_FNKEY_F */
254 22, /* 29 SONYPI_EVENT_FNKEY_S */
255 23, /* 30 SONYPI_EVENT_FNKEY_B */
256 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
257 25, /* 32 SONYPI_EVENT_PKEY_P1 */
258 26, /* 33 SONYPI_EVENT_PKEY_P2 */
259 27, /* 34 SONYPI_EVENT_PKEY_P3 */
260 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
261 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
262 -1, /* 37 SONYPI_EVENT_LID_OPENED */
263 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
264 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
265 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
266 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
267 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
268 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
269 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
270 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
271 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
272 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
273 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
274 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
275 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
276 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
277 43, /* 52 SONYPI_EVENT_MEYE_FACE */
278 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
279 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
280 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
281 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
282 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
283 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
284 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
285 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
286 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
287 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
288 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
289 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
290 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
291 53, /* 66 SONYPI_EVENT_PKEY_P4 */
292 54, /* 67 SONYPI_EVENT_PKEY_P5 */
293 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
294 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
295 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
296 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
297 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
298 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */
301 static int sony_laptop_input_keycode_map
[] = {
302 KEY_CAMERA
, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
303 KEY_RESERVED
, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
304 KEY_RESERVED
, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
305 KEY_RESERVED
, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
306 KEY_FN_ESC
, /* 4 SONYPI_EVENT_FNKEY_ESC */
307 KEY_FN_F1
, /* 5 SONYPI_EVENT_FNKEY_F1 */
308 KEY_FN_F2
, /* 6 SONYPI_EVENT_FNKEY_F2 */
309 KEY_FN_F3
, /* 7 SONYPI_EVENT_FNKEY_F3 */
310 KEY_FN_F4
, /* 8 SONYPI_EVENT_FNKEY_F4 */
311 KEY_FN_F5
, /* 9 SONYPI_EVENT_FNKEY_F5 */
312 KEY_FN_F6
, /* 10 SONYPI_EVENT_FNKEY_F6 */
313 KEY_FN_F7
, /* 11 SONYPI_EVENT_FNKEY_F7 */
314 KEY_FN_F8
, /* 12 SONYPI_EVENT_FNKEY_F8 */
315 KEY_FN_F9
, /* 13 SONYPI_EVENT_FNKEY_F9 */
316 KEY_FN_F10
, /* 14 SONYPI_EVENT_FNKEY_F10 */
317 KEY_FN_F11
, /* 15 SONYPI_EVENT_FNKEY_F11 */
318 KEY_FN_F12
, /* 16 SONYPI_EVENT_FNKEY_F12 */
319 KEY_FN_1
, /* 17 SONYPI_EVENT_FNKEY_1 */
320 KEY_FN_2
, /* 18 SONYPI_EVENT_FNKEY_2 */
321 KEY_FN_D
, /* 19 SONYPI_EVENT_FNKEY_D */
322 KEY_FN_E
, /* 20 SONYPI_EVENT_FNKEY_E */
323 KEY_FN_F
, /* 21 SONYPI_EVENT_FNKEY_F */
324 KEY_FN_S
, /* 22 SONYPI_EVENT_FNKEY_S */
325 KEY_FN_B
, /* 23 SONYPI_EVENT_FNKEY_B */
326 KEY_BLUETOOTH
, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
327 KEY_PROG1
, /* 25 SONYPI_EVENT_PKEY_P1 */
328 KEY_PROG2
, /* 26 SONYPI_EVENT_PKEY_P2 */
329 KEY_PROG3
, /* 27 SONYPI_EVENT_PKEY_P3 */
330 KEY_BACK
, /* 28 SONYPI_EVENT_BACK_PRESSED */
331 KEY_BLUETOOTH
, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
332 KEY_BLUETOOTH
, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
333 KEY_HELP
, /* 31 SONYPI_EVENT_HELP_PRESSED */
334 KEY_FN
, /* 32 SONYPI_EVENT_FNKEY_ONLY */
335 KEY_RESERVED
, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
336 KEY_RESERVED
, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
337 KEY_RESERVED
, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
338 KEY_RESERVED
, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
339 KEY_RESERVED
, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
340 KEY_RESERVED
, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
341 KEY_RESERVED
, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
342 KEY_RESERVED
, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
343 KEY_ZOOM
, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
344 BTN_THUMB
, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
345 KEY_RESERVED
, /* 43 SONYPI_EVENT_MEYE_FACE */
346 KEY_RESERVED
, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
347 KEY_RESERVED
, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
348 KEY_RESERVED
, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
349 KEY_WLAN
, /* 47 SONYPI_EVENT_WIRELESS_ON */
350 KEY_WLAN
, /* 48 SONYPI_EVENT_WIRELESS_OFF */
351 KEY_ZOOMIN
, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
352 KEY_ZOOMOUT
, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
353 KEY_EJECTCD
, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
354 KEY_F13
, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
355 KEY_PROG4
, /* 53 SONYPI_EVENT_PKEY_P4 */
356 KEY_F14
, /* 54 SONYPI_EVENT_PKEY_P5 */
357 KEY_F15
, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
358 KEY_VOLUMEUP
, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
359 KEY_VOLUMEDOWN
, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
360 KEY_MEDIA
, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
361 KEY_VENDOR
, /* 59 SONYPI_EVENT_VENDOR_PRESSED */
364 /* release buttons after a short delay if pressed */
365 static void do_sony_laptop_release_key(unsigned long unused
)
367 struct sony_laptop_keypress kp
;
370 spin_lock_irqsave(&sony_laptop_input
.fifo_lock
, flags
);
372 if (kfifo_out(&sony_laptop_input
.fifo
,
373 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
374 input_report_key(kp
.dev
, kp
.key
, 0);
378 /* If there is something in the fifo schedule next release. */
379 if (kfifo_len(&sony_laptop_input
.fifo
) != 0)
380 mod_timer(&sony_laptop_input
.release_key_timer
,
381 jiffies
+ msecs_to_jiffies(10));
383 spin_unlock_irqrestore(&sony_laptop_input
.fifo_lock
, flags
);
386 /* forward event to the input subsystem */
387 static void sony_laptop_report_input_event(u8 event
)
389 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
390 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
391 struct sony_laptop_keypress kp
= { NULL
};
394 if (event
== SONYPI_EVENT_FNKEY_RELEASED
||
395 event
== SONYPI_EVENT_ANYBUTTON_RELEASED
) {
396 /* Nothing, not all VAIOs generate this event */
403 case SONYPI_EVENT_JOGDIAL_UP
:
404 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
405 input_report_rel(jog_dev
, REL_WHEEL
, 1);
409 case SONYPI_EVENT_JOGDIAL_DOWN
:
410 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
411 input_report_rel(jog_dev
, REL_WHEEL
, -1);
416 case SONYPI_EVENT_JOGDIAL_PRESSED
:
422 if (event
>= ARRAY_SIZE(sony_laptop_input_index
)) {
423 dprintk("sony_laptop_report_input_event, event not known: %d\n", event
);
426 if ((scancode
= sony_laptop_input_index
[event
]) != -1) {
427 kp
.key
= sony_laptop_input_keycode_map
[scancode
];
428 if (kp
.key
!= KEY_UNKNOWN
)
435 /* if we have a scancode we emit it so we can always
438 input_event(kp
.dev
, EV_MSC
, MSC_SCAN
, scancode
);
439 input_report_key(kp
.dev
, kp
.key
, 1);
442 /* schedule key release */
443 kfifo_in_locked(&sony_laptop_input
.fifo
,
444 (unsigned char *)&kp
, sizeof(kp
),
445 &sony_laptop_input
.fifo_lock
);
446 mod_timer(&sony_laptop_input
.release_key_timer
,
447 jiffies
+ msecs_to_jiffies(10));
449 dprintk("unknown input event %.2x\n", event
);
452 static int sony_laptop_setup_input(struct acpi_device
*acpi_device
)
454 struct input_dev
*jog_dev
;
455 struct input_dev
*key_dev
;
459 /* don't run again if already initialized */
460 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
464 spin_lock_init(&sony_laptop_input
.fifo_lock
);
465 error
= kfifo_alloc(&sony_laptop_input
.fifo
,
466 SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
468 pr_err("kfifo_alloc failed\n");
472 setup_timer(&sony_laptop_input
.release_key_timer
,
473 do_sony_laptop_release_key
, 0);
476 key_dev
= input_allocate_device();
482 key_dev
->name
= "Sony Vaio Keys";
483 key_dev
->id
.bustype
= BUS_ISA
;
484 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
485 key_dev
->dev
.parent
= &acpi_device
->dev
;
487 /* Initialize the Input Drivers: special keys */
488 input_set_capability(key_dev
, EV_MSC
, MSC_SCAN
);
490 __set_bit(EV_KEY
, key_dev
->evbit
);
491 key_dev
->keycodesize
= sizeof(sony_laptop_input_keycode_map
[0]);
492 key_dev
->keycodemax
= ARRAY_SIZE(sony_laptop_input_keycode_map
);
493 key_dev
->keycode
= &sony_laptop_input_keycode_map
;
494 for (i
= 0; i
< ARRAY_SIZE(sony_laptop_input_keycode_map
); i
++)
495 __set_bit(sony_laptop_input_keycode_map
[i
], key_dev
->keybit
);
496 __clear_bit(KEY_RESERVED
, key_dev
->keybit
);
498 error
= input_register_device(key_dev
);
500 goto err_free_keydev
;
502 sony_laptop_input
.key_dev
= key_dev
;
505 jog_dev
= input_allocate_device();
508 goto err_unregister_keydev
;
511 jog_dev
->name
= "Sony Vaio Jogdial";
512 jog_dev
->id
.bustype
= BUS_ISA
;
513 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
514 jog_dev
->dev
.parent
= &acpi_device
->dev
;
516 input_set_capability(jog_dev
, EV_KEY
, BTN_MIDDLE
);
517 input_set_capability(jog_dev
, EV_REL
, REL_WHEEL
);
519 error
= input_register_device(jog_dev
);
521 goto err_free_jogdev
;
523 sony_laptop_input
.jog_dev
= jog_dev
;
528 input_free_device(jog_dev
);
530 err_unregister_keydev
:
531 input_unregister_device(key_dev
);
532 /* to avoid kref underflow below at input_free_device */
536 input_free_device(key_dev
);
539 kfifo_free(&sony_laptop_input
.fifo
);
542 atomic_dec(&sony_laptop_input
.users
);
546 static void sony_laptop_remove_input(void)
548 struct sony_laptop_keypress kp
= { NULL
};
550 /* Cleanup only after the last user has gone */
551 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
554 del_timer_sync(&sony_laptop_input
.release_key_timer
);
557 * Generate key-up events for remaining keys. Note that we don't
558 * need locking since nobody is adding new events to the kfifo.
560 while (kfifo_out(&sony_laptop_input
.fifo
,
561 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
562 input_report_key(kp
.dev
, kp
.key
, 0);
566 /* destroy input devs */
567 input_unregister_device(sony_laptop_input
.key_dev
);
568 sony_laptop_input
.key_dev
= NULL
;
570 if (sony_laptop_input
.jog_dev
) {
571 input_unregister_device(sony_laptop_input
.jog_dev
);
572 sony_laptop_input
.jog_dev
= NULL
;
575 kfifo_free(&sony_laptop_input
.fifo
);
578 /*********** Platform Device ***********/
580 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
581 static struct platform_driver sony_pf_driver
= {
583 .name
= "sony-laptop",
586 static struct platform_device
*sony_pf_device
;
588 static int sony_pf_add(void)
592 /* don't run again if already initialized */
593 if (atomic_add_return(1, &sony_pf_users
) > 1)
596 ret
= platform_driver_register(&sony_pf_driver
);
600 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
601 if (!sony_pf_device
) {
603 goto out_platform_registered
;
606 ret
= platform_device_add(sony_pf_device
);
608 goto out_platform_alloced
;
612 out_platform_alloced
:
613 platform_device_put(sony_pf_device
);
614 sony_pf_device
= NULL
;
615 out_platform_registered
:
616 platform_driver_unregister(&sony_pf_driver
);
618 atomic_dec(&sony_pf_users
);
622 static void sony_pf_remove(void)
624 /* deregister only after the last user has gone */
625 if (!atomic_dec_and_test(&sony_pf_users
))
628 platform_device_unregister(sony_pf_device
);
629 platform_driver_unregister(&sony_pf_driver
);
632 /*********** SNC (SNY5001) Device ***********/
634 /* the device uses 1-based values, while the backlight subsystem uses
636 #define SONY_MAX_BRIGHTNESS 8
638 #define SNC_VALIDATE_IN 0
639 #define SNC_VALIDATE_OUT 1
641 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
643 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
644 const char *, size_t);
645 static int boolean_validate(const int, const int);
646 static int brightness_default_validate(const int, const int);
648 struct sony_nc_value
{
649 char *name
; /* name of the entry */
650 char **acpiget
; /* names of the ACPI get function */
651 char **acpiset
; /* names of the ACPI set function */
652 int (*validate
)(const int, const int); /* input/output validation */
653 int value
; /* current setting */
654 int valid
; /* Has ever been set */
655 int debug
; /* active only in debug mode ? */
656 struct device_attribute devattr
; /* sysfs attribute */
659 #define SNC_HANDLE_NAMES(_name, _values...) \
660 static char *snc_##_name[] = { _values, NULL }
662 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
664 .name = __stringify(_name), \
665 .acpiget = _getters, \
666 .acpiset = _setters, \
667 .validate = _validate, \
669 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
672 #define SNC_HANDLE_NULL { .name = NULL }
674 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
676 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
677 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
679 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
680 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
682 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
683 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
685 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
686 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
688 SNC_HANDLE_NAMES(lidstate_get
, "GLID");
690 SNC_HANDLE_NAMES(indicatorlamp_get
, "GILS");
691 SNC_HANDLE_NAMES(indicatorlamp_set
, "SILS");
693 SNC_HANDLE_NAMES(gainbass_get
, "GMGB");
694 SNC_HANDLE_NAMES(gainbass_set
, "CMGB");
696 SNC_HANDLE_NAMES(PID_get
, "GPID");
698 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
699 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
701 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
702 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
704 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
705 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
707 static struct sony_nc_value sony_nc_values
[] = {
708 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
709 snc_brightness_def_set
, brightness_default_validate
, 0),
710 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
711 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
712 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
713 boolean_validate
, 0),
714 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
715 boolean_validate
, 1),
716 SNC_HANDLE(lidstate
, snc_lidstate_get
, NULL
,
717 boolean_validate
, 0),
718 SNC_HANDLE(indicatorlamp
, snc_indicatorlamp_get
, snc_indicatorlamp_set
,
719 boolean_validate
, 0),
720 SNC_HANDLE(gainbass
, snc_gainbass_get
, snc_gainbass_set
,
721 boolean_validate
, 0),
722 /* unknown methods */
723 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
724 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
725 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
726 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
730 static acpi_handle sony_nc_acpi_handle
;
731 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
734 * acpi_evaluate_object wrappers
735 * all useful calls into SNC methods take one or zero parameters and return
736 * integers or arrays.
738 static union acpi_object
*__call_snc_method(acpi_handle handle
, char *method
,
741 union acpi_object
*result
= NULL
;
742 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
746 struct acpi_object_list params
;
747 union acpi_object in
;
748 in
.type
= ACPI_TYPE_INTEGER
;
749 in
.integer
.value
= *value
;
751 params
.pointer
= &in
;
752 status
= acpi_evaluate_object(handle
, method
, ¶ms
, &output
);
753 dprintk("__call_snc_method: [%s:0x%.8x%.8x]\n", method
,
754 (unsigned int)(*value
>> 32),
755 (unsigned int)*value
& 0xffffffff);
757 status
= acpi_evaluate_object(handle
, method
, NULL
, &output
);
758 dprintk("__call_snc_method: [%s]\n", method
);
761 if (ACPI_FAILURE(status
)) {
762 pr_err("Failed to evaluate [%s]\n", method
);
766 result
= (union acpi_object
*) output
.pointer
;
768 dprintk("No return object [%s]\n", method
);
773 static int sony_nc_int_call(acpi_handle handle
, char *name
, int *value
,
776 union acpi_object
*object
= NULL
;
779 object
= __call_snc_method(handle
, name
, &v
);
781 object
= __call_snc_method(handle
, name
, NULL
);
786 if (object
->type
!= ACPI_TYPE_INTEGER
) {
787 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
788 ACPI_TYPE_INTEGER
, object
->type
);
794 *result
= object
->integer
.value
;
800 #define MIN(a, b) (a > b ? b : a)
801 static int sony_nc_buffer_call(acpi_handle handle
, char *name
, u64
*value
,
802 void *buffer
, size_t buflen
)
806 union acpi_object
*object
= __call_snc_method(handle
, name
, value
);
811 if (object
->type
== ACPI_TYPE_BUFFER
) {
812 len
= MIN(buflen
, object
->buffer
.length
);
813 memcpy(buffer
, object
->buffer
.pointer
, len
);
815 } else if (object
->type
== ACPI_TYPE_INTEGER
) {
816 len
= MIN(buflen
, sizeof(object
->integer
.value
));
817 memcpy(buffer
, &object
->integer
.value
, len
);
820 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
821 ACPI_TYPE_BUFFER
, object
->type
);
829 struct sony_nc_handles
{
831 struct device_attribute devattr
;
834 static struct sony_nc_handles
*handles
;
836 static ssize_t
sony_nc_handles_show(struct device
*dev
,
837 struct device_attribute
*attr
, char *buffer
)
842 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
843 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "0x%.4x ",
846 len
+= snprintf(buffer
+ len
, PAGE_SIZE
- len
, "\n");
851 static int sony_nc_handles_setup(struct platform_device
*pd
)
853 int i
, r
, result
, arg
;
855 handles
= kzalloc(sizeof(*handles
), GFP_KERNEL
);
859 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
861 r
= sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
,
864 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
866 handles
->cap
[i
] = result
;
871 sysfs_attr_init(&handles
->devattr
.attr
);
872 handles
->devattr
.attr
.name
= "handles";
873 handles
->devattr
.attr
.mode
= S_IRUGO
;
874 handles
->devattr
.show
= sony_nc_handles_show
;
876 /* allow reading capabilities via sysfs */
877 if (device_create_file(&pd
->dev
, &handles
->devattr
)) {
887 static int sony_nc_handles_cleanup(struct platform_device
*pd
)
891 device_remove_file(&pd
->dev
, &handles
->devattr
);
898 static int sony_find_snc_handle(int handle
)
902 /* not initialized yet, return early */
903 if (!handles
|| !handle
)
906 for (i
= 0; i
< 0x10; i
++) {
907 if (handles
->cap
[i
] == handle
) {
908 dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
913 dprintk("handle 0x%.4x not found\n", handle
);
917 static int sony_call_snc_handle(int handle
, int argument
, int *result
)
920 int offset
= sony_find_snc_handle(handle
);
925 arg
= offset
| argument
;
926 ret
= sony_nc_int_call(sony_nc_acpi_handle
, "SN07", &arg
, result
);
927 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", arg
, *result
);
932 * sony_nc_values input/output validate functions
935 /* brightness_default_validate:
937 * manipulate input output values to keep consistency with the
938 * backlight framework for which brightness values are 0-based.
940 static int brightness_default_validate(const int direction
, const int value
)
943 case SNC_VALIDATE_OUT
:
945 case SNC_VALIDATE_IN
:
946 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
954 * on input validate boolean values 0/1, on output just pass the
957 static int boolean_validate(const int direction
, const int value
)
959 if (direction
== SNC_VALIDATE_IN
) {
960 if (value
!= 0 && value
!= 1)
967 * Sysfs show/store common to all sony_nc_values
969 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
973 struct sony_nc_value
*item
=
974 container_of(attr
, struct sony_nc_value
, devattr
);
979 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiget
, NULL
,
985 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
987 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
990 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
991 struct device_attribute
*attr
,
992 const char *buffer
, size_t count
)
996 struct sony_nc_value
*item
=
997 container_of(attr
, struct sony_nc_value
, devattr
);
1005 if (kstrtoint(buffer
, 10, &value
))
1009 value
= item
->validate(SNC_VALIDATE_IN
, value
);
1014 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
1019 item
->value
= value
;
1028 struct sony_backlight_props
{
1029 struct backlight_device
*dev
;
1035 static struct sony_backlight_props sony_bl_props
;
1037 static int sony_backlight_update_status(struct backlight_device
*bd
)
1039 int arg
= bd
->props
.brightness
+ 1;
1040 return sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &arg
, NULL
);
1043 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
1047 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
, &value
))
1049 /* brightness levels are 1-based, while backlight ones are 0-based */
1053 static int sony_nc_get_brightness_ng(struct backlight_device
*bd
)
1056 struct sony_backlight_props
*sdev
=
1057 (struct sony_backlight_props
*)bl_get_data(bd
);
1059 sony_call_snc_handle(sdev
->handle
, sdev
->cmd_base
+ 0x100, &result
);
1061 return (result
& 0xff) - sdev
->offset
;
1064 static int sony_nc_update_status_ng(struct backlight_device
*bd
)
1067 struct sony_backlight_props
*sdev
=
1068 (struct sony_backlight_props
*)bl_get_data(bd
);
1070 value
= bd
->props
.brightness
+ sdev
->offset
;
1071 if (sony_call_snc_handle(sdev
->handle
, sdev
->cmd_base
| (value
<< 0x10),
1078 static const struct backlight_ops sony_backlight_ops
= {
1079 .options
= BL_CORE_SUSPENDRESUME
,
1080 .update_status
= sony_backlight_update_status
,
1081 .get_brightness
= sony_backlight_get_brightness
,
1083 static const struct backlight_ops sony_backlight_ng_ops
= {
1084 .options
= BL_CORE_SUSPENDRESUME
,
1085 .update_status
= sony_nc_update_status_ng
,
1086 .get_brightness
= sony_nc_get_brightness_ng
,
1090 * New SNC-only Vaios event mapping to driver known keys
1092 struct sony_nc_event
{
1097 static struct sony_nc_event sony_100_events
[] = {
1098 { 0x90, SONYPI_EVENT_PKEY_P1
},
1099 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1100 { 0x91, SONYPI_EVENT_PKEY_P2
},
1101 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1102 { 0x81, SONYPI_EVENT_FNKEY_F1
},
1103 { 0x01, SONYPI_EVENT_FNKEY_RELEASED
},
1104 { 0x82, SONYPI_EVENT_FNKEY_F2
},
1105 { 0x02, SONYPI_EVENT_FNKEY_RELEASED
},
1106 { 0x83, SONYPI_EVENT_FNKEY_F3
},
1107 { 0x03, SONYPI_EVENT_FNKEY_RELEASED
},
1108 { 0x84, SONYPI_EVENT_FNKEY_F4
},
1109 { 0x04, SONYPI_EVENT_FNKEY_RELEASED
},
1110 { 0x85, SONYPI_EVENT_FNKEY_F5
},
1111 { 0x05, SONYPI_EVENT_FNKEY_RELEASED
},
1112 { 0x86, SONYPI_EVENT_FNKEY_F6
},
1113 { 0x06, SONYPI_EVENT_FNKEY_RELEASED
},
1114 { 0x87, SONYPI_EVENT_FNKEY_F7
},
1115 { 0x07, SONYPI_EVENT_FNKEY_RELEASED
},
1116 { 0x88, SONYPI_EVENT_FNKEY_F8
},
1117 { 0x08, SONYPI_EVENT_FNKEY_RELEASED
},
1118 { 0x89, SONYPI_EVENT_FNKEY_F9
},
1119 { 0x09, SONYPI_EVENT_FNKEY_RELEASED
},
1120 { 0x8A, SONYPI_EVENT_FNKEY_F10
},
1121 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED
},
1122 { 0x8B, SONYPI_EVENT_FNKEY_F11
},
1123 { 0x0B, SONYPI_EVENT_FNKEY_RELEASED
},
1124 { 0x8C, SONYPI_EVENT_FNKEY_F12
},
1125 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED
},
1126 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED
},
1127 { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1128 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED
},
1129 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1130 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED
},
1131 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1132 { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED
},
1133 { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1134 { 0xa5, SONYPI_EVENT_VENDOR_PRESSED
},
1135 { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1136 { 0xa6, SONYPI_EVENT_HELP_PRESSED
},
1137 { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1138 { 0xa8, SONYPI_EVENT_FNKEY_1
},
1139 { 0x28, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1143 static struct sony_nc_event sony_127_events
[] = {
1144 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED
},
1145 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1146 { 0x82, SONYPI_EVENT_PKEY_P1
},
1147 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1148 { 0x83, SONYPI_EVENT_PKEY_P2
},
1149 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1150 { 0x84, SONYPI_EVENT_PKEY_P3
},
1151 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1152 { 0x85, SONYPI_EVENT_PKEY_P4
},
1153 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1154 { 0x86, SONYPI_EVENT_PKEY_P5
},
1155 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1156 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED
},
1157 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1161 static int sony_nc_hotkeys_decode(u32 event
, unsigned int handle
)
1164 unsigned int result
= 0;
1165 struct sony_nc_event
*key_event
;
1167 if (sony_call_snc_handle(handle
, 0x200, &result
)) {
1168 dprintk("Unable to decode event 0x%.2x 0x%.2x\n", handle
,
1175 if (handle
== 0x0100)
1176 key_event
= sony_100_events
;
1178 key_event
= sony_127_events
;
1180 for (; key_event
->data
; key_event
++) {
1181 if (key_event
->data
== result
) {
1182 ret
= key_event
->event
;
1187 if (!key_event
->data
)
1188 pr_info("Unknown hotkey 0x%.2x/0x%.2x (handle 0x%.2x)\n",
1189 event
, result
, handle
);
1202 static void sony_nc_notify(struct acpi_device
*device
, u32 event
)
1204 u32 real_ev
= event
;
1206 dprintk("sony_nc_notify, event: 0x%.2x\n", event
);
1208 if (event
>= 0x90) {
1209 unsigned int result
= 0;
1210 unsigned int arg
= 0;
1211 unsigned int handle
= 0;
1212 unsigned int offset
= event
- 0x90;
1214 if (offset
>= ARRAY_SIZE(handles
->cap
)) {
1215 pr_err("Event 0x%x outside of capabilities list\n",
1219 handle
= handles
->cap
[offset
];
1221 /* list of handles known for generating events */
1227 real_ev
= sony_nc_hotkeys_decode(event
, handle
);
1230 sony_laptop_report_input_event(real_ev
);
1232 /* restore the original event for reporting */
1240 /* events on this handle are reported when the
1241 * switch changes position or for battery
1242 * events. We'll notify both of them but only
1243 * update the rfkill device status when the
1246 ev_type
= KILLSWITCH
;
1247 sony_call_snc_handle(handle
, 0x0100, &result
);
1248 real_ev
= result
& 0x03;
1250 /* hw switch event */
1252 sony_nc_rfkill_update();
1258 /* Hybrid GFX switching */
1259 sony_call_snc_handle(handle
, 0x0000, &result
);
1260 dprintk("GFX switch event received (reason: %s)\n",
1261 (result
== 0x1) ? "switch change" :
1262 (result
== 0x2) ? "output switch" :
1263 (result
== 0x3) ? "output switch" :
1266 ev_type
= GFX_SWITCH
;
1267 real_ev
= __sony_nc_gfx_switch_status_get();
1271 /* Hybrid GFX switching SVS151290S */
1272 ev_type
= GFX_SWITCH
;
1273 real_ev
= __sony_nc_gfx_switch_status_get();
1276 dprintk("Unknown event 0x%x for handle 0x%x\n",
1281 /* clear the event (and the event reason when present) */
1283 sony_nc_int_call(sony_nc_acpi_handle
, "SN05", &arg
, &result
);
1286 /* old style event */
1288 sony_laptop_report_input_event(real_ev
);
1290 acpi_bus_generate_netlink_event(sony_nc_acpi_device
->pnp
.device_class
,
1291 dev_name(&sony_nc_acpi_device
->dev
), ev_type
, real_ev
);
1294 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
1295 void *context
, void **return_value
)
1297 struct acpi_device_info
*info
;
1299 if (ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
1300 pr_warn("method: name: %4.4s, args %X\n",
1301 (char *)&info
->name
, info
->param_count
);
1312 static void sony_nc_function_setup(struct acpi_device
*device
,
1313 struct platform_device
*pf_device
)
1315 unsigned int i
, result
, bitmask
, arg
;
1320 /* setup found handles here */
1321 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1322 unsigned int handle
= handles
->cap
[i
];
1327 dprintk("setting up handle 0x%.4x\n", handle
);
1334 sony_call_snc_handle(handle
, 0, &result
);
1338 sony_call_snc_handle(handle
, 0x100, &result
);
1342 /* touchpad enable/disable */
1343 result
= sony_nc_touchpad_setup(pf_device
, handle
);
1345 pr_err("couldn't set up touchpad control function (%d)\n",
1351 result
= sony_nc_battery_care_setup(pf_device
, handle
);
1353 pr_err("couldn't set up battery care function (%d)\n",
1358 result
= sony_nc_lid_resume_setup(pf_device
, handle
);
1360 pr_err("couldn't set up lid resume function (%d)\n",
1364 result
= sony_nc_thermal_setup(pf_device
);
1366 pr_err("couldn't set up thermal profile function (%d)\n",
1372 result
= sony_nc_gfx_switch_setup(pf_device
, handle
);
1374 pr_err("couldn't set up GFX Switch status (%d)\n",
1378 result
= sony_nc_highspeed_charging_setup(pf_device
);
1380 pr_err("couldn't set up high speed charging function (%d)\n",
1385 result
= sony_nc_rfkill_setup(device
, handle
);
1387 pr_err("couldn't set up rfkill support (%d)\n",
1395 result
= sony_nc_kbd_backlight_setup(pf_device
, handle
);
1397 pr_err("couldn't set up keyboard backlight function (%d)\n",
1401 result
= sony_nc_lowbatt_setup(pf_device
);
1403 pr_err("couldn't set up low battery function (%d)\n",
1407 result
= sony_nc_fanspeed_setup(pf_device
);
1409 pr_err("couldn't set up fan speed function (%d)\n",
1413 result
= sony_nc_usb_charge_setup(pf_device
);
1415 pr_err("couldn't set up USB charge support (%d)\n",
1419 result
= sony_nc_panelid_setup(pf_device
);
1421 pr_err("couldn't set up panel ID function (%d)\n",
1425 result
= sony_nc_smart_conn_setup(pf_device
);
1427 pr_err("couldn't set up smart connect support (%d)\n",
1435 /* Enable all events */
1437 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1438 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1442 static void sony_nc_function_cleanup(struct platform_device
*pd
)
1444 unsigned int i
, result
, bitmask
, handle
;
1446 /* get enabled events and disable them */
1447 sony_nc_int_call(sony_nc_acpi_handle
, "SN01", NULL
, &bitmask
);
1448 sony_nc_int_call(sony_nc_acpi_handle
, "SN03", &bitmask
, &result
);
1450 /* cleanup handles here */
1451 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1453 handle
= handles
->cap
[i
];
1461 sony_nc_touchpad_cleanup(pd
);
1466 sony_nc_battery_care_cleanup(pd
);
1470 sony_nc_lid_resume_cleanup(pd
);
1473 sony_nc_thermal_cleanup(pd
);
1478 sony_nc_gfx_switch_cleanup(pd
);
1481 sony_nc_highspeed_charging_cleanup(pd
);
1485 sony_nc_rfkill_cleanup();
1492 sony_nc_kbd_backlight_cleanup(pd
, handle
);
1495 sony_nc_lowbatt_cleanup(pd
);
1498 sony_nc_fanspeed_cleanup(pd
);
1501 sony_nc_usb_charge_cleanup(pd
);
1504 sony_nc_panelid_cleanup(pd
);
1507 sony_nc_smart_conn_cleanup(pd
);
1514 /* finally cleanup the handles list */
1515 sony_nc_handles_cleanup(pd
);
1518 #ifdef CONFIG_PM_SLEEP
1519 static void sony_nc_function_resume(void)
1521 unsigned int i
, result
, bitmask
, arg
;
1523 dprintk("Resuming SNC device\n");
1525 for (i
= 0; i
< ARRAY_SIZE(handles
->cap
); i
++) {
1526 unsigned int handle
= handles
->cap
[i
];
1535 /* re-enable hotkeys */
1536 sony_call_snc_handle(handle
, 0, &result
);
1539 /* re-enable hotkeys */
1540 sony_call_snc_handle(handle
, 0x100, &result
);
1543 sony_nc_thermal_resume();
1547 sony_nc_rfkill_update();
1554 /* Enable all events */
1556 if (!sony_nc_int_call(sony_nc_acpi_handle
, "SN00", &arg
, &bitmask
))
1557 sony_nc_int_call(sony_nc_acpi_handle
, "SN02", &bitmask
,
1561 static int sony_nc_resume(struct device
*dev
)
1563 struct sony_nc_value
*item
;
1565 for (item
= sony_nc_values
; item
->name
; item
++) {
1570 ret
= sony_nc_int_call(sony_nc_acpi_handle
, *item
->acpiset
,
1571 &item
->value
, NULL
);
1573 pr_err("%s: %d\n", __func__
, ret
);
1578 if (acpi_has_method(sony_nc_acpi_handle
, "ECON")) {
1580 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
1581 dprintk("ECON Method failed\n");
1584 if (acpi_has_method(sony_nc_acpi_handle
, "SN00"))
1585 sony_nc_function_resume();
1591 static SIMPLE_DEV_PM_OPS(sony_nc_pm
, NULL
, sony_nc_resume
);
1593 static void sony_nc_rfkill_cleanup(void)
1597 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1598 if (sony_rfkill_devices
[i
]) {
1599 rfkill_unregister(sony_rfkill_devices
[i
]);
1600 rfkill_destroy(sony_rfkill_devices
[i
]);
1605 static int sony_nc_rfkill_set(void *data
, bool blocked
)
1608 int argument
= sony_rfkill_address
[(long) data
] + 0x100;
1611 argument
|= 0x070000;
1613 return sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1616 static const struct rfkill_ops sony_rfkill_ops
= {
1617 .set_block
= sony_nc_rfkill_set
,
1620 static int sony_nc_setup_rfkill(struct acpi_device
*device
,
1621 enum sony_nc_rfkill nc_type
)
1625 enum rfkill_type type
;
1628 bool hwblock
, swblock
;
1632 type
= RFKILL_TYPE_WLAN
;
1635 case SONY_BLUETOOTH
:
1636 type
= RFKILL_TYPE_BLUETOOTH
;
1637 name
= "sony-bluetooth";
1640 type
= RFKILL_TYPE_WWAN
;
1644 type
= RFKILL_TYPE_WIMAX
;
1645 name
= "sony-wimax";
1651 rfk
= rfkill_alloc(name
, &device
->dev
, type
,
1652 &sony_rfkill_ops
, (void *)nc_type
);
1656 if (sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
) < 0) {
1657 rfkill_destroy(rfk
);
1660 hwblock
= !(result
& 0x1);
1662 if (sony_call_snc_handle(sony_rfkill_handle
,
1663 sony_rfkill_address
[nc_type
],
1665 rfkill_destroy(rfk
);
1668 swblock
= !(result
& 0x2);
1670 rfkill_init_sw_state(rfk
, swblock
);
1671 rfkill_set_hw_state(rfk
, hwblock
);
1673 err
= rfkill_register(rfk
);
1675 rfkill_destroy(rfk
);
1678 sony_rfkill_devices
[nc_type
] = rfk
;
1682 static void sony_nc_rfkill_update(void)
1684 enum sony_nc_rfkill i
;
1688 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1689 hwblock
= !(result
& 0x1);
1691 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1692 int argument
= sony_rfkill_address
[i
];
1694 if (!sony_rfkill_devices
[i
])
1698 if (rfkill_set_hw_state(sony_rfkill_devices
[i
], true)) {
1699 /* we already know we're blocked */
1704 sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1705 rfkill_set_states(sony_rfkill_devices
[i
],
1706 !(result
& 0x2), false);
1710 static int sony_nc_rfkill_setup(struct acpi_device
*device
,
1711 unsigned int handle
)
1715 unsigned char buffer
[32] = { 0 };
1717 offset
= sony_find_snc_handle(handle
);
1718 sony_rfkill_handle
= handle
;
1720 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
1725 /* The buffer is filled with magic numbers describing the devices
1726 * available, 0xff terminates the enumeration.
1730 * 0x20 WWAN GPRS-EDGE
1734 * 0x25 Gobi WWAN no GPS
1735 * 0x26 Gobi WWAN + GPS
1736 * 0x28 Gobi WWAN no GPS
1737 * 0x29 Gobi WWAN + GPS
1739 * 0x50 Gobi WWAN no GPS
1740 * 0x51 Gobi WWAN + GPS
1741 * 0x70 no SIM card slot
1742 * 0x71 SIM card slot
1744 for (i
= 0; i
< ARRAY_SIZE(buffer
); i
++) {
1746 if (buffer
[i
] == 0xff)
1749 dprintk("Radio devices, found 0x%.2x\n", buffer
[i
]);
1751 if (buffer
[i
] == 0 && !sony_rfkill_devices
[SONY_WIFI
])
1752 sony_nc_setup_rfkill(device
, SONY_WIFI
);
1754 if (buffer
[i
] == 0x10 && !sony_rfkill_devices
[SONY_BLUETOOTH
])
1755 sony_nc_setup_rfkill(device
, SONY_BLUETOOTH
);
1757 if (((0xf0 & buffer
[i
]) == 0x20 ||
1758 (0xf0 & buffer
[i
]) == 0x50) &&
1759 !sony_rfkill_devices
[SONY_WWAN
])
1760 sony_nc_setup_rfkill(device
, SONY_WWAN
);
1762 if (buffer
[i
] == 0x30 && !sony_rfkill_devices
[SONY_WIMAX
])
1763 sony_nc_setup_rfkill(device
, SONY_WIMAX
);
1768 /* Keyboard backlight feature */
1769 struct kbd_backlight
{
1770 unsigned int handle
;
1773 unsigned int timeout
;
1774 struct device_attribute mode_attr
;
1775 struct device_attribute timeout_attr
;
1778 static struct kbd_backlight
*kbdbl_ctl
;
1780 static ssize_t
__sony_nc_kbd_backlight_mode_set(u8 value
)
1787 if (sony_call_snc_handle(kbdbl_ctl
->handle
,
1788 (value
<< 0x10) | (kbdbl_ctl
->base
), &result
))
1791 /* Try to turn the light on/off immediately */
1793 sony_call_snc_handle(kbdbl_ctl
->handle
,
1794 (value
<< 0x0f) | (kbdbl_ctl
->base
+ 0x100),
1797 kbdbl_ctl
->mode
= value
;
1802 static ssize_t
sony_nc_kbd_backlight_mode_store(struct device
*dev
,
1803 struct device_attribute
*attr
,
1804 const char *buffer
, size_t count
)
1807 unsigned long value
;
1812 if (kstrtoul(buffer
, 10, &value
))
1815 ret
= __sony_nc_kbd_backlight_mode_set(value
);
1822 static ssize_t
sony_nc_kbd_backlight_mode_show(struct device
*dev
,
1823 struct device_attribute
*attr
, char *buffer
)
1826 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_ctl
->mode
);
1830 static int __sony_nc_kbd_backlight_timeout_set(u8 value
)
1837 if (sony_call_snc_handle(kbdbl_ctl
->handle
, (value
<< 0x10) |
1838 (kbdbl_ctl
->base
+ 0x200), &result
))
1841 kbdbl_ctl
->timeout
= value
;
1846 static ssize_t
sony_nc_kbd_backlight_timeout_store(struct device
*dev
,
1847 struct device_attribute
*attr
,
1848 const char *buffer
, size_t count
)
1851 unsigned long value
;
1856 if (kstrtoul(buffer
, 10, &value
))
1859 ret
= __sony_nc_kbd_backlight_timeout_set(value
);
1866 static ssize_t
sony_nc_kbd_backlight_timeout_show(struct device
*dev
,
1867 struct device_attribute
*attr
, char *buffer
)
1870 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", kbdbl_ctl
->timeout
);
1874 static int sony_nc_kbd_backlight_setup(struct platform_device
*pd
,
1875 unsigned int handle
)
1881 pr_warn("handle 0x%.4x: keyboard backlight setup already done for 0x%.4x\n",
1882 handle
, kbdbl_ctl
->handle
);
1886 /* verify the kbd backlight presence, these handles are not used for
1887 * keyboard backlight only
1889 ret
= sony_call_snc_handle(handle
, handle
== 0x0137 ? 0x0B00 : 0x0100,
1894 if ((handle
== 0x0137 && !(result
& 0x02)) ||
1896 dprintk("no backlight keyboard found\n");
1900 kbdbl_ctl
= kzalloc(sizeof(*kbdbl_ctl
), GFP_KERNEL
);
1904 kbdbl_ctl
->mode
= kbd_backlight
;
1905 kbdbl_ctl
->timeout
= kbd_backlight_timeout
;
1906 kbdbl_ctl
->handle
= handle
;
1907 if (handle
== 0x0137)
1908 kbdbl_ctl
->base
= 0x0C00;
1910 kbdbl_ctl
->base
= 0x4000;
1912 sysfs_attr_init(&kbdbl_ctl
->mode_attr
.attr
);
1913 kbdbl_ctl
->mode_attr
.attr
.name
= "kbd_backlight";
1914 kbdbl_ctl
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1915 kbdbl_ctl
->mode_attr
.show
= sony_nc_kbd_backlight_mode_show
;
1916 kbdbl_ctl
->mode_attr
.store
= sony_nc_kbd_backlight_mode_store
;
1918 sysfs_attr_init(&kbdbl_ctl
->timeout_attr
.attr
);
1919 kbdbl_ctl
->timeout_attr
.attr
.name
= "kbd_backlight_timeout";
1920 kbdbl_ctl
->timeout_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
1921 kbdbl_ctl
->timeout_attr
.show
= sony_nc_kbd_backlight_timeout_show
;
1922 kbdbl_ctl
->timeout_attr
.store
= sony_nc_kbd_backlight_timeout_store
;
1924 ret
= device_create_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1928 ret
= device_create_file(&pd
->dev
, &kbdbl_ctl
->timeout_attr
);
1932 __sony_nc_kbd_backlight_mode_set(kbdbl_ctl
->mode
);
1933 __sony_nc_kbd_backlight_timeout_set(kbdbl_ctl
->timeout
);
1938 device_remove_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1945 static void sony_nc_kbd_backlight_cleanup(struct platform_device
*pd
,
1946 unsigned int handle
)
1948 if (kbdbl_ctl
&& handle
== kbdbl_ctl
->handle
) {
1949 device_remove_file(&pd
->dev
, &kbdbl_ctl
->mode_attr
);
1950 device_remove_file(&pd
->dev
, &kbdbl_ctl
->timeout_attr
);
1956 struct battery_care_control
{
1957 struct device_attribute attrs
[2];
1958 unsigned int handle
;
1960 static struct battery_care_control
*bcare_ctl
;
1962 static ssize_t
sony_nc_battery_care_limit_store(struct device
*dev
,
1963 struct device_attribute
*attr
,
1964 const char *buffer
, size_t count
)
1966 unsigned int result
, cmd
;
1967 unsigned long value
;
1972 if (kstrtoul(buffer
, 10, &value
))
1975 /* limit values (2 bits):
1981 * bit 0: 0 disable BCL, 1 enable BCL
1982 * bit 1: 1 tell to store the battery limit (see bits 6,7) too
1983 * bits 2,3: reserved
1984 * bits 4,5: store the limit into the EC
1985 * bits 6,7: store the limit into the battery
1993 else if (value
<= 80)
1996 else if (value
<= 100)
2003 * handle 0x0115 should allow storing on battery too;
2004 * handle 0x0136 same as 0x0115 + health status;
2005 * handle 0x013f, same as 0x0136 but no storing on the battery
2007 if (bcare_ctl
->handle
!= 0x013f)
2008 cmd
= cmd
| (cmd
<< 2);
2010 cmd
= (cmd
| 0x1) << 0x10;
2013 if (sony_call_snc_handle(bcare_ctl
->handle
, cmd
| 0x0100, &result
))
2019 static ssize_t
sony_nc_battery_care_limit_show(struct device
*dev
,
2020 struct device_attribute
*attr
, char *buffer
)
2022 unsigned int result
, status
;
2024 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0000, &result
))
2027 status
= (result
& 0x01) ? ((result
& 0x30) >> 0x04) : 0;
2043 return snprintf(buffer
, PAGE_SIZE
, "%d\n", status
);
2046 static ssize_t
sony_nc_battery_care_health_show(struct device
*dev
,
2047 struct device_attribute
*attr
, char *buffer
)
2050 unsigned int health
;
2052 if (sony_call_snc_handle(bcare_ctl
->handle
, 0x0200, &health
))
2055 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", health
& 0xff);
2060 static int sony_nc_battery_care_setup(struct platform_device
*pd
,
2061 unsigned int handle
)
2065 bcare_ctl
= kzalloc(sizeof(struct battery_care_control
), GFP_KERNEL
);
2069 bcare_ctl
->handle
= handle
;
2071 sysfs_attr_init(&bcare_ctl
->attrs
[0].attr
);
2072 bcare_ctl
->attrs
[0].attr
.name
= "battery_care_limiter";
2073 bcare_ctl
->attrs
[0].attr
.mode
= S_IRUGO
| S_IWUSR
;
2074 bcare_ctl
->attrs
[0].show
= sony_nc_battery_care_limit_show
;
2075 bcare_ctl
->attrs
[0].store
= sony_nc_battery_care_limit_store
;
2077 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2081 /* 0x0115 is for models with no health reporting capability */
2082 if (handle
== 0x0115)
2085 sysfs_attr_init(&bcare_ctl
->attrs
[1].attr
);
2086 bcare_ctl
->attrs
[1].attr
.name
= "battery_care_health";
2087 bcare_ctl
->attrs
[1].attr
.mode
= S_IRUGO
;
2088 bcare_ctl
->attrs
[1].show
= sony_nc_battery_care_health_show
;
2090 ret
= device_create_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
2097 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2106 static void sony_nc_battery_care_cleanup(struct platform_device
*pd
)
2109 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[0]);
2110 if (bcare_ctl
->handle
!= 0x0115)
2111 device_remove_file(&pd
->dev
, &bcare_ctl
->attrs
[1]);
2118 struct snc_thermal_ctrl
{
2120 unsigned int profiles
;
2121 struct device_attribute mode_attr
;
2122 struct device_attribute profiles_attr
;
2124 static struct snc_thermal_ctrl
*th_handle
;
2126 #define THM_PROFILE_MAX 3
2127 static const char * const snc_thermal_profiles
[] = {
2133 static int sony_nc_thermal_mode_set(unsigned short mode
)
2135 unsigned int result
;
2137 /* the thermal profile seems to be a two bit bitmask:
2139 * msb -> performance
2140 * no bit set is the normal operation and is always valid
2141 * Some vaio models only have "balanced" and "performance"
2143 if ((mode
&& !(th_handle
->profiles
& mode
)) || mode
>= THM_PROFILE_MAX
)
2146 if (sony_call_snc_handle(0x0122, mode
<< 0x10 | 0x0200, &result
))
2149 th_handle
->mode
= mode
;
2154 static int sony_nc_thermal_mode_get(void)
2156 unsigned int result
;
2158 if (sony_call_snc_handle(0x0122, 0x0100, &result
))
2161 return result
& 0xff;
2164 static ssize_t
sony_nc_thermal_profiles_show(struct device
*dev
,
2165 struct device_attribute
*attr
, char *buffer
)
2170 for (cnt
= 0; cnt
< THM_PROFILE_MAX
; cnt
++) {
2171 if (!cnt
|| (th_handle
->profiles
& cnt
))
2172 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "%s ",
2173 snc_thermal_profiles
[cnt
]);
2175 idx
+= snprintf(buffer
+ idx
, PAGE_SIZE
- idx
, "\n");
2180 static ssize_t
sony_nc_thermal_mode_store(struct device
*dev
,
2181 struct device_attribute
*attr
,
2182 const char *buffer
, size_t count
)
2190 /* skip the newline if present */
2191 if (buffer
[len
- 1] == '\n')
2194 for (cmd
= 0; cmd
< THM_PROFILE_MAX
; cmd
++)
2195 if (strncmp(buffer
, snc_thermal_profiles
[cmd
], len
) == 0)
2198 if (sony_nc_thermal_mode_set(cmd
))
2204 static ssize_t
sony_nc_thermal_mode_show(struct device
*dev
,
2205 struct device_attribute
*attr
, char *buffer
)
2208 int mode
= sony_nc_thermal_mode_get();
2213 count
= snprintf(buffer
, PAGE_SIZE
, "%s\n", snc_thermal_profiles
[mode
]);
2218 static int sony_nc_thermal_setup(struct platform_device
*pd
)
2221 th_handle
= kzalloc(sizeof(struct snc_thermal_ctrl
), GFP_KERNEL
);
2225 ret
= sony_call_snc_handle(0x0122, 0x0000, &th_handle
->profiles
);
2227 pr_warn("couldn't to read the thermal profiles\n");
2231 ret
= sony_nc_thermal_mode_get();
2233 pr_warn("couldn't to read the current thermal profile");
2236 th_handle
->mode
= ret
;
2238 sysfs_attr_init(&th_handle
->profiles_attr
.attr
);
2239 th_handle
->profiles_attr
.attr
.name
= "thermal_profiles";
2240 th_handle
->profiles_attr
.attr
.mode
= S_IRUGO
;
2241 th_handle
->profiles_attr
.show
= sony_nc_thermal_profiles_show
;
2243 sysfs_attr_init(&th_handle
->mode_attr
.attr
);
2244 th_handle
->mode_attr
.attr
.name
= "thermal_control";
2245 th_handle
->mode_attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
2246 th_handle
->mode_attr
.show
= sony_nc_thermal_mode_show
;
2247 th_handle
->mode_attr
.store
= sony_nc_thermal_mode_store
;
2249 ret
= device_create_file(&pd
->dev
, &th_handle
->profiles_attr
);
2253 ret
= device_create_file(&pd
->dev
, &th_handle
->mode_attr
);
2260 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2267 static void sony_nc_thermal_cleanup(struct platform_device
*pd
)
2270 device_remove_file(&pd
->dev
, &th_handle
->profiles_attr
);
2271 device_remove_file(&pd
->dev
, &th_handle
->mode_attr
);
2277 #ifdef CONFIG_PM_SLEEP
2278 static void sony_nc_thermal_resume(void)
2280 unsigned int status
= sony_nc_thermal_mode_get();
2282 if (status
!= th_handle
->mode
)
2283 sony_nc_thermal_mode_set(th_handle
->mode
);
2287 /* resume on LID open */
2288 #define LID_RESUME_S5 0
2289 #define LID_RESUME_S4 1
2290 #define LID_RESUME_S3 2
2291 #define LID_RESUME_MAX 3
2292 struct snc_lid_resume_control
{
2293 struct device_attribute attrs
[LID_RESUME_MAX
];
2294 unsigned int status
;
2297 static struct snc_lid_resume_control
*lid_ctl
;
2299 static ssize_t
sony_nc_lid_resume_store(struct device
*dev
,
2300 struct device_attribute
*attr
,
2301 const char *buffer
, size_t count
)
2303 unsigned int result
;
2304 unsigned long value
;
2305 unsigned int pos
= LID_RESUME_S5
;
2309 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2312 /* the value we have to write to SNC is a bitmask:
2318 while (pos
< LID_RESUME_MAX
) {
2319 if (&lid_ctl
->attrs
[pos
].attr
== &attr
->attr
)
2323 if (pos
== LID_RESUME_MAX
)
2327 value
= lid_ctl
->status
| (1 << pos
);
2329 value
= lid_ctl
->status
& ~(1 << pos
);
2331 if (sony_call_snc_handle(lid_ctl
->handle
, value
<< 0x10 | 0x0100,
2335 lid_ctl
->status
= value
;
2340 static ssize_t
sony_nc_lid_resume_show(struct device
*dev
,
2341 struct device_attribute
*attr
,
2344 unsigned int pos
= LID_RESUME_S5
;
2346 while (pos
< LID_RESUME_MAX
) {
2347 if (&lid_ctl
->attrs
[pos
].attr
== &attr
->attr
)
2348 return snprintf(buffer
, PAGE_SIZE
, "%d\n",
2349 (lid_ctl
->status
>> pos
) & 0x01);
2355 static int sony_nc_lid_resume_setup(struct platform_device
*pd
,
2356 unsigned int handle
)
2358 unsigned int result
;
2361 if (sony_call_snc_handle(handle
, 0x0000, &result
))
2364 lid_ctl
= kzalloc(sizeof(struct snc_lid_resume_control
), GFP_KERNEL
);
2368 lid_ctl
->status
= result
& 0x7;
2369 lid_ctl
->handle
= handle
;
2371 sysfs_attr_init(&lid_ctl
->attrs
[0].attr
);
2372 lid_ctl
->attrs
[LID_RESUME_S5
].attr
.name
= "lid_resume_S5";
2373 lid_ctl
->attrs
[LID_RESUME_S5
].attr
.mode
= S_IRUGO
| S_IWUSR
;
2374 lid_ctl
->attrs
[LID_RESUME_S5
].show
= sony_nc_lid_resume_show
;
2375 lid_ctl
->attrs
[LID_RESUME_S5
].store
= sony_nc_lid_resume_store
;
2377 if (handle
== 0x0119) {
2378 sysfs_attr_init(&lid_ctl
->attrs
[1].attr
);
2379 lid_ctl
->attrs
[LID_RESUME_S4
].attr
.name
= "lid_resume_S4";
2380 lid_ctl
->attrs
[LID_RESUME_S4
].attr
.mode
= S_IRUGO
| S_IWUSR
;
2381 lid_ctl
->attrs
[LID_RESUME_S4
].show
= sony_nc_lid_resume_show
;
2382 lid_ctl
->attrs
[LID_RESUME_S4
].store
= sony_nc_lid_resume_store
;
2384 sysfs_attr_init(&lid_ctl
->attrs
[2].attr
);
2385 lid_ctl
->attrs
[LID_RESUME_S3
].attr
.name
= "lid_resume_S3";
2386 lid_ctl
->attrs
[LID_RESUME_S3
].attr
.mode
= S_IRUGO
| S_IWUSR
;
2387 lid_ctl
->attrs
[LID_RESUME_S3
].show
= sony_nc_lid_resume_show
;
2388 lid_ctl
->attrs
[LID_RESUME_S3
].store
= sony_nc_lid_resume_store
;
2390 for (i
= 0; i
< LID_RESUME_MAX
&&
2391 lid_ctl
->attrs
[i
].attr
.name
; i
++) {
2392 result
= device_create_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2400 for (i
--; i
>= 0; i
--)
2401 device_remove_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2409 static void sony_nc_lid_resume_cleanup(struct platform_device
*pd
)
2414 for (i
= 0; i
< LID_RESUME_MAX
; i
++) {
2415 if (!lid_ctl
->attrs
[i
].attr
.name
)
2418 device_remove_file(&pd
->dev
, &lid_ctl
->attrs
[i
]);
2426 /* GFX Switch position */
2432 struct snc_gfx_switch_control
{
2433 struct device_attribute attr
;
2434 unsigned int handle
;
2436 static struct snc_gfx_switch_control
*gfxs_ctl
;
2438 /* returns 0 for speed, 1 for stamina */
2439 static int __sony_nc_gfx_switch_status_get(void)
2441 unsigned int result
;
2443 if (sony_call_snc_handle(gfxs_ctl
->handle
,
2444 gfxs_ctl
->handle
== 0x015B ? 0x0000 : 0x0100,
2448 switch (gfxs_ctl
->handle
) {
2450 /* 1: discrete GFX (speed)
2451 * 0: integrated GFX (stamina)
2453 return result
& 0x1 ? SPEED
: STAMINA
;
2456 /* 0: discrete GFX (speed)
2457 * 1: integrated GFX (stamina)
2459 return result
& 0x1 ? STAMINA
: SPEED
;
2462 /* it's a more elaborated bitmask, for now:
2463 * 2: integrated GFX (stamina)
2464 * 0: discrete GFX (speed)
2466 dprintk("GFX Status: 0x%x\n", result
);
2467 return result
& 0x80 ? AUTO
:
2468 result
& 0x02 ? STAMINA
: SPEED
;
2474 static ssize_t
sony_nc_gfx_switch_status_show(struct device
*dev
,
2475 struct device_attribute
*attr
,
2478 int pos
= __sony_nc_gfx_switch_status_get();
2483 return snprintf(buffer
, PAGE_SIZE
, "%s\n",
2484 pos
== SPEED
? "speed" :
2485 pos
== STAMINA
? "stamina" :
2486 pos
== AUTO
? "auto" : "unknown");
2489 static int sony_nc_gfx_switch_setup(struct platform_device
*pd
,
2490 unsigned int handle
)
2492 unsigned int result
;
2494 gfxs_ctl
= kzalloc(sizeof(struct snc_gfx_switch_control
), GFP_KERNEL
);
2498 gfxs_ctl
->handle
= handle
;
2500 sysfs_attr_init(&gfxs_ctl
->attr
.attr
);
2501 gfxs_ctl
->attr
.attr
.name
= "gfx_switch_status";
2502 gfxs_ctl
->attr
.attr
.mode
= S_IRUGO
;
2503 gfxs_ctl
->attr
.show
= sony_nc_gfx_switch_status_show
;
2505 result
= device_create_file(&pd
->dev
, &gfxs_ctl
->attr
);
2518 static void sony_nc_gfx_switch_cleanup(struct platform_device
*pd
)
2521 device_remove_file(&pd
->dev
, &gfxs_ctl
->attr
);
2528 /* High speed charging function */
2529 static struct device_attribute
*hsc_handle
;
2531 static ssize_t
sony_nc_highspeed_charging_store(struct device
*dev
,
2532 struct device_attribute
*attr
,
2533 const char *buffer
, size_t count
)
2535 unsigned int result
;
2536 unsigned long value
;
2541 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2544 if (sony_call_snc_handle(0x0131, value
<< 0x10 | 0x0200, &result
))
2550 static ssize_t
sony_nc_highspeed_charging_show(struct device
*dev
,
2551 struct device_attribute
*attr
, char *buffer
)
2553 unsigned int result
;
2555 if (sony_call_snc_handle(0x0131, 0x0100, &result
))
2558 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 0x01);
2561 static int sony_nc_highspeed_charging_setup(struct platform_device
*pd
)
2563 unsigned int result
;
2565 if (sony_call_snc_handle(0x0131, 0x0000, &result
) || !(result
& 0x01)) {
2566 /* some models advertise the handle but have no implementation
2569 pr_info("No High Speed Charging capability found\n");
2573 hsc_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2577 sysfs_attr_init(&hsc_handle
->attr
);
2578 hsc_handle
->attr
.name
= "battery_highspeed_charging";
2579 hsc_handle
->attr
.mode
= S_IRUGO
| S_IWUSR
;
2580 hsc_handle
->show
= sony_nc_highspeed_charging_show
;
2581 hsc_handle
->store
= sony_nc_highspeed_charging_store
;
2583 result
= device_create_file(&pd
->dev
, hsc_handle
);
2593 static void sony_nc_highspeed_charging_cleanup(struct platform_device
*pd
)
2596 device_remove_file(&pd
->dev
, hsc_handle
);
2602 /* low battery function */
2603 static struct device_attribute
*lowbatt_handle
;
2605 static ssize_t
sony_nc_lowbatt_store(struct device
*dev
,
2606 struct device_attribute
*attr
,
2607 const char *buffer
, size_t count
)
2609 unsigned int result
;
2610 unsigned long value
;
2615 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2618 if (sony_call_snc_handle(0x0121, value
<< 8, &result
))
2624 static ssize_t
sony_nc_lowbatt_show(struct device
*dev
,
2625 struct device_attribute
*attr
, char *buffer
)
2627 unsigned int result
;
2629 if (sony_call_snc_handle(0x0121, 0x0200, &result
))
2632 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 1);
2635 static int sony_nc_lowbatt_setup(struct platform_device
*pd
)
2637 unsigned int result
;
2639 lowbatt_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2640 if (!lowbatt_handle
)
2643 sysfs_attr_init(&lowbatt_handle
->attr
);
2644 lowbatt_handle
->attr
.name
= "lowbatt_hibernate";
2645 lowbatt_handle
->attr
.mode
= S_IRUGO
| S_IWUSR
;
2646 lowbatt_handle
->show
= sony_nc_lowbatt_show
;
2647 lowbatt_handle
->store
= sony_nc_lowbatt_store
;
2649 result
= device_create_file(&pd
->dev
, lowbatt_handle
);
2651 kfree(lowbatt_handle
);
2652 lowbatt_handle
= NULL
;
2659 static void sony_nc_lowbatt_cleanup(struct platform_device
*pd
)
2661 if (lowbatt_handle
) {
2662 device_remove_file(&pd
->dev
, lowbatt_handle
);
2663 kfree(lowbatt_handle
);
2664 lowbatt_handle
= NULL
;
2668 /* fan speed function */
2669 static struct device_attribute
*fan_handle
, *hsf_handle
;
2671 static ssize_t
sony_nc_hsfan_store(struct device
*dev
,
2672 struct device_attribute
*attr
,
2673 const char *buffer
, size_t count
)
2675 unsigned int result
;
2676 unsigned long value
;
2681 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2684 if (sony_call_snc_handle(0x0149, value
<< 0x10 | 0x0200, &result
))
2690 static ssize_t
sony_nc_hsfan_show(struct device
*dev
,
2691 struct device_attribute
*attr
, char *buffer
)
2693 unsigned int result
;
2695 if (sony_call_snc_handle(0x0149, 0x0100, &result
))
2698 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 0x01);
2701 static ssize_t
sony_nc_fanspeed_show(struct device
*dev
,
2702 struct device_attribute
*attr
, char *buffer
)
2704 unsigned int result
;
2706 if (sony_call_snc_handle(0x0149, 0x0300, &result
))
2709 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 0xff);
2712 static int sony_nc_fanspeed_setup(struct platform_device
*pd
)
2714 unsigned int result
;
2716 fan_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2720 hsf_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2723 goto out_hsf_handle_alloc
;
2726 sysfs_attr_init(&fan_handle
->attr
);
2727 fan_handle
->attr
.name
= "fanspeed";
2728 fan_handle
->attr
.mode
= S_IRUGO
;
2729 fan_handle
->show
= sony_nc_fanspeed_show
;
2730 fan_handle
->store
= NULL
;
2732 sysfs_attr_init(&hsf_handle
->attr
);
2733 hsf_handle
->attr
.name
= "fan_forced";
2734 hsf_handle
->attr
.mode
= S_IRUGO
| S_IWUSR
;
2735 hsf_handle
->show
= sony_nc_hsfan_show
;
2736 hsf_handle
->store
= sony_nc_hsfan_store
;
2738 result
= device_create_file(&pd
->dev
, fan_handle
);
2740 goto out_fan_handle
;
2742 result
= device_create_file(&pd
->dev
, hsf_handle
);
2744 goto out_hsf_handle
;
2749 device_remove_file(&pd
->dev
, fan_handle
);
2755 out_hsf_handle_alloc
:
2761 static void sony_nc_fanspeed_cleanup(struct platform_device
*pd
)
2764 device_remove_file(&pd
->dev
, fan_handle
);
2769 device_remove_file(&pd
->dev
, hsf_handle
);
2775 /* USB charge function */
2776 static struct device_attribute
*uc_handle
;
2778 static ssize_t
sony_nc_usb_charge_store(struct device
*dev
,
2779 struct device_attribute
*attr
,
2780 const char *buffer
, size_t count
)
2782 unsigned int result
;
2783 unsigned long value
;
2788 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2791 if (sony_call_snc_handle(0x0155, value
<< 0x10 | 0x0100, &result
))
2797 static ssize_t
sony_nc_usb_charge_show(struct device
*dev
,
2798 struct device_attribute
*attr
, char *buffer
)
2800 unsigned int result
;
2802 if (sony_call_snc_handle(0x0155, 0x0000, &result
))
2805 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
& 0x01);
2808 static int sony_nc_usb_charge_setup(struct platform_device
*pd
)
2810 unsigned int result
;
2812 if (sony_call_snc_handle(0x0155, 0x0000, &result
) || !(result
& 0x01)) {
2813 /* some models advertise the handle but have no implementation
2816 pr_info("No USB Charge capability found\n");
2820 uc_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2824 sysfs_attr_init(&uc_handle
->attr
);
2825 uc_handle
->attr
.name
= "usb_charge";
2826 uc_handle
->attr
.mode
= S_IRUGO
| S_IWUSR
;
2827 uc_handle
->show
= sony_nc_usb_charge_show
;
2828 uc_handle
->store
= sony_nc_usb_charge_store
;
2830 result
= device_create_file(&pd
->dev
, uc_handle
);
2840 static void sony_nc_usb_charge_cleanup(struct platform_device
*pd
)
2843 device_remove_file(&pd
->dev
, uc_handle
);
2849 /* Panel ID function */
2850 static struct device_attribute
*panel_handle
;
2852 static ssize_t
sony_nc_panelid_show(struct device
*dev
,
2853 struct device_attribute
*attr
, char *buffer
)
2855 unsigned int result
;
2857 if (sony_call_snc_handle(0x011D, 0x0000, &result
))
2860 return snprintf(buffer
, PAGE_SIZE
, "%d\n", result
);
2863 static int sony_nc_panelid_setup(struct platform_device
*pd
)
2865 unsigned int result
;
2867 panel_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2871 sysfs_attr_init(&panel_handle
->attr
);
2872 panel_handle
->attr
.name
= "panel_id";
2873 panel_handle
->attr
.mode
= S_IRUGO
;
2874 panel_handle
->show
= sony_nc_panelid_show
;
2875 panel_handle
->store
= NULL
;
2877 result
= device_create_file(&pd
->dev
, panel_handle
);
2879 kfree(panel_handle
);
2880 panel_handle
= NULL
;
2887 static void sony_nc_panelid_cleanup(struct platform_device
*pd
)
2890 device_remove_file(&pd
->dev
, panel_handle
);
2891 kfree(panel_handle
);
2892 panel_handle
= NULL
;
2896 /* smart connect function */
2897 static struct device_attribute
*sc_handle
;
2899 static ssize_t
sony_nc_smart_conn_store(struct device
*dev
,
2900 struct device_attribute
*attr
,
2901 const char *buffer
, size_t count
)
2903 unsigned int result
;
2904 unsigned long value
;
2909 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2912 if (sony_call_snc_handle(0x0168, value
<< 0x10, &result
))
2918 static int sony_nc_smart_conn_setup(struct platform_device
*pd
)
2920 unsigned int result
;
2922 sc_handle
= kzalloc(sizeof(struct device_attribute
), GFP_KERNEL
);
2926 sysfs_attr_init(&sc_handle
->attr
);
2927 sc_handle
->attr
.name
= "smart_connect";
2928 sc_handle
->attr
.mode
= S_IWUSR
;
2929 sc_handle
->show
= NULL
;
2930 sc_handle
->store
= sony_nc_smart_conn_store
;
2932 result
= device_create_file(&pd
->dev
, sc_handle
);
2942 static void sony_nc_smart_conn_cleanup(struct platform_device
*pd
)
2945 device_remove_file(&pd
->dev
, sc_handle
);
2951 /* Touchpad enable/disable */
2952 struct touchpad_control
{
2953 struct device_attribute attr
;
2956 static struct touchpad_control
*tp_ctl
;
2958 static ssize_t
sony_nc_touchpad_store(struct device
*dev
,
2959 struct device_attribute
*attr
, const char *buffer
, size_t count
)
2961 unsigned int result
;
2962 unsigned long value
;
2967 if (kstrtoul(buffer
, 10, &value
) || value
> 1)
2970 /* sysfs: 0 disabled, 1 enabled
2971 * EC: 0 enabled, 1 disabled
2973 if (sony_call_snc_handle(tp_ctl
->handle
,
2974 (!value
<< 0x10) | 0x100, &result
))
2980 static ssize_t
sony_nc_touchpad_show(struct device
*dev
,
2981 struct device_attribute
*attr
, char *buffer
)
2983 unsigned int result
;
2985 if (sony_call_snc_handle(tp_ctl
->handle
, 0x000, &result
))
2988 return snprintf(buffer
, PAGE_SIZE
, "%d\n", !(result
& 0x01));
2991 static int sony_nc_touchpad_setup(struct platform_device
*pd
,
2992 unsigned int handle
)
2996 tp_ctl
= kzalloc(sizeof(struct touchpad_control
), GFP_KERNEL
);
3000 tp_ctl
->handle
= handle
;
3002 sysfs_attr_init(&tp_ctl
->attr
.attr
);
3003 tp_ctl
->attr
.attr
.name
= "touchpad";
3004 tp_ctl
->attr
.attr
.mode
= S_IRUGO
| S_IWUSR
;
3005 tp_ctl
->attr
.show
= sony_nc_touchpad_show
;
3006 tp_ctl
->attr
.store
= sony_nc_touchpad_store
;
3008 ret
= device_create_file(&pd
->dev
, &tp_ctl
->attr
);
3017 static void sony_nc_touchpad_cleanup(struct platform_device
*pd
)
3020 device_remove_file(&pd
->dev
, &tp_ctl
->attr
);
3026 static void sony_nc_backlight_ng_read_limits(int handle
,
3027 struct sony_backlight_props
*props
)
3031 int lvl_table_len
= 0;
3032 u8 min
= 0xff, max
= 0x00;
3033 unsigned char buffer
[32] = { 0 };
3035 props
->handle
= handle
;
3037 props
->maxlvl
= 0xff;
3039 offset
= sony_find_snc_handle(handle
);
3041 /* try to read the boundaries from ACPI tables, if we fail the above
3042 * defaults should be reasonable
3044 i
= sony_nc_buffer_call(sony_nc_acpi_handle
, "SN06", &offset
, buffer
,
3061 /* the buffer lists brightness levels available, brightness levels are
3062 * from position 0 to 8 in the array, other values are used by ALS
3065 for (i
= 0; i
< lvl_table_len
&& i
< ARRAY_SIZE(buffer
); i
++) {
3067 dprintk("Brightness level: %d\n", buffer
[i
]);
3072 if (buffer
[i
] > max
)
3074 if (buffer
[i
] < min
)
3077 props
->offset
= min
;
3078 props
->maxlvl
= max
;
3079 dprintk("Brightness levels: min=%d max=%d\n", props
->offset
,
3083 static void sony_nc_backlight_setup(void)
3085 int max_brightness
= 0;
3086 const struct backlight_ops
*ops
= NULL
;
3087 struct backlight_properties props
;
3089 if (sony_find_snc_handle(0x12f) >= 0) {
3090 ops
= &sony_backlight_ng_ops
;
3091 sony_bl_props
.cmd_base
= 0x0100;
3092 sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props
);
3093 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
3095 } else if (sony_find_snc_handle(0x137) >= 0) {
3096 ops
= &sony_backlight_ng_ops
;
3097 sony_bl_props
.cmd_base
= 0x0100;
3098 sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props
);
3099 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
3101 } else if (sony_find_snc_handle(0x143) >= 0) {
3102 ops
= &sony_backlight_ng_ops
;
3103 sony_bl_props
.cmd_base
= 0x3000;
3104 sony_nc_backlight_ng_read_limits(0x143, &sony_bl_props
);
3105 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
3107 } else if (sony_find_snc_handle(0x14b) >= 0) {
3108 ops
= &sony_backlight_ng_ops
;
3109 sony_bl_props
.cmd_base
= 0x3000;
3110 sony_nc_backlight_ng_read_limits(0x14b, &sony_bl_props
);
3111 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
3113 } else if (sony_find_snc_handle(0x14c) >= 0) {
3114 ops
= &sony_backlight_ng_ops
;
3115 sony_bl_props
.cmd_base
= 0x3000;
3116 sony_nc_backlight_ng_read_limits(0x14c, &sony_bl_props
);
3117 max_brightness
= sony_bl_props
.maxlvl
- sony_bl_props
.offset
;
3119 } else if (acpi_has_method(sony_nc_acpi_handle
, "GBRT")) {
3120 ops
= &sony_backlight_ops
;
3121 max_brightness
= SONY_MAX_BRIGHTNESS
- 1;
3126 memset(&props
, 0, sizeof(struct backlight_properties
));
3127 props
.type
= BACKLIGHT_PLATFORM
;
3128 props
.max_brightness
= max_brightness
;
3129 sony_bl_props
.dev
= backlight_device_register("sony", NULL
,
3133 if (IS_ERR(sony_bl_props
.dev
)) {
3134 pr_warn("unable to register backlight device\n");
3135 sony_bl_props
.dev
= NULL
;
3137 sony_bl_props
.dev
->props
.brightness
=
3138 ops
->get_brightness(sony_bl_props
.dev
);
3141 static void sony_nc_backlight_cleanup(void)
3143 backlight_device_unregister(sony_bl_props
.dev
);
3146 static int sony_nc_add(struct acpi_device
*device
)
3150 struct sony_nc_value
*item
;
3152 sony_nc_acpi_device
= device
;
3153 strcpy(acpi_device_class(device
), "sony/hotkey");
3155 sony_nc_acpi_handle
= device
->handle
;
3157 /* read device status */
3158 result
= acpi_bus_get_status(device
);
3159 /* bail IFF the above call was successful and the device is not present */
3160 if (!result
&& !device
->status
.present
) {
3161 dprintk("Device not present\n");
3166 result
= sony_pf_add();
3171 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
,
3172 sony_nc_acpi_handle
, 1, sony_walk_callback
,
3174 if (ACPI_FAILURE(status
)) {
3175 pr_warn("unable to walk acpi resources\n");
3181 result
= sony_laptop_setup_input(device
);
3183 pr_err("Unable to create input devices\n");
3187 if (acpi_has_method(sony_nc_acpi_handle
, "ECON")) {
3189 if (sony_nc_int_call(sony_nc_acpi_handle
, "ECON", &arg
, NULL
))
3190 dprintk("ECON Method failed\n");
3193 if (acpi_has_method(sony_nc_acpi_handle
, "SN00")) {
3194 dprintk("Doing SNC setup\n");
3195 /* retrieve the available handles */
3196 result
= sony_nc_handles_setup(sony_pf_device
);
3198 sony_nc_function_setup(device
, sony_pf_device
);
3201 /* setup input devices and helper fifo */
3202 if (acpi_video_backlight_support()) {
3203 pr_info("brightness ignored, must be controlled by ACPI video driver\n");
3205 sony_nc_backlight_setup();
3208 /* create sony_pf sysfs attributes related to the SNC device */
3209 for (item
= sony_nc_values
; item
->name
; ++item
) {
3211 if (!debug
&& item
->debug
)
3214 /* find the available acpiget as described in the DSDT */
3215 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
3216 if (acpi_has_method(sony_nc_acpi_handle
,
3218 dprintk("Found %s getter: %s\n",
3219 item
->name
, *item
->acpiget
);
3220 item
->devattr
.attr
.mode
|= S_IRUGO
;
3225 /* find the available acpiset as described in the DSDT */
3226 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
3227 if (acpi_has_method(sony_nc_acpi_handle
,
3229 dprintk("Found %s setter: %s\n",
3230 item
->name
, *item
->acpiset
);
3231 item
->devattr
.attr
.mode
|= S_IWUSR
;
3236 if (item
->devattr
.attr
.mode
!= 0) {
3238 device_create_file(&sony_pf_device
->dev
,
3245 pr_info("SNC setup done.\n");
3249 for (item
= sony_nc_values
; item
->name
; ++item
) {
3250 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
3252 sony_nc_backlight_cleanup();
3253 sony_nc_function_cleanup(sony_pf_device
);
3254 sony_nc_handles_cleanup(sony_pf_device
);
3257 sony_laptop_remove_input();
3263 sony_nc_rfkill_cleanup();
3267 static int sony_nc_remove(struct acpi_device
*device
)
3269 struct sony_nc_value
*item
;
3271 sony_nc_backlight_cleanup();
3273 sony_nc_acpi_device
= NULL
;
3275 for (item
= sony_nc_values
; item
->name
; ++item
) {
3276 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
3279 sony_nc_function_cleanup(sony_pf_device
);
3280 sony_nc_handles_cleanup(sony_pf_device
);
3282 sony_laptop_remove_input();
3283 dprintk(SONY_NC_DRIVER_NAME
" removed.\n");
3288 static const struct acpi_device_id sony_device_ids
[] = {
3293 MODULE_DEVICE_TABLE(acpi
, sony_device_ids
);
3295 static const struct acpi_device_id sony_nc_device_ids
[] = {
3300 static struct acpi_driver sony_nc_driver
= {
3301 .name
= SONY_NC_DRIVER_NAME
,
3302 .class = SONY_NC_CLASS
,
3303 .ids
= sony_nc_device_ids
,
3304 .owner
= THIS_MODULE
,
3307 .remove
= sony_nc_remove
,
3308 .notify
= sony_nc_notify
,
3310 .drv
.pm
= &sony_nc_pm
,
3313 /*********** SPIC (SNY6001) Device ***********/
3315 #define SONYPI_DEVICE_TYPE1 0x00000001
3316 #define SONYPI_DEVICE_TYPE2 0x00000002
3317 #define SONYPI_DEVICE_TYPE3 0x00000004
3319 #define SONYPI_TYPE1_OFFSET 0x04
3320 #define SONYPI_TYPE2_OFFSET 0x12
3321 #define SONYPI_TYPE3_OFFSET 0x12
3323 struct sony_pic_ioport
{
3324 struct acpi_resource_io io1
;
3325 struct acpi_resource_io io2
;
3326 struct list_head list
;
3329 struct sony_pic_irq
{
3330 struct acpi_resource_irq irq
;
3331 struct list_head list
;
3334 struct sonypi_eventtypes
{
3337 struct sonypi_event
*events
;
3340 struct sony_pic_dev
{
3341 struct acpi_device
*acpi_dev
;
3342 struct sony_pic_irq
*cur_irq
;
3343 struct sony_pic_ioport
*cur_ioport
;
3344 struct list_head interrupts
;
3345 struct list_head ioports
;
3347 struct sonypi_eventtypes
*event_types
;
3348 int (*handle_irq
)(const u8
, const u8
);
3356 static struct sony_pic_dev spic_dev
= {
3357 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
3358 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
3361 static int spic_drv_registered
;
3364 #define SONYPI_JOGGER_MASK 0x00000001
3365 #define SONYPI_CAPTURE_MASK 0x00000002
3366 #define SONYPI_FNKEY_MASK 0x00000004
3367 #define SONYPI_BLUETOOTH_MASK 0x00000008
3368 #define SONYPI_PKEY_MASK 0x00000010
3369 #define SONYPI_BACK_MASK 0x00000020
3370 #define SONYPI_HELP_MASK 0x00000040
3371 #define SONYPI_LID_MASK 0x00000080
3372 #define SONYPI_ZOOM_MASK 0x00000100
3373 #define SONYPI_THUMBPHRASE_MASK 0x00000200
3374 #define SONYPI_MEYE_MASK 0x00000400
3375 #define SONYPI_MEMORYSTICK_MASK 0x00000800
3376 #define SONYPI_BATTERY_MASK 0x00001000
3377 #define SONYPI_WIRELESS_MASK 0x00002000
3379 struct sonypi_event
{
3384 /* The set of possible button release events */
3385 static struct sonypi_event sonypi_releaseev
[] = {
3386 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
3390 /* The set of possible jogger events */
3391 static struct sonypi_event sonypi_joggerev
[] = {
3392 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
3393 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
3394 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
3395 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
3396 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
3397 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
3398 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
3399 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
3400 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
3401 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
3402 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
3403 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
3404 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
3408 /* The set of possible capture button events */
3409 static struct sonypi_event sonypi_captureev
[] = {
3410 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
3411 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
3412 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED
},
3413 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
3417 /* The set of possible fnkeys events */
3418 static struct sonypi_event sonypi_fnkeyev
[] = {
3419 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
3420 { 0x11, SONYPI_EVENT_FNKEY_F1
},
3421 { 0x12, SONYPI_EVENT_FNKEY_F2
},
3422 { 0x13, SONYPI_EVENT_FNKEY_F3
},
3423 { 0x14, SONYPI_EVENT_FNKEY_F4
},
3424 { 0x15, SONYPI_EVENT_FNKEY_F5
},
3425 { 0x16, SONYPI_EVENT_FNKEY_F6
},
3426 { 0x17, SONYPI_EVENT_FNKEY_F7
},
3427 { 0x18, SONYPI_EVENT_FNKEY_F8
},
3428 { 0x19, SONYPI_EVENT_FNKEY_F9
},
3429 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
3430 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
3431 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
3432 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
3433 { 0x21, SONYPI_EVENT_FNKEY_1
},
3434 { 0x22, SONYPI_EVENT_FNKEY_2
},
3435 { 0x31, SONYPI_EVENT_FNKEY_D
},
3436 { 0x32, SONYPI_EVENT_FNKEY_E
},
3437 { 0x33, SONYPI_EVENT_FNKEY_F
},
3438 { 0x34, SONYPI_EVENT_FNKEY_S
},
3439 { 0x35, SONYPI_EVENT_FNKEY_B
},
3440 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
3444 /* The set of possible program key events */
3445 static struct sonypi_event sonypi_pkeyev
[] = {
3446 { 0x01, SONYPI_EVENT_PKEY_P1
},
3447 { 0x02, SONYPI_EVENT_PKEY_P2
},
3448 { 0x04, SONYPI_EVENT_PKEY_P3
},
3449 { 0x20, SONYPI_EVENT_PKEY_P1
},
3453 /* The set of possible bluetooth events */
3454 static struct sonypi_event sonypi_blueev
[] = {
3455 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
3456 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
3457 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
3461 /* The set of possible wireless events */
3462 static struct sonypi_event sonypi_wlessev
[] = {
3463 { 0x59, SONYPI_EVENT_IGNORE
},
3464 { 0x5a, SONYPI_EVENT_IGNORE
},
3468 /* The set of possible back button events */
3469 static struct sonypi_event sonypi_backev
[] = {
3470 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
3474 /* The set of possible help button events */
3475 static struct sonypi_event sonypi_helpev
[] = {
3476 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
3481 /* The set of possible lid events */
3482 static struct sonypi_event sonypi_lidev
[] = {
3483 { 0x51, SONYPI_EVENT_LID_CLOSED
},
3484 { 0x50, SONYPI_EVENT_LID_OPENED
},
3488 /* The set of possible zoom events */
3489 static struct sonypi_event sonypi_zoomev
[] = {
3490 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
3491 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED
},
3492 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED
},
3493 { 0x04, SONYPI_EVENT_ZOOM_PRESSED
},
3497 /* The set of possible thumbphrase events */
3498 static struct sonypi_event sonypi_thumbphraseev
[] = {
3499 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
3503 /* The set of possible motioneye camera events */
3504 static struct sonypi_event sonypi_meyeev
[] = {
3505 { 0x00, SONYPI_EVENT_MEYE_FACE
},
3506 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
3510 /* The set of possible memorystick events */
3511 static struct sonypi_event sonypi_memorystickev
[] = {
3512 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
3513 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
3517 /* The set of possible battery events */
3518 static struct sonypi_event sonypi_batteryev
[] = {
3519 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
3520 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
3524 /* The set of possible volume events */
3525 static struct sonypi_event sonypi_volumeev
[] = {
3526 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED
},
3527 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED
},
3531 /* The set of possible brightness events */
3532 static struct sonypi_event sonypi_brightnessev
[] = {
3533 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED
},
3537 static struct sonypi_eventtypes type1_events
[] = {
3538 { 0, 0xffffffff, sonypi_releaseev
},
3539 { 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
3540 { 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
3541 { 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3542 { 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
3543 { 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3544 { 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
3545 { 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3546 { 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3547 { 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3550 static struct sonypi_eventtypes type2_events
[] = {
3551 { 0, 0xffffffff, sonypi_releaseev
},
3552 { 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
3553 { 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
3554 { 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3555 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3556 { 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
3557 { 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3558 { 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
3559 { 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
3560 { 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
3561 { 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
3562 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3563 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3564 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3567 static struct sonypi_eventtypes type3_events
[] = {
3568 { 0, 0xffffffff, sonypi_releaseev
},
3569 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
3570 { 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
3571 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
3572 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
3573 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3574 { 0x05, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
3575 { 0x05, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
3576 { 0x05, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
3577 { 0x05, SONYPI_PKEY_MASK
, sonypi_volumeev
},
3578 { 0x05, SONYPI_PKEY_MASK
, sonypi_brightnessev
},
3582 /* low level spic calls */
3583 #define ITERATIONS_LONG 10000
3584 #define ITERATIONS_SHORT 10
3585 #define wait_on_command(command, iterations) { \
3586 unsigned int n = iterations; \
3587 while (--n && (command)) \
3590 dprintk("command failed at %s : %s (line %d)\n", \
3591 __FILE__, __func__, __LINE__); \
3594 static u8
sony_pic_call1(u8 dev
)
3598 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3600 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3601 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3602 v2
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3603 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev
, (v2
<< 8) | v1
);
3607 static u8
sony_pic_call2(u8 dev
, u8 fn
)
3611 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3613 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3614 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
3616 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
3617 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3618 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev
, fn
, v1
);
3622 static u8
sony_pic_call3(u8 dev
, u8 fn
, u8 v
)
3626 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3627 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
3628 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3629 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
3630 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
3631 outb(v
, spic_dev
.cur_ioport
->io1
.minimum
);
3632 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
3633 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
3639 * minidrivers for SPIC models
3641 static int type3_handle_irq(const u8 data_mask
, const u8 ev
)
3644 * 0x31 could mean we have to take some extra action and wait for
3645 * the next irq for some Type3 models, it will generate a new
3646 * irq and we can read new data from the device:
3647 * - 0x5c and 0x5f requires 0xA0
3648 * - 0x61 requires 0xB3
3650 if (data_mask
== 0x31) {
3651 if (ev
== 0x5c || ev
== 0x5f)
3652 sony_pic_call1(0xA0);
3653 else if (ev
== 0x61)
3654 sony_pic_call1(0xB3);
3660 static void sony_pic_detect_device_type(struct sony_pic_dev
*dev
)
3662 struct pci_dev
*pcidev
;
3664 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3665 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
3667 dev
->model
= SONYPI_DEVICE_TYPE1
;
3668 dev
->evport_offset
= SONYPI_TYPE1_OFFSET
;
3669 dev
->event_types
= type1_events
;
3673 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3674 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
);
3676 dev
->model
= SONYPI_DEVICE_TYPE2
;
3677 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
3678 dev
->event_types
= type2_events
;
3682 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3683 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
);
3685 dev
->model
= SONYPI_DEVICE_TYPE3
;
3686 dev
->handle_irq
= type3_handle_irq
;
3687 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3688 dev
->event_types
= type3_events
;
3692 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3693 PCI_DEVICE_ID_INTEL_ICH8_4
, NULL
);
3695 dev
->model
= SONYPI_DEVICE_TYPE3
;
3696 dev
->handle_irq
= type3_handle_irq
;
3697 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3698 dev
->event_types
= type3_events
;
3702 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
3703 PCI_DEVICE_ID_INTEL_ICH9_1
, NULL
);
3705 dev
->model
= SONYPI_DEVICE_TYPE3
;
3706 dev
->handle_irq
= type3_handle_irq
;
3707 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
3708 dev
->event_types
= type3_events
;
3713 dev
->model
= SONYPI_DEVICE_TYPE2
;
3714 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
3715 dev
->event_types
= type2_events
;
3718 pci_dev_put(pcidev
);
3720 pr_info("detected Type%d model\n",
3721 dev
->model
== SONYPI_DEVICE_TYPE1
? 1 :
3722 dev
->model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
3725 /* camera tests and poweron/poweroff */
3726 #define SONYPI_CAMERA_PICTURE 5
3727 #define SONYPI_CAMERA_CONTROL 0x10
3729 #define SONYPI_CAMERA_BRIGHTNESS 0
3730 #define SONYPI_CAMERA_CONTRAST 1
3731 #define SONYPI_CAMERA_HUE 2
3732 #define SONYPI_CAMERA_COLOR 3
3733 #define SONYPI_CAMERA_SHARPNESS 4
3735 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
3736 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
3737 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
3738 #define SONYPI_CAMERA_MUTE_MASK 0x40
3740 /* the rest don't need a loop until not 0xff */
3741 #define SONYPI_CAMERA_AGC 6
3742 #define SONYPI_CAMERA_AGC_MASK 0x30
3743 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
3745 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
3746 #define SONYPI_CAMERA_CONTROL 0x10
3748 #define SONYPI_CAMERA_STATUS 7
3749 #define SONYPI_CAMERA_STATUS_READY 0x2
3750 #define SONYPI_CAMERA_STATUS_POSITION 0x4
3752 #define SONYPI_DIRECTION_BACKWARDS 0x4
3754 #define SONYPI_CAMERA_REVISION 8
3755 #define SONYPI_CAMERA_ROMVERSION 9
3757 static int __sony_pic_camera_ready(void)
3761 v
= sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS
);
3762 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
3765 static int __sony_pic_camera_off(void)
3768 pr_warn("camera control not enabled\n");
3772 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
,
3773 SONYPI_CAMERA_MUTE_MASK
),
3776 if (spic_dev
.camera_power
) {
3777 sony_pic_call2(0x91, 0);
3778 spic_dev
.camera_power
= 0;
3783 static int __sony_pic_camera_on(void)
3788 pr_warn("camera control not enabled\n");
3792 if (spic_dev
.camera_power
)
3795 for (j
= 5; j
> 0; j
--) {
3797 for (x
= 0; x
< 100 && sony_pic_call2(0x91, 0x1); x
++)
3799 sony_pic_call1(0x93);
3801 for (i
= 400; i
> 0; i
--) {
3802 if (__sony_pic_camera_ready())
3811 pr_warn("failed to power on camera\n");
3815 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL
,
3819 spic_dev
.camera_power
= 1;
3823 /* External camera command (exported to the motion eye v4l driver) */
3824 int sony_pic_camera_command(int command
, u8 value
)
3829 mutex_lock(&spic_dev
.lock
);
3832 case SONY_PIC_COMMAND_SETCAMERA
:
3834 __sony_pic_camera_on();
3836 __sony_pic_camera_off();
3838 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS
:
3839 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS
, value
),
3842 case SONY_PIC_COMMAND_SETCAMERACONTRAST
:
3843 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST
, value
),
3846 case SONY_PIC_COMMAND_SETCAMERAHUE
:
3847 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE
, value
),
3850 case SONY_PIC_COMMAND_SETCAMERACOLOR
:
3851 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR
, value
),
3854 case SONY_PIC_COMMAND_SETCAMERASHARPNESS
:
3855 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS
, value
),
3858 case SONY_PIC_COMMAND_SETCAMERAPICTURE
:
3859 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
, value
),
3862 case SONY_PIC_COMMAND_SETCAMERAAGC
:
3863 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC
, value
),
3867 pr_err("sony_pic_camera_command invalid: %d\n", command
);
3870 mutex_unlock(&spic_dev
.lock
);
3873 EXPORT_SYMBOL(sony_pic_camera_command
);
3875 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
3876 static void __sony_pic_set_wwanpower(u8 state
)
3879 if (spic_dev
.wwan_power
== state
)
3881 sony_pic_call2(0xB0, state
);
3882 sony_pic_call1(0x82);
3883 spic_dev
.wwan_power
= state
;
3886 static ssize_t
sony_pic_wwanpower_store(struct device
*dev
,
3887 struct device_attribute
*attr
,
3888 const char *buffer
, size_t count
)
3890 unsigned long value
;
3894 if (kstrtoul(buffer
, 10, &value
))
3897 mutex_lock(&spic_dev
.lock
);
3898 __sony_pic_set_wwanpower(value
);
3899 mutex_unlock(&spic_dev
.lock
);
3904 static ssize_t
sony_pic_wwanpower_show(struct device
*dev
,
3905 struct device_attribute
*attr
, char *buffer
)
3908 mutex_lock(&spic_dev
.lock
);
3909 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.wwan_power
);
3910 mutex_unlock(&spic_dev
.lock
);
3914 /* bluetooth subsystem power state */
3915 static void __sony_pic_set_bluetoothpower(u8 state
)
3918 if (spic_dev
.bluetooth_power
== state
)
3920 sony_pic_call2(0x96, state
);
3921 sony_pic_call1(0x82);
3922 spic_dev
.bluetooth_power
= state
;
3925 static ssize_t
sony_pic_bluetoothpower_store(struct device
*dev
,
3926 struct device_attribute
*attr
,
3927 const char *buffer
, size_t count
)
3929 unsigned long value
;
3933 if (kstrtoul(buffer
, 10, &value
))
3936 mutex_lock(&spic_dev
.lock
);
3937 __sony_pic_set_bluetoothpower(value
);
3938 mutex_unlock(&spic_dev
.lock
);
3943 static ssize_t
sony_pic_bluetoothpower_show(struct device
*dev
,
3944 struct device_attribute
*attr
, char *buffer
)
3947 mutex_lock(&spic_dev
.lock
);
3948 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.bluetooth_power
);
3949 mutex_unlock(&spic_dev
.lock
);
3954 /* FAN0 information (reverse engineered from ACPI tables) */
3955 #define SONY_PIC_FAN0_STATUS 0x93
3956 static int sony_pic_set_fanspeed(unsigned long value
)
3958 return ec_write(SONY_PIC_FAN0_STATUS
, value
);
3961 static int sony_pic_get_fanspeed(u8
*value
)
3963 return ec_read(SONY_PIC_FAN0_STATUS
, value
);
3966 static ssize_t
sony_pic_fanspeed_store(struct device
*dev
,
3967 struct device_attribute
*attr
,
3968 const char *buffer
, size_t count
)
3970 unsigned long value
;
3974 if (kstrtoul(buffer
, 10, &value
))
3977 if (sony_pic_set_fanspeed(value
))
3983 static ssize_t
sony_pic_fanspeed_show(struct device
*dev
,
3984 struct device_attribute
*attr
, char *buffer
)
3987 if (sony_pic_get_fanspeed(&value
))
3990 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
3993 #define SPIC_ATTR(_name, _mode) \
3994 struct device_attribute spic_attr_##_name = __ATTR(_name, \
3995 _mode, sony_pic_## _name ##_show, \
3996 sony_pic_## _name ##_store)
3998 static SPIC_ATTR(bluetoothpower
, 0644);
3999 static SPIC_ATTR(wwanpower
, 0644);
4000 static SPIC_ATTR(fanspeed
, 0644);
4002 static struct attribute
*spic_attributes
[] = {
4003 &spic_attr_bluetoothpower
.attr
,
4004 &spic_attr_wwanpower
.attr
,
4005 &spic_attr_fanspeed
.attr
,
4009 static struct attribute_group spic_attribute_group
= {
4010 .attrs
= spic_attributes
4013 /******** SONYPI compatibility **********/
4014 #ifdef CONFIG_SONYPI_COMPAT
4016 /* battery / brightness / temperature addresses */
4017 #define SONYPI_BAT_FLAGS 0x81
4018 #define SONYPI_LCD_LIGHT 0x96
4019 #define SONYPI_BAT1_PCTRM 0xa0
4020 #define SONYPI_BAT1_LEFT 0xa2
4021 #define SONYPI_BAT1_MAXRT 0xa4
4022 #define SONYPI_BAT2_PCTRM 0xa8
4023 #define SONYPI_BAT2_LEFT 0xaa
4024 #define SONYPI_BAT2_MAXRT 0xac
4025 #define SONYPI_BAT1_MAXTK 0xb0
4026 #define SONYPI_BAT1_FULL 0xb2
4027 #define SONYPI_BAT2_MAXTK 0xb8
4028 #define SONYPI_BAT2_FULL 0xba
4029 #define SONYPI_TEMP_STATUS 0xC1
4031 struct sonypi_compat_s
{
4032 struct fasync_struct
*fifo_async
;
4034 spinlock_t fifo_lock
;
4035 wait_queue_head_t fifo_proc_list
;
4036 atomic_t open_count
;
4038 static struct sonypi_compat_s sonypi_compat
= {
4039 .open_count
= ATOMIC_INIT(0),
4042 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
4044 return fasync_helper(fd
, filp
, on
, &sonypi_compat
.fifo_async
);
4047 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
4049 atomic_dec(&sonypi_compat
.open_count
);
4053 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
4055 /* Flush input queue on first open */
4056 unsigned long flags
;
4058 spin_lock_irqsave(&sonypi_compat
.fifo_lock
, flags
);
4060 if (atomic_inc_return(&sonypi_compat
.open_count
) == 1)
4061 kfifo_reset(&sonypi_compat
.fifo
);
4063 spin_unlock_irqrestore(&sonypi_compat
.fifo_lock
, flags
);
4068 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
4069 size_t count
, loff_t
*pos
)
4074 if ((kfifo_len(&sonypi_compat
.fifo
) == 0) &&
4075 (file
->f_flags
& O_NONBLOCK
))
4078 ret
= wait_event_interruptible(sonypi_compat
.fifo_proc_list
,
4079 kfifo_len(&sonypi_compat
.fifo
) != 0);
4083 while (ret
< count
&&
4084 (kfifo_out_locked(&sonypi_compat
.fifo
, &c
, sizeof(c
),
4085 &sonypi_compat
.fifo_lock
) == sizeof(c
))) {
4086 if (put_user(c
, buf
++))
4092 struct inode
*inode
= file_inode(file
);
4093 inode
->i_atime
= current_fs_time(inode
->i_sb
);
4099 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
4101 poll_wait(file
, &sonypi_compat
.fifo_proc_list
, wait
);
4102 if (kfifo_len(&sonypi_compat
.fifo
))
4103 return POLLIN
| POLLRDNORM
;
4107 static int ec_read16(u8 addr
, u16
*value
)
4110 if (ec_read(addr
, &val_lb
))
4112 if (ec_read(addr
+ 1, &val_hb
))
4114 *value
= val_lb
| (val_hb
<< 8);
4118 static long sonypi_misc_ioctl(struct file
*fp
, unsigned int cmd
,
4122 void __user
*argp
= (void __user
*)arg
;
4127 mutex_lock(&spic_dev
.lock
);
4129 case SONYPI_IOCGBRT
:
4130 if (sony_bl_props
.dev
== NULL
) {
4134 if (sony_nc_int_call(sony_nc_acpi_handle
, "GBRT", NULL
,
4139 val8
= ((value
& 0xff) - 1) << 5;
4140 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
4143 case SONYPI_IOCSBRT
:
4144 if (sony_bl_props
.dev
== NULL
) {
4148 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
4152 value
= (val8
>> 5) + 1;
4153 if (sony_nc_int_call(sony_nc_acpi_handle
, "SBRT", &value
,
4158 /* sync the backlight device status */
4159 sony_bl_props
.dev
->props
.brightness
=
4160 sony_backlight_get_brightness(sony_bl_props
.dev
);
4162 case SONYPI_IOCGBAT1CAP
:
4163 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
4167 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
4170 case SONYPI_IOCGBAT1REM
:
4171 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
4175 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
4178 case SONYPI_IOCGBAT2CAP
:
4179 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
4183 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
4186 case SONYPI_IOCGBAT2REM
:
4187 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
4191 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
4194 case SONYPI_IOCGBATFLAGS
:
4195 if (ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
4200 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
4203 case SONYPI_IOCGBLUE
:
4204 val8
= spic_dev
.bluetooth_power
;
4205 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
4208 case SONYPI_IOCSBLUE
:
4209 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
4213 __sony_pic_set_bluetoothpower(val8
);
4216 case SONYPI_IOCGFAN
:
4217 if (sony_pic_get_fanspeed(&val8
)) {
4221 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
4224 case SONYPI_IOCSFAN
:
4225 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
4229 if (sony_pic_set_fanspeed(val8
))
4232 /* GET Temperature (useful under APM) */
4233 case SONYPI_IOCGTEMP
:
4234 if (ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
4238 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
4244 mutex_unlock(&spic_dev
.lock
);
4248 static const struct file_operations sonypi_misc_fops
= {
4249 .owner
= THIS_MODULE
,
4250 .read
= sonypi_misc_read
,
4251 .poll
= sonypi_misc_poll
,
4252 .open
= sonypi_misc_open
,
4253 .release
= sonypi_misc_release
,
4254 .fasync
= sonypi_misc_fasync
,
4255 .unlocked_ioctl
= sonypi_misc_ioctl
,
4256 .llseek
= noop_llseek
,
4259 static struct miscdevice sonypi_misc_device
= {
4260 .minor
= MISC_DYNAMIC_MINOR
,
4262 .fops
= &sonypi_misc_fops
,
4265 static void sonypi_compat_report_event(u8 event
)
4267 kfifo_in_locked(&sonypi_compat
.fifo
, (unsigned char *)&event
,
4268 sizeof(event
), &sonypi_compat
.fifo_lock
);
4269 kill_fasync(&sonypi_compat
.fifo_async
, SIGIO
, POLL_IN
);
4270 wake_up_interruptible(&sonypi_compat
.fifo_proc_list
);
4273 static int sonypi_compat_init(void)
4277 spin_lock_init(&sonypi_compat
.fifo_lock
);
4279 kfifo_alloc(&sonypi_compat
.fifo
, SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
4281 pr_err("kfifo_alloc failed\n");
4285 init_waitqueue_head(&sonypi_compat
.fifo_proc_list
);
4288 sonypi_misc_device
.minor
= minor
;
4289 error
= misc_register(&sonypi_misc_device
);
4291 pr_err("misc_register failed\n");
4292 goto err_free_kfifo
;
4295 pr_info("device allocated minor is %d\n",
4296 sonypi_misc_device
.minor
);
4301 kfifo_free(&sonypi_compat
.fifo
);
4305 static void sonypi_compat_exit(void)
4307 misc_deregister(&sonypi_misc_device
);
4308 kfifo_free(&sonypi_compat
.fifo
);
4311 static int sonypi_compat_init(void) { return 0; }
4312 static void sonypi_compat_exit(void) { }
4313 static void sonypi_compat_report_event(u8 event
) { }
4314 #endif /* CONFIG_SONYPI_COMPAT */
4320 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
4323 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
4325 switch (resource
->type
) {
4326 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
4328 /* start IO enumeration */
4329 struct sony_pic_ioport
*ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
4333 list_add(&ioport
->list
, &dev
->ioports
);
4337 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
4338 /* end IO enumeration */
4341 case ACPI_RESOURCE_TYPE_IRQ
:
4343 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
4344 struct sony_pic_irq
*interrupt
= NULL
;
4345 if (!p
|| !p
->interrupt_count
) {
4347 * IRQ descriptors may have no IRQ# bits set,
4348 * particularly those those w/ _STA disabled
4350 dprintk("Blank IRQ resource\n");
4353 for (i
= 0; i
< p
->interrupt_count
; i
++) {
4354 if (!p
->interrupts
[i
]) {
4355 pr_warn("Invalid IRQ %d\n",
4359 interrupt
= kzalloc(sizeof(*interrupt
),
4364 list_add(&interrupt
->list
, &dev
->interrupts
);
4365 interrupt
->irq
.triggering
= p
->triggering
;
4366 interrupt
->irq
.polarity
= p
->polarity
;
4367 interrupt
->irq
.sharable
= p
->sharable
;
4368 interrupt
->irq
.interrupt_count
= 1;
4369 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
4373 case ACPI_RESOURCE_TYPE_IO
:
4375 struct acpi_resource_io
*io
= &resource
->data
.io
;
4376 struct sony_pic_ioport
*ioport
=
4377 list_first_entry(&dev
->ioports
, struct sony_pic_ioport
, list
);
4379 dprintk("Blank IO resource\n");
4383 if (!ioport
->io1
.minimum
) {
4384 memcpy(&ioport
->io1
, io
, sizeof(*io
));
4385 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport
->io1
.minimum
,
4386 ioport
->io1
.address_length
);
4388 else if (!ioport
->io2
.minimum
) {
4389 memcpy(&ioport
->io2
, io
, sizeof(*io
));
4390 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport
->io2
.minimum
,
4391 ioport
->io2
.address_length
);
4394 pr_err("Unknown SPIC Type, more than 2 IO Ports\n");
4400 dprintk("Resource %d isn't an IRQ nor an IO port\n",
4403 case ACPI_RESOURCE_TYPE_END_TAG
:
4406 return AE_CTRL_TERMINATE
;
4409 static int sony_pic_possible_resources(struct acpi_device
*device
)
4412 acpi_status status
= AE_OK
;
4417 /* get device status */
4418 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
4419 dprintk("Evaluating _STA\n");
4420 result
= acpi_bus_get_status(device
);
4422 pr_warn("Unable to read status\n");
4426 if (!device
->status
.enabled
)
4427 dprintk("Device disabled\n");
4429 dprintk("Device enabled\n");
4432 * Query and parse 'method'
4434 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
4435 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
4436 sony_pic_read_possible_resource
, &spic_dev
);
4437 if (ACPI_FAILURE(status
)) {
4438 pr_warn("Failure evaluating %s\n", METHOD_NAME__PRS
);
4446 * Disable the spic device by calling its _DIS method
4448 static int sony_pic_disable(struct acpi_device
*device
)
4450 acpi_status ret
= acpi_evaluate_object(device
->handle
, "_DIS", NULL
,
4453 if (ACPI_FAILURE(ret
) && ret
!= AE_NOT_FOUND
)
4456 dprintk("Device disabled\n");
4462 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
4464 * Call _SRS to set current resources
4466 static int sony_pic_enable(struct acpi_device
*device
,
4467 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
4471 /* Type 1 resource layout is:
4477 * Type 2 and 3 resource layout is:
4483 struct acpi_resource res1
;
4484 struct acpi_resource res2
;
4485 struct acpi_resource res3
;
4486 struct acpi_resource res4
;
4488 struct acpi_buffer buffer
= { 0, NULL
};
4490 if (!ioport
|| !irq
)
4493 /* init acpi_buffer */
4494 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
4498 buffer
.length
= sizeof(*resource
) + 1;
4499 buffer
.pointer
= resource
;
4501 /* setup Type 1 resources */
4502 if (spic_dev
.model
== SONYPI_DEVICE_TYPE1
) {
4504 /* setup io resources */
4505 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
4506 resource
->res1
.length
= sizeof(struct acpi_resource
);
4507 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
4508 sizeof(struct acpi_resource_io
));
4510 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IO
;
4511 resource
->res2
.length
= sizeof(struct acpi_resource
);
4512 memcpy(&resource
->res2
.data
.io
, &ioport
->io2
,
4513 sizeof(struct acpi_resource_io
));
4515 /* setup irq resource */
4516 resource
->res3
.type
= ACPI_RESOURCE_TYPE_IRQ
;
4517 resource
->res3
.length
= sizeof(struct acpi_resource
);
4518 memcpy(&resource
->res3
.data
.irq
, &irq
->irq
,
4519 sizeof(struct acpi_resource_irq
));
4520 /* we requested a shared irq */
4521 resource
->res3
.data
.irq
.sharable
= ACPI_SHARED
;
4523 resource
->res4
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
4524 resource
->res4
.length
= sizeof(struct acpi_resource
);
4526 /* setup Type 2/3 resources */
4528 /* setup io resource */
4529 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
4530 resource
->res1
.length
= sizeof(struct acpi_resource
);
4531 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
4532 sizeof(struct acpi_resource_io
));
4534 /* setup irq resource */
4535 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IRQ
;
4536 resource
->res2
.length
= sizeof(struct acpi_resource
);
4537 memcpy(&resource
->res2
.data
.irq
, &irq
->irq
,
4538 sizeof(struct acpi_resource_irq
));
4539 /* we requested a shared irq */
4540 resource
->res2
.data
.irq
.sharable
= ACPI_SHARED
;
4542 resource
->res3
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
4543 resource
->res3
.length
= sizeof(struct acpi_resource
);
4546 /* Attempt to set the resource */
4547 dprintk("Evaluating _SRS\n");
4548 status
= acpi_set_current_resources(device
->handle
, &buffer
);
4550 /* check for total failure */
4551 if (ACPI_FAILURE(status
)) {
4552 pr_err("Error evaluating _SRS\n");
4557 /* Necessary device initializations calls (from sonypi) */
4558 sony_pic_call1(0x82);
4559 sony_pic_call2(0x81, 0xff);
4560 sony_pic_call1(compat
? 0x92 : 0x82);
4569 * ISR: some event is available
4572 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
4577 u8 device_event
= 0;
4579 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
4581 ev
= inb_p(dev
->cur_ioport
->io1
.minimum
);
4582 if (dev
->cur_ioport
->io2
.minimum
)
4583 data_mask
= inb_p(dev
->cur_ioport
->io2
.minimum
);
4585 data_mask
= inb_p(dev
->cur_ioport
->io1
.minimum
+
4586 dev
->evport_offset
);
4588 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
4589 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
4590 dev
->evport_offset
);
4592 if (ev
== 0x00 || ev
== 0xff)
4595 for (i
= 0; dev
->event_types
[i
].mask
; i
++) {
4597 if ((data_mask
& dev
->event_types
[i
].data
) !=
4598 dev
->event_types
[i
].data
)
4601 if (!(mask
& dev
->event_types
[i
].mask
))
4604 for (j
= 0; dev
->event_types
[i
].events
[j
].event
; j
++) {
4605 if (ev
== dev
->event_types
[i
].events
[j
].data
) {
4607 dev
->event_types
[i
].events
[j
].event
;
4608 /* some events may require ignoring */
4615 /* Still not able to decode the event try to pass
4616 * it over to the minidriver
4618 if (dev
->handle_irq
&& dev
->handle_irq(data_mask
, ev
) == 0)
4621 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
4622 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
4623 dev
->evport_offset
);
4627 sony_laptop_report_input_event(device_event
);
4628 sonypi_compat_report_event(device_event
);
4637 static int sony_pic_remove(struct acpi_device
*device
)
4639 struct sony_pic_ioport
*io
, *tmp_io
;
4640 struct sony_pic_irq
*irq
, *tmp_irq
;
4642 if (sony_pic_disable(device
)) {
4643 pr_err("Couldn't disable device\n");
4647 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
4648 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
4649 spic_dev
.cur_ioport
->io1
.address_length
);
4650 if (spic_dev
.cur_ioport
->io2
.minimum
)
4651 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
4652 spic_dev
.cur_ioport
->io2
.address_length
);
4654 sonypi_compat_exit();
4656 sony_laptop_remove_input();
4659 sysfs_remove_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
4662 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
4663 list_del(&io
->list
);
4666 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
4667 list_del(&irq
->list
);
4670 spic_dev
.cur_ioport
= NULL
;
4671 spic_dev
.cur_irq
= NULL
;
4673 dprintk(SONY_PIC_DRIVER_NAME
" removed.\n");
4677 static int sony_pic_add(struct acpi_device
*device
)
4680 struct sony_pic_ioport
*io
, *tmp_io
;
4681 struct sony_pic_irq
*irq
, *tmp_irq
;
4683 spic_dev
.acpi_dev
= device
;
4684 strcpy(acpi_device_class(device
), "sony/hotkey");
4685 sony_pic_detect_device_type(&spic_dev
);
4686 mutex_init(&spic_dev
.lock
);
4688 /* read _PRS resources */
4689 result
= sony_pic_possible_resources(device
);
4691 pr_err("Unable to read possible resources\n");
4692 goto err_free_resources
;
4695 /* setup input devices and helper fifo */
4696 result
= sony_laptop_setup_input(device
);
4698 pr_err("Unable to create input devices\n");
4699 goto err_free_resources
;
4702 result
= sonypi_compat_init();
4704 goto err_remove_input
;
4706 /* request io port */
4707 list_for_each_entry_reverse(io
, &spic_dev
.ioports
, list
) {
4708 if (request_region(io
->io1
.minimum
, io
->io1
.address_length
,
4709 "Sony Programmable I/O Device")) {
4710 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
4711 io
->io1
.minimum
, io
->io1
.maximum
,
4712 io
->io1
.address_length
);
4713 /* Type 1 have 2 ioports */
4714 if (io
->io2
.minimum
) {
4715 if (request_region(io
->io2
.minimum
,
4716 io
->io2
.address_length
,
4717 "Sony Programmable I/O Device")) {
4718 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
4719 io
->io2
.minimum
, io
->io2
.maximum
,
4720 io
->io2
.address_length
);
4721 spic_dev
.cur_ioport
= io
;
4725 dprintk("Unable to get I/O port2: "
4726 "0x%.4x (0x%.4x) + 0x%.2x\n",
4727 io
->io2
.minimum
, io
->io2
.maximum
,
4728 io
->io2
.address_length
);
4729 release_region(io
->io1
.minimum
,
4730 io
->io1
.address_length
);
4734 spic_dev
.cur_ioport
= io
;
4739 if (!spic_dev
.cur_ioport
) {
4740 pr_err("Failed to request_region\n");
4742 goto err_remove_compat
;
4746 list_for_each_entry_reverse(irq
, &spic_dev
.interrupts
, list
) {
4747 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
4748 0, "sony-laptop", &spic_dev
)) {
4749 dprintk("IRQ: %d - triggering: %d - "
4750 "polarity: %d - shr: %d\n",
4751 irq
->irq
.interrupts
[0],
4752 irq
->irq
.triggering
,
4755 spic_dev
.cur_irq
= irq
;
4759 if (!spic_dev
.cur_irq
) {
4760 pr_err("Failed to request_irq\n");
4762 goto err_release_region
;
4765 /* set resource status _SRS */
4766 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
4768 pr_err("Couldn't enable device\n");
4772 spic_dev
.bluetooth_power
= -1;
4773 /* create device attributes */
4774 result
= sony_pf_add();
4776 goto err_disable_device
;
4778 result
= sysfs_create_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
4782 pr_info("SPIC setup done.\n");
4789 sony_pic_disable(device
);
4792 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
4795 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
4796 spic_dev
.cur_ioport
->io1
.address_length
);
4797 if (spic_dev
.cur_ioport
->io2
.minimum
)
4798 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
4799 spic_dev
.cur_ioport
->io2
.address_length
);
4802 sonypi_compat_exit();
4805 sony_laptop_remove_input();
4808 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
4809 list_del(&io
->list
);
4812 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
4813 list_del(&irq
->list
);
4816 spic_dev
.cur_ioport
= NULL
;
4817 spic_dev
.cur_irq
= NULL
;
4822 #ifdef CONFIG_PM_SLEEP
4823 static int sony_pic_suspend(struct device
*dev
)
4825 if (sony_pic_disable(to_acpi_device(dev
)))
4830 static int sony_pic_resume(struct device
*dev
)
4832 sony_pic_enable(to_acpi_device(dev
),
4833 spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
4838 static SIMPLE_DEV_PM_OPS(sony_pic_pm
, sony_pic_suspend
, sony_pic_resume
);
4840 static const struct acpi_device_id sony_pic_device_ids
[] = {
4845 static struct acpi_driver sony_pic_driver
= {
4846 .name
= SONY_PIC_DRIVER_NAME
,
4847 .class = SONY_PIC_CLASS
,
4848 .ids
= sony_pic_device_ids
,
4849 .owner
= THIS_MODULE
,
4851 .add
= sony_pic_add
,
4852 .remove
= sony_pic_remove
,
4854 .drv
.pm
= &sony_pic_pm
,
4857 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
4859 .ident
= "Sony Vaio",
4861 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
4862 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
4866 .ident
= "Sony Vaio",
4868 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
4869 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
4875 static int __init
sony_laptop_init(void)
4879 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
4880 result
= acpi_bus_register_driver(&sony_pic_driver
);
4882 pr_err("Unable to register SPIC driver\n");
4885 spic_drv_registered
= 1;
4888 result
= acpi_bus_register_driver(&sony_nc_driver
);
4890 pr_err("Unable to register SNC driver\n");
4891 goto out_unregister_pic
;
4897 if (spic_drv_registered
)
4898 acpi_bus_unregister_driver(&sony_pic_driver
);
4903 static void __exit
sony_laptop_exit(void)
4905 acpi_bus_unregister_driver(&sony_nc_driver
);
4906 if (spic_drv_registered
)
4907 acpi_bus_unregister_driver(&sony_pic_driver
);
4910 module_init(sony_laptop_init
);
4911 module_exit(sony_laptop_exit
);