Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * LoCoMo keyboard driver for Linux-based ARM PDAs:
4 * - SHARP Zaurus Collie (SL-5500)
5 * - SHARP Zaurus Poodle (SL-5600)
6 *
7 * Copyright (c) 2005 John Lenz
8 * Based on from xtkbd.c
9 */
10
11#include <linux/slab.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/input.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
19
20#include <asm/hardware/locomo.h>
21#include <asm/irq.h>
22
23MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
24MODULE_DESCRIPTION("LoCoMo keyboard driver");
25MODULE_LICENSE("GPL");
26
27#define LOCOMOKBD_NUMKEYS 128
28
29#define KEY_ACTIVITY KEY_F16
30#define KEY_CONTACT KEY_F18
31#define KEY_CENTER KEY_F15
32
33static const unsigned char
34locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
35 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
36 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
38 0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0, /* 30 - 39 */
39 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT, /* 40 - 49 */
40 KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T, /* 50 - 59 */
41 KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0, /* 60 - 69 */
42 KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0, /* 70 - 79 */
43 0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J, /* 80 - 89 */
44 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */
45 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */
46 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */
47 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */
48};
49
50#define KB_ROWS 16
51#define KB_COLS 8
52#define KB_ROWMASK(r) (1 << (r))
53#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
54
55#define KB_DELAY 8
56#define SCAN_INTERVAL (HZ/10)
57
58struct locomokbd {
59 unsigned char keycode[LOCOMOKBD_NUMKEYS];
60 struct input_dev *input;
61 char phys[32];
62
63 unsigned long base;
64 spinlock_t lock;
65
66 struct timer_list timer;
67 unsigned long suspend_jiffies;
68 unsigned int count_cancel;
69};
70
71/* helper functions for reading the keyboard matrix */
72static inline void locomokbd_charge_all(unsigned long membase)
73{
74 locomo_writel(0x00FF, membase + LOCOMO_KSC);
75}
76
77static inline void locomokbd_activate_all(unsigned long membase)
78{
79 unsigned long r;
80
81 locomo_writel(0, membase + LOCOMO_KSC);
82 r = locomo_readl(membase + LOCOMO_KIC);
83 r &= 0xFEFF;
84 locomo_writel(r, membase + LOCOMO_KIC);
85}
86
87static inline void locomokbd_activate_col(unsigned long membase, int col)
88{
89 unsigned short nset;
90 unsigned short nbset;
91
92 nset = 0xFF & ~(1 << col);
93 nbset = (nset << 8) + nset;
94 locomo_writel(nbset, membase + LOCOMO_KSC);
95}
96
97static inline void locomokbd_reset_col(unsigned long membase, int col)
98{
99 unsigned short nbset;
100
101 nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF;
102 locomo_writel(nbset, membase + LOCOMO_KSC);
103}
104
105/*
106 * The LoCoMo keyboard only generates interrupts when a key is pressed.
107 * So when a key is pressed, we enable a timer. This timer scans the
108 * keyboard, and this is how we detect when the key is released.
109 */
110
111/* Scan the hardware keyboard and push any changes up through the input layer */
112static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
113{
114 unsigned int row, col, rowd;
115 unsigned int num_pressed;
116 unsigned long membase = locomokbd->base;
117
118 guard(spinlock_irqsave)(&locomokbd->lock);
119
120 locomokbd_charge_all(membase);
121
122 num_pressed = 0;
123 for (col = 0; col < KB_COLS; col++) {
124
125 locomokbd_activate_col(membase, col);
126 udelay(KB_DELAY);
127
128 rowd = ~locomo_readl(membase + LOCOMO_KIB);
129 for (row = 0; row < KB_ROWS; row++) {
130 unsigned int scancode, pressed, key;
131
132 scancode = SCANCODE(col, row);
133 pressed = rowd & KB_ROWMASK(row);
134 key = locomokbd->keycode[scancode];
135
136 input_report_key(locomokbd->input, key, pressed);
137 if (likely(!pressed))
138 continue;
139
140 num_pressed++;
141
142 /* The "Cancel/ESC" key is labeled "On/Off" on
143 * Collie and Poodle and should suspend the device
144 * if it was pressed for more than a second. */
145 if (unlikely(key == KEY_ESC)) {
146 if (!time_after(jiffies,
147 locomokbd->suspend_jiffies + HZ))
148 continue;
149 if (locomokbd->count_cancel++
150 != (HZ/SCAN_INTERVAL + 1))
151 continue;
152 input_event(locomokbd->input, EV_PWR,
153 KEY_SUSPEND, 1);
154 locomokbd->suspend_jiffies = jiffies;
155 } else
156 locomokbd->count_cancel = 0;
157 }
158 locomokbd_reset_col(membase, col);
159 }
160 locomokbd_activate_all(membase);
161
162 input_sync(locomokbd->input);
163
164 /* if any keys are pressed, enable the timer */
165 if (num_pressed)
166 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
167 else
168 locomokbd->count_cancel = 0;
169}
170
171/*
172 * LoCoMo keyboard interrupt handler.
173 */
174static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
175{
176 struct locomokbd *locomokbd = dev_id;
177 u16 r;
178
179 r = locomo_readl(locomokbd->base + LOCOMO_KIC);
180 if ((r & 0x0001) == 0)
181 return IRQ_HANDLED;
182
183 locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */
184
185 /** wait chattering delay **/
186 udelay(100);
187
188 locomokbd_scankeyboard(locomokbd);
189 return IRQ_HANDLED;
190}
191
192/*
193 * LoCoMo timer checking for released keys
194 */
195static void locomokbd_timer_callback(struct timer_list *t)
196{
197 struct locomokbd *locomokbd = from_timer(locomokbd, t, timer);
198
199 locomokbd_scankeyboard(locomokbd);
200}
201
202static int locomokbd_open(struct input_dev *dev)
203{
204 struct locomokbd *locomokbd = input_get_drvdata(dev);
205 u16 r;
206
207 r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010;
208 locomo_writel(r, locomokbd->base + LOCOMO_KIC);
209 return 0;
210}
211
212static void locomokbd_close(struct input_dev *dev)
213{
214 struct locomokbd *locomokbd = input_get_drvdata(dev);
215 u16 r;
216
217 r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010;
218 locomo_writel(r, locomokbd->base + LOCOMO_KIC);
219}
220
221static int locomokbd_probe(struct locomo_dev *dev)
222{
223 struct locomokbd *locomokbd;
224 struct input_dev *input_dev;
225 int i, err;
226
227 locomokbd = kzalloc(sizeof(*locomokbd), GFP_KERNEL);
228 input_dev = input_allocate_device();
229 if (!locomokbd || !input_dev) {
230 err = -ENOMEM;
231 goto err_free_mem;
232 }
233
234 /* try and claim memory region */
235 if (!request_mem_region((unsigned long) dev->mapbase,
236 dev->length,
237 LOCOMO_DRIVER_NAME(dev))) {
238 err = -EBUSY;
239 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
240 goto err_free_mem;
241 }
242
243 locomo_set_drvdata(dev, locomokbd);
244
245 locomokbd->base = (unsigned long) dev->mapbase;
246
247 spin_lock_init(&locomokbd->lock);
248
249 timer_setup(&locomokbd->timer, locomokbd_timer_callback, 0);
250
251 locomokbd->suspend_jiffies = jiffies;
252
253 locomokbd->input = input_dev;
254 strcpy(locomokbd->phys, "locomokbd/input0");
255
256 input_dev->name = "LoCoMo keyboard";
257 input_dev->phys = locomokbd->phys;
258 input_dev->id.bustype = BUS_HOST;
259 input_dev->id.vendor = 0x0001;
260 input_dev->id.product = 0x0001;
261 input_dev->id.version = 0x0100;
262 input_dev->open = locomokbd_open;
263 input_dev->close = locomokbd_close;
264 input_dev->dev.parent = &dev->dev;
265
266 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
267 BIT_MASK(EV_PWR);
268 input_dev->keycode = locomokbd->keycode;
269 input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
270 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
271
272 input_set_drvdata(input_dev, locomokbd);
273
274 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
275 for (i = 0; i < LOCOMOKBD_NUMKEYS; i++)
276 set_bit(locomokbd->keycode[i], input_dev->keybit);
277 clear_bit(0, input_dev->keybit);
278
279 /* attempt to get the interrupt */
280 err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
281 if (err) {
282 printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n");
283 goto err_release_region;
284 }
285
286 err = input_register_device(locomokbd->input);
287 if (err)
288 goto err_free_irq;
289
290 return 0;
291
292 err_free_irq:
293 free_irq(dev->irq[0], locomokbd);
294 err_release_region:
295 release_mem_region((unsigned long) dev->mapbase, dev->length);
296 locomo_set_drvdata(dev, NULL);
297 err_free_mem:
298 input_free_device(input_dev);
299 kfree(locomokbd);
300
301 return err;
302}
303
304static void locomokbd_remove(struct locomo_dev *dev)
305{
306 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
307
308 free_irq(dev->irq[0], locomokbd);
309
310 timer_shutdown_sync(&locomokbd->timer);
311
312 input_unregister_device(locomokbd->input);
313 locomo_set_drvdata(dev, NULL);
314
315 release_mem_region((unsigned long) dev->mapbase, dev->length);
316
317 kfree(locomokbd);
318}
319
320static struct locomo_driver keyboard_driver = {
321 .drv = {
322 .name = "locomokbd"
323 },
324 .devid = LOCOMO_DEVID_KEYBOARD,
325 .probe = locomokbd_probe,
326 .remove = locomokbd_remove,
327};
328
329static int __init locomokbd_init(void)
330{
331 return locomo_driver_register(&keyboard_driver);
332}
333
334static void __exit locomokbd_exit(void)
335{
336 locomo_driver_unregister(&keyboard_driver);
337}
338
339module_init(locomokbd_init);
340module_exit(locomokbd_exit);
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * LoCoMo keyboard driver for Linux-based ARM PDAs:
4 * - SHARP Zaurus Collie (SL-5500)
5 * - SHARP Zaurus Poodle (SL-5600)
6 *
7 * Copyright (c) 2005 John Lenz
8 * Based on from xtkbd.c
9 */
10
11#include <linux/slab.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/input.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
19
20#include <asm/hardware/locomo.h>
21#include <asm/irq.h>
22
23MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
24MODULE_DESCRIPTION("LoCoMo keyboard driver");
25MODULE_LICENSE("GPL");
26
27#define LOCOMOKBD_NUMKEYS 128
28
29#define KEY_ACTIVITY KEY_F16
30#define KEY_CONTACT KEY_F18
31#define KEY_CENTER KEY_F15
32
33static const unsigned char
34locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
35 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
36 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
38 0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0, /* 30 - 39 */
39 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT, /* 40 - 49 */
40 KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T, /* 50 - 59 */
41 KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0, /* 60 - 69 */
42 KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0, /* 70 - 79 */
43 0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J, /* 80 - 89 */
44 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */
45 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */
46 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */
47 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */
48};
49
50#define KB_ROWS 16
51#define KB_COLS 8
52#define KB_ROWMASK(r) (1 << (r))
53#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
54
55#define KB_DELAY 8
56#define SCAN_INTERVAL (HZ/10)
57
58struct locomokbd {
59 unsigned char keycode[LOCOMOKBD_NUMKEYS];
60 struct input_dev *input;
61 char phys[32];
62
63 unsigned long base;
64 spinlock_t lock;
65
66 struct timer_list timer;
67 unsigned long suspend_jiffies;
68 unsigned int count_cancel;
69};
70
71/* helper functions for reading the keyboard matrix */
72static inline void locomokbd_charge_all(unsigned long membase)
73{
74 locomo_writel(0x00FF, membase + LOCOMO_KSC);
75}
76
77static inline void locomokbd_activate_all(unsigned long membase)
78{
79 unsigned long r;
80
81 locomo_writel(0, membase + LOCOMO_KSC);
82 r = locomo_readl(membase + LOCOMO_KIC);
83 r &= 0xFEFF;
84 locomo_writel(r, membase + LOCOMO_KIC);
85}
86
87static inline void locomokbd_activate_col(unsigned long membase, int col)
88{
89 unsigned short nset;
90 unsigned short nbset;
91
92 nset = 0xFF & ~(1 << col);
93 nbset = (nset << 8) + nset;
94 locomo_writel(nbset, membase + LOCOMO_KSC);
95}
96
97static inline void locomokbd_reset_col(unsigned long membase, int col)
98{
99 unsigned short nbset;
100
101 nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF;
102 locomo_writel(nbset, membase + LOCOMO_KSC);
103}
104
105/*
106 * The LoCoMo keyboard only generates interrupts when a key is pressed.
107 * So when a key is pressed, we enable a timer. This timer scans the
108 * keyboard, and this is how we detect when the key is released.
109 */
110
111/* Scan the hardware keyboard and push any changes up through the input layer */
112static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
113{
114 unsigned int row, col, rowd;
115 unsigned long flags;
116 unsigned int num_pressed;
117 unsigned long membase = locomokbd->base;
118
119 spin_lock_irqsave(&locomokbd->lock, flags);
120
121 locomokbd_charge_all(membase);
122
123 num_pressed = 0;
124 for (col = 0; col < KB_COLS; col++) {
125
126 locomokbd_activate_col(membase, col);
127 udelay(KB_DELAY);
128
129 rowd = ~locomo_readl(membase + LOCOMO_KIB);
130 for (row = 0; row < KB_ROWS; row++) {
131 unsigned int scancode, pressed, key;
132
133 scancode = SCANCODE(col, row);
134 pressed = rowd & KB_ROWMASK(row);
135 key = locomokbd->keycode[scancode];
136
137 input_report_key(locomokbd->input, key, pressed);
138 if (likely(!pressed))
139 continue;
140
141 num_pressed++;
142
143 /* The "Cancel/ESC" key is labeled "On/Off" on
144 * Collie and Poodle and should suspend the device
145 * if it was pressed for more than a second. */
146 if (unlikely(key == KEY_ESC)) {
147 if (!time_after(jiffies,
148 locomokbd->suspend_jiffies + HZ))
149 continue;
150 if (locomokbd->count_cancel++
151 != (HZ/SCAN_INTERVAL + 1))
152 continue;
153 input_event(locomokbd->input, EV_PWR,
154 KEY_SUSPEND, 1);
155 locomokbd->suspend_jiffies = jiffies;
156 } else
157 locomokbd->count_cancel = 0;
158 }
159 locomokbd_reset_col(membase, col);
160 }
161 locomokbd_activate_all(membase);
162
163 input_sync(locomokbd->input);
164
165 /* if any keys are pressed, enable the timer */
166 if (num_pressed)
167 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
168 else
169 locomokbd->count_cancel = 0;
170
171 spin_unlock_irqrestore(&locomokbd->lock, flags);
172}
173
174/*
175 * LoCoMo keyboard interrupt handler.
176 */
177static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
178{
179 struct locomokbd *locomokbd = dev_id;
180 u16 r;
181
182 r = locomo_readl(locomokbd->base + LOCOMO_KIC);
183 if ((r & 0x0001) == 0)
184 return IRQ_HANDLED;
185
186 locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */
187
188 /** wait chattering delay **/
189 udelay(100);
190
191 locomokbd_scankeyboard(locomokbd);
192 return IRQ_HANDLED;
193}
194
195/*
196 * LoCoMo timer checking for released keys
197 */
198static void locomokbd_timer_callback(struct timer_list *t)
199{
200 struct locomokbd *locomokbd = from_timer(locomokbd, t, timer);
201
202 locomokbd_scankeyboard(locomokbd);
203}
204
205static int locomokbd_open(struct input_dev *dev)
206{
207 struct locomokbd *locomokbd = input_get_drvdata(dev);
208 u16 r;
209
210 r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010;
211 locomo_writel(r, locomokbd->base + LOCOMO_KIC);
212 return 0;
213}
214
215static void locomokbd_close(struct input_dev *dev)
216{
217 struct locomokbd *locomokbd = input_get_drvdata(dev);
218 u16 r;
219
220 r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010;
221 locomo_writel(r, locomokbd->base + LOCOMO_KIC);
222}
223
224static int locomokbd_probe(struct locomo_dev *dev)
225{
226 struct locomokbd *locomokbd;
227 struct input_dev *input_dev;
228 int i, err;
229
230 locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL);
231 input_dev = input_allocate_device();
232 if (!locomokbd || !input_dev) {
233 err = -ENOMEM;
234 goto err_free_mem;
235 }
236
237 /* try and claim memory region */
238 if (!request_mem_region((unsigned long) dev->mapbase,
239 dev->length,
240 LOCOMO_DRIVER_NAME(dev))) {
241 err = -EBUSY;
242 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
243 goto err_free_mem;
244 }
245
246 locomo_set_drvdata(dev, locomokbd);
247
248 locomokbd->base = (unsigned long) dev->mapbase;
249
250 spin_lock_init(&locomokbd->lock);
251
252 timer_setup(&locomokbd->timer, locomokbd_timer_callback, 0);
253
254 locomokbd->suspend_jiffies = jiffies;
255
256 locomokbd->input = input_dev;
257 strcpy(locomokbd->phys, "locomokbd/input0");
258
259 input_dev->name = "LoCoMo keyboard";
260 input_dev->phys = locomokbd->phys;
261 input_dev->id.bustype = BUS_HOST;
262 input_dev->id.vendor = 0x0001;
263 input_dev->id.product = 0x0001;
264 input_dev->id.version = 0x0100;
265 input_dev->open = locomokbd_open;
266 input_dev->close = locomokbd_close;
267 input_dev->dev.parent = &dev->dev;
268
269 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
270 BIT_MASK(EV_PWR);
271 input_dev->keycode = locomokbd->keycode;
272 input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
273 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
274
275 input_set_drvdata(input_dev, locomokbd);
276
277 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
278 for (i = 0; i < LOCOMOKBD_NUMKEYS; i++)
279 set_bit(locomokbd->keycode[i], input_dev->keybit);
280 clear_bit(0, input_dev->keybit);
281
282 /* attempt to get the interrupt */
283 err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
284 if (err) {
285 printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n");
286 goto err_release_region;
287 }
288
289 err = input_register_device(locomokbd->input);
290 if (err)
291 goto err_free_irq;
292
293 return 0;
294
295 err_free_irq:
296 free_irq(dev->irq[0], locomokbd);
297 err_release_region:
298 release_mem_region((unsigned long) dev->mapbase, dev->length);
299 locomo_set_drvdata(dev, NULL);
300 err_free_mem:
301 input_free_device(input_dev);
302 kfree(locomokbd);
303
304 return err;
305}
306
307static void locomokbd_remove(struct locomo_dev *dev)
308{
309 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
310
311 free_irq(dev->irq[0], locomokbd);
312
313 timer_shutdown_sync(&locomokbd->timer);
314
315 input_unregister_device(locomokbd->input);
316 locomo_set_drvdata(dev, NULL);
317
318 release_mem_region((unsigned long) dev->mapbase, dev->length);
319
320 kfree(locomokbd);
321}
322
323static struct locomo_driver keyboard_driver = {
324 .drv = {
325 .name = "locomokbd"
326 },
327 .devid = LOCOMO_DEVID_KEYBOARD,
328 .probe = locomokbd_probe,
329 .remove = locomokbd_remove,
330};
331
332static int __init locomokbd_init(void)
333{
334 return locomo_driver_register(&keyboard_driver);
335}
336
337static void __exit locomokbd_exit(void)
338{
339 locomo_driver_unregister(&keyboard_driver);
340}
341
342module_init(locomokbd_init);
343module_exit(locomokbd_exit);