blob: 907f5dadc4fb4bf000543683e48b5cff30fd8681 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese1c60fe72014-11-07 12:37:49 +01002/*
3 * Copyright (C) 2012
4 * Altera Corporation <www.altera.com>
Stefan Roese1c60fe72014-11-07 12:37:49 +01005 */
6
7#include <common.h>
Simon Goldschmidtbaaa3fc2019-11-20 22:27:31 +01008#include <clk.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Vignesh Raghavendra68f82662019-12-05 15:46:06 +053010#include <asm-generic/io.h>
Stefan Roese1c60fe72014-11-07 12:37:49 +010011#include <dm.h>
12#include <fdtdec.h>
13#include <malloc.h>
Simon Goldschmidt46e56a42019-03-01 20:12:35 +010014#include <reset.h>
Stefan Roese1c60fe72014-11-07 12:37:49 +010015#include <spi.h>
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053016#include <spi-mem.h>
Simon Glass9bc15642020-02-03 07:36:16 -070017#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070018#include <linux/err.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053020#include <linux/sizes.h>
T Karthik Reddy3b49fbf2022-05-12 04:05:34 -060021#include <zynqmp_firmware.h>
Stefan Roese1c60fe72014-11-07 12:37:49 +010022#include "cadence_qspi.h"
T Karthik Reddy3b49fbf2022-05-12 04:05:34 -060023#include <dt-bindings/power/xlnx-versal-power.h>
Stefan Roese1c60fe72014-11-07 12:37:49 +010024
Pratyush Yadav8dcf3e22021-06-26 00:47:08 +053025#define NSEC_PER_SEC 1000000000L
26
Stefan Roese1c60fe72014-11-07 12:37:49 +010027#define CQSPI_STIG_READ 0
28#define CQSPI_STIG_WRITE 1
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053029#define CQSPI_READ 2
30#define CQSPI_WRITE 3
Stefan Roese1c60fe72014-11-07 12:37:49 +010031
T Karthik Reddy73701e72022-05-12 04:05:32 -060032__weak int cadence_qspi_apb_dma_read(struct cadence_spi_plat *plat,
33 const struct spi_mem_op *op)
34{
35 return 0;
36}
37
T Karthik Reddy3d71b2d2022-05-12 04:05:33 -060038__weak int cadence_qspi_versal_flash_reset(struct udevice *dev)
39{
40 return 0;
41}
42
Stefan Roese1c60fe72014-11-07 12:37:49 +010043static int cadence_spi_write_speed(struct udevice *bus, uint hz)
44{
Simon Glass95588622020-12-22 19:30:28 -070045 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +010046 struct cadence_spi_priv *priv = dev_get_priv(bus);
47
48 cadence_qspi_apb_config_baudrate_div(priv->regbase,
Simon Goldschmidtbaaa3fc2019-11-20 22:27:31 +010049 plat->ref_clk_hz, hz);
Stefan Roese1c60fe72014-11-07 12:37:49 +010050
51 /* Reconfigure delay timing if speed is changed. */
Simon Goldschmidtbaaa3fc2019-11-20 22:27:31 +010052 cadence_qspi_apb_delay(priv->regbase, plat->ref_clk_hz, hz,
Stefan Roese1c60fe72014-11-07 12:37:49 +010053 plat->tshsl_ns, plat->tsd2d_ns,
54 plat->tchsh_ns, plat->tslch_ns);
55
56 return 0;
57}
58
Pratyush Yadave1814ad2021-06-26 00:47:09 +053059static int cadence_spi_read_id(struct cadence_spi_plat *plat, u8 len,
60 u8 *idcode)
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053061{
62 struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x9F, 1),
63 SPI_MEM_OP_NO_ADDR,
64 SPI_MEM_OP_NO_DUMMY,
65 SPI_MEM_OP_DATA_IN(len, idcode, 1));
66
Pratyush Yadave1814ad2021-06-26 00:47:09 +053067 return cadence_qspi_apb_command_read(plat, &op);
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053068}
69
Stefan Roese1c60fe72014-11-07 12:37:49 +010070/* Calibration sequence to determine the read data capture delay register */
Chin Liang See36431f92015-10-17 08:31:55 -050071static int spi_calibration(struct udevice *bus, uint hz)
Stefan Roese1c60fe72014-11-07 12:37:49 +010072{
Stefan Roese1c60fe72014-11-07 12:37:49 +010073 struct cadence_spi_priv *priv = dev_get_priv(bus);
Pratyush Yadave1814ad2021-06-26 00:47:09 +053074 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +010075 void *base = priv->regbase;
Stefan Roese1c60fe72014-11-07 12:37:49 +010076 unsigned int idcode = 0, temp = 0;
77 int err = 0, i, range_lo = -1, range_hi = -1;
78
79 /* start with slowest clock (1 MHz) */
80 cadence_spi_write_speed(bus, 1000000);
81
82 /* configure the read data capture delay register to 0 */
83 cadence_qspi_apb_readdata_capture(base, 1, 0);
84
85 /* Enable QSPI */
86 cadence_qspi_apb_controller_enable(base);
87
88 /* read the ID which will be our golden value */
Pratyush Yadave1814ad2021-06-26 00:47:09 +053089 err = cadence_spi_read_id(plat, 3, (u8 *)&idcode);
Stefan Roese1c60fe72014-11-07 12:37:49 +010090 if (err) {
91 puts("SF: Calibration failed (read)\n");
92 return err;
93 }
94
95 /* use back the intended clock and find low range */
Chin Liang See36431f92015-10-17 08:31:55 -050096 cadence_spi_write_speed(bus, hz);
Stefan Roese1c60fe72014-11-07 12:37:49 +010097 for (i = 0; i < CQSPI_READ_CAPTURE_MAX_DELAY; i++) {
98 /* Disable QSPI */
99 cadence_qspi_apb_controller_disable(base);
100
101 /* reconfigure the read data capture delay register */
102 cadence_qspi_apb_readdata_capture(base, 1, i);
103
104 /* Enable back QSPI */
105 cadence_qspi_apb_controller_enable(base);
106
107 /* issue a RDID to get the ID value */
Pratyush Yadave1814ad2021-06-26 00:47:09 +0530108 err = cadence_spi_read_id(plat, 3, (u8 *)&temp);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100109 if (err) {
110 puts("SF: Calibration failed (read)\n");
111 return err;
112 }
113
114 /* search for range lo */
115 if (range_lo == -1 && temp == idcode) {
116 range_lo = i;
117 continue;
118 }
119
120 /* search for range hi */
121 if (range_lo != -1 && temp != idcode) {
122 range_hi = i - 1;
123 break;
124 }
125 range_hi = i;
126 }
127
128 if (range_lo == -1) {
129 puts("SF: Calibration failed (low range)\n");
130 return err;
131 }
132
133 /* Disable QSPI for subsequent initialization */
134 cadence_qspi_apb_controller_disable(base);
135
136 /* configure the final value for read data capture delay register */
137 cadence_qspi_apb_readdata_capture(base, 1, (range_hi + range_lo) / 2);
138 debug("SF: Read data capture delay calibrated to %i (%i - %i)\n",
139 (range_hi + range_lo) / 2, range_lo, range_hi);
140
141 /* just to ensure we do once only when speed or chip select change */
Chin Liang See36431f92015-10-17 08:31:55 -0500142 priv->qspi_calibrated_hz = hz;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100143 priv->qspi_calibrated_cs = spi_chip_select(bus);
144
145 return 0;
146}
147
148static int cadence_spi_set_speed(struct udevice *bus, uint hz)
149{
Simon Glass95588622020-12-22 19:30:28 -0700150 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100151 struct cadence_spi_priv *priv = dev_get_priv(bus);
152 int err;
153
T Karthik Reddyb005b042022-05-12 04:05:35 -0600154 if (!hz || hz > plat->max_hz)
Chin Liang Seecb4ac0b2015-10-17 08:32:38 -0500155 hz = plat->max_hz;
156
Stefan Roese1c60fe72014-11-07 12:37:49 +0100157 /* Disable QSPI */
158 cadence_qspi_apb_controller_disable(priv->regbase);
159
Chin Liang See36431f92015-10-17 08:31:55 -0500160 /*
Pratyush Yadav8e0be9e2021-06-26 00:47:07 +0530161 * If the device tree already provides a read delay value, use that
162 * instead of calibrating.
Chin Liang See36431f92015-10-17 08:31:55 -0500163 */
Pratyush Yadav8e0be9e2021-06-26 00:47:07 +0530164 if (plat->read_delay >= 0) {
165 cadence_spi_write_speed(bus, hz);
166 cadence_qspi_apb_readdata_capture(priv->regbase, 1,
167 plat->read_delay);
168 } else if (priv->previous_hz != hz ||
169 priv->qspi_calibrated_hz != hz ||
170 priv->qspi_calibrated_cs != spi_chip_select(bus)) {
171 /*
172 * Calibration required for different current SCLK speed,
173 * requested SCLK speed or chip select
174 */
Chin Liang See36431f92015-10-17 08:31:55 -0500175 err = spi_calibration(bus, hz);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100176 if (err)
177 return err;
Chin Liang See36431f92015-10-17 08:31:55 -0500178
179 /* prevent calibration run when same as previous request */
180 priv->previous_hz = hz;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100181 }
182
183 /* Enable QSPI */
184 cadence_qspi_apb_controller_enable(priv->regbase);
185
186 debug("%s: speed=%d\n", __func__, hz);
187
188 return 0;
189}
190
191static int cadence_spi_probe(struct udevice *bus)
192{
Simon Glass95588622020-12-22 19:30:28 -0700193 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100194 struct cadence_spi_priv *priv = dev_get_priv(bus);
Pratyush Yadav5d9e7782020-02-24 12:40:51 +0530195 struct clk clk;
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100196 int ret;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100197
198 priv->regbase = plat->regbase;
199 priv->ahbbase = plat->ahbbase;
200
T Karthik Reddy3b49fbf2022-05-12 04:05:34 -0600201 if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE))
202 xilinx_pm_request(PM_REQUEST_NODE, PM_DEV_OSPI,
203 ZYNQMP_PM_CAPABILITY_ACCESS, ZYNQMP_PM_MAX_QOS,
204 ZYNQMP_PM_REQUEST_ACK_NO, NULL);
205
Pratyush Yadav5d9e7782020-02-24 12:40:51 +0530206 if (plat->ref_clk_hz == 0) {
207 ret = clk_get_by_index(bus, 0, &clk);
208 if (ret) {
Tom Rini3fb5b2f2022-03-30 18:07:23 -0400209#ifdef CONFIG_HAS_CQSPI_REF_CLK
Pratyush Yadav5d9e7782020-02-24 12:40:51 +0530210 plat->ref_clk_hz = CONFIG_CQSPI_REF_CLK;
Tom Rini3fb5b2f2022-03-30 18:07:23 -0400211#elif defined(CONFIG_ARCH_SOCFPGA)
212 plat->ref_clk_hz = cm_get_qspi_controller_clk_hz();
Pratyush Yadav5d9e7782020-02-24 12:40:51 +0530213#else
214 return ret;
215#endif
216 } else {
217 plat->ref_clk_hz = clk_get_rate(&clk);
218 clk_free(&clk);
219 if (IS_ERR_VALUE(plat->ref_clk_hz))
220 return plat->ref_clk_hz;
221 }
222 }
223
Christian Gmeinerd560a672022-02-22 17:23:25 +0100224 priv->resets = devm_reset_bulk_get_optional(bus);
225 if (priv->resets)
226 reset_deassert_bulk(priv->resets);
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100227
Stefan Roese1c60fe72014-11-07 12:37:49 +0100228 if (!priv->qspi_is_init) {
229 cadence_qspi_apb_controller_init(plat);
230 priv->qspi_is_init = 1;
231 }
232
Pratyush Yadav8dcf3e22021-06-26 00:47:08 +0530233 plat->wr_delay = 50 * DIV_ROUND_UP(NSEC_PER_SEC, plat->ref_clk_hz);
234
T Karthik Reddy3d71b2d2022-05-12 04:05:33 -0600235 if (CONFIG_IS_ENABLED(ARCH_VERSAL)) {
236 /* Versal platform uses spi calibration to set read delay */
237 if (plat->read_delay >= 0)
238 plat->read_delay = -1;
239 /* Reset ospi flash device */
240 ret = cadence_qspi_versal_flash_reset(bus);
241 if (ret)
242 return ret;
243 }
244
Stefan Roese1c60fe72014-11-07 12:37:49 +0100245 return 0;
246}
247
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100248static int cadence_spi_remove(struct udevice *dev)
249{
250 struct cadence_spi_priv *priv = dev_get_priv(dev);
Christian Gmeinerd560a672022-02-22 17:23:25 +0100251 int ret = 0;
252
253 if (priv->resets)
254 ret = reset_release_bulk(priv->resets);
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100255
Christian Gmeinerd560a672022-02-22 17:23:25 +0100256 return ret;
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100257}
258
Stefan Roese1c60fe72014-11-07 12:37:49 +0100259static int cadence_spi_set_mode(struct udevice *bus, uint mode)
260{
Simon Glass95588622020-12-22 19:30:28 -0700261 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100262 struct cadence_spi_priv *priv = dev_get_priv(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100263
264 /* Disable QSPI */
265 cadence_qspi_apb_controller_disable(priv->regbase);
266
267 /* Set SPI mode */
Phil Edworthyeef2edc2016-11-29 12:58:31 +0000268 cadence_qspi_apb_set_clk_mode(priv->regbase, mode);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100269
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530270 /* Enable Direct Access Controller */
271 if (plat->use_dac_mode)
272 cadence_qspi_apb_dac_mode_enable(priv->regbase);
273
Stefan Roese1c60fe72014-11-07 12:37:49 +0100274 /* Enable QSPI */
275 cadence_qspi_apb_controller_enable(priv->regbase);
276
277 return 0;
278}
279
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530280static int cadence_spi_mem_exec_op(struct spi_slave *spi,
281 const struct spi_mem_op *op)
Stefan Roese1c60fe72014-11-07 12:37:49 +0100282{
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530283 struct udevice *bus = spi->dev->parent;
Simon Glass95588622020-12-22 19:30:28 -0700284 struct cadence_spi_plat *plat = dev_get_plat(bus);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100285 struct cadence_spi_priv *priv = dev_get_priv(bus);
286 void *base = priv->regbase;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100287 int err = 0;
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530288 u32 mode;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100289
290 /* Set Chip select */
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530291 cadence_qspi_apb_chipselect(base, spi_chip_select(spi->dev),
Jason Rush1b4df5e2018-01-23 17:13:09 -0600292 plat->is_decoded_cs);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100293
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530294 if (op->data.dir == SPI_MEM_DATA_IN && op->data.buf.in) {
295 if (!op->addr.nbytes)
296 mode = CQSPI_STIG_READ;
297 else
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530298 mode = CQSPI_READ;
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530299 } else {
300 if (!op->addr.nbytes || !op->data.buf.out)
301 mode = CQSPI_STIG_WRITE;
302 else
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530303 mode = CQSPI_WRITE;
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530304 }
Stefan Roese1c60fe72014-11-07 12:37:49 +0100305
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530306 switch (mode) {
307 case CQSPI_STIG_READ:
Pratyush Yadave1814ad2021-06-26 00:47:09 +0530308 err = cadence_qspi_apb_command_read_setup(plat, op);
309 if (!err)
310 err = cadence_qspi_apb_command_read(plat, op);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100311 break;
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530312 case CQSPI_STIG_WRITE:
Pratyush Yadave1814ad2021-06-26 00:47:09 +0530313 err = cadence_qspi_apb_command_write_setup(plat, op);
314 if (!err)
315 err = cadence_qspi_apb_command_write(plat, op);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100316 break;
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530317 case CQSPI_READ:
318 err = cadence_qspi_apb_read_setup(plat, op);
T Karthik Reddy73701e72022-05-12 04:05:32 -0600319 if (!err) {
320 if (plat->is_dma)
321 err = cadence_qspi_apb_dma_read(plat, op);
322 else
323 err = cadence_qspi_apb_read_execute(plat, op);
324 }
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530325 break;
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530326 case CQSPI_WRITE:
327 err = cadence_qspi_apb_write_setup(plat, op);
328 if (!err)
329 err = cadence_qspi_apb_write_execute(plat, op);
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530330 break;
331 default:
332 err = -1;
333 break;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100334 }
335
336 return err;
337}
338
Pratyush Yadave1814ad2021-06-26 00:47:09 +0530339static bool cadence_spi_mem_supports_op(struct spi_slave *slave,
340 const struct spi_mem_op *op)
341{
342 bool all_true, all_false;
343
344 all_true = op->cmd.dtr && op->addr.dtr && op->dummy.dtr &&
345 op->data.dtr;
346 all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
347 !op->data.dtr;
348
349 /* Mixed DTR modes not supported. */
350 if (!(all_true || all_false))
351 return false;
352
353 if (all_true)
354 return spi_mem_dtr_supports_op(slave, op);
355 else
356 return spi_mem_default_supports_op(slave, op);
357}
358
Simon Glassaad29ae2020-12-03 16:55:21 -0700359static int cadence_spi_of_to_plat(struct udevice *bus)
Stefan Roese1c60fe72014-11-07 12:37:49 +0100360{
Simon Glass95588622020-12-22 19:30:28 -0700361 struct cadence_spi_plat *plat = dev_get_plat(bus);
Simon Goldschmidtf9d7d3a2019-05-09 22:11:56 +0200362 ofnode subnode;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100363
Ley Foon Tan3bca8f52018-05-07 17:42:55 +0800364 plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530365 plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
366 &plat->ahbsize);
Simon Goldschmidtf9d7d3a2019-05-09 22:11:56 +0200367 plat->is_decoded_cs = dev_read_bool(bus, "cdns,is-decoded-cs");
368 plat->fifo_depth = dev_read_u32_default(bus, "cdns,fifo-depth", 128);
369 plat->fifo_width = dev_read_u32_default(bus, "cdns,fifo-width", 4);
370 plat->trigger_address = dev_read_u32_default(bus,
371 "cdns,trigger-address",
372 0);
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +0530373 /* Use DAC mode only when MMIO window is at least 8M wide */
374 if (plat->ahbsize >= SZ_8M)
375 plat->use_dac_mode = true;
Stefan Roese1c60fe72014-11-07 12:37:49 +0100376
T Karthik Reddy73701e72022-05-12 04:05:32 -0600377 plat->is_dma = dev_read_bool(bus, "cdns,is-dma");
378
Stefan Roese1c60fe72014-11-07 12:37:49 +0100379 /* All other paramters are embedded in the child node */
Simon Goldschmidtf9d7d3a2019-05-09 22:11:56 +0200380 subnode = dev_read_first_subnode(bus);
381 if (!ofnode_valid(subnode)) {
Stefan Roese1c60fe72014-11-07 12:37:49 +0100382 printf("Error: subnode with SPI flash config missing!\n");
383 return -ENODEV;
384 }
385
Chin Liang Seef1d200f2015-10-17 08:32:14 -0500386 /* Use 500 KHz as a suitable default */
Simon Goldschmidtf9d7d3a2019-05-09 22:11:56 +0200387 plat->max_hz = ofnode_read_u32_default(subnode, "spi-max-frequency",
388 500000);
Chin Liang Seef1d200f2015-10-17 08:32:14 -0500389
Stefan Roese1c60fe72014-11-07 12:37:49 +0100390 /* Read other parameters from DT */
Simon Goldschmidtf9d7d3a2019-05-09 22:11:56 +0200391 plat->page_size = ofnode_read_u32_default(subnode, "page-size", 256);
392 plat->block_size = ofnode_read_u32_default(subnode, "block-size", 16);
393 plat->tshsl_ns = ofnode_read_u32_default(subnode, "cdns,tshsl-ns",
394 200);
395 plat->tsd2d_ns = ofnode_read_u32_default(subnode, "cdns,tsd2d-ns",
396 255);
397 plat->tchsh_ns = ofnode_read_u32_default(subnode, "cdns,tchsh-ns", 20);
398 plat->tslch_ns = ofnode_read_u32_default(subnode, "cdns,tslch-ns", 20);
Pratyush Yadav8e0be9e2021-06-26 00:47:07 +0530399 /*
400 * Read delay should be an unsigned value but we use a signed integer
401 * so that negative values can indicate that the device tree did not
402 * specify any signed values and we need to perform the calibration
403 * sequence to find it out.
404 */
405 plat->read_delay = ofnode_read_s32_default(subnode, "cdns,read-delay",
406 -1);
Stefan Roese1c60fe72014-11-07 12:37:49 +0100407
408 debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n",
409 __func__, plat->regbase, plat->ahbbase, plat->max_hz,
410 plat->page_size);
411
412 return 0;
413}
414
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530415static const struct spi_controller_mem_ops cadence_spi_mem_ops = {
416 .exec_op = cadence_spi_mem_exec_op,
Pratyush Yadave1814ad2021-06-26 00:47:09 +0530417 .supports_op = cadence_spi_mem_supports_op,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530418};
419
Stefan Roese1c60fe72014-11-07 12:37:49 +0100420static const struct dm_spi_ops cadence_spi_ops = {
Stefan Roese1c60fe72014-11-07 12:37:49 +0100421 .set_speed = cadence_spi_set_speed,
422 .set_mode = cadence_spi_set_mode,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +0530423 .mem_ops = &cadence_spi_mem_ops,
Stefan Roese1c60fe72014-11-07 12:37:49 +0100424 /*
425 * cs_info is not needed, since we require all chip selects to be
426 * in the device tree explicitly
427 */
428};
429
430static const struct udevice_id cadence_spi_ids[] = {
Simon Goldschmidt454c9b32018-11-02 11:54:51 +0100431 { .compatible = "cdns,qspi-nor" },
Vignesh Raghavendra99276f02019-12-05 15:46:07 +0530432 { .compatible = "ti,am654-ospi" },
Stefan Roese1c60fe72014-11-07 12:37:49 +0100433 { }
434};
435
436U_BOOT_DRIVER(cadence_spi) = {
437 .name = "cadence_spi",
438 .id = UCLASS_SPI,
439 .of_match = cadence_spi_ids,
440 .ops = &cadence_spi_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700441 .of_to_plat = cadence_spi_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700442 .plat_auto = sizeof(struct cadence_spi_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700443 .priv_auto = sizeof(struct cadence_spi_priv),
Stefan Roese1c60fe72014-11-07 12:37:49 +0100444 .probe = cadence_spi_probe,
Simon Goldschmidt46e56a42019-03-01 20:12:35 +0100445 .remove = cadence_spi_remove,
446 .flags = DM_FLAG_OS_PREPARE,
Stefan Roese1c60fe72014-11-07 12:37:49 +0100447};