| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1 | /* | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2 |  * ACPI Sony Notebook Control Driver (SNC and SPIC) | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 3 |  * | 
 | 4 |  * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net> | 
| Mattia Dongili | 3741834 | 2009-03-26 21:58:24 +0900 | [diff] [blame] | 5 |  * Copyright (C) 2007-2009 Mattia Dongili <malattia@linux.it> | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 6 |  * | 
 | 7 |  * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c | 
 | 8 |  * which are copyrighted by their respective authors. | 
 | 9 |  * | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 10 |  * The SNY6001 driver part is based on the sonypi driver which includes | 
 | 11 |  * material from: | 
 | 12 |  * | 
 | 13 |  * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net> | 
 | 14 |  * | 
 | 15 |  * Copyright (C) 2005 Narayanan R S <nars@kadamba.org> | 
 | 16 |  * | 
| Marcin Garski | db955170 | 2007-10-19 23:22:11 +0200 | [diff] [blame] | 17 |  * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com> | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 18 |  * | 
 | 19 |  * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au> | 
 | 20 |  * | 
 | 21 |  * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp> | 
 | 22 |  * | 
 | 23 |  * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp> | 
 | 24 |  * | 
 | 25 |  * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com> | 
 | 26 |  * | 
 | 27 |  * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras. | 
 | 28 |  * | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 29 |  * This program is free software; you can redistribute it and/or modify | 
 | 30 |  * it under the terms of the GNU General Public License as published by | 
 | 31 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 32 |  * (at your option) any later version. | 
 | 33 |  * | 
 | 34 |  * This program is distributed in the hope that it will be useful, | 
 | 35 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 36 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 37 |  * GNU General Public License for more details. | 
 | 38 |  * | 
 | 39 |  * You should have received a copy of the GNU General Public License | 
 | 40 |  * along with this program; if not, write to the Free Software | 
 | 41 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 42 |  * | 
 | 43 |  */ | 
 | 44 |  | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 45 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
 | 46 |  | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 47 | #include <linux/kernel.h> | 
 | 48 | #include <linux/module.h> | 
 | 49 | #include <linux/moduleparam.h> | 
 | 50 | #include <linux/init.h> | 
 | 51 | #include <linux/types.h> | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 52 | #include <linux/backlight.h> | 
| Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 53 | #include <linux/platform_device.h> | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 54 | #include <linux/err.h> | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 55 | #include <linux/dmi.h> | 
 | 56 | #include <linux/pci.h> | 
 | 57 | #include <linux/interrupt.h> | 
 | 58 | #include <linux/delay.h> | 
 | 59 | #include <linux/input.h> | 
 | 60 | #include <linux/kfifo.h> | 
 | 61 | #include <linux/workqueue.h> | 
 | 62 | #include <linux/acpi.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 63 | #include <linux/slab.h> | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 64 | #include <acpi/acpi_drivers.h> | 
 | 65 | #include <acpi/acpi_bus.h> | 
 | 66 | #include <asm/uaccess.h> | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 67 | #include <linux/sonypi.h> | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 68 | #include <linux/sony-laptop.h> | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 69 | #include <linux/rfkill.h> | 
| Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 70 | #ifdef CONFIG_SONYPI_COMPAT | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 71 | #include <linux/poll.h> | 
 | 72 | #include <linux/miscdevice.h> | 
 | 73 | #endif | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 74 |  | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 75 | #define dprintk(fmt, ...)			\ | 
 | 76 | do {						\ | 
 | 77 | 	if (debug)				\ | 
 | 78 | 		pr_warn(fmt, ##__VA_ARGS__);	\ | 
| malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 79 | } while (0) | 
 | 80 |  | 
| Mattia Dongili | 425ef5d | 2008-01-14 18:05:44 +0900 | [diff] [blame] | 81 | #define SONY_LAPTOP_DRIVER_VERSION	"0.6" | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 82 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 83 | #define SONY_NC_CLASS		"sony-nc" | 
 | 84 | #define SONY_NC_HID		"SNY5001" | 
| malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 85 | #define SONY_NC_DRIVER_NAME	"Sony Notebook Control Driver" | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 86 |  | 
 | 87 | #define SONY_PIC_CLASS		"sony-pic" | 
 | 88 | #define SONY_PIC_HID		"SNY6001" | 
| malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 89 | #define SONY_PIC_DRIVER_NAME	"Sony Programmable IO Control Driver" | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 90 |  | 
| Mattia Dongili | ed3aa4b | 2007-02-07 20:01:54 +0100 | [diff] [blame] | 91 | MODULE_AUTHOR("Stelian Pop, Mattia Dongili"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 92 | MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)"); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 93 | MODULE_LICENSE("GPL"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 94 | MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 95 |  | 
 | 96 | static int debug; | 
 | 97 | module_param(debug, int, 0); | 
 | 98 | MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help " | 
| Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 99 | 		 "the development of this driver"); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 100 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 101 | static int no_spic;		/* = 0 */ | 
 | 102 | module_param(no_spic, int, 0444); | 
 | 103 | MODULE_PARM_DESC(no_spic, | 
 | 104 | 		 "set this if you don't want to enable the SPIC device"); | 
 | 105 |  | 
 | 106 | static int compat;		/* = 0 */ | 
 | 107 | module_param(compat, int, 0444); | 
 | 108 | MODULE_PARM_DESC(compat, | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 109 | 		 "set this if you want to enable backward compatibility mode"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 110 |  | 
 | 111 | static unsigned long mask = 0xffffffff; | 
 | 112 | module_param(mask, ulong, 0644); | 
 | 113 | MODULE_PARM_DESC(mask, | 
 | 114 | 		 "set this to the mask of event you want to enable (see doc)"); | 
 | 115 |  | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 116 | static int camera;		/* = 0 */ | 
 | 117 | module_param(camera, int, 0444); | 
 | 118 | MODULE_PARM_DESC(camera, | 
 | 119 | 		 "set this to 1 to enable Motion Eye camera controls " | 
 | 120 | 		 "(only use it if you have a C1VE or C1VN model)"); | 
 | 121 |  | 
| Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 122 | #ifdef CONFIG_SONYPI_COMPAT | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 123 | static int minor = -1; | 
 | 124 | module_param(minor, int, 0); | 
 | 125 | MODULE_PARM_DESC(minor, | 
 | 126 | 		 "minor number of the misc device for the SPIC compatibility code, " | 
 | 127 | 		 "default is -1 (automatic)"); | 
 | 128 | #endif | 
 | 129 |  | 
| Josh Boyer | 6fe6ae5 | 2011-11-02 14:32:00 -0400 | [diff] [blame] | 130 | static int kbd_backlight = 1; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 131 | module_param(kbd_backlight, int, 0444); | 
 | 132 | MODULE_PARM_DESC(kbd_backlight, | 
 | 133 | 		 "set this to 0 to disable keyboard backlight, " | 
 | 134 | 		 "1 to enable it (default: 0)"); | 
 | 135 |  | 
 | 136 | static int kbd_backlight_timeout;	/* = 0 */ | 
 | 137 | module_param(kbd_backlight_timeout, int, 0444); | 
 | 138 | MODULE_PARM_DESC(kbd_backlight_timeout, | 
 | 139 | 		 "set this to 0 to set the default 10 seconds timeout, " | 
 | 140 | 		 "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout " | 
 | 141 | 		 "(default: 0)"); | 
 | 142 |  | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 143 | #ifdef CONFIG_PM_SLEEP | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 144 | static void sony_nc_kbd_backlight_resume(void); | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 145 | static void sony_nc_thermal_resume(void); | 
 | 146 | #endif | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 147 | static int sony_nc_kbd_backlight_setup(struct platform_device *pd, | 
 | 148 | 		unsigned int handle); | 
 | 149 | static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd); | 
| 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 */ | 
 | 308 | 	KEY_FN_F1,	/* 17 SONYPI_EVENT_FNKEY_1 */ | 
 | 309 | 	KEY_FN_F2,	/* 18 SONYPI_EVENT_FNKEY_2 */ | 
 | 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 | 855b8bc | 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 | 855b8bc | 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 | c7a29183 | 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 | c7a29183 | 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 | c7a29183 | 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 |  | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1258 | 		default: | 
 | 1259 | 			dprintk("Unknown event 0x%x for handle 0x%x\n", | 
 | 1260 | 					event, handle); | 
 | 1261 | 			break; | 
 | 1262 | 		} | 
 | 1263 |  | 
 | 1264 | 		/* clear the event (and the event reason when present) */ | 
 | 1265 | 		arg = 1 << offset; | 
 | 1266 | 		sony_nc_int_call(sony_nc_acpi_handle, "SN05", &arg, &result); | 
 | 1267 |  | 
 | 1268 | 	} else { | 
 | 1269 | 		/* old style event */ | 
| Mattia Dongili | 4069d6f | 2012-06-09 13:18:08 +0900 | [diff] [blame] | 1270 | 		ev_type = HOTKEY; | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1271 | 		sony_laptop_report_input_event(real_ev); | 
 | 1272 | 	} | 
 | 1273 |  | 
 | 1274 | 	acpi_bus_generate_proc_event(sony_nc_acpi_device, ev_type, real_ev); | 
 | 1275 |  | 
 | 1276 | 	acpi_bus_generate_netlink_event(sony_nc_acpi_device->pnp.device_class, | 
 | 1277 | 			dev_name(&sony_nc_acpi_device->dev), ev_type, real_ev); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1278 | } | 
 | 1279 |  | 
 | 1280 | static acpi_status sony_walk_callback(acpi_handle handle, u32 level, | 
 | 1281 | 				      void *context, void **return_value) | 
 | 1282 | { | 
| Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1283 | 	struct acpi_device_info *info; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1284 |  | 
| Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 1285 | 	if (ACPI_SUCCESS(acpi_get_object_info(handle, &info))) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 1286 | 		pr_warn("method: name: %4.4s, args %X\n", | 
| Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1287 | 			(char *)&info->name, info->param_count); | 
 | 1288 |  | 
| Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 1289 | 		kfree(info); | 
| Lin Ming | 3082373 | 2008-12-16 16:59:35 +0800 | [diff] [blame] | 1290 | 	} | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 1291 |  | 
 | 1292 | 	return AE_OK; | 
 | 1293 | } | 
 | 1294 |  | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1295 | /* | 
 | 1296 |  * ACPI device | 
 | 1297 |  */ | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1298 | static void sony_nc_function_setup(struct acpi_device *device, | 
 | 1299 | 		struct platform_device *pf_device) | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1300 | { | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1301 | 	unsigned int i, result, bitmask, arg; | 
 | 1302 |  | 
 | 1303 | 	if (!handles) | 
 | 1304 | 		return; | 
 | 1305 |  | 
 | 1306 | 	/* setup found handles here */ | 
 | 1307 | 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { | 
 | 1308 | 		unsigned int handle = handles->cap[i]; | 
 | 1309 |  | 
 | 1310 | 		if (!handle) | 
 | 1311 | 			continue; | 
 | 1312 |  | 
 | 1313 | 		dprintk("setting up handle 0x%.4x\n", handle); | 
 | 1314 |  | 
 | 1315 | 		switch (handle) { | 
 | 1316 | 		case 0x0100: | 
 | 1317 | 		case 0x0101: | 
 | 1318 | 		case 0x0127: | 
 | 1319 | 			/* setup hotkeys */ | 
 | 1320 | 			sony_call_snc_handle(handle, 0, &result); | 
 | 1321 | 			break; | 
 | 1322 | 		case 0x0102: | 
 | 1323 | 			/* setup hotkeys */ | 
 | 1324 | 			sony_call_snc_handle(handle, 0x100, &result); | 
 | 1325 | 			break; | 
| Marco Chiappero | 2b8791c | 2012-05-19 22:36:00 +0900 | [diff] [blame] | 1326 | 		case 0x0105: | 
 | 1327 | 		case 0x0148: | 
 | 1328 | 			/* touchpad enable/disable */ | 
 | 1329 | 			result = sony_nc_touchpad_setup(pf_device, handle); | 
 | 1330 | 			if (result) | 
 | 1331 | 				pr_err("couldn't set up touchpad control function (%d)\n", | 
 | 1332 | 						result); | 
 | 1333 | 			break; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1334 | 		case 0x0115: | 
 | 1335 | 		case 0x0136: | 
 | 1336 | 		case 0x013f: | 
 | 1337 | 			result = sony_nc_battery_care_setup(pf_device, handle); | 
 | 1338 | 			if (result) | 
 | 1339 | 				pr_err("couldn't set up battery care function (%d)\n", | 
 | 1340 | 						result); | 
 | 1341 | 			break; | 
| Marco Chiappero | 54535d0 | 2012-05-19 22:35:54 +0900 | [diff] [blame] | 1342 | 		case 0x0119: | 
 | 1343 | 			result = sony_nc_lid_resume_setup(pf_device); | 
 | 1344 | 			if (result) | 
 | 1345 | 				pr_err("couldn't set up lid resume function (%d)\n", | 
 | 1346 | 						result); | 
 | 1347 | 			break; | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 1348 | 		case 0x0122: | 
 | 1349 | 			result = sony_nc_thermal_setup(pf_device); | 
 | 1350 | 			if (result) | 
 | 1351 | 				pr_err("couldn't set up thermal profile function (%d)\n", | 
 | 1352 | 						result); | 
 | 1353 | 			break; | 
| Mattia Dongili | 3a7abcd | 2012-12-21 07:21:10 +0900 | [diff] [blame] | 1354 | 		case 0x0128: | 
 | 1355 | 		case 0x0146: | 
 | 1356 | 			result = sony_nc_gfx_switch_setup(pf_device, handle); | 
 | 1357 | 			if (result) | 
 | 1358 | 				pr_err("couldn't set up GFX Switch status (%d)\n", | 
 | 1359 | 						result); | 
 | 1360 | 			break; | 
| Marco Chiappero | 88bf170 | 2012-05-19 22:35:55 +0900 | [diff] [blame] | 1361 | 		case 0x0131: | 
 | 1362 | 			result = sony_nc_highspeed_charging_setup(pf_device); | 
 | 1363 | 			if (result) | 
 | 1364 | 				pr_err("couldn't set up high speed charging function (%d)\n", | 
 | 1365 | 				       result); | 
 | 1366 | 			break; | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1367 | 		case 0x0124: | 
 | 1368 | 		case 0x0135: | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1369 | 			result = sony_nc_rfkill_setup(device, handle); | 
 | 1370 | 			if (result) | 
 | 1371 | 				pr_err("couldn't set up rfkill support (%d)\n", | 
 | 1372 | 						result); | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1373 | 			break; | 
 | 1374 | 		case 0x0137: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1375 | 		case 0x0143: | 
| Mattia Dongili | 7517a17 | 2012-12-21 07:21:11 +0900 | [diff] [blame] | 1376 | 		case 0x014b: | 
 | 1377 | 		case 0x014c: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1378 | 			result = sony_nc_kbd_backlight_setup(pf_device, handle); | 
 | 1379 | 			if (result) | 
 | 1380 | 				pr_err("couldn't set up keyboard backlight function (%d)\n", | 
 | 1381 | 						result); | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1382 | 			break; | 
 | 1383 | 		default: | 
 | 1384 | 			continue; | 
 | 1385 | 		} | 
 | 1386 | 	} | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1387 |  | 
 | 1388 | 	/* Enable all events */ | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1389 | 	arg = 0x10; | 
 | 1390 | 	if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask)) | 
 | 1391 | 		sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask, | 
 | 1392 | 				&result); | 
 | 1393 | } | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1394 |  | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1395 | static void sony_nc_function_cleanup(struct platform_device *pd) | 
 | 1396 | { | 
 | 1397 | 	unsigned int i, result, bitmask, handle; | 
| 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 | 	/* get enabled events and disable them */ | 
 | 1400 | 	sony_nc_int_call(sony_nc_acpi_handle, "SN01", NULL, &bitmask); | 
 | 1401 | 	sony_nc_int_call(sony_nc_acpi_handle, "SN03", &bitmask, &result); | 
 | 1402 |  | 
 | 1403 | 	/* cleanup handles here */ | 
 | 1404 | 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { | 
 | 1405 |  | 
 | 1406 | 		handle = handles->cap[i]; | 
 | 1407 |  | 
 | 1408 | 		if (!handle) | 
 | 1409 | 			continue; | 
 | 1410 |  | 
 | 1411 | 		switch (handle) { | 
| Marco Chiappero | 2b8791c | 2012-05-19 22:36:00 +0900 | [diff] [blame] | 1412 | 		case 0x0105: | 
 | 1413 | 		case 0x0148: | 
 | 1414 | 			sony_nc_touchpad_cleanup(pd); | 
 | 1415 | 			break; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1416 | 		case 0x0115: | 
 | 1417 | 		case 0x0136: | 
 | 1418 | 		case 0x013f: | 
 | 1419 | 			sony_nc_battery_care_cleanup(pd); | 
 | 1420 | 			break; | 
| Marco Chiappero | 54535d0 | 2012-05-19 22:35:54 +0900 | [diff] [blame] | 1421 | 		case 0x0119: | 
 | 1422 | 			sony_nc_lid_resume_cleanup(pd); | 
 | 1423 | 			break; | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 1424 | 		case 0x0122: | 
 | 1425 | 			sony_nc_thermal_cleanup(pd); | 
 | 1426 | 			break; | 
| Mattia Dongili | 3a7abcd | 2012-12-21 07:21:10 +0900 | [diff] [blame] | 1427 | 		case 0x0128: | 
 | 1428 | 		case 0x0146: | 
 | 1429 | 			sony_nc_gfx_switch_cleanup(pd); | 
 | 1430 | 			break; | 
| Marco Chiappero | 88bf170 | 2012-05-19 22:35:55 +0900 | [diff] [blame] | 1431 | 		case 0x0131: | 
 | 1432 | 			sony_nc_highspeed_charging_cleanup(pd); | 
 | 1433 | 			break; | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1434 | 		case 0x0124: | 
 | 1435 | 		case 0x0135: | 
 | 1436 | 			sony_nc_rfkill_cleanup(); | 
 | 1437 | 			break; | 
 | 1438 | 		case 0x0137: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1439 | 		case 0x0143: | 
| Mattia Dongili | 7517a17 | 2012-12-21 07:21:11 +0900 | [diff] [blame] | 1440 | 		case 0x014b: | 
 | 1441 | 		case 0x014c: | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1442 | 			sony_nc_kbd_backlight_cleanup(pd); | 
 | 1443 | 			break; | 
 | 1444 | 		default: | 
 | 1445 | 			continue; | 
 | 1446 | 		} | 
 | 1447 | 	} | 
 | 1448 |  | 
 | 1449 | 	/* finally cleanup the handles list */ | 
 | 1450 | 	sony_nc_handles_cleanup(pd); | 
 | 1451 | } | 
 | 1452 |  | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 1453 | #ifdef CONFIG_PM_SLEEP | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1454 | static void sony_nc_function_resume(void) | 
 | 1455 | { | 
 | 1456 | 	unsigned int i, result, bitmask, arg; | 
 | 1457 |  | 
 | 1458 | 	dprintk("Resuming SNC device\n"); | 
 | 1459 |  | 
 | 1460 | 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { | 
 | 1461 | 		unsigned int handle = handles->cap[i]; | 
 | 1462 |  | 
 | 1463 | 		if (!handle) | 
 | 1464 | 			continue; | 
 | 1465 |  | 
 | 1466 | 		switch (handle) { | 
 | 1467 | 		case 0x0100: | 
 | 1468 | 		case 0x0101: | 
 | 1469 | 		case 0x0127: | 
 | 1470 | 			/* re-enable hotkeys */ | 
 | 1471 | 			sony_call_snc_handle(handle, 0, &result); | 
 | 1472 | 			break; | 
 | 1473 | 		case 0x0102: | 
 | 1474 | 			/* re-enable hotkeys */ | 
 | 1475 | 			sony_call_snc_handle(handle, 0x100, &result); | 
 | 1476 | 			break; | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 1477 | 		case 0x0122: | 
 | 1478 | 			sony_nc_thermal_resume(); | 
 | 1479 | 			break; | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1480 | 		case 0x0124: | 
 | 1481 | 		case 0x0135: | 
 | 1482 | 			sony_nc_rfkill_update(); | 
 | 1483 | 			break; | 
 | 1484 | 		case 0x0137: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1485 | 		case 0x0143: | 
| Mattia Dongili | 7517a17 | 2012-12-21 07:21:11 +0900 | [diff] [blame] | 1486 | 		case 0x014b: | 
 | 1487 | 		case 0x014c: | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1488 | 			sony_nc_kbd_backlight_resume(); | 
 | 1489 | 			break; | 
 | 1490 | 		default: | 
 | 1491 | 			continue; | 
 | 1492 | 		} | 
 | 1493 | 	} | 
 | 1494 |  | 
 | 1495 | 	/* Enable all events */ | 
 | 1496 | 	arg = 0x10; | 
 | 1497 | 	if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask)) | 
 | 1498 | 		sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask, | 
 | 1499 | 				&result); | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1500 | } | 
 | 1501 |  | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 1502 | static int sony_nc_resume(struct device *dev) | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1503 | { | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1504 | 	struct sony_nc_value *item; | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1505 | 	acpi_handle handle; | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1506 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 1507 | 	for (item = sony_nc_values; item->name; item++) { | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1508 | 		int ret; | 
 | 1509 |  | 
 | 1510 | 		if (!item->valid) | 
 | 1511 | 			continue; | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1512 | 		ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiset, | 
 | 1513 | 				       &item->value, NULL); | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1514 | 		if (ret < 0) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 1515 | 			pr_err("%s: %d\n", __func__, ret); | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1516 | 			break; | 
 | 1517 | 		} | 
 | 1518 | 	} | 
| Mattia Dongili | 6315fd1 | 2007-07-16 02:34:35 +0900 | [diff] [blame] | 1519 |  | 
| Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 1520 | 	if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", | 
 | 1521 | 					 &handle))) { | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1522 | 		int arg = 1; | 
 | 1523 | 		if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL)) | 
| Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 1524 | 			dprintk("ECON Method failed\n"); | 
 | 1525 | 	} | 
 | 1526 |  | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 1527 | 	if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 1528 | 					 &handle))) | 
 | 1529 | 		sony_nc_function_resume(); | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1530 |  | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1531 | 	return 0; | 
 | 1532 | } | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 1533 | #endif | 
