Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Xilinx SPI driver |
| 4 | * |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 5 | * Supports 8 bit SPI transfers only, with or w/o FIFO |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 6 | * |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 7 | * Based on bfin_spi.c, by way of altera_spi.c |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 8 | * Copyright (c) 2015 Jagan Teki <jteki@openedev.com> |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 9 | * Copyright (c) 2012 Stephan Linz <linz@li-pro.net> |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 10 | * Copyright (c) 2010 Graeme Smecher <graeme.smecher@mail.mcgill.ca> |
| 11 | * Copyright (c) 2010 Thomas Chou <thomas@wytron.com.tw> |
| 12 | * Copyright (c) 2005-2008 Analog Devices Inc. |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 13 | */ |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 14 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 15 | #include <config.h> |
| 16 | #include <common.h> |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 17 | #include <dm.h> |
| 18 | #include <errno.h> |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 19 | #include <malloc.h> |
| 20 | #include <spi.h> |
Jagan Teki | 41fcbba | 2015-06-27 00:51:37 +0530 | [diff] [blame] | 21 | #include <asm/io.h> |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 22 | #include <wait_bit.h> |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 23 | |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 24 | /* |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 25 | * [0]: http://www.xilinx.com/support/documentation |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 26 | * |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 27 | * Xilinx SPI Register Definitions |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 28 | * [1]: [0]/ip_documentation/xps_spi.pdf |
| 29 | * page 8, Register Descriptions |
| 30 | * [2]: [0]/ip_documentation/axi_spi_ds742.pdf |
| 31 | * page 7, Register Overview Table |
| 32 | */ |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 33 | |
| 34 | /* SPI Control Register (spicr), [1] p9, [2] p8 */ |
Jagan Teki | f0a0141 | 2015-10-23 01:39:31 +0530 | [diff] [blame] | 35 | #define SPICR_LSB_FIRST BIT(9) |
| 36 | #define SPICR_MASTER_INHIBIT BIT(8) |
| 37 | #define SPICR_MANUAL_SS BIT(7) |
| 38 | #define SPICR_RXFIFO_RESEST BIT(6) |
| 39 | #define SPICR_TXFIFO_RESEST BIT(5) |
| 40 | #define SPICR_CPHA BIT(4) |
| 41 | #define SPICR_CPOL BIT(3) |
| 42 | #define SPICR_MASTER_MODE BIT(2) |
| 43 | #define SPICR_SPE BIT(1) |
| 44 | #define SPICR_LOOP BIT(0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 45 | |
| 46 | /* SPI Status Register (spisr), [1] p11, [2] p10 */ |
Jagan Teki | f0a0141 | 2015-10-23 01:39:31 +0530 | [diff] [blame] | 47 | #define SPISR_SLAVE_MODE_SELECT BIT(5) |
| 48 | #define SPISR_MODF BIT(4) |
| 49 | #define SPISR_TX_FULL BIT(3) |
| 50 | #define SPISR_TX_EMPTY BIT(2) |
| 51 | #define SPISR_RX_FULL BIT(1) |
| 52 | #define SPISR_RX_EMPTY BIT(0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 53 | |
| 54 | /* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */ |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 55 | #define SPIDTR_8BIT_MASK GENMASK(7, 0) |
| 56 | #define SPIDTR_16BIT_MASK GENMASK(15, 0) |
| 57 | #define SPIDTR_32BIT_MASK GENMASK(31, 0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 58 | |
| 59 | /* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */ |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 60 | #define SPIDRR_8BIT_MASK GENMASK(7, 0) |
| 61 | #define SPIDRR_16BIT_MASK GENMASK(15, 0) |
| 62 | #define SPIDRR_32BIT_MASK GENMASK(31, 0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 63 | |
| 64 | /* SPI Slave Select Register (spissr), [1] p13, [2] p13 */ |
| 65 | #define SPISSR_MASK(cs) (1 << (cs)) |
| 66 | #define SPISSR_ACT(cs) ~SPISSR_MASK(cs) |
| 67 | #define SPISSR_OFF ~0UL |
| 68 | |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 69 | /* SPI Software Reset Register (ssr) */ |
| 70 | #define SPISSR_RESET_VALUE 0x0a |
| 71 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 72 | #define XILSPI_MAX_XFER_BITS 8 |
| 73 | #define XILSPI_SPICR_DFLT_ON (SPICR_MANUAL_SS | SPICR_MASTER_MODE | \ |
| 74 | SPICR_SPE) |
| 75 | #define XILSPI_SPICR_DFLT_OFF (SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS) |
| 76 | |
| 77 | #ifndef CONFIG_XILINX_SPI_IDLE_VAL |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 78 | #define CONFIG_XILINX_SPI_IDLE_VAL GENMASK(7, 0) |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 79 | #endif |
| 80 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 81 | #define XILINX_SPISR_TIMEOUT 10000 /* in milliseconds */ |
| 82 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 83 | /* xilinx spi register set */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 84 | struct xilinx_spi_regs { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 85 | u32 __space0__[7]; |
| 86 | u32 dgier; /* Device Global Interrupt Enable Register (DGIER) */ |
| 87 | u32 ipisr; /* IP Interrupt Status Register (IPISR) */ |
| 88 | u32 __space1__; |
| 89 | u32 ipier; /* IP Interrupt Enable Register (IPIER) */ |
| 90 | u32 __space2__[5]; |
| 91 | u32 srr; /* Softare Reset Register (SRR) */ |
| 92 | u32 __space3__[7]; |
| 93 | u32 spicr; /* SPI Control Register (SPICR) */ |
| 94 | u32 spisr; /* SPI Status Register (SPISR) */ |
| 95 | u32 spidtr; /* SPI Data Transmit Register (SPIDTR) */ |
| 96 | u32 spidrr; /* SPI Data Receive Register (SPIDRR) */ |
| 97 | u32 spissr; /* SPI Slave Select Register (SPISSR) */ |
| 98 | u32 spitfor; /* SPI Transmit FIFO Occupancy Register (SPITFOR) */ |
| 99 | u32 spirfor; /* SPI Receive FIFO Occupancy Register (SPIRFOR) */ |
| 100 | }; |
| 101 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 102 | /* xilinx spi priv */ |
| 103 | struct xilinx_spi_priv { |
| 104 | struct xilinx_spi_regs *regs; |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 105 | unsigned int freq; |
| 106 | unsigned int mode; |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 107 | unsigned int fifo_depth; |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 108 | }; |
| 109 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 110 | static int xilinx_spi_probe(struct udevice *bus) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 111 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 112 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 113 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 114 | |
Michal Simek | 1ba1386 | 2018-06-30 08:15:17 +0530 | [diff] [blame] | 115 | priv->regs = (struct xilinx_spi_regs *)devfdt_get_addr(bus); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 116 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 117 | priv->fifo_depth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), |
| 118 | "fifo-size", 0); |
| 119 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 120 | writel(SPISSR_RESET_VALUE, ®s->srr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 121 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 122 | return 0; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 125 | static void spi_cs_activate(struct udevice *dev, uint cs) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 126 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 127 | struct udevice *bus = dev_get_parent(dev); |
| 128 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 129 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 130 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 131 | writel(SPISSR_ACT(cs), ®s->spissr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 134 | static void spi_cs_deactivate(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 135 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 136 | struct udevice *bus = dev_get_parent(dev); |
| 137 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 138 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 139 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 140 | writel(SPISSR_OFF, ®s->spissr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 143 | static int xilinx_spi_claim_bus(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 144 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 145 | struct udevice *bus = dev_get_parent(dev); |
| 146 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 147 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 148 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 149 | writel(SPISSR_OFF, ®s->spissr); |
| 150 | writel(XILSPI_SPICR_DFLT_ON, ®s->spicr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 151 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 155 | static int xilinx_spi_release_bus(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 156 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 157 | struct udevice *bus = dev_get_parent(dev); |
| 158 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 159 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 160 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 161 | writel(SPISSR_OFF, ®s->spissr); |
| 162 | writel(XILSPI_SPICR_DFLT_OFF, ®s->spicr); |
| 163 | |
| 164 | return 0; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 167 | static u32 xilinx_spi_fill_txfifo(struct udevice *bus, const u8 *txp, |
| 168 | u32 txbytes) |
| 169 | { |
| 170 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 171 | struct xilinx_spi_regs *regs = priv->regs; |
| 172 | unsigned char d; |
| 173 | u32 i = 0; |
| 174 | |
| 175 | while (txbytes && !(readl(®s->spisr) & SPISR_TX_FULL) && |
| 176 | i < priv->fifo_depth) { |
| 177 | d = txp ? *txp++ : CONFIG_XILINX_SPI_IDLE_VAL; |
| 178 | debug("spi_xfer: tx:%x ", d); |
| 179 | /* write out and wait for processing (receive data) */ |
| 180 | writel(d & SPIDTR_8BIT_MASK, ®s->spidtr); |
| 181 | txbytes--; |
| 182 | i++; |
| 183 | } |
| 184 | |
| 185 | return i; |
| 186 | } |
| 187 | |
| 188 | static u32 xilinx_spi_read_rxfifo(struct udevice *bus, u8 *rxp, u32 rxbytes) |
| 189 | { |
| 190 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 191 | struct xilinx_spi_regs *regs = priv->regs; |
| 192 | unsigned char d; |
| 193 | unsigned int i = 0; |
| 194 | |
| 195 | while (rxbytes && !(readl(®s->spisr) & SPISR_RX_EMPTY)) { |
| 196 | d = readl(®s->spidrr) & SPIDRR_8BIT_MASK; |
| 197 | if (rxp) |
| 198 | *rxp++ = d; |
| 199 | debug("spi_xfer: rx:%x\n", d); |
| 200 | rxbytes--; |
| 201 | i++; |
| 202 | } |
| 203 | debug("Rx_done\n"); |
| 204 | |
| 205 | return i; |
| 206 | } |
| 207 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 208 | static int xilinx_spi_xfer(struct udevice *dev, unsigned int bitlen, |
| 209 | const void *dout, void *din, unsigned long flags) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 210 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 211 | struct udevice *bus = dev_get_parent(dev); |
| 212 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 213 | struct xilinx_spi_regs *regs = priv->regs; |
| 214 | struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 215 | /* assume spi core configured to do 8 bit transfers */ |
| 216 | unsigned int bytes = bitlen / XILSPI_MAX_XFER_BITS; |
| 217 | const unsigned char *txp = dout; |
| 218 | unsigned char *rxp = din; |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 219 | u32 txbytes = bytes; |
| 220 | u32 rxbytes = bytes; |
| 221 | u32 reg, count, timeout; |
| 222 | int ret; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 223 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 224 | debug("spi_xfer: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 225 | bus->seq, slave_plat->cs, bitlen, bytes, flags); |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 226 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 227 | if (bitlen == 0) |
| 228 | goto done; |
| 229 | |
| 230 | if (bitlen % XILSPI_MAX_XFER_BITS) { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 231 | printf("XILSPI warning: Not a multiple of %d bits\n", |
| 232 | XILSPI_MAX_XFER_BITS); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 233 | flags |= SPI_XFER_END; |
| 234 | goto done; |
| 235 | } |
| 236 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 237 | if (flags & SPI_XFER_BEGIN) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 238 | spi_cs_activate(dev, slave_plat->cs); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 239 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 240 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 241 | while (txbytes && rxbytes) { |
| 242 | count = xilinx_spi_fill_txfifo(bus, txp, txbytes); |
| 243 | reg = readl(®s->spicr) & ~SPICR_MASTER_INHIBIT; |
| 244 | writel(reg, ®s->spicr); |
| 245 | txbytes -= count; |
| 246 | if (txp) |
| 247 | txp += count; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 248 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 249 | ret = wait_for_bit_le32(®s->spisr, SPISR_TX_EMPTY, true, |
| 250 | XILINX_SPISR_TIMEOUT, false); |
| 251 | if (ret < 0) { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 252 | printf("XILSPI error: Xfer timeout\n"); |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 253 | return ret; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 256 | debug("txbytes:0x%x,txp:0x%p\n", txbytes, txp); |
| 257 | count = xilinx_spi_read_rxfifo(bus, rxp, rxbytes); |
| 258 | rxbytes -= count; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 259 | if (rxp) |
Vipul Kumar | 90098ba | 2018-06-30 08:15:18 +0530 | [diff] [blame^] | 260 | rxp += count; |
| 261 | debug("rxbytes:0x%x rxp:0x%p\n", rxbytes, rxp); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | done: |
| 265 | if (flags & SPI_XFER_END) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 266 | spi_cs_deactivate(dev); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 267 | |
| 268 | return 0; |
| 269 | } |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 270 | |
| 271 | static int xilinx_spi_set_speed(struct udevice *bus, uint speed) |
| 272 | { |
| 273 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 274 | |
| 275 | priv->freq = speed; |
| 276 | |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 277 | debug("xilinx_spi_set_speed: regs=%p, speed=%d\n", priv->regs, |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 278 | priv->freq); |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int xilinx_spi_set_mode(struct udevice *bus, uint mode) |
| 284 | { |
| 285 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 286 | struct xilinx_spi_regs *regs = priv->regs; |
| 287 | uint32_t spicr; |
| 288 | |
| 289 | spicr = readl(®s->spicr); |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 290 | if (mode & SPI_LSB_FIRST) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 291 | spicr |= SPICR_LSB_FIRST; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 292 | if (mode & SPI_CPHA) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 293 | spicr |= SPICR_CPHA; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 294 | if (mode & SPI_CPOL) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 295 | spicr |= SPICR_CPOL; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 296 | if (mode & SPI_LOOP) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 297 | spicr |= SPICR_LOOP; |
| 298 | |
| 299 | writel(spicr, ®s->spicr); |
| 300 | priv->mode = mode; |
| 301 | |
| 302 | debug("xilinx_spi_set_mode: regs=%p, mode=%d\n", priv->regs, |
| 303 | priv->mode); |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static const struct dm_spi_ops xilinx_spi_ops = { |
| 309 | .claim_bus = xilinx_spi_claim_bus, |
| 310 | .release_bus = xilinx_spi_release_bus, |
| 311 | .xfer = xilinx_spi_xfer, |
| 312 | .set_speed = xilinx_spi_set_speed, |
| 313 | .set_mode = xilinx_spi_set_mode, |
| 314 | }; |
| 315 | |
| 316 | static const struct udevice_id xilinx_spi_ids[] = { |
Michal Simek | 7465f31 | 2015-12-11 12:41:14 +0100 | [diff] [blame] | 317 | { .compatible = "xlnx,xps-spi-2.00.a" }, |
| 318 | { .compatible = "xlnx,xps-spi-2.00.b" }, |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 319 | { } |
| 320 | }; |
| 321 | |
| 322 | U_BOOT_DRIVER(xilinx_spi) = { |
| 323 | .name = "xilinx_spi", |
| 324 | .id = UCLASS_SPI, |
| 325 | .of_match = xilinx_spi_ids, |
| 326 | .ops = &xilinx_spi_ops, |
| 327 | .priv_auto_alloc_size = sizeof(struct xilinx_spi_priv), |
| 328 | .probe = xilinx_spi_probe, |
| 329 | }; |