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