2 * Sony Programmable I/O Control Device driver for VAIO
4 * Copyright (C) 2001-2003 Stelian Pop <stelian@popies.net>
6 * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com>
8 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
10 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
12 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
14 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
16 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #ifndef _SONYPI_PRIV_H_
35 #define _SONYPI_PRIV_H_
39 #define SONYPI_DRIVER_MAJORVERSION 1
40 #define SONYPI_DRIVER_MINORVERSION 23
42 #define SONYPI_DEVICE_MODEL_TYPE1 1
43 #define SONYPI_DEVICE_MODEL_TYPE2 2
45 #include <linux/config.h>
46 #include <linux/types.h>
47 #include <linux/pci.h>
48 #include <linux/input.h>
50 #include <linux/acpi.h>
51 #include "linux/sonypi.h"
53 /* type1 models use those */
54 #define SONYPI_IRQ_PORT 0x8034
55 #define SONYPI_IRQ_SHIFT 22
56 #define SONYPI_BASE 0x50
57 #define SONYPI_G10A (SONYPI_BASE+0x14)
58 #define SONYPI_TYPE1_REGION_SIZE 0x08
59 #define SONYPI_TYPE1_EVTYPE_OFFSET 0x04
61 /* type2 series specifics */
62 #define SONYPI_SIRQ 0x9b
63 #define SONYPI_SLOB 0x9c
64 #define SONYPI_SHIB 0x9d
65 #define SONYPI_TYPE2_REGION_SIZE 0x20
66 #define SONYPI_TYPE2_EVTYPE_OFFSET 0x12
68 /* battery / brightness addresses */
69 #define SONYPI_BAT_FLAGS 0x81
70 #define SONYPI_LCD_LIGHT 0x96
71 #define SONYPI_BAT1_PCTRM 0xa0
72 #define SONYPI_BAT1_LEFT 0xa2
73 #define SONYPI_BAT1_MAXRT 0xa4
74 #define SONYPI_BAT2_PCTRM 0xa8
75 #define SONYPI_BAT2_LEFT 0xaa
76 #define SONYPI_BAT2_MAXRT 0xac
77 #define SONYPI_BAT1_MAXTK 0xb0
78 #define SONYPI_BAT1_FULL 0xb2
79 #define SONYPI_BAT2_MAXTK 0xb8
80 #define SONYPI_BAT2_FULL 0xba
82 /* ioports used for brightness and type2 events */
83 #define SONYPI_DATA_IOPORT 0x62
84 #define SONYPI_CST_IOPORT 0x66
86 /* The set of possible ioports */
87 struct sonypi_ioport_list {
92 static struct sonypi_ioport_list sonypi_type1_ioport_list[] = {
93 { 0x10c0, 0x10c4 }, /* looks like the default on C1Vx */
101 static struct sonypi_ioport_list sonypi_type2_ioport_list[] = {
109 /* The set of possible interrupts */
110 struct sonypi_irq_list {
115 static struct sonypi_irq_list sonypi_type1_irq_list[] = {
116 { 11, 0x2 }, /* IRQ 11, GO22=0,GO23=1 in AML */
117 { 10, 0x1 }, /* IRQ 10, GO22=1,GO23=0 in AML */
118 { 5, 0x0 }, /* IRQ 5, GO22=0,GO23=0 in AML */
119 { 0, 0x3 } /* no IRQ, GO22=1,GO23=1 in AML */
122 static struct sonypi_irq_list sonypi_type2_irq_list[] = {
123 { 11, 0x80 }, /* IRQ 11, 0x80 in SIRQ in AML */
124 { 10, 0x40 }, /* IRQ 10, 0x40 in SIRQ in AML */
125 { 9, 0x20 }, /* IRQ 9, 0x20 in SIRQ in AML */
126 { 6, 0x10 }, /* IRQ 6, 0x10 in SIRQ in AML */
127 { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */
130 #define SONYPI_CAMERA_BRIGHTNESS 0
131 #define SONYPI_CAMERA_CONTRAST 1
132 #define SONYPI_CAMERA_HUE 2
133 #define SONYPI_CAMERA_COLOR 3
134 #define SONYPI_CAMERA_SHARPNESS 4
136 #define SONYPI_CAMERA_PICTURE 5
137 #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
138 #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
139 #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
140 #define SONYPI_CAMERA_MUTE_MASK 0x40
142 /* the rest don't need a loop until not 0xff */
143 #define SONYPI_CAMERA_AGC 6
144 #define SONYPI_CAMERA_AGC_MASK 0x30
145 #define SONYPI_CAMERA_SHUTTER_MASK 0x7
147 #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
148 #define SONYPI_CAMERA_CONTROL 0x10
150 #define SONYPI_CAMERA_STATUS 7
151 #define SONYPI_CAMERA_STATUS_READY 0x2
152 #define SONYPI_CAMERA_STATUS_POSITION 0x4
154 #define SONYPI_DIRECTION_BACKWARDS 0x4
156 #define SONYPI_CAMERA_REVISION 8
157 #define SONYPI_CAMERA_ROMVERSION 9
160 #define SONYPI_JOGGER_MASK 0x00000001
161 #define SONYPI_CAPTURE_MASK 0x00000002
162 #define SONYPI_FNKEY_MASK 0x00000004
163 #define SONYPI_BLUETOOTH_MASK 0x00000008
164 #define SONYPI_PKEY_MASK 0x00000010
165 #define SONYPI_BACK_MASK 0x00000020
166 #define SONYPI_HELP_MASK 0x00000040
167 #define SONYPI_LID_MASK 0x00000080
168 #define SONYPI_ZOOM_MASK 0x00000100
169 #define SONYPI_THUMBPHRASE_MASK 0x00000200
170 #define SONYPI_MEYE_MASK 0x00000400
171 #define SONYPI_MEMORYSTICK_MASK 0x00000800
172 #define SONYPI_BATTERY_MASK 0x00001000
174 struct sonypi_event {
179 /* The set of possible button release events */
180 static struct sonypi_event sonypi_releaseev[] = {
181 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
185 /* The set of possible jogger events */
186 static struct sonypi_event sonypi_joggerev[] = {
187 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
188 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
189 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
190 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
191 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
192 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
193 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
194 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
195 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
196 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
197 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
198 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
199 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
203 /* The set of possible capture button events */
204 static struct sonypi_event sonypi_captureev[] = {
205 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
206 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
207 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
211 /* The set of possible fnkeys events */
212 static struct sonypi_event sonypi_fnkeyev[] = {
213 { 0x10, SONYPI_EVENT_FNKEY_ESC },
214 { 0x11, SONYPI_EVENT_FNKEY_F1 },
215 { 0x12, SONYPI_EVENT_FNKEY_F2 },
216 { 0x13, SONYPI_EVENT_FNKEY_F3 },
217 { 0x14, SONYPI_EVENT_FNKEY_F4 },
218 { 0x15, SONYPI_EVENT_FNKEY_F5 },
219 { 0x16, SONYPI_EVENT_FNKEY_F6 },
220 { 0x17, SONYPI_EVENT_FNKEY_F7 },
221 { 0x18, SONYPI_EVENT_FNKEY_F8 },
222 { 0x19, SONYPI_EVENT_FNKEY_F9 },
223 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
224 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
225 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
226 { 0x21, SONYPI_EVENT_FNKEY_1 },
227 { 0x22, SONYPI_EVENT_FNKEY_2 },
228 { 0x31, SONYPI_EVENT_FNKEY_D },
229 { 0x32, SONYPI_EVENT_FNKEY_E },
230 { 0x33, SONYPI_EVENT_FNKEY_F },
231 { 0x34, SONYPI_EVENT_FNKEY_S },
232 { 0x35, SONYPI_EVENT_FNKEY_B },
233 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
237 /* The set of possible program key events */
238 static struct sonypi_event sonypi_pkeyev[] = {
239 { 0x01, SONYPI_EVENT_PKEY_P1 },
240 { 0x02, SONYPI_EVENT_PKEY_P2 },
241 { 0x04, SONYPI_EVENT_PKEY_P3 },
242 { 0x5c, SONYPI_EVENT_PKEY_P1 },
246 /* The set of possible bluetooth events */
247 static struct sonypi_event sonypi_blueev[] = {
248 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
249 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
250 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
254 /* The set of possible back button events */
255 static struct sonypi_event sonypi_backev[] = {
256 { 0x20, SONYPI_EVENT_BACK_PRESSED },
260 /* The set of possible help button events */
261 static struct sonypi_event sonypi_helpev[] = {
262 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
267 /* The set of possible lid events */
268 static struct sonypi_event sonypi_lidev[] = {
269 { 0x51, SONYPI_EVENT_LID_CLOSED },
270 { 0x50, SONYPI_EVENT_LID_OPENED },
274 /* The set of possible zoom events */
275 static struct sonypi_event sonypi_zoomev[] = {
276 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
280 /* The set of possible thumbphrase events */
281 static struct sonypi_event sonypi_thumbphraseev[] = {
282 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
286 /* The set of possible motioneye camera events */
287 static struct sonypi_event sonypi_meyeev[] = {
288 { 0x00, SONYPI_EVENT_MEYE_FACE },
289 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
293 /* The set of possible memorystick events */
294 static struct sonypi_event sonypi_memorystickev[] = {
295 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
296 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
300 /* The set of possible battery events */
301 static struct sonypi_event sonypi_batteryev[] = {
302 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
303 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
307 struct sonypi_eventtypes {
311 struct sonypi_event * events;
312 } sonypi_eventtypes[] = {
313 { SONYPI_DEVICE_MODEL_TYPE1, 0, 0xffffffff, sonypi_releaseev },
314 { SONYPI_DEVICE_MODEL_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
315 { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
316 { SONYPI_DEVICE_MODEL_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
317 { SONYPI_DEVICE_MODEL_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
318 { SONYPI_DEVICE_MODEL_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
319 { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
320 { SONYPI_DEVICE_MODEL_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
321 { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
322 { SONYPI_DEVICE_MODEL_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
324 { SONYPI_DEVICE_MODEL_TYPE2, 0, 0xffffffff, sonypi_releaseev },
325 { SONYPI_DEVICE_MODEL_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
326 { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
327 { SONYPI_DEVICE_MODEL_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
328 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
329 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
330 { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
331 { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
332 { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_HELP_MASK, sonypi_helpev },
333 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
334 { SONYPI_DEVICE_MODEL_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
335 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
336 { SONYPI_DEVICE_MODEL_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
337 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
342 #define SONYPI_BUF_SIZE 128
343 struct sonypi_queue {
348 wait_queue_head_t proc_list;
349 struct fasync_struct *fasync;
350 unsigned char buf[SONYPI_BUF_SIZE];
353 /* We enable input subsystem event forwarding if the input
354 * subsystem is compiled in, but only if sonypi is not into the
355 * kernel and input as a module... */
356 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
357 #if ! (defined(CONFIG_SONYPI) && defined(CONFIG_INPUT_MODULE))
358 #define SONYPI_USE_INPUT
362 /* The name of the Jog Dial for the input device drivers */
363 #define SONYPI_INPUTNAME "Sony VAIO Jog Dial"
365 struct sonypi_device {
375 struct semaphore lock;
376 struct sonypi_queue queue;
379 #ifdef SONYPI_USE_INPUT
380 struct input_dev jog_dev;
387 #define ITERATIONS_LONG 10000
388 #define ITERATIONS_SHORT 10
390 #define wait_on_command(quiet, command, iterations) { \
391 unsigned int n = iterations; \
392 while (--n && (command)) \
394 if (!n && (verbose || !quiet)) \
395 printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __FUNCTION__, __LINE__); \
399 #define SONYPI_ACPI_ACTIVE (!acpi_disabled)
401 #define SONYPI_ACPI_ACTIVE 0
402 #endif /* CONFIG_ACPI */
404 static inline int sonypi_ec_write(u8 addr, u8 value) {
405 #ifdef CONFIG_ACPI_EC
406 if (SONYPI_ACPI_ACTIVE)
407 return ec_write(addr, value);
409 wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG);
410 outb_p(0x81, SONYPI_CST_IOPORT);
411 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
412 outb_p(addr, SONYPI_DATA_IOPORT);
413 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
414 outb_p(value, SONYPI_DATA_IOPORT);
415 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
419 static inline int sonypi_ec_read(u8 addr, u8 *value) {
420 #ifdef CONFIG_ACPI_EC
421 if (SONYPI_ACPI_ACTIVE)
422 return ec_read(addr, value);
424 wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG);
425 outb_p(0x80, SONYPI_CST_IOPORT);
426 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
427 outb_p(addr, SONYPI_DATA_IOPORT);
428 wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG);
429 *value = inb_p(SONYPI_DATA_IOPORT);
433 #endif /* __KERNEL__ */
435 #endif /* _SONYPI_PRIV_H_ */