rpckbd.c revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2
1/* 2 * $Id: rpckbd.c,v 1.7 2001/09/25 10:12:07 vojtech Exp $ 3 * 4 * Copyright (c) 2000-2001 Vojtech Pavlik 5 * Copyright (c) 2002 Russell King 6 */ 7 8/* 9 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM 10 */ 11 12/* 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 * 27 * Should you need to contact me, the author, you can do so either by 28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 30 */ 31 32#include <linux/module.h> 33#include <linux/interrupt.h> 34#include <linux/init.h> 35#include <linux/serio.h> 36#include <linux/err.h> 37 38#include <asm/irq.h> 39#include <asm/hardware.h> 40#include <asm/io.h> 41#include <asm/hardware/iomd.h> 42#include <asm/system.h> 43 44MODULE_AUTHOR("Vojtech Pavlik, Russell King"); 45MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver"); 46MODULE_LICENSE("GPL"); 47 48static int rpckbd_write(struct serio *port, unsigned char val) 49{ 50 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7))) 51 cpu_relax(); 52 53 iomd_writeb(val, IOMD_KARTTX); 54 55 return 0; 56} 57 58static irqreturn_t rpckbd_rx(int irq, void *dev_id, struct pt_regs *regs) 59{ 60 struct serio *port = dev_id; 61 unsigned int byte; 62 int handled = IRQ_NONE; 63 64 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) { 65 byte = iomd_readb(IOMD_KARTRX); 66 67 serio_interrupt(port, byte, 0, regs); 68 handled = IRQ_HANDLED; 69 } 70 return handled; 71} 72 73static irqreturn_t rpckbd_tx(int irq, void *dev_id, struct pt_regs *regs) 74{ 75 return IRQ_HANDLED; 76} 77 78static int rpckbd_open(struct serio *port) 79{ 80 /* Reset the keyboard state machine. */ 81 iomd_writeb(0, IOMD_KCTRL); 82 iomd_writeb(8, IOMD_KCTRL); 83 iomd_readb(IOMD_KARTRX); 84 85 if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) { 86 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n"); 87 return -EBUSY; 88 } 89 90 if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) { 91 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n"); 92 free_irq(IRQ_KEYBOARDRX, NULL); 93 return -EBUSY; 94 } 95 96 return 0; 97} 98 99static void rpckbd_close(struct serio *port) 100{ 101 free_irq(IRQ_KEYBOARDRX, port); 102 free_irq(IRQ_KEYBOARDTX, port); 103} 104 105/* 106 * Allocate and initialize serio structure for subsequent registration 107 * with serio core. 108 */ 109static int __devinit rpckbd_probe(struct device *dev) 110{ 111 struct serio *serio; 112 113 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 114 if (!serio) 115 return -ENOMEM; 116 117 memset(serio, 0, sizeof(struct serio)); 118 serio->id.type = SERIO_8042; 119 serio->write = rpckbd_write; 120 serio->open = rpckbd_open; 121 serio->close = rpckbd_close; 122 serio->dev.parent = dev; 123 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name)); 124 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys)); 125 126 dev_set_drvdata(dev, serio); 127 serio_register_port(serio); 128 return 0; 129} 130 131static int __devexit rpckbd_remove(struct device *dev) 132{ 133 struct serio *serio = dev_get_drvdata(dev); 134 serio_unregister_port(serio); 135 return 0; 136} 137 138static struct device_driver rpckbd_driver = { 139 .name = "kart", 140 .bus = &platform_bus_type, 141 .probe = rpckbd_probe, 142 .remove = __devexit_p(rpckbd_remove), 143}; 144 145static int __init rpckbd_init(void) 146{ 147 return driver_register(&rpckbd_driver); 148} 149 150static void __exit rpckbd_exit(void) 151{ 152 driver_unregister(&rpckbd_driver); 153} 154 155module_init(rpckbd_init); 156module_exit(rpckbd_exit); 157