| Mattia Dongili | d78865c | 2007-02-07 20:01:56 +0100 | [diff] [blame] | 1534 |  | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 1535 | static SIMPLE_DEV_PM_OPS(sony_nc_pm, NULL, sony_nc_resume); | 
 | 1536 |  | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1537 | static void sony_nc_rfkill_cleanup(void) | 
 | 1538 | { | 
 | 1539 | 	int i; | 
 | 1540 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1541 | 	for (i = 0; i < N_SONY_RFKILL; i++) { | 
 | 1542 | 		if (sony_rfkill_devices[i]) { | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1543 | 			rfkill_unregister(sony_rfkill_devices[i]); | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1544 | 			rfkill_destroy(sony_rfkill_devices[i]); | 
 | 1545 | 		} | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1546 | 	} | 
 | 1547 | } | 
 | 1548 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1549 | static int sony_nc_rfkill_set(void *data, bool blocked) | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1550 | { | 
 | 1551 | 	int result; | 
 | 1552 | 	int argument = sony_rfkill_address[(long) data] + 0x100; | 
 | 1553 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1554 | 	if (!blocked) | 
| Mattia Dongili | 3ec1c39 | 2012-12-21 07:21:08 +0900 | [diff] [blame] | 1555 | 		argument |= 0x070000; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1556 |  | 
| Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1557 | 	return sony_call_snc_handle(sony_rfkill_handle, argument, &result); | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1558 | } | 
 | 1559 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1560 | static const struct rfkill_ops sony_rfkill_ops = { | 
 | 1561 | 	.set_block = sony_nc_rfkill_set, | 
 | 1562 | }; | 
 | 1563 |  | 
 | 1564 | static int sony_nc_setup_rfkill(struct acpi_device *device, | 
 | 1565 | 				enum sony_nc_rfkill nc_type) | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1566 | { | 
 | 1567 | 	int err = 0; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1568 | 	struct rfkill *rfk; | 
 | 1569 | 	enum rfkill_type type; | 
 | 1570 | 	const char *name; | 
| Alan Jenkins | 50fab07 | 2009-09-24 20:15:24 +0100 | [diff] [blame] | 1571 | 	int result; | 
| Marco Chiappero | d6f15ed | 2012-05-19 22:35:44 +0900 | [diff] [blame] | 1572 | 	bool hwblock, swblock; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1573 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1574 | 	switch (nc_type) { | 
 | 1575 | 	case SONY_WIFI: | 
 | 1576 | 		type = RFKILL_TYPE_WLAN; | 
 | 1577 | 		name = "sony-wifi"; | 
 | 1578 | 		break; | 
 | 1579 | 	case SONY_BLUETOOTH: | 
 | 1580 | 		type = RFKILL_TYPE_BLUETOOTH; | 
 | 1581 | 		name = "sony-bluetooth"; | 
 | 1582 | 		break; | 
 | 1583 | 	case SONY_WWAN: | 
 | 1584 | 		type = RFKILL_TYPE_WWAN; | 
 | 1585 | 		name = "sony-wwan"; | 
 | 1586 | 		break; | 
 | 1587 | 	case SONY_WIMAX: | 
 | 1588 | 		type = RFKILL_TYPE_WIMAX; | 
 | 1589 | 		name = "sony-wimax"; | 
 | 1590 | 		break; | 
 | 1591 | 	default: | 
 | 1592 | 		return -EINVAL; | 
| Mattia Dongili | 53005a0 | 2009-04-12 11:26:31 +0000 | [diff] [blame] | 1593 | 	} | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1594 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1595 | 	rfk = rfkill_alloc(name, &device->dev, type, | 
 | 1596 | 			   &sony_rfkill_ops, (void *)nc_type); | 
 | 1597 | 	if (!rfk) | 
 | 1598 | 		return -ENOMEM; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1599 |  | 
| Marco Chiappero | d6f15ed | 2012-05-19 22:35:44 +0900 | [diff] [blame] | 1600 | 	if (sony_call_snc_handle(sony_rfkill_handle, 0x200, &result) < 0) { | 
 | 1601 | 		rfkill_destroy(rfk); | 
 | 1602 | 		return -1; | 
 | 1603 | 	} | 
| Alan Jenkins | 50fab07 | 2009-09-24 20:15:24 +0100 | [diff] [blame] | 1604 | 	hwblock = !(result & 0x1); | 
| Marco Chiappero | d6f15ed | 2012-05-19 22:35:44 +0900 | [diff] [blame] | 1605 |  | 
 | 1606 | 	if (sony_call_snc_handle(sony_rfkill_handle, | 
 | 1607 | 				sony_rfkill_address[nc_type], | 
 | 1608 | 				&result) < 0) { | 
 | 1609 | 		rfkill_destroy(rfk); | 
 | 1610 | 		return -1; | 
 | 1611 | 	} | 
 | 1612 | 	swblock = !(result & 0x2); | 
 | 1613 |  | 
 | 1614 | 	rfkill_init_sw_state(rfk, swblock); | 
| Alan Jenkins | 50fab07 | 2009-09-24 20:15:24 +0100 | [diff] [blame] | 1615 | 	rfkill_set_hw_state(rfk, hwblock); | 
 | 1616 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1617 | 	err = rfkill_register(rfk); | 
 | 1618 | 	if (err) { | 
 | 1619 | 		rfkill_destroy(rfk); | 
 | 1620 | 		return err; | 
| Mattia Dongili | 53005a0 | 2009-04-12 11:26:31 +0000 | [diff] [blame] | 1621 | 	} | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1622 | 	sony_rfkill_devices[nc_type] = rfk; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1623 | 	return err; | 
 | 1624 | } | 
 | 1625 |  | 
| Randy Dunlap | a46a780 | 2011-01-08 19:56:44 -0800 | [diff] [blame] | 1626 | static void sony_nc_rfkill_update(void) | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1627 | { | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1628 | 	enum sony_nc_rfkill i; | 
 | 1629 | 	int result; | 
 | 1630 | 	bool hwblock; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1631 |  | 
| Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1632 | 	sony_call_snc_handle(sony_rfkill_handle, 0x200, &result); | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1633 | 	hwblock = !(result & 0x1); | 
 | 1634 |  | 
 | 1635 | 	for (i = 0; i < N_SONY_RFKILL; i++) { | 
 | 1636 | 		int argument = sony_rfkill_address[i]; | 
 | 1637 |  | 
 | 1638 | 		if (!sony_rfkill_devices[i]) | 
 | 1639 | 			continue; | 
 | 1640 |  | 
 | 1641 | 		if (hwblock) { | 
| Johannes Berg | e1f8a19 | 2009-06-11 12:08:15 +0200 | [diff] [blame] | 1642 | 			if (rfkill_set_hw_state(sony_rfkill_devices[i], true)) { | 
 | 1643 | 				/* we already know we're blocked */ | 
 | 1644 | 			} | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1645 | 			continue; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1646 | 		} | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1647 |  | 
| Mattia Dongili | d5a664a | 2009-12-17 00:08:35 +0900 | [diff] [blame] | 1648 | 		sony_call_snc_handle(sony_rfkill_handle, argument, &result); | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1649 | 		rfkill_set_states(sony_rfkill_devices[i], | 
| Marco Chiappero | d6f15ed | 2012-05-19 22:35:44 +0900 | [diff] [blame] | 1650 | 				  !(result & 0x2), false); | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1651 | 	} | 
 | 1652 | } | 
 | 1653 |  | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1654 | static int sony_nc_rfkill_setup(struct acpi_device *device, | 
 | 1655 | 		unsigned int handle) | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1656 | { | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1657 | 	u64 offset; | 
 | 1658 | 	int i; | 
 | 1659 | 	unsigned char buffer[32] = { 0 }; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1660 |  | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1661 | 	offset = sony_find_snc_handle(handle); | 
 | 1662 | 	sony_rfkill_handle = handle; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1663 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1664 | 	i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer, | 
 | 1665 | 			32); | 
 | 1666 | 	if (i < 0) | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1667 | 		return i; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1668 |  | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1669 | 	/* The buffer is filled with magic numbers describing the devices | 
 | 1670 | 	 * available, 0xff terminates the enumeration. | 
 | 1671 | 	 * Known codes: | 
 | 1672 | 	 *	0x00 WLAN | 
 | 1673 | 	 *	0x10 BLUETOOTH | 
 | 1674 | 	 *	0x20 WWAN GPRS-EDGE | 
 | 1675 | 	 *	0x21 WWAN HSDPA | 
 | 1676 | 	 *	0x22 WWAN EV-DO | 
 | 1677 | 	 *	0x23 WWAN GPS | 
 | 1678 | 	 *	0x25 Gobi WWAN no GPS | 
 | 1679 | 	 *	0x26 Gobi WWAN + GPS | 
 | 1680 | 	 *	0x28 Gobi WWAN no GPS | 
 | 1681 | 	 *	0x29 Gobi WWAN + GPS | 
 | 1682 | 	 *	0x30 WIMAX | 
 | 1683 | 	 *	0x50 Gobi WWAN no GPS | 
 | 1684 | 	 *	0x51 Gobi WWAN + GPS | 
 | 1685 | 	 *	0x70 no SIM card slot | 
 | 1686 | 	 *	0x71 SIM card slot | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1687 | 	 */ | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1688 | 	for (i = 0; i < ARRAY_SIZE(buffer); i++) { | 
| Dmitry Torokhov | c14973f | 2010-01-10 00:15:44 -0800 | [diff] [blame] | 1689 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1690 | 		if (buffer[i] == 0xff) | 
| Dmitry Torokhov | c14973f | 2010-01-10 00:15:44 -0800 | [diff] [blame] | 1691 | 			break; | 
 | 1692 |  | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1693 | 		dprintk("Radio devices, found 0x%.2x\n", buffer[i]); | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1694 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1695 | 		if (buffer[i] == 0 && !sony_rfkill_devices[SONY_WIFI]) | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1696 | 			sony_nc_setup_rfkill(device, SONY_WIFI); | 
 | 1697 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1698 | 		if (buffer[i] == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH]) | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1699 | 			sony_nc_setup_rfkill(device, SONY_BLUETOOTH); | 
 | 1700 |  | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1701 | 		if (((0xf0 & buffer[i]) == 0x20 || | 
 | 1702 | 					(0xf0 & buffer[i]) == 0x50) && | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1703 | 				!sony_rfkill_devices[SONY_WWAN]) | 
 | 1704 | 			sony_nc_setup_rfkill(device, SONY_WWAN); | 
 | 1705 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 1706 | 		if (buffer[i] == 0x30 && !sony_rfkill_devices[SONY_WIMAX]) | 
| Mattia Dongili | 528809c | 2009-12-17 00:08:36 +0900 | [diff] [blame] | 1707 | 			sony_nc_setup_rfkill(device, SONY_WIMAX); | 
 | 1708 | 	} | 
| Marco Chiappero | a1e7363 | 2012-05-19 22:35:57 +0900 | [diff] [blame] | 1709 | 	return 0; | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 1710 | } | 
 | 1711 |  | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1712 | /* Keyboard backlight feature */ | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1713 | struct kbd_backlight { | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1714 | 	unsigned int handle; | 
 | 1715 | 	unsigned int base; | 
 | 1716 | 	unsigned int mode; | 
 | 1717 | 	unsigned int timeout; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1718 | 	struct device_attribute mode_attr; | 
 | 1719 | 	struct device_attribute timeout_attr; | 
 | 1720 | }; | 
 | 1721 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1722 | static struct kbd_backlight *kbdbl_ctl; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1723 |  | 
 | 1724 | static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value) | 
 | 1725 | { | 
 | 1726 | 	int result; | 
 | 1727 |  | 
 | 1728 | 	if (value > 1) | 
 | 1729 | 		return -EINVAL; | 
 | 1730 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1731 | 	if (sony_call_snc_handle(kbdbl_ctl->handle, | 
 | 1732 | 				(value << 0x10) | (kbdbl_ctl->base), &result)) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1733 | 		return -EIO; | 
 | 1734 |  | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1735 | 	/* Try to turn the light on/off immediately */ | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1736 | 	sony_call_snc_handle(kbdbl_ctl->handle, | 
 | 1737 | 			(value << 0x10) | (kbdbl_ctl->base + 0x100), &result); | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1738 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1739 | 	kbdbl_ctl->mode = value; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1740 |  | 
 | 1741 | 	return 0; | 
 | 1742 | } | 
 | 1743 |  | 
 | 1744 | static ssize_t sony_nc_kbd_backlight_mode_store(struct device *dev, | 
 | 1745 | 		struct device_attribute *attr, | 
 | 1746 | 		const char *buffer, size_t count) | 
 | 1747 | { | 
 | 1748 | 	int ret = 0; | 
 | 1749 | 	unsigned long value; | 
 | 1750 |  | 
 | 1751 | 	if (count > 31) | 
 | 1752 | 		return -EINVAL; | 
 | 1753 |  | 
| Mattia Dongili | 9e12337 | 2012-05-19 22:35:47 +0900 | [diff] [blame] | 1754 | 	if (kstrtoul(buffer, 10, &value)) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1755 | 		return -EINVAL; | 
 | 1756 |  | 
 | 1757 | 	ret = __sony_nc_kbd_backlight_mode_set(value); | 
 | 1758 | 	if (ret < 0) | 
 | 1759 | 		return ret; | 
 | 1760 |  | 
 | 1761 | 	return count; | 
 | 1762 | } | 
 | 1763 |  | 
 | 1764 | static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev, | 
 | 1765 | 		struct device_attribute *attr, char *buffer) | 
 | 1766 | { | 
 | 1767 | 	ssize_t count = 0; | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1768 | 	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->mode); | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1769 | 	return count; | 
 | 1770 | } | 
 | 1771 |  | 
 | 1772 | static int __sony_nc_kbd_backlight_timeout_set(u8 value) | 
 | 1773 | { | 
 | 1774 | 	int result; | 
 | 1775 |  | 
 | 1776 | 	if (value > 3) | 
 | 1777 | 		return -EINVAL; | 
 | 1778 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1779 | 	if (sony_call_snc_handle(kbdbl_ctl->handle, (value << 0x10) | | 
 | 1780 | 				(kbdbl_ctl->base + 0x200), &result)) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1781 | 		return -EIO; | 
 | 1782 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1783 | 	kbdbl_ctl->timeout = value; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1784 |  | 
 | 1785 | 	return 0; | 
 | 1786 | } | 
 | 1787 |  | 
 | 1788 | static ssize_t sony_nc_kbd_backlight_timeout_store(struct device *dev, | 
 | 1789 | 		struct device_attribute *attr, | 
 | 1790 | 		const char *buffer, size_t count) | 
 | 1791 | { | 
 | 1792 | 	int ret = 0; | 
 | 1793 | 	unsigned long value; | 
 | 1794 |  | 
 | 1795 | 	if (count > 31) | 
 | 1796 | 		return -EINVAL; | 
 | 1797 |  | 
| Mattia Dongili | 9e12337 | 2012-05-19 22:35:47 +0900 | [diff] [blame] | 1798 | 	if (kstrtoul(buffer, 10, &value)) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1799 | 		return -EINVAL; | 
 | 1800 |  | 
 | 1801 | 	ret = __sony_nc_kbd_backlight_timeout_set(value); | 
 | 1802 | 	if (ret < 0) | 
 | 1803 | 		return ret; | 
 | 1804 |  | 
 | 1805 | 	return count; | 
 | 1806 | } | 
 | 1807 |  | 
 | 1808 | static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev, | 
 | 1809 | 		struct device_attribute *attr, char *buffer) | 
 | 1810 | { | 
 | 1811 | 	ssize_t count = 0; | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1812 | 	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->timeout); | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1813 | 	return count; | 
 | 1814 | } | 
 | 1815 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1816 | static int sony_nc_kbd_backlight_setup(struct platform_device *pd, | 
 | 1817 | 		unsigned int handle) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1818 | { | 
 | 1819 | 	int result; | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1820 | 	int ret = 0; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1821 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1822 | 	/* verify the kbd backlight presence, these handles are not used for | 
 | 1823 | 	 * keyboard backlight only | 
 | 1824 | 	 */ | 
 | 1825 | 	ret = sony_call_snc_handle(handle, handle == 0x0137 ? 0x0B00 : 0x0100, | 
 | 1826 | 			&result); | 
 | 1827 | 	if (ret) | 
 | 1828 | 		return ret; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1829 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1830 | 	if ((handle == 0x0137 && !(result & 0x02)) || | 
 | 1831 | 			!(result & 0x01)) { | 
 | 1832 | 		dprintk("no backlight keyboard found\n"); | 
 | 1833 | 		return 0; | 
 | 1834 | 	} | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1835 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1836 | 	kbdbl_ctl = kzalloc(sizeof(*kbdbl_ctl), GFP_KERNEL); | 
 | 1837 | 	if (!kbdbl_ctl) | 
 | 1838 | 		return -ENOMEM; | 
| 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 | 	kbdbl_ctl->handle = handle; | 
 | 1841 | 	if (handle == 0x0137) | 
 | 1842 | 		kbdbl_ctl->base = 0x0C00; | 
 | 1843 | 	else | 
 | 1844 | 		kbdbl_ctl->base = 0x4000; | 
| 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 | 	sysfs_attr_init(&kbdbl_ctl->mode_attr.attr); | 
 | 1847 | 	kbdbl_ctl->mode_attr.attr.name = "kbd_backlight"; | 
 | 1848 | 	kbdbl_ctl->mode_attr.attr.mode = S_IRUGO | S_IWUSR; | 
 | 1849 | 	kbdbl_ctl->mode_attr.show = sony_nc_kbd_backlight_mode_show; | 
 | 1850 | 	kbdbl_ctl->mode_attr.store = sony_nc_kbd_backlight_mode_store; | 
 | 1851 |  | 
 | 1852 | 	sysfs_attr_init(&kbdbl_ctl->timeout_attr.attr); | 
 | 1853 | 	kbdbl_ctl->timeout_attr.attr.name = "kbd_backlight_timeout"; | 
 | 1854 | 	kbdbl_ctl->timeout_attr.attr.mode = S_IRUGO | S_IWUSR; | 
 | 1855 | 	kbdbl_ctl->timeout_attr.show = sony_nc_kbd_backlight_timeout_show; | 
 | 1856 | 	kbdbl_ctl->timeout_attr.store = sony_nc_kbd_backlight_timeout_store; | 
 | 1857 |  | 
 | 1858 | 	ret = device_create_file(&pd->dev, &kbdbl_ctl->mode_attr); | 
 | 1859 | 	if (ret) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1860 | 		goto outkzalloc; | 
 | 1861 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1862 | 	ret = device_create_file(&pd->dev, &kbdbl_ctl->timeout_attr); | 
 | 1863 | 	if (ret) | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1864 | 		goto outmode; | 
 | 1865 |  | 
 | 1866 | 	__sony_nc_kbd_backlight_mode_set(kbd_backlight); | 
 | 1867 | 	__sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout); | 
 | 1868 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1869 | 	return 0; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1870 |  | 
 | 1871 | outmode: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1872 | 	device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr); | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1873 | outkzalloc: | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1874 | 	kfree(kbdbl_ctl); | 
 | 1875 | 	kbdbl_ctl = NULL; | 
 | 1876 | 	return ret; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1877 | } | 
 | 1878 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1879 | static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd) | 
| 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 | 	if (kbdbl_ctl) { | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1882 | 		int result; | 
 | 1883 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1884 | 		device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr); | 
 | 1885 | 		device_remove_file(&pd->dev, &kbdbl_ctl->timeout_attr); | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1886 |  | 
 | 1887 | 		/* restore the default hw behaviour */ | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1888 | 		sony_call_snc_handle(kbdbl_ctl->handle, | 
 | 1889 | 				kbdbl_ctl->base | 0x10000, &result); | 
 | 1890 | 		sony_call_snc_handle(kbdbl_ctl->handle, | 
 | 1891 | 				kbdbl_ctl->base + 0x200, &result); | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1892 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1893 | 		kfree(kbdbl_ctl); | 
 | 1894 | 		kbdbl_ctl = NULL; | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1895 | 	} | 
| Mattia Dongili | bf15571 | 2011-02-19 11:52:31 +0900 | [diff] [blame] | 1896 | } | 
 | 1897 |  | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 1898 | #ifdef CONFIG_PM_SLEEP | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1899 | static void sony_nc_kbd_backlight_resume(void) | 
 | 1900 | { | 
 | 1901 | 	int ignore = 0; | 
 | 1902 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1903 | 	if (!kbdbl_ctl) | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1904 | 		return; | 
 | 1905 |  | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1906 | 	if (kbdbl_ctl->mode == 0) | 
 | 1907 | 		sony_call_snc_handle(kbdbl_ctl->handle, kbdbl_ctl->base, | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1908 | 				&ignore); | 
| Marco Chiappero | aa33924 | 2012-05-19 22:35:56 +0900 | [diff] [blame] | 1909 |  | 
 | 1910 | 	if (kbdbl_ctl->timeout != 0) | 
 | 1911 | 		sony_call_snc_handle(kbdbl_ctl->handle, | 
 | 1912 | 				(kbdbl_ctl->base + 0x200) | | 
 | 1913 | 				(kbdbl_ctl->timeout << 0x10), &ignore); | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1914 | } | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 1915 | #endif | 
