Skip to content

Commit 0c68c12

Browse files
finley1226rkhuangtao
authored andcommitted
nvmem: rockchip-otp: Reset opt phy before access otp
It would be more stable to reset phy before use user interface to access otp. Change-Id: Icd5660db15f6da7bad0ef8d01970f88aeca369a2 Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
1 parent 263dfde commit 0c68c12

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Documentation/devicetree/bindings/nvmem/rockchip-otp.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Required properties:
88
- size-cells: must be set to 1.
99
- clocks: Must contain an entry for each entry in clock-names.
1010
- clock-names: Should be "clk_opt", "pclk_otp" and "pclk_otp_phy".
11+
- resets: Must contain an entry for each entry in reset-names.
12+
See ../../reset/reset.txt for details.
13+
- reset-names: Should be "otp_phy".
1114

1215
See nvmem.txt for more information.
1316

drivers/nvmem/rockchip-otp.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/iopoll.h>
2222
#include <linux/module.h>
2323
#include <linux/nvmem-provider.h>
24+
#include <linux/reset.h>
2425
#include <linux/slab.h>
2526
#include <linux/of.h>
2627
#include <linux/of_platform.h>
@@ -67,12 +68,34 @@ struct rockchip_otp {
6768
struct clk *clk;
6869
struct clk *pclk;
6970
struct clk *pclk_phy;
71+
struct reset_control *rst;
7072
};
7173

7274
struct rockchip_data {
7375
int size;
7476
};
7577

78+
static int rockchip_otp_reset(struct rockchip_otp *otp)
79+
{
80+
int ret;
81+
82+
ret = reset_control_assert(otp->rst);
83+
if (ret) {
84+
dev_err(otp->dev, "failed to assert otp phy %d\n", ret);
85+
return ret;
86+
}
87+
88+
udelay(2);
89+
90+
ret = reset_control_deassert(otp->rst);
91+
if (ret) {
92+
dev_err(otp->dev, "failed to deassert otp phy %d\n", ret);
93+
return ret;
94+
}
95+
96+
return 0;
97+
}
98+
7699
static int rockchip_otp_wait_status(struct rockchip_otp *otp, u32 flag)
77100
{
78101
u32 status = 0;
@@ -138,6 +161,12 @@ static int rockchip_otp_read(void *context, unsigned int offset,
138161
goto opt_pclk;
139162
}
140163

164+
ret = rockchip_otp_reset(otp);
165+
if (ret) {
166+
dev_err(otp->dev, "failed to reset otp phy\n");
167+
goto opt_pclk_phy;
168+
}
169+
141170
ret = rockchip_otp_ecc_enable(otp, false);
142171
if (ret < 0) {
143172
dev_err(otp->dev, "rockchip_otp_ecc_enable err\n");
@@ -232,6 +261,10 @@ static int __init rockchip_otp_probe(struct platform_device *pdev)
232261
if (IS_ERR(otp->pclk_phy))
233262
return PTR_ERR(otp->pclk_phy);
234263

264+
otp->rst = devm_reset_control_get(dev, "otp_phy");
265+
if (IS_ERR(otp->rst))
266+
return PTR_ERR(otp->rst);
267+
235268
otp_config.size = data->size;
236269
otp_config.priv = otp;
237270
otp_config.dev = dev;

0 commit comments

Comments
 (0)