Skip to content

Commit a77b5ac

Browse files
committed
sh: clkfwk: Update SH7785 for refactored clock framework.
This updates the SH7785 CPU code as well as the SH7785LCR board support code for making use of the newly refactored clock framework. Support for the legacy CPG clocks is dropped at this point, with the extal frequency fed in from the board code. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 253b088 commit a77b5ac

4 files changed

Lines changed: 125 additions & 104 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ config SH_PCLK_FREQ
514514
platforms lacking an RTC.
515515

516516
config SH_CLK_CPG_LEGACY
517-
def_bool y
517+
def_bool y if !CPU_SUBTYPE_SH7785
518518

519519
config SH_CLK_MD
520520
int "CPU Mode Pin Setting"

‎arch/sh/boards/board-sh7785lcr.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* Renesas Technology Corp. R0P7785LC0011RL Support.
33
*
44
* Copyright (C) 2008 Yoshihiro Shimoda
5+
* Copyright (C) 2009 Paul Mundt
56
*
67
* This file is subject to the terms and conditions of the GNU General Public
78
* License. See the file "COPYING" in the main directory of this archive
89
* for more details.
910
*/
10-
1111
#include <linux/init.h>
1212
#include <linux/platform_device.h>
1313
#include <linux/sm501.h>
@@ -19,8 +19,11 @@
1919
#include <linux/i2c-pca-platform.h>
2020
#include <linux/i2c-algo-pca.h>
2121
#include <linux/irq.h>
22-
#include <asm/heartbeat.h>
22+
#include <linux/clk.h>
23+
#include <linux/errno.h>
2324
#include <mach/sh7785lcr.h>
25+
#include <asm/heartbeat.h>
26+
#include <asm/clock.h>
2427

2528
/*
2629
* NOTE: This board has 2 physical memory maps.
@@ -273,6 +276,20 @@ void __init init_sh7785lcr_IRQ(void)
273276
plat_irq_setup_pins(IRQ_MODE_IRQ3210);
274277
}
275278

279+
static int sh7785lcr_clk_init(void)
280+
{
281+
struct clk *clk;
282+
int ret;
283+
284+
clk = clk_get(NULL, "extal");
285+
if (!clk || IS_ERR(clk))
286+
return PTR_ERR(clk);
287+
ret = clk_set_rate(clk, 33333333);
288+
clk_put(clk);
289+
290+
return ret;
291+
}
292+
276293
static void sh7785lcr_power_off(void)
277294
{
278295
unsigned char *p;
@@ -309,6 +326,7 @@ static void __init sh7785lcr_setup(char **cmdline_p)
309326
static struct sh_machine_vector mv_sh7785lcr __initmv = {
310327
.mv_name = "SH7785LCR",
311328
.mv_setup = sh7785lcr_setup,
329+
.mv_clk_init = sh7785lcr_clk_init,
312330
.mv_init_irq = init_sh7785lcr_IRQ,
313331
};
314332

‎arch/sh/include/asm/clock.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ struct clk {
3434

3535
unsigned long rate;
3636
unsigned long flags;
37+
3738
unsigned long arch_flags;
39+
void *priv;
3840
};
3941

4042
struct clk_lookup {

‎arch/sh/kernel/cpu/sh4a/clock-sh7785.c‎

Lines changed: 102 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,153 +3,154 @@
33
*
44
* SH7785 support for the clock framework
55
*
6-
* Copyright (C) 2007 Paul Mundt
6+
* Copyright (C) 2007 - 2009 Paul Mundt
77
*
88
* This file is subject to the terms and conditions of the GNU General Public
99
* License. See the file "COPYING" in the main directory of this archive
1010
* for more details.
1111
*/
1212
#include <linux/init.h>
1313
#include <linux/kernel.h>
14+
#include <linux/clk.h>
15+
#include <linux/io.h>
1416
#include <asm/clock.h>
1517
#include <asm/freq.h>
16-
#include <asm/io.h>
17-
18-
static int ifc_divisors[] = { 1, 2, 4, 6 };
19-
static int ufc_divisors[] = { 1, 1, 4, 6 };
20-
static int sfc_divisors[] = { 1, 1, 4, 6 };
21-
static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18,
22-
24, 32, 36, 48, 1, 1, 1, 1 };
23-
static int mfc_divisors[] = { 1, 1, 4, 6 };
24-
static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18,
25-
24, 32, 36, 48, 1, 1, 1, 1 };
26-
27-
static void master_clk_init(struct clk *clk)
28-
{
29-
clk->rate *= pfc_divisors[ctrl_inl(FRQMR1) & 0x000f];
30-
}
3118

