blob: 51c37d72eb62c5e7c7145c1fcf13e98186a12439 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut6ca967b2017-11-29 06:29:46 +01002/*
3 * Renesas RCar Gen3 RPC QSPI driver
4 *
5 * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
Marek Vasut6ca967b2017-11-29 06:29:46 +01006 */
7
8#include <common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Marek Vasut6ca967b2017-11-29 06:29:46 +010010#include <asm/io.h>
11#include <clk.h>
12#include <dm.h>
13#include <dm/of_access.h>
14#include <dt-structs.h>
15#include <errno.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060016#include <linux/bitops.h>
Simon Glassc06c1be2020-05-10 11:40:08 -060017#include <linux/bug.h>
Marek Vasut6ca967b2017-11-29 06:29:46 +010018#include <linux/errno.h>
19#include <spi.h>
Cong Dangce335632022-08-25 06:06:54 +070020#include <spi-mem.h>
Marek Vasut6ca967b2017-11-29 06:29:46 +010021#include <wait_bit.h>
22
23#define RPC_CMNCR 0x0000 /* R/W */
24#define RPC_CMNCR_MD BIT(31)
25#define RPC_CMNCR_SFDE BIT(24)
26#define RPC_CMNCR_MOIIO3(val) (((val) & 0x3) << 22)
27#define RPC_CMNCR_MOIIO2(val) (((val) & 0x3) << 20)
28#define RPC_CMNCR_MOIIO1(val) (((val) & 0x3) << 18)
29#define RPC_CMNCR_MOIIO0(val) (((val) & 0x3) << 16)
30#define RPC_CMNCR_MOIIO_HIZ (RPC_CMNCR_MOIIO0(3) | RPC_CMNCR_MOIIO1(3) | \
31 RPC_CMNCR_MOIIO2(3) | RPC_CMNCR_MOIIO3(3))
32#define RPC_CMNCR_IO3FV(val) (((val) & 0x3) << 14)
33#define RPC_CMNCR_IO2FV(val) (((val) & 0x3) << 12)
34#define RPC_CMNCR_IO0FV(val) (((val) & 0x3) << 8)
35#define RPC_CMNCR_IOFV_HIZ (RPC_CMNCR_IO0FV(3) | RPC_CMNCR_IO2FV(3) | \
36 RPC_CMNCR_IO3FV(3))
37#define RPC_CMNCR_CPHAT BIT(6)
38#define RPC_CMNCR_CPHAR BIT(5)
39#define RPC_CMNCR_SSLP BIT(4)
40#define RPC_CMNCR_CPOL BIT(3)
41#define RPC_CMNCR_BSZ(val) (((val) & 0x3) << 0)
42
43#define RPC_SSLDR 0x0004 /* R/W */
44#define RPC_SSLDR_SPNDL(d) (((d) & 0x7) << 16)
45#define RPC_SSLDR_SLNDL(d) (((d) & 0x7) << 8)
46#define RPC_SSLDR_SCKDL(d) (((d) & 0x7) << 0)
47
48#define RPC_DRCR 0x000C /* R/W */
49#define RPC_DRCR_SSLN BIT(24)
50#define RPC_DRCR_RBURST(v) (((v) & 0x1F) << 16)
51#define RPC_DRCR_RCF BIT(9)
52#define RPC_DRCR_RBE BIT(8)
53#define RPC_DRCR_SSLE BIT(0)
54
55#define RPC_DRCMR 0x0010 /* R/W */
56#define RPC_DRCMR_CMD(c) (((c) & 0xFF) << 16)
57#define RPC_DRCMR_OCMD(c) (((c) & 0xFF) << 0)
58
59#define RPC_DREAR 0x0014 /* R/W */
60#define RPC_DREAR_EAV(v) (((v) & 0xFF) << 16)
61#define RPC_DREAR_EAC(v) (((v) & 0x7) << 0)
62
63#define RPC_DROPR 0x0018 /* R/W */
64#define RPC_DROPR_OPD3(o) (((o) & 0xFF) << 24)
65#define RPC_DROPR_OPD2(o) (((o) & 0xFF) << 16)
66#define RPC_DROPR_OPD1(o) (((o) & 0xFF) << 8)
67#define RPC_DROPR_OPD0(o) (((o) & 0xFF) << 0)
68
69#define RPC_DRENR 0x001C /* R/W */
70#define RPC_DRENR_CDB(o) (u32)((((o) & 0x3) << 30))
71#define RPC_DRENR_OCDB(o) (((o) & 0x3) << 28)
72#define RPC_DRENR_ADB(o) (((o) & 0x3) << 24)
73#define RPC_DRENR_OPDB(o) (((o) & 0x3) << 20)
74#define RPC_DRENR_SPIDB(o) (((o) & 0x3) << 16)
75#define RPC_DRENR_DME BIT(15)
76#define RPC_DRENR_CDE BIT(14)
77#define RPC_DRENR_OCDE BIT(12)
78#define RPC_DRENR_ADE(v) (((v) & 0xF) << 8)
79#define RPC_DRENR_OPDE(v) (((v) & 0xF) << 4)
80
81#define RPC_SMCR 0x0020 /* R/W */
82#define RPC_SMCR_SSLKP BIT(8)
83#define RPC_SMCR_SPIRE BIT(2)
84#define RPC_SMCR_SPIWE BIT(1)
85#define RPC_SMCR_SPIE BIT(0)
86
87#define RPC_SMCMR 0x0024 /* R/W */
88#define RPC_SMCMR_CMD(c) (((c) & 0xFF) << 16)
89#define RPC_SMCMR_OCMD(c) (((c) & 0xFF) << 0)
90
91#define RPC_SMADR 0x0028 /* R/W */
92#define RPC_SMOPR 0x002C /* R/W */
93#define RPC_SMOPR_OPD0(o) (((o) & 0xFF) << 0)
94#define RPC_SMOPR_OPD1(o) (((o) & 0xFF) << 8)
95#define RPC_SMOPR_OPD2(o) (((o) & 0xFF) << 16)
96#define RPC_SMOPR_OPD3(o) (((o) & 0xFF) << 24)
97
98#define RPC_SMENR 0x0030 /* R/W */
99#define RPC_SMENR_CDB(o) (((o) & 0x3) << 30)
100#define RPC_SMENR_OCDB(o) (((o) & 0x3) << 28)
101#define RPC_SMENR_ADB(o) (((o) & 0x3) << 24)
102#define RPC_SMENR_OPDB(o) (((o) & 0x3) << 20)
103#define RPC_SMENR_SPIDB(o) (((o) & 0x3) << 16)
104#define RPC_SMENR_DME BIT(15)
105#define RPC_SMENR_CDE BIT(14)
106#define RPC_SMENR_OCDE BIT(12)
107#define RPC_SMENR_ADE(v) (((v) & 0xF) << 8)
108#define RPC_SMENR_OPDE(v) (((v) & 0xF) << 4)
109#define RPC_SMENR_SPIDE(v) (((v) & 0xF) << 0)
110
111#define RPC_SMRDR0 0x0038 /* R */
112#define RPC_SMRDR1 0x003C /* R */
113#define RPC_SMWDR0 0x0040 /* R/W */
114#define RPC_SMWDR1 0x0044 /* R/W */
115#define RPC_CMNSR 0x0048 /* R */
116#define RPC_CMNSR_SSLF BIT(1)
117#define RPC_CMNSR_TEND BIT(0)
118
119#define RPC_DRDMCR 0x0058 /* R/W */
120#define RPC_DRDMCR_DMCYC(v) (((v) & 0xF) << 0)
121
122#define RPC_DRDRENR 0x005C /* R/W */
123#define RPC_DRDRENR_HYPE (0x5 << 12)
124#define RPC_DRDRENR_ADDRE BIT(8)
125#define RPC_DRDRENR_OPDRE BIT(4)
126#define RPC_DRDRENR_DRDRE BIT(0)
127
128#define RPC_SMDMCR 0x0060 /* R/W */
129#define RPC_SMDMCR_DMCYC(v) (((v) & 0xF) << 0)
130
131#define RPC_SMDRENR 0x0064 /* R/W */
132#define RPC_SMDRENR_HYPE (0x5 << 12)
133#define RPC_SMDRENR_ADDRE BIT(8)
134#define RPC_SMDRENR_OPDRE BIT(4)
135#define RPC_SMDRENR_SPIDRE BIT(0)
136
137#define RPC_PHYCNT 0x007C /* R/W */
138#define RPC_PHYCNT_CAL BIT(31)
139#define PRC_PHYCNT_OCTA_AA BIT(22)
140#define PRC_PHYCNT_OCTA_SA BIT(23)
141#define PRC_PHYCNT_EXDS BIT(21)
142#define RPC_PHYCNT_OCT BIT(20)
143#define RPC_PHYCNT_STRTIM(v) (((v) & 0x7) << 15)
Hai Pham581d2532021-08-05 14:38:26 +0700144#define RPC_PHYCNT_STRTIM2(v) ((((v) & 0x7) << 15) | (((v) & 0x8) << 24))
Marek Vasut6ca967b2017-11-29 06:29:46 +0100145#define RPC_PHYCNT_WBUF2 BIT(4)
146#define RPC_PHYCNT_WBUF BIT(2)
147#define RPC_PHYCNT_MEM(v) (((v) & 0x3) << 0)
148
149#define RPC_PHYINT 0x0088 /* R/W */
150#define RPC_PHYINT_RSTEN BIT(18)
151#define RPC_PHYINT_WPEN BIT(17)
152#define RPC_PHYINT_INTEN BIT(16)
153#define RPC_PHYINT_RST BIT(2)
154#define RPC_PHYINT_WP BIT(1)
155#define RPC_PHYINT_INT BIT(0)
156
157#define RPC_WBUF 0x8000 /* R/W size=4/8/16/32/64Bytes */
158#define RPC_WBUF_SIZE 0x100
159
160DECLARE_GLOBAL_DATA_PTR;
161
Simon Glassb75b15b2020-12-03 16:55:23 -0700162struct rpc_spi_plat {
Marek Vasut6ca967b2017-11-29 06:29:46 +0100163 fdt_addr_t regs;
164 fdt_addr_t extr;
165 s32 freq; /* Default clock freq, -1 for none */
166};
167
168struct rpc_spi_priv {
169 fdt_addr_t regs;
170 fdt_addr_t extr;
171 struct clk clk;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100172};
173
174static int rpc_spi_wait_sslf(struct udevice *dev)
175{
176 struct rpc_spi_priv *priv = dev_get_priv(dev->parent);
177
178 return wait_for_bit_le32((void *)priv->regs + RPC_CMNSR, RPC_CMNSR_SSLF,
179 false, 1000, false);
180}
181
182static int rpc_spi_wait_tend(struct udevice *dev)
183{
184 struct rpc_spi_priv *priv = dev_get_priv(dev->parent);
185
186 return wait_for_bit_le32((void *)priv->regs + RPC_CMNSR, RPC_CMNSR_TEND,
187 true, 1000, false);
188}
189
190static void rpc_spi_flush_read_cache(struct udevice *dev)
191{
192 struct udevice *bus = dev->parent;
193 struct rpc_spi_priv *priv = dev_get_priv(bus);
194
195 /* Flush read cache */
196 writel(RPC_DRCR_SSLN | RPC_DRCR_RBURST(0x1f) |
197 RPC_DRCR_RCF | RPC_DRCR_RBE | RPC_DRCR_SSLE,
198 priv->regs + RPC_DRCR);
199 readl(priv->regs + RPC_DRCR);
200
201}
202
Hai Pham286ed072021-08-16 09:26:36 +0700203static u32 rpc_spi_get_strobe_delay(void)
204{
205#ifndef CONFIG_RZA1
206 u32 cpu_type = rmobile_get_cpu_type();
207
208 /*
209 * NOTE: RPC_PHYCNT_STRTIM value:
210 * 0: On H3 ES1.x (not supported in mainline U-Boot)
211 * 6: On M3 ES1.x
212 * 7: On other R-Car Gen3
Hai Pham581d2532021-08-05 14:38:26 +0700213 * 15: On R-Car Gen4
Hai Pham286ed072021-08-16 09:26:36 +0700214 */
215 if (cpu_type == RMOBILE_CPU_TYPE_R8A7796 && rmobile_get_cpu_rev_integer() == 1)
216 return RPC_PHYCNT_STRTIM(6);
Hai Pham581d2532021-08-05 14:38:26 +0700217 else if (cpu_type == RMOBILE_CPU_TYPE_R8A779F0 ||
218 cpu_type == RMOBILE_CPU_TYPE_R8A779G0)
219 return RPC_PHYCNT_STRTIM2(15);
Hai Pham286ed072021-08-16 09:26:36 +0700220 else
221#endif
222 return RPC_PHYCNT_STRTIM(7);
223}
224
Marek Vasut6ca967b2017-11-29 06:29:46 +0100225static int rpc_spi_claim_bus(struct udevice *dev, bool manual)
226{
227 struct udevice *bus = dev->parent;
228 struct rpc_spi_priv *priv = dev_get_priv(bus);
229
Hai Pham286ed072021-08-16 09:26:36 +0700230 /* NOTE: The 0x260 are undocumented bits, but they must be set. */
231 writel(RPC_PHYCNT_CAL | rpc_spi_get_strobe_delay() | 0x260,
Marek Vasut6ca967b2017-11-29 06:29:46 +0100232 priv->regs + RPC_PHYCNT);
233 writel((manual ? RPC_CMNCR_MD : 0) | RPC_CMNCR_SFDE |
234 RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ | RPC_CMNCR_BSZ(0),
235 priv->regs + RPC_CMNCR);
236
237 writel(RPC_SSLDR_SPNDL(7) | RPC_SSLDR_SLNDL(7) |
238 RPC_SSLDR_SCKDL(7), priv->regs + RPC_SSLDR);
239
240 rpc_spi_flush_read_cache(dev);
241
242 return 0;
243}
244
245static int rpc_spi_release_bus(struct udevice *dev)
246{
247 struct udevice *bus = dev->parent;
248 struct rpc_spi_priv *priv = dev_get_priv(bus);
249
250 /* NOTE: The 0x260 are undocumented bits, but they must be set. */
Hai Pham286ed072021-08-16 09:26:36 +0700251 writel(rpc_spi_get_strobe_delay() | 0x260, priv->regs + RPC_PHYCNT);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100252
253 rpc_spi_flush_read_cache(dev);
254
255 return 0;
256}
257
Cong Dangce335632022-08-25 06:06:54 +0700258static int rpc_spi_mem_exec_op(struct spi_slave *spi,
259 const struct spi_mem_op *op)
Marek Vasut6ca967b2017-11-29 06:29:46 +0100260{
Cong Dangce335632022-08-25 06:06:54 +0700261 struct udevice *bus = spi->dev->parent;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100262 struct rpc_spi_priv *priv = dev_get_priv(bus);
Cong Dangce335632022-08-25 06:06:54 +0700263 const void *dout = op->data.buf.out ? op->data.buf.out : NULL;
264 void *din = op->data.buf.in ? op->data.buf.in : NULL;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100265 int ret = 0;
Cong Dangce335632022-08-25 06:06:54 +0700266 u32 offset = 0;
267 u32 smenr, smcr;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100268
Cong Dangce335632022-08-25 06:06:54 +0700269 smenr = 0;
270 offset = op->addr.val;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100271
Cong Dangce335632022-08-25 06:06:54 +0700272 switch (op->data.dir) {
273 case SPI_MEM_DATA_IN:
274 rpc_spi_claim_bus(spi->dev, false);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100275
Cong Dangce335632022-08-25 06:06:54 +0700276 writel(0, priv->regs + RPC_DRCMR);
277 writel(RPC_DRCMR_CMD(op->cmd.opcode), priv->regs + RPC_DRCMR);
278 smenr |= RPC_DRENR_CDE;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100279
Cong Dangce335632022-08-25 06:06:54 +0700280 writel(0, priv->regs + RPC_DREAR);
281 if (op->addr.nbytes == 4) {
282 writel(RPC_DREAR_EAV(offset >> 25) | RPC_DREAR_EAC(1),
283 priv->regs + RPC_DREAR);
284 smenr |= RPC_DRENR_ADE(0xF);
285 } else if (op->addr.nbytes == 3) {
286 smenr |= RPC_DRENR_ADE(0x7);
287 } else {
288 smenr |= RPC_DRENR_ADE(0);
289 }
Marek Vasut6ca967b2017-11-29 06:29:46 +0100290
Cong Dangce335632022-08-25 06:06:54 +0700291 writel(0, priv->regs + RPC_DRDMCR);
292 if (op->dummy.nbytes) {
293 writel(8 * op->dummy.nbytes - 1, priv->regs + RPC_DRDMCR);
294 smenr |= RPC_DRENR_DME;
295 }
Marek Vasut6ca967b2017-11-29 06:29:46 +0100296
Cong Dangce335632022-08-25 06:06:54 +0700297 writel(0, priv->regs + RPC_DROPR);
298 writel(smenr, priv->regs + RPC_DRENR);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100299
Cong Dangce335632022-08-25 06:06:54 +0700300 memcpy_fromio(din, (void *)(priv->extr + offset), op->data.nbytes);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100301
Cong Dangce335632022-08-25 06:06:54 +0700302 rpc_spi_release_bus(spi->dev);
303 break;
304 case SPI_MEM_DATA_OUT:
305 case SPI_MEM_NO_DATA:
306 rpc_spi_claim_bus(spi->dev, true);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100307
Cong Dangce335632022-08-25 06:06:54 +0700308 writel(0, priv->regs + RPC_SMCR);
309 writel(0, priv->regs + RPC_SMCMR);
310 writel(RPC_SMCMR_CMD(op->cmd.opcode), priv->regs + RPC_SMCMR);
311 smenr |= RPC_SMENR_CDE;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100312
Cong Dangce335632022-08-25 06:06:54 +0700313 writel(0, priv->regs + RPC_SMADR);
314 if (op->addr.nbytes == 4)
315 smenr |= RPC_SMENR_ADE(0xF);
316 else if (op->addr.nbytes == 3)
317 smenr |= RPC_SMENR_ADE(0x7);
318 else
319 smenr |= RPC_SMENR_ADE(0);
320 writel(offset, priv->regs + RPC_SMADR);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100321
Cong Dangce335632022-08-25 06:06:54 +0700322 writel(0, priv->regs + RPC_SMDMCR);
323 if (op->dummy.nbytes) {
324 writel(8 * op->dummy.nbytes - 1, priv->regs + RPC_SMDMCR);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100325 smenr |= RPC_SMENR_DME;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100326 }
327
328 writel(0, priv->regs + RPC_SMOPR);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100329 writel(0, priv->regs + RPC_SMDRENR);
330
Cong Dangce335632022-08-25 06:06:54 +0700331 if (dout && op->data.nbytes) {
Marek Vasut6ca967b2017-11-29 06:29:46 +0100332 u32 *datout = (u32 *)dout;
Cong Dangce335632022-08-25 06:06:54 +0700333 u32 wloop = DIV_ROUND_UP(op->data.nbytes, 4);
334
335 smenr |= RPC_SMENR_SPIDE(0xF);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100336
337 while (wloop--) {
338 smcr = RPC_SMCR_SPIWE | RPC_SMCR_SPIE;
339 if (wloop >= 1)
340 smcr |= RPC_SMCR_SSLKP;
341 writel(smenr, priv->regs + RPC_SMENR);
342 writel(*datout, priv->regs + RPC_SMWDR0);
343 writel(smcr, priv->regs + RPC_SMCR);
Cong Dangce335632022-08-25 06:06:54 +0700344 ret = rpc_spi_wait_tend(spi->dev);
345 if (ret) {
346 rpc_spi_release_bus(spi->dev);
347 return ret;
348 }
Marek Vasut6ca967b2017-11-29 06:29:46 +0100349 datout++;
Cong Dangce335632022-08-25 06:06:54 +0700350 smenr &= (~RPC_SMENR_CDE & ~RPC_SMENR_ADE(0xF));
Marek Vasut6ca967b2017-11-29 06:29:46 +0100351 }
352
Cong Dangce335632022-08-25 06:06:54 +0700353 ret = rpc_spi_wait_sslf(spi->dev);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100354 } else {
355 writel(smenr, priv->regs + RPC_SMENR);
356 writel(RPC_SMCR_SPIE, priv->regs + RPC_SMCR);
Cong Dangce335632022-08-25 06:06:54 +0700357 ret = rpc_spi_wait_tend(spi->dev);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100358 }
359
Cong Dangce335632022-08-25 06:06:54 +0700360 rpc_spi_release_bus(spi->dev);
361 break;
362 default:
363 break;
Marek Vasut6ca967b2017-11-29 06:29:46 +0100364 }
365
Marek Vasut6ca967b2017-11-29 06:29:46 +0100366 return ret;
367}
368
369static int rpc_spi_set_speed(struct udevice *bus, uint speed)
370{
371 /* This is a SPI NOR controller, do nothing. */
372 return 0;
373}
374
375static int rpc_spi_set_mode(struct udevice *bus, uint mode)
376{
377 /* This is a SPI NOR controller, do nothing. */
378 return 0;
379}
380
Cong Dangce335632022-08-25 06:06:54 +0700381static const struct spi_controller_mem_ops rpc_spi_mem_ops = {
382 .exec_op = rpc_spi_mem_exec_op
383};
384
Marek Vasut6ca967b2017-11-29 06:29:46 +0100385static int rpc_spi_bind(struct udevice *parent)
386{
387 const void *fdt = gd->fdt_blob;
388 ofnode node;
389 int ret, off;
390
391 /*
392 * Check if there are any SPI NOR child nodes, if so, bind as
393 * this controller will be operated in SPI mode.
394 */
395 dev_for_each_subnode(node, parent) {
396 off = ofnode_to_offset(node);
397
398 ret = fdt_node_check_compatible(fdt, off, "spi-flash");
399 if (!ret)
400 return 0;
401
402 ret = fdt_node_check_compatible(fdt, off, "jedec,spi-nor");
403 if (!ret)
404 return 0;
405 }
406
407 return -ENODEV;
408}
409
410static int rpc_spi_probe(struct udevice *dev)
411{
Simon Glassb75b15b2020-12-03 16:55:23 -0700412 struct rpc_spi_plat *plat = dev_get_plat(dev);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100413 struct rpc_spi_priv *priv = dev_get_priv(dev);
414
415 priv->regs = plat->regs;
416 priv->extr = plat->extr;
Marek Vasutf9db3b32019-05-04 18:52:33 +0200417#if CONFIG_IS_ENABLED(CLK)
Marek Vasut6ca967b2017-11-29 06:29:46 +0100418 clk_enable(&priv->clk);
Marek Vasutf9db3b32019-05-04 18:52:33 +0200419#endif
Marek Vasut6ca967b2017-11-29 06:29:46 +0100420 return 0;
421}
422
Simon Glassaad29ae2020-12-03 16:55:21 -0700423static int rpc_spi_of_to_plat(struct udevice *bus)
Marek Vasut6ca967b2017-11-29 06:29:46 +0100424{
Simon Glassb75b15b2020-12-03 16:55:23 -0700425 struct rpc_spi_plat *plat = dev_get_plat(bus);
Marek Vasut6ca967b2017-11-29 06:29:46 +0100426
427 plat->regs = dev_read_addr_index(bus, 0);
428 plat->extr = dev_read_addr_index(bus, 1);
429
Marek Vasutf9db3b32019-05-04 18:52:33 +0200430#if CONFIG_IS_ENABLED(CLK)
431 struct rpc_spi_priv *priv = dev_get_priv(bus);
432 int ret;
433
Marek Vasut6ca967b2017-11-29 06:29:46 +0100434 ret = clk_get_by_index(bus, 0, &priv->clk);
435 if (ret < 0) {
436 printf("%s: Could not get clock for %s: %d\n",
437 __func__, bus->name, ret);
438 return ret;
439 }
Marek Vasutf9db3b32019-05-04 18:52:33 +0200440#endif
Marek Vasut6ca967b2017-11-29 06:29:46 +0100441
442 plat->freq = dev_read_u32_default(bus, "spi-max-freq", 50000000);
443
444 return 0;
445}
446
447static const struct dm_spi_ops rpc_spi_ops = {
Marek Vasut6ca967b2017-11-29 06:29:46 +0100448 .set_speed = rpc_spi_set_speed,
449 .set_mode = rpc_spi_set_mode,
Cong Dangce335632022-08-25 06:06:54 +0700450 .mem_ops = &rpc_spi_mem_ops
Marek Vasut6ca967b2017-11-29 06:29:46 +0100451};
452
453static const struct udevice_id rpc_spi_ids[] = {
Geert Uytterhoeven431ded62022-03-29 14:19:09 +0200454 { .compatible = "renesas,r7s72100-rpc-if" },
455 { .compatible = "renesas,rcar-gen3-rpc-if" },
Marek Vasut6ca967b2017-11-29 06:29:46 +0100456 { }
457};
458
459U_BOOT_DRIVER(rpc_spi) = {
460 .name = "rpc_spi",
461 .id = UCLASS_SPI,
462 .of_match = rpc_spi_ids,
463 .ops = &rpc_spi_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700464 .of_to_plat = rpc_spi_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700465 .plat_auto = sizeof(struct rpc_spi_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700466 .priv_auto = sizeof(struct rpc_spi_priv),
Marek Vasut6ca967b2017-11-29 06:29:46 +0100467 .bind = rpc_spi_bind,
468 .probe = rpc_spi_probe,
469};