26 #include <linux/slab.h>
27 #include <linux/module.h>
29 #include <linux/input.h>
31 #include <linux/device.h>
42 #define LOCOMOKBD_NUMKEYS 128
44 #define KEY_ACTIVITY KEY_F16
45 #define KEY_CONTACT KEY_F18
46 #define KEY_CENTER KEY_F15
48 static const unsigned char
50 0,
KEY_ESC,
KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0,
KEY_MENU,
KEY_HOME,
KEY_CONTACT,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0,
KEY_CENTER, 0,
KEY_MAIL, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0,
KEY_RIGHT,
55 KEY_UP,
KEY_LEFT, 0, 0,
KEY_P, 0,
KEY_O,
KEY_I,
KEY_Y,
KEY_T,
56 KEY_E,
KEY_W, 0, 0, 0, 0,
KEY_DOWN,
KEY_ENTER, 0, 0,
57 KEY_BACKSPACE, 0,
KEY_L,
KEY_U,
KEY_H,
KEY_R,
KEY_D,
KEY_Q, 0, 0,
58 0, 0, 0, 0, 0, 0,
KEY_ENTER,
KEY_RIGHTSHIFT,
KEY_K,
KEY_J,
59 KEY_G,
KEY_F,
KEY_X,
KEY_S, 0, 0, 0, 0, 0, 0,
60 0, 0,
KEY_DOT, 0,
KEY_COMMA,
KEY_N,
KEY_B,
KEY_C,
KEY_Z,
KEY_A,
61 KEY_LEFTSHIFT,
KEY_TAB,
KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0,
67 #define KB_ROWMASK(r) (1 << (r))
68 #define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
71 #define SCAN_INTERVAL (HZ/10)
87 static inline void locomokbd_charge_all(
unsigned long membase)
92 static inline void locomokbd_activate_all(
unsigned long membase)
102 static inline void locomokbd_activate_col(
unsigned long membase,
int col)
105 unsigned short nbset;
107 nset = 0xFF & ~(1 << col);
108 nbset = (nset << 8) + nset;
112 static inline void locomokbd_reset_col(
unsigned long membase,
int col)
114 unsigned short nbset;
116 nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF;
129 unsigned int row, col, rowd;
131 unsigned int num_pressed;
132 unsigned long membase = locomokbd->
base;
136 locomokbd_charge_all(membase);
139 for (col = 0; col <
KB_COLS; col++) {
141 locomokbd_activate_col(membase, col);
145 for (row = 0; row <
KB_ROWS; row++) {
146 unsigned int scancode, pressed,
key;
150 key = locomokbd->
keycode[scancode];
152 input_report_key(locomokbd->
input, key, pressed);
174 locomokbd_reset_col(membase, col);
176 locomokbd_activate_all(membase);
178 input_sync(locomokbd->
input);
186 spin_unlock_irqrestore(&locomokbd->
lock, flags);
194 struct locomokbd *locomokbd =
dev_id;
198 if ((r & 0x0001) == 0)
206 locomokbd_scankeyboard(locomokbd);
213 static void locomokbd_timer_callback(
unsigned long data)
215 struct locomokbd *locomokbd = (
struct locomokbd *) data;
217 locomokbd_scankeyboard(locomokbd);
220 static int locomokbd_open(
struct input_dev *
dev)
222 struct locomokbd *locomokbd = input_get_drvdata(dev);
230 static void locomokbd_close(
struct input_dev *
dev)
232 struct locomokbd *locomokbd = input_get_drvdata(dev);
241 struct locomokbd *locomokbd;
242 struct input_dev *input_dev;
245 locomokbd = kzalloc(
sizeof(
struct locomokbd),
GFP_KERNEL);
246 input_dev = input_allocate_device();
247 if (!locomokbd || !input_dev) {
257 printk(
KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
268 locomokbd->
timer.function = locomokbd_timer_callback;
269 locomokbd->
timer.data = (
unsigned long) locomokbd;
273 locomokbd->
input = input_dev;
276 input_dev->name =
"LoCoMo keyboard";
277 input_dev->phys = locomokbd->
phys;
279 input_dev->id.vendor = 0x0001;
280 input_dev->id.product = 0x0001;
281 input_dev->id.version = 0x0100;
282 input_dev->open = locomokbd_open;
283 input_dev->close = locomokbd_close;
284 input_dev->dev.parent = &dev->
dev;
288 input_dev->keycode = locomokbd->
keycode;
289 input_dev->keycodesize =
sizeof(locomokbd_keycode[0]);
290 input_dev->keycodemax =
ARRAY_SIZE(locomokbd_keycode);
292 input_set_drvdata(input_dev, locomokbd);
300 err =
request_irq(dev->
irq[0], locomokbd_interrupt, 0,
"locomokbd", locomokbd);
303 goto err_release_region;
306 err = input_register_device(locomokbd->
input);
318 input_free_device(input_dev);
332 input_unregister_device(locomokbd->
input);
347 .probe = locomokbd_probe,
351 static int __init locomokbd_init(
void)
356 static void __exit locomokbd_exit(
void)