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

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

Return to bug 448004