| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 1 | /* | 
 | 2 |  * Xilinx XPS PS/2 device driver | 
 | 3 |  * | 
 | 4 |  * (c) 2005 MontaVista Software, Inc. | 
 | 5 |  * (c) 2008 Xilinx, Inc. | 
 | 6 |  * | 
 | 7 |  * This program is free software; you can redistribute it and/or modify it | 
 | 8 |  * under the terms of the GNU General Public License as published by the | 
 | 9 |  * Free Software Foundation; either version 2 of the License, or (at your | 
 | 10 |  * option) any later version. | 
 | 11 |  * | 
 | 12 |  * You should have received a copy of the GNU General Public License along | 
 | 13 |  * with this program; if not, write to the Free Software Foundation, Inc., | 
 | 14 |  * 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 |  | 
 | 18 | #include <linux/module.h> | 
 | 19 | #include <linux/serio.h> | 
 | 20 | #include <linux/interrupt.h> | 
 | 21 | #include <linux/errno.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 23 | #include <linux/init.h> | 
 | 24 | #include <linux/list.h> | 
 | 25 | #include <linux/io.h> | 
 | 26 |  | 
 | 27 | #include <linux/of_device.h> | 
 | 28 | #include <linux/of_platform.h> | 
 | 29 |  | 
 | 30 | #define DRIVER_NAME		"xilinx_ps2" | 
 | 31 |  | 
 | 32 | /* Register offsets for the xps2 device */ | 
 | 33 | #define XPS2_SRST_OFFSET	0x00000000 /* Software Reset register */ | 
 | 34 | #define XPS2_STATUS_OFFSET	0x00000004 /* Status register */ | 
 | 35 | #define XPS2_RX_DATA_OFFSET	0x00000008 /* Receive Data register */ | 
 | 36 | #define XPS2_TX_DATA_OFFSET	0x0000000C /* Transmit Data register */ | 
 | 37 | #define XPS2_GIER_OFFSET	0x0000002C /* Global Interrupt Enable reg */ | 
 | 38 | #define XPS2_IPISR_OFFSET	0x00000030 /* Interrupt Status register */ | 
 | 39 | #define XPS2_IPIER_OFFSET	0x00000038 /* Interrupt Enable register */ | 
 | 40 |  | 
 | 41 | /* Reset Register Bit Definitions */ | 
 | 42 | #define XPS2_SRST_RESET		0x0000000A /* Software Reset  */ | 
 | 43 |  | 
 | 44 | /* Status Register Bit Positions */ | 
 | 45 | #define XPS2_STATUS_RX_FULL	0x00000001 /* Receive Full  */ | 
 | 46 | #define XPS2_STATUS_TX_FULL	0x00000002 /* Transmit Full  */ | 
 | 47 |  | 
 | 48 | /* Bit definitions for ISR/IER registers. Both the registers have the same bit | 
 | 49 |  * definitions and are only defined once. */ | 
 | 50 | #define XPS2_IPIXR_WDT_TOUT	0x00000001 /* Watchdog Timeout Interrupt */ | 
 | 51 | #define XPS2_IPIXR_TX_NOACK	0x00000002 /* Transmit No ACK Interrupt */ | 
 | 52 | #define XPS2_IPIXR_TX_ACK	0x00000004 /* Transmit ACK (Data) Interrupt */ | 
 | 53 | #define XPS2_IPIXR_RX_OVF	0x00000008 /* Receive Overflow Interrupt */ | 
 | 54 | #define XPS2_IPIXR_RX_ERR	0x00000010 /* Receive Error Interrupt */ | 
 | 55 | #define XPS2_IPIXR_RX_FULL	0x00000020 /* Receive Data Interrupt */ | 
 | 56 |  | 
 | 57 | /* Mask for all the Transmit Interrupts */ | 
 | 58 | #define XPS2_IPIXR_TX_ALL	(XPS2_IPIXR_TX_NOACK | XPS2_IPIXR_TX_ACK) | 
 | 59 |  | 
 | 60 | /* Mask for all the Receive Interrupts */ | 
 | 61 | #define XPS2_IPIXR_RX_ALL	(XPS2_IPIXR_RX_OVF | XPS2_IPIXR_RX_ERR |  \ | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 62 | 				 XPS2_IPIXR_RX_FULL) | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 63 |  | 
 | 64 | /* Mask for all the Interrupts */ | 
 | 65 | #define XPS2_IPIXR_ALL		(XPS2_IPIXR_TX_ALL | XPS2_IPIXR_RX_ALL |  \ | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 66 | 				 XPS2_IPIXR_WDT_TOUT) | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 67 |  | 
 | 68 | /* Global Interrupt Enable mask */ | 
 | 69 | #define XPS2_GIER_GIE_MASK	0x80000000 | 
 | 70 |  | 
 | 71 | struct xps2data { | 
 | 72 | 	int irq; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 73 | 	spinlock_t lock; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 74 | 	void __iomem *base_address;	/* virt. address of control registers */ | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 75 | 	unsigned int flags; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 76 | 	struct serio serio;		/* serio */ | 
 | 77 | }; | 
 | 78 |  | 
 | 79 | /************************************/ | 
 | 80 | /* XPS PS/2 data transmission calls */ | 
 | 81 | /************************************/ | 
 | 82 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 83 | /** | 
 | 84 |  * xps2_recv() - attempts to receive a byte from the PS/2 port. | 
 | 85 |  * @drvdata:	pointer to ps2 device private data structure | 
 | 86 |  * @byte:	address where the read data will be copied | 
 | 87 |  * | 
 | 88 |  * If there is any data available in the PS/2 receiver, this functions reads | 
 | 89 |  * the data, otherwise it returns error. | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 90 |  */ | 
 | 91 | static int xps2_recv(struct xps2data *drvdata, u8 *byte) | 
 | 92 | { | 
 | 93 | 	u32 sr; | 
 | 94 | 	int status = -1; | 
 | 95 |  | 
 | 96 | 	/* If there is data available in the PS/2 receiver, read it */ | 
 | 97 | 	sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET); | 
 | 98 | 	if (sr & XPS2_STATUS_RX_FULL) { | 
 | 99 | 		*byte = in_be32(drvdata->base_address + XPS2_RX_DATA_OFFSET); | 
 | 100 | 		status = 0; | 
 | 101 | 	} | 
 | 102 |  | 
 | 103 | 	return status; | 
 | 104 | } | 
 | 105 |  | 
 | 106 | /*********************/ | 
 | 107 | /* Interrupt handler */ | 
 | 108 | /*********************/ | 
 | 109 | static irqreturn_t xps2_interrupt(int irq, void *dev_id) | 
 | 110 | { | 
 | 111 | 	struct xps2data *drvdata = dev_id; | 
 | 112 | 	u32 intr_sr; | 
 | 113 | 	u8 c; | 
 | 114 | 	int status; | 
 | 115 |  | 
 | 116 | 	/* Get the PS/2 interrupts and clear them */ | 
 | 117 | 	intr_sr = in_be32(drvdata->base_address + XPS2_IPISR_OFFSET); | 
 | 118 | 	out_be32(drvdata->base_address + XPS2_IPISR_OFFSET, intr_sr); | 
 | 119 |  | 
 | 120 | 	/* Check which interrupt is active */ | 
 | 121 | 	if (intr_sr & XPS2_IPIXR_RX_OVF) | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 122 | 		dev_warn(drvdata->serio.dev.parent, "receive overrun error\n"); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 123 |  | 
 | 124 | 	if (intr_sr & XPS2_IPIXR_RX_ERR) | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 125 | 		drvdata->flags |= SERIO_PARITY; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 126 |  | 
 | 127 | 	if (intr_sr & (XPS2_IPIXR_TX_NOACK | XPS2_IPIXR_WDT_TOUT)) | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 128 | 		drvdata->flags |= SERIO_TIMEOUT; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 129 |  | 
 | 130 | 	if (intr_sr & XPS2_IPIXR_RX_FULL) { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 131 | 		status = xps2_recv(drvdata, &c); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 132 |  | 
 | 133 | 		/* Error, if a byte is not received */ | 
 | 134 | 		if (status) { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 135 | 			dev_err(drvdata->serio.dev.parent, | 
 | 136 | 				"wrong rcvd byte count (%d)\n", status); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 137 | 		} else { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 138 | 			serio_interrupt(&drvdata->serio, c, drvdata->flags); | 
 | 139 | 			drvdata->flags = 0; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 140 | 		} | 
 | 141 | 	} | 
 | 142 |  | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 143 | 	return IRQ_HANDLED; | 
 | 144 | } | 
 | 145 |  | 
 | 146 | /*******************/ | 
 | 147 | /* serio callbacks */ | 
 | 148 | /*******************/ | 
 | 149 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 150 | /** | 
 | 151 |  * sxps2_write() - sends a byte out through the PS/2 port. | 
 | 152 |  * @pserio:	pointer to the serio structure of the PS/2 port | 
 | 153 |  * @c:		data that needs to be written to the PS/2 port | 
 | 154 |  * | 
 | 155 |  * This function checks if the PS/2 transmitter is empty and sends a byte. | 
 | 156 |  * Otherwise it returns error. Transmission fails only when nothing is connected | 
 | 157 |  * to the PS/2 port. Thats why, we do not try to resend the data in case of a | 
 | 158 |  * failure. | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 159 |  */ | 
 | 160 | static int sxps2_write(struct serio *pserio, unsigned char c) | 
 | 161 | { | 
 | 162 | 	struct xps2data *drvdata = pserio->port_data; | 
 | 163 | 	unsigned long flags; | 
 | 164 | 	u32 sr; | 
 | 165 | 	int status = -1; | 
 | 166 |  | 
 | 167 | 	spin_lock_irqsave(&drvdata->lock, flags); | 
 | 168 |  | 
 | 169 | 	/* If the PS/2 transmitter is empty send a byte of data */ | 
 | 170 | 	sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET); | 
 | 171 | 	if (!(sr & XPS2_STATUS_TX_FULL)) { | 
 | 172 | 		out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); | 
 | 173 | 		status = 0; | 
 | 174 | 	} | 
 | 175 |  | 
 | 176 | 	spin_unlock_irqrestore(&drvdata->lock, flags); | 
 | 177 |  | 
 | 178 | 	return status; | 
 | 179 | } | 
 | 180 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 181 | /** | 
 | 182 |  * sxps2_open() - called when a port is opened by the higher layer. | 
 | 183 |  * @pserio:	pointer to the serio structure of the PS/2 device | 
 | 184 |  * | 
 | 185 |  * This function requests irq and enables interrupts for the PS/2 device. | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 186 |  */ | 
 | 187 | static int sxps2_open(struct serio *pserio) | 
 | 188 | { | 
 | 189 | 	struct xps2data *drvdata = pserio->port_data; | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 190 | 	int error; | 
 | 191 | 	u8 c; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 192 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 193 | 	error = request_irq(drvdata->irq, &xps2_interrupt, 0, | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 194 | 				DRIVER_NAME, drvdata); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 195 | 	if (error) { | 
 | 196 | 		dev_err(drvdata->serio.dev.parent, | 
 | 197 | 			"Couldn't allocate interrupt %d\n", drvdata->irq); | 
 | 198 | 		return error; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 199 | 	} | 
 | 200 |  | 
 | 201 | 	/* start reception by enabling the interrupts */ | 
 | 202 | 	out_be32(drvdata->base_address + XPS2_GIER_OFFSET, XPS2_GIER_GIE_MASK); | 
 | 203 | 	out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, XPS2_IPIXR_RX_ALL); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 204 | 	(void)xps2_recv(drvdata, &c); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 205 |  | 
 | 206 | 	return 0;		/* success */ | 
 | 207 | } | 
 | 208 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 209 | /** | 
 | 210 |  * sxps2_close() - frees the interrupt. | 
 | 211 |  * @pserio:	pointer to the serio structure of the PS/2 device | 
 | 212 |  * | 
 | 213 |  * This function frees the irq and disables interrupts for the PS/2 device. | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 214 |  */ | 
 | 215 | static void sxps2_close(struct serio *pserio) | 
 | 216 | { | 
 | 217 | 	struct xps2data *drvdata = pserio->port_data; | 
 | 218 |  | 
 | 219 | 	/* Disable the PS2 interrupts */ | 
 | 220 | 	out_be32(drvdata->base_address + XPS2_GIER_OFFSET, 0x00); | 
 | 221 | 	out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, 0x00); | 
 | 222 | 	free_irq(drvdata->irq, drvdata); | 
 | 223 | } | 
 | 224 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 225 | /** | 
 | 226 |  * xps2_of_probe - probe method for the PS/2 device. | 
 | 227 |  * @of_dev:	pointer to OF device structure | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 228 |  * @match:	pointer to the structure used for matching a device | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 229 |  * | 
 | 230 |  * This function probes the PS/2 device in the device tree. | 
 | 231 |  * It initializes the driver data structure and the hardware. | 
 | 232 |  * It returns 0, if the driver is bound to the PS/2 device, or a negative | 
 | 233 |  * value if there is an error. | 
 | 234 |  */ | 
| Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 235 | static int __devinit xps2_of_probe(struct platform_device *ofdev) | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 236 | { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 237 | 	struct resource r_irq; /* Interrupt resources */ | 
 | 238 | 	struct resource r_mem; /* IO mem resources */ | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 239 | 	struct xps2data *drvdata; | 
 | 240 | 	struct serio *serio; | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 241 | 	struct device *dev = &ofdev->dev; | 
 | 242 | 	resource_size_t remap_size, phys_addr; | 
 | 243 | 	int error; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 244 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 245 | 	dev_info(dev, "Device Tree Probing \'%s\'\n", | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 246 | 			ofdev->dev.of_node->name); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 247 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 248 | 	/* Get iospace for the device */ | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 249 | 	error = of_address_to_resource(ofdev->dev.of_node, 0, &r_mem); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 250 | 	if (error) { | 
 | 251 | 		dev_err(dev, "invalid address\n"); | 
 | 252 | 		return error; | 
 | 253 | 	} | 
 | 254 |  | 
 | 255 | 	/* Get IRQ for the device */ | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 256 | 	if (of_irq_to_resource(ofdev->dev.of_node, 0, &r_irq) == NO_IRQ) { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 257 | 		dev_err(dev, "no IRQ found\n"); | 
 | 258 | 		return -ENODEV; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 259 | 	} | 
 | 260 |  | 
 | 261 | 	drvdata = kzalloc(sizeof(struct xps2data), GFP_KERNEL); | 
 | 262 | 	if (!drvdata) { | 
 | 263 | 		dev_err(dev, "Couldn't allocate device private record\n"); | 
 | 264 | 		return -ENOMEM; | 
 | 265 | 	} | 
 | 266 |  | 
 | 267 | 	dev_set_drvdata(dev, drvdata); | 
 | 268 |  | 
 | 269 | 	spin_lock_init(&drvdata->lock); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 270 | 	drvdata->irq = r_irq.start; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 271 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 272 | 	phys_addr = r_mem.start; | 
| Tobias Klauser | ce841b9 | 2010-01-21 23:52:37 -0800 | [diff] [blame] | 273 | 	remap_size = resource_size(&r_mem); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 274 | 	if (!request_mem_region(phys_addr, remap_size, DRIVER_NAME)) { | 
 | 275 | 		dev_err(dev, "Couldn't lock memory region at 0x%08llX\n", | 
 | 276 | 			(unsigned long long)phys_addr); | 
 | 277 | 		error = -EBUSY; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 278 | 		goto failed1; | 
 | 279 | 	} | 
 | 280 |  | 
 | 281 | 	/* Fill in configuration data and add them to the list */ | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 282 | 	drvdata->base_address = ioremap(phys_addr, remap_size); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 283 | 	if (drvdata->base_address == NULL) { | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 284 | 		dev_err(dev, "Couldn't ioremap memory at 0x%08llX\n", | 
 | 285 | 			(unsigned long long)phys_addr); | 
 | 286 | 		error = -EFAULT; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 287 | 		goto failed2; | 
 | 288 | 	} | 
 | 289 |  | 
 | 290 | 	/* Disable all the interrupts, just in case */ | 
 | 291 | 	out_be32(drvdata->base_address + XPS2_IPIER_OFFSET, 0); | 
 | 292 |  | 
 | 293 | 	/* Reset the PS2 device and abort any current transaction, to make sure | 
 | 294 | 	 * we have the PS2 in a good state */ | 
 | 295 | 	out_be32(drvdata->base_address + XPS2_SRST_OFFSET, XPS2_SRST_RESET); | 
 | 296 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 297 | 	dev_info(dev, "Xilinx PS2 at 0x%08llX mapped to 0x%p, irq=%d\n", | 
 | 298 | 		 (unsigned long long)phys_addr, drvdata->base_address, | 
 | 299 | 		 drvdata->irq); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 300 |  | 
 | 301 | 	serio = &drvdata->serio; | 
 | 302 | 	serio->id.type = SERIO_8042; | 
 | 303 | 	serio->write = sxps2_write; | 
 | 304 | 	serio->open = sxps2_open; | 
 | 305 | 	serio->close = sxps2_close; | 
 | 306 | 	serio->port_data = drvdata; | 
 | 307 | 	serio->dev.parent = dev; | 
 | 308 | 	snprintf(serio->name, sizeof(serio->name), | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 309 | 		 "Xilinx XPS PS/2 at %08llX", (unsigned long long)phys_addr); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 310 | 	snprintf(serio->phys, sizeof(serio->phys), | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 311 | 		 "xilinxps2/serio at %08llX", (unsigned long long)phys_addr); | 
 | 312 |  | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 313 | 	serio_register_port(serio); | 
 | 314 |  | 
 | 315 | 	return 0;		/* success */ | 
 | 316 |  | 
 | 317 | failed2: | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 318 | 	release_mem_region(phys_addr, remap_size); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 319 | failed1: | 
 | 320 | 	kfree(drvdata); | 
 | 321 | 	dev_set_drvdata(dev, NULL); | 
 | 322 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 323 | 	return error; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 324 | } | 
 | 325 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 326 | /** | 
 | 327 |  * xps2_of_remove - unbinds the driver from the PS/2 device. | 
 | 328 |  * @of_dev:	pointer to OF device structure | 
 | 329 |  * | 
 | 330 |  * This function is called if a device is physically removed from the system or | 
 | 331 |  * if the driver module is being unloaded. It frees any resources allocated to | 
 | 332 |  * the device. | 
 | 333 |  */ | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 334 | static int __devexit xps2_of_remove(struct platform_device *of_dev) | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 335 | { | 
 | 336 | 	struct device *dev = &of_dev->dev; | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 337 | 	struct xps2data *drvdata = dev_get_drvdata(dev); | 
 | 338 | 	struct resource r_mem; /* IO mem resources */ | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 339 |  | 
 | 340 | 	serio_unregister_port(&drvdata->serio); | 
 | 341 | 	iounmap(drvdata->base_address); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 342 |  | 
 | 343 | 	/* Get iospace of the device */ | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 344 | 	if (of_address_to_resource(of_dev->dev.of_node, 0, &r_mem)) | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 345 | 		dev_err(dev, "invalid address\n"); | 
 | 346 | 	else | 
| Tobias Klauser | ce841b9 | 2010-01-21 23:52:37 -0800 | [diff] [blame] | 347 | 		release_mem_region(r_mem.start, resource_size(&r_mem)); | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 348 |  | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 349 | 	kfree(drvdata); | 
 | 350 |  | 
 | 351 | 	dev_set_drvdata(dev, NULL); | 
 | 352 |  | 
| John Linn | b4a3ac9 | 2008-10-27 22:17:22 -0400 | [diff] [blame] | 353 | 	return 0; | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 354 | } | 
 | 355 |  | 
 | 356 | /* Match table for of_platform binding */ | 
