Skip to content

Commit a028c6d

Browse files
lyakhhorms
authored andcommitted
ARM: shmobile: wait for MSTP clock status to toggle, when enabling it
On r-/sh-mobile SoCs MSTP clocks are used by the runtime PM to dynamically enable and disable peripheral clocks. To make sure the clock has really started we have to read back its status register until it confirms success. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
1 parent 38dbfb5 commit a028c6d

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎drivers/sh/clk/cpg.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,47 @@ static void sh_clk_write(int value, struct clk *clk)
3636
iowrite32(value, clk->mapped_reg);
3737
}
3838

39+
static unsigned int r8(const void __iomem *addr)
40+
{
41+
return ioread8(addr);
42+
}
43+
44+
static unsigned int r16(const void __iomem *addr)
45+
{
46+
return ioread16(addr);
47+
}
48+
49+
static unsigned int r32(const void __iomem *addr)
50+
{
51+
return ioread32(addr);
52+
}
53+
3954
static int sh_clk_mstp_enable(struct clk *clk)
4055
{
4156
sh_clk_write(sh_clk_read(clk) & ~(1 << clk->enable_bit), clk);
57+
if (clk->status_reg) {
58+
unsigned int (*read)(const void __iomem *addr);
59+
int i;
60+
void __iomem *mapped_status = (phys_addr_t)clk->status_reg -
61+
(phys_addr_t)clk->enable_reg + clk->mapped_reg;
62+
63+
if (clk->flags & CLK_ENABLE_REG_8BIT)
64+
read = r8;
65+
else if (clk->flags & CLK_ENABLE_REG_16BIT)
66+
read = r16;
67+
else
68+
read = r32;
69+
70+
for (i = 1000;
71+
(read(mapped_status) & (1 << clk->enable_bit)) && i;
72+
i--)
73+
cpu_relax();
74+
if (!i) {
75+
pr_err("cpg: failed to enable %p[%d]\n",
76+
clk->enable_reg, clk->enable_bit);
77+
return -ETIMEDOUT;
78+
}
79+
}
4280
return 0;
4381
}
4482

‎include/linux/sh_clk.h‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct clk {
5252
unsigned long flags;
5353

5454
void __iomem *enable_reg;
55+
void __iomem *status_reg;
5556
unsigned int enable_bit;
5657
void __iomem *mapped_reg;
5758

@@ -116,22 +117,26 @@ long clk_round_parent(struct clk *clk, unsigned long target,
116117
unsigned long *best_freq, unsigned long *parent_freq,
117118
unsigned int div_min, unsigned int div_max);
118119

119-
#define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _flags) \
120+
#define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \
120121
{ \
121122
.parent = _parent, \
122123
.enable_reg = (void __iomem *)_enable_reg, \
123124
.enable_bit = _enable_bit, \
125+
.status_reg = _status_reg, \
124126
.flags = _flags, \
125127
}
126128

127-
#define SH_CLK_MSTP32(_p, _r, _b, _f) \
128-
SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_32BIT)
129+
#define SH_CLK_MSTP32(_p, _r, _b, _f) \
130+
SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_32BIT)
129131

130-
#define SH_CLK_MSTP16(_p, _r, _b, _f) \
131-
SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_16BIT)
132+
#define SH_CLK_MSTP32_STS(_p, _r, _b, _s, _f) \
133+
SH_CLK_MSTP(_p, _r, _b, _s, _f | CLK_ENABLE_REG_32BIT)
132134

133-
#define SH_CLK_MSTP8(_p, _r, _b, _f) \
134-
SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_8BIT)
135+
#define SH_CLK_MSTP16(_p, _r, _b, _f) \
136+
SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_16BIT)
137+
138+
#define SH_CLK_MSTP8(_p, _r, _b, _f) \
139+
SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_8BIT)
135140

136141
int sh_clk_mstp_register(struct clk *clks, int nr);
137142

0 commit comments

Comments
 (0)