Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (c) 2000-2001 Vojtech Pavlik |
| 3 | * Copyright (c) 2002 Russell King |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | * Should you need to contact me, the author, you can do so either by |
| 26 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 27 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 28 | */ |
| 29 | |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/serio.h> |
| 34 | #include <linux/err.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 35 | #include <linux/platform_device.h> |
Russell King | 9973022 | 2009-03-25 10:21:35 +0000 | [diff] [blame] | 36 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 39 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/hardware/iomd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | MODULE_AUTHOR("Vojtech Pavlik, Russell King"); |
| 43 | MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver"); |
| 44 | MODULE_LICENSE("GPL"); |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 45 | MODULE_ALIAS("platform:kart"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 47 | struct rpckbd_data { |
| 48 | int tx_irq; |
| 49 | int rx_irq; |
| 50 | }; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int rpckbd_write(struct serio *port, unsigned char val) |
| 53 | { |
| 54 | while (!(iomd_readb(IOMD_KCTRL) & (1 << 7))) |
| 55 | cpu_relax(); |
| 56 | |
| 57 | iomd_writeb(val, IOMD_KARTTX); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 62 | static irqreturn_t rpckbd_rx(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | struct serio *port = dev_id; |
| 65 | unsigned int byte; |
| 66 | int handled = IRQ_NONE; |
| 67 | |
| 68 | while (iomd_readb(IOMD_KCTRL) & (1 << 5)) { |
| 69 | byte = iomd_readb(IOMD_KARTRX); |
| 70 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 71 | serio_interrupt(port, byte, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | handled = IRQ_HANDLED; |
| 73 | } |
| 74 | return handled; |
| 75 | } |
| 76 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 77 | static irqreturn_t rpckbd_tx(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | return IRQ_HANDLED; |
| 80 | } |
| 81 | |
| 82 | static int rpckbd_open(struct serio *port) |
| 83 | { |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 84 | struct rpckbd_data *rpckbd = port->port_data; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* Reset the keyboard state machine. */ |
| 87 | iomd_writeb(0, IOMD_KCTRL); |
| 88 | iomd_writeb(8, IOMD_KCTRL); |
| 89 | iomd_readb(IOMD_KARTRX); |
| 90 | |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 91 | if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n"); |
| 93 | return -EBUSY; |
| 94 | } |
| 95 | |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 96 | if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n"); |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 98 | free_irq(rpckbd->rx_irq, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return -EBUSY; |
| 100 | } |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static void rpckbd_close(struct serio *port) |
| 106 | { |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 107 | struct rpckbd_data *rpckbd = port->port_data; |
| 108 | |
| 109 | free_irq(rpckbd->rx_irq, port); |
| 110 | free_irq(rpckbd->tx_irq, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Allocate and initialize serio structure for subsequent registration |
| 115 | * with serio core. |
| 116 | */ |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 117 | static int rpckbd_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 119 | struct rpckbd_data *rpckbd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | struct serio *serio; |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 121 | int tx_irq, rx_irq; |
| 122 | |
| 123 | rx_irq = platform_get_irq(dev, 0); |
| 124 | if (rx_irq <= 0) |
| 125 | return rx_irq < 0 ? rx_irq : -ENXIO; |
| 126 | |
| 127 | tx_irq = platform_get_irq(dev, 1); |
| 128 | if (tx_irq <= 0) |
| 129 | return tx_irq < 0 ? tx_irq : -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 131 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 132 | rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL); |
| 133 | if (!serio || !rpckbd) { |
| 134 | kfree(rpckbd); |
| 135 | kfree(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return -ENOMEM; |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | rpckbd->rx_irq = rx_irq; |
| 140 | rpckbd->tx_irq = tx_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | serio->id.type = SERIO_8042; |
| 143 | serio->write = rpckbd_write; |
| 144 | serio->open = rpckbd_open; |
| 145 | serio->close = rpckbd_close; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 146 | serio->dev.parent = &dev->dev; |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 147 | serio->port_data = rpckbd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name)); |
| 149 | strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys)); |
| 150 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 151 | platform_set_drvdata(dev, serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | serio_register_port(serio); |
| 153 | return 0; |
| 154 | } |
| 155 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 156 | static int rpckbd_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 158 | struct serio *serio = platform_get_drvdata(dev); |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 159 | struct rpckbd_data *rpckbd = serio->port_data; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | serio_unregister_port(serio); |
Russell King | 8c6d9d0 | 2012-03-01 15:47:10 +0000 | [diff] [blame] | 162 | kfree(rpckbd); |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 167 | static struct platform_driver rpckbd_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | .probe = rpckbd_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 169 | .remove = rpckbd_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 170 | .driver = { |
| 171 | .name = "kart", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 172 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 173 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
JJ Ding | 24d2469 | 2011-11-29 11:08:43 -0800 | [diff] [blame] | 175 | module_platform_driver(rpckbd_driver); |