blob: f6cdc8929fd7ee8e739f9135e512d30843424e5f [file] [log] [blame]
Stelian Pop7f09c432007-01-13 23:04:31 +01001/*
malattia@linux.it33a04452007-04-09 19:26:03 +02002 * ACPI Sony Notebook Control Driver (SNC and SPIC)
Stelian Pop7f09c432007-01-13 23:04:31 +01003 *
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
Mattia Dongilied3aa4b2007-02-07 20:01:54 +01005 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
Stelian Pop7f09c432007-01-13 23:04:31 +01006 *
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
9 *
malattia@linux.it33a04452007-04-09 19:26:03 +020010 * The SNY6001 driver part is based on the sonypi driver which includes
11 * material from:
12 *
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
14 *
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
16 *
Marcin Garskidb955172007-10-19 23:22:11 +020017 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
malattia@linux.it33a04452007-04-09 19:26:03 +020018 *
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
20 *
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
22 *
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
24 *
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
26 *
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
28 *
Stelian Pop7f09c432007-01-13 23:04:31 +010029 * 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.
33 *
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.
38 *
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.
42 *
43 */
44
45#include <linux/kernel.h>
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/init.h>
Arnd Bergmann0410e682008-05-20 19:16:45 +020049#include <linux/smp_lock.h>
Stelian Pop7f09c432007-01-13 23:04:31 +010050#include <linux/types.h>
Alessandro Guido50f62af2007-01-13 23:04:34 +010051#include <linux/backlight.h>
Mattia Dongilied3aa4b2007-02-07 20:01:54 +010052#include <linux/platform_device.h>
Alessandro Guido50f62af2007-01-13 23:04:34 +010053#include <linux/err.h>
malattia@linux.it33a04452007-04-09 19:26:03 +020054#include <linux/dmi.h>
55#include <linux/pci.h>
56#include <linux/interrupt.h>
57#include <linux/delay.h>
58#include <linux/input.h>
59#include <linux/kfifo.h>
60#include <linux/workqueue.h>
61#include <linux/acpi.h>
Stelian Pop7f09c432007-01-13 23:04:31 +010062#include <acpi/acpi_drivers.h>
63#include <acpi/acpi_bus.h>
64#include <asm/uaccess.h>
malattia@linux.it33a04452007-04-09 19:26:03 +020065#include <linux/sonypi.h>
malattia@linux.it1ce82c12007-04-28 23:34:36 +090066#include <linux/sony-laptop.h>
Mattia Dongilia64e62a2007-05-01 11:19:53 +090067#ifdef CONFIG_SONYPI_COMPAT
malattia@linux.it7b153f32007-04-09 19:31:25 +020068#include <linux/poll.h>
69#include <linux/miscdevice.h>
70#endif
Stelian Pop7f09c432007-01-13 23:04:31 +010071
malattia@linux.it33a04452007-04-09 19:26:03 +020072#define DRV_PFX "sony-laptop: "
malattia@linux.itb9a218b2007-04-09 10:19:06 +020073#define dprintk(msg...) do { \
malattia@linux.itf6119b02007-04-09 19:31:06 +020074 if (debug) printk(KERN_WARNING DRV_PFX msg); \
malattia@linux.itb9a218b2007-04-09 10:19:06 +020075} while (0)
76
Mattia Dongili425ef5d2008-01-14 18:05:44 +090077#define SONY_LAPTOP_DRIVER_VERSION "0.6"
Alessandro Guido50f62af2007-01-13 23:04:34 +010078
malattia@linux.it33a04452007-04-09 19:26:03 +020079#define SONY_NC_CLASS "sony-nc"
80#define SONY_NC_HID "SNY5001"
malattia@linux.itf6119b02007-04-09 19:31:06 +020081#define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
malattia@linux.it33a04452007-04-09 19:26:03 +020082
83#define SONY_PIC_CLASS "sony-pic"
84#define SONY_PIC_HID "SNY6001"
malattia@linux.itf6119b02007-04-09 19:31:06 +020085#define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
Stelian Pop7f09c432007-01-13 23:04:31 +010086
Mattia Dongilied3aa4b2007-02-07 20:01:54 +010087MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
malattia@linux.it33a04452007-04-09 19:26:03 +020088MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
Stelian Pop7f09c432007-01-13 23:04:31 +010089MODULE_LICENSE("GPL");
malattia@linux.it33a04452007-04-09 19:26:03 +020090MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
Stelian Pop7f09c432007-01-13 23:04:31 +010091
92static int debug;
93module_param(debug, int, 0);
94MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
Len Browna02d1c12007-02-07 15:34:02 -050095 "the development of this driver");
Stelian Pop7f09c432007-01-13 23:04:31 +010096
malattia@linux.it33a04452007-04-09 19:26:03 +020097static int no_spic; /* = 0 */
98module_param(no_spic, int, 0444);
99MODULE_PARM_DESC(no_spic,
100 "set this if you don't want to enable the SPIC device");
101
102static int compat; /* = 0 */
103module_param(compat, int, 0444);
104MODULE_PARM_DESC(compat,
malattia@linux.it7b153f32007-04-09 19:31:25 +0200105 "set this if you want to enable backward compatibility mode");
malattia@linux.it33a04452007-04-09 19:26:03 +0200106
107static unsigned long mask = 0xffffffff;
108module_param(mask, ulong, 0644);
109MODULE_PARM_DESC(mask,
110 "set this to the mask of event you want to enable (see doc)");
111
malattia@linux.it5f3d2892007-04-28 23:18:45 +0900112static int camera; /* = 0 */
113module_param(camera, int, 0444);
114MODULE_PARM_DESC(camera,
115 "set this to 1 to enable Motion Eye camera controls "
116 "(only use it if you have a C1VE or C1VN model)");
117
Mattia Dongilia64e62a2007-05-01 11:19:53 +0900118#ifdef CONFIG_SONYPI_COMPAT
malattia@linux.it7b153f32007-04-09 19:31:25 +0200119static int minor = -1;
120module_param(minor, int, 0);
121MODULE_PARM_DESC(minor,
122 "minor number of the misc device for the SPIC compatibility code, "
123 "default is -1 (automatic)");
124#endif
125
malattia@linux.it1549ee62007-04-09 10:19:08 +0200126/*********** Input Devices ***********/
127
128#define SONY_LAPTOP_BUF_SIZE 128
129struct sony_laptop_input_s {
130 atomic_t users;
131 struct input_dev *jog_dev;
132 struct input_dev *key_dev;
133 struct kfifo *fifo;
134 spinlock_t fifo_lock;
135 struct workqueue_struct *wq;
136};
137static struct sony_laptop_input_s sony_laptop_input = {
138 .users = ATOMIC_INIT(0),
139};
140
141struct sony_laptop_keypress {
142 struct input_dev *dev;
143 int key;
144};
145
Mattia Dongilibc57f862007-07-20 02:01:57 +0900146/* Correspondance table between sonypi events
147 * and input layer indexes in the keymap
148 */
149static int sony_laptop_input_index[] = {
Mattia Dongili3eb87492008-01-14 18:05:45 +0900150 -1, /* 0 no event */
151 -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
152 -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
153 -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
154 -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
155 -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
156 -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
157 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
158 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
159 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
160 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
161 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
162 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
163 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
164 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
165 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
166 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
167 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
168 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
169 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
170 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
171 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
172 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
173 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
174 17, /* 24 SONYPI_EVENT_FNKEY_1 */
175 18, /* 25 SONYPI_EVENT_FNKEY_2 */
176 19, /* 26 SONYPI_EVENT_FNKEY_D */
177 20, /* 27 SONYPI_EVENT_FNKEY_E */
178 21, /* 28 SONYPI_EVENT_FNKEY_F */
179 22, /* 29 SONYPI_EVENT_FNKEY_S */
180 23, /* 30 SONYPI_EVENT_FNKEY_B */
181 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
182 25, /* 32 SONYPI_EVENT_PKEY_P1 */
183 26, /* 33 SONYPI_EVENT_PKEY_P2 */
184 27, /* 34 SONYPI_EVENT_PKEY_P3 */
185 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
186 -1, /* 36 SONYPI_EVENT_LID_CLOSED */
187 -1, /* 37 SONYPI_EVENT_LID_OPENED */
188 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
189 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
190 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
191 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
192 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
193 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
194 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
195 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
196 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
197 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
198 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
199 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
200 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
201 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
202 43, /* 52 SONYPI_EVENT_MEYE_FACE */
203 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
204 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
205 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
206 -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
207 -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
208 -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
209 -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
210 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
211 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
212 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
213 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
Matthew Garrett9b578962009-03-26 21:58:14 +0900214 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
Mattia Dongilibc57f862007-07-20 02:01:57 +0900215};
216
217static int sony_laptop_input_keycode_map[] = {
218 KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
219 KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
220 KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
221 KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
222 KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */
223 KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */
224 KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */
225 KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */
226 KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */
227 KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */
228 KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */
229 KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */
230 KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */
231 KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */
232 KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */
233 KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */
234 KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */
235 KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */
236 KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */
237 KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */
238 KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */
239 KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */
240 KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */
241 KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */
242 KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
243 KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */
244 KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */
245 KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */
246 KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */
247 KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
248 KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
249 KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */
250 KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */
251 KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
252 KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
253 KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
254 KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
255 KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
256 KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
257 KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
258 KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
259 KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
260 BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
261 KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */
262 KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
263 KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
264 KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
265 KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */
266 KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */
Mattia Dongili3eb87492008-01-14 18:05:45 +0900267 KEY_ZOOMIN, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
Matthew Garrett9b578962009-03-26 21:58:14 +0900268 KEY_ZOOMOUT, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
269 KEY_EJECTCD /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
malattia@linux.it1549ee62007-04-09 10:19:08 +0200270};
271
272/* release buttons after a short delay if pressed */
273static void do_sony_laptop_release_key(struct work_struct *work)
274{
275 struct sony_laptop_keypress kp;
276
277 while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
278 sizeof(kp)) == sizeof(kp)) {
279 msleep(10);
280 input_report_key(kp.dev, kp.key, 0);
281 input_sync(kp.dev);
282 }
283}
284static DECLARE_WORK(sony_laptop_release_key_work,
285 do_sony_laptop_release_key);
286
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200287/* forward event to the input subsystem */
malattia@linux.it1549ee62007-04-09 10:19:08 +0200288static void sony_laptop_report_input_event(u8 event)
289{
290 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
291 struct input_dev *key_dev = sony_laptop_input.key_dev;
292 struct sony_laptop_keypress kp = { NULL };
malattia@linux.it1549ee62007-04-09 10:19:08 +0200293
294 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
295 /* Nothing, not all VAIOs generate this event */
296 return;
297 }
298
299 /* report events */
300 switch (event) {
301 /* jog_dev events */
302 case SONYPI_EVENT_JOGDIAL_UP:
303 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
304 input_report_rel(jog_dev, REL_WHEEL, 1);
305 input_sync(jog_dev);
306 return;
307
308 case SONYPI_EVENT_JOGDIAL_DOWN:
309 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
310 input_report_rel(jog_dev, REL_WHEEL, -1);
311 input_sync(jog_dev);
312 return;
313
314 /* key_dev events */
315 case SONYPI_EVENT_JOGDIAL_PRESSED:
316 kp.key = BTN_MIDDLE;
317 kp.dev = jog_dev;
318 break;
319
320 default:
Adrian Bunkd399d132008-02-20 00:59:03 +0200321 if (event >= ARRAY_SIZE(sony_laptop_input_index)) {
Mattia Dongilibc57f862007-07-20 02:01:57 +0900322 dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
323 break;
324 }
325 if (sony_laptop_input_index[event] != -1) {
326 kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]];
327 if (kp.key != KEY_UNKNOWN)
malattia@linux.it1549ee62007-04-09 10:19:08 +0200328 kp.dev = key_dev;
Mattia Dongilibc57f862007-07-20 02:01:57 +0900329 }
malattia@linux.it1549ee62007-04-09 10:19:08 +0200330 break;
331 }
332
333 if (kp.dev) {
334 input_report_key(kp.dev, kp.key, 1);
Mattia Dongilibc57f862007-07-20 02:01:57 +0900335 /* we emit the scancode so we can always remap the key */
336 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
malattia@linux.it1549ee62007-04-09 10:19:08 +0200337 input_sync(kp.dev);
338 kfifo_put(sony_laptop_input.fifo,
339 (unsigned char *)&kp, sizeof(kp));
340
341 if (!work_pending(&sony_laptop_release_key_work))
342 queue_work(sony_laptop_input.wq,
343 &sony_laptop_release_key_work);
344 } else
345 dprintk("unknown input event %.2x\n", event);
346}
347
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -0500348static int sony_laptop_setup_input(struct acpi_device *acpi_device)
malattia@linux.it1549ee62007-04-09 10:19:08 +0200349{
350 struct input_dev *jog_dev;
351 struct input_dev *key_dev;
352 int i;
353 int error;
354
355 /* don't run again if already initialized */
356 if (atomic_add_return(1, &sony_laptop_input.users) > 1)
357 return 0;
358
359 /* kfifo */
360 spin_lock_init(&sony_laptop_input.fifo_lock);
361 sony_laptop_input.fifo =
362 kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
363 &sony_laptop_input.fifo_lock);
364 if (IS_ERR(sony_laptop_input.fifo)) {
365 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
366 error = PTR_ERR(sony_laptop_input.fifo);
367 goto err_dec_users;
368 }
369
370 /* init workqueue */
371 sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
372 if (!sony_laptop_input.wq) {
373 printk(KERN_ERR DRV_PFX
374 "Unabe to create workqueue.\n");
375 error = -ENXIO;
376 goto err_free_kfifo;
377 }
378
379 /* input keys */
380 key_dev = input_allocate_device();
381 if (!key_dev) {
382 error = -ENOMEM;
383 goto err_destroy_wq;
384 }
385
386 key_dev->name = "Sony Vaio Keys";
387 key_dev->id.bustype = BUS_ISA;
388 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -0500389 key_dev->dev.parent = &acpi_device->dev;
malattia@linux.it1549ee62007-04-09 10:19:08 +0200390
391 /* Initialize the Input Drivers: special keys */
Mattia Dongilibc57f862007-07-20 02:01:57 +0900392 set_bit(EV_KEY, key_dev->evbit);
393 set_bit(EV_MSC, key_dev->evbit);
394 set_bit(MSC_SCAN, key_dev->mscbit);
395 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
396 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
397 key_dev->keycode = &sony_laptop_input_keycode_map;
398 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) {
399 if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) {
400 set_bit(sony_laptop_input_keycode_map[i],
401 key_dev->keybit);
402 }
403 }
malattia@linux.it1549ee62007-04-09 10:19:08 +0200404
405 error = input_register_device(key_dev);
406 if (error)
407 goto err_free_keydev;
408
409 sony_laptop_input.key_dev = key_dev;
410
411 /* jogdial */
412 jog_dev = input_allocate_device();
413 if (!jog_dev) {
414 error = -ENOMEM;
415 goto err_unregister_keydev;
416 }
417
418 jog_dev->name = "Sony Vaio Jogdial";
419 jog_dev->id.bustype = BUS_ISA;
420 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -0500421 key_dev->dev.parent = &acpi_device->dev;
malattia@linux.it1549ee62007-04-09 10:19:08 +0200422
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700423 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
424 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE);
425 jog_dev->relbit[0] = BIT_MASK(REL_WHEEL);
malattia@linux.it1549ee62007-04-09 10:19:08 +0200426
427 error = input_register_device(jog_dev);
428 if (error)
429 goto err_free_jogdev;
430
431 sony_laptop_input.jog_dev = jog_dev;
432
433 return 0;
434
435err_free_jogdev:
436 input_free_device(jog_dev);
437
438err_unregister_keydev:
439 input_unregister_device(key_dev);
440 /* to avoid kref underflow below at input_free_device */
441 key_dev = NULL;
442
443err_free_keydev:
444 input_free_device(key_dev);
445
446err_destroy_wq:
447 destroy_workqueue(sony_laptop_input.wq);
448
449err_free_kfifo:
450 kfifo_free(sony_laptop_input.fifo);
451
452err_dec_users:
453 atomic_dec(&sony_laptop_input.users);
454 return error;
455}
456
457static void sony_laptop_remove_input(void)
458{
459 /* cleanup only after the last user has gone */
460 if (!atomic_dec_and_test(&sony_laptop_input.users))
461 return;
462
463 /* flush workqueue first */
464 flush_workqueue(sony_laptop_input.wq);
465
466 /* destroy input devs */
467 input_unregister_device(sony_laptop_input.key_dev);
468 sony_laptop_input.key_dev = NULL;
469
470 if (sony_laptop_input.jog_dev) {
471 input_unregister_device(sony_laptop_input.jog_dev);
472 sony_laptop_input.jog_dev = NULL;
473 }
474
475 destroy_workqueue(sony_laptop_input.wq);
476 kfifo_free(sony_laptop_input.fifo);
477}
478
malattia@linux.it56b87562007-04-09 10:19:05 +0200479/*********** Platform Device ***********/
480
481static atomic_t sony_pf_users = ATOMIC_INIT(0);
482static struct platform_driver sony_pf_driver = {
483 .driver = {
484 .name = "sony-laptop",
485 .owner = THIS_MODULE,
486 }
487};
488static struct platform_device *sony_pf_device;
489
490static int sony_pf_add(void)
491{
492 int ret = 0;
493
494 /* don't run again if already initialized */
495 if (atomic_add_return(1, &sony_pf_users) > 1)
496 return 0;
497
498 ret = platform_driver_register(&sony_pf_driver);
499 if (ret)
500 goto out;
501
502 sony_pf_device = platform_device_alloc("sony-laptop", -1);
503 if (!sony_pf_device) {
504 ret = -ENOMEM;
505 goto out_platform_registered;
506 }
507
508 ret = platform_device_add(sony_pf_device);
509 if (ret)
510 goto out_platform_alloced;
511
512 return 0;
513
514 out_platform_alloced:
515 platform_device_put(sony_pf_device);
516 sony_pf_device = NULL;
517 out_platform_registered:
518 platform_driver_unregister(&sony_pf_driver);
519 out:
520 atomic_dec(&sony_pf_users);
521 return ret;
522}
523
524static void sony_pf_remove(void)
525{
526 /* deregister only after the last user has gone */
527 if (!atomic_dec_and_test(&sony_pf_users))
528 return;
529
530 platform_device_del(sony_pf_device);
531 platform_device_put(sony_pf_device);
532 platform_driver_unregister(&sony_pf_driver);
533}
534
535/*********** SNC (SNY5001) Device ***********/
536
malattia@linux.it33a04452007-04-09 19:26:03 +0200537/* the device uses 1-based values, while the backlight subsystem uses
538 0-based values */
539#define SONY_MAX_BRIGHTNESS 8
540
541#define SNC_VALIDATE_IN 0
542#define SNC_VALIDATE_OUT 1
543
malattia@linux.it59b19102007-04-09 10:19:04 +0200544static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
Len Browna02d1c12007-02-07 15:34:02 -0500545 char *);
malattia@linux.it59b19102007-04-09 10:19:04 +0200546static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
Len Browna02d1c12007-02-07 15:34:02 -0500547 const char *, size_t);
Mattia Dongili156c2212007-02-12 22:01:07 +0100548static int boolean_validate(const int, const int);
549static int brightness_default_validate(const int, const int);
550
malattia@linux.it59b19102007-04-09 10:19:04 +0200551struct sony_nc_value {
Len Browna02d1c12007-02-07 15:34:02 -0500552 char *name; /* name of the entry */
553 char **acpiget; /* names of the ACPI get function */
554 char **acpiset; /* names of the ACPI set function */
Mattia Dongili156c2212007-02-12 22:01:07 +0100555 int (*validate)(const int, const int); /* input/output validation */
Len Browna02d1c12007-02-07 15:34:02 -0500556 int value; /* current setting */
557 int valid; /* Has ever been set */
558 int debug; /* active only in debug mode ? */
559 struct device_attribute devattr; /* sysfs atribute */
Stelian Pop7f09c432007-01-13 23:04:31 +0100560};
561
malattia@linux.it59b19102007-04-09 10:19:04 +0200562#define SNC_HANDLE_NAMES(_name, _values...) \
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100563 static char *snc_##_name[] = { _values, NULL }
564
malattia@linux.it59b19102007-04-09 10:19:04 +0200565#define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100566 { \
567 .name = __stringify(_name), \
568 .acpiget = _getters, \
569 .acpiset = _setters, \
Mattia Dongili156c2212007-02-12 22:01:07 +0100570 .validate = _validate, \
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100571 .debug = _debug, \
malattia@linux.it59b19102007-04-09 10:19:04 +0200572 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100573 }
574
malattia@linux.it59b19102007-04-09 10:19:04 +0200575#define SNC_HANDLE_NULL { .name = NULL }
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100576
malattia@linux.it59b19102007-04-09 10:19:04 +0200577SNC_HANDLE_NAMES(fnkey_get, "GHKE");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100578
malattia@linux.it59b19102007-04-09 10:19:04 +0200579SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
580SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100581
malattia@linux.it59b19102007-04-09 10:19:04 +0200582SNC_HANDLE_NAMES(cdpower_get, "GCDP");
583SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100584
malattia@linux.it59b19102007-04-09 10:19:04 +0200585SNC_HANDLE_NAMES(audiopower_get, "GAZP");
586SNC_HANDLE_NAMES(audiopower_set, "AZPW");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100587
malattia@linux.it59b19102007-04-09 10:19:04 +0200588SNC_HANDLE_NAMES(lanpower_get, "GLNP");
589SNC_HANDLE_NAMES(lanpower_set, "LNPW");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100590
Mattia Dongili044847e2007-07-16 02:34:33 +0900591SNC_HANDLE_NAMES(lidstate_get, "GLID");
592
593SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
594SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
595
596SNC_HANDLE_NAMES(gainbass_get, "GMGB");
597SNC_HANDLE_NAMES(gainbass_set, "CMGB");
598
malattia@linux.it59b19102007-04-09 10:19:04 +0200599SNC_HANDLE_NAMES(PID_get, "GPID");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100600
malattia@linux.it59b19102007-04-09 10:19:04 +0200601SNC_HANDLE_NAMES(CTR_get, "GCTR");
602SNC_HANDLE_NAMES(CTR_set, "SCTR");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100603
malattia@linux.it59b19102007-04-09 10:19:04 +0200604SNC_HANDLE_NAMES(PCR_get, "GPCR");
605SNC_HANDLE_NAMES(PCR_set, "SPCR");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100606
malattia@linux.it59b19102007-04-09 10:19:04 +0200607SNC_HANDLE_NAMES(CMI_get, "GCMI");
608SNC_HANDLE_NAMES(CMI_set, "SCMI");
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100609
malattia@linux.it59b19102007-04-09 10:19:04 +0200610static struct sony_nc_value sony_nc_values[] = {
611 SNC_HANDLE(brightness_default, snc_brightness_def_get,
Mattia Dongili156c2212007-02-12 22:01:07 +0100612 snc_brightness_def_set, brightness_default_validate, 0),
malattia@linux.it59b19102007-04-09 10:19:04 +0200613 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
614 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
615 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
Mattia Dongili156c2212007-02-12 22:01:07 +0100616 boolean_validate, 0),
malattia@linux.it59b19102007-04-09 10:19:04 +0200617 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
Mattia Dongili156c2212007-02-12 22:01:07 +0100618 boolean_validate, 1),
Mattia Dongili044847e2007-07-16 02:34:33 +0900619 SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
620 boolean_validate, 0),
621 SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
622 boolean_validate, 0),
623 SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
624 boolean_validate, 0),
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100625 /* unknown methods */
malattia@linux.it59b19102007-04-09 10:19:04 +0200626 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
627 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
628 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
629 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
630 SNC_HANDLE_NULL
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100631};
632
malattia@linux.it59b19102007-04-09 10:19:04 +0200633static acpi_handle sony_nc_acpi_handle;
634static struct acpi_device *sony_nc_acpi_device = NULL;
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100635
Mattia Dongilid78865c2007-02-07 20:01:56 +0100636/*
637 * acpi_evaluate_object wrappers
638 */
Stelian Pop7f09c432007-01-13 23:04:31 +0100639static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
640{
641 struct acpi_buffer output;
642 union acpi_object out_obj;
643 acpi_status status;
644
645 output.length = sizeof(out_obj);
646 output.pointer = &out_obj;
647
648 status = acpi_evaluate_object(handle, name, NULL, &output);
649 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
650 *result = out_obj.integer.value;
651 return 0;
652 }
653
malattia@linux.itf6119b02007-04-09 19:31:06 +0200654 printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
Stelian Pop7f09c432007-01-13 23:04:31 +0100655
656 return -1;
657}
658
659static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
660 int *result)
661{
662 struct acpi_object_list params;
663 union acpi_object in_obj;
664 struct acpi_buffer output;
665 union acpi_object out_obj;
666 acpi_status status;
667
668 params.count = 1;
669 params.pointer = &in_obj;
670 in_obj.type = ACPI_TYPE_INTEGER;
671 in_obj.integer.value = value;
672
673 output.length = sizeof(out_obj);
674 output.pointer = &out_obj;
675
676 status = acpi_evaluate_object(handle, name, &params, &output);
677 if (status == AE_OK) {
678 if (result != NULL) {
679 if (out_obj.type != ACPI_TYPE_INTEGER) {
malattia@linux.itf6119b02007-04-09 19:31:06 +0200680 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
Stelian Pop7f09c432007-01-13 23:04:31 +0100681 "return type\n");
682 return -1;
683 }
684 *result = out_obj.integer.value;
685 }
686 return 0;
687 }
688
malattia@linux.itf6119b02007-04-09 19:31:06 +0200689 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
Stelian Pop7f09c432007-01-13 23:04:31 +0100690
691 return -1;
692}
693
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900694static int sony_find_snc_handle(int handle)
695{
696 int i;
697 int result;
698
699 for (i = 0x20; i < 0x30; i++) {
700 acpi_callsetfunc(sony_nc_acpi_handle, "SN00", i, &result);
701 if (result == handle)
702 return i-0x20;
703 }
704
705 return -1;
706}
707
708static int sony_call_snc_handle(int handle, int argument, int *result)
709{
710 int offset = sony_find_snc_handle(handle);
711
712 if (offset < 0)
713 return -1;
714
715 return acpi_callsetfunc(sony_nc_acpi_handle, "SN07", offset | argument,
716 result);
717}
718
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100719/*
malattia@linux.it59b19102007-04-09 10:19:04 +0200720 * sony_nc_values input/output validate functions
Mattia Dongili156c2212007-02-12 22:01:07 +0100721 */
722
723/* brightness_default_validate:
724 *
725 * manipulate input output values to keep consistency with the
726 * backlight framework for which brightness values are 0-based.
727 */
728static int brightness_default_validate(const int direction, const int value)
729{
730 switch (direction) {
731 case SNC_VALIDATE_OUT:
732 return value - 1;
733 case SNC_VALIDATE_IN:
734 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
735 return value + 1;
736 }
737 return -EINVAL;
738}
739
740/* boolean_validate:
741 *
742 * on input validate boolean values 0/1, on output just pass the
743 * received value.
744 */
745static int boolean_validate(const int direction, const int value)
746{
747 if (direction == SNC_VALIDATE_IN) {
748 if (value != 0 && value != 1)
749 return -EINVAL;
750 }
751 return value;
752}
753
754/*
malattia@linux.it59b19102007-04-09 10:19:04 +0200755 * Sysfs show/store common to all sony_nc_values
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100756 */
malattia@linux.it59b19102007-04-09 10:19:04 +0200757static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
Len Browna02d1c12007-02-07 15:34:02 -0500758 char *buffer)
Stelian Pop7f09c432007-01-13 23:04:31 +0100759{
Stelian Pop7f09c432007-01-13 23:04:31 +0100760 int value;
malattia@linux.it59b19102007-04-09 10:19:04 +0200761 struct sony_nc_value *item =
762 container_of(attr, struct sony_nc_value, devattr);
Stelian Pop7f09c432007-01-13 23:04:31 +0100763
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100764 if (!*item->acpiget)
Stelian Pop7f09c432007-01-13 23:04:31 +0100765 return -EIO;
766
malattia@linux.it59b19102007-04-09 10:19:04 +0200767 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
Stelian Pop7f09c432007-01-13 23:04:31 +0100768 return -EIO;
769
Mattia Dongili156c2212007-02-12 22:01:07 +0100770 if (item->validate)
771 value = item->validate(SNC_VALIDATE_OUT, value);
772
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100773 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
Stelian Pop7f09c432007-01-13 23:04:31 +0100774}
775
malattia@linux.it59b19102007-04-09 10:19:04 +0200776static ssize_t sony_nc_sysfs_store(struct device *dev,
Len Browna02d1c12007-02-07 15:34:02 -0500777 struct device_attribute *attr,
778 const char *buffer, size_t count)
Stelian Pop7f09c432007-01-13 23:04:31 +0100779{
Stelian Pop7f09c432007-01-13 23:04:31 +0100780 int value;
malattia@linux.it59b19102007-04-09 10:19:04 +0200781 struct sony_nc_value *item =
782 container_of(attr, struct sony_nc_value, devattr);
Stelian Pop7f09c432007-01-13 23:04:31 +0100783
784 if (!item->acpiset)
785 return -EIO;
786
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100787 if (count > 31)
788 return -EINVAL;
789
790 value = simple_strtoul(buffer, NULL, 10);
Stelian Pop7f09c432007-01-13 23:04:31 +0100791
Mattia Dongili156c2212007-02-12 22:01:07 +0100792 if (item->validate)
793 value = item->validate(SNC_VALIDATE_IN, value);
794
795 if (value < 0)
796 return value;
Stelian Pop7f09c432007-01-13 23:04:31 +0100797
malattia@linux.it59b19102007-04-09 10:19:04 +0200798 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
Stelian Pop7f09c432007-01-13 23:04:31 +0100799 return -EIO;
Andrew Morton3f4f4612007-01-13 23:04:32 +0100800 item->value = value;
801 item->valid = 1;
Stelian Pop7f09c432007-01-13 23:04:31 +0100802 return count;
803}
804
Mattia Dongilied3aa4b2007-02-07 20:01:54 +0100805
Mattia Dongilid78865c2007-02-07 20:01:56 +0100806/*
807 * Backlight device
808 */
809static int sony_backlight_update_status(struct backlight_device *bd)
Andrew Morton3f4f4612007-01-13 23:04:32 +0100810{
malattia@linux.it59b19102007-04-09 10:19:04 +0200811 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
Richard Purdie321709c2007-02-10 15:04:08 +0000812 bd->props.brightness + 1, NULL);
Andrew Morton3f4f4612007-01-13 23:04:32 +0100813}
814
Mattia Dongilid78865c2007-02-07 20:01:56 +0100815static int sony_backlight_get_brightness(struct backlight_device *bd)
816{
817 int value;
818
malattia@linux.it59b19102007-04-09 10:19:04 +0200819 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
Mattia Dongilid78865c2007-02-07 20:01:56 +0100820 return 0;
821 /* brightness levels are 1-based, while backlight ones are 0-based */
822 return value - 1;
823}
824
825static struct backlight_device *sony_backlight_device;
Richard Purdie321709c2007-02-10 15:04:08 +0000826static struct backlight_ops sony_backlight_ops = {
Len Browna02d1c12007-02-07 15:34:02 -0500827 .update_status = sony_backlight_update_status,
828 .get_brightness = sony_backlight_get_brightness,
Mattia Dongilid78865c2007-02-07 20:01:56 +0100829};
830
831/*
Mattia Dongili6315fd12007-07-16 02:34:35 +0900832 * New SNC-only Vaios event mapping to driver known keys
833 */
834struct sony_nc_event {
835 u8 data;
836 u8 event;
837};
838
Matthew Garrett9b578962009-03-26 21:58:14 +0900839static struct sony_nc_event sony_nc_events[] = {
840 { 0x90, SONYPI_EVENT_PKEY_P1 },
841 { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED },
842 { 0x91, SONYPI_EVENT_PKEY_P1 },
843 { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED },
Mattia Dongili6315fd12007-07-16 02:34:35 +0900844 { 0x81, SONYPI_EVENT_FNKEY_F1 },
845 { 0x01, SONYPI_EVENT_FNKEY_RELEASED },
846 { 0x85, SONYPI_EVENT_FNKEY_F5 },
847 { 0x05, SONYPI_EVENT_FNKEY_RELEASED },
848 { 0x86, SONYPI_EVENT_FNKEY_F6 },
849 { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
850 { 0x87, SONYPI_EVENT_FNKEY_F7 },
851 { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
Matthew Garrett9b578962009-03-26 21:58:14 +0900852 { 0x89, SONYPI_EVENT_FNKEY_F9 },
853 { 0x09, SONYPI_EVENT_FNKEY_RELEASED },
Mattia Dongili6315fd12007-07-16 02:34:35 +0900854 { 0x8A, SONYPI_EVENT_FNKEY_F10 },
855 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
856 { 0x8C, SONYPI_EVENT_FNKEY_F12 },
857 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
Matthew Garrett9b578962009-03-26 21:58:14 +0900858 { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED },
859 { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED },
Mattia Dongili6315fd12007-07-16 02:34:35 +0900860 { 0, 0 },
861};
862
Mattia Dongili6315fd12007-07-16 02:34:35 +0900863/*
Mattia Dongilid78865c2007-02-07 20:01:56 +0100864 * ACPI callbacks
865 */
Stelian Pop7f09c432007-01-13 23:04:31 +0100866static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
867{
Mattia Dongili6315fd12007-07-16 02:34:35 +0900868 u32 ev = event;
869 int result;
870
Matthew Garrett9b578962009-03-26 21:58:14 +0900871 if (ev >= 0x90) {
872 /* New-style event */
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900873 int origev = ev;
Matthew Garrett9b578962009-03-26 21:58:14 +0900874 ev -= 0x90;
Mattia Dongili6315fd12007-07-16 02:34:35 +0900875
Matthew Garrett9b578962009-03-26 21:58:14 +0900876 if (sony_find_snc_handle(0x100) == ev) {
877 int i;
878
879 if (sony_call_snc_handle(0x100, 0x200, &result))
880 dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev);
881 else
882 ev = result & 0xFF;
883
884 for (i = 0; sony_nc_events[i].event; i++) {
885 if (sony_nc_events[i].data == ev) {
886 ev = sony_nc_events[i].event;
887 break;
888 }
Mattia Dongili6315fd12007-07-16 02:34:35 +0900889 }
Mattia Dongili6315fd12007-07-16 02:34:35 +0900890
Matthew Garrett9b578962009-03-26 21:58:14 +0900891 if (!sony_nc_events[i].data)
892 printk(KERN_INFO DRV_PFX
893 "Unknown event: %x %x\n", origev, ev);
894 }
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900895 }
896
Mattia Dongili6315fd12007-07-16 02:34:35 +0900897 dprintk("sony_acpi_notify, event: 0x%.2x\n", ev);
898 sony_laptop_report_input_event(ev);
Len Brown14e04fb2007-08-23 15:20:26 -0400899 acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev);
Stelian Pop7f09c432007-01-13 23:04:31 +0100900}
901
902static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
903 void *context, void **return_value)
904{
Lin Ming30823732008-12-16 16:59:35 +0800905 struct acpi_device_info *info;
906 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
Stelian Pop7f09c432007-01-13 23:04:31 +0100907
Lin Ming30823732008-12-16 16:59:35 +0800908 if (ACPI_SUCCESS(acpi_get_object_info(handle, &buffer))) {
909 info = buffer.pointer;
Stelian Pop7f09c432007-01-13 23:04:31 +0100910
Lin Ming30823732008-12-16 16:59:35 +0800911 printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n",
912 (char *)&info->name, info->param_count);
913
914 kfree(buffer.pointer);
915 }
Stelian Pop7f09c432007-01-13 23:04:31 +0100916
917 return AE_OK;
918}
919
Mattia Dongilid78865c2007-02-07 20:01:56 +0100920/*
921 * ACPI device
922 */
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900923static int sony_nc_function_setup(struct acpi_device *device)
924{
925 int result;
926
927 /* Enable all events */
928 acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0xffff, &result);
929
930 /* Setup hotkeys */
931 sony_call_snc_handle(0x0100, 0, &result);
932 sony_call_snc_handle(0x0101, 0, &result);
933 sony_call_snc_handle(0x0102, 0x100, &result);
934
935 return 0;
936}
937
malattia@linux.it59b19102007-04-09 10:19:04 +0200938static int sony_nc_resume(struct acpi_device *device)
Mattia Dongilid78865c2007-02-07 20:01:56 +0100939{
malattia@linux.it59b19102007-04-09 10:19:04 +0200940 struct sony_nc_value *item;
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900941 acpi_handle handle;
Mattia Dongilid78865c2007-02-07 20:01:56 +0100942
malattia@linux.it59b19102007-04-09 10:19:04 +0200943 for (item = sony_nc_values; item->name; item++) {
Mattia Dongilid78865c2007-02-07 20:01:56 +0100944 int ret;
945
946 if (!item->valid)
947 continue;
malattia@linux.it59b19102007-04-09 10:19:04 +0200948 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
Len Browna02d1c12007-02-07 15:34:02 -0500949 item->value, NULL);
Mattia Dongilid78865c2007-02-07 20:01:56 +0100950 if (ret < 0) {
Harvey Harrison6e574192008-04-29 00:59:20 -0700951 printk("%s: %d\n", __func__, ret);
Mattia Dongilid78865c2007-02-07 20:01:56 +0100952 break;
953 }
954 }
Mattia Dongili6315fd12007-07-16 02:34:35 +0900955
Matthew Garrett82734bf2009-03-26 21:58:13 +0900956 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
957 &handle))) {
958 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL))
959 dprintk("ECON Method failed\n");
960 }
961
Matthew Garrettbadf26f2009-03-26 21:58:12 +0900962 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
963 &handle))) {
964 dprintk("Doing SNC setup\n");
965 sony_nc_function_setup(device);
966 }
967
Mattia Dongilie84a02b2007-08-04 00:22:30 +0900968 /* set the last requested brightness level */
969 if (sony_backlight_device &&
970 !sony_backlight_update_status(sony_backlight_device))
Adam Jackson0ef9cff2008-10-16 15:15:35 -0400971 printk(KERN_WARNING DRV_PFX "unable to restore brightness level\n");
Mattia Dongilie84a02b2007-08-04 00:22:30 +0900972
Mattia Dongilid78865c2007-02-07 20:01:56 +0100973 return 0;
974}
975
malattia@linux.it59b19102007-04-09 10:19:04 +0200976static int sony_nc_add(struct acpi_device *device)
Stelian Pop7f09c432007-01-13 23:04:31 +0100977{
978 acpi_status status;
Andrew Morton8607c672007-03-06 02:29:42 -0800979 int result = 0;
Alessandro Guido50f62af2007-01-13 23:04:34 +0100980 acpi_handle handle;
malattia@linux.it56b87562007-04-09 10:19:05 +0200981 struct sony_nc_value *item;
Stelian Pop7f09c432007-01-13 23:04:31 +0100982
malattia@linux.itf6119b02007-04-09 19:31:06 +0200983 printk(KERN_INFO DRV_PFX "%s v%s.\n",
984 SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
985
malattia@linux.it59b19102007-04-09 10:19:04 +0200986 sony_nc_acpi_device = device;
malattia@linux.it33a04452007-04-09 19:26:03 +0200987 strcpy(acpi_device_class(device), "sony/hotkey");
Stelian Popc5611622007-01-13 23:04:37 +0100988
malattia@linux.it59b19102007-04-09 10:19:04 +0200989 sony_nc_acpi_handle = device->handle;
Stelian Pop7f09c432007-01-13 23:04:31 +0100990
Mattia Dongilib25b7322007-07-16 02:34:36 +0900991 /* read device status */
992 result = acpi_bus_get_status(device);
993 /* bail IFF the above call was successful and the device is not present */
994 if (!result && !device->status.present) {
995 dprintk("Device not present\n");
996 result = -ENODEV;
997 goto outwalk;
998 }
999
Stelian Pop7f09c432007-01-13 23:04:31 +01001000 if (debug) {
malattia@linux.it59b19102007-04-09 10:19:04 +02001001 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
Stelian Pop7f09c432007-01-13 23:04:31 +01001002 1, sony_walk_callback, NULL, NULL);
1003 if (ACPI_FAILURE(status)) {
malattia@linux.itf6119b02007-04-09 19:31:06 +02001004 printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
Stelian Pop7f09c432007-01-13 23:04:31 +01001005 result = -ENODEV;
1006 goto outwalk;
1007 }
Stelian Popc5611622007-01-13 23:04:37 +01001008 }
Stelian Pop7f09c432007-01-13 23:04:31 +01001009
Mattia Dongilib25b7322007-07-16 02:34:36 +09001010 /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1
1011 * should be respected as we already checked for the device presence above */
1012 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) {
1013 dprintk("Invoking _INI\n");
1014 if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI,
1015 NULL, NULL)))
1016 dprintk("_INI Method failed\n");
1017 }
1018
Matthew Garrett82734bf2009-03-26 21:58:13 +09001019 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
1020 &handle))) {
1021 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL))
1022 dprintk("ECON Method failed\n");
1023 }
1024
Matthew Garrettbadf26f2009-03-26 21:58:12 +09001025 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
1026 &handle))) {
1027 dprintk("Doing SNC setup\n");
1028 sony_nc_function_setup(device);
1029 }
1030
malattia@linux.it1549ee62007-04-09 10:19:08 +02001031 /* setup input devices and helper fifo */
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -05001032 result = sony_laptop_setup_input(device);
malattia@linux.it1549ee62007-04-09 10:19:08 +02001033 if (result) {
1034 printk(KERN_ERR DRV_PFX
1035 "Unabe to create input devices.\n");
1036 goto outwalk;
1037 }
1038
malattia@linux.it59b19102007-04-09 10:19:04 +02001039 status = acpi_install_notify_handler(sony_nc_acpi_handle,
Stelian Popc5611622007-01-13 23:04:37 +01001040 ACPI_DEVICE_NOTIFY,
Len Browna02d1c12007-02-07 15:34:02 -05001041 sony_acpi_notify, NULL);
Stelian Popc5611622007-01-13 23:04:37 +01001042 if (ACPI_FAILURE(status)) {
Mattia Dongilib25b7322007-07-16 02:34:36 +09001043 printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status);
Stelian Popc5611622007-01-13 23:04:37 +01001044 result = -ENODEV;
malattia@linux.it1549ee62007-04-09 10:19:08 +02001045 goto outinput;
Stelian Pop7f09c432007-01-13 23:04:31 +01001046 }
1047
Alessandro Guido38cfc142008-11-12 23:03:28 +01001048 if (acpi_video_backlight_support()) {
Alessandro Guido3fedd902008-11-12 23:13:35 +01001049 printk(KERN_INFO DRV_PFX "brightness ignored, must be "
Thomas Renninger540b8bb2008-08-01 17:38:02 +02001050 "controlled by ACPI video driver\n");
1051 } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT",
1052 &handle))) {
Alessandro Guido50f62af2007-01-13 23:04:34 +01001053 sony_backlight_device = backlight_device_register("sony", NULL,
Len Browna02d1c12007-02-07 15:34:02 -05001054 NULL,
Richard Purdie321709c2007-02-10 15:04:08 +00001055 &sony_backlight_ops);
Mattia Dongili7df03b82007-01-13 23:04:41 +01001056
Len Browna02d1c12007-02-07 15:34:02 -05001057 if (IS_ERR(sony_backlight_device)) {
malattia@linux.itf6119b02007-04-09 19:31:06 +02001058 printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
Mattia Dongili7df03b82007-01-13 23:04:41 +01001059 sony_backlight_device = NULL;
Richard Purdie321709c2007-02-10 15:04:08 +00001060 } else {
1061 sony_backlight_device->props.brightness =
Len Browna02d1c12007-02-07 15:34:02 -05001062 sony_backlight_get_brightness
1063 (sony_backlight_device);
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -05001064 sony_backlight_device->props.max_brightness =
Richard Purdie321709c2007-02-10 15:04:08 +00001065 SONY_MAX_BRIGHTNESS - 1;
1066 }
1067
Alessandro Guido50f62af2007-01-13 23:04:34 +01001068 }
Stelian Pop7f09c432007-01-13 23:04:31 +01001069
malattia@linux.it49a11de2007-04-09 19:28:56 +02001070 result = sony_pf_add();
1071 if (result)
Mattia Dongilied3aa4b2007-02-07 20:01:54 +01001072 goto outbacklight;
Stelian Pop7f09c432007-01-13 23:04:31 +01001073
malattia@linux.it56b87562007-04-09 10:19:05 +02001074 /* create sony_pf sysfs attributes related to the SNC device */
1075 for (item = sony_nc_values; item->name; ++item) {
1076
1077 if (!debug && item->debug)
1078 continue;
1079
1080 /* find the available acpiget as described in the DSDT */
1081 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
1082 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1083 *item->acpiget,
1084 &handle))) {
malattia@linux.itb9a218b2007-04-09 10:19:06 +02001085 dprintk("Found %s getter: %s\n",
1086 item->name, *item->acpiget);
malattia@linux.it56b87562007-04-09 10:19:05 +02001087 item->devattr.attr.mode |= S_IRUGO;
1088 break;
1089 }
1090 }
1091
1092 /* find the available acpiset as described in the DSDT */
1093 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
1094 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
1095 *item->acpiset,
1096 &handle))) {
malattia@linux.itb9a218b2007-04-09 10:19:06 +02001097 dprintk("Found %s setter: %s\n",
1098 item->name, *item->acpiset);
malattia@linux.it56b87562007-04-09 10:19:05 +02001099 item->devattr.attr.mode |= S_IWUSR;
1100 break;
1101 }
1102 }
1103
1104 if (item->devattr.attr.mode != 0) {
1105 result =
1106 device_create_file(&sony_pf_device->dev,
1107 &item->devattr);
1108 if (result)
1109 goto out_sysfs;
1110 }
1111 }
1112
Stelian Pop7f09c432007-01-13 23:04:31 +01001113 return 0;
1114
malattia@linux.it56b87562007-04-09 10:19:05 +02001115 out_sysfs:
1116 for (item = sony_nc_values; item->name; ++item) {
1117 device_remove_file(&sony_pf_device->dev, &item->devattr);
1118 }
1119 sony_pf_remove();
malattia@linux.it1549ee62007-04-09 10:19:08 +02001120
Len Browna02d1c12007-02-07 15:34:02 -05001121 outbacklight:
Mattia Dongili7df03b82007-01-13 23:04:41 +01001122 if (sony_backlight_device)
1123 backlight_device_unregister(sony_backlight_device);
1124
malattia@linux.it59b19102007-04-09 10:19:04 +02001125 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
Stelian Popc5611622007-01-13 23:04:37 +01001126 ACPI_DEVICE_NOTIFY,
1127 sony_acpi_notify);
1128 if (ACPI_FAILURE(status))
malattia@linux.itf6119b02007-04-09 19:31:06 +02001129 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
malattia@linux.it1549ee62007-04-09 10:19:08 +02001130
1131 outinput:
1132 sony_laptop_remove_input();
1133
Len Browna02d1c12007-02-07 15:34:02 -05001134 outwalk:
Stelian Pop7f09c432007-01-13 23:04:31 +01001135 return result;
1136}
1137
malattia@linux.it59b19102007-04-09 10:19:04 +02001138static int sony_nc_remove(struct acpi_device *device, int type)
Stelian Pop7f09c432007-01-13 23:04:31 +01001139{
1140 acpi_status status;
malattia@linux.it56b87562007-04-09 10:19:05 +02001141 struct sony_nc_value *item;
Stelian Pop7f09c432007-01-13 23:04:31 +01001142
Alessandro Guido50f62af2007-01-13 23:04:34 +01001143 if (sony_backlight_device)
1144 backlight_device_unregister(sony_backlight_device);
1145
malattia@linux.it59b19102007-04-09 10:19:04 +02001146 sony_nc_acpi_device = NULL;
Stelian Popc5611622007-01-13 23:04:37 +01001147
malattia@linux.it59b19102007-04-09 10:19:04 +02001148 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
Stelian Popc5611622007-01-13 23:04:37 +01001149 ACPI_DEVICE_NOTIFY,
1150 sony_acpi_notify);
1151 if (ACPI_FAILURE(status))
malattia@linux.itf6119b02007-04-09 19:31:06 +02001152 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
Stelian Pop7f09c432007-01-13 23:04:31 +01001153
malattia@linux.it56b87562007-04-09 10:19:05 +02001154 for (item = sony_nc_values; item->name; ++item) {
1155 device_remove_file(&sony_pf_device->dev, &item->devattr);
1156 }
1157
1158 sony_pf_remove();
malattia@linux.it1549ee62007-04-09 10:19:08 +02001159 sony_laptop_remove_input();
malattia@linux.itf6119b02007-04-09 19:31:06 +02001160 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
Stelian Pop7f09c432007-01-13 23:04:31 +01001161
1162 return 0;
1163}
1164
Thomas Renninger1ba90e32007-07-23 14:44:41 +02001165static const struct acpi_device_id sony_device_ids[] = {
1166 {SONY_NC_HID, 0},
1167 {SONY_PIC_HID, 0},
1168 {"", 0},
1169};
1170MODULE_DEVICE_TABLE(acpi, sony_device_ids);
1171
1172static const struct acpi_device_id sony_nc_device_ids[] = {
1173 {SONY_NC_HID, 0},
1174 {"", 0},
1175};
1176
malattia@linux.it59b19102007-04-09 10:19:04 +02001177static struct acpi_driver sony_nc_driver = {
1178 .name = SONY_NC_DRIVER_NAME,
1179 .class = SONY_NC_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +02001180 .ids = sony_nc_device_ids,
malattia@linux.it33a04452007-04-09 19:26:03 +02001181 .owner = THIS_MODULE,
Len Browna02d1c12007-02-07 15:34:02 -05001182 .ops = {
malattia@linux.it59b19102007-04-09 10:19:04 +02001183 .add = sony_nc_add,
1184 .remove = sony_nc_remove,
1185 .resume = sony_nc_resume,
Len Browna02d1c12007-02-07 15:34:02 -05001186 },
Andrew Morton3f4f4612007-01-13 23:04:32 +01001187};
1188
malattia@linux.it33a04452007-04-09 19:26:03 +02001189/*********** SPIC (SNY6001) Device ***********/
1190
1191#define SONYPI_DEVICE_TYPE1 0x00000001
1192#define SONYPI_DEVICE_TYPE2 0x00000002
1193#define SONYPI_DEVICE_TYPE3 0x00000004
Mattia Dongili3eb87492008-01-14 18:05:45 +09001194#define SONYPI_DEVICE_TYPE4 0x00000008
malattia@linux.it33a04452007-04-09 19:26:03 +02001195
Mattia Dongili22a17782007-07-16 02:34:39 +09001196#define SONYPI_TYPE1_OFFSET 0x04
1197#define SONYPI_TYPE2_OFFSET 0x12
1198#define SONYPI_TYPE3_OFFSET 0x12
Mattia Dongili3eb87492008-01-14 18:05:45 +09001199#define SONYPI_TYPE4_OFFSET 0x12
malattia@linux.it33a04452007-04-09 19:26:03 +02001200
malattia@linux.it33a04452007-04-09 19:26:03 +02001201struct sony_pic_ioport {
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001202 struct acpi_resource_io io1;
1203 struct acpi_resource_io io2;
malattia@linux.it33a04452007-04-09 19:26:03 +02001204 struct list_head list;
1205};
1206
1207struct sony_pic_irq {
1208 struct acpi_resource_irq irq;
1209 struct list_head list;
1210};
1211
Mattia Dongilide920432008-01-14 18:05:43 +09001212struct sonypi_eventtypes {
1213 u8 data;
1214 unsigned long mask;
1215 struct sonypi_event *events;
1216};
1217
1218struct device_ctrl {
1219 int model;
Mattia Dongili3eb87492008-01-14 18:05:45 +09001220 int (*handle_irq)(const u8, const u8);
Mattia Dongilide920432008-01-14 18:05:43 +09001221 u16 evport_offset;
1222 u8 has_camera;
1223 u8 has_bluetooth;
1224 u8 has_wwan;
1225 struct sonypi_eventtypes *event_types;
1226};
1227
malattia@linux.it33a04452007-04-09 19:26:03 +02001228struct sony_pic_dev {
Mattia Dongilide920432008-01-14 18:05:43 +09001229 struct device_ctrl *control;
malattia@linux.it33a04452007-04-09 19:26:03 +02001230 struct acpi_device *acpi_dev;
1231 struct sony_pic_irq *cur_irq;
1232 struct sony_pic_ioport *cur_ioport;
1233 struct list_head interrupts;
1234 struct list_head ioports;
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001235 struct mutex lock;
Mattia Dongilide920432008-01-14 18:05:43 +09001236 u8 camera_power;
1237 u8 bluetooth_power;
1238 u8 wwan_power;
malattia@linux.it33a04452007-04-09 19:26:03 +02001239};
1240
1241static struct sony_pic_dev spic_dev = {
1242 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
1243 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
1244};
1245
1246/* Event masks */
1247#define SONYPI_JOGGER_MASK 0x00000001
1248#define SONYPI_CAPTURE_MASK 0x00000002
1249#define SONYPI_FNKEY_MASK 0x00000004
1250#define SONYPI_BLUETOOTH_MASK 0x00000008
1251#define SONYPI_PKEY_MASK 0x00000010
1252#define SONYPI_BACK_MASK 0x00000020
1253#define SONYPI_HELP_MASK 0x00000040
1254#define SONYPI_LID_MASK 0x00000080
1255#define SONYPI_ZOOM_MASK 0x00000100
1256#define SONYPI_THUMBPHRASE_MASK 0x00000200
1257#define SONYPI_MEYE_MASK 0x00000400
1258#define SONYPI_MEMORYSTICK_MASK 0x00000800
1259#define SONYPI_BATTERY_MASK 0x00001000
1260#define SONYPI_WIRELESS_MASK 0x00002000
1261
1262struct sonypi_event {
1263 u8 data;
1264 u8 event;
1265};
1266
1267/* The set of possible button release events */
1268static struct sonypi_event sonypi_releaseev[] = {
1269 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
1270 { 0, 0 }
1271};
1272
1273/* The set of possible jogger events */
1274static struct sonypi_event sonypi_joggerev[] = {
1275 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
1276 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
1277 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
1278 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
1279 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
1280 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
1281 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
1282 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
1283 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
1284 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
1285 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
1286 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
1287 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
1288 { 0, 0 }
1289};
1290
1291/* The set of possible capture button events */
1292static struct sonypi_event sonypi_captureev[] = {
1293 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
1294 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
Mattia Dongili3eb87492008-01-14 18:05:45 +09001295 { 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
malattia@linux.it33a04452007-04-09 19:26:03 +02001296 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
1297 { 0, 0 }
1298};
1299
1300/* The set of possible fnkeys events */
1301static struct sonypi_event sonypi_fnkeyev[] = {
1302 { 0x10, SONYPI_EVENT_FNKEY_ESC },
1303 { 0x11, SONYPI_EVENT_FNKEY_F1 },
1304 { 0x12, SONYPI_EVENT_FNKEY_F2 },
1305 { 0x13, SONYPI_EVENT_FNKEY_F3 },
1306 { 0x14, SONYPI_EVENT_FNKEY_F4 },
1307 { 0x15, SONYPI_EVENT_FNKEY_F5 },
1308 { 0x16, SONYPI_EVENT_FNKEY_F6 },
1309 { 0x17, SONYPI_EVENT_FNKEY_F7 },
1310 { 0x18, SONYPI_EVENT_FNKEY_F8 },
1311 { 0x19, SONYPI_EVENT_FNKEY_F9 },
1312 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
1313 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
1314 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
1315 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
1316 { 0x21, SONYPI_EVENT_FNKEY_1 },
1317 { 0x22, SONYPI_EVENT_FNKEY_2 },
1318 { 0x31, SONYPI_EVENT_FNKEY_D },
1319 { 0x32, SONYPI_EVENT_FNKEY_E },
1320 { 0x33, SONYPI_EVENT_FNKEY_F },
1321 { 0x34, SONYPI_EVENT_FNKEY_S },
1322 { 0x35, SONYPI_EVENT_FNKEY_B },
1323 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
1324 { 0, 0 }
1325};
1326
1327/* The set of possible program key events */
1328static struct sonypi_event sonypi_pkeyev[] = {
1329 { 0x01, SONYPI_EVENT_PKEY_P1 },
1330 { 0x02, SONYPI_EVENT_PKEY_P2 },
1331 { 0x04, SONYPI_EVENT_PKEY_P3 },
malattia@linux.it33a04452007-04-09 19:26:03 +02001332 { 0, 0 }
1333};
1334
1335/* The set of possible bluetooth events */
1336static struct sonypi_event sonypi_blueev[] = {
1337 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
1338 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
1339 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
1340 { 0, 0 }
1341};
1342
1343/* The set of possible wireless events */
1344static struct sonypi_event sonypi_wlessev[] = {
1345 { 0x59, SONYPI_EVENT_WIRELESS_ON },
1346 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
1347 { 0, 0 }
1348};
1349
1350/* The set of possible back button events */
1351static struct sonypi_event sonypi_backev[] = {
1352 { 0x20, SONYPI_EVENT_BACK_PRESSED },
1353 { 0, 0 }
1354};
1355
1356/* The set of possible help button events */
1357static struct sonypi_event sonypi_helpev[] = {
1358 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
1359 { 0, 0 }
1360};
1361
1362
1363/* The set of possible lid events */
1364static struct sonypi_event sonypi_lidev[] = {
1365 { 0x51, SONYPI_EVENT_LID_CLOSED },
1366 { 0x50, SONYPI_EVENT_LID_OPENED },
1367 { 0, 0 }
1368};
1369
1370/* The set of possible zoom events */
1371static struct sonypi_event sonypi_zoomev[] = {
1372 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
Mattia Dongili3eb87492008-01-14 18:05:45 +09001373 { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
1374 { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
malattia@linux.it33a04452007-04-09 19:26:03 +02001375 { 0, 0 }
1376};
1377
1378/* The set of possible thumbphrase events */
1379static struct sonypi_event sonypi_thumbphraseev[] = {
1380 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
1381 { 0, 0 }
1382};
1383
1384/* The set of possible motioneye camera events */
1385static struct sonypi_event sonypi_meyeev[] = {
1386 { 0x00, SONYPI_EVENT_MEYE_FACE },
1387 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
1388 { 0, 0 }
1389};
1390
1391/* The set of possible memorystick events */
1392static struct sonypi_event sonypi_memorystickev[] = {
1393 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
1394 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
1395 { 0, 0 }
1396};
1397
1398/* The set of possible battery events */
1399static struct sonypi_event sonypi_batteryev[] = {
1400 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
1401 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
1402 { 0, 0 }
1403};
1404
Mattia Dongilide920432008-01-14 18:05:43 +09001405static struct sonypi_eventtypes type1_events[] = {
1406 { 0, 0xffffffff, sonypi_releaseev },
1407 { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
1408 { 0x30, SONYPI_LID_MASK, sonypi_lidev },
1409 { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
1410 { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
1411 { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1412 { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1413 { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
1414 { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1415 { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
1416 { 0 },
1417};
1418static struct sonypi_eventtypes type2_events[] = {
1419 { 0, 0xffffffff, sonypi_releaseev },
1420 { 0x38, SONYPI_LID_MASK, sonypi_lidev },
1421 { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
1422 { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
1423 { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1424 { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1425 { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
1426 { 0x11, SONYPI_BACK_MASK, sonypi_backev },
1427 { 0x21, SONYPI_HELP_MASK, sonypi_helpev },
1428 { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
1429 { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
1430 { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1431 { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1432 { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1433 { 0 },
1434};
1435static struct sonypi_eventtypes type3_events[] = {
1436 { 0, 0xffffffff, sonypi_releaseev },
1437 { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1438 { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
1439 { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1440 { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1441 { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1442 { 0 },
malattia@linux.it33a04452007-04-09 19:26:03 +02001443};
Mattia Dongili3eb87492008-01-14 18:05:45 +09001444static struct sonypi_eventtypes type4_events[] = {
1445 { 0, 0xffffffff, sonypi_releaseev },
1446 { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1447 { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
1448 { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1449 { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1450 { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
1451 { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
1452 { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
1453 { 0 },
Mattia Dongilide920432008-01-14 18:05:43 +09001454};
1455
Mattia Dongili3eb87492008-01-14 18:05:45 +09001456/* low level spic calls */
malattia@linux.it33a04452007-04-09 19:26:03 +02001457#define ITERATIONS_LONG 10000
1458#define ITERATIONS_SHORT 10
1459#define wait_on_command(command, iterations) { \
1460 unsigned int n = iterations; \
1461 while (--n && (command)) \
1462 udelay(1); \
1463 if (!n) \
1464 dprintk("command failed at %s : %s (line %d)\n", \
Harvey Harrison6e574192008-04-29 00:59:20 -07001465 __FILE__, __func__, __LINE__); \
malattia@linux.it33a04452007-04-09 19:26:03 +02001466}
1467
1468static u8 sony_pic_call1(u8 dev)
1469{
1470 u8 v1, v2;
1471
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001472 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
malattia@linux.it33a04452007-04-09 19:26:03 +02001473 ITERATIONS_LONG);
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001474 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
1475 v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
1476 v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
Mattia Dongili75a1f9c2008-01-14 18:05:41 +09001477 dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
malattia@linux.it33a04452007-04-09 19:26:03 +02001478 return v2;
1479}
1480
1481static u8 sony_pic_call2(u8 dev, u8 fn)
1482{
1483 u8 v1;
1484
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001485 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
malattia@linux.it33a04452007-04-09 19:26:03 +02001486 ITERATIONS_LONG);
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001487 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
1488 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
malattia@linux.it33a04452007-04-09 19:26:03 +02001489 ITERATIONS_LONG);
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001490 outb(fn, spic_dev.cur_ioport->io1.minimum);
1491 v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
Mattia Dongili75a1f9c2008-01-14 18:05:41 +09001492 dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
malattia@linux.it33a04452007-04-09 19:26:03 +02001493 return v1;
1494}
1495
malattia@linux.it49a11de2007-04-09 19:28:56 +02001496static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
1497{
1498 u8 v1;
1499
Mattia Dongilifd1caae2007-08-12 16:20:28 +09001500 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
1501 outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
1502 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
1503 outb(fn, spic_dev.cur_ioport->io1.minimum);
1504 wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
1505 outb(v, spic_dev.cur_ioport->io1.minimum);
1506 v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
Mattia Dongili75a1f9c2008-01-14 18:05:41 +09001507 dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
1508 dev, fn, v, v1);
malattia@linux.it49a11de2007-04-09 19:28:56 +02001509 return v1;
1510}
1511
Mattia Dongili3eb87492008-01-14 18:05:45 +09001512/*
1513 * minidrivers for SPIC models
1514 */
1515static int type4_handle_irq(const u8 data_mask, const u8 ev)
1516{
1517 /*
1518 * 0x31 could mean we have to take some extra action and wait for
1519 * the next irq for some Type4 models, it will generate a new
1520 * irq and we can read new data from the device:
1521 * - 0x5c and 0x5f requires 0xA0
1522 * - 0x61 requires 0xB3
1523 */
1524 if (data_mask == 0x31) {
1525 if (ev == 0x5c || ev == 0x5f)
1526 sony_pic_call1(0xA0);
1527 else if (ev == 0x61)
1528 sony_pic_call1(0xB3);
1529 return 0;
1530 }
1531 return 1;
1532}
1533
1534static struct device_ctrl spic_types[] = {
1535 {
1536 .model = SONYPI_DEVICE_TYPE1,
1537 .handle_irq = NULL,
1538 .evport_offset = SONYPI_TYPE1_OFFSET,
1539 .event_types = type1_events,
1540 },
1541 {
1542 .model = SONYPI_DEVICE_TYPE2,
1543 .handle_irq = NULL,
1544 .evport_offset = SONYPI_TYPE2_OFFSET,
1545 .event_types = type2_events,
1546 },
1547 {
1548 .model = SONYPI_DEVICE_TYPE3,
1549 .handle_irq = NULL,
1550 .evport_offset = SONYPI_TYPE3_OFFSET,
1551 .event_types = type3_events,
1552 },
1553 {
1554 .model = SONYPI_DEVICE_TYPE4,
1555 .handle_irq = type4_handle_irq,
1556 .evport_offset = SONYPI_TYPE4_OFFSET,
1557 .event_types = type4_events,
1558 },
1559};
1560
1561static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
1562{
1563 struct pci_dev *pcidev;
1564
1565 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1566 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
1567 if (pcidev) {
1568 dev->control = &spic_types[0];
1569 goto out;
1570 }
1571
1572 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1573 PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
1574 if (pcidev) {
1575 dev->control = &spic_types[2];
1576 goto out;
1577 }
1578
1579 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1580 PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
1581 if (pcidev) {
1582 dev->control = &spic_types[3];
1583 goto out;
1584 }
1585
1586 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1587 PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
1588 if (pcidev) {
1589 dev->control = &spic_types[3];
1590 goto out;
1591 }
1592
1593 /* default */
1594 dev->control = &spic_types[1];
1595
1596out:
1597 if (pcidev)
1598 pci_dev_put(pcidev);
1599
1600 printk(KERN_INFO DRV_PFX "detected Type%d model\n",
1601 dev->control->model == SONYPI_DEVICE_TYPE1 ? 1 :
1602 dev->control->model == SONYPI_DEVICE_TYPE2 ? 2 :
1603 dev->control->model == SONYPI_DEVICE_TYPE3 ? 3 : 4);
1604}
1605
malattia@linux.it49a11de2007-04-09 19:28:56 +02001606/* camera tests and poweron/poweroff */
1607#define SONYPI_CAMERA_PICTURE 5
malattia@linux.it49a11de2007-04-09 19:28:56 +02001608#define SONYPI_CAMERA_CONTROL 0x10
malattia@linux.ite3646322007-04-28 23:34:22 +09001609
1610#define SONYPI_CAMERA_BRIGHTNESS 0
1611#define SONYPI_CAMERA_CONTRAST 1
1612#define SONYPI_CAMERA_HUE 2
1613#define SONYPI_CAMERA_COLOR 3
1614#define SONYPI_CAMERA_SHARPNESS 4
1615
1616#define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1617#define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1618#define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1619#define SONYPI_CAMERA_MUTE_MASK 0x40
1620
1621/* the rest don't need a loop until not 0xff */
1622#define SONYPI_CAMERA_AGC 6
1623#define SONYPI_CAMERA_AGC_MASK 0x30
1624#define SONYPI_CAMERA_SHUTTER_MASK 0x7
1625
1626#define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1627#define SONYPI_CAMERA_CONTROL 0x10
1628
1629#define SONYPI_CAMERA_STATUS 7
1630#define SONYPI_CAMERA_STATUS_READY 0x2
1631#define SONYPI_CAMERA_STATUS_POSITION 0x4
1632
1633#define SONYPI_DIRECTION_BACKWARDS 0x4
1634
1635#define SONYPI_CAMERA_REVISION 8
1636#define SONYPI_CAMERA_ROMVERSION 9
malattia@linux.it49a11de2007-04-09 19:28:56 +02001637
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001638static int __sony_pic_camera_ready(void)
malattia@linux.it49a11de2007-04-09 19:28:56 +02001639{
1640 u8 v;
1641
1642 v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
1643 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
1644}
1645
malattia@linux.ite3646322007-04-28 23:34:22 +09001646static int __sony_pic_camera_off(void)
malattia@linux.it49a11de2007-04-09 19:28:56 +02001647{
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001648 if (!camera) {
1649 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1650 return -ENODEV;
1651 }
1652
malattia@linux.it49a11de2007-04-09 19:28:56 +02001653 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
1654 SONYPI_CAMERA_MUTE_MASK),
1655 ITERATIONS_SHORT);
1656
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001657 if (spic_dev.camera_power) {
1658 sony_pic_call2(0x91, 0);
1659 spic_dev.camera_power = 0;
1660 }
1661 return 0;
malattia@linux.it49a11de2007-04-09 19:28:56 +02001662}
1663
malattia@linux.ite3646322007-04-28 23:34:22 +09001664static int __sony_pic_camera_on(void)
malattia@linux.it49a11de2007-04-09 19:28:56 +02001665{
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001666 int i, j, x;
1667
1668 if (!camera) {
1669 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1670 return -ENODEV;
1671 }
malattia@linux.it49a11de2007-04-09 19:28:56 +02001672
1673 if (spic_dev.camera_power)
malattia@linux.ite3646322007-04-28 23:34:22 +09001674 return 0;
malattia@linux.it49a11de2007-04-09 19:28:56 +02001675
1676 for (j = 5; j > 0; j--) {
1677
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001678 for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
malattia@linux.it49a11de2007-04-09 19:28:56 +02001679 msleep(10);
1680 sony_pic_call1(0x93);
1681
1682 for (i = 400; i > 0; i--) {
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001683 if (__sony_pic_camera_ready())
malattia@linux.it49a11de2007-04-09 19:28:56 +02001684 break;
1685 msleep(10);
1686 }
1687 if (i)
1688 break;
1689 }
1690
1691 if (j == 0) {
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001692 printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
malattia@linux.ite3646322007-04-28 23:34:22 +09001693 return -ENODEV;
malattia@linux.it49a11de2007-04-09 19:28:56 +02001694 }
1695
1696 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
1697 0x5a),
1698 ITERATIONS_SHORT);
1699
1700 spic_dev.camera_power = 1;
malattia@linux.it5f3d2892007-04-28 23:18:45 +09001701 return 0;
malattia@linux.it49a11de2007-04-09 19:28:56 +02001702}
1703
malattia@linux.ite3646322007-04-28 23:34:22 +09001704/* External camera command (exported to the motion eye v4l driver) */
1705int sony_pic_camera_command(int command, u8 value)
1706{
1707 if (!camera)
1708 return -EIO;
1709
1710 mutex_lock(&spic_dev.lock);
1711
1712 switch (command) {
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001713 case SONY_PIC_COMMAND_SETCAMERA:
malattia@linux.ite3646322007-04-28 23:34:22 +09001714 if (value)
1715 __sony_pic_camera_on();
1716 else
1717 __sony_pic_camera_off();
1718 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001719 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
malattia@linux.ite3646322007-04-28 23:34:22 +09001720 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
1721 ITERATIONS_SHORT);
1722 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001723 case SONY_PIC_COMMAND_SETCAMERACONTRAST:
malattia@linux.ite3646322007-04-28 23:34:22 +09001724 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
1725 ITERATIONS_SHORT);
1726 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001727 case SONY_PIC_COMMAND_SETCAMERAHUE:
malattia@linux.ite3646322007-04-28 23:34:22 +09001728 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
1729 ITERATIONS_SHORT);
1730 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001731 case SONY_PIC_COMMAND_SETCAMERACOLOR:
malattia@linux.ite3646322007-04-28 23:34:22 +09001732 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
1733 ITERATIONS_SHORT);
1734 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001735 case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
malattia@linux.ite3646322007-04-28 23:34:22 +09001736 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
1737 ITERATIONS_SHORT);
1738 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001739 case SONY_PIC_COMMAND_SETCAMERAPICTURE:
malattia@linux.ite3646322007-04-28 23:34:22 +09001740 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
1741 ITERATIONS_SHORT);
1742 break;
malattia@linux.it1ce82c12007-04-28 23:34:36 +09001743 case SONY_PIC_COMMAND_SETCAMERAAGC:
malattia@linux.ite3646322007-04-28 23:34:22 +09001744 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
1745 ITERATIONS_SHORT);
1746 break;
1747 default:
1748 printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
1749 command);
1750 break;
1751 }
1752 mutex_unlock(&spic_dev.lock);
1753 return 0;
1754}
1755EXPORT_SYMBOL(sony_pic_camera_command);
1756
malattia@linux.it9476cdf2007-04-28 23:21:42 +09001757/* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
1758static void sony_pic_set_wwanpower(u8 state)
1759{
1760 state = !!state;
1761 mutex_lock(&spic_dev.lock);
1762 if (spic_dev.wwan_power == state) {
1763 mutex_unlock(&spic_dev.lock);
1764 return;
1765 }
1766 sony_pic_call2(0xB0, state);
1767 spic_dev.wwan_power = state;
1768 mutex_unlock(&spic_dev.lock);
1769}
1770
1771static ssize_t sony_pic_wwanpower_store(struct device *dev,
1772 struct device_attribute *attr,
1773 const char *buffer, size_t count)
1774{
1775 unsigned long value;
1776 if (count > 31)
1777 return -EINVAL;
1778
1779 value = simple_strtoul(buffer, NULL, 10);
1780 sony_pic_set_wwanpower(value);
1781
1782 return count;
1783}
1784
1785static ssize_t sony_pic_wwanpower_show(struct device *dev,
1786 struct device_attribute *attr, char *buffer)
1787{
1788 ssize_t count;
1789 mutex_lock(&spic_dev.lock);
1790 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
1791 mutex_unlock(&spic_dev.lock);
1792 return count;
1793}
1794
malattia@linux.it49a11de2007-04-09 19:28:56 +02001795/* bluetooth subsystem power state */
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001796static void __sony_pic_set_bluetoothpower(u8 state)
malattia@linux.it49a11de2007-04-09 19:28:56 +02001797{
1798 state = !!state;
1799 if (spic_dev.bluetooth_power == state)
1800 return;
1801 sony_pic_call2(0x96, state);
1802 sony_pic_call1(0x82);
1803 spic_dev.bluetooth_power = state;
1804}
1805
1806static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
1807 struct device_attribute *attr,
1808 const char *buffer, size_t count)
1809{
1810 unsigned long value;
1811 if (count > 31)
1812 return -EINVAL;
1813
1814 value = simple_strtoul(buffer, NULL, 10);
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001815 mutex_lock(&spic_dev.lock);
1816 __sony_pic_set_bluetoothpower(value);
1817 mutex_unlock(&spic_dev.lock);
malattia@linux.it49a11de2007-04-09 19:28:56 +02001818
1819 return count;
1820}
1821
1822static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
1823 struct device_attribute *attr, char *buffer)
1824{
malattia@linux.it9f9f0762007-04-28 23:19:36 +09001825 ssize_t count = 0;
1826 mutex_lock(&spic_dev.lock);
1827 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
1828 mutex_unlock(&spic_dev.lock);
1829 return count;
malattia@linux.it49a11de2007-04-09 19:28:56 +02001830}
1831
1832/* fan speed */
1833/* FAN0 information (reverse engineered from ACPI tables) */
1834#define SONY_PIC_FAN0_STATUS 0x93
malattia@linux.it7b153f32007-04-09 19:31:25 +02001835static int sony_pic_set_fanspeed(unsigned long value)
1836{
1837 return ec_write(SONY_PIC_FAN0_STATUS, value);
1838}
1839
1840static int sony_pic_get_fanspeed(u8 *value)
1841{
1842 return ec_read(SONY_PIC_FAN0_STATUS, value);
1843}
1844
malattia@linux.it49a11de2007-04-09 19:28:56 +02001845static ssize_t sony_pic_fanspeed_store(struct device *dev,
1846 struct device_attribute *attr,
1847 const char *buffer, size_t count)
1848{
1849 unsigned long value;
1850 if (count > 31)
1851 return -EINVAL;
1852
1853 value = simple_strtoul(buffer, NULL, 10);
malattia@linux.it7b153f32007-04-09 19:31:25 +02001854 if (sony_pic_set_fanspeed(value))
malattia@linux.it49a11de2007-04-09 19:28:56 +02001855 return -EIO;
1856
1857 return count;
1858}
1859
1860static ssize_t sony_pic_fanspeed_show(struct device *dev,
1861 struct device_attribute *attr, char *buffer)
1862{
1863 u8 value = 0;
malattia@linux.it7b153f32007-04-09 19:31:25 +02001864 if (sony_pic_get_fanspeed(&value))
malattia@linux.it49a11de2007-04-09 19:28:56 +02001865 return -EIO;
1866
1867 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
1868}
1869
1870#define SPIC_ATTR(_name, _mode) \
1871struct device_attribute spic_attr_##_name = __ATTR(_name, \
1872 _mode, sony_pic_## _name ##_show, \
1873 sony_pic_## _name ##_store)
1874
malattia@linux.it49a11de2007-04-09 19:28:56 +02001875static SPIC_ATTR(bluetoothpower, 0644);
malattia@linux.it9476cdf2007-04-28 23:21:42 +09001876static SPIC_ATTR(wwanpower, 0644);
malattia@linux.it49a11de2007-04-09 19:28:56 +02001877static SPIC_ATTR(fanspeed, 0644);
1878
1879static struct attribute *spic_attributes[] = {
malattia@linux.it49a11de2007-04-09 19:28:56 +02001880 &spic_attr_bluetoothpower.attr,
malattia@linux.it9476cdf2007-04-28 23:21:42 +09001881 &spic_attr_wwanpower.attr,
malattia@linux.it49a11de2007-04-09 19:28:56 +02001882 &spic_attr_fanspeed.attr,
1883 NULL
1884};
1885
1886static struct attribute_group spic_attribute_group = {
1887 .attrs = spic_attributes
1888};
1889
malattia@linux.it7b153f32007-04-09 19:31:25 +02001890/******** SONYPI compatibility **********/
Mattia Dongilia64e62a2007-05-01 11:19:53 +09001891#ifdef CONFIG_SONYPI_COMPAT
malattia@linux.it7b153f32007-04-09 19:31:25 +02001892
1893/* battery / brightness / temperature addresses */
1894#define SONYPI_BAT_FLAGS 0x81
1895#define SONYPI_LCD_LIGHT 0x96
1896#define SONYPI_BAT1_PCTRM 0xa0
1897#define SONYPI_BAT1_LEFT 0xa2
1898#define SONYPI_BAT1_MAXRT 0xa4
1899#define SONYPI_BAT2_PCTRM 0xa8
1900#define SONYPI_BAT2_LEFT 0xaa
1901#define SONYPI_BAT2_MAXRT 0xac
1902#define SONYPI_BAT1_MAXTK 0xb0
1903#define SONYPI_BAT1_FULL 0xb2
1904#define SONYPI_BAT2_MAXTK 0xb8
1905#define SONYPI_BAT2_FULL 0xba
1906#define SONYPI_TEMP_STATUS 0xC1
1907
1908struct sonypi_compat_s {
1909 struct fasync_struct *fifo_async;
1910 struct kfifo *fifo;
1911 spinlock_t fifo_lock;
1912 wait_queue_head_t fifo_proc_list;
1913 atomic_t open_count;
1914};
1915static struct sonypi_compat_s sonypi_compat = {
1916 .open_count = ATOMIC_INIT(0),
1917};
1918
1919static int sonypi_misc_fasync(int fd, struct file *filp, int on)
1920{
1921 int retval;
1922
1923 retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
1924 if (retval < 0)
1925 return retval;
1926 return 0;
1927}
1928
1929static int sonypi_misc_release(struct inode *inode, struct file *file)
1930{
malattia@linux.it7b153f32007-04-09 19:31:25 +02001931 atomic_dec(&sonypi_compat.open_count);
1932 return 0;
1933}
1934
1935static int sonypi_misc_open(struct inode *inode, struct file *file)
1936{
1937 /* Flush input queue on first open */
Arnd Bergmann0410e682008-05-20 19:16:45 +02001938 lock_kernel();
malattia@linux.it7b153f32007-04-09 19:31:25 +02001939 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
1940 kfifo_reset(sonypi_compat.fifo);
Arnd Bergmann0410e682008-05-20 19:16:45 +02001941 unlock_kernel();
malattia@linux.it7b153f32007-04-09 19:31:25 +02001942 return 0;
1943}
1944
1945static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
1946 size_t count, loff_t *pos)
1947{
1948 ssize_t ret;
1949 unsigned char c;
1950
1951 if ((kfifo_len(sonypi_compat.fifo) == 0) &&
1952 (file->f_flags & O_NONBLOCK))
1953 return -EAGAIN;
1954
1955 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
1956 kfifo_len(sonypi_compat.fifo) != 0);
1957 if (ret)
1958 return ret;
1959
1960 while (ret < count &&
1961 (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
1962 if (put_user(c, buf++))
1963 return -EFAULT;
1964 ret++;
1965 }
1966
1967 if (ret > 0) {
1968 struct inode *inode = file->f_path.dentry->d_inode;
1969 inode->i_atime = current_fs_time(inode->i_sb);
1970 }
1971
1972 return ret;
1973}
1974
1975static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
1976{
1977 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
1978 if (kfifo_len(sonypi_compat.fifo))
1979 return POLLIN | POLLRDNORM;
1980 return 0;
1981}
1982
1983static int ec_read16(u8 addr, u16 *value)
1984{
1985 u8 val_lb, val_hb;
1986 if (ec_read(addr, &val_lb))
1987 return -1;
1988 if (ec_read(addr + 1, &val_hb))
1989 return -1;
1990 *value = val_lb | (val_hb << 8);
1991 return 0;
1992}
1993
1994static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1995 unsigned int cmd, unsigned long arg)
1996{
1997 int ret = 0;
1998 void __user *argp = (void __user *)arg;
1999 u8 val8;
2000 u16 val16;
2001 int value;
2002
malattia@linux.it9f9f0762007-04-28 23:19:36 +09002003 mutex_lock(&spic_dev.lock);
malattia@linux.it7b153f32007-04-09 19:31:25 +02002004 switch (cmd) {
2005 case SONYPI_IOCGBRT:
2006 if (sony_backlight_device == NULL) {
2007 ret = -EIO;
2008 break;
2009 }
2010 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
2011 ret = -EIO;
2012 break;
2013 }
2014 val8 = ((value & 0xff) - 1) << 5;
2015 if (copy_to_user(argp, &val8, sizeof(val8)))
2016 ret = -EFAULT;
2017 break;
2018 case SONYPI_IOCSBRT:
2019 if (sony_backlight_device == NULL) {
2020 ret = -EIO;
2021 break;
2022 }
2023 if (copy_from_user(&val8, argp, sizeof(val8))) {
2024 ret = -EFAULT;
2025 break;
2026 }
2027 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
2028 (val8 >> 5) + 1, NULL)) {
2029 ret = -EIO;
2030 break;
2031 }
2032 /* sync the backlight device status */
2033 sony_backlight_device->props.brightness =
2034 sony_backlight_get_brightness(sony_backlight_device);
2035 break;
2036 case SONYPI_IOCGBAT1CAP:
2037 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
2038 ret = -EIO;
2039 break;
2040 }
2041 if (copy_to_user(argp, &val16, sizeof(val16)))
2042 ret = -EFAULT;
2043 break;
2044 case SONYPI_IOCGBAT1REM:
2045 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
2046 ret = -EIO;
2047 break;
2048 }
2049 if (copy_to_user(argp, &val16, sizeof(val16)))
2050 ret = -EFAULT;
2051 break;
2052 case SONYPI_IOCGBAT2CAP:
2053 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
2054 ret = -EIO;
2055 break;
2056 }
2057 if (copy_to_user(argp, &val16, sizeof(val16)))
2058 ret = -EFAULT;
2059 break;
2060 case SONYPI_IOCGBAT2REM:
2061 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
2062 ret = -EIO;
2063 break;
2064 }
2065 if (copy_to_user(argp, &val16, sizeof(val16)))
2066 ret = -EFAULT;
2067 break;
2068 case SONYPI_IOCGBATFLAGS:
2069 if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
2070 ret = -EIO;
2071 break;
2072 }
2073 val8 &= 0x07;
2074 if (copy_to_user(argp, &val8, sizeof(val8)))
2075 ret = -EFAULT;
2076 break;
2077 case SONYPI_IOCGBLUE:
2078 val8 = spic_dev.bluetooth_power;
2079 if (copy_to_user(argp, &val8, sizeof(val8)))
2080 ret = -EFAULT;
2081 break;
2082 case SONYPI_IOCSBLUE:
2083 if (copy_from_user(&val8, argp, sizeof(val8))) {
2084 ret = -EFAULT;
2085 break;
2086 }
malattia@linux.it9f9f0762007-04-28 23:19:36 +09002087 __sony_pic_set_bluetoothpower(val8);
malattia@linux.it7b153f32007-04-09 19:31:25 +02002088 break;
2089 /* FAN Controls */
2090 case SONYPI_IOCGFAN:
2091 if (sony_pic_get_fanspeed(&val8)) {
2092 ret = -EIO;
2093 break;
2094 }
2095 if (copy_to_user(argp, &val8, sizeof(val8)))
2096 ret = -EFAULT;
2097 break;
2098 case SONYPI_IOCSFAN:
2099 if (copy_from_user(&val8, argp, sizeof(val8))) {
2100 ret = -EFAULT;
2101 break;
2102 }
2103 if (sony_pic_set_fanspeed(val8))
2104 ret = -EIO;
2105 break;
2106 /* GET Temperature (useful under APM) */
2107 case SONYPI_IOCGTEMP:
2108 if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
2109 ret = -EIO;
2110 break;
2111 }
2112 if (copy_to_user(argp, &val8, sizeof(val8)))
2113 ret = -EFAULT;
2114 break;
2115 default:
2116 ret = -EINVAL;
2117 }
malattia@linux.it9f9f0762007-04-28 23:19:36 +09002118 mutex_unlock(&spic_dev.lock);
malattia@linux.it7b153f32007-04-09 19:31:25 +02002119 return ret;
2120}
2121
2122static const struct file_operations sonypi_misc_fops = {
2123 .owner = THIS_MODULE,
2124 .read = sonypi_misc_read,
2125 .poll = sonypi_misc_poll,
2126 .open = sonypi_misc_open,
2127 .release = sonypi_misc_release,
2128 .fasync = sonypi_misc_fasync,
2129 .ioctl = sonypi_misc_ioctl,
2130};
2131
2132static struct miscdevice sonypi_misc_device = {
2133 .minor = MISC_DYNAMIC_MINOR,
2134 .name = "sonypi",
2135 .fops = &sonypi_misc_fops,
2136};
2137
2138static void sonypi_compat_report_event(u8 event)
2139{
2140 kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
2141 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
2142 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
2143}
2144
2145static int sonypi_compat_init(void)
2146{
2147 int error;
2148
2149 spin_lock_init(&sonypi_compat.fifo_lock);
2150 sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
2151 &sonypi_compat.fifo_lock);
2152 if (IS_ERR(sonypi_compat.fifo)) {
2153 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
2154 return PTR_ERR(sonypi_compat.fifo);
2155 }
2156
2157 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
malattia@linux.it7b153f32007-04-09 19:31:25 +02002158
2159 if (minor != -1)
2160 sonypi_misc_device.minor = minor;
2161 error = misc_register(&sonypi_misc_device);
2162 if (error) {
2163 printk(KERN_ERR DRV_PFX "misc_register failed\n");
2164 goto err_free_kfifo;
2165 }
2166 if (minor == -1)
malattia@linux.it5f3d2892007-04-28 23:18:45 +09002167 printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
malattia@linux.it7b153f32007-04-09 19:31:25 +02002168 sonypi_misc_device.minor);
2169
2170 return 0;
2171
2172err_free_kfifo:
2173 kfifo_free(sonypi_compat.fifo);
2174 return error;
2175}
2176
2177static void sonypi_compat_exit(void)
2178{
2179 misc_deregister(&sonypi_misc_device);
2180 kfifo_free(sonypi_compat.fifo);
2181}
2182#else
2183static int sonypi_compat_init(void) { return 0; }
2184static void sonypi_compat_exit(void) { }
2185static void sonypi_compat_report_event(u8 event) { }
Mattia Dongilia64e62a2007-05-01 11:19:53 +09002186#endif /* CONFIG_SONYPI_COMPAT */
malattia@linux.it7b153f32007-04-09 19:31:25 +02002187
malattia@linux.it1549ee62007-04-09 10:19:08 +02002188/*
malattia@linux.it33a04452007-04-09 19:26:03 +02002189 * ACPI callbacks
malattia@linux.it1549ee62007-04-09 10:19:08 +02002190 */
malattia@linux.it33a04452007-04-09 19:26:03 +02002191static acpi_status
2192sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
2193{
2194 u32 i;
2195 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
2196
2197 switch (resource->type) {
2198 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002199 {
2200 /* start IO enumeration */
2201 struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
2202 if (!ioport)
2203 return AE_ERROR;
2204
2205 list_add(&ioport->list, &dev->ioports);
2206 return AE_OK;
2207 }
2208
malattia@linux.it33a04452007-04-09 19:26:03 +02002209 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002210 /* end IO enumeration */
malattia@linux.it33a04452007-04-09 19:26:03 +02002211 return AE_OK;
2212
2213 case ACPI_RESOURCE_TYPE_IRQ:
2214 {
2215 struct acpi_resource_irq *p = &resource->data.irq;
2216 struct sony_pic_irq *interrupt = NULL;
2217 if (!p || !p->interrupt_count) {
2218 /*
2219 * IRQ descriptors may have no IRQ# bits set,
2220 * particularly those those w/ _STA disabled
2221 */
2222 dprintk("Blank IRQ resource\n");
2223 return AE_OK;
2224 }
2225 for (i = 0; i < p->interrupt_count; i++) {
2226 if (!p->interrupts[i]) {
2227 printk(KERN_WARNING DRV_PFX
2228 "Invalid IRQ %d\n",
2229 p->interrupts[i]);
2230 continue;
2231 }
2232 interrupt = kzalloc(sizeof(*interrupt),
2233 GFP_KERNEL);
2234 if (!interrupt)
2235 return AE_ERROR;
2236
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002237 list_add(&interrupt->list, &dev->interrupts);
malattia@linux.it33a04452007-04-09 19:26:03 +02002238 interrupt->irq.triggering = p->triggering;
2239 interrupt->irq.polarity = p->polarity;
2240 interrupt->irq.sharable = p->sharable;
2241 interrupt->irq.interrupt_count = 1;
2242 interrupt->irq.interrupts[0] = p->interrupts[i];
2243 }
2244 return AE_OK;
2245 }
2246 case ACPI_RESOURCE_TYPE_IO:
2247 {
2248 struct acpi_resource_io *io = &resource->data.io;
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002249 struct sony_pic_ioport *ioport =
2250 list_first_entry(&dev->ioports, struct sony_pic_ioport, list);
malattia@linux.it33a04452007-04-09 19:26:03 +02002251 if (!io) {
2252 dprintk("Blank IO resource\n");
2253 return AE_OK;
2254 }
2255
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002256 if (!ioport->io1.minimum) {
2257 memcpy(&ioport->io1, io, sizeof(*io));
2258 dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum,
2259 ioport->io1.address_length);
2260 }
2261 else if (!ioport->io2.minimum) {
2262 memcpy(&ioport->io2, io, sizeof(*io));
2263 dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum,
2264 ioport->io2.address_length);
2265 }
2266 else {
2267 printk(KERN_ERR DRV_PFX "Unknown SPIC Type, more than 2 IO Ports\n");
malattia@linux.it33a04452007-04-09 19:26:03 +02002268 return AE_ERROR;
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002269 }
malattia@linux.it33a04452007-04-09 19:26:03 +02002270 return AE_OK;
2271 }
2272 default:
2273 dprintk("Resource %d isn't an IRQ nor an IO port\n",
2274 resource->type);
2275
2276 case ACPI_RESOURCE_TYPE_END_TAG:
2277 return AE_OK;
2278 }
2279 return AE_CTRL_TERMINATE;
2280}
2281
2282static int sony_pic_possible_resources(struct acpi_device *device)
2283{
2284 int result = 0;
2285 acpi_status status = AE_OK;
2286
2287 if (!device)
2288 return -EINVAL;
2289
2290 /* get device status */
2291 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
2292 dprintk("Evaluating _STA\n");
2293 result = acpi_bus_get_status(device);
2294 if (result) {
2295 printk(KERN_WARNING DRV_PFX "Unable to read status\n");
2296 goto end;
2297 }
2298
2299 if (!device->status.enabled)
2300 dprintk("Device disabled\n");
2301 else
2302 dprintk("Device enabled\n");
2303
2304 /*
2305 * Query and parse 'method'
2306 */
2307 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
2308 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
2309 sony_pic_read_possible_resource, &spic_dev);
2310 if (ACPI_FAILURE(status)) {
2311 printk(KERN_WARNING DRV_PFX
2312 "Failure evaluating %s\n",
2313 METHOD_NAME__PRS);
2314 result = -ENODEV;
2315 }
2316end:
2317 return result;
2318}
2319
2320/*
2321 * Disable the spic device by calling its _DIS method
2322 */
2323static int sony_pic_disable(struct acpi_device *device)
2324{
Matthew Garrett6158d3a2008-10-29 14:01:03 -07002325 acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL,
2326 NULL);
2327
2328 if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND)
malattia@linux.it33a04452007-04-09 19:26:03 +02002329 return -ENXIO;
2330
2331 dprintk("Device disabled\n");
2332 return 0;
2333}
2334
2335
2336/*
2337 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
2338 *
2339 * Call _SRS to set current resources
2340 */
2341static int sony_pic_enable(struct acpi_device *device,
2342 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
2343{
2344 acpi_status status;
2345 int result = 0;
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002346 /* Type 1 resource layout is:
2347 * IO
2348 * IO
2349 * IRQNoFlags
2350 * End
2351 *
2352 * Type 2 and 3 resource layout is:
2353 * IO
2354 * IRQNoFlags
2355 * End
2356 */
malattia@linux.it33a04452007-04-09 19:26:03 +02002357 struct {
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002358 struct acpi_resource res1;
2359 struct acpi_resource res2;
2360 struct acpi_resource res3;
2361 struct acpi_resource res4;
malattia@linux.it33a04452007-04-09 19:26:03 +02002362 } *resource;
2363 struct acpi_buffer buffer = { 0, NULL };
2364
2365 if (!ioport || !irq)
2366 return -EINVAL;
2367
2368 /* init acpi_buffer */
2369 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
2370 if (!resource)
2371 return -ENOMEM;
2372
2373 buffer.length = sizeof(*resource) + 1;
2374 buffer.pointer = resource;
2375
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002376 /* setup Type 1 resources */
Mattia Dongilide920432008-01-14 18:05:43 +09002377 if (spic_dev.control->model == SONYPI_DEVICE_TYPE1) {
malattia@linux.it33a04452007-04-09 19:26:03 +02002378
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002379 /* setup io resources */
2380 resource->res1.type = ACPI_RESOURCE_TYPE_IO;
2381 resource->res1.length = sizeof(struct acpi_resource);
2382 memcpy(&resource->res1.data.io, &ioport->io1,
2383 sizeof(struct acpi_resource_io));
malattia@linux.it33a04452007-04-09 19:26:03 +02002384
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002385 resource->res2.type = ACPI_RESOURCE_TYPE_IO;
2386 resource->res2.length = sizeof(struct acpi_resource);
2387 memcpy(&resource->res2.data.io, &ioport->io2,
2388 sizeof(struct acpi_resource_io));
2389
2390 /* setup irq resource */
2391 resource->res3.type = ACPI_RESOURCE_TYPE_IRQ;
2392 resource->res3.length = sizeof(struct acpi_resource);
2393 memcpy(&resource->res3.data.irq, &irq->irq,
2394 sizeof(struct acpi_resource_irq));
2395 /* we requested a shared irq */
2396 resource->res3.data.irq.sharable = ACPI_SHARED;
2397
2398 resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
2399
2400 }
2401 /* setup Type 2/3 resources */
2402 else {
2403 /* setup io resource */
2404 resource->res1.type = ACPI_RESOURCE_TYPE_IO;
2405 resource->res1.length = sizeof(struct acpi_resource);
2406 memcpy(&resource->res1.data.io, &ioport->io1,
2407 sizeof(struct acpi_resource_io));
2408
2409 /* setup irq resource */
2410 resource->res2.type = ACPI_RESOURCE_TYPE_IRQ;
2411 resource->res2.length = sizeof(struct acpi_resource);
2412 memcpy(&resource->res2.data.irq, &irq->irq,
2413 sizeof(struct acpi_resource_irq));
2414 /* we requested a shared irq */
2415 resource->res2.data.irq.sharable = ACPI_SHARED;
2416
2417 resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
2418 }
malattia@linux.it33a04452007-04-09 19:26:03 +02002419
2420 /* Attempt to set the resource */
2421 dprintk("Evaluating _SRS\n");
2422 status = acpi_set_current_resources(device->handle, &buffer);
2423
2424 /* check for total failure */
2425 if (ACPI_FAILURE(status)) {
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002426 printk(KERN_ERR DRV_PFX "Error evaluating _SRS\n");
malattia@linux.it33a04452007-04-09 19:26:03 +02002427 result = -ENODEV;
2428 goto end;
2429 }
2430
2431 /* Necessary device initializations calls (from sonypi) */
2432 sony_pic_call1(0x82);
2433 sony_pic_call2(0x81, 0xff);
2434 sony_pic_call1(compat ? 0x92 : 0x82);
2435
2436end:
2437 kfree(resource);
2438 return result;
2439}
2440
2441/*****************
2442 *
2443 * ISR: some event is available
2444 *
2445 *****************/
2446static irqreturn_t sony_pic_irq(int irq, void *dev_id)
2447{
2448 int i, j;
malattia@linux.it33a04452007-04-09 19:26:03 +02002449 u8 ev = 0;
2450 u8 data_mask = 0;
2451 u8 device_event = 0;
2452
2453 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
2454
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002455 ev = inb_p(dev->cur_ioport->io1.minimum);
2456 if (dev->cur_ioport->io2.minimum)
2457 data_mask = inb_p(dev->cur_ioport->io2.minimum);
2458 else
Mattia Dongilide920432008-01-14 18:05:43 +09002459 data_mask = inb_p(dev->cur_ioport->io1.minimum +
2460 dev->control->evport_offset);
malattia@linux.it33a04452007-04-09 19:26:03 +02002461
Mattia Dongili22a17782007-07-16 02:34:39 +09002462 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
Mattia Dongilide920432008-01-14 18:05:43 +09002463 ev, data_mask, dev->cur_ioport->io1.minimum,
2464 dev->control->evport_offset);
malattia@linux.it33a04452007-04-09 19:26:03 +02002465
2466 if (ev == 0x00 || ev == 0xff)
2467 return IRQ_HANDLED;
2468
Mattia Dongilide920432008-01-14 18:05:43 +09002469 for (i = 0; dev->control->event_types[i].mask; i++) {
malattia@linux.it33a04452007-04-09 19:26:03 +02002470
Mattia Dongilide920432008-01-14 18:05:43 +09002471 if ((data_mask & dev->control->event_types[i].data) !=
2472 dev->control->event_types[i].data)
malattia@linux.it33a04452007-04-09 19:26:03 +02002473 continue;
2474
Mattia Dongilide920432008-01-14 18:05:43 +09002475 if (!(mask & dev->control->event_types[i].mask))
malattia@linux.it33a04452007-04-09 19:26:03 +02002476 continue;
2477
Mattia Dongilide920432008-01-14 18:05:43 +09002478 for (j = 0; dev->control->event_types[i].events[j].event; j++) {
2479 if (ev == dev->control->event_types[i].events[j].data) {
malattia@linux.it33a04452007-04-09 19:26:03 +02002480 device_event =
Mattia Dongilide920432008-01-14 18:05:43 +09002481 dev->control->
2482 event_types[i].events[j].event;
malattia@linux.it33a04452007-04-09 19:26:03 +02002483 goto found;
2484 }
2485 }
2486 }
Mattia Dongili3eb87492008-01-14 18:05:45 +09002487 /* Still not able to decode the event try to pass
2488 * it over to the minidriver
2489 */
2490 if (dev->control->handle_irq &&
2491 dev->control->handle_irq(data_mask, ev) == 0)
2492 return IRQ_HANDLED;
2493
Mattia Dongilide920432008-01-14 18:05:43 +09002494 dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2495 ev, data_mask, dev->cur_ioport->io1.minimum,
2496 dev->control->evport_offset);
malattia@linux.it33a04452007-04-09 19:26:03 +02002497 return IRQ_HANDLED;
2498
2499found:
malattia@linux.it1549ee62007-04-09 10:19:08 +02002500 sony_laptop_report_input_event(device_event);
Mattia Dongilide920432008-01-14 18:05:43 +09002501 acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event);
malattia@linux.it7b153f32007-04-09 19:31:25 +02002502 sonypi_compat_report_event(device_event);
malattia@linux.it33a04452007-04-09 19:26:03 +02002503
2504 return IRQ_HANDLED;
2505}
2506
2507/*****************
2508 *
2509 * ACPI driver
2510 *
2511 *****************/
2512static int sony_pic_remove(struct acpi_device *device, int type)
2513{
2514 struct sony_pic_ioport *io, *tmp_io;
2515 struct sony_pic_irq *irq, *tmp_irq;
2516
2517 if (sony_pic_disable(device)) {
2518 printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
2519 return -ENXIO;
2520 }
2521
2522 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002523 release_region(spic_dev.cur_ioport->io1.minimum,
2524 spic_dev.cur_ioport->io1.address_length);
2525 if (spic_dev.cur_ioport->io2.minimum)
2526 release_region(spic_dev.cur_ioport->io2.minimum,
2527 spic_dev.cur_ioport->io2.address_length);
malattia@linux.it33a04452007-04-09 19:26:03 +02002528
Mattia Dongili015a9162007-08-12 16:20:27 +09002529 sonypi_compat_exit();
2530
malattia@linux.it1549ee62007-04-09 10:19:08 +02002531 sony_laptop_remove_input();
malattia@linux.it33a04452007-04-09 19:26:03 +02002532
malattia@linux.it49a11de2007-04-09 19:28:56 +02002533 /* pf attrs */
2534 sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2535 sony_pf_remove();
2536
malattia@linux.it33a04452007-04-09 19:26:03 +02002537 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2538 list_del(&io->list);
2539 kfree(io);
2540 }
2541 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2542 list_del(&irq->list);
2543 kfree(irq);
2544 }
2545 spic_dev.cur_ioport = NULL;
2546 spic_dev.cur_irq = NULL;
2547
malattia@linux.itf6119b02007-04-09 19:31:06 +02002548 dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
malattia@linux.it33a04452007-04-09 19:26:03 +02002549 return 0;
2550}
2551
2552static int sony_pic_add(struct acpi_device *device)
2553{
2554 int result;
2555 struct sony_pic_ioport *io, *tmp_io;
2556 struct sony_pic_irq *irq, *tmp_irq;
2557
malattia@linux.itf6119b02007-04-09 19:31:06 +02002558 printk(KERN_INFO DRV_PFX "%s v%s.\n",
2559 SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
malattia@linux.it33a04452007-04-09 19:26:03 +02002560
2561 spic_dev.acpi_dev = device;
2562 strcpy(acpi_device_class(device), "sony/hotkey");
Mattia Dongilide920432008-01-14 18:05:43 +09002563 sony_pic_detect_device_type(&spic_dev);
malattia@linux.it9f9f0762007-04-28 23:19:36 +09002564 mutex_init(&spic_dev.lock);
malattia@linux.it33a04452007-04-09 19:26:03 +02002565
2566 /* read _PRS resources */
2567 result = sony_pic_possible_resources(device);
2568 if (result) {
2569 printk(KERN_ERR DRV_PFX
2570 "Unabe to read possible resources.\n");
2571 goto err_free_resources;
2572 }
2573
2574 /* setup input devices and helper fifo */
Dmitry Torokhov2e4d2422007-11-21 14:15:53 -05002575 result = sony_laptop_setup_input(device);
malattia@linux.it33a04452007-04-09 19:26:03 +02002576 if (result) {
2577 printk(KERN_ERR DRV_PFX
2578 "Unabe to create input devices.\n");
2579 goto err_free_resources;
2580 }
2581
Mattia Dongili015a9162007-08-12 16:20:27 +09002582 if (sonypi_compat_init())
2583 goto err_remove_input;
2584
malattia@linux.it33a04452007-04-09 19:26:03 +02002585 /* request io port */
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002586 list_for_each_entry_reverse(io, &spic_dev.ioports, list) {
2587 if (request_region(io->io1.minimum, io->io1.address_length,
malattia@linux.it33a04452007-04-09 19:26:03 +02002588 "Sony Programable I/O Device")) {
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002589 dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
2590 io->io1.minimum, io->io1.maximum,
2591 io->io1.address_length);
2592 /* Type 1 have 2 ioports */
2593 if (io->io2.minimum) {
2594 if (request_region(io->io2.minimum,
2595 io->io2.address_length,
2596 "Sony Programable I/O Device")) {
2597 dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
2598 io->io2.minimum, io->io2.maximum,
2599 io->io2.address_length);
2600 spic_dev.cur_ioport = io;
2601 break;
2602 }
2603 else {
2604 dprintk("Unable to get I/O port2: "
2605 "0x%.4x (0x%.4x) + 0x%.2x\n",
2606 io->io2.minimum, io->io2.maximum,
2607 io->io2.address_length);
2608 release_region(io->io1.minimum,
2609 io->io1.address_length);
2610 }
2611 }
2612 else {
2613 spic_dev.cur_ioport = io;
2614 break;
2615 }
malattia@linux.it33a04452007-04-09 19:26:03 +02002616 }
2617 }
2618 if (!spic_dev.cur_ioport) {
2619 printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
2620 result = -ENODEV;
Mattia Dongili015a9162007-08-12 16:20:27 +09002621 goto err_remove_compat;
malattia@linux.it33a04452007-04-09 19:26:03 +02002622 }
2623
2624 /* request IRQ */
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002625 list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
malattia@linux.it33a04452007-04-09 19:26:03 +02002626 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
2627 IRQF_SHARED, "sony-laptop", &spic_dev)) {
2628 dprintk("IRQ: %d - triggering: %d - "
2629 "polarity: %d - shr: %d\n",
2630 irq->irq.interrupts[0],
2631 irq->irq.triggering,
2632 irq->irq.polarity,
2633 irq->irq.sharable);
2634 spic_dev.cur_irq = irq;
2635 break;
2636 }
2637 }
2638 if (!spic_dev.cur_irq) {
2639 printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
2640 result = -ENODEV;
2641 goto err_release_region;
2642 }
2643
2644 /* set resource status _SRS */
2645 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2646 if (result) {
2647 printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
2648 goto err_free_irq;
2649 }
2650
malattia@linux.it49a11de2007-04-09 19:28:56 +02002651 spic_dev.bluetooth_power = -1;
2652 /* create device attributes */
2653 result = sony_pf_add();
2654 if (result)
2655 goto err_disable_device;
2656
2657 result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2658 if (result)
2659 goto err_remove_pf;
2660
malattia@linux.it33a04452007-04-09 19:26:03 +02002661 return 0;
2662
malattia@linux.it49a11de2007-04-09 19:28:56 +02002663err_remove_pf:
2664 sony_pf_remove();
2665
2666err_disable_device:
2667 sony_pic_disable(device);
2668
malattia@linux.it33a04452007-04-09 19:26:03 +02002669err_free_irq:
2670 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2671
2672err_release_region:
Mattia Dongilifd1caae2007-08-12 16:20:28 +09002673 release_region(spic_dev.cur_ioport->io1.minimum,
2674 spic_dev.cur_ioport->io1.address_length);
2675 if (spic_dev.cur_ioport->io2.minimum)
2676 release_region(spic_dev.cur_ioport->io2.minimum,
2677 spic_dev.cur_ioport->io2.address_length);
malattia@linux.it33a04452007-04-09 19:26:03 +02002678
Mattia Dongili015a9162007-08-12 16:20:27 +09002679err_remove_compat:
2680 sonypi_compat_exit();
2681
malattia@linux.it33a04452007-04-09 19:26:03 +02002682err_remove_input:
malattia@linux.it1549ee62007-04-09 10:19:08 +02002683 sony_laptop_remove_input();
malattia@linux.it33a04452007-04-09 19:26:03 +02002684
2685err_free_resources:
2686 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2687 list_del(&io->list);
2688 kfree(io);
2689 }
2690 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2691 list_del(&irq->list);
2692 kfree(irq);
2693 }
2694 spic_dev.cur_ioport = NULL;
2695 spic_dev.cur_irq = NULL;
2696
2697 return result;
2698}
2699
2700static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
2701{
2702 if (sony_pic_disable(device))
2703 return -ENXIO;
2704 return 0;
2705}
2706
2707static int sony_pic_resume(struct acpi_device *device)
2708{
2709 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2710 return 0;
2711}
2712
Thomas Renninger1ba90e32007-07-23 14:44:41 +02002713static const struct acpi_device_id sony_pic_device_ids[] = {
2714 {SONY_PIC_HID, 0},
2715 {"", 0},
2716};
2717
malattia@linux.it33a04452007-04-09 19:26:03 +02002718static struct acpi_driver sony_pic_driver = {
2719 .name = SONY_PIC_DRIVER_NAME,
2720 .class = SONY_PIC_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +02002721 .ids = sony_pic_device_ids,
malattia@linux.it33a04452007-04-09 19:26:03 +02002722 .owner = THIS_MODULE,
2723 .ops = {
2724 .add = sony_pic_add,
2725 .remove = sony_pic_remove,
2726 .suspend = sony_pic_suspend,
2727 .resume = sony_pic_resume,
2728 },
2729};
2730
2731static struct dmi_system_id __initdata sonypi_dmi_table[] = {
2732 {
2733 .ident = "Sony Vaio",
2734 .matches = {
2735 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2736 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
2737 },
2738 },
2739 {
2740 .ident = "Sony Vaio",
2741 .matches = {
2742 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2743 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
2744 },
2745 },
2746 { }
2747};
2748
malattia@linux.it59b19102007-04-09 10:19:04 +02002749static int __init sony_laptop_init(void)
Stelian Pop7f09c432007-01-13 23:04:31 +01002750{
malattia@linux.it33a04452007-04-09 19:26:03 +02002751 int result;
2752
2753 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
2754 result = acpi_bus_register_driver(&sony_pic_driver);
2755 if (result) {
2756 printk(KERN_ERR DRV_PFX
2757 "Unable to register SPIC driver.");
2758 goto out;
2759 }
2760 }
2761
2762 result = acpi_bus_register_driver(&sony_nc_driver);
2763 if (result) {
2764 printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
2765 goto out_unregister_pic;
2766 }
2767
2768 return 0;
2769
2770out_unregister_pic:
2771 if (!no_spic)
2772 acpi_bus_unregister_driver(&sony_pic_driver);
2773out:
2774 return result;
Stelian Pop7f09c432007-01-13 23:04:31 +01002775}
2776
malattia@linux.it59b19102007-04-09 10:19:04 +02002777static void __exit sony_laptop_exit(void)
Stelian Pop7f09c432007-01-13 23:04:31 +01002778{
malattia@linux.it59b19102007-04-09 10:19:04 +02002779 acpi_bus_unregister_driver(&sony_nc_driver);
malattia@linux.it33a04452007-04-09 19:26:03 +02002780 if (!no_spic)
2781 acpi_bus_unregister_driver(&sony_pic_driver);
Stelian Pop7f09c432007-01-13 23:04:31 +01002782}
2783
malattia@linux.it59b19102007-04-09 10:19:04 +02002784module_init(sony_laptop_init);
2785module_exit(sony_laptop_exit);