| Marco Chiappero | df410d5 | 2011-04-05 23:38:34 +0900 | [diff] [blame] | 1916 |  | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1917 | struct battery_care_control { | 
 | 1918 | 	struct device_attribute attrs[2]; | 
 | 1919 | 	unsigned int handle; | 
 | 1920 | }; | 
 | 1921 | static struct battery_care_control *bcare_ctl; | 
 | 1922 |  | 
 | 1923 | static ssize_t sony_nc_battery_care_limit_store(struct device *dev, | 
 | 1924 | 		struct device_attribute *attr, | 
 | 1925 | 		const char *buffer, size_t count) | 
 | 1926 | { | 
 | 1927 | 	unsigned int result, cmd; | 
 | 1928 | 	unsigned long value; | 
 | 1929 |  | 
 | 1930 | 	if (count > 31) | 
 | 1931 | 		return -EINVAL; | 
 | 1932 |  | 
 | 1933 | 	if (kstrtoul(buffer, 10, &value)) | 
 | 1934 | 		return -EINVAL; | 
 | 1935 |  | 
 | 1936 | 	/*  limit values (2 bits): | 
 | 1937 | 	 *  00 - none | 
 | 1938 | 	 *  01 - 80% | 
 | 1939 | 	 *  10 - 50% | 
 | 1940 | 	 *  11 - 100% | 
 | 1941 | 	 * | 
 | 1942 | 	 *  bit 0: 0 disable BCL, 1 enable BCL | 
 | 1943 | 	 *  bit 1: 1 tell to store the battery limit (see bits 6,7) too | 
 | 1944 | 	 *  bits 2,3: reserved | 
 | 1945 | 	 *  bits 4,5: store the limit into the EC | 
 | 1946 | 	 *  bits 6,7: store the limit into the battery | 
 | 1947 | 	 */ | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1948 | 	cmd = 0; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1949 |  | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1950 | 	if (value > 0) { | 
 | 1951 | 		if (value <= 50) | 
 | 1952 | 			cmd = 0x20; | 
| 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 | 		else if (value <= 80) | 
 | 1955 | 			cmd = 0x10; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1956 |  | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1957 | 		else if (value <= 100) | 
 | 1958 | 			cmd = 0x30; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1959 |  | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1960 | 		else | 
 | 1961 | 			return -EINVAL; | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1962 |  | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1963 | 		/* | 
 | 1964 | 		 * handle 0x0115 should allow storing on battery too; | 
 | 1965 | 		 * handle 0x0136 same as 0x0115 + health status; | 
 | 1966 | 		 * handle 0x013f, same as 0x0136 but no storing on the battery | 
 | 1967 | 		 */ | 
 | 1968 | 		if (bcare_ctl->handle != 0x013f) | 
 | 1969 | 			cmd = cmd | (cmd << 2); | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1970 |  | 
| Mattia Dongili | 15aa5c7 | 2012-06-11 07:18:31 +0900 | [diff] [blame] | 1971 | 		cmd = (cmd | 0x1) << 0x10; | 
 | 1972 | 	} | 
 | 1973 |  | 
 | 1974 | 	if (sony_call_snc_handle(bcare_ctl->handle, cmd | 0x0100, &result)) | 
| Marco Chiappero | 967145a | 2012-05-19 22:35:50 +0900 | [diff] [blame] | 1975 | 		return -EIO; | 
 | 1976 |  | 
 | 1977 | 	return count; | 
 | 1978 | } | 
 | 1979 |  | 
 | 1980 | static ssize_t sony_nc_battery_care_limit_show(struct device *dev, | 
 | 1981 | 		struct device_attribute *attr, char *buffer) | 
 | 1982 | { | 
 | 1983 | 	unsigned int result, status; | 
 | 1984 |  | 
 | 1985 | 	if (sony_call_snc_handle(bcare_ctl->handle, 0x0000, &result)) | 
 | 1986 | 		return -EIO; | 
 | 1987 |  | 
 | 1988 | 	status = (result & 0x01) ? ((result & 0x30) >> 0x04) : 0; | 
 | 1989 | 	switch (status) { | 
 | 1990 | 	case 1: | 
 | 1991 | 		status = 80; | 
 | 1992 | 		break; | 
 | 1993 | 	case 2: | 
 | 1994 | 		status = 50; | 
 | 1995 | 		break; | 
 | 1996 | 	case 3: | 
 | 1997 | 		status = 100; | 
 | 1998 | 		break; | 
 | 1999 | 	default: | 
 | 2000 | 		status = 0; | 
 | 2001 | 		break; | 
 | 2002 | 	} | 
 | 2003 |  | 
 | 2004 | 	return snprintf(buffer, PAGE_SIZE, "%d\n", status); | 
 | 2005 | } | 
 | 2006 |  | 
 | 2007 | static ssize_t sony_nc_battery_care_health_show(struct device *dev, | 
 | 2008 | 		struct device_attribute *attr, char *buffer) | 
 | 2009 | { | 
 | 2010 | 	ssize_t count = 0; | 
 | 2011 | 	unsigned int health; | 
 | 2012 |  | 
 | 2013 | 	if (sony_call_snc_handle(bcare_ctl->handle, 0x0200, &health)) | 
 | 2014 | 		return -EIO; | 
 | 2015 |  | 
 | 2016 | 	count = snprintf(buffer, PAGE_SIZE, "%d\n", health & 0xff); | 
 | 2017 |  | 
 | 2018 | 	return count; | 
 | 2019 | } | 
 | 2020 |  | 
 | 2021 | static int sony_nc_battery_care_setup(struct platform_device *pd, | 
 | 2022 | 		unsigned int handle) | 
 | 2023 | { | 
 | 2024 | 	int ret = 0; | 
 | 2025 |  | 
 | 2026 | 	bcare_ctl = kzalloc(sizeof(struct battery_care_control), GFP_KERNEL); | 
 | 2027 | 	if (!bcare_ctl) | 
 | 2028 | 		return -ENOMEM; | 
 | 2029 |  | 
 | 2030 | 	bcare_ctl->handle = handle; | 
 | 2031 |  | 
 | 2032 | 	sysfs_attr_init(&bcare_ctl->attrs[0].attr); | 
 | 2033 | 	bcare_ctl->attrs[0].attr.name = "battery_care_limiter"; | 
 | 2034 | 	bcare_ctl->attrs[0].attr.mode = S_IRUGO | S_IWUSR; | 
 | 2035 | 	bcare_ctl->attrs[0].show = sony_nc_battery_care_limit_show; | 
 | 2036 | 	bcare_ctl->attrs[0].store = sony_nc_battery_care_limit_store; | 
 | 2037 |  | 
 | 2038 | 	ret = device_create_file(&pd->dev, &bcare_ctl->attrs[0]); | 
 | 2039 | 	if (ret) | 
 | 2040 | 		goto outkzalloc; | 
 | 2041 |  | 
 | 2042 | 	/* 0x0115 is for models with no health reporting capability */ | 
 | 2043 | 	if (handle == 0x0115) | 
 | 2044 | 		return 0; | 
 | 2045 |  | 
 | 2046 | 	sysfs_attr_init(&bcare_ctl->attrs[1].attr); | 
 | 2047 | 	bcare_ctl->attrs[1].attr.name = "battery_care_health"; | 
 | 2048 | 	bcare_ctl->attrs[1].attr.mode = S_IRUGO; | 
 | 2049 | 	bcare_ctl->attrs[1].show = sony_nc_battery_care_health_show; | 
 | 2050 |  | 
 | 2051 | 	ret = device_create_file(&pd->dev, &bcare_ctl->attrs[1]); | 
 | 2052 | 	if (ret) | 
 | 2053 | 		goto outlimiter; | 
 | 2054 |  | 
 | 2055 | 	return 0; | 
 | 2056 |  | 
 | 2057 | outlimiter: | 
 | 2058 | 	device_remove_file(&pd->dev, &bcare_ctl->attrs[0]); | 
 | 2059 |  | 
 | 2060 | outkzalloc: | 
 | 2061 | 	kfree(bcare_ctl); | 
 | 2062 | 	bcare_ctl = NULL; | 
 | 2063 |  | 
 | 2064 | 	return ret; | 
 | 2065 | } | 
 | 2066 |  | 
 | 2067 | static void sony_nc_battery_care_cleanup(struct platform_device *pd) | 
 | 2068 | { | 
 | 2069 | 	if (bcare_ctl) { | 
 | 2070 | 		device_remove_file(&pd->dev, &bcare_ctl->attrs[0]); | 
 | 2071 | 		if (bcare_ctl->handle != 0x0115) | 
 | 2072 | 			device_remove_file(&pd->dev, &bcare_ctl->attrs[1]); | 
 | 2073 |  | 
 | 2074 | 		kfree(bcare_ctl); | 
 | 2075 | 		bcare_ctl = NULL; | 
 | 2076 | 	} | 
 | 2077 | } | 
 | 2078 |  | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 2079 | struct snc_thermal_ctrl { | 
 | 2080 | 	unsigned int mode; | 
 | 2081 | 	unsigned int profiles; | 
 | 2082 | 	struct device_attribute mode_attr; | 
 | 2083 | 	struct device_attribute profiles_attr; | 
 | 2084 | }; | 
 | 2085 | static struct snc_thermal_ctrl *th_handle; | 
 | 2086 |  | 
 | 2087 | #define THM_PROFILE_MAX 3 | 
 | 2088 | static const char * const snc_thermal_profiles[] = { | 
 | 2089 | 	"balanced", | 
 | 2090 | 	"silent", | 
 | 2091 | 	"performance" | 
 | 2092 | }; | 
 | 2093 |  | 
 | 2094 | static int sony_nc_thermal_mode_set(unsigned short mode) | 
 | 2095 | { | 
 | 2096 | 	unsigned int result; | 
 | 2097 |  | 
 | 2098 | 	/* the thermal profile seems to be a two bit bitmask: | 
 | 2099 | 	 * lsb -> silent | 
 | 2100 | 	 * msb -> performance | 
 | 2101 | 	 * no bit set is the normal operation and is always valid | 
 | 2102 | 	 * Some vaio models only have "balanced" and "performance" | 
 | 2103 | 	 */ | 
 | 2104 | 	if ((mode && !(th_handle->profiles & mode)) || mode >= THM_PROFILE_MAX) | 
 | 2105 | 		return -EINVAL; | 
 | 2106 |  | 
 | 2107 | 	if (sony_call_snc_handle(0x0122, mode << 0x10 | 0x0200, &result)) | 
 | 2108 | 		return -EIO; | 
 | 2109 |  | 
 | 2110 | 	th_handle->mode = mode; | 
 | 2111 |  | 
 | 2112 | 	return 0; | 
 | 2113 | } | 
 | 2114 |  | 
 | 2115 | static int sony_nc_thermal_mode_get(void) | 
 | 2116 | { | 
 | 2117 | 	unsigned int result; | 
 | 2118 |  | 
 | 2119 | 	if (sony_call_snc_handle(0x0122, 0x0100, &result)) | 
 | 2120 | 		return -EIO; | 
 | 2121 |  | 
 | 2122 | 	return result & 0xff; | 
 | 2123 | } | 
 | 2124 |  | 
 | 2125 | static ssize_t sony_nc_thermal_profiles_show(struct device *dev, | 
 | 2126 | 		struct device_attribute *attr, char *buffer) | 
 | 2127 | { | 
 | 2128 | 	short cnt; | 
 | 2129 | 	size_t idx = 0; | 
 | 2130 |  | 
 | 2131 | 	for (cnt = 0; cnt < THM_PROFILE_MAX; cnt++) { | 
 | 2132 | 		if (!cnt || (th_handle->profiles & cnt)) | 
 | 2133 | 			idx += snprintf(buffer + idx, PAGE_SIZE - idx, "%s ", | 
 | 2134 | 					snc_thermal_profiles[cnt]); | 
 | 2135 | 	} | 
 | 2136 | 	idx += snprintf(buffer + idx, PAGE_SIZE - idx, "\n"); | 
 | 2137 |  | 
 | 2138 | 	return idx; | 
 | 2139 | } | 
 | 2140 |  | 
 | 2141 | static ssize_t sony_nc_thermal_mode_store(struct device *dev, | 
 | 2142 | 		struct device_attribute *attr, | 
 | 2143 | 		const char *buffer, size_t count) | 
 | 2144 | { | 
 | 2145 | 	unsigned short cmd; | 
 | 2146 | 	size_t len = count; | 
 | 2147 |  | 
 | 2148 | 	if (count == 0) | 
 | 2149 | 		return -EINVAL; | 
 | 2150 |  | 
 | 2151 | 	/* skip the newline if present */ | 
 | 2152 | 	if (buffer[len - 1] == '\n') | 
 | 2153 | 		len--; | 
 | 2154 |  | 
 | 2155 | 	for (cmd = 0; cmd < THM_PROFILE_MAX; cmd++) | 
 | 2156 | 		if (strncmp(buffer, snc_thermal_profiles[cmd], len) == 0) | 
 | 2157 | 			break; | 
 | 2158 |  | 
 | 2159 | 	if (sony_nc_thermal_mode_set(cmd)) | 
 | 2160 | 		return -EIO; | 
 | 2161 |  | 
 | 2162 | 	return count; | 
 | 2163 | } | 
 | 2164 |  | 
 | 2165 | static ssize_t sony_nc_thermal_mode_show(struct device *dev, | 
 | 2166 | 		struct device_attribute *attr, char *buffer) | 
 | 2167 | { | 
 | 2168 | 	ssize_t count = 0; | 
| Dan Carpenter | 56f4a9f | 2012-06-09 13:18:14 +0900 | [diff] [blame] | 2169 | 	int mode = sony_nc_thermal_mode_get(); | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 2170 |  | 
 | 2171 | 	if (mode < 0) | 
 | 2172 | 		return mode; | 
 | 2173 |  | 
 | 2174 | 	count = snprintf(buffer, PAGE_SIZE, "%s\n", snc_thermal_profiles[mode]); | 
 | 2175 |  | 
 | 2176 | 	return count; | 
 | 2177 | } | 
 | 2178 |  | 
 | 2179 | static int sony_nc_thermal_setup(struct platform_device *pd) | 
 | 2180 | { | 
 | 2181 | 	int ret = 0; | 
 | 2182 | 	th_handle = kzalloc(sizeof(struct snc_thermal_ctrl), GFP_KERNEL); | 
 | 2183 | 	if (!th_handle) | 
 | 2184 | 		return -ENOMEM; | 
 | 2185 |  | 
 | 2186 | 	ret = sony_call_snc_handle(0x0122, 0x0000, &th_handle->profiles); | 
 | 2187 | 	if (ret) { | 
 | 2188 | 		pr_warn("couldn't to read the thermal profiles\n"); | 
 | 2189 | 		goto outkzalloc; | 
 | 2190 | 	} | 
 | 2191 |  | 
 | 2192 | 	ret = sony_nc_thermal_mode_get(); | 
 | 2193 | 	if (ret < 0) { | 
 | 2194 | 		pr_warn("couldn't to read the current thermal profile"); | 
 | 2195 | 		goto outkzalloc; | 
 | 2196 | 	} | 
 | 2197 | 	th_handle->mode = ret; | 
 | 2198 |  | 
 | 2199 | 	sysfs_attr_init(&th_handle->profiles_attr.attr); | 
 | 2200 | 	th_handle->profiles_attr.attr.name = "thermal_profiles"; | 
 | 2201 | 	th_handle->profiles_attr.attr.mode = S_IRUGO; | 
 | 2202 | 	th_handle->profiles_attr.show = sony_nc_thermal_profiles_show; | 
 | 2203 |  | 
 | 2204 | 	sysfs_attr_init(&th_handle->mode_attr.attr); | 
 | 2205 | 	th_handle->mode_attr.attr.name = "thermal_control"; | 
 | 2206 | 	th_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR; | 
 | 2207 | 	th_handle->mode_attr.show = sony_nc_thermal_mode_show; | 
 | 2208 | 	th_handle->mode_attr.store = sony_nc_thermal_mode_store; | 
 | 2209 |  | 
 | 2210 | 	ret = device_create_file(&pd->dev, &th_handle->profiles_attr); | 
 | 2211 | 	if (ret) | 
 | 2212 | 		goto outkzalloc; | 
 | 2213 |  | 
 | 2214 | 	ret = device_create_file(&pd->dev, &th_handle->mode_attr); | 
 | 2215 | 	if (ret) | 
 | 2216 | 		goto outprofiles; | 
 | 2217 |  | 
 | 2218 | 	return 0; | 
 | 2219 |  | 
 | 2220 | outprofiles: | 
 | 2221 | 	device_remove_file(&pd->dev, &th_handle->profiles_attr); | 
 | 2222 | outkzalloc: | 
 | 2223 | 	kfree(th_handle); | 
 | 2224 | 	th_handle = NULL; | 
 | 2225 | 	return ret; | 
 | 2226 | } | 
 | 2227 |  | 
 | 2228 | static void sony_nc_thermal_cleanup(struct platform_device *pd) | 
 | 2229 | { | 
 | 2230 | 	if (th_handle) { | 
 | 2231 | 		device_remove_file(&pd->dev, &th_handle->profiles_attr); | 
 | 2232 | 		device_remove_file(&pd->dev, &th_handle->mode_attr); | 
 | 2233 | 		kfree(th_handle); | 
 | 2234 | 		th_handle = NULL; | 
 | 2235 | 	} | 
 | 2236 | } | 
 | 2237 |  | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 2238 | #ifdef CONFIG_PM_SLEEP | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 2239 | static void sony_nc_thermal_resume(void) | 
 | 2240 | { | 
 | 2241 | 	unsigned int status = sony_nc_thermal_mode_get(); | 
 | 2242 |  | 
 | 2243 | 	if (status != th_handle->mode) | 
 | 2244 | 		sony_nc_thermal_mode_set(th_handle->mode); | 
 | 2245 | } | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 2246 | #endif | 
| Marco Chiappero | 49f000a | 2012-05-19 22:35:51 +0900 | [diff] [blame] | 2247 |  | 
| Marco Chiappero | 54535d0 | 2012-05-19 22:35:54 +0900 | [diff] [blame] | 2248 | /* resume on LID open */ | 
 | 2249 | struct snc_lid_resume_control { | 
 | 2250 | 	struct device_attribute attrs[3]; | 
 | 2251 | 	unsigned int status; | 
 | 2252 | }; | 
 | 2253 | static struct snc_lid_resume_control *lid_ctl; | 
 | 2254 |  | 
 | 2255 | static ssize_t sony_nc_lid_resume_store(struct device *dev, | 
 | 2256 | 					struct device_attribute *attr, | 
 | 2257 | 					const char *buffer, size_t count) | 
 | 2258 | { | 
 | 2259 | 	unsigned int result, pos; | 
 | 2260 | 	unsigned long value; | 
 | 2261 | 	if (count > 31) | 
 | 2262 | 		return -EINVAL; | 
 | 2263 |  | 
 | 2264 | 	if (kstrtoul(buffer, 10, &value) || value > 1) | 
 | 2265 | 		return -EINVAL; | 
 | 2266 |  | 
 | 2267 | 	/* the value we have to write to SNC is a bitmask: | 
 | 2268 | 	 * +--------------+ | 
 | 2269 | 	 * | S3 | S4 | S5 | | 
 | 2270 | 	 * +--------------+ | 
 | 2271 | 	 *   2    1    0 | 
 | 2272 | 	 */ | 
 | 2273 | 	if (strcmp(attr->attr.name, "lid_resume_S3") == 0) | 
 | 2274 | 		pos = 2; | 
 | 2275 | 	else if (strcmp(attr->attr.name, "lid_resume_S4") == 0) | 
 | 2276 | 		pos = 1; | 
 | 2277 | 	else if (strcmp(attr->attr.name, "lid_resume_S5") == 0) | 
 | 2278 | 		pos = 0; | 
 | 2279 | 	else | 
 | 2280 |                return -EINVAL; | 
 | 2281 |  | 
 | 2282 | 	if (value) | 
 | 2283 | 		value = lid_ctl->status | (1 << pos); | 
 | 2284 | 	else | 
 | 2285 | 		value = lid_ctl->status & ~(1 << pos); | 
 | 2286 |  | 
 | 2287 | 	if (sony_call_snc_handle(0x0119, value << 0x10 | 0x0100, &result)) | 
 | 2288 | 		return -EIO; | 
 | 2289 |  | 
 | 2290 | 	lid_ctl->status = value; | 
 | 2291 |  | 
 | 2292 | 	return count; | 
 | 2293 | } | 
 | 2294 |  | 
 | 2295 | static ssize_t sony_nc_lid_resume_show(struct device *dev, | 
 | 2296 | 				       struct device_attribute *attr, char *buffer) | 
 | 2297 | { | 
 | 2298 | 	unsigned int pos; | 
 | 2299 |  | 
 | 2300 | 	if (strcmp(attr->attr.name, "lid_resume_S3") == 0) | 
 | 2301 | 		pos = 2; | 
 | 2302 | 	else if (strcmp(attr->attr.name, "lid_resume_S4") == 0) | 
 | 2303 | 		pos = 1; | 
 | 2304 | 	else if (strcmp(attr->attr.name, "lid_resume_S5") == 0) | 
 | 2305 | 		pos = 0; | 
 | 2306 | 	else | 
 | 2307 | 		return -EINVAL; | 
 | 2308 | 	        | 
 | 2309 | 	return snprintf(buffer, PAGE_SIZE, "%d\n", | 
 | 2310 | 			(lid_ctl->status >> pos) & 0x01); | 
 | 2311 | } | 
 | 2312 |  | 
 | 2313 | static int sony_nc_lid_resume_setup(struct platform_device *pd) | 
 | 2314 | { | 
 | 2315 | 	unsigned int result; | 
 | 2316 | 	int i; | 
 | 2317 |  | 
 | 2318 | 	if (sony_call_snc_handle(0x0119, 0x0000, &result)) | 
 | 2319 | 		return -EIO; | 
 | 2320 |  | 
 | 2321 | 	lid_ctl = kzalloc(sizeof(struct snc_lid_resume_control), GFP_KERNEL); | 
 | 2322 | 	if (!lid_ctl) | 
 | 2323 | 		return -ENOMEM; | 
 | 2324 |  | 
 | 2325 | 	lid_ctl->status = result & 0x7; | 
 | 2326 |  | 
 | 2327 | 	sysfs_attr_init(&lid_ctl->attrs[0].attr); | 
 | 2328 | 	lid_ctl->attrs[0].attr.name = "lid_resume_S3"; | 
 | 2329 | 	lid_ctl->attrs[0].attr.mode = S_IRUGO | S_IWUSR; | 
 | 2330 | 	lid_ctl->attrs[0].show = sony_nc_lid_resume_show; | 
 | 2331 | 	lid_ctl->attrs[0].store = sony_nc_lid_resume_store; | 
 | 2332 |  | 
 | 2333 | 	sysfs_attr_init(&lid_ctl->attrs[1].attr); | 
 | 2334 | 	lid_ctl->attrs[1].attr.name = "lid_resume_S4"; | 
 | 2335 | 	lid_ctl->attrs[1].attr.mode = S_IRUGO | S_IWUSR; | 
 | 2336 | 	lid_ctl->attrs[1].show = sony_nc_lid_resume_show; | 
 | 2337 | 	lid_ctl->attrs[1].store = sony_nc_lid_resume_store; | 
 | 2338 |  | 
 | 2339 | 	sysfs_attr_init(&lid_ctl->attrs[2].attr); | 
 | 2340 | 	lid_ctl->attrs[2].attr.name = "lid_resume_S5"; | 
 | 2341 | 	lid_ctl->attrs[2].attr.mode = S_IRUGO | S_IWUSR; | 
 | 2342 | 	lid_ctl->attrs[2].show = sony_nc_lid_resume_show; | 
 | 2343 | 	lid_ctl->attrs[2].store = sony_nc_lid_resume_store; | 
 | 2344 |  | 
 | 2345 | 	for (i = 0; i < 3; i++) { | 
 | 2346 | 		result = device_create_file(&pd->dev, &lid_ctl->attrs[i]); | 
 | 2347 | 		if (result) | 
 | 2348 | 			goto liderror; | 
 | 2349 | 	} | 
 | 2350 |  | 
 | 2351 | 	return 0; | 
 | 2352 |  | 
 | 2353 | liderror: | 
| Dan Carpenter | 34cf1df | 2013-02-01 16:28:27 +0300 | [diff] [blame] | 2354 | 	for (i--; i >= 0; i--) | 
| Marco Chiappero | 54535d0 | 2012-05-19 22:35:54 +0900 | [diff] [blame] | 2355 | 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]); | 
 | 2356 |  | 
 | 2357 | 	kfree(lid_ctl); | 
 | 2358 | 	lid_ctl = NULL; | 
 | 2359 |  | 
 | 2360 | 	return result; | 
 | 2361 | } | 
 | 2362 |  | 
 | 2363 | static void sony_nc_lid_resume_cleanup(struct platform_device *pd) | 
 | 2364 | { | 
 | 2365 | 	int i; | 
 | 2366 |  | 
 | 2367 | 	if (lid_ctl) { | 
 | 2368 | 		for (i = 0; i < 3; i++) | 
 | 2369 | 			device_remove_file(&pd->dev, &lid_ctl->attrs[i]); | 
 | 2370 |  | 
 | 2371 | 		kfree(lid_ctl); | 
 | 2372 | 		lid_ctl = NULL; | 
 | 2373 | 	} | 
 | 2374 | } | 
 | 2375 |  | 
