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 { \
75 if (debug) printk(KERN_WARNING DRV_PFX msg); \
78 #define SONY_LAPTOP_DRIVER_VERSION "0.6"
80 #define SONY_NC_CLASS "sony-nc"
81 #define SONY_NC_HID "SNY5001"
82 #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
84 #define SONY_PIC_CLASS "sony-pic"
85 #define SONY_PIC_HID "SNY6001"
86 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
88 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
89 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
90 MODULE_LICENSE("GPL");
91 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION
);
94 module_param(debug
, int, 0);
95 MODULE_PARM_DESC(debug
, "set this to 1 (and RTFM) if you want to help "
96 "the development of this driver");
98 static int no_spic
; /* = 0 */
99 module_param(no_spic
, int, 0444);
100 MODULE_PARM_DESC(no_spic
,
101 "set this if you don't want to enable the SPIC device");
103 static int compat
; /* = 0 */
104 module_param(compat
, int, 0444);
105 MODULE_PARM_DESC(compat
,
106 "set this if you want to enable backward compatibility mode");
108 static unsigned long mask
= 0xffffffff;
109 module_param(mask
, ulong
, 0644);
110 MODULE_PARM_DESC(mask
,
111 "set this to the mask of event you want to enable (see doc)");
113 static int camera
; /* = 0 */
114 module_param(camera
, int, 0444);
115 MODULE_PARM_DESC(camera
,
116 "set this to 1 to enable Motion Eye camera controls "
117 "(only use it if you have a C1VE or C1VN model)");
119 #ifdef CONFIG_SONYPI_COMPAT
120 static int minor
= -1;
121 module_param(minor
, int, 0);
122 MODULE_PARM_DESC(minor
,
123 "minor number of the misc device for the SPIC compatibility code, "
124 "default is -1 (automatic)");
127 enum sony_nc_rfkill
{
135 static int sony_rfkill_handle
;
136 static struct rfkill
*sony_rfkill_devices
[N_SONY_RFKILL
];
137 static int sony_rfkill_address
[N_SONY_RFKILL
] = {0x300, 0x500, 0x700, 0x900};
138 static void sony_nc_rfkill_update(void);
140 /*********** Input Devices ***********/
142 #define SONY_LAPTOP_BUF_SIZE 128
143 struct sony_laptop_input_s
{
145 struct input_dev
*jog_dev
;
146 struct input_dev
*key_dev
;
148 spinlock_t fifo_lock
;
149 struct timer_list release_key_timer
;
152 static struct sony_laptop_input_s sony_laptop_input
= {
153 .users
= ATOMIC_INIT(0),
156 struct sony_laptop_keypress
{
157 struct input_dev
*dev
;
161 /* Correspondance table between sonypi events
162 * and input layer indexes in the keymap
164 static int sony_laptop_input_index
[] = {
166 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
167 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
168 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
169 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
170 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
171 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
172 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
173 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
174 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
175 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
176 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
177 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
178 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
179 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
180 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
181 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
182 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
183 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
184 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
185 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
186 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
187 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
188 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
189 17, /* 24 SONYPI_EVENT_FNKEY_1 */
190 18, /* 25 SONYPI_EVENT_FNKEY_2 */
191 19, /* 26 SONYPI_EVENT_FNKEY_D */
192 20, /* 27 SONYPI_EVENT_FNKEY_E */
193 21, /* 28 SONYPI_EVENT_FNKEY_F */
194 22, /* 29 SONYPI_EVENT_FNKEY_S */
195 23, /* 30 SONYPI_EVENT_FNKEY_B */
196 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
197 25, /* 32 SONYPI_EVENT_PKEY_P1 */
198 26, /* 33 SONYPI_EVENT_PKEY_P2 */
199 27, /* 34 SONYPI_EVENT_PKEY_P3 */
200 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
201 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
202 -1, /* 37 SONYPI_EVENT_LID_OPENED */
203 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
204 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
205 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
206 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
207 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
208 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
209 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
210 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
211 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
212 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
213 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
214 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
215 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
216 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
217 43, /* 52 SONYPI_EVENT_MEYE_FACE */
218 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
219 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
220 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
221 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
222 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
223 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
224 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
225 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
226 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
227 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
228 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
229 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
230 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */
231 53, /* 66 SONYPI_EVENT_PKEY_P4 */
232 54, /* 67 SONYPI_EVENT_PKEY_P5 */
233 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
234 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
235 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
236 -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
237 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */
240 static int sony_laptop_input_keycode_map
[] = {
241 KEY_CAMERA
, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
242 KEY_RESERVED
, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
243 KEY_RESERVED
, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
244 KEY_RESERVED
, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
245 KEY_FN_ESC
, /* 4 SONYPI_EVENT_FNKEY_ESC */
246 KEY_FN_F1
, /* 5 SONYPI_EVENT_FNKEY_F1 */
247 KEY_FN_F2
, /* 6 SONYPI_EVENT_FNKEY_F2 */
248 KEY_FN_F3
, /* 7 SONYPI_EVENT_FNKEY_F3 */
249 KEY_FN_F4
, /* 8 SONYPI_EVENT_FNKEY_F4 */
250 KEY_FN_F5
, /* 9 SONYPI_EVENT_FNKEY_F5 */
251 KEY_FN_F6
, /* 10 SONYPI_EVENT_FNKEY_F6 */
252 KEY_FN_F7
, /* 11 SONYPI_EVENT_FNKEY_F7 */
253 KEY_FN_F8
, /* 12 SONYPI_EVENT_FNKEY_F8 */
254 KEY_FN_F9
, /* 13 SONYPI_EVENT_FNKEY_F9 */
255 KEY_FN_F10
, /* 14 SONYPI_EVENT_FNKEY_F10 */
256 KEY_FN_F11
, /* 15 SONYPI_EVENT_FNKEY_F11 */
257 KEY_FN_F12
, /* 16 SONYPI_EVENT_FNKEY_F12 */
258 KEY_FN_F1
, /* 17 SONYPI_EVENT_FNKEY_1 */
259 KEY_FN_F2
, /* 18 SONYPI_EVENT_FNKEY_2 */
260 KEY_FN_D
, /* 19 SONYPI_EVENT_FNKEY_D */
261 KEY_FN_E
, /* 20 SONYPI_EVENT_FNKEY_E */
262 KEY_FN_F
, /* 21 SONYPI_EVENT_FNKEY_F */
263 KEY_FN_S
, /* 22 SONYPI_EVENT_FNKEY_S */
264 KEY_FN_B
, /* 23 SONYPI_EVENT_FNKEY_B */
265 KEY_BLUETOOTH
, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
266 KEY_PROG1
, /* 25 SONYPI_EVENT_PKEY_P1 */
267 KEY_PROG2
, /* 26 SONYPI_EVENT_PKEY_P2 */
268 KEY_PROG3
, /* 27 SONYPI_EVENT_PKEY_P3 */
269 KEY_BACK
, /* 28 SONYPI_EVENT_BACK_PRESSED */
270 KEY_BLUETOOTH
, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
271 KEY_BLUETOOTH
, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
272 KEY_HELP
, /* 31 SONYPI_EVENT_HELP_PRESSED */
273 KEY_FN
, /* 32 SONYPI_EVENT_FNKEY_ONLY */
274 KEY_RESERVED
, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
275 KEY_RESERVED
, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
276 KEY_RESERVED
, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
277 KEY_RESERVED
, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
278 KEY_RESERVED
, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
279 KEY_RESERVED
, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
280 KEY_RESERVED
, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
281 KEY_RESERVED
, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
282 KEY_ZOOM
, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
283 BTN_THUMB
, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
284 KEY_RESERVED
, /* 43 SONYPI_EVENT_MEYE_FACE */
285 KEY_RESERVED
, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
286 KEY_RESERVED
, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
287 KEY_RESERVED
, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
288 KEY_WLAN
, /* 47 SONYPI_EVENT_WIRELESS_ON */
289 KEY_WLAN
, /* 48 SONYPI_EVENT_WIRELESS_OFF */
290 KEY_ZOOMIN
, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
291 KEY_ZOOMOUT
, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
292 KEY_EJECTCD
, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
293 KEY_F13
, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */
294 KEY_PROG4
, /* 53 SONYPI_EVENT_PKEY_P4 */
295 KEY_F14
, /* 54 SONYPI_EVENT_PKEY_P5 */
296 KEY_F15
, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
297 KEY_VOLUMEUP
, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
298 KEY_VOLUMEDOWN
, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
299 KEY_MEDIA
, /* 58 SONYPI_EVENT_MEDIA_PRESSED */
302 /* release buttons after a short delay if pressed */
303 static void do_sony_laptop_release_key(unsigned long unused
)
305 struct sony_laptop_keypress kp
;
308 spin_lock_irqsave(&sony_laptop_input
.fifo_lock
, flags
);
310 if (kfifo_out(&sony_laptop_input
.fifo
,
311 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
312 input_report_key(kp
.dev
, kp
.key
, 0);
316 /* If there is something in the fifo schedule next release. */
317 if (kfifo_len(&sony_laptop_input
.fifo
) != 0)
318 mod_timer(&sony_laptop_input
.release_key_timer
,
319 jiffies
+ msecs_to_jiffies(10));
321 spin_unlock_irqrestore(&sony_laptop_input
.fifo_lock
, flags
);
324 /* forward event to the input subsystem */
325 static void sony_laptop_report_input_event(u8 event
)
327 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
328 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
329 struct sony_laptop_keypress kp
= { NULL
};
331 if (event
== SONYPI_EVENT_FNKEY_RELEASED
||
332 event
== SONYPI_EVENT_ANYBUTTON_RELEASED
) {
333 /* Nothing, not all VAIOs generate this event */
340 case SONYPI_EVENT_JOGDIAL_UP
:
341 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
342 input_report_rel(jog_dev
, REL_WHEEL
, 1);
346 case SONYPI_EVENT_JOGDIAL_DOWN
:
347 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
348 input_report_rel(jog_dev
, REL_WHEEL
, -1);
353 case SONYPI_EVENT_JOGDIAL_PRESSED
:
359 if (event
>= ARRAY_SIZE(sony_laptop_input_index
)) {
360 dprintk("sony_laptop_report_input_event, event not known: %d\n", event
);
363 if (sony_laptop_input_index
[event
] != -1) {
364 kp
.key
= sony_laptop_input_keycode_map
[sony_laptop_input_index
[event
]];
365 if (kp
.key
!= KEY_UNKNOWN
)
372 input_report_key(kp
.dev
, kp
.key
, 1);
373 /* we emit the scancode so we can always remap the key */
374 input_event(kp
.dev
, EV_MSC
, MSC_SCAN
, event
);
377 /* schedule key release */
378 kfifo_in_locked(&sony_laptop_input
.fifo
,
379 (unsigned char *)&kp
, sizeof(kp
),
380 &sony_laptop_input
.fifo_lock
);
381 mod_timer(&sony_laptop_input
.release_key_timer
,
382 jiffies
+ msecs_to_jiffies(10));
384 dprintk("unknown input event %.2x\n", event
);
387 static int sony_laptop_setup_input(struct acpi_device
*acpi_device
)
389 struct input_dev
*jog_dev
;
390 struct input_dev
*key_dev
;
394 /* don't run again if already initialized */
395 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
399 spin_lock_init(&sony_laptop_input
.fifo_lock
);
400 error
= kfifo_alloc(&sony_laptop_input
.fifo
,
401 SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
403 printk(KERN_ERR DRV_PFX
"kfifo_alloc failed\n");
407 setup_timer(&sony_laptop_input
.release_key_timer
,
408 do_sony_laptop_release_key
, 0);
411 key_dev
= input_allocate_device();
417 key_dev
->name
= "Sony Vaio Keys";
418 key_dev
->id
.bustype
= BUS_ISA
;
419 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
420 key_dev
->dev
.parent
= &acpi_device
->dev
;
422 /* Initialize the Input Drivers: special keys */
423 input_set_capability(key_dev
, EV_MSC
, MSC_SCAN
);
425 __set_bit(EV_KEY
, key_dev
->evbit
);
426 key_dev
->keycodesize
= sizeof(sony_laptop_input_keycode_map
[0]);
427 key_dev
->keycodemax
= ARRAY_SIZE(sony_laptop_input_keycode_map
);
428 key_dev
->keycode
= &sony_laptop_input_keycode_map
;
429 for (i
= 0; i
< ARRAY_SIZE(sony_laptop_input_keycode_map
); i
++)
430 __set_bit(sony_laptop_input_keycode_map
[i
], key_dev
->keybit
);
431 __clear_bit(KEY_RESERVED
, key_dev
->keybit
);
433 error
= input_register_device(key_dev
);
435 goto err_free_keydev
;
437 sony_laptop_input
.key_dev
= key_dev
;
440 jog_dev
= input_allocate_device();
443 goto err_unregister_keydev
;
446 jog_dev
->name
= "Sony Vaio Jogdial";
447 jog_dev
->id
.bustype
= BUS_ISA
;
448 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
449 key_dev
->dev
.parent
= &acpi_device
->dev
;
451 input_set_capability(jog_dev
, EV_KEY
, BTN_MIDDLE
);
452 input_set_capability(jog_dev
, EV_REL
, REL_WHEEL
);
454 error
= input_register_device(jog_dev
);
456 goto err_free_jogdev
;
458 sony_laptop_input
.jog_dev
= jog_dev
;
463 input_free_device(jog_dev
);
465 err_unregister_keydev
:
466 input_unregister_device(key_dev
);
467 /* to avoid kref underflow below at input_free_device */
471 input_free_device(key_dev
);
474 kfifo_free(&sony_laptop_input
.fifo
);
477 atomic_dec(&sony_laptop_input
.users
);
481 static void sony_laptop_remove_input(void)
483 struct sony_laptop_keypress kp
= { NULL
};
485 /* Cleanup only after the last user has gone */
486 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
489 del_timer_sync(&sony_laptop_input
.release_key_timer
);
492 * Generate key-up events for remaining keys. Note that we don't
493 * need locking since nobody is adding new events to the kfifo.
495 while (kfifo_out(&sony_laptop_input
.fifo
,
496 (unsigned char *)&kp
, sizeof(kp
)) == sizeof(kp
)) {
497 input_report_key(kp
.dev
, kp
.key
, 0);
501 /* destroy input devs */
502 input_unregister_device(sony_laptop_input
.key_dev
);
503 sony_laptop_input
.key_dev
= NULL
;
505 if (sony_laptop_input
.jog_dev
) {
506 input_unregister_device(sony_laptop_input
.jog_dev
);
507 sony_laptop_input
.jog_dev
= NULL
;
510 kfifo_free(&sony_laptop_input
.fifo
);
513 /*********** Platform Device ***********/
515 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
516 static struct platform_driver sony_pf_driver
= {
518 .name
= "sony-laptop",
519 .owner
= THIS_MODULE
,
522 static struct platform_device
*sony_pf_device
;
524 static int sony_pf_add(void)
528 /* don't run again if already initialized */
529 if (atomic_add_return(1, &sony_pf_users
) > 1)
532 ret
= platform_driver_register(&sony_pf_driver
);
536 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
537 if (!sony_pf_device
) {
539 goto out_platform_registered
;
542 ret
= platform_device_add(sony_pf_device
);
544 goto out_platform_alloced
;
548 out_platform_alloced
:
549 platform_device_put(sony_pf_device
);
550 sony_pf_device
= NULL
;
551 out_platform_registered
:
552 platform_driver_unregister(&sony_pf_driver
);
554 atomic_dec(&sony_pf_users
);
558 static void sony_pf_remove(void)
560 /* deregister only after the last user has gone */
561 if (!atomic_dec_and_test(&sony_pf_users
))
564 platform_device_del(sony_pf_device
);
565 platform_device_put(sony_pf_device
);
566 platform_driver_unregister(&sony_pf_driver
);
569 /*********** SNC (SNY5001) Device ***********/
571 /* the device uses 1-based values, while the backlight subsystem uses
573 #define SONY_MAX_BRIGHTNESS 8
575 #define SNC_VALIDATE_IN 0
576 #define SNC_VALIDATE_OUT 1
578 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
580 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
581 const char *, size_t);
582 static int boolean_validate(const int, const int);
583 static int brightness_default_validate(const int, const int);
585 struct sony_nc_value
{
586 char *name
; /* name of the entry */
587 char **acpiget
; /* names of the ACPI get function */
588 char **acpiset
; /* names of the ACPI set function */
589 int (*validate
)(const int, const int); /* input/output validation */
590 int value
; /* current setting */
591 int valid
; /* Has ever been set */
592 int debug
; /* active only in debug mode ? */
593 struct device_attribute devattr
; /* sysfs atribute */
596 #define SNC_HANDLE_NAMES(_name, _values...) \
597 static char *snc_##_name[] = { _values, NULL }
599 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
601 .name = __stringify(_name), \
602 .acpiget = _getters, \
603 .acpiset = _setters, \
604 .validate = _validate, \
606 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
609 #define SNC_HANDLE_NULL { .name = NULL }
611 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
613 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
614 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
616 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
617 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
619 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
620 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
622 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
623 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
625 SNC_HANDLE_NAMES(lidstate_get
, "GLID");
627 SNC_HANDLE_NAMES(indicatorlamp_get
, "GILS");
628 SNC_HANDLE_NAMES(indicatorlamp_set
, "SILS");
630 SNC_HANDLE_NAMES(gainbass_get
, "GMGB");
631 SNC_HANDLE_NAMES(gainbass_set
, "CMGB");
633 SNC_HANDLE_NAMES(PID_get
, "GPID");
635 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
636 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
638 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
639 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
641 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
642 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
644 static struct sony_nc_value sony_nc_values
[] = {
645 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
646 snc_brightness_def_set
, brightness_default_validate
, 0),
647 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
648 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
649 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
650 boolean_validate
, 0),
651 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
652 boolean_validate
, 1),
653 SNC_HANDLE(lidstate
, snc_lidstate_get
, NULL
,
654 boolean_validate
, 0),
655 SNC_HANDLE(indicatorlamp
, snc_indicatorlamp_get
, snc_indicatorlamp_set
,
656 boolean_validate
, 0),
657 SNC_HANDLE(gainbass
, snc_gainbass_get
, snc_gainbass_set
,
658 boolean_validate
, 0),
659 /* unknown methods */
660 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
661 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
662 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
663 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
667 static acpi_handle sony_nc_acpi_handle
;
668 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
671 * acpi_evaluate_object wrappers
673 static int acpi_callgetfunc(acpi_handle handle
, char *name
, int *result
)
675 struct acpi_buffer output
;
676 union acpi_object out_obj
;
679 output
.length
= sizeof(out_obj
);
680 output
.pointer
= &out_obj
;
682 status
= acpi_evaluate_object(handle
, name
, NULL
, &output
);
683 if ((status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
)) {
684 *result
= out_obj
.integer
.value
;
688 printk(KERN_WARNING DRV_PFX
"acpi_callreadfunc failed\n");
693 static int acpi_callsetfunc(acpi_handle handle
, char *name
, int value
,
696 struct acpi_object_list params
;
697 union acpi_object in_obj
;
698 struct acpi_buffer output
;
699 union acpi_object out_obj
;
703 params
.pointer
= &in_obj
;
704 in_obj
.type
= ACPI_TYPE_INTEGER
;
705 in_obj
.integer
.value
= value
;
707 output
.length
= sizeof(out_obj
);
708 output
.pointer
= &out_obj
;
710 status
= acpi_evaluate_object(handle
, name
, ¶ms
, &output
);
711 if (status
== AE_OK
) {
712 if (result
!= NULL
) {
713 if (out_obj
.type
!= ACPI_TYPE_INTEGER
) {
714 printk(KERN_WARNING DRV_PFX
"acpi_evaluate_object bad "
718 *result
= out_obj
.integer
.value
;
723 printk(KERN_WARNING DRV_PFX
"acpi_evaluate_object failed\n");
728 static int sony_find_snc_handle(int handle
)
733 for (i
= 0x20; i
< 0x30; i
++) {
734 acpi_callsetfunc(sony_nc_acpi_handle
, "SN00", i
, &result
);
735 if (result
== handle
)
742 static int sony_call_snc_handle(int handle
, int argument
, int *result
)
744 int offset
= sony_find_snc_handle(handle
);
749 return acpi_callsetfunc(sony_nc_acpi_handle
, "SN07", offset
| argument
,
754 * sony_nc_values input/output validate functions
757 /* brightness_default_validate:
759 * manipulate input output values to keep consistency with the
760 * backlight framework for which brightness values are 0-based.
762 static int brightness_default_validate(const int direction
, const int value
)
765 case SNC_VALIDATE_OUT
:
767 case SNC_VALIDATE_IN
:
768 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
776 * on input validate boolean values 0/1, on output just pass the
779 static int boolean_validate(const int direction
, const int value
)
781 if (direction
== SNC_VALIDATE_IN
) {
782 if (value
!= 0 && value
!= 1)
789 * Sysfs show/store common to all sony_nc_values
791 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
795 struct sony_nc_value
*item
=
796 container_of(attr
, struct sony_nc_value
, devattr
);
801 if (acpi_callgetfunc(sony_nc_acpi_handle
, *item
->acpiget
, &value
) < 0)
805 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
807 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
810 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
811 struct device_attribute
*attr
,
812 const char *buffer
, size_t count
)
815 struct sony_nc_value
*item
=
816 container_of(attr
, struct sony_nc_value
, devattr
);
824 value
= simple_strtoul(buffer
, NULL
, 10);
827 value
= item
->validate(SNC_VALIDATE_IN
, value
);
832 if (acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
, value
, NULL
) < 0)
843 static int sony_backlight_update_status(struct backlight_device
*bd
)
845 return acpi_callsetfunc(sony_nc_acpi_handle
, "SBRT",
846 bd
->props
.brightness
+ 1, NULL
);
849 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
853 if (acpi_callgetfunc(sony_nc_acpi_handle
, "GBRT", &value
))
855 /* brightness levels are 1-based, while backlight ones are 0-based */
859 static struct backlight_device
*sony_backlight_device
;
860 static struct backlight_ops sony_backlight_ops
= {
861 .update_status
= sony_backlight_update_status
,
862 .get_brightness
= sony_backlight_get_brightness
,
866 * New SNC-only Vaios event mapping to driver known keys
868 struct sony_nc_event
{
873 static struct sony_nc_event sony_100_events
[] = {
874 { 0x90, SONYPI_EVENT_PKEY_P1
},
875 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED
},
876 { 0x91, SONYPI_EVENT_PKEY_P2
},
877 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED
},
878 { 0x81, SONYPI_EVENT_FNKEY_F1
},
879 { 0x01, SONYPI_EVENT_FNKEY_RELEASED
},
880 { 0x82, SONYPI_EVENT_FNKEY_F2
},
881 { 0x02, SONYPI_EVENT_FNKEY_RELEASED
},
882 { 0x83, SONYPI_EVENT_FNKEY_F3
},
883 { 0x03, SONYPI_EVENT_FNKEY_RELEASED
},
884 { 0x84, SONYPI_EVENT_FNKEY_F4
},
885 { 0x04, SONYPI_EVENT_FNKEY_RELEASED
},
886 { 0x85, SONYPI_EVENT_FNKEY_F5
},
887 { 0x05, SONYPI_EVENT_FNKEY_RELEASED
},
888 { 0x86, SONYPI_EVENT_FNKEY_F6
},
889 { 0x06, SONYPI_EVENT_FNKEY_RELEASED
},
890 { 0x87, SONYPI_EVENT_FNKEY_F7
},
891 { 0x07, SONYPI_EVENT_FNKEY_RELEASED
},
892 { 0x89, SONYPI_EVENT_FNKEY_F9
},
893 { 0x09, SONYPI_EVENT_FNKEY_RELEASED
},
894 { 0x8A, SONYPI_EVENT_FNKEY_F10
},
895 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED
},
896 { 0x8C, SONYPI_EVENT_FNKEY_F12
},
897 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED
},
898 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED
},
899 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED
},
900 { 0xa1, SONYPI_EVENT_MEDIA_PRESSED
},
901 { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED
},
905 static struct sony_nc_event sony_127_events
[] = {
906 { 0x81, SONYPI_EVENT_MODEKEY_PRESSED
},
907 { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED
},
908 { 0x82, SONYPI_EVENT_PKEY_P1
},
909 { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED
},
910 { 0x83, SONYPI_EVENT_PKEY_P2
},
911 { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED
},
912 { 0x84, SONYPI_EVENT_PKEY_P3
},
913 { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED
},
914 { 0x85, SONYPI_EVENT_PKEY_P4
},
915 { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED
},
916 { 0x86, SONYPI_EVENT_PKEY_P5
},
917 { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED
},
918 { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED
},
919 { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED
},
926 static void sony_nc_notify(struct acpi_device
*device
, u32 event
)
931 /* New-style event */
936 if (sony_find_snc_handle(0x100) == ev
)
938 if (sony_find_snc_handle(0x127) == ev
)
942 struct sony_nc_event
*key_event
;
944 if (sony_call_snc_handle(key_handle
, 0x200, &result
)) {
945 dprintk("sony_nc_notify, unable to decode"
946 " event 0x%.2x 0x%.2x\n", key_handle
,
948 /* restore the original event */
953 if (key_handle
== 0x100)
954 key_event
= sony_100_events
;
956 key_event
= sony_127_events
;
958 for (; key_event
->data
; key_event
++) {
959 if (key_event
->data
== ev
) {
960 ev
= key_event
->event
;
965 if (!key_event
->data
)
966 printk(KERN_INFO DRV_PFX
967 "Unknown event: 0x%x 0x%x\n",
971 sony_laptop_report_input_event(ev
);
973 } else if (sony_find_snc_handle(sony_rfkill_handle
) == ev
) {
974 sony_nc_rfkill_update();
978 sony_laptop_report_input_event(ev
);
980 dprintk("sony_nc_notify, event: 0x%.2x\n", ev
);
981 acpi_bus_generate_proc_event(sony_nc_acpi_device
, 1, ev
);
984 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
985 void *context
, void **return_value
)
987 struct acpi_device_info
*info
;
989 if (ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
990 printk(KERN_WARNING DRV_PFX
"method: name: %4.4s, args %X\n",
991 (char *)&info
->name
, info
->param_count
);
1002 static int sony_nc_function_setup(struct acpi_device
*device
)
1006 /* Enable all events */
1007 acpi_callsetfunc(sony_nc_acpi_handle
, "SN02", 0xffff, &result
);
1010 sony_call_snc_handle(0x0100, 0, &result
);
1011 sony_call_snc_handle(0x0101, 0, &result
);
1012 sony_call_snc_handle(0x0102, 0x100, &result
);
1013 sony_call_snc_handle(0x0127, 0, &result
);
1018 static int sony_nc_resume(struct acpi_device
*device
)
1020 struct sony_nc_value
*item
;
1023 for (item
= sony_nc_values
; item
->name
; item
++) {
1028 ret
= acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
,
1031 printk("%s: %d\n", __func__
, ret
);
1036 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1038 if (acpi_callsetfunc(sony_nc_acpi_handle
, "ECON", 1, NULL
))
1039 dprintk("ECON Method failed\n");
1042 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1044 dprintk("Doing SNC setup\n");
1045 sony_nc_function_setup(device
);
1048 /* set the last requested brightness level */
1049 if (sony_backlight_device
&&
1050 sony_backlight_update_status(sony_backlight_device
) < 0)
1051 printk(KERN_WARNING DRV_PFX
"unable to restore brightness level\n");
1053 /* re-read rfkill state */
1054 sony_nc_rfkill_update();
1059 static void sony_nc_rfkill_cleanup(void)
1063 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1064 if (sony_rfkill_devices
[i
]) {
1065 rfkill_unregister(sony_rfkill_devices
[i
]);
1066 rfkill_destroy(sony_rfkill_devices
[i
]);
1071 static int sony_nc_rfkill_set(void *data
, bool blocked
)
1074 int argument
= sony_rfkill_address
[(long) data
] + 0x100;
1077 argument
|= 0xff0000;
1079 return sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1082 static const struct rfkill_ops sony_rfkill_ops
= {
1083 .set_block
= sony_nc_rfkill_set
,
1086 static int sony_nc_setup_rfkill(struct acpi_device
*device
,
1087 enum sony_nc_rfkill nc_type
)
1091 enum rfkill_type type
;
1098 type
= RFKILL_TYPE_WLAN
;
1101 case SONY_BLUETOOTH
:
1102 type
= RFKILL_TYPE_BLUETOOTH
;
1103 name
= "sony-bluetooth";
1106 type
= RFKILL_TYPE_WWAN
;
1110 type
= RFKILL_TYPE_WIMAX
;
1111 name
= "sony-wimax";
1117 rfk
= rfkill_alloc(name
, &device
->dev
, type
,
1118 &sony_rfkill_ops
, (void *)nc_type
);
1122 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1123 hwblock
= !(result
& 0x1);
1124 rfkill_set_hw_state(rfk
, hwblock
);
1126 err
= rfkill_register(rfk
);
1128 rfkill_destroy(rfk
);
1131 sony_rfkill_devices
[nc_type
] = rfk
;
1135 static void sony_nc_rfkill_update()
1137 enum sony_nc_rfkill i
;
1141 sony_call_snc_handle(sony_rfkill_handle
, 0x200, &result
);
1142 hwblock
= !(result
& 0x1);
1144 for (i
= 0; i
< N_SONY_RFKILL
; i
++) {
1145 int argument
= sony_rfkill_address
[i
];
1147 if (!sony_rfkill_devices
[i
])
1151 if (rfkill_set_hw_state(sony_rfkill_devices
[i
], true)) {
1152 /* we already know we're blocked */
1157 sony_call_snc_handle(sony_rfkill_handle
, argument
, &result
);
1158 rfkill_set_states(sony_rfkill_devices
[i
],
1159 !(result
& 0xf), false);
1163 static void sony_nc_rfkill_setup(struct acpi_device
*device
)
1168 struct acpi_object_list params
;
1169 union acpi_object in_obj
;
1170 union acpi_object
*device_enum
;
1171 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1173 offset
= sony_find_snc_handle(0x124);
1175 offset
= sony_find_snc_handle(0x135);
1179 sony_rfkill_handle
= 0x135;
1181 sony_rfkill_handle
= 0x124;
1182 dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle
);
1184 /* need to read the whole buffer returned by the acpi call to SN06
1185 * here otherwise we may miss some features
1188 params
.pointer
= &in_obj
;
1189 in_obj
.type
= ACPI_TYPE_INTEGER
;
1190 in_obj
.integer
.value
= offset
;
1191 status
= acpi_evaluate_object(sony_nc_acpi_handle
, "SN06", ¶ms
,
1193 if (ACPI_FAILURE(status
)) {
1194 dprintk("Radio device enumeration failed\n");
1198 device_enum
= (union acpi_object
*) buffer
.pointer
;
1199 if (!device_enum
|| device_enum
->type
!= ACPI_TYPE_BUFFER
) {
1200 printk(KERN_ERR
"Invalid SN06 return object 0x%.2x\n",
1205 /* the buffer is filled with magic numbers describing the devices
1206 * available, 0xff terminates the enumeration
1208 for (i
= 0; i
< device_enum
->buffer
.length
; i
++) {
1210 dev_code
= *(device_enum
->buffer
.pointer
+ i
);
1211 if (dev_code
== 0xff)
1214 dprintk("Radio devices, looking at 0x%.2x\n", dev_code
);
1216 if (dev_code
== 0 && !sony_rfkill_devices
[SONY_WIFI
])
1217 sony_nc_setup_rfkill(device
, SONY_WIFI
);
1219 if (dev_code
== 0x10 && !sony_rfkill_devices
[SONY_BLUETOOTH
])
1220 sony_nc_setup_rfkill(device
, SONY_BLUETOOTH
);
1222 if ((0xf0 & dev_code
) == 0x20 &&
1223 !sony_rfkill_devices
[SONY_WWAN
])
1224 sony_nc_setup_rfkill(device
, SONY_WWAN
);
1226 if (dev_code
== 0x30 && !sony_rfkill_devices
[SONY_WIMAX
])
1227 sony_nc_setup_rfkill(device
, SONY_WIMAX
);
1231 kfree(buffer
.pointer
);
1235 static int sony_nc_add(struct acpi_device
*device
)
1240 struct sony_nc_value
*item
;
1242 printk(KERN_INFO DRV_PFX
"%s v%s.\n",
1243 SONY_NC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
1245 sony_nc_acpi_device
= device
;
1246 strcpy(acpi_device_class(device
), "sony/hotkey");
1248 sony_nc_acpi_handle
= device
->handle
;
1250 /* read device status */
1251 result
= acpi_bus_get_status(device
);
1252 /* bail IFF the above call was successful and the device is not present */
1253 if (!result
&& !device
->status
.present
) {
1254 dprintk("Device not present\n");
1260 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, sony_nc_acpi_handle
,
1261 1, sony_walk_callback
, NULL
, NULL
, NULL
);
1262 if (ACPI_FAILURE(status
)) {
1263 printk(KERN_WARNING DRV_PFX
"unable to walk acpi resources\n");
1269 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "ECON",
1271 if (acpi_callsetfunc(sony_nc_acpi_handle
, "ECON", 1, NULL
))
1272 dprintk("ECON Method failed\n");
1275 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "SN00",
1277 dprintk("Doing SNC setup\n");
1278 sony_nc_function_setup(device
);
1279 sony_nc_rfkill_setup(device
);
1282 /* setup input devices and helper fifo */
1283 result
= sony_laptop_setup_input(device
);
1285 printk(KERN_ERR DRV_PFX
1286 "Unable to create input devices.\n");
1290 if (acpi_video_backlight_support()) {
1291 printk(KERN_INFO DRV_PFX
"brightness ignored, must be "
1292 "controlled by ACPI video driver\n");
1293 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "GBRT",
1295 struct backlight_properties props
;
1296 memset(&props
, 0, sizeof(struct backlight_properties
));
1297 props
.max_brightness
= SONY_MAX_BRIGHTNESS
- 1;
1298 sony_backlight_device
= backlight_device_register("sony", NULL
,
1300 &sony_backlight_ops
,
1303 if (IS_ERR(sony_backlight_device
)) {
1304 printk(KERN_WARNING DRV_PFX
"unable to register backlight device\n");
1305 sony_backlight_device
= NULL
;
1307 sony_backlight_device
->props
.brightness
=
1308 sony_backlight_get_brightness
1309 (sony_backlight_device
);
1314 result
= sony_pf_add();
1318 /* create sony_pf sysfs attributes related to the SNC device */
1319 for (item
= sony_nc_values
; item
->name
; ++item
) {
1321 if (!debug
&& item
->debug
)
1324 /* find the available acpiget as described in the DSDT */
1325 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
1326 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
1329 dprintk("Found %s getter: %s\n",
1330 item
->name
, *item
->acpiget
);
1331 item
->devattr
.attr
.mode
|= S_IRUGO
;
1336 /* find the available acpiset as described in the DSDT */
1337 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
1338 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
1341 dprintk("Found %s setter: %s\n",
1342 item
->name
, *item
->acpiset
);
1343 item
->devattr
.attr
.mode
|= S_IWUSR
;
1348 if (item
->devattr
.attr
.mode
!= 0) {
1350 device_create_file(&sony_pf_device
->dev
,
1360 for (item
= sony_nc_values
; item
->name
; ++item
) {
1361 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
1366 if (sony_backlight_device
)
1367 backlight_device_unregister(sony_backlight_device
);
1369 sony_laptop_remove_input();
1372 sony_nc_rfkill_cleanup();
1376 static int sony_nc_remove(struct acpi_device
*device
, int type
)
1378 struct sony_nc_value
*item
;
1380 if (sony_backlight_device
)
1381 backlight_device_unregister(sony_backlight_device
);
1383 sony_nc_acpi_device
= NULL
;
1385 for (item
= sony_nc_values
; item
->name
; ++item
) {
1386 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
1390 sony_laptop_remove_input();
1391 sony_nc_rfkill_cleanup();
1392 dprintk(SONY_NC_DRIVER_NAME
" removed.\n");
1397 static const struct acpi_device_id sony_device_ids
[] = {
1402 MODULE_DEVICE_TABLE(acpi
, sony_device_ids
);
1404 static const struct acpi_device_id sony_nc_device_ids
[] = {
1409 static struct acpi_driver sony_nc_driver
= {
1410 .name
= SONY_NC_DRIVER_NAME
,
1411 .class = SONY_NC_CLASS
,
1412 .ids
= sony_nc_device_ids
,
1413 .owner
= THIS_MODULE
,
1416 .remove
= sony_nc_remove
,
1417 .resume
= sony_nc_resume
,
1418 .notify
= sony_nc_notify
,
1422 /*********** SPIC (SNY6001) Device ***********/
1424 #define SONYPI_DEVICE_TYPE1 0x00000001
1425 #define SONYPI_DEVICE_TYPE2 0x00000002
1426 #define SONYPI_DEVICE_TYPE3 0x00000004
1427 #define SONYPI_DEVICE_TYPE4 0x00000008
1429 #define SONYPI_TYPE1_OFFSET 0x04
1430 #define SONYPI_TYPE2_OFFSET 0x12
1431 #define SONYPI_TYPE3_OFFSET 0x12
1433 struct sony_pic_ioport
{
1434 struct acpi_resource_io io1
;
1435 struct acpi_resource_io io2
;
1436 struct list_head list
;
1439 struct sony_pic_irq
{
1440 struct acpi_resource_irq irq
;
1441 struct list_head list
;
1444 struct sonypi_eventtypes
{
1447 struct sonypi_event
*events
;
1450 struct sony_pic_dev
{
1451 struct acpi_device
*acpi_dev
;
1452 struct sony_pic_irq
*cur_irq
;
1453 struct sony_pic_ioport
*cur_ioport
;
1454 struct list_head interrupts
;
1455 struct list_head ioports
;
1457 struct sonypi_eventtypes
*event_types
;
1458 int (*handle_irq
)(const u8
, const u8
);
1466 static struct sony_pic_dev spic_dev
= {
1467 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
1468 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
1471 static int spic_drv_registered
;
1474 #define SONYPI_JOGGER_MASK 0x00000001
1475 #define SONYPI_CAPTURE_MASK 0x00000002
1476 #define SONYPI_FNKEY_MASK 0x00000004
1477 #define SONYPI_BLUETOOTH_MASK 0x00000008
1478 #define SONYPI_PKEY_MASK 0x00000010
1479 #define SONYPI_BACK_MASK 0x00000020
1480 #define SONYPI_HELP_MASK 0x00000040
1481 #define SONYPI_LID_MASK 0x00000080
1482 #define SONYPI_ZOOM_MASK 0x00000100
1483 #define SONYPI_THUMBPHRASE_MASK 0x00000200
1484 #define SONYPI_MEYE_MASK 0x00000400
1485 #define SONYPI_MEMORYSTICK_MASK 0x00000800
1486 #define SONYPI_BATTERY_MASK 0x00001000
1487 #define SONYPI_WIRELESS_MASK 0x00002000
1489 struct sonypi_event
{
1494 /* The set of possible button release events */
1495 static struct sonypi_event sonypi_releaseev
[] = {
1496 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
1500 /* The set of possible jogger events */
1501 static struct sonypi_event sonypi_joggerev
[] = {
1502 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
1503 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
1504 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
1505 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
1506 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
1507 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
1508 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
1509 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
1510 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
1511 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
1512 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
1513 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
1514 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
1518 /* The set of possible capture button events */
1519 static struct sonypi_event sonypi_captureev
[] = {
1520 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
1521 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
1522 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED
},
1523 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
1527 /* The set of possible fnkeys events */
1528 static struct sonypi_event sonypi_fnkeyev
[] = {
1529 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
1530 { 0x11, SONYPI_EVENT_FNKEY_F1
},
1531 { 0x12, SONYPI_EVENT_FNKEY_F2
},
1532 { 0x13, SONYPI_EVENT_FNKEY_F3
},
1533 { 0x14, SONYPI_EVENT_FNKEY_F4
},
1534 { 0x15, SONYPI_EVENT_FNKEY_F5
},
1535 { 0x16, SONYPI_EVENT_FNKEY_F6
},
1536 { 0x17, SONYPI_EVENT_FNKEY_F7
},
1537 { 0x18, SONYPI_EVENT_FNKEY_F8
},
1538 { 0x19, SONYPI_EVENT_FNKEY_F9
},
1539 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
1540 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
1541 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
1542 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
1543 { 0x21, SONYPI_EVENT_FNKEY_1
},
1544 { 0x22, SONYPI_EVENT_FNKEY_2
},
1545 { 0x31, SONYPI_EVENT_FNKEY_D
},
1546 { 0x32, SONYPI_EVENT_FNKEY_E
},
1547 { 0x33, SONYPI_EVENT_FNKEY_F
},
1548 { 0x34, SONYPI_EVENT_FNKEY_S
},
1549 { 0x35, SONYPI_EVENT_FNKEY_B
},
1550 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
1554 /* The set of possible program key events */
1555 static struct sonypi_event sonypi_pkeyev
[] = {
1556 { 0x01, SONYPI_EVENT_PKEY_P1
},
1557 { 0x02, SONYPI_EVENT_PKEY_P2
},
1558 { 0x04, SONYPI_EVENT_PKEY_P3
},
1559 { 0x20, SONYPI_EVENT_PKEY_P1
},
1563 /* The set of possible bluetooth events */
1564 static struct sonypi_event sonypi_blueev
[] = {
1565 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
1566 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
1567 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
1571 /* The set of possible wireless events */
1572 static struct sonypi_event sonypi_wlessev
[] = {
1573 { 0x59, SONYPI_EVENT_WIRELESS_ON
},
1574 { 0x5a, SONYPI_EVENT_WIRELESS_OFF
},
1578 /* The set of possible back button events */
1579 static struct sonypi_event sonypi_backev
[] = {
1580 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
1584 /* The set of possible help button events */
1585 static struct sonypi_event sonypi_helpev
[] = {
1586 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
1591 /* The set of possible lid events */
1592 static struct sonypi_event sonypi_lidev
[] = {
1593 { 0x51, SONYPI_EVENT_LID_CLOSED
},
1594 { 0x50, SONYPI_EVENT_LID_OPENED
},
1598 /* The set of possible zoom events */
1599 static struct sonypi_event sonypi_zoomev
[] = {
1600 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
1601 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED
},
1602 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED
},
1603 { 0x04, SONYPI_EVENT_ZOOM_PRESSED
},
1607 /* The set of possible thumbphrase events */
1608 static struct sonypi_event sonypi_thumbphraseev
[] = {
1609 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
1613 /* The set of possible motioneye camera events */
1614 static struct sonypi_event sonypi_meyeev
[] = {
1615 { 0x00, SONYPI_EVENT_MEYE_FACE
},
1616 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
1620 /* The set of possible memorystick events */
1621 static struct sonypi_event sonypi_memorystickev
[] = {
1622 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
1623 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
1627 /* The set of possible battery events */
1628 static struct sonypi_event sonypi_batteryev
[] = {
1629 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
1630 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
1634 /* The set of possible volume events */
1635 static struct sonypi_event sonypi_volumeev
[] = {
1636 { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED
},
1637 { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED
},
1641 /* The set of possible brightness events */
1642 static struct sonypi_event sonypi_brightnessev
[] = {
1643 { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED
},
1647 static struct sonypi_eventtypes type1_events
[] = {
1648 { 0, 0xffffffff, sonypi_releaseev
},
1649 { 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
1650 { 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
1651 { 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1652 { 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1653 { 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1654 { 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1655 { 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1656 { 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1657 { 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1660 static struct sonypi_eventtypes type2_events
[] = {
1661 { 0, 0xffffffff, sonypi_releaseev
},
1662 { 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
1663 { 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1664 { 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1665 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1666 { 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1667 { 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1668 { 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
1669 { 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
1670 { 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
1671 { 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
1672 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1673 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1674 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1677 static struct sonypi_eventtypes type3_events
[] = {
1678 { 0, 0xffffffff, sonypi_releaseev
},
1679 { 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1680 { 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
1681 { 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1682 { 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1683 { 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1684 { 0x05, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1685 { 0x05, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
1686 { 0x05, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1687 { 0x05, SONYPI_PKEY_MASK
, sonypi_volumeev
},
1688 { 0x05, SONYPI_PKEY_MASK
, sonypi_brightnessev
},
1692 /* low level spic calls */
1693 #define ITERATIONS_LONG 10000
1694 #define ITERATIONS_SHORT 10
1695 #define wait_on_command(command, iterations) { \
1696 unsigned int n = iterations; \
1697 while (--n && (command)) \
1700 dprintk("command failed at %s : %s (line %d)\n", \
1701 __FILE__, __func__, __LINE__); \
1704 static u8
sony_pic_call1(u8 dev
)
1708 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1710 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1711 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1712 v2
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1713 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev
, (v2
<< 8) | v1
);
1717 static u8
sony_pic_call2(u8 dev
, u8 fn
)
1721 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1723 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1724 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2,
1726 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
1727 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1728 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev
, fn
, v1
);
1732 static u8
sony_pic_call3(u8 dev
, u8 fn
, u8 v
)
1736 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1737 outb(dev
, spic_dev
.cur_ioport
->io1
.minimum
+ 4);
1738 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1739 outb(fn
, spic_dev
.cur_ioport
->io1
.minimum
);
1740 wait_on_command(inb_p(spic_dev
.cur_ioport
->io1
.minimum
+ 4) & 2, ITERATIONS_LONG
);
1741 outb(v
, spic_dev
.cur_ioport
->io1
.minimum
);
1742 v1
= inb_p(spic_dev
.cur_ioport
->io1
.minimum
);
1743 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
1749 * minidrivers for SPIC models
1751 static int type3_handle_irq(const u8 data_mask
, const u8 ev
)
1754 * 0x31 could mean we have to take some extra action and wait for
1755 * the next irq for some Type3 models, it will generate a new
1756 * irq and we can read new data from the device:
1757 * - 0x5c and 0x5f requires 0xA0
1758 * - 0x61 requires 0xB3
1760 if (data_mask
== 0x31) {
1761 if (ev
== 0x5c || ev
== 0x5f)
1762 sony_pic_call1(0xA0);
1763 else if (ev
== 0x61)
1764 sony_pic_call1(0xB3);
1770 static void sony_pic_detect_device_type(struct sony_pic_dev
*dev
)
1772 struct pci_dev
*pcidev
;
1774 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1775 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
1777 dev
->model
= SONYPI_DEVICE_TYPE1
;
1778 dev
->evport_offset
= SONYPI_TYPE1_OFFSET
;
1779 dev
->event_types
= type1_events
;
1783 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1784 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
);
1786 dev
->model
= SONYPI_DEVICE_TYPE2
;
1787 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
1788 dev
->event_types
= type2_events
;
1792 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1793 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
);
1795 dev
->model
= SONYPI_DEVICE_TYPE3
;
1796 dev
->handle_irq
= type3_handle_irq
;
1797 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1798 dev
->event_types
= type3_events
;
1802 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1803 PCI_DEVICE_ID_INTEL_ICH8_4
, NULL
);
1805 dev
->model
= SONYPI_DEVICE_TYPE3
;
1806 dev
->handle_irq
= type3_handle_irq
;
1807 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1808 dev
->event_types
= type3_events
;
1812 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1813 PCI_DEVICE_ID_INTEL_ICH9_1
, NULL
);
1815 dev
->model
= SONYPI_DEVICE_TYPE3
;
1816 dev
->handle_irq
= type3_handle_irq
;
1817 dev
->evport_offset
= SONYPI_TYPE3_OFFSET
;
1818 dev
->event_types
= type3_events
;
1823 dev
->model
= SONYPI_DEVICE_TYPE2
;
1824 dev
->evport_offset
= SONYPI_TYPE2_OFFSET
;
1825 dev
->event_types
= type2_events
;
1829 pci_dev_put(pcidev
);
1831 printk(KERN_INFO DRV_PFX
"detected Type%d model\n",
1832 dev
->model
== SONYPI_DEVICE_TYPE1
? 1 :
1833 dev
->model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
1836 /* camera tests and poweron/poweroff */
1837 #define SONYPI_CAMERA_PICTURE 5
1838 #define SONYPI_CAMERA_CONTROL 0x10
1840 #define SONYPI_CAMERA_BRIGHTNESS 0
1841 #define SONYPI_CAMERA_CONTRAST 1
1842 #define SONYPI_CAMERA_HUE 2
1843 #define SONYPI_CAMERA_COLOR 3
1844 #define SONYPI_CAMERA_SHARPNESS 4
1846 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1847 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1848 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1849 #define SONYPI_CAMERA_MUTE_MASK 0x40
1851 /* the rest don't need a loop until not 0xff */
1852 #define SONYPI_CAMERA_AGC 6
1853 #define SONYPI_CAMERA_AGC_MASK 0x30
1854 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
1856 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1857 #define SONYPI_CAMERA_CONTROL 0x10
1859 #define SONYPI_CAMERA_STATUS 7
1860 #define SONYPI_CAMERA_STATUS_READY 0x2
1861 #define SONYPI_CAMERA_STATUS_POSITION 0x4
1863 #define SONYPI_DIRECTION_BACKWARDS 0x4
1865 #define SONYPI_CAMERA_REVISION 8
1866 #define SONYPI_CAMERA_ROMVERSION 9
1868 static int __sony_pic_camera_ready(void)
1872 v
= sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS
);
1873 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
1876 static int __sony_pic_camera_off(void)
1879 printk(KERN_WARNING DRV_PFX
"camera control not enabled\n");
1883 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
,
1884 SONYPI_CAMERA_MUTE_MASK
),
1887 if (spic_dev
.camera_power
) {
1888 sony_pic_call2(0x91, 0);
1889 spic_dev
.camera_power
= 0;
1894 static int __sony_pic_camera_on(void)
1899 printk(KERN_WARNING DRV_PFX
"camera control not enabled\n");
1903 if (spic_dev
.camera_power
)
1906 for (j
= 5; j
> 0; j
--) {
1908 for (x
= 0; x
< 100 && sony_pic_call2(0x91, 0x1); x
++)
1910 sony_pic_call1(0x93);
1912 for (i
= 400; i
> 0; i
--) {
1913 if (__sony_pic_camera_ready())
1922 printk(KERN_WARNING DRV_PFX
"failed to power on camera\n");
1926 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL
,
1930 spic_dev
.camera_power
= 1;
1934 /* External camera command (exported to the motion eye v4l driver) */
1935 int sony_pic_camera_command(int command
, u8 value
)
1940 mutex_lock(&spic_dev
.lock
);
1943 case SONY_PIC_COMMAND_SETCAMERA
:
1945 __sony_pic_camera_on();
1947 __sony_pic_camera_off();
1949 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS
:
1950 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS
, value
),
1953 case SONY_PIC_COMMAND_SETCAMERACONTRAST
:
1954 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST
, value
),
1957 case SONY_PIC_COMMAND_SETCAMERAHUE
:
1958 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE
, value
),
1961 case SONY_PIC_COMMAND_SETCAMERACOLOR
:
1962 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR
, value
),
1965 case SONY_PIC_COMMAND_SETCAMERASHARPNESS
:
1966 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS
, value
),
1969 case SONY_PIC_COMMAND_SETCAMERAPICTURE
:
1970 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE
, value
),
1973 case SONY_PIC_COMMAND_SETCAMERAAGC
:
1974 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC
, value
),
1978 printk(KERN_ERR DRV_PFX
"sony_pic_camera_command invalid: %d\n",
1982 mutex_unlock(&spic_dev
.lock
);
1985 EXPORT_SYMBOL(sony_pic_camera_command
);
1987 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
1988 static void __sony_pic_set_wwanpower(u8 state
)
1991 if (spic_dev
.wwan_power
== state
)
1993 sony_pic_call2(0xB0, state
);
1994 sony_pic_call1(0x82);
1995 spic_dev
.wwan_power
= state
;
1998 static ssize_t
sony_pic_wwanpower_store(struct device
*dev
,
1999 struct device_attribute
*attr
,
2000 const char *buffer
, size_t count
)
2002 unsigned long value
;
2006 value
= simple_strtoul(buffer
, NULL
, 10);
2007 mutex_lock(&spic_dev
.lock
);
2008 __sony_pic_set_wwanpower(value
);
2009 mutex_unlock(&spic_dev
.lock
);
2014 static ssize_t
sony_pic_wwanpower_show(struct device
*dev
,
2015 struct device_attribute
*attr
, char *buffer
)
2018 mutex_lock(&spic_dev
.lock
);
2019 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.wwan_power
);
2020 mutex_unlock(&spic_dev
.lock
);
2024 /* bluetooth subsystem power state */
2025 static void __sony_pic_set_bluetoothpower(u8 state
)
2028 if (spic_dev
.bluetooth_power
== state
)
2030 sony_pic_call2(0x96, state
);
2031 sony_pic_call1(0x82);
2032 spic_dev
.bluetooth_power
= state
;
2035 static ssize_t
sony_pic_bluetoothpower_store(struct device
*dev
,
2036 struct device_attribute
*attr
,
2037 const char *buffer
, size_t count
)
2039 unsigned long value
;
2043 value
= simple_strtoul(buffer
, NULL
, 10);
2044 mutex_lock(&spic_dev
.lock
);
2045 __sony_pic_set_bluetoothpower(value
);
2046 mutex_unlock(&spic_dev
.lock
);
2051 static ssize_t
sony_pic_bluetoothpower_show(struct device
*dev
,
2052 struct device_attribute
*attr
, char *buffer
)
2055 mutex_lock(&spic_dev
.lock
);
2056 count
= snprintf(buffer
, PAGE_SIZE
, "%d\n", spic_dev
.bluetooth_power
);
2057 mutex_unlock(&spic_dev
.lock
);
2062 /* FAN0 information (reverse engineered from ACPI tables) */
2063 #define SONY_PIC_FAN0_STATUS 0x93
2064 static int sony_pic_set_fanspeed(unsigned long value
)
2066 return ec_write(SONY_PIC_FAN0_STATUS
, value
);
2069 static int sony_pic_get_fanspeed(u8
*value
)
2071 return ec_read(SONY_PIC_FAN0_STATUS
, value
);
2074 static ssize_t
sony_pic_fanspeed_store(struct device
*dev
,
2075 struct device_attribute
*attr
,
2076 const char *buffer
, size_t count
)
2078 unsigned long value
;
2082 value
= simple_strtoul(buffer
, NULL
, 10);
2083 if (sony_pic_set_fanspeed(value
))
2089 static ssize_t
sony_pic_fanspeed_show(struct device
*dev
,
2090 struct device_attribute
*attr
, char *buffer
)
2093 if (sony_pic_get_fanspeed(&value
))
2096 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
2099 #define SPIC_ATTR(_name, _mode) \
2100 struct device_attribute spic_attr_##_name = __ATTR(_name, \
2101 _mode, sony_pic_## _name ##_show, \
2102 sony_pic_## _name ##_store)
2104 static SPIC_ATTR(bluetoothpower
, 0644);
2105 static SPIC_ATTR(wwanpower
, 0644);
2106 static SPIC_ATTR(fanspeed
, 0644);
2108 static struct attribute
*spic_attributes
[] = {
2109 &spic_attr_bluetoothpower
.attr
,
2110 &spic_attr_wwanpower
.attr
,
2111 &spic_attr_fanspeed
.attr
,
2115 static struct attribute_group spic_attribute_group
= {
2116 .attrs
= spic_attributes
2119 /******** SONYPI compatibility **********/
2120 #ifdef CONFIG_SONYPI_COMPAT
2122 /* battery / brightness / temperature addresses */
2123 #define SONYPI_BAT_FLAGS 0x81
2124 #define SONYPI_LCD_LIGHT 0x96
2125 #define SONYPI_BAT1_PCTRM 0xa0
2126 #define SONYPI_BAT1_LEFT 0xa2
2127 #define SONYPI_BAT1_MAXRT 0xa4
2128 #define SONYPI_BAT2_PCTRM 0xa8
2129 #define SONYPI_BAT2_LEFT 0xaa
2130 #define SONYPI_BAT2_MAXRT 0xac
2131 #define SONYPI_BAT1_MAXTK 0xb0
2132 #define SONYPI_BAT1_FULL 0xb2
2133 #define SONYPI_BAT2_MAXTK 0xb8
2134 #define SONYPI_BAT2_FULL 0xba
2135 #define SONYPI_TEMP_STATUS 0xC1
2137 struct sonypi_compat_s
{
2138 struct fasync_struct
*fifo_async
;
2140 spinlock_t fifo_lock
;
2141 wait_queue_head_t fifo_proc_list
;
2142 atomic_t open_count
;
2144 static struct sonypi_compat_s sonypi_compat
= {
2145 .open_count
= ATOMIC_INIT(0),
2148 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
2150 return fasync_helper(fd
, filp
, on
, &sonypi_compat
.fifo_async
);
2153 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
2155 atomic_dec(&sonypi_compat
.open_count
);
2159 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
2161 /* Flush input queue on first open */
2162 unsigned long flags
;
2164 spin_lock_irqsave(&sonypi_compat
.fifo_lock
, flags
);
2166 if (atomic_inc_return(&sonypi_compat
.open_count
) == 1)
2167 kfifo_reset(&sonypi_compat
.fifo
);
2169 spin_unlock_irqrestore(&sonypi_compat
.fifo_lock
, flags
);
2174 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
2175 size_t count
, loff_t
*pos
)
2180 if ((kfifo_len(&sonypi_compat
.fifo
) == 0) &&
2181 (file
->f_flags
& O_NONBLOCK
))
2184 ret
= wait_event_interruptible(sonypi_compat
.fifo_proc_list
,
2185 kfifo_len(&sonypi_compat
.fifo
) != 0);
2189 while (ret
< count
&&
2190 (kfifo_out_locked(&sonypi_compat
.fifo
, &c
, sizeof(c
),
2191 &sonypi_compat
.fifo_lock
) == sizeof(c
))) {
2192 if (put_user(c
, buf
++))
2198 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
2199 inode
->i_atime
= current_fs_time(inode
->i_sb
);
2205 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
2207 poll_wait(file
, &sonypi_compat
.fifo_proc_list
, wait
);
2208 if (kfifo_len(&sonypi_compat
.fifo
))
2209 return POLLIN
| POLLRDNORM
;
2213 static int ec_read16(u8 addr
, u16
*value
)
2216 if (ec_read(addr
, &val_lb
))
2218 if (ec_read(addr
+ 1, &val_hb
))
2220 *value
= val_lb
| (val_hb
<< 8);
2224 static long sonypi_misc_ioctl(struct file
*fp
, unsigned int cmd
,
2228 void __user
*argp
= (void __user
*)arg
;
2233 mutex_lock(&spic_dev
.lock
);
2235 case SONYPI_IOCGBRT
:
2236 if (sony_backlight_device
== NULL
) {
2240 if (acpi_callgetfunc(sony_nc_acpi_handle
, "GBRT", &value
)) {
2244 val8
= ((value
& 0xff) - 1) << 5;
2245 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2248 case SONYPI_IOCSBRT
:
2249 if (sony_backlight_device
== NULL
) {
2253 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2257 if (acpi_callsetfunc(sony_nc_acpi_handle
, "SBRT",
2258 (val8
>> 5) + 1, NULL
)) {
2262 /* sync the backlight device status */
2263 sony_backlight_device
->props
.brightness
=
2264 sony_backlight_get_brightness(sony_backlight_device
);
2266 case SONYPI_IOCGBAT1CAP
:
2267 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
2271 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2274 case SONYPI_IOCGBAT1REM
:
2275 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
2279 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2282 case SONYPI_IOCGBAT2CAP
:
2283 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
2287 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2290 case SONYPI_IOCGBAT2REM
:
2291 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
2295 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
2298 case SONYPI_IOCGBATFLAGS
:
2299 if (ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
2304 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2307 case SONYPI_IOCGBLUE
:
2308 val8
= spic_dev
.bluetooth_power
;
2309 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2312 case SONYPI_IOCSBLUE
:
2313 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2317 __sony_pic_set_bluetoothpower(val8
);
2320 case SONYPI_IOCGFAN
:
2321 if (sony_pic_get_fanspeed(&val8
)) {
2325 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2328 case SONYPI_IOCSFAN
:
2329 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
2333 if (sony_pic_set_fanspeed(val8
))
2336 /* GET Temperature (useful under APM) */
2337 case SONYPI_IOCGTEMP
:
2338 if (ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
2342 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
2348 mutex_unlock(&spic_dev
.lock
);
2352 static const struct file_operations sonypi_misc_fops
= {
2353 .owner
= THIS_MODULE
,
2354 .read
= sonypi_misc_read
,
2355 .poll
= sonypi_misc_poll
,
2356 .open
= sonypi_misc_open
,
2357 .release
= sonypi_misc_release
,
2358 .fasync
= sonypi_misc_fasync
,
2359 .unlocked_ioctl
= sonypi_misc_ioctl
,
2362 static struct miscdevice sonypi_misc_device
= {
2363 .minor
= MISC_DYNAMIC_MINOR
,
2365 .fops
= &sonypi_misc_fops
,
2368 static void sonypi_compat_report_event(u8 event
)
2370 kfifo_in_locked(&sonypi_compat
.fifo
, (unsigned char *)&event
,
2371 sizeof(event
), &sonypi_compat
.fifo_lock
);
2372 kill_fasync(&sonypi_compat
.fifo_async
, SIGIO
, POLL_IN
);
2373 wake_up_interruptible(&sonypi_compat
.fifo_proc_list
);
2376 static int sonypi_compat_init(void)
2380 spin_lock_init(&sonypi_compat
.fifo_lock
);
2382 kfifo_alloc(&sonypi_compat
.fifo
, SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
);
2384 printk(KERN_ERR DRV_PFX
"kfifo_alloc failed\n");
2388 init_waitqueue_head(&sonypi_compat
.fifo_proc_list
);
2391 sonypi_misc_device
.minor
= minor
;
2392 error
= misc_register(&sonypi_misc_device
);
2394 printk(KERN_ERR DRV_PFX
"misc_register failed\n");
2395 goto err_free_kfifo
;
2398 printk(KERN_INFO DRV_PFX
"device allocated minor is %d\n",
2399 sonypi_misc_device
.minor
);
2404 kfifo_free(&sonypi_compat
.fifo
);
2408 static void sonypi_compat_exit(void)
2410 misc_deregister(&sonypi_misc_device
);
2411 kfifo_free(&sonypi_compat
.fifo
);
2414 static int sonypi_compat_init(void) { return 0; }
2415 static void sonypi_compat_exit(void) { }
2416 static void sonypi_compat_report_event(u8 event
) { }
2417 #endif /* CONFIG_SONYPI_COMPAT */
2423 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
2426 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
2428 switch (resource
->type
) {
2429 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
2431 /* start IO enumeration */
2432 struct sony_pic_ioport
*ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
2436 list_add(&ioport
->list
, &dev
->ioports
);
2440 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
2441 /* end IO enumeration */
2444 case ACPI_RESOURCE_TYPE_IRQ
:
2446 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
2447 struct sony_pic_irq
*interrupt
= NULL
;
2448 if (!p
|| !p
->interrupt_count
) {
2450 * IRQ descriptors may have no IRQ# bits set,
2451 * particularly those those w/ _STA disabled
2453 dprintk("Blank IRQ resource\n");
2456 for (i
= 0; i
< p
->interrupt_count
; i
++) {
2457 if (!p
->interrupts
[i
]) {
2458 printk(KERN_WARNING DRV_PFX
2463 interrupt
= kzalloc(sizeof(*interrupt
),
2468 list_add(&interrupt
->list
, &dev
->interrupts
);
2469 interrupt
->irq
.triggering
= p
->triggering
;
2470 interrupt
->irq
.polarity
= p
->polarity
;
2471 interrupt
->irq
.sharable
= p
->sharable
;
2472 interrupt
->irq
.interrupt_count
= 1;
2473 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
2477 case ACPI_RESOURCE_TYPE_IO
:
2479 struct acpi_resource_io
*io
= &resource
->data
.io
;
2480 struct sony_pic_ioport
*ioport
=
2481 list_first_entry(&dev
->ioports
, struct sony_pic_ioport
, list
);
2483 dprintk("Blank IO resource\n");
2487 if (!ioport
->io1
.minimum
) {
2488 memcpy(&ioport
->io1
, io
, sizeof(*io
));
2489 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport
->io1
.minimum
,
2490 ioport
->io1
.address_length
);
2492 else if (!ioport
->io2
.minimum
) {
2493 memcpy(&ioport
->io2
, io
, sizeof(*io
));
2494 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport
->io2
.minimum
,
2495 ioport
->io2
.address_length
);
2498 printk(KERN_ERR DRV_PFX
"Unknown SPIC Type, more than 2 IO Ports\n");
2504 dprintk("Resource %d isn't an IRQ nor an IO port\n",
2507 case ACPI_RESOURCE_TYPE_END_TAG
:
2510 return AE_CTRL_TERMINATE
;
2513 static int sony_pic_possible_resources(struct acpi_device
*device
)
2516 acpi_status status
= AE_OK
;
2521 /* get device status */
2522 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
2523 dprintk("Evaluating _STA\n");
2524 result
= acpi_bus_get_status(device
);
2526 printk(KERN_WARNING DRV_PFX
"Unable to read status\n");
2530 if (!device
->status
.enabled
)
2531 dprintk("Device disabled\n");
2533 dprintk("Device enabled\n");
2536 * Query and parse 'method'
2538 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
2539 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
2540 sony_pic_read_possible_resource
, &spic_dev
);
2541 if (ACPI_FAILURE(status
)) {
2542 printk(KERN_WARNING DRV_PFX
2543 "Failure evaluating %s\n",
2552 * Disable the spic device by calling its _DIS method
2554 static int sony_pic_disable(struct acpi_device
*device
)
2556 acpi_status ret
= acpi_evaluate_object(device
->handle
, "_DIS", NULL
,
2559 if (ACPI_FAILURE(ret
) && ret
!= AE_NOT_FOUND
)
2562 dprintk("Device disabled\n");
2568 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
2570 * Call _SRS to set current resources
2572 static int sony_pic_enable(struct acpi_device
*device
,
2573 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
2577 /* Type 1 resource layout is:
2583 * Type 2 and 3 resource layout is:
2589 struct acpi_resource res1
;
2590 struct acpi_resource res2
;
2591 struct acpi_resource res3
;
2592 struct acpi_resource res4
;
2594 struct acpi_buffer buffer
= { 0, NULL
};
2596 if (!ioport
|| !irq
)
2599 /* init acpi_buffer */
2600 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
2604 buffer
.length
= sizeof(*resource
) + 1;
2605 buffer
.pointer
= resource
;
2607 /* setup Type 1 resources */
2608 if (spic_dev
.model
== SONYPI_DEVICE_TYPE1
) {
2610 /* setup io resources */
2611 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
2612 resource
->res1
.length
= sizeof(struct acpi_resource
);
2613 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
2614 sizeof(struct acpi_resource_io
));
2616 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IO
;
2617 resource
->res2
.length
= sizeof(struct acpi_resource
);
2618 memcpy(&resource
->res2
.data
.io
, &ioport
->io2
,
2619 sizeof(struct acpi_resource_io
));
2621 /* setup irq resource */
2622 resource
->res3
.type
= ACPI_RESOURCE_TYPE_IRQ
;
2623 resource
->res3
.length
= sizeof(struct acpi_resource
);
2624 memcpy(&resource
->res3
.data
.irq
, &irq
->irq
,
2625 sizeof(struct acpi_resource_irq
));
2626 /* we requested a shared irq */
2627 resource
->res3
.data
.irq
.sharable
= ACPI_SHARED
;
2629 resource
->res4
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
2632 /* setup Type 2/3 resources */
2634 /* setup io resource */
2635 resource
->res1
.type
= ACPI_RESOURCE_TYPE_IO
;
2636 resource
->res1
.length
= sizeof(struct acpi_resource
);
2637 memcpy(&resource
->res1
.data
.io
, &ioport
->io1
,
2638 sizeof(struct acpi_resource_io
));
2640 /* setup irq resource */
2641 resource
->res2
.type
= ACPI_RESOURCE_TYPE_IRQ
;
2642 resource
->res2
.length
= sizeof(struct acpi_resource
);
2643 memcpy(&resource
->res2
.data
.irq
, &irq
->irq
,
2644 sizeof(struct acpi_resource_irq
));
2645 /* we requested a shared irq */
2646 resource
->res2
.data
.irq
.sharable
= ACPI_SHARED
;
2648 resource
->res3
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
2651 /* Attempt to set the resource */
2652 dprintk("Evaluating _SRS\n");
2653 status
= acpi_set_current_resources(device
->handle
, &buffer
);
2655 /* check for total failure */
2656 if (ACPI_FAILURE(status
)) {
2657 printk(KERN_ERR DRV_PFX
"Error evaluating _SRS\n");
2662 /* Necessary device initializations calls (from sonypi) */
2663 sony_pic_call1(0x82);
2664 sony_pic_call2(0x81, 0xff);
2665 sony_pic_call1(compat
? 0x92 : 0x82);
2674 * ISR: some event is available
2677 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
2682 u8 device_event
= 0;
2684 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
2686 ev
= inb_p(dev
->cur_ioport
->io1
.minimum
);
2687 if (dev
->cur_ioport
->io2
.minimum
)
2688 data_mask
= inb_p(dev
->cur_ioport
->io2
.minimum
);
2690 data_mask
= inb_p(dev
->cur_ioport
->io1
.minimum
+
2691 dev
->evport_offset
);
2693 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2694 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
2695 dev
->evport_offset
);
2697 if (ev
== 0x00 || ev
== 0xff)
2700 for (i
= 0; dev
->event_types
[i
].mask
; i
++) {
2702 if ((data_mask
& dev
->event_types
[i
].data
) !=
2703 dev
->event_types
[i
].data
)
2706 if (!(mask
& dev
->event_types
[i
].mask
))
2709 for (j
= 0; dev
->event_types
[i
].events
[j
].event
; j
++) {
2710 if (ev
== dev
->event_types
[i
].events
[j
].data
) {
2712 dev
->event_types
[i
].events
[j
].event
;
2717 /* Still not able to decode the event try to pass
2718 * it over to the minidriver
2720 if (dev
->handle_irq
&& dev
->handle_irq(data_mask
, ev
) == 0)
2723 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2724 ev
, data_mask
, dev
->cur_ioport
->io1
.minimum
,
2725 dev
->evport_offset
);
2729 sony_laptop_report_input_event(device_event
);
2730 acpi_bus_generate_proc_event(dev
->acpi_dev
, 1, device_event
);
2731 sonypi_compat_report_event(device_event
);
2741 static int sony_pic_remove(struct acpi_device
*device
, int type
)
2743 struct sony_pic_ioport
*io
, *tmp_io
;
2744 struct sony_pic_irq
*irq
, *tmp_irq
;
2746 if (sony_pic_disable(device
)) {
2747 printk(KERN_ERR DRV_PFX
"Couldn't disable device.\n");
2751 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
2752 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
2753 spic_dev
.cur_ioport
->io1
.address_length
);
2754 if (spic_dev
.cur_ioport
->io2
.minimum
)
2755 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
2756 spic_dev
.cur_ioport
->io2
.address_length
);
2758 sonypi_compat_exit();
2760 sony_laptop_remove_input();
2763 sysfs_remove_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
2766 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
2767 list_del(&io
->list
);
2770 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
2771 list_del(&irq
->list
);
2774 spic_dev
.cur_ioport
= NULL
;
2775 spic_dev
.cur_irq
= NULL
;
2777 dprintk(SONY_PIC_DRIVER_NAME
" removed.\n");
2781 static int sony_pic_add(struct acpi_device
*device
)
2784 struct sony_pic_ioport
*io
, *tmp_io
;
2785 struct sony_pic_irq
*irq
, *tmp_irq
;
2787 printk(KERN_INFO DRV_PFX
"%s v%s.\n",
2788 SONY_PIC_DRIVER_NAME
, SONY_LAPTOP_DRIVER_VERSION
);
2790 spic_dev
.acpi_dev
= device
;
2791 strcpy(acpi_device_class(device
), "sony/hotkey");
2792 sony_pic_detect_device_type(&spic_dev
);
2793 mutex_init(&spic_dev
.lock
);
2795 /* read _PRS resources */
2796 result
= sony_pic_possible_resources(device
);
2798 printk(KERN_ERR DRV_PFX
2799 "Unable to read possible resources.\n");
2800 goto err_free_resources
;
2803 /* setup input devices and helper fifo */
2804 result
= sony_laptop_setup_input(device
);
2806 printk(KERN_ERR DRV_PFX
2807 "Unable to create input devices.\n");
2808 goto err_free_resources
;
2811 if (sonypi_compat_init())
2812 goto err_remove_input
;
2814 /* request io port */
2815 list_for_each_entry_reverse(io
, &spic_dev
.ioports
, list
) {
2816 if (request_region(io
->io1
.minimum
, io
->io1
.address_length
,
2817 "Sony Programable I/O Device")) {
2818 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
2819 io
->io1
.minimum
, io
->io1
.maximum
,
2820 io
->io1
.address_length
);
2821 /* Type 1 have 2 ioports */
2822 if (io
->io2
.minimum
) {
2823 if (request_region(io
->io2
.minimum
,
2824 io
->io2
.address_length
,
2825 "Sony Programable I/O Device")) {
2826 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
2827 io
->io2
.minimum
, io
->io2
.maximum
,
2828 io
->io2
.address_length
);
2829 spic_dev
.cur_ioport
= io
;
2833 dprintk("Unable to get I/O port2: "
2834 "0x%.4x (0x%.4x) + 0x%.2x\n",
2835 io
->io2
.minimum
, io
->io2
.maximum
,
2836 io
->io2
.address_length
);
2837 release_region(io
->io1
.minimum
,
2838 io
->io1
.address_length
);
2842 spic_dev
.cur_ioport
= io
;
2847 if (!spic_dev
.cur_ioport
) {
2848 printk(KERN_ERR DRV_PFX
"Failed to request_region.\n");
2850 goto err_remove_compat
;
2854 list_for_each_entry_reverse(irq
, &spic_dev
.interrupts
, list
) {
2855 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
2856 IRQF_DISABLED
, "sony-laptop", &spic_dev
)) {
2857 dprintk("IRQ: %d - triggering: %d - "
2858 "polarity: %d - shr: %d\n",
2859 irq
->irq
.interrupts
[0],
2860 irq
->irq
.triggering
,
2863 spic_dev
.cur_irq
= irq
;
2867 if (!spic_dev
.cur_irq
) {
2868 printk(KERN_ERR DRV_PFX
"Failed to request_irq.\n");
2870 goto err_release_region
;
2873 /* set resource status _SRS */
2874 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
2876 printk(KERN_ERR DRV_PFX
"Couldn't enable device.\n");
2880 spic_dev
.bluetooth_power
= -1;
2881 /* create device attributes */
2882 result
= sony_pf_add();
2884 goto err_disable_device
;
2886 result
= sysfs_create_group(&sony_pf_device
->dev
.kobj
, &spic_attribute_group
);
2896 sony_pic_disable(device
);
2899 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
2902 release_region(spic_dev
.cur_ioport
->io1
.minimum
,
2903 spic_dev
.cur_ioport
->io1
.address_length
);
2904 if (spic_dev
.cur_ioport
->io2
.minimum
)
2905 release_region(spic_dev
.cur_ioport
->io2
.minimum
,
2906 spic_dev
.cur_ioport
->io2
.address_length
);
2909 sonypi_compat_exit();
2912 sony_laptop_remove_input();
2915 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
2916 list_del(&io
->list
);
2919 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
2920 list_del(&irq
->list
);
2923 spic_dev
.cur_ioport
= NULL
;
2924 spic_dev
.cur_irq
= NULL
;
2929 static int sony_pic_suspend(struct acpi_device
*device
, pm_message_t state
)
2931 if (sony_pic_disable(device
))
2936 static int sony_pic_resume(struct acpi_device
*device
)
2938 sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
2942 static const struct acpi_device_id sony_pic_device_ids
[] = {
2947 static struct acpi_driver sony_pic_driver
= {
2948 .name
= SONY_PIC_DRIVER_NAME
,
2949 .class = SONY_PIC_CLASS
,
2950 .ids
= sony_pic_device_ids
,
2951 .owner
= THIS_MODULE
,
2953 .add
= sony_pic_add
,
2954 .remove
= sony_pic_remove
,
2955 .suspend
= sony_pic_suspend
,
2956 .resume
= sony_pic_resume
,
2960 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
2962 .ident
= "Sony Vaio",
2964 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
2965 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
2969 .ident
= "Sony Vaio",
2971 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
2972 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
2978 static int __init
sony_laptop_init(void)
2982 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
2983 result
= acpi_bus_register_driver(&sony_pic_driver
);
2985 printk(KERN_ERR DRV_PFX
2986 "Unable to register SPIC driver.");
2989 spic_drv_registered
= 1;
2992 result
= acpi_bus_register_driver(&sony_nc_driver
);
2994 printk(KERN_ERR DRV_PFX
"Unable to register SNC driver.");
2995 goto out_unregister_pic
;
3001 if (spic_drv_registered
)
3002 acpi_bus_unregister_driver(&sony_pic_driver
);
3007 static void __exit
sony_laptop_exit(void)
3009 acpi_bus_unregister_driver(&sony_nc_driver
);
3010 if (spic_drv_registered
)
3011 acpi_bus_unregister_driver(&sony_pic_driver
);
3014 module_init(sony_laptop_init
);
3015 module_exit(sony_laptop_exit
);