blob: b400959f48fe5886deff1a78da4eea485288be30 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +05302/*
Jagan Teki86e99b92015-09-02 11:39:45 +05303 * (C) Copyright 2013 Xilinx, Inc.
Jagan Tekib1c82da2015-06-27 00:51:31 +05304 * (C) Copyright 2015 Jagan Teki <jteki@openedev.com>
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +05305 *
6 * Xilinx Zynq PS SPI controller driver (master mode only)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +05307 */
8
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +05309#include <common.h>
Jagan Tekib1c82da2015-06-27 00:51:31 +053010#include <dm.h>
T Karthik Reddyb79a7032020-02-04 05:47:44 -070011#include <dm/device_compat.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053013#include <malloc.h>
14#include <spi.h>
Simon Glass10453152019-11-14 12:57:30 -070015#include <time.h>
T Karthik Reddyb79a7032020-02-04 05:47:44 -070016#include <clk.h>
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053017#include <asm/io.h>
Simon Glasscd93d622020-05-10 11:40:13 -060018#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060019#include <linux/delay.h>
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053020
Jagan Tekicdc9dd02015-06-27 00:51:34 +053021DECLARE_GLOBAL_DATA_PTR;
22
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053023/* zynq spi register bit masks ZYNQ_SPI_<REG>_<BIT>_MASK */
Jagan Teki736b4df2015-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 Teki9cf2ffb2015-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 Teki736b4df2015-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 Teki9cf2ffb2015-10-22 21:06:37 +053033#define ZYNQ_SPI_IXR_ALL_MASK GENMASK(6, 0) /* All IXR bits */
Jagan Teki736b4df2015-10-22 20:40:16 +053034#define ZYNQ_SPI_ENR_SPI_EN_MASK BIT(0) /* SPI Enable */
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053035
Jagan Teki46ab8a62015-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 Teki1465d052013-07-29 23:45:16 +053040#define ZYNQ_SPI_FIFO_DEPTH 128
Ashok Reddy Somaf44bd3b2020-05-18 01:11:00 -060041#define ZYNQ_SPI_WAIT (CONFIG_SYS_HZ / 100) /* 10 ms */
Jagannadha Sutradharudu Teki1465d052013-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 Tekib1c82da2015-06-27 00:51:31 +053056
57/* zynq spi platform data */
58struct zynq_spi_platdata {
59 struct zynq_spi_regs *regs;
60 u32 frequency; /* input frequency */
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053061 u32 speed_hz;
Moritz Fischerac6991f2016-12-08 12:11:09 -080062 uint deactivate_delay_us; /* Delay to wait after deactivate */
63 uint activate_delay_us; /* Delay to wait after activate */
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053064};
65
Jagan Tekib1c82da2015-06-27 00:51:31 +053066/* zynq spi priv */
67struct zynq_spi_priv {
68 struct zynq_spi_regs *regs;
Jagan Teki19126992015-08-17 18:31:39 +053069 u8 cs;
Jagan Tekib1c82da2015-06-27 00:51:31 +053070 u8 mode;
Moritz Fischerac6991f2016-12-08 12:11:09 -080071 ulong last_transaction_us; /* Time of last transaction end */
Jagan Tekib1c82da2015-06-27 00:51:31 +053072 u8 fifo_depth;
73 u32 freq; /* required frequency */
74};
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053075
Jagan Tekib1c82da2015-06-27 00:51:31 +053076static int zynq_spi_ofdata_to_platdata(struct udevice *bus)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053077{
Simon Glasscaa4daa2020-12-03 16:55:18 -070078 struct zynq_spi_platdata *plat = bus->plat;
Jagan Tekicdc9dd02015-06-27 00:51:34 +053079 const void *blob = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -070080 int node = dev_of_offset(bus);
Jagan Tekib1c82da2015-06-27 00:51:31 +053081
Masahiro Yamada8613c8d2020-07-17 14:36:46 +090082 plat->regs = dev_read_addr_ptr(bus);
Jagan Tekicdc9dd02015-06-27 00:51:34 +053083
Moritz Fischerac6991f2016-12-08 12:11:09 -080084 plat->deactivate_delay_us = fdtdec_get_int(blob, node,
85 "spi-deactivate-delay", 0);
86 plat->activate_delay_us = fdtdec_get_int(blob, node,
87 "spi-activate-delay", 0);
Jagan Tekicdc9dd02015-06-27 00:51:34 +053088
Jagan Tekib1c82da2015-06-27 00:51:31 +053089 return 0;
90}
91
92static void zynq_spi_init_hw(struct zynq_spi_priv *priv)
93{
94 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +053095 u32 confr;
96
97 /* Disable SPI */
Michal Simek5f647c22016-09-01 12:51:27 +020098 confr = ZYNQ_SPI_ENR_SPI_EN_MASK;
99 writel(~confr, &regs->enr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530100
101 /* Disable Interrupts */
Jagan Tekib1c82da2015-06-27 00:51:31 +0530102 writel(ZYNQ_SPI_IXR_ALL_MASK, &regs->idr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530103
104 /* Clear RX FIFO */
Jagan Tekib1c82da2015-06-27 00:51:31 +0530105 while (readl(&regs->isr) &
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530106 ZYNQ_SPI_IXR_RXNEMPTY_MASK)
Jagan Tekib1c82da2015-06-27 00:51:31 +0530107 readl(&regs->rxdr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530108
109 /* Clear Interrupts */
Jagan Tekib1c82da2015-06-27 00:51:31 +0530110 writel(ZYNQ_SPI_IXR_ALL_MASK, &regs->isr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530111
112 /* Manual slave select and Auto start */
113 confr = ZYNQ_SPI_CR_MCS_MASK | ZYNQ_SPI_CR_CS_MASK |
114 ZYNQ_SPI_CR_MSTREN_MASK;
115 confr &= ~ZYNQ_SPI_CR_MSA_MASK;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530116 writel(confr, &regs->cr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530117
118 /* Enable SPI */
Jagan Tekib1c82da2015-06-27 00:51:31 +0530119 writel(ZYNQ_SPI_ENR_SPI_EN_MASK, &regs->enr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530120}
121
Jagan Tekib1c82da2015-06-27 00:51:31 +0530122static int zynq_spi_probe(struct udevice *bus)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530123{
Simon Glassc69cda22020-12-03 16:55:20 -0700124 struct zynq_spi_platdata *plat = dev_get_plat(bus);
Jagan Tekib1c82da2015-06-27 00:51:31 +0530125 struct zynq_spi_priv *priv = dev_get_priv(bus);
T Karthik Reddyb79a7032020-02-04 05:47:44 -0700126 struct clk clk;
127 unsigned long clock;
128 int ret;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530129
130 priv->regs = plat->regs;
131 priv->fifo_depth = ZYNQ_SPI_FIFO_DEPTH;
132
T Karthik Reddyb79a7032020-02-04 05:47:44 -0700133 ret = clk_get_by_name(bus, "ref_clk", &clk);
134 if (ret < 0) {
135 dev_err(bus, "failed to get clock\n");
136 return ret;
137 }
138
139 clock = clk_get_rate(&clk);
140 if (IS_ERR_VALUE(clock)) {
141 dev_err(bus, "failed to get rate\n");
142 return clock;
143 }
144
145 ret = clk_enable(&clk);
146 if (ret && ret != -ENOSYS) {
147 dev_err(bus, "failed to enable clock\n");
148 return ret;
149 }
150
Jagan Tekib1c82da2015-06-27 00:51:31 +0530151 /* init the zynq spi hw */
152 zynq_spi_init_hw(priv);
153
T Karthik Reddyb79a7032020-02-04 05:47:44 -0700154 plat->frequency = clock;
155 plat->speed_hz = plat->frequency / 2;
156
157 debug("%s: max-frequency=%d\n", __func__, plat->speed_hz);
158
Jagan Tekib1c82da2015-06-27 00:51:31 +0530159 return 0;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530160}
161
Jagan Teki19126992015-08-17 18:31:39 +0530162static void spi_cs_activate(struct udevice *dev)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530163{
Jagan Tekib1c82da2015-06-27 00:51:31 +0530164 struct udevice *bus = dev->parent;
Simon Glasscaa4daa2020-12-03 16:55:18 -0700165 struct zynq_spi_platdata *plat = bus->plat;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530166 struct zynq_spi_priv *priv = dev_get_priv(bus);
167 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530168 u32 cr;
169
Moritz Fischerac6991f2016-12-08 12:11:09 -0800170 /* If it's too soon to do another transaction, wait */
171 if (plat->deactivate_delay_us && priv->last_transaction_us) {
172 ulong delay_us; /* The delay completed so far */
173 delay_us = timer_get_us() - priv->last_transaction_us;
174 if (delay_us < plat->deactivate_delay_us)
175 udelay(plat->deactivate_delay_us - delay_us);
176 }
177
Jagan Tekib1c82da2015-06-27 00:51:31 +0530178 clrbits_le32(&regs->cr, ZYNQ_SPI_CR_CS_MASK);
179 cr = readl(&regs->cr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530180 /*
181 * CS cal logic: CS[13:10]
182 * xxx0 - cs0
183 * xx01 - cs1
184 * x011 - cs2
185 */
Jagan Teki19126992015-08-17 18:31:39 +0530186 cr |= (~(1 << priv->cs) << ZYNQ_SPI_CR_SS_SHIFT) & ZYNQ_SPI_CR_CS_MASK;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530187 writel(cr, &regs->cr);
Moritz Fischerac6991f2016-12-08 12:11:09 -0800188
189 if (plat->activate_delay_us)
190 udelay(plat->activate_delay_us);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530191}
192
Jagan Tekib1c82da2015-06-27 00:51:31 +0530193static void spi_cs_deactivate(struct udevice *dev)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530194{
Jagan Tekib1c82da2015-06-27 00:51:31 +0530195 struct udevice *bus = dev->parent;
Simon Glasscaa4daa2020-12-03 16:55:18 -0700196 struct zynq_spi_platdata *plat = bus->plat;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530197 struct zynq_spi_priv *priv = dev_get_priv(bus);
198 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530199
Jagan Tekib1c82da2015-06-27 00:51:31 +0530200 setbits_le32(&regs->cr, ZYNQ_SPI_CR_CS_MASK);
Moritz Fischerac6991f2016-12-08 12:11:09 -0800201
202 /* Remember time of this transaction so we can honour the bus delay */
203 if (plat->deactivate_delay_us)
204 priv->last_transaction_us = timer_get_us();
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530205}
206
Jagan Tekib1c82da2015-06-27 00:51:31 +0530207static int zynq_spi_claim_bus(struct udevice *dev)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530208{
Jagan Tekib1c82da2015-06-27 00:51:31 +0530209 struct udevice *bus = dev->parent;
210 struct zynq_spi_priv *priv = dev_get_priv(bus);
211 struct zynq_spi_regs *regs = priv->regs;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530212
Jagan Tekib1c82da2015-06-27 00:51:31 +0530213 writel(ZYNQ_SPI_ENR_SPI_EN_MASK, &regs->enr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530214
215 return 0;
216}
217
Jagan Tekib1c82da2015-06-27 00:51:31 +0530218static int zynq_spi_release_bus(struct udevice *dev)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530219{
Jagan Tekib1c82da2015-06-27 00:51:31 +0530220 struct udevice *bus = dev->parent;
221 struct zynq_spi_priv *priv = dev_get_priv(bus);
222 struct zynq_spi_regs *regs = priv->regs;
Michal Simek5f647c22016-09-01 12:51:27 +0200223 u32 confr;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530224
Michal Simek5f647c22016-09-01 12:51:27 +0200225 confr = ZYNQ_SPI_ENR_SPI_EN_MASK;
226 writel(~confr, &regs->enr);
Jagan Tekib1c82da2015-06-27 00:51:31 +0530227
228 return 0;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530229}
230
Jagan Tekib1c82da2015-06-27 00:51:31 +0530231static int zynq_spi_xfer(struct udevice *dev, unsigned int bitlen,
232 const void *dout, void *din, unsigned long flags)
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530233{
Jagan Tekib1c82da2015-06-27 00:51:31 +0530234 struct udevice *bus = dev->parent;
235 struct zynq_spi_priv *priv = dev_get_priv(bus);
236 struct zynq_spi_regs *regs = priv->regs;
Simon Glasscaa4daa2020-12-03 16:55:18 -0700237 struct dm_spi_slave_platdata *slave_plat = dev_get_parent_plat(dev);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530238 u32 len = bitlen / 8;
239 u32 tx_len = len, rx_len = len, tx_tvl;
240 const u8 *tx_buf = dout;
241 u8 *rx_buf = din, buf;
242 u32 ts, status;
243
244 debug("spi_xfer: bus:%i cs:%i bitlen:%i len:%i flags:%lx\n",
Jagan Tekib1c82da2015-06-27 00:51:31 +0530245 bus->seq, slave_plat->cs, bitlen, len, flags);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530246
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530247 if (bitlen % 8) {
248 debug("spi_xfer: Non byte aligned SPI transfer\n");
249 return -1;
250 }
251
Jagan Teki19126992015-08-17 18:31:39 +0530252 priv->cs = slave_plat->cs;
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530253 if (flags & SPI_XFER_BEGIN)
Jagan Teki19126992015-08-17 18:31:39 +0530254 spi_cs_activate(dev);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530255
256 while (rx_len > 0) {
257 /* Write the data into TX FIFO - tx threshold is fifo_depth */
258 tx_tvl = 0;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530259 while ((tx_tvl < priv->fifo_depth) && tx_len) {
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530260 if (tx_buf)
261 buf = *tx_buf++;
262 else
263 buf = 0;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530264 writel(buf, &regs->txdr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530265 tx_len--;
266 tx_tvl++;
267 }
268
269 /* Check TX FIFO completion */
270 ts = get_timer(0);
Jagan Tekib1c82da2015-06-27 00:51:31 +0530271 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530272 while (!(status & ZYNQ_SPI_IXR_TXOW_MASK)) {
Ashok Reddy Somaf44bd3b2020-05-18 01:11:00 -0600273 if (get_timer(ts) > ZYNQ_SPI_WAIT) {
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530274 printf("spi_xfer: Timeout! TX FIFO not full\n");
275 return -1;
276 }
Jagan Tekib1c82da2015-06-27 00:51:31 +0530277 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530278 }
279
280 /* Read the data from RX FIFO */
Jagan Tekib1c82da2015-06-27 00:51:31 +0530281 status = readl(&regs->isr);
Lad, Prabhakard2998282016-07-30 22:28:24 +0100282 while ((status & ZYNQ_SPI_IXR_RXNEMPTY_MASK) && rx_len) {
Jagan Tekib1c82da2015-06-27 00:51:31 +0530283 buf = readl(&regs->rxdr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530284 if (rx_buf)
285 *rx_buf++ = buf;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530286 status = readl(&regs->isr);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530287 rx_len--;
288 }
289 }
290
291 if (flags & SPI_XFER_END)
Jagan Tekib1c82da2015-06-27 00:51:31 +0530292 spi_cs_deactivate(dev);
Jagannadha Sutradharudu Teki1465d052013-07-29 23:45:16 +0530293
294 return 0;
295}
Jagan Tekib1c82da2015-06-27 00:51:31 +0530296
297static int zynq_spi_set_speed(struct udevice *bus, uint speed)
298{
Simon Glasscaa4daa2020-12-03 16:55:18 -0700299 struct zynq_spi_platdata *plat = bus->plat;
Jagan Tekib1c82da2015-06-27 00:51:31 +0530300 struct zynq_spi_priv *priv = dev_get_priv(bus);
301 struct zynq_spi_regs *regs = priv->regs;
302 uint32_t confr;
303 u8 baud_rate_val = 0;
304
305 if (speed > plat->frequency)
306 speed = plat->frequency;
307
308 /* Set the clock frequency */
309 confr = readl(&regs->cr);
310 if (speed == 0) {
311 /* Set baudrate x8, if the freq is 0 */
312 baud_rate_val = 0x2;
313 } else if (plat->speed_hz != speed) {
Jagan Teki46ab8a62015-08-17 18:25:03 +0530314 while ((baud_rate_val < ZYNQ_SPI_CR_BAUD_MAX) &&
Jagan Tekib1c82da2015-06-27 00:51:31 +0530315 ((plat->frequency /
316 (2 << baud_rate_val)) > speed))
317 baud_rate_val++;
318 plat->speed_hz = speed / (2 << baud_rate_val);
319 }
Jagan Tekidda62412015-08-17 18:27:47 +0530320 confr &= ~ZYNQ_SPI_CR_BAUD_MASK;
Jagan Teki46ab8a62015-08-17 18:25:03 +0530321 confr |= (baud_rate_val << ZYNQ_SPI_CR_BAUD_SHIFT);
Jagan Tekib1c82da2015-06-27 00:51:31 +0530322
323 writel(confr, &regs->cr);
324 priv->freq = speed;
325
Jagan Tekia22bba82015-09-08 01:38:50 +0530326 debug("zynq_spi_set_speed: regs=%p, speed=%d\n",
327 priv->regs, priv->freq);
Jagan Tekib1c82da2015-06-27 00:51:31 +0530328
329 return 0;
330}
331
332static int zynq_spi_set_mode(struct udevice *bus, uint mode)
333{
334 struct zynq_spi_priv *priv = dev_get_priv(bus);
335 struct zynq_spi_regs *regs = priv->regs;
336 uint32_t confr;
337
338 /* Set the SPI Clock phase and polarities */
339 confr = readl(&regs->cr);
340 confr &= ~(ZYNQ_SPI_CR_CPHA_MASK | ZYNQ_SPI_CR_CPOL_MASK);
341
Jagan Tekia22bba82015-09-08 01:38:50 +0530342 if (mode & SPI_CPHA)
Jagan Tekib1c82da2015-06-27 00:51:31 +0530343 confr |= ZYNQ_SPI_CR_CPHA_MASK;
Jagan Tekia22bba82015-09-08 01:38:50 +0530344 if (mode & SPI_CPOL)
Jagan Tekib1c82da2015-06-27 00:51:31 +0530345 confr |= ZYNQ_SPI_CR_CPOL_MASK;
346
347 writel(confr, &regs->cr);
348 priv->mode = mode;
349
350 debug("zynq_spi_set_mode: regs=%p, mode=%d\n", priv->regs, priv->mode);
351
352 return 0;
353}
354
355static const struct dm_spi_ops zynq_spi_ops = {
356 .claim_bus = zynq_spi_claim_bus,
357 .release_bus = zynq_spi_release_bus,
358 .xfer = zynq_spi_xfer,
359 .set_speed = zynq_spi_set_speed,
360 .set_mode = zynq_spi_set_mode,
361};
362
363static const struct udevice_id zynq_spi_ids[] = {
Michal Simek40b383f2015-07-22 10:47:33 +0200364 { .compatible = "xlnx,zynq-spi-r1p6" },
Michal Simek23ef5ae2015-12-07 13:06:54 +0100365 { .compatible = "cdns,spi-r1p6" },
Jagan Tekib1c82da2015-06-27 00:51:31 +0530366 { }
367};
368
369U_BOOT_DRIVER(zynq_spi) = {
370 .name = "zynq_spi",
371 .id = UCLASS_SPI,
372 .of_match = zynq_spi_ids,
373 .ops = &zynq_spi_ops,
374 .ofdata_to_platdata = zynq_spi_ofdata_to_platdata,
Simon Glasscaa4daa2020-12-03 16:55:18 -0700375 .plat_auto = sizeof(struct zynq_spi_platdata),
Simon Glass41575d82020-12-03 16:55:17 -0700376 .priv_auto = sizeof(struct zynq_spi_priv),
Jagan Tekib1c82da2015-06-27 00:51:31 +0530377 .probe = zynq_spi_probe,
378};