| Mattia Dongili | 3a7abcd | 2012-12-21 07:21:10 +0900 | [diff] [blame] | 2376 | /* GFX Switch position */ | 
 | 2377 | enum gfx_switch { | 
 | 2378 | 	SPEED, | 
 | 2379 | 	STAMINA, | 
 | 2380 | 	AUTO | 
 | 2381 | }; | 
 | 2382 | struct snc_gfx_switch_control { | 
 | 2383 | 	struct device_attribute attr; | 
 | 2384 | 	unsigned int handle; | 
 | 2385 | }; | 
 | 2386 | static struct snc_gfx_switch_control *gfxs_ctl; | 
 | 2387 |  | 
 | 2388 | /* returns 0 for speed, 1 for stamina */ | 
 | 2389 | static int __sony_nc_gfx_switch_status_get(void) | 
 | 2390 | { | 
 | 2391 | 	unsigned int result; | 
 | 2392 |  | 
 | 2393 | 	if (sony_call_snc_handle(gfxs_ctl->handle, 0x0100, &result)) | 
 | 2394 | 		return -EIO; | 
 | 2395 |  | 
 | 2396 | 	switch (gfxs_ctl->handle) { | 
 | 2397 | 	case 0x0146: | 
 | 2398 | 		/* 1: discrete GFX (speed) | 
 | 2399 | 		 * 0: integrated GFX (stamina) | 
 | 2400 | 		 */ | 
 | 2401 | 		return result & 0x1 ? SPEED : STAMINA; | 
 | 2402 | 		break; | 
 | 2403 | 	case 0x0128: | 
 | 2404 | 		/* it's a more elaborated bitmask, for now: | 
 | 2405 | 		 * 2: integrated GFX (stamina) | 
 | 2406 | 		 * 0: discrete GFX (speed) | 
 | 2407 | 		 */ | 
 | 2408 | 		dprintk("GFX Status: 0x%x\n", result); | 
 | 2409 | 		return result & 0x80 ? AUTO : | 
 | 2410 | 			result & 0x02 ? STAMINA : SPEED; | 
 | 2411 | 		break; | 
 | 2412 | 	} | 
 | 2413 | 	return -EINVAL; | 
 | 2414 | } | 
 | 2415 |  | 
 | 2416 | static ssize_t sony_nc_gfx_switch_status_show(struct device *dev, | 
 | 2417 | 				       struct device_attribute *attr, | 
 | 2418 | 				       char *buffer) | 
 | 2419 | { | 
 | 2420 | 	int pos = __sony_nc_gfx_switch_status_get(); | 
 | 2421 |  | 
 | 2422 | 	if (pos < 0) | 
 | 2423 | 		return pos; | 
 | 2424 |  | 
 | 2425 | 	return snprintf(buffer, PAGE_SIZE, "%s\n", pos ? "speed" : "stamina"); | 
 | 2426 | } | 
 | 2427 |  | 
 | 2428 | static int sony_nc_gfx_switch_setup(struct platform_device *pd, | 
 | 2429 | 		unsigned int handle) | 
 | 2430 | { | 
 | 2431 | 	unsigned int result; | 
 | 2432 |  | 
 | 2433 | 	gfxs_ctl = kzalloc(sizeof(struct snc_gfx_switch_control), GFP_KERNEL); | 
 | 2434 | 	if (!gfxs_ctl) | 
 | 2435 | 		return -ENOMEM; | 
 | 2436 |  | 
 | 2437 | 	gfxs_ctl->handle = handle; | 
 | 2438 |  | 
 | 2439 | 	sysfs_attr_init(&gfxs_ctl->attr.attr); | 
 | 2440 | 	gfxs_ctl->attr.attr.name = "gfx_switch_status"; | 
 | 2441 | 	gfxs_ctl->attr.attr.mode = S_IRUGO; | 
 | 2442 | 	gfxs_ctl->attr.show = sony_nc_gfx_switch_status_show; | 
 | 2443 |  | 
 | 2444 | 	result = device_create_file(&pd->dev, &gfxs_ctl->attr); | 
 | 2445 | 	if (result) | 
 | 2446 | 		goto gfxerror; | 
 | 2447 |  | 
 | 2448 | 	return 0; | 
 | 2449 |  | 
 | 2450 | gfxerror: | 
 | 2451 | 	kfree(gfxs_ctl); | 
 | 2452 | 	gfxs_ctl = NULL; | 
 | 2453 |  | 
 | 2454 | 	return result; | 
 | 2455 | } | 
 | 2456 |  | 
 | 2457 | static void sony_nc_gfx_switch_cleanup(struct platform_device *pd) | 
 | 2458 | { | 
 | 2459 | 	if (gfxs_ctl) { | 
 | 2460 | 		device_remove_file(&pd->dev, &gfxs_ctl->attr); | 
 | 2461 |  | 
 | 2462 | 		kfree(gfxs_ctl); | 
 | 2463 | 		gfxs_ctl = NULL; | 
 | 2464 | 	} | 
 | 2465 | } | 
 | 2466 |  | 
| Marco Chiappero | 88bf170 | 2012-05-19 22:35:55 +0900 | [diff] [blame] | 2467 | /* High speed charging function */ | 
 | 2468 | static struct device_attribute *hsc_handle; | 
 | 2469 |  | 
 | 2470 | static ssize_t sony_nc_highspeed_charging_store(struct device *dev, | 
 | 2471 | 		struct device_attribute *attr, | 
 | 2472 | 		const char *buffer, size_t count) | 
 | 2473 | { | 
 | 2474 | 	unsigned int result; | 
 | 2475 | 	unsigned long value; | 
 | 2476 |  | 
 | 2477 | 	if (count > 31) | 
 | 2478 | 		return -EINVAL; | 
 | 2479 |  | 
 | 2480 | 	if (kstrtoul(buffer, 10, &value) || value > 1) | 
 | 2481 | 		return -EINVAL; | 
 | 2482 |  | 
 | 2483 | 	if (sony_call_snc_handle(0x0131, value << 0x10 | 0x0200, &result)) | 
 | 2484 | 		return -EIO; | 
 | 2485 |  | 
 | 2486 | 	return count; | 
 | 2487 | } | 
 | 2488 |  | 
 | 2489 | static ssize_t sony_nc_highspeed_charging_show(struct device *dev, | 
 | 2490 | 		struct device_attribute *attr, char *buffer) | 
 | 2491 | { | 
 | 2492 | 	unsigned int result; | 
 | 2493 |  | 
 | 2494 | 	if (sony_call_snc_handle(0x0131, 0x0100, &result)) | 
 | 2495 | 		return -EIO; | 
 | 2496 |  | 
 | 2497 | 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01); | 
 | 2498 | } | 
 | 2499 |  | 
 | 2500 | static int sony_nc_highspeed_charging_setup(struct platform_device *pd) | 
 | 2501 | { | 
 | 2502 | 	unsigned int result; | 
 | 2503 |  | 
 | 2504 | 	if (sony_call_snc_handle(0x0131, 0x0000, &result) || !(result & 0x01)) { | 
 | 2505 | 		/* some models advertise the handle but have no implementation | 
 | 2506 | 		 * for it | 
 | 2507 | 		 */ | 
 | 2508 | 		pr_info("No High Speed Charging capability found\n"); | 
 | 2509 | 		return 0; | 
 | 2510 | 	} | 
 | 2511 |  | 
 | 2512 | 	hsc_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL); | 
 | 2513 | 	if (!hsc_handle) | 
 | 2514 | 		return -ENOMEM; | 
 | 2515 |  | 
 | 2516 | 	sysfs_attr_init(&hsc_handle->attr); | 
 | 2517 | 	hsc_handle->attr.name = "battery_highspeed_charging"; | 
 | 2518 | 	hsc_handle->attr.mode = S_IRUGO | S_IWUSR; | 
 | 2519 | 	hsc_handle->show = sony_nc_highspeed_charging_show; | 
 | 2520 | 	hsc_handle->store = sony_nc_highspeed_charging_store; | 
 | 2521 |  | 
 | 2522 | 	result = device_create_file(&pd->dev, hsc_handle); | 
 | 2523 | 	if (result) { | 
 | 2524 | 		kfree(hsc_handle); | 
 | 2525 | 		hsc_handle = NULL; | 
 | 2526 | 		return result; | 
 | 2527 | 	} | 
 | 2528 |  | 
 | 2529 | 	return 0; | 
 | 2530 | } | 
 | 2531 |  | 
 | 2532 | static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd) | 
 | 2533 | { | 
 | 2534 | 	if (hsc_handle) { | 
 | 2535 | 		device_remove_file(&pd->dev, hsc_handle); | 
 | 2536 | 		kfree(hsc_handle); | 
 | 2537 | 		hsc_handle = NULL; | 
 | 2538 | 	} | 
 | 2539 | } | 
 | 2540 |  | 
| Marco Chiappero | 2b8791c | 2012-05-19 22:36:00 +0900 | [diff] [blame] | 2541 | /* Touchpad enable/disable */ | 
 | 2542 | struct touchpad_control { | 
 | 2543 | 	struct device_attribute attr; | 
 | 2544 | 	int handle; | 
 | 2545 | }; | 
 | 2546 | static struct touchpad_control *tp_ctl; | 
 | 2547 |  | 
 | 2548 | static ssize_t sony_nc_touchpad_store(struct device *dev, | 
 | 2549 | 		struct device_attribute *attr, const char *buffer, size_t count) | 
 | 2550 | { | 
 | 2551 | 	unsigned int result; | 
 | 2552 | 	unsigned long value; | 
 | 2553 |  | 
 | 2554 | 	if (count > 31) | 
 | 2555 | 		return -EINVAL; | 
 | 2556 |  | 
 | 2557 | 	if (kstrtoul(buffer, 10, &value) || value > 1) | 
 | 2558 | 		return -EINVAL; | 
 | 2559 |  | 
 | 2560 | 	/* sysfs: 0 disabled, 1 enabled | 
 | 2561 | 	 * EC: 0 enabled, 1 disabled | 
 | 2562 | 	 */ | 
 | 2563 | 	if (sony_call_snc_handle(tp_ctl->handle, | 
 | 2564 | 				(!value << 0x10) | 0x100, &result)) | 
 | 2565 | 		return -EIO; | 
 | 2566 |  | 
 | 2567 | 	return count; | 
 | 2568 | } | 
 | 2569 |  | 
 | 2570 | static ssize_t sony_nc_touchpad_show(struct device *dev, | 
 | 2571 | 		struct device_attribute *attr, char *buffer) | 
 | 2572 | { | 
 | 2573 | 	unsigned int result; | 
 | 2574 |  | 
 | 2575 | 	if (sony_call_snc_handle(tp_ctl->handle, 0x000, &result)) | 
 | 2576 | 		return -EINVAL; | 
 | 2577 |  | 
 | 2578 | 	return snprintf(buffer, PAGE_SIZE, "%d\n", !(result & 0x01)); | 
 | 2579 | } | 
 | 2580 |  | 
 | 2581 | static int sony_nc_touchpad_setup(struct platform_device *pd, | 
 | 2582 | 		unsigned int handle) | 
 | 2583 | { | 
 | 2584 | 	int ret = 0; | 
 | 2585 |  | 
 | 2586 | 	tp_ctl = kzalloc(sizeof(struct touchpad_control), GFP_KERNEL); | 
 | 2587 | 	if (!tp_ctl) | 
 | 2588 | 		return -ENOMEM; | 
 | 2589 |  | 
 | 2590 | 	tp_ctl->handle = handle; | 
 | 2591 |  | 
 | 2592 | 	sysfs_attr_init(&tp_ctl->attr.attr); | 
 | 2593 | 	tp_ctl->attr.attr.name = "touchpad"; | 
 | 2594 | 	tp_ctl->attr.attr.mode = S_IRUGO | S_IWUSR; | 
 | 2595 | 	tp_ctl->attr.show = sony_nc_touchpad_show; | 
 | 2596 | 	tp_ctl->attr.store = sony_nc_touchpad_store; | 
 | 2597 |  | 
 | 2598 | 	ret = device_create_file(&pd->dev, &tp_ctl->attr); | 
 | 2599 | 	if (ret) { | 
 | 2600 | 		kfree(tp_ctl); | 
 | 2601 | 		tp_ctl = NULL; | 
 | 2602 | 	} | 
 | 2603 |  | 
 | 2604 | 	return ret; | 
 | 2605 | } | 
 | 2606 |  | 
 | 2607 | static void sony_nc_touchpad_cleanup(struct platform_device *pd) | 
 | 2608 | { | 
 | 2609 | 	if (tp_ctl) { | 
 | 2610 | 		device_remove_file(&pd->dev, &tp_ctl->attr); | 
 | 2611 | 		kfree(tp_ctl); | 
 | 2612 | 		tp_ctl = NULL; | 
 | 2613 | 	} | 
 | 2614 | } | 
 | 2615 |  | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2616 | static void sony_nc_backlight_ng_read_limits(int handle, | 
 | 2617 | 		struct sony_backlight_props *props) | 
 | 2618 | { | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2619 | 	u64 offset; | 
 | 2620 | 	int i; | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2621 | 	int lvl_table_len = 0; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2622 | 	u8 min = 0xff, max = 0x00; | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2623 | 	unsigned char buffer[32] = { 0 }; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2624 |  | 
 | 2625 | 	props->handle = handle; | 
 | 2626 | 	props->offset = 0; | 
 | 2627 | 	props->maxlvl = 0xff; | 
 | 2628 |  | 
 | 2629 | 	offset = sony_find_snc_handle(handle); | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2630 |  | 
 | 2631 | 	/* try to read the boundaries from ACPI tables, if we fail the above | 
 | 2632 | 	 * defaults should be reasonable | 
 | 2633 | 	 */ | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2634 | 	i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer, | 
 | 2635 | 			32); | 
 | 2636 | 	if (i < 0) | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2637 | 		return; | 
 | 2638 |  | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2639 | 	switch (handle) { | 
 | 2640 | 	case 0x012f: | 
 | 2641 | 	case 0x0137: | 
 | 2642 | 		lvl_table_len = 9; | 
 | 2643 | 		break; | 
 | 2644 | 	case 0x143: | 
| Mattia Dongili | 7517a17 | 2012-12-21 07:21:11 +0900 | [diff] [blame] | 2645 | 	case 0x14b: | 
 | 2646 | 	case 0x14c: | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2647 | 		lvl_table_len = 16; | 
 | 2648 | 		break; | 
 | 2649 | 	} | 
 | 2650 |  | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2651 | 	/* the buffer lists brightness levels available, brightness levels are | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2652 | 	 * from position 0 to 8 in the array, other values are used by ALS | 
 | 2653 | 	 * control. | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2654 | 	 */ | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2655 | 	for (i = 0; i < lvl_table_len && i < ARRAY_SIZE(buffer); i++) { | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2656 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2657 | 		dprintk("Brightness level: %d\n", buffer[i]); | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2658 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2659 | 		if (!buffer[i]) | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2660 | 			break; | 
 | 2661 |  | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2662 | 		if (buffer[i] > max) | 
 | 2663 | 			max = buffer[i]; | 
 | 2664 | 		if (buffer[i] < min) | 
 | 2665 | 			min = buffer[i]; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2666 | 	} | 
 | 2667 | 	props->offset = min; | 
 | 2668 | 	props->maxlvl = max; | 
 | 2669 | 	dprintk("Brightness levels: min=%d max=%d\n", props->offset, | 
 | 2670 | 			props->maxlvl); | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2671 | } | 
 | 2672 |  | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2673 | static void sony_nc_backlight_setup(void) | 
 | 2674 | { | 
 | 2675 | 	acpi_handle unused; | 
 | 2676 | 	int max_brightness = 0; | 
 | 2677 | 	const struct backlight_ops *ops = NULL; | 
 | 2678 | 	struct backlight_properties props; | 
 | 2679 |  | 
| Mattia Dongili | a1071a5 | 2012-06-14 06:36:02 +0900 | [diff] [blame] | 2680 | 	if (sony_find_snc_handle(0x12f) >= 0) { | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2681 | 		ops = &sony_backlight_ng_ops; | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2682 | 		sony_bl_props.cmd_base = 0x0100; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2683 | 		sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props); | 
 | 2684 | 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset; | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2685 |  | 
| Mattia Dongili | a1071a5 | 2012-06-14 06:36:02 +0900 | [diff] [blame] | 2686 | 	} else if (sony_find_snc_handle(0x137) >= 0) { | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2687 | 		ops = &sony_backlight_ng_ops; | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2688 | 		sony_bl_props.cmd_base = 0x0100; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2689 | 		sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props); | 
 | 2690 | 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset; | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2691 |  | 
| Mattia Dongili | a1071a5 | 2012-06-14 06:36:02 +0900 | [diff] [blame] | 2692 | 	} else if (sony_find_snc_handle(0x143) >= 0) { | 
| Mattia Dongili | 014fc8f | 2012-06-09 13:18:11 +0900 | [diff] [blame] | 2693 | 		ops = &sony_backlight_ng_ops; | 
 | 2694 | 		sony_bl_props.cmd_base = 0x3000; | 
 | 2695 | 		sony_nc_backlight_ng_read_limits(0x143, &sony_bl_props); | 
 | 2696 | 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset; | 
 | 2697 |  | 
| Mattia Dongili | 7517a17 | 2012-12-21 07:21:11 +0900 | [diff] [blame] | 2698 | 	} else if (sony_find_snc_handle(0x14b) >= 0) { | 
 | 2699 | 		ops = &sony_backlight_ng_ops; | 
 | 2700 | 		sony_bl_props.cmd_base = 0x3000; | 
 | 2701 | 		sony_nc_backlight_ng_read_limits(0x14b, &sony_bl_props); | 
 | 2702 | 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset; | 
 | 2703 |  | 
 | 2704 | 	} else if (sony_find_snc_handle(0x14c) >= 0) { | 
 | 2705 | 		ops = &sony_backlight_ng_ops; | 
 | 2706 | 		sony_bl_props.cmd_base = 0x3000; | 
 | 2707 | 		sony_nc_backlight_ng_read_limits(0x14c, &sony_bl_props); | 
 | 2708 | 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset; | 
 | 2709 |  | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2710 | 	} else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", | 
 | 2711 | 						&unused))) { | 
 | 2712 | 		ops = &sony_backlight_ops; | 
 | 2713 | 		max_brightness = SONY_MAX_BRIGHTNESS - 1; | 
 | 2714 |  | 
 | 2715 | 	} else | 
 | 2716 | 		return; | 
 | 2717 |  | 
 | 2718 | 	memset(&props, 0, sizeof(struct backlight_properties)); | 
 | 2719 | 	props.type = BACKLIGHT_PLATFORM; | 
 | 2720 | 	props.max_brightness = max_brightness; | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2721 | 	sony_bl_props.dev = backlight_device_register("sony", NULL, | 
 | 2722 | 						      &sony_bl_props, | 
 | 2723 | 						      ops, &props); | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2724 |  | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2725 | 	if (IS_ERR(sony_bl_props.dev)) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 2726 | 		pr_warn("unable to register backlight device\n"); | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2727 | 		sony_bl_props.dev = NULL; | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2728 | 	} else | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2729 | 		sony_bl_props.dev->props.brightness = | 
 | 2730 | 			ops->get_brightness(sony_bl_props.dev); | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2731 | } | 
 | 2732 |  | 
 | 2733 | static void sony_nc_backlight_cleanup(void) | 
 | 2734 | { | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 2735 | 	if (sony_bl_props.dev) | 
 | 2736 | 		backlight_device_unregister(sony_bl_props.dev); | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2737 | } | 
 | 2738 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2739 | static int sony_nc_add(struct acpi_device *device) | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2740 | { | 
 | 2741 | 	acpi_status status; | 
| Andrew Morton | 8607c67 | 2007-03-06 02:29:42 -0800 | [diff] [blame] | 2742 | 	int result = 0; | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 2743 | 	acpi_handle handle; | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2744 | 	struct sony_nc_value *item; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2745 |  | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 2746 | 	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] | 2747 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2748 | 	sony_nc_acpi_device = device; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2749 | 	strcpy(acpi_device_class(device), "sony/hotkey"); | 
| Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 2750 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2751 | 	sony_nc_acpi_handle = device->handle; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2752 |  | 
| Mattia Dongili | b25b732 | 2007-07-16 02:34:36 +0900 | [diff] [blame] | 2753 | 	/* read device status */ | 
 | 2754 | 	result = acpi_bus_get_status(device); | 
 | 2755 | 	/* bail IFF the above call was successful and the device is not present */ | 
 | 2756 | 	if (!result && !device->status.present) { | 
 | 2757 | 		dprintk("Device not present\n"); | 
 | 2758 | 		result = -ENODEV; | 
 | 2759 | 		goto outwalk; | 
 | 2760 | 	} | 
 | 2761 |  | 
| Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 2762 | 	result = sony_pf_add(); | 
 | 2763 | 	if (result) | 
 | 2764 | 		goto outpresent; | 
 | 2765 |  | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2766 | 	if (debug) { | 
| Mattia Dongili | d669793 | 2011-02-19 11:52:28 +0900 | [diff] [blame] | 2767 | 		status = acpi_walk_namespace(ACPI_TYPE_METHOD, | 
 | 2768 | 				sony_nc_acpi_handle, 1, sony_walk_callback, | 
 | 2769 | 				NULL, NULL, NULL); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2770 | 		if (ACPI_FAILURE(status)) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 2771 | 			pr_warn("unable to walk acpi resources\n"); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2772 | 			result = -ENODEV; | 
| Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 2773 | 			goto outpresent; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2774 | 		} | 
| Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 2775 | 	} | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2776 |  | 
| Mattia Dongili | ca3c2c7 | 2012-06-09 13:18:12 +0900 | [diff] [blame] | 2777 | 	result = sony_laptop_setup_input(device); | 
 | 2778 | 	if (result) { | 
 | 2779 | 		pr_err("Unable to create input devices\n"); | 
 | 2780 | 		goto outplatform; | 
 | 2781 | 	} | 
 | 2782 |  | 
| Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 2783 | 	if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", | 
 | 2784 | 					 &handle))) { | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 2785 | 		int arg = 1; | 
 | 2786 | 		if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL)) | 
| Matthew Garrett | 82734bf | 2009-03-26 21:58:13 +0900 | [diff] [blame] | 2787 | 			dprintk("ECON Method failed\n"); | 
 | 2788 | 	} | 
 | 2789 |  | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 2790 | 	if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", | 
 | 2791 | 					 &handle))) { | 
 | 2792 | 		dprintk("Doing SNC setup\n"); | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 2793 | 		/* retrieve the available handles */ | 
| Dan Carpenter | 7227ded | 2011-02-26 15:54:57 +0300 | [diff] [blame] | 2794 | 		result = sony_nc_handles_setup(sony_pf_device); | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 2795 | 		if (!result) | 
 | 2796 | 			sony_nc_function_setup(device, sony_pf_device); | 
| Matthew Garrett | badf26f | 2009-03-26 21:58:12 +0900 | [diff] [blame] | 2797 | 	} | 
 | 2798 |  | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 2799 | 	/* setup input devices and helper fifo */ | 
