@@ -174,16 +174,11 @@ static void rpcif_rzg2l_timing_adjust_sdr(struct rpcif_priv *rpc)
regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000032);
}
-int rpcif_hw_init(struct device *dev, bool hyperflash)
+static int rpcif_hw_init_helper(struct rpcif_priv *rpc, bool hyperflash)
{
- struct rpcif_priv *rpc = dev_get_drvdata(dev);
u32 dummy;
int ret;
- ret = pm_runtime_resume_and_get(dev);
- if (ret)
- return ret;
-
if (rpc->info->type == RPCIF_RZ_G2L) {
ret = reset_control_reset(rpc->rstc);
if (ret)
@@ -231,12 +226,26 @@ int rpcif_hw_init(struct device *dev, bool hyperflash)
regmap_write(rpc->regmap, RPCIF_SSLDR, RPCIF_SSLDR_SPNDL(7) |
RPCIF_SSLDR_SLNDL(7) | RPCIF_SSLDR_SCKDL(7));
- pm_runtime_put(dev);
-
rpc->bus_size = hyperflash ? 2 : 1;
return 0;
}
+
+int rpcif_hw_init(struct device *dev, bool hyperflash)
+{
+ struct rpcif_priv *rpc = dev_get_drvdata(dev);
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret)
+ return ret;
+
+ ret = rpcif_hw_init_helper(rpc, hyperflash);
+
+ pm_runtime_put(dev);
+
+ return ret;
+}
EXPORT_SYMBOL(rpcif_hw_init);
static int wait_msg_xfer_end(struct rpcif_priv *rpc)
@@ -261,11 +270,9 @@ static u8 rpcif_bit_size(u8 buswidth)
return buswidth > 4 ? 2 : ilog2(buswidth);
}
-void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
- size_t *len)
+static void rpcif_prepare_helper(struct rpcif_priv *rpc, const struct rpcif_op *op,
+ u64 *offs, size_t *len)
{
- struct rpcif_priv *rpc = dev_get_drvdata(dev);
-
rpc->smcr = 0;
rpc->smadr = 0;
rpc->enable = 0;
@@ -346,18 +353,21 @@ void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
rpc->enable |= RPCIF_SMENR_SPIDB(rpcif_bit_size(op->data.buswidth));
}
}
-EXPORT_SYMBOL(rpcif_prepare);
-int rpcif_manual_xfer(struct device *dev)
+void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *offs,
+ size_t *len)
{
struct rpcif_priv *rpc = dev_get_drvdata(dev);
+
+ rpcif_prepare_helper(rpc, op, offs, len);
+}
+EXPORT_SYMBOL(rpcif_prepare);
+
+static int rpcif_manual_xfer_helper(struct rpcif_priv *rpc)
+{
u32 smenr, smcr, pos = 0, max = rpc->bus_size == 2 ? 8 : 4;
int ret = 0;
- ret = pm_runtime_resume_and_get(dev);
- if (ret < 0)
- return ret;
-
regmap_update_bits(rpc->regmap, RPCIF_PHYCNT,
RPCIF_PHYCNT_CAL, RPCIF_PHYCNT_CAL);
regmap_update_bits(rpc->regmap, RPCIF_CMNCR,
@@ -465,15 +475,29 @@ int rpcif_manual_xfer(struct device *dev)
goto err_out;
}
-exit:
- pm_runtime_put(dev);
return ret;
err_out:
if (reset_control_reset(rpc->rstc))
- dev_err(dev, "Failed to reset HW\n");
- rpcif_hw_init(dev, rpc->bus_size == 2);
- goto exit;
+ dev_err(rpc->dev, "Failed to reset HW\n");
+ rpcif_hw_init_helper(rpc, rpc->bus_size == 2);
+ return ret;
+}
+
+int rpcif_manual_xfer(struct device *dev)
+{
+ struct rpcif_priv *rpc = dev_get_drvdata(dev);
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret)
+ return ret;
+
+ ret = rpcif_manual_xfer_helper(rpc);
+
+ pm_runtime_put(dev);
+
+ return ret;
}
EXPORT_SYMBOL(rpcif_manual_xfer);
@@ -519,20 +543,15 @@ static void memcpy_fromio_readw(void *to,
}
}
-ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf)
+static ssize_t rpcif_dirmap_read_helper(struct rpcif_priv *rpc, u64 offs,
+ size_t len, void *buf)
{
- struct rpcif_priv *rpc = dev_get_drvdata(dev);
loff_t from = offs & (rpc->size - 1);
size_t size = rpc->size - from;
- int ret;
if (len > size)
len = size;
- ret = pm_runtime_resume_and_get(dev);
- if (ret < 0)
- return ret;
-
regmap_update_bits(rpc->regmap, RPCIF_CMNCR, RPCIF_CMNCR_MD, 0);
regmap_write(rpc->regmap, RPCIF_DRCR, 0);
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)
else
memcpy_fromio(buf, rpc->dirmap + from, len);
+ return len;
+}
+
+ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *buf)
+{
+ struct rpcif_priv *rpc = dev_get_drvdata(dev);
+ ssize_t length;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret)
+ return ret;
+
+ length = rpcif_dirmap_read_helper(rpc, offs, len, buf);
+
pm_runtime_put(dev);
- return len;
+ return length;
}
EXPORT_SYMBOL(rpcif_dirmap_read);
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() as it can return positive value as well. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- drivers/memory/renesas-rpc-if.c | 96 ++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 31 deletions(-)