Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 3 | * (C) Copyright 2013 - 2022, Xilinx, Inc. |
| 4 | * (C) Copyright 2023, Advanced Micro Devices, Inc. |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 5 | * Xilinx ZynqMP Generic Quad-SPI(QSPI) controller driver(master mode only) |
| 6 | */ |
| 7 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 8 | #define LOG_CATEGORY UCLASS_SPI |
| 9 | |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 12 | #include <asm/arch/sys_proto.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <asm/cache.h> |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <clk.h> |
| 16 | #include <dm.h> |
| 17 | #include <malloc.h> |
| 18 | #include <memalign.h> |
| 19 | #include <spi.h> |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 20 | #include <spi-mem.h> |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 21 | #include <ubi_uboot.h> |
| 22 | #include <wait_bit.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 23 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 24 | #include <linux/bitops.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 25 | #include <linux/err.h> |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 26 | #include <linux/sizes.h> |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 27 | #include <linux/mtd/spi-nor.h> |
| 28 | #include "../mtd/spi/sf_internal.h" |
Ashok Reddy Soma | e3c77a6 | 2022-08-25 06:59:01 -0600 | [diff] [blame] | 29 | #include <zynqmp_firmware.h> |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 30 | |
| 31 | #define GQSPI_GFIFO_STRT_MODE_MASK BIT(29) |
| 32 | #define GQSPI_CONFIG_MODE_EN_MASK (3 << 30) |
| 33 | #define GQSPI_CONFIG_DMA_MODE (2 << 30) |
| 34 | #define GQSPI_CONFIG_CPHA_MASK BIT(2) |
| 35 | #define GQSPI_CONFIG_CPOL_MASK BIT(1) |
| 36 | |
| 37 | /* |
| 38 | * QSPI Interrupt Registers bit Masks |
| 39 | * |
| 40 | * All the four interrupt registers (Status/Mask/Enable/Disable) have the same |
| 41 | * bit definitions. |
| 42 | */ |
| 43 | #define GQSPI_IXR_TXNFULL_MASK 0x00000004 /* QSPI TX FIFO Overflow */ |
| 44 | #define GQSPI_IXR_TXFULL_MASK 0x00000008 /* QSPI TX FIFO is full */ |
Ashok Reddy Soma | 26f77d7 | 2021-10-19 19:43:00 +0530 | [diff] [blame] | 45 | #define GQSPI_IXR_TXFIFOEMPTY_MASK 0x00000100 /* QSPI TX FIFO is Empty */ |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 46 | #define GQSPI_IXR_RXNEMTY_MASK 0x00000010 /* QSPI RX FIFO Not Empty */ |
| 47 | #define GQSPI_IXR_GFEMTY_MASK 0x00000080 /* QSPI Generic FIFO Empty */ |
Ashok Reddy Soma | 2af829f | 2021-05-25 06:36:27 -0600 | [diff] [blame] | 48 | #define GQSPI_IXR_GFNFULL_MASK 0x00000200 /* QSPI GENFIFO not full */ |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 49 | #define GQSPI_IXR_ALL_MASK (GQSPI_IXR_TXNFULL_MASK | \ |
| 50 | GQSPI_IXR_RXNEMTY_MASK) |
| 51 | |
| 52 | /* |
| 53 | * QSPI Enable Register bit Masks |
| 54 | * |
| 55 | * This register is used to enable or disable the QSPI controller |
| 56 | */ |
| 57 | #define GQSPI_ENABLE_ENABLE_MASK 0x00000001 /* QSPI Enable Bit Mask */ |
| 58 | |
| 59 | #define GQSPI_GFIFO_LOW_BUS BIT(14) |
| 60 | #define GQSPI_GFIFO_CS_LOWER BIT(12) |
| 61 | #define GQSPI_GFIFO_UP_BUS BIT(15) |
| 62 | #define GQSPI_GFIFO_CS_UPPER BIT(13) |
| 63 | #define GQSPI_SPI_MODE_QSPI (3 << 10) |
| 64 | #define GQSPI_SPI_MODE_SPI BIT(10) |
| 65 | #define GQSPI_SPI_MODE_DUAL_SPI (2 << 10) |
| 66 | #define GQSPI_IMD_DATA_CS_ASSERT 5 |
| 67 | #define GQSPI_IMD_DATA_CS_DEASSERT 5 |
| 68 | #define GQSPI_GFIFO_TX BIT(16) |
| 69 | #define GQSPI_GFIFO_RX BIT(17) |
| 70 | #define GQSPI_GFIFO_STRIPE_MASK BIT(18) |
| 71 | #define GQSPI_GFIFO_IMD_MASK 0xFF |
| 72 | #define GQSPI_GFIFO_EXP_MASK BIT(9) |
| 73 | #define GQSPI_GFIFO_DATA_XFR_MASK BIT(8) |
| 74 | #define GQSPI_STRT_GEN_FIFO BIT(28) |
| 75 | #define GQSPI_GEN_FIFO_STRT_MOD BIT(29) |
| 76 | #define GQSPI_GFIFO_WP_HOLD BIT(19) |
| 77 | #define GQSPI_BAUD_DIV_MASK (7 << 3) |
| 78 | #define GQSPI_DFLT_BAUD_RATE_DIV BIT(3) |
| 79 | #define GQSPI_GFIFO_ALL_INT_MASK 0xFBE |
| 80 | #define GQSPI_DMA_DST_I_STS_DONE BIT(1) |
| 81 | #define GQSPI_DMA_DST_I_STS_MASK 0xFE |
| 82 | #define MODEBITS 0x6 |
| 83 | |
| 84 | #define GQSPI_GFIFO_SELECT BIT(0) |
| 85 | #define GQSPI_FIFO_THRESHOLD 1 |
Ashok Reddy Soma | 822a243 | 2021-08-20 07:43:17 -0600 | [diff] [blame] | 86 | #define GQSPI_GENFIFO_THRESHOLD 31 |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 87 | |
| 88 | #define SPI_XFER_ON_BOTH 0 |
| 89 | #define SPI_XFER_ON_LOWER 1 |
| 90 | #define SPI_XFER_ON_UPPER 2 |
| 91 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 92 | #define GQSPI_SELECT_LOWER_CS BIT(0) |
| 93 | #define GQSPI_SELECT_UPPER_CS BIT(1) |
| 94 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 95 | #define GQSPI_DMA_ALIGN 0x4 |
| 96 | #define GQSPI_MAX_BAUD_RATE_VAL 7 |
| 97 | #define GQSPI_DFLT_BAUD_RATE_VAL 2 |
| 98 | |
| 99 | #define GQSPI_TIMEOUT 100000000 |
| 100 | |
| 101 | #define GQSPI_BAUD_DIV_SHIFT 2 |
| 102 | #define GQSPI_LPBK_DLY_ADJ_LPBK_SHIFT 5 |
T Karthik Reddy | 751533d | 2022-11-23 02:04:51 -0700 | [diff] [blame] | 103 | #define GQSPI_LPBK_DLY_ADJ_DLY_1 0x1 |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 104 | #define GQSPI_LPBK_DLY_ADJ_DLY_1_SHIFT 3 |
| 105 | #define GQSPI_LPBK_DLY_ADJ_DLY_0 0x3 |
| 106 | #define GQSPI_USE_DATA_DLY 0x1 |
| 107 | #define GQSPI_USE_DATA_DLY_SHIFT 31 |
| 108 | #define GQSPI_DATA_DLY_ADJ_VALUE 0x2 |
| 109 | #define GQSPI_DATA_DLY_ADJ_SHIFT 28 |
| 110 | #define TAP_DLY_BYPASS_LQSPI_RX_VALUE 0x1 |
| 111 | #define TAP_DLY_BYPASS_LQSPI_RX_SHIFT 2 |
| 112 | #define GQSPI_DATA_DLY_ADJ_OFST 0x000001F8 |
Ashok Reddy Soma | ef3e30b | 2022-11-16 16:40:30 +0100 | [diff] [blame] | 113 | #define IOU_TAPDLY_BYPASS_OFST !(IS_ENABLED(CONFIG_ARCH_VERSAL) || \ |
Michal Simek | 71bfd39 | 2024-05-29 16:48:01 +0200 | [diff] [blame] | 114 | IS_ENABLED(CONFIG_ARCH_VERSAL_NET) || \ |
| 115 | IS_ENABLED(CONFIG_ARCH_VERSAL2)) ? \ |
Ashok Reddy Soma | e3c77a6 | 2022-08-25 06:59:01 -0600 | [diff] [blame] | 116 | 0xFF180390 : 0xF103003C |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 117 | #define GQSPI_LPBK_DLY_ADJ_LPBK_MASK 0x00000020 |
Ashok Reddy Soma | e3c77a6 | 2022-08-25 06:59:01 -0600 | [diff] [blame] | 118 | #define GQSPI_FREQ_37_5MHZ 37500000 |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 119 | #define GQSPI_FREQ_40MHZ 40000000 |
| 120 | #define GQSPI_FREQ_100MHZ 100000000 |
| 121 | #define GQSPI_FREQ_150MHZ 150000000 |
| 122 | #define IOU_TAPDLY_BYPASS_MASK 0x7 |
| 123 | |
| 124 | #define GQSPI_REG_OFFSET 0x100 |
| 125 | #define GQSPI_DMA_REG_OFFSET 0x800 |
| 126 | |
| 127 | /* QSPI register offsets */ |
| 128 | struct zynqmp_qspi_regs { |
| 129 | u32 confr; /* 0x00 */ |
| 130 | u32 isr; /* 0x04 */ |
| 131 | u32 ier; /* 0x08 */ |
| 132 | u32 idisr; /* 0x0C */ |
| 133 | u32 imaskr; /* 0x10 */ |
| 134 | u32 enbr; /* 0x14 */ |
| 135 | u32 dr; /* 0x18 */ |
| 136 | u32 txd0r; /* 0x1C */ |
| 137 | u32 drxr; /* 0x20 */ |
| 138 | u32 sicr; /* 0x24 */ |
| 139 | u32 txftr; /* 0x28 */ |
| 140 | u32 rxftr; /* 0x2C */ |
| 141 | u32 gpior; /* 0x30 */ |
| 142 | u32 reserved0; /* 0x34 */ |
| 143 | u32 lpbkdly; /* 0x38 */ |
| 144 | u32 reserved1; /* 0x3C */ |
| 145 | u32 genfifo; /* 0x40 */ |
| 146 | u32 gqspisel; /* 0x44 */ |
| 147 | u32 reserved2; /* 0x48 */ |
| 148 | u32 gqfifoctrl; /* 0x4C */ |
| 149 | u32 gqfthr; /* 0x50 */ |
| 150 | u32 gqpollcfg; /* 0x54 */ |
| 151 | u32 gqpollto; /* 0x58 */ |
| 152 | u32 gqxfersts; /* 0x5C */ |
| 153 | u32 gqfifosnap; /* 0x60 */ |
| 154 | u32 gqrxcpy; /* 0x64 */ |
| 155 | u32 reserved3[36]; /* 0x68 */ |
| 156 | u32 gqspidlyadj; /* 0xF8 */ |
| 157 | }; |
| 158 | |
| 159 | struct zynqmp_qspi_dma_regs { |
| 160 | u32 dmadst; /* 0x00 */ |
| 161 | u32 dmasize; /* 0x04 */ |
| 162 | u32 dmasts; /* 0x08 */ |
| 163 | u32 dmactrl; /* 0x0C */ |
| 164 | u32 reserved0; /* 0x10 */ |
| 165 | u32 dmaisr; /* 0x14 */ |
| 166 | u32 dmaier; /* 0x18 */ |
| 167 | u32 dmaidr; /* 0x1C */ |
| 168 | u32 dmaimr; /* 0x20 */ |
| 169 | u32 dmactrl2; /* 0x24 */ |
| 170 | u32 dmadstmsb; /* 0x28 */ |
| 171 | }; |
| 172 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 173 | struct zynqmp_qspi_plat { |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 174 | struct zynqmp_qspi_regs *regs; |
| 175 | struct zynqmp_qspi_dma_regs *dma_regs; |
| 176 | u32 frequency; |
| 177 | u32 speed_hz; |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 178 | unsigned int io_mode; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | struct zynqmp_qspi_priv { |
| 182 | struct zynqmp_qspi_regs *regs; |
| 183 | struct zynqmp_qspi_dma_regs *dma_regs; |
| 184 | const void *tx_buf; |
| 185 | void *rx_buf; |
| 186 | unsigned int len; |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 187 | unsigned int io_mode; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 188 | int bytes_to_transfer; |
| 189 | int bytes_to_receive; |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 190 | const struct spi_mem_op *op; |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 191 | unsigned int is_parallel; |
| 192 | unsigned int u_page; |
| 193 | unsigned int bus; |
| 194 | unsigned int stripe; |
| 195 | unsigned int flags; |
| 196 | u32 max_hz; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 197 | }; |
| 198 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 199 | static int zynqmp_qspi_of_to_plat(struct udevice *bus) |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 200 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 201 | struct zynqmp_qspi_plat *plat = dev_get_plat(bus); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 202 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 203 | plat->regs = (struct zynqmp_qspi_regs *)(dev_read_addr(bus) + |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 204 | GQSPI_REG_OFFSET); |
| 205 | plat->dma_regs = (struct zynqmp_qspi_dma_regs *) |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 206 | (dev_read_addr(bus) + GQSPI_DMA_REG_OFFSET); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 207 | |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 208 | plat->io_mode = dev_read_bool(bus, "has-io-mode"); |
| 209 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static void zynqmp_qspi_init_hw(struct zynqmp_qspi_priv *priv) |
| 214 | { |
| 215 | u32 config_reg; |
| 216 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 217 | |
| 218 | writel(GQSPI_GFIFO_SELECT, ®s->gqspisel); |
| 219 | writel(GQSPI_GFIFO_ALL_INT_MASK, ®s->idisr); |
| 220 | writel(GQSPI_FIFO_THRESHOLD, ®s->txftr); |
| 221 | writel(GQSPI_FIFO_THRESHOLD, ®s->rxftr); |
Ashok Reddy Soma | 822a243 | 2021-08-20 07:43:17 -0600 | [diff] [blame] | 222 | writel(GQSPI_GENFIFO_THRESHOLD, ®s->gqfthr); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 223 | writel(GQSPI_GFIFO_ALL_INT_MASK, ®s->isr); |
Ashok Reddy Soma | 822a243 | 2021-08-20 07:43:17 -0600 | [diff] [blame] | 224 | writel(~GQSPI_ENABLE_ENABLE_MASK, ®s->enbr); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 225 | |
| 226 | config_reg = readl(®s->confr); |
| 227 | config_reg &= ~(GQSPI_GFIFO_STRT_MODE_MASK | |
| 228 | GQSPI_CONFIG_MODE_EN_MASK); |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 229 | config_reg |= GQSPI_GFIFO_WP_HOLD | GQSPI_DFLT_BAUD_RATE_DIV; |
| 230 | config_reg |= GQSPI_GFIFO_STRT_MODE_MASK; |
| 231 | if (!priv->io_mode) |
| 232 | config_reg |= GQSPI_CONFIG_DMA_MODE; |
| 233 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 234 | writel(config_reg, ®s->confr); |
| 235 | |
| 236 | writel(GQSPI_ENABLE_ENABLE_MASK, ®s->enbr); |
| 237 | } |
| 238 | |
| 239 | static u32 zynqmp_qspi_bus_select(struct zynqmp_qspi_priv *priv) |
| 240 | { |
| 241 | u32 gqspi_fifo_reg = 0; |
| 242 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 243 | if (priv->is_parallel) { |
| 244 | if (priv->bus == SPI_XFER_ON_BOTH) |
| 245 | gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS | |
| 246 | GQSPI_GFIFO_UP_BUS | |
| 247 | GQSPI_GFIFO_CS_UPPER | |
| 248 | GQSPI_GFIFO_CS_LOWER; |
| 249 | else if (priv->bus == SPI_XFER_ON_LOWER) |
| 250 | gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS | |
| 251 | GQSPI_GFIFO_CS_UPPER | |
| 252 | GQSPI_GFIFO_CS_LOWER; |
| 253 | else if (priv->bus == SPI_XFER_ON_UPPER) |
| 254 | gqspi_fifo_reg = GQSPI_GFIFO_UP_BUS | |
| 255 | GQSPI_GFIFO_CS_LOWER | |
| 256 | GQSPI_GFIFO_CS_UPPER; |
| 257 | else |
| 258 | debug("Wrong Bus selection:0x%x\n", priv->bus); |
| 259 | } else { |
| 260 | if (priv->u_page) |
| 261 | gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS | |
| 262 | GQSPI_GFIFO_CS_UPPER; |
| 263 | else |
| 264 | gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS | |
| 265 | GQSPI_GFIFO_CS_LOWER; |
| 266 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 267 | |
| 268 | return gqspi_fifo_reg; |
| 269 | } |
| 270 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 271 | static u32 zynqmp_qspi_genfifo_mode(u8 buswidth) |
| 272 | { |
| 273 | switch (buswidth) { |
| 274 | case 1: |
| 275 | return GQSPI_SPI_MODE_SPI; |
| 276 | case 2: |
| 277 | return GQSPI_SPI_MODE_DUAL_SPI; |
| 278 | case 4: |
| 279 | return GQSPI_SPI_MODE_QSPI; |
| 280 | default: |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 281 | log_warning("Unsupported bus width %u\n", buswidth); |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 282 | return GQSPI_SPI_MODE_SPI; |
| 283 | } |
| 284 | } |
| 285 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 286 | static void zynqmp_qspi_fill_gen_fifo(struct zynqmp_qspi_priv *priv, |
| 287 | u32 gqspi_fifo_reg) |
| 288 | { |
| 289 | struct zynqmp_qspi_regs *regs = priv->regs; |
Ashok Reddy Soma | 2af829f | 2021-05-25 06:36:27 -0600 | [diff] [blame] | 290 | u32 config_reg, ier; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 291 | int ret = 0; |
| 292 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 293 | log_content("%s, GFIFO_CMD: 0x%X\n", __func__, gqspi_fifo_reg); |
| 294 | |
Ashok Reddy Soma | 1c35adc | 2021-08-20 07:43:16 -0600 | [diff] [blame] | 295 | writel(gqspi_fifo_reg, ®s->genfifo); |
| 296 | |
Ashok Reddy Soma | 2af829f | 2021-05-25 06:36:27 -0600 | [diff] [blame] | 297 | config_reg = readl(®s->confr); |
| 298 | /* Manual start if needed */ |
| 299 | config_reg |= GQSPI_STRT_GEN_FIFO; |
| 300 | writel(config_reg, ®s->confr); |
| 301 | |
| 302 | /* Enable interrupts */ |
| 303 | ier = readl(®s->ier); |
Ashok Reddy Soma | 1c35adc | 2021-08-20 07:43:16 -0600 | [diff] [blame] | 304 | ier |= GQSPI_IXR_GFEMTY_MASK; |
Ashok Reddy Soma | 2af829f | 2021-05-25 06:36:27 -0600 | [diff] [blame] | 305 | writel(ier, ®s->ier); |
| 306 | |
Ashok Reddy Soma | 1c35adc | 2021-08-20 07:43:16 -0600 | [diff] [blame] | 307 | /* Wait until the gen fifo is empty to write the new command */ |
| 308 | ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_GFEMTY_MASK, 1, |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 309 | GQSPI_TIMEOUT, 1); |
| 310 | if (ret) |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 311 | log_warning("%s, Timeout\n", __func__); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 312 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static void zynqmp_qspi_chipselect(struct zynqmp_qspi_priv *priv, int is_on) |
| 316 | { |
| 317 | u32 gqspi_fifo_reg = 0; |
| 318 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 319 | log_debug("%s, assert: %d\r\n", __func__, is_on); |
| 320 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 321 | if (is_on) { |
| 322 | gqspi_fifo_reg = zynqmp_qspi_bus_select(priv); |
| 323 | gqspi_fifo_reg |= GQSPI_SPI_MODE_SPI | |
| 324 | GQSPI_IMD_DATA_CS_ASSERT; |
| 325 | } else { |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 326 | if (priv->is_parallel) { |
| 327 | gqspi_fifo_reg = GQSPI_GFIFO_UP_BUS | |
| 328 | GQSPI_GFIFO_LOW_BUS; |
| 329 | } else if (priv->u_page) { |
| 330 | gqspi_fifo_reg = GQSPI_GFIFO_UP_BUS; |
| 331 | } else { |
| 332 | gqspi_fifo_reg = GQSPI_GFIFO_LOW_BUS; |
| 333 | gqspi_fifo_reg |= GQSPI_IMD_DATA_CS_DEASSERT; |
| 334 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 335 | } |
| 336 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 337 | zynqmp_qspi_fill_gen_fifo(priv, gqspi_fifo_reg); |
| 338 | } |
| 339 | |
Venkatesh Yadav Abbarapu | f6dfade | 2022-10-04 11:07:30 +0530 | [diff] [blame] | 340 | static void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval) |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 341 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 342 | struct zynqmp_qspi_plat *plat = dev_get_plat(bus); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 343 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 344 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 345 | u32 tapdlybypass = 0, lpbkdlyadj = 0, datadlyadj = 0, clk_rate; |
| 346 | u32 reqhz = 0; |
| 347 | |
| 348 | clk_rate = plat->frequency; |
| 349 | reqhz = (clk_rate / (GQSPI_BAUD_DIV_SHIFT << baudrateval)); |
| 350 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 351 | log_debug("%s, clk_rate:%d, baudrateval:%d, bus_clk: %d\n", |
| 352 | __func__, clk_rate, baudrateval, reqhz); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 353 | |
Michal Simek | 06995c4 | 2022-09-19 14:21:04 +0200 | [diff] [blame] | 354 | if (!(IS_ENABLED(CONFIG_ARCH_VERSAL) || |
Michal Simek | 71bfd39 | 2024-05-29 16:48:01 +0200 | [diff] [blame] | 355 | IS_ENABLED(CONFIG_ARCH_VERSAL_NET) || |
| 356 | IS_ENABLED(CONFIG_ARCH_VERSAL2))) { |
Ashok Reddy Soma | e3c77a6 | 2022-08-25 06:59:01 -0600 | [diff] [blame] | 357 | if (reqhz <= GQSPI_FREQ_40MHZ) { |
| 358 | tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE << |
| 359 | TAP_DLY_BYPASS_LQSPI_RX_SHIFT; |
| 360 | } else if (reqhz <= GQSPI_FREQ_100MHZ) { |
| 361 | tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE << |
| 362 | TAP_DLY_BYPASS_LQSPI_RX_SHIFT; |
| 363 | lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK; |
| 364 | datadlyadj = (GQSPI_USE_DATA_DLY << |
| 365 | GQSPI_USE_DATA_DLY_SHIFT) | |
| 366 | (GQSPI_DATA_DLY_ADJ_VALUE << |
| 367 | GQSPI_DATA_DLY_ADJ_SHIFT); |
| 368 | } else if (reqhz <= GQSPI_FREQ_150MHZ) { |
| 369 | lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK | |
| 370 | GQSPI_LPBK_DLY_ADJ_DLY_0; |
| 371 | } |
| 372 | zynqmp_mmio_write(IOU_TAPDLY_BYPASS_OFST, |
| 373 | IOU_TAPDLY_BYPASS_MASK, tapdlybypass); |
| 374 | } else { |
| 375 | if (reqhz <= GQSPI_FREQ_37_5MHZ) { |
| 376 | tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE << |
| 377 | TAP_DLY_BYPASS_LQSPI_RX_SHIFT; |
| 378 | } else if (reqhz <= GQSPI_FREQ_100MHZ) { |
| 379 | tapdlybypass = TAP_DLY_BYPASS_LQSPI_RX_VALUE << |
| 380 | TAP_DLY_BYPASS_LQSPI_RX_SHIFT; |
| 381 | lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK; |
| 382 | datadlyadj = GQSPI_USE_DATA_DLY << |
| 383 | GQSPI_USE_DATA_DLY_SHIFT; |
| 384 | } else if (reqhz <= GQSPI_FREQ_150MHZ) { |
| 385 | lpbkdlyadj = GQSPI_LPBK_DLY_ADJ_LPBK_MASK | |
| 386 | (GQSPI_LPBK_DLY_ADJ_DLY_1 << |
| 387 | GQSPI_LPBK_DLY_ADJ_DLY_1_SHIFT); |
| 388 | } |
| 389 | writel(tapdlybypass, IOU_TAPDLY_BYPASS_OFST); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 390 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 391 | writel(lpbkdlyadj, ®s->lpbkdly); |
| 392 | writel(datadlyadj, ®s->gqspidlyadj); |
| 393 | } |
| 394 | |
| 395 | static int zynqmp_qspi_set_speed(struct udevice *bus, uint speed) |
| 396 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 397 | struct zynqmp_qspi_plat *plat = dev_get_plat(bus); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 398 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 399 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 400 | u32 confr; |
| 401 | u8 baud_rate_val = 0; |
| 402 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 403 | log_debug("%s, Speed: %d, Max: %d\n", __func__, speed, plat->frequency); |
| 404 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 405 | /* |
| 406 | * If speed == 0 or speed > max freq, then set speed to highest |
| 407 | */ |
| 408 | if (!speed || speed > priv->max_hz) |
| 409 | speed = priv->max_hz; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 410 | |
Brandon Maier | b8003d5 | 2021-01-20 14:28:30 -0600 | [diff] [blame] | 411 | if (plat->speed_hz != speed) { |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 412 | while ((baud_rate_val < 8) && |
| 413 | ((plat->frequency / |
| 414 | (2 << baud_rate_val)) > speed)) |
| 415 | baud_rate_val++; |
| 416 | |
| 417 | if (baud_rate_val > GQSPI_MAX_BAUD_RATE_VAL) |
| 418 | baud_rate_val = GQSPI_DFLT_BAUD_RATE_VAL; |
| 419 | |
| 420 | plat->speed_hz = plat->frequency / (2 << baud_rate_val); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 421 | |
Brandon Maier | b8003d5 | 2021-01-20 14:28:30 -0600 | [diff] [blame] | 422 | confr = readl(®s->confr); |
| 423 | confr &= ~GQSPI_BAUD_DIV_MASK; |
| 424 | confr |= (baud_rate_val << 3); |
| 425 | writel(confr, ®s->confr); |
Brandon Maier | b8003d5 | 2021-01-20 14:28:30 -0600 | [diff] [blame] | 426 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 427 | zynqmp_qspi_set_tapdelay(bus, baud_rate_val); |
Brandon Maier | b8003d5 | 2021-01-20 14:28:30 -0600 | [diff] [blame] | 428 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 433 | static int zynqmp_qspi_child_pre_probe(struct udevice *bus) |
| 434 | { |
| 435 | struct spi_slave *slave = dev_get_parent_priv(bus); |
| 436 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus->parent); |
| 437 | |
| 438 | slave->multi_cs_cap = true; |
| 439 | slave->bytemode = SPI_4BYTE_MODE; |
| 440 | priv->max_hz = slave->max_hz; |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 445 | static int zynqmp_qspi_probe(struct udevice *bus) |
| 446 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 447 | struct zynqmp_qspi_plat *plat = dev_get_plat(bus); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 448 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 449 | struct clk clk; |
| 450 | unsigned long clock; |
| 451 | int ret; |
| 452 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 453 | priv->regs = plat->regs; |
| 454 | priv->dma_regs = plat->dma_regs; |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 455 | priv->io_mode = plat->io_mode; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 456 | |
| 457 | ret = clk_get_by_index(bus, 0, &clk); |
| 458 | if (ret < 0) { |
Sean Anderson | 241232a | 2020-09-15 10:45:12 -0400 | [diff] [blame] | 459 | dev_err(bus, "failed to get clock\n"); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | clock = clk_get_rate(&clk); |
| 464 | if (IS_ERR_VALUE(clock)) { |
Sean Anderson | 241232a | 2020-09-15 10:45:12 -0400 | [diff] [blame] | 465 | dev_err(bus, "failed to get rate\n"); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 466 | return clock; |
| 467 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 468 | |
| 469 | ret = clk_enable(&clk); |
Michal Simek | 4171095 | 2021-02-09 15:28:15 +0100 | [diff] [blame] | 470 | if (ret) { |
Sean Anderson | 241232a | 2020-09-15 10:45:12 -0400 | [diff] [blame] | 471 | dev_err(bus, "failed to enable clock\n"); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 472 | return ret; |
| 473 | } |
| 474 | plat->frequency = clock; |
| 475 | plat->speed_hz = plat->frequency / 2; |
| 476 | |
| 477 | /* init the zynq spi hw */ |
| 478 | zynqmp_qspi_init_hw(priv); |
| 479 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 480 | log_debug("%s, Rerence clock frequency: %ld\n", __func__, clock); |
| 481 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static int zynqmp_qspi_set_mode(struct udevice *bus, uint mode) |
| 486 | { |
| 487 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 488 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 489 | u32 confr; |
| 490 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 491 | log_debug("%s, 0x%X\n", __func__, mode); |
| 492 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 493 | /* Set the SPI Clock phase and polarities */ |
| 494 | confr = readl(®s->confr); |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 495 | confr &= ~(GQSPI_CONFIG_CPHA_MASK | GQSPI_CONFIG_CPOL_MASK); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 496 | |
| 497 | if (mode & SPI_CPHA) |
| 498 | confr |= GQSPI_CONFIG_CPHA_MASK; |
| 499 | if (mode & SPI_CPOL) |
| 500 | confr |= GQSPI_CONFIG_CPOL_MASK; |
| 501 | |
| 502 | writel(confr, ®s->confr); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static int zynqmp_qspi_fill_tx_fifo(struct zynqmp_qspi_priv *priv, u32 size) |
| 508 | { |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 509 | u32 data, ier; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 510 | int ret = 0; |
| 511 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 512 | u32 *buf = (u32 *)priv->tx_buf; |
| 513 | u32 len = size; |
| 514 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 515 | /* Enable interrupts */ |
| 516 | ier = readl(®s->ier); |
| 517 | ier |= GQSPI_IXR_ALL_MASK | GQSPI_IXR_TXFIFOEMPTY_MASK; |
| 518 | writel(ier, ®s->ier); |
| 519 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 520 | while (size) { |
| 521 | ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_TXNFULL_MASK, 1, |
| 522 | GQSPI_TIMEOUT, 1); |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 523 | if (ret) |
| 524 | return log_msg_ret("Timeout\n", ret); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 525 | |
| 526 | if (size >= 4) { |
| 527 | writel(*buf, ®s->txd0r); |
| 528 | buf++; |
| 529 | size -= 4; |
| 530 | } else { |
| 531 | switch (size) { |
| 532 | case 1: |
| 533 | data = *((u8 *)buf); |
| 534 | buf += 1; |
| 535 | data |= GENMASK(31, 8); |
| 536 | break; |
| 537 | case 2: |
| 538 | data = *((u16 *)buf); |
| 539 | buf += 2; |
| 540 | data |= GENMASK(31, 16); |
| 541 | break; |
| 542 | case 3: |
T Karthik Reddy | cc59fc9 | 2020-11-19 05:00:36 -0700 | [diff] [blame] | 543 | data = *buf; |
| 544 | buf += 3; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 545 | data |= GENMASK(31, 24); |
| 546 | break; |
| 547 | } |
| 548 | writel(data, ®s->txd0r); |
| 549 | size = 0; |
| 550 | } |
| 551 | } |
| 552 | |
Ashok Reddy Soma | 26f77d7 | 2021-10-19 19:43:00 +0530 | [diff] [blame] | 553 | ret = wait_for_bit_le32(®s->isr, GQSPI_IXR_TXFIFOEMPTY_MASK, 1, |
| 554 | GQSPI_TIMEOUT, 1); |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 555 | if (ret) |
| 556 | return log_msg_ret("Timeout\n", ret); |
Ashok Reddy Soma | 26f77d7 | 2021-10-19 19:43:00 +0530 | [diff] [blame] | 557 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 558 | priv->tx_buf += len; |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static void zynqmp_qspi_genfifo_cmd(struct zynqmp_qspi_priv *priv) |
| 563 | { |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 564 | const struct spi_mem_op *op = priv->op; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 565 | u32 gen_fifo_cmd; |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 566 | u8 i, dummy_cycles, addr; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 567 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 568 | log_debug("%s, opcode: 0x%0X, addr.nbytes: %d, dummy.mbytes: %d\r\n", |
| 569 | __func__, op->cmd.opcode, op->addr.nbytes, op->dummy.nbytes); |
| 570 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 571 | /* Send opcode */ |
| 572 | gen_fifo_cmd = zynqmp_qspi_bus_select(priv); |
| 573 | gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->cmd.buswidth); |
| 574 | gen_fifo_cmd |= GQSPI_GFIFO_TX; |
| 575 | gen_fifo_cmd |= op->cmd.opcode; |
| 576 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
| 577 | |
| 578 | /* Send address */ |
| 579 | for (i = 0; i < op->addr.nbytes; i++) { |
| 580 | addr = op->addr.val >> (8 * (op->addr.nbytes - i - 1)); |
| 581 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 582 | gen_fifo_cmd = zynqmp_qspi_bus_select(priv); |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 583 | gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->addr.buswidth); |
| 584 | gen_fifo_cmd |= GQSPI_GFIFO_TX; |
| 585 | gen_fifo_cmd |= addr; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 586 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 587 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
| 588 | } |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 589 | |
| 590 | /* Send dummy */ |
| 591 | if (op->dummy.nbytes) { |
| 592 | dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth; |
| 593 | |
| 594 | gen_fifo_cmd = zynqmp_qspi_bus_select(priv); |
| 595 | gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(op->dummy.buswidth); |
| 596 | gen_fifo_cmd &= ~(GQSPI_GFIFO_TX | GQSPI_GFIFO_RX); |
| 597 | gen_fifo_cmd |= GQSPI_GFIFO_DATA_XFR_MASK; |
| 598 | gen_fifo_cmd |= dummy_cycles; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 599 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | static u32 zynqmp_qspi_calc_exp(struct zynqmp_qspi_priv *priv, |
| 604 | u32 *gen_fifo_cmd) |
| 605 | { |
| 606 | u32 expval = 8; |
| 607 | u32 len; |
| 608 | |
| 609 | while (1) { |
| 610 | if (priv->len > 255) { |
| 611 | if (priv->len & (1 << expval)) { |
| 612 | *gen_fifo_cmd &= ~GQSPI_GFIFO_IMD_MASK; |
| 613 | *gen_fifo_cmd |= GQSPI_GFIFO_EXP_MASK; |
| 614 | *gen_fifo_cmd |= expval; |
| 615 | priv->len -= (1 << expval); |
| 616 | return expval; |
| 617 | } |
| 618 | expval++; |
| 619 | } else { |
| 620 | *gen_fifo_cmd &= ~(GQSPI_GFIFO_IMD_MASK | |
| 621 | GQSPI_GFIFO_EXP_MASK); |
| 622 | *gen_fifo_cmd |= (u8)priv->len; |
| 623 | len = (u8)priv->len; |
| 624 | priv->len = 0; |
| 625 | return len; |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | static int zynqmp_qspi_genfifo_fill_tx(struct zynqmp_qspi_priv *priv) |
| 631 | { |
| 632 | u32 gen_fifo_cmd; |
| 633 | u32 len; |
| 634 | int ret = 0; |
| 635 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 636 | log_debug("%s, length: %d\r\n", __func__, priv->len); |
| 637 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 638 | gen_fifo_cmd = zynqmp_qspi_bus_select(priv); |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 639 | gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth); |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 640 | gen_fifo_cmd |= GQSPI_GFIFO_TX | GQSPI_GFIFO_DATA_XFR_MASK; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 641 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 642 | if (priv->stripe) |
| 643 | gen_fifo_cmd |= GQSPI_GFIFO_STRIPE_MASK; |
| 644 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 645 | while (priv->len) { |
| 646 | len = zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd); |
| 647 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
| 648 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 649 | if (gen_fifo_cmd & GQSPI_GFIFO_EXP_MASK) |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 650 | ret = zynqmp_qspi_fill_tx_fifo(priv, 1 << len); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 651 | else |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 652 | ret = zynqmp_qspi_fill_tx_fifo(priv, len); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 653 | |
| 654 | if (ret) |
| 655 | return ret; |
| 656 | } |
| 657 | return ret; |
| 658 | } |
| 659 | |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 660 | static int zynqmp_qspi_start_io(struct zynqmp_qspi_priv *priv, |
| 661 | u32 gen_fifo_cmd, u32 *buf) |
| 662 | { |
| 663 | u32 len; |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 664 | u32 config_reg, ier, isr; |
| 665 | u32 timeout = GQSPI_TIMEOUT; |
| 666 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 667 | u32 last_bits; |
| 668 | u32 *traverse = buf; |
| 669 | |
| 670 | while (priv->len) { |
| 671 | len = zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd); |
| 672 | /* If exponent bit is set, reset immediate to be 2^len */ |
| 673 | if (gen_fifo_cmd & GQSPI_GFIFO_EXP_MASK) |
| 674 | priv->bytes_to_receive = (1 << len); |
| 675 | else |
| 676 | priv->bytes_to_receive = len; |
| 677 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 678 | |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 679 | /* Manual start */ |
| 680 | config_reg = readl(®s->confr); |
| 681 | config_reg |= GQSPI_STRT_GEN_FIFO; |
| 682 | writel(config_reg, ®s->confr); |
| 683 | /* Enable RX interrupts for IO mode */ |
| 684 | ier = readl(®s->ier); |
| 685 | ier |= GQSPI_IXR_ALL_MASK; |
| 686 | writel(ier, ®s->ier); |
| 687 | while (priv->bytes_to_receive && timeout) { |
| 688 | isr = readl(®s->isr); |
| 689 | if (isr & GQSPI_IXR_RXNEMTY_MASK) { |
| 690 | if (priv->bytes_to_receive >= 4) { |
| 691 | *traverse = readl(®s->drxr); |
| 692 | traverse++; |
| 693 | priv->bytes_to_receive -= 4; |
| 694 | } else { |
| 695 | last_bits = readl(®s->drxr); |
| 696 | memcpy(traverse, &last_bits, |
| 697 | priv->bytes_to_receive); |
| 698 | priv->bytes_to_receive = 0; |
| 699 | } |
| 700 | timeout = GQSPI_TIMEOUT; |
| 701 | } else { |
| 702 | udelay(1); |
| 703 | timeout--; |
| 704 | } |
| 705 | } |
| 706 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 707 | if (!timeout) |
| 708 | return log_msg_retz("Timeout\n", timeout); |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 714 | static int zynqmp_qspi_start_dma(struct zynqmp_qspi_priv *priv, |
| 715 | u32 gen_fifo_cmd, u32 *buf) |
| 716 | { |
Venkatesh Yadav Abbarapu | fce730e | 2022-11-25 16:14:13 +0530 | [diff] [blame] | 717 | unsigned long addr; |
Ashok Reddy Soma | 822a243 | 2021-08-20 07:43:17 -0600 | [diff] [blame] | 718 | u32 size; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 719 | u32 actuallen = priv->len; |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 720 | u32 totallen = priv->len; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 721 | int ret = 0; |
| 722 | struct zynqmp_qspi_dma_regs *dma_regs = priv->dma_regs; |
| 723 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 724 | while (totallen) { |
| 725 | if (totallen >= SZ_512M) |
| 726 | priv->len = SZ_256M; |
| 727 | else |
| 728 | priv->len = totallen; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 729 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 730 | totallen -= priv->len; /* Save remaining bytes length to read */ |
| 731 | actuallen = priv->len; /* Actual number of bytes reading */ |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 732 | |
Venkatesh Yadav Abbarapu | fce730e | 2022-11-25 16:14:13 +0530 | [diff] [blame] | 733 | writel(lower_32_bits((unsigned long)buf), &dma_regs->dmadst); |
| 734 | writel(upper_32_bits((unsigned long)buf) & GENMASK(11, 0), |
| 735 | &dma_regs->dmadstmsb); |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 736 | writel(roundup(priv->len, GQSPI_DMA_ALIGN), &dma_regs->dmasize); |
| 737 | writel(GQSPI_DMA_DST_I_STS_MASK, &dma_regs->dmaier); |
| 738 | addr = (unsigned long)buf; |
| 739 | size = roundup(priv->len, GQSPI_DMA_ALIGN); |
Ashok Reddy Soma | 6753c8b | 2023-09-15 08:47:58 +0530 | [diff] [blame] | 740 | invalidate_dcache_range(addr, addr + size); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 741 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 742 | while (priv->len) { |
| 743 | zynqmp_qspi_calc_exp(priv, &gen_fifo_cmd); |
| 744 | zynqmp_qspi_fill_gen_fifo(priv, gen_fifo_cmd); |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | ret = wait_for_bit_le32(&dma_regs->dmaisr, |
| 748 | GQSPI_DMA_DST_I_STS_DONE, 1, |
| 749 | GQSPI_TIMEOUT, 1); |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 750 | if (ret) |
| 751 | return log_msg_ret("Timeout:\n", ret); |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 752 | |
Venkatesh Yadav Abbarapu | 5f97cef | 2023-09-15 08:47:59 +0530 | [diff] [blame] | 753 | invalidate_dcache_range(addr, addr + size); |
| 754 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 755 | writel(GQSPI_DMA_DST_I_STS_DONE, &dma_regs->dmaisr); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 756 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 757 | if (buf != priv->rx_buf) |
| 758 | memcpy(priv->rx_buf, buf, actuallen); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 759 | |
Ashok Reddy Soma | 2d322cc | 2022-08-25 06:59:04 -0600 | [diff] [blame] | 760 | buf = (u32 *)((u8 *)buf + actuallen); |
| 761 | priv->rx_buf = (u8 *)priv->rx_buf + actuallen; |
| 762 | } |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | static int zynqmp_qspi_genfifo_fill_rx(struct zynqmp_qspi_priv *priv) |
| 768 | { |
| 769 | u32 gen_fifo_cmd; |
| 770 | u32 *buf; |
| 771 | u32 actuallen = priv->len; |
| 772 | |
Ibai Erkiaga | 78974fb | 2023-10-13 13:37:27 +0100 | [diff] [blame] | 773 | log_debug("%s, length: %d\r\n", __func__, priv->len); |
| 774 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 775 | gen_fifo_cmd = zynqmp_qspi_bus_select(priv); |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 776 | gen_fifo_cmd |= zynqmp_qspi_genfifo_mode(priv->op->data.buswidth); |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 777 | gen_fifo_cmd |= GQSPI_GFIFO_RX | GQSPI_GFIFO_DATA_XFR_MASK; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 778 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 779 | if (priv->stripe) |
| 780 | gen_fifo_cmd |= GQSPI_GFIFO_STRIPE_MASK; |
| 781 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 782 | /* |
| 783 | * Check if receive buffer is aligned to 4 byte and length |
| 784 | * is multiples of four byte as we are using dma to receive. |
| 785 | */ |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 786 | if ((!((unsigned long)priv->rx_buf & (GQSPI_DMA_ALIGN - 1)) && |
| 787 | !(actuallen % GQSPI_DMA_ALIGN)) || priv->io_mode) { |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 788 | buf = (u32 *)priv->rx_buf; |
Ashok Reddy Soma | 96db8b6 | 2022-08-25 06:59:03 -0600 | [diff] [blame] | 789 | if (priv->io_mode) |
| 790 | return zynqmp_qspi_start_io(priv, gen_fifo_cmd, buf); |
| 791 | else |
| 792 | return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 793 | } |
| 794 | |
Ashok Reddy Soma | 7b4bded | 2022-08-25 06:59:05 -0600 | [diff] [blame] | 795 | ALLOC_CACHE_ALIGN_BUFFER(u8, tmp, roundup(priv->len, GQSPI_DMA_ALIGN)); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 796 | buf = (u32 *)tmp; |
| 797 | return zynqmp_qspi_start_dma(priv, gen_fifo_cmd, buf); |
| 798 | } |
| 799 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 800 | static int zynqmp_qspi_claim_bus(struct udevice *dev) |
| 801 | { |
| 802 | struct udevice *bus = dev->parent; |
| 803 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 804 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 805 | |
| 806 | writel(GQSPI_ENABLE_ENABLE_MASK, ®s->enbr); |
| 807 | |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | static int zynqmp_qspi_release_bus(struct udevice *dev) |
| 812 | { |
| 813 | struct udevice *bus = dev->parent; |
| 814 | struct zynqmp_qspi_priv *priv = dev_get_priv(bus); |
| 815 | struct zynqmp_qspi_regs *regs = priv->regs; |
| 816 | |
| 817 | writel(~GQSPI_ENABLE_ENABLE_MASK, ®s->enbr); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 822 | static bool zynqmp_qspi_update_stripe(const struct spi_mem_op *op) |
| 823 | { |
| 824 | /* |
| 825 | * This is a list of opcodes for which we must not use striped access |
| 826 | * even in dual parallel mode, but instead broadcast the same data to |
| 827 | * both chips. This is primarily erase commands and writing some |
| 828 | * registers. |
| 829 | */ |
| 830 | switch (op->cmd.opcode) { |
| 831 | case SPINOR_OP_BE_4K: |
| 832 | case SPINOR_OP_BE_32K: |
| 833 | case SPINOR_OP_CHIP_ERASE: |
| 834 | case SPINOR_OP_SE: |
| 835 | case SPINOR_OP_BE_32K_4B: |
| 836 | case SPINOR_OP_SE_4B: |
| 837 | case SPINOR_OP_BE_4K_4B: |
| 838 | case SPINOR_OP_WRSR: |
| 839 | case SPINOR_OP_WREAR: |
| 840 | case SPINOR_OP_BRWR: |
| 841 | return false; |
| 842 | case SPINOR_OP_WRSR2: |
| 843 | return op->addr.nbytes != 0; |
| 844 | default: |
| 845 | return true; |
| 846 | } |
| 847 | } |
| 848 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 849 | static int zynqmp_qspi_exec_op(struct spi_slave *slave, |
| 850 | const struct spi_mem_op *op) |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 851 | { |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 852 | struct zynqmp_qspi_priv *priv = dev_get_priv(slave->dev->parent); |
| 853 | int ret = 0; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 854 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 855 | priv->op = op; |
| 856 | priv->tx_buf = op->data.buf.out; |
| 857 | priv->rx_buf = op->data.buf.in; |
| 858 | priv->len = op->data.nbytes; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 859 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 860 | if (slave->flags & SPI_XFER_U_PAGE) |
| 861 | priv->u_page = 1; |
| 862 | else |
| 863 | priv->u_page = 0; |
| 864 | |
| 865 | if ((slave->flags & GQSPI_SELECT_LOWER_CS) && |
| 866 | (slave->flags & GQSPI_SELECT_UPPER_CS)) |
| 867 | priv->is_parallel = true; |
| 868 | |
| 869 | priv->stripe = 0; |
| 870 | priv->bus = 0; |
| 871 | |
| 872 | if (priv->is_parallel) { |
Marek Vasut | a2f7500 | 2024-11-03 00:57:31 +0100 | [diff] [blame] | 873 | if (slave->flags & SPI_XFER_LOWER) |
| 874 | priv->bus = 1; |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 875 | if (zynqmp_qspi_update_stripe(op)) |
| 876 | priv->stripe = 1; |
| 877 | } |
| 878 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 879 | zynqmp_qspi_chipselect(priv, 1); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 880 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 881 | /* Send opcode, addr, dummy */ |
| 882 | zynqmp_qspi_genfifo_cmd(priv); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 883 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 884 | /* Request the transfer */ |
| 885 | if (op->data.dir == SPI_MEM_DATA_IN) |
| 886 | ret = zynqmp_qspi_genfifo_fill_rx(priv); |
| 887 | else if (op->data.dir == SPI_MEM_DATA_OUT) |
| 888 | ret = zynqmp_qspi_genfifo_fill_tx(priv); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 889 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 890 | zynqmp_qspi_chipselect(priv, 0); |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 891 | |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 892 | priv->is_parallel = false; |
Marek Vasut | a2f7500 | 2024-11-03 00:57:31 +0100 | [diff] [blame] | 893 | slave->flags &= ~SPI_XFER_LOWER; |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 894 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 895 | return ret; |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 896 | } |
| 897 | |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 898 | static const struct spi_controller_mem_ops zynqmp_qspi_mem_ops = { |
| 899 | .exec_op = zynqmp_qspi_exec_op, |
| 900 | }; |
| 901 | |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 902 | static const struct dm_spi_ops zynqmp_qspi_ops = { |
| 903 | .claim_bus = zynqmp_qspi_claim_bus, |
| 904 | .release_bus = zynqmp_qspi_release_bus, |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 905 | .set_speed = zynqmp_qspi_set_speed, |
| 906 | .set_mode = zynqmp_qspi_set_mode, |
Brandon Maier | 4d9cce7 | 2021-01-20 10:39:46 -0600 | [diff] [blame] | 907 | .mem_ops = &zynqmp_qspi_mem_ops, |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 908 | }; |
| 909 | |
| 910 | static const struct udevice_id zynqmp_qspi_ids[] = { |
| 911 | { .compatible = "xlnx,zynqmp-qspi-1.0" }, |
Michal Simek | ed373eb | 2018-11-29 08:48:28 +0100 | [diff] [blame] | 912 | { .compatible = "xlnx,versal-qspi-1.0" }, |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 913 | { } |
| 914 | }; |
| 915 | |
| 916 | U_BOOT_DRIVER(zynqmp_qspi) = { |
| 917 | .name = "zynqmp_qspi", |
| 918 | .id = UCLASS_SPI, |
| 919 | .of_match = zynqmp_qspi_ids, |
| 920 | .ops = &zynqmp_qspi_ops, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 921 | .of_to_plat = zynqmp_qspi_of_to_plat, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 922 | .plat_auto = sizeof(struct zynqmp_qspi_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 923 | .priv_auto = sizeof(struct zynqmp_qspi_priv), |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 924 | .probe = zynqmp_qspi_probe, |
Venkatesh Yadav Abbarapu | f0b9d77 | 2024-09-26 10:25:06 +0530 | [diff] [blame] | 925 | .child_pre_probe = zynqmp_qspi_child_pre_probe, |
Siva Durga Prasad Paladugu | 7659738 | 2018-07-04 17:31:23 +0530 | [diff] [blame] | 926 | }; |