| Alessandro Guido | 38cfc14 | 2008-11-12 23:03:28 +0100 | [diff] [blame] | 2800 | 	if (acpi_video_backlight_support()) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 2801 | 		pr_info("brightness ignored, must be controlled by ACPI video driver\n"); | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2802 | 	} else { | 
 | 2803 | 		sony_nc_backlight_setup(); | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 2804 | 	} | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2805 |  | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2806 | 	/* create sony_pf sysfs attributes related to the SNC device */ | 
 | 2807 | 	for (item = sony_nc_values; item->name; ++item) { | 
 | 2808 |  | 
 | 2809 | 		if (!debug && item->debug) | 
 | 2810 | 			continue; | 
 | 2811 |  | 
 | 2812 | 		/* find the available acpiget as described in the DSDT */ | 
 | 2813 | 		for (; item->acpiget && *item->acpiget; ++item->acpiget) { | 
 | 2814 | 			if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, | 
 | 2815 | 							 *item->acpiget, | 
 | 2816 | 							 &handle))) { | 
| malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 2817 | 				dprintk("Found %s getter: %s\n", | 
 | 2818 | 						item->name, *item->acpiget); | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2819 | 				item->devattr.attr.mode |= S_IRUGO; | 
 | 2820 | 				break; | 
 | 2821 | 			} | 
 | 2822 | 		} | 
 | 2823 |  | 
 | 2824 | 		/* find the available acpiset as described in the DSDT */ | 
 | 2825 | 		for (; item->acpiset && *item->acpiset; ++item->acpiset) { | 
 | 2826 | 			if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, | 
 | 2827 | 							 *item->acpiset, | 
 | 2828 | 							 &handle))) { | 
| malattia@linux.it | b9a218b | 2007-04-09 10:19:06 +0200 | [diff] [blame] | 2829 | 				dprintk("Found %s setter: %s\n", | 
 | 2830 | 						item->name, *item->acpiset); | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2831 | 				item->devattr.attr.mode |= S_IWUSR; | 
 | 2832 | 				break; | 
 | 2833 | 			} | 
 | 2834 | 		} | 
 | 2835 |  | 
 | 2836 | 		if (item->devattr.attr.mode != 0) { | 
 | 2837 | 			result = | 
 | 2838 | 			    device_create_file(&sony_pf_device->dev, | 
 | 2839 | 					       &item->devattr); | 
 | 2840 | 			if (result) | 
 | 2841 | 				goto out_sysfs; | 
 | 2842 | 		} | 
 | 2843 | 	} | 
 | 2844 |  | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2845 | 	return 0; | 
 | 2846 |  | 
| Mattia Dongili | ca3c2c7 | 2012-06-09 13:18:12 +0900 | [diff] [blame] | 2847 | out_sysfs: | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2848 | 	for (item = sony_nc_values; item->name; ++item) { | 
 | 2849 | 		device_remove_file(&sony_pf_device->dev, &item->devattr); | 
 | 2850 | 	} | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2851 | 	sony_nc_backlight_cleanup(); | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 2852 | 	sony_nc_function_cleanup(sony_pf_device); | 
| Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 2853 | 	sony_nc_handles_cleanup(sony_pf_device); | 
 | 2854 |  | 
| Mattia Dongili | ca3c2c7 | 2012-06-09 13:18:12 +0900 | [diff] [blame] | 2855 | outplatform: | 
 | 2856 | 	sony_laptop_remove_input(); | 
 | 2857 |  | 
 | 2858 | outpresent: | 
| Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 2859 | 	sony_pf_remove(); | 
 | 2860 |  | 
| Mattia Dongili | ca3c2c7 | 2012-06-09 13:18:12 +0900 | [diff] [blame] | 2861 | outwalk: | 
| Matthew Garrett | 6cc056b | 2009-03-26 21:58:15 +0900 | [diff] [blame] | 2862 | 	sony_nc_rfkill_cleanup(); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2863 | 	return result; | 
 | 2864 | } | 
 | 2865 |  | 
| Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 2866 | static int sony_nc_remove(struct acpi_device *device) | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2867 | { | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2868 | 	struct sony_nc_value *item; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2869 |  | 
| Mattia Dongili | 7751ab8 | 2011-02-19 11:52:32 +0900 | [diff] [blame] | 2870 | 	sony_nc_backlight_cleanup(); | 
| Alessandro Guido | 50f62af | 2007-01-13 23:04:34 +0100 | [diff] [blame] | 2871 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2872 | 	sony_nc_acpi_device = NULL; | 
| Stelian Pop | c561162 | 2007-01-13 23:04:37 +0100 | [diff] [blame] | 2873 |  | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2874 | 	for (item = sony_nc_values; item->name; ++item) { | 
 | 2875 | 		device_remove_file(&sony_pf_device->dev, &item->devattr); | 
 | 2876 | 	} | 
 | 2877 |  | 
| Marco Chiappero | 5fe801a | 2012-05-19 22:35:48 +0900 | [diff] [blame] | 2878 | 	sony_nc_function_cleanup(sony_pf_device); | 
| Mattia Dongili | 2a4f0c8 | 2011-02-19 11:52:30 +0900 | [diff] [blame] | 2879 | 	sony_nc_handles_cleanup(sony_pf_device); | 
| malattia@linux.it | 56b8756 | 2007-04-09 10:19:05 +0200 | [diff] [blame] | 2880 | 	sony_pf_remove(); | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 2881 | 	sony_laptop_remove_input(); | 
| malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 2882 | 	dprintk(SONY_NC_DRIVER_NAME " removed.\n"); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 2883 |  | 
 | 2884 | 	return 0; | 
 | 2885 | } | 
 | 2886 |  | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2887 | static const struct acpi_device_id sony_device_ids[] = { | 
 | 2888 | 	{SONY_NC_HID, 0}, | 
 | 2889 | 	{SONY_PIC_HID, 0}, | 
 | 2890 | 	{"", 0}, | 
 | 2891 | }; | 
 | 2892 | MODULE_DEVICE_TABLE(acpi, sony_device_ids); | 
 | 2893 |  | 
 | 2894 | static const struct acpi_device_id sony_nc_device_ids[] = { | 
 | 2895 | 	{SONY_NC_HID, 0}, | 
 | 2896 | 	{"", 0}, | 
 | 2897 | }; | 
 | 2898 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2899 | static struct acpi_driver sony_nc_driver = { | 
 | 2900 | 	.name = SONY_NC_DRIVER_NAME, | 
 | 2901 | 	.class = SONY_NC_CLASS, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2902 | 	.ids = sony_nc_device_ids, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2903 | 	.owner = THIS_MODULE, | 
| Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 2904 | 	.ops = { | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 2905 | 		.add = sony_nc_add, | 
 | 2906 | 		.remove = sony_nc_remove, | 
| Bjorn Helgaas | 8037d6e | 2009-04-07 15:37:32 +0000 | [diff] [blame] | 2907 | 		.notify = sony_nc_notify, | 
| Len Brown | a02d1c1 | 2007-02-07 15:34:02 -0500 | [diff] [blame] | 2908 | 		}, | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 2909 | 	.drv.pm = &sony_nc_pm, | 
| Andrew Morton | 3f4f461 | 2007-01-13 23:04:32 +0100 | [diff] [blame] | 2910 | }; | 
 | 2911 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2912 | /*********** SPIC (SNY6001) Device ***********/ | 
 | 2913 |  | 
 | 2914 | #define SONYPI_DEVICE_TYPE1	0x00000001 | 
 | 2915 | #define SONYPI_DEVICE_TYPE2	0x00000002 | 
 | 2916 | #define SONYPI_DEVICE_TYPE3	0x00000004 | 
 | 2917 |  | 
| Mattia Dongili | 22a1778 | 2007-07-16 02:34:39 +0900 | [diff] [blame] | 2918 | #define SONYPI_TYPE1_OFFSET	0x04 | 
 | 2919 | #define SONYPI_TYPE2_OFFSET	0x12 | 
 | 2920 | #define SONYPI_TYPE3_OFFSET	0x12 | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2921 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2922 | struct sony_pic_ioport { | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 2923 | 	struct acpi_resource_io	io1; | 
 | 2924 | 	struct acpi_resource_io	io2; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2925 | 	struct list_head	list; | 
 | 2926 | }; | 
 | 2927 |  | 
 | 2928 | struct sony_pic_irq { | 
 | 2929 | 	struct acpi_resource_irq	irq; | 
 | 2930 | 	struct list_head		list; | 
 | 2931 | }; | 
 | 2932 |  | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 2933 | struct sonypi_eventtypes { | 
 | 2934 | 	u8			data; | 
 | 2935 | 	unsigned long		mask; | 
 | 2936 | 	struct sonypi_event	*events; | 
 | 2937 | }; | 
 | 2938 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2939 | struct sony_pic_dev { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 2940 | 	struct acpi_device		*acpi_dev; | 
 | 2941 | 	struct sony_pic_irq		*cur_irq; | 
 | 2942 | 	struct sony_pic_ioport		*cur_ioport; | 
 | 2943 | 	struct list_head		interrupts; | 
 | 2944 | 	struct list_head		ioports; | 
 | 2945 | 	struct mutex			lock; | 
 | 2946 | 	struct sonypi_eventtypes	*event_types; | 
 | 2947 | 	int                             (*handle_irq)(const u8, const u8); | 
 | 2948 | 	int				model; | 
 | 2949 | 	u16				evport_offset; | 
 | 2950 | 	u8				camera_power; | 
 | 2951 | 	u8				bluetooth_power; | 
 | 2952 | 	u8				wwan_power; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2953 | }; | 
 | 2954 |  | 
 | 2955 | static struct sony_pic_dev spic_dev = { | 
 | 2956 | 	.interrupts	= LIST_HEAD_INIT(spic_dev.interrupts), | 
 | 2957 | 	.ioports	= LIST_HEAD_INIT(spic_dev.ioports), | 
 | 2958 | }; | 
 | 2959 |  | 
| Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 2960 | static int spic_drv_registered; | 
 | 2961 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 2962 | /* Event masks */ | 
 | 2963 | #define SONYPI_JOGGER_MASK			0x00000001 | 
 | 2964 | #define SONYPI_CAPTURE_MASK			0x00000002 | 
 | 2965 | #define SONYPI_FNKEY_MASK			0x00000004 | 
 | 2966 | #define SONYPI_BLUETOOTH_MASK			0x00000008 | 
 | 2967 | #define SONYPI_PKEY_MASK			0x00000010 | 
 | 2968 | #define SONYPI_BACK_MASK			0x00000020 | 
 | 2969 | #define SONYPI_HELP_MASK			0x00000040 | 
 | 2970 | #define SONYPI_LID_MASK				0x00000080 | 
 | 2971 | #define SONYPI_ZOOM_MASK			0x00000100 | 
 | 2972 | #define SONYPI_THUMBPHRASE_MASK			0x00000200 | 
 | 2973 | #define SONYPI_MEYE_MASK			0x00000400 | 
 | 2974 | #define SONYPI_MEMORYSTICK_MASK			0x00000800 | 
 | 2975 | #define SONYPI_BATTERY_MASK			0x00001000 | 
 | 2976 | #define SONYPI_WIRELESS_MASK			0x00002000 | 
 | 2977 |  | 
 | 2978 | struct sonypi_event { | 
 | 2979 | 	u8	data; | 
 | 2980 | 	u8	event; | 
 | 2981 | }; | 
 | 2982 |  | 
 | 2983 | /* The set of possible button release events */ | 
 | 2984 | static struct sonypi_event sonypi_releaseev[] = { | 
 | 2985 | 	{ 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED }, | 
 | 2986 | 	{ 0, 0 } | 
 | 2987 | }; | 
 | 2988 |  | 
 | 2989 | /* The set of possible jogger events  */ | 
 | 2990 | static struct sonypi_event sonypi_joggerev[] = { | 
 | 2991 | 	{ 0x1f, SONYPI_EVENT_JOGDIAL_UP }, | 
 | 2992 | 	{ 0x01, SONYPI_EVENT_JOGDIAL_DOWN }, | 
 | 2993 | 	{ 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED }, | 
 | 2994 | 	{ 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED }, | 
 | 2995 | 	{ 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP }, | 
 | 2996 | 	{ 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN }, | 
 | 2997 | 	{ 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED }, | 
 | 2998 | 	{ 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED }, | 
 | 2999 | 	{ 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP }, | 
 | 3000 | 	{ 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN }, | 
 | 3001 | 	{ 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED }, | 
 | 3002 | 	{ 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED }, | 
 | 3003 | 	{ 0x40, SONYPI_EVENT_JOGDIAL_PRESSED }, | 
 | 3004 | 	{ 0, 0 } | 
 | 3005 | }; | 
 | 3006 |  | 
 | 3007 | /* The set of possible capture button events */ | 
 | 3008 | static struct sonypi_event sonypi_captureev[] = { | 
 | 3009 | 	{ 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED }, | 
 | 3010 | 	{ 0x07, SONYPI_EVENT_CAPTURE_PRESSED }, | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3011 | 	{ 0x40, SONYPI_EVENT_CAPTURE_PRESSED }, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3012 | 	{ 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED }, | 
 | 3013 | 	{ 0, 0 } | 
 | 3014 | }; | 
 | 3015 |  | 
 | 3016 | /* The set of possible fnkeys events */ | 
 | 3017 | static struct sonypi_event sonypi_fnkeyev[] = { | 
 | 3018 | 	{ 0x10, SONYPI_EVENT_FNKEY_ESC }, | 
 | 3019 | 	{ 0x11, SONYPI_EVENT_FNKEY_F1 }, | 
 | 3020 | 	{ 0x12, SONYPI_EVENT_FNKEY_F2 }, | 
 | 3021 | 	{ 0x13, SONYPI_EVENT_FNKEY_F3 }, | 
 | 3022 | 	{ 0x14, SONYPI_EVENT_FNKEY_F4 }, | 
 | 3023 | 	{ 0x15, SONYPI_EVENT_FNKEY_F5 }, | 
 | 3024 | 	{ 0x16, SONYPI_EVENT_FNKEY_F6 }, | 
 | 3025 | 	{ 0x17, SONYPI_EVENT_FNKEY_F7 }, | 
 | 3026 | 	{ 0x18, SONYPI_EVENT_FNKEY_F8 }, | 
 | 3027 | 	{ 0x19, SONYPI_EVENT_FNKEY_F9 }, | 
 | 3028 | 	{ 0x1a, SONYPI_EVENT_FNKEY_F10 }, | 
 | 3029 | 	{ 0x1b, SONYPI_EVENT_FNKEY_F11 }, | 
 | 3030 | 	{ 0x1c, SONYPI_EVENT_FNKEY_F12 }, | 
 | 3031 | 	{ 0x1f, SONYPI_EVENT_FNKEY_RELEASED }, | 
 | 3032 | 	{ 0x21, SONYPI_EVENT_FNKEY_1 }, | 
 | 3033 | 	{ 0x22, SONYPI_EVENT_FNKEY_2 }, | 
 | 3034 | 	{ 0x31, SONYPI_EVENT_FNKEY_D }, | 
 | 3035 | 	{ 0x32, SONYPI_EVENT_FNKEY_E }, | 
 | 3036 | 	{ 0x33, SONYPI_EVENT_FNKEY_F }, | 
 | 3037 | 	{ 0x34, SONYPI_EVENT_FNKEY_S }, | 
 | 3038 | 	{ 0x35, SONYPI_EVENT_FNKEY_B }, | 
 | 3039 | 	{ 0x36, SONYPI_EVENT_FNKEY_ONLY }, | 
 | 3040 | 	{ 0, 0 } | 
 | 3041 | }; | 
 | 3042 |  | 
 | 3043 | /* The set of possible program key events */ | 
 | 3044 | static struct sonypi_event sonypi_pkeyev[] = { | 
 | 3045 | 	{ 0x01, SONYPI_EVENT_PKEY_P1 }, | 
 | 3046 | 	{ 0x02, SONYPI_EVENT_PKEY_P2 }, | 
 | 3047 | 	{ 0x04, SONYPI_EVENT_PKEY_P3 }, | 
| Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 3048 | 	{ 0x20, SONYPI_EVENT_PKEY_P1 }, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3049 | 	{ 0, 0 } | 
 | 3050 | }; | 
 | 3051 |  | 
 | 3052 | /* The set of possible bluetooth events */ | 
 | 3053 | static struct sonypi_event sonypi_blueev[] = { | 
 | 3054 | 	{ 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED }, | 
 | 3055 | 	{ 0x59, SONYPI_EVENT_BLUETOOTH_ON }, | 
 | 3056 | 	{ 0x5a, SONYPI_EVENT_BLUETOOTH_OFF }, | 
 | 3057 | 	{ 0, 0 } | 
 | 3058 | }; | 
 | 3059 |  | 
 | 3060 | /* The set of possible wireless events */ | 
 | 3061 | static struct sonypi_event sonypi_wlessev[] = { | 
| Mattia Dongili | 4eeb502 | 2011-02-19 11:52:27 +0900 | [diff] [blame] | 3062 | 	{ 0x59, SONYPI_EVENT_IGNORE }, | 
 | 3063 | 	{ 0x5a, SONYPI_EVENT_IGNORE }, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3064 | 	{ 0, 0 } | 
 | 3065 | }; | 
 | 3066 |  | 
 | 3067 | /* The set of possible back button events */ | 
 | 3068 | static struct sonypi_event sonypi_backev[] = { | 
 | 3069 | 	{ 0x20, SONYPI_EVENT_BACK_PRESSED }, | 
 | 3070 | 	{ 0, 0 } | 
 | 3071 | }; | 
 | 3072 |  | 
 | 3073 | /* The set of possible help button events */ | 
 | 3074 | static struct sonypi_event sonypi_helpev[] = { | 
 | 3075 | 	{ 0x3b, SONYPI_EVENT_HELP_PRESSED }, | 
 | 3076 | 	{ 0, 0 } | 
 | 3077 | }; | 
 | 3078 |  | 
 | 3079 |  | 
 | 3080 | /* The set of possible lid events */ | 
 | 3081 | static struct sonypi_event sonypi_lidev[] = { | 
 | 3082 | 	{ 0x51, SONYPI_EVENT_LID_CLOSED }, | 
 | 3083 | 	{ 0x50, SONYPI_EVENT_LID_OPENED }, | 
 | 3084 | 	{ 0, 0 } | 
 | 3085 | }; | 
 | 3086 |  | 
 | 3087 | /* The set of possible zoom events */ | 
 | 3088 | static struct sonypi_event sonypi_zoomev[] = { | 
 | 3089 | 	{ 0x39, SONYPI_EVENT_ZOOM_PRESSED }, | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3090 | 	{ 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED }, | 
 | 3091 | 	{ 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED }, | 
| Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 3092 | 	{ 0x04, SONYPI_EVENT_ZOOM_PRESSED }, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3093 | 	{ 0, 0 } | 
 | 3094 | }; | 
 | 3095 |  | 
 | 3096 | /* The set of possible thumbphrase events */ | 
 | 3097 | static struct sonypi_event sonypi_thumbphraseev[] = { | 
 | 3098 | 	{ 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED }, | 
 | 3099 | 	{ 0, 0 } | 
 | 3100 | }; | 
 | 3101 |  | 
 | 3102 | /* The set of possible motioneye camera events */ | 
 | 3103 | static struct sonypi_event sonypi_meyeev[] = { | 
 | 3104 | 	{ 0x00, SONYPI_EVENT_MEYE_FACE }, | 
 | 3105 | 	{ 0x01, SONYPI_EVENT_MEYE_OPPOSITE }, | 
 | 3106 | 	{ 0, 0 } | 
 | 3107 | }; | 
 | 3108 |  | 
 | 3109 | /* The set of possible memorystick events */ | 
 | 3110 | static struct sonypi_event sonypi_memorystickev[] = { | 
 | 3111 | 	{ 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT }, | 
 | 3112 | 	{ 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT }, | 
 | 3113 | 	{ 0, 0 } | 
 | 3114 | }; | 
 | 3115 |  | 
 | 3116 | /* The set of possible battery events */ | 
 | 3117 | static struct sonypi_event sonypi_batteryev[] = { | 
 | 3118 | 	{ 0x20, SONYPI_EVENT_BATTERY_INSERT }, | 
 | 3119 | 	{ 0x30, SONYPI_EVENT_BATTERY_REMOVE }, | 
 | 3120 | 	{ 0, 0 } | 
 | 3121 | }; | 
 | 3122 |  | 
| Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 3123 | /* The set of possible volume events */ | 
 | 3124 | static struct sonypi_event sonypi_volumeev[] = { | 
 | 3125 | 	{ 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED }, | 
 | 3126 | 	{ 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED }, | 
 | 3127 | 	{ 0, 0 } | 
 | 3128 | }; | 
 | 3129 |  | 
 | 3130 | /* The set of possible brightness events */ | 
 | 3131 | static struct sonypi_event sonypi_brightnessev[] = { | 
 | 3132 | 	{ 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED }, | 
 | 3133 | 	{ 0, 0 } | 
 | 3134 | }; | 
 | 3135 |  | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3136 | static struct sonypi_eventtypes type1_events[] = { | 
 | 3137 | 	{ 0, 0xffffffff, sonypi_releaseev }, | 
 | 3138 | 	{ 0x70, SONYPI_MEYE_MASK, sonypi_meyeev }, | 
 | 3139 | 	{ 0x30, SONYPI_LID_MASK, sonypi_lidev }, | 
 | 3140 | 	{ 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev }, | 
 | 3141 | 	{ 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev }, | 
 | 3142 | 	{ 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, | 
 | 3143 | 	{ 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, | 
 | 3144 | 	{ 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev }, | 
 | 3145 | 	{ 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, | 
 | 3146 | 	{ 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev }, | 
 | 3147 | 	{ 0 }, | 
 | 3148 | }; | 
 | 3149 | static struct sonypi_eventtypes type2_events[] = { | 
 | 3150 | 	{ 0, 0xffffffff, sonypi_releaseev }, | 
 | 3151 | 	{ 0x38, SONYPI_LID_MASK, sonypi_lidev }, | 
 | 3152 | 	{ 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev }, | 
 | 3153 | 	{ 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev }, | 
 | 3154 | 	{ 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, | 
 | 3155 | 	{ 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, | 
 | 3156 | 	{ 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev }, | 
 | 3157 | 	{ 0x11, SONYPI_BACK_MASK, sonypi_backev }, | 
 | 3158 | 	{ 0x21, SONYPI_HELP_MASK, sonypi_helpev }, | 
 | 3159 | 	{ 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev }, | 
 | 3160 | 	{ 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev }, | 
 | 3161 | 	{ 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, | 
 | 3162 | 	{ 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, | 
 | 3163 | 	{ 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, | 
 | 3164 | 	{ 0 }, | 
 | 3165 | }; | 
 | 3166 | static struct sonypi_eventtypes type3_events[] = { | 
 | 3167 | 	{ 0, 0xffffffff, sonypi_releaseev }, | 
 | 3168 | 	{ 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev }, | 
 | 3169 | 	{ 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev }, | 
 | 3170 | 	{ 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev }, | 
 | 3171 | 	{ 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, | 
 | 3172 | 	{ 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3173 | 	{ 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev }, | 
 | 3174 | 	{ 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev }, | 
 | 3175 | 	{ 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev }, | 
| Harald Jenny | 1cae710 | 2009-03-26 21:58:18 +0900 | [diff] [blame] | 3176 | 	{ 0x05, SONYPI_PKEY_MASK, sonypi_volumeev }, | 
 | 3177 | 	{ 0x05, SONYPI_PKEY_MASK, sonypi_brightnessev }, | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3178 | 	{ 0 }, | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 3179 | }; | 
 | 3180 |  | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3181 | /* low level spic calls */ | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3182 | #define ITERATIONS_LONG		10000 | 
 | 3183 | #define ITERATIONS_SHORT	10 | 
 | 3184 | #define wait_on_command(command, iterations) {				\ | 
 | 3185 | 	unsigned int n = iterations;					\ | 
 | 3186 | 	while (--n && (command))					\ | 
 | 3187 | 		udelay(1);						\ | 
 | 3188 | 	if (!n)								\ | 
 | 3189 | 		dprintk("command failed at %s : %s (line %d)\n",	\ | 
| Harvey Harrison | 6e57419 | 2008-04-29 00:59:20 -0700 | [diff] [blame] | 3190 | 				__FILE__, __func__, __LINE__);	\ | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3191 | } | 
 | 3192 |  | 
 | 3193 | static u8 sony_pic_call1(u8 dev) | 
 | 3194 | { | 
 | 3195 | 	u8 v1, v2; | 
 | 3196 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3197 | 	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] | 3198 | 			ITERATIONS_LONG); | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3199 | 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4); | 
 | 3200 | 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4); | 
 | 3201 | 	v2 = inb_p(spic_dev.cur_ioport->io1.minimum); | 
| Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 3202 | 	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] | 3203 | 	return v2; | 
 | 3204 | } | 
 | 3205 |  | 
 | 3206 | static u8 sony_pic_call2(u8 dev, u8 fn) | 
 | 3207 | { | 
 | 3208 | 	u8 v1; | 
 | 3209 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3210 | 	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] | 3211 | 			ITERATIONS_LONG); | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3212 | 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4); | 
 | 3213 | 	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] | 3214 | 			ITERATIONS_LONG); | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3215 | 	outb(fn, spic_dev.cur_ioport->io1.minimum); | 
 | 3216 | 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum); | 
| Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 3217 | 	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] | 3218 | 	return v1; | 
 | 3219 | } | 
 | 3220 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3221 | static u8 sony_pic_call3(u8 dev, u8 fn, u8 v) | 
 | 3222 | { | 
 | 3223 | 	u8 v1; | 
 | 3224 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3225 | 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); | 
 | 3226 | 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4); | 
 | 3227 | 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); | 
 | 3228 | 	outb(fn, spic_dev.cur_ioport->io1.minimum); | 
 | 3229 | 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG); | 
 | 3230 | 	outb(v, spic_dev.cur_ioport->io1.minimum); | 
 | 3231 | 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum); | 
| Mattia Dongili | 75a1f9c | 2008-01-14 18:05:41 +0900 | [diff] [blame] | 3232 | 	dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n", | 
 | 3233 | 			dev, fn, v, v1); | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3234 | 	return v1; | 
 | 3235 | } | 
 | 3236 |  | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3237 | /* | 
 | 3238 |  * minidrivers for SPIC models | 
 | 3239 |  */ | 
| Mattia Dongili | e93c8a6 | 2009-03-26 21:58:17 +0900 | [diff] [blame] | 3240 | static int type3_handle_irq(const u8 data_mask, const u8 ev) | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3241 | { | 
 | 3242 | 	/* | 
 | 3243 | 	 * 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] | 3244 | 	 * the next irq for some Type3 models, it will generate a new | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3245 | 	 * irq and we can read new data from the device: | 
 | 3246 | 	 *  - 0x5c and 0x5f requires 0xA0 | 
 | 3247 | 	 *  - 0x61 requires 0xB3 | 
 | 3248 | 	 */ | 
 | 3249 | 	if (data_mask == 0x31) { | 
 | 3250 | 		if (ev == 0x5c || ev == 0x5f) | 
 | 3251 | 			sony_pic_call1(0xA0); | 
 | 3252 | 		else if (ev == 0x61) | 
 | 3253 | 			sony_pic_call1(0xB3); | 
 | 3254 | 		return 0; | 
 | 3255 | 	} | 
 | 3256 | 	return 1; | 
 | 3257 | } | 
 | 3258 |  | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3259 | static void sony_pic_detect_device_type(struct sony_pic_dev *dev) | 
 | 3260 | { | 
 | 3261 | 	struct pci_dev *pcidev; | 
 | 3262 |  | 
 | 3263 | 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 
 | 3264 | 			PCI_DEVICE_ID_INTEL_82371AB_3, NULL); | 
 | 3265 | 	if (pcidev) { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3266 | 		dev->model = SONYPI_DEVICE_TYPE1; | 
 | 3267 | 		dev->evport_offset = SONYPI_TYPE1_OFFSET; | 
 | 3268 | 		dev->event_types = type1_events; | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3269 | 		goto out; | 
 | 3270 | 	} | 
 | 3271 |  | 
 | 3272 | 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 
 | 3273 | 			PCI_DEVICE_ID_INTEL_ICH6_1, NULL); | 
 | 3274 | 	if (pcidev) { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3275 | 		dev->model = SONYPI_DEVICE_TYPE2; | 
 | 3276 | 		dev->evport_offset = SONYPI_TYPE2_OFFSET; | 
 | 3277 | 		dev->event_types = type2_events; | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3278 | 		goto out; | 
 | 3279 | 	} | 
 | 3280 |  | 
 | 3281 | 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 
 | 3282 | 			PCI_DEVICE_ID_INTEL_ICH7_1, NULL); | 
 | 3283 | 	if (pcidev) { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3284 | 		dev->model = SONYPI_DEVICE_TYPE3; | 
 | 3285 | 		dev->handle_irq = type3_handle_irq; | 
 | 3286 | 		dev->evport_offset = SONYPI_TYPE3_OFFSET; | 
 | 3287 | 		dev->event_types = type3_events; | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3288 | 		goto out; | 
 | 3289 | 	} | 
 | 3290 |  | 
 | 3291 | 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 
 | 3292 | 			PCI_DEVICE_ID_INTEL_ICH8_4, NULL); | 
 | 3293 | 	if (pcidev) { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3294 | 		dev->model = SONYPI_DEVICE_TYPE3; | 
 | 3295 | 		dev->handle_irq = type3_handle_irq; | 
 | 3296 | 		dev->evport_offset = SONYPI_TYPE3_OFFSET; | 
 | 3297 | 		dev->event_types = type3_events; | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3298 | 		goto out; | 
 | 3299 | 	} | 
 | 3300 |  | 
| ISHIKAWA Mutsumi | d5b0269 | 2009-03-26 21:58:20 +0900 | [diff] [blame] | 3301 | 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 
 | 3302 | 			PCI_DEVICE_ID_INTEL_ICH9_1, NULL); | 
 | 3303 | 	if (pcidev) { | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3304 | 		dev->model = SONYPI_DEVICE_TYPE3; | 
 | 3305 | 		dev->handle_irq = type3_handle_irq; | 
 | 3306 | 		dev->evport_offset = SONYPI_TYPE3_OFFSET; | 
 | 3307 | 		dev->event_types = type3_events; | 
| ISHIKAWA Mutsumi | d5b0269 | 2009-03-26 21:58:20 +0900 | [diff] [blame] | 3308 | 		goto out; | 
 | 3309 | 	} | 
 | 3310 |  | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3311 | 	/* default */ | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 3312 | 	dev->model = SONYPI_DEVICE_TYPE2; | 
 | 3313 | 	dev->evport_offset = SONYPI_TYPE2_OFFSET; | 
 | 3314 | 	dev->event_types = type2_events; | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3315 |  | 
 | 3316 | out: | 
 | 3317 | 	if (pcidev) | 
 | 3318 | 		pci_dev_put(pcidev); | 
 | 3319 |  | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3320 | 	pr_info("detected Type%d model\n", | 
 | 3321 | 		dev->model == SONYPI_DEVICE_TYPE1 ? 1 : | 
 | 3322 | 		dev->model == SONYPI_DEVICE_TYPE2 ? 2 : 3); | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 3323 | } | 
 | 3324 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3325 | /* camera tests and poweron/poweroff */ | 
 | 3326 | #define SONYPI_CAMERA_PICTURE		5 | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3327 | #define SONYPI_CAMERA_CONTROL		0x10 | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3328 |  | 
 | 3329 | #define SONYPI_CAMERA_BRIGHTNESS		0 | 
 | 3330 | #define SONYPI_CAMERA_CONTRAST			1 | 
 | 3331 | #define SONYPI_CAMERA_HUE			2 | 
 | 3332 | #define SONYPI_CAMERA_COLOR			3 | 
 | 3333 | #define SONYPI_CAMERA_SHARPNESS			4 | 
 | 3334 |  | 
 | 3335 | #define SONYPI_CAMERA_EXPOSURE_MASK		0xC | 
 | 3336 | #define SONYPI_CAMERA_WHITE_BALANCE_MASK	0x3 | 
 | 3337 | #define SONYPI_CAMERA_PICTURE_MODE_MASK		0x30 | 
 | 3338 | #define SONYPI_CAMERA_MUTE_MASK			0x40 | 
 | 3339 |  | 
 | 3340 | /* the rest don't need a loop until not 0xff */ | 
 | 3341 | #define SONYPI_CAMERA_AGC			6 | 
 | 3342 | #define SONYPI_CAMERA_AGC_MASK			0x30 | 
 | 3343 | #define SONYPI_CAMERA_SHUTTER_MASK 		0x7 | 
 | 3344 |  | 
 | 3345 | #define SONYPI_CAMERA_SHUTDOWN_REQUEST		7 | 
 | 3346 | #define SONYPI_CAMERA_CONTROL			0x10 | 
 | 3347 |  | 
 | 3348 | #define SONYPI_CAMERA_STATUS 			7 | 
 | 3349 | #define SONYPI_CAMERA_STATUS_READY 		0x2 | 
 | 3350 | #define SONYPI_CAMERA_STATUS_POSITION		0x4 | 
 | 3351 |  | 
 | 3352 | #define SONYPI_DIRECTION_BACKWARDS 		0x4 | 
 | 3353 |  | 
 | 3354 | #define SONYPI_CAMERA_REVISION 			8 | 
 | 3355 | #define SONYPI_CAMERA_ROMVERSION 		9 | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3356 |  | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3357 | static int __sony_pic_camera_ready(void) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3358 | { | 
 | 3359 | 	u8 v; | 
 | 3360 |  | 
 | 3361 | 	v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS); | 
 | 3362 | 	return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY)); | 
 | 3363 | } | 
 | 3364 |  | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3365 | static int __sony_pic_camera_off(void) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3366 | { | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3367 | 	if (!camera) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3368 | 		pr_warn("camera control not enabled\n"); | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3369 | 		return -ENODEV; | 
 | 3370 | 	} | 
 | 3371 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3372 | 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, | 
 | 3373 | 				SONYPI_CAMERA_MUTE_MASK), | 
 | 3374 | 			ITERATIONS_SHORT); | 
 | 3375 |  | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3376 | 	if (spic_dev.camera_power) { | 
 | 3377 | 		sony_pic_call2(0x91, 0); | 
 | 3378 | 		spic_dev.camera_power = 0; | 
 | 3379 | 	} | 
 | 3380 | 	return 0; | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3381 | } | 
 | 3382 |  | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3383 | static int __sony_pic_camera_on(void) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3384 | { | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3385 | 	int i, j, x; | 
 | 3386 |  | 
 | 3387 | 	if (!camera) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3388 | 		pr_warn("camera control not enabled\n"); | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3389 | 		return -ENODEV; | 
 | 3390 | 	} | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3391 |  | 
 | 3392 | 	if (spic_dev.camera_power) | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3393 | 		return 0; | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3394 |  | 
 | 3395 | 	for (j = 5; j > 0; j--) { | 
 | 3396 |  | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3397 | 		for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3398 | 			msleep(10); | 
 | 3399 | 		sony_pic_call1(0x93); | 
 | 3400 |  | 
 | 3401 | 		for (i = 400; i > 0; i--) { | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3402 | 			if (__sony_pic_camera_ready()) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3403 | 				break; | 
 | 3404 | 			msleep(10); | 
 | 3405 | 		} | 
 | 3406 | 		if (i) | 
 | 3407 | 			break; | 
 | 3408 | 	} | 
 | 3409 |  | 
 | 3410 | 	if (j == 0) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3411 | 		pr_warn("failed to power on camera\n"); | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3412 | 		return -ENODEV; | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3413 | 	} | 
 | 3414 |  | 
 | 3415 | 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL, | 
 | 3416 | 				0x5a), | 
 | 3417 | 			ITERATIONS_SHORT); | 
 | 3418 |  | 
 | 3419 | 	spic_dev.camera_power = 1; | 
| malattia@linux.it | 5f3d289 | 2007-04-28 23:18:45 +0900 | [diff] [blame] | 3420 | 	return 0; | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3421 | } | 
 | 3422 |  | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3423 | /* External camera command (exported to the motion eye v4l driver) */ | 
 | 3424 | int sony_pic_camera_command(int command, u8 value) | 
 | 3425 | { | 
 | 3426 | 	if (!camera) | 
 | 3427 | 		return -EIO; | 
 | 3428 |  | 
 | 3429 | 	mutex_lock(&spic_dev.lock); | 
 | 3430 |  | 
 | 3431 | 	switch (command) { | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3432 | 	case SONY_PIC_COMMAND_SETCAMERA: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3433 | 		if (value) | 
 | 3434 | 			__sony_pic_camera_on(); | 
 | 3435 | 		else | 
 | 3436 | 			__sony_pic_camera_off(); | 
 | 3437 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3438 | 	case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3439 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value), | 
 | 3440 | 				ITERATIONS_SHORT); | 
 | 3441 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3442 | 	case SONY_PIC_COMMAND_SETCAMERACONTRAST: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3443 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value), | 
 | 3444 | 				ITERATIONS_SHORT); | 
 | 3445 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3446 | 	case SONY_PIC_COMMAND_SETCAMERAHUE: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3447 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value), | 
 | 3448 | 				ITERATIONS_SHORT); | 
 | 3449 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3450 | 	case SONY_PIC_COMMAND_SETCAMERACOLOR: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3451 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value), | 
 | 3452 | 				ITERATIONS_SHORT); | 
 | 3453 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3454 | 	case SONY_PIC_COMMAND_SETCAMERASHARPNESS: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3455 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value), | 
 | 3456 | 				ITERATIONS_SHORT); | 
 | 3457 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3458 | 	case SONY_PIC_COMMAND_SETCAMERAPICTURE: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3459 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value), | 
 | 3460 | 				ITERATIONS_SHORT); | 
 | 3461 | 		break; | 
| malattia@linux.it | 1ce82c1 | 2007-04-28 23:34:36 +0900 | [diff] [blame] | 3462 | 	case SONY_PIC_COMMAND_SETCAMERAAGC: | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3463 | 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value), | 
 | 3464 | 				ITERATIONS_SHORT); | 
 | 3465 | 		break; | 
 | 3466 | 	default: | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3467 | 		pr_err("sony_pic_camera_command invalid: %d\n", command); | 
| malattia@linux.it | e364632 | 2007-04-28 23:34:22 +0900 | [diff] [blame] | 3468 | 		break; | 
 | 3469 | 	} | 
 | 3470 | 	mutex_unlock(&spic_dev.lock); | 
 | 3471 | 	return 0; | 
 | 3472 | } | 
 | 3473 | EXPORT_SYMBOL(sony_pic_camera_command); | 
 | 3474 |  | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3475 | /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */ | 
| Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 3476 | static void __sony_pic_set_wwanpower(u8 state) | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3477 | { | 
 | 3478 | 	state = !!state; | 
| Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 3479 | 	if (spic_dev.wwan_power == state) | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3480 | 		return; | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3481 | 	sony_pic_call2(0xB0, state); | 
| Sergey Yanovich | 3ad1b76 | 2009-03-26 21:58:21 +0900 | [diff] [blame] | 3482 | 	sony_pic_call1(0x82); | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3483 | 	spic_dev.wwan_power = state; | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3484 | } | 
 | 3485 |  | 
 | 3486 | static ssize_t sony_pic_wwanpower_store(struct device *dev, | 
 | 3487 | 		struct device_attribute *attr, | 
 | 3488 | 		const char *buffer, size_t count) | 
 | 3489 | { | 
 | 3490 | 	unsigned long value; | 
 | 3491 | 	if (count > 31) | 
 | 3492 | 		return -EINVAL; | 
 | 3493 |  | 
| Mattia Dongili | 9e12337 | 2012-05-19 22:35:47 +0900 | [diff] [blame] | 3494 | 	if (kstrtoul(buffer, 10, &value)) | 
 | 3495 | 		return -EINVAL; | 
 | 3496 |  | 
| Mattia Dongili | c9f1e6f | 2009-03-26 21:58:23 +0900 | [diff] [blame] | 3497 | 	mutex_lock(&spic_dev.lock); | 
 | 3498 | 	__sony_pic_set_wwanpower(value); | 
 | 3499 | 	mutex_unlock(&spic_dev.lock); | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3500 |  | 
 | 3501 | 	return count; | 
 | 3502 | } | 
 | 3503 |  | 
 | 3504 | static ssize_t sony_pic_wwanpower_show(struct device *dev, | 
 | 3505 | 		struct device_attribute *attr, char *buffer) | 
 | 3506 | { | 
 | 3507 | 	ssize_t count; | 
 | 3508 | 	mutex_lock(&spic_dev.lock); | 
 | 3509 | 	count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power); | 
 | 3510 | 	mutex_unlock(&spic_dev.lock); | 
 | 3511 | 	return count; | 
 | 3512 | } | 
 | 3513 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3514 | /* bluetooth subsystem power state */ | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3515 | static void __sony_pic_set_bluetoothpower(u8 state) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3516 | { | 
 | 3517 | 	state = !!state; | 
 | 3518 | 	if (spic_dev.bluetooth_power == state) | 
 | 3519 | 		return; | 
 | 3520 | 	sony_pic_call2(0x96, state); | 
 | 3521 | 	sony_pic_call1(0x82); | 
 | 3522 | 	spic_dev.bluetooth_power = state; | 
 | 3523 | } | 
 | 3524 |  | 
 | 3525 | static ssize_t sony_pic_bluetoothpower_store(struct device *dev, | 
 | 3526 | 		struct device_attribute *attr, | 
 | 3527 | 		const char *buffer, size_t count) | 
 | 3528 | { | 
 | 3529 | 	unsigned long value; | 
 | 3530 | 	if (count > 31) | 
 | 3531 | 		return -EINVAL; | 
 | 3532 |  | 
| Mattia Dongili | 9e12337 | 2012-05-19 22:35:47 +0900 | [diff] [blame] | 3533 | 	if (kstrtoul(buffer, 10, &value)) | 
 | 3534 | 		return -EINVAL; | 
 | 3535 |  | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3536 | 	mutex_lock(&spic_dev.lock); | 
 | 3537 | 	__sony_pic_set_bluetoothpower(value); | 
 | 3538 | 	mutex_unlock(&spic_dev.lock); | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3539 |  | 
 | 3540 | 	return count; | 
 | 3541 | } | 
 | 3542 |  | 
 | 3543 | static ssize_t sony_pic_bluetoothpower_show(struct device *dev, | 
 | 3544 | 		struct device_attribute *attr, char *buffer) | 
 | 3545 | { | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3546 | 	ssize_t count = 0; | 
 | 3547 | 	mutex_lock(&spic_dev.lock); | 
 | 3548 | 	count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power); | 
 | 3549 | 	mutex_unlock(&spic_dev.lock); | 
 | 3550 | 	return count; | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3551 | } | 
 | 3552 |  | 
 | 3553 | /* fan speed */ | 
 | 3554 | /* FAN0 information (reverse engineered from ACPI tables) */ | 
 | 3555 | #define SONY_PIC_FAN0_STATUS	0x93 | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3556 | static int sony_pic_set_fanspeed(unsigned long value) | 
 | 3557 | { | 
 | 3558 | 	return ec_write(SONY_PIC_FAN0_STATUS, value); | 
 | 3559 | } | 
 | 3560 |  | 
 | 3561 | static int sony_pic_get_fanspeed(u8 *value) | 
 | 3562 | { | 
 | 3563 | 	return ec_read(SONY_PIC_FAN0_STATUS, value); | 
 | 3564 | } | 
 | 3565 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3566 | static ssize_t sony_pic_fanspeed_store(struct device *dev, | 
 | 3567 | 		struct device_attribute *attr, | 
 | 3568 | 		const char *buffer, size_t count) | 
 | 3569 | { | 
 | 3570 | 	unsigned long value; | 
 | 3571 | 	if (count > 31) | 
 | 3572 | 		return -EINVAL; | 
 | 3573 |  | 
| Mattia Dongili | 9e12337 | 2012-05-19 22:35:47 +0900 | [diff] [blame] | 3574 | 	if (kstrtoul(buffer, 10, &value)) | 
 | 3575 | 		return -EINVAL; | 
 | 3576 |  | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3577 | 	if (sony_pic_set_fanspeed(value)) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3578 | 		return -EIO; | 
 | 3579 |  | 
 | 3580 | 	return count; | 
 | 3581 | } | 
 | 3582 |  | 
 | 3583 | static ssize_t sony_pic_fanspeed_show(struct device *dev, | 
 | 3584 | 		struct device_attribute *attr, char *buffer) | 
 | 3585 | { | 
 | 3586 | 	u8 value = 0; | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3587 | 	if (sony_pic_get_fanspeed(&value)) | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3588 | 		return -EIO; | 
 | 3589 |  | 
 | 3590 | 	return snprintf(buffer, PAGE_SIZE, "%d\n", value); | 
 | 3591 | } | 
 | 3592 |  | 
 | 3593 | #define SPIC_ATTR(_name, _mode)					\ | 
 | 3594 | struct device_attribute spic_attr_##_name = __ATTR(_name,	\ | 
 | 3595 | 		_mode, sony_pic_## _name ##_show,		\ | 
 | 3596 | 		sony_pic_## _name ##_store) | 
 | 3597 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3598 | static SPIC_ATTR(bluetoothpower, 0644); | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3599 | static SPIC_ATTR(wwanpower, 0644); | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3600 | static SPIC_ATTR(fanspeed, 0644); | 
 | 3601 |  | 
 | 3602 | static struct attribute *spic_attributes[] = { | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3603 | 	&spic_attr_bluetoothpower.attr, | 
| malattia@linux.it | 9476cdf | 2007-04-28 23:21:42 +0900 | [diff] [blame] | 3604 | 	&spic_attr_wwanpower.attr, | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 3605 | 	&spic_attr_fanspeed.attr, | 
 | 3606 | 	NULL | 
 | 3607 | }; | 
 | 3608 |  | 
 | 3609 | static struct attribute_group spic_attribute_group = { | 
 | 3610 | 	.attrs = spic_attributes | 
 | 3611 | }; | 
 | 3612 |  | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3613 | /******** SONYPI compatibility **********/ | 
| Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 3614 | #ifdef CONFIG_SONYPI_COMPAT | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3615 |  | 
 | 3616 | /* battery / brightness / temperature  addresses */ | 
 | 3617 | #define SONYPI_BAT_FLAGS	0x81 | 
 | 3618 | #define SONYPI_LCD_LIGHT	0x96 | 
 | 3619 | #define SONYPI_BAT1_PCTRM	0xa0 | 
 | 3620 | #define SONYPI_BAT1_LEFT	0xa2 | 
 | 3621 | #define SONYPI_BAT1_MAXRT	0xa4 | 
 | 3622 | #define SONYPI_BAT2_PCTRM	0xa8 | 
 | 3623 | #define SONYPI_BAT2_LEFT	0xaa | 
 | 3624 | #define SONYPI_BAT2_MAXRT	0xac | 
 | 3625 | #define SONYPI_BAT1_MAXTK	0xb0 | 
 | 3626 | #define SONYPI_BAT1_FULL	0xb2 | 
 | 3627 | #define SONYPI_BAT2_MAXTK	0xb8 | 
 | 3628 | #define SONYPI_BAT2_FULL	0xba | 
 | 3629 | #define SONYPI_TEMP_STATUS	0xC1 | 
 | 3630 |  | 
 | 3631 | struct sonypi_compat_s { | 
 | 3632 | 	struct fasync_struct	*fifo_async; | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3633 | 	struct kfifo		fifo; | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3634 | 	spinlock_t		fifo_lock; | 
 | 3635 | 	wait_queue_head_t	fifo_proc_list; | 
 | 3636 | 	atomic_t		open_count; | 
 | 3637 | }; | 
 | 3638 | static struct sonypi_compat_s sonypi_compat = { | 
 | 3639 | 	.open_count = ATOMIC_INIT(0), | 
 | 3640 | }; | 
 | 3641 |  | 
 | 3642 | static int sonypi_misc_fasync(int fd, struct file *filp, int on) | 
 | 3643 | { | 
| Jonathan Corbet | 60aa492 | 2009-02-01 14:52:56 -0700 | [diff] [blame] | 3644 | 	return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3645 | } | 
 | 3646 |  | 
 | 3647 | static int sonypi_misc_release(struct inode *inode, struct file *file) | 
 | 3648 | { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3649 | 	atomic_dec(&sonypi_compat.open_count); | 
 | 3650 | 	return 0; | 
 | 3651 | } | 
 | 3652 |  | 
 | 3653 | static int sonypi_misc_open(struct inode *inode, struct file *file) | 
 | 3654 | { | 
 | 3655 | 	/* Flush input queue on first open */ | 
| Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 3656 | 	unsigned long flags; | 
 | 3657 |  | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3658 | 	spin_lock_irqsave(&sonypi_compat.fifo_lock, flags); | 
| Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 3659 |  | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3660 | 	if (atomic_inc_return(&sonypi_compat.open_count) == 1) | 
| Stefani Seibold | e64c026 | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 3661 | 		kfifo_reset(&sonypi_compat.fifo); | 
| Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 3662 |  | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3663 | 	spin_unlock_irqrestore(&sonypi_compat.fifo_lock, flags); | 
| Alessio Igor Bogani | 4ef4cbb | 2009-03-26 21:58:25 +0900 | [diff] [blame] | 3664 |  | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3665 | 	return 0; | 
 | 3666 | } | 
 | 3667 |  | 
 | 3668 | static ssize_t sonypi_misc_read(struct file *file, char __user *buf, | 
 | 3669 | 				size_t count, loff_t *pos) | 
 | 3670 | { | 
 | 3671 | 	ssize_t ret; | 
 | 3672 | 	unsigned char c; | 
 | 3673 |  | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3674 | 	if ((kfifo_len(&sonypi_compat.fifo) == 0) && | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3675 | 	    (file->f_flags & O_NONBLOCK)) | 
 | 3676 | 		return -EAGAIN; | 
 | 3677 |  | 
 | 3678 | 	ret = wait_event_interruptible(sonypi_compat.fifo_proc_list, | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3679 | 				       kfifo_len(&sonypi_compat.fifo) != 0); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3680 | 	if (ret) | 
 | 3681 | 		return ret; | 
 | 3682 |  | 
 | 3683 | 	while (ret < count && | 
| Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 3684 | 	       (kfifo_out_locked(&sonypi_compat.fifo, &c, sizeof(c), | 
| Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 3685 | 			  &sonypi_compat.fifo_lock) == sizeof(c))) { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3686 | 		if (put_user(c, buf++)) | 
 | 3687 | 			return -EFAULT; | 
 | 3688 | 		ret++; | 
 | 3689 | 	} | 
 | 3690 |  | 
 | 3691 | 	if (ret > 0) { | 
| Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 3692 | 		struct inode *inode = file_inode(file); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3693 | 		inode->i_atime = current_fs_time(inode->i_sb); | 
 | 3694 | 	} | 
 | 3695 |  | 
 | 3696 | 	return ret; | 
 | 3697 | } | 
 | 3698 |  | 
 | 3699 | static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait) | 
 | 3700 | { | 
 | 3701 | 	poll_wait(file, &sonypi_compat.fifo_proc_list, wait); | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3702 | 	if (kfifo_len(&sonypi_compat.fifo)) | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3703 | 		return POLLIN | POLLRDNORM; | 
 | 3704 | 	return 0; | 
 | 3705 | } | 
 | 3706 |  | 
 | 3707 | static int ec_read16(u8 addr, u16 *value) | 
 | 3708 | { | 
 | 3709 | 	u8 val_lb, val_hb; | 
 | 3710 | 	if (ec_read(addr, &val_lb)) | 
 | 3711 | 		return -1; | 
 | 3712 | 	if (ec_read(addr + 1, &val_hb)) | 
 | 3713 | 		return -1; | 
 | 3714 | 	*value = val_lb | (val_hb << 8); | 
 | 3715 | 	return 0; | 
 | 3716 | } | 
 | 3717 |  | 
| Alan Cox | 2b24ef0 | 2009-03-26 21:58:19 +0900 | [diff] [blame] | 3718 | static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd, | 
 | 3719 | 							unsigned long arg) | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3720 | { | 
 | 3721 | 	int ret = 0; | 
 | 3722 | 	void __user *argp = (void __user *)arg; | 
 | 3723 | 	u8 val8; | 
 | 3724 | 	u16 val16; | 
 | 3725 | 	int value; | 
 | 3726 |  | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3727 | 	mutex_lock(&spic_dev.lock); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3728 | 	switch (cmd) { | 
 | 3729 | 	case SONYPI_IOCGBRT: | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 3730 | 		if (sony_bl_props.dev == NULL) { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3731 | 			ret = -EIO; | 
 | 3732 | 			break; | 
 | 3733 | 		} | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 3734 | 		if (sony_nc_int_call(sony_nc_acpi_handle, "GBRT", NULL, | 
 | 3735 | 					&value)) { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3736 | 			ret = -EIO; | 
 | 3737 | 			break; | 
 | 3738 | 		} | 
 | 3739 | 		val8 = ((value & 0xff) - 1) << 5; | 
 | 3740 | 		if (copy_to_user(argp, &val8, sizeof(val8))) | 
 | 3741 | 				ret = -EFAULT; | 
 | 3742 | 		break; | 
 | 3743 | 	case SONYPI_IOCSBRT: | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 3744 | 		if (sony_bl_props.dev == NULL) { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3745 | 			ret = -EIO; | 
 | 3746 | 			break; | 
 | 3747 | 		} | 
 | 3748 | 		if (copy_from_user(&val8, argp, sizeof(val8))) { | 
 | 3749 | 			ret = -EFAULT; | 
 | 3750 | 			break; | 
 | 3751 | 		} | 
| Mattia Dongili | ebcef1b | 2012-05-19 22:35:46 +0900 | [diff] [blame] | 3752 | 		value = (val8 >> 5) + 1; | 
 | 3753 | 		if (sony_nc_int_call(sony_nc_acpi_handle, "SBRT", &value, | 
 | 3754 | 					NULL)) { | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3755 | 			ret = -EIO; | 
 | 3756 | 			break; | 
 | 3757 | 		} | 
 | 3758 | 		/* sync the backlight device status */ | 
| Mattia Dongili | 62d2f23 | 2011-05-09 10:20:29 -0400 | [diff] [blame] | 3759 | 		sony_bl_props.dev->props.brightness = | 
 | 3760 | 		    sony_backlight_get_brightness(sony_bl_props.dev); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3761 | 		break; | 
 | 3762 | 	case SONYPI_IOCGBAT1CAP: | 
 | 3763 | 		if (ec_read16(SONYPI_BAT1_FULL, &val16)) { | 
 | 3764 | 			ret = -EIO; | 
 | 3765 | 			break; | 
 | 3766 | 		} | 
 | 3767 | 		if (copy_to_user(argp, &val16, sizeof(val16))) | 
 | 3768 | 			ret = -EFAULT; | 
 | 3769 | 		break; | 
 | 3770 | 	case SONYPI_IOCGBAT1REM: | 
 | 3771 | 		if (ec_read16(SONYPI_BAT1_LEFT, &val16)) { | 
 | 3772 | 			ret = -EIO; | 
 | 3773 | 			break; | 
 | 3774 | 		} | 
 | 3775 | 		if (copy_to_user(argp, &val16, sizeof(val16))) | 
 | 3776 | 			ret = -EFAULT; | 
 | 3777 | 		break; | 
 | 3778 | 	case SONYPI_IOCGBAT2CAP: | 
 | 3779 | 		if (ec_read16(SONYPI_BAT2_FULL, &val16)) { | 
 | 3780 | 			ret = -EIO; | 
 | 3781 | 			break; | 
 | 3782 | 		} | 
 | 3783 | 		if (copy_to_user(argp, &val16, sizeof(val16))) | 
 | 3784 | 			ret = -EFAULT; | 
 | 3785 | 		break; | 
 | 3786 | 	case SONYPI_IOCGBAT2REM: | 
 | 3787 | 		if (ec_read16(SONYPI_BAT2_LEFT, &val16)) { | 
 | 3788 | 			ret = -EIO; | 
 | 3789 | 			break; | 
 | 3790 | 		} | 
 | 3791 | 		if (copy_to_user(argp, &val16, sizeof(val16))) | 
 | 3792 | 			ret = -EFAULT; | 
 | 3793 | 		break; | 
 | 3794 | 	case SONYPI_IOCGBATFLAGS: | 
 | 3795 | 		if (ec_read(SONYPI_BAT_FLAGS, &val8)) { | 
 | 3796 | 			ret = -EIO; | 
 | 3797 | 			break; | 
 | 3798 | 		} | 
 | 3799 | 		val8 &= 0x07; | 
 | 3800 | 		if (copy_to_user(argp, &val8, sizeof(val8))) | 
 | 3801 | 			ret = -EFAULT; | 
 | 3802 | 		break; | 
 | 3803 | 	case SONYPI_IOCGBLUE: | 
 | 3804 | 		val8 = spic_dev.bluetooth_power; | 
 | 3805 | 		if (copy_to_user(argp, &val8, sizeof(val8))) | 
 | 3806 | 			ret = -EFAULT; | 
 | 3807 | 		break; | 
 | 3808 | 	case SONYPI_IOCSBLUE: | 
 | 3809 | 		if (copy_from_user(&val8, argp, sizeof(val8))) { | 
 | 3810 | 			ret = -EFAULT; | 
 | 3811 | 			break; | 
 | 3812 | 		} | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3813 | 		__sony_pic_set_bluetoothpower(val8); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3814 | 		break; | 
 | 3815 | 	/* FAN Controls */ | 
 | 3816 | 	case SONYPI_IOCGFAN: | 
 | 3817 | 		if (sony_pic_get_fanspeed(&val8)) { | 
 | 3818 | 			ret = -EIO; | 
 | 3819 | 			break; | 
 | 3820 | 		} | 
 | 3821 | 		if (copy_to_user(argp, &val8, sizeof(val8))) | 
 | 3822 | 			ret = -EFAULT; | 
 | 3823 | 		break; | 
 | 3824 | 	case SONYPI_IOCSFAN: | 
 | 3825 | 		if (copy_from_user(&val8, argp, sizeof(val8))) { | 
 | 3826 | 			ret = -EFAULT; | 
 | 3827 | 			break; | 
 | 3828 | 		} | 
 | 3829 | 		if (sony_pic_set_fanspeed(val8)) | 
 | 3830 | 			ret = -EIO; | 
 | 3831 | 		break; | 
 | 3832 | 	/* GET Temperature (useful under APM) */ | 
 | 3833 | 	case SONYPI_IOCGTEMP: | 
 | 3834 | 		if (ec_read(SONYPI_TEMP_STATUS, &val8)) { | 
 | 3835 | 			ret = -EIO; | 
 | 3836 | 			break; | 
 | 3837 | 		} | 
 | 3838 | 		if (copy_to_user(argp, &val8, sizeof(val8))) | 
 | 3839 | 			ret = -EFAULT; | 
 | 3840 | 		break; | 
 | 3841 | 	default: | 
 | 3842 | 		ret = -EINVAL; | 
 | 3843 | 	} | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 3844 | 	mutex_unlock(&spic_dev.lock); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3845 | 	return ret; | 
 | 3846 | } | 
 | 3847 |  | 
 | 3848 | static const struct file_operations sonypi_misc_fops = { | 
 | 3849 | 	.owner		= THIS_MODULE, | 
 | 3850 | 	.read		= sonypi_misc_read, | 
 | 3851 | 	.poll		= sonypi_misc_poll, | 
 | 3852 | 	.open		= sonypi_misc_open, | 
 | 3853 | 	.release	= sonypi_misc_release, | 
 | 3854 | 	.fasync		= sonypi_misc_fasync, | 
| Alan Cox | 2b24ef0 | 2009-03-26 21:58:19 +0900 | [diff] [blame] | 3855 | 	.unlocked_ioctl	= sonypi_misc_ioctl, | 
| Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 3856 | 	.llseek		= noop_llseek, | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3857 | }; | 
 | 3858 |  | 
 | 3859 | static struct miscdevice sonypi_misc_device = { | 
 | 3860 | 	.minor		= MISC_DYNAMIC_MINOR, | 
 | 3861 | 	.name		= "sonypi", | 
 | 3862 | 	.fops		= &sonypi_misc_fops, | 
 | 3863 | }; | 
 | 3864 |  | 
 | 3865 | static void sonypi_compat_report_event(u8 event) | 
 | 3866 | { | 
| Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 3867 | 	kfifo_in_locked(&sonypi_compat.fifo, (unsigned char *)&event, | 
| Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 3868 | 			sizeof(event), &sonypi_compat.fifo_lock); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3869 | 	kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN); | 
 | 3870 | 	wake_up_interruptible(&sonypi_compat.fifo_proc_list); | 
 | 3871 | } | 
 | 3872 |  | 
 | 3873 | static int sonypi_compat_init(void) | 
 | 3874 | { | 
 | 3875 | 	int error; | 
 | 3876 |  | 
 | 3877 | 	spin_lock_init(&sonypi_compat.fifo_lock); | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3878 | 	error = | 
| Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 3879 | 	 kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3880 | 	if (error) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3881 | 		pr_err("kfifo_alloc failed\n"); | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3882 | 		return error; | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3883 | 	} | 
 | 3884 |  | 
 | 3885 | 	init_waitqueue_head(&sonypi_compat.fifo_proc_list); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3886 |  | 
 | 3887 | 	if (minor != -1) | 
 | 3888 | 		sonypi_misc_device.minor = minor; | 
 | 3889 | 	error = misc_register(&sonypi_misc_device); | 
 | 3890 | 	if (error) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3891 | 		pr_err("misc_register failed\n"); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3892 | 		goto err_free_kfifo; | 
 | 3893 | 	} | 
 | 3894 | 	if (minor == -1) | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3895 | 		pr_info("device allocated minor is %d\n", | 
 | 3896 | 			sonypi_misc_device.minor); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3897 |  | 
 | 3898 | 	return 0; | 
 | 3899 |  | 
 | 3900 | err_free_kfifo: | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3901 | 	kfifo_free(&sonypi_compat.fifo); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3902 | 	return error; | 
 | 3903 | } | 
 | 3904 |  | 
 | 3905 | static void sonypi_compat_exit(void) | 
 | 3906 | { | 
 | 3907 | 	misc_deregister(&sonypi_misc_device); | 
| Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 3908 | 	kfifo_free(&sonypi_compat.fifo); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3909 | } | 
 | 3910 | #else | 
 | 3911 | static int sonypi_compat_init(void) { return 0; } | 
 | 3912 | static void sonypi_compat_exit(void) { } | 
 | 3913 | static void sonypi_compat_report_event(u8 event) { } | 
