2 * Sony Programmable I/O Control Device driver for VAIO
4 * Copyright (C) 2001-2004 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/err.h>
49 #include <asm/uaccess.h>
51 #include <asm/system.h>
54 #include <linux/sonypi.h>
56 MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
57 MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver");
58 MODULE_LICENSE("GPL");
59 MODULE_VERSION(SONYPI_DRIVER_VERSION);
61 static int minor = -1;
62 module_param(minor, int, 0);
63 MODULE_PARM_DESC(minor,
64 "minor number of the misc device, default is -1 (automatic)");
66 static int verbose; /* = 0 */
67 module_param(verbose, int, 0644);
68 MODULE_PARM_DESC(verbose, "be verbose, default is 0 (no)");
70 static int fnkeyinit; /* = 0 */
71 module_param(fnkeyinit, int, 0444);
72 MODULE_PARM_DESC(fnkeyinit,
73 "set this if your Fn keys do not generate any event");
75 static int camera; /* = 0 */
76 module_param(camera, int, 0444);
77 MODULE_PARM_DESC(camera,
78 "set this if you have a MotionEye camera (PictureBook series)");
80 static int compat; /* = 0 */
81 module_param(compat, int, 0444);
82 MODULE_PARM_DESC(compat,
83 "set this if you want to enable backward compatibility mode");
85 static unsigned long mask = 0xffffffff;
86 module_param(mask, ulong, 0644);
87 MODULE_PARM_DESC(mask,
88 "set this to the mask of event you want to enable (see doc)");
90 static int useinput = 1;
91 module_param(useinput, int, 0444);
92 MODULE_PARM_DESC(useinput,
93 "set this if you would like sonypi to feed events to the input subsystem");
95 static struct sonypi_device sonypi_device;
97 static int sonypi_ec_write(u8 addr, u8 value)
100 if (SONYPI_ACPI_ACTIVE)
101 return ec_write(addr, value);
103 wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG);
104 outb_p(0x81, SONYPI_CST_IOPORT);
105 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
106 outb_p(addr, SONYPI_DATA_IOPORT);
107 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
108 outb_p(value, SONYPI_DATA_IOPORT);
109 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
113 static int sonypi_ec_read(u8 addr, u8 *value)
115 #ifdef CONFIG_ACPI_EC
116 if (SONYPI_ACPI_ACTIVE)
117 return ec_read(addr, value);
119 wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG);
120 outb_p(0x80, SONYPI_CST_IOPORT);
121 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
122 outb_p(addr, SONYPI_DATA_IOPORT);
123 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
124 *value = inb_p(SONYPI_DATA_IOPORT);
128 static int ec_read16(u8 addr, u16 *value)
131 if (sonypi_ec_read(addr, &val_lb))
133 if (sonypi_ec_read(addr + 1, &val_hb))
135 *value = val_lb | (val_hb << 8);
139 /* Initializes the device - this comes from the AML code in the ACPI bios */
140 static void sonypi_type1_srs(void)
144 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
145 v = (v & 0xFFFF0000) | ((u32) sonypi_device.ioport1);
146 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
148 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
149 v = (v & 0xFFF0FFFF) |
150 (((u32) sonypi_device.ioport1 ^ sonypi_device.ioport2) << 16);
151 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
153 v = inl(SONYPI_IRQ_PORT);
154 v &= ~(((u32) 0x3) << SONYPI_IRQ_SHIFT);
155 v |= (((u32) sonypi_device.bits) << SONYPI_IRQ_SHIFT);
156 outl(v, SONYPI_IRQ_PORT);
158 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
159 v = (v & 0xFF1FFFFF) | 0x00C00000;
160 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
163 static void sonypi_type2_srs(void)
165 if (sonypi_ec_write(SONYPI_SHIB, (sonypi_device.ioport1 & 0xFF00) >> 8))
166 printk(KERN_WARNING "ec_write failed\n");
167 if (sonypi_ec_write(SONYPI_SLOB, sonypi_device.ioport1 & 0x00FF))
168 printk(KERN_WARNING "ec_write failed\n");
169 if (sonypi_ec_write(SONYPI_SIRQ, sonypi_device.bits))
170 printk(KERN_WARNING "ec_write failed\n");
174 /* Disables the device - this comes from the AML code in the ACPI bios */
175 static void sonypi_type1_dis(void)
179 pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v);
181 pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v);
183 v = inl(SONYPI_IRQ_PORT);
184 v |= (0x3 << SONYPI_IRQ_SHIFT);
185 outl(v, SONYPI_IRQ_PORT);
188 static void sonypi_type2_dis(void)
190 if (sonypi_ec_write(SONYPI_SHIB, 0))
191 printk(KERN_WARNING "ec_write failed\n");
192 if (sonypi_ec_write(SONYPI_SLOB, 0))
193 printk(KERN_WARNING "ec_write failed\n");
194 if (sonypi_ec_write(SONYPI_SIRQ, 0))
195 printk(KERN_WARNING "ec_write failed\n");
198 static u8 sonypi_call1(u8 dev)
202 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
203 outb(dev, sonypi_device.ioport2);
204 v1 = inb_p(sonypi_device.ioport2);
205 v2 = inb_p(sonypi_device.ioport1);
209 static u8 sonypi_call2(u8 dev, u8 fn)
213 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
214 outb(dev, sonypi_device.ioport2);
215 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
216 outb(fn, sonypi_device.ioport1);
217 v1 = inb_p(sonypi_device.ioport1);
221 static u8 sonypi_call3(u8 dev, u8 fn, u8 v)
225 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
226 outb(dev, sonypi_device.ioport2);
227 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
228 outb(fn, sonypi_device.ioport1);
229 wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG);
230 outb(v, sonypi_device.ioport1);
231 v1 = inb_p(sonypi_device.ioport1);
236 /* Get brightness, hue etc. Unreliable... */
237 static u8 sonypi_read(u8 fn)
243 v1 = sonypi_call2(0x8f, fn);
244 v2 = sonypi_call2(0x8f, fn);
245 if (v1 == v2 && v1 != 0xff)
252 /* Set brightness, hue etc */
253 static void sonypi_set(u8 fn, u8 v)
255 wait_on_command(0, sonypi_call3(0x90, fn, v), ITERATIONS_SHORT);
258 /* Tests if the camera is ready */
259 static int sonypi_camera_ready(void)
263 v = sonypi_call2(0x8f, SONYPI_CAMERA_STATUS);
264 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
267 /* Turns the camera off */
268 static void sonypi_camera_off(void)
270 sonypi_set(SONYPI_CAMERA_PICTURE, SONYPI_CAMERA_MUTE_MASK);
272 if (!sonypi_device.camera_power)
275 sonypi_call2(0x91, 0);
276 sonypi_device.camera_power = 0;
279 /* Turns the camera on */
280 static void sonypi_camera_on(void)
284 if (sonypi_device.camera_power)
287 for (j = 5; j > 0; j--) {
289 while (sonypi_call2(0x91, 0x1)) {
290 set_current_state(TASK_UNINTERRUPTIBLE);
295 for (i = 400; i > 0; i--) {
296 if (sonypi_camera_ready())
298 set_current_state(TASK_UNINTERRUPTIBLE);
306 printk(KERN_WARNING "sonypi: failed to power on camera\n");
310 sonypi_set(0x10, 0x5a);
311 sonypi_device.camera_power = 1;
314 /* sets the bluetooth subsystem power state */
315 static void sonypi_setbluetoothpower(u8 state)
319 if (sonypi_device.bluetooth_power == state)
322 sonypi_call2(0x96, state);
324 sonypi_device.bluetooth_power = state;
327 static void input_keyrelease(void *data)
329 struct input_dev *input_dev;
333 if (kfifo_get(sonypi_device.input_fifo,
334 (unsigned char *)&input_dev,
335 sizeof(input_dev)) != sizeof(input_dev))
337 if (kfifo_get(sonypi_device.input_fifo,
338 (unsigned char *)&key,
339 sizeof(key)) != sizeof(key))
343 input_report_key(input_dev, key, 0);
344 input_sync(input_dev);
348 /* Interrupt handler: some event is available */
349 static irqreturn_t sonypi_irq(int irq, void *dev_id, struct pt_regs *regs)
351 u8 v1, v2, event = 0;
354 v1 = inb_p(sonypi_device.ioport1);
355 v2 = inb_p(sonypi_device.ioport1 + sonypi_device.evtype_offset);
357 for (i = 0; sonypi_eventtypes[i].model; i++) {
358 if (sonypi_device.model != sonypi_eventtypes[i].model)
360 if ((v2 & sonypi_eventtypes[i].data) !=
361 sonypi_eventtypes[i].data)
363 if (!(mask & sonypi_eventtypes[i].mask))
365 for (j = 0; sonypi_eventtypes[i].events[j].event; j++) {
366 if (v1 == sonypi_eventtypes[i].events[j].data) {
367 event = sonypi_eventtypes[i].events[j].event;
375 "sonypi: unknown event port1=0x%02x,port2=0x%02x\n",
377 /* We need to return IRQ_HANDLED here because there *are*
378 * events belonging to the sonypi device we don't know about,
379 * but we still don't want those to pollute the logs... */
385 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2);
388 struct input_dev *input_jog_dev = &sonypi_device.input_jog_dev;
389 struct input_dev *input_key_dev = &sonypi_device.input_key_dev;
391 case SONYPI_EVENT_JOGDIAL_UP:
392 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
393 input_report_rel(input_jog_dev, REL_WHEEL, 1);
395 case SONYPI_EVENT_JOGDIAL_DOWN:
396 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
397 input_report_rel(input_jog_dev, REL_WHEEL, -1);
399 case SONYPI_EVENT_JOGDIAL_PRESSED: {
400 int key = BTN_MIDDLE;
401 input_report_key(input_jog_dev, key, 1);
402 kfifo_put(sonypi_device.input_fifo,
403 (unsigned char *)&input_jog_dev,
404 sizeof(input_jog_dev));
405 kfifo_put(sonypi_device.input_fifo,
406 (unsigned char *)&key, sizeof(key));
409 case SONYPI_EVENT_FNKEY_RELEASED:
410 /* Nothing, not all VAIOs generate this event */
413 input_sync(input_jog_dev);
415 for (i = 0; sonypi_inputkeys[i].sonypiev; i++) {
418 if (event != sonypi_inputkeys[i].sonypiev)
421 key = sonypi_inputkeys[i].inputev;
422 input_report_key(input_key_dev, key, 1);
423 kfifo_put(sonypi_device.input_fifo,
424 (unsigned char *)&input_key_dev,
425 sizeof(input_key_dev));
426 kfifo_put(sonypi_device.input_fifo,
427 (unsigned char *)&key, sizeof(key));
429 input_sync(input_key_dev);
430 schedule_work(&sonypi_device.input_work);
433 kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
434 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN);
435 wake_up_interruptible(&sonypi_device.fifo_proc_list);
440 /* External camera command (exported to the motion eye v4l driver) */
441 int sonypi_camera_command(int command, u8 value)
446 down(&sonypi_device.lock);
449 case SONYPI_COMMAND_SETCAMERA:
455 case SONYPI_COMMAND_SETCAMERABRIGHTNESS:
456 sonypi_set(SONYPI_CAMERA_BRIGHTNESS, value);
458 case SONYPI_COMMAND_SETCAMERACONTRAST:
459 sonypi_set(SONYPI_CAMERA_CONTRAST, value);
461 case SONYPI_COMMAND_SETCAMERAHUE:
462 sonypi_set(SONYPI_CAMERA_HUE, value);
464 case SONYPI_COMMAND_SETCAMERACOLOR:
465 sonypi_set(SONYPI_CAMERA_COLOR, value);
467 case SONYPI_COMMAND_SETCAMERASHARPNESS:
468 sonypi_set(SONYPI_CAMERA_SHARPNESS, value);
470 case SONYPI_COMMAND_SETCAMERAPICTURE:
471 sonypi_set(SONYPI_CAMERA_PICTURE, value);
473 case SONYPI_COMMAND_SETCAMERAAGC:
474 sonypi_set(SONYPI_CAMERA_AGC, value);
477 printk(KERN_ERR "sonypi: sonypi_camera_command invalid: %d\n",
481 up(&sonypi_device.lock);
485 EXPORT_SYMBOL(sonypi_camera_command);
487 static int sonypi_misc_fasync(int fd, struct file *filp, int on)
491 retval = fasync_helper(fd, filp, on, &sonypi_device.fifo_async);
497 static int sonypi_misc_release(struct inode *inode, struct file *file)
499 sonypi_misc_fasync(-1, file, 0);
500 down(&sonypi_device.lock);
501 sonypi_device.open_count--;
502 up(&sonypi_device.lock);
506 static int sonypi_misc_open(struct inode *inode, struct file *file)
508 down(&sonypi_device.lock);
509 /* Flush input queue on first open */
510 if (!sonypi_device.open_count)
511 kfifo_reset(sonypi_device.fifo);
512 sonypi_device.open_count++;
513 up(&sonypi_device.lock);
517 static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
518 size_t count, loff_t *pos)
523 if ((kfifo_len(sonypi_device.fifo) == 0) &&
524 (file->f_flags & O_NONBLOCK))
527 ret = wait_event_interruptible(sonypi_device.fifo_proc_list,
528 kfifo_len(sonypi_device.fifo) != 0);
532 while (ret < count &&
533 (kfifo_get(sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
534 if (put_user(c, buf++))
540 file->f_dentry->d_inode->i_atime = CURRENT_TIME;
545 static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
547 poll_wait(file, &sonypi_device.fifo_proc_list, wait);
548 if (kfifo_len(sonypi_device.fifo))
549 return POLLIN | POLLRDNORM;
553 static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
554 unsigned int cmd, unsigned long arg)
557 void __user *argp = (void __user *)arg;
561 down(&sonypi_device.lock);
564 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
568 if (copy_to_user(argp, &val8, sizeof(val8)))
572 if (copy_from_user(&val8, argp, sizeof(val8))) {
576 if (sonypi_ec_write(SONYPI_LCD_LIGHT, val8))
579 case SONYPI_IOCGBAT1CAP:
580 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
584 if (copy_to_user(argp, &val16, sizeof(val16)))
587 case SONYPI_IOCGBAT1REM:
588 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
592 if (copy_to_user(argp, &val16, sizeof(val16)))
595 case SONYPI_IOCGBAT2CAP:
596 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
600 if (copy_to_user(argp, &val16, sizeof(val16)))
603 case SONYPI_IOCGBAT2REM:
604 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
608 if (copy_to_user(argp, &val16, sizeof(val16)))
611 case SONYPI_IOCGBATFLAGS:
612 if (sonypi_ec_read(SONYPI_BAT_FLAGS, &val8)) {
617 if (copy_to_user(argp, &val8, sizeof(val8)))
620 case SONYPI_IOCGBLUE:
621 val8 = sonypi_device.bluetooth_power;
622 if (copy_to_user(argp, &val8, sizeof(val8)))
625 case SONYPI_IOCSBLUE:
626 if (copy_from_user(&val8, argp, sizeof(val8))) {
630 sonypi_setbluetoothpower(val8);
635 up(&sonypi_device.lock);
639 static struct file_operations sonypi_misc_fops = {
640 .owner = THIS_MODULE,
641 .read = sonypi_misc_read,
642 .poll = sonypi_misc_poll,
643 .open = sonypi_misc_open,
644 .release = sonypi_misc_release,
645 .fasync = sonypi_misc_fasync,
646 .ioctl = sonypi_misc_ioctl,
649 struct miscdevice sonypi_misc_device = {
652 .fops = &sonypi_misc_fops,
655 static void sonypi_enable(unsigned int camera_on)
657 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
663 sonypi_call2(0x81, 0xff);
664 sonypi_call1(compat ? 0x92 : 0x82);
666 /* Enable ACPI mode to get Fn key events */
667 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
670 if (camera && camera_on)
674 static int sonypi_disable(void)
676 sonypi_call2(0x81, 0); /* make sure we don't get any more events */
680 /* disable ACPI mode */
681 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
684 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2)
692 static int old_camera_power;
694 static int sonypi_suspend(struct device *dev, u32 state, u32 level)
696 if (level == SUSPEND_DISABLE) {
697 old_camera_power = sonypi_device.camera_power;
703 static int sonypi_resume(struct device *dev, u32 level)
705 if (level == RESUME_ENABLE)
706 sonypi_enable(old_camera_power);
711 static void sonypi_shutdown(struct device *dev)
716 static struct device_driver sonypi_driver = {
718 .bus = &platform_bus_type,
720 .suspend = sonypi_suspend,
721 .resume = sonypi_resume,
723 .shutdown = sonypi_shutdown,
726 static int __devinit sonypi_probe(void)
729 struct sonypi_ioport_list *ioport_list;
730 struct sonypi_irq_list *irq_list;
731 struct pci_dev *pcidev;
733 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
734 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
736 sonypi_device.dev = pcidev;
737 sonypi_device.model = pcidev ?
738 SONYPI_DEVICE_MODEL_TYPE1 : SONYPI_DEVICE_MODEL_TYPE2;
740 sonypi_device.fifo_lock = SPIN_LOCK_UNLOCKED;
741 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
742 &sonypi_device.fifo_lock);
743 if (IS_ERR(sonypi_device.fifo)) {
744 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
745 ret = PTR_ERR(sonypi_device.fifo);
749 init_waitqueue_head(&sonypi_device.fifo_proc_list);
750 init_MUTEX(&sonypi_device.lock);
751 sonypi_device.bluetooth_power = -1;
753 if (pcidev && pci_enable_device(pcidev)) {
754 printk(KERN_ERR "sonypi: pci_enable_device failed\n");
759 sonypi_misc_device.minor = (minor == -1) ? MISC_DYNAMIC_MINOR : minor;
760 if ((ret = misc_register(&sonypi_misc_device))) {
761 printk(KERN_ERR "sonypi: misc_register failed\n");
765 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
766 ioport_list = sonypi_type2_ioport_list;
767 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE;
768 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET;
769 irq_list = sonypi_type2_irq_list;
771 ioport_list = sonypi_type1_ioport_list;
772 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE;
773 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET;
774 irq_list = sonypi_type1_irq_list;
777 for (i = 0; ioport_list[i].port1; i++) {
778 if (request_region(ioport_list[i].port1,
779 sonypi_device.region_size,
780 "Sony Programable I/O Device")) {
782 sonypi_device.ioport1 = ioport_list[i].port1;
783 sonypi_device.ioport2 = ioport_list[i].port2;
787 if (!sonypi_device.ioport1) {
788 printk(KERN_ERR "sonypi: request_region failed\n");
793 for (i = 0; irq_list[i].irq; i++) {
795 sonypi_device.irq = irq_list[i].irq;
796 sonypi_device.bits = irq_list[i].bits;
798 if (!request_irq(sonypi_device.irq, sonypi_irq,
799 SA_SHIRQ, "sonypi", sonypi_irq))
803 if (!irq_list[i].irq) {
804 printk(KERN_ERR "sonypi: request_irq failed\n");
810 /* Initialize the Input Drivers: jogdial */
812 sonypi_device.input_jog_dev.evbit[0] =
813 BIT(EV_KEY) | BIT(EV_REL);
814 sonypi_device.input_jog_dev.keybit[LONG(BTN_MOUSE)] =
816 sonypi_device.input_jog_dev.relbit[0] = BIT(REL_WHEEL);
817 sonypi_device.input_jog_dev.name =
818 kmalloc(sizeof(SONYPI_JOG_INPUTNAME), GFP_KERNEL);
819 if (!sonypi_device.input_jog_dev.name) {
820 printk(KERN_ERR "sonypi: kmalloc failed\n");
822 goto out_inkmallocinput1;
824 sprintf(sonypi_device.input_jog_dev.name, SONYPI_JOG_INPUTNAME);
825 sonypi_device.input_jog_dev.id.bustype = BUS_ISA;
826 sonypi_device.input_jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
828 input_register_device(&sonypi_device.input_jog_dev);
829 printk(KERN_INFO "%s input method installed.\n",
830 sonypi_device.input_jog_dev.name);
832 /* Initialize the Input Drivers: special keys */
833 sonypi_device.input_key_dev.evbit[0] = BIT(EV_KEY);
834 for (i = 0; sonypi_inputkeys[i].sonypiev; i++)
835 if (sonypi_inputkeys[i].inputev)
836 set_bit(sonypi_inputkeys[i].inputev,
837 sonypi_device.input_key_dev.keybit);
838 sonypi_device.input_key_dev.name =
839 kmalloc(sizeof(SONYPI_KEY_INPUTNAME), GFP_KERNEL);
840 if (!sonypi_device.input_key_dev.name) {
841 printk(KERN_ERR "sonypi: kmalloc failed\n");
843 goto out_inkmallocinput2;
845 sprintf(sonypi_device.input_key_dev.name, SONYPI_KEY_INPUTNAME);
846 sonypi_device.input_key_dev.id.bustype = BUS_ISA;
847 sonypi_device.input_key_dev.id.vendor = PCI_VENDOR_ID_SONY;
849 input_register_device(&sonypi_device.input_key_dev);
850 printk(KERN_INFO "%s input method installed.\n",
851 sonypi_device.input_key_dev.name);
853 sonypi_device.input_fifo_lock = SPIN_LOCK_UNLOCKED;
854 sonypi_device.input_fifo =
855 kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
856 &sonypi_device.input_fifo_lock);
857 if (IS_ERR(sonypi_device.input_fifo)) {
858 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
859 ret = PTR_ERR(sonypi_device.input_fifo);
863 INIT_WORK(&sonypi_device.input_work, input_keyrelease, NULL);
866 sonypi_device.pdev = platform_device_register_simple("sonypi", -1,
868 if (IS_ERR(sonypi_device.pdev)) {
869 ret = PTR_ERR(sonypi_device.pdev);
870 goto out_platformdev;
875 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver"
876 "v%s.\n", SONYPI_DRIVER_VERSION);
877 printk(KERN_INFO "sonypi: detected %s model, "
878 "verbose = %d, fnkeyinit = %s, camera = %s, "
879 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
880 (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) ?
883 fnkeyinit ? "on" : "off",
884 camera ? "on" : "off",
885 compat ? "on" : "off",
887 useinput ? "on" : "off",
888 SONYPI_ACPI_ACTIVE ? "on" : "off");
889 printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
891 sonypi_device.ioport1, sonypi_device.ioport2);
894 printk(KERN_INFO "sonypi: device allocated minor is %d\n",
895 sonypi_misc_device.minor);
900 kfifo_free(sonypi_device.input_fifo);
902 input_unregister_device(&sonypi_device.input_key_dev);
903 kfree(sonypi_device.input_key_dev.name);
905 input_unregister_device(&sonypi_device.input_jog_dev);
906 kfree(sonypi_device.input_jog_dev.name);
908 free_irq(sonypi_device.irq, sonypi_irq);
910 release_region(sonypi_device.ioport1, sonypi_device.region_size);
912 misc_deregister(&sonypi_misc_device);
915 pci_disable_device(pcidev);
917 kfifo_free(sonypi_device.fifo);
919 pci_dev_put(sonypi_device.dev);
923 static void __devexit sonypi_remove(void)
927 platform_device_unregister(sonypi_device.pdev);
930 input_unregister_device(&sonypi_device.input_key_dev);
931 kfree(sonypi_device.input_key_dev.name);
932 input_unregister_device(&sonypi_device.input_jog_dev);
933 kfree(sonypi_device.input_jog_dev.name);
934 kfifo_free(sonypi_device.input_fifo);
937 free_irq(sonypi_device.irq, sonypi_irq);
938 release_region(sonypi_device.ioport1, sonypi_device.region_size);
939 misc_deregister(&sonypi_misc_device);
940 if (sonypi_device.dev)
941 pci_disable_device(sonypi_device.dev);
942 kfifo_free(sonypi_device.fifo);
943 pci_dev_put(sonypi_device.dev);
944 printk(KERN_INFO "sonypi: removed.\n");
947 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
949 .ident = "Sony Vaio",
951 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
952 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
956 .ident = "Sony Vaio",
958 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
959 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
965 static int __init sonypi_init(void)
969 if (!dmi_check_system(sonypi_dmi_table))
972 ret = driver_register(&sonypi_driver);
976 ret = sonypi_probe();
978 driver_unregister(&sonypi_driver);
983 static void __exit sonypi_exit(void)
985 driver_unregister(&sonypi_driver);
989 module_init(sonypi_init);
990 module_exit(sonypi_exit);