Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20250424090000.136804-6-biju.das.jz@bp.renesas.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by

Biju Das and committed by
Krzysztof Kozlowski
e1c200a4 198158a8

+65 -31
+65 -31
drivers/memory/renesas-rpc-if.c
··· 174 174 regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000032); 175 175 } 176 176 177 - int rpcif_hw_init(struct device *dev, bool hyperflash) 177 + static int rpcif_hw_init_impl(struct rpcif_priv *rpc, bool hyperflash) 178 178 { 179 - struct rpcif_priv *rpc = dev_get_drvdata(dev); 180 179 u32 dummy; 181 180 int ret; 182 - 183 - ret = pm_runtime_resume_and_get(dev); 184 - if (ret) 185 - return ret; 186 181 187 182 if (rpc->info->type == RPCIF_RZ_G2L) { 188 183 ret = reset_control_reset(rpc->rstc); ··· 226 231 regmap_write(rpc->regmap, RPCIF_SSLDR, RPCIF_SSLDR_SPNDL(7) | 227 232 RPCIF_SSLDR_SLNDL(7) | RPCIF_SSLDR_SCKDL(7)); 228 233 229 - pm_runtime_put(dev); 230 - 231 234 rpc->bus_size = hyperflash ? 2 : 1; 232 235 233 236 return 0; 237 + } 238 + 239 + int rpcif_hw_init(struct device *dev, bool hyperflash) 240 + { 241 + struct rpcif_priv *rpc = dev_get_drvdata(dev); 242 + int ret; 243 + 244 + ret = pm_runtime_resume_and_get(dev); 245 + if (ret) 246 + return ret; 247 + 248 + ret = rpcif_hw_init_impl(rpc, hyperflash); 249 + 250 + pm_runtime_put(dev); 251 + 252 + return ret; 234 253 } 235 254 EXPORT_SYMBOL(rpcif_hw_init); 236 255 ··· 270 261 return buswidth > 4 ? 2 : ilog2(buswidth); 271 262 } 272 263 273 - void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs, 274 - size_t *len) 264 + static void rpcif_prepare_impl(struct rpcif_priv *rpc, const struct rpcif_op *op, 265 + u64 *offs, size_t *len) 275 266 { 276 - struct rpcif_priv *rpc = dev_get_drvdata(dev); 277 - 278 267 rpc->smcr = 0; 279 268 rpc->smadr = 0; 280 269 rpc->enable = 0; ··· 353 346 rpc->enable |= RPCIF_SMENR_SPIDB(rpcif_bit_size(op->data.buswidth)); 354 347 } 355 348 } 356 - EXPORT_SYMBOL(rpcif_prepare); 357 349 358 - int rpcif_manual_xfer(struct device *dev) 350 + void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs, 351 + size_t *len) 359 352 { 360 353 struct rpcif_priv *rpc = dev_get_drvdata(dev); 354 + 355 + rpcif_prepare_impl(rpc, op, offs, len); 356 + } 357 + EXPORT_SYMBOL(rpcif_prepare); 358 + 359 + static int rpcif_manual_xfer_impl(struct rpcif_priv *rpc) 360 + { 361 361 u32 smenr, smcr, pos = 0, max = rpc->bus_size == 2 ? 8 : 4; 362 362 int ret = 0; 363 - 364 - ret = pm_runtime_resume_and_get(dev); 365 - if (ret < 0) 366 - return ret; 367 363 368 364 regmap_update_bits(rpc->regmap, RPCIF_PHYCNT, 369 365 RPCIF_PHYCNT_CAL, RPCIF_PHYCNT_CAL); ··· 475 465 goto err_out; 476 466 } 477 467 478 - exit: 479 - pm_runtime_put(dev); 480 468 return ret; 481 469 482 470 err_out: 483 471 if (reset_control_reset(rpc->rstc)) 484 - dev_err(dev, "Failed to reset HW\n"); 485 - rpcif_hw_init(dev, rpc->bus_size == 2); 486 - goto exit; 472 + dev_err(rpc->dev, "Failed to reset HW\n"); 473 + rpcif_hw_init_impl(rpc, rpc->bus_size == 2); 474 + return ret; 475 + } 476 + 477 + int rpcif_manual_xfer(struct device *dev) 478 + { 479 + struct rpcif_priv *rpc = dev_get_drvdata(dev); 480 + int ret; 481 + 482 + ret = pm_runtime_resume_and_get(dev); 483 + if (ret) 484 + return ret; 485 + 486 + ret = rpcif_manual_xfer_impl(rpc); 487 + 488 + pm_runtime_put(dev); 489 + 490 + return ret; 487 491 } 488 492 EXPORT_SYMBOL(rpcif_manual_xfer); 489 493 ··· 543 519 } 544 520 } 545 521 546 - ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf) 522 + static size_t rpcif_dirmap_read_impl(struct rpcif_priv *rpc, u64 offs, 523 + size_t len, void *buf) 547 524 { 548 - struct rpcif_priv *rpc = dev_get_drvdata(dev); 549 525 loff_t from = offs & (rpc->size - 1); 550 526 size_t size = rpc->size - from; 551 - int ret; 552 527 553 528 if (len > size) 554 529 len = size; 555 - 556 - ret = pm_runtime_resume_and_get(dev); 557 - if (ret < 0) 558 - return ret; 559 530 560 531 regmap_update_bits(rpc->regmap, RPCIF_CMNCR, RPCIF_CMNCR_MD, 0); 561 532 regmap_write(rpc->regmap, RPCIF_DRCR, 0); ··· 568 549 else 569 550 memcpy_fromio(buf, rpc->dirmap + from, len); 570 551 552 + return len; 553 + } 554 + 555 + ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf) 556 + { 557 + struct rpcif_priv *rpc = dev_get_drvdata(dev); 558 + size_t read; 559 + int ret; 560 + 561 + ret = pm_runtime_resume_and_get(dev); 562 + if (ret) 563 + return ret; 564 + 565 + read = rpcif_dirmap_read_impl(rpc, offs, len, buf); 566 + 571 567 pm_runtime_put(dev); 572 568 573 - return len; 569 + return read; 574 570 } 575 571 EXPORT_SYMBOL(rpcif_dirmap_read); 576 572