| Mattia Dongili | a64e62a | 2007-05-01 11:19:53 +0900 | [diff] [blame] | 3914 | #endif /* CONFIG_SONYPI_COMPAT */ | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 3915 |  | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 3916 | /* | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3917 |  * ACPI callbacks | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 3918 |  */ | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3919 | static acpi_status | 
 | 3920 | sony_pic_read_possible_resource(struct acpi_resource *resource, void *context) | 
 | 3921 | { | 
 | 3922 | 	u32 i; | 
 | 3923 | 	struct sony_pic_dev *dev = (struct sony_pic_dev *)context; | 
 | 3924 |  | 
 | 3925 | 	switch (resource->type) { | 
 | 3926 | 	case ACPI_RESOURCE_TYPE_START_DEPENDENT: | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3927 | 		{ | 
 | 3928 | 			/* start IO enumeration */ | 
 | 3929 | 			struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL); | 
 | 3930 | 			if (!ioport) | 
 | 3931 | 				return AE_ERROR; | 
 | 3932 |  | 
 | 3933 | 			list_add(&ioport->list, &dev->ioports); | 
 | 3934 | 			return AE_OK; | 
 | 3935 | 		} | 
 | 3936 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3937 | 	case ACPI_RESOURCE_TYPE_END_DEPENDENT: | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3938 | 		/* end IO enumeration */ | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3939 | 		return AE_OK; | 
 | 3940 |  | 
 | 3941 | 	case ACPI_RESOURCE_TYPE_IRQ: | 
 | 3942 | 		{ | 
 | 3943 | 			struct acpi_resource_irq *p = &resource->data.irq; | 
 | 3944 | 			struct sony_pic_irq *interrupt = NULL; | 
 | 3945 | 			if (!p || !p->interrupt_count) { | 
 | 3946 | 				/* | 
 | 3947 | 				 * IRQ descriptors may have no IRQ# bits set, | 
 | 3948 | 				 * particularly those those w/ _STA disabled | 
 | 3949 | 				 */ | 
 | 3950 | 				dprintk("Blank IRQ resource\n"); | 
 | 3951 | 				return AE_OK; | 
 | 3952 | 			} | 
 | 3953 | 			for (i = 0; i < p->interrupt_count; i++) { | 
 | 3954 | 				if (!p->interrupts[i]) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3955 | 					pr_warn("Invalid IRQ %d\n", | 
 | 3956 | 						p->interrupts[i]); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3957 | 					continue; | 
 | 3958 | 				} | 
 | 3959 | 				interrupt = kzalloc(sizeof(*interrupt), | 
 | 3960 | 						GFP_KERNEL); | 
 | 3961 | 				if (!interrupt) | 
 | 3962 | 					return AE_ERROR; | 
 | 3963 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3964 | 				list_add(&interrupt->list, &dev->interrupts); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3965 | 				interrupt->irq.triggering = p->triggering; | 
 | 3966 | 				interrupt->irq.polarity = p->polarity; | 
 | 3967 | 				interrupt->irq.sharable = p->sharable; | 
 | 3968 | 				interrupt->irq.interrupt_count = 1; | 
 | 3969 | 				interrupt->irq.interrupts[0] = p->interrupts[i]; | 
 | 3970 | 			} | 
 | 3971 | 			return AE_OK; | 
 | 3972 | 		} | 
 | 3973 | 	case ACPI_RESOURCE_TYPE_IO: | 
 | 3974 | 		{ | 
 | 3975 | 			struct acpi_resource_io *io = &resource->data.io; | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3976 | 			struct sony_pic_ioport *ioport = | 
 | 3977 | 				list_first_entry(&dev->ioports, struct sony_pic_ioport, list); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3978 | 			if (!io) { | 
 | 3979 | 				dprintk("Blank IO resource\n"); | 
 | 3980 | 				return AE_OK; | 
 | 3981 | 			} | 
 | 3982 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3983 | 			if (!ioport->io1.minimum) { | 
 | 3984 | 				memcpy(&ioport->io1, io, sizeof(*io)); | 
 | 3985 | 				dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum, | 
 | 3986 | 						ioport->io1.address_length); | 
 | 3987 | 			} | 
 | 3988 | 			else if (!ioport->io2.minimum) { | 
 | 3989 | 				memcpy(&ioport->io2, io, sizeof(*io)); | 
 | 3990 | 				dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum, | 
 | 3991 | 						ioport->io2.address_length); | 
 | 3992 | 			} | 
 | 3993 | 			else { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 3994 | 				pr_err("Unknown SPIC Type, more than 2 IO Ports\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3995 | 				return AE_ERROR; | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 3996 | 			} | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 3997 | 			return AE_OK; | 
 | 3998 | 		} | 
 | 3999 | 	default: | 
 | 4000 | 		dprintk("Resource %d isn't an IRQ nor an IO port\n", | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4001 | 			resource->type); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4002 |  | 
 | 4003 | 	case ACPI_RESOURCE_TYPE_END_TAG: | 
 | 4004 | 		return AE_OK; | 
 | 4005 | 	} | 
 | 4006 | 	return AE_CTRL_TERMINATE; | 
 | 4007 | } | 
 | 4008 |  | 
 | 4009 | static int sony_pic_possible_resources(struct acpi_device *device) | 
 | 4010 | { | 
 | 4011 | 	int result = 0; | 
 | 4012 | 	acpi_status status = AE_OK; | 
 | 4013 |  | 
 | 4014 | 	if (!device) | 
 | 4015 | 		return -EINVAL; | 
 | 4016 |  | 
 | 4017 | 	/* get device status */ | 
 | 4018 | 	/* see acpi_pci_link_get_current acpi_pci_link_get_possible */ | 
 | 4019 | 	dprintk("Evaluating _STA\n"); | 
 | 4020 | 	result = acpi_bus_get_status(device); | 
 | 4021 | 	if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4022 | 		pr_warn("Unable to read status\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4023 | 		goto end; | 
 | 4024 | 	} | 
 | 4025 |  | 
 | 4026 | 	if (!device->status.enabled) | 
 | 4027 | 		dprintk("Device disabled\n"); | 
 | 4028 | 	else | 
 | 4029 | 		dprintk("Device enabled\n"); | 
 | 4030 |  | 
 | 4031 | 	/* | 
 | 4032 | 	 * Query and parse 'method' | 
 | 4033 | 	 */ | 
 | 4034 | 	dprintk("Evaluating %s\n", METHOD_NAME__PRS); | 
 | 4035 | 	status = acpi_walk_resources(device->handle, METHOD_NAME__PRS, | 
 | 4036 | 			sony_pic_read_possible_resource, &spic_dev); | 
 | 4037 | 	if (ACPI_FAILURE(status)) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4038 | 		pr_warn("Failure evaluating %s\n", METHOD_NAME__PRS); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4039 | 		result = -ENODEV; | 
 | 4040 | 	} | 
 | 4041 | end: | 
 | 4042 | 	return result; | 
 | 4043 | } | 
 | 4044 |  | 
 | 4045 | /* | 
 | 4046 |  *  Disable the spic device by calling its _DIS method | 
 | 4047 |  */ | 
 | 4048 | static int sony_pic_disable(struct acpi_device *device) | 
 | 4049 | { | 
| Matthew Garrett | 6158d3a | 2008-10-29 14:01:03 -0700 | [diff] [blame] | 4050 | 	acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL, | 
 | 4051 | 					       NULL); | 
 | 4052 |  | 
 | 4053 | 	if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4054 | 		return -ENXIO; | 
 | 4055 |  | 
 | 4056 | 	dprintk("Device disabled\n"); | 
 | 4057 | 	return 0; | 
 | 4058 | } | 
 | 4059 |  | 
 | 4060 |  | 
 | 4061 | /* | 
 | 4062 |  *  Based on drivers/acpi/pci_link.c:acpi_pci_link_set | 
 | 4063 |  * | 
 | 4064 |  *  Call _SRS to set current resources | 
 | 4065 |  */ | 
 | 4066 | static int sony_pic_enable(struct acpi_device *device, | 
 | 4067 | 		struct sony_pic_ioport *ioport, struct sony_pic_irq *irq) | 
 | 4068 | { | 
 | 4069 | 	acpi_status status; | 
 | 4070 | 	int result = 0; | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4071 | 	/* Type 1 resource layout is: | 
 | 4072 | 	 *    IO | 
 | 4073 | 	 *    IO | 
 | 4074 | 	 *    IRQNoFlags | 
 | 4075 | 	 *    End | 
 | 4076 | 	 * | 
 | 4077 | 	 * Type 2 and 3 resource layout is: | 
 | 4078 | 	 *    IO | 
 | 4079 | 	 *    IRQNoFlags | 
 | 4080 | 	 *    End | 
 | 4081 | 	 */ | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4082 | 	struct { | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4083 | 		struct acpi_resource res1; | 
 | 4084 | 		struct acpi_resource res2; | 
 | 4085 | 		struct acpi_resource res3; | 
 | 4086 | 		struct acpi_resource res4; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4087 | 	} *resource; | 
 | 4088 | 	struct acpi_buffer buffer = { 0, NULL }; | 
 | 4089 |  | 
 | 4090 | 	if (!ioport || !irq) | 
 | 4091 | 		return -EINVAL; | 
 | 4092 |  | 
 | 4093 | 	/* init acpi_buffer */ | 
 | 4094 | 	resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL); | 
 | 4095 | 	if (!resource) | 
 | 4096 | 		return -ENOMEM; | 
 | 4097 |  | 
 | 4098 | 	buffer.length = sizeof(*resource) + 1; | 
 | 4099 | 	buffer.pointer = resource; | 
 | 4100 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4101 | 	/* setup Type 1 resources */ | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4102 | 	if (spic_dev.model == SONYPI_DEVICE_TYPE1) { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4103 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4104 | 		/* setup io resources */ | 
 | 4105 | 		resource->res1.type = ACPI_RESOURCE_TYPE_IO; | 
 | 4106 | 		resource->res1.length = sizeof(struct acpi_resource); | 
 | 4107 | 		memcpy(&resource->res1.data.io, &ioport->io1, | 
 | 4108 | 				sizeof(struct acpi_resource_io)); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4109 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4110 | 		resource->res2.type = ACPI_RESOURCE_TYPE_IO; | 
 | 4111 | 		resource->res2.length = sizeof(struct acpi_resource); | 
 | 4112 | 		memcpy(&resource->res2.data.io, &ioport->io2, | 
 | 4113 | 				sizeof(struct acpi_resource_io)); | 
 | 4114 |  | 
 | 4115 | 		/* setup irq resource */ | 
 | 4116 | 		resource->res3.type = ACPI_RESOURCE_TYPE_IRQ; | 
 | 4117 | 		resource->res3.length = sizeof(struct acpi_resource); | 
 | 4118 | 		memcpy(&resource->res3.data.irq, &irq->irq, | 
 | 4119 | 				sizeof(struct acpi_resource_irq)); | 
 | 4120 | 		/* we requested a shared irq */ | 
 | 4121 | 		resource->res3.data.irq.sharable = ACPI_SHARED; | 
 | 4122 |  | 
 | 4123 | 		resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG; | 
 | 4124 |  | 
 | 4125 | 	} | 
 | 4126 | 	/* setup Type 2/3 resources */ | 
 | 4127 | 	else { | 
 | 4128 | 		/* setup io resource */ | 
 | 4129 | 		resource->res1.type = ACPI_RESOURCE_TYPE_IO; | 
 | 4130 | 		resource->res1.length = sizeof(struct acpi_resource); | 
 | 4131 | 		memcpy(&resource->res1.data.io, &ioport->io1, | 
 | 4132 | 				sizeof(struct acpi_resource_io)); | 
 | 4133 |  | 
 | 4134 | 		/* setup irq resource */ | 
 | 4135 | 		resource->res2.type = ACPI_RESOURCE_TYPE_IRQ; | 
 | 4136 | 		resource->res2.length = sizeof(struct acpi_resource); | 
 | 4137 | 		memcpy(&resource->res2.data.irq, &irq->irq, | 
 | 4138 | 				sizeof(struct acpi_resource_irq)); | 
 | 4139 | 		/* we requested a shared irq */ | 
 | 4140 | 		resource->res2.data.irq.sharable = ACPI_SHARED; | 
 | 4141 |  | 
 | 4142 | 		resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG; | 
 | 4143 | 	} | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4144 |  | 
 | 4145 | 	/* Attempt to set the resource */ | 
 | 4146 | 	dprintk("Evaluating _SRS\n"); | 
 | 4147 | 	status = acpi_set_current_resources(device->handle, &buffer); | 
 | 4148 |  | 
 | 4149 | 	/* check for total failure */ | 
 | 4150 | 	if (ACPI_FAILURE(status)) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4151 | 		pr_err("Error evaluating _SRS\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4152 | 		result = -ENODEV; | 
 | 4153 | 		goto end; | 
 | 4154 | 	} | 
 | 4155 |  | 
 | 4156 | 	/* Necessary device initializations calls (from sonypi) */ | 
 | 4157 | 	sony_pic_call1(0x82); | 
 | 4158 | 	sony_pic_call2(0x81, 0xff); | 
 | 4159 | 	sony_pic_call1(compat ? 0x92 : 0x82); | 
 | 4160 |  | 
 | 4161 | end: | 
 | 4162 | 	kfree(resource); | 
 | 4163 | 	return result; | 
 | 4164 | } | 
 | 4165 |  | 
 | 4166 | /***************** | 
 | 4167 |  * | 
 | 4168 |  * ISR: some event is available | 
 | 4169 |  * | 
 | 4170 |  *****************/ | 
 | 4171 | static irqreturn_t sony_pic_irq(int irq, void *dev_id) | 
 | 4172 | { | 
 | 4173 | 	int i, j; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4174 | 	u8 ev = 0; | 
 | 4175 | 	u8 data_mask = 0; | 
 | 4176 | 	u8 device_event = 0; | 
 | 4177 |  | 
 | 4178 | 	struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id; | 
 | 4179 |  | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4180 | 	ev = inb_p(dev->cur_ioport->io1.minimum); | 
 | 4181 | 	if (dev->cur_ioport->io2.minimum) | 
 | 4182 | 		data_mask = inb_p(dev->cur_ioport->io2.minimum); | 
 | 4183 | 	else | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 4184 | 		data_mask = inb_p(dev->cur_ioport->io1.minimum + | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4185 | 				dev->evport_offset); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4186 |  | 
| Mattia Dongili | 22a1778 | 2007-07-16 02:34:39 +0900 | [diff] [blame] | 4187 | 	dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n", | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 4188 | 			ev, data_mask, dev->cur_ioport->io1.minimum, | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4189 | 			dev->evport_offset); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4190 |  | 
 | 4191 | 	if (ev == 0x00 || ev == 0xff) | 
 | 4192 | 		return IRQ_HANDLED; | 
 | 4193 |  | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4194 | 	for (i = 0; dev->event_types[i].mask; i++) { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4195 |  | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4196 | 		if ((data_mask & dev->event_types[i].data) != | 
 | 4197 | 		    dev->event_types[i].data) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4198 | 			continue; | 
 | 4199 |  | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4200 | 		if (!(mask & dev->event_types[i].mask)) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4201 | 			continue; | 
 | 4202 |  | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4203 | 		for (j = 0; dev->event_types[i].events[j].event; j++) { | 
 | 4204 | 			if (ev == dev->event_types[i].events[j].data) { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4205 | 				device_event = | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4206 | 					dev->event_types[i].events[j].event; | 
| Mattia Dongili | 4eeb502 | 2011-02-19 11:52:27 +0900 | [diff] [blame] | 4207 | 				/* some events may require ignoring */ | 
 | 4208 | 				if (!device_event) | 
 | 4209 | 					return IRQ_HANDLED; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4210 | 				goto found; | 
 | 4211 | 			} | 
 | 4212 | 		} | 
 | 4213 | 	} | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 4214 | 	/* Still not able to decode the event try to pass | 
 | 4215 | 	 * it over to the minidriver | 
 | 4216 | 	 */ | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4217 | 	if (dev->handle_irq && dev->handle_irq(data_mask, ev) == 0) | 
| Mattia Dongili | 3eb8749 | 2008-01-14 18:05:45 +0900 | [diff] [blame] | 4218 | 		return IRQ_HANDLED; | 
 | 4219 |  | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 4220 | 	dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n", | 
 | 4221 | 			ev, data_mask, dev->cur_ioport->io1.minimum, | 
| Mattia Dongili | 31df714 | 2009-09-16 00:05:29 +0900 | [diff] [blame] | 4222 | 			dev->evport_offset); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4223 | 	return IRQ_HANDLED; | 
 | 4224 |  | 
 | 4225 | found: | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 4226 | 	sony_laptop_report_input_event(device_event); | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 4227 | 	acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event); | 
| malattia@linux.it | 7b153f3 | 2007-04-09 19:31:25 +0200 | [diff] [blame] | 4228 | 	sonypi_compat_report_event(device_event); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4229 | 	return IRQ_HANDLED; | 
 | 4230 | } | 
 | 4231 |  | 
 | 4232 | /***************** | 
 | 4233 |  * | 
 | 4234 |  *  ACPI driver | 
 | 4235 |  * | 
 | 4236 |  *****************/ | 
| Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 4237 | static int sony_pic_remove(struct acpi_device *device) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4238 | { | 
 | 4239 | 	struct sony_pic_ioport *io, *tmp_io; | 
 | 4240 | 	struct sony_pic_irq *irq, *tmp_irq; | 
 | 4241 |  | 
 | 4242 | 	if (sony_pic_disable(device)) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4243 | 		pr_err("Couldn't disable device\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4244 | 		return -ENXIO; | 
 | 4245 | 	} | 
 | 4246 |  | 
 | 4247 | 	free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev); | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4248 | 	release_region(spic_dev.cur_ioport->io1.minimum, | 
 | 4249 | 			spic_dev.cur_ioport->io1.address_length); | 
 | 4250 | 	if (spic_dev.cur_ioport->io2.minimum) | 
 | 4251 | 		release_region(spic_dev.cur_ioport->io2.minimum, | 
 | 4252 | 				spic_dev.cur_ioport->io2.address_length); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4253 |  | 
| Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 4254 | 	sonypi_compat_exit(); | 
 | 4255 |  | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 4256 | 	sony_laptop_remove_input(); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4257 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 4258 | 	/* pf attrs */ | 
 | 4259 | 	sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group); | 
 | 4260 | 	sony_pf_remove(); | 
 | 4261 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4262 | 	list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) { | 
 | 4263 | 		list_del(&io->list); | 
 | 4264 | 		kfree(io); | 
 | 4265 | 	} | 
 | 4266 | 	list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) { | 
 | 4267 | 		list_del(&irq->list); | 
 | 4268 | 		kfree(irq); | 
 | 4269 | 	} | 
 | 4270 | 	spic_dev.cur_ioport = NULL; | 
 | 4271 | 	spic_dev.cur_irq = NULL; | 
 | 4272 |  | 
| malattia@linux.it | f6119b0 | 2007-04-09 19:31:06 +0200 | [diff] [blame] | 4273 | 	dprintk(SONY_PIC_DRIVER_NAME " removed.\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4274 | 	return 0; | 
 | 4275 | } | 
 | 4276 |  | 
 | 4277 | static int sony_pic_add(struct acpi_device *device) | 
 | 4278 | { | 
 | 4279 | 	int result; | 
 | 4280 | 	struct sony_pic_ioport *io, *tmp_io; | 
 | 4281 | 	struct sony_pic_irq *irq, *tmp_irq; | 
 | 4282 |  | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4283 | 	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] | 4284 |  | 
 | 4285 | 	spic_dev.acpi_dev = device; | 
 | 4286 | 	strcpy(acpi_device_class(device), "sony/hotkey"); | 
| Mattia Dongili | de92043 | 2008-01-14 18:05:43 +0900 | [diff] [blame] | 4287 | 	sony_pic_detect_device_type(&spic_dev); | 
| malattia@linux.it | 9f9f076 | 2007-04-28 23:19:36 +0900 | [diff] [blame] | 4288 | 	mutex_init(&spic_dev.lock); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4289 |  | 
 | 4290 | 	/* read _PRS resources */ | 
 | 4291 | 	result = sony_pic_possible_resources(device); | 
 | 4292 | 	if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4293 | 		pr_err("Unable to read possible resources\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4294 | 		goto err_free_resources; | 
 | 4295 | 	} | 
 | 4296 |  | 
 | 4297 | 	/* setup input devices and helper fifo */ | 
| Dmitry Torokhov | 2e4d242 | 2007-11-21 14:15:53 -0500 | [diff] [blame] | 4298 | 	result = sony_laptop_setup_input(device); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4299 | 	if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4300 | 		pr_err("Unable to create input devices\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4301 | 		goto err_free_resources; | 
 | 4302 | 	} | 
 | 4303 |  | 
| Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 4304 | 	if (sonypi_compat_init()) | 
 | 4305 | 		goto err_remove_input; | 
 | 4306 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4307 | 	/* request io port */ | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4308 | 	list_for_each_entry_reverse(io, &spic_dev.ioports, list) { | 
 | 4309 | 		if (request_region(io->io1.minimum, io->io1.address_length, | 
| Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 4310 | 					"Sony Programmable I/O Device")) { | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4311 | 			dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n", | 
 | 4312 | 					io->io1.minimum, io->io1.maximum, | 
 | 4313 | 					io->io1.address_length); | 
 | 4314 | 			/* Type 1 have 2 ioports */ | 
 | 4315 | 			if (io->io2.minimum) { | 
 | 4316 | 				if (request_region(io->io2.minimum, | 
 | 4317 | 						io->io2.address_length, | 
| Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 4318 | 						"Sony Programmable I/O Device")) { | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4319 | 					dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n", | 
 | 4320 | 							io->io2.minimum, io->io2.maximum, | 
 | 4321 | 							io->io2.address_length); | 
 | 4322 | 					spic_dev.cur_ioport = io; | 
 | 4323 | 					break; | 
 | 4324 | 				} | 
 | 4325 | 				else { | 
 | 4326 | 					dprintk("Unable to get I/O port2: " | 
 | 4327 | 							"0x%.4x (0x%.4x) + 0x%.2x\n", | 
 | 4328 | 							io->io2.minimum, io->io2.maximum, | 
 | 4329 | 							io->io2.address_length); | 
 | 4330 | 					release_region(io->io1.minimum, | 
 | 4331 | 							io->io1.address_length); | 
 | 4332 | 				} | 
 | 4333 | 			} | 
 | 4334 | 			else { | 
 | 4335 | 				spic_dev.cur_ioport = io; | 
 | 4336 | 				break; | 
 | 4337 | 			} | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4338 | 		} | 
 | 4339 | 	} | 
 | 4340 | 	if (!spic_dev.cur_ioport) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4341 | 		pr_err("Failed to request_region\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4342 | 		result = -ENODEV; | 
| Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 4343 | 		goto err_remove_compat; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4344 | 	} | 
 | 4345 |  | 
 | 4346 | 	/* request IRQ */ | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4347 | 	list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4348 | 		if (!request_irq(irq->irq.interrupts[0], sony_pic_irq, | 
| Yong Zhang | 6a0d89c | 2011-10-22 17:56:50 +0800 | [diff] [blame] | 4349 | 					0, "sony-laptop", &spic_dev)) { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4350 | 			dprintk("IRQ: %d - triggering: %d - " | 
 | 4351 | 					"polarity: %d - shr: %d\n", | 
 | 4352 | 					irq->irq.interrupts[0], | 
 | 4353 | 					irq->irq.triggering, | 
 | 4354 | 					irq->irq.polarity, | 
 | 4355 | 					irq->irq.sharable); | 
 | 4356 | 			spic_dev.cur_irq = irq; | 
 | 4357 | 			break; | 
 | 4358 | 		} | 
 | 4359 | 	} | 
 | 4360 | 	if (!spic_dev.cur_irq) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4361 | 		pr_err("Failed to request_irq\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4362 | 		result = -ENODEV; | 
 | 4363 | 		goto err_release_region; | 
 | 4364 | 	} | 
 | 4365 |  | 
 | 4366 | 	/* set resource status _SRS */ | 
 | 4367 | 	result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq); | 
 | 4368 | 	if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4369 | 		pr_err("Couldn't enable device\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4370 | 		goto err_free_irq; | 
 | 4371 | 	} | 
 | 4372 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 4373 | 	spic_dev.bluetooth_power = -1; | 
 | 4374 | 	/* create device attributes */ | 
 | 4375 | 	result = sony_pf_add(); | 
 | 4376 | 	if (result) | 
 | 4377 | 		goto err_disable_device; | 
 | 4378 |  | 
 | 4379 | 	result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group); | 
 | 4380 | 	if (result) | 
 | 4381 | 		goto err_remove_pf; | 
 | 4382 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4383 | 	return 0; | 
 | 4384 |  | 
| malattia@linux.it | 49a11de | 2007-04-09 19:28:56 +0200 | [diff] [blame] | 4385 | err_remove_pf: | 
 | 4386 | 	sony_pf_remove(); | 
 | 4387 |  | 
 | 4388 | err_disable_device: | 
 | 4389 | 	sony_pic_disable(device); | 
 | 4390 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4391 | err_free_irq: | 
 | 4392 | 	free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev); | 
 | 4393 |  | 
 | 4394 | err_release_region: | 
| Mattia Dongili | fd1caae | 2007-08-12 16:20:28 +0900 | [diff] [blame] | 4395 | 	release_region(spic_dev.cur_ioport->io1.minimum, | 
 | 4396 | 			spic_dev.cur_ioport->io1.address_length); | 
 | 4397 | 	if (spic_dev.cur_ioport->io2.minimum) | 
 | 4398 | 		release_region(spic_dev.cur_ioport->io2.minimum, | 
 | 4399 | 				spic_dev.cur_ioport->io2.address_length); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4400 |  | 
| Mattia Dongili | 015a916 | 2007-08-12 16:20:27 +0900 | [diff] [blame] | 4401 | err_remove_compat: | 
 | 4402 | 	sonypi_compat_exit(); | 
 | 4403 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4404 | err_remove_input: | 
| malattia@linux.it | 1549ee6 | 2007-04-09 10:19:08 +0200 | [diff] [blame] | 4405 | 	sony_laptop_remove_input(); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4406 |  | 
 | 4407 | err_free_resources: | 
 | 4408 | 	list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) { | 
 | 4409 | 		list_del(&io->list); | 
 | 4410 | 		kfree(io); | 
 | 4411 | 	} | 
 | 4412 | 	list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) { | 
 | 4413 | 		list_del(&irq->list); | 
 | 4414 | 		kfree(irq); | 
 | 4415 | 	} | 
 | 4416 | 	spic_dev.cur_ioport = NULL; | 
 | 4417 | 	spic_dev.cur_irq = NULL; | 
 | 4418 |  | 
 | 4419 | 	return result; | 
 | 4420 | } | 
 | 4421 |  | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 4422 | #ifdef CONFIG_PM_SLEEP | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4423 | static int sony_pic_suspend(struct device *dev) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4424 | { | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4425 | 	if (sony_pic_disable(to_acpi_device(dev))) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4426 | 		return -ENXIO; | 
 | 4427 | 	return 0; | 
 | 4428 | } | 
 | 4429 |  | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4430 | static int sony_pic_resume(struct device *dev) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4431 | { | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4432 | 	sony_pic_enable(to_acpi_device(dev), | 
 | 4433 | 			spic_dev.cur_ioport, spic_dev.cur_irq); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4434 | 	return 0; | 
 | 4435 | } | 
| Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 4436 | #endif | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4437 |  | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4438 | static SIMPLE_DEV_PM_OPS(sony_pic_pm, sony_pic_suspend, sony_pic_resume); | 
 | 4439 |  | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4440 | static const struct acpi_device_id sony_pic_device_ids[] = { | 
 | 4441 | 	{SONY_PIC_HID, 0}, | 
 | 4442 | 	{"", 0}, | 
 | 4443 | }; | 
 | 4444 |  | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4445 | static struct acpi_driver sony_pic_driver = { | 
 | 4446 | 	.name = SONY_PIC_DRIVER_NAME, | 
 | 4447 | 	.class = SONY_PIC_CLASS, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4448 | 	.ids = sony_pic_device_ids, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4449 | 	.owner = THIS_MODULE, | 
 | 4450 | 	.ops = { | 
 | 4451 | 		.add = sony_pic_add, | 
 | 4452 | 		.remove = sony_pic_remove, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4453 | 		}, | 
| Rafael J. Wysocki | bb6b98d | 2012-06-27 23:27:33 +0200 | [diff] [blame] | 4454 | 	.drv.pm = &sony_pic_pm, | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4455 | }; | 
 | 4456 |  | 
 | 4457 | static struct dmi_system_id __initdata sonypi_dmi_table[] = { | 
 | 4458 | 	{ | 
 | 4459 | 		.ident = "Sony Vaio", | 
 | 4460 | 		.matches = { | 
 | 4461 | 			DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 4462 | 			DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"), | 
 | 4463 | 		}, | 
 | 4464 | 	}, | 
 | 4465 | 	{ | 
 | 4466 | 		.ident = "Sony Vaio", | 
 | 4467 | 		.matches = { | 
 | 4468 | 			DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 4469 | 			DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"), | 
 | 4470 | 		}, | 
 | 4471 | 	}, | 
 | 4472 | 	{ } | 
 | 4473 | }; | 
 | 4474 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 4475 | static int __init sony_laptop_init(void) | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 4476 | { | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4477 | 	int result; | 
 | 4478 |  | 
 | 4479 | 	if (!no_spic && dmi_check_system(sonypi_dmi_table)) { | 
 | 4480 | 		result = acpi_bus_register_driver(&sony_pic_driver); | 
 | 4481 | 		if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4482 | 			pr_err("Unable to register SPIC driver\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4483 | 			goto out; | 
 | 4484 | 		} | 
| Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 4485 | 		spic_drv_registered = 1; | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4486 | 	} | 
 | 4487 |  | 
 | 4488 | 	result = acpi_bus_register_driver(&sony_nc_driver); | 
 | 4489 | 	if (result) { | 
| Joe Perches | 50f581a | 2011-03-29 15:21:48 -0700 | [diff] [blame] | 4490 | 		pr_err("Unable to register SNC driver\n"); | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4491 | 		goto out_unregister_pic; | 
 | 4492 | 	} | 
 | 4493 |  | 
 | 4494 | 	return 0; | 
 | 4495 |  | 
 | 4496 | out_unregister_pic: | 
| Alan Jenkins | 5e6f972 | 2009-09-16 00:05:32 +0900 | [diff] [blame] | 4497 | 	if (spic_drv_registered) | 
| malattia@linux.it | 33a0445 | 2007-04-09 19:26:03 +0200 | [diff] [blame] | 4498 | 		acpi_bus_unregister_driver(&sony_pic_driver); | 
 | 4499 | out: | 
 | 4500 | 	return result; | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 4501 | } | 
 | 4502 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 4503 | static void __exit sony_laptop_exit(void) | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 4504 | { | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 4505 | 	acpi_bus_unregister_driver(&sony_nc_driver); | 
| 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); | 
| Stelian Pop | 7f09c43 | 2007-01-13 23:04:31 +0100 | [diff] [blame] | 4508 | } | 
 | 4509 |  | 
| malattia@linux.it | 59b1910 | 2007-04-09 10:19:04 +0200 | [diff] [blame] | 4510 | module_init(sony_laptop_init); | 
 | 4511 | module_exit(sony_laptop_exit); |