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