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>
47 #include <asm/uaccess.h>
49 #include <asm/system.h>
52 #include <linux/sonypi.h>
54 static struct sonypi_device sonypi_device;
55 static int minor = -1;
56 static int verbose; /* = 0 */
57 static int fnkeyinit; /* = 0 */
58 static int camera; /* = 0 */
59 static int compat; /* = 0 */
60 static int useinput = 1;
61 static unsigned long mask = 0xffffffff;
64 static inline void sonypi_initq(void) {
65 sonypi_device.queue.head = sonypi_device.queue.tail = 0;
66 sonypi_device.queue.len = 0;
67 sonypi_device.queue.s_lock = (spinlock_t)SPIN_LOCK_UNLOCKED;
68 init_waitqueue_head(&sonypi_device.queue.proc_list);
71 /* Pulls an event from the queue */
72 static inline unsigned char sonypi_pullq(void) {
76 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
77 if (!sonypi_device.queue.len) {
78 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
81 result = sonypi_device.queue.buf[sonypi_device.queue.head];
82 sonypi_device.queue.head++;
83 sonypi_device.queue.head &= (SONYPI_BUF_SIZE - 1);
84 sonypi_device.queue.len--;
85 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
89 /* Pushes an event into the queue */
90 static inline void sonypi_pushq(unsigned char event) {
93 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
94 if (sonypi_device.queue.len == SONYPI_BUF_SIZE) {
95 /* remove the first element */
96 sonypi_device.queue.head++;
97 sonypi_device.queue.head &= (SONYPI_BUF_SIZE - 1);
98 sonypi_device.queue.len--;
100 sonypi_device.queue.buf[sonypi_device.queue.tail] = event;
101 sonypi_device.queue.tail++;
102 sonypi_device.queue.tail &= (SONYPI_BUF_SIZE - 1);
103 sonypi_device.queue.len++;
105 kill_fasync(&sonypi_device.queue.fasync, SIGIO, POLL_IN);
106 wake_up_interruptible(&sonypi_device.queue.proc_list);
107 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
110 /* Tests if the queue is empty */
111 static inline int sonypi_emptyq(void) {
115 spin_lock_irqsave(&sonypi_device.queue.s_lock, flags);
116 result = (sonypi_device.queue.len == 0);
117 spin_unlock_irqrestore(&sonypi_device.queue.s_lock, flags);
121 static int ec_read16(u8 addr, u16 *value) {
123 if (sonypi_ec_read(addr, &val_lb))
125 if (sonypi_ec_read(addr + 1, &val_hb))
127 *value = val_lb | (val_hb << 8);
131 /* Initializes the device - this comes from the AML code in the ACPI bios */
132 static void sonypi_type1_srs(void) {
135 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
136 v = (v & 0xFFFF0000) | ((u32)sonypi_device.ioport1);
137 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
139 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
140 v = (v & 0xFFF0FFFF) |
141 (((u32)sonypi_device.ioport1 ^ sonypi_device.ioport2) << 16);
142 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
144 v = inl(SONYPI_IRQ_PORT);
145 v &= ~(((u32)0x3) << SONYPI_IRQ_SHIFT);
146 v |= (((u32)sonypi_device.bits) << SONYPI_IRQ_SHIFT);
147 outl(v, SONYPI_IRQ_PORT);
149 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
150 v = (v & 0xFF1FFFFF) | 0x00C00000;
151 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
154 static void sonypi_type2_srs(void) {
155 if (sonypi_ec_write(SONYPI_SHIB, (sonypi_device.ioport1 & 0xFF00) >> 8))
156 printk(KERN_WARNING "ec_write failed\n");
157 if (sonypi_ec_write(SONYPI_SLOB, sonypi_device.ioport1 & 0x00FF))
158 printk(KERN_WARNING "ec_write failed\n");
159 if (sonypi_ec_write(SONYPI_SIRQ, sonypi_device.bits))
160 printk(KERN_WARNING "ec_write failed\n");
164 /* Disables the device - this comes from the AML code in the ACPI bios */
165 static void sonypi_type1_dis(void) {
168 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
170 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
172 v = inl(SONYPI_IRQ_PORT);
173 v |= (0x3 << SONYPI_IRQ_SHIFT);
174 outl(v, SONYPI_IRQ_PORT);
177 static void sonypi_type2_dis(void) {
178 if (sonypi_ec_write(SONYPI_SHIB, 0))
179 printk(KERN_WARNING "ec_write failed\n");
180 if (sonypi_ec_write(SONYPI_SLOB, 0))
181 printk(KERN_WARNING "ec_write failed\n");
182 if (sonypi_ec_write(SONYPI_SIRQ, 0))
183 printk(KERN_WARNING "ec_write failed\n");
186 static u8 sonypi_call1(u8 dev) {
189 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
190 outb(dev, sonypi_device.ioport2);
191 v1 = inb_p(sonypi_device.ioport2);
192 v2 = inb_p(sonypi_device.ioport1);
196 static u8 sonypi_call2(u8 dev, u8 fn) {
199 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
200 outb(dev, sonypi_device.ioport2);
201 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
202 outb(fn, sonypi_device.ioport1);
203 v1 = inb_p(sonypi_device.ioport1);
207 static u8 sonypi_call3(u8 dev, u8 fn, u8 v) {
210 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
211 outb(dev, sonypi_device.ioport2);
212 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
213 outb(fn, sonypi_device.ioport1);
214 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
215 outb(v, sonypi_device.ioport1);
216 v1 = inb_p(sonypi_device.ioport1);
220 static u8 sonypi_read(u8 fn) {
225 v1 = sonypi_call2(0x8f, fn);
226 v2 = sonypi_call2(0x8f, fn);
227 if (v1 == v2 && v1 != 0xff)
233 /* Set brightness, hue etc */
234 static void sonypi_set(u8 fn, u8 v) {
236 wait_on_command(0, sonypi_call3(0x90, fn, v), ITERATIONS_SHORT);
239 /* Tests if the camera is ready */
240 static int sonypi_camera_ready(void) {
243 v = sonypi_call2(0x8f, SONYPI_CAMERA_STATUS);
244 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
247 /* Turns the camera off */
248 static void sonypi_camera_off(void) {
250 sonypi_set(SONYPI_CAMERA_PICTURE, SONYPI_CAMERA_MUTE_MASK);
252 if (!sonypi_device.camera_power)
255 sonypi_call2(0x91, 0);
256 sonypi_device.camera_power = 0;
259 /* Turns the camera on */
260 static void sonypi_camera_on(void) {
263 if (sonypi_device.camera_power)
266 for (j = 5; j > 0; j--) {
268 while (sonypi_call2(0x91, 0x1)) {
269 set_current_state(TASK_UNINTERRUPTIBLE);
274 for (i = 400; i > 0; i--) {
275 if (sonypi_camera_ready())
277 set_current_state(TASK_UNINTERRUPTIBLE);
285 printk(KERN_WARNING "sonypi: failed to power on camera\n");
289 sonypi_set(0x10, 0x5a);
290 sonypi_device.camera_power = 1;
293 /* sets the bluetooth subsystem power state */
294 static void sonypi_setbluetoothpower(u8 state) {
297 if (sonypi_device.bluetooth_power == state)
300 sonypi_call2(0x96, state);
302 sonypi_device.bluetooth_power = state;
305 /* Interrupt handler: some event is available */
306 static irqreturn_t sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) {
307 u8 v1, v2, event = 0;
310 v1 = inb_p(sonypi_device.ioport1);
311 v2 = inb_p(sonypi_device.ioport1 + sonypi_device.evtype_offset);
313 for (i = 0; sonypi_eventtypes[i].model; i++) {
314 if (sonypi_device.model != sonypi_eventtypes[i].model)
316 if ((v2 & sonypi_eventtypes[i].data) != sonypi_eventtypes[i].data)
318 if (! (mask & sonypi_eventtypes[i].mask))
320 for (j = 0; sonypi_eventtypes[i].events[j].event; j++) {
321 if (v1 == sonypi_eventtypes[i].events[j].data) {
322 event = sonypi_eventtypes[i].events[j].event;
330 "sonypi: unknown event port1=0x%02x,port2=0x%02x\n",v1,v2);
331 /* We need to return IRQ_HANDLED here because there *are*
332 * events belonging to the sonypi device we don't know about,
333 * but we still don't want those to pollute the logs... */
339 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2);
341 #ifdef SONYPI_USE_INPUT
343 struct input_dev *jog_dev = &sonypi_device.jog_dev;
344 if (event == SONYPI_EVENT_JOGDIAL_PRESSED)
345 input_report_key(jog_dev, BTN_MIDDLE, 1);
346 else if (event == SONYPI_EVENT_ANYBUTTON_RELEASED)
347 input_report_key(jog_dev, BTN_MIDDLE, 0);
348 else if ((event == SONYPI_EVENT_JOGDIAL_UP) ||
349 (event == SONYPI_EVENT_JOGDIAL_UP_PRESSED))
350 input_report_rel(jog_dev, REL_WHEEL, 1);
351 else if ((event == SONYPI_EVENT_JOGDIAL_DOWN) ||
352 (event == SONYPI_EVENT_JOGDIAL_DOWN_PRESSED))
353 input_report_rel(jog_dev, REL_WHEEL, -1);
356 #endif /* SONYPI_USE_INPUT */
361 /* External camera command (exported to the motion eye v4l driver) */
362 u8 sonypi_camera_command(int command, u8 value) {
368 down(&sonypi_device.lock);
371 case SONYPI_COMMAND_GETCAMERA:
372 ret = sonypi_camera_ready();
374 case SONYPI_COMMAND_SETCAMERA:
380 case SONYPI_COMMAND_GETCAMERABRIGHTNESS:
381 ret = sonypi_read(SONYPI_CAMERA_BRIGHTNESS);
383 case SONYPI_COMMAND_SETCAMERABRIGHTNESS:
384 sonypi_set(SONYPI_CAMERA_BRIGHTNESS, value);
386 case SONYPI_COMMAND_GETCAMERACONTRAST:
387 ret = sonypi_read(SONYPI_CAMERA_CONTRAST);
389 case SONYPI_COMMAND_SETCAMERACONTRAST:
390 sonypi_set(SONYPI_CAMERA_CONTRAST, value);
392 case SONYPI_COMMAND_GETCAMERAHUE:
393 ret = sonypi_read(SONYPI_CAMERA_HUE);
395 case SONYPI_COMMAND_SETCAMERAHUE:
396 sonypi_set(SONYPI_CAMERA_HUE, value);
398 case SONYPI_COMMAND_GETCAMERACOLOR:
399 ret = sonypi_read(SONYPI_CAMERA_COLOR);
401 case SONYPI_COMMAND_SETCAMERACOLOR:
402 sonypi_set(SONYPI_CAMERA_COLOR, value);
404 case SONYPI_COMMAND_GETCAMERASHARPNESS:
405 ret = sonypi_read(SONYPI_CAMERA_SHARPNESS);
407 case SONYPI_COMMAND_SETCAMERASHARPNESS:
408 sonypi_set(SONYPI_CAMERA_SHARPNESS, value);
410 case SONYPI_COMMAND_GETCAMERAPICTURE:
411 ret = sonypi_read(SONYPI_CAMERA_PICTURE);
413 case SONYPI_COMMAND_SETCAMERAPICTURE:
414 sonypi_set(SONYPI_CAMERA_PICTURE, value);
416 case SONYPI_COMMAND_GETCAMERAAGC:
417 ret = sonypi_read(SONYPI_CAMERA_AGC);
419 case SONYPI_COMMAND_SETCAMERAAGC:
420 sonypi_set(SONYPI_CAMERA_AGC, value);
422 case SONYPI_COMMAND_GETCAMERADIRECTION:
423 ret = sonypi_read(SONYPI_CAMERA_STATUS);
424 ret &= SONYPI_DIRECTION_BACKWARDS;
426 case SONYPI_COMMAND_GETCAMERAROMVERSION:
427 ret = sonypi_read(SONYPI_CAMERA_ROMVERSION);
429 case SONYPI_COMMAND_GETCAMERAREVISION:
430 ret = sonypi_read(SONYPI_CAMERA_REVISION);
433 up(&sonypi_device.lock);
437 static int sonypi_misc_fasync(int fd, struct file *filp, int on) {
440 retval = fasync_helper(fd, filp, on, &sonypi_device.queue.fasync);
446 static int sonypi_misc_release(struct inode * inode, struct file * file) {
447 sonypi_misc_fasync(-1, file, 0);
448 down(&sonypi_device.lock);
449 sonypi_device.open_count--;
450 up(&sonypi_device.lock);
454 static int sonypi_misc_open(struct inode * inode, struct file * file) {
455 down(&sonypi_device.lock);
456 /* Flush input queue on first open */
457 if (!sonypi_device.open_count)
459 sonypi_device.open_count++;
460 up(&sonypi_device.lock);
464 static ssize_t sonypi_misc_read(struct file * file, char __user * buf,
465 size_t count, loff_t *pos)
467 DECLARE_WAITQUEUE(wait, current);
471 if (sonypi_emptyq()) {
472 if (file->f_flags & O_NONBLOCK)
474 add_wait_queue(&sonypi_device.queue.proc_list, &wait);
476 set_current_state(TASK_INTERRUPTIBLE);
477 if (sonypi_emptyq() && !signal_pending(current)) {
481 current->state = TASK_RUNNING;
482 remove_wait_queue(&sonypi_device.queue.proc_list, &wait);
484 while (i > 0 && !sonypi_emptyq()) {
490 file->f_dentry->d_inode->i_atime = CURRENT_TIME;
493 if (signal_pending(current))
498 static unsigned int sonypi_misc_poll(struct file *file, poll_table * wait) {
499 poll_wait(file, &sonypi_device.queue.proc_list, wait);
500 if (!sonypi_emptyq())
501 return POLLIN | POLLRDNORM;
505 static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
506 unsigned int cmd, unsigned long arg) {
508 void __user *argp = (void __user *)arg;
512 down(&sonypi_device.lock);
515 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
519 if (copy_to_user(argp, &val8, sizeof(val8)))
523 if (copy_from_user(&val8, argp, sizeof(val8))) {
527 if (sonypi_ec_write(SONYPI_LCD_LIGHT, val8))
530 case SONYPI_IOCGBAT1CAP:
531 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
535 if (copy_to_user(argp, &val16, sizeof(val16)))
538 case SONYPI_IOCGBAT1REM:
539 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
543 if (copy_to_user(argp, &val16, sizeof(val16)))
546 case SONYPI_IOCGBAT2CAP:
547 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
551 if (copy_to_user(argp, &val16, sizeof(val16)))
554 case SONYPI_IOCGBAT2REM:
555 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
559 if (copy_to_user(argp, &val16, sizeof(val16)))
562 case SONYPI_IOCGBATFLAGS:
563 if (sonypi_ec_read(SONYPI_BAT_FLAGS, &val8)) {
568 if (copy_to_user(argp, &val8, sizeof(val8)))
571 case SONYPI_IOCGBLUE:
572 val8 = sonypi_device.bluetooth_power;
573 if (copy_to_user(argp, &val8, sizeof(val8)))
576 case SONYPI_IOCSBLUE:
577 if (copy_from_user(&val8, argp, sizeof(val8))) {
581 sonypi_setbluetoothpower(val8);
586 up(&sonypi_device.lock);
590 static struct file_operations sonypi_misc_fops = {
591 .owner = THIS_MODULE,
592 .read = sonypi_misc_read,
593 .poll = sonypi_misc_poll,
594 .open = sonypi_misc_open,
595 .release = sonypi_misc_release,
596 .fasync = sonypi_misc_fasync,
597 .ioctl = sonypi_misc_ioctl,
600 struct miscdevice sonypi_misc_device = {
601 -1, "sonypi", &sonypi_misc_fops
605 static int sonypi_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data) {
606 static int old_camera_power;
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)
624 /* Enable ACPI mode to get Fn key events */
625 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
627 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
632 sonypi_call2(0x81, 0xff);
637 if (camera && old_camera_power)
645 static int __devinit sonypi_probe(struct pci_dev *pcidev) {
647 struct sonypi_ioport_list *ioport_list;
648 struct sonypi_irq_list *irq_list;
650 sonypi_device.dev = pcidev;
652 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
654 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
656 init_MUTEX(&sonypi_device.lock);
657 sonypi_device.bluetooth_power = 0;
659 if (pcidev && pci_enable_device(pcidev)) {
660 printk(KERN_ERR "sonypi: pci_enable_device failed\n");
665 sonypi_misc_device.minor = (minor == -1) ?
666 MISC_DYNAMIC_MINOR : minor;
667 if ((ret = misc_register(&sonypi_misc_device))) {
668 printk(KERN_ERR "sonypi: misc_register failed\n");
672 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
673 ioport_list = sonypi_type2_ioport_list;
674 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE;
675 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET;
676 irq_list = sonypi_type2_irq_list;
679 ioport_list = sonypi_type1_ioport_list;
680 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE;
681 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET;
682 irq_list = sonypi_type1_irq_list;
685 for (i = 0; ioport_list[i].port1; i++) {
686 if (request_region(ioport_list[i].port1,
687 sonypi_device.region_size,
688 "Sony Programable I/O Device")) {
690 sonypi_device.ioport1 = ioport_list[i].port1;
691 sonypi_device.ioport2 = ioport_list[i].port2;
695 if (!sonypi_device.ioport1) {
696 printk(KERN_ERR "sonypi: request_region failed\n");
701 for (i = 0; irq_list[i].irq; i++) {
703 sonypi_device.irq = irq_list[i].irq;
704 sonypi_device.bits = irq_list[i].bits;
706 /* Enable sonypi IRQ settings */
707 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
713 sonypi_call2(0x81, 0xff);
719 /* Now try requesting the irq from the system */
720 if (!request_irq(sonypi_device.irq, sonypi_irq,
721 SA_SHIRQ, "sonypi", sonypi_irq))
724 /* If request_irq failed, disable sonypi IRQ settings */
725 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
731 if (!irq_list[i].irq) {
732 printk(KERN_ERR "sonypi: request_irq failed\n");
737 /* Enable ACPI mode to get Fn key events */
738 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
741 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver v%d.%d.\n",
742 SONYPI_DRIVER_MAJORVERSION,
743 SONYPI_DRIVER_MINORVERSION);
744 printk(KERN_INFO "sonypi: detected %s model, "
745 "verbose = %d, fnkeyinit = %s, camera = %s, "
746 "compat = %s, mask = 0x%08lx, useinput = %s\n",
747 (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) ?
750 fnkeyinit ? "on" : "off",
751 camera ? "on" : "off",
752 compat ? "on" : "off",
754 useinput ? "on" : "off");
755 printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
757 sonypi_device.ioport1, sonypi_device.ioport2);
759 printk(KERN_INFO "sonypi: device allocated minor is %d\n",
760 sonypi_misc_device.minor);
762 #ifdef SONYPI_USE_INPUT
764 /* Initialize the Input Drivers: */
765 sonypi_device.jog_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
766 sonypi_device.jog_dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
767 sonypi_device.jog_dev.relbit[0] = BIT(REL_WHEEL);
768 sonypi_device.jog_dev.name = (char *) kmalloc(
769 sizeof(SONYPI_INPUTNAME), GFP_KERNEL);
770 sprintf(sonypi_device.jog_dev.name, SONYPI_INPUTNAME);
771 sonypi_device.jog_dev.id.bustype = BUS_ISA;
772 sonypi_device.jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
774 input_register_device(&sonypi_device.jog_dev);
775 printk(KERN_INFO "%s installed.\n", sonypi_device.jog_dev.name);
777 #endif /* SONYPI_USE_INPUT */
780 sonypi_device.pm = pm_register(PM_PCI_DEV, 0, sonypi_pm_callback);
786 release_region(sonypi_device.ioport1, sonypi_device.region_size);
788 misc_deregister(&sonypi_misc_device);
793 static void __devexit sonypi_remove(void) {
796 pm_unregister(sonypi_device.pm);
799 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
801 #ifdef SONYPI_USE_INPUT
803 input_unregister_device(&sonypi_device.jog_dev);
804 kfree(sonypi_device.jog_dev.name);
806 #endif /* SONYPI_USE_INPUT */
810 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
814 /* disable ACPI mode */
815 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
817 free_irq(sonypi_device.irq, sonypi_irq);
818 release_region(sonypi_device.ioport1, sonypi_device.region_size);
819 misc_deregister(&sonypi_misc_device);
820 printk(KERN_INFO "sonypi: removed.\n");
823 static int __init sonypi_init_module(void) {
824 struct pci_dev *pcidev = NULL;
826 if (is_sony_vaio_laptop) {
827 pcidev = pci_find_device(PCI_VENDOR_ID_INTEL,
828 PCI_DEVICE_ID_INTEL_82371AB_3,
830 return sonypi_probe(pcidev);
836 static void __exit sonypi_cleanup_module(void) {
841 static int __init sonypi_setup(char *str) {
844 str = get_options(str, ARRAY_SIZE(ints), ints);
870 __setup("sonypi=", sonypi_setup);
873 /* Module entry points */
874 module_init(sonypi_init_module);
875 module_exit(sonypi_cleanup_module);
877 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
878 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
879 MODULE_LICENSE("GPL");
882 MODULE_PARM(minor,"i");
883 MODULE_PARM_DESC(minor, "minor number of the misc device, default is -1 (automatic)");
884 MODULE_PARM(verbose,"i");
885 MODULE_PARM_DESC(verbose, "be verbose, default is 0 (no)");
886 MODULE_PARM(fnkeyinit,"i");
887 MODULE_PARM_DESC(fnkeyinit, "set this if your Fn keys do not generate any event");
888 MODULE_PARM(camera,"i");
889 MODULE_PARM_DESC(camera, "set this if you have a MotionEye camera (PictureBook series)");
890 MODULE_PARM(compat,"i");
891 MODULE_PARM_DESC(compat, "set this if you want to enable backward compatibility mode");
892 MODULE_PARM(mask, "i");
893 MODULE_PARM_DESC(mask, "set this to the mask of event you want to enable (see doc)");
894 MODULE_PARM(useinput, "i");
895 MODULE_PARM_DESC(useinput, "if you have a jogdial, set this if you would like it to use the modern Linux Input Driver system");
897 EXPORT_SYMBOL(sonypi_camera_command);