1 From 8dc61364164e79e44c07fa2ac0a7b6939f00d5db Mon Sep 17 00:00:00 2001
2 From: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
3 Date: Sun, 11 Jun 2023 15:03:13 +0100
4 Subject: [PATCH] nvmem: rockchip-otp: Add clks and reg_read to rockchip_data
6 In preparation to support new Rockchip OTP memory devices with different
7 clock configurations and register layout, extend rockchip_data struct
8 with the related members: clks, num_clks, reg_read.
10 Additionally, to avoid managing redundant driver data, drop num_clks
11 member from rockchip_otp struct and update all references to point to
12 the equivalent member in rockchip_data.
14 Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
15 Tested-by: Vincent Legoll <vincent.legoll@gmail.com>
16 Reviewed-by: Heiko Stuebner <heiko@sntech.de>
17 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
18 Message-ID: <20230611140330.154222-10-srinivas.kandagatla@linaro.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 drivers/nvmem/rockchip-otp.c | 79 ++++++++++++++++++++++--------------
22 1 file changed, 49 insertions(+), 30 deletions(-)
24 --- a/drivers/nvmem/rockchip-otp.c
25 +++ b/drivers/nvmem/rockchip-otp.c
28 #define OTPC_TIMEOUT 10000
30 +struct rockchip_data {
32 + const char * const *clks;
34 + nvmem_reg_read_t reg_read;
40 - struct clk_bulk_data *clks;
42 + struct clk_bulk_data *clks;
43 struct reset_control *rst;
46 -/* list of required clocks */
47 -static const char * const rockchip_otp_clocks[] = {
48 - "otp", "apb_pclk", "phy",
51 -struct rockchip_data {
53 + const struct rockchip_data *data;
56 static int rockchip_otp_reset(struct rockchip_otp *otp)
57 @@ -132,29 +130,23 @@ static int rockchip_otp_ecc_enable(struc
61 -static int rockchip_otp_read(void *context, unsigned int offset,
62 - void *val, size_t bytes)
63 +static int px30_otp_read(void *context, unsigned int offset,
64 + void *val, size_t bytes)
66 struct rockchip_otp *otp = context;
70 - ret = clk_bulk_prepare_enable(otp->num_clks, otp->clks);
72 - dev_err(otp->dev, "failed to prepare/enable clks\n");
77 ret = rockchip_otp_reset(otp);
79 dev_err(otp->dev, "failed to reset otp phy\n");
84 ret = rockchip_otp_ecc_enable(otp, false);
86 dev_err(otp->dev, "rockchip_otp_ecc_enable err\n");
91 writel(OTPC_USE_USER | OTPC_USE_USER_MASK, otp->base + OTPC_USER_CTRL);
92 @@ -174,8 +166,28 @@ static int rockchip_otp_read(void *conte
95 writel(0x0 | OTPC_USE_USER_MASK, otp->base + OTPC_USER_CTRL);
97 - clk_bulk_disable_unprepare(otp->num_clks, otp->clks);
102 +static int rockchip_otp_read(void *context, unsigned int offset,
103 + void *val, size_t bytes)
105 + struct rockchip_otp *otp = context;
108 + if (!otp->data || !otp->data->reg_read)
111 + ret = clk_bulk_prepare_enable(otp->data->num_clks, otp->clks);
113 + dev_err(otp->dev, "failed to prepare/enable clks\n");
117 + ret = otp->data->reg_read(context, offset, val, bytes);
119 + clk_bulk_disable_unprepare(otp->data->num_clks, otp->clks);
123 @@ -189,8 +201,15 @@ static struct nvmem_config otp_config =
124 .reg_read = rockchip_otp_read,
127 +static const char * const px30_otp_clocks[] = {
128 + "otp", "apb_pclk", "phy",
131 static const struct rockchip_data px30_data = {
133 + .clks = px30_otp_clocks,
134 + .num_clks = ARRAY_SIZE(px30_otp_clocks),
135 + .reg_read = px30_otp_read,
138 static const struct of_device_id rockchip_otp_match[] = {
139 @@ -225,21 +244,21 @@ static int rockchip_otp_probe(struct pla
145 otp->base = devm_platform_ioremap_resource(pdev, 0);
146 if (IS_ERR(otp->base))
147 return PTR_ERR(otp->base);
149 - otp->num_clks = ARRAY_SIZE(rockchip_otp_clocks);
150 - otp->clks = devm_kcalloc(dev, otp->num_clks,
151 - sizeof(*otp->clks), GFP_KERNEL);
152 + otp->clks = devm_kcalloc(dev, data->num_clks, sizeof(*otp->clks),
157 - for (i = 0; i < otp->num_clks; ++i)
158 - otp->clks[i].id = rockchip_otp_clocks[i];
159 + for (i = 0; i < data->num_clks; ++i)
160 + otp->clks[i].id = data->clks[i];
162 - ret = devm_clk_bulk_get(dev, otp->num_clks, otp->clks);
163 + ret = devm_clk_bulk_get(dev, data->num_clks, otp->clks);