eeepc-laptop.c (10ae4b5663ff3092553bfbd867e7bd474ce6c553) | eeepc-laptop.c (642e0447cb910ceabae0b4ea6c0cd3449d5c5abb) |
---|---|
1/* 2 * eeepc-laptop.c - Asus Eee PC extras 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 --- 17 unchanged lines hidden (view full) --- 26#include <linux/backlight.h> 27#include <linux/fb.h> 28#include <linux/hwmon.h> 29#include <linux/hwmon-sysfs.h> 30#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_bus.h> 32#include <linux/uaccess.h> 33#include <linux/input.h> | 1/* 2 * eeepc-laptop.c - Asus Eee PC extras 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 --- 17 unchanged lines hidden (view full) --- 26#include <linux/backlight.h> 27#include <linux/fb.h> 28#include <linux/hwmon.h> 29#include <linux/hwmon-sysfs.h> 30#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_bus.h> 32#include <linux/uaccess.h> 33#include <linux/input.h> |
34#include <linux/input/sparse-keymap.h> |
|
34#include <linux/rfkill.h> 35#include <linux/pci.h> 36#include <linux/pci_hotplug.h> 37#include <linux/leds.h> 38#include <linux/dmi.h> 39 40#define EEEPC_LAPTOP_VERSION "0.1" 41#define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver" --- 74 unchanged lines hidden (view full) --- 116 "CAMS", NULL, NULL, NULL, 117 "SDSP", "PBLS", "HDPS", NULL, 118 "CFVS", NULL, NULL, NULL, 119 "USBG", NULL, NULL, "MODS", 120 "CRDS", "M3GS", "WIMS", NULL, 121 NULL, NULL, "PBPS", "TPDS" 122}; 123 | 35#include <linux/rfkill.h> 36#include <linux/pci.h> 37#include <linux/pci_hotplug.h> 38#include <linux/leds.h> 39#include <linux/dmi.h> 40 41#define EEEPC_LAPTOP_VERSION "0.1" 42#define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver" --- 74 unchanged lines hidden (view full) --- 117 "CAMS", NULL, NULL, NULL, 118 "SDSP", "PBLS", "HDPS", NULL, 119 "CFVS", NULL, NULL, NULL, 120 "USBG", NULL, NULL, "MODS", 121 "CRDS", "M3GS", "WIMS", NULL, 122 NULL, NULL, "PBPS", "TPDS" 123}; 124 |
124struct key_entry { 125 char type; 126 u8 code; 127 u16 keycode; 128}; 129 130enum { KE_KEY, KE_END }; 131 | |
132static const struct key_entry eeepc_keymap[] = { | 125static const struct key_entry eeepc_keymap[] = { |
133 /* Sleep already handled via generic ACPI code */ 134 {KE_KEY, 0x10, KEY_WLAN }, 135 {KE_KEY, 0x11, KEY_WLAN }, 136 {KE_KEY, 0x12, KEY_PROG1 }, 137 {KE_KEY, 0x13, KEY_MUTE }, 138 {KE_KEY, 0x14, KEY_VOLUMEDOWN }, 139 {KE_KEY, 0x15, KEY_VOLUMEUP }, 140 {KE_KEY, 0x16, KEY_DISPLAY_OFF }, 141 {KE_KEY, 0x1a, KEY_COFFEE }, 142 {KE_KEY, 0x1b, KEY_ZOOM }, 143 {KE_KEY, 0x1c, KEY_PROG2 }, 144 {KE_KEY, 0x1d, KEY_PROG3 }, 145 {KE_KEY, NOTIFY_BRN_MIN, KEY_BRIGHTNESSDOWN }, 146 {KE_KEY, NOTIFY_BRN_MAX, KEY_BRIGHTNESSUP }, 147 {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE }, 148 {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE }, 149 {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE }, 150 {KE_KEY, 0x37, KEY_F13 }, /* Disable Touchpad */ 151 {KE_KEY, 0x38, KEY_F14 }, 152 {KE_END, 0}, | 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 }, |
153}; 154 | 145}; 146 |
155 | |
156/* 157 * This is the main structure, we can use it to store useful information 158 */ 159struct eeepc_laptop { 160 acpi_handle handle; /* the handle of the acpi device */ 161 u32 cm_supported; /* the control methods supported 162 by this BIOS */ 163 bool cpufv_disabled; --- 974 unchanged lines hidden (view full) --- 1138 backlight_device_unregister(eeepc->backlight_device); 1139 eeepc->backlight_device = NULL; 1140} 1141 1142 1143/* 1144 * Input device (i.e. hotkeys) 1145 */ | 147/* 148 * This is the main structure, we can use it to store useful information 149 */ 150struct eeepc_laptop { 151 acpi_handle handle; /* the handle of the acpi device */ 152 u32 cm_supported; /* the control methods supported 153 by this BIOS */ 154 bool cpufv_disabled; --- 974 unchanged lines hidden (view full) --- 1129 backlight_device_unregister(eeepc->backlight_device); 1130 eeepc->backlight_device = NULL; 1131} 1132 1133 1134/* 1135 * Input device (i.e. hotkeys) 1136 */ |
1146static struct key_entry *eeepc_get_entry_by_scancode( 1147 struct eeepc_laptop *eeepc, 1148 int code) 1149{ 1150 struct key_entry *key; 1151 1152 for (key = eeepc->keymap; key->type != KE_END; key++) 1153 if (code == key->code) 1154 return key; 1155 1156 return NULL; 1157} 1158 1159static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event) 1160{ 1161 static struct key_entry *key; 1162 1163 key = eeepc_get_entry_by_scancode(eeepc, event); 1164 if (key) { 1165 switch (key->type) { 1166 case KE_KEY: 1167 input_report_key(eeepc->inputdev, key->keycode, 1168 1); 1169 input_sync(eeepc->inputdev); 1170 input_report_key(eeepc->inputdev, key->keycode, 1171 0); 1172 input_sync(eeepc->inputdev); 1173 break; 1174 } 1175 } 1176} 1177 1178static struct key_entry *eeepc_get_entry_by_keycode( 1179 struct eeepc_laptop *eeepc, int code) 1180{ 1181 struct key_entry *key; 1182 1183 for (key = eeepc->keymap; key->type != KE_END; key++) 1184 if (code == key->keycode && key->type == KE_KEY) 1185 return key; 1186 1187 return NULL; 1188} 1189 1190static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode) 1191{ 1192 struct eeepc_laptop *eeepc = input_get_drvdata(dev); 1193 struct key_entry *key = eeepc_get_entry_by_scancode(eeepc, scancode); 1194 1195 if (key && key->type == KE_KEY) { 1196 *keycode = key->keycode; 1197 return 0; 1198 } 1199 1200 return -EINVAL; 1201} 1202 1203static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode) 1204{ 1205 struct eeepc_laptop *eeepc = input_get_drvdata(dev); 1206 struct key_entry *key; 1207 int old_keycode; 1208 1209 if (keycode < 0 || keycode > KEY_MAX) 1210 return -EINVAL; 1211 1212 key = eeepc_get_entry_by_scancode(eeepc, scancode); 1213 if (key && key->type == KE_KEY) { 1214 old_keycode = key->keycode; 1215 key->keycode = keycode; 1216 set_bit(keycode, dev->keybit); 1217 if (!eeepc_get_entry_by_keycode(eeepc, old_keycode)) 1218 clear_bit(old_keycode, dev->keybit); 1219 return 0; 1220 } 1221 1222 return -EINVAL; 1223} 1224 | |
1225static int eeepc_input_init(struct eeepc_laptop *eeepc) 1226{ | 1137static int eeepc_input_init(struct eeepc_laptop *eeepc) 1138{ |
1227 const struct key_entry *key; 1228 int result; | 1139 struct input_dev *input; 1140 int error; |
1229 | 1141 |
1230 eeepc->inputdev = input_allocate_device(); 1231 if (!eeepc->inputdev) { | 1142 input = input_allocate_device(); 1143 if (!input) { |
1232 pr_info("Unable to allocate input device\n"); 1233 return -ENOMEM; 1234 } | 1144 pr_info("Unable to allocate input device\n"); 1145 return -ENOMEM; 1146 } |
1235 eeepc->inputdev->name = "Asus EeePC extra buttons"; 1236 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev; 1237 eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0"; 1238 eeepc->inputdev->id.bustype = BUS_HOST; 1239 eeepc->inputdev->getkeycode = eeepc_getkeycode; 1240 eeepc->inputdev->setkeycode = eeepc_setkeycode; 1241 input_set_drvdata(eeepc->inputdev, eeepc); | |
1242 | 1147 |
1243 eeepc->keymap = kmemdup(eeepc_keymap, sizeof(eeepc_keymap), 1244 GFP_KERNEL); 1245 for (key = eeepc_keymap; key->type != KE_END; key++) { 1246 switch (key->type) { 1247 case KE_KEY: 1248 set_bit(EV_KEY, eeepc->inputdev->evbit); 1249 set_bit(key->keycode, eeepc->inputdev->keybit); 1250 break; 1251 } | 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; |
1252 } | 1157 } |
1253 result = input_register_device(eeepc->inputdev); 1254 if (result) { 1255 pr_info("Unable to register input device\n"); 1256 input_free_device(eeepc->inputdev); 1257 return result; | 1158 1159 error = input_register_device(input); 1160 if (error) { 1161 pr_err("Unable to register input device\n"); 1162 goto err_free_keymap; |
1258 } | 1163 } |
1164 1165 eeepc->inputdev = input; |
|
1259 return 0; | 1166 return 0; |
1167 1168 err_free_keymap: 1169 sparse_keymap_free(input); 1170 err_free_dev: 1171 input_free_device(input); 1172 return error; |
|
1260} 1261 1262static void eeepc_input_exit(struct eeepc_laptop *eeepc) 1263{ 1264 if (eeepc->inputdev) { 1265 input_unregister_device(eeepc->inputdev); 1266 kfree(eeepc->keymap); 1267 } --- 33 unchanged lines hidden (view full) --- 1301 } else if (new_brightness > old_brightness) { 1302 event = NOTIFY_BRN_MAX; /* brightness up */ 1303 } else { 1304 /* 1305 * no change in brightness - already at min/max, 1306 * event will be desired value (or else ignored) 1307 */ 1308 } | 1173} 1174 1175static void eeepc_input_exit(struct eeepc_laptop *eeepc) 1176{ 1177 if (eeepc->inputdev) { 1178 input_unregister_device(eeepc->inputdev); 1179 kfree(eeepc->keymap); 1180 } --- 33 unchanged lines hidden (view full) --- 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 } |
1309 eeepc_input_notify(eeepc, event); | 1222 sparse_keymap_report_event(eeepc->inputdev, event, 1223 1, true); |
1310 } 1311 } else { 1312 /* Everything else is a bona-fide keypress event */ | 1224 } 1225 } else { 1226 /* Everything else is a bona-fide keypress event */ |
1313 eeepc_input_notify(eeepc, event); | 1227 sparse_keymap_report_event(eeepc->inputdev, event, 1, true); |
1314 } 1315} 1316 1317static void eeepc_dmi_check(struct eeepc_laptop *eeepc) 1318{ 1319 const char *model; 1320 1321 model = dmi_get_system_info(DMI_PRODUCT_NAME); --- 227 unchanged lines hidden (view full) --- 1549 1550 result = platform_driver_register(&platform_driver); 1551 if (result < 0) 1552 return result; 1553 1554 result = acpi_bus_register_driver(&eeepc_acpi_driver); 1555 if (result < 0) 1556 goto fail_acpi_driver; | 1228 } 1229} 1230 1231static void eeepc_dmi_check(struct eeepc_laptop *eeepc) 1232{ 1233 const char *model; 1234 1235 model = dmi_get_system_info(DMI_PRODUCT_NAME); --- 227 unchanged lines hidden (view full) --- 1463 1464 result = platform_driver_register(&platform_driver); 1465 if (result < 0) 1466 return result; 1467 1468 result = acpi_bus_register_driver(&eeepc_acpi_driver); 1469 if (result < 0) 1470 goto fail_acpi_driver; |
1471 |
|
1557 if (!eeepc_device_present) { 1558 result = -ENODEV; 1559 goto fail_no_device; 1560 } | 1472 if (!eeepc_device_present) { 1473 result = -ENODEV; 1474 goto fail_no_device; 1475 } |
1476 |
|
1561 return 0; 1562 1563fail_no_device: 1564 acpi_bus_unregister_driver(&eeepc_acpi_driver); 1565fail_acpi_driver: 1566 platform_driver_unregister(&platform_driver); 1567 return result; 1568} 1569 1570static void __exit eeepc_laptop_exit(void) 1571{ 1572 acpi_bus_unregister_driver(&eeepc_acpi_driver); 1573 platform_driver_unregister(&platform_driver); 1574} 1575 1576module_init(eeepc_laptop_init); 1577module_exit(eeepc_laptop_exit); | 1477 return 0; 1478 1479fail_no_device: 1480 acpi_bus_unregister_driver(&eeepc_acpi_driver); 1481fail_acpi_driver: 1482 platform_driver_unregister(&platform_driver); 1483 return result; 1484} 1485 1486static void __exit eeepc_laptop_exit(void) 1487{ 1488 acpi_bus_unregister_driver(&eeepc_acpi_driver); 1489 platform_driver_unregister(&platform_driver); 1490} 1491 1492module_init(eeepc_laptop_init); 1493module_exit(eeepc_laptop_exit); |