Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 |
| 4 | * Altera Corporation <www.altera.com> |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Goldschmidt | baaa3fc | 2019-11-20 22:27:31 +0100 | [diff] [blame] | 8 | #include <clk.h> |
Vignesh Raghavendra | 68f8266 | 2019-12-05 15:46:06 +0530 | [diff] [blame] | 9 | #include <asm-generic/io.h> |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <malloc.h> |
Simon Goldschmidt | 46e56a4 | 2019-03-01 20:12:35 +0100 | [diff] [blame] | 13 | #include <reset.h> |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 14 | #include <spi.h> |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 15 | #include <spi-mem.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 17 | #include <linux/err.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 18 | #include <linux/errno.h> |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 19 | #include <linux/sizes.h> |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 20 | #include "cadence_qspi.h" |
| 21 | |
| 22 | #define CQSPI_STIG_READ 0 |
| 23 | #define CQSPI_STIG_WRITE 1 |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 24 | #define CQSPI_READ 2 |
| 25 | #define CQSPI_WRITE 3 |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 26 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 27 | static int cadence_spi_write_speed(struct udevice *bus, uint hz) |
| 28 | { |
| 29 | struct cadence_spi_platdata *plat = bus->platdata; |
| 30 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
| 31 | |
| 32 | cadence_qspi_apb_config_baudrate_div(priv->regbase, |
Simon Goldschmidt | baaa3fc | 2019-11-20 22:27:31 +0100 | [diff] [blame] | 33 | plat->ref_clk_hz, hz); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 34 | |
| 35 | /* Reconfigure delay timing if speed is changed. */ |
Simon Goldschmidt | baaa3fc | 2019-11-20 22:27:31 +0100 | [diff] [blame] | 36 | cadence_qspi_apb_delay(priv->regbase, plat->ref_clk_hz, hz, |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 37 | plat->tshsl_ns, plat->tsd2d_ns, |
| 38 | plat->tchsh_ns, plat->tslch_ns); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 43 | static int cadence_spi_read_id(void *reg_base, u8 len, u8 *idcode) |
| 44 | { |
| 45 | struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x9F, 1), |
| 46 | SPI_MEM_OP_NO_ADDR, |
| 47 | SPI_MEM_OP_NO_DUMMY, |
| 48 | SPI_MEM_OP_DATA_IN(len, idcode, 1)); |
| 49 | |
| 50 | return cadence_qspi_apb_command_read(reg_base, &op); |
| 51 | } |
| 52 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 53 | /* Calibration sequence to determine the read data capture delay register */ |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 54 | static int spi_calibration(struct udevice *bus, uint hz) |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 55 | { |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 56 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
| 57 | void *base = priv->regbase; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 58 | unsigned int idcode = 0, temp = 0; |
| 59 | int err = 0, i, range_lo = -1, range_hi = -1; |
| 60 | |
| 61 | /* start with slowest clock (1 MHz) */ |
| 62 | cadence_spi_write_speed(bus, 1000000); |
| 63 | |
| 64 | /* configure the read data capture delay register to 0 */ |
| 65 | cadence_qspi_apb_readdata_capture(base, 1, 0); |
| 66 | |
| 67 | /* Enable QSPI */ |
| 68 | cadence_qspi_apb_controller_enable(base); |
| 69 | |
| 70 | /* read the ID which will be our golden value */ |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 71 | err = cadence_spi_read_id(base, 3, (u8 *)&idcode); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 72 | if (err) { |
| 73 | puts("SF: Calibration failed (read)\n"); |
| 74 | return err; |
| 75 | } |
| 76 | |
| 77 | /* use back the intended clock and find low range */ |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 78 | cadence_spi_write_speed(bus, hz); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 79 | for (i = 0; i < CQSPI_READ_CAPTURE_MAX_DELAY; i++) { |
| 80 | /* Disable QSPI */ |
| 81 | cadence_qspi_apb_controller_disable(base); |
| 82 | |
| 83 | /* reconfigure the read data capture delay register */ |
| 84 | cadence_qspi_apb_readdata_capture(base, 1, i); |
| 85 | |
| 86 | /* Enable back QSPI */ |
| 87 | cadence_qspi_apb_controller_enable(base); |
| 88 | |
| 89 | /* issue a RDID to get the ID value */ |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 90 | err = cadence_spi_read_id(base, 3, (u8 *)&temp); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 91 | if (err) { |
| 92 | puts("SF: Calibration failed (read)\n"); |
| 93 | return err; |
| 94 | } |
| 95 | |
| 96 | /* search for range lo */ |
| 97 | if (range_lo == -1 && temp == idcode) { |
| 98 | range_lo = i; |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | /* search for range hi */ |
| 103 | if (range_lo != -1 && temp != idcode) { |
| 104 | range_hi = i - 1; |
| 105 | break; |
| 106 | } |
| 107 | range_hi = i; |
| 108 | } |
| 109 | |
| 110 | if (range_lo == -1) { |
| 111 | puts("SF: Calibration failed (low range)\n"); |
| 112 | return err; |
| 113 | } |
| 114 | |
| 115 | /* Disable QSPI for subsequent initialization */ |
| 116 | cadence_qspi_apb_controller_disable(base); |
| 117 | |
| 118 | /* configure the final value for read data capture delay register */ |
| 119 | cadence_qspi_apb_readdata_capture(base, 1, (range_hi + range_lo) / 2); |
| 120 | debug("SF: Read data capture delay calibrated to %i (%i - %i)\n", |
| 121 | (range_hi + range_lo) / 2, range_lo, range_hi); |
| 122 | |
| 123 | /* just to ensure we do once only when speed or chip select change */ |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 124 | priv->qspi_calibrated_hz = hz; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 125 | priv->qspi_calibrated_cs = spi_chip_select(bus); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static int cadence_spi_set_speed(struct udevice *bus, uint hz) |
| 131 | { |
| 132 | struct cadence_spi_platdata *plat = bus->platdata; |
| 133 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
| 134 | int err; |
| 135 | |
Chin Liang See | cb4ac0b | 2015-10-17 08:32:38 -0500 | [diff] [blame] | 136 | if (hz > plat->max_hz) |
| 137 | hz = plat->max_hz; |
| 138 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 139 | /* Disable QSPI */ |
| 140 | cadence_qspi_apb_controller_disable(priv->regbase); |
| 141 | |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 142 | /* |
| 143 | * Calibration required for different current SCLK speed, requested |
| 144 | * SCLK speed or chip select |
| 145 | */ |
| 146 | if (priv->previous_hz != hz || |
| 147 | priv->qspi_calibrated_hz != hz || |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 148 | priv->qspi_calibrated_cs != spi_chip_select(bus)) { |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 149 | err = spi_calibration(bus, hz); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 150 | if (err) |
| 151 | return err; |
Chin Liang See | 36431f9 | 2015-10-17 08:31:55 -0500 | [diff] [blame] | 152 | |
| 153 | /* prevent calibration run when same as previous request */ |
| 154 | priv->previous_hz = hz; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* Enable QSPI */ |
| 158 | cadence_qspi_apb_controller_enable(priv->regbase); |
| 159 | |
| 160 | debug("%s: speed=%d\n", __func__, hz); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int cadence_spi_probe(struct udevice *bus) |
| 166 | { |
| 167 | struct cadence_spi_platdata *plat = bus->platdata; |
| 168 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
Simon Goldschmidt | 46e56a4 | 2019-03-01 20:12:35 +0100 | [diff] [blame] | 169 | int ret; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 170 | |
| 171 | priv->regbase = plat->regbase; |
| 172 | priv->ahbbase = plat->ahbbase; |
| 173 | |
Simon Goldschmidt | 46e56a4 | 2019-03-01 20:12:35 +0100 | [diff] [blame] | 174 | ret = reset_get_bulk(bus, &priv->resets); |
| 175 | if (ret) |
| 176 | dev_warn(bus, "Can't get reset: %d\n", ret); |
| 177 | else |
| 178 | reset_deassert_bulk(&priv->resets); |
| 179 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 180 | if (!priv->qspi_is_init) { |
| 181 | cadence_qspi_apb_controller_init(plat); |
| 182 | priv->qspi_is_init = 1; |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Simon Goldschmidt | 46e56a4 | 2019-03-01 20:12:35 +0100 | [diff] [blame] | 188 | static int cadence_spi_remove(struct udevice *dev) |
| 189 | { |
| 190 | struct cadence_spi_priv *priv = dev_get_priv(dev); |
| 191 | |
| 192 | return reset_release_bulk(&priv->resets); |
| 193 | } |
| 194 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 195 | static int cadence_spi_set_mode(struct udevice *bus, uint mode) |
| 196 | { |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 197 | struct cadence_spi_platdata *plat = bus->platdata; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 198 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 199 | |
| 200 | /* Disable QSPI */ |
| 201 | cadence_qspi_apb_controller_disable(priv->regbase); |
| 202 | |
| 203 | /* Set SPI mode */ |
Phil Edworthy | eef2edc | 2016-11-29 12:58:31 +0000 | [diff] [blame] | 204 | cadence_qspi_apb_set_clk_mode(priv->regbase, mode); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 205 | |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 206 | /* Enable Direct Access Controller */ |
| 207 | if (plat->use_dac_mode) |
| 208 | cadence_qspi_apb_dac_mode_enable(priv->regbase); |
| 209 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 210 | /* Enable QSPI */ |
| 211 | cadence_qspi_apb_controller_enable(priv->regbase); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 216 | static int cadence_spi_mem_exec_op(struct spi_slave *spi, |
| 217 | const struct spi_mem_op *op) |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 218 | { |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 219 | struct udevice *bus = spi->dev->parent; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 220 | struct cadence_spi_platdata *plat = bus->platdata; |
| 221 | struct cadence_spi_priv *priv = dev_get_priv(bus); |
| 222 | void *base = priv->regbase; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 223 | int err = 0; |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 224 | u32 mode; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 225 | |
| 226 | /* Set Chip select */ |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 227 | cadence_qspi_apb_chipselect(base, spi_chip_select(spi->dev), |
Jason Rush | 1b4df5e | 2018-01-23 17:13:09 -0600 | [diff] [blame] | 228 | plat->is_decoded_cs); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 229 | |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 230 | if (op->data.dir == SPI_MEM_DATA_IN && op->data.buf.in) { |
| 231 | if (!op->addr.nbytes) |
| 232 | mode = CQSPI_STIG_READ; |
| 233 | else |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 234 | mode = CQSPI_READ; |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 235 | } else { |
| 236 | if (!op->addr.nbytes || !op->data.buf.out) |
| 237 | mode = CQSPI_STIG_WRITE; |
| 238 | else |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 239 | mode = CQSPI_WRITE; |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 240 | } |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 241 | |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 242 | switch (mode) { |
| 243 | case CQSPI_STIG_READ: |
| 244 | err = cadence_qspi_apb_command_read(base, op); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 245 | break; |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 246 | case CQSPI_STIG_WRITE: |
| 247 | err = cadence_qspi_apb_command_write(base, op); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 248 | break; |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 249 | case CQSPI_READ: |
| 250 | err = cadence_qspi_apb_read_setup(plat, op); |
| 251 | if (!err) |
| 252 | err = cadence_qspi_apb_read_execute(plat, op); |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 253 | break; |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 254 | case CQSPI_WRITE: |
| 255 | err = cadence_qspi_apb_write_setup(plat, op); |
| 256 | if (!err) |
| 257 | err = cadence_qspi_apb_write_execute(plat, op); |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 258 | break; |
| 259 | default: |
| 260 | err = -1; |
| 261 | break; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | static int cadence_spi_ofdata_to_platdata(struct udevice *bus) |
| 268 | { |
| 269 | struct cadence_spi_platdata *plat = bus->platdata; |
Simon Goldschmidt | f9d7d3a | 2019-05-09 22:11:56 +0200 | [diff] [blame] | 270 | ofnode subnode; |
Simon Goldschmidt | baaa3fc | 2019-11-20 22:27:31 +0100 | [diff] [blame] | 271 | struct clk clk; |
| 272 | int ret; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 273 | |
Ley Foon Tan | 3bca8f5 | 2018-05-07 17:42:55 +0800 | [diff] [blame] | 274 | plat->regbase = (void *)devfdt_get_addr_index(bus, 0); |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 275 | plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1, |
| 276 | &plat->ahbsize); |
Simon Goldschmidt | f9d7d3a | 2019-05-09 22:11:56 +0200 | [diff] [blame] | 277 | plat->is_decoded_cs = dev_read_bool(bus, "cdns,is-decoded-cs"); |
| 278 | plat->fifo_depth = dev_read_u32_default(bus, "cdns,fifo-depth", 128); |
| 279 | plat->fifo_width = dev_read_u32_default(bus, "cdns,fifo-width", 4); |
| 280 | plat->trigger_address = dev_read_u32_default(bus, |
| 281 | "cdns,trigger-address", |
| 282 | 0); |
Vignesh Raghavendra | 6b7df22 | 2020-01-27 10:36:40 +0530 | [diff] [blame] | 283 | /* Use DAC mode only when MMIO window is at least 8M wide */ |
| 284 | if (plat->ahbsize >= SZ_8M) |
| 285 | plat->use_dac_mode = true; |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 286 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 287 | /* All other paramters are embedded in the child node */ |
Simon Goldschmidt | f9d7d3a | 2019-05-09 22:11:56 +0200 | [diff] [blame] | 288 | subnode = dev_read_first_subnode(bus); |
| 289 | if (!ofnode_valid(subnode)) { |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 290 | printf("Error: subnode with SPI flash config missing!\n"); |
| 291 | return -ENODEV; |
| 292 | } |
| 293 | |
Chin Liang See | f1d200f | 2015-10-17 08:32:14 -0500 | [diff] [blame] | 294 | /* Use 500 KHz as a suitable default */ |
Simon Goldschmidt | f9d7d3a | 2019-05-09 22:11:56 +0200 | [diff] [blame] | 295 | plat->max_hz = ofnode_read_u32_default(subnode, "spi-max-frequency", |
| 296 | 500000); |
Chin Liang See | f1d200f | 2015-10-17 08:32:14 -0500 | [diff] [blame] | 297 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 298 | /* Read other parameters from DT */ |
Simon Goldschmidt | f9d7d3a | 2019-05-09 22:11:56 +0200 | [diff] [blame] | 299 | plat->page_size = ofnode_read_u32_default(subnode, "page-size", 256); |
| 300 | plat->block_size = ofnode_read_u32_default(subnode, "block-size", 16); |
| 301 | plat->tshsl_ns = ofnode_read_u32_default(subnode, "cdns,tshsl-ns", |
| 302 | 200); |
| 303 | plat->tsd2d_ns = ofnode_read_u32_default(subnode, "cdns,tsd2d-ns", |
| 304 | 255); |
| 305 | plat->tchsh_ns = ofnode_read_u32_default(subnode, "cdns,tchsh-ns", 20); |
| 306 | plat->tslch_ns = ofnode_read_u32_default(subnode, "cdns,tslch-ns", 20); |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 307 | |
Simon Goldschmidt | baaa3fc | 2019-11-20 22:27:31 +0100 | [diff] [blame] | 308 | ret = clk_get_by_index(bus, 0, &clk); |
| 309 | if (ret) { |
| 310 | #ifdef CONFIG_CQSPI_REF_CLK |
| 311 | plat->ref_clk_hz = CONFIG_CQSPI_REF_CLK; |
| 312 | #else |
| 313 | return ret; |
| 314 | #endif |
| 315 | } else { |
| 316 | plat->ref_clk_hz = clk_get_rate(&clk); |
| 317 | clk_free(&clk); |
| 318 | if (IS_ERR_VALUE(plat->ref_clk_hz)) |
| 319 | return plat->ref_clk_hz; |
| 320 | } |
| 321 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 322 | debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n", |
| 323 | __func__, plat->regbase, plat->ahbbase, plat->max_hz, |
| 324 | plat->page_size); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 329 | static const struct spi_controller_mem_ops cadence_spi_mem_ops = { |
| 330 | .exec_op = cadence_spi_mem_exec_op, |
| 331 | }; |
| 332 | |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 333 | static const struct dm_spi_ops cadence_spi_ops = { |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 334 | .set_speed = cadence_spi_set_speed, |
| 335 | .set_mode = cadence_spi_set_mode, |
Vignesh Raghavendra | 27516a3 | 2020-01-27 10:36:39 +0530 | [diff] [blame] | 336 | .mem_ops = &cadence_spi_mem_ops, |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 337 | /* |
| 338 | * cs_info is not needed, since we require all chip selects to be |
| 339 | * in the device tree explicitly |
| 340 | */ |
| 341 | }; |
| 342 | |
| 343 | static const struct udevice_id cadence_spi_ids[] = { |
Simon Goldschmidt | 454c9b3 | 2018-11-02 11:54:51 +0100 | [diff] [blame] | 344 | { .compatible = "cdns,qspi-nor" }, |
Vignesh Raghavendra | 99276f0 | 2019-12-05 15:46:07 +0530 | [diff] [blame] | 345 | { .compatible = "ti,am654-ospi" }, |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 346 | { } |
| 347 | }; |
| 348 | |
| 349 | U_BOOT_DRIVER(cadence_spi) = { |
| 350 | .name = "cadence_spi", |
| 351 | .id = UCLASS_SPI, |
| 352 | .of_match = cadence_spi_ids, |
| 353 | .ops = &cadence_spi_ops, |
| 354 | .ofdata_to_platdata = cadence_spi_ofdata_to_platdata, |
| 355 | .platdata_auto_alloc_size = sizeof(struct cadence_spi_platdata), |
| 356 | .priv_auto_alloc_size = sizeof(struct cadence_spi_priv), |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 357 | .probe = cadence_spi_probe, |
Simon Goldschmidt | 46e56a4 | 2019-03-01 20:12:35 +0100 | [diff] [blame] | 358 | .remove = cadence_spi_remove, |
| 359 | .flags = DM_FLAG_OS_PREPARE, |
Stefan Roese | 1c60fe7 | 2014-11-07 12:37:49 +0100 | [diff] [blame] | 360 | }; |