32-
static struct clk_ops sh7785_master_clk_ops = {
33-
.init = master_clk_init,
19+
static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
20+
24, 32, 36, 48 };
21+
struct clk_priv {
22+
unsigned int shift;
3423
};
3524

36-
static unsigned long module_clk_recalc(struct clk *clk)
37-
{
38-
int idx = (ctrl_inl(FRQMR1) & 0x000f);
39-
return clk->parent->rate / pfc_divisors[idx];
40-
}
25+
#define FRQMR_CLK_DATA(_name, _shift) \
26+
static struct clk_priv _name##_data = { .shift = _shift, }
4127

42-
static struct clk_ops sh7785_module_clk_ops = {
43-
.recalc = module_clk_recalc,
44-
};
28+
FRQMR_CLK_DATA(pfc, 0);
29+
FRQMR_CLK_DATA(s3fc, 4);
30+
FRQMR_CLK_DATA(s2fc, 8);
31+
FRQMR_CLK_DATA(mfc, 12);
32+
FRQMR_CLK_DATA(bfc, 16);
33+
FRQMR_CLK_DATA(sfc, 20);
34+
FRQMR_CLK_DATA(ufc, 24);
35+
FRQMR_CLK_DATA(ifc, 28);
4536

46-
static unsigned long bus_clk_recalc(struct clk *clk)
37+
static unsigned long frqmr_clk_recalc(struct clk *clk)
4738
{
48-
int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
49-
return clk->parent->rate / bfc_divisors[idx];
50-
}
39+
struct clk_priv *data = clk->priv;
40+
unsigned int idx;
5141

52-
static struct clk_ops sh7785_bus_clk_ops = {
53-
.recalc = bus_clk_recalc,
54-
};
42+
idx = (__raw_readl(FRQMR1) >> data->shift) & 0x000f;
5543

56-
static unsigned long cpu_clk_recalc(struct clk *clk)
57-
{
58-
int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003);
59-
return clk->parent->rate / ifc_divisors[idx];
44+
/*
45+
* XXX: PLL1 multiplier is locked for the default clock mode,
46+
* when mode pin detection and configuration support is added,
47+
* select the multiplier dynamically.
48+
*/
49+
return clk->parent->rate * 36 / div2[idx];
6050
}
6151

