Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Copyright (c) 2000-2001 Vojtech Pavlik
  4 *  Copyright (c) 2002 Russell King
  5 */
  6
  7/*
  8 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
  9 */
 10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 11#include <linux/module.h>
 12#include <linux/interrupt.h>
 
 13#include <linux/serio.h>
 14#include <linux/err.h>
 15#include <linux/platform_device.h>
 16#include <linux/io.h>
 17#include <linux/slab.h>
 18
 
 19#include <mach/hardware.h>
 20#include <asm/hardware/iomd.h>
 
 21
 22MODULE_AUTHOR("Vojtech Pavlik, Russell King");
 23MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
 24MODULE_LICENSE("GPL");
 25MODULE_ALIAS("platform:kart");
 26
 27struct rpckbd_data {
 28	int tx_irq;
 29	int rx_irq;
 30};
 31
 32static int rpckbd_write(struct serio *port, unsigned char val)
 33{
 34	while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
 35		cpu_relax();
 36
 37	iomd_writeb(val, IOMD_KARTTX);
 38
 39	return 0;
 40}
 41
 42static irqreturn_t rpckbd_rx(int irq, void *dev_id)
 43{
 44	struct serio *port = dev_id;
 45	unsigned int byte;
 46	int handled = IRQ_NONE;
 47
 48	while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
 49		byte = iomd_readb(IOMD_KARTRX);
 50
 51		serio_interrupt(port, byte, 0);
 52		handled = IRQ_HANDLED;
 53	}
 54	return handled;
 55}
 56
 57static irqreturn_t rpckbd_tx(int irq, void *dev_id)
 58{
 59	return IRQ_HANDLED;
 60}
 61
 62static int rpckbd_open(struct serio *port)
 63{
 64	struct rpckbd_data *rpckbd = port->port_data;
 65
 66	/* Reset the keyboard state machine. */
 67	iomd_writeb(0, IOMD_KCTRL);
 68	iomd_writeb(8, IOMD_KCTRL);
 69	iomd_readb(IOMD_KARTRX);
 70
 71	if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) {
 72		printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
 73		return -EBUSY;
 74	}
 75
 76	if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) {
 77		printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
 78		free_irq(rpckbd->rx_irq, port);
 79		return -EBUSY;
 80	}
 81
 82	return 0;
 83}
 84
 85static void rpckbd_close(struct serio *port)
 86{
 87	struct rpckbd_data *rpckbd = port->port_data;
 88
 89	free_irq(rpckbd->rx_irq, port);
 90	free_irq(rpckbd->tx_irq, port);
 91}
 92
 93/*
 94 * Allocate and initialize serio structure for subsequent registration
 95 * with serio core.
 96 */
 97static int rpckbd_probe(struct platform_device *dev)
 98{
 99	struct rpckbd_data *rpckbd;
100	struct serio *serio;
101	int tx_irq, rx_irq;
102
103	rx_irq = platform_get_irq(dev, 0);
104	if (rx_irq <= 0)
105		return rx_irq < 0 ? rx_irq : -ENXIO;
106
107	tx_irq = platform_get_irq(dev, 1);
108	if (tx_irq <= 0)
109		return tx_irq < 0 ? tx_irq : -ENXIO;
110
111	serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
112	rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL);
113	if (!serio || !rpckbd) {
114		kfree(rpckbd);
115		kfree(serio);
116		return -ENOMEM;
117	}
118
119	rpckbd->rx_irq = rx_irq;
120	rpckbd->tx_irq = tx_irq;
121
122	serio->id.type		= SERIO_8042;
123	serio->write		= rpckbd_write;
124	serio->open		= rpckbd_open;
125	serio->close		= rpckbd_close;
126	serio->dev.parent	= &dev->dev;
127	serio->port_data	= rpckbd;
128	strscpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
129	strscpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
130
131	platform_set_drvdata(dev, serio);
132	serio_register_port(serio);
133	return 0;
134}
135
136static int rpckbd_remove(struct platform_device *dev)
137{
138	struct serio *serio = platform_get_drvdata(dev);
139	struct rpckbd_data *rpckbd = serio->port_data;
140
141	serio_unregister_port(serio);
142	kfree(rpckbd);
143
144	return 0;
145}
146
147static struct platform_driver rpckbd_driver = {
148	.probe		= rpckbd_probe,
149	.remove		= rpckbd_remove,
150	.driver		= {
151		.name	= "kart",
 
152	},
153};
154module_platform_driver(rpckbd_driver);
 
 
 
 
 
 
 
 
 
 
 
 
v3.1
 
  1/*
  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>
 35#include <linux/platform_device.h>
 36#include <linux/io.h>
 37#include <linux/slab.h>
 38
 39#include <asm/irq.h>
 40#include <mach/hardware.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");
 47MODULE_ALIAS("platform:kart");
 48
 
 
 
 
 
 49static int rpckbd_write(struct serio *port, unsigned char val)
 50{
 51	while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
 52		cpu_relax();
 53
 54	iomd_writeb(val, IOMD_KARTTX);
 55
 56	return 0;
 57}
 58
 59static irqreturn_t rpckbd_rx(int irq, void *dev_id)
 60{
 61	struct serio *port = dev_id;
 62	unsigned int byte;
 63	int handled = IRQ_NONE;
 64
 65	while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
 66		byte = iomd_readb(IOMD_KARTRX);
 67
 68		serio_interrupt(port, byte, 0);
 69		handled = IRQ_HANDLED;
 70	}
 71	return handled;
 72}
 73
 74static irqreturn_t rpckbd_tx(int irq, void *dev_id)
 75{
 76	return IRQ_HANDLED;
 77}
 78
 79static int rpckbd_open(struct serio *port)
 80{
 
 
 81	/* Reset the keyboard state machine. */
 82	iomd_writeb(0, IOMD_KCTRL);
 83	iomd_writeb(8, IOMD_KCTRL);
 84	iomd_readb(IOMD_KARTRX);
 85
 86	if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
 87		printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
 88		return -EBUSY;
 89	}
 90
 91	if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
 92		printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
 93		free_irq(IRQ_KEYBOARDRX, port);
 94		return -EBUSY;
 95	}
 96
 97	return 0;
 98}
 99
