Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Eee PC WMI hotkey driver |
| 3 | * |
| 4 | * Copyright(C) 2010 Intel Corporation. |
| 5 | * |
| 6 | * Portions based on wistron_btns.c: |
| 7 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
| 8 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> |
| 9 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/types.h> |
Tejun Heo | a32f392 | 2010-04-05 11:37:59 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 33 | #include <linux/input.h> |
| 34 | #include <linux/input/sparse-keymap.h> |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 35 | #include <linux/fb.h> |
| 36 | #include <linux/backlight.h> |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 37 | #include <linux/leds.h> |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 38 | #include <linux/rfkill.h> |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 39 | #include <linux/debugfs.h> |
| 40 | #include <linux/seq_file.h> |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 41 | #include <linux/platform_device.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <acpi/acpi_drivers.h> |
| 44 | |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 45 | #define EEEPC_WMI_FILE "eeepc-wmi" |
| 46 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 47 | MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); |
| 48 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); |
| 49 | MODULE_LICENSE("GPL"); |
| 50 | |
| 51 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 52 | #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 53 | |
| 54 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 55 | MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 56 | |
| 57 | #define NOTIFY_BRNUP_MIN 0x11 |
| 58 | #define NOTIFY_BRNUP_MAX 0x1f |
| 59 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 60 | #define NOTIFY_BRNDOWN_MAX 0x2e |
| 61 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 62 | #define EEEPC_WMI_METHODID_DEVS 0x53564544 |
| 63 | #define EEEPC_WMI_METHODID_DSTS 0x53544344 |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 64 | #define EEEPC_WMI_METHODID_CFVS 0x53564643 |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 65 | |
| 66 | #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012 |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 67 | #define EEEPC_WMI_DEVID_TPDLED 0x00100011 |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 68 | #define EEEPC_WMI_DEVID_WLAN 0x00010011 |
| 69 | #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013 |
| 70 | #define EEEPC_WMI_DEVID_WWAN3G 0x00010019 |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 71 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 72 | static const struct key_entry eeepc_wmi_keymap[] = { |
| 73 | /* Sleep already handled via generic ACPI code */ |
| 74 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
| 75 | { KE_KEY, 0x32, { KEY_MUTE } }, |
| 76 | { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, |
| 77 | { KE_KEY, 0x30, { KEY_VOLUMEUP } }, |
| 78 | { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } }, |
| 79 | { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } }, |
| 80 | { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, |
Chris Bagwell | eda1748 | 2010-10-11 18:47:17 -0500 | [diff] [blame] | 81 | { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */ |
| 82 | { KE_KEY, 0xe1, { KEY_F14 } }, |
| 83 | { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } }, |
| 84 | { KE_KEY, 0xe0, { KEY_PROG1 } }, |
| 85 | { KE_KEY, 0x5c, { KEY_F15 } }, |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 86 | { KE_END, 0}, |
| 87 | }; |
| 88 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 89 | struct bios_args { |
| 90 | u32 dev_id; |
| 91 | u32 ctrl_param; |
| 92 | }; |
| 93 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 94 | /* |
| 95 | * eeepc-wmi/ - debugfs root directory |
| 96 | * dev_id - current dev_id |
| 97 | * ctrl_param - current ctrl_param |
| 98 | * devs - call DEVS(dev_id, ctrl_param) and print result |
| 99 | * dsts - call DSTS(dev_id) and print result |
| 100 | */ |
| 101 | struct eeepc_wmi_debug { |
| 102 | struct dentry *root; |
| 103 | u32 dev_id; |
| 104 | u32 ctrl_param; |
| 105 | }; |
| 106 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 107 | struct eeepc_wmi { |
| 108 | struct input_dev *inputdev; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 109 | struct backlight_device *backlight_device; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 110 | struct platform_device *platform_device; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 111 | |
| 112 | struct led_classdev tpd_led; |
| 113 | int tpd_led_wk; |
| 114 | struct workqueue_struct *led_workqueue; |
| 115 | struct work_struct tpd_led_work; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 116 | |
| 117 | struct rfkill *wlan_rfkill; |
| 118 | struct rfkill *bluetooth_rfkill; |
| 119 | struct rfkill *wwan3g_rfkill; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 120 | |
| 121 | struct eeepc_wmi_debug debug; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 122 | }; |
| 123 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 124 | /* Only used in eeepc_wmi_init() and eeepc_wmi_exit() */ |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 125 | static struct platform_device *platform_device; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 126 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 127 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 128 | { |
| 129 | int err; |
| 130 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 131 | eeepc->inputdev = input_allocate_device(); |
| 132 | if (!eeepc->inputdev) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 133 | return -ENOMEM; |
| 134 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 135 | eeepc->inputdev->name = "Eee PC WMI hotkeys"; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 136 | eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0"; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 137 | eeepc->inputdev->id.bustype = BUS_HOST; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 138 | eeepc->inputdev->dev.parent = &eeepc->platform_device->dev; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 139 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 140 | err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 141 | if (err) |
| 142 | goto err_free_dev; |
| 143 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 144 | err = input_register_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 145 | if (err) |
| 146 | goto err_free_keymap; |
| 147 | |
| 148 | return 0; |
| 149 | |
| 150 | err_free_keymap: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 151 | sparse_keymap_free(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 152 | err_free_dev: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 153 | input_free_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 154 | return err; |
| 155 | } |
| 156 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 157 | static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) |
| 158 | { |
| 159 | if (eeepc->inputdev) { |
| 160 | sparse_keymap_free(eeepc->inputdev); |
| 161 | input_unregister_device(eeepc->inputdev); |
| 162 | } |
| 163 | |
| 164 | eeepc->inputdev = NULL; |
| 165 | } |
| 166 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 167 | static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *ctrl_param) |
| 168 | { |
| 169 | struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id }; |
| 170 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 171 | union acpi_object *obj; |
| 172 | acpi_status status; |
| 173 | u32 tmp; |
| 174 | |
| 175 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, |
| 176 | 1, EEEPC_WMI_METHODID_DSTS, &input, &output); |
| 177 | |
| 178 | if (ACPI_FAILURE(status)) |
| 179 | return status; |
| 180 | |
| 181 | obj = (union acpi_object *)output.pointer; |
| 182 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 183 | tmp = (u32)obj->integer.value; |
| 184 | else |
| 185 | tmp = 0; |
| 186 | |
| 187 | if (ctrl_param) |
| 188 | *ctrl_param = tmp; |
| 189 | |
| 190 | kfree(obj); |
| 191 | |
| 192 | return status; |
| 193 | |
| 194 | } |
| 195 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 196 | static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param, |
| 197 | u32 *retval) |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 198 | { |
| 199 | struct bios_args args = { |
| 200 | .dev_id = dev_id, |
| 201 | .ctrl_param = ctrl_param, |
| 202 | }; |
| 203 | struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; |
| 204 | acpi_status status; |
| 205 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 206 | if (!retval) { |
| 207 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1, |
| 208 | EEEPC_WMI_METHODID_DEVS, |
| 209 | &input, NULL); |
| 210 | } else { |
| 211 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 212 | union acpi_object *obj; |
| 213 | u32 tmp; |
| 214 | |
| 215 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1, |
| 216 | EEEPC_WMI_METHODID_DEVS, |
| 217 | &input, &output); |
| 218 | |
| 219 | if (ACPI_FAILURE(status)) |
| 220 | return status; |
| 221 | |
| 222 | obj = (union acpi_object *)output.pointer; |
| 223 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 224 | tmp = (u32)obj->integer.value; |
| 225 | else |
| 226 | tmp = 0; |
| 227 | |
| 228 | *retval = tmp; |
| 229 | |
| 230 | kfree(obj); |
| 231 | } |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 232 | |
| 233 | return status; |
| 234 | } |
| 235 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 236 | /* |
| 237 | * LEDs |
| 238 | */ |
| 239 | /* |
| 240 | * These functions actually update the LED's, and are called from a |
| 241 | * workqueue. By doing this as separate work rather than when the LED |
| 242 | * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a |
| 243 | * potentially bad time, such as a timer interrupt. |
| 244 | */ |
| 245 | static void tpd_led_update(struct work_struct *work) |
| 246 | { |
| 247 | int ctrl_param; |
| 248 | struct eeepc_wmi *eeepc; |
| 249 | |
| 250 | eeepc = container_of(work, struct eeepc_wmi, tpd_led_work); |
| 251 | |
| 252 | ctrl_param = eeepc->tpd_led_wk; |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 253 | eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param, NULL); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static void tpd_led_set(struct led_classdev *led_cdev, |
| 257 | enum led_brightness value) |
| 258 | { |
| 259 | struct eeepc_wmi *eeepc; |
| 260 | |
| 261 | eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); |
| 262 | |
| 263 | eeepc->tpd_led_wk = !!value; |
| 264 | queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work); |
| 265 | } |
| 266 | |
| 267 | static int read_tpd_state(struct eeepc_wmi *eeepc) |
| 268 | { |
| 269 | static u32 ctrl_param; |
| 270 | acpi_status status; |
| 271 | |
| 272 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_TPDLED, &ctrl_param); |
| 273 | |
| 274 | if (ACPI_FAILURE(status)) |
| 275 | return -1; |
| 276 | else if (!ctrl_param || ctrl_param == 0x00060000) |
| 277 | /* |
| 278 | * if touchpad led is present, DSTS will set some bits, |
| 279 | * usually 0x00020000. |
| 280 | * 0x00060000 means that the device is not supported |
| 281 | */ |
| 282 | return -ENODEV; |
| 283 | else |
| 284 | /* Status is stored in the first bit */ |
| 285 | return ctrl_param & 0x1; |
| 286 | } |
| 287 | |
| 288 | static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) |
| 289 | { |
| 290 | struct eeepc_wmi *eeepc; |
| 291 | |
| 292 | eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); |
| 293 | |
| 294 | return read_tpd_state(eeepc); |
| 295 | } |
| 296 | |
| 297 | static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc) |
| 298 | { |
| 299 | int rv; |
| 300 | |
| 301 | if (read_tpd_state(eeepc) < 0) |
| 302 | return 0; |
| 303 | |
| 304 | eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 305 | if (!eeepc->led_workqueue) |
| 306 | return -ENOMEM; |
| 307 | INIT_WORK(&eeepc->tpd_led_work, tpd_led_update); |
| 308 | |
| 309 | eeepc->tpd_led.name = "eeepc::touchpad"; |
| 310 | eeepc->tpd_led.brightness_set = tpd_led_set; |
| 311 | eeepc->tpd_led.brightness_get = tpd_led_get; |
| 312 | eeepc->tpd_led.max_brightness = 1; |
| 313 | |
| 314 | rv = led_classdev_register(&eeepc->platform_device->dev, |
| 315 | &eeepc->tpd_led); |
| 316 | if (rv) { |
| 317 | destroy_workqueue(eeepc->led_workqueue); |
| 318 | return rv; |
| 319 | } |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc) |
| 325 | { |
| 326 | if (eeepc->tpd_led.dev) |
| 327 | led_classdev_unregister(&eeepc->tpd_led); |
| 328 | if (eeepc->led_workqueue) |
| 329 | destroy_workqueue(eeepc->led_workqueue); |
| 330 | } |
| 331 | |
| 332 | /* |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 333 | * Rfkill devices |
| 334 | */ |
| 335 | static int eeepc_rfkill_set(void *data, bool blocked) |
| 336 | { |
| 337 | int dev_id = (unsigned long)data; |
| 338 | u32 ctrl_param = !blocked; |
| 339 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 340 | return eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static void eeepc_rfkill_query(struct rfkill *rfkill, void *data) |
| 344 | { |
| 345 | int dev_id = (unsigned long)data; |
| 346 | u32 ctrl_param; |
| 347 | acpi_status status; |
| 348 | |
| 349 | status = eeepc_wmi_get_devstate(dev_id, &ctrl_param); |
| 350 | |
| 351 | if (ACPI_FAILURE(status)) |
| 352 | return ; |
| 353 | |
| 354 | rfkill_set_sw_state(rfkill, !(ctrl_param & 0x1)); |
| 355 | } |
| 356 | |
| 357 | static const struct rfkill_ops eeepc_rfkill_ops = { |
| 358 | .set_block = eeepc_rfkill_set, |
| 359 | .query = eeepc_rfkill_query, |
| 360 | }; |
| 361 | |
| 362 | static int eeepc_new_rfkill(struct eeepc_wmi *eeepc, |
| 363 | struct rfkill **rfkill, |
| 364 | const char *name, |
| 365 | enum rfkill_type type, int dev_id) |
| 366 | { |
| 367 | int result; |
| 368 | u32 ctrl_param; |
| 369 | acpi_status status; |
| 370 | |
| 371 | status = eeepc_wmi_get_devstate(dev_id, &ctrl_param); |
| 372 | |
| 373 | if (ACPI_FAILURE(status)) |
| 374 | return -1; |
| 375 | |
| 376 | /* If the device is present, DSTS will always set some bits |
| 377 | * 0x00070000 - 1110000000000000000 - device supported |
| 378 | * 0x00060000 - 1100000000000000000 - not supported |
| 379 | * 0x00020000 - 0100000000000000000 - device supported |
| 380 | * 0x00010000 - 0010000000000000000 - not supported / special mode ? |
| 381 | */ |
| 382 | if (!ctrl_param || ctrl_param == 0x00060000) |
| 383 | return -ENODEV; |
| 384 | |
| 385 | *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, |
| 386 | &eeepc_rfkill_ops, (void *)(long)dev_id); |
| 387 | |
| 388 | if (!*rfkill) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | rfkill_init_sw_state(*rfkill, !(ctrl_param & 0x1)); |
| 392 | result = rfkill_register(*rfkill); |
| 393 | if (result) { |
| 394 | rfkill_destroy(*rfkill); |
| 395 | *rfkill = NULL; |
| 396 | return result; |
| 397 | } |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc) |
| 402 | { |
| 403 | if (eeepc->wlan_rfkill) { |
| 404 | rfkill_unregister(eeepc->wlan_rfkill); |
| 405 | rfkill_destroy(eeepc->wlan_rfkill); |
| 406 | eeepc->wlan_rfkill = NULL; |
| 407 | } |
| 408 | if (eeepc->bluetooth_rfkill) { |
| 409 | rfkill_unregister(eeepc->bluetooth_rfkill); |
| 410 | rfkill_destroy(eeepc->bluetooth_rfkill); |
| 411 | eeepc->bluetooth_rfkill = NULL; |
| 412 | } |
| 413 | if (eeepc->wwan3g_rfkill) { |
| 414 | rfkill_unregister(eeepc->wwan3g_rfkill); |
| 415 | rfkill_destroy(eeepc->wwan3g_rfkill); |
| 416 | eeepc->wwan3g_rfkill = NULL; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc) |
| 421 | { |
| 422 | int result = 0; |
| 423 | |
| 424 | result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill, |
| 425 | "eeepc-wlan", RFKILL_TYPE_WLAN, |
| 426 | EEEPC_WMI_DEVID_WLAN); |
| 427 | |
| 428 | if (result && result != -ENODEV) |
| 429 | goto exit; |
| 430 | |
| 431 | result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill, |
| 432 | "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH, |
| 433 | EEEPC_WMI_DEVID_BLUETOOTH); |
| 434 | |
| 435 | if (result && result != -ENODEV) |
| 436 | goto exit; |
| 437 | |
| 438 | result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill, |
| 439 | "eeepc-wwan3g", RFKILL_TYPE_WWAN, |
| 440 | EEEPC_WMI_DEVID_WWAN3G); |
| 441 | |
| 442 | if (result && result != -ENODEV) |
| 443 | goto exit; |
| 444 | |
| 445 | exit: |
| 446 | if (result && result != -ENODEV) |
| 447 | eeepc_wmi_rfkill_exit(eeepc); |
| 448 | |
| 449 | if (result == -ENODEV) |
| 450 | result = 0; |
| 451 | |
| 452 | return result; |
| 453 | } |
| 454 | |
| 455 | /* |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 456 | * Backlight |
| 457 | */ |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 458 | static int read_brightness(struct backlight_device *bd) |
| 459 | { |
| 460 | static u32 ctrl_param; |
| 461 | acpi_status status; |
| 462 | |
| 463 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &ctrl_param); |
| 464 | |
| 465 | if (ACPI_FAILURE(status)) |
| 466 | return -1; |
| 467 | else |
| 468 | return ctrl_param & 0xFF; |
| 469 | } |
| 470 | |
| 471 | static int update_bl_status(struct backlight_device *bd) |
| 472 | { |
| 473 | |
| 474 | static u32 ctrl_param; |
| 475 | acpi_status status; |
| 476 | |
| 477 | ctrl_param = bd->props.brightness; |
| 478 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 479 | status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, |
| 480 | ctrl_param, NULL); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 481 | |
| 482 | if (ACPI_FAILURE(status)) |
| 483 | return -1; |
| 484 | else |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static const struct backlight_ops eeepc_wmi_bl_ops = { |
| 489 | .get_brightness = read_brightness, |
| 490 | .update_status = update_bl_status, |
| 491 | }; |
| 492 | |
| 493 | static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code) |
| 494 | { |
| 495 | struct backlight_device *bd = eeepc->backlight_device; |
| 496 | int old = bd->props.brightness; |
Daniel Mack | b7670ed | 2010-05-19 12:37:01 +0200 | [diff] [blame] | 497 | int new = old; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 498 | |
| 499 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 500 | new = code - NOTIFY_BRNUP_MIN + 1; |
| 501 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
| 502 | new = code - NOTIFY_BRNDOWN_MIN; |
| 503 | |
| 504 | bd->props.brightness = new; |
| 505 | backlight_update_status(bd); |
| 506 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); |
| 507 | |
| 508 | return old; |
| 509 | } |
| 510 | |
| 511 | static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc) |
| 512 | { |
| 513 | struct backlight_device *bd; |
| 514 | struct backlight_properties props; |
| 515 | |
| 516 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 517 | props.max_brightness = 15; |
| 518 | bd = backlight_device_register(EEEPC_WMI_FILE, |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 519 | &eeepc->platform_device->dev, eeepc, |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 520 | &eeepc_wmi_bl_ops, &props); |
| 521 | if (IS_ERR(bd)) { |
| 522 | pr_err("Could not register backlight device\n"); |
| 523 | return PTR_ERR(bd); |
| 524 | } |
| 525 | |
| 526 | eeepc->backlight_device = bd; |
| 527 | |
| 528 | bd->props.brightness = read_brightness(bd); |
| 529 | bd->props.power = FB_BLANK_UNBLANK; |
| 530 | backlight_update_status(bd); |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc) |
| 536 | { |
| 537 | if (eeepc->backlight_device) |
| 538 | backlight_device_unregister(eeepc->backlight_device); |
| 539 | |
| 540 | eeepc->backlight_device = NULL; |
| 541 | } |
| 542 | |
| 543 | static void eeepc_wmi_notify(u32 value, void *context) |
| 544 | { |
| 545 | struct eeepc_wmi *eeepc = context; |
| 546 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 547 | union acpi_object *obj; |
| 548 | acpi_status status; |
| 549 | int code; |
| 550 | int orig_code; |
| 551 | |
| 552 | status = wmi_get_event_data(value, &response); |
| 553 | if (status != AE_OK) { |
| 554 | pr_err("bad event status 0x%x\n", status); |
| 555 | return; |
| 556 | } |
| 557 | |
| 558 | obj = (union acpi_object *)response.pointer; |
| 559 | |
| 560 | if (obj && obj->type == ACPI_TYPE_INTEGER) { |
| 561 | code = obj->integer.value; |
| 562 | orig_code = code; |
| 563 | |
| 564 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 565 | code = NOTIFY_BRNUP_MIN; |
| 566 | else if (code >= NOTIFY_BRNDOWN_MIN && |
| 567 | code <= NOTIFY_BRNDOWN_MAX) |
| 568 | code = NOTIFY_BRNDOWN_MIN; |
| 569 | |
| 570 | if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) { |
| 571 | if (!acpi_video_backlight_support()) |
| 572 | eeepc_wmi_backlight_notify(eeepc, orig_code); |
| 573 | } |
| 574 | |
| 575 | if (!sparse_keymap_report_event(eeepc->inputdev, |
| 576 | code, 1, true)) |
| 577 | pr_info("Unknown key %x pressed\n", code); |
| 578 | } |
| 579 | |
| 580 | kfree(obj); |
| 581 | } |
| 582 | |
Dmitry Torokhov | 67fa38e | 2010-11-03 11:14:01 -0700 | [diff] [blame] | 583 | static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr, |
| 584 | const char *buf, size_t count) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 585 | { |
| 586 | int value; |
| 587 | struct acpi_buffer input = { (acpi_size)sizeof(value), &value }; |
| 588 | acpi_status status; |
| 589 | |
| 590 | if (!count || sscanf(buf, "%i", &value) != 1) |
| 591 | return -EINVAL; |
| 592 | if (value < 0 || value > 2) |
| 593 | return -EINVAL; |
| 594 | |
| 595 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, |
| 596 | 1, EEEPC_WMI_METHODID_CFVS, &input, NULL); |
| 597 | |
| 598 | if (ACPI_FAILURE(status)) |
| 599 | return -EIO; |
| 600 | else |
| 601 | return count; |
| 602 | } |
| 603 | |
| 604 | static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv); |
| 605 | |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 606 | static struct attribute *platform_attributes[] = { |
| 607 | &dev_attr_cpufv.attr, |
| 608 | NULL |
| 609 | }; |
| 610 | |
| 611 | static struct attribute_group platform_attribute_group = { |
| 612 | .attrs = platform_attributes |
| 613 | }; |
| 614 | |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 615 | static void eeepc_wmi_sysfs_exit(struct platform_device *device) |
| 616 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 617 | sysfs_remove_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static int eeepc_wmi_sysfs_init(struct platform_device *device) |
| 621 | { |
Corentin Chary | 4e37b42 | 2010-11-29 08:14:08 +0100 | [diff] [blame] | 622 | return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 625 | /* |
| 626 | * Platform device |
| 627 | */ |
| 628 | static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc) |
| 629 | { |
| 630 | int err; |
| 631 | |
| 632 | eeepc->platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1); |
| 633 | if (!eeepc->platform_device) |
| 634 | return -ENOMEM; |
| 635 | platform_set_drvdata(eeepc->platform_device, eeepc); |
| 636 | |
| 637 | err = platform_device_add(eeepc->platform_device); |
| 638 | if (err) |
| 639 | goto fail_platform_device; |
| 640 | |
| 641 | err = eeepc_wmi_sysfs_init(eeepc->platform_device); |
| 642 | if (err) |
| 643 | goto fail_sysfs; |
| 644 | return 0; |
| 645 | |
| 646 | fail_sysfs: |
| 647 | platform_device_del(eeepc->platform_device); |
| 648 | fail_platform_device: |
| 649 | platform_device_put(eeepc->platform_device); |
| 650 | return err; |
| 651 | } |
| 652 | |
| 653 | static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc) |
| 654 | { |
| 655 | eeepc_wmi_sysfs_exit(eeepc->platform_device); |
| 656 | platform_device_unregister(eeepc->platform_device); |
| 657 | } |
| 658 | |
| 659 | /* |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 660 | * debugfs |
| 661 | */ |
| 662 | struct eeepc_wmi_debugfs_node { |
| 663 | struct eeepc_wmi *eeepc; |
| 664 | char *name; |
| 665 | int (*show)(struct seq_file *m, void *data); |
| 666 | }; |
| 667 | |
| 668 | static int show_dsts(struct seq_file *m, void *data) |
| 669 | { |
| 670 | struct eeepc_wmi *eeepc = m->private; |
| 671 | acpi_status status; |
| 672 | u32 retval = -1; |
| 673 | |
| 674 | status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval); |
| 675 | |
| 676 | if (ACPI_FAILURE(status)) |
| 677 | return -EIO; |
| 678 | |
| 679 | seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval); |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | static int show_devs(struct seq_file *m, void *data) |
| 685 | { |
| 686 | struct eeepc_wmi *eeepc = m->private; |
| 687 | acpi_status status; |
| 688 | u32 retval = -1; |
| 689 | |
| 690 | status = eeepc_wmi_set_devstate(eeepc->debug.dev_id, |
| 691 | eeepc->debug.ctrl_param, &retval); |
| 692 | if (ACPI_FAILURE(status)) |
| 693 | return -EIO; |
| 694 | |
| 695 | seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id, |
| 696 | eeepc->debug.ctrl_param, retval); |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = { |
| 702 | { NULL, "devs", show_devs }, |
| 703 | { NULL, "dsts", show_dsts }, |
| 704 | }; |
| 705 | |
| 706 | static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file) |
| 707 | { |
| 708 | struct eeepc_wmi_debugfs_node *node = inode->i_private; |
| 709 | |
| 710 | return single_open(file, node->show, node->eeepc); |
| 711 | } |
| 712 | |
| 713 | static const struct file_operations eeepc_wmi_debugfs_io_ops = { |
| 714 | .owner = THIS_MODULE, |
| 715 | .open = eeepc_wmi_debugfs_open, |
| 716 | .read = seq_read, |
| 717 | .llseek = seq_lseek, |
| 718 | .release = single_release, |
| 719 | }; |
| 720 | |
| 721 | static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc) |
| 722 | { |
| 723 | debugfs_remove_recursive(eeepc->debug.root); |
| 724 | } |
| 725 | |
| 726 | static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc) |
| 727 | { |
| 728 | struct dentry *dent; |
| 729 | int i; |
| 730 | |
| 731 | eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL); |
| 732 | if (!eeepc->debug.root) { |
| 733 | pr_err("failed to create debugfs directory"); |
| 734 | goto error_debugfs; |
| 735 | } |
| 736 | |
| 737 | dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR, |
| 738 | eeepc->debug.root, &eeepc->debug.dev_id); |
| 739 | if (!dent) |
| 740 | goto error_debugfs; |
| 741 | |
| 742 | dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR, |
| 743 | eeepc->debug.root, &eeepc->debug.ctrl_param); |
| 744 | if (!dent) |
| 745 | goto error_debugfs; |
| 746 | |
| 747 | for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) { |
| 748 | struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i]; |
| 749 | |
| 750 | node->eeepc = eeepc; |
| 751 | dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO, |
| 752 | eeepc->debug.root, node, |
| 753 | &eeepc_wmi_debugfs_io_ops); |
| 754 | if (!dent) { |
| 755 | pr_err("failed to create debug file: %s\n", node->name); |
| 756 | goto error_debugfs; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | return 0; |
| 761 | |
| 762 | error_debugfs: |
| 763 | eeepc_wmi_debugfs_exit(eeepc); |
| 764 | return -ENOMEM; |
| 765 | } |
| 766 | |
| 767 | /* |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 768 | * WMI Driver |
| 769 | */ |
| 770 | static struct platform_device * __init eeepc_wmi_add(void) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 771 | { |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 772 | struct eeepc_wmi *eeepc; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 773 | acpi_status status; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 774 | int err; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 775 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 776 | eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); |
| 777 | if (!eeepc) |
| 778 | return ERR_PTR(-ENOMEM); |
| 779 | |
| 780 | /* |
| 781 | * Register the platform device first. It is used as a parent for the |
| 782 | * sub-devices below. |
| 783 | */ |
| 784 | err = eeepc_wmi_platform_init(eeepc); |
| 785 | if (err) |
| 786 | goto fail_platform; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 787 | |
| 788 | err = eeepc_wmi_input_init(eeepc); |
| 789 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 790 | goto fail_input; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 791 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 792 | err = eeepc_wmi_led_init(eeepc); |
| 793 | if (err) |
| 794 | goto fail_leds; |
| 795 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 796 | err = eeepc_wmi_rfkill_init(eeepc); |
| 797 | if (err) |
| 798 | goto fail_rfkill; |
| 799 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 800 | if (!acpi_video_backlight_support()) { |
| 801 | err = eeepc_wmi_backlight_init(eeepc); |
| 802 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 803 | goto fail_backlight; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 804 | } else |
| 805 | pr_info("Backlight controlled by ACPI video driver\n"); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 806 | |
| 807 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 808 | eeepc_wmi_notify, eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 809 | if (ACPI_FAILURE(status)) { |
| 810 | pr_err("Unable to register notify handler - %d\n", |
| 811 | status); |
| 812 | err = -ENODEV; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 813 | goto fail_wmi_handler; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 814 | } |
| 815 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 816 | err = eeepc_wmi_debugfs_init(eeepc); |
| 817 | if (err) |
| 818 | goto fail_debugfs; |
| 819 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 820 | return eeepc->platform_device; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 821 | |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 822 | fail_debugfs: |
| 823 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 824 | fail_wmi_handler: |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 825 | eeepc_wmi_backlight_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 826 | fail_backlight: |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 827 | eeepc_wmi_rfkill_exit(eeepc); |
| 828 | fail_rfkill: |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 829 | eeepc_wmi_led_exit(eeepc); |
| 830 | fail_leds: |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 831 | eeepc_wmi_input_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 832 | fail_input: |
| 833 | eeepc_wmi_platform_exit(eeepc); |
| 834 | fail_platform: |
| 835 | kfree(eeepc); |
| 836 | return ERR_PTR(err); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 837 | } |
| 838 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 839 | static int eeepc_wmi_remove(struct platform_device *device) |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 840 | { |
| 841 | struct eeepc_wmi *eeepc; |
| 842 | |
| 843 | eeepc = platform_get_drvdata(device); |
| 844 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 845 | eeepc_wmi_backlight_exit(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 846 | eeepc_wmi_input_exit(eeepc); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 847 | eeepc_wmi_led_exit(eeepc); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame] | 848 | eeepc_wmi_rfkill_exit(eeepc); |
Corentin Chary | 8c1b2d8 | 2010-11-29 08:14:09 +0100 | [diff] [blame^] | 849 | eeepc_wmi_debugfs_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 850 | eeepc_wmi_platform_exit(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 851 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 852 | kfree(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | static struct platform_driver platform_driver = { |
| 857 | .driver = { |
| 858 | .name = EEEPC_WMI_FILE, |
| 859 | .owner = THIS_MODULE, |
| 860 | }, |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | static int __init eeepc_wmi_init(void) |
| 864 | { |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 865 | int err; |
| 866 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 867 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) || |
| 868 | !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 869 | pr_warning("No known WMI GUID found\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 870 | return -ENODEV; |
| 871 | } |
| 872 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 873 | platform_device = eeepc_wmi_add(); |
| 874 | if (IS_ERR(platform_device)) { |
| 875 | err = PTR_ERR(platform_device); |
| 876 | goto fail_eeepc_wmi; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 877 | } |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 878 | |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 879 | err = platform_driver_register(&platform_driver); |
| 880 | if (err) { |
| 881 | pr_warning("Unable to register platform driver\n"); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 882 | goto fail_platform_driver; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | return 0; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 886 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 887 | fail_platform_driver: |
| 888 | eeepc_wmi_remove(platform_device); |
| 889 | fail_eeepc_wmi: |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 890 | return err; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static void __exit eeepc_wmi_exit(void) |
| 894 | { |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 895 | eeepc_wmi_remove(platform_device); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 896 | platform_driver_unregister(&platform_driver); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | module_init(eeepc_wmi_init); |
| 900 | module_exit(eeepc_wmi_exit); |