Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1 | /* |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 2 | * eeepc-laptop.c - Asus Eee PC extras |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 3 | * |
| 4 | * Based on asus_acpi.c as patched for the Eee PC by Asus: |
| 5 | * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar |
| 6 | * Based on eee.c from eeepc-linux |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/platform_device.h> |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 26 | #include <linux/backlight.h> |
| 27 | #include <linux/fb.h> |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 28 | #include <linux/hwmon.h> |
| 29 | #include <linux/hwmon-sysfs.h> |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 30 | #include <acpi/acpi_drivers.h> |
| 31 | #include <acpi/acpi_bus.h> |
| 32 | #include <linux/uaccess.h> |
Matthew Garrett | a195dcd | 2008-08-19 12:13:20 +0100 | [diff] [blame] | 33 | #include <linux/input.h> |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 34 | #include <linux/input/sparse-keymap.h> |
Matthew Garrett | a195dcd | 2008-08-19 12:13:20 +0100 | [diff] [blame] | 35 | #include <linux/rfkill.h> |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 36 | #include <linux/pci.h> |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 37 | #include <linux/pci_hotplug.h> |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 38 | #include <linux/leds.h> |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 39 | #include <linux/dmi.h> |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 40 | |
| 41 | #define EEEPC_LAPTOP_VERSION "0.1" |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 42 | #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver" |
| 43 | #define EEEPC_LAPTOP_FILE "eeepc" |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 44 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 45 | #define EEEPC_ACPI_CLASS "hotkey" |
| 46 | #define EEEPC_ACPI_DEVICE_NAME "Hotkey" |
| 47 | #define EEEPC_ACPI_HID "ASUS010" |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 48 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 49 | MODULE_AUTHOR("Corentin Chary, Eric Cooper"); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 50 | MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 51 | MODULE_LICENSE("GPL"); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * Definitions for Asus EeePC |
| 55 | */ |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 56 | #define NOTIFY_BRN_MIN 0x20 |
| 57 | #define NOTIFY_BRN_MAX 0x2f |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 58 | |
| 59 | enum { |
| 60 | DISABLE_ASL_WLAN = 0x0001, |
| 61 | DISABLE_ASL_BLUETOOTH = 0x0002, |
| 62 | DISABLE_ASL_IRDA = 0x0004, |
| 63 | DISABLE_ASL_CAMERA = 0x0008, |
| 64 | DISABLE_ASL_TV = 0x0010, |
| 65 | DISABLE_ASL_GPS = 0x0020, |
| 66 | DISABLE_ASL_DISPLAYSWITCH = 0x0040, |
| 67 | DISABLE_ASL_MODEM = 0x0080, |
Corentin Chary | b7b700d | 2009-06-16 19:28:52 +0000 | [diff] [blame] | 68 | DISABLE_ASL_CARDREADER = 0x0100, |
| 69 | DISABLE_ASL_3G = 0x0200, |
| 70 | DISABLE_ASL_WIMAX = 0x0400, |
| 71 | DISABLE_ASL_HWCF = 0x0800 |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | enum { |
| 75 | CM_ASL_WLAN = 0, |
| 76 | CM_ASL_BLUETOOTH, |
| 77 | CM_ASL_IRDA, |
| 78 | CM_ASL_1394, |
| 79 | CM_ASL_CAMERA, |
| 80 | CM_ASL_TV, |
| 81 | CM_ASL_GPS, |
| 82 | CM_ASL_DVDROM, |
| 83 | CM_ASL_DISPLAYSWITCH, |
| 84 | CM_ASL_PANELBRIGHT, |
| 85 | CM_ASL_BIOSFLASH, |
| 86 | CM_ASL_ACPIFLASH, |
| 87 | CM_ASL_CPUFV, |
| 88 | CM_ASL_CPUTEMPERATURE, |
| 89 | CM_ASL_FANCPU, |
| 90 | CM_ASL_FANCHASSIS, |
| 91 | CM_ASL_USBPORT1, |
| 92 | CM_ASL_USBPORT2, |
| 93 | CM_ASL_USBPORT3, |
| 94 | CM_ASL_MODEM, |
| 95 | CM_ASL_CARDREADER, |
Corentin Chary | b7b700d | 2009-06-16 19:28:52 +0000 | [diff] [blame] | 96 | CM_ASL_3G, |
| 97 | CM_ASL_WIMAX, |
| 98 | CM_ASL_HWCF, |
| 99 | CM_ASL_LID, |
| 100 | CM_ASL_TYPE, |
| 101 | CM_ASL_PANELPOWER, /*P901*/ |
| 102 | CM_ASL_TPD |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
Adrian Bunk | 1410946 | 2008-06-25 19:25:47 +0300 | [diff] [blame] | 105 | static const char *cm_getv[] = { |
Jonathan McDowell | 3af9bfc | 2008-12-03 20:31:11 +0000 | [diff] [blame] | 106 | "WLDG", "BTHG", NULL, NULL, |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 107 | "CAMG", NULL, NULL, NULL, |
| 108 | NULL, "PBLG", NULL, NULL, |
| 109 | "CFVG", NULL, NULL, NULL, |
| 110 | "USBG", NULL, NULL, "MODG", |
Corentin Chary | b7b700d | 2009-06-16 19:28:52 +0000 | [diff] [blame] | 111 | "CRDG", "M3GG", "WIMG", "HWCF", |
| 112 | "LIDG", "TYPE", "PBPG", "TPDG" |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
Adrian Bunk | 1410946 | 2008-06-25 19:25:47 +0300 | [diff] [blame] | 115 | static const char *cm_setv[] = { |
Jonathan McDowell | 3af9bfc | 2008-12-03 20:31:11 +0000 | [diff] [blame] | 116 | "WLDS", "BTHS", NULL, NULL, |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 117 | "CAMS", NULL, NULL, NULL, |
| 118 | "SDSP", "PBLS", "HDPS", NULL, |
| 119 | "CFVS", NULL, NULL, NULL, |
| 120 | "USBG", NULL, NULL, "MODS", |
Corentin Chary | b7b700d | 2009-06-16 19:28:52 +0000 | [diff] [blame] | 121 | "CRDS", "M3GS", "WIMS", NULL, |
| 122 | NULL, NULL, "PBPS", "TPDS" |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 125 | static const struct key_entry eeepc_keymap[] = { |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 126 | { KE_KEY, 0x10, { KEY_WLAN } }, |
| 127 | { KE_KEY, 0x11, { KEY_WLAN } }, |
| 128 | { KE_KEY, 0x12, { KEY_PROG1 } }, |
| 129 | { KE_KEY, 0x13, { KEY_MUTE } }, |
| 130 | { KE_KEY, 0x14, { KEY_VOLUMEDOWN } }, |
| 131 | { KE_KEY, 0x15, { KEY_VOLUMEUP } }, |
| 132 | { KE_KEY, 0x16, { KEY_DISPLAY_OFF } }, |
| 133 | { KE_KEY, 0x1a, { KEY_COFFEE } }, |
| 134 | { KE_KEY, 0x1b, { KEY_ZOOM } }, |
| 135 | { KE_KEY, 0x1c, { KEY_PROG2 } }, |
| 136 | { KE_KEY, 0x1d, { KEY_PROG3 } }, |
| 137 | { KE_KEY, NOTIFY_BRN_MIN, { KEY_BRIGHTNESSDOWN } }, |
| 138 | { KE_KEY, NOTIFY_BRN_MAX, { KEY_BRIGHTNESSUP } }, |
| 139 | { KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } }, |
| 140 | { KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } }, |
| 141 | { KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } }, |
| 142 | { KE_KEY, 0x37, { KEY_F13 } }, /* Disable Touchpad */ |
| 143 | { KE_KEY, 0x38, { KEY_F14 } }, |
| 144 | { KE_END, 0 }, |
Matthew Garrett | a195dcd | 2008-08-19 12:13:20 +0100 | [diff] [blame] | 145 | }; |
| 146 | |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 147 | /* |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 148 | * This is the main structure, we can use it to store useful information |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 149 | */ |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 150 | struct eeepc_laptop { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 151 | acpi_handle handle; /* the handle of the acpi device */ |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 152 | u32 cm_supported; /* the control methods supported |
| 153 | by this BIOS */ |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 154 | bool cpufv_disabled; |
Corentin Chary | 10ae4b5 | 2010-01-06 22:07:38 +0100 | [diff] [blame] | 155 | bool hotplug_disabled; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 156 | u16 event_count[128]; /* count for each event */ |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 157 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 158 | struct platform_device *platform_device; |
| 159 | struct device *hwmon_device; |
| 160 | struct backlight_device *backlight_device; |
| 161 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 162 | struct input_dev *inputdev; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 163 | struct key_entry *keymap; |
| 164 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 165 | struct rfkill *wlan_rfkill; |
| 166 | struct rfkill *bluetooth_rfkill; |
| 167 | struct rfkill *wwan3g_rfkill; |
| 168 | struct rfkill *wimax_rfkill; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 169 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 170 | struct hotplug_slot *hotplug_slot; |
| 171 | struct mutex hotplug_lock; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 172 | |
| 173 | struct led_classdev tpd_led; |
| 174 | int tpd_led_wk; |
| 175 | struct workqueue_struct *led_workqueue; |
| 176 | struct work_struct tpd_led_work; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 177 | }; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * ACPI Helpers |
| 181 | */ |
Alan Jenkins | 6b188a7 | 2009-12-03 07:45:02 +0000 | [diff] [blame] | 182 | static int write_acpi_int(acpi_handle handle, const char *method, int val) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 183 | { |
| 184 | struct acpi_object_list params; |
| 185 | union acpi_object in_obj; |
| 186 | acpi_status status; |
| 187 | |
| 188 | params.count = 1; |
| 189 | params.pointer = &in_obj; |
| 190 | in_obj.type = ACPI_TYPE_INTEGER; |
| 191 | in_obj.integer.value = val; |
| 192 | |
Alan Jenkins | 6b188a7 | 2009-12-03 07:45:02 +0000 | [diff] [blame] | 193 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, NULL); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 194 | return (status == AE_OK ? 0 : -1); |
| 195 | } |
| 196 | |
| 197 | static int read_acpi_int(acpi_handle handle, const char *method, int *val) |
| 198 | { |
| 199 | acpi_status status; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 200 | unsigned long long result; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 201 | |
| 202 | status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); |
| 203 | if (ACPI_FAILURE(status)) { |
| 204 | *val = -1; |
| 205 | return -1; |
| 206 | } else { |
| 207 | *val = result; |
| 208 | return 0; |
| 209 | } |
| 210 | } |
| 211 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 212 | static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 213 | { |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 214 | const char *method = cm_setv[cm]; |
| 215 | |
| 216 | if (method == NULL) |
| 217 | return -ENODEV; |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 218 | if ((eeepc->cm_supported & (0x1 << cm)) == 0) |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 219 | return -ENODEV; |
| 220 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 221 | if (write_acpi_int(eeepc->handle, method, value)) |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 222 | pr_warning("Error writing %s\n", method); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 226 | static int get_acpi(struct eeepc_laptop *eeepc, int cm) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 227 | { |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 228 | const char *method = cm_getv[cm]; |
| 229 | int value; |
| 230 | |
| 231 | if (method == NULL) |
| 232 | return -ENODEV; |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 233 | if ((eeepc->cm_supported & (0x1 << cm)) == 0) |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 234 | return -ENODEV; |
| 235 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 236 | if (read_acpi_int(eeepc->handle, method, &value)) |
Alan Jenkins | 13f7002 | 2009-12-03 07:44:59 +0000 | [diff] [blame] | 237 | pr_warning("Error reading %s\n", method); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 238 | return value; |
| 239 | } |
| 240 | |
Corentin Chary | f90be87 | 2009-12-03 07:45:14 +0000 | [diff] [blame] | 241 | static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm, |
| 242 | acpi_handle *handle) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 243 | { |
| 244 | const char *method = cm_setv[cm]; |
| 245 | acpi_status status; |
| 246 | |
| 247 | if (method == NULL) |
| 248 | return -ENODEV; |
| 249 | if ((eeepc->cm_supported & (0x1 << cm)) == 0) |
| 250 | return -ENODEV; |
| 251 | |
| 252 | status = acpi_get_handle(eeepc->handle, (char *)method, |
Corentin Chary | f90be87 | 2009-12-03 07:45:14 +0000 | [diff] [blame] | 253 | handle); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 254 | if (status != AE_OK) { |
| 255 | pr_warning("Error finding %s\n", method); |
| 256 | return -ENODEV; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 257 | } |
| 258 | return 0; |
| 259 | } |
| 260 | |
Pekka Enberg | cede2cb | 2009-06-16 19:28:45 +0000 | [diff] [blame] | 261 | |
Matthew Garrett | a195dcd | 2008-08-19 12:13:20 +0100 | [diff] [blame] | 262 | /* |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 263 | * Sys helpers |
| 264 | */ |
| 265 | static int parse_arg(const char *buf, unsigned long count, int *val) |
| 266 | { |
| 267 | if (!count) |
| 268 | return 0; |
| 269 | if (sscanf(buf, "%i", val) != 1) |
| 270 | return -EINVAL; |
| 271 | return count; |
| 272 | } |
| 273 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 274 | static ssize_t store_sys_acpi(struct device *dev, int cm, |
| 275 | const char *buf, size_t count) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 276 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 277 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 278 | int rv, value; |
| 279 | |
| 280 | rv = parse_arg(buf, count, &value); |
| 281 | if (rv > 0) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 282 | value = set_acpi(eeepc, cm, value); |
Corentin Chary | f36509e | 2009-06-25 13:25:40 +0200 | [diff] [blame] | 283 | if (value < 0) |
Alan Jenkins | 6dff29b | 2009-12-03 07:44:45 +0000 | [diff] [blame] | 284 | return -EIO; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 285 | return rv; |
| 286 | } |
| 287 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 288 | static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 289 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 290 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
| 291 | int value = get_acpi(eeepc, cm); |
Corentin Chary | f36509e | 2009-06-25 13:25:40 +0200 | [diff] [blame] | 292 | |
| 293 | if (value < 0) |
Alan Jenkins | 6dff29b | 2009-12-03 07:44:45 +0000 | [diff] [blame] | 294 | return -EIO; |
Corentin Chary | f36509e | 2009-06-25 13:25:40 +0200 | [diff] [blame] | 295 | return sprintf(buf, "%d\n", value); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Alan Jenkins | 6dff29b | 2009-12-03 07:44:45 +0000 | [diff] [blame] | 298 | #define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 299 | static ssize_t show_##_name(struct device *dev, \ |
| 300 | struct device_attribute *attr, \ |
| 301 | char *buf) \ |
| 302 | { \ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 303 | return show_sys_acpi(dev, _cm, buf); \ |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 304 | } \ |
| 305 | static ssize_t store_##_name(struct device *dev, \ |
| 306 | struct device_attribute *attr, \ |
| 307 | const char *buf, size_t count) \ |
| 308 | { \ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 309 | return store_sys_acpi(dev, _cm, buf, count); \ |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 310 | } \ |
| 311 | static struct device_attribute dev_attr_##_name = { \ |
| 312 | .attr = { \ |
| 313 | .name = __stringify(_name), \ |
Alan Jenkins | 6dff29b | 2009-12-03 07:44:45 +0000 | [diff] [blame] | 314 | .mode = _mode }, \ |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 315 | .show = show_##_name, \ |
| 316 | .store = store_##_name, \ |
| 317 | } |
| 318 | |
Alan Jenkins | 6dff29b | 2009-12-03 07:44:45 +0000 | [diff] [blame] | 319 | EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA); |
| 320 | EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER); |
| 321 | EEEPC_CREATE_DEVICE_ATTR(disp, 0200, CM_ASL_DISPLAYSWITCH); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 322 | |
| 323 | struct eeepc_cpufv { |
| 324 | int num; |
| 325 | int cur; |
| 326 | }; |
| 327 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 328 | static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c) |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 329 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 330 | c->cur = get_acpi(eeepc, CM_ASL_CPUFV); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 331 | c->num = (c->cur >> 8) & 0xff; |
| 332 | c->cur &= 0xff; |
| 333 | if (c->cur < 0 || c->num <= 0 || c->num > 12) |
| 334 | return -ENODEV; |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static ssize_t show_available_cpufv(struct device *dev, |
| 339 | struct device_attribute *attr, |
| 340 | char *buf) |
| 341 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 342 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 343 | struct eeepc_cpufv c; |
| 344 | int i; |
| 345 | ssize_t len = 0; |
| 346 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 347 | if (get_cpufv(eeepc, &c)) |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 348 | return -ENODEV; |
| 349 | for (i = 0; i < c.num; i++) |
| 350 | len += sprintf(buf + len, "%d ", i); |
| 351 | len += sprintf(buf + len, "\n"); |
| 352 | return len; |
| 353 | } |
| 354 | |
| 355 | static ssize_t show_cpufv(struct device *dev, |
| 356 | struct device_attribute *attr, |
| 357 | char *buf) |
| 358 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 359 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 360 | struct eeepc_cpufv c; |
| 361 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 362 | if (get_cpufv(eeepc, &c)) |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 363 | return -ENODEV; |
| 364 | return sprintf(buf, "%#x\n", (c.num << 8) | c.cur); |
| 365 | } |
| 366 | |
| 367 | static ssize_t store_cpufv(struct device *dev, |
| 368 | struct device_attribute *attr, |
| 369 | const char *buf, size_t count) |
| 370 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 371 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 372 | struct eeepc_cpufv c; |
| 373 | int rv, value; |
| 374 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 375 | if (eeepc->cpufv_disabled) |
| 376 | return -EPERM; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 377 | if (get_cpufv(eeepc, &c)) |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 378 | return -ENODEV; |
| 379 | rv = parse_arg(buf, count, &value); |
| 380 | if (rv < 0) |
| 381 | return rv; |
| 382 | if (!rv || value < 0 || value >= c.num) |
| 383 | return -EINVAL; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 384 | set_acpi(eeepc, CM_ASL_CPUFV, value); |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 385 | return rv; |
| 386 | } |
| 387 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 388 | static ssize_t show_cpufv_disabled(struct device *dev, |
| 389 | struct device_attribute *attr, |
| 390 | char *buf) |
| 391 | { |
| 392 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
| 393 | |
| 394 | return sprintf(buf, "%d\n", eeepc->cpufv_disabled); |
| 395 | } |
| 396 | |
| 397 | static ssize_t store_cpufv_disabled(struct device *dev, |
| 398 | struct device_attribute *attr, |
| 399 | const char *buf, size_t count) |
| 400 | { |
| 401 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); |
| 402 | int rv, value; |
| 403 | |
| 404 | rv = parse_arg(buf, count, &value); |
| 405 | if (rv < 0) |
| 406 | return rv; |
| 407 | |
| 408 | switch (value) { |
| 409 | case 0: |
| 410 | if (eeepc->cpufv_disabled) |
| 411 | pr_warning("cpufv enabled (not officially supported " |
| 412 | "on this model)\n"); |
| 413 | eeepc->cpufv_disabled = false; |
| 414 | return rv; |
| 415 | case 1: |
| 416 | return -EPERM; |
| 417 | default: |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 423 | static struct device_attribute dev_attr_cpufv = { |
| 424 | .attr = { |
| 425 | .name = "cpufv", |
| 426 | .mode = 0644 }, |
| 427 | .show = show_cpufv, |
| 428 | .store = store_cpufv |
| 429 | }; |
| 430 | |
| 431 | static struct device_attribute dev_attr_available_cpufv = { |
| 432 | .attr = { |
| 433 | .name = "available_cpufv", |
| 434 | .mode = 0444 }, |
| 435 | .show = show_available_cpufv |
| 436 | }; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 437 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 438 | static struct device_attribute dev_attr_cpufv_disabled = { |
| 439 | .attr = { |
| 440 | .name = "cpufv_disabled", |
| 441 | .mode = 0644 }, |
| 442 | .show = show_cpufv_disabled, |
| 443 | .store = store_cpufv_disabled |
| 444 | }; |
| 445 | |
| 446 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 447 | static struct attribute *platform_attributes[] = { |
| 448 | &dev_attr_camera.attr, |
| 449 | &dev_attr_cardr.attr, |
| 450 | &dev_attr_disp.attr, |
Grigori Goronzy | 158ca1d | 2009-04-27 09:23:40 +0200 | [diff] [blame] | 451 | &dev_attr_cpufv.attr, |
Corentin Chary | b31d0fd | 2009-06-16 19:28:56 +0000 | [diff] [blame] | 452 | &dev_attr_available_cpufv.attr, |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 453 | &dev_attr_cpufv_disabled.attr, |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 454 | NULL |
| 455 | }; |
| 456 | |
| 457 | static struct attribute_group platform_attribute_group = { |
| 458 | .attrs = platform_attributes |
| 459 | }; |
| 460 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 461 | static int eeepc_platform_init(struct eeepc_laptop *eeepc) |
Matthew Garrett | a195dcd | 2008-08-19 12:13:20 +0100 | [diff] [blame] | 462 | { |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 463 | int result; |
| 464 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 465 | eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1); |
| 466 | if (!eeepc->platform_device) |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 467 | return -ENOMEM; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 468 | platform_set_drvdata(eeepc->platform_device, eeepc); |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 469 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 470 | result = platform_device_add(eeepc->platform_device); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 471 | if (result) |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 472 | goto fail_platform_device; |
| 473 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 474 | result = sysfs_create_group(&eeepc->platform_device->dev.kobj, |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 475 | &platform_attribute_group); |
| 476 | if (result) |
| 477 | goto fail_sysfs; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 478 | return 0; |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 479 | |
| 480 | fail_sysfs: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 481 | platform_device_del(eeepc->platform_device); |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 482 | fail_platform_device: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 483 | platform_device_put(eeepc->platform_device); |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 484 | return result; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 485 | } |
| 486 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 487 | static void eeepc_platform_exit(struct eeepc_laptop *eeepc) |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 488 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 489 | sysfs_remove_group(&eeepc->platform_device->dev.kobj, |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 490 | &platform_attribute_group); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 491 | platform_device_unregister(eeepc->platform_device); |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 494 | /* |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 495 | * LEDs |
| 496 | */ |
| 497 | /* |
| 498 | * These functions actually update the LED's, and are called from a |
| 499 | * workqueue. By doing this as separate work rather than when the LED |
| 500 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a |
| 501 | * potentially bad time, such as a timer interrupt. |
| 502 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 503 | static void tpd_led_update(struct work_struct *work) |
| 504 | { |
| 505 | struct eeepc_laptop *eeepc; |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 506 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 507 | eeepc = container_of(work, struct eeepc_laptop, tpd_led_work); |
| 508 | |
| 509 | set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk); |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 512 | static void tpd_led_set(struct led_classdev *led_cdev, |
| 513 | enum led_brightness value) |
| 514 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 515 | struct eeepc_laptop *eeepc; |
| 516 | |
| 517 | eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led); |
| 518 | |
| 519 | eeepc->tpd_led_wk = (value > 0) ? 1 : 0; |
| 520 | queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work); |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 523 | static int eeepc_led_init(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 524 | { |
| 525 | int rv; |
| 526 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 527 | if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 528 | return 0; |
| 529 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 530 | eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 531 | if (!eeepc->led_workqueue) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 532 | return -ENOMEM; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 533 | INIT_WORK(&eeepc->tpd_led_work, tpd_led_update); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 534 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 535 | eeepc->tpd_led.name = "eeepc::touchpad"; |
| 536 | eeepc->tpd_led.brightness_set = tpd_led_set; |
| 537 | eeepc->tpd_led.max_brightness = 1; |
| 538 | |
| 539 | rv = led_classdev_register(&eeepc->platform_device->dev, |
| 540 | &eeepc->tpd_led); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 541 | if (rv) { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 542 | destroy_workqueue(eeepc->led_workqueue); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 543 | return rv; |
Darren Salt | 64b86b6 | 2009-04-27 09:23:38 +0200 | [diff] [blame] | 544 | } |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 549 | static void eeepc_led_exit(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 550 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 551 | if (eeepc->tpd_led.dev) |
| 552 | led_classdev_unregister(&eeepc->tpd_led); |
| 553 | if (eeepc->led_workqueue) |
| 554 | destroy_workqueue(eeepc->led_workqueue); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 558 | /* |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 559 | * PCI hotplug (for wlan rfkill) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 560 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 561 | static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 562 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 563 | if (get_acpi(eeepc, CM_ASL_WLAN) == 1) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 564 | return false; |
| 565 | return true; |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 568 | static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc) |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 569 | { |
| 570 | struct pci_dev *dev; |
Alan Jenkins | 6d41839 | 2009-08-28 12:56:32 +0000 | [diff] [blame] | 571 | struct pci_bus *bus; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 572 | bool blocked = eeepc_wlan_rfkill_blocked(eeepc); |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 573 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 574 | if (eeepc->wlan_rfkill) |
| 575 | rfkill_set_sw_state(eeepc->wlan_rfkill, blocked); |
Alan Jenkins | 6d41839 | 2009-08-28 12:56:32 +0000 | [diff] [blame] | 576 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 577 | mutex_lock(&eeepc->hotplug_lock); |
Alan Jenkins | dcf443b | 2009-08-28 12:56:33 +0000 | [diff] [blame] | 578 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 579 | if (eeepc->hotplug_slot) { |
Alan Jenkins | 07e84aa | 2009-08-28 12:56:34 +0000 | [diff] [blame] | 580 | bus = pci_find_bus(0, 1); |
| 581 | if (!bus) { |
| 582 | pr_warning("Unable to find PCI bus 1?\n"); |
Alan Jenkins | dcf443b | 2009-08-28 12:56:33 +0000 | [diff] [blame] | 583 | goto out_unlock; |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 584 | } |
Alan Jenkins | 07e84aa | 2009-08-28 12:56:34 +0000 | [diff] [blame] | 585 | |
| 586 | if (!blocked) { |
| 587 | dev = pci_get_slot(bus, 0); |
| 588 | if (dev) { |
| 589 | /* Device already present */ |
| 590 | pci_dev_put(dev); |
| 591 | goto out_unlock; |
| 592 | } |
| 593 | dev = pci_scan_single_device(bus, 0); |
| 594 | if (dev) { |
| 595 | pci_bus_assign_resources(bus); |
| 596 | if (pci_bus_add_device(dev)) |
| 597 | pr_err("Unable to hotplug wifi\n"); |
| 598 | } |
| 599 | } else { |
| 600 | dev = pci_get_slot(bus, 0); |
| 601 | if (dev) { |
| 602 | pci_remove_bus_device(dev); |
| 603 | pci_dev_put(dev); |
| 604 | } |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 605 | } |
| 606 | } |
Alan Jenkins | dcf443b | 2009-08-28 12:56:33 +0000 | [diff] [blame] | 607 | |
| 608 | out_unlock: |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 609 | mutex_unlock(&eeepc->hotplug_lock); |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 610 | } |
| 611 | |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 612 | static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) |
| 613 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 614 | struct eeepc_laptop *eeepc = data; |
| 615 | |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 616 | if (event != ACPI_NOTIFY_BUS_CHECK) |
| 617 | return; |
| 618 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 619 | eeepc_rfkill_hotplug(eeepc); |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 622 | static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc, |
| 623 | char *node) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 624 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 625 | acpi_status status; |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 626 | acpi_handle handle; |
| 627 | |
| 628 | status = acpi_get_handle(NULL, node, &handle); |
| 629 | |
| 630 | if (ACPI_SUCCESS(status)) { |
| 631 | status = acpi_install_notify_handler(handle, |
| 632 | ACPI_SYSTEM_NOTIFY, |
| 633 | eeepc_rfkill_notify, |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 634 | eeepc); |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 635 | if (ACPI_FAILURE(status)) |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 636 | pr_warning("Failed to register notify on %s\n", node); |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 637 | } else |
| 638 | return -ENODEV; |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 643 | static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc, |
| 644 | char *node) |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 645 | { |
| 646 | acpi_status status = AE_OK; |
| 647 | acpi_handle handle; |
| 648 | |
| 649 | status = acpi_get_handle(NULL, node, &handle); |
| 650 | |
| 651 | if (ACPI_SUCCESS(status)) { |
| 652 | status = acpi_remove_notify_handler(handle, |
| 653 | ACPI_SYSTEM_NOTIFY, |
| 654 | eeepc_rfkill_notify); |
| 655 | if (ACPI_FAILURE(status)) |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 656 | pr_err("Error removing rfkill notify handler %s\n", |
Matthew Garrett | 5740294 | 2009-01-20 16:17:48 +0100 | [diff] [blame] | 657 | node); |
| 658 | } |
| 659 | } |
| 660 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 661 | static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, |
| 662 | u8 *value) |
| 663 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 664 | struct eeepc_laptop *eeepc = hotplug_slot->private; |
| 665 | int val = get_acpi(eeepc, CM_ASL_WLAN); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 666 | |
| 667 | if (val == 1 || val == 0) |
| 668 | *value = val; |
| 669 | else |
| 670 | return -EINVAL; |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 675 | static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot) |
| 676 | { |
| 677 | kfree(hotplug_slot->info); |
| 678 | kfree(hotplug_slot); |
| 679 | } |
| 680 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 681 | static struct hotplug_slot_ops eeepc_hotplug_slot_ops = { |
| 682 | .owner = THIS_MODULE, |
| 683 | .get_adapter_status = eeepc_get_adapter_status, |
| 684 | .get_power_status = eeepc_get_adapter_status, |
| 685 | }; |
| 686 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 687 | static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc) |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 688 | { |
| 689 | int ret = -ENOMEM; |
| 690 | struct pci_bus *bus = pci_find_bus(0, 1); |
| 691 | |
| 692 | if (!bus) { |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 693 | pr_err("Unable to find wifi PCI bus\n"); |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 694 | return -ENODEV; |
| 695 | } |
| 696 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 697 | eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); |
| 698 | if (!eeepc->hotplug_slot) |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 699 | goto error_slot; |
| 700 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 701 | eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info), |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 702 | GFP_KERNEL); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 703 | if (!eeepc->hotplug_slot->info) |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 704 | goto error_info; |
| 705 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 706 | eeepc->hotplug_slot->private = eeepc; |
| 707 | eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug; |
| 708 | eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops; |
| 709 | eeepc_get_adapter_status(eeepc->hotplug_slot, |
| 710 | &eeepc->hotplug_slot->info->adapter_status); |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 711 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 712 | ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi"); |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 713 | if (ret) { |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 714 | pr_err("Unable to register hotplug slot - %d\n", ret); |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 715 | goto error_register; |
| 716 | } |
| 717 | |
| 718 | return 0; |
| 719 | |
| 720 | error_register: |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 721 | kfree(eeepc->hotplug_slot->info); |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 722 | error_info: |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 723 | kfree(eeepc->hotplug_slot); |
| 724 | eeepc->hotplug_slot = NULL; |
Corentin Chary | 2b121bc | 2009-06-25 13:25:36 +0200 | [diff] [blame] | 725 | error_slot: |
| 726 | return ret; |
| 727 | } |
| 728 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 729 | /* |
| 730 | * Rfkill devices |
| 731 | */ |
| 732 | static int eeepc_rfkill_set(void *data, bool blocked) |
| 733 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 734 | acpi_handle handle = data; |
| 735 | |
| 736 | return write_acpi_int(handle, NULL, !blocked); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static const struct rfkill_ops eeepc_rfkill_ops = { |
| 740 | .set_block = eeepc_rfkill_set, |
| 741 | }; |
| 742 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 743 | static int eeepc_new_rfkill(struct eeepc_laptop *eeepc, |
| 744 | struct rfkill **rfkill, |
| 745 | const char *name, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 746 | enum rfkill_type type, int cm) |
| 747 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 748 | acpi_handle handle; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 749 | int result; |
| 750 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 751 | result = acpi_setter_handle(eeepc, cm, &handle); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 752 | if (result < 0) |
| 753 | return result; |
| 754 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 755 | *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, |
| 756 | &eeepc_rfkill_ops, handle); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 757 | |
| 758 | if (!*rfkill) |
| 759 | return -EINVAL; |
| 760 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 761 | rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 762 | result = rfkill_register(*rfkill); |
| 763 | if (result) { |
| 764 | rfkill_destroy(*rfkill); |
| 765 | *rfkill = NULL; |
| 766 | return result; |
| 767 | } |
| 768 | return 0; |
| 769 | } |
| 770 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 771 | static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 772 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 773 | eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5"); |
| 774 | eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6"); |
| 775 | eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7"); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 776 | if (eeepc->wlan_rfkill) { |
| 777 | rfkill_unregister(eeepc->wlan_rfkill); |
| 778 | rfkill_destroy(eeepc->wlan_rfkill); |
| 779 | eeepc->wlan_rfkill = NULL; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 780 | } |
| 781 | /* |
| 782 | * Refresh pci hotplug in case the rfkill state was changed after |
| 783 | * eeepc_unregister_rfkill_notifier() |
| 784 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 785 | eeepc_rfkill_hotplug(eeepc); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 786 | if (eeepc->hotplug_slot) |
| 787 | pci_hp_deregister(eeepc->hotplug_slot); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 788 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 789 | if (eeepc->bluetooth_rfkill) { |
| 790 | rfkill_unregister(eeepc->bluetooth_rfkill); |
| 791 | rfkill_destroy(eeepc->bluetooth_rfkill); |
| 792 | eeepc->bluetooth_rfkill = NULL; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 793 | } |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 794 | if (eeepc->wwan3g_rfkill) { |
| 795 | rfkill_unregister(eeepc->wwan3g_rfkill); |
| 796 | rfkill_destroy(eeepc->wwan3g_rfkill); |
| 797 | eeepc->wwan3g_rfkill = NULL; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 798 | } |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 799 | if (eeepc->wimax_rfkill) { |
| 800 | rfkill_unregister(eeepc->wimax_rfkill); |
| 801 | rfkill_destroy(eeepc->wimax_rfkill); |
| 802 | eeepc->wimax_rfkill = NULL; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 806 | static int eeepc_rfkill_init(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 807 | { |
| 808 | int result = 0; |
| 809 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 810 | mutex_init(&eeepc->hotplug_lock); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 811 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 812 | result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill, |
| 813 | "eeepc-wlan", RFKILL_TYPE_WLAN, |
| 814 | CM_ASL_WLAN); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 815 | |
| 816 | if (result && result != -ENODEV) |
| 817 | goto exit; |
| 818 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 819 | result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill, |
| 820 | "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH, |
| 821 | CM_ASL_BLUETOOTH); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 822 | |
| 823 | if (result && result != -ENODEV) |
| 824 | goto exit; |
| 825 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 826 | result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill, |
| 827 | "eeepc-wwan3g", RFKILL_TYPE_WWAN, |
| 828 | CM_ASL_3G); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 829 | |
| 830 | if (result && result != -ENODEV) |
| 831 | goto exit; |
| 832 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 833 | result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill, |
| 834 | "eeepc-wimax", RFKILL_TYPE_WIMAX, |
| 835 | CM_ASL_WIMAX); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 836 | |
| 837 | if (result && result != -ENODEV) |
| 838 | goto exit; |
| 839 | |
Corentin Chary | 10ae4b5 | 2010-01-06 22:07:38 +0100 | [diff] [blame] | 840 | if (eeepc->hotplug_disabled) |
| 841 | return 0; |
| 842 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 843 | result = eeepc_setup_pci_hotplug(eeepc); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 844 | /* |
| 845 | * If we get -EBUSY then something else is handling the PCI hotplug - |
| 846 | * don't fail in this case |
| 847 | */ |
| 848 | if (result == -EBUSY) |
| 849 | result = 0; |
| 850 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 851 | eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5"); |
| 852 | eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6"); |
| 853 | eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7"); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 854 | /* |
| 855 | * Refresh pci hotplug in case the rfkill state was changed during |
| 856 | * setup. |
| 857 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 858 | eeepc_rfkill_hotplug(eeepc); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 859 | |
| 860 | exit: |
| 861 | if (result && result != -ENODEV) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 862 | eeepc_rfkill_exit(eeepc); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 863 | return result; |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * Platform driver - hibernate/resume callbacks |
| 868 | */ |
Alan Jenkins | c200da5 | 2009-08-28 12:56:40 +0000 | [diff] [blame] | 869 | static int eeepc_hotk_thaw(struct device *device) |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 870 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 871 | struct eeepc_laptop *eeepc = dev_get_drvdata(device); |
| 872 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 873 | if (eeepc->wlan_rfkill) { |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 874 | bool wlan; |
| 875 | |
Alan Jenkins | c1edd99 | 2009-08-28 12:56:39 +0000 | [diff] [blame] | 876 | /* |
| 877 | * Work around bios bug - acpi _PTS turns off the wireless led |
| 878 | * during suspend. Normally it restores it on resume, but |
Alan Jenkins | c200da5 | 2009-08-28 12:56:40 +0000 | [diff] [blame] | 879 | * we should kick it ourselves in case hibernation is aborted. |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 880 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 881 | wlan = get_acpi(eeepc, CM_ASL_WLAN); |
| 882 | set_acpi(eeepc, CM_ASL_WLAN, wlan); |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Alan Jenkins | c200da5 | 2009-08-28 12:56:40 +0000 | [diff] [blame] | 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int eeepc_hotk_restore(struct device *device) |
| 889 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 890 | struct eeepc_laptop *eeepc = dev_get_drvdata(device); |
Alan Jenkins | c200da5 | 2009-08-28 12:56:40 +0000 | [diff] [blame] | 891 | |
Alan Jenkins | 96e9cfe | 2009-06-16 14:53:52 +0100 | [diff] [blame] | 892 | /* Refresh both wlan rfkill state and pci hotplug */ |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 893 | if (eeepc->wlan_rfkill) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 894 | eeepc_rfkill_hotplug(eeepc); |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 895 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 896 | if (eeepc->bluetooth_rfkill) |
| 897 | rfkill_set_sw_state(eeepc->bluetooth_rfkill, |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 898 | get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 899 | if (eeepc->wwan3g_rfkill) |
| 900 | rfkill_set_sw_state(eeepc->wwan3g_rfkill, |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 901 | get_acpi(eeepc, CM_ASL_3G) != 1); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 902 | if (eeepc->wimax_rfkill) |
| 903 | rfkill_set_sw_state(eeepc->wimax_rfkill, |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 904 | get_acpi(eeepc, CM_ASL_WIMAX) != 1); |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Len Brown | 9a3bff2 | 2009-12-15 22:34:48 -0500 | [diff] [blame] | 909 | static const struct dev_pm_ops eeepc_pm_ops = { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 910 | .thaw = eeepc_hotk_thaw, |
| 911 | .restore = eeepc_hotk_restore, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 912 | }; |
| 913 | |
| 914 | static struct platform_driver platform_driver = { |
| 915 | .driver = { |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 916 | .name = EEEPC_LAPTOP_FILE, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 917 | .owner = THIS_MODULE, |
| 918 | .pm = &eeepc_pm_ops, |
| 919 | } |
| 920 | }; |
| 921 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 922 | /* |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 923 | * Hwmon device |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 924 | */ |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 925 | |
| 926 | #define EEEPC_EC_SC00 0x61 |
| 927 | #define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */ |
| 928 | #define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */ |
| 929 | #define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */ |
| 930 | |
| 931 | #define EEEPC_EC_SFB0 0xD0 |
| 932 | #define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */ |
| 933 | |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 934 | static int eeepc_get_fan_pwm(void) |
| 935 | { |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 936 | u8 value = 0; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 937 | |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 938 | ec_read(EEEPC_EC_FAN_PWM, &value); |
| 939 | return value * 255 / 100; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | static void eeepc_set_fan_pwm(int value) |
| 943 | { |
| 944 | value = SENSORS_LIMIT(value, 0, 255); |
| 945 | value = value * 100 / 255; |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 946 | ec_write(EEEPC_EC_FAN_PWM, value); |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | static int eeepc_get_fan_rpm(void) |
| 950 | { |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 951 | u8 high = 0; |
| 952 | u8 low = 0; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 953 | |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 954 | ec_read(EEEPC_EC_FAN_HRPM, &high); |
| 955 | ec_read(EEEPC_EC_FAN_LRPM, &low); |
| 956 | return high << 8 | low; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | static int eeepc_get_fan_ctrl(void) |
| 960 | { |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 961 | u8 value = 0; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 962 | |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 963 | ec_read(EEEPC_EC_FAN_CTRL, &value); |
Alan Jenkins | 4871868 | 2009-12-03 07:44:56 +0000 | [diff] [blame] | 964 | if (value & 0x02) |
| 965 | return 1; /* manual */ |
| 966 | else |
| 967 | return 2; /* automatic */ |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | static void eeepc_set_fan_ctrl(int manual) |
| 971 | { |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 972 | u8 value = 0; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 973 | |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 974 | ec_read(EEEPC_EC_FAN_CTRL, &value); |
Alan Jenkins | 4871868 | 2009-12-03 07:44:56 +0000 | [diff] [blame] | 975 | if (manual == 1) |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 976 | value |= 0x02; |
| 977 | else |
| 978 | value &= ~0x02; |
Alan Jenkins | 463b4e4 | 2009-12-03 07:45:03 +0000 | [diff] [blame] | 979 | ec_write(EEEPC_EC_FAN_CTRL, value); |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count) |
| 983 | { |
| 984 | int rv, value; |
| 985 | |
| 986 | rv = parse_arg(buf, count, &value); |
| 987 | if (rv > 0) |
| 988 | set(value); |
| 989 | return rv; |
| 990 | } |
| 991 | |
| 992 | static ssize_t show_sys_hwmon(int (*get)(void), char *buf) |
| 993 | { |
| 994 | return sprintf(buf, "%d\n", get()); |
| 995 | } |
| 996 | |
| 997 | #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \ |
| 998 | static ssize_t show_##_name(struct device *dev, \ |
| 999 | struct device_attribute *attr, \ |
| 1000 | char *buf) \ |
| 1001 | { \ |
| 1002 | return show_sys_hwmon(_set, buf); \ |
| 1003 | } \ |
| 1004 | static ssize_t store_##_name(struct device *dev, \ |
| 1005 | struct device_attribute *attr, \ |
| 1006 | const char *buf, size_t count) \ |
| 1007 | { \ |
| 1008 | return store_sys_hwmon(_get, buf, count); \ |
| 1009 | } \ |
| 1010 | static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0); |
| 1011 | |
| 1012 | EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL); |
Corentin Chary | 04dcd84 | 2008-10-09 15:33:57 +0200 | [diff] [blame] | 1013 | EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1014 | eeepc_get_fan_pwm, eeepc_set_fan_pwm); |
| 1015 | EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
| 1016 | eeepc_get_fan_ctrl, eeepc_set_fan_ctrl); |
| 1017 | |
Corentin Chary | 04dcd84 | 2008-10-09 15:33:57 +0200 | [diff] [blame] | 1018 | static ssize_t |
| 1019 | show_name(struct device *dev, struct device_attribute *attr, char *buf) |
| 1020 | { |
| 1021 | return sprintf(buf, "eeepc\n"); |
| 1022 | } |
| 1023 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0); |
| 1024 | |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1025 | static struct attribute *hwmon_attributes[] = { |
Corentin Chary | 04dcd84 | 2008-10-09 15:33:57 +0200 | [diff] [blame] | 1026 | &sensor_dev_attr_pwm1.dev_attr.attr, |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1027 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1028 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Corentin Chary | 04dcd84 | 2008-10-09 15:33:57 +0200 | [diff] [blame] | 1029 | &sensor_dev_attr_name.dev_attr.attr, |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1030 | NULL |
| 1031 | }; |
| 1032 | |
| 1033 | static struct attribute_group hwmon_attribute_group = { |
| 1034 | .attrs = hwmon_attributes |
| 1035 | }; |
| 1036 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1037 | static void eeepc_hwmon_exit(struct eeepc_laptop *eeepc) |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1038 | { |
| 1039 | struct device *hwmon; |
| 1040 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1041 | hwmon = eeepc->hwmon_device; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1042 | if (!hwmon) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1043 | return; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1044 | sysfs_remove_group(&hwmon->kobj, |
| 1045 | &hwmon_attribute_group); |
Matthew Garrett | f144131 | 2008-08-20 14:08:57 -0700 | [diff] [blame] | 1046 | hwmon_device_unregister(hwmon); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1047 | eeepc->hwmon_device = NULL; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1050 | static int eeepc_hwmon_init(struct eeepc_laptop *eeepc) |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1051 | { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1052 | struct device *hwmon; |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1053 | int result; |
| 1054 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1055 | hwmon = hwmon_device_register(&eeepc->platform_device->dev); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1056 | if (IS_ERR(hwmon)) { |
| 1057 | pr_err("Could not register eeepc hwmon device\n"); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1058 | eeepc->hwmon_device = NULL; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1059 | return PTR_ERR(hwmon); |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1060 | } |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1061 | eeepc->hwmon_device = hwmon; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1062 | result = sysfs_create_group(&hwmon->kobj, |
| 1063 | &hwmon_attribute_group); |
| 1064 | if (result) |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1065 | eeepc_hwmon_exit(eeepc); |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1066 | return result; |
| 1067 | } |
| 1068 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1069 | /* |
| 1070 | * Backlight device |
| 1071 | */ |
| 1072 | static int read_brightness(struct backlight_device *bd) |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1073 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1074 | struct eeepc_laptop *eeepc = bl_get_data(bd); |
| 1075 | |
| 1076 | return get_acpi(eeepc, CM_ASL_PANELBRIGHT); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1077 | } |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1078 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1079 | static int set_brightness(struct backlight_device *bd, int value) |
| 1080 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1081 | struct eeepc_laptop *eeepc = bl_get_data(bd); |
| 1082 | |
| 1083 | return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1084 | } |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1085 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1086 | static int update_bl_status(struct backlight_device *bd) |
| 1087 | { |
| 1088 | return set_brightness(bd, bd->props.brightness); |
| 1089 | } |
Corentin Chary | a9df80c | 2009-01-20 16:17:40 +0100 | [diff] [blame] | 1090 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1091 | static struct backlight_ops eeepcbl_ops = { |
| 1092 | .get_brightness = read_brightness, |
| 1093 | .update_status = update_bl_status, |
| 1094 | }; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1095 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1096 | static int eeepc_backlight_notify(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1097 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1098 | struct backlight_device *bd = eeepc->backlight_device; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1099 | int old = bd->props.brightness; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1100 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1101 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1102 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1103 | return old; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1106 | static int eeepc_backlight_init(struct eeepc_laptop *eeepc) |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1107 | { |
| 1108 | struct backlight_device *bd; |
| 1109 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1110 | bd = backlight_device_register(EEEPC_LAPTOP_FILE, |
| 1111 | &eeepc->platform_device->dev, |
| 1112 | eeepc, &eeepcbl_ops); |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1113 | if (IS_ERR(bd)) { |
Joe Perches | 19b5328 | 2009-06-25 13:25:37 +0200 | [diff] [blame] | 1114 | pr_err("Could not register eeepc backlight device\n"); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1115 | eeepc->backlight_device = NULL; |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1116 | return PTR_ERR(bd); |
| 1117 | } |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1118 | eeepc->backlight_device = bd; |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1119 | bd->props.max_brightness = 15; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1120 | bd->props.brightness = read_brightness(bd); |
Corentin Chary | a5fa429 | 2008-03-13 12:56:37 +0100 | [diff] [blame] | 1121 | bd->props.power = FB_BLANK_UNBLANK; |
| 1122 | backlight_update_status(bd); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1126 | static void eeepc_backlight_exit(struct eeepc_laptop *eeepc) |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1127 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1128 | if (eeepc->backlight_device) |
| 1129 | backlight_device_unregister(eeepc->backlight_device); |
| 1130 | eeepc->backlight_device = NULL; |
Corentin Chary | e1faa9d | 2008-03-13 12:57:18 +0100 | [diff] [blame] | 1131 | } |
| 1132 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1133 | |
| 1134 | /* |
| 1135 | * Input device (i.e. hotkeys) |
| 1136 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1137 | static int eeepc_input_init(struct eeepc_laptop *eeepc) |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1138 | { |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1139 | struct input_dev *input; |
| 1140 | int error; |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1141 | |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1142 | input = input_allocate_device(); |
| 1143 | if (!input) { |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1144 | pr_info("Unable to allocate input device\n"); |
| 1145 | return -ENOMEM; |
| 1146 | } |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1147 | |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1148 | input->name = "Asus EeePC extra buttons"; |
| 1149 | input->phys = EEEPC_LAPTOP_FILE "/input0"; |
| 1150 | input->id.bustype = BUS_HOST; |
| 1151 | input->dev.parent = &eeepc->platform_device->dev; |
| 1152 | |
| 1153 | error = sparse_keymap_setup(input, eeepc_keymap, NULL); |
| 1154 | if (error) { |
| 1155 | pr_err("Unable to setup input device keymap\n"); |
| 1156 | goto err_free_dev; |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1157 | } |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1158 | |
| 1159 | error = input_register_device(input); |
| 1160 | if (error) { |
| 1161 | pr_err("Unable to register input device\n"); |
| 1162 | goto err_free_keymap; |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1163 | } |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1164 | |
| 1165 | eeepc->inputdev = input; |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1166 | return 0; |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1167 | |
| 1168 | err_free_keymap: |
| 1169 | sparse_keymap_free(input); |
| 1170 | err_free_dev: |
| 1171 | input_free_device(input); |
| 1172 | return error; |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1175 | static void eeepc_input_exit(struct eeepc_laptop *eeepc) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1176 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1177 | if (eeepc->inputdev) { |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1178 | input_unregister_device(eeepc->inputdev); |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1179 | kfree(eeepc->keymap); |
| 1180 | } |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1181 | } |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1182 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1183 | /* |
| 1184 | * ACPI driver |
| 1185 | */ |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1186 | static void eeepc_acpi_notify(struct acpi_device *device, u32 event) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1187 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1188 | struct eeepc_laptop *eeepc = acpi_driver_data(device); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1189 | u16 count; |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1190 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1191 | if (event > ACPI_MAX_SYS_NOTIFY) |
| 1192 | return; |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1193 | count = eeepc->event_count[event % 128]++; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1194 | acpi_bus_generate_proc_event(device, event, count); |
| 1195 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
| 1196 | dev_name(&device->dev), event, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1197 | count); |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1198 | |
Alan Jenkins | 325fb8e | 2009-12-03 07:45:15 +0000 | [diff] [blame] | 1199 | /* Brightness events are special */ |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1200 | if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1201 | |
Alan Jenkins | 325fb8e | 2009-12-03 07:45:15 +0000 | [diff] [blame] | 1202 | /* Ignore them completely if the acpi video driver is used */ |
| 1203 | if (eeepc->backlight_device != NULL) { |
| 1204 | int old_brightness, new_brightness; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1205 | |
Alan Jenkins | 325fb8e | 2009-12-03 07:45:15 +0000 | [diff] [blame] | 1206 | /* Update the backlight device. */ |
| 1207 | old_brightness = eeepc_backlight_notify(eeepc); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1208 | |
Alan Jenkins | 325fb8e | 2009-12-03 07:45:15 +0000 | [diff] [blame] | 1209 | /* Convert event to keypress (obsolescent hack) */ |
| 1210 | new_brightness = event - NOTIFY_BRN_MIN; |
| 1211 | |
| 1212 | if (new_brightness < old_brightness) { |
| 1213 | event = NOTIFY_BRN_MIN; /* brightness down */ |
| 1214 | } else if (new_brightness > old_brightness) { |
| 1215 | event = NOTIFY_BRN_MAX; /* brightness up */ |
| 1216 | } else { |
| 1217 | /* |
| 1218 | * no change in brightness - already at min/max, |
| 1219 | * event will be desired value (or else ignored) |
| 1220 | */ |
| 1221 | } |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1222 | sparse_keymap_report_event(eeepc->inputdev, event, |
| 1223 | 1, true); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1224 | } |
Alan Jenkins | 325fb8e | 2009-12-03 07:45:15 +0000 | [diff] [blame] | 1225 | } else { |
| 1226 | /* Everything else is a bona-fide keypress event */ |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1227 | sparse_keymap_report_event(eeepc->inputdev, event, 1, true); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1228 | } |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 1231 | static void eeepc_dmi_check(struct eeepc_laptop *eeepc) |
| 1232 | { |
| 1233 | const char *model; |
| 1234 | |
Corentin Chary | 10ae4b5 | 2010-01-06 22:07:38 +0100 | [diff] [blame] | 1235 | model = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 1236 | if (!model) |
| 1237 | return; |
| 1238 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 1239 | /* |
| 1240 | * Blacklist for setting cpufv (cpu speed). |
| 1241 | * |
| 1242 | * EeePC 4G ("701") implements CFVS, but it is not supported |
| 1243 | * by the pre-installed OS, and the original option to change it |
| 1244 | * in the BIOS setup screen was removed in later versions. |
| 1245 | * |
| 1246 | * Judging by the lack of "Super Hybrid Engine" on Asus product pages, |
| 1247 | * this applies to all "701" models (4G/4G Surf/2G Surf). |
| 1248 | * |
| 1249 | * So Asus made a deliberate decision not to support it on this model. |
| 1250 | * We have several reports that using it can cause the system to hang |
| 1251 | * |
| 1252 | * The hang has also been reported on a "702" (Model name "8G"?). |
| 1253 | * |
| 1254 | * We avoid dmi_check_system() / dmi_match(), because they use |
| 1255 | * substring matching. We don't want to affect the "701SD" |
| 1256 | * and "701SDX" models, because they do support S.H.E. |
| 1257 | */ |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 1258 | if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) { |
| 1259 | eeepc->cpufv_disabled = true; |
| 1260 | pr_info("model %s does not officially support setting cpu " |
| 1261 | "speed\n", model); |
| 1262 | pr_info("cpufv disabled to avoid instability\n"); |
| 1263 | } |
Corentin Chary | 10ae4b5 | 2010-01-06 22:07:38 +0100 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * Blacklist for wlan hotplug |
| 1267 | * |
| 1268 | * Eeepc 1005HA doesn't work like others models and don't need the |
| 1269 | * hotplug code. In fact, current hotplug code seems to unplug another |
| 1270 | * device... |
| 1271 | */ |
| 1272 | if (strcmp(model, "1005HA") == 0) { |
| 1273 | eeepc->hotplug_disabled = true; |
| 1274 | pr_info("wlan hotplug disabled\n"); |
| 1275 | } |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1278 | static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1279 | { |
| 1280 | int dummy; |
| 1281 | |
| 1282 | /* Some BIOSes do not report cm although it is avaliable. |
| 1283 | Check if cm_getv[cm] works and, if yes, assume cm should be set. */ |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1284 | if (!(eeepc->cm_supported & (1 << cm)) |
| 1285 | && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1286 | pr_info("%s (%x) not reported by BIOS," |
| 1287 | " enabling anyway\n", name, 1 << cm); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1288 | eeepc->cm_supported |= 1 << cm; |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1292 | static void cmsg_quirks(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1293 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1294 | cmsg_quirk(eeepc, CM_ASL_LID, "LID"); |
| 1295 | cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE"); |
| 1296 | cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER"); |
| 1297 | cmsg_quirk(eeepc, CM_ASL_TPD, "TPD"); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Corentin Chary | f90be87 | 2009-12-03 07:45:14 +0000 | [diff] [blame] | 1300 | static int eeepc_acpi_init(struct eeepc_laptop *eeepc, |
| 1301 | struct acpi_device *device) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1302 | { |
| 1303 | unsigned int init_flags; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1304 | int result; |
| 1305 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1306 | result = acpi_bus_get_status(device); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1307 | if (result) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1308 | return result; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1309 | if (!device->status.present) { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1310 | pr_err("Hotkey device not present, aborting\n"); |
| 1311 | return -ENODEV; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1312 | } |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1313 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1314 | init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH; |
| 1315 | pr_notice("Hotkey init flags 0x%x\n", init_flags); |
| 1316 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1317 | if (write_acpi_int(eeepc->handle, "INIT", init_flags)) { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1318 | pr_err("Hotkey initialization failed\n"); |
| 1319 | return -ENODEV; |
| 1320 | } |
| 1321 | |
| 1322 | /* get control methods supported */ |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1323 | if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) { |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1324 | pr_err("Get control methods supported failed\n"); |
| 1325 | return -ENODEV; |
| 1326 | } |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1327 | cmsg_quirks(eeepc); |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1328 | pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1329 | |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1330 | return 0; |
| 1331 | } |
| 1332 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1333 | static void __devinit eeepc_enable_camera(struct eeepc_laptop *eeepc) |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1334 | { |
| 1335 | /* |
| 1336 | * If the following call to set_acpi() fails, it's because there's no |
| 1337 | * camera so we can ignore the error. |
| 1338 | */ |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1339 | if (get_acpi(eeepc, CM_ASL_CAMERA) == 0) |
| 1340 | set_acpi(eeepc, CM_ASL_CAMERA, 1); |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1343 | static bool eeepc_device_present; |
| 1344 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1345 | static int __devinit eeepc_acpi_add(struct acpi_device *device) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1346 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1347 | struct eeepc_laptop *eeepc; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1348 | int result; |
| 1349 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1350 | pr_notice(EEEPC_LAPTOP_NAME "\n"); |
| 1351 | eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL); |
| 1352 | if (!eeepc) |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1353 | return -ENOMEM; |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1354 | eeepc->handle = device->handle; |
| 1355 | strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME); |
| 1356 | strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS); |
| 1357 | device->driver_data = eeepc; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1358 | |
Alan Jenkins | da8ba01 | 2010-01-06 22:07:37 +0100 | [diff] [blame] | 1359 | eeepc_dmi_check(eeepc); |
| 1360 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1361 | result = eeepc_acpi_init(eeepc, device); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1362 | if (result) |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 1363 | goto fail_platform; |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1364 | eeepc_enable_camera(eeepc); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1365 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1366 | /* |
| 1367 | * Register the platform device first. It is used as a parent for the |
| 1368 | * sub-devices below. |
| 1369 | * |
| 1370 | * Note that if there are multiple instances of this ACPI device it |
| 1371 | * will bail out, because the platform device is registered with a |
| 1372 | * fixed name. Of course it doesn't make sense to have more than one, |
| 1373 | * and machine-specific scripts find the fixed name convenient. But |
| 1374 | * It's also good for us to exclude multiple instances because both |
| 1375 | * our hwmon and our wlan rfkill subdevice use global ACPI objects |
| 1376 | * (the EC and the wlan PCI slot respectively). |
| 1377 | */ |
| 1378 | result = eeepc_platform_init(eeepc); |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1379 | if (result) |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 1380 | goto fail_platform; |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1381 | |
| 1382 | if (!acpi_video_backlight_support()) { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1383 | result = eeepc_backlight_init(eeepc); |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1384 | if (result) |
| 1385 | goto fail_backlight; |
| 1386 | } else |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 1387 | pr_info("Backlight controlled by ACPI video driver\n"); |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1388 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1389 | result = eeepc_input_init(eeepc); |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1390 | if (result) |
| 1391 | goto fail_input; |
| 1392 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1393 | result = eeepc_hwmon_init(eeepc); |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1394 | if (result) |
| 1395 | goto fail_hwmon; |
| 1396 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1397 | result = eeepc_led_init(eeepc); |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1398 | if (result) |
| 1399 | goto fail_led; |
| 1400 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1401 | result = eeepc_rfkill_init(eeepc); |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1402 | if (result) |
| 1403 | goto fail_rfkill; |
| 1404 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1405 | eeepc_device_present = true; |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1406 | return 0; |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1407 | |
Corentin Chary | 7de3938 | 2009-06-25 13:25:38 +0200 | [diff] [blame] | 1408 | fail_rfkill: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1409 | eeepc_led_exit(eeepc); |
Corentin Chary | 3c0eb51 | 2009-12-03 07:44:52 +0000 | [diff] [blame] | 1410 | fail_led: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1411 | eeepc_hwmon_exit(eeepc); |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1412 | fail_hwmon: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1413 | eeepc_input_exit(eeepc); |
Alan Jenkins | f2a9d5e | 2009-08-28 12:56:36 +0000 | [diff] [blame] | 1414 | fail_input: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1415 | eeepc_backlight_exit(eeepc); |
Corentin Chary | 1ddec2f | 2009-06-25 13:25:39 +0200 | [diff] [blame] | 1416 | fail_backlight: |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1417 | eeepc_platform_exit(eeepc); |
Alan Jenkins | 9db106b | 2009-12-03 07:45:06 +0000 | [diff] [blame] | 1418 | fail_platform: |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1419 | kfree(eeepc); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1420 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1421 | return result; |
| 1422 | } |
| 1423 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1424 | static int eeepc_acpi_remove(struct acpi_device *device, int type) |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1425 | { |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1426 | struct eeepc_laptop *eeepc = acpi_driver_data(device); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1427 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1428 | eeepc_backlight_exit(eeepc); |
| 1429 | eeepc_rfkill_exit(eeepc); |
| 1430 | eeepc_input_exit(eeepc); |
| 1431 | eeepc_hwmon_exit(eeepc); |
| 1432 | eeepc_led_exit(eeepc); |
| 1433 | eeepc_platform_exit(eeepc); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1434 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1435 | kfree(eeepc); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1439 | |
| 1440 | static const struct acpi_device_id eeepc_device_ids[] = { |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1441 | {EEEPC_ACPI_HID, 0}, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1442 | {"", 0}, |
| 1443 | }; |
| 1444 | MODULE_DEVICE_TABLE(acpi, eeepc_device_ids); |
| 1445 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1446 | static struct acpi_driver eeepc_acpi_driver = { |
| 1447 | .name = EEEPC_LAPTOP_NAME, |
| 1448 | .class = EEEPC_ACPI_CLASS, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1449 | .owner = THIS_MODULE, |
| 1450 | .ids = eeepc_device_ids, |
| 1451 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, |
| 1452 | .ops = { |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1453 | .add = eeepc_acpi_add, |
| 1454 | .remove = eeepc_acpi_remove, |
| 1455 | .notify = eeepc_acpi_notify, |
Alan Jenkins | 52bbe3c | 2009-12-03 07:45:07 +0000 | [diff] [blame] | 1456 | }, |
| 1457 | }; |
| 1458 | |
| 1459 | |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1460 | static int __init eeepc_laptop_init(void) |
| 1461 | { |
| 1462 | int result; |
| 1463 | |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1464 | result = platform_driver_register(&platform_driver); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1465 | if (result < 0) |
| 1466 | return result; |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1467 | |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1468 | result = acpi_bus_register_driver(&eeepc_acpi_driver); |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1469 | if (result < 0) |
| 1470 | goto fail_acpi_driver; |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1471 | |
Alan Jenkins | 854c783 | 2009-12-03 07:45:09 +0000 | [diff] [blame] | 1472 | if (!eeepc_device_present) { |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1473 | result = -ENODEV; |
| 1474 | goto fail_no_device; |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1475 | } |
Dmitry Torokhov | 642e044 | 2010-01-06 22:07:39 +0100 | [diff] [blame^] | 1476 | |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1477 | return 0; |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1478 | |
| 1479 | fail_no_device: |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1480 | acpi_bus_unregister_driver(&eeepc_acpi_driver); |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1481 | fail_acpi_driver: |
| 1482 | platform_driver_unregister(&platform_driver); |
| 1483 | return result; |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | static void __exit eeepc_laptop_exit(void) |
| 1487 | { |
Alan Jenkins | a7624b6 | 2009-12-03 07:45:08 +0000 | [diff] [blame] | 1488 | acpi_bus_unregister_driver(&eeepc_acpi_driver); |
Alan Jenkins | 22072e9 | 2009-12-03 07:45:05 +0000 | [diff] [blame] | 1489 | platform_driver_unregister(&platform_driver); |
Alan Jenkins | 1e77985 | 2009-08-28 12:56:35 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Eric Cooper | e59f879 | 2008-03-13 12:55:46 +0100 | [diff] [blame] | 1492 | module_init(eeepc_laptop_init); |
| 1493 | module_exit(eeepc_laptop_exit); |