diff options
author | Adrian McMenamin <adrian@newgolddream.dyndns.info> | 2008-07-30 15:31:38 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2008-08-03 20:55:56 -0400 |
commit | 86d9d32c7b17f8145dc8cbc9667e6385bf8ebc67 (patch) | |
tree | 1d41cc53ae3713bc78c965e12d1b9a0889752db0 /drivers/input/keyboard | |
parent | c07abb6dbec754511427dd847f10cfdec6d36b3c (diff) |
maple: allow removal and reinsertion of keyboard driver module
Allow the removal (and subsequent reinsertion) of the maple_keyb (maple
keyboard) driver by adding a working removal function.
Also tidy long lines.
Signed-off-by: Adrian McMenamin <adrian@mcmen.demon.co.uk>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r-- | drivers/input/keyboard/maple_keyb.c | 124 |
1 files changed, 81 insertions, 43 deletions
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c index 7797ef6e5e64..7d13f55b504e 100644 --- a/drivers/input/keyboard/maple_keyb.c +++ b/drivers/input/keyboard/maple_keyb.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * SEGA Dreamcast keyboard driver | 2 | * SEGA Dreamcast keyboard driver |
3 | * Based on drivers/usb/usbkbd.c | 3 | * Based on drivers/usb/usbkbd.c |
4 | * Copyright YAEGASHI Takeshi, 2001 | 4 | * Copyright YAEGASHI Takeshi, 2001 |
5 | * Porting to 2.6 Copyright Adrian McMenamin, 2007 | 5 | * Porting to 2.6 Copyright Adrian McMenamin, 2007, 2008 |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -45,39 +45,51 @@ struct dc_kbd { | |||
45 | }; | 45 | }; |
46 | 46 | ||
47 | static const unsigned short dc_kbd_keycode[NR_SCANCODES] = { | 47 | static const unsigned short dc_kbd_keycode[NR_SCANCODES] = { |
48 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_A, KEY_B, KEY_C, KEY_D, | 48 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_A, KEY_B, |
49 | KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, | 49 | KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, |
50 | KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, | 50 | KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, |
51 | KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_1, KEY_2, | 51 | KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, |
52 | KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, | 52 | KEY_7, KEY_8, KEY_9, KEY_0, KEY_ENTER, KEY_ESC, KEY_BACKSPACE, |
53 | KEY_ENTER, KEY_ESC, KEY_BACKSPACE, KEY_TAB, KEY_SPACE, KEY_MINUS, KEY_EQUAL, KEY_LEFTBRACE, | 53 | KEY_TAB, KEY_SPACE, KEY_MINUS, KEY_EQUAL, KEY_LEFTBRACE, |
54 | KEY_RIGHTBRACE, KEY_BACKSLASH, KEY_BACKSLASH, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_GRAVE, KEY_COMMA, | 54 | KEY_RIGHTBRACE, KEY_BACKSLASH, KEY_BACKSLASH, KEY_SEMICOLON, |
55 | KEY_DOT, KEY_SLASH, KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, | 55 | KEY_APOSTROPHE, KEY_GRAVE, KEY_COMMA, KEY_DOT, KEY_SLASH, |
56 | KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, | ||
56 | KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_SYSRQ, | 57 | KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_SYSRQ, |
57 | KEY_SCROLLLOCK, KEY_PAUSE, KEY_INSERT, KEY_HOME, KEY_PAGEUP, KEY_DELETE, | 58 | KEY_SCROLLLOCK, KEY_PAUSE, KEY_INSERT, KEY_HOME, KEY_PAGEUP, |
58 | KEY_END, KEY_PAGEDOWN, KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP, | 59 | KEY_DELETE, KEY_END, KEY_PAGEDOWN, KEY_RIGHT, KEY_LEFT, KEY_DOWN, |
59 | KEY_NUMLOCK, KEY_KPSLASH, KEY_KPASTERISK, KEY_KPMINUS, KEY_KPPLUS, KEY_KPENTER, KEY_KP1, KEY_KP2, | 60 | KEY_UP, KEY_NUMLOCK, KEY_KPSLASH, KEY_KPASTERISK, KEY_KPMINUS, |
60 | KEY_KP3, KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7, KEY_KP8, KEY_KP9, KEY_KP0, KEY_KPDOT, | 61 | KEY_KPPLUS, KEY_KPENTER, KEY_KP1, KEY_KP2, KEY_KP3, KEY_KP4, KEY_KP5, |
61 | KEY_102ND, KEY_COMPOSE, KEY_POWER, KEY_KPEQUAL, KEY_F13, KEY_F14, KEY_F15, | 62 | KEY_KP6, KEY_KP7, KEY_KP8, KEY_KP9, KEY_KP0, KEY_KPDOT, KEY_102ND, |
62 | KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, | 63 | KEY_COMPOSE, KEY_POWER, KEY_KPEQUAL, KEY_F13, KEY_F14, KEY_F15, |
63 | KEY_F21, KEY_F22, KEY_F23, KEY_F24, KEY_OPEN, KEY_HELP, KEY_PROPS, KEY_FRONT, | 64 | KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, |
64 | KEY_STOP, KEY_AGAIN, KEY_UNDO, KEY_CUT, KEY_COPY, KEY_PASTE, KEY_FIND, KEY_MUTE, | 65 | KEY_F23, KEY_F24, KEY_OPEN, KEY_HELP, KEY_PROPS, KEY_FRONT, KEY_STOP, |
65 | KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_KPCOMMA, KEY_RESERVED, KEY_RO, KEY_KATAKANAHIRAGANA , KEY_YEN, | 66 | KEY_AGAIN, KEY_UNDO, KEY_CUT, KEY_COPY, KEY_PASTE, KEY_FIND, KEY_MUTE, |
66 | KEY_HENKAN, KEY_MUHENKAN, KEY_KPJPCOMMA, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 67 | KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
67 | KEY_HANGEUL, KEY_HANJA, KEY_KATAKANA, KEY_HIRAGANA, KEY_ZENKAKUHANKAKU, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 68 | KEY_KPCOMMA, KEY_RESERVED, KEY_RO, KEY_KATAKANAHIRAGANA , KEY_YEN, |
68 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 69 | KEY_HENKAN, KEY_MUHENKAN, KEY_KPJPCOMMA, KEY_RESERVED, KEY_RESERVED, |
69 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 70 | KEY_RESERVED, KEY_HANGEUL, KEY_HANJA, KEY_KATAKANA, KEY_HIRAGANA, |
70 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 71 | KEY_ZENKAKUHANKAKU, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
71 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 72 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
72 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 73 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
73 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 74 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
74 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 75 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
75 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 76 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
76 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | 77 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
77 | KEY_LEFTCTRL, KEY_LEFTSHIFT, KEY_LEFTALT, KEY_LEFTMETA, KEY_RIGHTCTRL, KEY_RIGHTSHIFT, KEY_RIGHTALT, KEY_RIGHTMETA, | 78 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
78 | KEY_PLAYPAUSE, KEY_STOPCD, KEY_PREVIOUSSONG, KEY_NEXTSONG, KEY_EJECTCD, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, | 79 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
79 | KEY_WWW, KEY_BACK, KEY_FORWARD, KEY_STOP, KEY_FIND, KEY_SCROLLUP, KEY_SCROLLDOWN, KEY_EDIT, KEY_SLEEP, | 80 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
80 | KEY_SCREENLOCK, KEY_REFRESH, KEY_CALC, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED | 81 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, |
82 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | ||
83 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | ||
84 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | ||
85 | KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, | ||
86 | KEY_RESERVED, KEY_RESERVED, KEY_LEFTCTRL, KEY_LEFTSHIFT, KEY_LEFTALT, | ||
87 | KEY_LEFTMETA, KEY_RIGHTCTRL, KEY_RIGHTSHIFT, KEY_RIGHTALT, | ||
88 | KEY_RIGHTMETA, KEY_PLAYPAUSE, KEY_STOPCD, KEY_PREVIOUSSONG, | ||
89 | KEY_NEXTSONG, KEY_EJECTCD, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, | ||
90 | KEY_WWW, KEY_BACK, KEY_FORWARD, KEY_STOP, KEY_FIND, KEY_SCROLLUP, | ||
91 | KEY_SCROLLDOWN, KEY_EDIT, KEY_SLEEP, KEY_SCREENLOCK, KEY_REFRESH, | ||
92 | KEY_CALC, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED, KEY_RESERVED | ||
81 | }; | 93 | }; |
82 | 94 | ||
83 | static void dc_scan_kbd(struct dc_kbd *kbd) | 95 | static void dc_scan_kbd(struct dc_kbd *kbd) |
@@ -151,14 +163,15 @@ static int dc_kbd_connect(struct maple_device *mdev) | |||
151 | struct dc_kbd *kbd; | 163 | struct dc_kbd *kbd; |
152 | struct input_dev *dev; | 164 | struct input_dev *dev; |
153 | 165 | ||
154 | if (!(mdev->function & MAPLE_FUNC_KEYBOARD)) | ||
155 | return -EINVAL; | ||
156 | |||
157 | kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL); | 166 | kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL); |
167 | if (!kbd) { | ||
168 | error = -ENOMEM; | ||
169 | goto fail_kbd; | ||
170 | } | ||
158 | dev = input_allocate_device(); | 171 | dev = input_allocate_device(); |
159 | if (!kbd || !dev) { | 172 | if (!dev) { |
160 | error = -ENOMEM; | 173 | error = -ENOMEM; |
161 | goto fail; | 174 | goto fail_dev; |
162 | } | 175 | } |
163 | 176 | ||
164 | mdev->private_data = kbd; | 177 | mdev->private_data = kbd; |
@@ -169,7 +182,7 @@ static int dc_kbd_connect(struct maple_device *mdev) | |||
169 | dev->name = mdev->product_name; | 182 | dev->name = mdev->product_name; |
170 | dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); | 183 | dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); |
171 | dev->keycode = kbd->keycode; | 184 | dev->keycode = kbd->keycode; |
172 | dev->keycodesize = sizeof (unsigned short); | 185 | dev->keycodesize = sizeof(unsigned short); |
173 | dev->keycodemax = ARRAY_SIZE(kbd->keycode); | 186 | dev->keycodemax = ARRAY_SIZE(kbd->keycode); |
174 | dev->id.bustype = BUS_HOST; | 187 | dev->id.bustype = BUS_HOST; |
175 | dev->dev.parent = &mdev->dev; | 188 | dev->dev.parent = &mdev->dev; |
@@ -186,12 +199,15 @@ static int dc_kbd_connect(struct maple_device *mdev) | |||
186 | goto fail; | 199 | goto fail; |
187 | 200 | ||
188 | /* Maple polling is locked to VBLANK - which may be just 50/s */ | 201 | /* Maple polling is locked to VBLANK - which may be just 50/s */ |
189 | maple_getcond_callback(mdev, dc_kbd_callback, HZ/50, MAPLE_FUNC_KEYBOARD); | 202 | maple_getcond_callback(mdev, dc_kbd_callback, HZ/50, |
203 | MAPLE_FUNC_KEYBOARD); | ||
190 | return 0; | 204 | return 0; |
191 | 205 | ||
192 | fail: | 206 | fail: |
193 | input_free_device(dev); | 207 | input_free_device(dev); |
208 | fail_dev: | ||
194 | kfree(kbd); | 209 | kfree(kbd); |
210 | fail_kbd: | ||
195 | mdev->private_data = NULL; | 211 | mdev->private_data = NULL; |
196 | return error; | 212 | return error; |
197 | } | 213 | } |
@@ -201,7 +217,7 @@ static void dc_kbd_disconnect(struct maple_device *mdev) | |||
201 | struct dc_kbd *kbd; | 217 | struct dc_kbd *kbd; |
202 | 218 | ||
203 | mutex_lock(&maple_keyb_mutex); | 219 | mutex_lock(&maple_keyb_mutex); |
204 | 220 | mdev->callback = NULL; | |
205 | kbd = mdev->private_data; | 221 | kbd = mdev->private_data; |
206 | mdev->private_data = NULL; | 222 | mdev->private_data = NULL; |
207 | input_unregister_device(kbd->dev); | 223 | input_unregister_device(kbd->dev); |
@@ -222,11 +238,18 @@ static int probe_maple_kbd(struct device *dev) | |||
222 | return error; | 238 | return error; |
223 | 239 | ||
224 | mdev->driver = mdrv; | 240 | mdev->driver = mdrv; |
225 | mdev->registered = 1; | ||
226 | 241 | ||
227 | return 0; | 242 | return 0; |
228 | } | 243 | } |
229 | 244 | ||
245 | static int remove_maple_kbd(struct device *dev) | ||
246 | { | ||
247 | struct maple_device *mdev = to_maple_dev(dev); | ||
248 | |||
249 | dc_kbd_disconnect(mdev); | ||
250 | return 0; | ||
251 | } | ||
252 | |||
230 | static struct maple_driver dc_kbd_driver = { | 253 | static struct maple_driver dc_kbd_driver = { |
231 | .function = MAPLE_FUNC_KEYBOARD, | 254 | .function = MAPLE_FUNC_KEYBOARD, |
232 | .connect = dc_kbd_connect, | 255 | .connect = dc_kbd_connect, |
@@ -234,9 +257,23 @@ static struct maple_driver dc_kbd_driver = { | |||
234 | .drv = { | 257 | .drv = { |
235 | .name = "Dreamcast_keyboard", | 258 | .name = "Dreamcast_keyboard", |
236 | .probe = probe_maple_kbd, | 259 | .probe = probe_maple_kbd, |
260 | .remove = remove_maple_kbd, | ||
237 | }, | 261 | }, |
238 | }; | 262 | }; |
239 | 263 | ||
264 | static int unplug_maple_keyb(struct device *dev, void *ignored) | ||
265 | { | ||
266 | /* Please DO NOT really unplug your keyboard */ | ||
267 | struct maple_device *mdev; | ||
268 | |||
269 | mdev = to_maple_dev(dev); | ||
270 | if ((mdev->function & MAPLE_FUNC_KEYBOARD) | ||
271 | && (mdev->driver == &dc_kbd_driver)) | ||
272 | remove_maple_kbd(dev); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
240 | static int __init dc_kbd_init(void) | 277 | static int __init dc_kbd_init(void) |
241 | { | 278 | { |
242 | return maple_driver_register(&dc_kbd_driver.drv); | 279 | return maple_driver_register(&dc_kbd_driver.drv); |
@@ -244,6 +281,7 @@ static int __init dc_kbd_init(void) | |||
244 | 281 | ||
245 | static void __exit dc_kbd_exit(void) | 282 | static void __exit dc_kbd_exit(void) |
246 | { | 283 | { |
284 | bus_for_each_dev(&maple_bus_type, NULL, NULL, unplug_maple_keyb); | ||
247 | driver_unregister(&dc_kbd_driver.drv); | 285 | driver_unregister(&dc_kbd_driver.drv); |
248 | } | 286 | } |
249 | 287 | ||