]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/macintosh/mac_hid.c
sysctl: Remove CTL_NONE and CTL_UNNUMBERED
[net-next-2.6.git] / drivers / macintosh / mac_hid.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
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>
2301060e 16#include <linux/kbd_kern.h>
1da177e4
LT
17
18
c7f7a569
DT
19static struct input_dev *emumousebtn;
20static int emumousebtn_input_register(void);
87275856 21static int mouse_emulate_buttons;
1da177e4
LT
22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
87275856 24static int mouse_last_keycode;
1da177e4
LT
25
26#if defined(CONFIG_SYSCTL)
27/* file(s) in /proc/sys/dev/mac_hid */
f3e5d2bf 28static ctl_table mac_hid_files[] = {
1da177e4 29 {
1da177e4
LT
30 .procname = "mouse_button_emulation",
31 .data = &mouse_emulate_buttons,
32 .maxlen = sizeof(int),
33 .mode = 0644,
34 .proc_handler = &proc_dointvec,
35 },
36 {
1da177e4
LT
37 .procname = "mouse_button2_keycode",
38 .data = &mouse_button2_keycode,
39 .maxlen = sizeof(int),
40 .mode = 0644,
41 .proc_handler = &proc_dointvec,
42 },
43 {
1da177e4
LT
44 .procname = "mouse_button3_keycode",
45 .data = &mouse_button3_keycode,
46 .maxlen = sizeof(int),
47 .mode = 0644,
48 .proc_handler = &proc_dointvec,
49 },
894d2491 50 { }
1da177e4
LT
51};
52
53/* dir in /proc/sys/dev */
f3e5d2bf 54static ctl_table mac_hid_dir[] = {
1da177e4 55 {
1da177e4
LT
56 .procname = "mac_hid",
57 .maxlen = 0,
58 .mode = 0555,
59 .child = mac_hid_files,
60 },
894d2491 61 { }
1da177e4
LT
62};
63
64/* /proc/sys/dev itself, in case that is not there yet */
f3e5d2bf 65static ctl_table mac_hid_root_dir[] = {
1da177e4 66 {
1da177e4
LT
67 .procname = "dev",
68 .maxlen = 0,
69 .mode = 0555,
70 .child = mac_hid_dir,
71 },
894d2491 72 { }
1da177e4
LT
73};
74
75static struct ctl_table_header *mac_hid_sysctl_header;
76
77#endif /* endif CONFIG_SYSCTL */
78
79int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
80{
81 switch (caller) {
82 case 1:
83 /* Called from keyboard.c */
84 if (mouse_emulate_buttons
85 && (keycode == mouse_button2_keycode
86 || keycode == mouse_button3_keycode)) {
87 if (mouse_emulate_buttons == 1) {
c7f7a569 88 input_report_key(emumousebtn,
1da177e4
LT
89 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
90 down);
c7f7a569 91 input_sync(emumousebtn);
1da177e4
LT
92 return 1;
93 }
94 mouse_last_keycode = down ? keycode : 0;
95 }
96 break;
97 }
98 return 0;
99}
100
8fd76c45
PZ
101static struct lock_class_key emumousebtn_event_class;
102static struct lock_class_key emumousebtn_mutex_class;
103
c7f7a569 104static int emumousebtn_input_register(void)
1da177e4 105{
4bdbd280
DT
106 int ret;
107
c7f7a569
DT
108 emumousebtn = input_allocate_device();
109 if (!emumousebtn)
110 return -ENOMEM;
1da177e4 111
a9291072
HH
112 lockdep_set_class(&emumousebtn->event_lock, &emumousebtn_event_class);
113 lockdep_set_class(&emumousebtn->mutex, &emumousebtn_mutex_class);
8fd76c45 114
c7f7a569
DT
115 emumousebtn->name = "Macintosh mouse button emulation";
116 emumousebtn->id.bustype = BUS_ADB;
117 emumousebtn->id.vendor = 0x0001;
118 emumousebtn->id.product = 0x0001;
119 emumousebtn->id.version = 0x0100;
1da177e4 120
7b19ada2
JS
121 emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
122 emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
123 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
124 emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1da177e4 125
4bdbd280
DT
126 ret = input_register_device(emumousebtn);
127 if (ret)
128 input_free_device(emumousebtn);
1da177e4 129
4bdbd280 130 return ret;
1da177e4
LT
131}
132
f3e5d2bf 133static int __init mac_hid_init(void)
1da177e4 134{
c7f7a569 135 int err;
1da177e4 136
c7f7a569
DT
137 err = emumousebtn_input_register();
138 if (err)
139 return err;
1da177e4
LT
140
141#if defined(CONFIG_SYSCTL)
0b4d4147 142 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
1da177e4
LT
143#endif /* CONFIG_SYSCTL */
144
145 return 0;
146}
147
148device_initcall(mac_hid_init);