View | Details | Raw Unified | Return to bug 448004
Collapse All | Expand All

(-)a/drivers/misc/asus-laptop.c (-2 / +182 lines)
Lines 24-29 Link Here
24
 *  http://sourceforge.net/projects/acpi4asus/
24
 *  http://sourceforge.net/projects/acpi4asus/
25
 *
25
 *
26
 *  Credits:
26
 *  Credits:
27
 *  Nicolas Trangez  - Initial work to let ACPI buttons work over INPUT layer
27
 *  Pontus Fuchs   - Helper functions, cleanup
28
 *  Pontus Fuchs   - Helper functions, cleanup
28
 *  Johann Wiesner - Small compile fixes
29
 *  Johann Wiesner - Small compile fixes
29
 *  John Belmonte  - ACPI code for Toshiba laptop was a good starting point.
30
 *  John Belmonte  - ACPI code for Toshiba laptop was a good starting point.
Lines 46-51 Link Here
46
#include <acpi/acpi_drivers.h>
47
#include <acpi/acpi_drivers.h>
47
#include <acpi/acpi_bus.h>
48
#include <acpi/acpi_bus.h>
48
#include <asm/uaccess.h>
49
#include <asm/uaccess.h>
50
#include <linux/input.h>
51
#include <linux/pci_ids.h>
49
52
50
#define ASUS_LAPTOP_VERSION "0.42"
53
#define ASUS_LAPTOP_VERSION "0.42"
51
54
Lines 250-255 ASUS_LED(rled, "record"); Link Here
250
ASUS_LED(pled, "phone");
253
ASUS_LED(pled, "phone");
251
ASUS_LED(gled, "gaming");
254
ASUS_LED(gled, "gaming");
252
255
256
/* Input layer variables */
257
static u16 *hotk_keycode_map;
258
static int hotk_keycode_map_size;
259
static struct input_dev *asus_hotk_inputdev;
260
static int asus_hotk_inputdev_registered;
261
253
/*
262
/*
254
 * This function evaluates an ACPI method, given an int as parameter, the
263
 * This function evaluates an ACPI method, given an int as parameter, the
255
 * method is searched within the scope of the handle, can be NULL. The output
264
 * method is searched within the scope of the handle, can be NULL. The output
Lines 722-727 static ssize_t store_gps(struct device *dev, struct device_attribute *attr, Link Here
722
731
723
static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
732
static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
724
{
733
{
734
	int keycode;
735
725
	/* TODO Find a better way to handle events count. */
736
	/* TODO Find a better way to handle events count. */
726
	if (!hotk)
737
	if (!hotk)
727
		return;
738
		return;
Lines 738-744 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) Link Here
738
		lcd_blank(FB_BLANK_POWERDOWN);
749
		lcd_blank(FB_BLANK_POWERDOWN);
739
	}
750
	}
740
751
741
	acpi_bus_generate_proc_event(hotk->device, event,
752
	if (event < hotk_keycode_map_size) {
753
		keycode = hotk_keycode_map[event];
754
		printk("Keycode: %04x (%d)\n", keycode, keycode);
755
	} else {
756
		keycode = KEY_UNKNOWN;
757
		printk("Scancode %d out of keymap\n", event);
758
	}
759
760
	if (keycode != KEY_RESERVED) {
761
		input_report_key(asus_hotk_inputdev, keycode, 1);
762
		if (keycode == KEY_UNKNOWN)
763
			input_event(asus_hotk_inputdev, EV_MSC, MSC_SCAN, event);
764
		input_sync(asus_hotk_inputdev);
765
766
		input_report_key(asus_hotk_inputdev, keycode, 0);
767
		if (keycode == KEY_UNKNOWN)
768
			input_event(asus_hotk_inputdev, EV_MSC, MSC_SCAN, event);
769
		input_sync(asus_hotk_inputdev);
770
	}
771
772
	if (keycode == KEY_RESERVED || keycode == KEY_UNKNOWN)
773
		acpi_bus_generate_proc_event(hotk->device, event,
742
				hotk->event_count[event % 128]++);
774
				hotk->event_count[event % 128]++);
743
775
744
	return;
776
	return;
Lines 1071-1076 static int asus_hotk_remove(struct acpi_device *device, int type) Link Here
1071
	return 0;
1103
	return 0;
