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> |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 22 | |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 23 | /* |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 24 | * [0]: http://www.xilinx.com/support/documentation |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 25 | * |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 26 | * Xilinx SPI Register Definitions |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 27 | * [1]: [0]/ip_documentation/xps_spi.pdf |
| 28 | * page 8, Register Descriptions |
| 29 | * [2]: [0]/ip_documentation/axi_spi_ds742.pdf |
| 30 | * page 7, Register Overview Table |
| 31 | */ |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 32 | |
| 33 | /* SPI Control Register (spicr), [1] p9, [2] p8 */ |
Jagan Teki | f0a0141 | 2015-10-23 01:39:31 +0530 | [diff] [blame] | 34 | #define SPICR_LSB_FIRST BIT(9) |
| 35 | #define SPICR_MASTER_INHIBIT BIT(8) |
| 36 | #define SPICR_MANUAL_SS BIT(7) |
| 37 | #define SPICR_RXFIFO_RESEST BIT(6) |
| 38 | #define SPICR_TXFIFO_RESEST BIT(5) |
| 39 | #define SPICR_CPHA BIT(4) |
| 40 | #define SPICR_CPOL BIT(3) |
| 41 | #define SPICR_MASTER_MODE BIT(2) |
| 42 | #define SPICR_SPE BIT(1) |
| 43 | #define SPICR_LOOP BIT(0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 44 | |
| 45 | /* SPI Status Register (spisr), [1] p11, [2] p10 */ |
Jagan Teki | f0a0141 | 2015-10-23 01:39:31 +0530 | [diff] [blame] | 46 | #define SPISR_SLAVE_MODE_SELECT BIT(5) |
| 47 | #define SPISR_MODF BIT(4) |
| 48 | #define SPISR_TX_FULL BIT(3) |
| 49 | #define SPISR_TX_EMPTY BIT(2) |
| 50 | #define SPISR_RX_FULL BIT(1) |
| 51 | #define SPISR_RX_EMPTY BIT(0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 52 | |
| 53 | /* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */ |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 54 | #define SPIDTR_8BIT_MASK GENMASK(7, 0) |
| 55 | #define SPIDTR_16BIT_MASK GENMASK(15, 0) |
| 56 | #define SPIDTR_32BIT_MASK GENMASK(31, 0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 57 | |
| 58 | /* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */ |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 59 | #define SPIDRR_8BIT_MASK GENMASK(7, 0) |
| 60 | #define SPIDRR_16BIT_MASK GENMASK(15, 0) |
| 61 | #define SPIDRR_32BIT_MASK GENMASK(31, 0) |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 62 | |
| 63 | /* SPI Slave Select Register (spissr), [1] p13, [2] p13 */ |
| 64 | #define SPISSR_MASK(cs) (1 << (cs)) |
| 65 | #define SPISSR_ACT(cs) ~SPISSR_MASK(cs) |
| 66 | #define SPISSR_OFF ~0UL |
| 67 | |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 68 | /* SPI Software Reset Register (ssr) */ |
| 69 | #define SPISSR_RESET_VALUE 0x0a |
| 70 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 71 | #define XILSPI_MAX_XFER_BITS 8 |
| 72 | #define XILSPI_SPICR_DFLT_ON (SPICR_MANUAL_SS | SPICR_MASTER_MODE | \ |
| 73 | SPICR_SPE) |
| 74 | #define XILSPI_SPICR_DFLT_OFF (SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS) |
| 75 | |
| 76 | #ifndef CONFIG_XILINX_SPI_IDLE_VAL |
Jagan Teki | a2888d0 | 2015-10-23 01:03:44 +0530 | [diff] [blame] | 77 | #define CONFIG_XILINX_SPI_IDLE_VAL GENMASK(7, 0) |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 78 | #endif |
| 79 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 80 | /* xilinx spi register set */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 81 | struct xilinx_spi_regs { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 82 | u32 __space0__[7]; |
| 83 | u32 dgier; /* Device Global Interrupt Enable Register (DGIER) */ |
| 84 | u32 ipisr; /* IP Interrupt Status Register (IPISR) */ |
| 85 | u32 __space1__; |
| 86 | u32 ipier; /* IP Interrupt Enable Register (IPIER) */ |
| 87 | u32 __space2__[5]; |
| 88 | u32 srr; /* Softare Reset Register (SRR) */ |
| 89 | u32 __space3__[7]; |
| 90 | u32 spicr; /* SPI Control Register (SPICR) */ |
| 91 | u32 spisr; /* SPI Status Register (SPISR) */ |
| 92 | u32 spidtr; /* SPI Data Transmit Register (SPIDTR) */ |
| 93 | u32 spidrr; /* SPI Data Receive Register (SPIDRR) */ |
| 94 | u32 spissr; /* SPI Slave Select Register (SPISSR) */ |
| 95 | u32 spitfor; /* SPI Transmit FIFO Occupancy Register (SPITFOR) */ |
| 96 | u32 spirfor; /* SPI Receive FIFO Occupancy Register (SPIRFOR) */ |
| 97 | }; |
| 98 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 99 | /* xilinx spi priv */ |
| 100 | struct xilinx_spi_priv { |
| 101 | struct xilinx_spi_regs *regs; |
Jagan Teki | 23e281d | 2015-06-27 00:51:26 +0530 | [diff] [blame] | 102 | unsigned int freq; |
| 103 | unsigned int mode; |
| 104 | }; |
| 105 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 106 | static int xilinx_spi_probe(struct udevice *bus) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 107 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 108 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 109 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 110 | |
Michal Simek | 1ba1386 | 2018-06-30 08:15:17 +0530 | [diff] [blame^] | 111 | priv->regs = (struct xilinx_spi_regs *)devfdt_get_addr(bus); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 112 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 113 | writel(SPISSR_RESET_VALUE, ®s->srr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 114 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 115 | return 0; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 118 | static void spi_cs_activate(struct udevice *dev, uint cs) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 119 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 120 | struct udevice *bus = dev_get_parent(dev); |
| 121 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 122 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 123 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 124 | writel(SPISSR_ACT(cs), ®s->spissr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 127 | static void spi_cs_deactivate(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 128 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 129 | struct udevice *bus = dev_get_parent(dev); |
| 130 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 131 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 132 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 133 | writel(SPISSR_OFF, ®s->spissr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 136 | static int xilinx_spi_claim_bus(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 137 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 138 | struct udevice *bus = dev_get_parent(dev); |
| 139 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 140 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 141 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 142 | writel(SPISSR_OFF, ®s->spissr); |
| 143 | writel(XILSPI_SPICR_DFLT_ON, ®s->spicr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 144 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 148 | static int xilinx_spi_release_bus(struct udevice *dev) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 149 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 150 | struct udevice *bus = dev_get_parent(dev); |
| 151 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 152 | struct xilinx_spi_regs *regs = priv->regs; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 153 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 154 | writel(SPISSR_OFF, ®s->spissr); |
| 155 | writel(XILSPI_SPICR_DFLT_OFF, ®s->spicr); |
| 156 | |
| 157 | return 0; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 160 | static int xilinx_spi_xfer(struct udevice *dev, unsigned int bitlen, |
| 161 | const void *dout, void *din, unsigned long flags) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 162 | { |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 163 | struct udevice *bus = dev_get_parent(dev); |
| 164 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 165 | struct xilinx_spi_regs *regs = priv->regs; |
| 166 | struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 167 | /* assume spi core configured to do 8 bit transfers */ |
| 168 | unsigned int bytes = bitlen / XILSPI_MAX_XFER_BITS; |
| 169 | const unsigned char *txp = dout; |
| 170 | unsigned char *rxp = din; |
| 171 | unsigned rxecount = 17; /* max. 16 elements in FIFO, leftover 1 */ |
Michal Simek | f030d66 | 2014-01-22 09:48:55 +0100 | [diff] [blame] | 172 | unsigned global_timeout; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 173 | |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 174 | 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] | 175 | bus->seq, slave_plat->cs, bitlen, bytes, flags); |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 176 | |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 177 | if (bitlen == 0) |
| 178 | goto done; |
| 179 | |
| 180 | if (bitlen % XILSPI_MAX_XFER_BITS) { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 181 | printf("XILSPI warning: Not a multiple of %d bits\n", |
| 182 | XILSPI_MAX_XFER_BITS); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 183 | flags |= SPI_XFER_END; |
| 184 | goto done; |
| 185 | } |
| 186 | |
| 187 | /* empty read buffer */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 188 | while (rxecount && !(readl(®s->spisr) & SPISR_RX_EMPTY)) { |
| 189 | readl(®s->spidrr); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 190 | rxecount--; |
| 191 | } |
| 192 | |
| 193 | if (!rxecount) { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 194 | printf("XILSPI error: Rx buffer not empty\n"); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 195 | return -1; |
| 196 | } |
| 197 | |
| 198 | if (flags & SPI_XFER_BEGIN) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 199 | spi_cs_activate(dev, slave_plat->cs); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 200 | |
Michal Simek | f030d66 | 2014-01-22 09:48:55 +0100 | [diff] [blame] | 201 | /* at least 1usec or greater, leftover 1 */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 202 | global_timeout = priv->freq > XILSPI_MAX_XFER_BITS * 1000000 ? 2 : |
| 203 | (XILSPI_MAX_XFER_BITS * 1000000 / priv->freq) + 1; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 204 | |
Michal Simek | f030d66 | 2014-01-22 09:48:55 +0100 | [diff] [blame] | 205 | while (bytes--) { |
| 206 | unsigned timeout = global_timeout; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 207 | /* get Tx element from data out buffer and count up */ |
| 208 | unsigned char d = txp ? *txp++ : CONFIG_XILINX_SPI_IDLE_VAL; |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 209 | debug("spi_xfer: tx:%x ", d); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 210 | |
| 211 | /* write out and wait for processing (receive data) */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 212 | writel(d & SPIDTR_8BIT_MASK, ®s->spidtr); |
| 213 | while (timeout && readl(®s->spisr) |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 214 | & SPISR_RX_EMPTY) { |
| 215 | timeout--; |
| 216 | udelay(1); |
| 217 | } |
| 218 | |
| 219 | if (!timeout) { |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 220 | printf("XILSPI error: Xfer timeout\n"); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | /* read Rx element and push into data in buffer */ |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 225 | d = readl(®s->spidrr) & SPIDRR_8BIT_MASK; |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 226 | if (rxp) |
| 227 | *rxp++ = d; |
Jagan Teki | 48a0dbd | 2015-06-27 00:51:27 +0530 | [diff] [blame] | 228 | debug("spi_xfer: rx:%x\n", d); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | done: |
| 232 | if (flags & SPI_XFER_END) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 233 | spi_cs_deactivate(dev); |
Stephan Linz | fc77d51 | 2012-07-29 00:25:35 +0200 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 237 | |
| 238 | static int xilinx_spi_set_speed(struct udevice *bus, uint speed) |
| 239 | { |
| 240 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 241 | |
| 242 | priv->freq = speed; |
| 243 | |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 244 | debug("xilinx_spi_set_speed: regs=%p, speed=%d\n", priv->regs, |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 245 | priv->freq); |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static int xilinx_spi_set_mode(struct udevice *bus, uint mode) |
| 251 | { |
| 252 | struct xilinx_spi_priv *priv = dev_get_priv(bus); |
| 253 | struct xilinx_spi_regs *regs = priv->regs; |
| 254 | uint32_t spicr; |
| 255 | |
| 256 | spicr = readl(®s->spicr); |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 257 | if (mode & SPI_LSB_FIRST) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 258 | spicr |= SPICR_LSB_FIRST; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 259 | if (mode & SPI_CPHA) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 260 | spicr |= SPICR_CPHA; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 261 | if (mode & SPI_CPOL) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 262 | spicr |= SPICR_CPOL; |
Jagan Teki | 0dc543f | 2015-09-08 01:26:29 +0530 | [diff] [blame] | 263 | if (mode & SPI_LOOP) |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 264 | spicr |= SPICR_LOOP; |
| 265 | |
| 266 | writel(spicr, ®s->spicr); |
| 267 | priv->mode = mode; |
| 268 | |
| 269 | debug("xilinx_spi_set_mode: regs=%p, mode=%d\n", priv->regs, |
| 270 | priv->mode); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static const struct dm_spi_ops xilinx_spi_ops = { |
| 276 | .claim_bus = xilinx_spi_claim_bus, |
| 277 | .release_bus = xilinx_spi_release_bus, |
| 278 | .xfer = xilinx_spi_xfer, |
| 279 | .set_speed = xilinx_spi_set_speed, |
| 280 | .set_mode = xilinx_spi_set_mode, |
| 281 | }; |
| 282 | |
| 283 | static const struct udevice_id xilinx_spi_ids[] = { |
Michal Simek | 7465f31 | 2015-12-11 12:41:14 +0100 | [diff] [blame] | 284 | { .compatible = "xlnx,xps-spi-2.00.a" }, |
| 285 | { .compatible = "xlnx,xps-spi-2.00.b" }, |
Jagan Teki | fdc2b3d | 2015-06-29 13:15:18 +0530 | [diff] [blame] | 286 | { } |
| 287 | }; |
| 288 | |
| 289 | U_BOOT_DRIVER(xilinx_spi) = { |
| 290 | .name = "xilinx_spi", |
| 291 | .id = UCLASS_SPI, |
| 292 | .of_match = xilinx_spi_ids, |
| 293 | .ops = &xilinx_spi_ops, |
| 294 | .priv_auto_alloc_size = sizeof(struct xilinx_spi_priv), |
| 295 | .probe = xilinx_spi_probe, |
| 296 | }; |