2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
10 * The SNY6001 driver part is based on the sonypi driver which includes
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
17 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/moduleparam.h>
48 #include <linux/init.h>
49 #include <linux/types.h>
50 #include <linux/backlight.h>
51 #include <linux/platform_device.h>
52 #include <linux/err.h>
53 #include <linux/dmi.h>
54 #include <linux/pci.h>
55 #include <linux/interrupt.h>
56 #include <linux/delay.h>
57 #include <linux/input.h>
58 #include <linux/kfifo.h>
59 #include <linux/workqueue.h>
60 #include <linux/acpi.h>
61 #include <acpi/acpi_drivers.h>
62 #include <acpi/acpi_bus.h>
63 #include <asm/uaccess.h>
64 #include <linux/sonypi.h>
66 #define DRV_PFX "sony-laptop: "
67 #define LOG_PFX KERN_WARNING DRV_PFX
68 #define dprintk(msg...) do { \
69 if (debug) printk(LOG_PFX msg); \
72 #define SONY_LAPTOP_DRIVER_VERSION "0.5"
74 #define SONY_NC_CLASS "sony-nc"
75 #define SONY_NC_HID "SNY5001"
76 #define SONY_NC_DRIVER_NAME "Sony Notebook Control"
78 #define SONY_PIC_CLASS "sony-pic"
79 #define SONY_PIC_HID "SNY6001"
80 #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control"
82 MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
83 MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
84 MODULE_LICENSE("GPL");
85 MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
88 module_param(debug, int, 0);
89 MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
90 "the development of this driver");
92 static int no_spic; /* = 0 */
93 module_param(no_spic, int, 0444);
94 MODULE_PARM_DESC(no_spic,
95 "set this if you don't want to enable the SPIC device");
97 static int compat; /* = 0 */
98 module_param(compat, int, 0444);
99 MODULE_PARM_DESC(compat,
100 "set this if you want to enable backward compatibility mode");
102 static int force_jog; /* = 0 */
103 module_param(force_jog, int, 0444);
104 MODULE_PARM_DESC(force_jog,
105 "set this if the driver doesn't detect your jogdial");
107 static unsigned long mask = 0xffffffff;
108 module_param(mask, ulong, 0644);
109 MODULE_PARM_DESC(mask,
110 "set this to the mask of event you want to enable (see doc)");
112 /*********** Platform Device ***********/
114 static atomic_t sony_pf_users = ATOMIC_INIT(0);
115 static struct platform_driver sony_pf_driver = {
117 .name = "sony-laptop",
118 .owner = THIS_MODULE,
121 static struct platform_device *sony_pf_device;
123 static int sony_pf_add(void)
127 /* don't run again if already initialized */
128 if (atomic_add_return(1, &sony_pf_users) > 1)
131 ret = platform_driver_register(&sony_pf_driver);
135 sony_pf_device = platform_device_alloc("sony-laptop", -1);
136 if (!sony_pf_device) {
138 goto out_platform_registered;
141 ret = platform_device_add(sony_pf_device);
143 goto out_platform_alloced;
147 out_platform_alloced:
148 platform_device_put(sony_pf_device);
149 sony_pf_device = NULL;
150 out_platform_registered:
151 platform_driver_unregister(&sony_pf_driver);
153 atomic_dec(&sony_pf_users);
157 static void sony_pf_remove(void)
159 /* deregister only after the last user has gone */
160 if (!atomic_dec_and_test(&sony_pf_users))
163 platform_device_del(sony_pf_device);
164 platform_device_put(sony_pf_device);
165 platform_driver_unregister(&sony_pf_driver);
168 /*********** SNC (SNY5001) Device ***********/
170 /* the device uses 1-based values, while the backlight subsystem uses
172 #define SONY_MAX_BRIGHTNESS 8
174 #define SNC_VALIDATE_IN 0
175 #define SNC_VALIDATE_OUT 1
177 static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
179 static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
180 const char *, size_t);
181 static int boolean_validate(const int, const int);
182 static int brightness_default_validate(const int, const int);
184 struct sony_nc_value {
185 char *name; /* name of the entry */
186 char **acpiget; /* names of the ACPI get function */
187 char **acpiset; /* names of the ACPI set function */
188 int (*validate)(const int, const int); /* input/output validation */
189 int value; /* current setting */
190 int valid; /* Has ever been set */
191 int debug; /* active only in debug mode ? */
192 struct device_attribute devattr; /* sysfs atribute */
195 #define SNC_HANDLE_NAMES(_name, _values...) \
196 static char *snc_##_name[] = { _values, NULL }
198 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
200 .name = __stringify(_name), \
201 .acpiget = _getters, \
202 .acpiset = _setters, \
203 .validate = _validate, \
205 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
208 #define SNC_HANDLE_NULL { .name = NULL }
210 SNC_HANDLE_NAMES(fnkey_get, "GHKE");
212 SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
213 SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
215 SNC_HANDLE_NAMES(cdpower_get, "GCDP");
216 SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
218 SNC_HANDLE_NAMES(audiopower_get, "GAZP");
219 SNC_HANDLE_NAMES(audiopower_set, "AZPW");
221 SNC_HANDLE_NAMES(lanpower_get, "GLNP");
222 SNC_HANDLE_NAMES(lanpower_set, "LNPW");
224 SNC_HANDLE_NAMES(PID_get, "GPID");
226 SNC_HANDLE_NAMES(CTR_get, "GCTR");
227 SNC_HANDLE_NAMES(CTR_set, "SCTR");
229 SNC_HANDLE_NAMES(PCR_get, "GPCR");
230 SNC_HANDLE_NAMES(PCR_set, "SPCR");
232 SNC_HANDLE_NAMES(CMI_get, "GCMI");
233 SNC_HANDLE_NAMES(CMI_set, "SCMI");
235 static struct sony_nc_value sony_nc_values[] = {
236 SNC_HANDLE(brightness_default, snc_brightness_def_get,
237 snc_brightness_def_set, brightness_default_validate, 0),
238 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
239 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
240 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
241 boolean_validate, 0),
242 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
243 boolean_validate, 1),
244 /* unknown methods */
245 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
246 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
247 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
248 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
252 static acpi_handle sony_nc_acpi_handle;
253 static struct acpi_device *sony_nc_acpi_device = NULL;
256 * acpi_evaluate_object wrappers
258 static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
260 struct acpi_buffer output;
261 union acpi_object out_obj;
264 output.length = sizeof(out_obj);
265 output.pointer = &out_obj;
267 status = acpi_evaluate_object(handle, name, NULL, &output);
268 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
269 *result = out_obj.integer.value;
273 printk(LOG_PFX "acpi_callreadfunc failed\n");
278 static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
281 struct acpi_object_list params;
282 union acpi_object in_obj;
283 struct acpi_buffer output;
284 union acpi_object out_obj;
288 params.pointer = &in_obj;
289 in_obj.type = ACPI_TYPE_INTEGER;
290 in_obj.integer.value = value;
292 output.length = sizeof(out_obj);
293 output.pointer = &out_obj;
295 status = acpi_evaluate_object(handle, name, ¶ms, &output);
296 if (status == AE_OK) {
297 if (result != NULL) {
298 if (out_obj.type != ACPI_TYPE_INTEGER) {
299 printk(LOG_PFX "acpi_evaluate_object bad "
303 *result = out_obj.integer.value;
308 printk(LOG_PFX "acpi_evaluate_object failed\n");
314 * sony_nc_values input/output validate functions
317 /* brightness_default_validate:
319 * manipulate input output values to keep consistency with the
320 * backlight framework for which brightness values are 0-based.
322 static int brightness_default_validate(const int direction, const int value)
325 case SNC_VALIDATE_OUT:
327 case SNC_VALIDATE_IN:
328 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
336 * on input validate boolean values 0/1, on output just pass the
339 static int boolean_validate(const int direction, const int value)
341 if (direction == SNC_VALIDATE_IN) {
342 if (value != 0 && value != 1)
349 * Sysfs show/store common to all sony_nc_values
351 static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
355 struct sony_nc_value *item =
356 container_of(attr, struct sony_nc_value, devattr);
361 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
365 value = item->validate(SNC_VALIDATE_OUT, value);
367 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
370 static ssize_t sony_nc_sysfs_store(struct device *dev,
371 struct device_attribute *attr,
372 const char *buffer, size_t count)
375 struct sony_nc_value *item =
376 container_of(attr, struct sony_nc_value, devattr);
384 value = simple_strtoul(buffer, NULL, 10);
387 value = item->validate(SNC_VALIDATE_IN, value);
392 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
403 static int sony_backlight_update_status(struct backlight_device *bd)
405 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
406 bd->props.brightness + 1, NULL);
409 static int sony_backlight_get_brightness(struct backlight_device *bd)
413 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
415 /* brightness levels are 1-based, while backlight ones are 0-based */
419 static struct backlight_device *sony_backlight_device;
420 static struct backlight_ops sony_backlight_ops = {
421 .update_status = sony_backlight_update_status,
422 .get_brightness = sony_backlight_get_brightness,
428 static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
430 dprintk("sony_acpi_notify, event: %d\n", event);
431 acpi_bus_generate_event(sony_nc_acpi_device, 1, event);
434 static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
435 void *context, void **return_value)
437 struct acpi_namespace_node *node;
438 union acpi_operand_object *operand;
440 node = (struct acpi_namespace_node *)handle;
441 operand = (union acpi_operand_object *)node->object;
443 printk(LOG_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
444 (u32) operand->method.param_count);
452 static int sony_nc_resume(struct acpi_device *device)
454 struct sony_nc_value *item;
456 for (item = sony_nc_values; item->name; item++) {
461 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
464 printk("%s: %d\n", __FUNCTION__, ret);
471 static int sony_nc_add(struct acpi_device *device)
476 struct sony_nc_value *item;
478 sony_nc_acpi_device = device;
479 strcpy(acpi_device_class(device), "sony/hotkey");
481 sony_nc_acpi_handle = device->handle;
484 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
485 1, sony_walk_callback, NULL, NULL);
486 if (ACPI_FAILURE(status)) {
487 printk(LOG_PFX "unable to walk acpi resources\n");
493 status = acpi_install_notify_handler(sony_nc_acpi_handle,
495 sony_acpi_notify, NULL);
496 if (ACPI_FAILURE(status)) {
497 printk(LOG_PFX "unable to install notify handler\n");
502 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", &handle))) {
503 sony_backlight_device = backlight_device_register("sony", NULL,
505 &sony_backlight_ops);
507 if (IS_ERR(sony_backlight_device)) {
508 printk(LOG_PFX "unable to register backlight device\n");
509 sony_backlight_device = NULL;
511 sony_backlight_device->props.brightness =
512 sony_backlight_get_brightness
513 (sony_backlight_device);
514 sony_backlight_device->props.max_brightness =
515 SONY_MAX_BRIGHTNESS - 1;
523 /* create sony_pf sysfs attributes related to the SNC device */
524 for (item = sony_nc_values; item->name; ++item) {
526 if (!debug && item->debug)
529 /* find the available acpiget as described in the DSDT */
530 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
531 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
534 dprintk("Found %s getter: %s\n",
535 item->name, *item->acpiget);
536 item->devattr.attr.mode |= S_IRUGO;
541 /* find the available acpiset as described in the DSDT */
542 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
543 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
546 dprintk("Found %s setter: %s\n",
547 item->name, *item->acpiset);
548 item->devattr.attr.mode |= S_IWUSR;
553 if (item->devattr.attr.mode != 0) {
555 device_create_file(&sony_pf_device->dev,
562 printk(KERN_INFO SONY_NC_DRIVER_NAME " successfully installed\n");
567 for (item = sony_nc_values; item->name; ++item) {
568 device_remove_file(&sony_pf_device->dev, &item->devattr);
572 if (sony_backlight_device)
573 backlight_device_unregister(sony_backlight_device);
575 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
578 if (ACPI_FAILURE(status))
579 printk(LOG_PFX "unable to remove notify handler\n");
584 static int sony_nc_remove(struct acpi_device *device, int type)
587 struct sony_nc_value *item;
589 if (sony_backlight_device)
590 backlight_device_unregister(sony_backlight_device);
592 sony_nc_acpi_device = NULL;
594 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
597 if (ACPI_FAILURE(status))
598 printk(LOG_PFX "unable to remove notify handler\n");
600 for (item = sony_nc_values; item->name; ++item) {
601 device_remove_file(&sony_pf_device->dev, &item->devattr);
606 printk(KERN_INFO SONY_NC_DRIVER_NAME " successfully removed\n");
611 static struct acpi_driver sony_nc_driver = {
612 .name = SONY_NC_DRIVER_NAME,
613 .class = SONY_NC_CLASS,
615 .owner = THIS_MODULE,
618 .remove = sony_nc_remove,
619 .resume = sony_nc_resume,
623 /*********** SPIC (SNY6001) Device ***********/
625 #define SONYPI_DEVICE_TYPE1 0x00000001
626 #define SONYPI_DEVICE_TYPE2 0x00000002
627 #define SONYPI_DEVICE_TYPE3 0x00000004
629 #define SONY_EC_JOGB 0x82
630 #define SONY_EC_JOGB_MASK 0x02
632 #define SONY_PIC_EV_MASK 0xff
634 #define SONYPI_BUF_SIZE 128
636 struct sony_pic_ioport {
637 struct acpi_resource_io io;
638 struct list_head list;
641 struct sony_pic_irq {
642 struct acpi_resource_irq irq;
643 struct list_head list;
646 struct sony_pic_dev {
648 struct acpi_device *acpi_dev;
649 struct sony_pic_irq *cur_irq;
650 struct sony_pic_ioport *cur_ioport;
651 struct list_head interrupts;
652 struct list_head ioports;
654 struct input_dev *input_jog_dev;
655 struct input_dev *input_key_dev;
656 struct kfifo *input_fifo;
657 spinlock_t input_fifo_lock;
658 struct workqueue_struct *sony_pic_wq;
661 static struct sony_pic_dev spic_dev = {
662 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
663 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
667 #define SONYPI_JOGGER_MASK 0x00000001
668 #define SONYPI_CAPTURE_MASK 0x00000002
669 #define SONYPI_FNKEY_MASK 0x00000004
670 #define SONYPI_BLUETOOTH_MASK 0x00000008
671 #define SONYPI_PKEY_MASK 0x00000010
672 #define SONYPI_BACK_MASK 0x00000020
673 #define SONYPI_HELP_MASK 0x00000040
674 #define SONYPI_LID_MASK 0x00000080
675 #define SONYPI_ZOOM_MASK 0x00000100
676 #define SONYPI_THUMBPHRASE_MASK 0x00000200
677 #define SONYPI_MEYE_MASK 0x00000400
678 #define SONYPI_MEMORYSTICK_MASK 0x00000800
679 #define SONYPI_BATTERY_MASK 0x00001000
680 #define SONYPI_WIRELESS_MASK 0x00002000
682 struct sonypi_event {
687 /* The set of possible button release events */
688 static struct sonypi_event sonypi_releaseev[] = {
689 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
693 /* The set of possible jogger events */
694 static struct sonypi_event sonypi_joggerev[] = {
695 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
696 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
697 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
698 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
699 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
700 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
701 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
702 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
703 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
704 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
705 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
706 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
707 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
711 /* The set of possible capture button events */
712 static struct sonypi_event sonypi_captureev[] = {
713 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
714 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
715 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
719 /* The set of possible fnkeys events */
720 static struct sonypi_event sonypi_fnkeyev[] = {
721 { 0x10, SONYPI_EVENT_FNKEY_ESC },
722 { 0x11, SONYPI_EVENT_FNKEY_F1 },
723 { 0x12, SONYPI_EVENT_FNKEY_F2 },
724 { 0x13, SONYPI_EVENT_FNKEY_F3 },
725 { 0x14, SONYPI_EVENT_FNKEY_F4 },
726 { 0x15, SONYPI_EVENT_FNKEY_F5 },
727 { 0x16, SONYPI_EVENT_FNKEY_F6 },
728 { 0x17, SONYPI_EVENT_FNKEY_F7 },
729 { 0x18, SONYPI_EVENT_FNKEY_F8 },
730 { 0x19, SONYPI_EVENT_FNKEY_F9 },
731 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
732 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
733 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
734 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
735 { 0x21, SONYPI_EVENT_FNKEY_1 },
736 { 0x22, SONYPI_EVENT_FNKEY_2 },
737 { 0x31, SONYPI_EVENT_FNKEY_D },
738 { 0x32, SONYPI_EVENT_FNKEY_E },
739 { 0x33, SONYPI_EVENT_FNKEY_F },
740 { 0x34, SONYPI_EVENT_FNKEY_S },
741 { 0x35, SONYPI_EVENT_FNKEY_B },
742 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
746 /* The set of possible program key events */
747 static struct sonypi_event sonypi_pkeyev[] = {
748 { 0x01, SONYPI_EVENT_PKEY_P1 },
749 { 0x02, SONYPI_EVENT_PKEY_P2 },
750 { 0x04, SONYPI_EVENT_PKEY_P3 },
751 { 0x5c, SONYPI_EVENT_PKEY_P1 },
755 /* The set of possible bluetooth events */
756 static struct sonypi_event sonypi_blueev[] = {
757 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
758 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
759 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
763 /* The set of possible wireless events */
764 static struct sonypi_event sonypi_wlessev[] = {
765 { 0x59, SONYPI_EVENT_WIRELESS_ON },
766 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
770 /* The set of possible back button events */
771 static struct sonypi_event sonypi_backev[] = {
772 { 0x20, SONYPI_EVENT_BACK_PRESSED },
776 /* The set of possible help button events */
777 static struct sonypi_event sonypi_helpev[] = {
778 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
783 /* The set of possible lid events */
784 static struct sonypi_event sonypi_lidev[] = {
785 { 0x51, SONYPI_EVENT_LID_CLOSED },
786 { 0x50, SONYPI_EVENT_LID_OPENED },
790 /* The set of possible zoom events */
791 static struct sonypi_event sonypi_zoomev[] = {
792 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
796 /* The set of possible thumbphrase events */
797 static struct sonypi_event sonypi_thumbphraseev[] = {
798 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
802 /* The set of possible motioneye camera events */
803 static struct sonypi_event sonypi_meyeev[] = {
804 { 0x00, SONYPI_EVENT_MEYE_FACE },
805 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
809 /* The set of possible memorystick events */
810 static struct sonypi_event sonypi_memorystickev[] = {
811 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
812 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
816 /* The set of possible battery events */
817 static struct sonypi_event sonypi_batteryev[] = {
818 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
819 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
823 static struct sonypi_eventtypes {
827 struct sonypi_event * events;
828 } sony_pic_eventtypes[] = {
829 { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
830 { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
831 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
832 { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
833 { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
834 { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
835 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
836 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
837 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
838 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
840 { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
841 { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
842 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
843 { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
844 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
845 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
846 { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
847 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
848 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
849 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
850 { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
851 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
852 { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
853 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
855 { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
856 { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
857 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
858 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
859 { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
860 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
864 static int sony_pic_detect_device_type(void)
866 struct pci_dev *pcidev;
869 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
870 PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
871 model = SONYPI_DEVICE_TYPE1;
873 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
874 PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
875 model = SONYPI_DEVICE_TYPE3;
877 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
878 PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
879 model = SONYPI_DEVICE_TYPE3;
882 model = SONYPI_DEVICE_TYPE2;
887 printk(KERN_INFO DRV_PFX "detected Type%d model\n",
888 model == SONYPI_DEVICE_TYPE1 ? 1 :
889 model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
893 #define ITERATIONS_LONG 10000
894 #define ITERATIONS_SHORT 10
895 #define wait_on_command(command, iterations) { \
896 unsigned int n = iterations; \
897 while (--n && (command)) \
900 dprintk("command failed at %s : %s (line %d)\n", \
901 __FILE__, __FUNCTION__, __LINE__); \
904 static u8 sony_pic_call1(u8 dev)
908 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
910 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
911 v1 = inb_p(spic_dev.cur_ioport->io.minimum + 4);
912 v2 = inb_p(spic_dev.cur_ioport->io.minimum);
913 dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
917 static u8 sony_pic_call2(u8 dev, u8 fn)
921 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
923 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
924 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
926 outb(fn, spic_dev.cur_ioport->io.minimum);
927 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
928 dprintk("sony_pic_call2: 0x%.4x\n", v1);
937 struct sony_pic_keypress {
938 struct input_dev *dev;
942 /* Correspondance table between sonypi events and input layer events */
946 } sony_pic_inputkeys[] = {
947 { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA },
948 { SONYPI_EVENT_FNKEY_ONLY, KEY_FN },
949 { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC },
950 { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 },
951 { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 },
952 { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 },
953 { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 },
954 { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 },
955 { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 },
956 { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 },
957 { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 },
958 { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 },
959 { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 },
960 { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 },
961 { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 },
962 { SONYPI_EVENT_FNKEY_1, KEY_FN_1 },
963 { SONYPI_EVENT_FNKEY_2, KEY_FN_2 },
964 { SONYPI_EVENT_FNKEY_D, KEY_FN_D },
965 { SONYPI_EVENT_FNKEY_E, KEY_FN_E },
966 { SONYPI_EVENT_FNKEY_F, KEY_FN_F },
967 { SONYPI_EVENT_FNKEY_S, KEY_FN_S },
968 { SONYPI_EVENT_FNKEY_B, KEY_FN_B },
969 { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE },
970 { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE },
971 { SONYPI_EVENT_PKEY_P1, KEY_PROG1 },
972 { SONYPI_EVENT_PKEY_P2, KEY_PROG2 },
973 { SONYPI_EVENT_PKEY_P3, KEY_PROG3 },
974 { SONYPI_EVENT_BACK_PRESSED, KEY_BACK },
975 { SONYPI_EVENT_HELP_PRESSED, KEY_HELP },
976 { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM },
977 { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB },
981 /* release buttons after a short delay if pressed */
982 static void do_sony_pic_release_key(struct work_struct *work)
984 struct sony_pic_keypress kp;
986 while (kfifo_get(spic_dev.input_fifo, (unsigned char *)&kp,
987 sizeof(kp)) == sizeof(kp)) {
989 input_report_key(kp.dev, kp.key, 0);
993 static DECLARE_WORK(sony_pic_release_key_work,
994 do_sony_pic_release_key);
996 /* forward event to the input subsytem */
997 static void sony_pic_report_input_event(u8 event)
999 struct input_dev *jog_dev = spic_dev.input_jog_dev;
1000 struct input_dev *key_dev = spic_dev.input_key_dev;
1001 struct sony_pic_keypress kp = { NULL };
1004 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
1005 /* Nothing, not all VAIOs generate this event */
1009 /* report jog_dev events */
1012 case SONYPI_EVENT_JOGDIAL_UP:
1013 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
1014 input_report_rel(jog_dev, REL_WHEEL, 1);
1015 input_sync(jog_dev);
1018 case SONYPI_EVENT_JOGDIAL_DOWN:
1019 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
1020 input_report_rel(jog_dev, REL_WHEEL, -1);
1021 input_sync(jog_dev);
1030 case SONYPI_EVENT_JOGDIAL_PRESSED:
1031 kp.key = BTN_MIDDLE;
1036 for (i = 0; sony_pic_inputkeys[i].sonypiev; i++)
1037 if (event == sony_pic_inputkeys[i].sonypiev) {
1039 kp.key = sony_pic_inputkeys[i].inputev;
1046 input_report_key(kp.dev, kp.key, 1);
1048 kfifo_put(spic_dev.input_fifo,
1049 (unsigned char *)&kp, sizeof(kp));
1051 if (!work_pending(&sony_pic_release_key_work))
1052 queue_work(spic_dev.sony_pic_wq,
1053 &sony_pic_release_key_work);
1057 static int sony_pic_setup_input(void)
1059 struct input_dev *jog_dev;
1060 struct input_dev *key_dev;
1066 spin_lock_init(&spic_dev.input_fifo_lock);
1067 spic_dev.input_fifo =
1068 kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
1069 &spic_dev.input_fifo_lock);
1070 if (IS_ERR(spic_dev.input_fifo)) {
1071 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
1072 return PTR_ERR(spic_dev.input_fifo);
1075 /* init workqueue */
1076 spic_dev.sony_pic_wq = create_singlethread_workqueue("sony-pic");
1077 if (!spic_dev.sony_pic_wq) {
1078 printk(KERN_ERR DRV_PFX
1079 "Unabe to create workqueue.\n");
1081 goto err_free_kfifo;
1085 key_dev = input_allocate_device();
1088 goto err_destroy_wq;
1091 key_dev->name = "Sony Vaio Keys";
1092 key_dev->id.bustype = BUS_ISA;
1093 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
1095 /* Initialize the Input Drivers: special keys */
1096 key_dev->evbit[0] = BIT(EV_KEY);
1097 for (i = 0; sony_pic_inputkeys[i].sonypiev; i++)
1098 if (sony_pic_inputkeys[i].inputev)
1099 set_bit(sony_pic_inputkeys[i].inputev, key_dev->keybit);
1101 error = input_register_device(key_dev);
1103 goto err_free_keydev;
1105 spic_dev.input_key_dev = key_dev;
1107 /* jogdial - really reliable ? */
1108 ec_read(SONY_EC_JOGB, &jog_present);
1109 if (jog_present & SONY_EC_JOGB_MASK || force_jog) {
1110 jog_dev = input_allocate_device();
1113 goto err_unregister_keydev;
1116 jog_dev->name = "Sony Vaio Jogdial";
1117 jog_dev->id.bustype = BUS_ISA;
1118 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
1120 jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
1121 jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
1122 jog_dev->relbit[0] = BIT(REL_WHEEL);
1124 error = input_register_device(jog_dev);
1126 goto err_free_jogdev;
1128 spic_dev.input_jog_dev = jog_dev;
1134 input_free_device(jog_dev);
1136 err_unregister_keydev:
1137 input_unregister_device(key_dev);
1138 /* to avoid kref underflow below at input_free_device */
1142 input_free_device(key_dev);
1145 destroy_workqueue(spic_dev.sony_pic_wq);
1148 kfifo_free(spic_dev.input_fifo);
1153 static void sony_pic_remove_input(void)
1155 /* flush workqueue first */
1156 flush_workqueue(spic_dev.sony_pic_wq);
1158 /* destroy input devs */
1159 input_unregister_device(spic_dev.input_key_dev);
1160 spic_dev.input_key_dev = NULL;
1162 if (spic_dev.input_jog_dev) {
1163 input_unregister_device(spic_dev.input_jog_dev);
1164 spic_dev.input_jog_dev = NULL;
1167 destroy_workqueue(spic_dev.sony_pic_wq);
1168 kfifo_free(spic_dev.input_fifo);
1171 /********************
1175 ********************/
1177 sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
1180 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
1182 switch (resource->type) {
1183 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1184 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1187 case ACPI_RESOURCE_TYPE_IRQ:
1189 struct acpi_resource_irq *p = &resource->data.irq;
1190 struct sony_pic_irq *interrupt = NULL;
1191 if (!p || !p->interrupt_count) {
1193 * IRQ descriptors may have no IRQ# bits set,
1194 * particularly those those w/ _STA disabled
1196 dprintk("Blank IRQ resource\n");
1199 for (i = 0; i < p->interrupt_count; i++) {
1200 if (!p->interrupts[i]) {
1201 printk(KERN_WARNING DRV_PFX
1206 interrupt = kzalloc(sizeof(*interrupt),
1211 list_add(&interrupt->list, &dev->interrupts);
1212 interrupt->irq.triggering = p->triggering;
1213 interrupt->irq.polarity = p->polarity;
1214 interrupt->irq.sharable = p->sharable;
1215 interrupt->irq.interrupt_count = 1;
1216 interrupt->irq.interrupts[0] = p->interrupts[i];
1220 case ACPI_RESOURCE_TYPE_IO:
1222 struct acpi_resource_io *io = &resource->data.io;
1223 struct sony_pic_ioport *ioport = NULL;
1225 dprintk("Blank IO resource\n");
1229 ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
1233 list_add(&ioport->list, &dev->ioports);
1234 memcpy(&ioport->io, io, sizeof(*io));
1238 dprintk("Resource %d isn't an IRQ nor an IO port\n",
1241 case ACPI_RESOURCE_TYPE_END_TAG:
1244 return AE_CTRL_TERMINATE;
1247 static int sony_pic_possible_resources(struct acpi_device *device)
1250 acpi_status status = AE_OK;
1255 /* get device status */
1256 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
1257 dprintk("Evaluating _STA\n");
1258 result = acpi_bus_get_status(device);
1260 printk(KERN_WARNING DRV_PFX "Unable to read status\n");
1264 if (!device->status.enabled)
1265 dprintk("Device disabled\n");
1267 dprintk("Device enabled\n");
1270 * Query and parse 'method'
1272 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
1273 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
1274 sony_pic_read_possible_resource, &spic_dev);
1275 if (ACPI_FAILURE(status)) {
1276 printk(KERN_WARNING DRV_PFX
1277 "Failure evaluating %s\n",
1286 * Disable the spic device by calling its _DIS method
1288 static int sony_pic_disable(struct acpi_device *device)
1290 if (ACPI_FAILURE(acpi_evaluate_object(device->handle, "_DIS", 0, NULL)))
1293 dprintk("Device disabled\n");
1299 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
1301 * Call _SRS to set current resources
1303 static int sony_pic_enable(struct acpi_device *device,
1304 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
1309 struct acpi_resource io_res;
1310 struct acpi_resource irq_res;
1311 struct acpi_resource end;
1313 struct acpi_buffer buffer = { 0, NULL };
1315 if (!ioport || !irq)
1318 /* init acpi_buffer */
1319 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
1323 buffer.length = sizeof(*resource) + 1;
1324 buffer.pointer = resource;
1326 /* setup io resource */
1327 resource->io_res.type = ACPI_RESOURCE_TYPE_IO;
1328 resource->io_res.length = sizeof(struct acpi_resource);
1329 memcpy(&resource->io_res.data.io, &ioport->io,
1330 sizeof(struct acpi_resource_io));
1332 /* setup irq resource */
1333 resource->irq_res.type = ACPI_RESOURCE_TYPE_IRQ;
1334 resource->irq_res.length = sizeof(struct acpi_resource);
1335 memcpy(&resource->irq_res.data.irq, &irq->irq,
1336 sizeof(struct acpi_resource_irq));
1337 /* we requested a shared irq */
1338 resource->irq_res.data.irq.sharable = ACPI_SHARED;
1340 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
1342 /* Attempt to set the resource */
1343 dprintk("Evaluating _SRS\n");
1344 status = acpi_set_current_resources(device->handle, &buffer);
1346 /* check for total failure */
1347 if (ACPI_FAILURE(status)) {
1348 printk(KERN_ERR DRV_PFX "Error evaluating _SRS");
1353 /* Necessary device initializations calls (from sonypi) */
1354 sony_pic_call1(0x82);
1355 sony_pic_call2(0x81, 0xff);
1356 sony_pic_call1(compat ? 0x92 : 0x82);
1365 * ISR: some event is available
1368 static irqreturn_t sony_pic_irq(int irq, void *dev_id)
1374 u8 device_event = 0;
1376 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
1378 acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val,
1379 dev->cur_ioport->io.address_length);
1380 ev = port_val & SONY_PIC_EV_MASK;
1381 data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
1383 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
1384 port_val, ev, data_mask, dev->cur_ioport->io.minimum);
1386 if (ev == 0x00 || ev == 0xff)
1389 for (i = 0; sony_pic_eventtypes[i].model; i++) {
1391 if (spic_dev.model != sony_pic_eventtypes[i].model)
1394 if ((data_mask & sony_pic_eventtypes[i].data) !=
1395 sony_pic_eventtypes[i].data)
1398 if (!(mask & sony_pic_eventtypes[i].mask))
1401 for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
1402 if (ev == sony_pic_eventtypes[i].events[j].data) {
1404 sony_pic_eventtypes[i].events[j].event;
1412 sony_pic_report_input_event(device_event);
1413 acpi_bus_generate_event(spic_dev.acpi_dev, 1, device_event);
1423 static int sony_pic_remove(struct acpi_device *device, int type)
1425 struct sony_pic_ioport *io, *tmp_io;
1426 struct sony_pic_irq *irq, *tmp_irq;
1428 if (sony_pic_disable(device)) {
1429 printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
1433 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
1434 release_region(spic_dev.cur_ioport->io.minimum,
1435 spic_dev.cur_ioport->io.address_length);
1437 sony_pic_remove_input();
1439 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
1440 list_del(&io->list);
1443 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
1444 list_del(&irq->list);
1447 spic_dev.cur_ioport = NULL;
1448 spic_dev.cur_irq = NULL;
1450 dprintk("removed.\n");
1454 static int sony_pic_add(struct acpi_device *device)
1457 struct sony_pic_ioport *io, *tmp_io;
1458 struct sony_pic_irq *irq, *tmp_irq;
1460 printk(KERN_INFO DRV_PFX
1461 "Sony Programmable I/O Controller Driver v%s.\n",
1462 SONY_LAPTOP_DRIVER_VERSION);
1464 spic_dev.acpi_dev = device;
1465 strcpy(acpi_device_class(device), "sony/hotkey");
1466 spic_dev.model = sony_pic_detect_device_type();
1468 /* read _PRS resources */
1469 result = sony_pic_possible_resources(device);
1471 printk(KERN_ERR DRV_PFX
1472 "Unabe to read possible resources.\n");
1473 goto err_free_resources;
1476 /* setup input devices and helper fifo */
1477 result = sony_pic_setup_input();
1479 printk(KERN_ERR DRV_PFX
1480 "Unabe to create input devices.\n");
1481 goto err_free_resources;
1484 /* request io port */
1485 list_for_each_entry(io, &spic_dev.ioports, list) {
1486 if (request_region(io->io.minimum, io->io.address_length,
1487 "Sony Programable I/O Device")) {
1488 dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
1489 io->io.minimum, io->io.maximum,
1490 io->io.address_length);
1491 spic_dev.cur_ioport = io;
1495 if (!spic_dev.cur_ioport) {
1496 printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
1498 goto err_remove_input;
1502 list_for_each_entry(irq, &spic_dev.interrupts, list) {
1503 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
1504 IRQF_SHARED, "sony-laptop", &spic_dev)) {
1505 dprintk("IRQ: %d - triggering: %d - "
1506 "polarity: %d - shr: %d\n",
1507 irq->irq.interrupts[0],
1508 irq->irq.triggering,
1511 spic_dev.cur_irq = irq;
1515 if (!spic_dev.cur_irq) {
1516 printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
1518 goto err_release_region;
1521 /* set resource status _SRS */
1522 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
1524 printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
1531 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
1534 release_region(spic_dev.cur_ioport->io.minimum,
1535 spic_dev.cur_ioport->io.address_length);
1538 sony_pic_remove_input();
1541 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
1542 list_del(&io->list);
1545 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
1546 list_del(&irq->list);
1549 spic_dev.cur_ioport = NULL;
1550 spic_dev.cur_irq = NULL;
1555 static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
1557 if (sony_pic_disable(device))
1562 static int sony_pic_resume(struct acpi_device *device)
1564 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
1568 static struct acpi_driver sony_pic_driver = {
1569 .name = SONY_PIC_DRIVER_NAME,
1570 .class = SONY_PIC_CLASS,
1571 .ids = SONY_PIC_HID,
1572 .owner = THIS_MODULE,
1574 .add = sony_pic_add,
1575 .remove = sony_pic_remove,
1576 .suspend = sony_pic_suspend,
1577 .resume = sony_pic_resume,
1581 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
1583 .ident = "Sony Vaio",
1585 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
1586 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
1590 .ident = "Sony Vaio",
1592 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
1593 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
1599 static int __init sony_laptop_init(void)
1603 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
1604 result = acpi_bus_register_driver(&sony_pic_driver);
1606 printk(KERN_ERR DRV_PFX
1607 "Unable to register SPIC driver.");
1612 result = acpi_bus_register_driver(&sony_nc_driver);
1614 printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
1615 goto out_unregister_pic;
1622 acpi_bus_unregister_driver(&sony_pic_driver);
1627 static void __exit sony_laptop_exit(void)
1629 acpi_bus_unregister_driver(&sony_nc_driver);
1631 acpi_bus_unregister_driver(&sony_pic_driver);
1634 module_init(sony_laptop_init);
1635 module_exit(sony_laptop_exit);