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 for SPIC");
102 static unsigned long mask
= 0xffffffff;
103 module_param(mask
, ulong
, 0644);
104 MODULE_PARM_DESC(mask
,
105 "set this to the mask of event you want to enable (see doc)");
107 /*********** Input Devices ***********/
109 #define SONY_LAPTOP_BUF_SIZE 128
110 struct sony_laptop_input_s
{
112 struct input_dev
*jog_dev
;
113 struct input_dev
*key_dev
;
115 spinlock_t fifo_lock
;
116 struct workqueue_struct
*wq
;
118 static struct sony_laptop_input_s sony_laptop_input
= {
119 .users
= ATOMIC_INIT(0),
122 struct sony_laptop_keypress
{
123 struct input_dev
*dev
;
127 /* Correspondance table between sonypi events and input layer events */
131 } sony_laptop_inputkeys
[] = {
132 { SONYPI_EVENT_CAPTURE_PRESSED
, KEY_CAMERA
},
133 { SONYPI_EVENT_FNKEY_ONLY
, KEY_FN
},
134 { SONYPI_EVENT_FNKEY_ESC
, KEY_FN_ESC
},
135 { SONYPI_EVENT_FNKEY_F1
, KEY_FN_F1
},
136 { SONYPI_EVENT_FNKEY_F2
, KEY_FN_F2
},
137 { SONYPI_EVENT_FNKEY_F3
, KEY_FN_F3
},
138 { SONYPI_EVENT_FNKEY_F4
, KEY_FN_F4
},
139 { SONYPI_EVENT_FNKEY_F5
, KEY_FN_F5
},
140 { SONYPI_EVENT_FNKEY_F6
, KEY_FN_F6
},
141 { SONYPI_EVENT_FNKEY_F7
, KEY_FN_F7
},
142 { SONYPI_EVENT_FNKEY_F8
, KEY_FN_F8
},
143 { SONYPI_EVENT_FNKEY_F9
, KEY_FN_F9
},
144 { SONYPI_EVENT_FNKEY_F10
, KEY_FN_F10
},
145 { SONYPI_EVENT_FNKEY_F11
, KEY_FN_F11
},
146 { SONYPI_EVENT_FNKEY_F12
, KEY_FN_F12
},
147 { SONYPI_EVENT_FNKEY_1
, KEY_FN_1
},
148 { SONYPI_EVENT_FNKEY_2
, KEY_FN_2
},
149 { SONYPI_EVENT_FNKEY_D
, KEY_FN_D
},
150 { SONYPI_EVENT_FNKEY_E
, KEY_FN_E
},
151 { SONYPI_EVENT_FNKEY_F
, KEY_FN_F
},
152 { SONYPI_EVENT_FNKEY_S
, KEY_FN_S
},
153 { SONYPI_EVENT_FNKEY_B
, KEY_FN_B
},
154 { SONYPI_EVENT_BLUETOOTH_PRESSED
, KEY_BLUE
},
155 { SONYPI_EVENT_BLUETOOTH_ON
, KEY_BLUE
},
156 { SONYPI_EVENT_PKEY_P1
, KEY_PROG1
},
157 { SONYPI_EVENT_PKEY_P2
, KEY_PROG2
},
158 { SONYPI_EVENT_PKEY_P3
, KEY_PROG3
},
159 { SONYPI_EVENT_BACK_PRESSED
, KEY_BACK
},
160 { SONYPI_EVENT_HELP_PRESSED
, KEY_HELP
},
161 { SONYPI_EVENT_ZOOM_PRESSED
, KEY_ZOOM
},
162 { SONYPI_EVENT_THUMBPHRASE_PRESSED
, BTN_THUMB
},
166 /* release buttons after a short delay if pressed */
167 static void do_sony_laptop_release_key(struct work_struct
*work
)
169 struct sony_laptop_keypress kp
;
171 while (kfifo_get(sony_laptop_input
.fifo
, (unsigned char *)&kp
,
172 sizeof(kp
)) == sizeof(kp
)) {
174 input_report_key(kp
.dev
, kp
.key
, 0);
178 static DECLARE_WORK(sony_laptop_release_key_work
,
179 do_sony_laptop_release_key
);
181 /* forward event to the input subsytem */
182 static void sony_laptop_report_input_event(u8 event
)
184 struct input_dev
*jog_dev
= sony_laptop_input
.jog_dev
;
185 struct input_dev
*key_dev
= sony_laptop_input
.key_dev
;
186 struct sony_laptop_keypress kp
= { NULL
};
189 if (event
== SONYPI_EVENT_FNKEY_RELEASED
) {
190 /* Nothing, not all VAIOs generate this event */
197 case SONYPI_EVENT_JOGDIAL_UP
:
198 case SONYPI_EVENT_JOGDIAL_UP_PRESSED
:
199 input_report_rel(jog_dev
, REL_WHEEL
, 1);
203 case SONYPI_EVENT_JOGDIAL_DOWN
:
204 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
:
205 input_report_rel(jog_dev
, REL_WHEEL
, -1);
210 case SONYPI_EVENT_JOGDIAL_PRESSED
:
216 for (i
= 0; sony_laptop_inputkeys
[i
].sonypiev
; i
++)
217 if (event
== sony_laptop_inputkeys
[i
].sonypiev
) {
219 kp
.key
= sony_laptop_inputkeys
[i
].inputev
;
226 input_report_key(kp
.dev
, kp
.key
, 1);
228 kfifo_put(sony_laptop_input
.fifo
,
229 (unsigned char *)&kp
, sizeof(kp
));
231 if (!work_pending(&sony_laptop_release_key_work
))
232 queue_work(sony_laptop_input
.wq
,
233 &sony_laptop_release_key_work
);
235 dprintk("unknown input event %.2x\n", event
);
238 static int sony_laptop_setup_input(void)
240 struct input_dev
*jog_dev
;
241 struct input_dev
*key_dev
;
245 /* don't run again if already initialized */
246 if (atomic_add_return(1, &sony_laptop_input
.users
) > 1)
250 spin_lock_init(&sony_laptop_input
.fifo_lock
);
251 sony_laptop_input
.fifo
=
252 kfifo_alloc(SONY_LAPTOP_BUF_SIZE
, GFP_KERNEL
,
253 &sony_laptop_input
.fifo_lock
);
254 if (IS_ERR(sony_laptop_input
.fifo
)) {
255 printk(KERN_ERR DRV_PFX
"kfifo_alloc failed\n");
256 error
= PTR_ERR(sony_laptop_input
.fifo
);
261 sony_laptop_input
.wq
= create_singlethread_workqueue("sony-laptop");
262 if (!sony_laptop_input
.wq
) {
263 printk(KERN_ERR DRV_PFX
264 "Unabe to create workqueue.\n");
270 key_dev
= input_allocate_device();
276 key_dev
->name
= "Sony Vaio Keys";
277 key_dev
->id
.bustype
= BUS_ISA
;
278 key_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
280 /* Initialize the Input Drivers: special keys */
281 key_dev
->evbit
[0] = BIT(EV_KEY
);
282 for (i
= 0; sony_laptop_inputkeys
[i
].sonypiev
; i
++)
283 if (sony_laptop_inputkeys
[i
].inputev
)
284 set_bit(sony_laptop_inputkeys
[i
].inputev
,
287 error
= input_register_device(key_dev
);
289 goto err_free_keydev
;
291 sony_laptop_input
.key_dev
= key_dev
;
294 jog_dev
= input_allocate_device();
297 goto err_unregister_keydev
;
300 jog_dev
->name
= "Sony Vaio Jogdial";
301 jog_dev
->id
.bustype
= BUS_ISA
;
302 jog_dev
->id
.vendor
= PCI_VENDOR_ID_SONY
;
304 jog_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_REL
);
305 jog_dev
->keybit
[LONG(BTN_MOUSE
)] = BIT(BTN_MIDDLE
);
306 jog_dev
->relbit
[0] = BIT(REL_WHEEL
);
308 error
= input_register_device(jog_dev
);
310 goto err_free_jogdev
;
312 sony_laptop_input
.jog_dev
= jog_dev
;
317 input_free_device(jog_dev
);
319 err_unregister_keydev
:
320 input_unregister_device(key_dev
);
321 /* to avoid kref underflow below at input_free_device */
325 input_free_device(key_dev
);
328 destroy_workqueue(sony_laptop_input
.wq
);
331 kfifo_free(sony_laptop_input
.fifo
);
334 atomic_dec(&sony_laptop_input
.users
);
338 static void sony_laptop_remove_input(void)
340 /* cleanup only after the last user has gone */
341 if (!atomic_dec_and_test(&sony_laptop_input
.users
))
344 /* flush workqueue first */
345 flush_workqueue(sony_laptop_input
.wq
);
347 /* destroy input devs */
348 input_unregister_device(sony_laptop_input
.key_dev
);
349 sony_laptop_input
.key_dev
= NULL
;
351 if (sony_laptop_input
.jog_dev
) {
352 input_unregister_device(sony_laptop_input
.jog_dev
);
353 sony_laptop_input
.jog_dev
= NULL
;
356 destroy_workqueue(sony_laptop_input
.wq
);
357 kfifo_free(sony_laptop_input
.fifo
);
360 /*********** Platform Device ***********/
362 static atomic_t sony_pf_users
= ATOMIC_INIT(0);
363 static struct platform_driver sony_pf_driver
= {
365 .name
= "sony-laptop",
366 .owner
= THIS_MODULE
,
369 static struct platform_device
*sony_pf_device
;
371 static int sony_pf_add(void)
375 /* don't run again if already initialized */
376 if (atomic_add_return(1, &sony_pf_users
) > 1)
379 ret
= platform_driver_register(&sony_pf_driver
);
383 sony_pf_device
= platform_device_alloc("sony-laptop", -1);
384 if (!sony_pf_device
) {
386 goto out_platform_registered
;
389 ret
= platform_device_add(sony_pf_device
);
391 goto out_platform_alloced
;
395 out_platform_alloced
:
396 platform_device_put(sony_pf_device
);
397 sony_pf_device
= NULL
;
398 out_platform_registered
:
399 platform_driver_unregister(&sony_pf_driver
);
401 atomic_dec(&sony_pf_users
);
405 static void sony_pf_remove(void)
407 /* deregister only after the last user has gone */
408 if (!atomic_dec_and_test(&sony_pf_users
))
411 platform_device_del(sony_pf_device
);
412 platform_device_put(sony_pf_device
);
413 platform_driver_unregister(&sony_pf_driver
);
416 /*********** SNC (SNY5001) Device ***********/
418 /* the device uses 1-based values, while the backlight subsystem uses
420 #define SONY_MAX_BRIGHTNESS 8
422 #define SNC_VALIDATE_IN 0
423 #define SNC_VALIDATE_OUT 1
425 static ssize_t
sony_nc_sysfs_show(struct device
*, struct device_attribute
*,
427 static ssize_t
sony_nc_sysfs_store(struct device
*, struct device_attribute
*,
428 const char *, size_t);
429 static int boolean_validate(const int, const int);
430 static int brightness_default_validate(const int, const int);
432 struct sony_nc_value
{
433 char *name
; /* name of the entry */
434 char **acpiget
; /* names of the ACPI get function */
435 char **acpiset
; /* names of the ACPI set function */
436 int (*validate
)(const int, const int); /* input/output validation */
437 int value
; /* current setting */
438 int valid
; /* Has ever been set */
439 int debug
; /* active only in debug mode ? */
440 struct device_attribute devattr
; /* sysfs atribute */
443 #define SNC_HANDLE_NAMES(_name, _values...) \
444 static char *snc_##_name[] = { _values, NULL }
446 #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
448 .name = __stringify(_name), \
449 .acpiget = _getters, \
450 .acpiset = _setters, \
451 .validate = _validate, \
453 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
456 #define SNC_HANDLE_NULL { .name = NULL }
458 SNC_HANDLE_NAMES(fnkey_get
, "GHKE");
460 SNC_HANDLE_NAMES(brightness_def_get
, "GPBR");
461 SNC_HANDLE_NAMES(brightness_def_set
, "SPBR");
463 SNC_HANDLE_NAMES(cdpower_get
, "GCDP");
464 SNC_HANDLE_NAMES(cdpower_set
, "SCDP", "CDPW");
466 SNC_HANDLE_NAMES(audiopower_get
, "GAZP");
467 SNC_HANDLE_NAMES(audiopower_set
, "AZPW");
469 SNC_HANDLE_NAMES(lanpower_get
, "GLNP");
470 SNC_HANDLE_NAMES(lanpower_set
, "LNPW");
472 SNC_HANDLE_NAMES(PID_get
, "GPID");
474 SNC_HANDLE_NAMES(CTR_get
, "GCTR");
475 SNC_HANDLE_NAMES(CTR_set
, "SCTR");
477 SNC_HANDLE_NAMES(PCR_get
, "GPCR");
478 SNC_HANDLE_NAMES(PCR_set
, "SPCR");
480 SNC_HANDLE_NAMES(CMI_get
, "GCMI");
481 SNC_HANDLE_NAMES(CMI_set
, "SCMI");
483 static struct sony_nc_value sony_nc_values
[] = {
484 SNC_HANDLE(brightness_default
, snc_brightness_def_get
,
485 snc_brightness_def_set
, brightness_default_validate
, 0),
486 SNC_HANDLE(fnkey
, snc_fnkey_get
, NULL
, NULL
, 0),
487 SNC_HANDLE(cdpower
, snc_cdpower_get
, snc_cdpower_set
, boolean_validate
, 0),
488 SNC_HANDLE(audiopower
, snc_audiopower_get
, snc_audiopower_set
,
489 boolean_validate
, 0),
490 SNC_HANDLE(lanpower
, snc_lanpower_get
, snc_lanpower_set
,
491 boolean_validate
, 1),
492 /* unknown methods */
493 SNC_HANDLE(PID
, snc_PID_get
, NULL
, NULL
, 1),
494 SNC_HANDLE(CTR
, snc_CTR_get
, snc_CTR_set
, NULL
, 1),
495 SNC_HANDLE(PCR
, snc_PCR_get
, snc_PCR_set
, NULL
, 1),
496 SNC_HANDLE(CMI
, snc_CMI_get
, snc_CMI_set
, NULL
, 1),
500 static acpi_handle sony_nc_acpi_handle
;
501 static struct acpi_device
*sony_nc_acpi_device
= NULL
;
504 * acpi_evaluate_object wrappers
506 static int acpi_callgetfunc(acpi_handle handle
, char *name
, int *result
)
508 struct acpi_buffer output
;
509 union acpi_object out_obj
;
512 output
.length
= sizeof(out_obj
);
513 output
.pointer
= &out_obj
;
515 status
= acpi_evaluate_object(handle
, name
, NULL
, &output
);
516 if ((status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
)) {
517 *result
= out_obj
.integer
.value
;
521 printk(LOG_PFX
"acpi_callreadfunc failed\n");
526 static int acpi_callsetfunc(acpi_handle handle
, char *name
, int value
,
529 struct acpi_object_list params
;
530 union acpi_object in_obj
;
531 struct acpi_buffer output
;
532 union acpi_object out_obj
;
536 params
.pointer
= &in_obj
;
537 in_obj
.type
= ACPI_TYPE_INTEGER
;
538 in_obj
.integer
.value
= value
;
540 output
.length
= sizeof(out_obj
);
541 output
.pointer
= &out_obj
;
543 status
= acpi_evaluate_object(handle
, name
, ¶ms
, &output
);
544 if (status
== AE_OK
) {
545 if (result
!= NULL
) {
546 if (out_obj
.type
!= ACPI_TYPE_INTEGER
) {
547 printk(LOG_PFX
"acpi_evaluate_object bad "
551 *result
= out_obj
.integer
.value
;
556 printk(LOG_PFX
"acpi_evaluate_object failed\n");
562 * sony_nc_values input/output validate functions
565 /* brightness_default_validate:
567 * manipulate input output values to keep consistency with the
568 * backlight framework for which brightness values are 0-based.
570 static int brightness_default_validate(const int direction
, const int value
)
573 case SNC_VALIDATE_OUT
:
575 case SNC_VALIDATE_IN
:
576 if (value
>= 0 && value
< SONY_MAX_BRIGHTNESS
)
584 * on input validate boolean values 0/1, on output just pass the
587 static int boolean_validate(const int direction
, const int value
)
589 if (direction
== SNC_VALIDATE_IN
) {
590 if (value
!= 0 && value
!= 1)
597 * Sysfs show/store common to all sony_nc_values
599 static ssize_t
sony_nc_sysfs_show(struct device
*dev
, struct device_attribute
*attr
,
603 struct sony_nc_value
*item
=
604 container_of(attr
, struct sony_nc_value
, devattr
);
609 if (acpi_callgetfunc(sony_nc_acpi_handle
, *item
->acpiget
, &value
) < 0)
613 value
= item
->validate(SNC_VALIDATE_OUT
, value
);
615 return snprintf(buffer
, PAGE_SIZE
, "%d\n", value
);
618 static ssize_t
sony_nc_sysfs_store(struct device
*dev
,
619 struct device_attribute
*attr
,
620 const char *buffer
, size_t count
)
623 struct sony_nc_value
*item
=
624 container_of(attr
, struct sony_nc_value
, devattr
);
632 value
= simple_strtoul(buffer
, NULL
, 10);
635 value
= item
->validate(SNC_VALIDATE_IN
, value
);
640 if (acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
, value
, NULL
) < 0)
651 static int sony_backlight_update_status(struct backlight_device
*bd
)
653 return acpi_callsetfunc(sony_nc_acpi_handle
, "SBRT",
654 bd
->props
.brightness
+ 1, NULL
);
657 static int sony_backlight_get_brightness(struct backlight_device
*bd
)
661 if (acpi_callgetfunc(sony_nc_acpi_handle
, "GBRT", &value
))
663 /* brightness levels are 1-based, while backlight ones are 0-based */
667 static struct backlight_device
*sony_backlight_device
;
668 static struct backlight_ops sony_backlight_ops
= {
669 .update_status
= sony_backlight_update_status
,
670 .get_brightness
= sony_backlight_get_brightness
,
676 static void sony_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
678 dprintk("sony_acpi_notify, event: %d\n", event
);
679 sony_laptop_report_input_event(event
);
680 acpi_bus_generate_event(sony_nc_acpi_device
, 1, event
);
683 static acpi_status
sony_walk_callback(acpi_handle handle
, u32 level
,
684 void *context
, void **return_value
)
686 struct acpi_namespace_node
*node
;
687 union acpi_operand_object
*operand
;
689 node
= (struct acpi_namespace_node
*)handle
;
690 operand
= (union acpi_operand_object
*)node
->object
;
692 printk(LOG_PFX
"method: name: %4.4s, args %X\n", node
->name
.ascii
,
693 (u32
) operand
->method
.param_count
);
701 static int sony_nc_resume(struct acpi_device
*device
)
703 struct sony_nc_value
*item
;
705 for (item
= sony_nc_values
; item
->name
; item
++) {
710 ret
= acpi_callsetfunc(sony_nc_acpi_handle
, *item
->acpiset
,
713 printk("%s: %d\n", __FUNCTION__
, ret
);
720 static int sony_nc_add(struct acpi_device
*device
)
725 struct sony_nc_value
*item
;
727 sony_nc_acpi_device
= device
;
728 strcpy(acpi_device_class(device
), "sony/hotkey");
730 sony_nc_acpi_handle
= device
->handle
;
733 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, sony_nc_acpi_handle
,
734 1, sony_walk_callback
, NULL
, NULL
);
735 if (ACPI_FAILURE(status
)) {
736 printk(LOG_PFX
"unable to walk acpi resources\n");
742 /* setup input devices and helper fifo */
743 result
= sony_laptop_setup_input();
745 printk(KERN_ERR DRV_PFX
746 "Unabe to create input devices.\n");
750 status
= acpi_install_notify_handler(sony_nc_acpi_handle
,
752 sony_acpi_notify
, NULL
);
753 if (ACPI_FAILURE(status
)) {
754 printk(LOG_PFX
"unable to install notify handler\n");
759 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
, "GBRT", &handle
))) {
760 sony_backlight_device
= backlight_device_register("sony", NULL
,
762 &sony_backlight_ops
);
764 if (IS_ERR(sony_backlight_device
)) {
765 printk(LOG_PFX
"unable to register backlight device\n");
766 sony_backlight_device
= NULL
;
768 sony_backlight_device
->props
.brightness
=
769 sony_backlight_get_brightness
770 (sony_backlight_device
);
771 sony_backlight_device
->props
.max_brightness
=
772 SONY_MAX_BRIGHTNESS
- 1;
780 /* create sony_pf sysfs attributes related to the SNC device */
781 for (item
= sony_nc_values
; item
->name
; ++item
) {
783 if (!debug
&& item
->debug
)
786 /* find the available acpiget as described in the DSDT */
787 for (; item
->acpiget
&& *item
->acpiget
; ++item
->acpiget
) {
788 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
791 dprintk("Found %s getter: %s\n",
792 item
->name
, *item
->acpiget
);
793 item
->devattr
.attr
.mode
|= S_IRUGO
;
798 /* find the available acpiset as described in the DSDT */
799 for (; item
->acpiset
&& *item
->acpiset
; ++item
->acpiset
) {
800 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle
,
803 dprintk("Found %s setter: %s\n",
804 item
->name
, *item
->acpiset
);
805 item
->devattr
.attr
.mode
|= S_IWUSR
;
810 if (item
->devattr
.attr
.mode
!= 0) {
812 device_create_file(&sony_pf_device
->dev
,
819 printk(KERN_INFO SONY_NC_DRIVER_NAME
" successfully installed\n");
824 for (item
= sony_nc_values
; item
->name
; ++item
) {
825 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
830 if (sony_backlight_device
)
831 backlight_device_unregister(sony_backlight_device
);
833 status
= acpi_remove_notify_handler(sony_nc_acpi_handle
,
836 if (ACPI_FAILURE(status
))
837 printk(LOG_PFX
"unable to remove notify handler\n");
840 sony_laptop_remove_input();
846 static int sony_nc_remove(struct acpi_device
*device
, int type
)
849 struct sony_nc_value
*item
;
851 if (sony_backlight_device
)
852 backlight_device_unregister(sony_backlight_device
);
854 sony_nc_acpi_device
= NULL
;
856 status
= acpi_remove_notify_handler(sony_nc_acpi_handle
,
859 if (ACPI_FAILURE(status
))
860 printk(LOG_PFX
"unable to remove notify handler\n");
862 for (item
= sony_nc_values
; item
->name
; ++item
) {
863 device_remove_file(&sony_pf_device
->dev
, &item
->devattr
);
867 sony_laptop_remove_input();
869 printk(KERN_INFO SONY_NC_DRIVER_NAME
" successfully removed\n");
874 static struct acpi_driver sony_nc_driver
= {
875 .name
= SONY_NC_DRIVER_NAME
,
876 .class = SONY_NC_CLASS
,
878 .owner
= THIS_MODULE
,
881 .remove
= sony_nc_remove
,
882 .resume
= sony_nc_resume
,
886 /*********** SPIC (SNY6001) Device ***********/
888 #define SONYPI_DEVICE_TYPE1 0x00000001
889 #define SONYPI_DEVICE_TYPE2 0x00000002
890 #define SONYPI_DEVICE_TYPE3 0x00000004
892 #define SONY_PIC_EV_MASK 0xff
894 struct sony_pic_ioport
{
895 struct acpi_resource_io io
;
896 struct list_head list
;
899 struct sony_pic_irq
{
900 struct acpi_resource_irq irq
;
901 struct list_head list
;
904 struct sony_pic_dev
{
906 struct acpi_device
*acpi_dev
;
907 struct sony_pic_irq
*cur_irq
;
908 struct sony_pic_ioport
*cur_ioport
;
909 struct list_head interrupts
;
910 struct list_head ioports
;
913 static struct sony_pic_dev spic_dev
= {
914 .interrupts
= LIST_HEAD_INIT(spic_dev
.interrupts
),
915 .ioports
= LIST_HEAD_INIT(spic_dev
.ioports
),
919 #define SONYPI_JOGGER_MASK 0x00000001
920 #define SONYPI_CAPTURE_MASK 0x00000002
921 #define SONYPI_FNKEY_MASK 0x00000004
922 #define SONYPI_BLUETOOTH_MASK 0x00000008
923 #define SONYPI_PKEY_MASK 0x00000010
924 #define SONYPI_BACK_MASK 0x00000020
925 #define SONYPI_HELP_MASK 0x00000040
926 #define SONYPI_LID_MASK 0x00000080
927 #define SONYPI_ZOOM_MASK 0x00000100
928 #define SONYPI_THUMBPHRASE_MASK 0x00000200
929 #define SONYPI_MEYE_MASK 0x00000400
930 #define SONYPI_MEMORYSTICK_MASK 0x00000800
931 #define SONYPI_BATTERY_MASK 0x00001000
932 #define SONYPI_WIRELESS_MASK 0x00002000
934 struct sonypi_event
{
939 /* The set of possible button release events */
940 static struct sonypi_event sonypi_releaseev
[] = {
941 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED
},
945 /* The set of possible jogger events */
946 static struct sonypi_event sonypi_joggerev
[] = {
947 { 0x1f, SONYPI_EVENT_JOGDIAL_UP
},
948 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN
},
949 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED
},
950 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED
},
951 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP
},
952 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN
},
953 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED
},
954 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED
},
955 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP
},
956 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN
},
957 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED
},
958 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED
},
959 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED
},
963 /* The set of possible capture button events */
964 static struct sonypi_event sonypi_captureev
[] = {
965 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED
},
966 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED
},
967 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED
},
971 /* The set of possible fnkeys events */
972 static struct sonypi_event sonypi_fnkeyev
[] = {
973 { 0x10, SONYPI_EVENT_FNKEY_ESC
},
974 { 0x11, SONYPI_EVENT_FNKEY_F1
},
975 { 0x12, SONYPI_EVENT_FNKEY_F2
},
976 { 0x13, SONYPI_EVENT_FNKEY_F3
},
977 { 0x14, SONYPI_EVENT_FNKEY_F4
},
978 { 0x15, SONYPI_EVENT_FNKEY_F5
},
979 { 0x16, SONYPI_EVENT_FNKEY_F6
},
980 { 0x17, SONYPI_EVENT_FNKEY_F7
},
981 { 0x18, SONYPI_EVENT_FNKEY_F8
},
982 { 0x19, SONYPI_EVENT_FNKEY_F9
},
983 { 0x1a, SONYPI_EVENT_FNKEY_F10
},
984 { 0x1b, SONYPI_EVENT_FNKEY_F11
},
985 { 0x1c, SONYPI_EVENT_FNKEY_F12
},
986 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED
},
987 { 0x21, SONYPI_EVENT_FNKEY_1
},
988 { 0x22, SONYPI_EVENT_FNKEY_2
},
989 { 0x31, SONYPI_EVENT_FNKEY_D
},
990 { 0x32, SONYPI_EVENT_FNKEY_E
},
991 { 0x33, SONYPI_EVENT_FNKEY_F
},
992 { 0x34, SONYPI_EVENT_FNKEY_S
},
993 { 0x35, SONYPI_EVENT_FNKEY_B
},
994 { 0x36, SONYPI_EVENT_FNKEY_ONLY
},
998 /* The set of possible program key events */
999 static struct sonypi_event sonypi_pkeyev
[] = {
1000 { 0x01, SONYPI_EVENT_PKEY_P1
},
1001 { 0x02, SONYPI_EVENT_PKEY_P2
},
1002 { 0x04, SONYPI_EVENT_PKEY_P3
},
1003 { 0x5c, SONYPI_EVENT_PKEY_P1
},
1007 /* The set of possible bluetooth events */
1008 static struct sonypi_event sonypi_blueev
[] = {
1009 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED
},
1010 { 0x59, SONYPI_EVENT_BLUETOOTH_ON
},
1011 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF
},
1015 /* The set of possible wireless events */
1016 static struct sonypi_event sonypi_wlessev
[] = {
1017 { 0x59, SONYPI_EVENT_WIRELESS_ON
},
1018 { 0x5a, SONYPI_EVENT_WIRELESS_OFF
},
1022 /* The set of possible back button events */
1023 static struct sonypi_event sonypi_backev
[] = {
1024 { 0x20, SONYPI_EVENT_BACK_PRESSED
},
1028 /* The set of possible help button events */
1029 static struct sonypi_event sonypi_helpev
[] = {
1030 { 0x3b, SONYPI_EVENT_HELP_PRESSED
},
1035 /* The set of possible lid events */
1036 static struct sonypi_event sonypi_lidev
[] = {
1037 { 0x51, SONYPI_EVENT_LID_CLOSED
},
1038 { 0x50, SONYPI_EVENT_LID_OPENED
},
1042 /* The set of possible zoom events */
1043 static struct sonypi_event sonypi_zoomev
[] = {
1044 { 0x39, SONYPI_EVENT_ZOOM_PRESSED
},
1048 /* The set of possible thumbphrase events */
1049 static struct sonypi_event sonypi_thumbphraseev
[] = {
1050 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED
},
1054 /* The set of possible motioneye camera events */
1055 static struct sonypi_event sonypi_meyeev
[] = {
1056 { 0x00, SONYPI_EVENT_MEYE_FACE
},
1057 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE
},
1061 /* The set of possible memorystick events */
1062 static struct sonypi_event sonypi_memorystickev
[] = {
1063 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT
},
1064 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT
},
1068 /* The set of possible battery events */
1069 static struct sonypi_event sonypi_batteryev
[] = {
1070 { 0x20, SONYPI_EVENT_BATTERY_INSERT
},
1071 { 0x30, SONYPI_EVENT_BATTERY_REMOVE
},
1075 static struct sonypi_eventtypes
{
1079 struct sonypi_event
* events
;
1080 } sony_pic_eventtypes
[] = {
1081 { SONYPI_DEVICE_TYPE1
, 0, 0xffffffff, sonypi_releaseev
},
1082 { SONYPI_DEVICE_TYPE1
, 0x70, SONYPI_MEYE_MASK
, sonypi_meyeev
},
1083 { SONYPI_DEVICE_TYPE1
, 0x30, SONYPI_LID_MASK
, sonypi_lidev
},
1084 { SONYPI_DEVICE_TYPE1
, 0x60, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1085 { SONYPI_DEVICE_TYPE1
, 0x10, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1086 { SONYPI_DEVICE_TYPE1
, 0x20, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1087 { SONYPI_DEVICE_TYPE1
, 0x30, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1088 { SONYPI_DEVICE_TYPE1
, 0x40, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1089 { SONYPI_DEVICE_TYPE1
, 0x30, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1090 { SONYPI_DEVICE_TYPE1
, 0x40, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1092 { SONYPI_DEVICE_TYPE2
, 0, 0xffffffff, sonypi_releaseev
},
1093 { SONYPI_DEVICE_TYPE2
, 0x38, SONYPI_LID_MASK
, sonypi_lidev
},
1094 { SONYPI_DEVICE_TYPE2
, 0x11, SONYPI_JOGGER_MASK
, sonypi_joggerev
},
1095 { SONYPI_DEVICE_TYPE2
, 0x61, SONYPI_CAPTURE_MASK
, sonypi_captureev
},
1096 { SONYPI_DEVICE_TYPE2
, 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1097 { SONYPI_DEVICE_TYPE2
, 0x31, SONYPI_BLUETOOTH_MASK
, sonypi_blueev
},
1098 { SONYPI_DEVICE_TYPE2
, 0x08, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1099 { SONYPI_DEVICE_TYPE2
, 0x11, SONYPI_BACK_MASK
, sonypi_backev
},
1100 { SONYPI_DEVICE_TYPE2
, 0x21, SONYPI_HELP_MASK
, sonypi_helpev
},
1101 { SONYPI_DEVICE_TYPE2
, 0x21, SONYPI_ZOOM_MASK
, sonypi_zoomev
},
1102 { SONYPI_DEVICE_TYPE2
, 0x20, SONYPI_THUMBPHRASE_MASK
, sonypi_thumbphraseev
},
1103 { SONYPI_DEVICE_TYPE2
, 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1104 { SONYPI_DEVICE_TYPE2
, 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1105 { SONYPI_DEVICE_TYPE2
, 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1107 { SONYPI_DEVICE_TYPE3
, 0, 0xffffffff, sonypi_releaseev
},
1108 { SONYPI_DEVICE_TYPE3
, 0x21, SONYPI_FNKEY_MASK
, sonypi_fnkeyev
},
1109 { SONYPI_DEVICE_TYPE3
, 0x31, SONYPI_WIRELESS_MASK
, sonypi_wlessev
},
1110 { SONYPI_DEVICE_TYPE3
, 0x31, SONYPI_MEMORYSTICK_MASK
, sonypi_memorystickev
},
1111 { SONYPI_DEVICE_TYPE3
, 0x41, SONYPI_BATTERY_MASK
, sonypi_batteryev
},
1112 { SONYPI_DEVICE_TYPE3
, 0x31, SONYPI_PKEY_MASK
, sonypi_pkeyev
},
1116 static int sony_pic_detect_device_type(void)
1118 struct pci_dev
*pcidev
;
1121 if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1122 PCI_DEVICE_ID_INTEL_82371AB_3
, NULL
)))
1123 model
= SONYPI_DEVICE_TYPE1
;
1125 else if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1126 PCI_DEVICE_ID_INTEL_ICH6_1
, NULL
)))
1127 model
= SONYPI_DEVICE_TYPE3
;
1129 else if ((pcidev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1130 PCI_DEVICE_ID_INTEL_ICH7_1
, NULL
)))
1131 model
= SONYPI_DEVICE_TYPE3
;
1134 model
= SONYPI_DEVICE_TYPE2
;
1137 pci_dev_put(pcidev
);
1139 printk(KERN_INFO DRV_PFX
"detected Type%d model\n",
1140 model
== SONYPI_DEVICE_TYPE1
? 1 :
1141 model
== SONYPI_DEVICE_TYPE2
? 2 : 3);
1145 #define ITERATIONS_LONG 10000
1146 #define ITERATIONS_SHORT 10
1147 #define wait_on_command(command, iterations) { \
1148 unsigned int n = iterations; \
1149 while (--n && (command)) \
1152 dprintk("command failed at %s : %s (line %d)\n", \
1153 __FILE__, __FUNCTION__, __LINE__); \
1156 static u8
sony_pic_call1(u8 dev
)
1160 wait_on_command(inb_p(spic_dev
.cur_ioport
->io
.minimum
+ 4) & 2,
1162 outb(dev
, spic_dev
.cur_ioport
->io
.minimum
+ 4);
1163 v1
= inb_p(spic_dev
.cur_ioport
->io
.minimum
+ 4);
1164 v2
= inb_p(spic_dev
.cur_ioport
->io
.minimum
);
1165 dprintk("sony_pic_call1: 0x%.4x\n", (v2
<< 8) | v1
);
1169 static u8
sony_pic_call2(u8 dev
, u8 fn
)
1173 wait_on_command(inb_p(spic_dev
.cur_ioport
->io
.minimum
+ 4) & 2,
1175 outb(dev
, spic_dev
.cur_ioport
->io
.minimum
+ 4);
1176 wait_on_command(inb_p(spic_dev
.cur_ioport
->io
.minimum
+ 4) & 2,
1178 outb(fn
, spic_dev
.cur_ioport
->io
.minimum
);
1179 v1
= inb_p(spic_dev
.cur_ioport
->io
.minimum
);
1180 dprintk("sony_pic_call2: 0x%.4x\n", v1
);
1188 sony_pic_read_possible_resource(struct acpi_resource
*resource
, void *context
)
1191 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*)context
;
1193 switch (resource
->type
) {
1194 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
1195 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
1198 case ACPI_RESOURCE_TYPE_IRQ
:
1200 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
1201 struct sony_pic_irq
*interrupt
= NULL
;
1202 if (!p
|| !p
->interrupt_count
) {
1204 * IRQ descriptors may have no IRQ# bits set,
1205 * particularly those those w/ _STA disabled
1207 dprintk("Blank IRQ resource\n");
1210 for (i
= 0; i
< p
->interrupt_count
; i
++) {
1211 if (!p
->interrupts
[i
]) {
1212 printk(KERN_WARNING DRV_PFX
1217 interrupt
= kzalloc(sizeof(*interrupt
),
1222 list_add(&interrupt
->list
, &dev
->interrupts
);
1223 interrupt
->irq
.triggering
= p
->triggering
;
1224 interrupt
->irq
.polarity
= p
->polarity
;
1225 interrupt
->irq
.sharable
= p
->sharable
;
1226 interrupt
->irq
.interrupt_count
= 1;
1227 interrupt
->irq
.interrupts
[0] = p
->interrupts
[i
];
1231 case ACPI_RESOURCE_TYPE_IO
:
1233 struct acpi_resource_io
*io
= &resource
->data
.io
;
1234 struct sony_pic_ioport
*ioport
= NULL
;
1236 dprintk("Blank IO resource\n");
1240 ioport
= kzalloc(sizeof(*ioport
), GFP_KERNEL
);
1244 list_add(&ioport
->list
, &dev
->ioports
);
1245 memcpy(&ioport
->io
, io
, sizeof(*io
));
1249 dprintk("Resource %d isn't an IRQ nor an IO port\n",
1252 case ACPI_RESOURCE_TYPE_END_TAG
:
1255 return AE_CTRL_TERMINATE
;
1258 static int sony_pic_possible_resources(struct acpi_device
*device
)
1261 acpi_status status
= AE_OK
;
1266 /* get device status */
1267 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
1268 dprintk("Evaluating _STA\n");
1269 result
= acpi_bus_get_status(device
);
1271 printk(KERN_WARNING DRV_PFX
"Unable to read status\n");
1275 if (!device
->status
.enabled
)
1276 dprintk("Device disabled\n");
1278 dprintk("Device enabled\n");
1281 * Query and parse 'method'
1283 dprintk("Evaluating %s\n", METHOD_NAME__PRS
);
1284 status
= acpi_walk_resources(device
->handle
, METHOD_NAME__PRS
,
1285 sony_pic_read_possible_resource
, &spic_dev
);
1286 if (ACPI_FAILURE(status
)) {
1287 printk(KERN_WARNING DRV_PFX
1288 "Failure evaluating %s\n",
1297 * Disable the spic device by calling its _DIS method
1299 static int sony_pic_disable(struct acpi_device
*device
)
1301 if (ACPI_FAILURE(acpi_evaluate_object(device
->handle
, "_DIS", 0, NULL
)))
1304 dprintk("Device disabled\n");
1310 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
1312 * Call _SRS to set current resources
1314 static int sony_pic_enable(struct acpi_device
*device
,
1315 struct sony_pic_ioport
*ioport
, struct sony_pic_irq
*irq
)
1320 struct acpi_resource io_res
;
1321 struct acpi_resource irq_res
;
1322 struct acpi_resource end
;
1324 struct acpi_buffer buffer
= { 0, NULL
};
1326 if (!ioport
|| !irq
)
1329 /* init acpi_buffer */
1330 resource
= kzalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
1334 buffer
.length
= sizeof(*resource
) + 1;
1335 buffer
.pointer
= resource
;
1337 /* setup io resource */
1338 resource
->io_res
.type
= ACPI_RESOURCE_TYPE_IO
;
1339 resource
->io_res
.length
= sizeof(struct acpi_resource
);
1340 memcpy(&resource
->io_res
.data
.io
, &ioport
->io
,
1341 sizeof(struct acpi_resource_io
));
1343 /* setup irq resource */
1344 resource
->irq_res
.type
= ACPI_RESOURCE_TYPE_IRQ
;
1345 resource
->irq_res
.length
= sizeof(struct acpi_resource
);
1346 memcpy(&resource
->irq_res
.data
.irq
, &irq
->irq
,
1347 sizeof(struct acpi_resource_irq
));
1348 /* we requested a shared irq */
1349 resource
->irq_res
.data
.irq
.sharable
= ACPI_SHARED
;
1351 resource
->end
.type
= ACPI_RESOURCE_TYPE_END_TAG
;
1353 /* Attempt to set the resource */
1354 dprintk("Evaluating _SRS\n");
1355 status
= acpi_set_current_resources(device
->handle
, &buffer
);
1357 /* check for total failure */
1358 if (ACPI_FAILURE(status
)) {
1359 printk(KERN_ERR DRV_PFX
"Error evaluating _SRS");
1364 /* Necessary device initializations calls (from sonypi) */
1365 sony_pic_call1(0x82);
1366 sony_pic_call2(0x81, 0xff);
1367 sony_pic_call1(compat
? 0x92 : 0x82);
1376 * ISR: some event is available
1379 static irqreturn_t
sony_pic_irq(int irq
, void *dev_id
)
1385 u8 device_event
= 0;
1387 struct sony_pic_dev
*dev
= (struct sony_pic_dev
*) dev_id
;
1389 acpi_os_read_port(dev
->cur_ioport
->io
.minimum
, &port_val
,
1390 dev
->cur_ioport
->io
.address_length
);
1391 ev
= port_val
& SONY_PIC_EV_MASK
;
1392 data_mask
= 0xff & (port_val
>> (dev
->cur_ioport
->io
.address_length
- 8));
1394 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
1395 port_val
, ev
, data_mask
, dev
->cur_ioport
->io
.minimum
);
1397 if (ev
== 0x00 || ev
== 0xff)
1400 for (i
= 0; sony_pic_eventtypes
[i
].model
; i
++) {
1402 if (spic_dev
.model
!= sony_pic_eventtypes
[i
].model
)
1405 if ((data_mask
& sony_pic_eventtypes
[i
].data
) !=
1406 sony_pic_eventtypes
[i
].data
)
1409 if (!(mask
& sony_pic_eventtypes
[i
].mask
))
1412 for (j
= 0; sony_pic_eventtypes
[i
].events
[j
].event
; j
++) {
1413 if (ev
== sony_pic_eventtypes
[i
].events
[j
].data
) {
1415 sony_pic_eventtypes
[i
].events
[j
].event
;
1423 sony_laptop_report_input_event(device_event
);
1424 acpi_bus_generate_event(spic_dev
.acpi_dev
, 1, device_event
);
1434 static int sony_pic_remove(struct acpi_device
*device
, int type
)
1436 struct sony_pic_ioport
*io
, *tmp_io
;
1437 struct sony_pic_irq
*irq
, *tmp_irq
;
1439 if (sony_pic_disable(device
)) {
1440 printk(KERN_ERR DRV_PFX
"Couldn't disable device.\n");
1444 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
1445 release_region(spic_dev
.cur_ioport
->io
.minimum
,
1446 spic_dev
.cur_ioport
->io
.address_length
);
1448 sony_laptop_remove_input();
1450 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
1451 list_del(&io
->list
);
1454 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
1455 list_del(&irq
->list
);
1458 spic_dev
.cur_ioport
= NULL
;
1459 spic_dev
.cur_irq
= NULL
;
1461 dprintk("removed.\n");
1465 static int sony_pic_add(struct acpi_device
*device
)
1468 struct sony_pic_ioport
*io
, *tmp_io
;
1469 struct sony_pic_irq
*irq
, *tmp_irq
;
1471 printk(KERN_INFO DRV_PFX
1472 "Sony Programmable I/O Controller Driver v%s.\n",
1473 SONY_LAPTOP_DRIVER_VERSION
);
1475 spic_dev
.acpi_dev
= device
;
1476 strcpy(acpi_device_class(device
), "sony/hotkey");
1477 spic_dev
.model
= sony_pic_detect_device_type();
1479 /* read _PRS resources */
1480 result
= sony_pic_possible_resources(device
);
1482 printk(KERN_ERR DRV_PFX
1483 "Unabe to read possible resources.\n");
1484 goto err_free_resources
;
1487 /* setup input devices and helper fifo */
1488 result
= sony_laptop_setup_input();
1490 printk(KERN_ERR DRV_PFX
1491 "Unabe to create input devices.\n");
1492 goto err_free_resources
;
1495 /* request io port */
1496 list_for_each_entry(io
, &spic_dev
.ioports
, list
) {
1497 if (request_region(io
->io
.minimum
, io
->io
.address_length
,
1498 "Sony Programable I/O Device")) {
1499 dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
1500 io
->io
.minimum
, io
->io
.maximum
,
1501 io
->io
.address_length
);
1502 spic_dev
.cur_ioport
= io
;
1506 if (!spic_dev
.cur_ioport
) {
1507 printk(KERN_ERR DRV_PFX
"Failed to request_region.\n");
1509 goto err_remove_input
;
1513 list_for_each_entry(irq
, &spic_dev
.interrupts
, list
) {
1514 if (!request_irq(irq
->irq
.interrupts
[0], sony_pic_irq
,
1515 IRQF_SHARED
, "sony-laptop", &spic_dev
)) {
1516 dprintk("IRQ: %d - triggering: %d - "
1517 "polarity: %d - shr: %d\n",
1518 irq
->irq
.interrupts
[0],
1519 irq
->irq
.triggering
,
1522 spic_dev
.cur_irq
= irq
;
1526 if (!spic_dev
.cur_irq
) {
1527 printk(KERN_ERR DRV_PFX
"Failed to request_irq.\n");
1529 goto err_release_region
;
1532 /* set resource status _SRS */
1533 result
= sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
1535 printk(KERN_ERR DRV_PFX
"Couldn't enable device.\n");
1542 free_irq(spic_dev
.cur_irq
->irq
.interrupts
[0], &spic_dev
);
1545 release_region(spic_dev
.cur_ioport
->io
.minimum
,
1546 spic_dev
.cur_ioport
->io
.address_length
);
1549 sony_laptop_remove_input();
1552 list_for_each_entry_safe(io
, tmp_io
, &spic_dev
.ioports
, list
) {
1553 list_del(&io
->list
);
1556 list_for_each_entry_safe(irq
, tmp_irq
, &spic_dev
.interrupts
, list
) {
1557 list_del(&irq
->list
);
1560 spic_dev
.cur_ioport
= NULL
;
1561 spic_dev
.cur_irq
= NULL
;
1566 static int sony_pic_suspend(struct acpi_device
*device
, pm_message_t state
)
1568 if (sony_pic_disable(device
))
1573 static int sony_pic_resume(struct acpi_device
*device
)
1575 sony_pic_enable(device
, spic_dev
.cur_ioport
, spic_dev
.cur_irq
);
1579 static struct acpi_driver sony_pic_driver
= {
1580 .name
= SONY_PIC_DRIVER_NAME
,
1581 .class = SONY_PIC_CLASS
,
1582 .ids
= SONY_PIC_HID
,
1583 .owner
= THIS_MODULE
,
1585 .add
= sony_pic_add
,
1586 .remove
= sony_pic_remove
,
1587 .suspend
= sony_pic_suspend
,
1588 .resume
= sony_pic_resume
,
1592 static struct dmi_system_id __initdata sonypi_dmi_table
[] = {
1594 .ident
= "Sony Vaio",
1596 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1597 DMI_MATCH(DMI_PRODUCT_NAME
, "PCG-"),
1601 .ident
= "Sony Vaio",
1603 DMI_MATCH(DMI_SYS_VENDOR
, "Sony Corporation"),
1604 DMI_MATCH(DMI_PRODUCT_NAME
, "VGN-"),
1610 static int __init
sony_laptop_init(void)
1614 if (!no_spic
&& dmi_check_system(sonypi_dmi_table
)) {
1615 result
= acpi_bus_register_driver(&sony_pic_driver
);
1617 printk(KERN_ERR DRV_PFX
1618 "Unable to register SPIC driver.");
1623 result
= acpi_bus_register_driver(&sony_nc_driver
);
1625 printk(KERN_ERR DRV_PFX
"Unable to register SNC driver.");
1626 goto out_unregister_pic
;
1633 acpi_bus_unregister_driver(&sony_pic_driver
);
1638 static void __exit
sony_laptop_exit(void)
1640 acpi_bus_unregister_driver(&sony_nc_driver
);
1642 acpi_bus_unregister_driver(&sony_pic_driver
);
1645 module_init(sony_laptop_init
);
1646 module_exit(sony_laptop_exit
);