blob: 4e9115dafee8dd15916f4cfa29024ae4efa75338 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephan Linzfc77d512012-07-29 00:25:35 +02002/*
3 * Xilinx SPI driver
4 *
Jagan Teki48a0dbd2015-06-27 00:51:27 +05305 * Supports 8 bit SPI transfers only, with or w/o FIFO
Stephan Linzfc77d512012-07-29 00:25:35 +02006 *
Jagan Teki48a0dbd2015-06-27 00:51:27 +05307 * Based on bfin_spi.c, by way of altera_spi.c
Jagan Tekifdc2b3d2015-06-29 13:15:18 +05308 * Copyright (c) 2015 Jagan Teki <jteki@openedev.com>
Stephan Linzfc77d512012-07-29 00:25:35 +02009 * Copyright (c) 2012 Stephan Linz <linz@li-pro.net>
Jagan Teki48a0dbd2015-06-27 00:51:27 +053010 * 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 Linzfc77d512012-07-29 00:25:35 +020013 */
Jagan Teki48a0dbd2015-06-27 00:51:27 +053014
Stephan Linzfc77d512012-07-29 00:25:35 +020015#include <config.h>
16#include <common.h>
Jagan Tekifdc2b3d2015-06-29 13:15:18 +053017#include <dm.h>
18#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Stephan Linzfc77d512012-07-29 00:25:35 +020020#include <malloc.h>
21#include <spi.h>
T Karthik Reddy50963802022-07-16 12:28:46 +053022#include <spi-mem.h>
Jagan Teki41fcbba2015-06-27 00:51:37 +053023#include <asm/io.h>
Vipul Kumar90098ba2018-06-30 08:15:18 +053024#include <wait_bit.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060025#include <linux/bitops.h>
Stephan Linzfc77d512012-07-29 00:25:35 +020026
Jagan Teki23e281d2015-06-27 00:51:26 +053027/*
Jagan Teki48a0dbd2015-06-27 00:51:27 +053028 * [0]: http://www.xilinx.com/support/documentation
Jagan Teki23e281d2015-06-27 00:51:26 +053029 *
Jagan Teki48a0dbd2015-06-27 00:51:27 +053030 * Xilinx SPI Register Definitions
Jagan Teki23e281d2015-06-27 00:51:26 +053031 * [1]: [0]/ip_documentation/xps_spi.pdf
32 * page 8, Register Descriptions
33 * [2]: [0]/ip_documentation/axi_spi_ds742.pdf
34 * page 7, Register Overview Table
35 */
Jagan Teki23e281d2015-06-27 00:51:26 +053036
37/* SPI Control Register (spicr), [1] p9, [2] p8 */
Jagan Tekif0a01412015-10-23 01:39:31 +053038#define SPICR_LSB_FIRST BIT(9)
39#define SPICR_MASTER_INHIBIT BIT(8)
40#define SPICR_MANUAL_SS BIT(7)
41#define SPICR_RXFIFO_RESEST BIT(6)
42#define SPICR_TXFIFO_RESEST BIT(5)
43#define SPICR_CPHA BIT(4)
44#define SPICR_CPOL BIT(3)
45#define SPICR_MASTER_MODE BIT(2)
46#define SPICR_SPE BIT(1)
47#define SPICR_LOOP BIT(0)
Jagan Teki23e281d2015-06-27 00:51:26 +053048
49/* SPI Status Register (spisr), [1] p11, [2] p10 */
Jagan Tekif0a01412015-10-23 01:39:31 +053050#define SPISR_SLAVE_MODE_SELECT BIT(5)
51#define SPISR_MODF BIT(4)
52#define SPISR_TX_FULL BIT(3)
53#define SPISR_TX_EMPTY BIT(2)
54#define SPISR_RX_FULL BIT(1)
55#define SPISR_RX_EMPTY BIT(0)
Jagan Teki23e281d2015-06-27 00:51:26 +053056
57/* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */
Jagan Tekia2888d02015-10-23 01:03:44 +053058#define SPIDTR_8BIT_MASK GENMASK(7, 0)
59#define SPIDTR_16BIT_MASK GENMASK(15, 0)
60#define SPIDTR_32BIT_MASK GENMASK(31, 0)
Jagan Teki23e281d2015-06-27 00:51:26 +053061
62/* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */
Jagan Tekia2888d02015-10-23 01:03:44 +053063#define SPIDRR_8BIT_MASK GENMASK(7, 0)
64#define SPIDRR_16BIT_MASK GENMASK(15, 0)
65#define SPIDRR_32BIT_MASK GENMASK(31, 0)
Jagan Teki23e281d2015-06-27 00:51:26 +053066
67/* SPI Slave Select Register (spissr), [1] p13, [2] p13 */
68#define SPISSR_MASK(cs) (1 << (cs))
69#define SPISSR_ACT(cs) ~SPISSR_MASK(cs)
70#define SPISSR_OFF ~0UL
71
Jagan Teki23e281d2015-06-27 00:51:26 +053072/* SPI Software Reset Register (ssr) */
73#define SPISSR_RESET_VALUE 0x0a
74
Jagan Teki48a0dbd2015-06-27 00:51:27 +053075#define XILSPI_MAX_XFER_BITS 8
76#define XILSPI_SPICR_DFLT_ON (SPICR_MANUAL_SS | SPICR_MASTER_MODE | \
T Karthik Reddy50963802022-07-16 12:28:46 +053077 SPICR_SPE | SPICR_MASTER_INHIBIT)
Jagan Teki48a0dbd2015-06-27 00:51:27 +053078#define XILSPI_SPICR_DFLT_OFF (SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS)
79
Ashok Reddy Somacaecfe62020-05-18 01:11:00 -060080#define XILINX_SPI_IDLE_VAL GENMASK(7, 0)
Jagan Teki48a0dbd2015-06-27 00:51:27 +053081
Vipul Kumar90098ba2018-06-30 08:15:18 +053082#define XILINX_SPISR_TIMEOUT 10000 /* in milliseconds */
83
Jagan Teki48a0dbd2015-06-27 00:51:27 +053084/* xilinx spi register set */
Jagan Tekifdc2b3d2015-06-29 13:15:18 +053085struct xilinx_spi_regs {
Jagan Teki48a0dbd2015-06-27 00:51:27 +053086 u32 __space0__[7];
87 u32 dgier; /* Device Global Interrupt Enable Register (DGIER) */
88 u32 ipisr; /* IP Interrupt Status Register (IPISR) */
89 u32 __space1__;
90 u32 ipier; /* IP Interrupt Enable Register (IPIER) */
91 u32 __space2__[5];
92 u32 srr; /* Softare Reset Register (SRR) */
93 u32 __space3__[7];
94 u32 spicr; /* SPI Control Register (SPICR) */
95 u32 spisr; /* SPI Status Register (SPISR) */
96 u32 spidtr; /* SPI Data Transmit Register (SPIDTR) */
97 u32 spidrr; /* SPI Data Receive Register (SPIDRR) */
98 u32 spissr; /* SPI Slave Select Register (SPISSR) */
99 u32 spitfor; /* SPI Transmit FIFO Occupancy Register (SPITFOR) */
100 u32 spirfor; /* SPI Receive FIFO Occupancy Register (SPIRFOR) */
101};
102
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530103/* xilinx spi priv */
104struct xilinx_spi_priv {
105 struct xilinx_spi_regs *regs;
Jagan Teki23e281d2015-06-27 00:51:26 +0530106 unsigned int freq;
107 unsigned int mode;
Vipul Kumar90098ba2018-06-30 08:15:18 +0530108 unsigned int fifo_depth;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530109 u8 startup;
Jagan Teki23e281d2015-06-27 00:51:26 +0530110};
111
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530112static int xilinx_spi_probe(struct udevice *bus)
Stephan Linzfc77d512012-07-29 00:25:35 +0200113{
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530114 struct xilinx_spi_priv *priv = dev_get_priv(bus);
115 struct xilinx_spi_regs *regs = priv->regs;
Stephan Linzfc77d512012-07-29 00:25:35 +0200116
Vipul Kumar646b4602018-06-30 08:15:20 +0530117 priv->regs = (struct xilinx_spi_regs *)dev_read_addr(bus);
Stephan Linzfc77d512012-07-29 00:25:35 +0200118
Vipul Kumar646b4602018-06-30 08:15:20 +0530119 priv->fifo_depth = dev_read_u32_default(bus, "fifo-size", 0);
Vipul Kumar90098ba2018-06-30 08:15:18 +0530120
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530121 writel(SPISSR_RESET_VALUE, &regs->srr);
Stephan Linzfc77d512012-07-29 00:25:35 +0200122
T Karthik Reddy50963802022-07-16 12:28:46 +0530123 /*
124 * Reset RX & TX FIFO
125 * Enable Manual Slave Select Assertion,
126 * Set SPI controller into master mode, and enable it
127 */
128 writel(SPICR_RXFIFO_RESEST | SPICR_TXFIFO_RESEST |
129 SPICR_MANUAL_SS | SPICR_MASTER_MODE | SPICR_SPE,
130 &regs->spicr);
131
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530132 return 0;
Stephan Linzfc77d512012-07-29 00:25:35 +0200133}
134
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530135static void spi_cs_activate(struct udevice *dev, uint cs)
Stephan Linzfc77d512012-07-29 00:25:35 +0200136{
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530137 struct udevice *bus = dev_get_parent(dev);
138 struct xilinx_spi_priv *priv = dev_get_priv(bus);
139 struct xilinx_spi_regs *regs = priv->regs;
Stephan Linzfc77d512012-07-29 00:25:35 +0200140
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530141 writel(SPISSR_ACT(cs), &regs->spissr);
Stephan Linzfc77d512012-07-29 00:25:35 +0200142}
143
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530144static void spi_cs_deactivate(struct udevice *dev)
Stephan Linzfc77d512012-07-29 00:25:35 +0200145{
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530146 struct udevice *bus = dev_get_parent(dev);
147 struct xilinx_spi_priv *priv = dev_get_priv(bus);
148 struct xilinx_spi_regs *regs = priv->regs;
T Karthik Reddy50963802022-07-16 12:28:46 +0530149 u32 reg;
Stephan Linzfc77d512012-07-29 00:25:35 +0200150
T Karthik Reddy50963802022-07-16 12:28:46 +0530151 reg = readl(&regs->spicr) | SPICR_RXFIFO_RESEST | SPICR_TXFIFO_RESEST;
152 writel(reg, &regs->spicr);
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530153 writel(SPISSR_OFF, &regs->spissr);
Stephan Linzfc77d512012-07-29 00:25:35 +0200154}
155
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530156static int xilinx_spi_claim_bus(struct udevice *dev)
Stephan Linzfc77d512012-07-29 00:25:35 +0200157{
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530158 struct udevice *bus = dev_get_parent(dev);
159 struct xilinx_spi_priv *priv = dev_get_priv(bus);
160 struct xilinx_spi_regs *regs = priv->regs;
Stephan Linzfc77d512012-07-29 00:25:35 +0200161
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530162 writel(SPISSR_OFF, &regs->spissr);
163 writel(XILSPI_SPICR_DFLT_ON, &regs->spicr);
Stephan Linzfc77d512012-07-29 00:25:35 +0200164
Stephan Linzfc77d512012-07-29 00:25:35 +0200165 return 0;
166}
167
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530168static int xilinx_spi_release_bus(struct udevice *dev)
Stephan Linzfc77d512012-07-29 00:25:35 +0200169{
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530170 struct udevice *bus = dev_get_parent(dev);
171 struct xilinx_spi_priv *priv = dev_get_priv(bus);
172 struct xilinx_spi_regs *regs = priv->regs;
Stephan Linzfc77d512012-07-29 00:25:35 +0200173
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530174 writel(SPISSR_OFF, &regs->spissr);
175 writel(XILSPI_SPICR_DFLT_OFF, &regs->spicr);
176
177 return 0;
Stephan Linzfc77d512012-07-29 00:25:35 +0200178}
179
Vipul Kumar90098ba2018-06-30 08:15:18 +0530180static u32 xilinx_spi_fill_txfifo(struct udevice *bus, const u8 *txp,
181 u32 txbytes)
182{
183 struct xilinx_spi_priv *priv = dev_get_priv(bus);
184 struct xilinx_spi_regs *regs = priv->regs;
185 unsigned char d;
186 u32 i = 0;
187
188 while (txbytes && !(readl(&regs->spisr) & SPISR_TX_FULL) &&
189 i < priv->fifo_depth) {
Ashok Reddy Somacaecfe62020-05-18 01:11:00 -0600190 d = txp ? *txp++ : XILINX_SPI_IDLE_VAL;
Vipul Kumar90098ba2018-06-30 08:15:18 +0530191 debug("spi_xfer: tx:%x ", d);
192 /* write out and wait for processing (receive data) */
193 writel(d & SPIDTR_8BIT_MASK, &regs->spidtr);
194 txbytes--;
195 i++;
196 }
197
198 return i;
199}
200
201static u32 xilinx_spi_read_rxfifo(struct udevice *bus, u8 *rxp, u32 rxbytes)
202{
203 struct xilinx_spi_priv *priv = dev_get_priv(bus);
204 struct xilinx_spi_regs *regs = priv->regs;
205 unsigned char d;
206 unsigned int i = 0;
207
208 while (rxbytes && !(readl(&regs->spisr) & SPISR_RX_EMPTY)) {
209 d = readl(&regs->spidrr) & SPIDRR_8BIT_MASK;
210 if (rxp)
211 *rxp++ = d;
212 debug("spi_xfer: rx:%x\n", d);
213 rxbytes--;
214 i++;
215 }
216 debug("Rx_done\n");
217
218 return i;
219}
220
T Karthik Reddy50963802022-07-16 12:28:46 +0530221static int start_transfer(struct spi_slave *spi, const void *dout, void *din, u32 len)
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530222{
T Karthik Reddy50963802022-07-16 12:28:46 +0530223 struct udevice *bus = spi->dev->parent;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530224 struct xilinx_spi_priv *priv = dev_get_priv(bus);
225 struct xilinx_spi_regs *regs = priv->regs;
T Karthik Reddy50963802022-07-16 12:28:46 +0530226 u32 count, txbytes, rxbytes;
227 int reg, ret;
228 const unsigned char *txp = (const unsigned char *)dout;
229 unsigned char *rxp = (unsigned char *)din;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530230
T Karthik Reddy50963802022-07-16 12:28:46 +0530231 txbytes = len;
232 rxbytes = len;
233 while (txbytes || rxbytes) {
234 /* Disable master transaction */
235 reg = readl(&regs->spicr) | SPICR_MASTER_INHIBIT;
236 writel(reg, &regs->spicr);
237 count = xilinx_spi_fill_txfifo(bus, txp, txbytes);
238 /* Enable master transaction */
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530239 reg = readl(&regs->spicr) & ~SPICR_MASTER_INHIBIT;
240 writel(reg, &regs->spicr);
T Karthik Reddy50963802022-07-16 12:28:46 +0530241 txbytes -= count;
242 if (txp)
243 txp += count;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530244
T Karthik Reddy50963802022-07-16 12:28:46 +0530245 ret = wait_for_bit_le32(&regs->spisr, SPISR_TX_EMPTY, true,
246 XILINX_SPISR_TIMEOUT, false);
247 if (ret < 0) {
248 printf("XILSPI error: Xfer timeout\n");
249 return ret;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530250 }
T Karthik Reddy50963802022-07-16 12:28:46 +0530251
252 reg = readl(&regs->spicr) | SPICR_MASTER_INHIBIT;
253 writel(reg, &regs->spicr);
254 count = xilinx_spi_read_rxfifo(bus, rxp, rxbytes);
255 rxbytes -= count;
256 if (rxp)
257 rxp += count;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530258 }
T Karthik Reddy50963802022-07-16 12:28:46 +0530259
260 return 0;
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530261}
262
T Karthik Reddy50963802022-07-16 12:28:46 +0530263static void xilinx_spi_startup_block(struct spi_slave *spi)
Stephan Linzfc77d512012-07-29 00:25:35 +0200264{
T Karthik Reddy50963802022-07-16 12:28:46 +0530265 struct dm_spi_slave_plat *slave_plat =
266 dev_get_parent_plat(spi->dev);
267 unsigned char txp;
268 unsigned char rxp[8];
Stephan Linzfc77d512012-07-29 00:25:35 +0200269
T Karthik Reddy50963802022-07-16 12:28:46 +0530270 /*
271 * Perform a dummy read as a work around for
272 * the startup block issue.
273 */
274 spi_cs_activate(spi->dev, slave_plat->cs);
275 txp = 0x9f;
276 start_transfer(spi, (void *)&txp, NULL, 1);
Jagan Teki48a0dbd2015-06-27 00:51:27 +0530277
T Karthik Reddy50963802022-07-16 12:28:46 +0530278 start_transfer(spi, NULL, (void *)rxp, 6);
Stephan Linzfc77d512012-07-29 00:25:35 +0200279
T Karthik Reddy50963802022-07-16 12:28:46 +0530280 spi_cs_deactivate(spi->dev);
281}
Stephan Linzfc77d512012-07-29 00:25:35 +0200282
T Karthik Reddy50963802022-07-16 12:28:46 +0530283static int xilinx_spi_mem_exec_op(struct spi_slave *spi,
284 const struct spi_mem_op *op)
285{
286 struct dm_spi_slave_plat *slave_plat =
287 dev_get_parent_plat(spi->dev);
288 static u32 startup;
289 u32 dummy_len, ret;
Stephan Linzfc77d512012-07-29 00:25:35 +0200290
Vipul Kumarc7e2aae2018-06-30 08:15:19 +0530291 /*
292 * This is the work around for the startup block issue in
293 * the spi controller. SPI clock is passing through STARTUP
294 * block to FLASH. STARTUP block don't provide clock as soon
295 * as QSPI provides command. So first command fails.
296 */
T Karthik Reddy50963802022-07-16 12:28:46 +0530297 if (!startup) {
298 xilinx_spi_startup_block(spi);
299 startup++;
300 }
Stephan Linzfc77d512012-07-29 00:25:35 +0200301
T Karthik Reddy50963802022-07-16 12:28:46 +0530302 spi_cs_activate(spi->dev, slave_plat->cs);
Stephan Linzfc77d512012-07-29 00:25:35 +0200303
T Karthik Reddy50963802022-07-16 12:28:46 +0530304 if (op->cmd.opcode) {
305 ret = start_transfer(spi, (void *)&op->cmd.opcode, NULL, 1);
306 if (ret)
307 goto done;
Stephan Linzfc77d512012-07-29 00:25:35 +0200308 }
T Karthik Reddy50963802022-07-16 12:28:46 +0530309 if (op->addr.nbytes) {
310 int i;
311 u8 addr_buf[4];
Stephan Linzfc77d512012-07-29 00:25:35 +0200312
T Karthik Reddy50963802022-07-16 12:28:46 +0530313 for (i = 0; i < op->addr.nbytes; i++)
314 addr_buf[i] = op->addr.val >>
315 (8 * (op->addr.nbytes - i - 1));
Stephan Linzfc77d512012-07-29 00:25:35 +0200316
T Karthik Reddy50963802022-07-16 12:28:46 +0530317 ret = start_transfer(spi, (void *)addr_buf, NULL,
318 op->addr.nbytes);
319 if (ret)
320 goto done;
321 }
322 if (op->dummy.nbytes) {
T Karthik Reddyea0bd082022-07-16 12:28:47 +0530323 dummy_len = (op->dummy.nbytes * op->data.buswidth) /
324 op->dummy.buswidth;
325
T Karthik Reddy50963802022-07-16 12:28:46 +0530326 ret = start_transfer(spi, NULL, NULL, dummy_len);
327 if (ret)
328 goto done;
329 }
330 if (op->data.nbytes) {
331 if (op->data.dir == SPI_MEM_DATA_IN) {
332 ret = start_transfer(spi, NULL,
333 op->data.buf.in, op->data.nbytes);
334 } else {
335 ret = start_transfer(spi, op->data.buf.out,
336 NULL, op->data.nbytes);
337 }
338 if (ret)
339 goto done;
340 }
341done:
342 spi_cs_deactivate(spi->dev);
343
344 return ret;
Stephan Linzfc77d512012-07-29 00:25:35 +0200345}
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530346
T Karthik Reddyea0bd082022-07-16 12:28:47 +0530347static int xilinx_qspi_check_buswidth(struct spi_slave *slave, u8 width)
348{
349 u32 mode = slave->mode;
350
351 switch (width) {
352 case 1:
353 return 0;
354 case 2:
355 if (mode & SPI_RX_DUAL)
356 return 0;
357 break;
358 case 4:
359 if (mode & SPI_RX_QUAD)
360 return 0;
361 break;
362 }
363
364 return -EOPNOTSUPP;
365}
366
367bool xilinx_qspi_mem_exec_op(struct spi_slave *slave,
368 const struct spi_mem_op *op)
369{
370 if (xilinx_qspi_check_buswidth(slave, op->cmd.buswidth))
371 return false;
372
373 if (op->addr.nbytes &&
374 xilinx_qspi_check_buswidth(slave, op->addr.buswidth))
375 return false;
376
377 if (op->dummy.nbytes &&
378 xilinx_qspi_check_buswidth(slave, op->dummy.buswidth))
379 return false;
380
381 if (op->data.dir != SPI_MEM_NO_DATA &&
382 xilinx_qspi_check_buswidth(slave, op->data.buswidth))
383 return false;
384
385 return true;
386}
387
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530388static int xilinx_spi_set_speed(struct udevice *bus, uint speed)
389{
390 struct xilinx_spi_priv *priv = dev_get_priv(bus);
391
392 priv->freq = speed;
393
T Karthik Reddyc17b3072021-03-17 01:01:50 -0600394 debug("%s: regs=%p, speed=%d\n", __func__, priv->regs, priv->freq);
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530395
396 return 0;
397}
398
399static int xilinx_spi_set_mode(struct udevice *bus, uint mode)
400{
401 struct xilinx_spi_priv *priv = dev_get_priv(bus);
402 struct xilinx_spi_regs *regs = priv->regs;
T Karthik Reddyc17b3072021-03-17 01:01:50 -0600403 u32 spicr;
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530404
405 spicr = readl(&regs->spicr);
Jagan Teki0dc543f2015-09-08 01:26:29 +0530406 if (mode & SPI_LSB_FIRST)
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530407 spicr |= SPICR_LSB_FIRST;
Jagan Teki0dc543f2015-09-08 01:26:29 +0530408 if (mode & SPI_CPHA)
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530409 spicr |= SPICR_CPHA;
Jagan Teki0dc543f2015-09-08 01:26:29 +0530410 if (mode & SPI_CPOL)
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530411 spicr |= SPICR_CPOL;
Jagan Teki0dc543f2015-09-08 01:26:29 +0530412 if (mode & SPI_LOOP)
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530413 spicr |= SPICR_LOOP;
414
415 writel(spicr, &regs->spicr);
416 priv->mode = mode;
417
T Karthik Reddyc17b3072021-03-17 01:01:50 -0600418 debug("%s: regs=%p, mode=%d\n", __func__, priv->regs, priv->mode);
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530419
420 return 0;
421}
422
T Karthik Reddy50963802022-07-16 12:28:46 +0530423static const struct spi_controller_mem_ops xilinx_spi_mem_ops = {
424 .exec_op = xilinx_spi_mem_exec_op,
T Karthik Reddyea0bd082022-07-16 12:28:47 +0530425 .supports_op = xilinx_qspi_mem_exec_op,
T Karthik Reddy50963802022-07-16 12:28:46 +0530426};
427
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530428static const struct dm_spi_ops xilinx_spi_ops = {
429 .claim_bus = xilinx_spi_claim_bus,
430 .release_bus = xilinx_spi_release_bus,
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530431 .set_speed = xilinx_spi_set_speed,
432 .set_mode = xilinx_spi_set_mode,
T Karthik Reddy50963802022-07-16 12:28:46 +0530433 .mem_ops = &xilinx_spi_mem_ops,
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530434};
435
436static const struct udevice_id xilinx_spi_ids[] = {
Michal Simek7465f312015-12-11 12:41:14 +0100437 { .compatible = "xlnx,xps-spi-2.00.a" },
438 { .compatible = "xlnx,xps-spi-2.00.b" },
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530439 { }
440};
441
442U_BOOT_DRIVER(xilinx_spi) = {
443 .name = "xilinx_spi",
444 .id = UCLASS_SPI,
445 .of_match = xilinx_spi_ids,
446 .ops = &xilinx_spi_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700447 .priv_auto = sizeof(struct xilinx_spi_priv),
Jagan Tekifdc2b3d2015-06-29 13:15:18 +0530448 .probe = xilinx_spi_probe,
449};