Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Sony Programmable I/O Control Device driver for VAIO |
| 3 | * |
malattia@linux.it | 74a882e | 2007-04-28 23:22:11 +0900 | [diff] [blame] | 4 | * Copyright (C) 2007 Mattia Dongili <malattia@linux.it> |
| 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net> |
| 7 | * |
| 8 | * Copyright (C) 2005 Narayanan R S <nars@kadamba.org> |
| 9 | * |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 10 | * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au> |
| 13 | * |
| 14 | * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp> |
| 15 | * |
| 16 | * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp> |
| 17 | * |
| 18 | * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com> |
| 19 | * |
| 20 | * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras. |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2 of the License, or |
| 25 | * (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | * |
| 36 | */ |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/module.h> |
Ingo Molnar | 86ae13b | 2009-10-12 16:22:46 +0200 | [diff] [blame] | 39 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/input.h> |
| 41 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/init.h> |
| 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/miscdevice.h> |
| 45 | #include <linux/poll.h> |
| 46 | #include <linux/delay.h> |
| 47 | #include <linux/wait.h> |
| 48 | #include <linux/acpi.h> |
| 49 | #include <linux/dmi.h> |
| 50 | #include <linux/err.h> |
| 51 | #include <linux/kfifo.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 52 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #include <asm/uaccess.h> |
| 56 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #include <linux/sonypi.h> |
| 59 | |
| 60 | #define SONYPI_DRIVER_VERSION "1.26" |
| 61 | |
| 62 | MODULE_AUTHOR("Stelian Pop <stelian@popies.net>"); |
| 63 | MODULE_DESCRIPTION("Sony Programmable I/O Control Device driver"); |
| 64 | MODULE_LICENSE("GPL"); |
| 65 | MODULE_VERSION(SONYPI_DRIVER_VERSION); |
| 66 | |
| 67 | static int minor = -1; |
| 68 | module_param(minor, int, 0); |
| 69 | MODULE_PARM_DESC(minor, |
| 70 | "minor number of the misc device, default is -1 (automatic)"); |
| 71 | |
| 72 | static int verbose; /* = 0 */ |
| 73 | module_param(verbose, int, 0644); |
| 74 | MODULE_PARM_DESC(verbose, "be verbose, default is 0 (no)"); |
| 75 | |
| 76 | static int fnkeyinit; /* = 0 */ |
| 77 | module_param(fnkeyinit, int, 0444); |
| 78 | MODULE_PARM_DESC(fnkeyinit, |
| 79 | "set this if your Fn keys do not generate any event"); |
| 80 | |
| 81 | static int camera; /* = 0 */ |
| 82 | module_param(camera, int, 0444); |
| 83 | MODULE_PARM_DESC(camera, |
| 84 | "set this if you have a MotionEye camera (PictureBook series)"); |
| 85 | |
| 86 | static int compat; /* = 0 */ |
| 87 | module_param(compat, int, 0444); |
| 88 | MODULE_PARM_DESC(compat, |
| 89 | "set this if you want to enable backward compatibility mode"); |
| 90 | |
| 91 | static unsigned long mask = 0xffffffff; |
| 92 | module_param(mask, ulong, 0644); |
| 93 | MODULE_PARM_DESC(mask, |
| 94 | "set this to the mask of event you want to enable (see doc)"); |
| 95 | |
| 96 | static int useinput = 1; |
| 97 | module_param(useinput, int, 0444); |
| 98 | MODULE_PARM_DESC(useinput, |
| 99 | "set this if you would like sonypi to feed events to the input subsystem"); |
| 100 | |
malattia@linux.it | 1a3e323 | 2007-04-28 23:34:10 +0900 | [diff] [blame] | 101 | static int check_ioport = 1; |
| 102 | module_param(check_ioport, int, 0444); |
| 103 | MODULE_PARM_DESC(check_ioport, |
| 104 | "set this to 0 if you think the automatic ioport check for sony-laptop is wrong"); |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #define SONYPI_DEVICE_MODEL_TYPE1 1 |
| 107 | #define SONYPI_DEVICE_MODEL_TYPE2 2 |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 108 | #define SONYPI_DEVICE_MODEL_TYPE3 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | /* type1 models use those */ |
| 111 | #define SONYPI_IRQ_PORT 0x8034 |
| 112 | #define SONYPI_IRQ_SHIFT 22 |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 113 | #define SONYPI_TYPE1_BASE 0x50 |
| 114 | #define SONYPI_G10A (SONYPI_TYPE1_BASE+0x14) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #define SONYPI_TYPE1_REGION_SIZE 0x08 |
| 116 | #define SONYPI_TYPE1_EVTYPE_OFFSET 0x04 |
| 117 | |
| 118 | /* type2 series specifics */ |
| 119 | #define SONYPI_SIRQ 0x9b |
| 120 | #define SONYPI_SLOB 0x9c |
| 121 | #define SONYPI_SHIB 0x9d |
| 122 | #define SONYPI_TYPE2_REGION_SIZE 0x20 |
| 123 | #define SONYPI_TYPE2_EVTYPE_OFFSET 0x12 |
| 124 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 125 | /* type3 series specifics */ |
| 126 | #define SONYPI_TYPE3_BASE 0x40 |
| 127 | #define SONYPI_TYPE3_GID2 (SONYPI_TYPE3_BASE+0x48) /* 16 bits */ |
| 128 | #define SONYPI_TYPE3_MISC (SONYPI_TYPE3_BASE+0x6d) /* 8 bits */ |
| 129 | #define SONYPI_TYPE3_REGION_SIZE 0x20 |
| 130 | #define SONYPI_TYPE3_EVTYPE_OFFSET 0x12 |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* battery / brightness addresses */ |
| 133 | #define SONYPI_BAT_FLAGS 0x81 |
| 134 | #define SONYPI_LCD_LIGHT 0x96 |
| 135 | #define SONYPI_BAT1_PCTRM 0xa0 |
| 136 | #define SONYPI_BAT1_LEFT 0xa2 |
| 137 | #define SONYPI_BAT1_MAXRT 0xa4 |
| 138 | #define SONYPI_BAT2_PCTRM 0xa8 |
| 139 | #define SONYPI_BAT2_LEFT 0xaa |
| 140 | #define SONYPI_BAT2_MAXRT 0xac |
| 141 | #define SONYPI_BAT1_MAXTK 0xb0 |
| 142 | #define SONYPI_BAT1_FULL 0xb2 |
| 143 | #define SONYPI_BAT2_MAXTK 0xb8 |
| 144 | #define SONYPI_BAT2_FULL 0xba |
| 145 | |
| 146 | /* FAN0 information (reverse engineered from ACPI tables) */ |
| 147 | #define SONYPI_FAN0_STATUS 0x93 |
| 148 | #define SONYPI_TEMP_STATUS 0xC1 |
| 149 | |
| 150 | /* ioports used for brightness and type2 events */ |
| 151 | #define SONYPI_DATA_IOPORT 0x62 |
| 152 | #define SONYPI_CST_IOPORT 0x66 |
| 153 | |
| 154 | /* The set of possible ioports */ |
| 155 | struct sonypi_ioport_list { |
| 156 | u16 port1; |
| 157 | u16 port2; |
| 158 | }; |
| 159 | |
| 160 | static struct sonypi_ioport_list sonypi_type1_ioport_list[] = { |
| 161 | { 0x10c0, 0x10c4 }, /* looks like the default on C1Vx */ |
| 162 | { 0x1080, 0x1084 }, |
| 163 | { 0x1090, 0x1094 }, |
| 164 | { 0x10a0, 0x10a4 }, |
| 165 | { 0x10b0, 0x10b4 }, |
| 166 | { 0x0, 0x0 } |
| 167 | }; |
| 168 | |
| 169 | static struct sonypi_ioport_list sonypi_type2_ioport_list[] = { |
| 170 | { 0x1080, 0x1084 }, |
| 171 | { 0x10a0, 0x10a4 }, |
| 172 | { 0x10c0, 0x10c4 }, |
| 173 | { 0x10e0, 0x10e4 }, |
| 174 | { 0x0, 0x0 } |
| 175 | }; |
| 176 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 177 | /* same as in type 2 models */ |
| 178 | static struct sonypi_ioport_list *sonypi_type3_ioport_list = |
| 179 | sonypi_type2_ioport_list; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* The set of possible interrupts */ |
| 182 | struct sonypi_irq_list { |
| 183 | u16 irq; |
| 184 | u16 bits; |
| 185 | }; |
| 186 | |
| 187 | static struct sonypi_irq_list sonypi_type1_irq_list[] = { |
| 188 | { 11, 0x2 }, /* IRQ 11, GO22=0,GO23=1 in AML */ |
| 189 | { 10, 0x1 }, /* IRQ 10, GO22=1,GO23=0 in AML */ |
| 190 | { 5, 0x0 }, /* IRQ 5, GO22=0,GO23=0 in AML */ |
| 191 | { 0, 0x3 } /* no IRQ, GO22=1,GO23=1 in AML */ |
| 192 | }; |
| 193 | |
| 194 | static struct sonypi_irq_list sonypi_type2_irq_list[] = { |
| 195 | { 11, 0x80 }, /* IRQ 11, 0x80 in SIRQ in AML */ |
| 196 | { 10, 0x40 }, /* IRQ 10, 0x40 in SIRQ in AML */ |
| 197 | { 9, 0x20 }, /* IRQ 9, 0x20 in SIRQ in AML */ |
| 198 | { 6, 0x10 }, /* IRQ 6, 0x10 in SIRQ in AML */ |
| 199 | { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */ |
| 200 | }; |
| 201 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 202 | /* same as in type2 models */ |
| 203 | static struct sonypi_irq_list *sonypi_type3_irq_list = sonypi_type2_irq_list; |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | #define SONYPI_CAMERA_BRIGHTNESS 0 |
| 206 | #define SONYPI_CAMERA_CONTRAST 1 |
| 207 | #define SONYPI_CAMERA_HUE 2 |
| 208 | #define SONYPI_CAMERA_COLOR 3 |
| 209 | #define SONYPI_CAMERA_SHARPNESS 4 |
| 210 | |
| 211 | #define SONYPI_CAMERA_PICTURE 5 |
| 212 | #define SONYPI_CAMERA_EXPOSURE_MASK 0xC |
| 213 | #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3 |
| 214 | #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30 |
| 215 | #define SONYPI_CAMERA_MUTE_MASK 0x40 |
| 216 | |
| 217 | /* the rest don't need a loop until not 0xff */ |
| 218 | #define SONYPI_CAMERA_AGC 6 |
| 219 | #define SONYPI_CAMERA_AGC_MASK 0x30 |
| 220 | #define SONYPI_CAMERA_SHUTTER_MASK 0x7 |
| 221 | |
| 222 | #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7 |
| 223 | #define SONYPI_CAMERA_CONTROL 0x10 |
| 224 | |
| 225 | #define SONYPI_CAMERA_STATUS 7 |
| 226 | #define SONYPI_CAMERA_STATUS_READY 0x2 |
| 227 | #define SONYPI_CAMERA_STATUS_POSITION 0x4 |
| 228 | |
| 229 | #define SONYPI_DIRECTION_BACKWARDS 0x4 |
| 230 | |
| 231 | #define SONYPI_CAMERA_REVISION 8 |
| 232 | #define SONYPI_CAMERA_ROMVERSION 9 |
| 233 | |
| 234 | /* Event masks */ |
| 235 | #define SONYPI_JOGGER_MASK 0x00000001 |
| 236 | #define SONYPI_CAPTURE_MASK 0x00000002 |
| 237 | #define SONYPI_FNKEY_MASK 0x00000004 |
| 238 | #define SONYPI_BLUETOOTH_MASK 0x00000008 |
| 239 | #define SONYPI_PKEY_MASK 0x00000010 |
| 240 | #define SONYPI_BACK_MASK 0x00000020 |
| 241 | #define SONYPI_HELP_MASK 0x00000040 |
| 242 | #define SONYPI_LID_MASK 0x00000080 |
| 243 | #define SONYPI_ZOOM_MASK 0x00000100 |
| 244 | #define SONYPI_THUMBPHRASE_MASK 0x00000200 |
| 245 | #define SONYPI_MEYE_MASK 0x00000400 |
| 246 | #define SONYPI_MEMORYSTICK_MASK 0x00000800 |
| 247 | #define SONYPI_BATTERY_MASK 0x00001000 |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 248 | #define SONYPI_WIRELESS_MASK 0x00002000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | struct sonypi_event { |
| 251 | u8 data; |
| 252 | u8 event; |
| 253 | }; |
| 254 | |
| 255 | /* The set of possible button release events */ |
| 256 | static struct sonypi_event sonypi_releaseev[] = { |
| 257 | { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 258 | { 0, 0 } |
| 259 | }; |
| 260 | |
| 261 | /* The set of possible jogger events */ |
| 262 | static struct sonypi_event sonypi_joggerev[] = { |
| 263 | { 0x1f, SONYPI_EVENT_JOGDIAL_UP }, |
| 264 | { 0x01, SONYPI_EVENT_JOGDIAL_DOWN }, |
| 265 | { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED }, |
| 266 | { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED }, |
| 267 | { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP }, |
| 268 | { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN }, |
| 269 | { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED }, |
| 270 | { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED }, |
| 271 | { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP }, |
| 272 | { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN }, |
| 273 | { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED }, |
| 274 | { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED }, |
| 275 | { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED }, |
| 276 | { 0, 0 } |
| 277 | }; |
| 278 | |
| 279 | /* The set of possible capture button events */ |
| 280 | static struct sonypi_event sonypi_captureev[] = { |
| 281 | { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED }, |
| 282 | { 0x07, SONYPI_EVENT_CAPTURE_PRESSED }, |
| 283 | { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED }, |
| 284 | { 0, 0 } |
| 285 | }; |
| 286 | |
| 287 | /* The set of possible fnkeys events */ |
| 288 | static struct sonypi_event sonypi_fnkeyev[] = { |
| 289 | { 0x10, SONYPI_EVENT_FNKEY_ESC }, |
| 290 | { 0x11, SONYPI_EVENT_FNKEY_F1 }, |
| 291 | { 0x12, SONYPI_EVENT_FNKEY_F2 }, |
| 292 | { 0x13, SONYPI_EVENT_FNKEY_F3 }, |
| 293 | { 0x14, SONYPI_EVENT_FNKEY_F4 }, |
| 294 | { 0x15, SONYPI_EVENT_FNKEY_F5 }, |
| 295 | { 0x16, SONYPI_EVENT_FNKEY_F6 }, |
| 296 | { 0x17, SONYPI_EVENT_FNKEY_F7 }, |
| 297 | { 0x18, SONYPI_EVENT_FNKEY_F8 }, |
| 298 | { 0x19, SONYPI_EVENT_FNKEY_F9 }, |
| 299 | { 0x1a, SONYPI_EVENT_FNKEY_F10 }, |
| 300 | { 0x1b, SONYPI_EVENT_FNKEY_F11 }, |
| 301 | { 0x1c, SONYPI_EVENT_FNKEY_F12 }, |
| 302 | { 0x1f, SONYPI_EVENT_FNKEY_RELEASED }, |
| 303 | { 0x21, SONYPI_EVENT_FNKEY_1 }, |
| 304 | { 0x22, SONYPI_EVENT_FNKEY_2 }, |
| 305 | { 0x31, SONYPI_EVENT_FNKEY_D }, |
| 306 | { 0x32, SONYPI_EVENT_FNKEY_E }, |
| 307 | { 0x33, SONYPI_EVENT_FNKEY_F }, |
| 308 | { 0x34, SONYPI_EVENT_FNKEY_S }, |
| 309 | { 0x35, SONYPI_EVENT_FNKEY_B }, |
| 310 | { 0x36, SONYPI_EVENT_FNKEY_ONLY }, |
| 311 | { 0, 0 } |
| 312 | }; |
| 313 | |
| 314 | /* The set of possible program key events */ |
| 315 | static struct sonypi_event sonypi_pkeyev[] = { |
| 316 | { 0x01, SONYPI_EVENT_PKEY_P1 }, |
| 317 | { 0x02, SONYPI_EVENT_PKEY_P2 }, |
| 318 | { 0x04, SONYPI_EVENT_PKEY_P3 }, |
| 319 | { 0x5c, SONYPI_EVENT_PKEY_P1 }, |
| 320 | { 0, 0 } |
| 321 | }; |
| 322 | |
| 323 | /* The set of possible bluetooth events */ |
| 324 | static struct sonypi_event sonypi_blueev[] = { |
| 325 | { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED }, |
| 326 | { 0x59, SONYPI_EVENT_BLUETOOTH_ON }, |
| 327 | { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF }, |
| 328 | { 0, 0 } |
| 329 | }; |
| 330 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 331 | /* The set of possible wireless events */ |
| 332 | static struct sonypi_event sonypi_wlessev[] = { |
| 333 | { 0x59, SONYPI_EVENT_WIRELESS_ON }, |
| 334 | { 0x5a, SONYPI_EVENT_WIRELESS_OFF }, |
| 335 | { 0, 0 } |
| 336 | }; |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | /* The set of possible back button events */ |
| 339 | static struct sonypi_event sonypi_backev[] = { |
| 340 | { 0x20, SONYPI_EVENT_BACK_PRESSED }, |
| 341 | { 0, 0 } |
| 342 | }; |
| 343 | |
| 344 | /* The set of possible help button events */ |
| 345 | static struct sonypi_event sonypi_helpev[] = { |
| 346 | { 0x3b, SONYPI_EVENT_HELP_PRESSED }, |
| 347 | { 0, 0 } |
| 348 | }; |
| 349 | |
| 350 | |
| 351 | /* The set of possible lid events */ |
| 352 | static struct sonypi_event sonypi_lidev[] = { |
| 353 | { 0x51, SONYPI_EVENT_LID_CLOSED }, |
| 354 | { 0x50, SONYPI_EVENT_LID_OPENED }, |
| 355 | { 0, 0 } |
| 356 | }; |
| 357 | |
| 358 | /* The set of possible zoom events */ |
| 359 | static struct sonypi_event sonypi_zoomev[] = { |
| 360 | { 0x39, SONYPI_EVENT_ZOOM_PRESSED }, |
| 361 | { 0, 0 } |
| 362 | }; |
| 363 | |
| 364 | /* The set of possible thumbphrase events */ |
| 365 | static struct sonypi_event sonypi_thumbphraseev[] = { |
| 366 | { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED }, |
| 367 | { 0, 0 } |
| 368 | }; |
| 369 | |
| 370 | /* The set of possible motioneye camera events */ |
| 371 | static struct sonypi_event sonypi_meyeev[] = { |
| 372 | { 0x00, SONYPI_EVENT_MEYE_FACE }, |
| 373 | { 0x01, SONYPI_EVENT_MEYE_OPPOSITE }, |
| 374 | { 0, 0 } |
| 375 | }; |
| 376 | |
| 377 | /* The set of possible memorystick events */ |
| 378 | static struct sonypi_event sonypi_memorystickev[] = { |
| 379 | { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT }, |
| 380 | { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT }, |
| 381 | { 0, 0 } |
| 382 | }; |
| 383 | |
| 384 | /* The set of possible battery events */ |
| 385 | static struct sonypi_event sonypi_batteryev[] = { |
| 386 | { 0x20, SONYPI_EVENT_BATTERY_INSERT }, |
| 387 | { 0x30, SONYPI_EVENT_BATTERY_REMOVE }, |
| 388 | { 0, 0 } |
| 389 | }; |
| 390 | |
| 391 | static struct sonypi_eventtypes { |
| 392 | int model; |
| 393 | u8 data; |
| 394 | unsigned long mask; |
| 395 | struct sonypi_event * events; |
| 396 | } sonypi_eventtypes[] = { |
| 397 | { SONYPI_DEVICE_MODEL_TYPE1, 0, 0xffffffff, sonypi_releaseev }, |
| 398 | { SONYPI_DEVICE_MODEL_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev }, |
| 399 | { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev }, |
| 400 | { SONYPI_DEVICE_MODEL_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev }, |
| 401 | { SONYPI_DEVICE_MODEL_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev }, |
| 402 | { SONYPI_DEVICE_MODEL_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 403 | { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, |
| 404 | { SONYPI_DEVICE_MODEL_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 405 | { SONYPI_DEVICE_MODEL_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 406 | { SONYPI_DEVICE_MODEL_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 407 | |
| 408 | { SONYPI_DEVICE_MODEL_TYPE2, 0, 0xffffffff, sonypi_releaseev }, |
| 409 | { SONYPI_DEVICE_MODEL_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev }, |
| 410 | { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev }, |
| 411 | { SONYPI_DEVICE_MODEL_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev }, |
| 412 | { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 413 | { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, |
| 414 | { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 415 | { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev }, |
| 417 | { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev }, |
| 418 | { SONYPI_DEVICE_MODEL_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev }, |
| 419 | { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 420 | { SONYPI_DEVICE_MODEL_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 421 | { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 422 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 423 | { SONYPI_DEVICE_MODEL_TYPE3, 0, 0xffffffff, sonypi_releaseev }, |
| 424 | { SONYPI_DEVICE_MODEL_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 425 | { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev }, |
| 426 | { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 427 | { SONYPI_DEVICE_MODEL_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 428 | { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { 0 } |
| 430 | }; |
| 431 | |
| 432 | #define SONYPI_BUF_SIZE 128 |
| 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | /* Correspondance table between sonypi events and input layer events */ |
| 435 | static struct { |
| 436 | int sonypiev; |
| 437 | int inputev; |
| 438 | } sonypi_inputkeys[] = { |
| 439 | { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA }, |
| 440 | { SONYPI_EVENT_FNKEY_ONLY, KEY_FN }, |
| 441 | { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC }, |
| 442 | { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 }, |
| 443 | { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 }, |
| 444 | { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 }, |
| 445 | { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 }, |
| 446 | { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 }, |
| 447 | { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 }, |
| 448 | { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 }, |
| 449 | { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 }, |
| 450 | { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 }, |
| 451 | { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 }, |
| 452 | { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 }, |
| 453 | { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 }, |
| 454 | { SONYPI_EVENT_FNKEY_1, KEY_FN_1 }, |
| 455 | { SONYPI_EVENT_FNKEY_2, KEY_FN_2 }, |
| 456 | { SONYPI_EVENT_FNKEY_D, KEY_FN_D }, |
| 457 | { SONYPI_EVENT_FNKEY_E, KEY_FN_E }, |
| 458 | { SONYPI_EVENT_FNKEY_F, KEY_FN_F }, |
| 459 | { SONYPI_EVENT_FNKEY_S, KEY_FN_S }, |
| 460 | { SONYPI_EVENT_FNKEY_B, KEY_FN_B }, |
| 461 | { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE }, |
| 462 | { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE }, |
| 463 | { SONYPI_EVENT_PKEY_P1, KEY_PROG1 }, |
| 464 | { SONYPI_EVENT_PKEY_P2, KEY_PROG2 }, |
| 465 | { SONYPI_EVENT_PKEY_P3, KEY_PROG3 }, |
| 466 | { SONYPI_EVENT_BACK_PRESSED, KEY_BACK }, |
| 467 | { SONYPI_EVENT_HELP_PRESSED, KEY_HELP }, |
| 468 | { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM }, |
| 469 | { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB }, |
| 470 | { 0, 0 }, |
| 471 | }; |
| 472 | |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 473 | struct sonypi_keypress { |
| 474 | struct input_dev *dev; |
| 475 | int key; |
| 476 | }; |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | static struct sonypi_device { |
| 479 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | u16 irq; |
| 481 | u16 bits; |
| 482 | u16 ioport1; |
| 483 | u16 ioport2; |
| 484 | u16 region_size; |
| 485 | u16 evtype_offset; |
| 486 | int camera_power; |
| 487 | int bluetooth_power; |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 488 | struct mutex lock; |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 489 | struct kfifo fifo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | spinlock_t fifo_lock; |
| 491 | wait_queue_head_t fifo_proc_list; |
| 492 | struct fasync_struct *fifo_async; |
| 493 | int open_count; |
| 494 | int model; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 495 | struct input_dev *input_jog_dev; |
| 496 | struct input_dev *input_key_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | struct work_struct input_work; |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 498 | struct kfifo input_fifo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | spinlock_t input_fifo_lock; |
| 500 | } sonypi_device; |
| 501 | |
| 502 | #define ITERATIONS_LONG 10000 |
| 503 | #define ITERATIONS_SHORT 10 |
| 504 | |
| 505 | #define wait_on_command(quiet, command, iterations) { \ |
| 506 | unsigned int n = iterations; \ |
| 507 | while (--n && (command)) \ |
| 508 | udelay(1); \ |
| 509 | if (!n && (verbose || !quiet)) \ |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 510 | printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __func__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | #ifdef CONFIG_ACPI |
| 514 | #define SONYPI_ACPI_ACTIVE (!acpi_disabled) |
| 515 | #else |
| 516 | #define SONYPI_ACPI_ACTIVE 0 |
| 517 | #endif /* CONFIG_ACPI */ |
| 518 | |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 519 | #ifdef CONFIG_ACPI |
| 520 | static struct acpi_device *sonypi_acpi_device; |
Bjorn Helgaas | e4513a5 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 521 | static int acpi_driver_registered; |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 522 | #endif |
| 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | static int sonypi_ec_write(u8 addr, u8 value) |
| 525 | { |
Bjorn Helgaas | 8950d89 | 2008-11-05 16:18:03 -0700 | [diff] [blame] | 526 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | if (SONYPI_ACPI_ACTIVE) |
| 528 | return ec_write(addr, value); |
| 529 | #endif |
| 530 | wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG); |
| 531 | outb_p(0x81, SONYPI_CST_IOPORT); |
| 532 | wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG); |
| 533 | outb_p(addr, SONYPI_DATA_IOPORT); |
| 534 | wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG); |
| 535 | outb_p(value, SONYPI_DATA_IOPORT); |
| 536 | wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG); |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int sonypi_ec_read(u8 addr, u8 *value) |
| 541 | { |
Bjorn Helgaas | 8950d89 | 2008-11-05 16:18:03 -0700 | [diff] [blame] | 542 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | if (SONYPI_ACPI_ACTIVE) |
| 544 | return ec_read(addr, value); |
| 545 | #endif |
| 546 | wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3, ITERATIONS_LONG); |
| 547 | outb_p(0x80, SONYPI_CST_IOPORT); |
| 548 | wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG); |
| 549 | outb_p(addr, SONYPI_DATA_IOPORT); |
| 550 | wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2, ITERATIONS_LONG); |
| 551 | *value = inb_p(SONYPI_DATA_IOPORT); |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | static int ec_read16(u8 addr, u16 *value) |
| 556 | { |
| 557 | u8 val_lb, val_hb; |
| 558 | if (sonypi_ec_read(addr, &val_lb)) |
| 559 | return -1; |
| 560 | if (sonypi_ec_read(addr + 1, &val_hb)) |
| 561 | return -1; |
| 562 | *value = val_lb | (val_hb << 8); |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | /* Initializes the device - this comes from the AML code in the ACPI bios */ |
| 567 | static void sonypi_type1_srs(void) |
| 568 | { |
| 569 | u32 v; |
| 570 | |
| 571 | pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v); |
| 572 | v = (v & 0xFFFF0000) | ((u32) sonypi_device.ioport1); |
| 573 | pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v); |
| 574 | |
| 575 | pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v); |
| 576 | v = (v & 0xFFF0FFFF) | |
| 577 | (((u32) sonypi_device.ioport1 ^ sonypi_device.ioport2) << 16); |
| 578 | pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v); |
| 579 | |
| 580 | v = inl(SONYPI_IRQ_PORT); |
| 581 | v &= ~(((u32) 0x3) << SONYPI_IRQ_SHIFT); |
| 582 | v |= (((u32) sonypi_device.bits) << SONYPI_IRQ_SHIFT); |
| 583 | outl(v, SONYPI_IRQ_PORT); |
| 584 | |
| 585 | pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v); |
| 586 | v = (v & 0xFF1FFFFF) | 0x00C00000; |
| 587 | pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v); |
| 588 | } |
| 589 | |
| 590 | static void sonypi_type2_srs(void) |
| 591 | { |
| 592 | if (sonypi_ec_write(SONYPI_SHIB, (sonypi_device.ioport1 & 0xFF00) >> 8)) |
| 593 | printk(KERN_WARNING "ec_write failed\n"); |
| 594 | if (sonypi_ec_write(SONYPI_SLOB, sonypi_device.ioport1 & 0x00FF)) |
| 595 | printk(KERN_WARNING "ec_write failed\n"); |
| 596 | if (sonypi_ec_write(SONYPI_SIRQ, sonypi_device.bits)) |
| 597 | printk(KERN_WARNING "ec_write failed\n"); |
| 598 | udelay(10); |
| 599 | } |
| 600 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 601 | static void sonypi_type3_srs(void) |
| 602 | { |
| 603 | u16 v16; |
| 604 | u8 v8; |
| 605 | |
| 606 | /* This model type uses the same initialiazation of |
| 607 | * the embedded controller as the type2 models. */ |
| 608 | sonypi_type2_srs(); |
| 609 | |
| 610 | /* Initialization of PCI config space of the LPC interface bridge. */ |
| 611 | v16 = (sonypi_device.ioport1 & 0xFFF0) | 0x01; |
| 612 | pci_write_config_word(sonypi_device.dev, SONYPI_TYPE3_GID2, v16); |
| 613 | pci_read_config_byte(sonypi_device.dev, SONYPI_TYPE3_MISC, &v8); |
| 614 | v8 = (v8 & 0xCF) | 0x10; |
| 615 | pci_write_config_byte(sonypi_device.dev, SONYPI_TYPE3_MISC, v8); |
| 616 | } |
| 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | /* Disables the device - this comes from the AML code in the ACPI bios */ |
| 619 | static void sonypi_type1_dis(void) |
| 620 | { |
| 621 | u32 v; |
| 622 | |
| 623 | pci_read_config_dword(sonypi_device.dev, SONYPI_G10A, &v); |
| 624 | v = v & 0xFF3FFFFF; |
| 625 | pci_write_config_dword(sonypi_device.dev, SONYPI_G10A, v); |
| 626 | |
| 627 | v = inl(SONYPI_IRQ_PORT); |
| 628 | v |= (0x3 << SONYPI_IRQ_SHIFT); |
| 629 | outl(v, SONYPI_IRQ_PORT); |
| 630 | } |
| 631 | |
| 632 | static void sonypi_type2_dis(void) |
| 633 | { |
| 634 | if (sonypi_ec_write(SONYPI_SHIB, 0)) |
| 635 | printk(KERN_WARNING "ec_write failed\n"); |
| 636 | if (sonypi_ec_write(SONYPI_SLOB, 0)) |
| 637 | printk(KERN_WARNING "ec_write failed\n"); |
| 638 | if (sonypi_ec_write(SONYPI_SIRQ, 0)) |
| 639 | printk(KERN_WARNING "ec_write failed\n"); |
| 640 | } |
| 641 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 642 | static void sonypi_type3_dis(void) |
| 643 | { |
| 644 | sonypi_type2_dis(); |
| 645 | udelay(10); |
| 646 | pci_write_config_word(sonypi_device.dev, SONYPI_TYPE3_GID2, 0); |
| 647 | } |
| 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | static u8 sonypi_call1(u8 dev) |
| 650 | { |
| 651 | u8 v1, v2; |
| 652 | |
| 653 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 654 | outb(dev, sonypi_device.ioport2); |
| 655 | v1 = inb_p(sonypi_device.ioport2); |
| 656 | v2 = inb_p(sonypi_device.ioport1); |
| 657 | return v2; |
| 658 | } |
| 659 | |
| 660 | static u8 sonypi_call2(u8 dev, u8 fn) |
| 661 | { |
| 662 | u8 v1; |
| 663 | |
| 664 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 665 | outb(dev, sonypi_device.ioport2); |
| 666 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 667 | outb(fn, sonypi_device.ioport1); |
| 668 | v1 = inb_p(sonypi_device.ioport1); |
| 669 | return v1; |
| 670 | } |
| 671 | |
| 672 | static u8 sonypi_call3(u8 dev, u8 fn, u8 v) |
| 673 | { |
| 674 | u8 v1; |
| 675 | |
| 676 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 677 | outb(dev, sonypi_device.ioport2); |
| 678 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 679 | outb(fn, sonypi_device.ioport1); |
| 680 | wait_on_command(0, inb_p(sonypi_device.ioport2) & 2, ITERATIONS_LONG); |
| 681 | outb(v, sonypi_device.ioport1); |
| 682 | v1 = inb_p(sonypi_device.ioport1); |
| 683 | return v1; |
| 684 | } |
| 685 | |
| 686 | #if 0 |
| 687 | /* Get brightness, hue etc. Unreliable... */ |
| 688 | static u8 sonypi_read(u8 fn) |
| 689 | { |
| 690 | u8 v1, v2; |
| 691 | int n = 100; |
| 692 | |
| 693 | while (n--) { |
| 694 | v1 = sonypi_call2(0x8f, fn); |
| 695 | v2 = sonypi_call2(0x8f, fn); |
| 696 | if (v1 == v2 && v1 != 0xff) |
| 697 | return v1; |
| 698 | } |
| 699 | return 0xff; |
| 700 | } |
| 701 | #endif |
| 702 | |
| 703 | /* Set brightness, hue etc */ |
| 704 | static void sonypi_set(u8 fn, u8 v) |
| 705 | { |
| 706 | wait_on_command(0, sonypi_call3(0x90, fn, v), ITERATIONS_SHORT); |
| 707 | } |
| 708 | |
| 709 | /* Tests if the camera is ready */ |
| 710 | static int sonypi_camera_ready(void) |
| 711 | { |
| 712 | u8 v; |
| 713 | |
| 714 | v = sonypi_call2(0x8f, SONYPI_CAMERA_STATUS); |
| 715 | return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY)); |
| 716 | } |
| 717 | |
| 718 | /* Turns the camera off */ |
| 719 | static void sonypi_camera_off(void) |
| 720 | { |
| 721 | sonypi_set(SONYPI_CAMERA_PICTURE, SONYPI_CAMERA_MUTE_MASK); |
| 722 | |
| 723 | if (!sonypi_device.camera_power) |
| 724 | return; |
| 725 | |
| 726 | sonypi_call2(0x91, 0); |
| 727 | sonypi_device.camera_power = 0; |
| 728 | } |
| 729 | |
| 730 | /* Turns the camera on */ |
| 731 | static void sonypi_camera_on(void) |
| 732 | { |
| 733 | int i, j; |
| 734 | |
| 735 | if (sonypi_device.camera_power) |
| 736 | return; |
| 737 | |
| 738 | for (j = 5; j > 0; j--) { |
| 739 | |
| 740 | while (sonypi_call2(0x91, 0x1)) |
| 741 | msleep(10); |
| 742 | sonypi_call1(0x93); |
| 743 | |
| 744 | for (i = 400; i > 0; i--) { |
| 745 | if (sonypi_camera_ready()) |
| 746 | break; |
| 747 | msleep(10); |
| 748 | } |
| 749 | if (i) |
| 750 | break; |
| 751 | } |
| 752 | |
| 753 | if (j == 0) { |
| 754 | printk(KERN_WARNING "sonypi: failed to power on camera\n"); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | sonypi_set(0x10, 0x5a); |
| 759 | sonypi_device.camera_power = 1; |
| 760 | } |
| 761 | |
| 762 | /* sets the bluetooth subsystem power state */ |
| 763 | static void sonypi_setbluetoothpower(u8 state) |
| 764 | { |
| 765 | state = !!state; |
| 766 | |
| 767 | if (sonypi_device.bluetooth_power == state) |
| 768 | return; |
| 769 | |
| 770 | sonypi_call2(0x96, state); |
| 771 | sonypi_call1(0x82); |
| 772 | sonypi_device.bluetooth_power = state; |
| 773 | } |
| 774 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 775 | static void input_keyrelease(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 777 | struct sonypi_keypress kp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 779 | while (kfifo_out_locked(&sonypi_device.input_fifo, (unsigned char *)&kp, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 780 | sizeof(kp), &sonypi_device.input_fifo_lock) |
| 781 | == sizeof(kp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | msleep(10); |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 783 | input_report_key(kp.dev, kp.key, 0); |
| 784 | input_sync(kp.dev); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | static void sonypi_report_input_event(u8 event) |
| 789 | { |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 790 | struct input_dev *jog_dev = sonypi_device.input_jog_dev; |
| 791 | struct input_dev *key_dev = sonypi_device.input_key_dev; |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 792 | struct sonypi_keypress kp = { NULL }; |
| 793 | int i; |
| 794 | |
| 795 | switch (event) { |
| 796 | case SONYPI_EVENT_JOGDIAL_UP: |
| 797 | case SONYPI_EVENT_JOGDIAL_UP_PRESSED: |
| 798 | input_report_rel(jog_dev, REL_WHEEL, 1); |
| 799 | input_sync(jog_dev); |
| 800 | break; |
| 801 | |
| 802 | case SONYPI_EVENT_JOGDIAL_DOWN: |
| 803 | case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED: |
| 804 | input_report_rel(jog_dev, REL_WHEEL, -1); |
| 805 | input_sync(jog_dev); |
| 806 | break; |
| 807 | |
| 808 | case SONYPI_EVENT_JOGDIAL_PRESSED: |
| 809 | kp.key = BTN_MIDDLE; |
| 810 | kp.dev = jog_dev; |
| 811 | break; |
| 812 | |
| 813 | case SONYPI_EVENT_FNKEY_RELEASED: |
| 814 | /* Nothing, not all VAIOs generate this event */ |
| 815 | break; |
| 816 | |
| 817 | default: |
| 818 | for (i = 0; sonypi_inputkeys[i].sonypiev; i++) |
| 819 | if (event == sonypi_inputkeys[i].sonypiev) { |
| 820 | kp.dev = key_dev; |
| 821 | kp.key = sonypi_inputkeys[i].inputev; |
| 822 | break; |
| 823 | } |
| 824 | break; |
| 825 | } |
| 826 | |
| 827 | if (kp.dev) { |
| 828 | input_report_key(kp.dev, kp.key, 1); |
| 829 | input_sync(kp.dev); |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 830 | kfifo_in_locked(&sonypi_device.input_fifo, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 831 | (unsigned char *)&kp, sizeof(kp), |
| 832 | &sonypi_device.input_fifo_lock); |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 833 | schedule_work(&sonypi_device.input_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | |
| 837 | /* Interrupt handler: some event is available */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 838 | static irqreturn_t sonypi_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
| 840 | u8 v1, v2, event = 0; |
| 841 | int i, j; |
| 842 | |
| 843 | v1 = inb_p(sonypi_device.ioport1); |
| 844 | v2 = inb_p(sonypi_device.ioport1 + sonypi_device.evtype_offset); |
| 845 | |
| 846 | for (i = 0; sonypi_eventtypes[i].model; i++) { |
| 847 | if (sonypi_device.model != sonypi_eventtypes[i].model) |
| 848 | continue; |
| 849 | if ((v2 & sonypi_eventtypes[i].data) != |
| 850 | sonypi_eventtypes[i].data) |
| 851 | continue; |
| 852 | if (!(mask & sonypi_eventtypes[i].mask)) |
| 853 | continue; |
| 854 | for (j = 0; sonypi_eventtypes[i].events[j].event; j++) { |
| 855 | if (v1 == sonypi_eventtypes[i].events[j].data) { |
| 856 | event = sonypi_eventtypes[i].events[j].event; |
| 857 | goto found; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | if (verbose) |
| 863 | printk(KERN_WARNING |
| 864 | "sonypi: unknown event port1=0x%02x,port2=0x%02x\n", |
| 865 | v1, v2); |
| 866 | /* We need to return IRQ_HANDLED here because there *are* |
| 867 | * events belonging to the sonypi device we don't know about, |
| 868 | * but we still don't want those to pollute the logs... */ |
| 869 | return IRQ_HANDLED; |
| 870 | |
| 871 | found: |
| 872 | if (verbose > 1) |
| 873 | printk(KERN_INFO |
| 874 | "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2); |
| 875 | |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 876 | if (useinput) |
| 877 | sonypi_report_input_event(event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 879 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | e4513a5 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 880 | if (sonypi_acpi_device) |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 881 | acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event); |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 882 | #endif |
| 883 | |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 884 | kfifo_in_locked(&sonypi_device.fifo, (unsigned char *)&event, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 885 | sizeof(event), &sonypi_device.fifo_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN); |
| 887 | wake_up_interruptible(&sonypi_device.fifo_proc_list); |
| 888 | |
| 889 | return IRQ_HANDLED; |
| 890 | } |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | static int sonypi_misc_fasync(int fd, struct file *filp, int on) |
| 893 | { |
Jonathan Corbet | 60aa492 | 2009-02-01 14:52:56 -0700 | [diff] [blame] | 894 | return fasync_helper(fd, filp, on, &sonypi_device.fifo_async); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static int sonypi_misc_release(struct inode *inode, struct file *file) |
| 898 | { |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 899 | mutex_lock(&sonypi_device.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | sonypi_device.open_count--; |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 901 | mutex_unlock(&sonypi_device.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static int sonypi_misc_open(struct inode *inode, struct file *file) |
| 906 | { |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 907 | mutex_lock(&sonypi_device.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | /* Flush input queue on first open */ |
| 909 | if (!sonypi_device.open_count) |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 910 | kfifo_reset(&sonypi_device.fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | sonypi_device.open_count++; |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 912 | mutex_unlock(&sonypi_device.lock); |
John Kacur | 6432e73 | 2009-10-18 23:49:49 +0200 | [diff] [blame] | 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static ssize_t sonypi_misc_read(struct file *file, char __user *buf, |
| 918 | size_t count, loff_t *pos) |
| 919 | { |
| 920 | ssize_t ret; |
| 921 | unsigned char c; |
| 922 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 923 | if ((kfifo_len(&sonypi_device.fifo) == 0) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | (file->f_flags & O_NONBLOCK)) |
| 925 | return -EAGAIN; |
| 926 | |
| 927 | ret = wait_event_interruptible(sonypi_device.fifo_proc_list, |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 928 | kfifo_len(&sonypi_device.fifo) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | if (ret) |
| 930 | return ret; |
| 931 | |
| 932 | while (ret < count && |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 933 | (kfifo_out_locked(&sonypi_device.fifo, &c, sizeof(c), |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 934 | &sonypi_device.fifo_lock) == sizeof(c))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | if (put_user(c, buf++)) |
| 936 | return -EFAULT; |
| 937 | ret++; |
| 938 | } |
| 939 | |
| 940 | if (ret > 0) { |
Josef Sipek | a7113a9 | 2006-12-08 02:36:55 -0800 | [diff] [blame] | 941 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | inode->i_atime = current_fs_time(inode->i_sb); |
| 943 | } |
| 944 | |
| 945 | return ret; |
| 946 | } |
| 947 | |
| 948 | static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait) |
| 949 | { |
| 950 | poll_wait(file, &sonypi_device.fifo_proc_list, wait); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 951 | if (kfifo_len(&sonypi_device.fifo)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | return POLLIN | POLLRDNORM; |
| 953 | return 0; |
| 954 | } |
| 955 | |
John Kacur | 6432e73 | 2009-10-18 23:49:49 +0200 | [diff] [blame] | 956 | static long sonypi_misc_ioctl(struct file *fp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | unsigned int cmd, unsigned long arg) |
| 958 | { |
John Kacur | 6432e73 | 2009-10-18 23:49:49 +0200 | [diff] [blame] | 959 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | void __user *argp = (void __user *)arg; |
| 961 | u8 val8; |
| 962 | u16 val16; |
| 963 | |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 964 | mutex_lock(&sonypi_device.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | switch (cmd) { |
| 966 | case SONYPI_IOCGBRT: |
| 967 | if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) { |
| 968 | ret = -EIO; |
| 969 | break; |
| 970 | } |
| 971 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 972 | ret = -EFAULT; |
| 973 | break; |
| 974 | case SONYPI_IOCSBRT: |
| 975 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
| 976 | ret = -EFAULT; |
| 977 | break; |
| 978 | } |
| 979 | if (sonypi_ec_write(SONYPI_LCD_LIGHT, val8)) |
| 980 | ret = -EIO; |
| 981 | break; |
| 982 | case SONYPI_IOCGBAT1CAP: |
| 983 | if (ec_read16(SONYPI_BAT1_FULL, &val16)) { |
| 984 | ret = -EIO; |
| 985 | break; |
| 986 | } |
| 987 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 988 | ret = -EFAULT; |
| 989 | break; |
| 990 | case SONYPI_IOCGBAT1REM: |
| 991 | if (ec_read16(SONYPI_BAT1_LEFT, &val16)) { |
| 992 | ret = -EIO; |
| 993 | break; |
| 994 | } |
| 995 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 996 | ret = -EFAULT; |
| 997 | break; |
| 998 | case SONYPI_IOCGBAT2CAP: |
| 999 | if (ec_read16(SONYPI_BAT2_FULL, &val16)) { |
| 1000 | ret = -EIO; |
| 1001 | break; |
| 1002 | } |
| 1003 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 1004 | ret = -EFAULT; |
| 1005 | break; |
| 1006 | case SONYPI_IOCGBAT2REM: |
| 1007 | if (ec_read16(SONYPI_BAT2_LEFT, &val16)) { |
| 1008 | ret = -EIO; |
| 1009 | break; |
| 1010 | } |
| 1011 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 1012 | ret = -EFAULT; |
| 1013 | break; |
| 1014 | case SONYPI_IOCGBATFLAGS: |
| 1015 | if (sonypi_ec_read(SONYPI_BAT_FLAGS, &val8)) { |
| 1016 | ret = -EIO; |
| 1017 | break; |
| 1018 | } |
| 1019 | val8 &= 0x07; |
| 1020 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 1021 | ret = -EFAULT; |
| 1022 | break; |
| 1023 | case SONYPI_IOCGBLUE: |
| 1024 | val8 = sonypi_device.bluetooth_power; |
| 1025 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 1026 | ret = -EFAULT; |
| 1027 | break; |
| 1028 | case SONYPI_IOCSBLUE: |
| 1029 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
| 1030 | ret = -EFAULT; |
| 1031 | break; |
| 1032 | } |
| 1033 | sonypi_setbluetoothpower(val8); |
| 1034 | break; |
| 1035 | /* FAN Controls */ |
| 1036 | case SONYPI_IOCGFAN: |
| 1037 | if (sonypi_ec_read(SONYPI_FAN0_STATUS, &val8)) { |
| 1038 | ret = -EIO; |
| 1039 | break; |
| 1040 | } |
Al Viro | 0555985 | 2005-05-04 05:40:02 +0100 | [diff] [blame] | 1041 | if (copy_to_user(argp, &val8, sizeof(val8))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | ret = -EFAULT; |
| 1043 | break; |
| 1044 | case SONYPI_IOCSFAN: |
Al Viro | 0555985 | 2005-05-04 05:40:02 +0100 | [diff] [blame] | 1045 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | ret = -EFAULT; |
| 1047 | break; |
| 1048 | } |
| 1049 | if (sonypi_ec_write(SONYPI_FAN0_STATUS, val8)) |
| 1050 | ret = -EIO; |
| 1051 | break; |
| 1052 | /* GET Temperature (useful under APM) */ |
| 1053 | case SONYPI_IOCGTEMP: |
| 1054 | if (sonypi_ec_read(SONYPI_TEMP_STATUS, &val8)) { |
| 1055 | ret = -EIO; |
| 1056 | break; |
| 1057 | } |
Al Viro | 0555985 | 2005-05-04 05:40:02 +0100 | [diff] [blame] | 1058 | if (copy_to_user(argp, &val8, sizeof(val8))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | ret = -EFAULT; |
| 1060 | break; |
| 1061 | default: |
| 1062 | ret = -EINVAL; |
| 1063 | } |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 1064 | mutex_unlock(&sonypi_device.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 1068 | static const struct file_operations sonypi_misc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | .owner = THIS_MODULE, |
| 1070 | .read = sonypi_misc_read, |
| 1071 | .poll = sonypi_misc_poll, |
| 1072 | .open = sonypi_misc_open, |
| 1073 | .release = sonypi_misc_release, |
| 1074 | .fasync = sonypi_misc_fasync, |
John Kacur | 6432e73 | 2009-10-18 23:49:49 +0200 | [diff] [blame] | 1075 | .unlocked_ioctl = sonypi_misc_ioctl, |
| 1076 | .llseek = no_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | static struct miscdevice sonypi_misc_device = { |
| 1080 | .minor = MISC_DYNAMIC_MINOR, |
| 1081 | .name = "sonypi", |
| 1082 | .fops = &sonypi_misc_fops, |
| 1083 | }; |
| 1084 | |
| 1085 | static void sonypi_enable(unsigned int camera_on) |
| 1086 | { |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1087 | switch (sonypi_device.model) { |
| 1088 | case SONYPI_DEVICE_MODEL_TYPE1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | sonypi_type1_srs(); |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1090 | break; |
| 1091 | case SONYPI_DEVICE_MODEL_TYPE2: |
| 1092 | sonypi_type2_srs(); |
| 1093 | break; |
| 1094 | case SONYPI_DEVICE_MODEL_TYPE3: |
| 1095 | sonypi_type3_srs(); |
| 1096 | break; |
| 1097 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | sonypi_call1(0x82); |
| 1100 | sonypi_call2(0x81, 0xff); |
| 1101 | sonypi_call1(compat ? 0x92 : 0x82); |
| 1102 | |
| 1103 | /* Enable ACPI mode to get Fn key events */ |
| 1104 | if (!SONYPI_ACPI_ACTIVE && fnkeyinit) |
| 1105 | outb(0xf0, 0xb2); |
| 1106 | |
| 1107 | if (camera && camera_on) |
| 1108 | sonypi_camera_on(); |
| 1109 | } |
| 1110 | |
| 1111 | static int sonypi_disable(void) |
| 1112 | { |
| 1113 | sonypi_call2(0x81, 0); /* make sure we don't get any more events */ |
| 1114 | if (camera) |
| 1115 | sonypi_camera_off(); |
| 1116 | |
| 1117 | /* disable ACPI mode */ |
| 1118 | if (!SONYPI_ACPI_ACTIVE && fnkeyinit) |
| 1119 | outb(0xf1, 0xb2); |
| 1120 | |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1121 | switch (sonypi_device.model) { |
| 1122 | case SONYPI_DEVICE_MODEL_TYPE1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | sonypi_type1_dis(); |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1124 | break; |
| 1125 | case SONYPI_DEVICE_MODEL_TYPE2: |
| 1126 | sonypi_type2_dis(); |
| 1127 | break; |
| 1128 | case SONYPI_DEVICE_MODEL_TYPE3: |
| 1129 | sonypi_type3_dis(); |
| 1130 | break; |
| 1131 | } |
| 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | return 0; |
| 1134 | } |
| 1135 | |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1136 | #ifdef CONFIG_ACPI |
| 1137 | static int sonypi_acpi_add(struct acpi_device *device) |
| 1138 | { |
| 1139 | sonypi_acpi_device = device; |
| 1140 | strcpy(acpi_device_name(device), "Sony laptop hotkeys"); |
| 1141 | strcpy(acpi_device_class(device), "sony/hotkey"); |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static int sonypi_acpi_remove(struct acpi_device *device, int type) |
| 1146 | { |
| 1147 | sonypi_acpi_device = NULL; |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
Tobias Klauser | b0cdb5e | 2008-04-21 22:29:37 +0000 | [diff] [blame] | 1151 | static const struct acpi_device_id sonypi_device_ids[] = { |
Eugene Teo | f7b88cc | 2007-08-04 00:22:32 +0900 | [diff] [blame] | 1152 | {"SNY6001", 0}, |
| 1153 | {"", 0}, |
| 1154 | }; |
| 1155 | |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1156 | static struct acpi_driver sonypi_acpi_driver = { |
| 1157 | .name = "sonypi", |
| 1158 | .class = "hkey", |
Eugene Teo | f7b88cc | 2007-08-04 00:22:32 +0900 | [diff] [blame] | 1159 | .ids = sonypi_device_ids, |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1160 | .ops = { |
| 1161 | .add = sonypi_acpi_add, |
| 1162 | .remove = sonypi_acpi_remove, |
| 1163 | }, |
| 1164 | }; |
| 1165 | #endif |
| 1166 | |
Dmitry Torokhov | dcf65cd | 2007-11-21 14:16:16 -0500 | [diff] [blame] | 1167 | static int __devinit sonypi_create_input_devices(struct platform_device *pdev) |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1168 | { |
| 1169 | struct input_dev *jog_dev; |
| 1170 | struct input_dev *key_dev; |
| 1171 | int i; |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1172 | int error; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1173 | |
| 1174 | sonypi_device.input_jog_dev = jog_dev = input_allocate_device(); |
| 1175 | if (!jog_dev) |
| 1176 | return -ENOMEM; |
| 1177 | |
| 1178 | jog_dev->name = "Sony Vaio Jogdial"; |
| 1179 | jog_dev->id.bustype = BUS_ISA; |
| 1180 | jog_dev->id.vendor = PCI_VENDOR_ID_SONY; |
Dmitry Torokhov | dcf65cd | 2007-11-21 14:16:16 -0500 | [diff] [blame] | 1181 | jog_dev->dev.parent = &pdev->dev; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1182 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1183 | jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 1184 | jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE); |
| 1185 | jog_dev->relbit[0] = BIT_MASK(REL_WHEEL); |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1186 | |
| 1187 | sonypi_device.input_key_dev = key_dev = input_allocate_device(); |
| 1188 | if (!key_dev) { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1189 | error = -ENOMEM; |
| 1190 | goto err_free_jogdev; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | key_dev->name = "Sony Vaio Keys"; |
| 1194 | key_dev->id.bustype = BUS_ISA; |
| 1195 | key_dev->id.vendor = PCI_VENDOR_ID_SONY; |
Dmitry Torokhov | dcf65cd | 2007-11-21 14:16:16 -0500 | [diff] [blame] | 1196 | key_dev->dev.parent = &pdev->dev; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1197 | |
| 1198 | /* Initialize the Input Drivers: special keys */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1199 | key_dev->evbit[0] = BIT_MASK(EV_KEY); |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1200 | for (i = 0; sonypi_inputkeys[i].sonypiev; i++) |
| 1201 | if (sonypi_inputkeys[i].inputev) |
| 1202 | set_bit(sonypi_inputkeys[i].inputev, key_dev->keybit); |
| 1203 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1204 | error = input_register_device(jog_dev); |
| 1205 | if (error) |
| 1206 | goto err_free_keydev; |
| 1207 | |
| 1208 | error = input_register_device(key_dev); |
| 1209 | if (error) |
| 1210 | goto err_unregister_jogdev; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1211 | |
| 1212 | return 0; |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1213 | |
| 1214 | err_unregister_jogdev: |
| 1215 | input_unregister_device(jog_dev); |
| 1216 | /* Set to NULL so we don't free it again below */ |
| 1217 | jog_dev = NULL; |
| 1218 | err_free_keydev: |
| 1219 | input_free_device(key_dev); |
| 1220 | sonypi_device.input_key_dev = NULL; |
| 1221 | err_free_jogdev: |
| 1222 | input_free_device(jog_dev); |
| 1223 | sonypi_device.input_jog_dev = NULL; |
| 1224 | |
| 1225 | return error; |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1226 | } |
| 1227 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1228 | static int __devinit sonypi_setup_ioports(struct sonypi_device *dev, |
| 1229 | const struct sonypi_ioport_list *ioport_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | { |
malattia@linux.it | 1a3e323 | 2007-04-28 23:34:10 +0900 | [diff] [blame] | 1231 | /* try to detect if sony-laptop is being used and thus |
| 1232 | * has already requested one of the known ioports. |
| 1233 | * As in the deprecated check_region this is racy has we have |
| 1234 | * multiple ioports available and one of them can be requested |
| 1235 | * between this check and the subsequent request. Anyway, as an |
| 1236 | * attempt to be some more user-friendly as we currently are, |
| 1237 | * this is enough. |
| 1238 | */ |
| 1239 | const struct sonypi_ioport_list *check = ioport_list; |
| 1240 | while (check_ioport && check->port1) { |
| 1241 | if (!request_region(check->port1, |
| 1242 | sonypi_device.region_size, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1243 | "Sony Programmable I/O Device Check")) { |
malattia@linux.it | 1a3e323 | 2007-04-28 23:34:10 +0900 | [diff] [blame] | 1244 | printk(KERN_ERR "sonypi: ioport 0x%.4x busy, using sony-laptop? " |
| 1245 | "if not use check_ioport=0\n", |
| 1246 | check->port1); |
| 1247 | return -EBUSY; |
| 1248 | } |
| 1249 | release_region(check->port1, sonypi_device.region_size); |
| 1250 | check++; |
| 1251 | } |
| 1252 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1253 | while (ioport_list->port1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1255 | if (request_region(ioport_list->port1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | sonypi_device.region_size, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1257 | "Sony Programmable I/O Device")) { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1258 | dev->ioport1 = ioport_list->port1; |
| 1259 | dev->ioport2 = ioport_list->port2; |
| 1260 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1262 | ioport_list++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1265 | return -EBUSY; |
| 1266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1268 | static int __devinit sonypi_setup_irq(struct sonypi_device *dev, |
| 1269 | const struct sonypi_irq_list *irq_list) |
| 1270 | { |
| 1271 | while (irq_list->irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1273 | if (!request_irq(irq_list->irq, sonypi_irq, |
Thomas Gleixner | 0f2ed4c | 2006-07-01 19:29:33 -0700 | [diff] [blame] | 1274 | IRQF_SHARED, "sonypi", sonypi_irq)) { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1275 | dev->irq = irq_list->irq; |
| 1276 | dev->bits = irq_list->bits; |
| 1277 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1279 | irq_list++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1282 | return -EBUSY; |
| 1283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1285 | static void __devinit sonypi_display_info(void) |
| 1286 | { |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1287 | printk(KERN_INFO "sonypi: detected type%d model, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | "verbose = %d, fnkeyinit = %s, camera = %s, " |
| 1289 | "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n", |
Erik Waling | d2052c1 | 2005-09-06 15:17:02 -0700 | [diff] [blame] | 1290 | sonypi_device.model, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | verbose, |
| 1292 | fnkeyinit ? "on" : "off", |
| 1293 | camera ? "on" : "off", |
| 1294 | compat ? "on" : "off", |
| 1295 | mask, |
| 1296 | useinput ? "on" : "off", |
| 1297 | SONYPI_ACPI_ACTIVE ? "on" : "off"); |
| 1298 | printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n", |
| 1299 | sonypi_device.irq, |
| 1300 | sonypi_device.ioport1, sonypi_device.ioport2); |
| 1301 | |
| 1302 | if (minor == -1) |
| 1303 | printk(KERN_INFO "sonypi: device allocated minor is %d\n", |
| 1304 | sonypi_misc_device.minor); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | static int __devinit sonypi_probe(struct platform_device *dev) |
| 1308 | { |
| 1309 | const struct sonypi_ioport_list *ioport_list; |
| 1310 | const struct sonypi_irq_list *irq_list; |
| 1311 | struct pci_dev *pcidev; |
| 1312 | int error; |
| 1313 | |
malattia@linux.it | 74a882e | 2007-04-28 23:22:11 +0900 | [diff] [blame] | 1314 | printk(KERN_WARNING "sonypi: please try the sony-laptop module instead " |
| 1315 | "and report failures, see also " |
| 1316 | "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n"); |
| 1317 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1318 | spin_lock_init(&sonypi_device.fifo_lock); |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 1319 | error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1320 | if (error) { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1321 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1322 | return error; |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | init_waitqueue_head(&sonypi_device.fifo_proc_list); |
Matthias Kaehlcke | c6c6010 | 2007-04-24 22:02:35 +0200 | [diff] [blame] | 1326 | mutex_init(&sonypi_device.lock); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1327 | sonypi_device.bluetooth_power = -1; |
| 1328 | |
| 1329 | if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1330 | PCI_DEVICE_ID_INTEL_82371AB_3, NULL))) |
| 1331 | sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1; |
| 1332 | else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1333 | PCI_DEVICE_ID_INTEL_ICH6_1, NULL))) |
| 1334 | sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3; |
Arnaud MAZIN | bf104e6 | 2006-04-20 02:43:20 -0700 | [diff] [blame] | 1335 | else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1336 | PCI_DEVICE_ID_INTEL_ICH7_1, NULL))) |
| 1337 | sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3; |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1338 | else |
| 1339 | sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2; |
| 1340 | |
| 1341 | if (pcidev && pci_enable_device(pcidev)) { |
| 1342 | printk(KERN_ERR "sonypi: pci_enable_device failed\n"); |
| 1343 | error = -EIO; |
| 1344 | goto err_put_pcidev; |
| 1345 | } |
| 1346 | |
| 1347 | sonypi_device.dev = pcidev; |
| 1348 | |
| 1349 | if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) { |
| 1350 | ioport_list = sonypi_type1_ioport_list; |
| 1351 | sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE; |
| 1352 | sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET; |
| 1353 | irq_list = sonypi_type1_irq_list; |
| 1354 | } else if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) { |
| 1355 | ioport_list = sonypi_type2_ioport_list; |
| 1356 | sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE; |
| 1357 | sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET; |
| 1358 | irq_list = sonypi_type2_irq_list; |
| 1359 | } else { |
| 1360 | ioport_list = sonypi_type3_ioport_list; |
| 1361 | sonypi_device.region_size = SONYPI_TYPE3_REGION_SIZE; |
| 1362 | sonypi_device.evtype_offset = SONYPI_TYPE3_EVTYPE_OFFSET; |
| 1363 | irq_list = sonypi_type3_irq_list; |
| 1364 | } |
| 1365 | |
| 1366 | error = sonypi_setup_ioports(&sonypi_device, ioport_list); |
| 1367 | if (error) { |
| 1368 | printk(KERN_ERR "sonypi: failed to request ioports\n"); |
| 1369 | goto err_disable_pcidev; |
| 1370 | } |
| 1371 | |
| 1372 | error = sonypi_setup_irq(&sonypi_device, irq_list); |
| 1373 | if (error) { |
| 1374 | printk(KERN_ERR "sonypi: request_irq failed\n"); |
| 1375 | goto err_free_ioports; |
| 1376 | } |
| 1377 | |
| 1378 | if (minor != -1) |
| 1379 | sonypi_misc_device.minor = minor; |
| 1380 | error = misc_register(&sonypi_misc_device); |
| 1381 | if (error) { |
| 1382 | printk(KERN_ERR "sonypi: misc_register failed\n"); |
| 1383 | goto err_free_irq; |
| 1384 | } |
| 1385 | |
| 1386 | sonypi_display_info(); |
| 1387 | |
| 1388 | if (useinput) { |
| 1389 | |
Dmitry Torokhov | dcf65cd | 2007-11-21 14:16:16 -0500 | [diff] [blame] | 1390 | error = sonypi_create_input_devices(dev); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1391 | if (error) { |
| 1392 | printk(KERN_ERR |
| 1393 | "sonypi: failed to create input devices\n"); |
| 1394 | goto err_miscdev_unregister; |
| 1395 | } |
| 1396 | |
| 1397 | spin_lock_init(&sonypi_device.input_fifo_lock); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1398 | error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 1399 | GFP_KERNEL); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1400 | if (error) { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1401 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1402 | goto err_inpdev_unregister; |
| 1403 | } |
| 1404 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1405 | INIT_WORK(&sonypi_device.input_work, input_keyrelease); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | sonypi_enable(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
| 1410 | return 0; |
| 1411 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1412 | err_inpdev_unregister: |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1413 | input_unregister_device(sonypi_device.input_key_dev); |
| 1414 | input_unregister_device(sonypi_device.input_jog_dev); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1415 | err_miscdev_unregister: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | misc_deregister(&sonypi_misc_device); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1417 | err_free_irq: |
| 1418 | free_irq(sonypi_device.irq, sonypi_irq); |
| 1419 | err_free_ioports: |
| 1420 | release_region(sonypi_device.ioport1, sonypi_device.region_size); |
| 1421 | err_disable_pcidev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | if (pcidev) |
| 1423 | pci_disable_device(pcidev); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1424 | err_put_pcidev: |
| 1425 | pci_dev_put(pcidev); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1426 | kfifo_free(&sonypi_device.fifo); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1427 | |
| 1428 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1431 | static int __devexit sonypi_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | { |
| 1433 | sonypi_disable(); |
| 1434 | |
Dmitry Torokhov | 3cb93db | 2007-11-21 14:16:38 -0500 | [diff] [blame] | 1435 | synchronize_irq(sonypi_device.irq); |
Tejun Heo | 3514870 | 2010-12-24 15:59:07 +0100 | [diff] [blame] | 1436 | flush_work_sync(&sonypi_device.input_work); |
Dmitry Torokhov | fb2ce3c | 2005-06-30 00:50:10 -0500 | [diff] [blame] | 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | if (useinput) { |
Dmitry Torokhov | b416f2e | 2005-09-15 02:01:50 -0500 | [diff] [blame] | 1439 | input_unregister_device(sonypi_device.input_key_dev); |
| 1440 | input_unregister_device(sonypi_device.input_jog_dev); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1441 | kfifo_free(&sonypi_device.input_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1444 | misc_deregister(&sonypi_misc_device); |
| 1445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | free_irq(sonypi_device.irq, sonypi_irq); |
| 1447 | release_region(sonypi_device.ioport1, sonypi_device.region_size); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1448 | |
| 1449 | if (sonypi_device.dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | pci_disable_device(sonypi_device.dev); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1451 | pci_dev_put(sonypi_device.dev); |
| 1452 | } |
| 1453 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 1454 | kfifo_free(&sonypi_device.fifo); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1455 | |
| 1456 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1459 | #ifdef CONFIG_PM |
| 1460 | static int old_camera_power; |
| 1461 | |
Rafael J. Wysocki | 199ac05 | 2012-06-27 23:20:29 +0200 | [diff] [blame] | 1462 | static int sonypi_suspend(struct device *dev) |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1463 | { |
| 1464 | old_camera_power = sonypi_device.camera_power; |
| 1465 | sonypi_disable(); |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
Rafael J. Wysocki | 199ac05 | 2012-06-27 23:20:29 +0200 | [diff] [blame] | 1470 | static int sonypi_resume(struct device *dev) |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1471 | { |
| 1472 | sonypi_enable(old_camera_power); |
| 1473 | return 0; |
| 1474 | } |
Rafael J. Wysocki | 199ac05 | 2012-06-27 23:20:29 +0200 | [diff] [blame] | 1475 | |
| 1476 | static SIMPLE_DEV_PM_OPS(sonypi_pm, sonypi_suspend, sonypi_resume); |
| 1477 | #define SONYPI_PM (&sonypi_pm) |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1478 | #else |
Rafael J. Wysocki | 199ac05 | 2012-06-27 23:20:29 +0200 | [diff] [blame] | 1479 | #define SONYPI_PM NULL |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1480 | #endif |
| 1481 | |
| 1482 | static void sonypi_shutdown(struct platform_device *dev) |
| 1483 | { |
| 1484 | sonypi_disable(); |
| 1485 | } |
| 1486 | |
| 1487 | static struct platform_driver sonypi_driver = { |
| 1488 | .driver = { |
| 1489 | .name = "sonypi", |
| 1490 | .owner = THIS_MODULE, |
Rafael J. Wysocki | 199ac05 | 2012-06-27 23:20:29 +0200 | [diff] [blame] | 1491 | .pm = SONYPI_PM, |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1492 | }, |
| 1493 | .probe = sonypi_probe, |
| 1494 | .remove = __devexit_p(sonypi_remove), |
| 1495 | .shutdown = sonypi_shutdown, |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1496 | }; |
| 1497 | |
| 1498 | static struct platform_device *sonypi_platform_device; |
| 1499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | static struct dmi_system_id __initdata sonypi_dmi_table[] = { |
| 1501 | { |
| 1502 | .ident = "Sony Vaio", |
| 1503 | .matches = { |
| 1504 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 1505 | DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"), |
| 1506 | }, |
| 1507 | }, |
| 1508 | { |
| 1509 | .ident = "Sony Vaio", |
| 1510 | .matches = { |
| 1511 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 1512 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"), |
| 1513 | }, |
| 1514 | }, |
| 1515 | { } |
| 1516 | }; |
| 1517 | |
| 1518 | static int __init sonypi_init(void) |
| 1519 | { |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1520 | int error; |
| 1521 | |
| 1522 | printk(KERN_INFO |
| 1523 | "sonypi: Sony Programmable I/O Controller Driver v%s.\n", |
| 1524 | SONYPI_DRIVER_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
| 1526 | if (!dmi_check_system(sonypi_dmi_table)) |
| 1527 | return -ENODEV; |
| 1528 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1529 | error = platform_driver_register(&sonypi_driver); |
| 1530 | if (error) |
| 1531 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1533 | sonypi_platform_device = platform_device_alloc("sonypi", -1); |
| 1534 | if (!sonypi_platform_device) { |
| 1535 | error = -ENOMEM; |
| 1536 | goto err_driver_unregister; |
| 1537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1539 | error = platform_device_add(sonypi_platform_device); |
| 1540 | if (error) |
| 1541 | goto err_free_device; |
| 1542 | |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1543 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | e4513a5 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1544 | if (acpi_bus_register_driver(&sonypi_acpi_driver) >= 0) |
| 1545 | acpi_driver_registered = 1; |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1546 | #endif |
| 1547 | |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1548 | return 0; |
| 1549 | |
| 1550 | err_free_device: |
| 1551 | platform_device_put(sonypi_platform_device); |
| 1552 | err_driver_unregister: |
| 1553 | platform_driver_unregister(&sonypi_driver); |
| 1554 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | static void __exit sonypi_exit(void) |
| 1558 | { |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1559 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | e4513a5 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 1560 | if (acpi_driver_registered) |
Ben Collins | b368fae | 2006-01-08 01:04:24 -0800 | [diff] [blame] | 1561 | acpi_bus_unregister_driver(&sonypi_acpi_driver); |
| 1562 | #endif |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1563 | platform_device_unregister(sonypi_platform_device); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1564 | platform_driver_unregister(&sonypi_driver); |
Dmitry Torokhov | 44f0610 | 2006-01-08 01:04:22 -0800 | [diff] [blame] | 1565 | printk(KERN_INFO "sonypi: removed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | module_init(sonypi_init); |
| 1569 | module_exit(sonypi_exit); |