2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007-2009 Mattia Dongili <malattia@linux.it>
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
10 * The SNY6001 driver part is based on the sonypi driver which includes
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
17 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/moduleparam.h>
48 #include <linux/init.h>
49 #include <linux/types.h>
50 #include <linux/backlight.h>
51 #include <linux/platform_device.h>
52 #include <linux/err.h>
53 #include <linux/dmi.h>
54 #include <linux/pci.h>
55 #include <linux/interrupt.h>
56 #include <linux/delay.h>
57 #include <linux/input.h>
58 #include <linux/kfifo.h>
59 #include <linux/workqueue.h>
60 #include <linux/acpi.h>
61 #include <linux/slab.h>
62 #include <acpi/acpi_drivers.h>
63 #include <acpi/acpi_bus.h>
64 #include <asm/uaccess.h>
65 #include <linux/sonypi.h>
66 #include <linux/sony-laptop.h>
67 #include <linux/rfkill.h>
68 #ifdef CONFIG_SONYPI_COMPAT
69 #include <linux/poll.h>
70 #include <linux/miscdevice.h>
73 #define DRV_PFX "sony-laptop: "
74 #define dprintk(msg...) do { \
76 pr_warn(DRV_PFX msg); \
79 #define SONY_LAPTOP_DRIVER_VERSION "0.6"
81 #define SONY_NC_CLASS "sony-nc"
82 #define SONY_NC_HID "SNY5001"
83 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
85 #define SONY_PIC_CLASS "sony-pic"
86 #define SONY_PIC_HID "SNY6001"
87 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
89 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
90 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
91 MODULE_LICENSE("GPL");
92 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION
);
95 module_param(debug
, int, 0);
96 MODULE_PARM_DESC(debug
, "set this to 1 (and RTFM) if you want to help "
97 "the development of this driver");
99 static int no_spic
; /* = 0 */
100 module_param(no_spic
, int, 0444);
101 MODULE_PARM_DESC(no_spic
,
102 "set this if you don't want to enable the SPIC device");
104 static int compat
; /* = 0 */
105 module_param(compat
, int, 0444);
106 MODULE_PARM_DESC(compat
,
107 "set this if you want to enable backward compatibility mode");
109 static unsigned long mask
= 0xffffffff;
110 module_param(mask
, ulong
, 0644);
111 MODULE_PARM_DESC(mask
,
112 "set this to the mask of event you want to enable (see doc)");
114 static int camera
; /* = 0 */
115 module_param(camera
, int, 0444);
116 MODULE_PARM_DESC(camera
,
117 "set this to 1 to enable Motion Eye camera controls "
118 "(only use it if you have a C1VE or C1VN model)");
120 #ifdef CONFIG_SONYPI_COMPAT
121 static int minor
= -1;
122 module_param(minor
, int, 0);
123 MODULE_PARM_DESC(minor
,
124 "minor number of the misc device for the SPIC compatibility code, "
125 "default is -1 (automatic)");
128 enum sony_nc_rfkill
{
136 static int sony_rfkill_handle
;
137 static struct rfkill
*sony_rfkill_devices
[N_SONY_RFKILL
];
138 static int sony_rfkill_address
[N_SONY_RFKILL
] = {0x300, 0x500, 0x700, 0x900};
139 static void sony_nc_rfkill_update(void);
141 /*********** Input Devices ***********/
143 #define SONY_LAPTOP_BUF_SIZE 128
144 struct sony_laptop_input_s
{
146 struct input_dev
*jog_dev
;
147 struct input_dev
*key_dev
;
149 spinlock_t fifo_lock
;
150 struct timer_list release_key_timer
;
153 static struct sony_laptop_input_s sony_laptop_input
= {
154 .users
= ATOMIC_INIT(0),
157 struct sony_laptop_keypress
{
158 struct input_dev
*dev
;
162 /* Correspondance table between sonypi events
163 * and input layer indexes in the keymap
165 static int sony_laptop_input_index
[] = {
167 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
168 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
169 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
170 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
171 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
172 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
173 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
174 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
175 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
176 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
177 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
178 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
179 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
180 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
181 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
182 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
183 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
184 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
185 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
186 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
187 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
188 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
189 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
190 17, /* 24 SONYPI_EVENT_FNKEY_1 */
191 18, /* 25 SONYPI_EVENT_FNKEY_2 */
192 19, /* 26 SONYPI_EVENT_FNKEY_D */
193 20, /* 27 SONYPI_EVENT_FNKEY_E */
194 21, /* 28 SONYPI_EVENT_FNKEY_F */
195 22, /* 29 SONYPI_EVENT_FNKEY_S */
196 23, /* 30 SONYPI_EVENT_FNKEY_B */
197 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
198 25, /* 32 SONYPI_EVENT_PKEY_P1 */
199 26, /* 33 SONYPI_EVENT_PKEY_P2 */
200 27, /* 34 SONYPI_EVENT_PKEY_P3 */
201 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
202 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
203 -1, /* 37 SONYPI_EVENT_LID_OPENED */
204 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
205 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
206 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
207 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
208 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
209 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
210 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
211 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
212 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
213 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
214 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
215 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
216 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
217 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
218 43, /* 52 SONYPI_EVENT_MEYE_FACE */
219 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
220 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
221 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
222 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
223 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
224 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
225 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
226 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
227 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
228 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
229 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
230 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
231 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
232 53, /* 66 SONYPI_EVENT_PKEY_P4 */
233 54, /* 67 SONYPI_EVENT_PKEY_P5 */
234 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
235 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
236 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
237 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
238 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
239 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */
242 static int sony_laptop_input_keycode_map
[] = {
243 KEY_CAMERA
, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
244 KEY_RESERVED
, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
245 KEY_RESERVED
, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
246 KEY_RESERVED
, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
247 KEY_FN_ESC
, /* 4 SONYPI_EVENT_FNKEY_ESC */
248 KEY_FN_F1
, /* 5 SONYPI_EVENT_FNKEY_F1 */
249 KEY_FN_F2
, /* 6 SONYPI_EVENT_FNKEY_F2 */
250 KEY_FN_F3
, /* 7 SONYPI_EVENT_FNKEY_F3 */
251 KEY_FN_F4
, /* 8 SONYPI_EVENT_FNKEY_F4 */
252 KEY_FN_F5
, /* 9 SONYPI_EVENT_FNKEY_F5 */
253 KEY_FN_F6
, /* 10 SONYPI_EVENT_FNKEY_F6 */
254 KEY_FN_F7
, /* 11 SONYPI_EVENT_FNKEY_F7 */
255 KEY_FN_F8
, /* 12 SONYPI_EVENT_FNKEY_F8 */
256 KEY_FN_F9
, /* 13 SONYPI_EVENT_FNKEY_F9 */
257 KEY_FN_F10
, /* 14 SONYPI_EVENT_FNKEY_F10 */
258 KEY_FN_F11
, /* 15 SONYPI_EVENT_FNKEY_F11 */
259 KEY_FN_F12
, /* 16 SONYPI_EVENT_FNKEY_F12 */
260 KEY_FN_F1
, /* 17 SONYPI_EVENT_FNKEY_1 */
261 KEY_FN_F2
, /* 18 SONYPI_EVENT_FNKEY_2 */
262 KEY_FN_D
, /* 19 SONYPI_EVENT_FNKEY_D */
263 KEY_FN_E
, /* 20 SONYPI_EVENT_FNKEY_E */
264 KEY_FN_F
, /* 21 SONYPI_EVENT_FNKEY_F */
265 KEY_FN_S
, /* 22 SONYPI_EVENT_FNKEY_S */
266 KEY_FN_B
, /* 23 SONYPI_EVENT_FNKEY_B */
267 KEY_BLUETOOTH
, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
268 KEY_PROG1
, /* 25 SONYPI_EVENT_PKEY_P1 */
269 KEY_PROG2
, /* 26 SONYPI_EVENT_PKEY_P2 */
270 KEY_PROG3
, /* 27 SONYPI_EVENT_PKEY_P3 */
271 KEY_BACK
, /* 28 SONYPI_EVENT_BACK_PRESSED */
272 KEY_BLUETOOTH
, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
273 KEY_BLUETOOTH
, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
274 KEY_HELP
, /* 31 SONYPI_EVENT_HELP_PRESSED */
275 KEY_FN
, /* 32 SONYPI_EVENT_FNKEY_ONLY */
276 KEY_RESERVED
, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
277 KEY_RESERVED
, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
278 KEY_RESERVED
, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
279 KEY_RESERVED
, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
280 KEY_RESERVED
, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
281 KEY_RESERVED
, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
282 KEY_RESERVED
, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
283 KEY_RESERVED
, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
284 KEY_ZOOM
, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
285 BTN_THUMB
, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
286 KEY_RESERVED
, /* 43 SONYPI_EVENT_MEYE_FACE */
287 KEY_RESERVED
, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
288 KEY_RESERVED
, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
289 KEY_RESERVED
, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
290 KEY_WLAN
, /* 47 SONYPI_EVENT_WIRELESS_ON */
291 KEY_WLAN
, /* 48 SONYPI_EVENT_WIRELESS_OFF */
292 KEY_ZOOMIN
, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
293 KEY_ZOOMOUT
, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
294 KEY_EJECTCD
, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
295 KEY_F13
, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
296 KEY_PROG4
, /* 53 SONYPI_EVENT_PKEY_P4 */
297 KEY_F14
, /* 54 SONYPI_EVENT_PKEY_P5 */
298 KEY_F15
, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
299 KEY_VOLUMEUP
, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
300 KEY_VOLUMEDOWN
, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
301 KEY_MEDIA
, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
302 KEY_VENDOR
, /* 59 SONYPI_EVENT_VENDOR_PRESSED */
305 /* release buttons after a short delay if pressed */
306 static void do_sony_laptop_release_key(unsigned long unused
)
308 struct sony_laptop_keypress kp
;
311 spin_lock_irqsave(&sony_laptop_input
.fifo_lock
, flags
);
313 if (kfifo_out(&sony_laptop_input
.fifo
,
314 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
315 input_report_key(kp
.dev
, kp
.key
, 0);
319 /* If there is something in the fifo schedule next release. */
320 if (kfifo_len(&sony_laptop_input
.fifo
) != 0)
321 mod_timer(&sony_laptop_input
.release_key_timer
,
322 jiffies
+ msecs_to_jiffies(10));
324 spin_unlock_irqrestore(&sony_laptop_input
.fifo_lock
, flags
);
327 /* forward event to the input subsystem */
328 static void sony_laptop_report_input_event(u8 event
)
330 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
331 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
332 struct sony_laptop_keypress kp
= { NULL
};
334 if (event
== SONYPI_EVENT_FNKEY_RELEASED
||
335 event
== SONYPI_EVENT_ANYBUTTON_RELEASED
) {
336 /* Nothing, not all VAIOs generate this event */
343 case SONYPI_EVENT_JOGDIAL_UP
:
344 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
345 input_report_rel(jog_dev
, REL_WHEEL
, 1);
349 case SONYPI_EVENT_JOGDIAL_DOWN
:
350 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
351 input_report_rel(jog_dev
, REL_WHEEL
, -1);
356 case SONYPI_EVENT_JOGDIAL_PRESSED
:
362 if (event
>= ARRAY_SIZE(sony_laptop_input_index
)) {
363 dprintk("sony_laptop_report_input_event, event not known: %d\n", event
);
366 if (sony_laptop_input_index
[event
] != -1) {
367 kp
.key
= sony_laptop_input_keycode_map
[sony_laptop_input_index
[event
]];
368 if (kp
.key
!= KEY_UNKNOWN
)
375 input_report_key(kp
.dev
, kp
.key
, 1);
376 /* we emit the scancode so we can always remap the key */
377 input_event(kp
.dev
, EV_MSC
, MSC_SCAN
, event
);
380 /* schedule key release */
381 kfifo_in_locked(&sony_laptop_input
.fifo
,
382 (unsigned char *)&kp
, sizeof(kp
),
383 &sony_laptop_input
.fifo_lock
);
384 mod_timer(&sony_laptop_input
.release_key_timer
,
385 jiffies
+ msecs_to_jiffies(10));
387 dprintk("unknown input event %.2x\n", event
);
390 static int sony_laptop_setup_input(struct acpi_device
*acpi_device
)
392 struct input_dev
*jog_dev
;
393 struct input_dev
*key_dev
;
397 /* don't run again if already initialized */
398 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
402 spin_lock_init(&sony_laptop_input
.fifo_lock
);
403 error
= kfifo_alloc(&sony_laptop_input
.fifo
,
404 SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
406 pr_err(DRV_PFX
"kfifo_alloc failed\n");
410 setup_timer(&sony_laptop_input
.release_key_timer
,
411 do_sony_laptop_release_key
, 0);
414 key_dev
= input_allocate_device();
420 key_dev
->name
= "Sony Vaio Keys";
421 key_dev
->id
.bustype
= BUS_ISA
;
422 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
423 key_dev
->dev
.parent
= &acpi_device
->dev
;
425 /* Initialize the Input Drivers: special keys */
426 input_set_capability(key_dev
, EV_MSC
, MSC_SCAN
);
428 __set_bit(EV_KEY
, key_dev
->evbit
);
429 key_dev
->keycodesize
= sizeof(sony_laptop_input_keycode_map
[0]);
430 key_dev
->keycodemax
= ARRAY_SIZE(sony_laptop_input_keycode_map
);
431 key_dev
->keycode
= &sony_laptop_input_keycode_map
;
432 for (i
= 0; i
< ARRAY_SIZE(sony_laptop_input_keycode_map
); i
++)
433 __set_bit(sony_laptop_input_keycode_map
[i
], key_dev
->keybit
);
434 __clear_bit(KEY_RESERVED
, key_dev
->keybit
);
436 error
= input_register_device(key_dev
);
438 goto err_free_keydev
;
440 sony_laptop_input
.key_dev
= key_dev
;
443 jog_dev
= input_allocate_device();
446 goto err_unregister_keydev
;
449 jog_dev
->name
= "Sony Vaio Jogdial";
450 jog_dev
->id
.bustype
= BUS_ISA
;
451 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
452 key_dev
->dev
.parent
= &acpi_device
->dev
;
454 input_set_capability(jog_dev
, EV_KEY
, BTN_MIDDLE
);
455 input_set_capability(jog_dev
, EV_REL
, REL_WHEEL
);
457 error
= input_register_device(jog_dev
);
459 goto err_free_jogdev
;
461 sony_laptop_input
.jog_dev
= jog_dev
;
466 input_free_device(jog_dev
);
468 err_unregister_keydev
:
469 input_unregister_device(key_dev
);
470 /* to avoid kref underflow below at input_free_device */
474 input_free_device(key_dev
);
477 kfifo_free(&sony_laptop_input
.fifo
);
480 atomic_dec(&sony_laptop_input
.users
);
484 static void sony_laptop_remove_input(void)
486 struct sony_laptop_keypress kp
= { NULL
};
488 /* Cleanup only after the last user has gone */
489 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
492 del_timer_sync(&sony_laptop_input
.release_key_timer
);
495 * Generate key-up events for remaining keys. Note that we don't
496 * need locking since nobody is adding new events to the kfifo.
498 while (kfifo_out(&sony_laptop_input
.fifo
,
499 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
500 input_report_key(kp
.dev
, kp
.key
, 0);
504 /* destroy input devs */
505 input_unregister_device(sony_laptop_input
.key_dev
);
506 sony_laptop_input
.key_dev
= NULL
;
508 if (sony_laptop_input
.jog_dev
) {
509 input_unregister_device(sony_laptop_input
.jog_dev
);
510 sony_laptop_input
.jog_dev
= NULL
;
513 kfifo_free(&sony_laptop_input
.fifo
);
516 /*********** Platform Device ***********/
518 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
519 static struct platform_driver sony_pf_driver
= {
521 .name
= "sony-laptop",
522 .owner
= THIS_MODULE
,
525 static struct platform_device
*sony_pf_device
;
527 static int sony_pf_add(void)
531 /* don't run again if already initialized */
532 if (atomic_add_return(1, &sony_pf_users
) > 1)
535 ret
= platform_driver_register(&sony_pf_driver
);
539 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
540 if (!sony_pf_device
) {
542 goto out_platform_registered
;
545 ret
= platform_device_add(sony_pf_device
);
547 goto out_platform_alloced
;
551 out_platform_alloced
:
552 platform_device_put(sony_pf_device
);
553 sony_pf_device
= NULL
;
554 out_platform_registered
:
555 platform_driver_unregister(&sony_pf_driver
);
557 atomic_dec(&sony_pf_users
);
561 static void sony_pf_remove(void)
563 /* deregister only after the last user has gone */
564 if (!atomic_dec_and_test(&sony_pf_users
))
567 platform_device_unregister(sony_pf_device
);
568 platform_driver_unregister(&sony_pf_driver
);
571 /*********** SNC (SNY5001) Device ***********/
573 /* the device uses 1-based values, while the backlight subsystem uses
575 #define SONY_MAX_BRIGHTNESS 8
577 #define SNC_VALIDATE_IN 0
578 #define SNC_VALIDATE_OUT 1
580 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
582 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
583 const char *, size_t);
584 static int boolean_validate(const int, const int);
585 static int brightness_default_validate(const int, const int);
587 struct sony_nc_value
{
588 char *name
; /* name of the entry */
589 char **acpiget
; /* names of the ACPI get function */
590 char **acpiset
; /* names of the ACPI set function */
591 int (*validate
)(const int, const int); /* input/output validation */
592 int value
; /* current setting */
593 int valid
; /* Has ever been set */
594 int debug
; /* active only in debug mode ? */
595 struct device_attribute devattr
; /* sysfs atribute */
598 #define SNC_HANDLE_NAMES(_name, _values...) \
599 static char *snc_##_name[] = { _values, NULL }
601 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
603 .name = __stringify(_name), \
604 .acpiget = _getters, \
605 .acpiset = _setters, \
606 .validate = _validate, \
608 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
611 #define SNC_HANDLE_NULL { .name = NULL }
613 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
615 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
616 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
618 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
619 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
621 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
622 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
624 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
625 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
627 SNC_HANDLE_NAMES(lidstate_get
, "GLID");
629 SNC_HANDLE_NAMES(indicatorlamp_get
, "GILS");
630 SNC_HANDLE_NAMES(indicatorlamp_set
, "SILS");
632 SNC_HANDLE_NAMES(gainbass_get
, "GMGB");
633 SNC_HANDLE_NAMES(gainbass_set
, "CMGB");
635 SNC_HANDLE_NAMES(PID_get
, "GPID");
637 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
638 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
640 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
641 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
643 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
644 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
646 static struct sony_nc_value sony_nc_values
[] = {
647 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
648 snc_brightness_def_set
, brightness_default_validate
, 0),
649 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
650 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
651 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
652 boolean_validate
, 0),
653 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
654 boolean_validate
, 1),
655 SNC_HANDLE(lidstate
, snc_lidstate_get
, NULL
,
656 boolean_validate
, 0),
657 SNC_HANDLE(indicatorlamp
, snc_indicatorlamp_get
, snc_indicatorlamp_set
,
658 boolean_validate
, 0),
659 SNC_HANDLE(gainbass
, snc_gainbass_get
, snc_gainbass_set
,
660 boolean_validate
, 0),
661 /* unknown methods */
662 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
663 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
664 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
665 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
669 static acpi_handle sony_nc_acpi_handle
;
670 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
673 * acpi_evaluate_object wrappers
675 static int acpi_callgetfunc(acpi_handle handle
, char *name
, int *result
)
677 struct acpi_buffer output
;
678 union acpi_object out_obj
;
681 output
.length
= sizeof(out_obj
);
682 output
.pointer
= &out_obj
;
684 status
= acpi_evaluate_object(handle
, name
, NULL
, &output
);
685 if ((status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
)) {
686 *result
= out_obj
.integer
.value
;
690 pr_warn(DRV_PFX
"acpi_callreadfunc failed\n");
695 static int acpi_callsetfunc(acpi_handle handle
, char *name
, int value
,
698 struct acpi_object_list params
;
699 union acpi_object in_obj
;
700 struct acpi_buffer output
;
701 union acpi_object out_obj
;
705 params
.pointer
= &in_obj
;
706 in_obj
.type
= ACPI_TYPE_INTEGER
;
707 in_obj
.integer
.value
= value
;
709 output
.length
= sizeof(out_obj
);
710 output
.pointer
= &out_obj
;
712 status
= acpi_evaluate_object(handle
, name
, ¶ms
, &output
);
713 if (status
== AE_OK
) {
714 if (result
!= NULL
) {
715 if (out_obj
.type
!= ACPI_TYPE_INTEGER
) {
716 pr_warn(DRV_PFX
"acpi_evaluate_object bad "
720 *result
= out_obj
.integer
.value
;
725 pr_warn(DRV_PFX
"acpi_evaluate_object failed\n");
730 static int sony_find_snc_handle(int handle
)
735 for (i
= 0x20; i
< 0x30; i
++) {
736 acpi_callsetfunc(sony_nc_acpi_handle
, "SN00", i
, &result
);
737 if (result
== handle
) {
738 dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
744 dprintk("handle 0x%.4x not found\n", handle
);
748 static int sony_call_snc_handle(int handle
, int argument
, int *result
)
751 int offset
= sony_find_snc_handle(handle
);
756 ret
= acpi_callsetfunc(sony_nc_acpi_handle
, "SN07", offset
| argument
,
758 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", offset
| argument
,
764 * sony_nc_values input/output validate functions
767 /* brightness_default_validate:
769 * manipulate input output values to keep consistency with the
770 * backlight framework for which brightness values are 0-based.
772 static int brightness_default_validate(const int direction
, const int value
)
775 case SNC_VALIDATE_OUT
:
777 case SNC_VALIDATE_IN
:
778 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
786 * on input validate boolean values 0/1, on output just pass the
789 static int boolean_validate(const int direction
, const int value
)
791 if (direction
== SNC_VALIDATE_IN
) {
792 if (value
!= 0 && value
!= 1)
799 * Sysfs show/store common to all sony_nc_values
801 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
805 struct sony_nc_value
*item
=
806 container_of(attr
, struct sony_nc_value
, devattr
);
811 if (acpi_callgetfunc(sony_nc_acpi_handle
, *item
->acpiget
, &value
) < 0)
815 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
817 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
820 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
821 struct device_attribute
*attr
,
822 const char *buffer
, size_t count
)
825 struct sony_nc_value
*item
=
826 container_of(attr
, struct sony_nc_value
, devattr
);
834 value
= simple_strtoul(buffer
, NULL
, 10);
837 value
= item
->validate(SNC_VALIDATE_IN
, value
);
842 if (acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
, value
, NULL
) < 0)
853 static int sony_backlight_update_status(struct backlight_device
*bd
)
855 return acpi_callsetfunc(sony_nc_acpi_handle
, "SBRT",
856 bd
->props
.brightness
+ 1, NULL
);
859 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
863 if (acpi_callgetfunc(sony_nc_acpi_handle
, "GBRT", &value
))
865 /* brightness levels are 1-based, while backlight ones are 0-based */
869 static struct backlight_device
*sony_backlight_device
;
870 static const struct backlight_ops sony_backlight_ops
= {
871 .update_status
= sony_backlight_update_status
,
872 .get_brightness
= sony_backlight_get_brightness
,
876 * New SNC-only Vaios event mapping to driver known keys
878 struct sony_nc_event
{
883 static struct sony_nc_event sony_100_events
[] = {
884 { 0x90, SONYPI_EVENT_PKEY_P1
},
885 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED
},
886 { 0x91, SONYPI_EVENT_PKEY_P2
},
887 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED
},
888 { 0x81, SONYPI_EVENT_FNKEY_F1
},
889 { 0x01, SONYPI_EVENT_FNKEY_RELEASED
},
890 { 0x82, SONYPI_EVENT_FNKEY_F2
},
891 { 0x02, SONYPI_EVENT_FNKEY_RELEASED
},
892 { 0x83, SONYPI_EVENT_FNKEY_F3
},
893 { 0x03, SONYPI_EVENT_FNKEY_RELEASED
},
894 { 0x84, SONYPI_EVENT_FNKEY_F4
},
895 { 0x04, SONYPI_EVENT_FNKEY_RELEASED
},
896 { 0x85, SONYPI_EVENT_FNKEY_F5
},
897 { 0x05, SONYPI_EVENT_FNKEY_RELEASED
},
898 { 0x86, SONYPI_EVENT_FNKEY_F6
},
899 { 0x06, SONYPI_EVENT_FNKEY_RELEASED
},
900 { 0x87, SONYPI_EVENT_FNKEY_F7
},
901 { 0x07, SONYPI_EVENT_FNKEY_RELEASED
},
902 { 0x89, SONYPI_EVENT_FNKEY_F9
},
903 { 0x09, SONYPI_EVENT_FNKEY_RELEASED
},
904 { 0x8A, SONYPI_EVENT_FNKEY_F10
},
905 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED
},
906 { 0x8C, SONYPI_EVENT_FNKEY_F12
},
907 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED
},
908 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED
},
909 { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED
},
910 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED
},
911 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED
},
912 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED
},
913 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED
},
914 { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED
},
915 { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED
},
916 { 0xa5, SONYPI_EVENT_VENDOR_PRESSED
},
917 { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED
},
918 { 0xa6, SONYPI_EVENT_HELP_PRESSED
},
919 { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED
},
923 static struct sony_nc_event sony_127_events
[] = {
924 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED
},
925 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED
},
926 { 0x82, SONYPI_EVENT_PKEY_P1
},
927 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED
},
928 { 0x83, SONYPI_EVENT_PKEY_P2
},
929 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED
},
930 { 0x84, SONYPI_EVENT_PKEY_P3
},
931 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED
},
932 { 0x85, SONYPI_EVENT_PKEY_P4
},
933 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED
},
934 { 0x86, SONYPI_EVENT_PKEY_P5
},
935 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED
},
936 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED
},
937 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED
},
944 static void sony_nc_notify(struct acpi_device
*device
, u32 event
)
949 /* New-style event */
954 if (sony_find_snc_handle(0x100) == ev
)
956 if (sony_find_snc_handle(0x127) == ev
)
960 struct sony_nc_event
*key_event
;
962 if (sony_call_snc_handle(key_handle
, 0x200, &result
)) {
963 dprintk("sony_nc_notify, unable to decode"
964 " event 0x%.2x 0x%.2x\n", key_handle
,
966 /* restore the original event */
971 if (key_handle
== 0x100)
972 key_event
= sony_100_events
;
974 key_event
= sony_127_events
;
976 for (; key_event
->data
; key_event
++) {
977 if (key_event
->data
== ev
) {
978 ev
= key_event
->event
;
983 if (!key_event
->data
)
985 "Unknown event: 0x%x 0x%x\n",
989 sony_laptop_report_input_event(ev
);
991 } else if (sony_find_snc_handle(sony_rfkill_handle
) == ev
) {
992 sony_nc_rfkill_update();
996 sony_laptop_report_input_event(ev
);
998 dprintk("sony_nc_notify, event: 0x%.2x\n", ev
);
999 acpi_bus_generate_proc_event(sony_nc_acpi_device
, 1, ev
);
1002 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
1003 void *context
, void **return_value
)
1005 struct acpi_device_info
*info
;
1007 if (ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
1008 pr_warn(DRV_PFX
"method: name: %4.4s, args %X\n",
1009 (char *)&info
->name
, info
->param_count
);
1020 static int sony_nc_function_setup(struct acpi_device
*device
)
1024 /* Enable all events */
1025 acpi_callsetfunc(sony_nc_acpi_handle
, "SN02", 0xffff, &result
);
1028 sony_call_snc_handle(0x0100, 0, &result
);
1029 sony_call_snc_handle(0x0101, 0, &result
);
1030 sony_call_snc_handle(0x0102, 0x100, &result
);
1031 sony_call_snc_handle(0x0127, 0, &result
);
1036 static int sony_nc_resume(struct acpi_device
*device
)
1038 struct sony_nc_value
*item
;
1041 for (item
= sony_nc_values
; item
->name
; item
++) {
1046 ret
= acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
,
1049 pr_err(DRV_PFX
"%s: %d\n", __func__
, ret
);
1054 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1056 if (acpi_callsetfunc(sony_nc_acpi_handle
, "ECON", 1, NULL
))
1057 dprintk("ECON Method failed\n");
1060 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1062 dprintk("Doing SNC setup\n");
1063 sony_nc_function_setup(device
);
1066 /* set the last requested brightness level */
1067 if (sony_backlight_device
&&
1068 sony_backlight_update_status(sony_backlight_device
) < 0)
1069 pr_warn(DRV_PFX
"unable to restore brightness level\n");
1071 /* re-read rfkill state */
1072 sony_nc_rfkill_update();
1077 static void sony_nc_rfkill_cleanup(void)
1081 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1082 if (sony_rfkill_devices
[i
]) {
1083 rfkill_unregister(sony_rfkill_devices
[i
]);
1084 rfkill_destroy(sony_rfkill_devices
[i
]);
1089 static int sony_nc_rfkill_set(void *data
, bool blocked
)
1092 int argument
= sony_rfkill_address
[(long) data
] + 0x100;
1095 argument
|= 0xff0000;
1097 return sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1100 static const struct rfkill_ops sony_rfkill_ops
= {
1101 .set_block
= sony_nc_rfkill_set
,
1104 static int sony_nc_setup_rfkill(struct acpi_device
*device
,
1105 enum sony_nc_rfkill nc_type
)
1109 enum rfkill_type type
;
1116 type
= RFKILL_TYPE_WLAN
;
1119 case SONY_BLUETOOTH
:
1120 type
= RFKILL_TYPE_BLUETOOTH
;
1121 name
= "sony-bluetooth";
1124 type
= RFKILL_TYPE_WWAN
;
1128 type
= RFKILL_TYPE_WIMAX
;
1129 name
= "sony-wimax";
1135 rfk
= rfkill_alloc(name
, &device
->dev
, type
,
1136 &sony_rfkill_ops
, (void *)nc_type
);
1140 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1141 hwblock
= !(result
& 0x1);
1142 rfkill_set_hw_state(rfk
, hwblock
);
1144 err
= rfkill_register(rfk
);
1146 rfkill_destroy(rfk
);
1149 sony_rfkill_devices
[nc_type
] = rfk
;
1153 static void sony_nc_rfkill_update(void)
1155 enum sony_nc_rfkill i
;
1159 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1160 hwblock
= !(result
& 0x1);
1162 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1163 int argument
= sony_rfkill_address
[i
];
1165 if (!sony_rfkill_devices
[i
])
1169 if (rfkill_set_hw_state(sony_rfkill_devices
[i
], true)) {
1170 /* we already know we're blocked */
1175 sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1176 rfkill_set_states(sony_rfkill_devices
[i
],
1177 !(result
& 0xf), false);
1181 static void sony_nc_rfkill_setup(struct acpi_device
*device
)
1186 struct acpi_object_list params
;
1187 union acpi_object in_obj
;
1188 union acpi_object
*device_enum
;
1189 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1191 offset
= sony_find_snc_handle(0x124);
1193 offset
= sony_find_snc_handle(0x135);
1197 sony_rfkill_handle
= 0x135;
1199 sony_rfkill_handle
= 0x124;
1200 dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle
);
1202 /* need to read the whole buffer returned by the acpi call to SN06
1203 * here otherwise we may miss some features
1206 params
.pointer
= &in_obj
;
1207 in_obj
.type
= ACPI_TYPE_INTEGER
;
1208 in_obj
.integer
.value
= offset
;
1209 status
= acpi_evaluate_object(sony_nc_acpi_handle
, "SN06", ¶ms
,
1211 if (ACPI_FAILURE(status
)) {
1212 dprintk("Radio device enumeration failed\n");
1216 device_enum
= (union acpi_object
*) buffer
.pointer
;
1217 if (!device_enum
|| device_enum
->type
!= ACPI_TYPE_BUFFER
) {
1218 pr_err(DRV_PFX
"Invalid SN06 return object 0x%.2x\n",
1223 /* the buffer is filled with magic numbers describing the devices
1224 * available, 0xff terminates the enumeration
1226 for (i
= 0; i
< device_enum
->buffer
.length
; i
++) {
1228 dev_code
= *(device_enum
->buffer
.pointer
+ i
);
1229 if (dev_code
== 0xff)
1232 dprintk("Radio devices, looking at 0x%.2x\n", dev_code
);
1234 if (dev_code
== 0 && !sony_rfkill_devices
[SONY_WIFI
])
1235 sony_nc_setup_rfkill(device
, SONY_WIFI
);
1237 if (dev_code
== 0x10 && !sony_rfkill_devices
[SONY_BLUETOOTH
])
1238 sony_nc_setup_rfkill(device
, SONY_BLUETOOTH
);
1240 if ((0xf0 & dev_code
) == 0x20 &&
1241 !sony_rfkill_devices
[SONY_WWAN
])
1242 sony_nc_setup_rfkill(device
, SONY_WWAN
);
1244 if (dev_code
== 0x30 && !sony_rfkill_devices
[SONY_WIMAX
])
1245 sony_nc_setup_rfkill(device
, SONY_WIMAX
);
1249 kfree(buffer
.pointer
);
1253 static int sony_nc_add(struct acpi_device
*device
)
1258 struct sony_nc_value
*item
;
1260 pr_info(DRV_PFX
"%s v%s.\n", SONY_NC_DRIVER_NAME
,
1261 SONY_LAPTOP_DRIVER_VERSION
);
1263 sony_nc_acpi_device
= device
;
1264 strcpy(acpi_device_class(device
), "sony/hotkey");
1266 sony_nc_acpi_handle
= device
->handle
;
1268 /* read device status */
1269 result
= acpi_bus_get_status(device
);
1270 /* bail IFF the above call was successful and the device is not present */
1271 if (!result
&& !device
->status
.present
) {
1272 dprintk("Device not present\n");
1278 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
,
1279 sony_nc_acpi_handle
, 1, sony_walk_callback
,
1281 if (ACPI_FAILURE(status
)) {
1282 pr_warn(DRV_PFX
"unable to walk acpi resources\n");
1288 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1290 if (acpi_callsetfunc(sony_nc_acpi_handle
, "ECON", 1, NULL
))
1291 dprintk("ECON Method failed\n");
1294 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1296 dprintk("Doing SNC setup\n");
1297 sony_nc_function_setup(device
);
1298 sony_nc_rfkill_setup(device
);
1301 /* setup input devices and helper fifo */
1302 result
= sony_laptop_setup_input(device
);
1304 pr_err(DRV_PFX
"Unable to create input devices.\n");
1308 if (acpi_video_backlight_support()) {
1309 pr_info(DRV_PFX
"brightness ignored, must be "
1310 "controlled by ACPI video driver\n");
1311 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "GBRT",
1313 struct backlight_properties props
;
1314 memset(&props
, 0, sizeof(struct backlight_properties
));
1315 props
.type
= BACKLIGHT_PLATFORM
;
1316 props
.max_brightness
= SONY_MAX_BRIGHTNESS
- 1;
1317 sony_backlight_device
= backlight_device_register("sony", NULL
,
1319 &sony_backlight_ops
,
1322 if (IS_ERR(sony_backlight_device
)) {
1323 pr_warning(DRV_PFX
"unable to register backlight device\n");
1324 sony_backlight_device
= NULL
;
1326 sony_backlight_device
->props
.brightness
=
1327 sony_backlight_get_brightness
1328 (sony_backlight_device
);
1333 result
= sony_pf_add();
1337 /* create sony_pf sysfs attributes related to the SNC device */
1338 for (item
= sony_nc_values
; item
->name
; ++item
) {
1340 if (!debug
&& item
->debug
)
1343 /* find the available acpiget as described in the DSDT */
1344 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
1345 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
1348 dprintk("Found %s getter: %s\n",
1349 item
->name
, *item
->acpiget
);
1350 item
->devattr
.attr
.mode
|= S_IRUGO
;
1355 /* find the available acpiset as described in the DSDT */
1356 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
1357 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
1360 dprintk("Found %s setter: %s\n",
1361 item
->name
, *item
->acpiset
);
1362 item
->devattr
.attr
.mode
|= S_IWUSR
;
1367 if (item
->devattr
.attr
.mode
!= 0) {
1369 device_create_file(&sony_pf_device
->dev
,
1379 for (item
= sony_nc_values
; item
->name
; ++item
) {
1380 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
1385 if (sony_backlight_device
)
1386 backlight_device_unregister(sony_backlight_device
);
1388 sony_laptop_remove_input();
1391 sony_nc_rfkill_cleanup();
1395 static int sony_nc_remove(struct acpi_device
*device
, int type
)
1397 struct sony_nc_value
*item
;
1399 if (sony_backlight_device
)
1400 backlight_device_unregister(sony_backlight_device
);
1402 sony_nc_acpi_device
= NULL
;
1404 for (item
= sony_nc_values
; item
->name
; ++item
) {
1405 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
1409 sony_laptop_remove_input();
1410 sony_nc_rfkill_cleanup();
1411 dprintk(SONY_NC_DRIVER_NAME
" removed.\n");
1416 static const struct acpi_device_id sony_device_ids
[] = {
1421 MODULE_DEVICE_TABLE(acpi
, sony_device_ids
);
1423 static const struct acpi_device_id sony_nc_device_ids
[] = {
1428 static struct acpi_driver sony_nc_driver
= {
1429 .name
= SONY_NC_DRIVER_NAME
,
1430 .class = SONY_NC_CLASS
,
1431 .ids
= sony_nc_device_ids
,
1432 .owner
= THIS_MODULE
,
1435 .remove
= sony_nc_remove
,
1436 .resume
= sony_nc_resume
,
1437 .notify
= sony_nc_notify
,
1441 /*********** SPIC (SNY6001) Device ***********/
1443 #define SONYPI_DEVICE_TYPE1 0x00000001
1444 #define SONYPI_DEVICE_TYPE2 0x00000002
1445 #define SONYPI_DEVICE_TYPE3 0x00000004
1446 #define SONYPI_DEVICE_TYPE4 0x00000008
1448 #define SONYPI_TYPE1_OFFSET 0x04
1449 #define SONYPI_TYPE2_OFFSET 0x12
1450 #define SONYPI_TYPE3_OFFSET 0x12
1452 struct sony_pic_ioport
{
1453 struct acpi_resource_io io1
;
1454 struct acpi_resource_io io2
;
1455 struct list_head list
;
1458 struct sony_pic_irq
{
1459 struct acpi_resource_irq irq
;
1460 struct list_head list
;
1463 struct sonypi_eventtypes
{
1466 struct sonypi_event
*events
;
1469 struct sony_pic_dev
{
1470 struct acpi_device
*acpi_dev
;
1471 struct sony_pic_irq
*cur_irq
;
1472 struct sony_pic_ioport
*cur_ioport
;
1473 struct list_head interrupts
;
1474 struct list_head ioports
;
1476 struct sonypi_eventtypes
*event_types
;
1477 int (*handle_irq
)(const u8
, const u8
);
1485 static struct sony_pic_dev spic_dev
= {
1486 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
1487 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
1490 static int spic_drv_registered
;
1493 #define SONYPI_JOGGER_MASK 0x00000001
1494 #define SONYPI_CAPTURE_MASK 0x00000002
1495 #define SONYPI_FNKEY_MASK 0x00000004
1496 #define SONYPI_BLUETOOTH_MASK 0x00000008
1497 #define SONYPI_PKEY_MASK 0x00000010
1498 #define SONYPI_BACK_MASK 0x00000020
1499 #define SONYPI_HELP_MASK 0x00000040
1500 #define SONYPI_LID_MASK 0x00000080
1501 #define SONYPI_ZOOM_MASK 0x00000100
1502 #define SONYPI_THUMBPHRASE_MASK 0x00000200
1503 #define SONYPI_MEYE_MASK 0x00000400
1504 #define SONYPI_MEMORYSTICK_MASK 0x00000800
1505 #define SONYPI_BATTERY_MASK 0x00001000
1506 #define SONYPI_WIRELESS_MASK 0x00002000
1508 struct sonypi_event
{
1513 /* The set of possible button release events */
1514 static struct sonypi_event sonypi_releaseev
[] = {
1515 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1519 /* The set of possible jogger events */
1520 static struct sonypi_event sonypi_joggerev
[] = {
1521 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
1522 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
1523 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
1524 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
1525 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
1526 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
1527 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
1528 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
1529 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
1530 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
1531 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
1532 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
1533 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
1537 /* The set of possible capture button events */
1538 static struct sonypi_event sonypi_captureev
[] = {
1539 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
1540 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
1541 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED
},
1542 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
1546 /* The set of possible fnkeys events */
1547 static struct sonypi_event sonypi_fnkeyev
[] = {
1548 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
1549 { 0x11, SONYPI_EVENT_FNKEY_F1
},
1550 { 0x12, SONYPI_EVENT_FNKEY_F2
},
1551 { 0x13, SONYPI_EVENT_FNKEY_F3
},
1552 { 0x14, SONYPI_EVENT_FNKEY_F4
},
1553 { 0x15, SONYPI_EVENT_FNKEY_F5
},
1554 { 0x16, SONYPI_EVENT_FNKEY_F6
},
1555 { 0x17, SONYPI_EVENT_FNKEY_F7
},
1556 { 0x18, SONYPI_EVENT_FNKEY_F8
},
1557 { 0x19, SONYPI_EVENT_FNKEY_F9
},
1558 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
1559 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
1560 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
1561 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
1562 { 0x21, SONYPI_EVENT_FNKEY_1
},
1563 { 0x22, SONYPI_EVENT_FNKEY_2
},
1564 { 0x31, SONYPI_EVENT_FNKEY_D
},
1565 { 0x32, SONYPI_EVENT_FNKEY_E
},
1566 { 0x33, SONYPI_EVENT_FNKEY_F
},
1567 { 0x34, SONYPI_EVENT_FNKEY_S
},
1568 { 0x35, SONYPI_EVENT_FNKEY_B
},
1569 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
1573 /* The set of possible program key events */
1574 static struct sonypi_event sonypi_pkeyev
[] = {
1575 { 0x01, SONYPI_EVENT_PKEY_P1
},
1576 { 0x02, SONYPI_EVENT_PKEY_P2
},
1577 { 0x04, SONYPI_EVENT_PKEY_P3
},
1578 { 0x20, SONYPI_EVENT_PKEY_P1
},
1582 /* The set of possible bluetooth events */
1583 static struct sonypi_event sonypi_blueev
[] = {
1584 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
1585 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
1586 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
1590 /* The set of possible wireless events */
1591 static struct sonypi_event sonypi_wlessev
[] = {
1592 { 0x59, SONYPI_EVENT_IGNORE
},
1593 { 0x5a, SONYPI_EVENT_IGNORE
},
1597 /* The set of possible back button events */
1598 static struct sonypi_event sonypi_backev
[] = {
1599 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
1603 /* The set of possible help button events */
1604 static struct sonypi_event sonypi_helpev
[] = {
1605 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
1610 /* The set of possible lid events */
1611 static struct sonypi_event sonypi_lidev
[] = {
1612 { 0x51, SONYPI_EVENT_LID_CLOSED
},
1613 { 0x50, SONYPI_EVENT_LID_OPENED
},
1617 /* The set of possible zoom events */
1618 static struct sonypi_event sonypi_zoomev
[] = {
1619 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
1620 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED
},
1621 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED
},
1622 { 0x04, SONYPI_EVENT_ZOOM_PRESSED
},
1626 /* The set of possible thumbphrase events */
1627 static struct sonypi_event sonypi_thumbphraseev
[] = {
1628 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
1632 /* The set of possible motioneye camera events */
1633 static struct sonypi_event sonypi_meyeev
[] = {
1634 { 0x00, SONYPI_EVENT_MEYE_FACE
},
1635 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
1639 /* The set of possible memorystick events */
1640 static struct sonypi_event sonypi_memorystickev
[] = {
1641 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
1642 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
1646 /* The set of possible battery events */
1647 static struct sonypi_event sonypi_batteryev
[] = {
1648 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
1649 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
1653 /* The set of possible volume events */
1654 static struct sonypi_event sonypi_volumeev
[] = {
1655 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED
},
1656 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED
},
1660 /* The set of possible brightness events */
1661 static struct sonypi_event sonypi_brightnessev
[] = {
1662 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED
},
1666 static struct sonypi_eventtypes type1_events
[] = {
1667 { 0, 0xffffffff, sonypi_releaseev
},
1668 { 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
1669 { 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
1670 { 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1671 { 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1672 { 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1673 { 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1674 { 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1675 { 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1676 { 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1679 static struct sonypi_eventtypes type2_events
[] = {
1680 { 0, 0xffffffff, sonypi_releaseev
},
1681 { 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
1682 { 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1683 { 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1684 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1685 { 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1686 { 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1687 { 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
1688 { 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
1689 { 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
1690 { 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
1691 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1692 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1693 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1696 static struct sonypi_eventtypes type3_events
[] = {
1697 { 0, 0xffffffff, sonypi_releaseev
},
1698 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1699 { 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
1700 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1701 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1702 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1703 { 0x05, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1704 { 0x05, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
1705 { 0x05, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1706 { 0x05, SONYPI_PKEY_MASK
, sonypi_volumeev
},
1707 { 0x05, SONYPI_PKEY_MASK
, sonypi_brightnessev
},
1711 /* low level spic calls */
1712 #define ITERATIONS_LONG 10000
1713 #define ITERATIONS_SHORT 10
1714 #define wait_on_command(command, iterations) { \
1715 unsigned int n = iterations; \
1716 while (--n && (command)) \
1719 dprintk("command failed at %s : %s (line %d)\n", \
1720 __FILE__, __func__, __LINE__); \
1723 static u8
sony_pic_call1(u8 dev
)
1727 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1729 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1730 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1731 v2
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1732 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev
, (v2
<< 8) | v1
);
1736 static u8
sony_pic_call2(u8 dev
, u8 fn
)
1740 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1742 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1743 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1745 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
1746 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1747 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev
, fn
, v1
);
1751 static u8
sony_pic_call3(u8 dev
, u8 fn
, u8 v
)
1755 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1756 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1757 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1758 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
1759 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1760 outb(v
, spic_dev
.cur_ioport
->io1
.minimum
);
1761 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1762 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
1768 * minidrivers for SPIC models
1770 static int type3_handle_irq(const u8 data_mask
, const u8 ev
)
1773 * 0x31 could mean we have to take some extra action and wait for
1774 * the next irq for some Type3 models, it will generate a new
1775 * irq and we can read new data from the device:
1776 * - 0x5c and 0x5f requires 0xA0
1777 * - 0x61 requires 0xB3
1779 if (data_mask
== 0x31) {
1780 if (ev
== 0x5c || ev
== 0x5f)
1781 sony_pic_call1(0xA0);
1782 else if (ev
== 0x61)
1783 sony_pic_call1(0xB3);
1789 static void sony_pic_detect_device_type(struct sony_pic_dev
*dev
)
1791 struct pci_dev
*pcidev
;
1793 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1794 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
1796 dev
->model
= SONYPI_DEVICE_TYPE1
;
1797 dev
->evport_offset
= SONYPI_TYPE1_OFFSET
;
1798 dev
->event_types
= type1_events
;
1802 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1803 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
);
1805 dev
->model
= SONYPI_DEVICE_TYPE2
;
1806 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
1807 dev
->event_types
= type2_events
;
1811 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1812 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
);
1814 dev
->model
= SONYPI_DEVICE_TYPE3
;
1815 dev
->handle_irq
= type3_handle_irq
;
1816 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1817 dev
->event_types
= type3_events
;
1821 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1822 PCI_DEVICE_ID_INTEL_ICH8_4
, NULL
);
1824 dev
->model
= SONYPI_DEVICE_TYPE3
;
1825 dev
->handle_irq
= type3_handle_irq
;
1826 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1827 dev
->event_types
= type3_events
;
1831 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1832 PCI_DEVICE_ID_INTEL_ICH9_1
, NULL
);
1834 dev
->model
= SONYPI_DEVICE_TYPE3
;
1835 dev
->handle_irq
= type3_handle_irq
;
1836 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1837 dev
->event_types
= type3_events
;
1842 dev
->model
= SONYPI_DEVICE_TYPE2
;
1843 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
1844 dev
->event_types
= type2_events
;
1848 pci_dev_put(pcidev
);
1850 pr_info(DRV_PFX
"detected Type%d model\n",
1851 dev
->model
== SONYPI_DEVICE_TYPE1
? 1 :
1852 dev
->model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
1855 /* camera tests and poweron/poweroff */
1856 #define SONYPI_CAMERA_PICTURE 5
1857 #define SONYPI_CAMERA_CONTROL 0x10
1859 #define SONYPI_CAMERA_BRIGHTNESS 0
1860 #define SONYPI_CAMERA_CONTRAST 1
1861 #define SONYPI_CAMERA_HUE 2
1862 #define SONYPI_CAMERA_COLOR 3
1863 #define SONYPI_CAMERA_SHARPNESS 4
1865 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1866 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1867 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1868 #define SONYPI_CAMERA_MUTE_MASK 0x40
1870 /* the rest don't need a loop until not 0xff */
1871 #define SONYPI_CAMERA_AGC 6
1872 #define SONYPI_CAMERA_AGC_MASK 0x30
1873 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
1875 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1876 #define SONYPI_CAMERA_CONTROL 0x10
1878 #define SONYPI_CAMERA_STATUS 7
1879 #define SONYPI_CAMERA_STATUS_READY 0x2
1880 #define SONYPI_CAMERA_STATUS_POSITION 0x4
1882 #define SONYPI_DIRECTION_BACKWARDS 0x4
1884 #define SONYPI_CAMERA_REVISION 8
1885 #define SONYPI_CAMERA_ROMVERSION 9
1887 static int __sony_pic_camera_ready(void)
1891 v
= sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS
);
1892 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
1895 static int __sony_pic_camera_off(void)
1898 pr_warn(DRV_PFX
"camera control not enabled\n");
1902 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
,
1903 SONYPI_CAMERA_MUTE_MASK
),
1906 if (spic_dev
.camera_power
) {
1907 sony_pic_call2(0x91, 0);
1908 spic_dev
.camera_power
= 0;
1913 static int __sony_pic_camera_on(void)
1918 pr_warn(DRV_PFX
"camera control not enabled\n");
1922 if (spic_dev
.camera_power
)
1925 for (j
= 5; j
> 0; j
--) {
1927 for (x
= 0; x
< 100 && sony_pic_call2(0x91, 0x1); x
++)
1929 sony_pic_call1(0x93);
1931 for (i
= 400; i
> 0; i
--) {
1932 if (__sony_pic_camera_ready())
1941 pr_warn(DRV_PFX
"failed to power on camera\n");
1945 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL
,
1949 spic_dev
.camera_power
= 1;
1953 /* External camera command (exported to the motion eye v4l driver) */
1954 int sony_pic_camera_command(int command
, u8 value
)
1959 mutex_lock(&spic_dev
.lock
);
1962 case SONY_PIC_COMMAND_SETCAMERA
:
1964 __sony_pic_camera_on();
1966 __sony_pic_camera_off();
1968 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS
:
1969 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS
, value
),
1972 case SONY_PIC_COMMAND_SETCAMERACONTRAST
:
1973 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST
, value
),
1976 case SONY_PIC_COMMAND_SETCAMERAHUE
:
1977 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE
, value
),
1980 case SONY_PIC_COMMAND_SETCAMERACOLOR
:
1981 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR
, value
),
1984 case SONY_PIC_COMMAND_SETCAMERASHARPNESS
:
1985 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS
, value
),
1988 case SONY_PIC_COMMAND_SETCAMERAPICTURE
:
1989 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
, value
),
1992 case SONY_PIC_COMMAND_SETCAMERAAGC
:
1993 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC
, value
),
1997 pr_err(DRV_PFX
"sony_pic_camera_command invalid: %d\n",
2001 mutex_unlock(&spic_dev
.lock
);
2004 EXPORT_SYMBOL(sony_pic_camera_command
);
2006 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
2007 static void __sony_pic_set_wwanpower(u8 state
)
2010 if (spic_dev
.wwan_power
== state
)
2012 sony_pic_call2(0xB0, state
);
2013 sony_pic_call1(0x82);
2014 spic_dev
.wwan_power
= state
;
2017 static ssize_t
sony_pic_wwanpower_store(struct device
*dev
,
2018 struct device_attribute
*attr
,
2019 const char *buffer
, size_t count
)
2021 unsigned long value
;
2025 value
= simple_strtoul(buffer
, NULL
, 10);
2026 mutex_lock(&spic_dev
.lock
);
2027 __sony_pic_set_wwanpower(value
);
2028 mutex_unlock(&spic_dev
.lock
);
2033 static ssize_t
sony_pic_wwanpower_show(struct device
*dev
,
2034 struct device_attribute
*attr
, char *buffer
)
2037 mutex_lock(&spic_dev
.lock
);
2038 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.wwan_power
);
2039 mutex_unlock(&spic_dev
.lock
);
2043 /* bluetooth subsystem power state */
2044 static void __sony_pic_set_bluetoothpower(u8 state
)
2047 if (spic_dev
.bluetooth_power
== state
)
2049 sony_pic_call2(0x96, state
);
2050 sony_pic_call1(0x82);
2051 spic_dev
.bluetooth_power
= state
;
2054 static ssize_t
sony_pic_bluetoothpower_store(struct device
*dev
,
2055 struct device_attribute
*attr
,
2056 const char *buffer
, size_t count
)
2058 unsigned long value
;
2062 value
= simple_strtoul(buffer
, NULL
, 10);
2063 mutex_lock(&spic_dev
.lock
);
2064 __sony_pic_set_bluetoothpower(value
);
2065 mutex_unlock(&spic_dev
.lock
);
2070 static ssize_t
sony_pic_bluetoothpower_show(struct device
*dev
,
2071 struct device_attribute
*attr
, char *buffer
)
2074 mutex_lock(&spic_dev
.lock
);
2075 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.bluetooth_power
);
2076 mutex_unlock(&spic_dev
.lock
);
2081 /* FAN0 information (reverse engineered from ACPI tables) */
2082 #define SONY_PIC_FAN0_STATUS 0x93
2083 static int sony_pic_set_fanspeed(unsigned long value
)
2085 return ec_write(SONY_PIC_FAN0_STATUS
, value
);
2088 static int sony_pic_get_fanspeed(u8
*value
)
2090 return ec_read(SONY_PIC_FAN0_STATUS
, value
);
2093 static ssize_t
sony_pic_fanspeed_store(struct device
*dev
,
2094 struct device_attribute
*attr
,
2095 const char *buffer
, size_t count
)
2097 unsigned long value
;
2101 value
= simple_strtoul(buffer
, NULL
, 10);
2102 if (sony_pic_set_fanspeed(value
))
2108 static ssize_t
sony_pic_fanspeed_show(struct device
*dev
,
2109 struct device_attribute
*attr
, char *buffer
)
2112 if (sony_pic_get_fanspeed(&value
))
2115 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
2118 #define SPIC_ATTR(_name, _mode) \
2119 struct device_attribute spic_attr_##_name = __ATTR(_name, \
2120 _mode, sony_pic_## _name ##_show, \
2121 sony_pic_## _name ##_store)
2123 static SPIC_ATTR(bluetoothpower
, 0644);
2124 static SPIC_ATTR(wwanpower
, 0644);
2125 static SPIC_ATTR(fanspeed
, 0644);
2127 static struct attribute
*spic_attributes
[] = {
2128 &spic_attr_bluetoothpower
.attr
,
2129 &spic_attr_wwanpower
.attr
,
2130 &spic_attr_fanspeed
.attr
,
2134 static struct attribute_group spic_attribute_group
= {
2135 .attrs
= spic_attributes
2138 /******** SONYPI compatibility **********/
2139 #ifdef CONFIG_SONYPI_COMPAT
2141 /* battery / brightness / temperature addresses */
2142 #define SONYPI_BAT_FLAGS 0x81
2143 #define SONYPI_LCD_LIGHT 0x96
2144 #define SONYPI_BAT1_PCTRM 0xa0
2145 #define SONYPI_BAT1_LEFT 0xa2
2146 #define SONYPI_BAT1_MAXRT 0xa4
2147 #define SONYPI_BAT2_PCTRM 0xa8
2148 #define SONYPI_BAT2_LEFT 0xaa
2149 #define SONYPI_BAT2_MAXRT 0xac
2150 #define SONYPI_BAT1_MAXTK 0xb0
2151 #define SONYPI_BAT1_FULL 0xb2
2152 #define SONYPI_BAT2_MAXTK 0xb8
2153 #define SONYPI_BAT2_FULL 0xba
2154 #define SONYPI_TEMP_STATUS 0xC1
2156 struct sonypi_compat_s
{
2157 struct fasync_struct
*fifo_async
;
2159 spinlock_t fifo_lock
;
2160 wait_queue_head_t fifo_proc_list
;
2161 atomic_t open_count
;
2163 static struct sonypi_compat_s sonypi_compat
= {
2164 .open_count
= ATOMIC_INIT(0),
2167 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
2169 return fasync_helper(fd
, filp
, on
, &sonypi_compat
.fifo_async
);
2172 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
2174 atomic_dec(&sonypi_compat
.open_count
);
2178 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
2180 /* Flush input queue on first open */
2181 unsigned long flags
;
2183 spin_lock_irqsave(&sonypi_compat
.fifo_lock
, flags
);
2185 if (atomic_inc_return(&sonypi_compat
.open_count
) == 1)
2186 kfifo_reset(&sonypi_compat
.fifo
);
2188 spin_unlock_irqrestore(&sonypi_compat
.fifo_lock
, flags
);
2193 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
2194 size_t count
, loff_t
*pos
)
2199 if ((kfifo_len(&sonypi_compat
.fifo
) == 0) &&
2200 (file
->f_flags
& O_NONBLOCK
))
2203 ret
= wait_event_interruptible(sonypi_compat
.fifo_proc_list
,
2204 kfifo_len(&sonypi_compat
.fifo
) != 0);
2208 while (ret
< count
&&
2209 (kfifo_out_locked(&sonypi_compat
.fifo
, &c
, sizeof(c
),
2210 &sonypi_compat
.fifo_lock
) == sizeof(c
))) {
2211 if (put_user(c
, buf
++))
2217 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
2218 inode
->i_atime
= current_fs_time(inode
->i_sb
);
2224 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
2226 poll_wait(file
, &sonypi_compat
.fifo_proc_list
, wait
);
2227 if (kfifo_len(&sonypi_compat
.fifo
))
2228 return POLLIN
| POLLRDNORM
;
2232 static int ec_read16(u8 addr
, u16
*value
)
2235 if (ec_read(addr
, &val_lb
))
2237 if (ec_read(addr
+ 1, &val_hb
))
2239 *value
= val_lb
| (val_hb
<< 8);
2243 static long sonypi_misc_ioctl(struct file
*fp
, unsigned int cmd
,
2247 void __user
*argp
= (void __user
*)arg
;
2252 mutex_lock(&spic_dev
.lock
);
2254 case SONYPI_IOCGBRT
:
2255 if (sony_backlight_device
== NULL
) {
2259 if (acpi_callgetfunc(sony_nc_acpi_handle
, "GBRT", &value
)) {
2263 val8
= ((value
& 0xff) - 1) << 5;
2264 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2267 case SONYPI_IOCSBRT
:
2268 if (sony_backlight_device
== NULL
) {
2272 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2276 if (acpi_callsetfunc(sony_nc_acpi_handle
, "SBRT",
2277 (val8
>> 5) + 1, NULL
)) {
2281 /* sync the backlight device status */
2282 sony_backlight_device
->props
.brightness
=
2283 sony_backlight_get_brightness(sony_backlight_device
);
2285 case SONYPI_IOCGBAT1CAP
:
2286 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
2290 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2293 case SONYPI_IOCGBAT1REM
:
2294 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
2298 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2301 case SONYPI_IOCGBAT2CAP
:
2302 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
2306 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2309 case SONYPI_IOCGBAT2REM
:
2310 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
2314 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2317 case SONYPI_IOCGBATFLAGS
:
2318 if (ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
2323 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2326 case SONYPI_IOCGBLUE
:
2327 val8
= spic_dev
.bluetooth_power
;
2328 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2331 case SONYPI_IOCSBLUE
:
2332 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2336 __sony_pic_set_bluetoothpower(val8
);
2339 case SONYPI_IOCGFAN
:
2340 if (sony_pic_get_fanspeed(&val8
)) {
2344 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2347 case SONYPI_IOCSFAN
:
2348 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2352 if (sony_pic_set_fanspeed(val8
))
2355 /* GET Temperature (useful under APM) */
2356 case SONYPI_IOCGTEMP
:
2357 if (ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
2361 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2367 mutex_unlock(&spic_dev
.lock
);
2371 static const struct file_operations sonypi_misc_fops
= {
2372 .owner
= THIS_MODULE
,
2373 .read
= sonypi_misc_read
,
2374 .poll
= sonypi_misc_poll
,
2375 .open
= sonypi_misc_open
,
2376 .release
= sonypi_misc_release
,
2377 .fasync
= sonypi_misc_fasync
,
2378 .unlocked_ioctl
= sonypi_misc_ioctl
,
2379 .llseek
= noop_llseek
,
2382 static struct miscdevice sonypi_misc_device
= {
2383 .minor
= MISC_DYNAMIC_MINOR
,
2385 .fops
= &sonypi_misc_fops
,
2388 static void sonypi_compat_report_event(u8 event
)
2390 kfifo_in_locked(&sonypi_compat
.fifo
, (unsigned char *)&event
,
2391 sizeof(event
), &sonypi_compat
.fifo_lock
);
2392 kill_fasync(&sonypi_compat
.fifo_async
, SIGIO
, POLL_IN
);
2393 wake_up_interruptible(&sonypi_compat
.fifo_proc_list
);
2396 static int sonypi_compat_init(void)
2400 spin_lock_init(&sonypi_compat
.fifo_lock
);
2402 kfifo_alloc(&sonypi_compat
.fifo
, SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
2404 pr_err(DRV_PFX
"kfifo_alloc failed\n");
2408 init_waitqueue_head(&sonypi_compat
.fifo_proc_list
);
2411 sonypi_misc_device
.minor
= minor
;
2412 error
= misc_register(&sonypi_misc_device
);
2414 pr_err(DRV_PFX
"misc_register failed\n");
2415 goto err_free_kfifo
;
2418 pr_info(DRV_PFX
"device allocated minor is %d\n",
2419 sonypi_misc_device
.minor
);
2424 kfifo_free(&sonypi_compat
.fifo
);
2428 static void sonypi_compat_exit(void)
2430 misc_deregister(&sonypi_misc_device
);
2431 kfifo_free(&sonypi_compat
.fifo
);
2434 static int sonypi_compat_init(void) { return 0; }
2435 static void sonypi_compat_exit(void) { }
2436 static void sonypi_compat_report_event(u8 event
) { }
2437 #endif /* CONFIG_SONYPI_COMPAT */
2443 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
2446 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
2448 switch (resource
->type
) {
2449 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
2451 /* start IO enumeration */
2452 struct sony_pic_ioport
*ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
2456 list_add(&ioport
->list
, &dev
->ioports
);
2460 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
2461 /* end IO enumeration */
2464 case ACPI_RESOURCE_TYPE_IRQ
:
2466 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
2467 struct sony_pic_irq
*interrupt
= NULL
;
2468 if (!p
|| !p
->interrupt_count
) {
2470 * IRQ descriptors may have no IRQ# bits set,
2471 * particularly those those w/ _STA disabled
2473 dprintk("Blank IRQ resource\n");
2476 for (i
= 0; i
< p
->interrupt_count
; i
++) {
2477 if (!p
->interrupts
[i
]) {
2478 pr_warn(DRV_PFX
"Invalid IRQ %d\n",
2482 interrupt
= kzalloc(sizeof(*interrupt
),
2487 list_add(&interrupt
->list
, &dev
->interrupts
);
2488 interrupt
->irq
.triggering
= p
->triggering
;
2489 interrupt
->irq
.polarity
= p
->polarity
;
2490 interrupt
->irq
.sharable
= p
->sharable
;
2491 interrupt
->irq
.interrupt_count
= 1;
2492 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
2496 case ACPI_RESOURCE_TYPE_IO
:
2498 struct acpi_resource_io
*io
= &resource
->data
.io
;
2499 struct sony_pic_ioport
*ioport
=
2500 list_first_entry(&dev
->ioports
, struct sony_pic_ioport
, list
);
2502 dprintk("Blank IO resource\n");
2506 if (!ioport
->io1
.minimum
) {
2507 memcpy(&ioport
->io1
, io
, sizeof(*io
));
2508 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport
->io1
.minimum
,
2509 ioport
->io1
.address_length
);
2511 else if (!ioport
->io2
.minimum
) {
2512 memcpy(&ioport
->io2
, io
, sizeof(*io
));
2513 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport
->io2
.minimum
,
2514 ioport
->io2
.address_length
);
2517 pr_err(DRV_PFX
"Unknown SPIC Type, more than 2 IO Ports\n");
2523 dprintk("Resource %d isn't an IRQ nor an IO port\n",
2526 case ACPI_RESOURCE_TYPE_END_TAG
:
2529 return AE_CTRL_TERMINATE
;
2532 static int sony_pic_possible_resources(struct acpi_device
*device
)
2535 acpi_status status
= AE_OK
;
2540 /* get device status */
2541 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
2542 dprintk("Evaluating _STA\n");
2543 result
= acpi_bus_get_status(device
);
2545 pr_warn(DRV_PFX
"Unable to read status\n");
2549 if (!device
->status
.enabled
)
2550 dprintk("Device disabled\n");
2552 dprintk("Device enabled\n");
2555 * Query and parse 'method'
2557 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
2558 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
2559 sony_pic_read_possible_resource
, &spic_dev
);
2560 if (ACPI_FAILURE(status
)) {
2561 pr_warn(DRV_PFX
"Failure evaluating %s\n",
2570 * Disable the spic device by calling its _DIS method
2572 static int sony_pic_disable(struct acpi_device
*device
)
2574 acpi_status ret
= acpi_evaluate_object(device
->handle
, "_DIS", NULL
,
2577 if (ACPI_FAILURE(ret
) && ret
!= AE_NOT_FOUND
)
2580 dprintk("Device disabled\n");
2586 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
2588 * Call _SRS to set current resources
2590 static int sony_pic_enable(struct acpi_device
*device
,
2591 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
2595 /* Type 1 resource layout is:
2601 * Type 2 and 3 resource layout is:
2607 struct acpi_resource res1
;
2608 struct acpi_resource res2
;
2609 struct acpi_resource res3
;
2610 struct acpi_resource res4
;
2612 struct acpi_buffer buffer
= { 0, NULL
};
2614 if (!ioport
|| !irq
)
2617 /* init acpi_buffer */
2618 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
2622 buffer
.length
= sizeof(*resource
) + 1;
2623 buffer
.pointer
= resource
;
2625 /* setup Type 1 resources */
2626 if (spic_dev
.model
== SONYPI_DEVICE_TYPE1
) {
2628 /* setup io resources */
2629 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
2630 resource
->res1
.length
= sizeof(struct acpi_resource
);
2631 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
2632 sizeof(struct acpi_resource_io
));
2634 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IO
;
2635 resource
->res2
.length
= sizeof(struct acpi_resource
);
2636 memcpy(&resource
->res2
.data
.io
, &ioport
->io2
,
2637 sizeof(struct acpi_resource_io
));
2639 /* setup irq resource */
2640 resource
->res3
.type
= ACPI_RESOURCE_TYPE_IRQ
;
2641 resource
->res3
.length
= sizeof(struct acpi_resource
);
2642 memcpy(&resource
->res3
.data
.irq
, &irq
->irq
,
2643 sizeof(struct acpi_resource_irq
));
2644 /* we requested a shared irq */
2645 resource
->res3
.data
.irq
.sharable
= ACPI_SHARED
;
2647 resource
->res4
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
2650 /* setup Type 2/3 resources */
2652 /* setup io resource */
2653 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
2654 resource
->res1
.length
= sizeof(struct acpi_resource
);
2655 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
2656 sizeof(struct acpi_resource_io
));
2658 /* setup irq resource */
2659 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IRQ
;
2660 resource
->res2
.length
= sizeof(struct acpi_resource
);
2661 memcpy(&resource
->res2
.data
.irq
, &irq
->irq
,
2662 sizeof(struct acpi_resource_irq
));
2663 /* we requested a shared irq */
2664 resource
->res2
.data
.irq
.sharable
= ACPI_SHARED
;
2666 resource
->res3
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
2669 /* Attempt to set the resource */
2670 dprintk("Evaluating _SRS\n");
2671 status
= acpi_set_current_resources(device
->handle
, &buffer
);
2673 /* check for total failure */
2674 if (ACPI_FAILURE(status
)) {
2675 pr_err(DRV_PFX
"Error evaluating _SRS\n");
2680 /* Necessary device initializations calls (from sonypi) */
2681 sony_pic_call1(0x82);
2682 sony_pic_call2(0x81, 0xff);
2683 sony_pic_call1(compat
? 0x92 : 0x82);
2692 * ISR: some event is available
2695 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
2700 u8 device_event
= 0;
2702 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
2704 ev
= inb_p(dev
->cur_ioport
->io1
.minimum
);
2705 if (dev
->cur_ioport
->io2
.minimum
)
2706 data_mask
= inb_p(dev
->cur_ioport
->io2
.minimum
);
2708 data_mask
= inb_p(dev
->cur_ioport
->io1
.minimum
+
2709 dev
->evport_offset
);
2711 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2712 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
2713 dev
->evport_offset
);
2715 if (ev
== 0x00 || ev
== 0xff)
2718 for (i
= 0; dev
->event_types
[i
].mask
; i
++) {
2720 if ((data_mask
& dev
->event_types
[i
].data
) !=
2721 dev
->event_types
[i
].data
)
2724 if (!(mask
& dev
->event_types
[i
].mask
))
2727 for (j
= 0; dev
->event_types
[i
].events
[j
].event
; j
++) {
2728 if (ev
== dev
->event_types
[i
].events
[j
].data
) {
2730 dev
->event_types
[i
].events
[j
].event
;
2731 /* some events may require ignoring */
2738 /* Still not able to decode the event try to pass
2739 * it over to the minidriver
2741 if (dev
->handle_irq
&& dev
->handle_irq(data_mask
, ev
) == 0)
2744 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2745 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
2746 dev
->evport_offset
);
2750 sony_laptop_report_input_event(device_event
);
2751 acpi_bus_generate_proc_event(dev
->acpi_dev
, 1, device_event
);
2752 sonypi_compat_report_event(device_event
);
2761 static int sony_pic_remove(struct acpi_device
*device
, int type
)
2763 struct sony_pic_ioport
*io
, *tmp_io
;
2764 struct sony_pic_irq
*irq
, *tmp_irq
;
2766 if (sony_pic_disable(device
)) {
2767 pr_err(DRV_PFX
"Couldn't disable device.\n");
2771 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
2772 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
2773 spic_dev
.cur_ioport
->io1
.address_length
);
2774 if (spic_dev
.cur_ioport
->io2
.minimum
)
2775 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
2776 spic_dev
.cur_ioport
->io2
.address_length
);
2778 sonypi_compat_exit();
2780 sony_laptop_remove_input();
2783 sysfs_remove_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
2786 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
2787 list_del(&io
->list
);
2790 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
2791 list_del(&irq
->list
);
2794 spic_dev
.cur_ioport
= NULL
;
2795 spic_dev
.cur_irq
= NULL
;
2797 dprintk(SONY_PIC_DRIVER_NAME
" removed.\n");
2801 static int sony_pic_add(struct acpi_device
*device
)
2804 struct sony_pic_ioport
*io
, *tmp_io
;
2805 struct sony_pic_irq
*irq
, *tmp_irq
;
2807 pr_info(DRV_PFX
"%s v%s.\n", SONY_PIC_DRIVER_NAME
,
2808 SONY_LAPTOP_DRIVER_VERSION
);
2810 spic_dev
.acpi_dev
= device
;
2811 strcpy(acpi_device_class(device
), "sony/hotkey");
2812 sony_pic_detect_device_type(&spic_dev
);
2813 mutex_init(&spic_dev
.lock
);
2815 /* read _PRS resources */
2816 result
= sony_pic_possible_resources(device
);
2818 pr_err(DRV_PFX
"Unable to read possible resources.\n");
2819 goto err_free_resources
;
2822 /* setup input devices and helper fifo */
2823 result
= sony_laptop_setup_input(device
);
2825 pr_err(DRV_PFX
"Unable to create input devices.\n");
2826 goto err_free_resources
;
2829 if (sonypi_compat_init())
2830 goto err_remove_input
;
2832 /* request io port */
2833 list_for_each_entry_reverse(io
, &spic_dev
.ioports
, list
) {
2834 if (request_region(io
->io1
.minimum
, io
->io1
.address_length
,
2835 "Sony Programable I/O Device")) {
2836 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
2837 io
->io1
.minimum
, io
->io1
.maximum
,
2838 io
->io1
.address_length
);
2839 /* Type 1 have 2 ioports */
2840 if (io
->io2
.minimum
) {
2841 if (request_region(io
->io2
.minimum
,
2842 io
->io2
.address_length
,
2843 "Sony Programable I/O Device")) {
2844 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
2845 io
->io2
.minimum
, io
->io2
.maximum
,
2846 io
->io2
.address_length
);
2847 spic_dev
.cur_ioport
= io
;
2851 dprintk("Unable to get I/O port2: "
2852 "0x%.4x (0x%.4x) + 0x%.2x\n",
2853 io
->io2
.minimum
, io
->io2
.maximum
,
2854 io
->io2
.address_length
);
2855 release_region(io
->io1
.minimum
,
2856 io
->io1
.address_length
);
2860 spic_dev
.cur_ioport
= io
;
2865 if (!spic_dev
.cur_ioport
) {
2866 pr_err(DRV_PFX
"Failed to request_region.\n");
2868 goto err_remove_compat
;
2872 list_for_each_entry_reverse(irq
, &spic_dev
.interrupts
, list
) {
2873 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
2874 IRQF_DISABLED
, "sony-laptop", &spic_dev
)) {
2875 dprintk("IRQ: %d - triggering: %d - "
2876 "polarity: %d - shr: %d\n",
2877 irq
->irq
.interrupts
[0],
2878 irq
->irq
.triggering
,
2881 spic_dev
.cur_irq
= irq
;
2885 if (!spic_dev
.cur_irq
) {
2886 pr_err(DRV_PFX
"Failed to request_irq.\n");
2888 goto err_release_region
;
2891 /* set resource status _SRS */
2892 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
2894 pr_err(DRV_PFX
"Couldn't enable device.\n");
2898 spic_dev
.bluetooth_power
= -1;
2899 /* create device attributes */
2900 result
= sony_pf_add();
2902 goto err_disable_device
;
2904 result
= sysfs_create_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
2914 sony_pic_disable(device
);
2917 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
2920 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
2921 spic_dev
.cur_ioport
->io1
.address_length
);
2922 if (spic_dev
.cur_ioport
->io2
.minimum
)
2923 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
2924 spic_dev
.cur_ioport
->io2
.address_length
);
2927 sonypi_compat_exit();
2930 sony_laptop_remove_input();
2933 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
2934 list_del(&io
->list
);
2937 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
2938 list_del(&irq
->list
);
2941 spic_dev
.cur_ioport
= NULL
;
2942 spic_dev
.cur_irq
= NULL
;
2947 static int sony_pic_suspend(struct acpi_device
*device
, pm_message_t state
)
2949 if (sony_pic_disable(device
))
2954 static int sony_pic_resume(struct acpi_device
*device
)
2956 sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
2960 static const struct acpi_device_id sony_pic_device_ids
[] = {
2965 static struct acpi_driver sony_pic_driver
= {
2966 .name
= SONY_PIC_DRIVER_NAME
,
2967 .class = SONY_PIC_CLASS
,
2968 .ids
= sony_pic_device_ids
,
2969 .owner
= THIS_MODULE
,
2971 .add
= sony_pic_add
,
2972 .remove
= sony_pic_remove
,
2973 .suspend
= sony_pic_suspend
,
2974 .resume
= sony_pic_resume
,
2978 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
2980 .ident
= "Sony Vaio",
2982 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
2983 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
2987 .ident
= "Sony Vaio",
2989 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
2990 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
2996 static int __init
sony_laptop_init(void)
3000 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
3001 result
= acpi_bus_register_driver(&sony_pic_driver
);
3003 pr_err(DRV_PFX
"Unable to register SPIC driver.");
3006 spic_drv_registered
= 1;
3009 result
= acpi_bus_register_driver(&sony_nc_driver
);
3011 pr_err(DRV_PFX
"Unable to register SNC driver.");
3012 goto out_unregister_pic
;
3018 if (spic_drv_registered
)
3019 acpi_bus_unregister_driver(&sony_pic_driver
);
3024 static void __exit
sony_laptop_exit(void)
3026 acpi_bus_unregister_driver(&sony_nc_driver
);
3027 if (spic_drv_registered
)
3028 acpi_bus_unregister_driver(&sony_pic_driver
);
3031 module_init(sony_laptop_init
);
3032 module_exit(sony_laptop_exit
);