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 * buf,
465 size_t count, loff_t *pos) {
466 DECLARE_WAITQUEUE(wait, current);
470 if (sonypi_emptyq()) {
471 if (file->f_flags & O_NONBLOCK)
473 add_wait_queue(&sonypi_device.queue.proc_list, &wait);
475 set_current_state(TASK_INTERRUPTIBLE);
476 if (sonypi_emptyq() && !signal_pending(current)) {
480 current->state = TASK_RUNNING;
481 remove_wait_queue(&sonypi_device.queue.proc_list, &wait);
483 while (i > 0 && !sonypi_emptyq()) {
489 file->f_dentry->d_inode->i_atime = CURRENT_TIME;
492 if (signal_pending(current))
497 static unsigned int sonypi_misc_poll(struct file *file, poll_table * wait) {
498 poll_wait(file, &sonypi_device.queue.proc_list, wait);
499 if (!sonypi_emptyq())
500 return POLLIN | POLLRDNORM;
504 static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
505 unsigned int cmd, unsigned long arg) {
510 down(&sonypi_device.lock);
513 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
517 if (copy_to_user((u8 *)arg, &val8, sizeof(val8)))
521 if (copy_from_user(&val8, (u8 *)arg, sizeof(val8))) {
525 if (sonypi_ec_write(SONYPI_LCD_LIGHT, val8))
528 case SONYPI_IOCGBAT1CAP:
529 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
533 if (copy_to_user((u16 *)arg, &val16, sizeof(val16)))
536 case SONYPI_IOCGBAT1REM:
537 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
541 if (copy_to_user((u16 *)arg, &val16, sizeof(val16)))
544 case SONYPI_IOCGBAT2CAP:
545 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
549 if (copy_to_user((u16 *)arg, &val16, sizeof(val16)))
552 case SONYPI_IOCGBAT2REM:
553 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
557 if (copy_to_user((u16 *)arg, &val16, sizeof(val16)))
560 case SONYPI_IOCGBATFLAGS:
561 if (sonypi_ec_read(SONYPI_BAT_FLAGS, &val8)) {
566 if (copy_to_user((u8 *)arg, &val8, sizeof(val8)))
569 case SONYPI_IOCGBLUE:
570 val8 = sonypi_device.bluetooth_power;
571 if (copy_to_user((u8 *)arg, &val8, sizeof(val8)))
574 case SONYPI_IOCSBLUE:
575 if (copy_from_user(&val8, (u8 *)arg, sizeof(val8))) {
579 sonypi_setbluetoothpower(val8);
584 up(&sonypi_device.lock);
588 static struct file_operations sonypi_misc_fops = {
589 .owner = THIS_MODULE,
590 .read = sonypi_misc_read,
591 .poll = sonypi_misc_poll,
592 .open = sonypi_misc_open,
593 .release = sonypi_misc_release,
594 .fasync = sonypi_misc_fasync,
595 .ioctl = sonypi_misc_ioctl,
598 struct miscdevice sonypi_misc_device = {
599 -1, "sonypi", &sonypi_misc_fops
603 static int sonypi_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data) {
604 static int old_camera_power;
608 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
610 old_camera_power = sonypi_device.camera_power;
613 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
617 /* disable ACPI mode */
618 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
622 /* Enable ACPI mode to get Fn key events */
623 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
625 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
630 sonypi_call2(0x81, 0xff);
635 if (camera && old_camera_power)
643 static int __devinit sonypi_probe(struct pci_dev *pcidev) {
645 struct sonypi_ioport_list *ioport_list;
646 struct sonypi_irq_list *irq_list;
648 sonypi_device.dev = pcidev;
650 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
652 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
654 init_MUTEX(&sonypi_device.lock);
655 sonypi_device.bluetooth_power = 0;
657 if (pcidev && pci_enable_device(pcidev)) {
658 printk(KERN_ERR "sonypi: pci_enable_device failed\n");
663 sonypi_misc_device.minor = (minor == -1) ?
664 MISC_DYNAMIC_MINOR : minor;
665 if ((ret = misc_register(&sonypi_misc_device))) {
666 printk(KERN_ERR "sonypi: misc_register failed\n");
670 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
671 ioport_list = sonypi_type2_ioport_list;
672 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE;
673 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET;
674 irq_list = sonypi_type2_irq_list;
677 ioport_list = sonypi_type1_ioport_list;
678 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE;
679 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET;
680 irq_list = sonypi_type1_irq_list;
683 for (i = 0; ioport_list[i].port1; i++) {
684 if (request_region(ioport_list[i].port1,
685 sonypi_device.region_size,
686 "Sony Programable I/O Device")) {
688 sonypi_device.ioport1 = ioport_list[i].port1;
689 sonypi_device.ioport2 = ioport_list[i].port2;
693 if (!sonypi_device.ioport1) {
694 printk(KERN_ERR "sonypi: request_region failed\n");
699 for (i = 0; irq_list[i].irq; i++) {
701 sonypi_device.irq = irq_list[i].irq;
702 sonypi_device.bits = irq_list[i].bits;
704 /* Enable sonypi IRQ settings */
705 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
711 sonypi_call2(0x81, 0xff);
717 /* Now try requesting the irq from the system */
718 if (!request_irq(sonypi_device.irq, sonypi_irq,
719 SA_SHIRQ, "sonypi", sonypi_irq))
722 /* If request_irq failed, disable sonypi IRQ settings */
723 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
729 if (!irq_list[i].irq) {
730 printk(KERN_ERR "sonypi: request_irq failed\n");
735 /* Enable ACPI mode to get Fn key events */
736 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
739 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver v%d.%d.\n",
740 SONYPI_DRIVER_MAJORVERSION,
741 SONYPI_DRIVER_MINORVERSION);
742 printk(KERN_INFO "sonypi: detected %s model, "
743 "verbose = %d, fnkeyinit = %s, camera = %s, "
744 "compat = %s, mask = 0x%08lx, useinput = %s\n",
745 (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) ?
748 fnkeyinit ? "on" : "off",
749 camera ? "on" : "off",
750 compat ? "on" : "off",
752 useinput ? "on" : "off");
753 printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
755 sonypi_device.ioport1, sonypi_device.ioport2);
757 printk(KERN_INFO "sonypi: device allocated minor is %d\n",
758 sonypi_misc_device.minor);
760 #ifdef SONYPI_USE_INPUT
762 /* Initialize the Input Drivers: */
763 sonypi_device.jog_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
764 sonypi_device.jog_dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
765 sonypi_device.jog_dev.relbit[0] = BIT(REL_WHEEL);
766 sonypi_device.jog_dev.name = (char *) kmalloc(
767 sizeof(SONYPI_INPUTNAME), GFP_KERNEL);
768 sprintf(sonypi_device.jog_dev.name, SONYPI_INPUTNAME);
769 sonypi_device.jog_dev.id.bustype = BUS_ISA;
770 sonypi_device.jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
772 input_register_device(&sonypi_device.jog_dev);
773 printk(KERN_INFO "%s installed.\n", sonypi_device.jog_dev.name);
775 #endif /* SONYPI_USE_INPUT */
778 sonypi_device.pm = pm_register(PM_PCI_DEV, 0, sonypi_pm_callback);
784 release_region(sonypi_device.ioport1, sonypi_device.region_size);
786 misc_deregister(&sonypi_misc_device);
791 static void __devexit sonypi_remove(void) {
794 pm_unregister(sonypi_device.pm);
797 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
799 #ifdef SONYPI_USE_INPUT
801 input_unregister_device(&sonypi_device.jog_dev);
802 kfree(sonypi_device.jog_dev.name);
804 #endif /* SONYPI_USE_INPUT */
808 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
812 /* disable ACPI mode */
813 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
815 free_irq(sonypi_device.irq, sonypi_irq);
816 release_region(sonypi_device.ioport1, sonypi_device.region_size);
817 misc_deregister(&sonypi_misc_device);
818 printk(KERN_INFO "sonypi: removed.\n");
821 static int __init sonypi_init_module(void) {
822 struct pci_dev *pcidev = NULL;
824 if (is_sony_vaio_laptop) {
825 pcidev = pci_find_device(PCI_VENDOR_ID_INTEL,
826 PCI_DEVICE_ID_INTEL_82371AB_3,
828 return sonypi_probe(pcidev);
834 static void __exit sonypi_cleanup_module(void) {
839 static int __init sonypi_setup(char *str) {
842 str = get_options(str, ARRAY_SIZE(ints), ints);
868 __setup("sonypi=", sonypi_setup);
871 /* Module entry points */
872 module_init(sonypi_init_module);
873 module_exit(sonypi_cleanup_module);
875 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
876 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
877 MODULE_LICENSE("GPL");
880 MODULE_PARM(minor,"i");
881 MODULE_PARM_DESC(minor, "minor number of the misc device, default is -1 (automatic)");
882 MODULE_PARM(verbose,"i");
883 MODULE_PARM_DESC(verbose, "be verbose, default is 0 (no)");
884 MODULE_PARM(fnkeyinit,"i");
885 MODULE_PARM_DESC(fnkeyinit, "set this if your Fn keys do not generate any event");
886 MODULE_PARM(camera,"i");
887 MODULE_PARM_DESC(camera, "set this if you have a MotionEye camera (PictureBook series)");
888 MODULE_PARM(compat,"i");
889 MODULE_PARM_DESC(compat, "set this if you want to enable backward compatibility mode");
890 MODULE_PARM(mask, "i");
891 MODULE_PARM_DESC(mask, "set this to the mask of event you want to enable (see doc)");
892 MODULE_PARM(useinput, "i");
893 MODULE_PARM_DESC(useinput, "if you have a jogdial, set this if you would like it to use the modern Linux Input Driver system");
895 EXPORT_SYMBOL(sonypi_camera_command);