aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2011-11-22 00:33:18 -0500
committerPaul Mundt <lethal@linux-sh.org>2011-11-24 03:15:23 -0500
commit56242a1fc595d158eddefbb4d6d76e82c2535f55 (patch)
tree78964e2ccde88e09ebb12412de26ab58f7b1417b
parenta9098b372606a15745cdeb012de4ee91c0df82c4 (diff)
sh: clkfwk: setup clock parent from current register value
Some clocks can select its parent clock by CPG register. But it might have been modified by boot-loader or something. This patch removed fixed initial parent clock, and setup it from their current register settings. It works on div6 reparent clocks for now. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
-rw-r--r--arch/arm/mach-shmobile/clock-sh7372.c6
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7724.c4
-rw-r--r--drivers/sh/clk/cpg.c35
-rw-r--r--include/linux/sh_clk.h9
4 files changed, 46 insertions, 8 deletions
diff --git a/arch/arm/mach-shmobile/clock-sh7372.c b/arch/arm/mach-shmobile/clock-sh7372.c
index 995a9c3aec8f..e349c22a0d71 100644
--- a/arch/arm/mach-shmobile/clock-sh7372.c
+++ b/arch/arm/mach-shmobile/clock-sh7372.c
@@ -411,11 +411,11 @@ static struct clk *fsibckcr_parent[] = {
411}; 411};
412 412
413static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = { 413static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
414 [DIV6_HDMI] = SH_CLK_DIV6_EXT(&pllc1_div2_clk, HDMICKCR, 0, 414 [DIV6_HDMI] = SH_CLK_DIV6_EXT(HDMICKCR, 0,
415 hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2), 415 hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2),
416 [DIV6_FSIA] = SH_CLK_DIV6_EXT(&pllc1_div2_clk, FSIACKCR, 0, 416 [DIV6_FSIA] = SH_CLK_DIV6_EXT(FSIACKCR, 0,
417 fsiackcr_parent, ARRAY_SIZE(fsiackcr_parent), 6, 2), 417 fsiackcr_parent, ARRAY_SIZE(fsiackcr_parent), 6, 2),
418 [DIV6_FSIB] = SH_CLK_DIV6_EXT(&pllc1_div2_clk, FSIBCKCR, 0, 418 [DIV6_FSIB] = SH_CLK_DIV6_EXT(FSIBCKCR, 0,
419 fsibckcr_parent, ARRAY_SIZE(fsibckcr_parent), 6, 2), 419 fsibckcr_parent, ARRAY_SIZE(fsibckcr_parent), 6, 2),
420}; 420};
421 421
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
index 8668f557e0ac..77118387f1cf 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
@@ -189,9 +189,9 @@ static struct clk *fclkbcr_parent[] = {
189}; 189};
190 190
191static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = { 191static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
192 [DIV6_FA] = SH_CLK_DIV6_EXT(&div3_clk, FCLKACR, 0, 192 [DIV6_FA] = SH_CLK_DIV6_EXT(FCLKACR, 0,
193 fclkacr_parent, ARRAY_SIZE(fclkacr_parent), 6, 2), 193 fclkacr_parent, ARRAY_SIZE(fclkacr_parent), 6, 2),
194 [DIV6_FB] = SH_CLK_DIV6_EXT(&div3_clk, FCLKBCR, 0, 194 [DIV6_FB] = SH_CLK_DIV6_EXT(FCLKBCR, 0,
195 fclkbcr_parent, ARRAY_SIZE(fclkbcr_parent), 6, 2), 195 fclkbcr_parent, ARRAY_SIZE(fclkbcr_parent), 6, 2),
196}; 196};
197 197
diff --git a/drivers/sh/clk/cpg.c b/drivers/sh/clk/cpg.c
index 82dd6fb17838..5e4301b936e7 100644
--- a/drivers/sh/clk/cpg.c
+++ b/drivers/sh/clk/cpg.c
@@ -167,6 +167,38 @@ static struct clk_ops sh_clk_div6_reparent_clk_ops = {
167 .set_parent = sh_clk_div6_set_parent, 167 .set_parent = sh_clk_div6_set_parent,
168}; 168};
169 169
170static int __init sh_clk_init_parent(struct clk *clk)
171{
172 u32 val;
173
174 if (clk->parent)
175 return 0;
176
177 if (!clk->parent_table || !clk->parent_num)
178 return 0;
179
180 if (!clk->src_width) {
181 pr_err("sh_clk_init_parent: cannot select parent clock\n");
182 return -EINVAL;
183 }
184
185 val = (__raw_readl(clk->enable_reg) >> clk->src_shift);
186 val &= (1 << clk->src_width) - 1;
187
188 if (val >= clk->parent_num) {
189 pr_err("sh_clk_init_parent: parent table size failed\n");
190 return -EINVAL;
191 }
192
193 clk->parent = clk->parent_table[val];
194 if (!clk->parent) {
195 pr_err("sh_clk_init_parent: unable to set parent");
196 return -EINVAL;
197 }
198
199 return 0;
200}
201
170static int __init sh_clk_div6_register_ops(struct clk *clks, int nr, 202static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
171 struct clk_ops *ops) 203 struct clk_ops *ops)
172{ 204{
@@ -190,6 +222,9 @@ static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
190 clkp->ops = ops; 222 clkp->ops = ops;
191 clkp->freq_table = freq_table + (k * freq_table_size); 223 clkp->freq_table = freq_table + (k * freq_table_size);
192 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 224 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
225 ret = sh_clk_init_parent(clkp);
226 if (ret < 0)
227 break;
193 228
194 ret = clk_register(clkp); 229 ret = clk_register(clkp);
195 } 230 }
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index a20831cf336a..e834304c0b6a 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -131,10 +131,9 @@ int sh_clk_div4_enable_register(struct clk *clks, int nr,
131int sh_clk_div4_reparent_register(struct clk *clks, int nr, 131int sh_clk_div4_reparent_register(struct clk *clks, int nr,
132 struct clk_div4_table *table); 132 struct clk_div4_table *table);
133 133
134#define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \ 134#define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \
135 _num_parents, _src_shift, _src_width) \ 135 _num_parents, _src_shift, _src_width) \
136{ \ 136{ \
137 .parent = _parent, \
138 .enable_reg = (void __iomem *)_reg, \ 137 .enable_reg = (void __iomem *)_reg, \
139 .flags = _flags, \ 138 .flags = _flags, \
140 .parent_table = _parents, \ 139 .parent_table = _parents, \
@@ -144,7 +143,11 @@ int sh_clk_div4_reparent_register(struct clk *clks, int nr,
144} 143}
145 144
146#define SH_CLK_DIV6(_parent, _reg, _flags) \ 145#define SH_CLK_DIV6(_parent, _reg, _flags) \
147 SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0) 146{ \
147 .parent = _parent, \
148 .enable_reg = (void __iomem *)_reg, \
149 .flags = _flags, \
150}
148 151
149int sh_clk_div6_register(struct clk *clks, int nr); 152int sh_clk_div6_register(struct clk *clks, int nr);
150int sh_clk_div6_reparent_register(struct clk *clks, int nr); 153int sh_clk_div6_reparent_register(struct clk *clks, int nr);