Skip to content

Commit e1c200a

Browse files
bijudaskrzk
authored andcommitted
memory: renesas-rpc-if: Add wrapper functions
Even though XSPI and RPCIF has different register layout, reuse the code by adding wrapper functions to support both XSPI and RPC-IF. While at it, replace error check for pm_runtime_resume_and_get(). Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Biju Das <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]>
1 parent 198158a commit e1c200a

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

drivers/memory/renesas-rpc-if.c

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,11 @@ static void rpcif_rzg2l_timing_adjust_sdr(struct rpcif_priv *rpc)
174174
regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000032);
175175
}
176176

177-
int rpcif_hw_init(struct device *dev, bool hyperflash)
177+
static int rpcif_hw_init_impl(struct rpcif_priv *rpc, bool hyperflash)
178178
{
179-
struct rpcif_priv *rpc = dev_get_drvdata(dev);
180179
u32 dummy;
181180
int ret;
182181

183-
ret = pm_runtime_resume_and_get(dev);
184-
if (ret)
185-
return ret;
186-
187182
if (rpc->info->type == RPCIF_RZ_G2L) {
188183
ret = reset_control_reset(rpc->rstc);
189184
if (ret)
@@ -231,12 +226,26 @@ int rpcif_hw_init(struct device *dev, bool hyperflash)
231226
regmap_write(rpc->regmap, RPCIF_SSLDR, RPCIF_SSLDR_SPNDL(7) |
232227
RPCIF_SSLDR_SLNDL(7) | RPCIF_SSLDR_SCKDL(7));
233228

234-
pm_runtime_put(dev);
235-
236229
rpc->bus_size = hyperflash ? 2 : 1;
237230

238231
return 0;
239232
}
233+
234+
int rpcif_hw_init(struct device *dev, bool hyperflash)
235+
{
236+
struct rpcif_priv *rpc = dev_get_drvdata(dev);
237+
int ret;
238+
239+
ret = pm_runtime_resume_and_get(dev);
240+
if (ret)
241+
return ret;
242+
243+
ret = rpcif_hw_init_impl(rpc, hyperflash);
244+
245+
pm_runtime_put(dev);
246+
247+
return ret;
248+
}
240249
EXPORT_SYMBOL(rpcif_hw_init);
241250

242251
static int wait_msg_xfer_end(struct rpcif_priv *rpc)
@@ -261,11 +270,9 @@ static u8 rpcif_bit_size(u8 buswidth)
261270
return buswidth > 4 ? 2 : ilog2(buswidth);
262271
}
263272

264-
void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
265-
size_t *len)
273+
static void rpcif_prepare_impl(struct rpcif_priv *rpc, const struct rpcif_op *op,
274+
u64 *offs, size_t *len)
266275
{
267-
struct rpcif_priv *rpc = dev_get_drvdata(dev);
268-
269276
rpc->smcr = 0;
270277
rpc->smadr = 0;
271278
rpc->enable = 0;
@@ -346,18 +353,21 @@ void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
346353
rpc->enable |= RPCIF_SMENR_SPIDB(rpcif_bit_size(op->data.buswidth));
347354
}
348355
}
349-
EXPORT_SYMBOL(rpcif_prepare);
350356

351-
int rpcif_manual_xfer(struct device *dev)
357+
void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
358+
size_t *len)
352359
{
353360
struct rpcif_priv *rpc = dev_get_drvdata(dev);
361+
362+
rpcif_prepare_impl(rpc, op, offs, len);
363+
}
364+
EXPORT_SYMBOL(rpcif_prepare);
365+
366+
static int rpcif_manual_xfer_impl(struct rpcif_priv *rpc)
367+
{
354368
u32 smenr, smcr, pos = 0, max = rpc->bus_size == 2 ? 8 : 4;
355369
int ret = 0;
356370

357-
ret = pm_runtime_resume_and_get(dev);
358-
if (ret < 0)
359-
return ret;
360-
361371
regmap_update_bits(rpc->regmap, RPCIF_PHYCNT,
362372
RPCIF_PHYCNT_CAL, RPCIF_PHYCNT_CAL);
363373
regmap_update_bits(rpc->regmap, RPCIF_CMNCR,
@@ -465,15 +475,29 @@ int rpcif_manual_xfer(struct device *dev)
465475
goto err_out;
466476
}
467477

468-
exit:
469-
pm_runtime_put(dev);
470478
return ret;
471479

472480
err_out:
473481
if (reset_control_reset(rpc->rstc))
474-
dev_err(dev, "Failed to reset HW\n");
475-
rpcif_hw_init(dev, rpc->bus_size == 2);
476-
goto exit;
482+
dev_err(rpc->dev, "Failed to reset HW\n");
483+
rpcif_hw_init_impl(rpc, rpc->bus_size == 2);
484+
return ret;
485+
}
486+
487+
int rpcif_manual_xfer(struct device *dev)
488+
{
489+
struct rpcif_priv *rpc = dev_get_drvdata(dev);
490+
int ret;
491+
492+
ret = pm_runtime_resume_and_get(dev);
493+
if (ret)
494+
return ret;
495+
496+
ret = rpcif_manual_xfer_impl(rpc);
497+
498+
pm_runtime_put(dev);
499+
500+
return ret;
477501
}
478502
EXPORT_SYMBOL(rpcif_manual_xfer);
479503

@@ -519,20 +543,15 @@ static void memcpy_fromio_readw(void *to,
519543
}
520544
}
521545

522-
ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf)
546+
static size_t rpcif_dirmap_read_impl(struct rpcif_priv *rpc, u64 offs,
547+
size_t len, void *buf)
523548
{
524-
struct rpcif_priv *rpc = dev_get_drvdata(dev);
525549
loff_t from = offs & (rpc->size - 1);
526550
size_t size = rpc->size - from;
527-
int ret;
528551

529552
if (len > size)
530553
len = size;
531554

532-
ret = pm_runtime_resume_and_get(dev);
533-
if (ret < 0)
534-
return ret;
535-
536555
regmap_update_bits(rpc->regmap, RPCIF_CMNCR, RPCIF_CMNCR_MD, 0);
537556
regmap_write(rpc->regmap, RPCIF_DRCR, 0);
538557
regmap_write(rpc->regmap, RPCIF_DRCMR, rpc->command);
@@ -549,9 +568,24 @@ ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf)
549568
else
550569
memcpy_fromio(buf, rpc->dirmap + from, len);
551570

571+
return len;
572+
}
573+
574+
ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf)
575+
{
576+
struct rpcif_priv *rpc = dev_get_drvdata(dev);
577+
size_t read;
578+
int ret;
579+
580+
ret = pm_runtime_resume_and_get(dev);
581+
if (ret)
582+
return ret;
583+
584+
read = rpcif_dirmap_read_impl(rpc, offs, len, buf);
585+
552586
pm_runtime_put(dev);
553587

554-
return len;
588+
return read;
555589
}
556590
EXPORT_SYMBOL(rpcif_dirmap_read);
557591

0 commit comments

Comments
 (0)