diff options
Diffstat (limited to 'drivers/platform/x86/eeepc-laptop.c')
-rw-r--r-- | drivers/platform/x86/eeepc-laptop.c | 298 |
1 files changed, 163 insertions, 135 deletions
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 5838c69b2fb3..e2be6bb33d92 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c | |||
@@ -31,10 +31,12 @@ | |||
31 | #include <acpi/acpi_bus.h> | 31 | #include <acpi/acpi_bus.h> |
32 | #include <linux/uaccess.h> | 32 | #include <linux/uaccess.h> |
33 | #include <linux/input.h> | 33 | #include <linux/input.h> |
34 | #include <linux/input/sparse-keymap.h> | ||
34 | #include <linux/rfkill.h> | 35 | #include <linux/rfkill.h> |
35 | #include <linux/pci.h> | 36 | #include <linux/pci.h> |
36 | #include <linux/pci_hotplug.h> | 37 | #include <linux/pci_hotplug.h> |
37 | #include <linux/leds.h> | 38 | #include <linux/leds.h> |
39 | #include <linux/dmi.h> | ||
38 | 40 | ||
39 | #define EEEPC_LAPTOP_VERSION "0.1" | 41 | #define EEEPC_LAPTOP_VERSION "0.1" |
40 | #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver" | 42 | #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver" |
@@ -48,6 +50,14 @@ MODULE_AUTHOR("Corentin Chary, Eric Cooper"); | |||
48 | MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME); | 50 | MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME); |
49 | MODULE_LICENSE("GPL"); | 51 | MODULE_LICENSE("GPL"); |
50 | 52 | ||
53 | static bool hotplug_disabled; | ||
54 | |||
55 | module_param(hotplug_disabled, bool, 0644); | ||
56 | MODULE_PARM_DESC(hotplug_disabled, | ||
57 | "Disable hotplug for wireless device. " | ||
58 | "If your laptop need that, please report to " | ||
59 | "acpi4asus-user@lists.sourceforge.net."); | ||
60 | |||
51 | /* | 61 | /* |
52 | * Definitions for Asus EeePC | 62 | * Definitions for Asus EeePC |
53 | */ | 63 | */ |
@@ -120,38 +130,28 @@ static const char *cm_setv[] = { | |||
120 | NULL, NULL, "PBPS", "TPDS" | 130 | NULL, NULL, "PBPS", "TPDS" |
121 | }; | 131 | }; |
122 | 132 | ||
123 | struct key_entry { | ||
124 | char type; | ||
125 | u8 code; | ||
126 | u16 keycode; | ||
127 | }; | ||
128 | |||
129 | enum { KE_KEY, KE_END }; | ||
130 | |||
131 | static const struct key_entry eeepc_keymap[] = { | 133 | static const struct key_entry eeepc_keymap[] = { |
132 | /* Sleep already handled via generic ACPI code */ | 134 | { KE_KEY, 0x10, { KEY_WLAN } }, |
133 | {KE_KEY, 0x10, KEY_WLAN }, | 135 | { KE_KEY, 0x11, { KEY_WLAN } }, |
134 | {KE_KEY, 0x11, KEY_WLAN }, | 136 | { KE_KEY, 0x12, { KEY_PROG1 } }, |
135 | {KE_KEY, 0x12, KEY_PROG1 }, | 137 | { KE_KEY, 0x13, { KEY_MUTE } }, |
136 | {KE_KEY, 0x13, KEY_MUTE }, | 138 | { KE_KEY, 0x14, { KEY_VOLUMEDOWN } }, |
137 | {KE_KEY, 0x14, KEY_VOLUMEDOWN }, | 139 | { KE_KEY, 0x15, { KEY_VOLUMEUP } }, |
138 | {KE_KEY, 0x15, KEY_VOLUMEUP }, | 140 | { KE_KEY, 0x16, { KEY_DISPLAY_OFF } }, |
139 | {KE_KEY, 0x16, KEY_DISPLAY_OFF }, | 141 | { KE_KEY, 0x1a, { KEY_COFFEE } }, |
140 | {KE_KEY, 0x1a, KEY_COFFEE }, | 142 | { KE_KEY, 0x1b, { KEY_ZOOM } }, |
141 | {KE_KEY, 0x1b, KEY_ZOOM }, | 143 | { KE_KEY, 0x1c, { KEY_PROG2 } }, |
142 | {KE_KEY, 0x1c, KEY_PROG2 }, | 144 | { KE_KEY, 0x1d, { KEY_PROG3 } }, |
143 | {KE_KEY, 0x1d, KEY_PROG3 }, | 145 | { KE_KEY, NOTIFY_BRN_MIN, { KEY_BRIGHTNESSDOWN } }, |
144 | {KE_KEY, NOTIFY_BRN_MIN, KEY_BRIGHTNESSDOWN }, | 146 | { KE_KEY, NOTIFY_BRN_MAX, { KEY_BRIGHTNESSUP } }, |
145 | {KE_KEY, NOTIFY_BRN_MAX, KEY_BRIGHTNESSUP }, | 147 | { KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } }, |
146 | {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE }, | 148 | { KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } }, |
147 | {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE }, | 149 | { KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } }, |
148 | {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE }, | 150 | { KE_KEY, 0x37, { KEY_F13 } }, /* Disable Touchpad */ |
149 | {KE_KEY, 0x37, KEY_F13 }, /* Disable Touchpad */ | 151 | { KE_KEY, 0x38, { KEY_F14 } }, |
150 | {KE_KEY, 0x38, KEY_F14 }, | 152 | { KE_END, 0 }, |
151 | {KE_END, 0}, | ||
152 | }; | 153 | }; |
153 | 154 | ||
154 | |||
155 | /* | 155 | /* |
156 | * This is the main structure, we can use it to store useful information | 156 | * This is the main structure, we can use it to store useful information |
157 | */ | 157 | */ |
@@ -159,6 +159,8 @@ struct eeepc_laptop { | |||
159 | acpi_handle handle; /* the handle of the acpi device */ | 159 | acpi_handle handle; /* the handle of the acpi device */ |
160 | u32 cm_supported; /* the control methods supported | 160 | u32 cm_supported; /* the control methods supported |
161 | by this BIOS */ | 161 | by this BIOS */ |
162 | bool cpufv_disabled; | ||
163 | bool hotplug_disabled; | ||
162 | u16 event_count[128]; /* count for each event */ | 164 | u16 event_count[128]; /* count for each event */ |
163 | 165 | ||
164 | struct platform_device *platform_device; | 166 | struct platform_device *platform_device; |
@@ -378,6 +380,8 @@ static ssize_t store_cpufv(struct device *dev, | |||
378 | struct eeepc_cpufv c; | 380 | struct eeepc_cpufv c; |
379 | int rv, value; | 381 | int rv, value; |
380 | 382 | ||
383 | if (eeepc->cpufv_disabled) | ||
384 | return -EPERM; | ||
381 | if (get_cpufv(eeepc, &c)) | 385 | if (get_cpufv(eeepc, &c)) |
382 | return -ENODEV; | 386 | return -ENODEV; |
383 | rv = parse_arg(buf, count, &value); | 387 | rv = parse_arg(buf, count, &value); |
@@ -389,6 +393,41 @@ static ssize_t store_cpufv(struct device *dev, | |||
389 | return rv; | 393 | return rv; |
390 | } | 394 | } |
391 | 395 | ||
396 | static ssize_t show_cpufv_disabled(struct device *dev, | ||
397 | struct device_attribute *attr, | ||
398 | char *buf) | ||
399 | { | ||
400 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); | ||
401 | |||
402 | return sprintf(buf, "%d\n", eeepc->cpufv_disabled); | ||
403 | } | ||
404 | |||
405 | static ssize_t store_cpufv_disabled(struct device *dev, | ||
406 | struct device_attribute *attr, | ||
407 | const char *buf, size_t count) | ||
408 | { | ||
409 | struct eeepc_laptop *eeepc = dev_get_drvdata(dev); | ||
410 | int rv, value; | ||
411 | |||
412 | rv = parse_arg(buf, count, &value); | ||
413 | if (rv < 0) | ||
414 | return rv; | ||
415 | |||
416 | switch (value) { | ||
417 | case 0: | ||
418 | if (eeepc->cpufv_disabled) | ||
419 | pr_warning("cpufv enabled (not officially supported " | ||
420 | "on this model)\n"); | ||
421 | eeepc->cpufv_disabled = false; | ||
422 | return rv; | ||
423 | case 1: | ||
424 | return -EPERM; | ||
425 | default: | ||
426 | return -EINVAL; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | |||
392 | static struct device_attribute dev_attr_cpufv = { | 431 | static struct device_attribute dev_attr_cpufv = { |
393 | .attr = { | 432 | .attr = { |
394 | .name = "cpufv", | 433 | .name = "cpufv", |
@@ -404,12 +443,22 @@ static struct device_attribute dev_attr_available_cpufv = { | |||
404 | .show = show_available_cpufv | 443 | .show = show_available_cpufv |
405 | }; | 444 | }; |
406 | 445 | ||
446 | static struct device_attribute dev_attr_cpufv_disabled = { | ||
447 | .attr = { | ||
448 | .name = "cpufv_disabled", | ||
449 | .mode = 0644 }, | ||
450 | .show = show_cpufv_disabled, | ||
451 | .store = store_cpufv_disabled | ||
452 | }; | ||
453 | |||
454 | |||
407 | static struct attribute *platform_attributes[] = { | 455 | static struct attribute *platform_attributes[] = { |
408 | &dev_attr_camera.attr, | 456 | &dev_attr_camera.attr, |
409 | &dev_attr_cardr.attr, | 457 | &dev_attr_cardr.attr, |
410 | &dev_attr_disp.attr, | 458 | &dev_attr_disp.attr, |
411 | &dev_attr_cpufv.attr, | 459 | &dev_attr_cpufv.attr, |
412 | &dev_attr_available_cpufv.attr, | 460 | &dev_attr_available_cpufv.attr, |
461 | &dev_attr_cpufv_disabled.attr, | ||
413 | NULL | 462 | NULL |
414 | }; | 463 | }; |
415 | 464 | ||
@@ -796,6 +845,9 @@ static int eeepc_rfkill_init(struct eeepc_laptop *eeepc) | |||
796 | if (result && result != -ENODEV) | 845 | if (result && result != -ENODEV) |
797 | goto exit; | 846 | goto exit; |
798 | 847 | ||
848 | if (eeepc->hotplug_disabled) | ||
849 | return 0; | ||
850 | |||
799 | result = eeepc_setup_pci_hotplug(eeepc); | 851 | result = eeepc_setup_pci_hotplug(eeepc); |
800 | /* | 852 | /* |
801 | * If we get -EBUSY then something else is handling the PCI hotplug - | 853 | * If we get -EBUSY then something else is handling the PCI hotplug - |
@@ -1090,120 +1142,42 @@ static void eeepc_backlight_exit(struct eeepc_laptop *eeepc) | |||
1090 | /* | 1142 | /* |
1091 | * Input device (i.e. hotkeys) | 1143 | * Input device (i.e. hotkeys) |
1092 | */ | 1144 | */ |
1093 | static struct key_entry *eeepc_get_entry_by_scancode( | 1145 | static int eeepc_input_init(struct eeepc_laptop *eeepc) |
1094 | struct eeepc_laptop *eeepc, | ||
1095 | int code) | ||
1096 | { | 1146 | { |
1097 | struct key_entry *key; | 1147 | struct input_dev *input; |
1148 | int error; | ||
1098 | 1149 | ||
1099 | for (key = eeepc->keymap; key->type != KE_END; key++) | 1150 | input = input_allocate_device(); |
1100 | if (code == key->code) | 1151 | if (!input) { |
1101 | return key; | 1152 | pr_info("Unable to allocate input device\n"); |
1102 | 1153 | return -ENOMEM; | |
1103 | return NULL; | ||
1104 | } | ||
1105 | |||
1106 | static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event) | ||
1107 | { | ||
1108 | static struct key_entry *key; | ||
1109 | |||
1110 | key = eeepc_get_entry_by_scancode(eeepc, event); | ||
1111 | if (key) { | ||
1112 | switch (key->type) { | ||
1113 | case KE_KEY: | ||
1114 | input_report_key(eeepc->inputdev, key->keycode, | ||
1115 | 1); | ||
1116 | input_sync(eeepc->inputdev); | ||
1117 | input_report_key(eeepc->inputdev, key->keycode, | ||
1118 | 0); | ||
1119 | input_sync(eeepc->inputdev); | ||
1120 | break; | ||
1121 | } | ||
1122 | } | 1154 | } |
1123 | } | ||
1124 | |||
1125 | static struct key_entry *eeepc_get_entry_by_keycode( | ||
1126 | struct eeepc_laptop *eeepc, int code) | ||
1127 | { | ||
1128 | struct key_entry *key; | ||
1129 | |||
1130 | for (key = eeepc->keymap; key->type != KE_END; key++) | ||
1131 | if (code == key->keycode && key->type == KE_KEY) | ||
1132 | return key; | ||
1133 | 1155 | ||
1134 | return NULL; | 1156 | input->name = "Asus EeePC extra buttons"; |
1135 | } | 1157 | input->phys = EEEPC_LAPTOP_FILE "/input0"; |
1158 | input->id.bustype = BUS_HOST; | ||
1159 | input->dev.parent = &eeepc->platform_device->dev; | ||
1136 | 1160 | ||
1137 | static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode) | 1161 | error = sparse_keymap_setup(input, eeepc_keymap, NULL); |
1138 | { | 1162 | if (error) { |
1139 | struct eeepc_laptop *eeepc = input_get_drvdata(dev); | 1163 | pr_err("Unable to setup input device keymap\n"); |
1140 | struct key_entry *key = eeepc_get_entry_by_scancode(eeepc, scancode); | 1164 | goto err_free_dev; |
1141 | |||
1142 | if (key && key->type == KE_KEY) { | ||
1143 | *keycode = key->keycode; | ||
1144 | return 0; | ||
1145 | } | 1165 | } |
1146 | 1166 | ||
1147 | return -EINVAL; | 1167 | error = input_register_device(input); |
1148 | } | 1168 | if (error) { |
1149 | 1169 | pr_err("Unable to register input device\n"); | |
1150 | static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode) | 1170 | goto err_free_keymap; |
1151 | { | ||
1152 | struct eeepc_laptop *eeepc = input_get_drvdata(dev); | ||
1153 | struct key_entry *key; | ||
1154 | int old_keycode; | ||
1155 | |||
1156 | if (keycode < 0 || keycode > KEY_MAX) | ||
1157 | return -EINVAL; | ||
1158 | |||
1159 | key = eeepc_get_entry_by_scancode(eeepc, scancode); | ||
1160 | if (key && key->type == KE_KEY) { | ||
1161 | old_keycode = key->keycode; | ||
1162 | key->keycode = keycode; | ||
1163 | set_bit(keycode, dev->keybit); | ||
1164 | if (!eeepc_get_entry_by_keycode(eeepc, old_keycode)) | ||
1165 | clear_bit(old_keycode, dev->keybit); | ||
1166 | return 0; | ||
1167 | } | 1171 | } |
1168 | 1172 | ||
1169 | return -EINVAL; | 1173 | eeepc->inputdev = input; |
1170 | } | ||
1171 | |||
1172 | static int eeepc_input_init(struct eeepc_laptop *eeepc) | ||
1173 | { | ||
1174 | const struct key_entry *key; | ||
1175 | int result; | ||
1176 | |||
1177 | eeepc->inputdev = input_allocate_device(); | ||
1178 | if (!eeepc->inputdev) { | ||
1179 | pr_info("Unable to allocate input device\n"); | ||
1180 | return -ENOMEM; | ||
1181 | } | ||
1182 | eeepc->inputdev->name = "Asus EeePC extra buttons"; | ||
1183 | eeepc->inputdev->dev.parent = &eeepc->platform_device->dev; | ||
1184 | eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0"; | ||
1185 | eeepc->inputdev->id.bustype = BUS_HOST; | ||
1186 | eeepc->inputdev->getkeycode = eeepc_getkeycode; | ||
1187 | eeepc->inputdev->setkeycode = eeepc_setkeycode; | ||
1188 | input_set_drvdata(eeepc->inputdev, eeepc); | ||
1189 | |||
1190 | eeepc->keymap = kmemdup(eeepc_keymap, sizeof(eeepc_keymap), | ||
1191 | GFP_KERNEL); | ||
1192 | for (key = eeepc_keymap; key->type != KE_END; key++) { | ||
1193 | switch (key->type) { | ||
1194 | case KE_KEY: | ||
1195 | set_bit(EV_KEY, eeepc->inputdev->evbit); | ||
1196 | set_bit(key->keycode, eeepc->inputdev->keybit); | ||
1197 | break; | ||
1198 | } | ||
1199 | } | ||
1200 | result = input_register_device(eeepc->inputdev); | ||
1201 | if (result) { | ||
1202 | pr_info("Unable to register input device\n"); | ||
1203 | input_free_device(eeepc->inputdev); | ||
1204 | return result; | ||
1205 | } | ||
1206 | return 0; | 1174 | return 0; |
1175 | |||
1176 | err_free_keymap: | ||
1177 | sparse_keymap_free(input); | ||
1178 | err_free_dev: | ||
1179 | input_free_device(input); | ||
1180 | return error; | ||
1207 | } | 1181 | } |
1208 | 1182 | ||
1209 | static void eeepc_input_exit(struct eeepc_laptop *eeepc) | 1183 | static void eeepc_input_exit(struct eeepc_laptop *eeepc) |
@@ -1253,11 +1227,59 @@ static void eeepc_acpi_notify(struct acpi_device *device, u32 event) | |||
1253 | * event will be desired value (or else ignored) | 1227 | * event will be desired value (or else ignored) |
1254 | */ | 1228 | */ |
1255 | } | 1229 | } |
1256 | eeepc_input_notify(eeepc, event); | 1230 | sparse_keymap_report_event(eeepc->inputdev, event, |
1231 | 1, true); | ||
1257 | } | 1232 | } |
1258 | } else { | 1233 | } else { |
1259 | /* Everything else is a bona-fide keypress event */ | 1234 | /* Everything else is a bona-fide keypress event */ |
1260 | eeepc_input_notify(eeepc, event); | 1235 | sparse_keymap_report_event(eeepc->inputdev, event, 1, true); |
1236 | } | ||
1237 | } | ||
1238 | |||
1239 | static void eeepc_dmi_check(struct eeepc_laptop *eeepc) | ||
1240 | { | ||
1241 | const char *model; | ||
1242 | |||
1243 | model = dmi_get_system_info(DMI_PRODUCT_NAME); | ||
1244 | if (!model) | ||
1245 | return; | ||
1246 | |||
1247 | /* | ||
1248 | * Blacklist for setting cpufv (cpu speed). | ||
1249 | * | ||
1250 | * EeePC 4G ("701") implements CFVS, but it is not supported | ||
1251 | * by the pre-installed OS, and the original option to change it | ||
1252 | * in the BIOS setup screen was removed in later versions. | ||
1253 | * | ||
1254 | * Judging by the lack of "Super Hybrid Engine" on Asus product pages, | ||
1255 | * this applies to all "701" models (4G/4G Surf/2G Surf). | ||
1256 | * | ||
1257 | * So Asus made a deliberate decision not to support it on this model. | ||
1258 | * We have several reports that using it can cause the system to hang | ||
1259 | * | ||
1260 | * The hang has also been reported on a "702" (Model name "8G"?). | ||
1261 | * | ||
1262 | * We avoid dmi_check_system() / dmi_match(), because they use | ||
1263 | * substring matching. We don't want to affect the "701SD" | ||
1264 | * and "701SDX" models, because they do support S.H.E. | ||
1265 | */ | ||
1266 | if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) { | ||
1267 | eeepc->cpufv_disabled = true; | ||
1268 | pr_info("model %s does not officially support setting cpu " | ||
1269 | "speed\n", model); | ||
1270 | pr_info("cpufv disabled to avoid instability\n"); | ||
1271 | } | ||
1272 | |||
1273 | /* | ||
1274 | * Blacklist for wlan hotplug | ||
1275 | * | ||
1276 | * Eeepc 1005HA doesn't work like others models and don't need the | ||
1277 | * hotplug code. In fact, current hotplug code seems to unplug another | ||
1278 | * device... | ||
1279 | */ | ||
1280 | if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0) { | ||
1281 | eeepc->hotplug_disabled = true; | ||
1282 | pr_info("wlan hotplug disabled\n"); | ||
1261 | } | 1283 | } |
1262 | } | 1284 | } |
1263 | 1285 | ||
@@ -1342,6 +1364,10 @@ static int __devinit eeepc_acpi_add(struct acpi_device *device) | |||
1342 | strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS); | 1364 | strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS); |
1343 | device->driver_data = eeepc; | 1365 | device->driver_data = eeepc; |
1344 | 1366 | ||
1367 | eeepc->hotplug_disabled = hotplug_disabled; | ||
1368 | |||
1369 | eeepc_dmi_check(eeepc); | ||
1370 | |||
1345 | result = eeepc_acpi_init(eeepc, device); | 1371 | result = eeepc_acpi_init(eeepc, device); |
1346 | if (result) | 1372 | if (result) |
1347 | goto fail_platform; | 1373 | goto fail_platform; |
@@ -1452,10 +1478,12 @@ static int __init eeepc_laptop_init(void) | |||
1452 | result = acpi_bus_register_driver(&eeepc_acpi_driver); | 1478 | result = acpi_bus_register_driver(&eeepc_acpi_driver); |
1453 | if (result < 0) | 1479 | if (result < 0) |
1454 | goto fail_acpi_driver; | 1480 | goto fail_acpi_driver; |
1481 | |||
1455 | if (!eeepc_device_present) { | 1482 | if (!eeepc_device_present) { |
1456 | result = -ENODEV; | 1483 | result = -ENODEV; |
1457 | goto fail_no_device; | 1484 | goto fail_no_device; |
1458 | } | 1485 | } |
1486 | |||
1459 | return 0; | 1487 | return 0; |
1460 | 1488 | ||
1461 | fail_no_device: | 1489 | fail_no_device: |