62-
static struct clk_ops sh7785_cpu_clk_ops = {
63-
.recalc = cpu_clk_recalc,
52+
static struct clk_ops frqmr_clk_ops = {
53+
.recalc = frqmr_clk_recalc,
6454
};
6555

66-
static struct clk_ops *sh7785_clk_ops[] = {
67-
&sh7785_master_clk_ops,
68-
&sh7785_module_clk_ops,
69-
&sh7785_bus_clk_ops,
70-
&sh7785_cpu_clk_ops,
56+
/*
57+
* Default rate for the root input clock, reset this with clk_set_rate()
58+
* from the platform code.
59+
*/
60+
static struct clk extal_clk = {
61+
.name = "extal",
62+
.id = -1,
63+
.rate = 33333333,
7164
};
7265

73-
void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
74-
{
75-
if (idx < ARRAY_SIZE(sh7785_clk_ops))
76-
*ops = sh7785_clk_ops[idx];
77-
}
78-
79-
static unsigned long shyway_clk_recalc(struct clk *clk)
80-
{
81-
int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
82-
return clk->parent->rate / sfc_divisors[idx];
83-
}
84-
85-
static struct clk_ops sh7785_shyway_clk_ops = {
86-
.recalc = shyway_clk_recalc,
66+
static struct clk cpu_clk = {
67+
.name = "cpu_clk", /* Ick */
68+
.id = -1,
69+
.ops = &frqmr_clk_ops,
70+
.parent = &extal_clk,
71+
.flags = CLK_ENABLE_ON_INIT,
72+
.priv = &ifc_data,
8773
};
8874

89-
static struct clk sh7785_shyway_clk = {
90-
.name = "shyway_clk",
75+
static struct clk shyway_clk = {
76+
.name = "shyway_clk", /* SHck */
77+
.id = -1,
78+
.ops = &frqmr_clk_ops,
79+
.parent = &extal_clk,
9180
.flags = CLK_ENABLE_ON_INIT,
92-
.ops = &sh7785_shyway_clk_ops,
81+
.priv = &sfc_data,
9382
};
9483

95-
static unsigned long ddr_clk_recalc(struct clk *clk)
96-
{
97-
int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003);
98-
return clk->parent->rate / mfc_divisors[idx];
99-
}
84+
static struct clk peripheral_clk = {
85+
.name = "peripheral_clk", /* Pck */
86+
.id = -1,
87+
.ops = &frqmr_clk_ops,
88+
.parent = &extal_clk,
89+
.flags = CLK_ENABLE_ON_INIT,
90+
.priv = &pfc_data,
91+
};
10092

101-
static struct clk_ops sh7785_ddr_clk_ops = {
102-
.recalc = ddr_clk_recalc,
93+
static struct clk ddr_clk = {
94+
.name = "ddr_clk", /* DDRck */
95+
.id = -1,
96+
.ops = &frqmr_clk_ops,
97+
.parent = &extal_clk,
98+
.flags = CLK_ENABLE_ON_INIT,
99+
.priv = &mfc_data,
103100
};
104101

105-
static struct clk sh7785_ddr_clk = {
106-
.name = "ddr_clk",
102+
static struct clk bus_clk = {
103+
.name = "bus_clk", /* Bck */
104+
.id = -1,
105+
.ops = &frqmr_clk_ops,
106+
.parent = &extal_clk,
107107
.flags = CLK_ENABLE_ON_INIT,
108-
.ops = &sh7785_ddr_clk_ops,
108+
.priv = &bfc_data,
109109
};
110110

111-
static unsigned long ram_clk_recalc(struct clk *clk)
112-
{
113-
int idx = ((ctrl_inl(FRQMR1) >> 24) & 0x0003);
114-
return clk->parent->rate / ufc_divisors[idx];
115-
}
111+
static struct clk ga_clk = {
112+
.name = "ga_clk", /* GAck */
113+
.id = -1,
114+
.ops = &frqmr_clk_ops,
115+
.parent = &extal_clk,
116+
.priv = &s2fc_data,
117+
};
116118

117-
static struct clk_ops sh7785_ram_clk_ops = {
118-
.recalc = ram_clk_recalc,
119+
static struct clk du_clk = {
120+
.name = "du_clk", /* DUck */
121+
.id = -1,
122+
.ops = &frqmr_clk_ops,
123+
.parent = &extal_clk,
124+
.priv = &s3fc_data,
119125
};
120126

121-
static struct clk sh7785_ram_clk = {
122-
.name = "ram_clk",
127+
static struct clk umem_clk = {
128+
.name = "umem_clk", /* uck */
129+
.id = -1,
130+
.ops = &frqmr_clk_ops,
131+
.parent = &extal_clk,
123132
.flags = CLK_ENABLE_ON_INIT,
124-
.ops = &sh7785_ram_clk_ops,
133+
.priv = &ufc_data,
125134
};
126135

127-
/*
128-
* Additional SH7785-specific on-chip clocks that aren't already part of the
129-
* clock framework
130-
*/
131-
static struct clk *sh7785_onchip_clocks[] = {
132-
&sh7785_shyway_clk,
133-
&sh7785_ddr_clk,
134-
&sh7785_ram_clk,
136+
static struct clk *clks[] = {
137+
&extal_clk,
138+
&cpu_clk,
139+
&shyway_clk,
140+
&peripheral_clk,
141+
&ddr_clk,
142+
&bus_clk,
143+
&ga_clk,
144+
&du_clk,
145+
&umem_clk,
135146
};
136147

137148
int __init arch_clk_init(void)
138149
{
139-
struct clk *clk;
140150
int i, ret = 0;
141151

142-
cpg_clk_init();
143-
144-
clk = clk_get(NULL, "master_clk");
145-
for (i = 0; i < ARRAY_SIZE(sh7785_onchip_clocks); i++) {
146-
struct clk *clkp = sh7785_onchip_clocks[i];
147-
148-
clkp->parent = clk;
149-
ret |= clk_register(clkp);
150-
}
151-
152-
clk_put(clk);
152+
for (i = 0; i < ARRAY_SIZE(clks); i++)
153+
ret |= clk_register(clks[i]);
153154

154155
return ret;
155156
}

0 commit comments

Comments
 (0)