2 * Sony Programmable I/O Control Device driver for VAIO
4 * Copyright (C) 2001-2003 Stelian Pop <stelian@popies.net>
6 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
8 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
10 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
12 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
14 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
16 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/input.h>
37 #include <linux/pci.h>
38 #include <linux/sched.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/sysdev.h>
49 #include <asm/uaccess.h>
51 #include <asm/system.h>
54 #include <linux/sonypi.h>
56 static struct sonypi_device sonypi_device;
57 static int minor = -1;
58 static int verbose; /* = 0 */
59 static int fnkeyinit; /* = 0 */
60 static int camera; /* = 0 */
61 static int compat; /* = 0 */
62 static int useinput = 1;
63 static unsigned long mask = 0xffffffff;
66 static inline void sonypi_initq(void) {
67 sonypi_device.queue.head = sonypi_device.queue.tail = 0;
68 sonypi_device.queue.len = 0;
69 sonypi_device.queue.s_lock = (spinlock_t)SPIN_LOCK_UNLOCKED;
70 init_waitqueue_head(&sonypi_device.queue.proc_list);
73 /* Pulls an event from the queue */
74 static inline unsigned char sonypi_pullq(void) {
78 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
79 if (!sonypi_device.queue.len) {
80 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
83 result = sonypi_device.queue.buf[sonypi_device.queue.head];
84 sonypi_device.queue.head++;
85 sonypi_device.queue.head &= (SONYPI_BUF_SIZE - 1);
86 sonypi_device.queue.len--;
87 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
91 /* Pushes an event into the queue */
92 static inline void sonypi_pushq(unsigned char event) {
95 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
96 if (sonypi_device.queue.len == SONYPI_BUF_SIZE) {
97 /* remove the first element */
98 sonypi_device.queue.head++;
99 sonypi_device.queue.head &= (SONYPI_BUF_SIZE - 1);
100 sonypi_device.queue.len--;
102 sonypi_device.queue.buf[sonypi_device.queue.tail] = event;
103 sonypi_device.queue.tail++;
104 sonypi_device.queue.tail &= (SONYPI_BUF_SIZE - 1);
105 sonypi_device.queue.len++;
107 kill_fasync(&sonypi_device.queue.fasync, SIGIO, POLL_IN);
108 wake_up_interruptible(&sonypi_device.queue.proc_list);
109 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
112 /* Tests if the queue is empty */
113 static inline int sonypi_emptyq(void) {
117 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
118 result = (sonypi_device.queue.len == 0);
119 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
123 static int ec_read16(u8 addr, u16 *value) {
125 if (sonypi_ec_read(addr, &val_lb))
127 if (sonypi_ec_read(addr + 1, &val_hb))
129 *value = val_lb | (val_hb << 8);
133 /* Initializes the device - this comes from the AML code in the ACPI bios */
134 static void sonypi_type1_srs(void) {
137 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
138 v = (v & 0xFFFF0000) | ((u32)sonypi_device.ioport1);
139 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
141 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
142 v = (v & 0xFFF0FFFF) |
143 (((u32)sonypi_device.ioport1 ^ sonypi_device.ioport2) << 16);
144 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
146 v = inl(SONYPI_IRQ_PORT);
147 v &= ~(((u32)0x3) << SONYPI_IRQ_SHIFT);
148 v |= (((u32)sonypi_device.bits) << SONYPI_IRQ_SHIFT);
149 outl(v, SONYPI_IRQ_PORT);
151 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
152 v = (v & 0xFF1FFFFF) | 0x00C00000;
153 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
156 static void sonypi_type2_srs(void) {
157 if (sonypi_ec_write(SONYPI_SHIB, (sonypi_device.ioport1 & 0xFF00) >> 8))
158 printk(KERN_WARNING "ec_write failed\n");
159 if (sonypi_ec_write(SONYPI_SLOB, sonypi_device.ioport1 & 0x00FF))
160 printk(KERN_WARNING "ec_write failed\n");
161 if (sonypi_ec_write(SONYPI_SIRQ, sonypi_device.bits))
162 printk(KERN_WARNING "ec_write failed\n");
166 /* Disables the device - this comes from the AML code in the ACPI bios */
167 static void sonypi_type1_dis(void) {
170 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
172 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
174 v = inl(SONYPI_IRQ_PORT);
175 v |= (0x3 << SONYPI_IRQ_SHIFT);
176 outl(v, SONYPI_IRQ_PORT);
179 static void sonypi_type2_dis(void) {
180 if (sonypi_ec_write(SONYPI_SHIB, 0))
181 printk(KERN_WARNING "ec_write failed\n");
182 if (sonypi_ec_write(SONYPI_SLOB, 0))
183 printk(KERN_WARNING "ec_write failed\n");
184 if (sonypi_ec_write(SONYPI_SIRQ, 0))
185 printk(KERN_WARNING "ec_write failed\n");
188 static u8 sonypi_call1(u8 dev) {
191 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
192 outb(dev, sonypi_device.ioport2);
193 v1 = inb_p(sonypi_device.ioport2);
194 v2 = inb_p(sonypi_device.ioport1);
198 static u8 sonypi_call2(u8 dev, u8 fn) {
201 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
202 outb(dev, sonypi_device.ioport2);
203 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
204 outb(fn, sonypi_device.ioport1);
205 v1 = inb_p(sonypi_device.ioport1);
209 static u8 sonypi_call3(u8 dev, u8 fn, u8 v) {
212 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
213 outb(dev, sonypi_device.ioport2);
214 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
215 outb(fn, sonypi_device.ioport1);
216 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
217 outb(v, sonypi_device.ioport1);
218 v1 = inb_p(sonypi_device.ioport1);
222 static u8 sonypi_read(u8 fn) {
227 v1 = sonypi_call2(0x8f, fn);
228 v2 = sonypi_call2(0x8f, fn);
229 if (v1 == v2 && v1 != 0xff)
235 /* Set brightness, hue etc */
236 static void sonypi_set(u8 fn, u8 v) {
238 wait_on_command(0, sonypi_call3(0x90, fn, v), ITERATIONS_SHORT);
241 /* Tests if the camera is ready */
242 static int sonypi_camera_ready(void) {
245 v = sonypi_call2(0x8f, SONYPI_CAMERA_STATUS);
246 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
249 /* Turns the camera off */
250 static void sonypi_camera_off(void) {
252 sonypi_set(SONYPI_CAMERA_PICTURE, SONYPI_CAMERA_MUTE_MASK);
254 if (!sonypi_device.camera_power)
257 sonypi_call2(0x91, 0);
258 sonypi_device.camera_power = 0;
261 /* Turns the camera on */
262 static void sonypi_camera_on(void) {
265 if (sonypi_device.camera_power)
268 for (j = 5; j > 0; j--) {
270 while (sonypi_call2(0x91, 0x1)) {
271 set_current_state(TASK_UNINTERRUPTIBLE);
276 for (i = 400; i > 0; i--) {
277 if (sonypi_camera_ready())
279 set_current_state(TASK_UNINTERRUPTIBLE);
287 printk(KERN_WARNING "sonypi: failed to power on camera\n");
291 sonypi_set(0x10, 0x5a);
292 sonypi_device.camera_power = 1;
295 /* sets the bluetooth subsystem power state */
296 static void sonypi_setbluetoothpower(u8 state) {
299 if (sonypi_device.bluetooth_power == state)
302 sonypi_call2(0x96, state);
304 sonypi_device.bluetooth_power = state;
307 /* Interrupt handler: some event is available */
308 static irqreturn_t sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) {
309 u8 v1, v2, event = 0;
312 v1 = inb_p(sonypi_device.ioport1);
313 v2 = inb_p(sonypi_device.ioport1 + sonypi_device.evtype_offset);
315 for (i = 0; sonypi_eventtypes[i].model; i++) {
316 if (sonypi_device.model != sonypi_eventtypes[i].model)
318 if ((v2 & sonypi_eventtypes[i].data) != sonypi_eventtypes[i].data)
320 if (! (mask & sonypi_eventtypes[i].mask))
322 for (j = 0; sonypi_eventtypes[i].events[j].event; j++) {
323 if (v1 == sonypi_eventtypes[i].events[j].data) {
324 event = sonypi_eventtypes[i].events[j].event;
332 "sonypi: unknown event port1=0x%02x,port2=0x%02x\n",v1,v2);
333 /* We need to return IRQ_HANDLED here because there *are*
334 * events belonging to the sonypi device we don't know about,
335 * but we still don't want those to pollute the logs... */
341 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2);
343 #ifdef SONYPI_USE_INPUT
345 struct input_dev *jog_dev = &sonypi_device.jog_dev;
346 if (event == SONYPI_EVENT_JOGDIAL_PRESSED)
347 input_report_key(jog_dev, BTN_MIDDLE, 1);
348 else if (event == SONYPI_EVENT_ANYBUTTON_RELEASED)
349 input_report_key(jog_dev, BTN_MIDDLE, 0);
350 else if ((event == SONYPI_EVENT_JOGDIAL_UP) ||
351 (event == SONYPI_EVENT_JOGDIAL_UP_PRESSED))
352 input_report_rel(jog_dev, REL_WHEEL, 1);
353 else if ((event == SONYPI_EVENT_JOGDIAL_DOWN) ||
354 (event == SONYPI_EVENT_JOGDIAL_DOWN_PRESSED))
355 input_report_rel(jog_dev, REL_WHEEL, -1);
358 #endif /* SONYPI_USE_INPUT */
363 /* External camera command (exported to the motion eye v4l driver) */
364 u8 sonypi_camera_command(int command, u8 value) {
370 down(&sonypi_device.lock);
373 case SONYPI_COMMAND_GETCAMERA:
374 ret = sonypi_camera_ready();
376 case SONYPI_COMMAND_SETCAMERA:
382 case SONYPI_COMMAND_GETCAMERABRIGHTNESS:
383 ret = sonypi_read(SONYPI_CAMERA_BRIGHTNESS);
385 case SONYPI_COMMAND_SETCAMERABRIGHTNESS:
386 sonypi_set(SONYPI_CAMERA_BRIGHTNESS, value);
388 case SONYPI_COMMAND_GETCAMERACONTRAST:
389 ret = sonypi_read(SONYPI_CAMERA_CONTRAST);
391 case SONYPI_COMMAND_SETCAMERACONTRAST:
392 sonypi_set(SONYPI_CAMERA_CONTRAST, value);
394 case SONYPI_COMMAND_GETCAMERAHUE:
395 ret = sonypi_read(SONYPI_CAMERA_HUE);
397 case SONYPI_COMMAND_SETCAMERAHUE:
398 sonypi_set(SONYPI_CAMERA_HUE, value);
400 case SONYPI_COMMAND_GETCAMERACOLOR:
401 ret = sonypi_read(SONYPI_CAMERA_COLOR);
403 case SONYPI_COMMAND_SETCAMERACOLOR:
404 sonypi_set(SONYPI_CAMERA_COLOR, value);
406 case SONYPI_COMMAND_GETCAMERASHARPNESS:
407 ret = sonypi_read(SONYPI_CAMERA_SHARPNESS);
409 case SONYPI_COMMAND_SETCAMERASHARPNESS:
410 sonypi_set(SONYPI_CAMERA_SHARPNESS, value);
412 case SONYPI_COMMAND_GETCAMERAPICTURE:
413 ret = sonypi_read(SONYPI_CAMERA_PICTURE);
415 case SONYPI_COMMAND_SETCAMERAPICTURE:
416 sonypi_set(SONYPI_CAMERA_PICTURE, value);
418 case SONYPI_COMMAND_GETCAMERAAGC:
419 ret = sonypi_read(SONYPI_CAMERA_AGC);
421 case SONYPI_COMMAND_SETCAMERAAGC:
422 sonypi_set(SONYPI_CAMERA_AGC, value);
424 case SONYPI_COMMAND_GETCAMERADIRECTION:
425 ret = sonypi_read(SONYPI_CAMERA_STATUS);
426 ret &= SONYPI_DIRECTION_BACKWARDS;
428 case SONYPI_COMMAND_GETCAMERAROMVERSION:
429 ret = sonypi_read(SONYPI_CAMERA_ROMVERSION);
431 case SONYPI_COMMAND_GETCAMERAREVISION:
432 ret = sonypi_read(SONYPI_CAMERA_REVISION);
435 up(&sonypi_device.lock);
439 static int sonypi_misc_fasync(int fd, struct file *filp, int on) {
442 retval = fasync_helper(fd, filp, on, &sonypi_device.queue.fasync);
448 static int sonypi_misc_release(struct inode * inode, struct file * file) {
449 sonypi_misc_fasync(-1, file, 0);
450 down(&sonypi_device.lock);
451 sonypi_device.open_count--;
452 up(&sonypi_device.lock);
456 static int sonypi_misc_open(struct inode * inode, struct file * file) {
457 down(&sonypi_device.lock);
458 /* Flush input queue on first open */
459 if (!sonypi_device.open_count)
461 sonypi_device.open_count++;
462 up(&sonypi_device.lock);
466 static ssize_t sonypi_misc_read(struct file * file, char __user * buf,
467 size_t count, loff_t *pos)
469 DECLARE_WAITQUEUE(wait, current);
473 if (sonypi_emptyq()) {
474 if (file->f_flags & O_NONBLOCK)
476 add_wait_queue(&sonypi_device.queue.proc_list, &wait);
478 set_current_state(TASK_INTERRUPTIBLE);
479 if (sonypi_emptyq() && !signal_pending(current)) {
483 current->state = TASK_RUNNING;
484 remove_wait_queue(&sonypi_device.queue.proc_list, &wait);
486 while (i > 0 && !sonypi_emptyq()) {
492 file->f_dentry->d_inode->i_atime = CURRENT_TIME;
495 if (signal_pending(current))
500 static unsigned int sonypi_misc_poll(struct file *file, poll_table * wait) {
501 poll_wait(file, &sonypi_device.queue.proc_list, wait);
502 if (!sonypi_emptyq())
503 return POLLIN | POLLRDNORM;
507 static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
508 unsigned int cmd, unsigned long arg) {
510 void __user *argp = (void __user *)arg;
514 down(&sonypi_device.lock);
517 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
521 if (copy_to_user(argp, &val8, sizeof(val8)))
525 if (copy_from_user(&val8, argp, sizeof(val8))) {
529 if (sonypi_ec_write(SONYPI_LCD_LIGHT, val8))
532 case SONYPI_IOCGBAT1CAP:
533 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
537 if (copy_to_user(argp, &val16, sizeof(val16)))
540 case SONYPI_IOCGBAT1REM:
541 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
545 if (copy_to_user(argp, &val16, sizeof(val16)))
548 case SONYPI_IOCGBAT2CAP:
549 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
553 if (copy_to_user(argp, &val16, sizeof(val16)))
556 case SONYPI_IOCGBAT2REM:
557 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
561 if (copy_to_user(argp, &val16, sizeof(val16)))
564 case SONYPI_IOCGBATFLAGS:
565 if (sonypi_ec_read(SONYPI_BAT_FLAGS, &val8)) {
570 if (copy_to_user(argp, &val8, sizeof(val8)))
573 case SONYPI_IOCGBLUE:
574 val8 = sonypi_device.bluetooth_power;
575 if (copy_to_user(argp, &val8, sizeof(val8)))
578 case SONYPI_IOCSBLUE:
579 if (copy_from_user(&val8, argp, sizeof(val8))) {
583 sonypi_setbluetoothpower(val8);
588 up(&sonypi_device.lock);
592 static struct file_operations sonypi_misc_fops = {
593 .owner = THIS_MODULE,
594 .read = sonypi_misc_read,
595 .poll = sonypi_misc_poll,
596 .open = sonypi_misc_open,
597 .release = sonypi_misc_release,
598 .fasync = sonypi_misc_fasync,
599 .ioctl = sonypi_misc_ioctl,
602 struct miscdevice sonypi_misc_device = {
603 -1, "sonypi", &sonypi_misc_fops
607 static int old_camera_power;
609 static int sonypi_suspend(struct sys_device *dev, u32 state) {
610 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
612 old_camera_power = sonypi_device.camera_power;
615 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
619 /* disable ACPI mode */
620 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
625 static int sonypi_resume(struct sys_device *dev) {
626 /* Enable ACPI mode to get Fn key events */
627 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
629 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
634 sonypi_call2(0x81, 0xff);
639 if (camera && old_camera_power)
645 static int sonypi_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data) {
649 sonypi_suspend(NULL, 0);
658 /* New PM scheme (device model) */
659 static struct sysdev_class sonypi_sysclass = {
660 set_kset_name("sonypi"),
661 .suspend = sonypi_suspend,
662 .resume = sonypi_resume,
665 static struct sys_device sonypi_sysdev = {
667 .cls = &sonypi_sysclass,
671 static int __devinit sonypi_probe(struct pci_dev *pcidev) {
673 struct sonypi_ioport_list *ioport_list;
674 struct sonypi_irq_list *irq_list;
676 sonypi_device.dev = pcidev;
678 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
680 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
682 init_MUTEX(&sonypi_device.lock);
683 sonypi_device.bluetooth_power = 0;
685 if (pcidev && pci_enable_device(pcidev)) {
686 printk(KERN_ERR "sonypi: pci_enable_device failed\n");
691 sonypi_misc_device.minor = (minor == -1) ?
692 MISC_DYNAMIC_MINOR : minor;
693 if ((ret = misc_register(&sonypi_misc_device))) {
694 printk(KERN_ERR "sonypi: misc_register failed\n");
698 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
699 ioport_list = sonypi_type2_ioport_list;
700 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE;
701 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET;
702 irq_list = sonypi_type2_irq_list;
705 ioport_list = sonypi_type1_ioport_list;
706 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE;
707 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET;
708 irq_list = sonypi_type1_irq_list;
711 for (i = 0; ioport_list[i].port1; i++) {
712 if (request_region(ioport_list[i].port1,
713 sonypi_device.region_size,
714 "Sony Programable I/O Device")) {
716 sonypi_device.ioport1 = ioport_list[i].port1;
717 sonypi_device.ioport2 = ioport_list[i].port2;
721 if (!sonypi_device.ioport1) {
722 printk(KERN_ERR "sonypi: request_region failed\n");
727 for (i = 0; irq_list[i].irq; i++) {
729 sonypi_device.irq = irq_list[i].irq;
730 sonypi_device.bits = irq_list[i].bits;
732 /* Enable sonypi IRQ settings */
733 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
739 sonypi_call2(0x81, 0xff);
745 /* Now try requesting the irq from the system */
746 if (!request_irq(sonypi_device.irq, sonypi_irq,
747 SA_SHIRQ, "sonypi", sonypi_irq))
750 /* If request_irq failed, disable sonypi IRQ settings */
751 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
757 if (!irq_list[i].irq) {
758 printk(KERN_ERR "sonypi: request_irq failed\n");
764 sonypi_device.pm = pm_register(PM_PCI_DEV, 0, sonypi_pm_callback);
766 if (sysdev_class_register(&sonypi_sysclass) != 0) {
767 printk(KERN_ERR "sonypi: sysdev_class_register failed\n");
771 if (sysdev_register(&sonypi_sysdev) != 0) {
772 printk(KERN_ERR "sonypi: sysdev_register failed\n");
778 /* Enable ACPI mode to get Fn key events */
779 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
782 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver v%d.%d.\n",
783 SONYPI_DRIVER_MAJORVERSION,
784 SONYPI_DRIVER_MINORVERSION);
785 printk(KERN_INFO "sonypi: detected %s model, "
786 "verbose = %d, fnkeyinit = %s, camera = %s, "
787 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
788 (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) ?
791 fnkeyinit ? "on" : "off",
792 camera ? "on" : "off",
793 compat ? "on" : "off",
795 useinput ? "on" : "off",
796 SONYPI_ACPI_ACTIVE ? "on" : "off");
797 printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
799 sonypi_device.ioport1, sonypi_device.ioport2);
802 printk(KERN_INFO "sonypi: device allocated minor is %d\n",
803 sonypi_misc_device.minor);
805 #ifdef SONYPI_USE_INPUT
807 /* Initialize the Input Drivers: */
808 sonypi_device.jog_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
809 sonypi_device.jog_dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
810 sonypi_device.jog_dev.relbit[0] = BIT(REL_WHEEL);
811 sonypi_device.jog_dev.name = (char *) kmalloc(
812 sizeof(SONYPI_INPUTNAME), GFP_KERNEL);
813 sprintf(sonypi_device.jog_dev.name, SONYPI_INPUTNAME);
814 sonypi_device.jog_dev.id.bustype = BUS_ISA;
815 sonypi_device.jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
817 input_register_device(&sonypi_device.jog_dev);
818 printk(KERN_INFO "%s installed.\n", sonypi_device.jog_dev.name);
820 #endif /* SONYPI_USE_INPUT */
826 sysdev_class_unregister(&sonypi_sysclass);
828 free_irq(sonypi_device.irq, sonypi_irq);
831 release_region(sonypi_device.ioport1, sonypi_device.region_size);
833 misc_deregister(&sonypi_misc_device);
838 static void __devexit sonypi_remove(void) {
841 pm_unregister(sonypi_device.pm);
843 sysdev_unregister(&sonypi_sysdev);
844 sysdev_class_unregister(&sonypi_sysclass);
847 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
849 #ifdef SONYPI_USE_INPUT
851 input_unregister_device(&sonypi_device.jog_dev);
852 kfree(sonypi_device.jog_dev.name);
854 #endif /* SONYPI_USE_INPUT */
858 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
862 /* disable ACPI mode */
863 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
865 free_irq(sonypi_device.irq, sonypi_irq);
866 release_region(sonypi_device.ioport1, sonypi_device.region_size);
867 misc_deregister(&sonypi_misc_device);
868 printk(KERN_INFO "sonypi: removed.\n");
871 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
873 .ident = "Sony Vaio",
875 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
876 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
880 .ident = "Sony Vaio",
882 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
883 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
889 static int __init sonypi_init_module(void)
891 struct pci_dev *pcidev = NULL;
892 if (dmi_check_system(sonypi_dmi_table)) {
893 pcidev = pci_find_device(PCI_VENDOR_ID_INTEL,
894 PCI_DEVICE_ID_INTEL_82371AB_3,
896 return sonypi_probe(pcidev);
902 static void __exit sonypi_cleanup_module(void) {
907 static int __init sonypi_setup(char *str) {
910 str = get_options(str, ARRAY_SIZE(ints), ints);
936 __setup("sonypi=", sonypi_setup);
939 /* Module entry points */
940 module_init(sonypi_init_module);
941 module_exit(sonypi_cleanup_module);
943 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
944 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
945 MODULE_LICENSE("GPL");
948 MODULE_PARM(minor,"i");
949 MODULE_PARM_DESC(minor, "minor number of the misc device, default is -1 (automatic)");
950 MODULE_PARM(verbose,"i");
951 MODULE_PARM_DESC(verbose, "be verbose, default is 0 (no)");
952 MODULE_PARM(fnkeyinit,"i");
953 MODULE_PARM_DESC(fnkeyinit, "set this if your Fn keys do not generate any event");
954 MODULE_PARM(camera,"i");
955 MODULE_PARM_DESC(camera, "set this if you have a MotionEye camera (PictureBook series)");
956 MODULE_PARM(compat,"i");
957 MODULE_PARM_DESC(compat, "set this if you want to enable backward compatibility mode");
958 MODULE_PARM(mask, "i");
959 MODULE_PARM_DESC(mask, "set this to the mask of event you want to enable (see doc)");
960 MODULE_PARM(useinput, "i");
961 MODULE_PARM_DESC(useinput, "if you have a jogdial, set this if you would like it to use the modern Linux Input Driver system");
963 EXPORT_SYMBOL(sonypi_camera_command);