blob: d15d91a1d24228759c85e30875822d3aa32555f5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +05302/*
Jagan Teki697cdaa2015-09-02 11:39:45 +05303 * (C) Copyright 2013 Xilinx, Inc.
Jagan Tekif2125762015-06-27 00:51:31 +05304 * (C) Copyright 2015 Jagan Teki <jteki@openedev.com>
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +05305 *
6 * Xilinx Zynq PS SPI controller driver (master mode only)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +05307 */
8
Jagan Tekif2125762015-06-27 00:51:31 +05309#include <dm.h>
T Karthik Reddy1f33d102020-02-04 05:47:44 -070010#include <dm/device_compat.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053012#include <malloc.h>
13#include <spi.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070014#include <time.h>
T Karthik Reddy1f33d102020-02-04 05:47:44 -070015#include <clk.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053017#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060019#include <linux/delay.h>
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053020
Jagan Teki82081632015-06-27 00:51:34 +053021DECLARE_GLOBAL_DATA_PTR;
22
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053023/* zynq spi register bit masks ZYNQ_SPI_<REG>_<BIT>_MASK */
Jagan Tekif94b3f72015-10-22 20:40:16 +053024#define ZYNQ_SPI_CR_MSA_MASK BIT(15) /* Manual start enb */
25#define ZYNQ_SPI_CR_MCS_MASK BIT(14) /* Manual chip select */
Jagan Tekie1af6ae2015-10-22 21:06:37 +053026#define ZYNQ_SPI_CR_CS_MASK GENMASK(13, 10) /* Chip select */
27#define ZYNQ_SPI_CR_BAUD_MASK GENMASK(5, 3) /* Baud rate div */
Jagan Tekif94b3f72015-10-22 20:40:16 +053028#define ZYNQ_SPI_CR_CPHA_MASK BIT(2) /* Clock phase */
29#define ZYNQ_SPI_CR_CPOL_MASK BIT(1) /* Clock polarity */
30#define ZYNQ_SPI_CR_MSTREN_MASK BIT(0) /* Mode select */
31#define ZYNQ_SPI_IXR_RXNEMPTY_MASK BIT(4) /* RX_FIFO_not_empty */
32#define ZYNQ_SPI_IXR_TXOW_MASK BIT(2) /* TX_FIFO_not_full */
Jagan Tekie1af6ae2015-10-22 21:06:37 +053033#define ZYNQ_SPI_IXR_ALL_MASK GENMASK(6, 0) /* All IXR bits */
Jagan Tekif94b3f72015-10-22 20:40:16 +053034#define ZYNQ_SPI_ENR_SPI_EN_MASK BIT(0) /* SPI Enable */
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053035
Jagan Tekibe47fc32015-08-17 18:25:03 +053036#define ZYNQ_SPI_CR_BAUD_MAX 8 /* Baud rate divisor max val */
37#define ZYNQ_SPI_CR_BAUD_SHIFT 3 /* Baud rate divisor shift */
38#define ZYNQ_SPI_CR_SS_SHIFT 10 /* Slave select shift */
39
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053040#define ZYNQ_SPI_FIFO_DEPTH 128
Ashok Reddy Somacaecfe62020-05-18 01:11:00 -060041#define ZYNQ_SPI_WAIT (CONFIG_SYS_HZ / 100) /* 10 ms */
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053042
43/* zynq spi register set */
44struct zynq_spi_regs {
45 u32 cr; /* 0x00 */
46 u32 isr; /* 0x04 */
47 u32 ier; /* 0x08 */
48 u32 idr; /* 0x0C */
49 u32 imr; /* 0x10 */
50 u32 enr; /* 0x14 */
51 u32 dr; /* 0x18 */
52 u32 txdr; /* 0x1C */
53 u32 rxdr; /* 0x20 */
54};
55
Jagan Tekif2125762015-06-27 00:51:31 +053056/* zynq spi platform data */
Simon Glassb75b15b2020-12-03 16:55:23 -070057struct zynq_spi_plat {
Jagan Tekif2125762015-06-27 00:51:31 +053058 struct zynq_spi_regs *regs;
59 u32 frequency; /* input frequency */
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053060 u32 speed_hz;
Moritz Fischer50b7d032016-12-08 12:11:09 -080061 uint deactivate_delay_us; /* Delay to wait after deactivate */
62 uint activate_delay_us; /* Delay to wait after activate */
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053063};
64
Jagan Tekif2125762015-06-27 00:51:31 +053065/* zynq spi priv */
66struct zynq_spi_priv {
67 struct zynq_spi_regs *regs;
Jagan Teki12c941e2015-08-17 18:31:39 +053068 u8 cs;
Jagan Tekif2125762015-06-27 00:51:31 +053069 u8 mode;
Moritz Fischer50b7d032016-12-08 12:11:09 -080070 ulong last_transaction_us; /* Time of last transaction end */
Jagan Tekif2125762015-06-27 00:51:31 +053071 u8 fifo_depth;
72 u32 freq; /* required frequency */
73};
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053074
Simon Glassaad29ae2020-12-03 16:55:21 -070075static int zynq_spi_of_to_plat(struct udevice *bus)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053076{
Simon Glass95588622020-12-22 19:30:28 -070077 struct zynq_spi_plat *plat = dev_get_plat(bus);
Jagan Teki82081632015-06-27 00:51:34 +053078 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -070079 int node = dev_of_offset(bus);
Jagan Tekif2125762015-06-27 00:51:31 +053080
Masahiro Yamada1096ae12020-07-17 14:36:46 +090081 plat->regs = dev_read_addr_ptr(bus);
Jagan Teki82081632015-06-27 00:51:34 +053082
Moritz Fischer50b7d032016-12-08 12:11:09 -080083 plat->deactivate_delay_us = fdtdec_get_int(blob, node,
84 "spi-deactivate-delay", 0);
85 plat->activate_delay_us = fdtdec_get_int(blob, node,
86 "spi-activate-delay", 0);
Jagan Teki82081632015-06-27 00:51:34 +053087
Jagan Tekif2125762015-06-27 00:51:31 +053088 return 0;
89}
90
91static void zynq_spi_init_hw(struct zynq_spi_priv *priv)
92{
93 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053094 u32 confr;
95
96 /* Disable SPI */
Michal Simekebbac2f2016-09-01 12:51:27 +020097 confr = ZYNQ_SPI_ENR_SPI_EN_MASK;
98 writel(~confr, &regs->enr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +053099
100 /* Disable Interrupts */
Jagan Tekif2125762015-06-27 00:51:31 +0530101 writel(ZYNQ_SPI_IXR_ALL_MASK, &regs->idr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530102
103 /* Clear RX FIFO */
Jagan Tekif2125762015-06-27 00:51:31 +0530104 while (readl(&regs->isr) &
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530105 ZYNQ_SPI_IXR_RXNEMPTY_MASK)
Jagan Tekif2125762015-06-27 00:51:31 +0530106 readl(&regs->rxdr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530107
108 /* Clear Interrupts */
Jagan Tekif2125762015-06-27 00:51:31 +0530109 writel(ZYNQ_SPI_IXR_ALL_MASK, &regs->isr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530110
111 /* Manual slave select and Auto start */
112 confr = ZYNQ_SPI_CR_MCS_MASK | ZYNQ_SPI_CR_CS_MASK |
113 ZYNQ_SPI_CR_MSTREN_MASK;
114 confr &= ~ZYNQ_SPI_CR_MSA_MASK;
Jagan Tekif2125762015-06-27 00:51:31 +0530115 writel(confr, &regs->cr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530116
117 /* Enable SPI */
Jagan Tekif2125762015-06-27 00:51:31 +0530118 writel(ZYNQ_SPI_ENR_SPI_EN_MASK, &regs->enr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530119}
120
Jagan Tekif2125762015-06-27 00:51:31 +0530121static int zynq_spi_probe(struct udevice *bus)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530122{
Simon Glassb75b15b2020-12-03 16:55:23 -0700123 struct zynq_spi_plat *plat = dev_get_plat(bus);
Jagan Tekif2125762015-06-27 00:51:31 +0530124 struct zynq_spi_priv *priv = dev_get_priv(bus);
T Karthik Reddy1f33d102020-02-04 05:47:44 -0700125 struct clk clk;
126 unsigned long clock;
127 int ret;
Jagan Tekif2125762015-06-27 00:51:31 +0530128
129 priv->regs = plat->regs;
130 priv->fifo_depth = ZYNQ_SPI_FIFO_DEPTH;
131
T Karthik Reddy1f33d102020-02-04 05:47:44 -0700132 ret = clk_get_by_name(bus, "ref_clk", &clk);
133 if (ret < 0) {
134 dev_err(bus, "failed to get clock\n");
135 return ret;
136 }
137
138 clock = clk_get_rate(&clk);
139 if (IS_ERR_VALUE(clock)) {
140 dev_err(bus, "failed to get rate\n");
141 return clock;
142 }
143
144 ret = clk_enable(&clk);
Michal Simek41710952021-02-09 15:28:15 +0100145 if (ret) {
T Karthik Reddy1f33d102020-02-04 05:47:44 -0700146 dev_err(bus, "failed to enable clock\n");
147 return ret;
148 }
149
Jagan Tekif2125762015-06-27 00:51:31 +0530150 /* init the zynq spi hw */
151 zynq_spi_init_hw(priv);
152
T Karthik Reddy1f33d102020-02-04 05:47:44 -0700153 plat->frequency = clock;
154 plat->speed_hz = plat->frequency / 2;
155
156 debug("%s: max-frequency=%d\n", __func__, plat->speed_hz);
157
Jagan Tekif2125762015-06-27 00:51:31 +0530158 return 0;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530159}
160
Jagan Teki12c941e2015-08-17 18:31:39 +0530161static void spi_cs_activate(struct udevice *dev)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530162{
Jagan Tekif2125762015-06-27 00:51:31 +0530163 struct udevice *bus = dev->parent;
Simon Glass95588622020-12-22 19:30:28 -0700164 struct zynq_spi_plat *plat = dev_get_plat(bus);
Jagan Tekif2125762015-06-27 00:51:31 +0530165 struct zynq_spi_priv *priv = dev_get_priv(bus);
166 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530167 u32 cr;
168
Moritz Fischer50b7d032016-12-08 12:11:09 -0800169 /* If it's too soon to do another transaction, wait */
170 if (plat->deactivate_delay_us && priv->last_transaction_us) {
171 ulong delay_us; /* The delay completed so far */
172 delay_us = timer_get_us() - priv->last_transaction_us;
173 if (delay_us < plat->deactivate_delay_us)
174 udelay(plat->deactivate_delay_us - delay_us);
175 }
176
Jagan Tekif2125762015-06-27 00:51:31 +0530177 clrbits_le32(&regs->cr, ZYNQ_SPI_CR_CS_MASK);
178 cr = readl(&regs->cr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530179 /*
180 * CS cal logic: CS[13:10]
181 * xxx0 - cs0
182 * xx01 - cs1
183 * x011 - cs2
184 */
Jagan Teki12c941e2015-08-17 18:31:39 +0530185 cr |= (~(1 << priv->cs) << ZYNQ_SPI_CR_SS_SHIFT) & ZYNQ_SPI_CR_CS_MASK;
Jagan Tekif2125762015-06-27 00:51:31 +0530186 writel(cr, &regs->cr);
Moritz Fischer50b7d032016-12-08 12:11:09 -0800187
188 if (plat->activate_delay_us)
189 udelay(plat->activate_delay_us);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530190}
191
Jagan Tekif2125762015-06-27 00:51:31 +0530192static void spi_cs_deactivate(struct udevice *dev)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530193{
Jagan Tekif2125762015-06-27 00:51:31 +0530194 struct udevice *bus = dev->parent;
Simon Glass95588622020-12-22 19:30:28 -0700195 struct zynq_spi_plat *plat = dev_get_plat(bus);
Jagan Tekif2125762015-06-27 00:51:31 +0530196 struct zynq_spi_priv *priv = dev_get_priv(bus);
197 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530198
Jagan Tekif2125762015-06-27 00:51:31 +0530199 setbits_le32(&regs->cr, ZYNQ_SPI_CR_CS_MASK);
Moritz Fischer50b7d032016-12-08 12:11:09 -0800200
201 /* Remember time of this transaction so we can honour the bus delay */
202 if (plat->deactivate_delay_us)
203 priv->last_transaction_us = timer_get_us();
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530204}
205
Jagan Tekif2125762015-06-27 00:51:31 +0530206static int zynq_spi_claim_bus(struct udevice *dev)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530207{
Jagan Tekif2125762015-06-27 00:51:31 +0530208 struct udevice *bus = dev->parent;
209 struct zynq_spi_priv *priv = dev_get_priv(bus);
210 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530211
Jagan Tekif2125762015-06-27 00:51:31 +0530212 writel(ZYNQ_SPI_ENR_SPI_EN_MASK, &regs->enr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530213
Jagan Tekif2125762015-06-27 00:51:31 +0530214 return 0;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530215}
216
Jagan Tekif2125762015-06-27 00:51:31 +0530217static int zynq_spi_release_bus(struct udevice *dev)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530218{
Jagan Tekif2125762015-06-27 00:51:31 +0530219 struct udevice *bus = dev->parent;
220 struct zynq_spi_priv *priv = dev_get_priv(bus);
221 struct zynq_spi_regs *regs = priv->regs;
Michal Simekebbac2f2016-09-01 12:51:27 +0200222 u32 confr;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530223
Michal Simekebbac2f2016-09-01 12:51:27 +0200224 confr = ZYNQ_SPI_ENR_SPI_EN_MASK;
225 writel(~confr, &regs->enr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530226
227 return 0;
228}
229
Jagan Tekif2125762015-06-27 00:51:31 +0530230static int zynq_spi_xfer(struct udevice *dev, unsigned int bitlen,
231 const void *dout, void *din, unsigned long flags)
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530232{
Jagan Tekif2125762015-06-27 00:51:31 +0530233 struct udevice *bus = dev->parent;
234 struct zynq_spi_priv *priv = dev_get_priv(bus);
235 struct zynq_spi_regs *regs = priv->regs;
Simon Glassb75b15b2020-12-03 16:55:23 -0700236 struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530237 u32 len = bitlen / 8;
238 u32 tx_len = len, rx_len = len, tx_tvl;
239 const u8 *tx_buf = dout;
240 u8 *rx_buf = din, buf;
241 u32 ts, status;
242
243 debug("spi_xfer: bus:%i cs:%i bitlen:%i len:%i flags:%lx\n",
Simon Glass75e534b2020-12-16 21:20:07 -0700244 dev_seq(bus), slave_plat->cs, bitlen, len, flags);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530245
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530246 if (bitlen % 8) {
247 debug("spi_xfer: Non byte aligned SPI transfer\n");
248 return -1;
249 }
250
Jagan Teki12c941e2015-08-17 18:31:39 +0530251 priv->cs = slave_plat->cs;
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530252 if (flags & SPI_XFER_BEGIN)
Jagan Teki12c941e2015-08-17 18:31:39 +0530253 spi_cs_activate(dev);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530254
255 while (rx_len > 0) {
256 /* Write the data into TX FIFO - tx threshold is fifo_depth */
257 tx_tvl = 0;
Jagan Tekif2125762015-06-27 00:51:31 +0530258 while ((tx_tvl < priv->fifo_depth) && tx_len) {
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530259 if (tx_buf)
260 buf = *tx_buf++;
261 else
262 buf = 0;
Jagan Tekif2125762015-06-27 00:51:31 +0530263 writel(buf, &regs->txdr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530264 tx_len--;
265 tx_tvl++;
266 }
267
268 /* Check TX FIFO completion */
269 ts = get_timer(0);
Jagan Tekif2125762015-06-27 00:51:31 +0530270 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530271 while (!(status & ZYNQ_SPI_IXR_TXOW_MASK)) {
Ashok Reddy Somacaecfe62020-05-18 01:11:00 -0600272 if (get_timer(ts) > ZYNQ_SPI_WAIT) {
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530273 printf("spi_xfer: Timeout! TX FIFO not full\n");
274 return -1;
275 }
Jagan Tekif2125762015-06-27 00:51:31 +0530276 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530277 }
278
279 /* Read the data from RX FIFO */
Jagan Tekif2125762015-06-27 00:51:31 +0530280 status = readl(&regs->isr);
Lad, Prabhakar636ef592016-07-30 22:28:24 +0100281 while ((status & ZYNQ_SPI_IXR_RXNEMPTY_MASK) && rx_len) {
Jagan Tekif2125762015-06-27 00:51:31 +0530282 buf = readl(&regs->rxdr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530283 if (rx_buf)
284 *rx_buf++ = buf;
Jagan Tekif2125762015-06-27 00:51:31 +0530285 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530286 rx_len--;
287 }
288 }
289
290 if (flags & SPI_XFER_END)
Jagan Tekif2125762015-06-27 00:51:31 +0530291 spi_cs_deactivate(dev);
292
293 return 0;
294}
295
296static int zynq_spi_set_speed(struct udevice *bus, uint speed)
297{
Simon Glass95588622020-12-22 19:30:28 -0700298 struct zynq_spi_plat *plat = dev_get_plat(bus);
Jagan Tekif2125762015-06-27 00:51:31 +0530299 struct zynq_spi_priv *priv = dev_get_priv(bus);
300 struct zynq_spi_regs *regs = priv->regs;
301 uint32_t confr;
302 u8 baud_rate_val = 0;
303
304 if (speed > plat->frequency)
305 speed = plat->frequency;
306
307 /* Set the clock frequency */
308 confr = readl(&regs->cr);
309 if (speed == 0) {
310 /* Set baudrate x8, if the freq is 0 */
311 baud_rate_val = 0x2;
312 } else if (plat->speed_hz != speed) {
Jagan Tekibe47fc32015-08-17 18:25:03 +0530313 while ((baud_rate_val < ZYNQ_SPI_CR_BAUD_MAX) &&
Jagan Tekif2125762015-06-27 00:51:31 +0530314 ((plat->frequency /
315 (2 << baud_rate_val)) > speed))
316 baud_rate_val++;
317 plat->speed_hz = speed / (2 << baud_rate_val);
318 }
Jagan Teki08dd0952015-08-17 18:27:47 +0530319 confr &= ~ZYNQ_SPI_CR_BAUD_MASK;
Jagan Tekibe47fc32015-08-17 18:25:03 +0530320 confr |= (baud_rate_val << ZYNQ_SPI_CR_BAUD_SHIFT);
Jagan Tekif2125762015-06-27 00:51:31 +0530321
322 writel(confr, &regs->cr);
323 priv->freq = speed;
324
Jagan Tekia61e2162015-09-08 01:38:50 +0530325 debug("zynq_spi_set_speed: regs=%p, speed=%d\n",
326 priv->regs, priv->freq);
Jagan Tekif2125762015-06-27 00:51:31 +0530327
328 return 0;
329}
330
331static int zynq_spi_set_mode(struct udevice *bus, uint mode)
332{
333 struct zynq_spi_priv *priv = dev_get_priv(bus);
334 struct zynq_spi_regs *regs = priv->regs;
335 uint32_t confr;
336
337 /* Set the SPI Clock phase and polarities */
338 confr = readl(&regs->cr);
339 confr &= ~(ZYNQ_SPI_CR_CPHA_MASK | ZYNQ_SPI_CR_CPOL_MASK);
340
Jagan Tekia61e2162015-09-08 01:38:50 +0530341 if (mode & SPI_CPHA)
Jagan Tekif2125762015-06-27 00:51:31 +0530342 confr |= ZYNQ_SPI_CR_CPHA_MASK;
Jagan Tekia61e2162015-09-08 01:38:50 +0530343 if (mode & SPI_CPOL)
Jagan Tekif2125762015-06-27 00:51:31 +0530344 confr |= ZYNQ_SPI_CR_CPOL_MASK;
345
346 writel(confr, &regs->cr);
347 priv->mode = mode;
348
349 debug("zynq_spi_set_mode: regs=%p, mode=%d\n", priv->regs, priv->mode);
Jagannadha Sutradharudu Teki216ec092013-07-29 23:45:16 +0530350
351 return 0;
352}
Jagan Tekif2125762015-06-27 00:51:31 +0530353
354static const struct dm_spi_ops zynq_spi_ops = {
355 .claim_bus = zynq_spi_claim_bus,
356 .release_bus = zynq_spi_release_bus,
357 .xfer = zynq_spi_xfer,
358 .set_speed = zynq_spi_set_speed,
359 .set_mode = zynq_spi_set_mode,
360};
361
362static const struct udevice_id zynq_spi_ids[] = {
Michal Simek0cf97aa2015-07-22 10:47:33 +0200363 { .compatible = "xlnx,zynq-spi-r1p6" },
Michal Simek8eb23ec2015-12-07 13:06:54 +0100364 { .compatible = "cdns,spi-r1p6" },
Jagan Tekif2125762015-06-27 00:51:31 +0530365 { }
366};
367
368U_BOOT_DRIVER(zynq_spi) = {
369 .name = "zynq_spi",
370 .id = UCLASS_SPI,
371 .of_match = zynq_spi_ids,
372 .ops = &zynq_spi_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700373 .of_to_plat = zynq_spi_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700374 .plat_auto = sizeof(struct zynq_spi_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700375 .priv_auto = sizeof(struct zynq_spi_priv),
Jagan Tekif2125762015-06-27 00:51:31 +0530376 .probe = zynq_spi_probe,
377};