100static void rpckbd_close(struct serio *port)
101{
102	free_irq(IRQ_KEYBOARDRX, port);
103	free_irq(IRQ_KEYBOARDTX, port);
 
 
104}
105
106/*
107 * Allocate and initialize serio structure for subsequent registration
108 * with serio core.
109 */
110static int __devinit rpckbd_probe(struct platform_device *dev)
111{
 
112	struct serio *serio;
 
 
 
 
 
 
 
 
 
113
114	serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
115	if (!serio)
 
 
 
116		return -ENOMEM;
 
 
 
 
117
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->dev;
123	strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
124	strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
 
125
126	platform_set_drvdata(dev, serio);
127	serio_register_port(serio);
128	return 0;
129}
130
131static int __devexit rpckbd_remove(struct platform_device *dev)
132{
133	struct serio *serio = platform_get_drvdata(dev);
 
 
134	serio_unregister_port(serio);
 
 
135	return 0;
136}
137
138static struct platform_driver rpckbd_driver = {
139	.probe		= rpckbd_probe,
140	.remove		= __devexit_p(rpckbd_remove),
141	.driver		= {
142		.name	= "kart",
143		.owner	= THIS_MODULE,
144	},
145};
146
147static int __init rpckbd_init(void)
148{
149	return platform_driver_register(&rpckbd_driver);
150}
151
152static void __exit rpckbd_exit(void)
153{
154	platform_driver_unregister(&rpckbd_driver);
155}
156
157module_init(rpckbd_init);
158module_exit(rpckbd_exit);