2 * Sony Programmable I/O Control Device driver for VAIO
4 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
6 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
8 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
10 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
12 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
14 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
16 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
18 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/module.h>
37 #include <linux/input.h>
38 #include <linux/pci.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.h>
41 #include <linux/miscdevice.h>
42 #include <linux/poll.h>
43 #include <linux/delay.h>
44 #include <linux/wait.h>
45 #include <linux/acpi.h>
46 #include <linux/dmi.h>
47 #include <linux/err.h>
48 #include <linux/kfifo.h>
49 #include <linux/platform_device.h>
51 #include <asm/uaccess.h>
53 #include <asm/system.h>
55 #include <linux/sonypi.h>
57 #define SONYPI_DRIVER_VERSION "1.26"
59 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
60 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(SONYPI_DRIVER_VERSION
);
64 static int minor
= -1;
65 module_param(minor
, int, 0);
66 MODULE_PARM_DESC(minor
,
67 "minor number of the misc device, default is -1 (automatic)");
69 static int verbose
; /* = 0 */
70 module_param(verbose
, int, 0644);
71 MODULE_PARM_DESC(verbose
, "be verbose, default is 0 (no)");
73 static int fnkeyinit
; /* = 0 */
74 module_param(fnkeyinit
, int, 0444);
75 MODULE_PARM_DESC(fnkeyinit
,
76 "set this if your Fn keys do not generate any event");
78 static int camera
; /* = 0 */
79 module_param(camera
, int, 0444);
80 MODULE_PARM_DESC(camera
,
81 "set this if you have a MotionEye camera (PictureBook series)");
83 static int compat
; /* = 0 */
84 module_param(compat
, int, 0444);
85 MODULE_PARM_DESC(compat
,
86 "set this if you want to enable backward compatibility mode");
88 static unsigned long mask
= 0xffffffff;
89 module_param(mask
, ulong
, 0644);
90 MODULE_PARM_DESC(mask
,
91 "set this to the mask of event you want to enable (see doc)");
93 static int useinput
= 1;
94 module_param(useinput
, int, 0444);
95 MODULE_PARM_DESC(useinput
,
96 "set this if you would like sonypi to feed events to the input subsystem");
98 #define SONYPI_DEVICE_MODEL_TYPE1 1
99 #define SONYPI_DEVICE_MODEL_TYPE2 2
100 #define SONYPI_DEVICE_MODEL_TYPE3 3
102 /* type1 models use those */
103 #define SONYPI_IRQ_PORT 0x8034
104 #define SONYPI_IRQ_SHIFT 22
105 #define SONYPI_TYPE1_BASE 0x50
106 #define SONYPI_G10A (SONYPI_TYPE1_BASE+0x14)
107 #define SONYPI_TYPE1_REGION_SIZE 0x08
108 #define SONYPI_TYPE1_EVTYPE_OFFSET 0x04
110 /* type2 series specifics */
111 #define SONYPI_SIRQ 0x9b
112 #define SONYPI_SLOB 0x9c
113 #define SONYPI_SHIB 0x9d
114 #define SONYPI_TYPE2_REGION_SIZE 0x20
115 #define SONYPI_TYPE2_EVTYPE_OFFSET 0x12
117 /* type3 series specifics */
118 #define SONYPI_TYPE3_BASE 0x40
119 #define SONYPI_TYPE3_GID2 (SONYPI_TYPE3_BASE+0x48) /* 16 bits */
120 #define SONYPI_TYPE3_MISC (SONYPI_TYPE3_BASE+0x6d) /* 8 bits */
121 #define SONYPI_TYPE3_REGION_SIZE 0x20
122 #define SONYPI_TYPE3_EVTYPE_OFFSET 0x12
124 /* battery / brightness addresses */
125 #define SONYPI_BAT_FLAGS 0x81
126 #define SONYPI_LCD_LIGHT 0x96
127 #define SONYPI_BAT1_PCTRM 0xa0
128 #define SONYPI_BAT1_LEFT 0xa2
129 #define SONYPI_BAT1_MAXRT 0xa4
130 #define SONYPI_BAT2_PCTRM 0xa8
131 #define SONYPI_BAT2_LEFT 0xaa
132 #define SONYPI_BAT2_MAXRT 0xac
133 #define SONYPI_BAT1_MAXTK 0xb0
134 #define SONYPI_BAT1_FULL 0xb2
135 #define SONYPI_BAT2_MAXTK 0xb8
136 #define SONYPI_BAT2_FULL 0xba
138 /* FAN0 information (reverse engineered from ACPI tables) */
139 #define SONYPI_FAN0_STATUS 0x93
140 #define SONYPI_TEMP_STATUS 0xC1
142 /* ioports used for brightness and type2 events */
143 #define SONYPI_DATA_IOPORT 0x62
144 #define SONYPI_CST_IOPORT 0x66
146 /* The set of possible ioports */
147 struct sonypi_ioport_list
{
152 static struct sonypi_ioport_list sonypi_type1_ioport_list
[] = {
153 { 0x10c0, 0x10c4 }, /* looks like the default on C1Vx */
161 static struct sonypi_ioport_list sonypi_type2_ioport_list
[] = {
169 /* same as in type 2 models */
170 static struct sonypi_ioport_list
*sonypi_type3_ioport_list
=
171 sonypi_type2_ioport_list
;
173 /* The set of possible interrupts */
174 struct sonypi_irq_list
{
179 static struct sonypi_irq_list sonypi_type1_irq_list
[] = {
180 { 11, 0x2 }, /* IRQ 11, GO22=0,GO23=1 in AML */
181 { 10, 0x1 }, /* IRQ 10, GO22=1,GO23=0 in AML */
182 { 5, 0x0 }, /* IRQ 5, GO22=0,GO23=0 in AML */
183 { 0, 0x3 } /* no IRQ, GO22=1,GO23=1 in AML */
186 static struct sonypi_irq_list sonypi_type2_irq_list
[] = {
187 { 11, 0x80 }, /* IRQ 11, 0x80 in SIRQ in AML */
188 { 10, 0x40 }, /* IRQ 10, 0x40 in SIRQ in AML */
189 { 9, 0x20 }, /* IRQ 9, 0x20 in SIRQ in AML */
190 { 6, 0x10 }, /* IRQ 6, 0x10 in SIRQ in AML */
191 { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */
194 /* same as in type2 models */
195 static struct sonypi_irq_list
*sonypi_type3_irq_list
= sonypi_type2_irq_list
;
197 #define SONYPI_CAMERA_BRIGHTNESS 0
198 #define SONYPI_CAMERA_CONTRAST 1
199 #define SONYPI_CAMERA_HUE 2
200 #define SONYPI_CAMERA_COLOR 3
201 #define SONYPI_CAMERA_SHARPNESS 4
203 #define SONYPI_CAMERA_PICTURE 5
204 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
205 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
206 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
207 #define SONYPI_CAMERA_MUTE_MASK 0x40
209 /* the rest don't need a loop until not 0xff */
210 #define SONYPI_CAMERA_AGC 6
211 #define SONYPI_CAMERA_AGC_MASK 0x30
212 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
214 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
215 #define SONYPI_CAMERA_CONTROL 0x10
217 #define SONYPI_CAMERA_STATUS 7
218 #define SONYPI_CAMERA_STATUS_READY 0x2
219 #define SONYPI_CAMERA_STATUS_POSITION 0x4
221 #define SONYPI_DIRECTION_BACKWARDS 0x4
223 #define SONYPI_CAMERA_REVISION 8
224 #define SONYPI_CAMERA_ROMVERSION 9
227 #define SONYPI_JOGGER_MASK 0x00000001
228 #define SONYPI_CAPTURE_MASK 0x00000002
229 #define SONYPI_FNKEY_MASK 0x00000004
230 #define SONYPI_BLUETOOTH_MASK 0x00000008
231 #define SONYPI_PKEY_MASK 0x00000010
232 #define SONYPI_BACK_MASK 0x00000020
233 #define SONYPI_HELP_MASK 0x00000040
234 #define SONYPI_LID_MASK 0x00000080
235 #define SONYPI_ZOOM_MASK 0x00000100
236 #define SONYPI_THUMBPHRASE_MASK 0x00000200
237 #define SONYPI_MEYE_MASK 0x00000400
238 #define SONYPI_MEMORYSTICK_MASK 0x00000800
239 #define SONYPI_BATTERY_MASK 0x00001000
240 #define SONYPI_WIRELESS_MASK 0x00002000
242 struct sonypi_event
{
247 /* The set of possible button release events */
248 static struct sonypi_event sonypi_releaseev
[] = {
249 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
253 /* The set of possible jogger events */
254 static struct sonypi_event sonypi_joggerev
[] = {
255 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
256 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
257 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
258 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
259 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
260 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
261 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
262 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
263 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
264 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
265 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
266 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
267 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
271 /* The set of possible capture button events */
272 static struct sonypi_event sonypi_captureev
[] = {
273 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
274 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
275 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
279 /* The set of possible fnkeys events */
280 static struct sonypi_event sonypi_fnkeyev
[] = {
281 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
282 { 0x11, SONYPI_EVENT_FNKEY_F1
},
283 { 0x12, SONYPI_EVENT_FNKEY_F2
},
284 { 0x13, SONYPI_EVENT_FNKEY_F3
},
285 { 0x14, SONYPI_EVENT_FNKEY_F4
},
286 { 0x15, SONYPI_EVENT_FNKEY_F5
},
287 { 0x16, SONYPI_EVENT_FNKEY_F6
},
288 { 0x17, SONYPI_EVENT_FNKEY_F7
},
289 { 0x18, SONYPI_EVENT_FNKEY_F8
},
290 { 0x19, SONYPI_EVENT_FNKEY_F9
},
291 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
292 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
293 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
294 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
295 { 0x21, SONYPI_EVENT_FNKEY_1
},
296 { 0x22, SONYPI_EVENT_FNKEY_2
},
297 { 0x31, SONYPI_EVENT_FNKEY_D
},
298 { 0x32, SONYPI_EVENT_FNKEY_E
},
299 { 0x33, SONYPI_EVENT_FNKEY_F
},
300 { 0x34, SONYPI_EVENT_FNKEY_S
},
301 { 0x35, SONYPI_EVENT_FNKEY_B
},
302 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
306 /* The set of possible program key events */
307 static struct sonypi_event sonypi_pkeyev
[] = {
308 { 0x01, SONYPI_EVENT_PKEY_P1
},
309 { 0x02, SONYPI_EVENT_PKEY_P2
},
310 { 0x04, SONYPI_EVENT_PKEY_P3
},
311 { 0x5c, SONYPI_EVENT_PKEY_P1
},
315 /* The set of possible bluetooth events */
316 static struct sonypi_event sonypi_blueev
[] = {
317 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
318 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
319 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
323 /* The set of possible wireless events */
324 static struct sonypi_event sonypi_wlessev
[] = {
325 { 0x59, SONYPI_EVENT_WIRELESS_ON
},
326 { 0x5a, SONYPI_EVENT_WIRELESS_OFF
},
330 /* The set of possible back button events */
331 static struct sonypi_event sonypi_backev
[] = {
332 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
336 /* The set of possible help button events */
337 static struct sonypi_event sonypi_helpev
[] = {
338 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
343 /* The set of possible lid events */
344 static struct sonypi_event sonypi_lidev
[] = {
345 { 0x51, SONYPI_EVENT_LID_CLOSED
},
346 { 0x50, SONYPI_EVENT_LID_OPENED
},
350 /* The set of possible zoom events */
351 static struct sonypi_event sonypi_zoomev
[] = {
352 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
356 /* The set of possible thumbphrase events */
357 static struct sonypi_event sonypi_thumbphraseev
[] = {
358 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
362 /* The set of possible motioneye camera events */
363 static struct sonypi_event sonypi_meyeev
[] = {
364 { 0x00, SONYPI_EVENT_MEYE_FACE
},
365 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
369 /* The set of possible memorystick events */
370 static struct sonypi_event sonypi_memorystickev
[] = {
371 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
372 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
376 /* The set of possible battery events */
377 static struct sonypi_event sonypi_batteryev
[] = {
378 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
379 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
383 static struct sonypi_eventtypes
{
387 struct sonypi_event
* events
;
388 } sonypi_eventtypes
[] = {
389 { SONYPI_DEVICE_MODEL_TYPE1
, 0, 0xffffffff, sonypi_releaseev
},
390 { SONYPI_DEVICE_MODEL_TYPE1
, 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
391 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
392 { SONYPI_DEVICE_MODEL_TYPE1
, 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
393 { SONYPI_DEVICE_MODEL_TYPE1
, 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
394 { SONYPI_DEVICE_MODEL_TYPE1
, 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
395 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
396 { SONYPI_DEVICE_MODEL_TYPE1
, 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
397 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
398 { SONYPI_DEVICE_MODEL_TYPE1
, 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
400 { SONYPI_DEVICE_MODEL_TYPE2
, 0, 0xffffffff, sonypi_releaseev
},
401 { SONYPI_DEVICE_MODEL_TYPE2
, 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
402 { SONYPI_DEVICE_MODEL_TYPE2
, 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
403 { SONYPI_DEVICE_MODEL_TYPE2
, 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
404 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
405 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
406 { SONYPI_DEVICE_MODEL_TYPE2
, 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
407 { SONYPI_DEVICE_MODEL_TYPE2
, 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
408 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
409 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
410 { SONYPI_DEVICE_MODEL_TYPE2
, 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
411 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
412 { SONYPI_DEVICE_MODEL_TYPE2
, 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
413 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
415 { SONYPI_DEVICE_MODEL_TYPE3
, 0, 0xffffffff, sonypi_releaseev
},
416 { SONYPI_DEVICE_MODEL_TYPE3
, 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
417 { SONYPI_DEVICE_MODEL_TYPE3
, 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
418 { SONYPI_DEVICE_MODEL_TYPE3
, 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
419 { SONYPI_DEVICE_MODEL_TYPE3
, 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
420 { SONYPI_DEVICE_MODEL_TYPE3
, 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
424 #define SONYPI_BUF_SIZE 128
426 /* Correspondance table between sonypi events and input layer events */
430 } sonypi_inputkeys
[] = {
431 { SONYPI_EVENT_CAPTURE_PRESSED
, KEY_CAMERA
},
432 { SONYPI_EVENT_FNKEY_ONLY
, KEY_FN
},
433 { SONYPI_EVENT_FNKEY_ESC
, KEY_FN_ESC
},
434 { SONYPI_EVENT_FNKEY_F1
, KEY_FN_F1
},
435 { SONYPI_EVENT_FNKEY_F2
, KEY_FN_F2
},
436 { SONYPI_EVENT_FNKEY_F3
, KEY_FN_F3
},
437 { SONYPI_EVENT_FNKEY_F4
, KEY_FN_F4
},
438 { SONYPI_EVENT_FNKEY_F5
, KEY_FN_F5
},
439 { SONYPI_EVENT_FNKEY_F6
, KEY_FN_F6
},
440 { SONYPI_EVENT_FNKEY_F7
, KEY_FN_F7
},
441 { SONYPI_EVENT_FNKEY_F8
, KEY_FN_F8
},
442 { SONYPI_EVENT_FNKEY_F9
, KEY_FN_F9
},
443 { SONYPI_EVENT_FNKEY_F10
, KEY_FN_F10
},
444 { SONYPI_EVENT_FNKEY_F11
, KEY_FN_F11
},
445 { SONYPI_EVENT_FNKEY_F12
, KEY_FN_F12
},
446 { SONYPI_EVENT_FNKEY_1
, KEY_FN_1
},
447 { SONYPI_EVENT_FNKEY_2
, KEY_FN_2
},
448 { SONYPI_EVENT_FNKEY_D
, KEY_FN_D
},
449 { SONYPI_EVENT_FNKEY_E
, KEY_FN_E
},
450 { SONYPI_EVENT_FNKEY_F
, KEY_FN_F
},
451 { SONYPI_EVENT_FNKEY_S
, KEY_FN_S
},
452 { SONYPI_EVENT_FNKEY_B
, KEY_FN_B
},
453 { SONYPI_EVENT_BLUETOOTH_PRESSED
, KEY_BLUE
},
454 { SONYPI_EVENT_BLUETOOTH_ON
, KEY_BLUE
},
455 { SONYPI_EVENT_PKEY_P1
, KEY_PROG1
},
456 { SONYPI_EVENT_PKEY_P2
, KEY_PROG2
},
457 { SONYPI_EVENT_PKEY_P3
, KEY_PROG3
},
458 { SONYPI_EVENT_BACK_PRESSED
, KEY_BACK
},
459 { SONYPI_EVENT_HELP_PRESSED
, KEY_HELP
},
460 { SONYPI_EVENT_ZOOM_PRESSED
, KEY_ZOOM
},
461 { SONYPI_EVENT_THUMBPHRASE_PRESSED
, BTN_THUMB
},
465 struct sonypi_keypress
{
466 struct input_dev
*dev
;
470 static struct sonypi_device
{
480 struct semaphore lock
;
482 spinlock_t fifo_lock
;
483 wait_queue_head_t fifo_proc_list
;
484 struct fasync_struct
*fifo_async
;
487 struct input_dev
*input_jog_dev
;
488 struct input_dev
*input_key_dev
;
489 struct work_struct input_work
;
490 struct kfifo
*input_fifo
;
491 spinlock_t input_fifo_lock
;
494 #define ITERATIONS_LONG 10000
495 #define ITERATIONS_SHORT 10
497 #define wait_on_command(quiet, command, iterations) { \
498 unsigned int n = iterations; \
499 while (--n && (command)) \
501 if (!n && (verbose || !quiet)) \
502 printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __FUNCTION__, __LINE__); \
506 #define SONYPI_ACPI_ACTIVE (!acpi_disabled)
508 #define SONYPI_ACPI_ACTIVE 0
509 #endif /* CONFIG_ACPI */
512 static struct acpi_device
*sonypi_acpi_device
;
513 static int acpi_driver_registered
;
516 static int sonypi_ec_write(u8 addr
, u8 value
)
518 #ifdef CONFIG_ACPI_EC
519 if (SONYPI_ACPI_ACTIVE
)
520 return ec_write(addr
, value
);
522 wait_on_command(1, inb_p(SONYPI_CST_IOPORT
) & 3, ITERATIONS_LONG
);
523 outb_p(0x81, SONYPI_CST_IOPORT
);
524 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
525 outb_p(addr
, SONYPI_DATA_IOPORT
);
526 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
527 outb_p(value
, SONYPI_DATA_IOPORT
);
528 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
532 static int sonypi_ec_read(u8 addr
, u8
*value
)
534 #ifdef CONFIG_ACPI_EC
535 if (SONYPI_ACPI_ACTIVE
)
536 return ec_read(addr
, value
);
538 wait_on_command(1, inb_p(SONYPI_CST_IOPORT
) & 3, ITERATIONS_LONG
);
539 outb_p(0x80, SONYPI_CST_IOPORT
);
540 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
541 outb_p(addr
, SONYPI_DATA_IOPORT
);
542 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
543 *value
= inb_p(SONYPI_DATA_IOPORT
);
547 static int ec_read16(u8 addr
, u16
*value
)
550 if (sonypi_ec_read(addr
, &val_lb
))
552 if (sonypi_ec_read(addr
+ 1, &val_hb
))
554 *value
= val_lb
| (val_hb
<< 8);
558 /* Initializes the device - this comes from the AML code in the ACPI bios */
559 static void sonypi_type1_srs(void)
563 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
564 v
= (v
& 0xFFFF0000) | ((u32
) sonypi_device
.ioport1
);
565 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
567 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
568 v
= (v
& 0xFFF0FFFF) |
569 (((u32
) sonypi_device
.ioport1
^ sonypi_device
.ioport2
) << 16);
570 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
572 v
= inl(SONYPI_IRQ_PORT
);
573 v
&= ~(((u32
) 0x3) << SONYPI_IRQ_SHIFT
);
574 v
|= (((u32
) sonypi_device
.bits
) << SONYPI_IRQ_SHIFT
);
575 outl(v
, SONYPI_IRQ_PORT
);
577 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
578 v
= (v
& 0xFF1FFFFF) | 0x00C00000;
579 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
582 static void sonypi_type2_srs(void)
584 if (sonypi_ec_write(SONYPI_SHIB
, (sonypi_device
.ioport1
& 0xFF00) >> 8))
585 printk(KERN_WARNING
"ec_write failed\n");
586 if (sonypi_ec_write(SONYPI_SLOB
, sonypi_device
.ioport1
& 0x00FF))
587 printk(KERN_WARNING
"ec_write failed\n");
588 if (sonypi_ec_write(SONYPI_SIRQ
, sonypi_device
.bits
))
589 printk(KERN_WARNING
"ec_write failed\n");
593 static void sonypi_type3_srs(void)
598 /* This model type uses the same initialiazation of
599 * the embedded controller as the type2 models. */
602 /* Initialization of PCI config space of the LPC interface bridge. */
603 v16
= (sonypi_device
.ioport1
& 0xFFF0) | 0x01;
604 pci_write_config_word(sonypi_device
.dev
, SONYPI_TYPE3_GID2
, v16
);
605 pci_read_config_byte(sonypi_device
.dev
, SONYPI_TYPE3_MISC
, &v8
);
606 v8
= (v8
& 0xCF) | 0x10;
607 pci_write_config_byte(sonypi_device
.dev
, SONYPI_TYPE3_MISC
, v8
);
610 /* Disables the device - this comes from the AML code in the ACPI bios */
611 static void sonypi_type1_dis(void)
615 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
617 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
619 v
= inl(SONYPI_IRQ_PORT
);
620 v
|= (0x3 << SONYPI_IRQ_SHIFT
);
621 outl(v
, SONYPI_IRQ_PORT
);
624 static void sonypi_type2_dis(void)
626 if (sonypi_ec_write(SONYPI_SHIB
, 0))
627 printk(KERN_WARNING
"ec_write failed\n");
628 if (sonypi_ec_write(SONYPI_SLOB
, 0))
629 printk(KERN_WARNING
"ec_write failed\n");
630 if (sonypi_ec_write(SONYPI_SIRQ
, 0))
631 printk(KERN_WARNING
"ec_write failed\n");
634 static void sonypi_type3_dis(void)
638 pci_write_config_word(sonypi_device
.dev
, SONYPI_TYPE3_GID2
, 0);
641 static u8
sonypi_call1(u8 dev
)
645 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
646 outb(dev
, sonypi_device
.ioport2
);
647 v1
= inb_p(sonypi_device
.ioport2
);
648 v2
= inb_p(sonypi_device
.ioport1
);
652 static u8
sonypi_call2(u8 dev
, u8 fn
)
656 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
657 outb(dev
, sonypi_device
.ioport2
);
658 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
659 outb(fn
, sonypi_device
.ioport1
);
660 v1
= inb_p(sonypi_device
.ioport1
);
664 static u8
sonypi_call3(u8 dev
, u8 fn
, u8 v
)
668 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
669 outb(dev
, sonypi_device
.ioport2
);
670 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
671 outb(fn
, sonypi_device
.ioport1
);
672 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
673 outb(v
, sonypi_device
.ioport1
);
674 v1
= inb_p(sonypi_device
.ioport1
);
679 /* Get brightness, hue etc. Unreliable... */
680 static u8
sonypi_read(u8 fn
)
686 v1
= sonypi_call2(0x8f, fn
);
687 v2
= sonypi_call2(0x8f, fn
);
688 if (v1
== v2
&& v1
!= 0xff)
695 /* Set brightness, hue etc */
696 static void sonypi_set(u8 fn
, u8 v
)
698 wait_on_command(0, sonypi_call3(0x90, fn
, v
), ITERATIONS_SHORT
);
701 /* Tests if the camera is ready */
702 static int sonypi_camera_ready(void)
706 v
= sonypi_call2(0x8f, SONYPI_CAMERA_STATUS
);
707 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
710 /* Turns the camera off */
711 static void sonypi_camera_off(void)
713 sonypi_set(SONYPI_CAMERA_PICTURE
, SONYPI_CAMERA_MUTE_MASK
);
715 if (!sonypi_device
.camera_power
)
718 sonypi_call2(0x91, 0);
719 sonypi_device
.camera_power
= 0;
722 /* Turns the camera on */
723 static void sonypi_camera_on(void)
727 if (sonypi_device
.camera_power
)
730 for (j
= 5; j
> 0; j
--) {
732 while (sonypi_call2(0x91, 0x1))
736 for (i
= 400; i
> 0; i
--) {
737 if (sonypi_camera_ready())
746 printk(KERN_WARNING
"sonypi: failed to power on camera\n");
750 sonypi_set(0x10, 0x5a);
751 sonypi_device
.camera_power
= 1;
754 /* sets the bluetooth subsystem power state */
755 static void sonypi_setbluetoothpower(u8 state
)
759 if (sonypi_device
.bluetooth_power
== state
)
762 sonypi_call2(0x96, state
);
764 sonypi_device
.bluetooth_power
= state
;
767 static void input_keyrelease(struct work_struct
*work
)
769 struct sonypi_keypress kp
;
771 while (kfifo_get(sonypi_device
.input_fifo
, (unsigned char *)&kp
,
772 sizeof(kp
)) == sizeof(kp
)) {
774 input_report_key(kp
.dev
, kp
.key
, 0);
779 static void sonypi_report_input_event(u8 event
)
781 struct input_dev
*jog_dev
= sonypi_device
.input_jog_dev
;
782 struct input_dev
*key_dev
= sonypi_device
.input_key_dev
;
783 struct sonypi_keypress kp
= { NULL
};
787 case SONYPI_EVENT_JOGDIAL_UP
:
788 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
789 input_report_rel(jog_dev
, REL_WHEEL
, 1);
793 case SONYPI_EVENT_JOGDIAL_DOWN
:
794 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
795 input_report_rel(jog_dev
, REL_WHEEL
, -1);
799 case SONYPI_EVENT_JOGDIAL_PRESSED
:
804 case SONYPI_EVENT_FNKEY_RELEASED
:
805 /* Nothing, not all VAIOs generate this event */
809 for (i
= 0; sonypi_inputkeys
[i
].sonypiev
; i
++)
810 if (event
== sonypi_inputkeys
[i
].sonypiev
) {
812 kp
.key
= sonypi_inputkeys
[i
].inputev
;
819 input_report_key(kp
.dev
, kp
.key
, 1);
821 kfifo_put(sonypi_device
.input_fifo
,
822 (unsigned char *)&kp
, sizeof(kp
));
823 schedule_work(&sonypi_device
.input_work
);
827 /* Interrupt handler: some event is available */
828 static irqreturn_t
sonypi_irq(int irq
, void *dev_id
)
830 u8 v1
, v2
, event
= 0;
833 v1
= inb_p(sonypi_device
.ioport1
);
834 v2
= inb_p(sonypi_device
.ioport1
+ sonypi_device
.evtype_offset
);
836 for (i
= 0; sonypi_eventtypes
[i
].model
; i
++) {
837 if (sonypi_device
.model
!= sonypi_eventtypes
[i
].model
)
839 if ((v2
& sonypi_eventtypes
[i
].data
) !=
840 sonypi_eventtypes
[i
].data
)
842 if (!(mask
& sonypi_eventtypes
[i
].mask
))
844 for (j
= 0; sonypi_eventtypes
[i
].events
[j
].event
; j
++) {
845 if (v1
== sonypi_eventtypes
[i
].events
[j
].data
) {
846 event
= sonypi_eventtypes
[i
].events
[j
].event
;
854 "sonypi: unknown event port1=0x%02x,port2=0x%02x\n",
856 /* We need to return IRQ_HANDLED here because there *are*
857 * events belonging to the sonypi device we don't know about,
858 * but we still don't want those to pollute the logs... */
864 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1
, v2
);
867 sonypi_report_input_event(event
);
870 if (sonypi_acpi_device
)
871 acpi_bus_generate_event(sonypi_acpi_device
, 1, event
);
874 kfifo_put(sonypi_device
.fifo
, (unsigned char *)&event
, sizeof(event
));
875 kill_fasync(&sonypi_device
.fifo_async
, SIGIO
, POLL_IN
);
876 wake_up_interruptible(&sonypi_device
.fifo_proc_list
);
881 /* External camera command (exported to the motion eye v4l driver) */
882 int sonypi_camera_command(int command
, u8 value
)
887 down(&sonypi_device
.lock
);
890 case SONYPI_COMMAND_SETCAMERA
:
896 case SONYPI_COMMAND_SETCAMERABRIGHTNESS
:
897 sonypi_set(SONYPI_CAMERA_BRIGHTNESS
, value
);
899 case SONYPI_COMMAND_SETCAMERACONTRAST
:
900 sonypi_set(SONYPI_CAMERA_CONTRAST
, value
);
902 case SONYPI_COMMAND_SETCAMERAHUE
:
903 sonypi_set(SONYPI_CAMERA_HUE
, value
);
905 case SONYPI_COMMAND_SETCAMERACOLOR
:
906 sonypi_set(SONYPI_CAMERA_COLOR
, value
);
908 case SONYPI_COMMAND_SETCAMERASHARPNESS
:
909 sonypi_set(SONYPI_CAMERA_SHARPNESS
, value
);
911 case SONYPI_COMMAND_SETCAMERAPICTURE
:
912 sonypi_set(SONYPI_CAMERA_PICTURE
, value
);
914 case SONYPI_COMMAND_SETCAMERAAGC
:
915 sonypi_set(SONYPI_CAMERA_AGC
, value
);
918 printk(KERN_ERR
"sonypi: sonypi_camera_command invalid: %d\n",
922 up(&sonypi_device
.lock
);
926 EXPORT_SYMBOL(sonypi_camera_command
);
928 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
932 retval
= fasync_helper(fd
, filp
, on
, &sonypi_device
.fifo_async
);
938 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
940 sonypi_misc_fasync(-1, file
, 0);
941 down(&sonypi_device
.lock
);
942 sonypi_device
.open_count
--;
943 up(&sonypi_device
.lock
);
947 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
949 down(&sonypi_device
.lock
);
950 /* Flush input queue on first open */
951 if (!sonypi_device
.open_count
)
952 kfifo_reset(sonypi_device
.fifo
);
953 sonypi_device
.open_count
++;
954 up(&sonypi_device
.lock
);
958 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
959 size_t count
, loff_t
*pos
)
964 if ((kfifo_len(sonypi_device
.fifo
) == 0) &&
965 (file
->f_flags
& O_NONBLOCK
))
968 ret
= wait_event_interruptible(sonypi_device
.fifo_proc_list
,
969 kfifo_len(sonypi_device
.fifo
) != 0);
973 while (ret
< count
&&
974 (kfifo_get(sonypi_device
.fifo
, &c
, sizeof(c
)) == sizeof(c
))) {
975 if (put_user(c
, buf
++))
981 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
982 inode
->i_atime
= current_fs_time(inode
->i_sb
);
988 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
990 poll_wait(file
, &sonypi_device
.fifo_proc_list
, wait
);
991 if (kfifo_len(sonypi_device
.fifo
))
992 return POLLIN
| POLLRDNORM
;
996 static int sonypi_misc_ioctl(struct inode
*ip
, struct file
*fp
,
997 unsigned int cmd
, unsigned long arg
)
1000 void __user
*argp
= (void __user
*)arg
;
1004 down(&sonypi_device
.lock
);
1006 case SONYPI_IOCGBRT
:
1007 if (sonypi_ec_read(SONYPI_LCD_LIGHT
, &val8
)) {
1011 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1014 case SONYPI_IOCSBRT
:
1015 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
1019 if (sonypi_ec_write(SONYPI_LCD_LIGHT
, val8
))
1022 case SONYPI_IOCGBAT1CAP
:
1023 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
1027 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
1030 case SONYPI_IOCGBAT1REM
:
1031 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
1035 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
1038 case SONYPI_IOCGBAT2CAP
:
1039 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
1043 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
1046 case SONYPI_IOCGBAT2REM
:
1047 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
1051 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
1054 case SONYPI_IOCGBATFLAGS
:
1055 if (sonypi_ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
1060 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1063 case SONYPI_IOCGBLUE
:
1064 val8
= sonypi_device
.bluetooth_power
;
1065 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1068 case SONYPI_IOCSBLUE
:
1069 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
1073 sonypi_setbluetoothpower(val8
);
1076 case SONYPI_IOCGFAN
:
1077 if (sonypi_ec_read(SONYPI_FAN0_STATUS
, &val8
)) {
1081 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1084 case SONYPI_IOCSFAN
:
1085 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
1089 if (sonypi_ec_write(SONYPI_FAN0_STATUS
, val8
))
1092 /* GET Temperature (useful under APM) */
1093 case SONYPI_IOCGTEMP
:
1094 if (sonypi_ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
1098 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1104 up(&sonypi_device
.lock
);
1108 static const struct file_operations sonypi_misc_fops
= {
1109 .owner
= THIS_MODULE
,
1110 .read
= sonypi_misc_read
,
1111 .poll
= sonypi_misc_poll
,
1112 .open
= sonypi_misc_open
,
1113 .release
= sonypi_misc_release
,
1114 .fasync
= sonypi_misc_fasync
,
1115 .ioctl
= sonypi_misc_ioctl
,
1118 static struct miscdevice sonypi_misc_device
= {
1119 .minor
= MISC_DYNAMIC_MINOR
,
1121 .fops
= &sonypi_misc_fops
,
1124 static void sonypi_enable(unsigned int camera_on
)
1126 switch (sonypi_device
.model
) {
1127 case SONYPI_DEVICE_MODEL_TYPE1
:
1130 case SONYPI_DEVICE_MODEL_TYPE2
:
1133 case SONYPI_DEVICE_MODEL_TYPE3
:
1139 sonypi_call2(0x81, 0xff);
1140 sonypi_call1(compat
? 0x92 : 0x82);
1142 /* Enable ACPI mode to get Fn key events */
1143 if (!SONYPI_ACPI_ACTIVE
&& fnkeyinit
)
1146 if (camera
&& camera_on
)
1150 static int sonypi_disable(void)
1152 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
1154 sonypi_camera_off();
1156 /* disable ACPI mode */
1157 if (!SONYPI_ACPI_ACTIVE
&& fnkeyinit
)
1160 switch (sonypi_device
.model
) {
1161 case SONYPI_DEVICE_MODEL_TYPE1
:
1164 case SONYPI_DEVICE_MODEL_TYPE2
:
1167 case SONYPI_DEVICE_MODEL_TYPE3
:
1176 static int sonypi_acpi_add(struct acpi_device
*device
)
1178 sonypi_acpi_device
= device
;
1179 strcpy(acpi_device_name(device
), "Sony laptop hotkeys");
1180 strcpy(acpi_device_class(device
), "sony/hotkey");
1184 static int sonypi_acpi_remove(struct acpi_device
*device
, int type
)
1186 sonypi_acpi_device
= NULL
;
1190 static struct acpi_driver sonypi_acpi_driver
= {
1195 .add
= sonypi_acpi_add
,
1196 .remove
= sonypi_acpi_remove
,
1201 static int __devinit
sonypi_create_input_devices(void)
1203 struct input_dev
*jog_dev
;
1204 struct input_dev
*key_dev
;
1208 sonypi_device
.input_jog_dev
= jog_dev
= input_allocate_device();
1212 jog_dev
->name
= "Sony Vaio Jogdial";
1213 jog_dev
->id
.bustype
= BUS_ISA
;
1214 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
1216 jog_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_REL
);
1217 jog_dev
->keybit
[LONG(BTN_MOUSE
)] = BIT(BTN_MIDDLE
);
1218 jog_dev
->relbit
[0] = BIT(REL_WHEEL
);
1220 sonypi_device
.input_key_dev
= key_dev
= input_allocate_device();
1223 goto err_free_jogdev
;
1226 key_dev
->name
= "Sony Vaio Keys";
1227 key_dev
->id
.bustype
= BUS_ISA
;
1228 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
1230 /* Initialize the Input Drivers: special keys */
1231 key_dev
->evbit
[0] = BIT(EV_KEY
);
1232 for (i
= 0; sonypi_inputkeys
[i
].sonypiev
; i
++)
1233 if (sonypi_inputkeys
[i
].inputev
)
1234 set_bit(sonypi_inputkeys
[i
].inputev
, key_dev
->keybit
);
1236 error
= input_register_device(jog_dev
);
1238 goto err_free_keydev
;
1240 error
= input_register_device(key_dev
);
1242 goto err_unregister_jogdev
;
1246 err_unregister_jogdev
:
1247 input_unregister_device(jog_dev
);
1248 /* Set to NULL so we don't free it again below */
1251 input_free_device(key_dev
);
1252 sonypi_device
.input_key_dev
= NULL
;
1254 input_free_device(jog_dev
);
1255 sonypi_device
.input_jog_dev
= NULL
;
1260 static int __devinit
sonypi_setup_ioports(struct sonypi_device
*dev
,
1261 const struct sonypi_ioport_list
*ioport_list
)
1263 while (ioport_list
->port1
) {
1265 if (request_region(ioport_list
->port1
,
1266 sonypi_device
.region_size
,
1267 "Sony Programable I/O Device")) {
1268 dev
->ioport1
= ioport_list
->port1
;
1269 dev
->ioport2
= ioport_list
->port2
;
1278 static int __devinit
sonypi_setup_irq(struct sonypi_device
*dev
,
1279 const struct sonypi_irq_list
*irq_list
)
1281 while (irq_list
->irq
) {
1283 if (!request_irq(irq_list
->irq
, sonypi_irq
,
1284 IRQF_SHARED
, "sonypi", sonypi_irq
)) {
1285 dev
->irq
= irq_list
->irq
;
1286 dev
->bits
= irq_list
->bits
;
1295 static void __devinit
sonypi_display_info(void)
1297 printk(KERN_INFO
"sonypi: detected type%d model, "
1298 "verbose = %d, fnkeyinit = %s, camera = %s, "
1299 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
1300 sonypi_device
.model
,
1302 fnkeyinit
? "on" : "off",
1303 camera
? "on" : "off",
1304 compat
? "on" : "off",
1306 useinput
? "on" : "off",
1307 SONYPI_ACPI_ACTIVE
? "on" : "off");
1308 printk(KERN_INFO
"sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
1310 sonypi_device
.ioport1
, sonypi_device
.ioport2
);
1313 printk(KERN_INFO
"sonypi: device allocated minor is %d\n",
1314 sonypi_misc_device
.minor
);
1317 static int __devinit
sonypi_probe(struct platform_device
*dev
)
1319 const struct sonypi_ioport_list
*ioport_list
;
1320 const struct sonypi_irq_list
*irq_list
;
1321 struct pci_dev
*pcidev
;
1324 spin_lock_init(&sonypi_device
.fifo_lock
);
1325 sonypi_device
.fifo
= kfifo_alloc(SONYPI_BUF_SIZE
, GFP_KERNEL
,
1326 &sonypi_device
.fifo_lock
);
1327 if (IS_ERR(sonypi_device
.fifo
)) {
1328 printk(KERN_ERR
"sonypi: kfifo_alloc failed\n");
1329 return PTR_ERR(sonypi_device
.fifo
);
1332 init_waitqueue_head(&sonypi_device
.fifo_proc_list
);
1333 init_MUTEX(&sonypi_device
.lock
);
1334 sonypi_device
.bluetooth_power
= -1;
1336 if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1337 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
)))
1338 sonypi_device
.model
= SONYPI_DEVICE_MODEL_TYPE1
;
1339 else if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1340 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
)))
1341 sonypi_device
.model
= SONYPI_DEVICE_MODEL_TYPE3
;
1342 else if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1343 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
)))
1344 sonypi_device
.model
= SONYPI_DEVICE_MODEL_TYPE3
;
1346 sonypi_device
.model
= SONYPI_DEVICE_MODEL_TYPE2
;
1348 if (pcidev
&& pci_enable_device(pcidev
)) {
1349 printk(KERN_ERR
"sonypi: pci_enable_device failed\n");
1351 goto err_put_pcidev
;
1354 sonypi_device
.dev
= pcidev
;
1356 if (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE1
) {
1357 ioport_list
= sonypi_type1_ioport_list
;
1358 sonypi_device
.region_size
= SONYPI_TYPE1_REGION_SIZE
;
1359 sonypi_device
.evtype_offset
= SONYPI_TYPE1_EVTYPE_OFFSET
;
1360 irq_list
= sonypi_type1_irq_list
;
1361 } else if (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE2
) {
1362 ioport_list
= sonypi_type2_ioport_list
;
1363 sonypi_device
.region_size
= SONYPI_TYPE2_REGION_SIZE
;
1364 sonypi_device
.evtype_offset
= SONYPI_TYPE2_EVTYPE_OFFSET
;
1365 irq_list
= sonypi_type2_irq_list
;
1367 ioport_list
= sonypi_type3_ioport_list
;
1368 sonypi_device
.region_size
= SONYPI_TYPE3_REGION_SIZE
;
1369 sonypi_device
.evtype_offset
= SONYPI_TYPE3_EVTYPE_OFFSET
;
1370 irq_list
= sonypi_type3_irq_list
;
1373 error
= sonypi_setup_ioports(&sonypi_device
, ioport_list
);
1375 printk(KERN_ERR
"sonypi: failed to request ioports\n");
1376 goto err_disable_pcidev
;
1379 error
= sonypi_setup_irq(&sonypi_device
, irq_list
);
1381 printk(KERN_ERR
"sonypi: request_irq failed\n");
1382 goto err_free_ioports
;
1386 sonypi_misc_device
.minor
= minor
;
1387 error
= misc_register(&sonypi_misc_device
);
1389 printk(KERN_ERR
"sonypi: misc_register failed\n");
1393 sonypi_display_info();
1397 error
= sonypi_create_input_devices();
1400 "sonypi: failed to create input devices\n");
1401 goto err_miscdev_unregister
;
1404 spin_lock_init(&sonypi_device
.input_fifo_lock
);
1405 sonypi_device
.input_fifo
=
1406 kfifo_alloc(SONYPI_BUF_SIZE
, GFP_KERNEL
,
1407 &sonypi_device
.input_fifo_lock
);
1408 if (IS_ERR(sonypi_device
.input_fifo
)) {
1409 printk(KERN_ERR
"sonypi: kfifo_alloc failed\n");
1410 error
= PTR_ERR(sonypi_device
.input_fifo
);
1411 goto err_inpdev_unregister
;
1414 INIT_WORK(&sonypi_device
.input_work
, input_keyrelease
);
1421 err_inpdev_unregister
:
1422 input_unregister_device(sonypi_device
.input_key_dev
);
1423 input_unregister_device(sonypi_device
.input_jog_dev
);
1424 err_miscdev_unregister
:
1425 misc_deregister(&sonypi_misc_device
);
1427 free_irq(sonypi_device
.irq
, sonypi_irq
);
1429 release_region(sonypi_device
.ioport1
, sonypi_device
.region_size
);
1432 pci_disable_device(pcidev
);
1434 pci_dev_put(pcidev
);
1435 kfifo_free(sonypi_device
.fifo
);
1440 static int __devexit
sonypi_remove(struct platform_device
*dev
)
1444 synchronize_sched(); /* Allow sonypi interrupt to complete. */
1445 flush_scheduled_work();
1448 input_unregister_device(sonypi_device
.input_key_dev
);
1449 input_unregister_device(sonypi_device
.input_jog_dev
);
1450 kfifo_free(sonypi_device
.input_fifo
);
1453 misc_deregister(&sonypi_misc_device
);
1455 free_irq(sonypi_device
.irq
, sonypi_irq
);
1456 release_region(sonypi_device
.ioport1
, sonypi_device
.region_size
);
1458 if (sonypi_device
.dev
) {
1459 pci_disable_device(sonypi_device
.dev
);
1460 pci_dev_put(sonypi_device
.dev
);
1463 kfifo_free(sonypi_device
.fifo
);
1469 static int old_camera_power
;
1471 static int sonypi_suspend(struct platform_device
*dev
, pm_message_t state
)
1473 old_camera_power
= sonypi_device
.camera_power
;
1479 static int sonypi_resume(struct platform_device
*dev
)
1481 sonypi_enable(old_camera_power
);
1485 #define sonypi_suspend NULL
1486 #define sonypi_resume NULL
1489 static void sonypi_shutdown(struct platform_device
*dev
)
1494 static struct platform_driver sonypi_driver
= {
1497 .owner
= THIS_MODULE
,
1499 .probe
= sonypi_probe
,
1500 .remove
= __devexit_p(sonypi_remove
),
1501 .shutdown
= sonypi_shutdown
,
1502 .suspend
= sonypi_suspend
,
1503 .resume
= sonypi_resume
,
1506 static struct platform_device
*sonypi_platform_device
;
1508 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
1510 .ident
= "Sony Vaio",
1512 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1513 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
1517 .ident
= "Sony Vaio",
1519 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1520 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
1526 static int __init
sonypi_init(void)
1531 "sonypi: Sony Programmable I/O Controller Driver v%s.\n",
1532 SONYPI_DRIVER_VERSION
);
1534 if (!dmi_check_system(sonypi_dmi_table
))
1537 error
= platform_driver_register(&sonypi_driver
);
1541 sonypi_platform_device
= platform_device_alloc("sonypi", -1);
1542 if (!sonypi_platform_device
) {
1544 goto err_driver_unregister
;
1547 error
= platform_device_add(sonypi_platform_device
);
1549 goto err_free_device
;
1552 if (acpi_bus_register_driver(&sonypi_acpi_driver
) >= 0)
1553 acpi_driver_registered
= 1;
1559 platform_device_put(sonypi_platform_device
);
1560 err_driver_unregister
:
1561 platform_driver_unregister(&sonypi_driver
);
1565 static void __exit
sonypi_exit(void)
1568 if (acpi_driver_registered
)
1569 acpi_bus_unregister_driver(&sonypi_acpi_driver
);
1571 platform_device_unregister(sonypi_platform_device
);
1572 platform_driver_unregister(&sonypi_driver
);
1573 printk(KERN_INFO
"sonypi: removed.\n");
1576 module_init(sonypi_init
);
1577 module_exit(sonypi_exit
);