V4L/DVB (6715): ivtv: Remove unnecessary register update
[linux-2.6/verdex.git] / drivers / input / keyboard / aaed2000_kbd.c
blob72abc196ce66580000b25e0800e5b4908fc03383
1 /*
2 * Keyboard driver for the AAED-2000 dev board
4 * Copyright (c) 2006 Nicolas Bellido Y Ortega
6 * Based on corgikbd.c
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/delay.h>
15 #include <linux/platform_device.h>
16 #include <linux/init.h>
17 #include <linux/input-polldev.h>
18 #include <linux/interrupt.h>
19 #include <linux/jiffies.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <asm/arch/hardware.h>
24 #include <asm/arch/aaed2000.h>
26 #define KB_ROWS 12
27 #define KB_COLS 8
28 #define KB_ROWMASK(r) (1 << (r))
29 #define SCANCODE(r,c) (((c) * KB_ROWS) + (r))
30 #define NR_SCANCODES (KB_COLS * KB_ROWS)
32 #define SCAN_INTERVAL (50) /* ms */
33 #define KB_ACTIVATE_DELAY (20) /* us */
35 static unsigned char aaedkbd_keycode[NR_SCANCODES] = {
36 KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, 0, KEY_SPACE, KEY_KP6, 0, KEY_KPDOT, 0, 0,
37 KEY_K, KEY_M, KEY_O, KEY_DOT, KEY_SLASH, 0, KEY_F, 0, 0, 0, KEY_LEFTSHIFT, 0,
38 KEY_I, KEY_P, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, 0, 0, 0, 0, KEY_RIGHTSHIFT, 0,
39 KEY_8, KEY_L, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_ENTER, 0, 0, 0, 0, 0, 0, 0,
40 KEY_J, KEY_H, KEY_B, KEY_KP8, KEY_KP4, 0, KEY_C, KEY_D, KEY_S, KEY_A, 0, KEY_CAPSLOCK,
41 KEY_Y, KEY_U, KEY_N, KEY_T, 0, 0, KEY_R, KEY_E, KEY_W, KEY_Q, 0, KEY_TAB,
42 KEY_7, KEY_6, KEY_G, 0, KEY_5, 0, KEY_4, KEY_3, KEY_2, KEY_1, 0, KEY_GRAVE,
43 0, 0, KEY_COMMA, 0, KEY_KP2, 0, KEY_V, KEY_LEFTALT, KEY_X, KEY_Z, 0, KEY_LEFTCTRL
46 struct aaedkbd {
47 unsigned char keycode[ARRAY_SIZE(aaedkbd_keycode)];
48 struct input_polled_dev *poll_dev;
49 int kbdscan_state[KB_COLS];
50 int kbdscan_count[KB_COLS];
53 #define KBDSCAN_STABLE_COUNT 2
55 static void aaedkbd_report_col(struct aaedkbd *aaedkbd,
56 unsigned int col, unsigned int rowd)
58 unsigned int scancode, pressed;
59 unsigned int row;
61 for (row = 0; row < KB_ROWS; row++) {
62 scancode = SCANCODE(row, col);
63 pressed = rowd & KB_ROWMASK(row);
65 input_report_key(aaedkbd->poll_dev->input,
66 aaedkbd->keycode[scancode], pressed);
70 /* Scan the hardware keyboard and push any changes up through the input layer */
71 static void aaedkbd_poll(struct input_polled_dev *dev)
73 struct aaedkbd *aaedkbd = dev->private;
74 unsigned int col, rowd;
76 col = 0;
77 do {
78 AAEC_GPIO_KSCAN = col + 8;
79 udelay(KB_ACTIVATE_DELAY);
80 rowd = AAED_EXT_GPIO & AAED_EGPIO_KBD_SCAN;
82 if (rowd != aaedkbd->kbdscan_state[col]) {
83 aaedkbd->kbdscan_count[col] = 0;
84 aaedkbd->kbdscan_state[col] = rowd;
85 } else if (++aaedkbd->kbdscan_count[col] >= KBDSCAN_STABLE_COUNT) {
86 aaedkbd_report_col(aaedkbd, col, rowd);
87 col++;
89 } while (col < KB_COLS);
91 AAEC_GPIO_KSCAN = 0x07;
92 input_sync(dev->input);
95 static int __devinit aaedkbd_probe(struct platform_device *pdev)
97 struct aaedkbd *aaedkbd;
98 struct input_polled_dev *poll_dev;
99 struct input_dev *input_dev;
100 int i;
101 int error;
103 aaedkbd = kzalloc(sizeof(struct aaedkbd), GFP_KERNEL);
104 poll_dev = input_allocate_polled_device();
105 if (!aaedkbd || !poll_dev) {
106 error = -ENOMEM;
107 goto fail;
110 platform_set_drvdata(pdev, aaedkbd);
112 aaedkbd->poll_dev = poll_dev;
113 memcpy(aaedkbd->keycode, aaedkbd_keycode, sizeof(aaedkbd->keycode));
115 poll_dev->private = aaedkbd;
116 poll_dev->poll = aaedkbd_poll;
117 poll_dev->poll_interval = SCAN_INTERVAL;
119 input_dev = poll_dev->input;
120 input_dev->name = "AAED-2000 Keyboard";
121 input_dev->phys = "aaedkbd/input0";
122 input_dev->id.bustype = BUS_HOST;
123 input_dev->id.vendor = 0x0001;
124 input_dev->id.product = 0x0001;
125 input_dev->id.version = 0x0100;
126 input_dev->dev.parent = &pdev->dev;
128 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
129 input_dev->keycode = aaedkbd->keycode;
130 input_dev->keycodesize = sizeof(unsigned char);
131 input_dev->keycodemax = ARRAY_SIZE(aaedkbd_keycode);
133 for (i = 0; i < ARRAY_SIZE(aaedkbd_keycode); i++)
134 set_bit(aaedkbd->keycode[i], input_dev->keybit);
135 clear_bit(0, input_dev->keybit);
137 error = input_register_polled_device(aaedkbd->poll_dev);
138 if (error)
139 goto fail;
141 return 0;
143 fail: kfree(aaedkbd);
144 input_free_polled_device(poll_dev);
145 return error;
148 static int __devexit aaedkbd_remove(struct platform_device *pdev)
150 struct aaedkbd *aaedkbd = platform_get_drvdata(pdev);
152 input_unregister_polled_device(aaedkbd->poll_dev);
153 input_free_polled_device(aaedkbd->poll_dev);
154 kfree(aaedkbd);
156 return 0;
159 static struct platform_driver aaedkbd_driver = {
160 .probe = aaedkbd_probe,
161 .remove = __devexit_p(aaedkbd_remove),
162 .driver = {
163 .name = "aaed2000-keyboard",
167 static int __init aaedkbd_init(void)
169 return platform_driver_register(&aaedkbd_driver);
172 static void __exit aaedkbd_exit(void)
174 platform_driver_unregister(&aaedkbd_driver);
177 module_init(aaedkbd_init);
178 module_exit(aaedkbd_exit);
180 MODULE_AUTHOR("Nicolas Bellido Y Ortega");
181 MODULE_DESCRIPTION("AAED-2000 Keyboard Driver");
182 MODULE_LICENSE("GPLv2");