Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
| 6 | * |
| 7 | * Derived from drivers/spi/mpc8xxx_spi.c |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 11 | #include <dm.h> |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 12 | #include <malloc.h> |
| 13 | #include <spi.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 14 | #include <asm/io.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 15 | #include <asm/arch/soc.h> |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 16 | #ifdef CONFIG_KIRKWOOD |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 17 | #include <asm/arch/mpp.h> |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 18 | #endif |
Stefan Roese | 2da296f | 2014-10-22 12:13:07 +0200 | [diff] [blame] | 19 | #include <asm/arch-mvebu/spi.h> |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 20 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 21 | static void _spi_cs_activate(struct kwspi_registers *reg) |
| 22 | { |
| 23 | setbits_le32(®->ctrl, KWSPI_CSN_ACT); |
| 24 | } |
| 25 | |
| 26 | static void _spi_cs_deactivate(struct kwspi_registers *reg) |
| 27 | { |
| 28 | clrbits_le32(®->ctrl, KWSPI_CSN_ACT); |
| 29 | } |
| 30 | |
| 31 | static int _spi_xfer(struct kwspi_registers *reg, unsigned int bitlen, |
| 32 | const void *dout, void *din, unsigned long flags) |
| 33 | { |
| 34 | unsigned int tmpdout, tmpdin; |
| 35 | int tm, isread = 0; |
| 36 | |
| 37 | debug("spi_xfer: dout %p din %p bitlen %u\n", dout, din, bitlen); |
| 38 | |
| 39 | if (flags & SPI_XFER_BEGIN) |
| 40 | _spi_cs_activate(reg); |
| 41 | |
| 42 | /* |
| 43 | * handle data in 8-bit chunks |
| 44 | * TBD: 2byte xfer mode to be enabled |
| 45 | */ |
| 46 | clrsetbits_le32(®->cfg, KWSPI_XFERLEN_MASK, KWSPI_XFERLEN_1BYTE); |
| 47 | |
| 48 | while (bitlen > 4) { |
| 49 | debug("loopstart bitlen %d\n", bitlen); |
| 50 | tmpdout = 0; |
| 51 | |
| 52 | /* Shift data so it's msb-justified */ |
| 53 | if (dout) |
| 54 | tmpdout = *(u32 *)dout & 0xff; |
| 55 | |
| 56 | clrbits_le32(®->irq_cause, KWSPI_SMEMRDIRQ); |
| 57 | writel(tmpdout, ®->dout); /* Write the data out */ |
| 58 | debug("*** spi_xfer: ... %08x written, bitlen %d\n", |
| 59 | tmpdout, bitlen); |
| 60 | |
| 61 | /* |
| 62 | * Wait for SPI transmit to get out |
| 63 | * or time out (1 second = 1000 ms) |
| 64 | * The NE event must be read and cleared first |
| 65 | */ |
| 66 | for (tm = 0, isread = 0; tm < KWSPI_TIMEOUT; ++tm) { |
| 67 | if (readl(®->irq_cause) & KWSPI_SMEMRDIRQ) { |
| 68 | isread = 1; |
| 69 | tmpdin = readl(®->din); |
| 70 | debug("spi_xfer: din %p..%08x read\n", |
| 71 | din, tmpdin); |
| 72 | |
| 73 | if (din) { |
| 74 | *((u8 *)din) = (u8)tmpdin; |
| 75 | din += 1; |
| 76 | } |
| 77 | if (dout) |
| 78 | dout += 1; |
| 79 | bitlen -= 8; |
| 80 | } |
| 81 | if (isread) |
| 82 | break; |
| 83 | } |
| 84 | if (tm >= KWSPI_TIMEOUT) |
| 85 | printf("*** spi_xfer: Time out during SPI transfer\n"); |
| 86 | |
| 87 | debug("loopend bitlen %d\n", bitlen); |
| 88 | } |
| 89 | |
| 90 | if (flags & SPI_XFER_END) |
| 91 | _spi_cs_deactivate(reg); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | #ifndef CONFIG_DM_SPI |
| 97 | |
Stefan Roese | 1b258d5 | 2014-10-22 12:13:12 +0200 | [diff] [blame] | 98 | static struct kwspi_registers *spireg = |
| 99 | (struct kwspi_registers *)MVEBU_SPI_BASE; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 100 | |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 101 | #ifdef CONFIG_KIRKWOOD |
Stefan Roese | 8edd6e0 | 2014-09-02 14:02:52 +0200 | [diff] [blame] | 102 | static u32 cs_spi_mpp_back[2]; |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 103 | #endif |
Valentin Longchamp | 1ad0acd | 2012-06-01 01:31:01 +0000 | [diff] [blame] | 104 | |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 105 | struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, |
| 106 | unsigned int max_hz, unsigned int mode) |
| 107 | { |
| 108 | struct spi_slave *slave; |
| 109 | u32 data; |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 110 | #ifdef CONFIG_KIRKWOOD |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 111 | static const u32 kwspi_mpp_config[2][2] = { |
| 112 | { MPP0_SPI_SCn, 0 }, /* if cs == 0 */ |
| 113 | { MPP7_SPI_SCn, 0 } /* if cs != 0 */ |
| 114 | }; |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 115 | #endif |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 116 | |
| 117 | if (!spi_cs_is_valid(bus, cs)) |
| 118 | return NULL; |
| 119 | |
Simon Glass | d034a95 | 2013-03-18 19:23:40 +0000 | [diff] [blame] | 120 | slave = spi_alloc_slave_base(bus, cs); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 121 | if (!slave) |
| 122 | return NULL; |
| 123 | |
Stefan Roese | b85f0cb | 2014-09-02 14:02:51 +0200 | [diff] [blame] | 124 | writel(KWSPI_SMEMRDY, &spireg->ctrl); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 125 | |
| 126 | /* calculate spi clock prescaller using max_hz */ |
Valentin Longchamp | baddd9f | 2012-08-15 05:31:49 +0000 | [diff] [blame] | 127 | data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10; |
| 128 | data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data; |
| 129 | data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 130 | |
| 131 | /* program spi clock prescaller using max_hz */ |
| 132 | writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg); |
Stefan Roese | 57767df | 2014-09-02 14:02:53 +0200 | [diff] [blame] | 133 | debug("data = 0x%08x\n", data); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 134 | |
| 135 | writel(KWSPI_SMEMRDIRQ, &spireg->irq_cause); |
Ian Campbell | 573b62b | 2012-01-12 06:10:22 +0000 | [diff] [blame] | 136 | writel(KWSPI_IRQMASK, &spireg->irq_mask); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 137 | |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 138 | #ifdef CONFIG_KIRKWOOD |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 139 | /* program mpp registers to select SPI_CSn */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 140 | kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back); |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 141 | #endif |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 142 | |
| 143 | return slave; |
| 144 | } |
| 145 | |
| 146 | void spi_free_slave(struct spi_slave *slave) |
| 147 | { |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_KIRKWOOD |
Valentin Longchamp | 1ad0acd | 2012-06-01 01:31:01 +0000 | [diff] [blame] | 149 | kirkwood_mpp_conf(cs_spi_mpp_back, NULL); |
Stefan Roese | 2a88a53 | 2014-10-22 12:13:10 +0200 | [diff] [blame] | 150 | #endif |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 151 | free(slave); |
| 152 | } |
| 153 | |
Valentin Longchamp | 41f94c4 | 2012-06-01 01:31:03 +0000 | [diff] [blame] | 154 | __attribute__((weak)) int board_spi_claim_bus(struct spi_slave *slave) |
| 155 | { |
| 156 | return 0; |
| 157 | } |
| 158 | |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 159 | int spi_claim_bus(struct spi_slave *slave) |
| 160 | { |
Valentin Longchamp | 41f94c4 | 2012-06-01 01:31:03 +0000 | [diff] [blame] | 161 | return board_spi_claim_bus(slave); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 162 | } |
| 163 | |
Valentin Longchamp | 41f94c4 | 2012-06-01 01:31:03 +0000 | [diff] [blame] | 164 | __attribute__((weak)) void board_spi_release_bus(struct spi_slave *slave) |
| 165 | { |
| 166 | } |
| 167 | |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 168 | void spi_release_bus(struct spi_slave *slave) |
| 169 | { |
Valentin Longchamp | 41f94c4 | 2012-06-01 01:31:03 +0000 | [diff] [blame] | 170 | board_spi_release_bus(slave); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #ifndef CONFIG_SPI_CS_IS_VALID |
| 174 | /* |
| 175 | * you can define this function board specific |
| 176 | * define above CONFIG in board specific config file and |
| 177 | * provide the function in board specific src file |
| 178 | */ |
| 179 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 180 | { |
Stefan Roese | 57767df | 2014-09-02 14:02:53 +0200 | [diff] [blame] | 181 | return bus == 0 && (cs == 0 || cs == 1); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 182 | } |
| 183 | #endif |
| 184 | |
Michael Walle | 86ea45b | 2011-10-18 20:12:00 +0530 | [diff] [blame] | 185 | void spi_init(void) |
| 186 | { |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 189 | void spi_cs_activate(struct spi_slave *slave) |
| 190 | { |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 191 | _spi_cs_activate(spireg); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void spi_cs_deactivate(struct spi_slave *slave) |
| 195 | { |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 196 | _spi_cs_deactivate(spireg); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 197 | } |
| 198 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 199 | int spi_xfer(struct spi_slave *slave, unsigned int bitlen, |
| 200 | const void *dout, void *din, unsigned long flags) |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 201 | { |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 202 | return _spi_xfer(spireg, bitlen, dout, din, flags); |
| 203 | } |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 204 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 205 | #else |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 206 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 207 | /* Here now the DM part */ |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 208 | |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 209 | struct mvebu_spi_dev { |
| 210 | bool is_errata_50mhz_ac; |
| 211 | }; |
| 212 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 213 | struct mvebu_spi_platdata { |
| 214 | struct kwspi_registers *spireg; |
Jagan Teki | f45abaa | 2018-03-15 17:03:22 +0530 | [diff] [blame] | 215 | bool is_errata_50mhz_ac; |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 216 | }; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 217 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 218 | struct mvebu_spi_priv { |
| 219 | struct kwspi_registers *spireg; |
| 220 | }; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 221 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 222 | static int mvebu_spi_set_speed(struct udevice *bus, uint hz) |
| 223 | { |
| 224 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 225 | struct kwspi_registers *reg = plat->spireg; |
| 226 | u32 data; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 227 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 228 | /* calculate spi clock prescaller using max_hz */ |
| 229 | data = ((CONFIG_SYS_TCLK / 2) / hz) + 0x10; |
| 230 | data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data; |
| 231 | data = data > KWSPI_CLKPRESCL_MASK ? KWSPI_CLKPRESCL_MASK : data; |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 232 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 233 | /* program spi clock prescaler using max_hz */ |
| 234 | writel(KWSPI_ADRLEN_3BYTE | data, ®->cfg); |
| 235 | debug("data = 0x%08x\n", data); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 236 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 237 | return 0; |
| 238 | } |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 239 | |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 240 | static void mvebu_spi_50mhz_ac_timing_erratum(struct udevice *bus, uint mode) |
| 241 | { |
| 242 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 243 | struct kwspi_registers *reg = plat->spireg; |
| 244 | u32 data; |
| 245 | |
| 246 | /* |
| 247 | * Erratum description: (Erratum NO. FE-9144572) The device |
| 248 | * SPI interface supports frequencies of up to 50 MHz. |
| 249 | * However, due to this erratum, when the device core clock is |
| 250 | * 250 MHz and the SPI interfaces is configured for 50MHz SPI |
| 251 | * clock and CPOL=CPHA=1 there might occur data corruption on |
| 252 | * reads from the SPI device. |
| 253 | * Erratum Workaround: |
| 254 | * Work in one of the following configurations: |
| 255 | * 1. Set CPOL=CPHA=0 in "SPI Interface Configuration |
| 256 | * Register". |
| 257 | * 2. Set TMISO_SAMPLE value to 0x2 in "SPI Timing Parameters 1 |
| 258 | * Register" before setting the interface. |
| 259 | */ |
| 260 | data = readl(®->timing1); |
| 261 | data &= ~KW_SPI_TMISO_SAMPLE_MASK; |
| 262 | |
| 263 | if (CONFIG_SYS_TCLK == 250000000 && |
| 264 | mode & SPI_CPOL && |
| 265 | mode & SPI_CPHA) |
| 266 | data |= KW_SPI_TMISO_SAMPLE_2; |
| 267 | else |
| 268 | data |= KW_SPI_TMISO_SAMPLE_1; |
| 269 | |
| 270 | writel(data, ®->timing1); |
| 271 | } |
| 272 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 273 | static int mvebu_spi_set_mode(struct udevice *bus, uint mode) |
| 274 | { |
Chris Packham | 21c3dca | 2016-10-27 21:16:05 +1300 | [diff] [blame] | 275 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 276 | struct kwspi_registers *reg = plat->spireg; |
| 277 | u32 data = readl(®->cfg); |
| 278 | |
| 279 | data &= ~(KWSPI_CPHA | KWSPI_CPOL | KWSPI_RXLSBF | KWSPI_TXLSBF); |
| 280 | |
| 281 | if (mode & SPI_CPHA) |
| 282 | data |= KWSPI_CPHA; |
| 283 | if (mode & SPI_CPOL) |
| 284 | data |= KWSPI_CPOL; |
| 285 | if (mode & SPI_LSB_FIRST) |
| 286 | data |= (KWSPI_RXLSBF | KWSPI_TXLSBF); |
| 287 | |
| 288 | writel(data, ®->cfg); |
| 289 | |
Jagan Teki | f45abaa | 2018-03-15 17:03:22 +0530 | [diff] [blame] | 290 | if (plat->is_errata_50mhz_ac) |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 291 | mvebu_spi_50mhz_ac_timing_erratum(bus, mode); |
| 292 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 293 | return 0; |
| 294 | } |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 295 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 296 | static int mvebu_spi_xfer(struct udevice *dev, unsigned int bitlen, |
| 297 | const void *dout, void *din, unsigned long flags) |
| 298 | { |
| 299 | struct udevice *bus = dev->parent; |
| 300 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 301 | |
| 302 | return _spi_xfer(plat->spireg, bitlen, dout, din, flags); |
| 303 | } |
| 304 | |
Pascal Linder | 96821ba | 2019-06-18 08:41:01 +0200 | [diff] [blame] | 305 | __attribute__((weak)) int mvebu_board_spi_claim_bus(struct udevice *dev) |
| 306 | { |
| 307 | return 0; |
| 308 | } |
| 309 | |
Stefan Roese | 90b499a | 2016-02-11 11:37:38 +0100 | [diff] [blame] | 310 | static int mvebu_spi_claim_bus(struct udevice *dev) |
| 311 | { |
| 312 | struct udevice *bus = dev->parent; |
| 313 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 314 | |
| 315 | /* Configure the chip-select in the CTRL register */ |
| 316 | clrsetbits_le32(&plat->spireg->ctrl, |
| 317 | KWSPI_CS_MASK << KWSPI_CS_SHIFT, |
| 318 | spi_chip_select(dev) << KWSPI_CS_SHIFT); |
| 319 | |
Pascal Linder | 96821ba | 2019-06-18 08:41:01 +0200 | [diff] [blame] | 320 | return mvebu_board_spi_claim_bus(dev); |
| 321 | } |
| 322 | |
| 323 | __attribute__((weak)) int mvebu_board_spi_release_bus(struct udevice *dev) |
| 324 | { |
Stefan Roese | 90b499a | 2016-02-11 11:37:38 +0100 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
Pascal Linder | 96821ba | 2019-06-18 08:41:01 +0200 | [diff] [blame] | 328 | static int mvebu_spi_release_bus(struct udevice *dev) |
| 329 | { |
| 330 | return mvebu_board_spi_release_bus(dev); |
| 331 | } |
| 332 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 333 | static int mvebu_spi_probe(struct udevice *bus) |
| 334 | { |
| 335 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
| 336 | struct kwspi_registers *reg = plat->spireg; |
| 337 | |
| 338 | writel(KWSPI_SMEMRDY, ®->ctrl); |
| 339 | writel(KWSPI_SMEMRDIRQ, ®->irq_cause); |
| 340 | writel(KWSPI_IRQMASK, ®->irq_mask); |
Prafulla Wadaskar | 1fd6a9b | 2009-05-30 01:13:33 +0530 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 344 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 345 | static int mvebu_spi_ofdata_to_platdata(struct udevice *bus) |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 346 | { |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 347 | struct mvebu_spi_platdata *plat = dev_get_platdata(bus); |
Jagan Teki | f45abaa | 2018-03-15 17:03:22 +0530 | [diff] [blame] | 348 | const struct mvebu_spi_dev *drvdata = |
| 349 | (struct mvebu_spi_dev *)dev_get_driver_data(bus); |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 350 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 351 | plat->spireg = (struct kwspi_registers *)devfdt_get_addr(bus); |
Jagan Teki | f45abaa | 2018-03-15 17:03:22 +0530 | [diff] [blame] | 352 | plat->is_errata_50mhz_ac = drvdata->is_errata_50mhz_ac; |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 353 | |
| 354 | return 0; |
Stefan Roese | ff74ca4 | 2015-11-20 08:44:21 +0100 | [diff] [blame] | 355 | } |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 356 | |
| 357 | static const struct dm_spi_ops mvebu_spi_ops = { |
Stefan Roese | 90b499a | 2016-02-11 11:37:38 +0100 | [diff] [blame] | 358 | .claim_bus = mvebu_spi_claim_bus, |
Pascal Linder | 96821ba | 2019-06-18 08:41:01 +0200 | [diff] [blame] | 359 | .release_bus = mvebu_spi_release_bus, |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 360 | .xfer = mvebu_spi_xfer, |
| 361 | .set_speed = mvebu_spi_set_speed, |
| 362 | .set_mode = mvebu_spi_set_mode, |
| 363 | /* |
| 364 | * cs_info is not needed, since we require all chip selects to be |
| 365 | * in the device tree explicitly |
| 366 | */ |
| 367 | }; |
| 368 | |
Chris Packham | 833ff18 | 2018-08-01 12:19:26 +0530 | [diff] [blame] | 369 | static const struct mvebu_spi_dev armada_spi_dev_data = { |
| 370 | .is_errata_50mhz_ac = false, |
| 371 | }; |
| 372 | |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 373 | static const struct mvebu_spi_dev armada_xp_spi_dev_data = { |
| 374 | .is_errata_50mhz_ac = false, |
| 375 | }; |
| 376 | |
| 377 | static const struct mvebu_spi_dev armada_375_spi_dev_data = { |
| 378 | .is_errata_50mhz_ac = false, |
| 379 | }; |
| 380 | |
| 381 | static const struct mvebu_spi_dev armada_380_spi_dev_data = { |
| 382 | .is_errata_50mhz_ac = true, |
| 383 | }; |
| 384 | |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 385 | static const struct udevice_id mvebu_spi_ids[] = { |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 386 | { |
Chris Packham | 833ff18 | 2018-08-01 12:19:26 +0530 | [diff] [blame] | 387 | .compatible = "marvell,orion-spi", |
| 388 | .data = (ulong)&armada_spi_dev_data, |
| 389 | }, |
| 390 | { |
Chris Packham | 479588d | 2018-01-22 22:44:20 +1300 | [diff] [blame] | 391 | .compatible = "marvell,armada-375-spi", |
| 392 | .data = (ulong)&armada_375_spi_dev_data |
| 393 | }, |
| 394 | { |
| 395 | .compatible = "marvell,armada-380-spi", |
| 396 | .data = (ulong)&armada_380_spi_dev_data |
| 397 | }, |
| 398 | { |
| 399 | .compatible = "marvell,armada-xp-spi", |
| 400 | .data = (ulong)&armada_xp_spi_dev_data |
| 401 | }, |
Stefan Roese | 27139a6 | 2015-11-20 13:39:43 +0100 | [diff] [blame] | 402 | { } |
| 403 | }; |
| 404 | |
| 405 | U_BOOT_DRIVER(mvebu_spi) = { |
| 406 | .name = "mvebu_spi", |
| 407 | .id = UCLASS_SPI, |
| 408 | .of_match = mvebu_spi_ids, |
| 409 | .ops = &mvebu_spi_ops, |
| 410 | .ofdata_to_platdata = mvebu_spi_ofdata_to_platdata, |
| 411 | .platdata_auto_alloc_size = sizeof(struct mvebu_spi_platdata), |
| 412 | .priv_auto_alloc_size = sizeof(struct mvebu_spi_priv), |
| 413 | .probe = mvebu_spi_probe, |
| 414 | }; |
| 415 | #endif |