1072
}
1104
}
1073
1105
1106
static void asus_hotk_exit(void)
1107
{
1108
	if (asus_hotk_inputdev) {
1109
		if (asus_hotk_inputdev_registered)
1110
			input_unregister_device(asus_hotk_inputdev);
1111
		else
1112
			input_free_device(asus_hotk_inputdev);
1113
	}
1114
}
1115
1074
static void asus_backlight_exit(void)
1116
static void asus_backlight_exit(void)
1075
{
1117
{
1076
	if (asus_backlight_device)
1118
	if (asus_backlight_device)
Lines 1095-1100 static void __exit asus_laptop_exit(void) Link Here
1095
{
1137
{
1096
	asus_backlight_exit();
1138
	asus_backlight_exit();
1097
	asus_led_exit();
1139
	asus_led_exit();
1140
	asus_hotk_exit();
1098
1141
1099
	acpi_bus_unregister_driver(&asus_hotk_driver);
1142
	acpi_bus_unregister_driver(&asus_hotk_driver);
1100
	sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1143
	sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
Lines 1102-1107 static void __exit asus_laptop_exit(void) Link Here
1102
	platform_driver_unregister(&asuspf_driver);
1145
	platform_driver_unregister(&asuspf_driver);
1103
}
1146
}
1104
1147
1148
static int asus_hotk_init(void)
1149
{
1150
	int ret, i;
1151
1152
	static u16 keycode_map_1[] __initdata = {
1153
		KEY_UNKNOWN, /* 0 */
1154
		KEY_UNKNOWN, /* 1 */
1155
		KEY_UNKNOWN, /* 2 */
1156
		KEY_UNKNOWN, /* 3 */
1157
		KEY_UNKNOWN, /* 4 */
1158
		KEY_UNKNOWN, /* 5 */
1159
		KEY_UNKNOWN, /* 6 */
1160
		KEY_UNKNOWN, /* 7 */
1161
		KEY_UNKNOWN, /* 8 */
1162
		KEY_UNKNOWN, /* 9 */
1163
		KEY_UNKNOWN, /* 10 */
1164
		KEY_UNKNOWN, /* 11 */
1165
		KEY_UNKNOWN, /* 12 */
1166
		KEY_UNKNOWN, /* 13 */
1167
		KEY_UNKNOWN, /* 14 */
1168
		KEY_UNKNOWN, /* 15 */
1169
		KEY_UNKNOWN, /* 16 */
1170
		KEY_UNKNOWN, /* 17 */
1171
		KEY_UNKNOWN, /* 18 */
1172
		KEY_UNKNOWN, /* 19 */
1173
		KEY_UNKNOWN, /* 20 */
1174
		KEY_UNKNOWN, /* 21 */
1175
		KEY_UNKNOWN, /* 22 */
1176
		KEY_UNKNOWN, /* 23 */
1177
		KEY_UNKNOWN, /* 24 */
1178
		KEY_UNKNOWN, /* 25 */
1179
		KEY_UNKNOWN, /* 26 */
1180
		KEY_UNKNOWN, /* 27 */
1181
		KEY_UNKNOWN, /* 28 */
1182
		KEY_UNKNOWN, /* 29 */
1183
		KEY_UNKNOWN, /* 30 */
1184
		KEY_UNKNOWN, /* 31 */
1185
		KEY_UNKNOWN, /* 32 */
1186
		KEY_UNKNOWN, /* 33 */
1187
		KEY_UNKNOWN, /* 34 */
1188
		KEY_UNKNOWN, /* 35 */
1189
		KEY_UNKNOWN, /* 36 */
1190
		KEY_UNKNOWN, /* 37 */
1191
		KEY_UNKNOWN, /* 38 */
1192
		KEY_UNKNOWN, /* 39 */
1193
		KEY_UNKNOWN, /* 40 */
1194
		KEY_UNKNOWN, /* 41 */
1195
		KEY_UNKNOWN, /* 42 */
1196
		KEY_UNKNOWN, /* 43 */
1197
		KEY_UNKNOWN, /* 44 */
1198
		KEY_UNKNOWN, /* 45 */
1199
		KEY_UNKNOWN, /* 46 */
1200
		KEY_UNKNOWN, /* 47 */
1201
		KEY_UNKNOWN, /* 48 */
1202
		KEY_UNKNOWN, /* 49 */
1203
		KEY_UNKNOWN, /* 50 */
1204
		KEY_UNKNOWN, /* 51 */
1205
		KEY_UNKNOWN, /* 52 */
1206
		KEY_UNKNOWN, /* 53 */
1207
		KEY_UNKNOWN, /* 54 */
1208
		KEY_UNKNOWN, /* 55 */
1209
		KEY_UNKNOWN, /* 56 */
1210
		KEY_UNKNOWN, /* 57 */
1211
		KEY_UNKNOWN, /* 58 */
1212
		KEY_UNKNOWN, /* 59 */
1213
		KEY_UNKNOWN, /* 60 */
1214
		KEY_UNKNOWN, /* 61 */
1215
		KEY_UNKNOWN, /* 62 */
1216
		KEY_UNKNOWN, /* 63 */
1217
		KEY_PREVIOUSSONG, /* 64 */
1218
		KEY_NEXTSONG, /* 65 */
1219
		KEY_UNKNOWN, /* 66 */
1220
		KEY_STOP, /* 67 */
1221
		KEY_UNKNOWN, /* 68 */
1222
		KEY_PLAYPAUSE, /* 69 */
1223
		KEY_UNKNOWN, /* 70 */
1224
	};
1225
1226
#define ASUS_HOTK_MAP_LEN       ARRAY_SIZE(keycode_map_1)
1227
#define ASUS_HOTK_MAP_SIZE      sizeof(keycode_map_1)
1228
#define ASUS_HOTK_MAP_TYPESIZE  sizeof(keycode_map_1[0])
1229
1230
	/* Always use first keymap. TODO make this model-specific */
1231
	hotk_keycode_map = kmalloc(ASUS_HOTK_MAP_SIZE, GFP_KERNEL);
1232
	hotk_keycode_map_size = ASUS_HOTK_MAP_LEN;
1233
	if (!hotk_keycode_map) {
1234
		printk(ASUS_ERR "failed to allocate memory for keymap\n");
1235
		return -ENOMEM;
1236
	}
1237
	printk(ASUS_NOTICE "using keycode_map_1\n");
1238
	memcpy(hotk_keycode_map, &keycode_map_1, ASUS_HOTK_MAP_SIZE);
1239
	/* TODO make sure no ACPI events are sent on known keycodes */
1240
1241
	asus_hotk_inputdev = input_allocate_device();
1242
	if (!asus_hotk_inputdev) {
1243
		printk(ASUS_ERR "unable to allocate input device\n");
1244
		return -ENOMEM;
1245
	}
1246
	asus_hotk_inputdev->name = "Asus Extra Buttons";
1247
	asus_hotk_inputdev->phys = ASUS_HOTK_FILE "/input0";
1248
	asus_hotk_inputdev->id.bustype = BUS_HOST;
1249
	asus_hotk_inputdev->id.vendor = PCI_VENDOR_ID_ASUSTEK;
1250
	/* TODO
1251
	asus_hotk_inputdev->id.product =
1252
	asus_hotk_inputdev->id.version =
1253
	*/
1254
1255
	set_bit(EV_KEY, asus_hotk_inputdev->evbit);
1256
	set_bit(EV_MSC, asus_hotk_inputdev->evbit);
1257
	set_bit(MSC_SCAN, asus_hotk_inputdev->mscbit);
1258
	asus_hotk_inputdev->keycodesize = ASUS_HOTK_MAP_TYPESIZE;
1259
	asus_hotk_inputdev->keycodemax = ASUS_HOTK_MAP_LEN;
1260
	asus_hotk_inputdev->keycode = hotk_keycode_map;
1261
	for (i = 0; i < ASUS_HOTK_MAP_LEN; i++) {
1262
		if (hotk_keycode_map[i] != KEY_RESERVED) {
1263
			set_bit(hotk_keycode_map[i], asus_hotk_inputdev->keybit);
1264
		} /*else {
1265
			if (i < sizeof(hotk_reserved_mask)*8)
1266
				hotk_reserved_mask |= 1 << i;
1267
		}*/
1268
	}
1269
1270
	ret = input_register_device(asus_hotk_inputdev);
1271
	if (ret < 0) {
1272
		printk(ASUS_ERR "unable to register input device\n");
1273
		return ret;
1274
	}
1275
	asus_hotk_inputdev_registered = 1;
1276
1277
	return 0;
1278
}
1279
1105
static int asus_backlight_init(struct device *dev)
1280
static int asus_backlight_init(struct device *dev)
1106
{
1281
{
1107
	struct backlight_device *bd;
1282
	struct backlight_device *bd;
Lines 1208-1213 static int __init asus_laptop_init(void) Link Here
1208
1383
1209
	dev = acpi_get_physical_device(hotk->device->handle);
1384
	dev = acpi_get_physical_device(hotk->device->handle);
1210
1385
1386
 	result = asus_hotk_init();
1387
	if (result)
1388
		goto fail_hotk;
1389
1211
	if (!acpi_video_backlight_support()) {
1390
	if (!acpi_video_backlight_support()) {
1212
		result = asus_backlight_init(dev);
1391
		result = asus_backlight_init(dev);
1213
		if (result)
1392
		if (result)
Lines 1259-1264 static int __init asus_laptop_init(void) Link Here
1259
1438
1260
      fail_backlight:
1439
      fail_backlight:
1261
1440
1441
      fail_hotk:
1442
1262
	return result;
1443
	return result;
1263
}
1444
}
1264
1445
1265
- 

Return to bug 448004