diff options
| author | Mischa Jonker <mischa.jonker@synopsys.com> | 2012-10-23 01:48:08 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-10-23 01:48:32 -0400 |
| commit | e4b290094603423623d3f268e054f40f3f51afa8 (patch) | |
| tree | 807045898ab03b74419f668f4039ac9aadb9b241 /drivers/input/serio | |
| parent | f6c0df6acbfc49abe0fe593936f170cc726e21fb (diff) | |
Input: serio - add ARC PS/2 driver
This adds support for the PS/2 block that is used in various ARC FPGA
platforms.
Signed-off-by: Mischa Jonker <mischa.jonker@synopsys.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/serio')
| -rw-r--r-- | drivers/input/serio/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/input/serio/Makefile | 1 | ||||
| -rw-r--r-- | drivers/input/serio/arc_ps2.c | 279 |
3 files changed, 289 insertions, 0 deletions
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig index 55f2c2293ec..4a4e182c33e 100644 --- a/drivers/input/serio/Kconfig +++ b/drivers/input/serio/Kconfig | |||
| @@ -234,4 +234,13 @@ config SERIO_PS2MULT | |||
| 234 | To compile this driver as a module, choose M here: the | 234 | To compile this driver as a module, choose M here: the |
| 235 | module will be called ps2mult. | 235 | module will be called ps2mult. |
| 236 | 236 | ||
| 237 | config SERIO_ARC_PS2 | ||
| 238 | tristate "ARC PS/2 support" | ||
| 239 | help | ||
| 240 | Say Y here if you have an ARC FPGA platform with a PS/2 | ||
| 241 | controller in it. | ||
| 242 | |||
| 243 | To compile this driver as a module, choose M here; the module | ||
| 244 | will be called arc_ps2. | ||
| 245 | |||
| 237 | endif | 246 | endif |
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile index dbbe37616c9..4b0c8f84f1c 100644 --- a/drivers/input/serio/Makefile +++ b/drivers/input/serio/Makefile | |||
| @@ -25,3 +25,4 @@ obj-$(CONFIG_SERIO_RAW) += serio_raw.o | |||
| 25 | obj-$(CONFIG_SERIO_AMS_DELTA) += ams_delta_serio.o | 25 | obj-$(CONFIG_SERIO_AMS_DELTA) += ams_delta_serio.o |
| 26 | obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o | 26 | obj-$(CONFIG_SERIO_XILINX_XPS_PS2) += xilinx_ps2.o |
| 27 | obj-$(CONFIG_SERIO_ALTERA_PS2) += altera_ps2.o | 27 | obj-$(CONFIG_SERIO_ALTERA_PS2) += altera_ps2.o |
| 28 | obj-$(CONFIG_SERIO_ARC_PS2) += arc_ps2.o | ||
diff --git a/drivers/input/serio/arc_ps2.c b/drivers/input/serio/arc_ps2.c new file mode 100644 index 00000000000..f8c026ac15e --- /dev/null +++ b/drivers/input/serio/arc_ps2.c | |||
| @@ -0,0 +1,279 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License version 2 as | ||
| 6 | * published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * Driver is originally developed by Pavel Sokolov <psokolov@synopsys.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/interrupt.h> | ||
| 13 | #include <linux/input.h> | ||
| 14 | #include <linux/serio.h> | ||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/io.h> | ||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/slab.h> | ||
| 19 | |||
| 20 | #define ARC_PS2_PORTS 2 | ||
| 21 | |||
| 22 | #define ARC_ARC_PS2_ID 0x0001f609 | ||
| 23 | |||
| 24 | #define STAT_TIMEOUT 128 | ||
| 25 | |||
| 26 | #define PS2_STAT_RX_FRM_ERR (1) | ||
| 27 | #define PS2_STAT_RX_BUF_OVER (1 << 1) | ||
| 28 | #define PS2_STAT_RX_INT_EN (1 << 2) | ||
| 29 | #define PS2_STAT_RX_VAL (1 << 3) | ||
| 30 | #define PS2_STAT_TX_ISNOT_FUL (1 << 4) | ||
| 31 | #define PS2_STAT_TX_INT_EN (1 << 5) | ||
| 32 | |||
| 33 | struct arc_ps2_port { | ||
| 34 | void __iomem *data_addr; | ||
| 35 | void __iomem *status_addr; | ||
| 36 | struct serio *io; | ||
| 37 | }; | ||
| 38 | |||
| 39 | struct arc_ps2_data { | ||
| 40 | struct arc_ps2_port port[ARC_PS2_PORTS]; | ||
| 41 | struct resource *iomem_res; | ||
| 42 | int irq; | ||
| 43 | void __iomem *addr; | ||
| 44 | unsigned int frame_error; | ||
| 45 | unsigned int buf_overflow; | ||
| 46 | unsigned int total_int; | ||
| 47 | }; | ||
| 48 | |||
| 49 | static void arc_ps2_check_rx(struct arc_ps2_data *arc_ps2, | ||
| 50 | struct arc_ps2_port *port) | ||
| 51 | { | ||
| 52 | unsigned int timeout = 1000; | ||
| 53 | unsigned int flag, status; | ||
| 54 | unsigned char data; | ||
| 55 | |||
| 56 | do { | ||
| 57 | status = ioread32(port->status_addr); | ||
| 58 | if (!(status & PS2_STAT_RX_VAL)) | ||
| 59 | return; | ||
| 60 | |||
| 61 | data = ioread32(port->data_addr) & 0xff; | ||
| 62 | |||
| 63 | flag = 0; | ||
| 64 | arc_ps2->total_int++; | ||
| 65 | if (status & PS2_STAT_RX_FRM_ERR) { | ||
| 66 | arc_ps2->frame_error++; | ||
| 67 | flag |= SERIO_PARITY; | ||
| 68 | } else if (status & PS2_STAT_RX_BUF_OVER) { | ||
| 69 | arc_ps2->buf_overflow++; | ||
| 70 | flag |= SERIO_FRAME; | ||
| 71 | } | ||
| 72 | |||
| 73 | serio_interrupt(port->io, data, flag); | ||
| 74 | } while (--timeout); | ||
| 75 | |||
| 76 | dev_err(&port->io->dev, "PS/2 hardware stuck\n"); | ||
| 77 | } | ||
| 78 | |||
| 79 | static irqreturn_t arc_ps2_interrupt(int irq, void *dev) | ||
| 80 | { | ||
| 81 | struct arc_ps2_data *arc_ps2 = dev; | ||
| 82 | int i; | ||
| 83 | |||
| 84 | for (i = 0; i < ARC_PS2_PORTS; i++) | ||
| 85 | arc_ps2_check_rx(arc_ps2, &arc_ps2->port[i]); | ||
| 86 | |||
| 87 | return IRQ_HANDLED; | ||
| 88 | } | ||
| 89 | |||
| 90 | static int arc_ps2_write(struct serio *io, unsigned char val) | ||
| 91 | { | ||
| 92 | unsigned status; | ||
| 93 | struct arc_ps2_port *port = io->port_data; | ||
| 94 | int timeout = STAT_TIMEOUT; | ||
| 95 | |||
| 96 | do { | ||
| 97 | status = ioread32(port->status_addr); | ||
| 98 | cpu_relax(); | ||
| 99 | |||
| 100 | if (status & PS2_STAT_TX_ISNOT_FUL) { | ||
| 101 | iowrite32(val & 0xff, port->data_addr); | ||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | } while (--timeout); | ||
| 106 | |||
| 107 | dev_err(&io->dev, "write timeout\n"); | ||
| 108 | return -ETIMEDOUT; | ||
| 109 | } | ||
| 110 | |||
| 111 | static int arc_ps2_open(struct serio *io) | ||
| 112 | { | ||
| 113 | struct arc_ps2_port *port = io->port_data; | ||
| 114 | |||
| 115 | iowrite32(PS2_STAT_RX_INT_EN, port->status_addr); | ||
| 116 | |||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | static void arc_ps2_close(struct serio *io) | ||
| 121 | { | ||
| 122 | struct arc_ps2_port *port = io->port_data; | ||
| 123 | |||
| 124 | iowrite32(ioread32(port->status_addr) & ~PS2_STAT_RX_INT_EN, | ||
| 125 | port->status_addr); | ||
| 126 | } | ||
| 127 | |||
| 128 | static int __devinit arc_ps2_create_port(struct platform_device *pdev, | ||
| 129 | struct arc_ps2_data *arc_ps2, | ||
| 130 | int index) | ||
| 131 | { | ||
| 132 | struct arc_ps2_port *port = &arc_ps2->port[index]; | ||
| 133 | struct serio *io; | ||
| 134 | |||
| 135 | io = kzalloc(sizeof(struct serio), GFP_KERNEL); | ||
| 136 | if (!io) | ||
| 137 | return -ENOMEM; | ||
| 138 | |||
| 139 | io->id.type = SERIO_8042; | ||
| 140 | io->write = arc_ps2_write; | ||
| 141 | io->open = arc_ps2_open; | ||
| 142 | io->close = arc_ps2_close; | ||
| 143 | snprintf(io->name, sizeof(io->name), "ARC PS/2 port%d", index); | ||
| 144 | snprintf(io->phys, sizeof(io->phys), "arc/serio%d", index); | ||
| 145 | io->port_data = port; | ||
| 146 | |||
| 147 | port->io = io; | ||
| 148 | |||
| 149 | port->data_addr = arc_ps2->addr + 4 + index * 4; | ||
| 150 | port->status_addr = arc_ps2->addr + 4 + ARC_PS2_PORTS * 4 + index * 4; | ||
| 151 | |||
| 152 | dev_dbg(&pdev->dev, "port%d is allocated (data = 0x%p, status = 0x%p)\n", | ||
| 153 | index, port->data_addr, port->status_addr); | ||
| 154 | |||
| 155 | serio_register_port(port->io); | ||
| 156 | return 0; | ||
| 157 | } | ||
| 158 | |||
| 159 | static int __devinit arc_ps2_probe(struct platform_device *pdev) | ||
| 160 | { | ||
| 161 | struct arc_ps2_data *arc_ps2; | ||
| 162 | int error, id, i; | ||
| 163 | |||
| 164 | arc_ps2 = kzalloc(sizeof(struct arc_ps2_data), GFP_KERNEL); | ||
| 165 | if (!arc_ps2) { | ||
| 166 | dev_err(&pdev->dev, "out of memory\n"); | ||
| 167 | return -ENOMEM; | ||
| 168 | } | ||
| 169 | |||
| 170 | arc_ps2->iomem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 171 | if (!arc_ps2->iomem_res) { | ||
| 172 | dev_err(&pdev->dev, "no IO memory defined\n"); | ||
| 173 | error = -EINVAL; | ||
| 174 | goto err_free_mem; | ||
| 175 | } | ||
| 176 | |||
| 177 | arc_ps2->irq = platform_get_irq_byname(pdev, "arc_ps2_irq"); | ||
| 178 | if (arc_ps2->irq < 0) { | ||
| 179 | dev_err(&pdev->dev, "no IRQ defined\n"); | ||
| 180 | error = -EINVAL; | ||
| 181 | goto err_free_mem; | ||
| 182 | } | ||
| 183 | |||
| 184 | if (!request_mem_region(arc_ps2->iomem_res->start, | ||
| 185 | resource_size(arc_ps2->iomem_res), pdev->name)) { | ||
| 186 | dev_err(&pdev->dev, "memory region allocation failed for %pR\n", | ||
| 187 | arc_ps2->iomem_res); | ||
| 188 | |||
| 189 | error = -EBUSY; | ||
| 190 | goto err_free_mem; | ||
| 191 | } | ||
| 192 | |||
| 193 | arc_ps2->addr = ioremap_nocache(arc_ps2->iomem_res->start, | ||
| 194 | resource_size(arc_ps2->iomem_res)); | ||
| 195 | if (!arc_ps2->addr) { | ||
| 196 | dev_err(&pdev->dev, "memory mapping failed\n"); | ||
| 197 | error = -ENOMEM; | ||
| 198 | goto err_release_region; | ||
| 199 | } | ||
| 200 | |||
| 201 | dev_info(&pdev->dev, "irq = %d, address = 0x%p, ports = %i\n", | ||
| 202 | arc_ps2->irq, arc_ps2->addr, ARC_PS2_PORTS); | ||
| 203 | |||
| 204 | id = ioread32(arc_ps2->addr); | ||
| 205 | if (id != ARC_ARC_PS2_ID) { | ||
| 206 | dev_err(&pdev->dev, "device id does not match\n"); | ||
| 207 | error = -ENXIO; | ||
| 208 | goto err_unmap; | ||
| 209 | } | ||
| 210 | |||
| 211 | for (i = 0; i < ARC_PS2_PORTS; i++) { | ||
| 212 | error = arc_ps2_create_port(pdev, arc_ps2, i); | ||
| 213 | if (error) | ||
| 214 | goto err_unregister_ports; | ||
| 215 | } | ||
| 216 | |||
| 217 | error = request_irq(arc_ps2->irq, arc_ps2_interrupt, 0, | ||
| 218 | "arc_ps2", arc_ps2); | ||
| 219 | if (error) { | ||
| 220 | dev_err(&pdev->dev, "Could not allocate IRQ\n"); | ||
| 221 | goto err_unregister_ports; | ||
| 222 | } | ||
| 223 | |||
| 224 | platform_set_drvdata(pdev, arc_ps2); | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | |||
| 228 | err_unregister_ports: | ||
| 229 | for (i = 0; i < ARC_PS2_PORTS; i++) { | ||
| 230 | if (arc_ps2->port[i].io) | ||
| 231 | serio_unregister_port(arc_ps2->port[i].io); | ||
| 232 | } | ||
| 233 | err_unmap: | ||
| 234 | iounmap(arc_ps2->addr); | ||
| 235 | err_release_region: | ||
| 236 | release_mem_region(arc_ps2->iomem_res->start, | ||
| 237 | resource_size(arc_ps2->iomem_res)); | ||
| 238 | err_free_mem: | ||
| 239 | kfree(arc_ps2); | ||
| 240 | return error; | ||
| 241 | } | ||
| 242 | |||
| 243 | static int __devexit arc_ps2_remove(struct platform_device *pdev) | ||
| 244 | { | ||
| 245 | struct arc_ps2_data *arc_ps2 = platform_get_drvdata(pdev); | ||
| 246 | int i; | ||
| 247 | |||
| 248 | for (i = 0; i < ARC_PS2_PORTS; i++) | ||
| 249 | serio_unregister_port(arc_ps2->port[i].io); | ||
| 250 | |||
| 251 | free_irq(arc_ps2->irq, arc_ps2); | ||
| 252 | iounmap(arc_ps2->addr); | ||
| 253 | release_mem_region(arc_ps2->iomem_res->start, | ||
| 254 | resource_size(arc_ps2->iomem_res)); | ||
| 255 | |||
| 256 | dev_dbg(&pdev->dev, "interrupt count = %i\n", arc_ps2->total_int); | ||
| 257 | dev_dbg(&pdev->dev, "frame error count = %i\n", arc_ps2->frame_error); | ||
| 258 | dev_dbg(&pdev->dev, "buffer overflow count = %i\n", | ||
| 259 | arc_ps2->buf_overflow); | ||
| 260 | |||
| 261 | kfree(arc_ps2); | ||
| 262 | |||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 266 | static struct platform_driver arc_ps2_driver = { | ||
| 267 | .driver = { | ||
| 268 | .name = "arc_ps2", | ||
| 269 | .owner = THIS_MODULE, | ||
| 270 | }, | ||
| 271 | .probe = arc_ps2_probe, | ||
| 272 | .remove = __devexit_p(arc_ps2_remove), | ||
| 273 | }; | ||
| 274 | |||
| 275 | module_platform_driver(arc_ps2_driver); | ||
| 276 | |||
| 277 | MODULE_LICENSE("GPL"); | ||
| 278 | MODULE_AUTHOR("Pavel Sokolov <psokolov@synopsys.com>"); | ||
| 279 | MODULE_DESCRIPTION("ARC PS/2 Driver"); | ||
