diff options
author | Javier Herrero <jherrero@hvsistemas.es> | 2009-09-16 04:06:42 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-09-18 02:24:02 -0400 |
commit | 422b552debae59b4bebc0ea5fbb9c809d3dfd057 (patch) | |
tree | 705588ecf12f9a2aca25a24384358ed3be25b67f /drivers/input | |
parent | 3b0a9ce0a6918e881c3f44bf1fc2194a8d019104 (diff) |
Input: add driver for OpenCores Keyboard Controller
Driver for the keyboard hardware documented here:
http://www.opencores.org/project,keyboardcontroller
Signed-off-by: Javier Herrero <jherrero@hvsistemas.es>
Signed-off-by: Bryan Wu <cooloney@kernel.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/Kconfig | 9 | ||||
-rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/keyboard/opencores-kbd.c | 180 |
3 files changed, 190 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 3525c19be428..b14bd3a07140 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
@@ -260,6 +260,15 @@ config KEYBOARD_NEWTON | |||
260 | To compile this driver as a module, choose M here: the | 260 | To compile this driver as a module, choose M here: the |
261 | module will be called newtonkbd. | 261 | module will be called newtonkbd. |
262 | 262 | ||
263 | config KEYBOARD_OPENCORES | ||
264 | tristate "OpenCores Keyboard Controller" | ||
265 | help | ||
266 | Say Y here if you want to use the OpenCores Keyboard Controller | ||
267 | http://www.opencores.org/project,keyboardcontroller | ||
268 | |||
269 | To compile this driver as a module, choose M here; the | ||
270 | module will be called opencores-kbd. | ||
271 | |||
263 | config KEYBOARD_PXA27x | 272 | config KEYBOARD_PXA27x |
264 | tristate "PXA27x/PXA3xx keypad support" | 273 | tristate "PXA27x/PXA3xx keypad support" |
265 | depends on PXA27x || PXA3xx | 274 | depends on PXA27x || PXA3xx |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 8a7a22b30266..ab35ac36111e 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
@@ -23,6 +23,7 @@ obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o | |||
23 | obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o | 23 | obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o |
24 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o | 24 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o |
25 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o | 25 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o |
26 | obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o | ||
26 | obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o | 27 | obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o |
27 | obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o | 28 | obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o |
28 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o | 29 | obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o |
diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c new file mode 100644 index 000000000000..78cccddbf551 --- /dev/null +++ b/drivers/input/keyboard/opencores-kbd.c | |||
@@ -0,0 +1,180 @@ | |||
1 | /* | ||
2 | * OpenCores Keyboard Controller Driver | ||
3 | * http://www.opencores.org/project,keyboardcontroller | ||
4 | * | ||
5 | * Copyright 2007-2009 HV Sistemas S.L. | ||
6 | * | ||
7 | * Licensed under the GPL-2 or later. | ||
8 | */ | ||
9 | |||
10 | #include <linux/input.h> | ||
11 | #include <linux/interrupt.h> | ||
12 | #include <linux/io.h> | ||
13 | #include <linux/ioport.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | struct opencores_kbd { | ||
19 | struct input_dev *input; | ||
20 | struct resource *addr_res; | ||
21 | void __iomem *addr; | ||
22 | int irq; | ||
23 | unsigned short keycodes[128]; | ||
24 | }; | ||
25 | |||
26 | static irqreturn_t opencores_kbd_isr(int irq, void *dev_id) | ||
27 | { | ||
28 | struct opencores_kbd *opencores_kbd = dev_id; | ||
29 | struct input_dev *input = opencores_kbd->input; | ||
30 | unsigned char c; | ||
31 | |||
32 | c = readb(opencores_kbd->addr); | ||
33 | input_report_key(input, c & 0x7f, c & 0x80 ? 0 : 1); | ||
34 | input_sync(input); | ||
35 | |||
36 | return IRQ_HANDLED; | ||
37 | } | ||
38 | |||
39 | static int __devinit opencores_kbd_probe(struct platform_device *pdev) | ||
40 | { | ||
41 | struct input_dev *input; | ||
42 | struct opencores_kbd *opencores_kbd; | ||
43 | struct resource *res; | ||
44 | int irq, i, error; | ||
45 | |||
46 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
47 | if (!res) { | ||
48 | dev_err(&pdev->dev, "missing board memory resource\n"); | ||
49 | return -EINVAL; | ||
50 | } | ||
51 | |||
52 | irq = platform_get_irq(pdev, 0); | ||
53 | if (irq < 0) { | ||
54 | dev_err(&pdev->dev, "missing board IRQ resource\n"); | ||
55 | return -EINVAL; | ||
56 | } | ||
57 | |||
58 | opencores_kbd = kzalloc(sizeof(*opencores_kbd), GFP_KERNEL); | ||
59 | input = input_allocate_device(); | ||
60 | if (!opencores_kbd || !input) { | ||
61 | dev_err(&pdev->dev, "failed to allocate device structures\n"); | ||
62 | error = -ENOMEM; | ||
63 | goto err_free_mem; | ||
64 | } | ||
65 | |||
66 | opencores_kbd->addr_res = res; | ||
67 | res = request_mem_region(res->start, resource_size(res), pdev->name); | ||
68 | if (!res) { | ||
69 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | ||
70 | error = -EBUSY; | ||
71 | goto err_free_mem; | ||
72 | } | ||
73 | |||
74 | opencores_kbd->addr = ioremap(res->start, resource_size(res)); | ||
75 | if (!opencores_kbd->addr) { | ||
76 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | ||
77 | error = -ENXIO; | ||
78 | goto err_rel_mem; | ||
79 | } | ||
80 | |||
81 | opencores_kbd->input = input; | ||
82 | opencores_kbd->irq = irq; | ||
83 | |||
84 | input->name = pdev->name; | ||
85 | input->phys = "opencores-kbd/input0"; | ||
86 | input->dev.parent = &pdev->dev; | ||
87 | |||
88 | input_set_drvdata(input, opencores_kbd); | ||
89 | |||
90 | input->id.bustype = BUS_HOST; | ||
91 | input->id.vendor = 0x0001; | ||
92 | input->id.product = 0x0001; | ||
93 | input->id.version = 0x0100; | ||
94 | |||
95 | input->keycode = opencores_kbd->keycodes; | ||
96 | input->keycodesize = sizeof(opencores_kbd->keycodes[0]); | ||
97 | input->keycodemax = ARRAY_SIZE(opencores_kbd->keycodes); | ||
98 | |||
99 | __set_bit(EV_KEY, input->evbit); | ||
100 | |||
101 | for (i = 0; i < ARRAY_SIZE(opencores_kbd->keycodes); i++) { | ||
102 | /* | ||
103 | * OpenCores controller happens to have scancodes match | ||
104 | * our KEY_* definitions. | ||
105 | */ | ||
106 | opencores_kbd->keycodes[i] = i; | ||
107 | __set_bit(opencores_kbd->keycodes[i], input->keybit); | ||
108 | } | ||
109 | __clear_bit(KEY_RESERVED, input->keybit); | ||
110 | |||
111 | error = request_irq(irq, &opencores_kbd_isr, | ||
112 | IRQF_TRIGGER_RISING, pdev->name, opencores_kbd); | ||
113 | if (error) { | ||
114 | dev_err(&pdev->dev, "unable to claim irq %d\n", irq); | ||
115 | goto err_unmap_mem; | ||
116 | } | ||
117 | |||
118 | error = input_register_device(input); | ||
119 | if (error) { | ||
120 | dev_err(&pdev->dev, "unable to register input device\n"); | ||
121 | goto err_free_irq; | ||
122 | } | ||
123 | |||
124 | platform_set_drvdata(pdev, opencores_kbd); | ||
125 | |||
126 | return 0; | ||
127 | |||
128 | err_free_irq: | ||
129 | free_irq(irq, opencores_kbd); | ||
130 | err_unmap_mem: | ||
131 | iounmap(opencores_kbd->addr); | ||
132 | err_rel_mem: | ||
133 | release_mem_region(res->start, resource_size(res)); | ||
134 | err_free_mem: | ||
135 | input_free_device(input); | ||
136 | kfree(opencores_kbd); | ||
137 | |||
138 | return error; | ||
139 | } | ||
140 | |||
141 | static int __devexit opencores_kbd_remove(struct platform_device *pdev) | ||
142 | { | ||
143 | struct opencores_kbd *opencores_kbd = platform_get_drvdata(pdev); | ||
144 | |||
145 | free_irq(opencores_kbd->irq, opencores_kbd); | ||
146 | |||
147 | iounmap(opencores_kbd->addr); | ||
148 | release_mem_region(opencores_kbd->addr_res->start, | ||
149 | resource_size(opencores_kbd->addr_res)); | ||
150 | input_unregister_device(opencores_kbd->input); | ||
151 | kfree(opencores_kbd); | ||
152 | |||
153 | platform_set_drvdata(pdev, NULL); | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static struct platform_driver opencores_kbd_device_driver = { | ||
159 | .probe = opencores_kbd_probe, | ||
160 | .remove = __devexit_p(opencores_kbd_remove), | ||
161 | .driver = { | ||
162 | .name = "opencores-kbd", | ||
163 | }, | ||
164 | }; | ||
165 | |||
166 | static int __init opencores_kbd_init(void) | ||
167 | { | ||
168 | return platform_driver_register(&opencores_kbd_device_driver); | ||
169 | } | ||
170 | module_init(opencores_kbd_init); | ||
171 | |||
172 | static void __exit opencores_kbd_exit(void) | ||
173 | { | ||
174 | platform_driver_unregister(&opencores_kbd_device_driver); | ||
175 | } | ||
176 | module_exit(opencores_kbd_exit); | ||
177 | |||
178 | MODULE_LICENSE("GPL"); | ||
179 | MODULE_AUTHOR("Javier Herrero <jherrero@hvsistemas.es>"); | ||
180 | MODULE_DESCRIPTION("Keyboard driver for OpenCores Keyboard Controller"); | ||