| Márton Németh | ef9a16f | 2010-01-09 23:23:02 -0800 | [diff] [blame] | 357 | static const struct of_device_id xps2_of_match[] __devinitconst = { | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 358 | 	{ .compatible = "xlnx,xps-ps2-1.00.a", }, | 
 | 359 | 	{ /* end of list */ }, | 
 | 360 | }; | 
 | 361 | MODULE_DEVICE_TABLE(of, xps2_of_match); | 
 | 362 |  | 
| Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 363 | static struct platform_driver xps2_of_driver = { | 
| Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 364 | 	.driver = { | 
 | 365 | 		.name = DRIVER_NAME, | 
 | 366 | 		.owner = THIS_MODULE, | 
 | 367 | 		.of_match_table = xps2_of_match, | 
 | 368 | 	}, | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 369 | 	.probe		= xps2_of_probe, | 
 | 370 | 	.remove		= __devexit_p(xps2_of_remove), | 
 | 371 | }; | 
 | 372 |  | 
 | 373 | static int __init xps2_init(void) | 
 | 374 | { | 
| Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 375 | 	return platform_driver_register(&xps2_of_driver); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 376 | } | 
 | 377 |  | 
 | 378 | static void __exit xps2_cleanup(void) | 
 | 379 | { | 
| Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 380 | 	platform_driver_unregister(&xps2_of_driver); | 
| John Linn | 1191828 | 2008-07-07 16:17:48 -0400 | [diff] [blame] | 381 | } | 
 | 382 |  | 
 | 383 | module_init(xps2_init); | 
 | 384 | module_exit(xps2_cleanup); | 
 | 385 |  | 
 | 386 | MODULE_AUTHOR("Xilinx, Inc."); | 
 | 387 | MODULE_DESCRIPTION("Xilinx XPS PS/2 driver"); | 
 | 388 | MODULE_LICENSE("GPL"); | 
 | 389 |  |