| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * drivers/macintosh/mac_hid.c | 
 | 3 |  * | 
 | 4 |  * HID support stuff for Macintosh computers. | 
 | 5 |  * | 
 | 6 |  * Copyright (C) 2000 Franz Sirl. | 
 | 7 |  * | 
 | 8 |  * This file will soon be removed in favor of an uinput userspace tool. | 
 | 9 |  */ | 
 | 10 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> | 
 | 12 | #include <linux/proc_fs.h> | 
 | 13 | #include <linux/sysctl.h> | 
 | 14 | #include <linux/input.h> | 
 | 15 | #include <linux/module.h> | 
 | 16 |  | 
 | 17 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 18 | static struct input_dev *emumousebtn; | 
 | 19 | static int emumousebtn_input_register(void); | 
| Olaf Hering | 8727585 | 2007-02-10 21:35:12 +0100 | [diff] [blame] | 20 | static int mouse_emulate_buttons; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | static int mouse_button2_keycode = KEY_RIGHTCTRL;	/* right control key */ | 
 | 22 | static int mouse_button3_keycode = KEY_RIGHTALT;	/* right option key */ | 
| Olaf Hering | 8727585 | 2007-02-10 21:35:12 +0100 | [diff] [blame] | 23 | static int mouse_last_keycode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 |  | 
 | 25 | #if defined(CONFIG_SYSCTL) | 
 | 26 | /* file(s) in /proc/sys/dev/mac_hid */ | 
| Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 27 | static ctl_table mac_hid_files[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | 	{ | 
 | 29 | 		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON_EMULATION, | 
 | 30 | 		.procname	= "mouse_button_emulation", | 
 | 31 | 		.data		= &mouse_emulate_buttons, | 
 | 32 | 		.maxlen		= sizeof(int), | 
 | 33 | 		.mode		= 0644, | 
 | 34 | 		.proc_handler	= &proc_dointvec, | 
 | 35 | 	}, | 
 | 36 | 	{ | 
 | 37 | 		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE, | 
 | 38 | 		.procname	= "mouse_button2_keycode", | 
 | 39 | 		.data		= &mouse_button2_keycode, | 
 | 40 | 		.maxlen		= sizeof(int), | 
 | 41 | 		.mode		= 0644, | 
 | 42 | 		.proc_handler	= &proc_dointvec, | 
 | 43 | 	}, | 
 | 44 | 	{ | 
 | 45 | 		.ctl_name	= DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE, | 
 | 46 | 		.procname	= "mouse_button3_keycode", | 
 | 47 | 		.data		= &mouse_button3_keycode, | 
 | 48 | 		.maxlen		= sizeof(int), | 
 | 49 | 		.mode		= 0644, | 
 | 50 | 		.proc_handler	= &proc_dointvec, | 
 | 51 | 	}, | 
 | 52 | 	{ .ctl_name = 0 } | 
 | 53 | }; | 
 | 54 |  | 
 | 55 | /* dir in /proc/sys/dev */ | 
| Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 56 | static ctl_table mac_hid_dir[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | 	{ | 
 | 58 | 		.ctl_name	= DEV_MAC_HID, | 
 | 59 | 		.procname	= "mac_hid", | 
 | 60 | 		.maxlen		= 0, | 
 | 61 | 		.mode		= 0555, | 
 | 62 | 		.child		= mac_hid_files, | 
 | 63 | 	}, | 
 | 64 | 	{ .ctl_name = 0 } | 
 | 65 | }; | 
 | 66 |  | 
 | 67 | /* /proc/sys/dev itself, in case that is not there yet */ | 
| Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 68 | static ctl_table mac_hid_root_dir[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | 	{ | 
 | 70 | 		.ctl_name	= CTL_DEV, | 
 | 71 | 		.procname	= "dev", | 
 | 72 | 		.maxlen		= 0, | 
 | 73 | 		.mode		= 0555, | 
 | 74 | 		.child		= mac_hid_dir, | 
 | 75 | 	}, | 
 | 76 | 	{ .ctl_name = 0 } | 
 | 77 | }; | 
 | 78 |  | 
 | 79 | static struct ctl_table_header *mac_hid_sysctl_header; | 
 | 80 |  | 
 | 81 | #endif /* endif CONFIG_SYSCTL */ | 
 | 82 |  | 
 | 83 | int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down) | 
 | 84 | { | 
 | 85 | 	switch (caller) { | 
 | 86 | 	case 1: | 
 | 87 | 		/* Called from keyboard.c */ | 
 | 88 | 		if (mouse_emulate_buttons | 
 | 89 | 		    && (keycode == mouse_button2_keycode | 
 | 90 | 			|| keycode == mouse_button3_keycode)) { | 
 | 91 | 			if (mouse_emulate_buttons == 1) { | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 92 | 				input_report_key(emumousebtn, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | 						 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT, | 
 | 94 | 						 down); | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 95 | 				input_sync(emumousebtn); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | 				return 1; | 
 | 97 | 			} | 
 | 98 | 			mouse_last_keycode = down ? keycode : 0; | 
 | 99 | 		} | 
 | 100 | 		break; | 
 | 101 | 	} | 
 | 102 | 	return 0; | 
 | 103 | } | 
 | 104 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 105 | static int emumousebtn_input_register(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { | 
| Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 107 | 	int ret; | 
 | 108 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 109 | 	emumousebtn = input_allocate_device(); | 
 | 110 | 	if (!emumousebtn) | 
 | 111 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 113 | 	emumousebtn->name = "Macintosh mouse button emulation"; | 
 | 114 | 	emumousebtn->id.bustype = BUS_ADB; | 
 | 115 | 	emumousebtn->id.vendor = 0x0001; | 
 | 116 | 	emumousebtn->id.product = 0x0001; | 
 | 117 | 	emumousebtn->id.version = 0x0100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 119 | 	emumousebtn->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | 
 | 120 | 	emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); | 
 | 121 | 	emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 |  | 
| Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 123 | 	ret = input_register_device(emumousebtn); | 
 | 124 | 	if (ret) | 
 | 125 | 		input_free_device(emumousebtn); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 |  | 
| Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 127 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } | 
 | 129 |  | 
| Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 130 | static int __init mac_hid_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 132 | 	int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 |  | 
| Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 134 | 	err = emumousebtn_input_register(); | 
 | 135 | 	if (err) | 
 | 136 | 		return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 |  | 
 | 138 | #if defined(CONFIG_SYSCTL) | 
| Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 139 | 	mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | #endif /* CONFIG_SYSCTL */ | 
 | 141 |  | 
 | 142 | 	return 0; | 
 | 143 | } | 
 | 144 |  | 
 | 145 | device_initcall(mac_hid_init); |