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