David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ideapad_acpi.c - Lenovo IdeaPad ACPI Extras |
| 3 | * |
| 4 | * Copyright © 2010 Intel Corporation |
| 5 | * Copyright © 2010 David Woodhouse <dwmw2@infradead.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 | * 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <acpi/acpi_bus.h> |
| 28 | #include <acpi/acpi_drivers.h> |
| 29 | #include <linux/rfkill.h> |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 31 | |
| 32 | #define IDEAPAD_DEV_CAMERA 0 |
| 33 | #define IDEAPAD_DEV_WLAN 1 |
| 34 | #define IDEAPAD_DEV_BLUETOOTH 2 |
| 35 | #define IDEAPAD_DEV_3G 3 |
| 36 | #define IDEAPAD_DEV_KILLSW 4 |
| 37 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 38 | struct ideapad_private { |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 39 | acpi_handle handle; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 40 | struct rfkill *rfk[5]; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 41 | struct platform_device *platform_device; |
Ike Panhc | fa08359 | 2010-10-01 15:39:59 +0800 | [diff] [blame] | 42 | } *ideapad_priv; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 43 | |
| 44 | static struct { |
| 45 | char *name; |
Ike Panhc | dfa7f6f | 2010-10-01 15:39:29 +0800 | [diff] [blame] | 46 | int cfgbit; |
Ike Panhc | fa08359 | 2010-10-01 15:39:59 +0800 | [diff] [blame] | 47 | int opcode; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 48 | int type; |
| 49 | } ideapad_rfk_data[] = { |
Ike Panhc | fa08359 | 2010-10-01 15:39:59 +0800 | [diff] [blame] | 50 | { "ideapad_camera", 19, 0x1E, NUM_RFKILL_TYPES }, |
| 51 | { "ideapad_wlan", 18, 0x15, RFKILL_TYPE_WLAN }, |
| 52 | { "ideapad_bluetooth", 16, 0x17, RFKILL_TYPE_BLUETOOTH }, |
| 53 | { "ideapad_3g", 17, 0x20, RFKILL_TYPE_WWAN }, |
| 54 | { "ideapad_killsw", 0, 0, RFKILL_TYPE_WLAN } |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Ike Panhc | bfa97b7 | 2010-10-01 15:40:22 +0800 | [diff] [blame] | 57 | static bool no_bt_rfkill; |
| 58 | module_param(no_bt_rfkill, bool, 0444); |
| 59 | MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); |
| 60 | |
Ike Panhc | 6a09f21 | 2010-10-01 15:38:46 +0800 | [diff] [blame] | 61 | /* |
| 62 | * ACPI Helpers |
| 63 | */ |
| 64 | #define IDEAPAD_EC_TIMEOUT (100) /* in ms */ |
| 65 | |
| 66 | static int read_method_int(acpi_handle handle, const char *method, int *val) |
| 67 | { |
| 68 | acpi_status status; |
| 69 | unsigned long long result; |
| 70 | |
| 71 | status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); |
| 72 | if (ACPI_FAILURE(status)) { |
| 73 | *val = -1; |
| 74 | return -1; |
| 75 | } else { |
| 76 | *val = result; |
| 77 | return 0; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static int method_vpcr(acpi_handle handle, int cmd, int *ret) |
| 82 | { |
| 83 | acpi_status status; |
| 84 | unsigned long long result; |
| 85 | struct acpi_object_list params; |
| 86 | union acpi_object in_obj; |
| 87 | |
| 88 | params.count = 1; |
| 89 | params.pointer = &in_obj; |
| 90 | in_obj.type = ACPI_TYPE_INTEGER; |
| 91 | in_obj.integer.value = cmd; |
| 92 | |
| 93 | status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); |
| 94 | |
| 95 | if (ACPI_FAILURE(status)) { |
| 96 | *ret = -1; |
| 97 | return -1; |
| 98 | } else { |
| 99 | *ret = result; |
| 100 | return 0; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static int method_vpcw(acpi_handle handle, int cmd, int data) |
| 105 | { |
| 106 | struct acpi_object_list params; |
| 107 | union acpi_object in_obj[2]; |
| 108 | acpi_status status; |
| 109 | |
| 110 | params.count = 2; |
| 111 | params.pointer = in_obj; |
| 112 | in_obj[0].type = ACPI_TYPE_INTEGER; |
| 113 | in_obj[0].integer.value = cmd; |
| 114 | in_obj[1].type = ACPI_TYPE_INTEGER; |
| 115 | in_obj[1].integer.value = data; |
| 116 | |
| 117 | status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); |
| 118 | if (status != AE_OK) |
| 119 | return -1; |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) |
| 124 | { |
| 125 | int val; |
| 126 | unsigned long int end_jiffies; |
| 127 | |
| 128 | if (method_vpcw(handle, 1, cmd)) |
| 129 | return -1; |
| 130 | |
| 131 | for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; |
| 132 | time_before(jiffies, end_jiffies);) { |
| 133 | schedule(); |
| 134 | if (method_vpcr(handle, 1, &val)) |
| 135 | return -1; |
| 136 | if (val == 0) { |
| 137 | if (method_vpcr(handle, 0, &val)) |
| 138 | return -1; |
| 139 | *data = val; |
| 140 | return 0; |
| 141 | } |
| 142 | } |
| 143 | pr_err("timeout in read_ec_cmd\n"); |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) |
| 148 | { |
| 149 | int val; |
| 150 | unsigned long int end_jiffies; |
| 151 | |
| 152 | if (method_vpcw(handle, 0, data)) |
| 153 | return -1; |
| 154 | if (method_vpcw(handle, 1, cmd)) |
| 155 | return -1; |
| 156 | |
| 157 | for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; |
| 158 | time_before(jiffies, end_jiffies);) { |
| 159 | schedule(); |
| 160 | if (method_vpcr(handle, 1, &val)) |
| 161 | return -1; |
| 162 | if (val == 0) |
| 163 | return 0; |
| 164 | } |
| 165 | pr_err("timeout in write_ec_cmd\n"); |
| 166 | return -1; |
| 167 | } |
| 168 | /* the above is ACPI helpers */ |
| 169 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 170 | static ssize_t show_ideapad_cam(struct device *dev, |
| 171 | struct device_attribute *attr, |
| 172 | char *buf) |
| 173 | { |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 174 | struct ideapad_private *priv = dev_get_drvdata(dev); |
| 175 | acpi_handle handle = priv->handle; |
| 176 | unsigned long result; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 177 | |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 178 | if (read_ec_data(handle, 0x1D, &result)) |
| 179 | return sprintf(buf, "-1\n"); |
| 180 | return sprintf(buf, "%lu\n", result); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static ssize_t store_ideapad_cam(struct device *dev, |
| 184 | struct device_attribute *attr, |
| 185 | const char *buf, size_t count) |
| 186 | { |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 187 | struct ideapad_private *priv = dev_get_drvdata(dev); |
| 188 | acpi_handle handle = priv->handle; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 189 | int ret, state; |
| 190 | |
| 191 | if (!count) |
| 192 | return 0; |
| 193 | if (sscanf(buf, "%i", &state) != 1) |
| 194 | return -EINVAL; |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 195 | ret = write_ec_cmd(handle, 0x1E, state); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 196 | if (ret < 0) |
| 197 | return ret; |
| 198 | return count; |
| 199 | } |
| 200 | |
| 201 | static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); |
| 202 | |
| 203 | static int ideapad_rfk_set(void *data, bool blocked) |
| 204 | { |
| 205 | int device = (unsigned long)data; |
| 206 | |
| 207 | if (device == IDEAPAD_DEV_KILLSW) |
| 208 | return -EINVAL; |
Ike Panhc | fa08359 | 2010-10-01 15:39:59 +0800 | [diff] [blame] | 209 | |
| 210 | return write_ec_cmd(ideapad_priv->handle, |
| 211 | ideapad_rfk_data[device].opcode, |
| 212 | !blocked); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static struct rfkill_ops ideapad_rfk_ops = { |
| 216 | .set_block = ideapad_rfk_set, |
| 217 | }; |
| 218 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 219 | static void ideapad_sync_rfk_state(struct acpi_device *adevice) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 220 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 221 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 222 | acpi_handle handle = priv->handle; |
| 223 | unsigned long hw_blocked; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 224 | int i; |
| 225 | |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 226 | if (read_ec_data(handle, 0x23, &hw_blocked)) |
| 227 | return; |
| 228 | hw_blocked = !hw_blocked; |
| 229 | |
| 230 | for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 231 | if (priv->rfk[i]) |
| 232 | rfkill_set_hw_state(priv->rfk[i], hw_blocked); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 233 | } |
| 234 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 235 | static int ideapad_register_rfkill(struct acpi_device *adevice, int dev) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 236 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 237 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 238 | int ret; |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 239 | unsigned long sw_blocked; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 240 | |
Ike Panhc | bfa97b7 | 2010-10-01 15:40:22 +0800 | [diff] [blame] | 241 | if (no_bt_rfkill && |
| 242 | (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { |
| 243 | /* Force to enable bluetooth when no_bt_rfkill=1 */ |
| 244 | write_ec_cmd(ideapad_priv->handle, |
| 245 | ideapad_rfk_data[dev].opcode, 1); |
| 246 | return 0; |
| 247 | } |
| 248 | |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 249 | priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name, &adevice->dev, |
| 250 | ideapad_rfk_data[dev].type, &ideapad_rfk_ops, |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 251 | (void *)(long)dev); |
| 252 | if (!priv->rfk[dev]) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 253 | return -ENOMEM; |
| 254 | |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 255 | if (read_ec_data(ideapad_priv->handle, ideapad_rfk_data[dev].opcode-1, |
| 256 | &sw_blocked)) { |
| 257 | rfkill_init_sw_state(priv->rfk[dev], 0); |
| 258 | } else { |
| 259 | sw_blocked = !sw_blocked; |
| 260 | rfkill_init_sw_state(priv->rfk[dev], sw_blocked); |
| 261 | } |
| 262 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 263 | ret = rfkill_register(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 264 | if (ret) { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 265 | rfkill_destroy(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 271 | static void ideapad_unregister_rfkill(struct acpi_device *adevice, int dev) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 272 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 273 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
| 274 | |
| 275 | if (!priv->rfk[dev]) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 276 | return; |
| 277 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 278 | rfkill_unregister(priv->rfk[dev]); |
| 279 | rfkill_destroy(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 282 | /* |
| 283 | * Platform device |
| 284 | */ |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 285 | static struct attribute *ideapad_attributes[] = { |
| 286 | &dev_attr_camera_power.attr, |
| 287 | NULL |
| 288 | }; |
| 289 | |
| 290 | static struct attribute_group ideapad_attribute_group = { |
| 291 | .attrs = ideapad_attributes |
| 292 | }; |
| 293 | |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 294 | static int __devinit ideapad_platform_init(void) |
| 295 | { |
| 296 | int result; |
| 297 | |
| 298 | ideapad_priv->platform_device = platform_device_alloc("ideapad", -1); |
| 299 | if (!ideapad_priv->platform_device) |
| 300 | return -ENOMEM; |
| 301 | platform_set_drvdata(ideapad_priv->platform_device, ideapad_priv); |
| 302 | |
| 303 | result = platform_device_add(ideapad_priv->platform_device); |
| 304 | if (result) |
| 305 | goto fail_platform_device; |
| 306 | |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 307 | result = sysfs_create_group(&ideapad_priv->platform_device->dev.kobj, |
| 308 | &ideapad_attribute_group); |
| 309 | if (result) |
| 310 | goto fail_sysfs; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 311 | return 0; |
| 312 | |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 313 | fail_sysfs: |
| 314 | platform_device_del(ideapad_priv->platform_device); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 315 | fail_platform_device: |
| 316 | platform_device_put(ideapad_priv->platform_device); |
| 317 | return result; |
| 318 | } |
| 319 | |
| 320 | static void ideapad_platform_exit(void) |
| 321 | { |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 322 | sysfs_remove_group(&ideapad_priv->platform_device->dev.kobj, |
| 323 | &ideapad_attribute_group); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 324 | platform_device_unregister(ideapad_priv->platform_device); |
| 325 | } |
| 326 | /* the above is platform device */ |
| 327 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 328 | static const struct acpi_device_id ideapad_device_ids[] = { |
| 329 | { "VPC2004", 0}, |
| 330 | { "", 0}, |
| 331 | }; |
| 332 | MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); |
| 333 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 334 | static int ideapad_acpi_add(struct acpi_device *adevice) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 335 | { |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 336 | int ret, i, cfg; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 337 | struct ideapad_private *priv; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 338 | |
Ike Panhc | 6f8371c | 2010-10-01 15:39:14 +0800 | [diff] [blame] | 339 | if (read_method_int(adevice->handle, "_CFG", &cfg)) |
| 340 | return -ENODEV; |
| 341 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 342 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 343 | if (!priv) |
| 344 | return -ENOMEM; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 345 | ideapad_priv = priv; |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 346 | priv->handle = adevice->handle; |
| 347 | dev_set_drvdata(&adevice->dev, priv); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 348 | |
| 349 | ret = ideapad_platform_init(); |
| 350 | if (ret) |
| 351 | goto platform_failed; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 352 | |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 353 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) { |
| 354 | if (test_bit(ideapad_rfk_data[i].cfgbit, (unsigned long *)&cfg)) |
| 355 | ideapad_register_rfkill(adevice, i); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 356 | } |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 357 | ideapad_sync_rfk_state(adevice); |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 358 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 359 | return 0; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 360 | |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 361 | platform_failed: |
| 362 | kfree(priv); |
| 363 | return ret; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 364 | } |
| 365 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 366 | static int ideapad_acpi_remove(struct acpi_device *adevice, int type) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 367 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 368 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 369 | int i; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 370 | |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 371 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 372 | ideapad_unregister_rfkill(adevice, i); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 373 | ideapad_platform_exit(); |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 374 | dev_set_drvdata(&adevice->dev, NULL); |
| 375 | kfree(priv); |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame^] | 376 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 380 | static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 381 | { |
Ike Panhc | 8e7d354 | 2010-10-01 15:39:05 +0800 | [diff] [blame] | 382 | acpi_handle handle = adevice->handle; |
| 383 | unsigned long vpc1, vpc2, vpc_bit; |
| 384 | |
| 385 | if (read_ec_data(handle, 0x10, &vpc1)) |
| 386 | return; |
| 387 | if (read_ec_data(handle, 0x1A, &vpc2)) |
| 388 | return; |
| 389 | |
| 390 | vpc1 = (vpc2 << 8) | vpc1; |
| 391 | for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) { |
| 392 | if (test_bit(vpc_bit, &vpc1)) { |
| 393 | if (vpc_bit == 9) |
| 394 | ideapad_sync_rfk_state(adevice); |
| 395 | } |
| 396 | } |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static struct acpi_driver ideapad_acpi_driver = { |
| 400 | .name = "ideapad_acpi", |
| 401 | .class = "IdeaPad", |
| 402 | .ids = ideapad_device_ids, |
| 403 | .ops.add = ideapad_acpi_add, |
| 404 | .ops.remove = ideapad_acpi_remove, |
| 405 | .ops.notify = ideapad_acpi_notify, |
| 406 | .owner = THIS_MODULE, |
| 407 | }; |
| 408 | |
| 409 | |
| 410 | static int __init ideapad_acpi_module_init(void) |
| 411 | { |
| 412 | acpi_bus_register_driver(&ideapad_acpi_driver); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | static void __exit ideapad_acpi_module_exit(void) |
| 419 | { |
| 420 | acpi_bus_unregister_driver(&ideapad_acpi_driver); |
| 421 | |
| 422 | } |
| 423 | |
| 424 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |
| 425 | MODULE_DESCRIPTION("IdeaPad ACPI Extras"); |
| 426 | MODULE_LICENSE("GPL"); |
| 427 | |
| 428 | module_init(ideapad_acpi_module_init); |
| 429 | module_exit(ideapad_acpi_module_exit); |