aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/serio
diff options
context:
space:
mode:
authorThomas Chou <thomas@wytron.com.tw>2009-10-13 00:35:00 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-10-13 00:43:11 -0400
commitfb5bbee0dd033db7c31fe6cb78d2ce2b6588fd42 (patch)
tree8db3da7b84cd58d652ed516bcccb2bb3b0d937fc /drivers/input/serio
parent161291396e76e0832c08f617eb9bd364d1648148 (diff)
Input: add driver for Altera PS/2 controller
This patch adds a new SERIO driver to support the Altera University Program PS/2 controller. [dtor@mail.ru: assorted cleanups] Signed-off-by: Thomas Chou <thomas@wytron.com.tw> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/serio')
-rw-r--r--drivers/input/serio/Kconfig8
-rw-r--r--drivers/input/serio/Makefile1
-rw-r--r--drivers/input/serio/altera_ps2.c200
3 files changed, 209 insertions, 0 deletions
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index aa533ceffe3..7e319d65ec5 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -201,4 +201,12 @@ config SERIO_XILINX_XPS_PS2
201 To compile this driver as a module, choose M here: the 201 To compile this driver as a module, choose M here: the
202 module will be called xilinx_ps2. 202 module will be called xilinx_ps2.
203 203
204config SERIO_ALTERA_PS2
205 tristate "Altera UP PS/2 controller"
206 help
207 Say Y here if you have Altera University Program PS/2 ports.
208
209 To compile this driver as a module, choose M here: the
210 module will be called altera_ps2.
211
204endif 212endif
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile
index 9b6c8135955..bf945f789d0 100644
--- a/drivers/input/serio/Makefile
+++ b/drivers/input/serio/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_SERIO_MACEPS2) += maceps2.o
22obj-$(CONFIG_SERIO_LIBPS2) += libps2.o 22obj-$(CONFIG_SERIO_LIBPS2) += libps2.o
23obj-$(CONFIG_SERIO_RAW) += serio_raw.o 23obj-$(CONFIG_SERIO_RAW) += serio_raw.o
24obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o 24obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o
25obj-$(CONFIG_SERIO_ALTERA_PS2) += altera_ps2.o
diff --git a/drivers/input/serio/altera_ps2.c b/drivers/input/serio/altera_ps2.c
new file mode 100644
index 00000000000..f479ea50919
--- /dev/null
+++ b/drivers/input/serio/altera_ps2.c
@@ -0,0 +1,200 @@
1/*
2 * Altera University Program PS2 controller driver
3 *
4 * Copyright (C) 2008 Thomas Chou <thomas@wytron.com.tw>
5 *
6 * Based on sa1111ps2.c, which is:
7 * Copyright (C) 2002 Russell King
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/input.h>
17#include <linux/serio.h>
18#include <linux/interrupt.h>
19#include <linux/platform_device.h>
20#include <linux/io.h>
21
22#define DRV_NAME "altera_ps2"
23
24struct ps2if {
25 struct serio *io;
26 struct resource *iomem_res;
27 void __iomem *base;
28 unsigned irq;
29};
30
31/*
32 * Read all bytes waiting in the PS2 port. There should be
33 * at the most one, but we loop for safety.
34 */
35static irqreturn_t altera_ps2_rxint(int irq, void *dev_id)
36{
37 struct ps2if *ps2if = dev_id;
38 unsigned int status;
39 int handled = IRQ_NONE;
40
41 while ((status = readl(ps2if->base)) & 0xffff0000) {
42 serio_interrupt(ps2if->io, status & 0xff, 0);
43 handled = IRQ_HANDLED;
44 }
45
46 return handled;
47}
48
49/*
50 * Write a byte to the PS2 port.
51 */
52static int altera_ps2_write(struct serio *io, unsigned char val)
53{
54 struct ps2if *ps2if = io->port_data;
55
56 writel(val, ps2if->base);
57 return 0;
58}
59
60static int altera_ps2_open(struct serio *io)
61{
62 struct ps2if *ps2if = io->port_data;
63
64 /* clear fifo */
65 while (readl(ps2if->base) & 0xffff0000)
66 /* empty */;
67
68 writel(1, ps2if->base + 4); /* enable rx irq */
69 return 0;
70}
71
72static void altera_ps2_close(struct serio *io)
73{
74 struct ps2if *ps2if = io->port_data;
75
76 writel(0, ps2if->base); /* disable rx irq */
77}
78
79/*
80 * Add one device to this driver.
81 */
82static int altera_ps2_probe(struct platform_device *pdev)
83{
84 struct ps2if *ps2if;
85 struct serio *serio;
86 int error;
87
88 ps2if = kzalloc(sizeof(struct ps2if), GFP_KERNEL);
89 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
90 if (!ps2if || !serio) {
91 error = -ENOMEM;
92 goto err_free_mem;
93 }
94
95 serio->id.type = SERIO_8042;
96 serio->write = altera_ps2_write;
97 serio->open = altera_ps2_open;
98 serio->close = altera_ps2_close;
99 strlcpy(serio->name, dev_name(&pdev->dev), sizeof(serio->name));
100 strlcpy(serio->phys, dev_name(&pdev->dev), sizeof(serio->phys));
101 serio->port_data = ps2if;
102 serio->dev.parent = &pdev->dev;
103 ps2if->io = serio;
104
105 ps2if->iomem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
106 if (ps2if->iomem_res == NULL) {
107 error = -ENOENT;
108 goto err_free_mem;
109 }
110
111 ps2if->irq = platform_get_irq(pdev, 0);
112 if (ps2if->irq < 0) {
113 error = -ENXIO;
114 goto err_free_mem;
115 }
116
117 if (!request_mem_region(ps2if->iomem_res->start,
118 resource_size(ps2if->iomem_res), pdev->name)) {
119 error = -EBUSY;
120 goto err_free_mem;
121 }
122
123 ps2if->base = ioremap(ps2if->iomem_res->start,
124 resource_size(ps2if->iomem_res));
125 if (!ps2if->base) {
126 error = -ENOMEM;
127 goto err_free_res;
128 }
129
130 error = request_irq(ps2if->irq, altera_ps2_rxint, 0, pdev->name, ps2if);
131 if (error) {
132 dev_err(&pdev->dev, "could not allocate IRQ %d: %d\n",
133 ps2if->irq, error);
134 goto err_unmap;
135 }
136
137 dev_info(&pdev->dev, "base %p, irq %d\n", ps2if->base, ps2if->irq);
138
139 serio_register_port(ps2if->io);
140 platform_set_drvdata(pdev, ps2if);
141
142 return 0;
143
144 err_unmap:
145 iounmap(ps2if->base);
146 err_free_res:
147 release_mem_region(ps2if->iomem_res->start,
148 resource_size(ps2if->iomem_res));
149 err_free_mem:
150 kfree(ps2if);
151 kfree(serio);
152 return error;
153}
154
155/*
156 * Remove one device from this driver.
157 */
158static int altera_ps2_remove(struct platform_device *pdev)
159{
160 struct ps2if *ps2if = platform_get_drvdata(pdev);
161
162 platform_set_drvdata(pdev, NULL);
163 serio_unregister_port(ps2if->io);
164 free_irq(ps2if->irq, ps2if);
165 iounmap(ps2if->base);
166 release_mem_region(ps2if->iomem_res->start,
167 resource_size(ps2if->iomem_res));
168 kfree(ps2if);
169
170 return 0;
171}
172
173/*
174 * Our device driver structure
175 */
176static struct platform_driver altera_ps2_driver = {
177 .probe = altera_ps2_probe,
178 .remove = altera_ps2_remove,
179 .driver = {
180 .name = DRV_NAME,
181 },
182};
183
184static int __init altera_ps2_init(void)
185{
186 return platform_driver_register(&altera_ps2_driver);
187}
188
189static void __exit altera_ps2_exit(void)
190{
191 platform_driver_unregister(&altera_ps2_driver);
192}
193
194module_init(altera_ps2_init);
195module_exit(altera_ps2_exit);
196
197MODULE_DESCRIPTION("Altera University Program PS2 controller driver");
198MODULE_AUTHOR("Thomas Chou <thomas@wytron.com.tw>");
199MODULE_LICENSE("GPL");
200MODULE_ALIAS("platform:" DRV_NAME);