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