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