Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1 | /* |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2 | * ACPI Sony Notebook Control Driver (SNC and SPIC) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net> |
Mattia Dongili | 3741834 | 2009-03-26 21:58:24 +0900 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 Mattia Dongili <malattia@linux.it> |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 6 | * |
| 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.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 10 | * 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 Garski | db955170 | 2007-10-19 23:22:11 +0200 | [diff] [blame] | 17 | * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com> |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 18 | * |
| 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 Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 29 | * This program is free software; you can redistribute it and/or modify |
| 30 | * it under the terms of the GNU General Public License as published by |
| 31 | * the Free Software Foundation; either version 2 of the License, or |
| 32 | * (at your option) any later version. |
| 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> |
| 49 | #include <linux/types.h> |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 50 | #include <linux/backlight.h> |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 51 | #include <linux/platform_device.h> |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 52 | #include <linux/err.h> |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 53 | #include <linux/dmi.h> |
| 54 | #include <linux/pci.h> |
| 55 | #include <linux/interrupt.h> |
| 56 | #include <linux/delay.h> |
| 57 | #include <linux/input.h> |
| 58 | #include <linux/kfifo.h> |
| 59 | #include <linux/workqueue.h> |
| 60 | #include <linux/acpi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 61 | #include <linux/slab.h> |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 62 | #include <acpi/acpi_drivers.h> |
| 63 | #include <acpi/acpi_bus.h> |
| 64 | #include <asm/uaccess.h> |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 65 | #include <linux/sonypi.h> |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 66 | #include <linux/sony-laptop.h> |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 67 | #include <linux/rfkill.h> |
Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 68 | #ifdef CONFIG_SONYPI_COMPAT |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 69 | #include <linux/poll.h> |
| 70 | #include <linux/miscdevice.h> |
| 71 | #endif |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 72 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 73 | #define DRV_PFX "sony-laptop: " |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 74 | #define dprintk(msg...) do { \ |
| 75 | if (debug) \ |
| 76 | pr_warn(DRV_PFX msg); \ |
malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 77 | } while (0) |
| 78 | |
Mattia Dongili | 425ef5d | 2008-01-14 18:05:44 +0900 | [diff] [blame] | 79 | #define SONY_LAPTOP_DRIVER_VERSION "0.6" |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 80 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 81 | #define SONY_NC_CLASS "sony-nc" |
| 82 | #define SONY_NC_HID "SNY5001" |
malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 83 | #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver" |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 84 | |
| 85 | #define SONY_PIC_CLASS "sony-pic" |
| 86 | #define SONY_PIC_HID "SNY6001" |
malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 87 | #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver" |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 88 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 89 | MODULE_AUTHOR("Stelian Pop, Mattia Dongili"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 90 | MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 91 | MODULE_LICENSE("GPL"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 92 | MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 93 | |
| 94 | static int debug; |
| 95 | module_param(debug, int, 0); |
| 96 | MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help " |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 97 | "the development of this driver"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 98 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 99 | static int no_spic; /* = 0 */ |
| 100 | module_param(no_spic, int, 0444); |
| 101 | MODULE_PARM_DESC(no_spic, |
| 102 | "set this if you don't want to enable the SPIC device"); |
| 103 | |
| 104 | static int compat; /* = 0 */ |
| 105 | module_param(compat, int, 0444); |
| 106 | MODULE_PARM_DESC(compat, |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 107 | "set this if you want to enable backward compatibility mode"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 108 | |
| 109 | static unsigned long mask = 0xffffffff; |
| 110 | module_param(mask, ulong, 0644); |
| 111 | MODULE_PARM_DESC(mask, |
| 112 | "set this to the mask of event you want to enable (see doc)"); |
| 113 | |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 114 | static int camera; /* = 0 */ |
| 115 | module_param(camera, int, 0444); |
| 116 | MODULE_PARM_DESC(camera, |
| 117 | "set this to 1 to enable Motion Eye camera controls " |
| 118 | "(only use it if you have a C1VE or C1VN model)"); |
| 119 | |
Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 120 | #ifdef CONFIG_SONYPI_COMPAT |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 121 | static int minor = -1; |
| 122 | module_param(minor, int, 0); |
| 123 | MODULE_PARM_DESC(minor, |
| 124 | "minor number of the misc device for the SPIC compatibility code, " |
| 125 | "default is -1 (automatic)"); |
| 126 | #endif |
| 127 | |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 128 | static int kbd_backlight; /* = 1 */ |
| 129 | module_param(kbd_backlight, int, 0444); |
| 130 | MODULE_PARM_DESC(kbd_backlight, |
| 131 | "set this to 0 to disable keyboard backlight, " |
| 132 | "1 to enable it (default: 0)"); |
| 133 | |
| 134 | static int kbd_backlight_timeout; /* = 0 */ |
| 135 | module_param(kbd_backlight_timeout, int, 0444); |
| 136 | MODULE_PARM_DESC(kbd_backlight_timeout, |
| 137 | "set this to 0 to set the default 10 seconds timeout, " |
| 138 | "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout " |
| 139 | "(default: 0)"); |
| 140 | |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 141 | enum sony_nc_rfkill { |
| 142 | SONY_WIFI, |
| 143 | SONY_BLUETOOTH, |
| 144 | SONY_WWAN, |
| 145 | SONY_WIMAX, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 146 | N_SONY_RFKILL, |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 147 | }; |
| 148 | |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 149 | static int sony_rfkill_handle; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 150 | static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL]; |
| 151 | static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900}; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 152 | static void sony_nc_rfkill_update(void); |
| 153 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 154 | /*********** Input Devices ***********/ |
| 155 | |
| 156 | #define SONY_LAPTOP_BUF_SIZE 128 |
| 157 | struct sony_laptop_input_s { |
| 158 | atomic_t users; |
| 159 | struct input_dev *jog_dev; |
| 160 | struct input_dev *key_dev; |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 161 | struct kfifo fifo; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 162 | spinlock_t fifo_lock; |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 163 | struct timer_list release_key_timer; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 164 | }; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 165 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 166 | static struct sony_laptop_input_s sony_laptop_input = { |
| 167 | .users = ATOMIC_INIT(0), |
| 168 | }; |
| 169 | |
| 170 | struct sony_laptop_keypress { |
| 171 | struct input_dev *dev; |
| 172 | int key; |
| 173 | }; |
| 174 | |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 175 | /* Correspondance table between sonypi events |
| 176 | * and input layer indexes in the keymap |
| 177 | */ |
| 178 | static int sony_laptop_input_index[] = { |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 179 | -1, /* 0 no event */ |
| 180 | -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */ |
| 181 | -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */ |
| 182 | -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */ |
| 183 | -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */ |
| 184 | -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */ |
| 185 | -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */ |
| 186 | 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */ |
| 187 | 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */ |
| 188 | 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ |
| 189 | 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ |
| 190 | 4, /* 11 SONYPI_EVENT_FNKEY_ESC */ |
| 191 | 5, /* 12 SONYPI_EVENT_FNKEY_F1 */ |
| 192 | 6, /* 13 SONYPI_EVENT_FNKEY_F2 */ |
| 193 | 7, /* 14 SONYPI_EVENT_FNKEY_F3 */ |
| 194 | 8, /* 15 SONYPI_EVENT_FNKEY_F4 */ |
| 195 | 9, /* 16 SONYPI_EVENT_FNKEY_F5 */ |
| 196 | 10, /* 17 SONYPI_EVENT_FNKEY_F6 */ |
| 197 | 11, /* 18 SONYPI_EVENT_FNKEY_F7 */ |
| 198 | 12, /* 19 SONYPI_EVENT_FNKEY_F8 */ |
| 199 | 13, /* 20 SONYPI_EVENT_FNKEY_F9 */ |
| 200 | 14, /* 21 SONYPI_EVENT_FNKEY_F10 */ |
| 201 | 15, /* 22 SONYPI_EVENT_FNKEY_F11 */ |
| 202 | 16, /* 23 SONYPI_EVENT_FNKEY_F12 */ |
| 203 | 17, /* 24 SONYPI_EVENT_FNKEY_1 */ |
| 204 | 18, /* 25 SONYPI_EVENT_FNKEY_2 */ |
| 205 | 19, /* 26 SONYPI_EVENT_FNKEY_D */ |
| 206 | 20, /* 27 SONYPI_EVENT_FNKEY_E */ |
| 207 | 21, /* 28 SONYPI_EVENT_FNKEY_F */ |
| 208 | 22, /* 29 SONYPI_EVENT_FNKEY_S */ |
| 209 | 23, /* 30 SONYPI_EVENT_FNKEY_B */ |
| 210 | 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */ |
| 211 | 25, /* 32 SONYPI_EVENT_PKEY_P1 */ |
| 212 | 26, /* 33 SONYPI_EVENT_PKEY_P2 */ |
| 213 | 27, /* 34 SONYPI_EVENT_PKEY_P3 */ |
| 214 | 28, /* 35 SONYPI_EVENT_BACK_PRESSED */ |
| 215 | -1, /* 36 SONYPI_EVENT_LID_CLOSED */ |
| 216 | -1, /* 37 SONYPI_EVENT_LID_OPENED */ |
| 217 | 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */ |
| 218 | 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */ |
| 219 | 31, /* 40 SONYPI_EVENT_HELP_PRESSED */ |
| 220 | 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */ |
| 221 | 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */ |
| 222 | 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */ |
| 223 | 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ |
| 224 | 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ |
| 225 | 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ |
| 226 | 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */ |
| 227 | 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ |
| 228 | 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ |
| 229 | 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */ |
| 230 | 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */ |
| 231 | 43, /* 52 SONYPI_EVENT_MEYE_FACE */ |
| 232 | 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */ |
| 233 | 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */ |
| 234 | 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */ |
| 235 | -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */ |
| 236 | -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */ |
| 237 | -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */ |
| 238 | -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */ |
| 239 | 47, /* 60 SONYPI_EVENT_WIRELESS_ON */ |
| 240 | 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */ |
| 241 | 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */ |
| 242 | 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */ |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 243 | 51, /* 64 SONYPI_EVENT_CD_EJECT_PRESSED */ |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 244 | 52, /* 65 SONYPI_EVENT_MODEKEY_PRESSED */ |
| 245 | 53, /* 66 SONYPI_EVENT_PKEY_P4 */ |
| 246 | 54, /* 67 SONYPI_EVENT_PKEY_P5 */ |
| 247 | 55, /* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */ |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 248 | 56, /* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */ |
| 249 | 57, /* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */ |
| 250 | -1, /* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */ |
Mattia Dongili | 4f924ba | 2009-12-17 00:08:33 +0900 | [diff] [blame] | 251 | 58, /* 72 SONYPI_EVENT_MEDIA_PRESSED */ |
Mattia Dongili | 1a7d946 | 2011-01-08 18:47:29 +0900 | [diff] [blame] | 252 | 59, /* 72 SONYPI_EVENT_VENDOR_PRESSED */ |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static int sony_laptop_input_keycode_map[] = { |
| 256 | KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */ |
| 257 | KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */ |
| 258 | KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ |
| 259 | KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ |
| 260 | KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */ |
| 261 | KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */ |
| 262 | KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */ |
| 263 | KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */ |
| 264 | KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */ |
| 265 | KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */ |
| 266 | KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */ |
| 267 | KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */ |
| 268 | KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */ |
| 269 | KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */ |
| 270 | KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */ |
| 271 | KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */ |
| 272 | KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */ |
| 273 | KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */ |
| 274 | KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */ |
| 275 | KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */ |
| 276 | KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */ |
| 277 | KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */ |
| 278 | KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */ |
| 279 | KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */ |
| 280 | KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */ |
| 281 | KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */ |
| 282 | KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */ |
| 283 | KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */ |
| 284 | KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */ |
| 285 | KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */ |
| 286 | KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */ |
| 287 | KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */ |
| 288 | KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */ |
| 289 | KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */ |
| 290 | KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */ |
| 291 | KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ |
| 292 | KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ |
| 293 | KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ |
| 294 | KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */ |
| 295 | KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ |
| 296 | KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ |
| 297 | KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */ |
| 298 | BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */ |
| 299 | KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */ |
| 300 | KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */ |
| 301 | KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */ |
| 302 | KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */ |
| 303 | KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */ |
| 304 | KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */ |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 305 | KEY_ZOOMIN, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */ |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 306 | KEY_ZOOMOUT, /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */ |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 307 | KEY_EJECTCD, /* 51 SONYPI_EVENT_CD_EJECT_PRESSED */ |
| 308 | KEY_F13, /* 52 SONYPI_EVENT_MODEKEY_PRESSED */ |
| 309 | KEY_PROG4, /* 53 SONYPI_EVENT_PKEY_P4 */ |
| 310 | KEY_F14, /* 54 SONYPI_EVENT_PKEY_P5 */ |
| 311 | KEY_F15, /* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */ |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 312 | KEY_VOLUMEUP, /* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */ |
| 313 | KEY_VOLUMEDOWN, /* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */ |
Mattia Dongili | 4f924ba | 2009-12-17 00:08:33 +0900 | [diff] [blame] | 314 | KEY_MEDIA, /* 58 SONYPI_EVENT_MEDIA_PRESSED */ |
Mattia Dongili | 1a7d946 | 2011-01-08 18:47:29 +0900 | [diff] [blame] | 315 | KEY_VENDOR, /* 59 SONYPI_EVENT_VENDOR_PRESSED */ |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | /* release buttons after a short delay if pressed */ |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 319 | static void do_sony_laptop_release_key(unsigned long unused) |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 320 | { |
| 321 | struct sony_laptop_keypress kp; |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 322 | unsigned long flags; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 323 | |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 324 | spin_lock_irqsave(&sony_laptop_input.fifo_lock, flags); |
| 325 | |
| 326 | if (kfifo_out(&sony_laptop_input.fifo, |
| 327 | (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) { |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 328 | input_report_key(kp.dev, kp.key, 0); |
| 329 | input_sync(kp.dev); |
| 330 | } |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 331 | |
| 332 | /* If there is something in the fifo schedule next release. */ |
| 333 | if (kfifo_len(&sony_laptop_input.fifo) != 0) |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 334 | mod_timer(&sony_laptop_input.release_key_timer, |
| 335 | jiffies + msecs_to_jiffies(10)); |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 336 | |
| 337 | spin_unlock_irqrestore(&sony_laptop_input.fifo_lock, flags); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 338 | } |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 339 | |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 340 | /* forward event to the input subsystem */ |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 341 | static void sony_laptop_report_input_event(u8 event) |
| 342 | { |
| 343 | struct input_dev *jog_dev = sony_laptop_input.jog_dev; |
| 344 | struct input_dev *key_dev = sony_laptop_input.key_dev; |
| 345 | struct sony_laptop_keypress kp = { NULL }; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 346 | |
Almer S. Tigelaar | a83021a | 2009-04-12 11:26:28 +0000 | [diff] [blame] | 347 | if (event == SONYPI_EVENT_FNKEY_RELEASED || |
| 348 | event == SONYPI_EVENT_ANYBUTTON_RELEASED) { |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 349 | /* Nothing, not all VAIOs generate this event */ |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | /* report events */ |
| 354 | switch (event) { |
| 355 | /* jog_dev events */ |
| 356 | case SONYPI_EVENT_JOGDIAL_UP: |
| 357 | case SONYPI_EVENT_JOGDIAL_UP_PRESSED: |
| 358 | input_report_rel(jog_dev, REL_WHEEL, 1); |
| 359 | input_sync(jog_dev); |
| 360 | return; |
| 361 | |
| 362 | case SONYPI_EVENT_JOGDIAL_DOWN: |
| 363 | case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED: |
| 364 | input_report_rel(jog_dev, REL_WHEEL, -1); |
| 365 | input_sync(jog_dev); |
| 366 | return; |
| 367 | |
| 368 | /* key_dev events */ |
| 369 | case SONYPI_EVENT_JOGDIAL_PRESSED: |
| 370 | kp.key = BTN_MIDDLE; |
| 371 | kp.dev = jog_dev; |
| 372 | break; |
| 373 | |
| 374 | default: |
Adrian Bunk | d399d13 | 2008-02-20 00:59:03 +0200 | [diff] [blame] | 375 | if (event >= ARRAY_SIZE(sony_laptop_input_index)) { |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 376 | dprintk("sony_laptop_report_input_event, event not known: %d\n", event); |
| 377 | break; |
| 378 | } |
| 379 | if (sony_laptop_input_index[event] != -1) { |
| 380 | kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]]; |
| 381 | if (kp.key != KEY_UNKNOWN) |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 382 | kp.dev = key_dev; |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 383 | } |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | |
| 387 | if (kp.dev) { |
| 388 | input_report_key(kp.dev, kp.key, 1); |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 389 | /* we emit the scancode so we can always remap the key */ |
| 390 | input_event(kp.dev, EV_MSC, MSC_SCAN, event); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 391 | input_sync(kp.dev); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 392 | |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 393 | /* schedule key release */ |
| 394 | kfifo_in_locked(&sony_laptop_input.fifo, |
| 395 | (unsigned char *)&kp, sizeof(kp), |
| 396 | &sony_laptop_input.fifo_lock); |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 397 | mod_timer(&sony_laptop_input.release_key_timer, |
| 398 | jiffies + msecs_to_jiffies(10)); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 399 | } else |
| 400 | dprintk("unknown input event %.2x\n", event); |
| 401 | } |
| 402 | |
Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 403 | static int sony_laptop_setup_input(struct acpi_device *acpi_device) |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 404 | { |
| 405 | struct input_dev *jog_dev; |
| 406 | struct input_dev *key_dev; |
| 407 | int i; |
| 408 | int error; |
| 409 | |
| 410 | /* don't run again if already initialized */ |
| 411 | if (atomic_add_return(1, &sony_laptop_input.users) > 1) |
| 412 | return 0; |
| 413 | |
| 414 | /* kfifo */ |
| 415 | spin_lock_init(&sony_laptop_input.fifo_lock); |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 416 | error = kfifo_alloc(&sony_laptop_input.fifo, |
| 417 | SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 418 | if (error) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 419 | pr_err(DRV_PFX "kfifo_alloc failed\n"); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 420 | goto err_dec_users; |
| 421 | } |
| 422 | |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 423 | setup_timer(&sony_laptop_input.release_key_timer, |
| 424 | do_sony_laptop_release_key, 0); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 425 | |
| 426 | /* input keys */ |
| 427 | key_dev = input_allocate_device(); |
| 428 | if (!key_dev) { |
| 429 | error = -ENOMEM; |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 430 | goto err_free_kfifo; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | key_dev->name = "Sony Vaio Keys"; |
| 434 | key_dev->id.bustype = BUS_ISA; |
| 435 | key_dev->id.vendor = PCI_VENDOR_ID_SONY; |
Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 436 | key_dev->dev.parent = &acpi_device->dev; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 437 | |
| 438 | /* Initialize the Input Drivers: special keys */ |
Dmitry Torokhov | c45bc9d | 2009-12-24 00:02:23 -0800 | [diff] [blame] | 439 | input_set_capability(key_dev, EV_MSC, MSC_SCAN); |
| 440 | |
| 441 | __set_bit(EV_KEY, key_dev->evbit); |
Mattia Dongili | bc57f86 | 2007-07-20 02:01:57 +0900 | [diff] [blame] | 442 | key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]); |
| 443 | key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map); |
| 444 | key_dev->keycode = &sony_laptop_input_keycode_map; |
Dmitry Torokhov | c45bc9d | 2009-12-24 00:02:23 -0800 | [diff] [blame] | 445 | for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) |
| 446 | __set_bit(sony_laptop_input_keycode_map[i], key_dev->keybit); |
| 447 | __clear_bit(KEY_RESERVED, key_dev->keybit); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 448 | |
| 449 | error = input_register_device(key_dev); |
| 450 | if (error) |
| 451 | goto err_free_keydev; |
| 452 | |
| 453 | sony_laptop_input.key_dev = key_dev; |
| 454 | |
| 455 | /* jogdial */ |
| 456 | jog_dev = input_allocate_device(); |
| 457 | if (!jog_dev) { |
| 458 | error = -ENOMEM; |
| 459 | goto err_unregister_keydev; |
| 460 | } |
| 461 | |
| 462 | jog_dev->name = "Sony Vaio Jogdial"; |
| 463 | jog_dev->id.bustype = BUS_ISA; |
| 464 | jog_dev->id.vendor = PCI_VENDOR_ID_SONY; |
Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 465 | key_dev->dev.parent = &acpi_device->dev; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 466 | |
Dmitry Torokhov | c45bc9d | 2009-12-24 00:02:23 -0800 | [diff] [blame] | 467 | input_set_capability(jog_dev, EV_KEY, BTN_MIDDLE); |
| 468 | input_set_capability(jog_dev, EV_REL, REL_WHEEL); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 469 | |
| 470 | error = input_register_device(jog_dev); |
| 471 | if (error) |
| 472 | goto err_free_jogdev; |
| 473 | |
| 474 | sony_laptop_input.jog_dev = jog_dev; |
| 475 | |
| 476 | return 0; |
| 477 | |
| 478 | err_free_jogdev: |
| 479 | input_free_device(jog_dev); |
| 480 | |
| 481 | err_unregister_keydev: |
| 482 | input_unregister_device(key_dev); |
| 483 | /* to avoid kref underflow below at input_free_device */ |
| 484 | key_dev = NULL; |
| 485 | |
| 486 | err_free_keydev: |
| 487 | input_free_device(key_dev); |
| 488 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 489 | err_free_kfifo: |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 490 | kfifo_free(&sony_laptop_input.fifo); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 491 | |
| 492 | err_dec_users: |
| 493 | atomic_dec(&sony_laptop_input.users); |
| 494 | return error; |
| 495 | } |
| 496 | |
| 497 | static void sony_laptop_remove_input(void) |
| 498 | { |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 499 | struct sony_laptop_keypress kp = { NULL }; |
| 500 | |
| 501 | /* Cleanup only after the last user has gone */ |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 502 | if (!atomic_dec_and_test(&sony_laptop_input.users)) |
| 503 | return; |
| 504 | |
Dmitry Torokhov | cffdde9 | 2009-12-24 00:02:30 -0800 | [diff] [blame] | 505 | del_timer_sync(&sony_laptop_input.release_key_timer); |
Dmitry Torokhov | 9593bd0 | 2009-12-24 00:02:16 -0800 | [diff] [blame] | 506 | |
| 507 | /* |
| 508 | * Generate key-up events for remaining keys. Note that we don't |
| 509 | * need locking since nobody is adding new events to the kfifo. |
| 510 | */ |
| 511 | while (kfifo_out(&sony_laptop_input.fifo, |
| 512 | (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) { |
| 513 | input_report_key(kp.dev, kp.key, 0); |
| 514 | input_sync(kp.dev); |
| 515 | } |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 516 | |
| 517 | /* destroy input devs */ |
| 518 | input_unregister_device(sony_laptop_input.key_dev); |
| 519 | sony_laptop_input.key_dev = NULL; |
| 520 | |
| 521 | if (sony_laptop_input.jog_dev) { |
| 522 | input_unregister_device(sony_laptop_input.jog_dev); |
| 523 | sony_laptop_input.jog_dev = NULL; |
| 524 | } |
| 525 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 526 | kfifo_free(&sony_laptop_input.fifo); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 527 | } |
| 528 | |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 529 | /*********** Platform Device ***********/ |
| 530 | |
| 531 | static atomic_t sony_pf_users = ATOMIC_INIT(0); |
| 532 | static struct platform_driver sony_pf_driver = { |
| 533 | .driver = { |
| 534 | .name = "sony-laptop", |
| 535 | .owner = THIS_MODULE, |
| 536 | } |
| 537 | }; |
| 538 | static struct platform_device *sony_pf_device; |
| 539 | |
| 540 | static int sony_pf_add(void) |
| 541 | { |
| 542 | int ret = 0; |
| 543 | |
| 544 | /* don't run again if already initialized */ |
| 545 | if (atomic_add_return(1, &sony_pf_users) > 1) |
| 546 | return 0; |
| 547 | |
| 548 | ret = platform_driver_register(&sony_pf_driver); |
| 549 | if (ret) |
| 550 | goto out; |
| 551 | |
| 552 | sony_pf_device = platform_device_alloc("sony-laptop", -1); |
| 553 | if (!sony_pf_device) { |
| 554 | ret = -ENOMEM; |
| 555 | goto out_platform_registered; |
| 556 | } |
| 557 | |
| 558 | ret = platform_device_add(sony_pf_device); |
| 559 | if (ret) |
| 560 | goto out_platform_alloced; |
| 561 | |
| 562 | return 0; |
| 563 | |
| 564 | out_platform_alloced: |
| 565 | platform_device_put(sony_pf_device); |
| 566 | sony_pf_device = NULL; |
| 567 | out_platform_registered: |
| 568 | platform_driver_unregister(&sony_pf_driver); |
| 569 | out: |
| 570 | atomic_dec(&sony_pf_users); |
| 571 | return ret; |
| 572 | } |
| 573 | |
| 574 | static void sony_pf_remove(void) |
| 575 | { |
| 576 | /* deregister only after the last user has gone */ |
| 577 | if (!atomic_dec_and_test(&sony_pf_users)) |
| 578 | return; |
| 579 | |
Axel Lin | 08db2b3 | 2010-07-01 10:18:01 +0800 | [diff] [blame] | 580 | platform_device_unregister(sony_pf_device); |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 581 | platform_driver_unregister(&sony_pf_driver); |
| 582 | } |
| 583 | |
| 584 | /*********** SNC (SNY5001) Device ***********/ |
| 585 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 586 | /* the device uses 1-based values, while the backlight subsystem uses |
| 587 | 0-based values */ |
| 588 | #define SONY_MAX_BRIGHTNESS 8 |
| 589 | |
| 590 | #define SNC_VALIDATE_IN 0 |
| 591 | #define SNC_VALIDATE_OUT 1 |
| 592 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 593 | static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 594 | char *); |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 595 | static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 596 | const char *, size_t); |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 597 | static int boolean_validate(const int, const int); |
| 598 | static int brightness_default_validate(const int, const int); |
| 599 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 600 | struct sony_nc_value { |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 601 | char *name; /* name of the entry */ |
| 602 | char **acpiget; /* names of the ACPI get function */ |
| 603 | char **acpiset; /* names of the ACPI set function */ |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 604 | int (*validate)(const int, const int); /* input/output validation */ |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 605 | int value; /* current setting */ |
| 606 | int valid; /* Has ever been set */ |
| 607 | int debug; /* active only in debug mode ? */ |
| 608 | struct device_attribute devattr; /* sysfs atribute */ |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 609 | }; |
| 610 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 611 | #define SNC_HANDLE_NAMES(_name, _values...) \ |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 612 | static char *snc_##_name[] = { _values, NULL } |
| 613 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 614 | #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \ |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 615 | { \ |
| 616 | .name = __stringify(_name), \ |
| 617 | .acpiget = _getters, \ |
| 618 | .acpiset = _setters, \ |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 619 | .validate = _validate, \ |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 620 | .debug = _debug, \ |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 621 | .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \ |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 622 | } |
| 623 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 624 | #define SNC_HANDLE_NULL { .name = NULL } |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 625 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 626 | SNC_HANDLE_NAMES(fnkey_get, "GHKE"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 627 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 628 | SNC_HANDLE_NAMES(brightness_def_get, "GPBR"); |
| 629 | SNC_HANDLE_NAMES(brightness_def_set, "SPBR"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 630 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 631 | SNC_HANDLE_NAMES(cdpower_get, "GCDP"); |
| 632 | SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 633 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 634 | SNC_HANDLE_NAMES(audiopower_get, "GAZP"); |
| 635 | SNC_HANDLE_NAMES(audiopower_set, "AZPW"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 636 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 637 | SNC_HANDLE_NAMES(lanpower_get, "GLNP"); |
| 638 | SNC_HANDLE_NAMES(lanpower_set, "LNPW"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 639 | |
Mattia Dongili | 044847e | 2007-07-16 02:34:33 +0900 | [diff] [blame] | 640 | SNC_HANDLE_NAMES(lidstate_get, "GLID"); |
| 641 | |
| 642 | SNC_HANDLE_NAMES(indicatorlamp_get, "GILS"); |
| 643 | SNC_HANDLE_NAMES(indicatorlamp_set, "SILS"); |
| 644 | |
| 645 | SNC_HANDLE_NAMES(gainbass_get, "GMGB"); |
| 646 | SNC_HANDLE_NAMES(gainbass_set, "CMGB"); |
| 647 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 648 | SNC_HANDLE_NAMES(PID_get, "GPID"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 649 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 650 | SNC_HANDLE_NAMES(CTR_get, "GCTR"); |
| 651 | SNC_HANDLE_NAMES(CTR_set, "SCTR"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 652 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 653 | SNC_HANDLE_NAMES(PCR_get, "GPCR"); |
| 654 | SNC_HANDLE_NAMES(PCR_set, "SPCR"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 655 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 656 | SNC_HANDLE_NAMES(CMI_get, "GCMI"); |
| 657 | SNC_HANDLE_NAMES(CMI_set, "SCMI"); |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 658 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 659 | static struct sony_nc_value sony_nc_values[] = { |
| 660 | SNC_HANDLE(brightness_default, snc_brightness_def_get, |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 661 | snc_brightness_def_set, brightness_default_validate, 0), |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 662 | SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0), |
| 663 | SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0), |
| 664 | SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set, |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 665 | boolean_validate, 0), |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 666 | SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set, |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 667 | boolean_validate, 1), |
Mattia Dongili | 044847e | 2007-07-16 02:34:33 +0900 | [diff] [blame] | 668 | SNC_HANDLE(lidstate, snc_lidstate_get, NULL, |
| 669 | boolean_validate, 0), |
| 670 | SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set, |
| 671 | boolean_validate, 0), |
| 672 | SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set, |
| 673 | boolean_validate, 0), |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 674 | /* unknown methods */ |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 675 | SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1), |
| 676 | SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), |
| 677 | SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1), |
| 678 | SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1), |
| 679 | SNC_HANDLE_NULL |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 680 | }; |
| 681 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 682 | static acpi_handle sony_nc_acpi_handle; |
| 683 | static struct acpi_device *sony_nc_acpi_device = NULL; |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 684 | |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 685 | /* |
| 686 | * acpi_evaluate_object wrappers |
| 687 | */ |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 688 | static int acpi_callgetfunc(acpi_handle handle, char *name, int *result) |
| 689 | { |
| 690 | struct acpi_buffer output; |
| 691 | union acpi_object out_obj; |
| 692 | acpi_status status; |
| 693 | |
| 694 | output.length = sizeof(out_obj); |
| 695 | output.pointer = &out_obj; |
| 696 | |
| 697 | status = acpi_evaluate_object(handle, name, NULL, &output); |
| 698 | if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) { |
| 699 | *result = out_obj.integer.value; |
| 700 | return 0; |
| 701 | } |
| 702 | |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 703 | pr_warn(DRV_PFX "acpi_callreadfunc failed\n"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 704 | |
| 705 | return -1; |
| 706 | } |
| 707 | |
| 708 | static int acpi_callsetfunc(acpi_handle handle, char *name, int value, |
| 709 | int *result) |
| 710 | { |
| 711 | struct acpi_object_list params; |
| 712 | union acpi_object in_obj; |
| 713 | struct acpi_buffer output; |
| 714 | union acpi_object out_obj; |
| 715 | acpi_status status; |
| 716 | |
| 717 | params.count = 1; |
| 718 | params.pointer = &in_obj; |
| 719 | in_obj.type = ACPI_TYPE_INTEGER; |
| 720 | in_obj.integer.value = value; |
| 721 | |
| 722 | output.length = sizeof(out_obj); |
| 723 | output.pointer = &out_obj; |
| 724 | |
| 725 | status = acpi_evaluate_object(handle, name, ¶ms, &output); |
| 726 | if (status == AE_OK) { |
| 727 | if (result != NULL) { |
| 728 | if (out_obj.type != ACPI_TYPE_INTEGER) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 729 | pr_warn(DRV_PFX "acpi_evaluate_object bad " |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 730 | "return type\n"); |
| 731 | return -1; |
| 732 | } |
| 733 | *result = out_obj.integer.value; |
| 734 | } |
| 735 | return 0; |
| 736 | } |
| 737 | |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 738 | pr_warn(DRV_PFX "acpi_evaluate_object failed\n"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 739 | |
| 740 | return -1; |
| 741 | } |
| 742 | |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 743 | struct sony_nc_handles { |
| 744 | u16 cap[0x10]; |
| 745 | struct device_attribute devattr; |
| 746 | }; |
| 747 | |
Dan Carpenter | f11113b | 2011-02-26 15:54:27 +0300 | [diff] [blame] | 748 | static struct sony_nc_handles *handles; |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 749 | |
| 750 | static ssize_t sony_nc_handles_show(struct device *dev, |
| 751 | struct device_attribute *attr, char *buffer) |
| 752 | { |
| 753 | ssize_t len = 0; |
| 754 | int i; |
| 755 | |
| 756 | for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { |
| 757 | len += snprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ", |
| 758 | handles->cap[i]); |
| 759 | } |
| 760 | len += snprintf(buffer + len, PAGE_SIZE - len, "\n"); |
| 761 | |
| 762 | return len; |
| 763 | } |
| 764 | |
| 765 | static int sony_nc_handles_setup(struct platform_device *pd) |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 766 | { |
| 767 | int i; |
| 768 | int result; |
| 769 | |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 770 | handles = kzalloc(sizeof(*handles), GFP_KERNEL); |
Dan Carpenter | 31f0075 | 2011-02-26 15:55:24 +0300 | [diff] [blame^] | 771 | if (!handles) |
| 772 | return -ENOMEM; |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 773 | |
| 774 | sysfs_attr_init(&handles->devattr.attr); |
| 775 | handles->devattr.attr.name = "handles"; |
| 776 | handles->devattr.attr.mode = S_IRUGO; |
| 777 | handles->devattr.show = sony_nc_handles_show; |
| 778 | |
| 779 | for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { |
| 780 | if (!acpi_callsetfunc(sony_nc_acpi_handle, |
| 781 | "SN00", i + 0x20, &result)) { |
| 782 | dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n", |
| 783 | result, i); |
| 784 | handles->cap[i] = result; |
Mattia Dongili | 56e6e71 | 2011-02-19 11:52:25 +0900 | [diff] [blame] | 785 | } |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 786 | } |
| 787 | |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 788 | /* allow reading capabilities via sysfs */ |
| 789 | if (device_create_file(&pd->dev, &handles->devattr)) { |
| 790 | kfree(handles); |
| 791 | handles = NULL; |
| 792 | return -1; |
| 793 | } |
| 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | static int sony_nc_handles_cleanup(struct platform_device *pd) |
| 799 | { |
| 800 | if (handles) { |
| 801 | device_remove_file(&pd->dev, &handles->devattr); |
| 802 | kfree(handles); |
| 803 | handles = NULL; |
| 804 | } |
| 805 | return 0; |
| 806 | } |
| 807 | |
| 808 | static int sony_find_snc_handle(int handle) |
| 809 | { |
| 810 | int i; |
| 811 | for (i = 0; i < 0x10; i++) { |
| 812 | if (handles->cap[i] == handle) { |
| 813 | dprintk("found handle 0x%.4x (offset: 0x%.2x)\n", |
| 814 | handle, i); |
| 815 | return i; |
| 816 | } |
| 817 | } |
Mattia Dongili | 56e6e71 | 2011-02-19 11:52:25 +0900 | [diff] [blame] | 818 | dprintk("handle 0x%.4x not found\n", handle); |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 819 | return -1; |
| 820 | } |
| 821 | |
| 822 | static int sony_call_snc_handle(int handle, int argument, int *result) |
| 823 | { |
Mattia Dongili | 56e6e71 | 2011-02-19 11:52:25 +0900 | [diff] [blame] | 824 | int ret = 0; |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 825 | int offset = sony_find_snc_handle(handle); |
| 826 | |
| 827 | if (offset < 0) |
| 828 | return -1; |
| 829 | |
Mattia Dongili | 56e6e71 | 2011-02-19 11:52:25 +0900 | [diff] [blame] | 830 | ret = acpi_callsetfunc(sony_nc_acpi_handle, "SN07", offset | argument, |
| 831 | result); |
| 832 | dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", offset | argument, |
| 833 | *result); |
| 834 | return ret; |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 835 | } |
| 836 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 837 | /* |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 838 | * sony_nc_values input/output validate functions |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 839 | */ |
| 840 | |
| 841 | /* brightness_default_validate: |
| 842 | * |
| 843 | * manipulate input output values to keep consistency with the |
| 844 | * backlight framework for which brightness values are 0-based. |
| 845 | */ |
| 846 | static int brightness_default_validate(const int direction, const int value) |
| 847 | { |
| 848 | switch (direction) { |
| 849 | case SNC_VALIDATE_OUT: |
| 850 | return value - 1; |
| 851 | case SNC_VALIDATE_IN: |
| 852 | if (value >= 0 && value < SONY_MAX_BRIGHTNESS) |
| 853 | return value + 1; |
| 854 | } |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | /* boolean_validate: |
| 859 | * |
| 860 | * on input validate boolean values 0/1, on output just pass the |
| 861 | * received value. |
| 862 | */ |
| 863 | static int boolean_validate(const int direction, const int value) |
| 864 | { |
| 865 | if (direction == SNC_VALIDATE_IN) { |
| 866 | if (value != 0 && value != 1) |
| 867 | return -EINVAL; |
| 868 | } |
| 869 | return value; |
| 870 | } |
| 871 | |
| 872 | /* |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 873 | * Sysfs show/store common to all sony_nc_values |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 874 | */ |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 875 | static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 876 | char *buffer) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 877 | { |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 878 | int value; |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 879 | struct sony_nc_value *item = |
| 880 | container_of(attr, struct sony_nc_value, devattr); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 881 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 882 | if (!*item->acpiget) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 883 | return -EIO; |
| 884 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 885 | if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 886 | return -EIO; |
| 887 | |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 888 | if (item->validate) |
| 889 | value = item->validate(SNC_VALIDATE_OUT, value); |
| 890 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 891 | return snprintf(buffer, PAGE_SIZE, "%d\n", value); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 892 | } |
| 893 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 894 | static ssize_t sony_nc_sysfs_store(struct device *dev, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 895 | struct device_attribute *attr, |
| 896 | const char *buffer, size_t count) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 897 | { |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 898 | int value; |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 899 | struct sony_nc_value *item = |
| 900 | container_of(attr, struct sony_nc_value, devattr); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 901 | |
| 902 | if (!item->acpiset) |
| 903 | return -EIO; |
| 904 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 905 | if (count > 31) |
| 906 | return -EINVAL; |
| 907 | |
| 908 | value = simple_strtoul(buffer, NULL, 10); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 909 | |
Mattia Dongili | 156c221 | 2007-02-12 22:01:07 +0100 | [diff] [blame] | 910 | if (item->validate) |
| 911 | value = item->validate(SNC_VALIDATE_IN, value); |
| 912 | |
| 913 | if (value < 0) |
| 914 | return value; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 915 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 916 | if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 917 | return -EIO; |
Andrew Morton | 3f4f461 | 2007-01-13 23:04:32 +0100 | [diff] [blame] | 918 | item->value = value; |
| 919 | item->valid = 1; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 920 | return count; |
| 921 | } |
| 922 | |
Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 923 | |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 924 | /* |
| 925 | * Backlight device |
| 926 | */ |
| 927 | static int sony_backlight_update_status(struct backlight_device *bd) |
Andrew Morton | 3f4f461 | 2007-01-13 23:04:32 +0100 | [diff] [blame] | 928 | { |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 929 | return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT", |
Richard Purdie | 321709c | 2007-02-10 15:04:08 +0000 | [diff] [blame] | 930 | bd->props.brightness + 1, NULL); |
Andrew Morton | 3f4f461 | 2007-01-13 23:04:32 +0100 | [diff] [blame] | 931 | } |
| 932 | |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 933 | static int sony_backlight_get_brightness(struct backlight_device *bd) |
| 934 | { |
| 935 | int value; |
| 936 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 937 | if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | /* brightness levels are 1-based, while backlight ones are 0-based */ |
| 940 | return value - 1; |
| 941 | } |
| 942 | |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 943 | static int sony_nc_get_brightness_ng(struct backlight_device *bd) |
| 944 | { |
| 945 | int result; |
| 946 | int *handle = (int *)bl_get_data(bd); |
| 947 | |
| 948 | sony_call_snc_handle(*handle, 0x0200, &result); |
| 949 | |
| 950 | return result & 0xff; |
| 951 | } |
| 952 | |
| 953 | static int sony_nc_update_status_ng(struct backlight_device *bd) |
| 954 | { |
| 955 | int value, result; |
| 956 | int *handle = (int *)bl_get_data(bd); |
| 957 | |
| 958 | value = bd->props.brightness; |
| 959 | sony_call_snc_handle(*handle, 0x0100 | (value << 16), &result); |
| 960 | |
| 961 | return sony_nc_get_brightness_ng(bd); |
| 962 | } |
| 963 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 964 | static const struct backlight_ops sony_backlight_ops = { |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 965 | .options = BL_CORE_SUSPENDRESUME, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 966 | .update_status = sony_backlight_update_status, |
| 967 | .get_brightness = sony_backlight_get_brightness, |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 968 | }; |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 969 | static const struct backlight_ops sony_backlight_ng_ops = { |
| 970 | .options = BL_CORE_SUSPENDRESUME, |
| 971 | .update_status = sony_nc_update_status_ng, |
| 972 | .get_brightness = sony_nc_get_brightness_ng, |
| 973 | }; |
| 974 | static int backlight_ng_handle; |
| 975 | static struct backlight_device *sony_backlight_device; |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 976 | |
| 977 | /* |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 978 | * New SNC-only Vaios event mapping to driver known keys |
| 979 | */ |
| 980 | struct sony_nc_event { |
| 981 | u8 data; |
| 982 | u8 event; |
| 983 | }; |
| 984 | |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 985 | static struct sony_nc_event sony_100_events[] = { |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 986 | { 0x90, SONYPI_EVENT_PKEY_P1 }, |
| 987 | { 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Matthias Welwarsky | 6479efb | 2009-04-01 22:10:45 +0900 | [diff] [blame] | 988 | { 0x91, SONYPI_EVENT_PKEY_P2 }, |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 989 | { 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 990 | { 0x81, SONYPI_EVENT_FNKEY_F1 }, |
| 991 | { 0x01, SONYPI_EVENT_FNKEY_RELEASED }, |
Anton Veretenenko | f5acf5e | 2009-03-26 22:44:26 +0900 | [diff] [blame] | 992 | { 0x82, SONYPI_EVENT_FNKEY_F2 }, |
| 993 | { 0x02, SONYPI_EVENT_FNKEY_RELEASED }, |
| 994 | { 0x83, SONYPI_EVENT_FNKEY_F3 }, |
| 995 | { 0x03, SONYPI_EVENT_FNKEY_RELEASED }, |
| 996 | { 0x84, SONYPI_EVENT_FNKEY_F4 }, |
| 997 | { 0x04, SONYPI_EVENT_FNKEY_RELEASED }, |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 998 | { 0x85, SONYPI_EVENT_FNKEY_F5 }, |
| 999 | { 0x05, SONYPI_EVENT_FNKEY_RELEASED }, |
| 1000 | { 0x86, SONYPI_EVENT_FNKEY_F6 }, |
| 1001 | { 0x06, SONYPI_EVENT_FNKEY_RELEASED }, |
| 1002 | { 0x87, SONYPI_EVENT_FNKEY_F7 }, |
| 1003 | { 0x07, SONYPI_EVENT_FNKEY_RELEASED }, |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1004 | { 0x89, SONYPI_EVENT_FNKEY_F9 }, |
| 1005 | { 0x09, SONYPI_EVENT_FNKEY_RELEASED }, |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1006 | { 0x8A, SONYPI_EVENT_FNKEY_F10 }, |
| 1007 | { 0x0A, SONYPI_EVENT_FNKEY_RELEASED }, |
| 1008 | { 0x8C, SONYPI_EVENT_FNKEY_F12 }, |
| 1009 | { 0x0C, SONYPI_EVENT_FNKEY_RELEASED }, |
Mattia Dongili | 1a7d946 | 2011-01-08 18:47:29 +0900 | [diff] [blame] | 1010 | { 0x9d, SONYPI_EVENT_ZOOM_PRESSED }, |
| 1011 | { 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1012 | { 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED }, |
| 1013 | { 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Mattia Dongili | 4f924ba | 2009-12-17 00:08:33 +0900 | [diff] [blame] | 1014 | { 0xa1, SONYPI_EVENT_MEDIA_PRESSED }, |
| 1015 | { 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Mattia Dongili | 1a7d946 | 2011-01-08 18:47:29 +0900 | [diff] [blame] | 1016 | { 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED }, |
| 1017 | { 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1018 | { 0xa5, SONYPI_EVENT_VENDOR_PRESSED }, |
| 1019 | { 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1020 | { 0xa6, SONYPI_EVENT_HELP_PRESSED }, |
| 1021 | { 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1022 | { 0, 0 }, |
| 1023 | }; |
| 1024 | |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1025 | static struct sony_nc_event sony_127_events[] = { |
| 1026 | { 0x81, SONYPI_EVENT_MODEKEY_PRESSED }, |
| 1027 | { 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1028 | { 0x82, SONYPI_EVENT_PKEY_P1 }, |
| 1029 | { 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1030 | { 0x83, SONYPI_EVENT_PKEY_P2 }, |
| 1031 | { 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1032 | { 0x84, SONYPI_EVENT_PKEY_P3 }, |
| 1033 | { 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1034 | { 0x85, SONYPI_EVENT_PKEY_P4 }, |
| 1035 | { 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1036 | { 0x86, SONYPI_EVENT_PKEY_P5 }, |
| 1037 | { 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1038 | { 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED }, |
| 1039 | { 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1040 | { 0, 0 }, |
| 1041 | }; |
| 1042 | |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1043 | /* |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1044 | * ACPI callbacks |
| 1045 | */ |
Bjorn Helgaas | 8037d6e | 2009-04-07 15:37:32 +0000 | [diff] [blame] | 1046 | static void sony_nc_notify(struct acpi_device *device, u32 event) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1047 | { |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1048 | u32 ev = event; |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1049 | |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1050 | if (ev >= 0x90) { |
| 1051 | /* New-style event */ |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1052 | int result; |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1053 | int key_handle = 0; |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1054 | ev -= 0x90; |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1055 | |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1056 | if (sony_find_snc_handle(0x100) == ev) |
| 1057 | key_handle = 0x100; |
| 1058 | if (sony_find_snc_handle(0x127) == ev) |
| 1059 | key_handle = 0x127; |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1060 | |
Matthias Welwarsky | 6479efb | 2009-04-01 22:10:45 +0900 | [diff] [blame] | 1061 | if (key_handle) { |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1062 | struct sony_nc_event *key_event; |
| 1063 | |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1064 | if (sony_call_snc_handle(key_handle, 0x200, &result)) { |
Bjorn Helgaas | 8037d6e | 2009-04-07 15:37:32 +0000 | [diff] [blame] | 1065 | dprintk("sony_nc_notify, unable to decode" |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1066 | " event 0x%.2x 0x%.2x\n", key_handle, |
| 1067 | ev); |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1068 | /* restore the original event */ |
| 1069 | ev = event; |
| 1070 | } else { |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1071 | ev = result & 0xFF; |
| 1072 | |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1073 | if (key_handle == 0x100) |
| 1074 | key_event = sony_100_events; |
| 1075 | else |
| 1076 | key_event = sony_127_events; |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1077 | |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1078 | for (; key_event->data; key_event++) { |
| 1079 | if (key_event->data == ev) { |
| 1080 | ev = key_event->event; |
| 1081 | break; |
| 1082 | } |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1083 | } |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1084 | |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1085 | if (!key_event->data) |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1086 | pr_info(DRV_PFX |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1087 | "Unknown event: 0x%x 0x%x\n", |
| 1088 | key_handle, |
| 1089 | ev); |
| 1090 | else |
| 1091 | sony_laptop_report_input_event(ev); |
Matthew Garrett | 45c7942 | 2009-03-26 21:58:16 +0900 | [diff] [blame] | 1092 | } |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1093 | } else if (sony_find_snc_handle(sony_rfkill_handle) == ev) { |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1094 | sony_nc_rfkill_update(); |
| 1095 | return; |
Matthew Garrett | 9b57896 | 2009-03-26 21:58:14 +0900 | [diff] [blame] | 1096 | } |
Matthias Welwarsky | 16dd55f | 2009-04-01 22:10:47 +0900 | [diff] [blame] | 1097 | } else |
| 1098 | sony_laptop_report_input_event(ev); |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1099 | |
Bjorn Helgaas | 8037d6e | 2009-04-07 15:37:32 +0000 | [diff] [blame] | 1100 | dprintk("sony_nc_notify, event: 0x%.2x\n", ev); |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 1101 | acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | static acpi_status sony_walk_callback(acpi_handle handle, u32 level, |
| 1105 | void *context, void **return_value) |
| 1106 | { |
Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1107 | struct acpi_device_info *info; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1108 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 1109 | if (ACPI_SUCCESS(acpi_get_object_info(handle, &info))) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1110 | pr_warn(DRV_PFX "method: name: %4.4s, args %X\n", |
Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1111 | (char *)&info->name, info->param_count); |
| 1112 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 1113 | kfree(info); |
Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1114 | } |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1115 | |
| 1116 | return AE_OK; |
| 1117 | } |
| 1118 | |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1119 | /* |
| 1120 | * ACPI device |
| 1121 | */ |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1122 | static int sony_nc_function_setup(struct acpi_device *device) |
| 1123 | { |
| 1124 | int result; |
| 1125 | |
| 1126 | /* Enable all events */ |
| 1127 | acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0xffff, &result); |
| 1128 | |
| 1129 | /* Setup hotkeys */ |
| 1130 | sony_call_snc_handle(0x0100, 0, &result); |
| 1131 | sony_call_snc_handle(0x0101, 0, &result); |
| 1132 | sony_call_snc_handle(0x0102, 0x100, &result); |
Almer S. Tigelaar | 560e84a | 2009-04-12 11:26:27 +0000 | [diff] [blame] | 1133 | sony_call_snc_handle(0x0127, 0, &result); |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1138 | static int sony_nc_resume(struct acpi_device *device) |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1139 | { |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1140 | struct sony_nc_value *item; |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1141 | acpi_handle handle; |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1142 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1143 | for (item = sony_nc_values; item->name; item++) { |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1144 | int ret; |
| 1145 | |
| 1146 | if (!item->valid) |
| 1147 | continue; |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1148 | ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 1149 | item->value, NULL); |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1150 | if (ret < 0) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1151 | pr_err(DRV_PFX "%s: %d\n", __func__, ret); |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | } |
Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1155 | |
Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 1156 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", |
| 1157 | &handle))) { |
| 1158 | if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL)) |
| 1159 | dprintk("ECON Method failed\n"); |
| 1160 | } |
| 1161 | |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1162 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", |
| 1163 | &handle))) { |
| 1164 | dprintk("Doing SNC setup\n"); |
| 1165 | sony_nc_function_setup(device); |
| 1166 | } |
| 1167 | |
Alan Jenkins | a0d97d6 | 2009-09-25 10:18:21 +0100 | [diff] [blame] | 1168 | /* re-read rfkill state */ |
| 1169 | sony_nc_rfkill_update(); |
| 1170 | |
Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1171 | return 0; |
| 1172 | } |
| 1173 | |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1174 | static void sony_nc_rfkill_cleanup(void) |
| 1175 | { |
| 1176 | int i; |
| 1177 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1178 | for (i = 0; i < N_SONY_RFKILL; i++) { |
| 1179 | if (sony_rfkill_devices[i]) { |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1180 | rfkill_unregister(sony_rfkill_devices[i]); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1181 | rfkill_destroy(sony_rfkill_devices[i]); |
| 1182 | } |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1186 | static int sony_nc_rfkill_set(void *data, bool blocked) |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1187 | { |
| 1188 | int result; |
| 1189 | int argument = sony_rfkill_address[(long) data] + 0x100; |
| 1190 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1191 | if (!blocked) |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1192 | argument |= 0xff0000; |
| 1193 | |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1194 | return sony_call_snc_handle(sony_rfkill_handle, argument, &result); |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1195 | } |
| 1196 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1197 | static const struct rfkill_ops sony_rfkill_ops = { |
| 1198 | .set_block = sony_nc_rfkill_set, |
| 1199 | }; |
| 1200 | |
| 1201 | static int sony_nc_setup_rfkill(struct acpi_device *device, |
| 1202 | enum sony_nc_rfkill nc_type) |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1203 | { |
| 1204 | int err = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1205 | struct rfkill *rfk; |
| 1206 | enum rfkill_type type; |
| 1207 | const char *name; |
Alan Jenkins | 50fab07 | 2009-09-24 20:15:24 +0100 | [diff] [blame] | 1208 | int result; |
| 1209 | bool hwblock; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1210 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1211 | switch (nc_type) { |
| 1212 | case SONY_WIFI: |
| 1213 | type = RFKILL_TYPE_WLAN; |
| 1214 | name = "sony-wifi"; |
| 1215 | break; |
| 1216 | case SONY_BLUETOOTH: |
| 1217 | type = RFKILL_TYPE_BLUETOOTH; |
| 1218 | name = "sony-bluetooth"; |
| 1219 | break; |
| 1220 | case SONY_WWAN: |
| 1221 | type = RFKILL_TYPE_WWAN; |
| 1222 | name = "sony-wwan"; |
| 1223 | break; |
| 1224 | case SONY_WIMAX: |
| 1225 | type = RFKILL_TYPE_WIMAX; |
| 1226 | name = "sony-wimax"; |
| 1227 | break; |
| 1228 | default: |
| 1229 | return -EINVAL; |
Mattia Dongili | 53005a0 | 2009-04-12 11:26:31 +0000 | [diff] [blame] | 1230 | } |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1231 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1232 | rfk = rfkill_alloc(name, &device->dev, type, |
| 1233 | &sony_rfkill_ops, (void *)nc_type); |
| 1234 | if (!rfk) |
| 1235 | return -ENOMEM; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1236 | |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1237 | sony_call_snc_handle(sony_rfkill_handle, 0x200, &result); |
Alan Jenkins | 50fab07 | 2009-09-24 20:15:24 +0100 | [diff] [blame] | 1238 | hwblock = !(result & 0x1); |
| 1239 | rfkill_set_hw_state(rfk, hwblock); |
| 1240 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1241 | err = rfkill_register(rfk); |
| 1242 | if (err) { |
| 1243 | rfkill_destroy(rfk); |
| 1244 | return err; |
Mattia Dongili | 53005a0 | 2009-04-12 11:26:31 +0000 | [diff] [blame] | 1245 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1246 | sony_rfkill_devices[nc_type] = rfk; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1247 | return err; |
| 1248 | } |
| 1249 | |
Randy Dunlap | a46a780 | 2011-01-08 19:56:44 -0800 | [diff] [blame] | 1250 | static void sony_nc_rfkill_update(void) |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1251 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1252 | enum sony_nc_rfkill i; |
| 1253 | int result; |
| 1254 | bool hwblock; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1255 | |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1256 | sony_call_snc_handle(sony_rfkill_handle, 0x200, &result); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1257 | hwblock = !(result & 0x1); |
| 1258 | |
| 1259 | for (i = 0; i < N_SONY_RFKILL; i++) { |
| 1260 | int argument = sony_rfkill_address[i]; |
| 1261 | |
| 1262 | if (!sony_rfkill_devices[i]) |
| 1263 | continue; |
| 1264 | |
| 1265 | if (hwblock) { |
Johannes Berg | e1f8a19 | 2009-06-11 12:08:15 +0200 | [diff] [blame] | 1266 | if (rfkill_set_hw_state(sony_rfkill_devices[i], true)) { |
| 1267 | /* we already know we're blocked */ |
| 1268 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1269 | continue; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1270 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1271 | |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1272 | sony_call_snc_handle(sony_rfkill_handle, argument, &result); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1273 | rfkill_set_states(sony_rfkill_devices[i], |
| 1274 | !(result & 0xf), false); |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1278 | static void sony_nc_rfkill_setup(struct acpi_device *device) |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1279 | { |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1280 | int offset; |
| 1281 | u8 dev_code, i; |
| 1282 | acpi_status status; |
| 1283 | struct acpi_object_list params; |
| 1284 | union acpi_object in_obj; |
| 1285 | union acpi_object *device_enum; |
| 1286 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1287 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1288 | offset = sony_find_snc_handle(0x124); |
| 1289 | if (offset == -1) { |
| 1290 | offset = sony_find_snc_handle(0x135); |
| 1291 | if (offset == -1) |
| 1292 | return; |
Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1293 | else |
| 1294 | sony_rfkill_handle = 0x135; |
| 1295 | } else |
| 1296 | sony_rfkill_handle = 0x124; |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1297 | dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle); |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1298 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1299 | /* need to read the whole buffer returned by the acpi call to SN06 |
| 1300 | * here otherwise we may miss some features |
| 1301 | */ |
| 1302 | params.count = 1; |
| 1303 | params.pointer = &in_obj; |
| 1304 | in_obj.type = ACPI_TYPE_INTEGER; |
| 1305 | in_obj.integer.value = offset; |
| 1306 | status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", ¶ms, |
| 1307 | &buffer); |
| 1308 | if (ACPI_FAILURE(status)) { |
| 1309 | dprintk("Radio device enumeration failed\n"); |
| 1310 | return; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1311 | } |
| 1312 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1313 | device_enum = (union acpi_object *) buffer.pointer; |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1314 | if (!device_enum || device_enum->type != ACPI_TYPE_BUFFER) { |
| 1315 | pr_err(DRV_PFX "Invalid SN06 return object 0x%.2x\n", |
| 1316 | device_enum->type); |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1317 | goto out_no_enum; |
| 1318 | } |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1319 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1320 | /* the buffer is filled with magic numbers describing the devices |
| 1321 | * available, 0xff terminates the enumeration |
| 1322 | */ |
Dmitry Torokhov | c14973f | 2010-01-10 00:15:44 -0800 | [diff] [blame] | 1323 | for (i = 0; i < device_enum->buffer.length; i++) { |
| 1324 | |
| 1325 | dev_code = *(device_enum->buffer.pointer + i); |
| 1326 | if (dev_code == 0xff) |
| 1327 | break; |
| 1328 | |
Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1329 | dprintk("Radio devices, looking at 0x%.2x\n", dev_code); |
| 1330 | |
| 1331 | if (dev_code == 0 && !sony_rfkill_devices[SONY_WIFI]) |
| 1332 | sony_nc_setup_rfkill(device, SONY_WIFI); |
| 1333 | |
| 1334 | if (dev_code == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH]) |
| 1335 | sony_nc_setup_rfkill(device, SONY_BLUETOOTH); |
| 1336 | |
| 1337 | if ((0xf0 & dev_code) == 0x20 && |
| 1338 | !sony_rfkill_devices[SONY_WWAN]) |
| 1339 | sony_nc_setup_rfkill(device, SONY_WWAN); |
| 1340 | |
| 1341 | if (dev_code == 0x30 && !sony_rfkill_devices[SONY_WIMAX]) |
| 1342 | sony_nc_setup_rfkill(device, SONY_WIMAX); |
| 1343 | } |
| 1344 | |
| 1345 | out_no_enum: |
| 1346 | kfree(buffer.pointer); |
| 1347 | return; |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1348 | } |
| 1349 | |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1350 | /* Keyboard backlight feature */ |
| 1351 | #define KBDBL_HANDLER 0x137 |
| 1352 | #define KBDBL_PRESENT 0xB00 |
| 1353 | #define SET_MODE 0xC00 |
| 1354 | #define SET_TIMEOUT 0xE00 |
| 1355 | |
| 1356 | struct kbd_backlight { |
| 1357 | int mode; |
| 1358 | int timeout; |
| 1359 | struct device_attribute mode_attr; |
| 1360 | struct device_attribute timeout_attr; |
| 1361 | }; |
| 1362 | |
Dan Carpenter | f11113b | 2011-02-26 15:54:27 +0300 | [diff] [blame] | 1363 | static struct kbd_backlight *kbdbl_handle; |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1364 | |
| 1365 | static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value) |
| 1366 | { |
| 1367 | int result; |
| 1368 | |
| 1369 | if (value > 1) |
| 1370 | return -EINVAL; |
| 1371 | |
| 1372 | if (sony_call_snc_handle(KBDBL_HANDLER, |
| 1373 | (value << 0x10) | SET_MODE, &result)) |
| 1374 | return -EIO; |
| 1375 | |
| 1376 | kbdbl_handle->mode = value; |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | static ssize_t sony_nc_kbd_backlight_mode_store(struct device *dev, |
| 1382 | struct device_attribute *attr, |
| 1383 | const char *buffer, size_t count) |
| 1384 | { |
| 1385 | int ret = 0; |
| 1386 | unsigned long value; |
| 1387 | |
| 1388 | if (count > 31) |
| 1389 | return -EINVAL; |
| 1390 | |
| 1391 | if (strict_strtoul(buffer, 10, &value)) |
| 1392 | return -EINVAL; |
| 1393 | |
| 1394 | ret = __sony_nc_kbd_backlight_mode_set(value); |
| 1395 | if (ret < 0) |
| 1396 | return ret; |
| 1397 | |
| 1398 | return count; |
| 1399 | } |
| 1400 | |
| 1401 | static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev, |
| 1402 | struct device_attribute *attr, char *buffer) |
| 1403 | { |
| 1404 | ssize_t count = 0; |
| 1405 | count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->mode); |
| 1406 | return count; |
| 1407 | } |
| 1408 | |
| 1409 | static int __sony_nc_kbd_backlight_timeout_set(u8 value) |
| 1410 | { |
| 1411 | int result; |
| 1412 | |
| 1413 | if (value > 3) |
| 1414 | return -EINVAL; |
| 1415 | |
| 1416 | if (sony_call_snc_handle(KBDBL_HANDLER, |
| 1417 | (value << 0x10) | SET_TIMEOUT, &result)) |
| 1418 | return -EIO; |
| 1419 | |
| 1420 | kbdbl_handle->timeout = value; |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static ssize_t sony_nc_kbd_backlight_timeout_store(struct device *dev, |
| 1426 | struct device_attribute *attr, |
| 1427 | const char *buffer, size_t count) |
| 1428 | { |
| 1429 | int ret = 0; |
| 1430 | unsigned long value; |
| 1431 | |
| 1432 | if (count > 31) |
| 1433 | return -EINVAL; |
| 1434 | |
| 1435 | if (strict_strtoul(buffer, 10, &value)) |
| 1436 | return -EINVAL; |
| 1437 | |
| 1438 | ret = __sony_nc_kbd_backlight_timeout_set(value); |
| 1439 | if (ret < 0) |
| 1440 | return ret; |
| 1441 | |
| 1442 | return count; |
| 1443 | } |
| 1444 | |
| 1445 | static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev, |
| 1446 | struct device_attribute *attr, char *buffer) |
| 1447 | { |
| 1448 | ssize_t count = 0; |
| 1449 | count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->timeout); |
| 1450 | return count; |
| 1451 | } |
| 1452 | |
| 1453 | static int sony_nc_kbd_backlight_setup(struct platform_device *pd) |
| 1454 | { |
| 1455 | int result; |
| 1456 | |
| 1457 | if (sony_call_snc_handle(0x137, KBDBL_PRESENT, &result)) |
| 1458 | return 0; |
| 1459 | if (!(result & 0x02)) |
| 1460 | return 0; |
| 1461 | |
| 1462 | kbdbl_handle = kzalloc(sizeof(*kbdbl_handle), GFP_KERNEL); |
Dan Carpenter | 31f0075 | 2011-02-26 15:55:24 +0300 | [diff] [blame^] | 1463 | if (!kbdbl_handle) |
| 1464 | return -ENOMEM; |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1465 | |
| 1466 | sysfs_attr_init(&kbdbl_handle->mode_attr.attr); |
| 1467 | kbdbl_handle->mode_attr.attr.name = "kbd_backlight"; |
| 1468 | kbdbl_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 1469 | kbdbl_handle->mode_attr.show = sony_nc_kbd_backlight_mode_show; |
| 1470 | kbdbl_handle->mode_attr.store = sony_nc_kbd_backlight_mode_store; |
| 1471 | |
| 1472 | sysfs_attr_init(&kbdbl_handle->timeout_attr.attr); |
| 1473 | kbdbl_handle->timeout_attr.attr.name = "kbd_backlight_timeout"; |
| 1474 | kbdbl_handle->timeout_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 1475 | kbdbl_handle->timeout_attr.show = sony_nc_kbd_backlight_timeout_show; |
| 1476 | kbdbl_handle->timeout_attr.store = sony_nc_kbd_backlight_timeout_store; |
| 1477 | |
| 1478 | if (device_create_file(&pd->dev, &kbdbl_handle->mode_attr)) |
| 1479 | goto outkzalloc; |
| 1480 | |
| 1481 | if (device_create_file(&pd->dev, &kbdbl_handle->timeout_attr)) |
| 1482 | goto outmode; |
| 1483 | |
| 1484 | __sony_nc_kbd_backlight_mode_set(kbd_backlight); |
| 1485 | __sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout); |
| 1486 | |
| 1487 | return 0; |
| 1488 | |
| 1489 | outmode: |
| 1490 | device_remove_file(&pd->dev, &kbdbl_handle->mode_attr); |
| 1491 | outkzalloc: |
| 1492 | kfree(kbdbl_handle); |
| 1493 | kbdbl_handle = NULL; |
| 1494 | return -1; |
| 1495 | } |
| 1496 | |
| 1497 | static int sony_nc_kbd_backlight_cleanup(struct platform_device *pd) |
| 1498 | { |
| 1499 | if (kbdbl_handle) { |
| 1500 | device_remove_file(&pd->dev, &kbdbl_handle->mode_attr); |
| 1501 | device_remove_file(&pd->dev, &kbdbl_handle->timeout_attr); |
| 1502 | kfree(kbdbl_handle); |
| 1503 | } |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 1507 | static void sony_nc_backlight_setup(void) |
| 1508 | { |
| 1509 | acpi_handle unused; |
| 1510 | int max_brightness = 0; |
| 1511 | const struct backlight_ops *ops = NULL; |
| 1512 | struct backlight_properties props; |
| 1513 | |
| 1514 | if (sony_find_snc_handle(0x12f) != -1) { |
| 1515 | backlight_ng_handle = 0x12f; |
| 1516 | ops = &sony_backlight_ng_ops; |
| 1517 | max_brightness = 0xff; |
| 1518 | |
| 1519 | } else if (sony_find_snc_handle(0x137) != -1) { |
| 1520 | backlight_ng_handle = 0x137; |
| 1521 | ops = &sony_backlight_ng_ops; |
| 1522 | max_brightness = 0xff; |
| 1523 | |
| 1524 | } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", |
| 1525 | &unused))) { |
| 1526 | ops = &sony_backlight_ops; |
| 1527 | max_brightness = SONY_MAX_BRIGHTNESS - 1; |
| 1528 | |
| 1529 | } else |
| 1530 | return; |
| 1531 | |
| 1532 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 1533 | props.type = BACKLIGHT_PLATFORM; |
| 1534 | props.max_brightness = max_brightness; |
| 1535 | sony_backlight_device = backlight_device_register("sony", NULL, |
| 1536 | &backlight_ng_handle, |
| 1537 | ops, &props); |
| 1538 | |
| 1539 | if (IS_ERR(sony_backlight_device)) { |
| 1540 | pr_warning(DRV_PFX "unable to register backlight device\n"); |
| 1541 | sony_backlight_device = NULL; |
| 1542 | } else |
| 1543 | sony_backlight_device->props.brightness = |
| 1544 | ops->get_brightness(sony_backlight_device); |
| 1545 | } |
| 1546 | |
| 1547 | static void sony_nc_backlight_cleanup(void) |
| 1548 | { |
| 1549 | if (sony_backlight_device) |
| 1550 | backlight_device_unregister(sony_backlight_device); |
| 1551 | } |
| 1552 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1553 | static int sony_nc_add(struct acpi_device *device) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1554 | { |
| 1555 | acpi_status status; |
Andrew Morton | 8607c67 | 2007-03-06 02:29:42 -0800 | [diff] [blame] | 1556 | int result = 0; |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 1557 | acpi_handle handle; |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1558 | struct sony_nc_value *item; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1559 | |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1560 | pr_info(DRV_PFX "%s v%s.\n", SONY_NC_DRIVER_NAME, |
| 1561 | SONY_LAPTOP_DRIVER_VERSION); |
malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 1562 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1563 | sony_nc_acpi_device = device; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1564 | strcpy(acpi_device_class(device), "sony/hotkey"); |
Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 1565 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1566 | sony_nc_acpi_handle = device->handle; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1567 | |
Mattia Dongili | b25b732 | 2007-07-16 02:34:36 +0900 | [diff] [blame] | 1568 | /* read device status */ |
| 1569 | result = acpi_bus_get_status(device); |
| 1570 | /* bail IFF the above call was successful and the device is not present */ |
| 1571 | if (!result && !device->status.present) { |
| 1572 | dprintk("Device not present\n"); |
| 1573 | result = -ENODEV; |
| 1574 | goto outwalk; |
| 1575 | } |
| 1576 | |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 1577 | result = sony_pf_add(); |
| 1578 | if (result) |
| 1579 | goto outpresent; |
| 1580 | |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1581 | if (debug) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1582 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, |
| 1583 | sony_nc_acpi_handle, 1, sony_walk_callback, |
| 1584 | NULL, NULL, NULL); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1585 | if (ACPI_FAILURE(status)) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1586 | pr_warn(DRV_PFX "unable to walk acpi resources\n"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1587 | result = -ENODEV; |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 1588 | goto outpresent; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1589 | } |
Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 1590 | } |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1591 | |
Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 1592 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", |
| 1593 | &handle))) { |
| 1594 | if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL)) |
| 1595 | dprintk("ECON Method failed\n"); |
| 1596 | } |
| 1597 | |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1598 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", |
| 1599 | &handle))) { |
| 1600 | dprintk("Doing SNC setup\n"); |
Dan Carpenter | 7227ded | 2011-02-26 15:54:57 +0300 | [diff] [blame] | 1601 | result = sony_nc_handles_setup(sony_pf_device); |
| 1602 | if (result) |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 1603 | goto outpresent; |
Dan Carpenter | 7227ded | 2011-02-26 15:54:57 +0300 | [diff] [blame] | 1604 | result = sony_nc_kbd_backlight_setup(sony_pf_device); |
| 1605 | if (result) |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1606 | goto outsnc; |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1607 | sony_nc_function_setup(device); |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1608 | sony_nc_rfkill_setup(device); |
Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1609 | } |
| 1610 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 1611 | /* setup input devices and helper fifo */ |
Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 1612 | result = sony_laptop_setup_input(device); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 1613 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1614 | pr_err(DRV_PFX "Unable to create input devices.\n"); |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1615 | goto outkbdbacklight; |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 1616 | } |
| 1617 | |
Alessandro Guido | 38cfc14 | 2008-11-12 23:03:28 +0100 | [diff] [blame] | 1618 | if (acpi_video_backlight_support()) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 1619 | pr_info(DRV_PFX "brightness ignored, must be " |
Thomas Renninger | 540b8bb | 2008-08-01 17:38:02 +0200 | [diff] [blame] | 1620 | "controlled by ACPI video driver\n"); |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 1621 | } else { |
| 1622 | sony_nc_backlight_setup(); |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 1623 | } |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1624 | |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1625 | /* create sony_pf sysfs attributes related to the SNC device */ |
| 1626 | for (item = sony_nc_values; item->name; ++item) { |
| 1627 | |
| 1628 | if (!debug && item->debug) |
| 1629 | continue; |
| 1630 | |
| 1631 | /* find the available acpiget as described in the DSDT */ |
| 1632 | for (; item->acpiget && *item->acpiget; ++item->acpiget) { |
| 1633 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, |
| 1634 | *item->acpiget, |
| 1635 | &handle))) { |
malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 1636 | dprintk("Found %s getter: %s\n", |
| 1637 | item->name, *item->acpiget); |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1638 | item->devattr.attr.mode |= S_IRUGO; |
| 1639 | break; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | /* find the available acpiset as described in the DSDT */ |
| 1644 | for (; item->acpiset && *item->acpiset; ++item->acpiset) { |
| 1645 | if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, |
| 1646 | *item->acpiset, |
| 1647 | &handle))) { |
malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 1648 | dprintk("Found %s setter: %s\n", |
| 1649 | item->name, *item->acpiset); |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1650 | item->devattr.attr.mode |= S_IWUSR; |
| 1651 | break; |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | if (item->devattr.attr.mode != 0) { |
| 1656 | result = |
| 1657 | device_create_file(&sony_pf_device->dev, |
| 1658 | &item->devattr); |
| 1659 | if (result) |
| 1660 | goto out_sysfs; |
| 1661 | } |
| 1662 | } |
| 1663 | |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1664 | return 0; |
| 1665 | |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1666 | out_sysfs: |
| 1667 | for (item = sony_nc_values; item->name; ++item) { |
| 1668 | device_remove_file(&sony_pf_device->dev, &item->devattr); |
| 1669 | } |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 1670 | sony_nc_backlight_cleanup(); |
Mattia Dongili | 7df03b82 | 2007-01-13 23:04:41 +0100 | [diff] [blame] | 1671 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 1672 | sony_laptop_remove_input(); |
| 1673 | |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1674 | outkbdbacklight: |
| 1675 | sony_nc_kbd_backlight_cleanup(sony_pf_device); |
| 1676 | |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 1677 | outsnc: |
| 1678 | sony_nc_handles_cleanup(sony_pf_device); |
| 1679 | |
| 1680 | outpresent: |
| 1681 | sony_pf_remove(); |
| 1682 | |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 1683 | outwalk: |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1684 | sony_nc_rfkill_cleanup(); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1685 | return result; |
| 1686 | } |
| 1687 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1688 | static int sony_nc_remove(struct acpi_device *device, int type) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1689 | { |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1690 | struct sony_nc_value *item; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1691 | |
Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 1692 | sony_nc_backlight_cleanup(); |
Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 1693 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1694 | sony_nc_acpi_device = NULL; |
Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 1695 | |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1696 | for (item = sony_nc_values; item->name; ++item) { |
| 1697 | device_remove_file(&sony_pf_device->dev, &item->devattr); |
| 1698 | } |
| 1699 | |
Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1700 | sony_nc_kbd_backlight_cleanup(sony_pf_device); |
Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 1701 | sony_nc_handles_cleanup(sony_pf_device); |
malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 1702 | sony_pf_remove(); |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 1703 | sony_laptop_remove_input(); |
Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1704 | sony_nc_rfkill_cleanup(); |
malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 1705 | dprintk(SONY_NC_DRIVER_NAME " removed.\n"); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1706 | |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 1710 | static const struct acpi_device_id sony_device_ids[] = { |
| 1711 | {SONY_NC_HID, 0}, |
| 1712 | {SONY_PIC_HID, 0}, |
| 1713 | {"", 0}, |
| 1714 | }; |
| 1715 | MODULE_DEVICE_TABLE(acpi, sony_device_ids); |
| 1716 | |
| 1717 | static const struct acpi_device_id sony_nc_device_ids[] = { |
| 1718 | {SONY_NC_HID, 0}, |
| 1719 | {"", 0}, |
| 1720 | }; |
| 1721 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1722 | static struct acpi_driver sony_nc_driver = { |
| 1723 | .name = SONY_NC_DRIVER_NAME, |
| 1724 | .class = SONY_NC_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 1725 | .ids = sony_nc_device_ids, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1726 | .owner = THIS_MODULE, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 1727 | .ops = { |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1728 | .add = sony_nc_add, |
| 1729 | .remove = sony_nc_remove, |
| 1730 | .resume = sony_nc_resume, |
Bjorn Helgaas | 8037d6e | 2009-04-07 15:37:32 +0000 | [diff] [blame] | 1731 | .notify = sony_nc_notify, |
Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 1732 | }, |
Andrew Morton | 3f4f461 | 2007-01-13 23:04:32 +0100 | [diff] [blame] | 1733 | }; |
| 1734 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1735 | /*********** SPIC (SNY6001) Device ***********/ |
| 1736 | |
| 1737 | #define SONYPI_DEVICE_TYPE1 0x00000001 |
| 1738 | #define SONYPI_DEVICE_TYPE2 0x00000002 |
| 1739 | #define SONYPI_DEVICE_TYPE3 0x00000004 |
| 1740 | |
Mattia Dongili | 22a1778 | 2007-07-16 02:34:39 +0900 | [diff] [blame] | 1741 | #define SONYPI_TYPE1_OFFSET 0x04 |
| 1742 | #define SONYPI_TYPE2_OFFSET 0x12 |
| 1743 | #define SONYPI_TYPE3_OFFSET 0x12 |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1744 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1745 | struct sony_pic_ioport { |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 1746 | struct acpi_resource_io io1; |
| 1747 | struct acpi_resource_io io2; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1748 | struct list_head list; |
| 1749 | }; |
| 1750 | |
| 1751 | struct sony_pic_irq { |
| 1752 | struct acpi_resource_irq irq; |
| 1753 | struct list_head list; |
| 1754 | }; |
| 1755 | |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 1756 | struct sonypi_eventtypes { |
| 1757 | u8 data; |
| 1758 | unsigned long mask; |
| 1759 | struct sonypi_event *events; |
| 1760 | }; |
| 1761 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1762 | struct sony_pic_dev { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 1763 | struct acpi_device *acpi_dev; |
| 1764 | struct sony_pic_irq *cur_irq; |
| 1765 | struct sony_pic_ioport *cur_ioport; |
| 1766 | struct list_head interrupts; |
| 1767 | struct list_head ioports; |
| 1768 | struct mutex lock; |
| 1769 | struct sonypi_eventtypes *event_types; |
| 1770 | int (*handle_irq)(const u8, const u8); |
| 1771 | int model; |
| 1772 | u16 evport_offset; |
| 1773 | u8 camera_power; |
| 1774 | u8 bluetooth_power; |
| 1775 | u8 wwan_power; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1776 | }; |
| 1777 | |
| 1778 | static struct sony_pic_dev spic_dev = { |
| 1779 | .interrupts = LIST_HEAD_INIT(spic_dev.interrupts), |
| 1780 | .ioports = LIST_HEAD_INIT(spic_dev.ioports), |
| 1781 | }; |
| 1782 | |
Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 1783 | static int spic_drv_registered; |
| 1784 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1785 | /* Event masks */ |
| 1786 | #define SONYPI_JOGGER_MASK 0x00000001 |
| 1787 | #define SONYPI_CAPTURE_MASK 0x00000002 |
| 1788 | #define SONYPI_FNKEY_MASK 0x00000004 |
| 1789 | #define SONYPI_BLUETOOTH_MASK 0x00000008 |
| 1790 | #define SONYPI_PKEY_MASK 0x00000010 |
| 1791 | #define SONYPI_BACK_MASK 0x00000020 |
| 1792 | #define SONYPI_HELP_MASK 0x00000040 |
| 1793 | #define SONYPI_LID_MASK 0x00000080 |
| 1794 | #define SONYPI_ZOOM_MASK 0x00000100 |
| 1795 | #define SONYPI_THUMBPHRASE_MASK 0x00000200 |
| 1796 | #define SONYPI_MEYE_MASK 0x00000400 |
| 1797 | #define SONYPI_MEMORYSTICK_MASK 0x00000800 |
| 1798 | #define SONYPI_BATTERY_MASK 0x00001000 |
| 1799 | #define SONYPI_WIRELESS_MASK 0x00002000 |
| 1800 | |
| 1801 | struct sonypi_event { |
| 1802 | u8 data; |
| 1803 | u8 event; |
| 1804 | }; |
| 1805 | |
| 1806 | /* The set of possible button release events */ |
| 1807 | static struct sonypi_event sonypi_releaseev[] = { |
| 1808 | { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED }, |
| 1809 | { 0, 0 } |
| 1810 | }; |
| 1811 | |
| 1812 | /* The set of possible jogger events */ |
| 1813 | static struct sonypi_event sonypi_joggerev[] = { |
| 1814 | { 0x1f, SONYPI_EVENT_JOGDIAL_UP }, |
| 1815 | { 0x01, SONYPI_EVENT_JOGDIAL_DOWN }, |
| 1816 | { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED }, |
| 1817 | { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED }, |
| 1818 | { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP }, |
| 1819 | { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN }, |
| 1820 | { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED }, |
| 1821 | { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED }, |
| 1822 | { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP }, |
| 1823 | { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN }, |
| 1824 | { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED }, |
| 1825 | { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED }, |
| 1826 | { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED }, |
| 1827 | { 0, 0 } |
| 1828 | }; |
| 1829 | |
| 1830 | /* The set of possible capture button events */ |
| 1831 | static struct sonypi_event sonypi_captureev[] = { |
| 1832 | { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED }, |
| 1833 | { 0x07, SONYPI_EVENT_CAPTURE_PRESSED }, |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 1834 | { 0x40, SONYPI_EVENT_CAPTURE_PRESSED }, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1835 | { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED }, |
| 1836 | { 0, 0 } |
| 1837 | }; |
| 1838 | |
| 1839 | /* The set of possible fnkeys events */ |
| 1840 | static struct sonypi_event sonypi_fnkeyev[] = { |
| 1841 | { 0x10, SONYPI_EVENT_FNKEY_ESC }, |
| 1842 | { 0x11, SONYPI_EVENT_FNKEY_F1 }, |
| 1843 | { 0x12, SONYPI_EVENT_FNKEY_F2 }, |
| 1844 | { 0x13, SONYPI_EVENT_FNKEY_F3 }, |
| 1845 | { 0x14, SONYPI_EVENT_FNKEY_F4 }, |
| 1846 | { 0x15, SONYPI_EVENT_FNKEY_F5 }, |
| 1847 | { 0x16, SONYPI_EVENT_FNKEY_F6 }, |
| 1848 | { 0x17, SONYPI_EVENT_FNKEY_F7 }, |
| 1849 | { 0x18, SONYPI_EVENT_FNKEY_F8 }, |
| 1850 | { 0x19, SONYPI_EVENT_FNKEY_F9 }, |
| 1851 | { 0x1a, SONYPI_EVENT_FNKEY_F10 }, |
| 1852 | { 0x1b, SONYPI_EVENT_FNKEY_F11 }, |
| 1853 | { 0x1c, SONYPI_EVENT_FNKEY_F12 }, |
| 1854 | { 0x1f, SONYPI_EVENT_FNKEY_RELEASED }, |
| 1855 | { 0x21, SONYPI_EVENT_FNKEY_1 }, |
| 1856 | { 0x22, SONYPI_EVENT_FNKEY_2 }, |
| 1857 | { 0x31, SONYPI_EVENT_FNKEY_D }, |
| 1858 | { 0x32, SONYPI_EVENT_FNKEY_E }, |
| 1859 | { 0x33, SONYPI_EVENT_FNKEY_F }, |
| 1860 | { 0x34, SONYPI_EVENT_FNKEY_S }, |
| 1861 | { 0x35, SONYPI_EVENT_FNKEY_B }, |
| 1862 | { 0x36, SONYPI_EVENT_FNKEY_ONLY }, |
| 1863 | { 0, 0 } |
| 1864 | }; |
| 1865 | |
| 1866 | /* The set of possible program key events */ |
| 1867 | static struct sonypi_event sonypi_pkeyev[] = { |
| 1868 | { 0x01, SONYPI_EVENT_PKEY_P1 }, |
| 1869 | { 0x02, SONYPI_EVENT_PKEY_P2 }, |
| 1870 | { 0x04, SONYPI_EVENT_PKEY_P3 }, |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 1871 | { 0x20, SONYPI_EVENT_PKEY_P1 }, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1872 | { 0, 0 } |
| 1873 | }; |
| 1874 | |
| 1875 | /* The set of possible bluetooth events */ |
| 1876 | static struct sonypi_event sonypi_blueev[] = { |
| 1877 | { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED }, |
| 1878 | { 0x59, SONYPI_EVENT_BLUETOOTH_ON }, |
| 1879 | { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF }, |
| 1880 | { 0, 0 } |
| 1881 | }; |
| 1882 | |
| 1883 | /* The set of possible wireless events */ |
| 1884 | static struct sonypi_event sonypi_wlessev[] = { |
Mattia Dongili | 4eeb502 | 2011-02-19 11:52:27 +0900 | [diff] [blame] | 1885 | { 0x59, SONYPI_EVENT_IGNORE }, |
| 1886 | { 0x5a, SONYPI_EVENT_IGNORE }, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1887 | { 0, 0 } |
| 1888 | }; |
| 1889 | |
| 1890 | /* The set of possible back button events */ |
| 1891 | static struct sonypi_event sonypi_backev[] = { |
| 1892 | { 0x20, SONYPI_EVENT_BACK_PRESSED }, |
| 1893 | { 0, 0 } |
| 1894 | }; |
| 1895 | |
| 1896 | /* The set of possible help button events */ |
| 1897 | static struct sonypi_event sonypi_helpev[] = { |
| 1898 | { 0x3b, SONYPI_EVENT_HELP_PRESSED }, |
| 1899 | { 0, 0 } |
| 1900 | }; |
| 1901 | |
| 1902 | |
| 1903 | /* The set of possible lid events */ |
| 1904 | static struct sonypi_event sonypi_lidev[] = { |
| 1905 | { 0x51, SONYPI_EVENT_LID_CLOSED }, |
| 1906 | { 0x50, SONYPI_EVENT_LID_OPENED }, |
| 1907 | { 0, 0 } |
| 1908 | }; |
| 1909 | |
| 1910 | /* The set of possible zoom events */ |
| 1911 | static struct sonypi_event sonypi_zoomev[] = { |
| 1912 | { 0x39, SONYPI_EVENT_ZOOM_PRESSED }, |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 1913 | { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED }, |
| 1914 | { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED }, |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 1915 | { 0x04, SONYPI_EVENT_ZOOM_PRESSED }, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 1916 | { 0, 0 } |
| 1917 | }; |
| 1918 | |
| 1919 | /* The set of possible thumbphrase events */ |
| 1920 | static struct sonypi_event sonypi_thumbphraseev[] = { |
| 1921 | { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED }, |
| 1922 | { 0, 0 } |
| 1923 | }; |
| 1924 | |
| 1925 | /* The set of possible motioneye camera events */ |
| 1926 | static struct sonypi_event sonypi_meyeev[] = { |
| 1927 | { 0x00, SONYPI_EVENT_MEYE_FACE }, |
| 1928 | { 0x01, SONYPI_EVENT_MEYE_OPPOSITE }, |
| 1929 | { 0, 0 } |
| 1930 | }; |
| 1931 | |
| 1932 | /* The set of possible memorystick events */ |
| 1933 | static struct sonypi_event sonypi_memorystickev[] = { |
| 1934 | { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT }, |
| 1935 | { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT }, |
| 1936 | { 0, 0 } |
| 1937 | }; |
| 1938 | |
| 1939 | /* The set of possible battery events */ |
| 1940 | static struct sonypi_event sonypi_batteryev[] = { |
| 1941 | { 0x20, SONYPI_EVENT_BATTERY_INSERT }, |
| 1942 | { 0x30, SONYPI_EVENT_BATTERY_REMOVE }, |
| 1943 | { 0, 0 } |
| 1944 | }; |
| 1945 | |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 1946 | /* The set of possible volume events */ |
| 1947 | static struct sonypi_event sonypi_volumeev[] = { |
| 1948 | { 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED }, |
| 1949 | { 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED }, |
| 1950 | { 0, 0 } |
| 1951 | }; |
| 1952 | |
| 1953 | /* The set of possible brightness events */ |
| 1954 | static struct sonypi_event sonypi_brightnessev[] = { |
| 1955 | { 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED }, |
| 1956 | { 0, 0 } |
| 1957 | }; |
| 1958 | |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 1959 | static struct sonypi_eventtypes type1_events[] = { |
| 1960 | { 0, 0xffffffff, sonypi_releaseev }, |
| 1961 | { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev }, |
| 1962 | { 0x30, SONYPI_LID_MASK, sonypi_lidev }, |
| 1963 | { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev }, |
| 1964 | { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev }, |
| 1965 | { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 1966 | { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, |
| 1967 | { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 1968 | { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 1969 | { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 1970 | { 0 }, |
| 1971 | }; |
| 1972 | static struct sonypi_eventtypes type2_events[] = { |
| 1973 | { 0, 0xffffffff, sonypi_releaseev }, |
| 1974 | { 0x38, SONYPI_LID_MASK, sonypi_lidev }, |
| 1975 | { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev }, |
| 1976 | { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev }, |
| 1977 | { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 1978 | { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, |
| 1979 | { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 1980 | { 0x11, SONYPI_BACK_MASK, sonypi_backev }, |
| 1981 | { 0x21, SONYPI_HELP_MASK, sonypi_helpev }, |
| 1982 | { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev }, |
| 1983 | { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev }, |
| 1984 | { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 1985 | { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 1986 | { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 1987 | { 0 }, |
| 1988 | }; |
| 1989 | static struct sonypi_eventtypes type3_events[] = { |
| 1990 | { 0, 0xffffffff, sonypi_releaseev }, |
| 1991 | { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, |
| 1992 | { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev }, |
| 1993 | { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, |
| 1994 | { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, |
| 1995 | { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 1996 | { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev }, |
| 1997 | { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev }, |
| 1998 | { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev }, |
Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 1999 | { 0x05, SONYPI_PKEY_MASK, sonypi_volumeev }, |
| 2000 | { 0x05, SONYPI_PKEY_MASK, sonypi_brightnessev }, |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2001 | { 0 }, |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 2002 | }; |
| 2003 | |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2004 | /* low level spic calls */ |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2005 | #define ITERATIONS_LONG 10000 |
| 2006 | #define ITERATIONS_SHORT 10 |
| 2007 | #define wait_on_command(command, iterations) { \ |
| 2008 | unsigned int n = iterations; \ |
| 2009 | while (--n && (command)) \ |
| 2010 | udelay(1); \ |
| 2011 | if (!n) \ |
| 2012 | dprintk("command failed at %s : %s (line %d)\n", \ |
Harvey Harrison | 6e57419 | 2008-04-29 00:59:20 -0700 | [diff] [blame] | 2013 | __FILE__, __func__, __LINE__); \ |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | static u8 sony_pic_call1(u8 dev) |
| 2017 | { |
| 2018 | u8 v1, v2; |
| 2019 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2020 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2021 | ITERATIONS_LONG); |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2022 | outb(dev, spic_dev.cur_ioport->io1.minimum + 4); |
| 2023 | v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4); |
| 2024 | v2 = inb_p(spic_dev.cur_ioport->io1.minimum); |
Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 2025 | dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2026 | return v2; |
| 2027 | } |
| 2028 | |
| 2029 | static u8 sony_pic_call2(u8 dev, u8 fn) |
| 2030 | { |
| 2031 | u8 v1; |
| 2032 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2033 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2034 | ITERATIONS_LONG); |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2035 | outb(dev, spic_dev.cur_ioport->io1.minimum + 4); |
| 2036 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2037 | ITERATIONS_LONG); |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2038 | outb(fn, spic_dev.cur_ioport->io1.minimum); |
| 2039 | v1 = inb_p(spic_dev.cur_ioport->io1.minimum); |
Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 2040 | dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2041 | return v1; |
| 2042 | } |
| 2043 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2044 | static u8 sony_pic_call3(u8 dev, u8 fn, u8 v) |
| 2045 | { |
| 2046 | u8 v1; |
| 2047 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2048 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); |
| 2049 | outb(dev, spic_dev.cur_ioport->io1.minimum + 4); |
| 2050 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); |
| 2051 | outb(fn, spic_dev.cur_ioport->io1.minimum); |
| 2052 | wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); |
| 2053 | outb(v, spic_dev.cur_ioport->io1.minimum); |
| 2054 | v1 = inb_p(spic_dev.cur_ioport->io1.minimum); |
Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 2055 | dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n", |
| 2056 | dev, fn, v, v1); |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2057 | return v1; |
| 2058 | } |
| 2059 | |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2060 | /* |
| 2061 | * minidrivers for SPIC models |
| 2062 | */ |
Mattia Dongili | e93c8a6 | 2009-03-26 21:58:17 +0900 | [diff] [blame] | 2063 | static int type3_handle_irq(const u8 data_mask, const u8 ev) |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2064 | { |
| 2065 | /* |
| 2066 | * 0x31 could mean we have to take some extra action and wait for |
Mattia Dongili | e93c8a6 | 2009-03-26 21:58:17 +0900 | [diff] [blame] | 2067 | * the next irq for some Type3 models, it will generate a new |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2068 | * irq and we can read new data from the device: |
| 2069 | * - 0x5c and 0x5f requires 0xA0 |
| 2070 | * - 0x61 requires 0xB3 |
| 2071 | */ |
| 2072 | if (data_mask == 0x31) { |
| 2073 | if (ev == 0x5c || ev == 0x5f) |
| 2074 | sony_pic_call1(0xA0); |
| 2075 | else if (ev == 0x61) |
| 2076 | sony_pic_call1(0xB3); |
| 2077 | return 0; |
| 2078 | } |
| 2079 | return 1; |
| 2080 | } |
| 2081 | |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2082 | static void sony_pic_detect_device_type(struct sony_pic_dev *dev) |
| 2083 | { |
| 2084 | struct pci_dev *pcidev; |
| 2085 | |
| 2086 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2087 | PCI_DEVICE_ID_INTEL_82371AB_3, NULL); |
| 2088 | if (pcidev) { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2089 | dev->model = SONYPI_DEVICE_TYPE1; |
| 2090 | dev->evport_offset = SONYPI_TYPE1_OFFSET; |
| 2091 | dev->event_types = type1_events; |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2092 | goto out; |
| 2093 | } |
| 2094 | |
| 2095 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2096 | PCI_DEVICE_ID_INTEL_ICH6_1, NULL); |
| 2097 | if (pcidev) { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2098 | dev->model = SONYPI_DEVICE_TYPE2; |
| 2099 | dev->evport_offset = SONYPI_TYPE2_OFFSET; |
| 2100 | dev->event_types = type2_events; |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2101 | goto out; |
| 2102 | } |
| 2103 | |
| 2104 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2105 | PCI_DEVICE_ID_INTEL_ICH7_1, NULL); |
| 2106 | if (pcidev) { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2107 | dev->model = SONYPI_DEVICE_TYPE3; |
| 2108 | dev->handle_irq = type3_handle_irq; |
| 2109 | dev->evport_offset = SONYPI_TYPE3_OFFSET; |
| 2110 | dev->event_types = type3_events; |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2111 | goto out; |
| 2112 | } |
| 2113 | |
| 2114 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2115 | PCI_DEVICE_ID_INTEL_ICH8_4, NULL); |
| 2116 | if (pcidev) { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2117 | dev->model = SONYPI_DEVICE_TYPE3; |
| 2118 | dev->handle_irq = type3_handle_irq; |
| 2119 | dev->evport_offset = SONYPI_TYPE3_OFFSET; |
| 2120 | dev->event_types = type3_events; |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2121 | goto out; |
| 2122 | } |
| 2123 | |
ISHIKAWA Mutsumi | d5b0269 | 2009-03-26 21:58:20 +0900 | [diff] [blame] | 2124 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 2125 | PCI_DEVICE_ID_INTEL_ICH9_1, NULL); |
| 2126 | if (pcidev) { |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2127 | dev->model = SONYPI_DEVICE_TYPE3; |
| 2128 | dev->handle_irq = type3_handle_irq; |
| 2129 | dev->evport_offset = SONYPI_TYPE3_OFFSET; |
| 2130 | dev->event_types = type3_events; |
ISHIKAWA Mutsumi | d5b0269 | 2009-03-26 21:58:20 +0900 | [diff] [blame] | 2131 | goto out; |
| 2132 | } |
| 2133 | |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2134 | /* default */ |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2135 | dev->model = SONYPI_DEVICE_TYPE2; |
| 2136 | dev->evport_offset = SONYPI_TYPE2_OFFSET; |
| 2137 | dev->event_types = type2_events; |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2138 | |
| 2139 | out: |
| 2140 | if (pcidev) |
| 2141 | pci_dev_put(pcidev); |
| 2142 | |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2143 | pr_info(DRV_PFX "detected Type%d model\n", |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2144 | dev->model == SONYPI_DEVICE_TYPE1 ? 1 : |
| 2145 | dev->model == SONYPI_DEVICE_TYPE2 ? 2 : 3); |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 2146 | } |
| 2147 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2148 | /* camera tests and poweron/poweroff */ |
| 2149 | #define SONYPI_CAMERA_PICTURE 5 |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2150 | #define SONYPI_CAMERA_CONTROL 0x10 |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2151 | |
| 2152 | #define SONYPI_CAMERA_BRIGHTNESS 0 |
| 2153 | #define SONYPI_CAMERA_CONTRAST 1 |
| 2154 | #define SONYPI_CAMERA_HUE 2 |
| 2155 | #define SONYPI_CAMERA_COLOR 3 |
| 2156 | #define SONYPI_CAMERA_SHARPNESS 4 |
| 2157 | |
| 2158 | #define SONYPI_CAMERA_EXPOSURE_MASK 0xC |
| 2159 | #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3 |
| 2160 | #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30 |
| 2161 | #define SONYPI_CAMERA_MUTE_MASK 0x40 |
| 2162 | |
| 2163 | /* the rest don't need a loop until not 0xff */ |
| 2164 | #define SONYPI_CAMERA_AGC 6 |
| 2165 | #define SONYPI_CAMERA_AGC_MASK 0x30 |
| 2166 | #define SONYPI_CAMERA_SHUTTER_MASK 0x7 |
| 2167 | |
| 2168 | #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7 |
| 2169 | #define SONYPI_CAMERA_CONTROL 0x10 |
| 2170 | |
| 2171 | #define SONYPI_CAMERA_STATUS 7 |
| 2172 | #define SONYPI_CAMERA_STATUS_READY 0x2 |
| 2173 | #define SONYPI_CAMERA_STATUS_POSITION 0x4 |
| 2174 | |
| 2175 | #define SONYPI_DIRECTION_BACKWARDS 0x4 |
| 2176 | |
| 2177 | #define SONYPI_CAMERA_REVISION 8 |
| 2178 | #define SONYPI_CAMERA_ROMVERSION 9 |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2179 | |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2180 | static int __sony_pic_camera_ready(void) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2181 | { |
| 2182 | u8 v; |
| 2183 | |
| 2184 | v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS); |
| 2185 | return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY)); |
| 2186 | } |
| 2187 | |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2188 | static int __sony_pic_camera_off(void) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2189 | { |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2190 | if (!camera) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2191 | pr_warn(DRV_PFX "camera control not enabled\n"); |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2192 | return -ENODEV; |
| 2193 | } |
| 2194 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2195 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, |
| 2196 | SONYPI_CAMERA_MUTE_MASK), |
| 2197 | ITERATIONS_SHORT); |
| 2198 | |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2199 | if (spic_dev.camera_power) { |
| 2200 | sony_pic_call2(0x91, 0); |
| 2201 | spic_dev.camera_power = 0; |
| 2202 | } |
| 2203 | return 0; |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2204 | } |
| 2205 | |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2206 | static int __sony_pic_camera_on(void) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2207 | { |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2208 | int i, j, x; |
| 2209 | |
| 2210 | if (!camera) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2211 | pr_warn(DRV_PFX "camera control not enabled\n"); |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2212 | return -ENODEV; |
| 2213 | } |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2214 | |
| 2215 | if (spic_dev.camera_power) |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2216 | return 0; |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2217 | |
| 2218 | for (j = 5; j > 0; j--) { |
| 2219 | |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2220 | for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2221 | msleep(10); |
| 2222 | sony_pic_call1(0x93); |
| 2223 | |
| 2224 | for (i = 400; i > 0; i--) { |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2225 | if (__sony_pic_camera_ready()) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2226 | break; |
| 2227 | msleep(10); |
| 2228 | } |
| 2229 | if (i) |
| 2230 | break; |
| 2231 | } |
| 2232 | |
| 2233 | if (j == 0) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2234 | pr_warn(DRV_PFX "failed to power on camera\n"); |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2235 | return -ENODEV; |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL, |
| 2239 | 0x5a), |
| 2240 | ITERATIONS_SHORT); |
| 2241 | |
| 2242 | spic_dev.camera_power = 1; |
malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 2243 | return 0; |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2244 | } |
| 2245 | |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2246 | /* External camera command (exported to the motion eye v4l driver) */ |
| 2247 | int sony_pic_camera_command(int command, u8 value) |
| 2248 | { |
| 2249 | if (!camera) |
| 2250 | return -EIO; |
| 2251 | |
| 2252 | mutex_lock(&spic_dev.lock); |
| 2253 | |
| 2254 | switch (command) { |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2255 | case SONY_PIC_COMMAND_SETCAMERA: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2256 | if (value) |
| 2257 | __sony_pic_camera_on(); |
| 2258 | else |
| 2259 | __sony_pic_camera_off(); |
| 2260 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2261 | case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2262 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value), |
| 2263 | ITERATIONS_SHORT); |
| 2264 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2265 | case SONY_PIC_COMMAND_SETCAMERACONTRAST: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2266 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value), |
| 2267 | ITERATIONS_SHORT); |
| 2268 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2269 | case SONY_PIC_COMMAND_SETCAMERAHUE: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2270 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value), |
| 2271 | ITERATIONS_SHORT); |
| 2272 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2273 | case SONY_PIC_COMMAND_SETCAMERACOLOR: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2274 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value), |
| 2275 | ITERATIONS_SHORT); |
| 2276 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2277 | case SONY_PIC_COMMAND_SETCAMERASHARPNESS: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2278 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value), |
| 2279 | ITERATIONS_SHORT); |
| 2280 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2281 | case SONY_PIC_COMMAND_SETCAMERAPICTURE: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2282 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value), |
| 2283 | ITERATIONS_SHORT); |
| 2284 | break; |
malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 2285 | case SONY_PIC_COMMAND_SETCAMERAAGC: |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2286 | wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value), |
| 2287 | ITERATIONS_SHORT); |
| 2288 | break; |
| 2289 | default: |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2290 | pr_err(DRV_PFX "sony_pic_camera_command invalid: %d\n", |
malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 2291 | command); |
| 2292 | break; |
| 2293 | } |
| 2294 | mutex_unlock(&spic_dev.lock); |
| 2295 | return 0; |
| 2296 | } |
| 2297 | EXPORT_SYMBOL(sony_pic_camera_command); |
| 2298 | |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2299 | /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */ |
Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 2300 | static void __sony_pic_set_wwanpower(u8 state) |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2301 | { |
| 2302 | state = !!state; |
Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 2303 | if (spic_dev.wwan_power == state) |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2304 | return; |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2305 | sony_pic_call2(0xB0, state); |
Sergey Yanovich | 3ad1b761 | 2009-03-26 21:58:21 +0900 | [diff] [blame] | 2306 | sony_pic_call1(0x82); |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2307 | spic_dev.wwan_power = state; |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | static ssize_t sony_pic_wwanpower_store(struct device *dev, |
| 2311 | struct device_attribute *attr, |
| 2312 | const char *buffer, size_t count) |
| 2313 | { |
| 2314 | unsigned long value; |
| 2315 | if (count > 31) |
| 2316 | return -EINVAL; |
| 2317 | |
| 2318 | value = simple_strtoul(buffer, NULL, 10); |
Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 2319 | mutex_lock(&spic_dev.lock); |
| 2320 | __sony_pic_set_wwanpower(value); |
| 2321 | mutex_unlock(&spic_dev.lock); |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2322 | |
| 2323 | return count; |
| 2324 | } |
| 2325 | |
| 2326 | static ssize_t sony_pic_wwanpower_show(struct device *dev, |
| 2327 | struct device_attribute *attr, char *buffer) |
| 2328 | { |
| 2329 | ssize_t count; |
| 2330 | mutex_lock(&spic_dev.lock); |
| 2331 | count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power); |
| 2332 | mutex_unlock(&spic_dev.lock); |
| 2333 | return count; |
| 2334 | } |
| 2335 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2336 | /* bluetooth subsystem power state */ |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2337 | static void __sony_pic_set_bluetoothpower(u8 state) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2338 | { |
| 2339 | state = !!state; |
| 2340 | if (spic_dev.bluetooth_power == state) |
| 2341 | return; |
| 2342 | sony_pic_call2(0x96, state); |
| 2343 | sony_pic_call1(0x82); |
| 2344 | spic_dev.bluetooth_power = state; |
| 2345 | } |
| 2346 | |
| 2347 | static ssize_t sony_pic_bluetoothpower_store(struct device *dev, |
| 2348 | struct device_attribute *attr, |
| 2349 | const char *buffer, size_t count) |
| 2350 | { |
| 2351 | unsigned long value; |
| 2352 | if (count > 31) |
| 2353 | return -EINVAL; |
| 2354 | |
| 2355 | value = simple_strtoul(buffer, NULL, 10); |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2356 | mutex_lock(&spic_dev.lock); |
| 2357 | __sony_pic_set_bluetoothpower(value); |
| 2358 | mutex_unlock(&spic_dev.lock); |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2359 | |
| 2360 | return count; |
| 2361 | } |
| 2362 | |
| 2363 | static ssize_t sony_pic_bluetoothpower_show(struct device *dev, |
| 2364 | struct device_attribute *attr, char *buffer) |
| 2365 | { |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2366 | ssize_t count = 0; |
| 2367 | mutex_lock(&spic_dev.lock); |
| 2368 | count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power); |
| 2369 | mutex_unlock(&spic_dev.lock); |
| 2370 | return count; |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | /* fan speed */ |
| 2374 | /* FAN0 information (reverse engineered from ACPI tables) */ |
| 2375 | #define SONY_PIC_FAN0_STATUS 0x93 |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2376 | static int sony_pic_set_fanspeed(unsigned long value) |
| 2377 | { |
| 2378 | return ec_write(SONY_PIC_FAN0_STATUS, value); |
| 2379 | } |
| 2380 | |
| 2381 | static int sony_pic_get_fanspeed(u8 *value) |
| 2382 | { |
| 2383 | return ec_read(SONY_PIC_FAN0_STATUS, value); |
| 2384 | } |
| 2385 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2386 | static ssize_t sony_pic_fanspeed_store(struct device *dev, |
| 2387 | struct device_attribute *attr, |
| 2388 | const char *buffer, size_t count) |
| 2389 | { |
| 2390 | unsigned long value; |
| 2391 | if (count > 31) |
| 2392 | return -EINVAL; |
| 2393 | |
| 2394 | value = simple_strtoul(buffer, NULL, 10); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2395 | if (sony_pic_set_fanspeed(value)) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2396 | return -EIO; |
| 2397 | |
| 2398 | return count; |
| 2399 | } |
| 2400 | |
| 2401 | static ssize_t sony_pic_fanspeed_show(struct device *dev, |
| 2402 | struct device_attribute *attr, char *buffer) |
| 2403 | { |
| 2404 | u8 value = 0; |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2405 | if (sony_pic_get_fanspeed(&value)) |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2406 | return -EIO; |
| 2407 | |
| 2408 | return snprintf(buffer, PAGE_SIZE, "%d\n", value); |
| 2409 | } |
| 2410 | |
| 2411 | #define SPIC_ATTR(_name, _mode) \ |
| 2412 | struct device_attribute spic_attr_##_name = __ATTR(_name, \ |
| 2413 | _mode, sony_pic_## _name ##_show, \ |
| 2414 | sony_pic_## _name ##_store) |
| 2415 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2416 | static SPIC_ATTR(bluetoothpower, 0644); |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2417 | static SPIC_ATTR(wwanpower, 0644); |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2418 | static SPIC_ATTR(fanspeed, 0644); |
| 2419 | |
| 2420 | static struct attribute *spic_attributes[] = { |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2421 | &spic_attr_bluetoothpower.attr, |
malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 2422 | &spic_attr_wwanpower.attr, |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 2423 | &spic_attr_fanspeed.attr, |
| 2424 | NULL |
| 2425 | }; |
| 2426 | |
| 2427 | static struct attribute_group spic_attribute_group = { |
| 2428 | .attrs = spic_attributes |
| 2429 | }; |
| 2430 | |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2431 | /******** SONYPI compatibility **********/ |
Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 2432 | #ifdef CONFIG_SONYPI_COMPAT |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2433 | |
| 2434 | /* battery / brightness / temperature addresses */ |
| 2435 | #define SONYPI_BAT_FLAGS 0x81 |
| 2436 | #define SONYPI_LCD_LIGHT 0x96 |
| 2437 | #define SONYPI_BAT1_PCTRM 0xa0 |
| 2438 | #define SONYPI_BAT1_LEFT 0xa2 |
| 2439 | #define SONYPI_BAT1_MAXRT 0xa4 |
| 2440 | #define SONYPI_BAT2_PCTRM 0xa8 |
| 2441 | #define SONYPI_BAT2_LEFT 0xaa |
| 2442 | #define SONYPI_BAT2_MAXRT 0xac |
| 2443 | #define SONYPI_BAT1_MAXTK 0xb0 |
| 2444 | #define SONYPI_BAT1_FULL 0xb2 |
| 2445 | #define SONYPI_BAT2_MAXTK 0xb8 |
| 2446 | #define SONYPI_BAT2_FULL 0xba |
| 2447 | #define SONYPI_TEMP_STATUS 0xC1 |
| 2448 | |
| 2449 | struct sonypi_compat_s { |
| 2450 | struct fasync_struct *fifo_async; |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2451 | struct kfifo fifo; |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2452 | spinlock_t fifo_lock; |
| 2453 | wait_queue_head_t fifo_proc_list; |
| 2454 | atomic_t open_count; |
| 2455 | }; |
| 2456 | static struct sonypi_compat_s sonypi_compat = { |
| 2457 | .open_count = ATOMIC_INIT(0), |
| 2458 | }; |
| 2459 | |
| 2460 | static int sonypi_misc_fasync(int fd, struct file *filp, int on) |
| 2461 | { |
Jonathan Corbet | 60aa492 | 2009-02-01 14:52:56 -0700 | [diff] [blame] | 2462 | return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | static int sonypi_misc_release(struct inode *inode, struct file *file) |
| 2466 | { |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2467 | atomic_dec(&sonypi_compat.open_count); |
| 2468 | return 0; |
| 2469 | } |
| 2470 | |
| 2471 | static int sonypi_misc_open(struct inode *inode, struct file *file) |
| 2472 | { |
| 2473 | /* Flush input queue on first open */ |
Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 2474 | unsigned long flags; |
| 2475 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2476 | spin_lock_irqsave(&sonypi_compat.fifo_lock, flags); |
Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 2477 | |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2478 | if (atomic_inc_return(&sonypi_compat.open_count) == 1) |
Stefani Seibold | e64c026 | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 2479 | kfifo_reset(&sonypi_compat.fifo); |
Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 2480 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2481 | spin_unlock_irqrestore(&sonypi_compat.fifo_lock, flags); |
Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 2482 | |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | static ssize_t sonypi_misc_read(struct file *file, char __user *buf, |
| 2487 | size_t count, loff_t *pos) |
| 2488 | { |
| 2489 | ssize_t ret; |
| 2490 | unsigned char c; |
| 2491 | |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2492 | if ((kfifo_len(&sonypi_compat.fifo) == 0) && |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2493 | (file->f_flags & O_NONBLOCK)) |
| 2494 | return -EAGAIN; |
| 2495 | |
| 2496 | ret = wait_event_interruptible(sonypi_compat.fifo_proc_list, |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2497 | kfifo_len(&sonypi_compat.fifo) != 0); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2498 | if (ret) |
| 2499 | return ret; |
| 2500 | |
| 2501 | while (ret < count && |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 2502 | (kfifo_out_locked(&sonypi_compat.fifo, &c, sizeof(c), |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 2503 | &sonypi_compat.fifo_lock) == sizeof(c))) { |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2504 | if (put_user(c, buf++)) |
| 2505 | return -EFAULT; |
| 2506 | ret++; |
| 2507 | } |
| 2508 | |
| 2509 | if (ret > 0) { |
| 2510 | struct inode *inode = file->f_path.dentry->d_inode; |
| 2511 | inode->i_atime = current_fs_time(inode->i_sb); |
| 2512 | } |
| 2513 | |
| 2514 | return ret; |
| 2515 | } |
| 2516 | |
| 2517 | static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait) |
| 2518 | { |
| 2519 | poll_wait(file, &sonypi_compat.fifo_proc_list, wait); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2520 | if (kfifo_len(&sonypi_compat.fifo)) |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2521 | return POLLIN | POLLRDNORM; |
| 2522 | return 0; |
| 2523 | } |
| 2524 | |
| 2525 | static int ec_read16(u8 addr, u16 *value) |
| 2526 | { |
| 2527 | u8 val_lb, val_hb; |
| 2528 | if (ec_read(addr, &val_lb)) |
| 2529 | return -1; |
| 2530 | if (ec_read(addr + 1, &val_hb)) |
| 2531 | return -1; |
| 2532 | *value = val_lb | (val_hb << 8); |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
Alan Cox | 2b24ef0 | 2009-03-26 21:58:19 +0900 | [diff] [blame] | 2536 | static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd, |
| 2537 | unsigned long arg) |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2538 | { |
| 2539 | int ret = 0; |
| 2540 | void __user *argp = (void __user *)arg; |
| 2541 | u8 val8; |
| 2542 | u16 val16; |
| 2543 | int value; |
| 2544 | |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2545 | mutex_lock(&spic_dev.lock); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2546 | switch (cmd) { |
| 2547 | case SONYPI_IOCGBRT: |
| 2548 | if (sony_backlight_device == NULL) { |
| 2549 | ret = -EIO; |
| 2550 | break; |
| 2551 | } |
| 2552 | if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) { |
| 2553 | ret = -EIO; |
| 2554 | break; |
| 2555 | } |
| 2556 | val8 = ((value & 0xff) - 1) << 5; |
| 2557 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 2558 | ret = -EFAULT; |
| 2559 | break; |
| 2560 | case SONYPI_IOCSBRT: |
| 2561 | if (sony_backlight_device == NULL) { |
| 2562 | ret = -EIO; |
| 2563 | break; |
| 2564 | } |
| 2565 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
| 2566 | ret = -EFAULT; |
| 2567 | break; |
| 2568 | } |
| 2569 | if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT", |
| 2570 | (val8 >> 5) + 1, NULL)) { |
| 2571 | ret = -EIO; |
| 2572 | break; |
| 2573 | } |
| 2574 | /* sync the backlight device status */ |
| 2575 | sony_backlight_device->props.brightness = |
| 2576 | sony_backlight_get_brightness(sony_backlight_device); |
| 2577 | break; |
| 2578 | case SONYPI_IOCGBAT1CAP: |
| 2579 | if (ec_read16(SONYPI_BAT1_FULL, &val16)) { |
| 2580 | ret = -EIO; |
| 2581 | break; |
| 2582 | } |
| 2583 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 2584 | ret = -EFAULT; |
| 2585 | break; |
| 2586 | case SONYPI_IOCGBAT1REM: |
| 2587 | if (ec_read16(SONYPI_BAT1_LEFT, &val16)) { |
| 2588 | ret = -EIO; |
| 2589 | break; |
| 2590 | } |
| 2591 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 2592 | ret = -EFAULT; |
| 2593 | break; |
| 2594 | case SONYPI_IOCGBAT2CAP: |
| 2595 | if (ec_read16(SONYPI_BAT2_FULL, &val16)) { |
| 2596 | ret = -EIO; |
| 2597 | break; |
| 2598 | } |
| 2599 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 2600 | ret = -EFAULT; |
| 2601 | break; |
| 2602 | case SONYPI_IOCGBAT2REM: |
| 2603 | if (ec_read16(SONYPI_BAT2_LEFT, &val16)) { |
| 2604 | ret = -EIO; |
| 2605 | break; |
| 2606 | } |
| 2607 | if (copy_to_user(argp, &val16, sizeof(val16))) |
| 2608 | ret = -EFAULT; |
| 2609 | break; |
| 2610 | case SONYPI_IOCGBATFLAGS: |
| 2611 | if (ec_read(SONYPI_BAT_FLAGS, &val8)) { |
| 2612 | ret = -EIO; |
| 2613 | break; |
| 2614 | } |
| 2615 | val8 &= 0x07; |
| 2616 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 2617 | ret = -EFAULT; |
| 2618 | break; |
| 2619 | case SONYPI_IOCGBLUE: |
| 2620 | val8 = spic_dev.bluetooth_power; |
| 2621 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 2622 | ret = -EFAULT; |
| 2623 | break; |
| 2624 | case SONYPI_IOCSBLUE: |
| 2625 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
| 2626 | ret = -EFAULT; |
| 2627 | break; |
| 2628 | } |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2629 | __sony_pic_set_bluetoothpower(val8); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2630 | break; |
| 2631 | /* FAN Controls */ |
| 2632 | case SONYPI_IOCGFAN: |
| 2633 | if (sony_pic_get_fanspeed(&val8)) { |
| 2634 | ret = -EIO; |
| 2635 | break; |
| 2636 | } |
| 2637 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 2638 | ret = -EFAULT; |
| 2639 | break; |
| 2640 | case SONYPI_IOCSFAN: |
| 2641 | if (copy_from_user(&val8, argp, sizeof(val8))) { |
| 2642 | ret = -EFAULT; |
| 2643 | break; |
| 2644 | } |
| 2645 | if (sony_pic_set_fanspeed(val8)) |
| 2646 | ret = -EIO; |
| 2647 | break; |
| 2648 | /* GET Temperature (useful under APM) */ |
| 2649 | case SONYPI_IOCGTEMP: |
| 2650 | if (ec_read(SONYPI_TEMP_STATUS, &val8)) { |
| 2651 | ret = -EIO; |
| 2652 | break; |
| 2653 | } |
| 2654 | if (copy_to_user(argp, &val8, sizeof(val8))) |
| 2655 | ret = -EFAULT; |
| 2656 | break; |
| 2657 | default: |
| 2658 | ret = -EINVAL; |
| 2659 | } |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 2660 | mutex_unlock(&spic_dev.lock); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2661 | return ret; |
| 2662 | } |
| 2663 | |
| 2664 | static const struct file_operations sonypi_misc_fops = { |
| 2665 | .owner = THIS_MODULE, |
| 2666 | .read = sonypi_misc_read, |
| 2667 | .poll = sonypi_misc_poll, |
| 2668 | .open = sonypi_misc_open, |
| 2669 | .release = sonypi_misc_release, |
| 2670 | .fasync = sonypi_misc_fasync, |
Alan Cox | 2b24ef0 | 2009-03-26 21:58:19 +0900 | [diff] [blame] | 2671 | .unlocked_ioctl = sonypi_misc_ioctl, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 2672 | .llseek = noop_llseek, |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2673 | }; |
| 2674 | |
| 2675 | static struct miscdevice sonypi_misc_device = { |
| 2676 | .minor = MISC_DYNAMIC_MINOR, |
| 2677 | .name = "sonypi", |
| 2678 | .fops = &sonypi_misc_fops, |
| 2679 | }; |
| 2680 | |
| 2681 | static void sonypi_compat_report_event(u8 event) |
| 2682 | { |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 2683 | kfifo_in_locked(&sonypi_compat.fifo, (unsigned char *)&event, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 2684 | sizeof(event), &sonypi_compat.fifo_lock); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2685 | kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN); |
| 2686 | wake_up_interruptible(&sonypi_compat.fifo_proc_list); |
| 2687 | } |
| 2688 | |
| 2689 | static int sonypi_compat_init(void) |
| 2690 | { |
| 2691 | int error; |
| 2692 | |
| 2693 | spin_lock_init(&sonypi_compat.fifo_lock); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2694 | error = |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 2695 | kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2696 | if (error) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2697 | pr_err(DRV_PFX "kfifo_alloc failed\n"); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2698 | return error; |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | init_waitqueue_head(&sonypi_compat.fifo_proc_list); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2702 | |
| 2703 | if (minor != -1) |
| 2704 | sonypi_misc_device.minor = minor; |
| 2705 | error = misc_register(&sonypi_misc_device); |
| 2706 | if (error) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2707 | pr_err(DRV_PFX "misc_register failed\n"); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2708 | goto err_free_kfifo; |
| 2709 | } |
| 2710 | if (minor == -1) |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2711 | pr_info(DRV_PFX "device allocated minor is %d\n", |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2712 | sonypi_misc_device.minor); |
| 2713 | |
| 2714 | return 0; |
| 2715 | |
| 2716 | err_free_kfifo: |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2717 | kfifo_free(&sonypi_compat.fifo); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2718 | return error; |
| 2719 | } |
| 2720 | |
| 2721 | static void sonypi_compat_exit(void) |
| 2722 | { |
| 2723 | misc_deregister(&sonypi_misc_device); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 2724 | kfifo_free(&sonypi_compat.fifo); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2725 | } |
| 2726 | #else |
| 2727 | static int sonypi_compat_init(void) { return 0; } |
| 2728 | static void sonypi_compat_exit(void) { } |
| 2729 | static void sonypi_compat_report_event(u8 event) { } |
Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 2730 | #endif /* CONFIG_SONYPI_COMPAT */ |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 2731 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 2732 | /* |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2733 | * ACPI callbacks |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 2734 | */ |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2735 | static acpi_status |
| 2736 | sony_pic_read_possible_resource(struct acpi_resource *resource, void *context) |
| 2737 | { |
| 2738 | u32 i; |
| 2739 | struct sony_pic_dev *dev = (struct sony_pic_dev *)context; |
| 2740 | |
| 2741 | switch (resource->type) { |
| 2742 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2743 | { |
| 2744 | /* start IO enumeration */ |
| 2745 | struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL); |
| 2746 | if (!ioport) |
| 2747 | return AE_ERROR; |
| 2748 | |
| 2749 | list_add(&ioport->list, &dev->ioports); |
| 2750 | return AE_OK; |
| 2751 | } |
| 2752 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2753 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2754 | /* end IO enumeration */ |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2755 | return AE_OK; |
| 2756 | |
| 2757 | case ACPI_RESOURCE_TYPE_IRQ: |
| 2758 | { |
| 2759 | struct acpi_resource_irq *p = &resource->data.irq; |
| 2760 | struct sony_pic_irq *interrupt = NULL; |
| 2761 | if (!p || !p->interrupt_count) { |
| 2762 | /* |
| 2763 | * IRQ descriptors may have no IRQ# bits set, |
| 2764 | * particularly those those w/ _STA disabled |
| 2765 | */ |
| 2766 | dprintk("Blank IRQ resource\n"); |
| 2767 | return AE_OK; |
| 2768 | } |
| 2769 | for (i = 0; i < p->interrupt_count; i++) { |
| 2770 | if (!p->interrupts[i]) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2771 | pr_warn(DRV_PFX "Invalid IRQ %d\n", |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2772 | p->interrupts[i]); |
| 2773 | continue; |
| 2774 | } |
| 2775 | interrupt = kzalloc(sizeof(*interrupt), |
| 2776 | GFP_KERNEL); |
| 2777 | if (!interrupt) |
| 2778 | return AE_ERROR; |
| 2779 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2780 | list_add(&interrupt->list, &dev->interrupts); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2781 | interrupt->irq.triggering = p->triggering; |
| 2782 | interrupt->irq.polarity = p->polarity; |
| 2783 | interrupt->irq.sharable = p->sharable; |
| 2784 | interrupt->irq.interrupt_count = 1; |
| 2785 | interrupt->irq.interrupts[0] = p->interrupts[i]; |
| 2786 | } |
| 2787 | return AE_OK; |
| 2788 | } |
| 2789 | case ACPI_RESOURCE_TYPE_IO: |
| 2790 | { |
| 2791 | struct acpi_resource_io *io = &resource->data.io; |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2792 | struct sony_pic_ioport *ioport = |
| 2793 | list_first_entry(&dev->ioports, struct sony_pic_ioport, list); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2794 | if (!io) { |
| 2795 | dprintk("Blank IO resource\n"); |
| 2796 | return AE_OK; |
| 2797 | } |
| 2798 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2799 | if (!ioport->io1.minimum) { |
| 2800 | memcpy(&ioport->io1, io, sizeof(*io)); |
| 2801 | dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum, |
| 2802 | ioport->io1.address_length); |
| 2803 | } |
| 2804 | else if (!ioport->io2.minimum) { |
| 2805 | memcpy(&ioport->io2, io, sizeof(*io)); |
| 2806 | dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum, |
| 2807 | ioport->io2.address_length); |
| 2808 | } |
| 2809 | else { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2810 | pr_err(DRV_PFX "Unknown SPIC Type, more than 2 IO Ports\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2811 | return AE_ERROR; |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2812 | } |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2813 | return AE_OK; |
| 2814 | } |
| 2815 | default: |
| 2816 | dprintk("Resource %d isn't an IRQ nor an IO port\n", |
| 2817 | resource->type); |
| 2818 | |
| 2819 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 2820 | return AE_OK; |
| 2821 | } |
| 2822 | return AE_CTRL_TERMINATE; |
| 2823 | } |
| 2824 | |
| 2825 | static int sony_pic_possible_resources(struct acpi_device *device) |
| 2826 | { |
| 2827 | int result = 0; |
| 2828 | acpi_status status = AE_OK; |
| 2829 | |
| 2830 | if (!device) |
| 2831 | return -EINVAL; |
| 2832 | |
| 2833 | /* get device status */ |
| 2834 | /* see acpi_pci_link_get_current acpi_pci_link_get_possible */ |
| 2835 | dprintk("Evaluating _STA\n"); |
| 2836 | result = acpi_bus_get_status(device); |
| 2837 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2838 | pr_warn(DRV_PFX "Unable to read status\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2839 | goto end; |
| 2840 | } |
| 2841 | |
| 2842 | if (!device->status.enabled) |
| 2843 | dprintk("Device disabled\n"); |
| 2844 | else |
| 2845 | dprintk("Device enabled\n"); |
| 2846 | |
| 2847 | /* |
| 2848 | * Query and parse 'method' |
| 2849 | */ |
| 2850 | dprintk("Evaluating %s\n", METHOD_NAME__PRS); |
| 2851 | status = acpi_walk_resources(device->handle, METHOD_NAME__PRS, |
| 2852 | sony_pic_read_possible_resource, &spic_dev); |
| 2853 | if (ACPI_FAILURE(status)) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2854 | pr_warn(DRV_PFX "Failure evaluating %s\n", |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2855 | METHOD_NAME__PRS); |
| 2856 | result = -ENODEV; |
| 2857 | } |
| 2858 | end: |
| 2859 | return result; |
| 2860 | } |
| 2861 | |
| 2862 | /* |
| 2863 | * Disable the spic device by calling its _DIS method |
| 2864 | */ |
| 2865 | static int sony_pic_disable(struct acpi_device *device) |
| 2866 | { |
Matthew Garrett | 6158d3a | 2008-10-29 14:01:03 -0700 | [diff] [blame] | 2867 | acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL, |
| 2868 | NULL); |
| 2869 | |
| 2870 | if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND) |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2871 | return -ENXIO; |
| 2872 | |
| 2873 | dprintk("Device disabled\n"); |
| 2874 | return 0; |
| 2875 | } |
| 2876 | |
| 2877 | |
| 2878 | /* |
| 2879 | * Based on drivers/acpi/pci_link.c:acpi_pci_link_set |
| 2880 | * |
| 2881 | * Call _SRS to set current resources |
| 2882 | */ |
| 2883 | static int sony_pic_enable(struct acpi_device *device, |
| 2884 | struct sony_pic_ioport *ioport, struct sony_pic_irq *irq) |
| 2885 | { |
| 2886 | acpi_status status; |
| 2887 | int result = 0; |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2888 | /* Type 1 resource layout is: |
| 2889 | * IO |
| 2890 | * IO |
| 2891 | * IRQNoFlags |
| 2892 | * End |
| 2893 | * |
| 2894 | * Type 2 and 3 resource layout is: |
| 2895 | * IO |
| 2896 | * IRQNoFlags |
| 2897 | * End |
| 2898 | */ |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2899 | struct { |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2900 | struct acpi_resource res1; |
| 2901 | struct acpi_resource res2; |
| 2902 | struct acpi_resource res3; |
| 2903 | struct acpi_resource res4; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2904 | } *resource; |
| 2905 | struct acpi_buffer buffer = { 0, NULL }; |
| 2906 | |
| 2907 | if (!ioport || !irq) |
| 2908 | return -EINVAL; |
| 2909 | |
| 2910 | /* init acpi_buffer */ |
| 2911 | resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL); |
| 2912 | if (!resource) |
| 2913 | return -ENOMEM; |
| 2914 | |
| 2915 | buffer.length = sizeof(*resource) + 1; |
| 2916 | buffer.pointer = resource; |
| 2917 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2918 | /* setup Type 1 resources */ |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2919 | if (spic_dev.model == SONYPI_DEVICE_TYPE1) { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2920 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2921 | /* setup io resources */ |
| 2922 | resource->res1.type = ACPI_RESOURCE_TYPE_IO; |
| 2923 | resource->res1.length = sizeof(struct acpi_resource); |
| 2924 | memcpy(&resource->res1.data.io, &ioport->io1, |
| 2925 | sizeof(struct acpi_resource_io)); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2926 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2927 | resource->res2.type = ACPI_RESOURCE_TYPE_IO; |
| 2928 | resource->res2.length = sizeof(struct acpi_resource); |
| 2929 | memcpy(&resource->res2.data.io, &ioport->io2, |
| 2930 | sizeof(struct acpi_resource_io)); |
| 2931 | |
| 2932 | /* setup irq resource */ |
| 2933 | resource->res3.type = ACPI_RESOURCE_TYPE_IRQ; |
| 2934 | resource->res3.length = sizeof(struct acpi_resource); |
| 2935 | memcpy(&resource->res3.data.irq, &irq->irq, |
| 2936 | sizeof(struct acpi_resource_irq)); |
| 2937 | /* we requested a shared irq */ |
| 2938 | resource->res3.data.irq.sharable = ACPI_SHARED; |
| 2939 | |
| 2940 | resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG; |
| 2941 | |
| 2942 | } |
| 2943 | /* setup Type 2/3 resources */ |
| 2944 | else { |
| 2945 | /* setup io resource */ |
| 2946 | resource->res1.type = ACPI_RESOURCE_TYPE_IO; |
| 2947 | resource->res1.length = sizeof(struct acpi_resource); |
| 2948 | memcpy(&resource->res1.data.io, &ioport->io1, |
| 2949 | sizeof(struct acpi_resource_io)); |
| 2950 | |
| 2951 | /* setup irq resource */ |
| 2952 | resource->res2.type = ACPI_RESOURCE_TYPE_IRQ; |
| 2953 | resource->res2.length = sizeof(struct acpi_resource); |
| 2954 | memcpy(&resource->res2.data.irq, &irq->irq, |
| 2955 | sizeof(struct acpi_resource_irq)); |
| 2956 | /* we requested a shared irq */ |
| 2957 | resource->res2.data.irq.sharable = ACPI_SHARED; |
| 2958 | |
| 2959 | resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG; |
| 2960 | } |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2961 | |
| 2962 | /* Attempt to set the resource */ |
| 2963 | dprintk("Evaluating _SRS\n"); |
| 2964 | status = acpi_set_current_resources(device->handle, &buffer); |
| 2965 | |
| 2966 | /* check for total failure */ |
| 2967 | if (ACPI_FAILURE(status)) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2968 | pr_err(DRV_PFX "Error evaluating _SRS\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2969 | result = -ENODEV; |
| 2970 | goto end; |
| 2971 | } |
| 2972 | |
| 2973 | /* Necessary device initializations calls (from sonypi) */ |
| 2974 | sony_pic_call1(0x82); |
| 2975 | sony_pic_call2(0x81, 0xff); |
| 2976 | sony_pic_call1(compat ? 0x92 : 0x82); |
| 2977 | |
| 2978 | end: |
| 2979 | kfree(resource); |
| 2980 | return result; |
| 2981 | } |
| 2982 | |
| 2983 | /***************** |
| 2984 | * |
| 2985 | * ISR: some event is available |
| 2986 | * |
| 2987 | *****************/ |
| 2988 | static irqreturn_t sony_pic_irq(int irq, void *dev_id) |
| 2989 | { |
| 2990 | int i, j; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2991 | u8 ev = 0; |
| 2992 | u8 data_mask = 0; |
| 2993 | u8 device_event = 0; |
| 2994 | |
| 2995 | struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id; |
| 2996 | |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2997 | ev = inb_p(dev->cur_ioport->io1.minimum); |
| 2998 | if (dev->cur_ioport->io2.minimum) |
| 2999 | data_mask = inb_p(dev->cur_ioport->io2.minimum); |
| 3000 | else |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3001 | data_mask = inb_p(dev->cur_ioport->io1.minimum + |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3002 | dev->evport_offset); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3003 | |
Mattia Dongili | 22a1778 | 2007-07-16 02:34:39 +0900 | [diff] [blame] | 3004 | dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n", |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3005 | ev, data_mask, dev->cur_ioport->io1.minimum, |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3006 | dev->evport_offset); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3007 | |
| 3008 | if (ev == 0x00 || ev == 0xff) |
| 3009 | return IRQ_HANDLED; |
| 3010 | |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3011 | for (i = 0; dev->event_types[i].mask; i++) { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3012 | |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3013 | if ((data_mask & dev->event_types[i].data) != |
| 3014 | dev->event_types[i].data) |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3015 | continue; |
| 3016 | |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3017 | if (!(mask & dev->event_types[i].mask)) |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3018 | continue; |
| 3019 | |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3020 | for (j = 0; dev->event_types[i].events[j].event; j++) { |
| 3021 | if (ev == dev->event_types[i].events[j].data) { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3022 | device_event = |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3023 | dev->event_types[i].events[j].event; |
Mattia Dongili | 4eeb502 | 2011-02-19 11:52:27 +0900 | [diff] [blame] | 3024 | /* some events may require ignoring */ |
| 3025 | if (!device_event) |
| 3026 | return IRQ_HANDLED; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3027 | goto found; |
| 3028 | } |
| 3029 | } |
| 3030 | } |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3031 | /* Still not able to decode the event try to pass |
| 3032 | * it over to the minidriver |
| 3033 | */ |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3034 | if (dev->handle_irq && dev->handle_irq(data_mask, ev) == 0) |
Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3035 | return IRQ_HANDLED; |
| 3036 | |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3037 | dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n", |
| 3038 | ev, data_mask, dev->cur_ioport->io1.minimum, |
Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3039 | dev->evport_offset); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3040 | return IRQ_HANDLED; |
| 3041 | |
| 3042 | found: |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 3043 | sony_laptop_report_input_event(device_event); |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3044 | acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event); |
malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3045 | sonypi_compat_report_event(device_event); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3046 | return IRQ_HANDLED; |
| 3047 | } |
| 3048 | |
| 3049 | /***************** |
| 3050 | * |
| 3051 | * ACPI driver |
| 3052 | * |
| 3053 | *****************/ |
| 3054 | static int sony_pic_remove(struct acpi_device *device, int type) |
| 3055 | { |
| 3056 | struct sony_pic_ioport *io, *tmp_io; |
| 3057 | struct sony_pic_irq *irq, *tmp_irq; |
| 3058 | |
| 3059 | if (sony_pic_disable(device)) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3060 | pr_err(DRV_PFX "Couldn't disable device.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3061 | return -ENXIO; |
| 3062 | } |
| 3063 | |
| 3064 | free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev); |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3065 | release_region(spic_dev.cur_ioport->io1.minimum, |
| 3066 | spic_dev.cur_ioport->io1.address_length); |
| 3067 | if (spic_dev.cur_ioport->io2.minimum) |
| 3068 | release_region(spic_dev.cur_ioport->io2.minimum, |
| 3069 | spic_dev.cur_ioport->io2.address_length); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3070 | |
Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 3071 | sonypi_compat_exit(); |
| 3072 | |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 3073 | sony_laptop_remove_input(); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3074 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3075 | /* pf attrs */ |
| 3076 | sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group); |
| 3077 | sony_pf_remove(); |
| 3078 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3079 | list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) { |
| 3080 | list_del(&io->list); |
| 3081 | kfree(io); |
| 3082 | } |
| 3083 | list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) { |
| 3084 | list_del(&irq->list); |
| 3085 | kfree(irq); |
| 3086 | } |
| 3087 | spic_dev.cur_ioport = NULL; |
| 3088 | spic_dev.cur_irq = NULL; |
| 3089 | |
malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 3090 | dprintk(SONY_PIC_DRIVER_NAME " removed.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3091 | return 0; |
| 3092 | } |
| 3093 | |
| 3094 | static int sony_pic_add(struct acpi_device *device) |
| 3095 | { |
| 3096 | int result; |
| 3097 | struct sony_pic_ioport *io, *tmp_io; |
| 3098 | struct sony_pic_irq *irq, *tmp_irq; |
| 3099 | |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3100 | pr_info(DRV_PFX "%s v%s.\n", SONY_PIC_DRIVER_NAME, |
| 3101 | SONY_LAPTOP_DRIVER_VERSION); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3102 | |
| 3103 | spic_dev.acpi_dev = device; |
| 3104 | strcpy(acpi_device_class(device), "sony/hotkey"); |
Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3105 | sony_pic_detect_device_type(&spic_dev); |
malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3106 | mutex_init(&spic_dev.lock); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3107 | |
| 3108 | /* read _PRS resources */ |
| 3109 | result = sony_pic_possible_resources(device); |
| 3110 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3111 | pr_err(DRV_PFX "Unable to read possible resources.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3112 | goto err_free_resources; |
| 3113 | } |
| 3114 | |
| 3115 | /* setup input devices and helper fifo */ |
Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 3116 | result = sony_laptop_setup_input(device); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3117 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3118 | pr_err(DRV_PFX "Unable to create input devices.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3119 | goto err_free_resources; |
| 3120 | } |
| 3121 | |
Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 3122 | if (sonypi_compat_init()) |
| 3123 | goto err_remove_input; |
| 3124 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3125 | /* request io port */ |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3126 | list_for_each_entry_reverse(io, &spic_dev.ioports, list) { |
| 3127 | if (request_region(io->io1.minimum, io->io1.address_length, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3128 | "Sony Programable I/O Device")) { |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3129 | dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n", |
| 3130 | io->io1.minimum, io->io1.maximum, |
| 3131 | io->io1.address_length); |
| 3132 | /* Type 1 have 2 ioports */ |
| 3133 | if (io->io2.minimum) { |
| 3134 | if (request_region(io->io2.minimum, |
| 3135 | io->io2.address_length, |
| 3136 | "Sony Programable I/O Device")) { |
| 3137 | dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n", |
| 3138 | io->io2.minimum, io->io2.maximum, |
| 3139 | io->io2.address_length); |
| 3140 | spic_dev.cur_ioport = io; |
| 3141 | break; |
| 3142 | } |
| 3143 | else { |
| 3144 | dprintk("Unable to get I/O port2: " |
| 3145 | "0x%.4x (0x%.4x) + 0x%.2x\n", |
| 3146 | io->io2.minimum, io->io2.maximum, |
| 3147 | io->io2.address_length); |
| 3148 | release_region(io->io1.minimum, |
| 3149 | io->io1.address_length); |
| 3150 | } |
| 3151 | } |
| 3152 | else { |
| 3153 | spic_dev.cur_ioport = io; |
| 3154 | break; |
| 3155 | } |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | if (!spic_dev.cur_ioport) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3159 | pr_err(DRV_PFX "Failed to request_region.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3160 | result = -ENODEV; |
Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 3161 | goto err_remove_compat; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | /* request IRQ */ |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3165 | list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3166 | if (!request_irq(irq->irq.interrupts[0], sony_pic_irq, |
Mattia Dongili | d1e0de9 | 2009-09-16 00:05:30 +0900 | [diff] [blame] | 3167 | IRQF_DISABLED, "sony-laptop", &spic_dev)) { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3168 | dprintk("IRQ: %d - triggering: %d - " |
| 3169 | "polarity: %d - shr: %d\n", |
| 3170 | irq->irq.interrupts[0], |
| 3171 | irq->irq.triggering, |
| 3172 | irq->irq.polarity, |
| 3173 | irq->irq.sharable); |
| 3174 | spic_dev.cur_irq = irq; |
| 3175 | break; |
| 3176 | } |
| 3177 | } |
| 3178 | if (!spic_dev.cur_irq) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3179 | pr_err(DRV_PFX "Failed to request_irq.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3180 | result = -ENODEV; |
| 3181 | goto err_release_region; |
| 3182 | } |
| 3183 | |
| 3184 | /* set resource status _SRS */ |
| 3185 | result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq); |
| 3186 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3187 | pr_err(DRV_PFX "Couldn't enable device.\n"); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3188 | goto err_free_irq; |
| 3189 | } |
| 3190 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3191 | spic_dev.bluetooth_power = -1; |
| 3192 | /* create device attributes */ |
| 3193 | result = sony_pf_add(); |
| 3194 | if (result) |
| 3195 | goto err_disable_device; |
| 3196 | |
| 3197 | result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group); |
| 3198 | if (result) |
| 3199 | goto err_remove_pf; |
| 3200 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3201 | return 0; |
| 3202 | |
malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3203 | err_remove_pf: |
| 3204 | sony_pf_remove(); |
| 3205 | |
| 3206 | err_disable_device: |
| 3207 | sony_pic_disable(device); |
| 3208 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3209 | err_free_irq: |
| 3210 | free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev); |
| 3211 | |
| 3212 | err_release_region: |
Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3213 | release_region(spic_dev.cur_ioport->io1.minimum, |
| 3214 | spic_dev.cur_ioport->io1.address_length); |
| 3215 | if (spic_dev.cur_ioport->io2.minimum) |
| 3216 | release_region(spic_dev.cur_ioport->io2.minimum, |
| 3217 | spic_dev.cur_ioport->io2.address_length); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3218 | |
Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 3219 | err_remove_compat: |
| 3220 | sonypi_compat_exit(); |
| 3221 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3222 | err_remove_input: |
malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 3223 | sony_laptop_remove_input(); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3224 | |
| 3225 | err_free_resources: |
| 3226 | list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) { |
| 3227 | list_del(&io->list); |
| 3228 | kfree(io); |
| 3229 | } |
| 3230 | list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) { |
| 3231 | list_del(&irq->list); |
| 3232 | kfree(irq); |
| 3233 | } |
| 3234 | spic_dev.cur_ioport = NULL; |
| 3235 | spic_dev.cur_irq = NULL; |
| 3236 | |
| 3237 | return result; |
| 3238 | } |
| 3239 | |
| 3240 | static int sony_pic_suspend(struct acpi_device *device, pm_message_t state) |
| 3241 | { |
| 3242 | if (sony_pic_disable(device)) |
| 3243 | return -ENXIO; |
| 3244 | return 0; |
| 3245 | } |
| 3246 | |
| 3247 | static int sony_pic_resume(struct acpi_device *device) |
| 3248 | { |
| 3249 | sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq); |
| 3250 | return 0; |
| 3251 | } |
| 3252 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3253 | static const struct acpi_device_id sony_pic_device_ids[] = { |
| 3254 | {SONY_PIC_HID, 0}, |
| 3255 | {"", 0}, |
| 3256 | }; |
| 3257 | |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3258 | static struct acpi_driver sony_pic_driver = { |
| 3259 | .name = SONY_PIC_DRIVER_NAME, |
| 3260 | .class = SONY_PIC_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3261 | .ids = sony_pic_device_ids, |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3262 | .owner = THIS_MODULE, |
| 3263 | .ops = { |
| 3264 | .add = sony_pic_add, |
| 3265 | .remove = sony_pic_remove, |
| 3266 | .suspend = sony_pic_suspend, |
| 3267 | .resume = sony_pic_resume, |
| 3268 | }, |
| 3269 | }; |
| 3270 | |
| 3271 | static struct dmi_system_id __initdata sonypi_dmi_table[] = { |
| 3272 | { |
| 3273 | .ident = "Sony Vaio", |
| 3274 | .matches = { |
| 3275 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 3276 | DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"), |
| 3277 | }, |
| 3278 | }, |
| 3279 | { |
| 3280 | .ident = "Sony Vaio", |
| 3281 | .matches = { |
| 3282 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
| 3283 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"), |
| 3284 | }, |
| 3285 | }, |
| 3286 | { } |
| 3287 | }; |
| 3288 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 3289 | static int __init sony_laptop_init(void) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3290 | { |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3291 | int result; |
| 3292 | |
| 3293 | if (!no_spic && dmi_check_system(sonypi_dmi_table)) { |
| 3294 | result = acpi_bus_register_driver(&sony_pic_driver); |
| 3295 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3296 | pr_err(DRV_PFX "Unable to register SPIC driver."); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3297 | goto out; |
| 3298 | } |
Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 3299 | spic_drv_registered = 1; |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | result = acpi_bus_register_driver(&sony_nc_driver); |
| 3303 | if (result) { |
Mattia Dongili | d6697938 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 3304 | pr_err(DRV_PFX "Unable to register SNC driver."); |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3305 | goto out_unregister_pic; |
| 3306 | } |
| 3307 | |
| 3308 | return 0; |
| 3309 | |
| 3310 | out_unregister_pic: |
Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 3311 | if (spic_drv_registered) |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3312 | acpi_bus_unregister_driver(&sony_pic_driver); |
| 3313 | out: |
| 3314 | return result; |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3315 | } |
| 3316 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 3317 | static void __exit sony_laptop_exit(void) |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3318 | { |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 3319 | acpi_bus_unregister_driver(&sony_nc_driver); |
Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 3320 | if (spic_drv_registered) |
malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3321 | acpi_bus_unregister_driver(&sony_pic_driver); |
Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3322 | } |
| 3323 | |
malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 3324 | module_init(sony_laptop_init); |
| 3325 | module_exit(sony_laptop_exit); |