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/config.h>
37 #include <linux/module.h>
38 #include <linux/input.h>
39 #include <linux/pci.h>
40 #include <linux/sched.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/miscdevice.h>
44 #include <linux/poll.h>
45 #include <linux/delay.h>
46 #include <linux/wait.h>
47 #include <linux/acpi.h>
48 #include <linux/dmi.h>
49 #include <linux/err.h>
50 #include <linux/kfifo.h>
52 #include <asm/uaccess.h>
54 #include <asm/system.h>
56 #include <linux/sonypi.h>
58 #define SONYPI_DRIVER_VERSION "1.26"
60 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
61 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(SONYPI_DRIVER_VERSION
);
65 static int minor
= -1;
66 module_param(minor
, int, 0);
67 MODULE_PARM_DESC(minor
,
68 "minor number of the misc device, default is -1 (automatic)");
70 static int verbose
; /* = 0 */
71 module_param(verbose
, int, 0644);
72 MODULE_PARM_DESC(verbose
, "be verbose, default is 0 (no)");
74 static int fnkeyinit
; /* = 0 */
75 module_param(fnkeyinit
, int, 0444);
76 MODULE_PARM_DESC(fnkeyinit
,
77 "set this if your Fn keys do not generate any event");
79 static int camera
; /* = 0 */
80 module_param(camera
, int, 0444);
81 MODULE_PARM_DESC(camera
,
82 "set this if you have a MotionEye camera (PictureBook series)");
84 static int compat
; /* = 0 */
85 module_param(compat
, int, 0444);
86 MODULE_PARM_DESC(compat
,
87 "set this if you want to enable backward compatibility mode");
89 static unsigned long mask
= 0xffffffff;
90 module_param(mask
, ulong
, 0644);
91 MODULE_PARM_DESC(mask
,
92 "set this to the mask of event you want to enable (see doc)");
94 static int useinput
= 1;
95 module_param(useinput
, int, 0444);
96 MODULE_PARM_DESC(useinput
,
97 "set this if you would like sonypi to feed events to the input subsystem");
99 #define SONYPI_DEVICE_MODEL_TYPE1 1
100 #define SONYPI_DEVICE_MODEL_TYPE2 2
102 /* type1 models use those */
103 #define SONYPI_IRQ_PORT 0x8034
104 #define SONYPI_IRQ_SHIFT 22
105 #define SONYPI_BASE 0x50
106 #define SONYPI_G10A (SONYPI_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 /* battery / brightness addresses */
118 #define SONYPI_BAT_FLAGS 0x81
119 #define SONYPI_LCD_LIGHT 0x96
120 #define SONYPI_BAT1_PCTRM 0xa0
121 #define SONYPI_BAT1_LEFT 0xa2
122 #define SONYPI_BAT1_MAXRT 0xa4
123 #define SONYPI_BAT2_PCTRM 0xa8
124 #define SONYPI_BAT2_LEFT 0xaa
125 #define SONYPI_BAT2_MAXRT 0xac
126 #define SONYPI_BAT1_MAXTK 0xb0
127 #define SONYPI_BAT1_FULL 0xb2
128 #define SONYPI_BAT2_MAXTK 0xb8
129 #define SONYPI_BAT2_FULL 0xba
131 /* FAN0 information (reverse engineered from ACPI tables) */
132 #define SONYPI_FAN0_STATUS 0x93
133 #define SONYPI_TEMP_STATUS 0xC1
135 /* ioports used for brightness and type2 events */
136 #define SONYPI_DATA_IOPORT 0x62
137 #define SONYPI_CST_IOPORT 0x66
139 /* The set of possible ioports */
140 struct sonypi_ioport_list
{
145 static struct sonypi_ioport_list sonypi_type1_ioport_list
[] = {
146 { 0x10c0, 0x10c4 }, /* looks like the default on C1Vx */
154 static struct sonypi_ioport_list sonypi_type2_ioport_list
[] = {
162 /* The set of possible interrupts */
163 struct sonypi_irq_list
{
168 static struct sonypi_irq_list sonypi_type1_irq_list
[] = {
169 { 11, 0x2 }, /* IRQ 11, GO22=0,GO23=1 in AML */
170 { 10, 0x1 }, /* IRQ 10, GO22=1,GO23=0 in AML */
171 { 5, 0x0 }, /* IRQ 5, GO22=0,GO23=0 in AML */
172 { 0, 0x3 } /* no IRQ, GO22=1,GO23=1 in AML */
175 static struct sonypi_irq_list sonypi_type2_irq_list
[] = {
176 { 11, 0x80 }, /* IRQ 11, 0x80 in SIRQ in AML */
177 { 10, 0x40 }, /* IRQ 10, 0x40 in SIRQ in AML */
178 { 9, 0x20 }, /* IRQ 9, 0x20 in SIRQ in AML */
179 { 6, 0x10 }, /* IRQ 6, 0x10 in SIRQ in AML */
180 { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */
183 #define SONYPI_CAMERA_BRIGHTNESS 0
184 #define SONYPI_CAMERA_CONTRAST 1
185 #define SONYPI_CAMERA_HUE 2
186 #define SONYPI_CAMERA_COLOR 3
187 #define SONYPI_CAMERA_SHARPNESS 4
189 #define SONYPI_CAMERA_PICTURE 5
190 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
191 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
192 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
193 #define SONYPI_CAMERA_MUTE_MASK 0x40
195 /* the rest don't need a loop until not 0xff */
196 #define SONYPI_CAMERA_AGC 6
197 #define SONYPI_CAMERA_AGC_MASK 0x30
198 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
200 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
201 #define SONYPI_CAMERA_CONTROL 0x10
203 #define SONYPI_CAMERA_STATUS 7
204 #define SONYPI_CAMERA_STATUS_READY 0x2
205 #define SONYPI_CAMERA_STATUS_POSITION 0x4
207 #define SONYPI_DIRECTION_BACKWARDS 0x4
209 #define SONYPI_CAMERA_REVISION 8
210 #define SONYPI_CAMERA_ROMVERSION 9
213 #define SONYPI_JOGGER_MASK 0x00000001
214 #define SONYPI_CAPTURE_MASK 0x00000002
215 #define SONYPI_FNKEY_MASK 0x00000004
216 #define SONYPI_BLUETOOTH_MASK 0x00000008
217 #define SONYPI_PKEY_MASK 0x00000010
218 #define SONYPI_BACK_MASK 0x00000020
219 #define SONYPI_HELP_MASK 0x00000040
220 #define SONYPI_LID_MASK 0x00000080
221 #define SONYPI_ZOOM_MASK 0x00000100
222 #define SONYPI_THUMBPHRASE_MASK 0x00000200
223 #define SONYPI_MEYE_MASK 0x00000400
224 #define SONYPI_MEMORYSTICK_MASK 0x00000800
225 #define SONYPI_BATTERY_MASK 0x00001000
227 struct sonypi_event
{
232 /* The set of possible button release events */
233 static struct sonypi_event sonypi_releaseev
[] = {
234 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
238 /* The set of possible jogger events */
239 static struct sonypi_event sonypi_joggerev
[] = {
240 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
241 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
242 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
243 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
244 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
245 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
246 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
247 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
248 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
249 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
250 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
251 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
252 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
256 /* The set of possible capture button events */
257 static struct sonypi_event sonypi_captureev
[] = {
258 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
259 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
260 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
264 /* The set of possible fnkeys events */
265 static struct sonypi_event sonypi_fnkeyev
[] = {
266 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
267 { 0x11, SONYPI_EVENT_FNKEY_F1
},
268 { 0x12, SONYPI_EVENT_FNKEY_F2
},
269 { 0x13, SONYPI_EVENT_FNKEY_F3
},
270 { 0x14, SONYPI_EVENT_FNKEY_F4
},
271 { 0x15, SONYPI_EVENT_FNKEY_F5
},
272 { 0x16, SONYPI_EVENT_FNKEY_F6
},
273 { 0x17, SONYPI_EVENT_FNKEY_F7
},
274 { 0x18, SONYPI_EVENT_FNKEY_F8
},
275 { 0x19, SONYPI_EVENT_FNKEY_F9
},
276 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
277 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
278 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
279 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
280 { 0x21, SONYPI_EVENT_FNKEY_1
},
281 { 0x22, SONYPI_EVENT_FNKEY_2
},
282 { 0x31, SONYPI_EVENT_FNKEY_D
},
283 { 0x32, SONYPI_EVENT_FNKEY_E
},
284 { 0x33, SONYPI_EVENT_FNKEY_F
},
285 { 0x34, SONYPI_EVENT_FNKEY_S
},
286 { 0x35, SONYPI_EVENT_FNKEY_B
},
287 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
291 /* The set of possible program key events */
292 static struct sonypi_event sonypi_pkeyev
[] = {
293 { 0x01, SONYPI_EVENT_PKEY_P1
},
294 { 0x02, SONYPI_EVENT_PKEY_P2
},
295 { 0x04, SONYPI_EVENT_PKEY_P3
},
296 { 0x5c, SONYPI_EVENT_PKEY_P1
},
300 /* The set of possible bluetooth events */
301 static struct sonypi_event sonypi_blueev
[] = {
302 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
303 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
304 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
308 /* The set of possible back button events */
309 static struct sonypi_event sonypi_backev
[] = {
310 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
314 /* The set of possible help button events */
315 static struct sonypi_event sonypi_helpev
[] = {
316 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
321 /* The set of possible lid events */
322 static struct sonypi_event sonypi_lidev
[] = {
323 { 0x51, SONYPI_EVENT_LID_CLOSED
},
324 { 0x50, SONYPI_EVENT_LID_OPENED
},
328 /* The set of possible zoom events */
329 static struct sonypi_event sonypi_zoomev
[] = {
330 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
334 /* The set of possible thumbphrase events */
335 static struct sonypi_event sonypi_thumbphraseev
[] = {
336 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
340 /* The set of possible motioneye camera events */
341 static struct sonypi_event sonypi_meyeev
[] = {
342 { 0x00, SONYPI_EVENT_MEYE_FACE
},
343 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
347 /* The set of possible memorystick events */
348 static struct sonypi_event sonypi_memorystickev
[] = {
349 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
350 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
354 /* The set of possible battery events */
355 static struct sonypi_event sonypi_batteryev
[] = {
356 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
357 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
361 static struct sonypi_eventtypes
{
365 struct sonypi_event
* events
;
366 } sonypi_eventtypes
[] = {
367 { SONYPI_DEVICE_MODEL_TYPE1
, 0, 0xffffffff, sonypi_releaseev
},
368 { SONYPI_DEVICE_MODEL_TYPE1
, 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
369 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
370 { SONYPI_DEVICE_MODEL_TYPE1
, 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
371 { SONYPI_DEVICE_MODEL_TYPE1
, 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
372 { SONYPI_DEVICE_MODEL_TYPE1
, 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
373 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
374 { SONYPI_DEVICE_MODEL_TYPE1
, 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
375 { SONYPI_DEVICE_MODEL_TYPE1
, 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
376 { SONYPI_DEVICE_MODEL_TYPE1
, 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
378 { SONYPI_DEVICE_MODEL_TYPE2
, 0, 0xffffffff, sonypi_releaseev
},
379 { SONYPI_DEVICE_MODEL_TYPE2
, 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
380 { SONYPI_DEVICE_MODEL_TYPE2
, 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
381 { SONYPI_DEVICE_MODEL_TYPE2
, 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
382 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
383 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
384 { SONYPI_DEVICE_MODEL_TYPE2
, 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
385 { SONYPI_DEVICE_MODEL_TYPE2
, 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
386 { SONYPI_DEVICE_MODEL_TYPE2
, 0x08, SONYPI_HELP_MASK
, sonypi_helpev
},
387 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
388 { SONYPI_DEVICE_MODEL_TYPE2
, 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
389 { SONYPI_DEVICE_MODEL_TYPE2
, 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
390 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
391 { SONYPI_DEVICE_MODEL_TYPE2
, 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
392 { SONYPI_DEVICE_MODEL_TYPE2
, 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
397 #define SONYPI_BUF_SIZE 128
399 /* The name of the devices for the input device drivers */
400 #define SONYPI_JOG_INPUTNAME "Sony Vaio Jogdial"
401 #define SONYPI_KEY_INPUTNAME "Sony Vaio Keys"
403 /* Correspondance table between sonypi events and input layer events */
407 } sonypi_inputkeys
[] = {
408 { SONYPI_EVENT_CAPTURE_PRESSED
, KEY_CAMERA
},
409 { SONYPI_EVENT_FNKEY_ONLY
, KEY_FN
},
410 { SONYPI_EVENT_FNKEY_ESC
, KEY_FN_ESC
},
411 { SONYPI_EVENT_FNKEY_F1
, KEY_FN_F1
},
412 { SONYPI_EVENT_FNKEY_F2
, KEY_FN_F2
},
413 { SONYPI_EVENT_FNKEY_F3
, KEY_FN_F3
},
414 { SONYPI_EVENT_FNKEY_F4
, KEY_FN_F4
},
415 { SONYPI_EVENT_FNKEY_F5
, KEY_FN_F5
},
416 { SONYPI_EVENT_FNKEY_F6
, KEY_FN_F6
},
417 { SONYPI_EVENT_FNKEY_F7
, KEY_FN_F7
},
418 { SONYPI_EVENT_FNKEY_F8
, KEY_FN_F8
},
419 { SONYPI_EVENT_FNKEY_F9
, KEY_FN_F9
},
420 { SONYPI_EVENT_FNKEY_F10
, KEY_FN_F10
},
421 { SONYPI_EVENT_FNKEY_F11
, KEY_FN_F11
},
422 { SONYPI_EVENT_FNKEY_F12
, KEY_FN_F12
},
423 { SONYPI_EVENT_FNKEY_1
, KEY_FN_1
},
424 { SONYPI_EVENT_FNKEY_2
, KEY_FN_2
},
425 { SONYPI_EVENT_FNKEY_D
, KEY_FN_D
},
426 { SONYPI_EVENT_FNKEY_E
, KEY_FN_E
},
427 { SONYPI_EVENT_FNKEY_F
, KEY_FN_F
},
428 { SONYPI_EVENT_FNKEY_S
, KEY_FN_S
},
429 { SONYPI_EVENT_FNKEY_B
, KEY_FN_B
},
430 { SONYPI_EVENT_BLUETOOTH_PRESSED
, KEY_BLUE
},
431 { SONYPI_EVENT_BLUETOOTH_ON
, KEY_BLUE
},
432 { SONYPI_EVENT_PKEY_P1
, KEY_PROG1
},
433 { SONYPI_EVENT_PKEY_P2
, KEY_PROG2
},
434 { SONYPI_EVENT_PKEY_P3
, KEY_PROG3
},
435 { SONYPI_EVENT_BACK_PRESSED
, KEY_BACK
},
436 { SONYPI_EVENT_HELP_PRESSED
, KEY_HELP
},
437 { SONYPI_EVENT_ZOOM_PRESSED
, KEY_ZOOM
},
438 { SONYPI_EVENT_THUMBPHRASE_PRESSED
, BTN_THUMB
},
442 static struct sonypi_device
{
444 struct platform_device
*pdev
;
453 struct semaphore lock
;
455 spinlock_t fifo_lock
;
456 wait_queue_head_t fifo_proc_list
;
457 struct fasync_struct
*fifo_async
;
460 struct input_dev input_jog_dev
;
461 struct input_dev input_key_dev
;
462 struct work_struct input_work
;
463 struct kfifo
*input_fifo
;
464 spinlock_t input_fifo_lock
;
467 #define ITERATIONS_LONG 10000
468 #define ITERATIONS_SHORT 10
470 #define wait_on_command(quiet, command, iterations) { \
471 unsigned int n = iterations; \
472 while (--n && (command)) \
474 if (!n && (verbose || !quiet)) \
475 printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __FUNCTION__, __LINE__); \
479 #define SONYPI_ACPI_ACTIVE (!acpi_disabled)
481 #define SONYPI_ACPI_ACTIVE 0
482 #endif /* CONFIG_ACPI */
484 static int sonypi_ec_write(u8 addr
, u8 value
)
486 #ifdef CONFIG_ACPI_EC
487 if (SONYPI_ACPI_ACTIVE
)
488 return ec_write(addr
, value
);
490 wait_on_command(1, inb_p(SONYPI_CST_IOPORT
) & 3, ITERATIONS_LONG
);
491 outb_p(0x81, SONYPI_CST_IOPORT
);
492 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
493 outb_p(addr
, SONYPI_DATA_IOPORT
);
494 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
495 outb_p(value
, SONYPI_DATA_IOPORT
);
496 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
500 static int sonypi_ec_read(u8 addr
, u8
*value
)
502 #ifdef CONFIG_ACPI_EC
503 if (SONYPI_ACPI_ACTIVE
)
504 return ec_read(addr
, value
);
506 wait_on_command(1, inb_p(SONYPI_CST_IOPORT
) & 3, ITERATIONS_LONG
);
507 outb_p(0x80, SONYPI_CST_IOPORT
);
508 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
509 outb_p(addr
, SONYPI_DATA_IOPORT
);
510 wait_on_command(0, inb_p(SONYPI_CST_IOPORT
) & 2, ITERATIONS_LONG
);
511 *value
= inb_p(SONYPI_DATA_IOPORT
);
515 static int ec_read16(u8 addr
, u16
*value
)
518 if (sonypi_ec_read(addr
, &val_lb
))
520 if (sonypi_ec_read(addr
+ 1, &val_hb
))
522 *value
= val_lb
| (val_hb
<< 8);
526 /* Initializes the device - this comes from the AML code in the ACPI bios */
527 static void sonypi_type1_srs(void)
531 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
532 v
= (v
& 0xFFFF0000) | ((u32
) sonypi_device
.ioport1
);
533 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
535 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
536 v
= (v
& 0xFFF0FFFF) |
537 (((u32
) sonypi_device
.ioport1
^ sonypi_device
.ioport2
) << 16);
538 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
540 v
= inl(SONYPI_IRQ_PORT
);
541 v
&= ~(((u32
) 0x3) << SONYPI_IRQ_SHIFT
);
542 v
|= (((u32
) sonypi_device
.bits
) << SONYPI_IRQ_SHIFT
);
543 outl(v
, SONYPI_IRQ_PORT
);
545 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
546 v
= (v
& 0xFF1FFFFF) | 0x00C00000;
547 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
550 static void sonypi_type2_srs(void)
552 if (sonypi_ec_write(SONYPI_SHIB
, (sonypi_device
.ioport1
& 0xFF00) >> 8))
553 printk(KERN_WARNING
"ec_write failed\n");
554 if (sonypi_ec_write(SONYPI_SLOB
, sonypi_device
.ioport1
& 0x00FF))
555 printk(KERN_WARNING
"ec_write failed\n");
556 if (sonypi_ec_write(SONYPI_SIRQ
, sonypi_device
.bits
))
557 printk(KERN_WARNING
"ec_write failed\n");
561 /* Disables the device - this comes from the AML code in the ACPI bios */
562 static void sonypi_type1_dis(void)
566 pci_read_config_dword(sonypi_device
.dev
, SONYPI_G10A
, &v
);
568 pci_write_config_dword(sonypi_device
.dev
, SONYPI_G10A
, v
);
570 v
= inl(SONYPI_IRQ_PORT
);
571 v
|= (0x3 << SONYPI_IRQ_SHIFT
);
572 outl(v
, SONYPI_IRQ_PORT
);
575 static void sonypi_type2_dis(void)
577 if (sonypi_ec_write(SONYPI_SHIB
, 0))
578 printk(KERN_WARNING
"ec_write failed\n");
579 if (sonypi_ec_write(SONYPI_SLOB
, 0))
580 printk(KERN_WARNING
"ec_write failed\n");
581 if (sonypi_ec_write(SONYPI_SIRQ
, 0))
582 printk(KERN_WARNING
"ec_write failed\n");
585 static u8
sonypi_call1(u8 dev
)
589 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
590 outb(dev
, sonypi_device
.ioport2
);
591 v1
= inb_p(sonypi_device
.ioport2
);
592 v2
= inb_p(sonypi_device
.ioport1
);
596 static u8
sonypi_call2(u8 dev
, u8 fn
)
600 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
601 outb(dev
, sonypi_device
.ioport2
);
602 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
603 outb(fn
, sonypi_device
.ioport1
);
604 v1
= inb_p(sonypi_device
.ioport1
);
608 static u8
sonypi_call3(u8 dev
, u8 fn
, u8 v
)
612 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
613 outb(dev
, sonypi_device
.ioport2
);
614 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
615 outb(fn
, sonypi_device
.ioport1
);
616 wait_on_command(0, inb_p(sonypi_device
.ioport2
) & 2, ITERATIONS_LONG
);
617 outb(v
, sonypi_device
.ioport1
);
618 v1
= inb_p(sonypi_device
.ioport1
);
623 /* Get brightness, hue etc. Unreliable... */
624 static u8
sonypi_read(u8 fn
)
630 v1
= sonypi_call2(0x8f, fn
);
631 v2
= sonypi_call2(0x8f, fn
);
632 if (v1
== v2
&& v1
!= 0xff)
639 /* Set brightness, hue etc */
640 static void sonypi_set(u8 fn
, u8 v
)
642 wait_on_command(0, sonypi_call3(0x90, fn
, v
), ITERATIONS_SHORT
);
645 /* Tests if the camera is ready */
646 static int sonypi_camera_ready(void)
650 v
= sonypi_call2(0x8f, SONYPI_CAMERA_STATUS
);
651 return (v
!= 0xff && (v
& SONYPI_CAMERA_STATUS_READY
));
654 /* Turns the camera off */
655 static void sonypi_camera_off(void)
657 sonypi_set(SONYPI_CAMERA_PICTURE
, SONYPI_CAMERA_MUTE_MASK
);
659 if (!sonypi_device
.camera_power
)
662 sonypi_call2(0x91, 0);
663 sonypi_device
.camera_power
= 0;
666 /* Turns the camera on */
667 static void sonypi_camera_on(void)
671 if (sonypi_device
.camera_power
)
674 for (j
= 5; j
> 0; j
--) {
676 while (sonypi_call2(0x91, 0x1))
680 for (i
= 400; i
> 0; i
--) {
681 if (sonypi_camera_ready())
690 printk(KERN_WARNING
"sonypi: failed to power on camera\n");
694 sonypi_set(0x10, 0x5a);
695 sonypi_device
.camera_power
= 1;
698 /* sets the bluetooth subsystem power state */
699 static void sonypi_setbluetoothpower(u8 state
)
703 if (sonypi_device
.bluetooth_power
== state
)
706 sonypi_call2(0x96, state
);
708 sonypi_device
.bluetooth_power
= state
;
711 static void input_keyrelease(void *data
)
713 struct input_dev
*input_dev
;
717 if (kfifo_get(sonypi_device
.input_fifo
,
718 (unsigned char *)&input_dev
,
719 sizeof(input_dev
)) != sizeof(input_dev
))
721 if (kfifo_get(sonypi_device
.input_fifo
,
722 (unsigned char *)&key
,
723 sizeof(key
)) != sizeof(key
))
727 input_report_key(input_dev
, key
, 0);
728 input_sync(input_dev
);
732 /* Interrupt handler: some event is available */
733 static irqreturn_t
sonypi_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
735 u8 v1
, v2
, event
= 0;
738 v1
= inb_p(sonypi_device
.ioport1
);
739 v2
= inb_p(sonypi_device
.ioport1
+ sonypi_device
.evtype_offset
);
741 for (i
= 0; sonypi_eventtypes
[i
].model
; i
++) {
742 if (sonypi_device
.model
!= sonypi_eventtypes
[i
].model
)
744 if ((v2
& sonypi_eventtypes
[i
].data
) !=
745 sonypi_eventtypes
[i
].data
)
747 if (!(mask
& sonypi_eventtypes
[i
].mask
))
749 for (j
= 0; sonypi_eventtypes
[i
].events
[j
].event
; j
++) {
750 if (v1
== sonypi_eventtypes
[i
].events
[j
].data
) {
751 event
= sonypi_eventtypes
[i
].events
[j
].event
;
759 "sonypi: unknown event port1=0x%02x,port2=0x%02x\n",
761 /* We need to return IRQ_HANDLED here because there *are*
762 * events belonging to the sonypi device we don't know about,
763 * but we still don't want those to pollute the logs... */
769 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1
, v2
);
772 struct input_dev
*input_jog_dev
= &sonypi_device
.input_jog_dev
;
773 struct input_dev
*input_key_dev
= &sonypi_device
.input_key_dev
;
775 case SONYPI_EVENT_JOGDIAL_UP
:
776 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
777 input_report_rel(input_jog_dev
, REL_WHEEL
, 1);
779 case SONYPI_EVENT_JOGDIAL_DOWN
:
780 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
781 input_report_rel(input_jog_dev
, REL_WHEEL
, -1);
783 case SONYPI_EVENT_JOGDIAL_PRESSED
: {
784 int key
= BTN_MIDDLE
;
785 input_report_key(input_jog_dev
, key
, 1);
786 kfifo_put(sonypi_device
.input_fifo
,
787 (unsigned char *)&input_jog_dev
,
788 sizeof(input_jog_dev
));
789 kfifo_put(sonypi_device
.input_fifo
,
790 (unsigned char *)&key
, sizeof(key
));
793 case SONYPI_EVENT_FNKEY_RELEASED
:
794 /* Nothing, not all VAIOs generate this event */
797 input_sync(input_jog_dev
);
799 for (i
= 0; sonypi_inputkeys
[i
].sonypiev
; i
++) {
802 if (event
!= sonypi_inputkeys
[i
].sonypiev
)
805 key
= sonypi_inputkeys
[i
].inputev
;
806 input_report_key(input_key_dev
, key
, 1);
807 kfifo_put(sonypi_device
.input_fifo
,
808 (unsigned char *)&input_key_dev
,
809 sizeof(input_key_dev
));
810 kfifo_put(sonypi_device
.input_fifo
,
811 (unsigned char *)&key
, sizeof(key
));
813 input_sync(input_key_dev
);
814 schedule_work(&sonypi_device
.input_work
);
817 kfifo_put(sonypi_device
.fifo
, (unsigned char *)&event
, sizeof(event
));
818 kill_fasync(&sonypi_device
.fifo_async
, SIGIO
, POLL_IN
);
819 wake_up_interruptible(&sonypi_device
.fifo_proc_list
);
824 /* External camera command (exported to the motion eye v4l driver) */
825 int sonypi_camera_command(int command
, u8 value
)
830 down(&sonypi_device
.lock
);
833 case SONYPI_COMMAND_SETCAMERA
:
839 case SONYPI_COMMAND_SETCAMERABRIGHTNESS
:
840 sonypi_set(SONYPI_CAMERA_BRIGHTNESS
, value
);
842 case SONYPI_COMMAND_SETCAMERACONTRAST
:
843 sonypi_set(SONYPI_CAMERA_CONTRAST
, value
);
845 case SONYPI_COMMAND_SETCAMERAHUE
:
846 sonypi_set(SONYPI_CAMERA_HUE
, value
);
848 case SONYPI_COMMAND_SETCAMERACOLOR
:
849 sonypi_set(SONYPI_CAMERA_COLOR
, value
);
851 case SONYPI_COMMAND_SETCAMERASHARPNESS
:
852 sonypi_set(SONYPI_CAMERA_SHARPNESS
, value
);
854 case SONYPI_COMMAND_SETCAMERAPICTURE
:
855 sonypi_set(SONYPI_CAMERA_PICTURE
, value
);
857 case SONYPI_COMMAND_SETCAMERAAGC
:
858 sonypi_set(SONYPI_CAMERA_AGC
, value
);
861 printk(KERN_ERR
"sonypi: sonypi_camera_command invalid: %d\n",
865 up(&sonypi_device
.lock
);
869 EXPORT_SYMBOL(sonypi_camera_command
);
871 static int sonypi_misc_fasync(int fd
, struct file
*filp
, int on
)
875 retval
= fasync_helper(fd
, filp
, on
, &sonypi_device
.fifo_async
);
881 static int sonypi_misc_release(struct inode
*inode
, struct file
*file
)
883 sonypi_misc_fasync(-1, file
, 0);
884 down(&sonypi_device
.lock
);
885 sonypi_device
.open_count
--;
886 up(&sonypi_device
.lock
);
890 static int sonypi_misc_open(struct inode
*inode
, struct file
*file
)
892 down(&sonypi_device
.lock
);
893 /* Flush input queue on first open */
894 if (!sonypi_device
.open_count
)
895 kfifo_reset(sonypi_device
.fifo
);
896 sonypi_device
.open_count
++;
897 up(&sonypi_device
.lock
);
901 static ssize_t
sonypi_misc_read(struct file
*file
, char __user
*buf
,
902 size_t count
, loff_t
*pos
)
907 if ((kfifo_len(sonypi_device
.fifo
) == 0) &&
908 (file
->f_flags
& O_NONBLOCK
))
911 ret
= wait_event_interruptible(sonypi_device
.fifo_proc_list
,
912 kfifo_len(sonypi_device
.fifo
) != 0);
916 while (ret
< count
&&
917 (kfifo_get(sonypi_device
.fifo
, &c
, sizeof(c
)) == sizeof(c
))) {
918 if (put_user(c
, buf
++))
924 struct inode
*inode
= file
->f_dentry
->d_inode
;
925 inode
->i_atime
= current_fs_time(inode
->i_sb
);
931 static unsigned int sonypi_misc_poll(struct file
*file
, poll_table
*wait
)
933 poll_wait(file
, &sonypi_device
.fifo_proc_list
, wait
);
934 if (kfifo_len(sonypi_device
.fifo
))
935 return POLLIN
| POLLRDNORM
;
939 static int sonypi_misc_ioctl(struct inode
*ip
, struct file
*fp
,
940 unsigned int cmd
, unsigned long arg
)
943 void __user
*argp
= (void __user
*)arg
;
947 down(&sonypi_device
.lock
);
950 if (sonypi_ec_read(SONYPI_LCD_LIGHT
, &val8
)) {
954 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
958 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
962 if (sonypi_ec_write(SONYPI_LCD_LIGHT
, val8
))
965 case SONYPI_IOCGBAT1CAP
:
966 if (ec_read16(SONYPI_BAT1_FULL
, &val16
)) {
970 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
973 case SONYPI_IOCGBAT1REM
:
974 if (ec_read16(SONYPI_BAT1_LEFT
, &val16
)) {
978 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
981 case SONYPI_IOCGBAT2CAP
:
982 if (ec_read16(SONYPI_BAT2_FULL
, &val16
)) {
986 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
989 case SONYPI_IOCGBAT2REM
:
990 if (ec_read16(SONYPI_BAT2_LEFT
, &val16
)) {
994 if (copy_to_user(argp
, &val16
, sizeof(val16
)))
997 case SONYPI_IOCGBATFLAGS
:
998 if (sonypi_ec_read(SONYPI_BAT_FLAGS
, &val8
)) {
1003 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1006 case SONYPI_IOCGBLUE
:
1007 val8
= sonypi_device
.bluetooth_power
;
1008 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1011 case SONYPI_IOCSBLUE
:
1012 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
1016 sonypi_setbluetoothpower(val8
);
1019 case SONYPI_IOCGFAN
:
1020 if (sonypi_ec_read(SONYPI_FAN0_STATUS
, &val8
)) {
1024 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1027 case SONYPI_IOCSFAN
:
1028 if (copy_from_user(&val8
, argp
, sizeof(val8
))) {
1032 if (sonypi_ec_write(SONYPI_FAN0_STATUS
, val8
))
1035 /* GET Temperature (useful under APM) */
1036 case SONYPI_IOCGTEMP
:
1037 if (sonypi_ec_read(SONYPI_TEMP_STATUS
, &val8
)) {
1041 if (copy_to_user(argp
, &val8
, sizeof(val8
)))
1047 up(&sonypi_device
.lock
);
1051 static struct file_operations sonypi_misc_fops
= {
1052 .owner
= THIS_MODULE
,
1053 .read
= sonypi_misc_read
,
1054 .poll
= sonypi_misc_poll
,
1055 .open
= sonypi_misc_open
,
1056 .release
= sonypi_misc_release
,
1057 .fasync
= sonypi_misc_fasync
,
1058 .ioctl
= sonypi_misc_ioctl
,
1061 static struct miscdevice sonypi_misc_device
= {
1062 .minor
= MISC_DYNAMIC_MINOR
,
1064 .fops
= &sonypi_misc_fops
,
1067 static void sonypi_enable(unsigned int camera_on
)
1069 if (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE2
)
1075 sonypi_call2(0x81, 0xff);
1076 sonypi_call1(compat
? 0x92 : 0x82);
1078 /* Enable ACPI mode to get Fn key events */
1079 if (!SONYPI_ACPI_ACTIVE
&& fnkeyinit
)
1082 if (camera
&& camera_on
)
1086 static int sonypi_disable(void)
1088 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
1090 sonypi_camera_off();
1092 /* disable ACPI mode */
1093 if (!SONYPI_ACPI_ACTIVE
&& fnkeyinit
)
1096 if (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE2
)
1104 static int old_camera_power
;
1106 static int sonypi_suspend(struct device
*dev
, pm_message_t state
, u32 level
)
1108 if (level
== SUSPEND_DISABLE
) {
1109 old_camera_power
= sonypi_device
.camera_power
;
1115 static int sonypi_resume(struct device
*dev
, u32 level
)
1117 if (level
== RESUME_ENABLE
)
1118 sonypi_enable(old_camera_power
);
1123 static void sonypi_shutdown(struct device
*dev
)
1128 static struct device_driver sonypi_driver
= {
1130 .bus
= &platform_bus_type
,
1132 .suspend
= sonypi_suspend
,
1133 .resume
= sonypi_resume
,
1135 .shutdown
= sonypi_shutdown
,
1138 static int __devinit
sonypi_probe(void)
1141 struct sonypi_ioport_list
*ioport_list
;
1142 struct sonypi_irq_list
*irq_list
;
1143 struct pci_dev
*pcidev
;
1145 pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1146 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
);
1148 sonypi_device
.dev
= pcidev
;
1149 sonypi_device
.model
= pcidev
?
1150 SONYPI_DEVICE_MODEL_TYPE1
: SONYPI_DEVICE_MODEL_TYPE2
;
1152 spin_lock_init(&sonypi_device
.fifo_lock
);
1153 sonypi_device
.fifo
= kfifo_alloc(SONYPI_BUF_SIZE
, GFP_KERNEL
,
1154 &sonypi_device
.fifo_lock
);
1155 if (IS_ERR(sonypi_device
.fifo
)) {
1156 printk(KERN_ERR
"sonypi: kfifo_alloc failed\n");
1157 ret
= PTR_ERR(sonypi_device
.fifo
);
1161 init_waitqueue_head(&sonypi_device
.fifo_proc_list
);
1162 init_MUTEX(&sonypi_device
.lock
);
1163 sonypi_device
.bluetooth_power
= -1;
1165 if (pcidev
&& pci_enable_device(pcidev
)) {
1166 printk(KERN_ERR
"sonypi: pci_enable_device failed\n");
1172 sonypi_misc_device
.minor
= minor
;
1173 if ((ret
= misc_register(&sonypi_misc_device
))) {
1174 printk(KERN_ERR
"sonypi: misc_register failed\n");
1178 if (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE2
) {
1179 ioport_list
= sonypi_type2_ioport_list
;
1180 sonypi_device
.region_size
= SONYPI_TYPE2_REGION_SIZE
;
1181 sonypi_device
.evtype_offset
= SONYPI_TYPE2_EVTYPE_OFFSET
;
1182 irq_list
= sonypi_type2_irq_list
;
1184 ioport_list
= sonypi_type1_ioport_list
;
1185 sonypi_device
.region_size
= SONYPI_TYPE1_REGION_SIZE
;
1186 sonypi_device
.evtype_offset
= SONYPI_TYPE1_EVTYPE_OFFSET
;
1187 irq_list
= sonypi_type1_irq_list
;
1190 for (i
= 0; ioport_list
[i
].port1
; i
++) {
1191 if (request_region(ioport_list
[i
].port1
,
1192 sonypi_device
.region_size
,
1193 "Sony Programable I/O Device")) {
1194 /* get the ioport */
1195 sonypi_device
.ioport1
= ioport_list
[i
].port1
;
1196 sonypi_device
.ioport2
= ioport_list
[i
].port2
;
1200 if (!sonypi_device
.ioport1
) {
1201 printk(KERN_ERR
"sonypi: request_region failed\n");
1206 for (i
= 0; irq_list
[i
].irq
; i
++) {
1208 sonypi_device
.irq
= irq_list
[i
].irq
;
1209 sonypi_device
.bits
= irq_list
[i
].bits
;
1211 if (!request_irq(sonypi_device
.irq
, sonypi_irq
,
1212 SA_SHIRQ
, "sonypi", sonypi_irq
))
1216 if (!irq_list
[i
].irq
) {
1217 printk(KERN_ERR
"sonypi: request_irq failed\n");
1223 /* Initialize the Input Drivers: jogdial */
1225 sonypi_device
.input_jog_dev
.evbit
[0] =
1226 BIT(EV_KEY
) | BIT(EV_REL
);
1227 sonypi_device
.input_jog_dev
.keybit
[LONG(BTN_MOUSE
)] =
1229 sonypi_device
.input_jog_dev
.relbit
[0] = BIT(REL_WHEEL
);
1230 sonypi_device
.input_jog_dev
.name
=
1231 kmalloc(sizeof(SONYPI_JOG_INPUTNAME
), GFP_KERNEL
);
1232 if (!sonypi_device
.input_jog_dev
.name
) {
1233 printk(KERN_ERR
"sonypi: kmalloc failed\n");
1235 goto out_inkmallocinput1
;
1237 sprintf(sonypi_device
.input_jog_dev
.name
, SONYPI_JOG_INPUTNAME
);
1238 sonypi_device
.input_jog_dev
.id
.bustype
= BUS_ISA
;
1239 sonypi_device
.input_jog_dev
.id
.vendor
= PCI_VENDOR_ID_SONY
;
1241 input_register_device(&sonypi_device
.input_jog_dev
);
1242 printk(KERN_INFO
"%s input method installed.\n",
1243 sonypi_device
.input_jog_dev
.name
);
1245 /* Initialize the Input Drivers: special keys */
1246 sonypi_device
.input_key_dev
.evbit
[0] = BIT(EV_KEY
);
1247 for (i
= 0; sonypi_inputkeys
[i
].sonypiev
; i
++)
1248 if (sonypi_inputkeys
[i
].inputev
)
1249 set_bit(sonypi_inputkeys
[i
].inputev
,
1250 sonypi_device
.input_key_dev
.keybit
);
1251 sonypi_device
.input_key_dev
.name
=
1252 kmalloc(sizeof(SONYPI_KEY_INPUTNAME
), GFP_KERNEL
);
1253 if (!sonypi_device
.input_key_dev
.name
) {
1254 printk(KERN_ERR
"sonypi: kmalloc failed\n");
1256 goto out_inkmallocinput2
;
1258 sprintf(sonypi_device
.input_key_dev
.name
, SONYPI_KEY_INPUTNAME
);
1259 sonypi_device
.input_key_dev
.id
.bustype
= BUS_ISA
;
1260 sonypi_device
.input_key_dev
.id
.vendor
= PCI_VENDOR_ID_SONY
;
1262 input_register_device(&sonypi_device
.input_key_dev
);
1263 printk(KERN_INFO
"%s input method installed.\n",
1264 sonypi_device
.input_key_dev
.name
);
1266 spin_lock_init(&sonypi_device
.input_fifo_lock
);
1267 sonypi_device
.input_fifo
=
1268 kfifo_alloc(SONYPI_BUF_SIZE
, GFP_KERNEL
,
1269 &sonypi_device
.input_fifo_lock
);
1270 if (IS_ERR(sonypi_device
.input_fifo
)) {
1271 printk(KERN_ERR
"sonypi: kfifo_alloc failed\n");
1272 ret
= PTR_ERR(sonypi_device
.input_fifo
);
1276 INIT_WORK(&sonypi_device
.input_work
, input_keyrelease
, NULL
);
1279 sonypi_device
.pdev
= platform_device_register_simple("sonypi", -1,
1281 if (IS_ERR(sonypi_device
.pdev
)) {
1282 ret
= PTR_ERR(sonypi_device
.pdev
);
1283 goto out_platformdev
;
1288 printk(KERN_INFO
"sonypi: Sony Programmable I/O Controller Driver"
1289 "v%s.\n", SONYPI_DRIVER_VERSION
);
1290 printk(KERN_INFO
"sonypi: detected %s model, "
1291 "verbose = %d, fnkeyinit = %s, camera = %s, "
1292 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
1293 (sonypi_device
.model
== SONYPI_DEVICE_MODEL_TYPE1
) ?
1296 fnkeyinit
? "on" : "off",
1297 camera
? "on" : "off",
1298 compat
? "on" : "off",
1300 useinput
? "on" : "off",
1301 SONYPI_ACPI_ACTIVE
? "on" : "off");
1302 printk(KERN_INFO
"sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
1304 sonypi_device
.ioport1
, sonypi_device
.ioport2
);
1307 printk(KERN_INFO
"sonypi: device allocated minor is %d\n",
1308 sonypi_misc_device
.minor
);
1313 kfifo_free(sonypi_device
.input_fifo
);
1315 input_unregister_device(&sonypi_device
.input_key_dev
);
1316 kfree(sonypi_device
.input_key_dev
.name
);
1317 out_inkmallocinput2
:
1318 input_unregister_device(&sonypi_device
.input_jog_dev
);
1319 kfree(sonypi_device
.input_jog_dev
.name
);
1320 out_inkmallocinput1
:
1321 free_irq(sonypi_device
.irq
, sonypi_irq
);
1323 release_region(sonypi_device
.ioport1
, sonypi_device
.region_size
);
1325 misc_deregister(&sonypi_misc_device
);
1328 pci_disable_device(pcidev
);
1330 kfifo_free(sonypi_device
.fifo
);
1332 pci_dev_put(sonypi_device
.dev
);
1336 static void __devexit
sonypi_remove(void)
1340 platform_device_unregister(sonypi_device
.pdev
);
1343 input_unregister_device(&sonypi_device
.input_key_dev
);
1344 kfree(sonypi_device
.input_key_dev
.name
);
1345 input_unregister_device(&sonypi_device
.input_jog_dev
);
1346 kfree(sonypi_device
.input_jog_dev
.name
);
1347 kfifo_free(sonypi_device
.input_fifo
);
1350 free_irq(sonypi_device
.irq
, sonypi_irq
);
1351 release_region(sonypi_device
.ioport1
, sonypi_device
.region_size
);
1352 misc_deregister(&sonypi_misc_device
);
1353 if (sonypi_device
.dev
)
1354 pci_disable_device(sonypi_device
.dev
);
1355 kfifo_free(sonypi_device
.fifo
);
1356 pci_dev_put(sonypi_device
.dev
);
1357 printk(KERN_INFO
"sonypi: removed.\n");
1360 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
1362 .ident
= "Sony Vaio",
1364 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1365 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
1369 .ident
= "Sony Vaio",
1371 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1372 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
1378 static int __init
sonypi_init(void)
1382 if (!dmi_check_system(sonypi_dmi_table
))
1385 ret
= driver_register(&sonypi_driver
);
1389 ret
= sonypi_probe();
1391 driver_unregister(&sonypi_driver
);
1396 static void __exit
sonypi_exit(void)
1398 driver_unregister(&sonypi_driver
);
1402 module_init(sonypi_init
);
1403 module_exit(sonypi_exit
);