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