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