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