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