diff options
| author | Nicolas Bellido <ml@acolin.be> | 2006-11-24 00:42:50 -0500 |
|---|---|---|
| committer | Dmitry Torokhov <dtor@insightbb.com> | 2006-11-24 00:42:50 -0500 |
| commit | f9705fcb9887fcff364a0c8dffbac693aa221d4f (patch) | |
| tree | 5126de9a40199f1c6b3c7797109b83f577f30d33 /drivers/input/keyboard | |
| parent | 153a9df01c0d1ecdc56161c7a0f830325145dd64 (diff) | |
Input: add driver for keyboard on AAED-2000 development board (ARM)
The keyboard is connected via GPIOs to the processor, and scanned
using a column sample register. The hardware provides no debouncing
mechanism, so the state of the keys is read KBDSCAN_STABLE_COUNT
times before being reported to the input layer.
The status of the keys needs to be polled because there is no
interrupt hooked to the lines. A workqueue is used for this.
Signed-off-by: Nicolas Bellido Y Ortega <ml@acolin.be>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/keyboard')
| -rw-r--r-- | drivers/input/keyboard/Kconfig | 11 | ||||
| -rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
| -rw-r--r-- | drivers/input/keyboard/aaed2000_kbd.c | 203 |
3 files changed, 215 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 81a333f73010..049f2f544e75 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
| @@ -203,4 +203,15 @@ config KEYBOARD_OMAP | |||
| 203 | To compile this driver as a module, choose M here: the | 203 | To compile this driver as a module, choose M here: the |
| 204 | module will be called omap-keypad. | 204 | module will be called omap-keypad. |
| 205 | 205 | ||
| 206 | config KEYBOARD_AAED2000 | ||
| 207 | tristate "AAED-2000 keyboard" | ||
| 208 | depends on MACH_AAED2000 | ||
| 209 | default y | ||
| 210 | help | ||
| 211 | Say Y here to enable the keyboard on the Agilent AAED-2000 | ||
| 212 | development board. | ||
| 213 | |||
| 214 | To compile this driver as a module, choose M here: the | ||
| 215 | module will be called aaed2000_kbd. | ||
| 216 | |||
| 206 | endif | 217 | endif |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 4c79e7bc9d06..568797907347 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
| @@ -17,4 +17,5 @@ obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o | |||
| 17 | obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o | 17 | obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o |
| 18 | obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o | 18 | obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o |
| 19 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o | 19 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o |
| 20 | obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o | ||
| 20 | 21 | ||
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c new file mode 100644 index 000000000000..65fcb6af63a8 --- /dev/null +++ b/drivers/input/keyboard/aaed2000_kbd.c | |||
| @@ -0,0 +1,203 @@ | |||
| 1 | /* | ||
| 2 | * Keyboard driver for the AAED-2000 dev board | ||
| 3 | * | ||
| 4 | * Copyright (c) 2006 Nicolas Bellido Y Ortega | ||
| 5 | * | ||
| 6 | * Based on corgikbd.c | ||
| 7 | * | ||
| 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. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/delay.h> | ||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/init.h> | ||
| 17 | #include <linux/input.h> | ||
| 18 | #include <linux/interrupt.h> | ||
| 19 | #include <linux/jiffies.h> | ||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/slab.h> | ||
| 22 | #include <linux/workqueue.h> | ||
| 23 | |||
| 24 | #include <asm/arch/hardware.h> | ||
| 25 | #include <asm/arch/aaed2000.h> | ||
| 26 | |||
| 27 | #define KB_ROWS 12 | ||
| 28 | #define KB_COLS 8 | ||
| 29 | #define KB_ROWMASK(r) (1 << (r)) | ||
| 30 | #define SCANCODE(r,c) (((c) * KB_ROWS) + (r)) | ||
| 31 | #define NR_SCANCODES (KB_COLS * KB_ROWS) | ||
| 32 | |||
| 33 | #define SCAN_INTERVAL (50) /* ms */ | ||
| 34 | #define KB_ACTIVATE_DELAY (20) /* us */ | ||
| 35 | |||
| 36 | static unsigned char aaedkbd_keycode[NR_SCANCODES] = { | ||
| 37 | KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, 0, KEY_SPACE, KEY_KP6, 0, KEY_KPDOT, 0, 0, | ||
| 38 | KEY_K, KEY_M, KEY_O, KEY_DOT, KEY_SLASH, 0, KEY_F, 0, 0, 0, KEY_LEFTSHIFT, 0, | ||
| 39 | KEY_I, KEY_P, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, 0, 0, 0, 0, KEY_RIGHTSHIFT, 0, | ||
| 40 | KEY_8, KEY_L, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_ENTER, 0, 0, 0, 0, 0, 0, 0, | ||
| 41 | KEY_J, KEY_H, KEY_B, KEY_KP8, KEY_KP4, 0, KEY_C, KEY_D, KEY_S, KEY_A, 0, KEY_CAPSLOCK, | ||
| 42 | KEY_Y, KEY_U, KEY_N, KEY_T, 0, 0, KEY_R, KEY_E, KEY_W, KEY_Q, 0, KEY_TAB, | ||
| 43 | KEY_7, KEY_6, KEY_G, 0, KEY_5, 0, KEY_4, KEY_3, KEY_2, KEY_1, 0, KEY_GRAVE, | ||
| 44 | 0, 0, KEY_COMMA, 0, KEY_KP2, 0, KEY_V, KEY_LEFTALT, KEY_X, KEY_Z, 0, KEY_LEFTCTRL | ||
| 45 | }; | ||
| 46 | |||
| 47 | struct aaedkbd { | ||
| 48 | unsigned char keycode[ARRAY_SIZE(aaedkbd_keycode)]; | ||
| 49 | struct input_dev *input; | ||
| 50 | struct work_struct workq; | ||
| 51 | int kbdscan_state[KB_COLS]; | ||
| 52 | int kbdscan_count[KB_COLS]; | ||
| 53 | }; | ||
| 54 | |||
| 55 | #define KBDSCAN_STABLE_COUNT 2 | ||
| 56 | |||
| 57 | static void aaedkbd_report_col(struct aaedkbd *aaedkbd, | ||
| 58 | unsigned int col, unsigned int rowd) | ||
| 59 | { | ||
| 60 | unsigned int scancode, pressed; | ||
| 61 | unsigned int row; | ||
| 62 | |||
| 63 | for (row = 0; row < KB_ROWS; row++) { | ||
| 64 | scancode = SCANCODE(row, col); | ||
| 65 | pressed = rowd & KB_ROWMASK(row); | ||
| 66 | |||
| 67 | input_report_key(aaedkbd->input, aaedkbd->keycode[scancode], pressed); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | /* Scan the hardware keyboard and push any changes up through the input layer */ | ||
| 72 | static void aaedkbd_work(void *data) | ||
| 73 | { | ||
| 74 | struct aaedkbd *aaedkbd = data; | ||
| 75 | unsigned int col, rowd; | ||
| 76 | |||
| 77 | col = 0; | ||
| 78 | do { | ||
| 79 | AAEC_GPIO_KSCAN = col + 8; | ||
| 80 | udelay(KB_ACTIVATE_DELAY); | ||
| 81 | rowd = AAED_EXT_GPIO & AAED_EGPIO_KBD_SCAN; | ||
| 82 | |||
| 83 | if (rowd != aaedkbd->kbdscan_state[col]) { | ||
| 84 | aaedkbd->kbdscan_count[col] = 0; | ||
| 85 | aaedkbd->kbdscan_state[col] = rowd; | ||
| 86 | } else if (++aaedkbd->kbdscan_count[col] >= KBDSCAN_STABLE_COUNT) { | ||
| 87 | aaedkbd_report_col(aaedkbd, col, rowd); | ||
| 88 | col++; | ||
| 89 | } | ||
| 90 | } while (col < KB_COLS); | ||
| 91 | |||
| 92 | AAEC_GPIO_KSCAN = 0x07; | ||
| 93 | input_sync(aaedkbd->input); | ||
| 94 | |||
| 95 | schedule_delayed_work(&aaedkbd->workq, msecs_to_jiffies(SCAN_INTERVAL)); | ||
| 96 | } | ||
| 97 | |||
| 98 | static int aaedkbd_open(struct input_dev *indev) | ||
| 99 | { | ||
| 100 | struct aaedkbd *aaedkbd = indev->private; | ||
| 101 | |||
| 102 | schedule_delayed_work(&aaedkbd->workq, msecs_to_jiffies(SCAN_INTERVAL)); | ||
| 103 | |||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | static void aaedkbd_close(struct input_dev *indev) | ||
| 108 | { | ||
| 109 | struct aaedkbd *aaedkbd = indev->private; | ||
| 110 | |||
| 111 | cancel_delayed_work(&aaedkbd->workq); | ||
| 112 | flush_scheduled_work(); | ||
| 113 | } | ||
| 114 | |||
| 115 | static int __devinit aaedkbd_probe(struct platform_device *pdev) | ||
| 116 | { | ||
| 117 | struct aaedkbd *aaedkbd; | ||
| 118 | struct input_dev *input_dev; | ||
| 119 | int i; | ||
| 120 | int error; | ||
| 121 | |||
| 122 | aaedkbd = kzalloc(sizeof(struct aaedkbd), GFP_KERNEL); | ||
| 123 | input_dev = input_allocate_device(); | ||
| 124 | if (!aaedkbd || !input_dev) { | ||
| 125 | error = -ENOMEM; | ||
| 126 | goto fail; | ||
| 127 | } | ||
| 128 | |||
| 129 | platform_set_drvdata(pdev, aaedkbd); | ||
| 130 | |||
| 131 | aaedkbd->input = input_dev; | ||
| 132 | |||
| 133 | /* Init keyboard rescan workqueue */ | ||
| 134 | INIT_WORK(&aaedkbd->workq, aaedkbd_work, aaedkbd); | ||
| 135 | |||
| 136 | memcpy(aaedkbd->keycode, aaedkbd_keycode, sizeof(aaedkbd->keycode)); | ||
| 137 | |||
| 138 | input_dev->name = "AAED-2000 Keyboard"; | ||
| 139 | input_dev->phys = "aaedkbd/input0"; | ||
| 140 | input_dev->id.bustype = BUS_HOST; | ||
| 141 | input_dev->id.vendor = 0x0001; | ||
| 142 | input_dev->id.product = 0x0001; | ||
| 143 | input_dev->id.version = 0x0100; | ||
| 144 | input_dev->cdev.dev = &pdev->dev; | ||
| 145 | input_dev->private = aaedkbd; | ||
| 146 | |||
| 147 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); | ||
| 148 | input_dev->keycode = aaedkbd->keycode; | ||
| 149 | input_dev->keycodesize = sizeof(unsigned char); | ||
| 150 | input_dev->keycodemax = ARRAY_SIZE(aaedkbd_keycode); | ||
| 151 | |||
| 152 | for (i = 0; i < ARRAY_SIZE(aaedkbd_keycode); i++) | ||
| 153 | set_bit(aaedkbd->keycode[i], input_dev->keybit); | ||
| 154 | clear_bit(0, input_dev->keybit); | ||
| 155 | |||
| 156 | input_dev->open = aaedkbd_open; | ||
| 157 | input_dev->close = aaedkbd_close; | ||
| 158 | |||
| 159 | error = input_register_device(aaedkbd->input); | ||
| 160 | if (error) | ||
| 161 | goto fail; | ||
| 162 | |||
| 163 | return 0; | ||
| 164 | |||
| 165 | fail: kfree(aaedkbd); | ||
| 166 | input_free_device(input_dev); | ||
| 167 | return error; | ||
| 168 | } | ||
| 169 | |||
| 170 | static int __devexit aaedkbd_remove(struct platform_device *pdev) | ||
| 171 | { | ||
| 172 | struct aaedkbd *aaedkbd = platform_get_drvdata(pdev); | ||
| 173 | |||
| 174 | input_unregister_device(aaedkbd->input); | ||
| 175 | kfree(aaedkbd); | ||
| 176 | |||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | static struct platform_driver aaedkbd_driver = { | ||
| 181 | .probe = aaedkbd_probe, | ||
| 182 | .remove = __devexit_p(aaedkbd_remove), | ||
| 183 | .driver = { | ||
| 184 | .name = "aaed2000-keyboard", | ||
| 185 | }, | ||
| 186 | }; | ||
| 187 | |||
| 188 | static int __init aaedkbd_init(void) | ||
| 189 | { | ||
| 190 | return platform_driver_register(&aaedkbd_driver); | ||
| 191 | } | ||
| 192 | |||
| 193 | static void __exit aaedkbd_exit(void) | ||
| 194 | { | ||
| 195 | platform_driver_unregister(&aaedkbd_driver); | ||
| 196 | } | ||
| 197 | |||
| 198 | module_init(aaedkbd_init); | ||
| 199 | module_exit(aaedkbd_exit); | ||
| 200 | |||
| 201 | MODULE_AUTHOR("Nicolas Bellido Y Ortega"); | ||
| 202 | MODULE_DESCRIPTION("AAED-2000 Keyboard Driver"); | ||
| 203 | MODULE_LICENSE("GPLv2"); | ||
