Skip to content

Commit 253b088

Browse files
committed
sh: clkfwk: Rework legacy CPG clock handling.
This moves out the old legacy CPG clocks to their own file, and converts over the existing users. With these clocks going away and each CPU dealing with them on their own, CPUs can gradually move over to the new interface. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 100890c commit 253b088

13 files changed

Lines changed: 110 additions & 63 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ config SH_PCLK_FREQ
513513
This is necessary for determining the reference clock value on
514514
platforms lacking an RTC.
515515

516+
config SH_CLK_CPG_LEGACY
517+
def_bool y
518+
516519
config SH_CLK_MD
517520
int "CPU Mode Pin Setting"
518521
depends on CPU_SH2

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct clk_lookup {
4747
#define CLK_ENABLE_ON_INIT (1 << 0)
4848

4949
/* Should be defined by processor-specific code */
50-
void arch_init_clk_ops(struct clk_ops **, int type);
50+
void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
5151
int __init arch_clk_init(void);
5252

5353
/* arch/sh/kernel/cpu/clock.c */
@@ -59,6 +59,9 @@ int clk_reparent(struct clk *child, struct clk *parent);
5959
int clk_register(struct clk *);
6060
void clk_unregister(struct clk *);
6161

62+
/* arch/sh/kernel/cpu/clock-cpg.c */
63+
int __init __deprecated cpg_clk_init(void);
64+
6265
/* the exported API, in addition to clk_set_rate */
6366
/**
6467
* clk_set_rate_ex - set the clock rate for a clock source, with additional parameter

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct sh_machine_vector {
4646

4747
void __iomem *(*mv_ioport_map)(unsigned long port, unsigned int size);
4848
void (*mv_ioport_unmap)(void __iomem *);
49+
50+
int (*mv_clk_init)(void);
4951
};
5052

5153
extern struct sh_machine_vector sh_mv;

‎arch/sh/kernel/cpu/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ obj-$(CONFIG_ARCH_SHMOBILE) += shmobile/
1717

1818
obj-$(CONFIG_UBC_WAKEUP) += ubc.o
1919
obj-$(CONFIG_SH_ADC) += adc.o
20+
obj-$(CONFIG_SH_CLK_CPG_LEGACY) += clock-cpg.o
2021

2122
obj-y += irq/ init.o clock.o

‎arch/sh/kernel/cpu/clock-cpg.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <linux/clk.h>
2+
#include <linux/compiler.h>
3+
#include <asm/clock.h>
4+
5+
static struct clk master_clk = {
6+
.name = "master_clk",
7+
.flags = CLK_ENABLE_ON_INIT,
8+
.rate = CONFIG_SH_PCLK_FREQ,
9+
};
10+
11+
static struct clk peripheral_clk = {
12+
.name = "peripheral_clk",
13+
.parent = &master_clk,
14+
.flags = CLK_ENABLE_ON_INIT,
15+
};
16+
17+
static struct clk bus_clk = {
18+
.name = "bus_clk",
19+
.parent = &master_clk,
20+
.flags = CLK_ENABLE_ON_INIT,
21+
};
22+
23+
static struct clk cpu_clk = {
24+
.name = "cpu_clk",
25+
.parent = &master_clk,
26+
.flags = CLK_ENABLE_ON_INIT,
27+
};
28+
29+
/*
30+
* The ordering of these clocks matters, do not change it.
31+
*/
32+
static struct clk *onchip_clocks[] = {
33+
&master_clk,
34+
&peripheral_clk,
35+
&bus_clk,
36+
&cpu_clk,
37+
};
38+
39+
int __init __deprecated cpg_clk_init(void)
40+
{
41+
int i, ret = 0;
42+
43+
for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
44+
struct clk *clk = onchip_clocks[i];
45+
arch_init_clk_ops(&clk->ops, i);
46+
if (clk->ops)
47+
ret |= clk_register(clk);
48+
}
49+
50+
return ret;
51+
}
52+
53+
/*
54+
* Placeholder for compatability, until the lazy CPUs do this
55+
* on their own.
56+
*/
57+
int __init __weak arch_clk_init(void)
58+
{
59+
return cpg_clk_init();
60+
}

‎arch/sh/kernel/cpu/clock.c‎

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,12 @@
3030
#include <linux/platform_device.h>
3131
#include <linux/proc_fs.h>
3232
#include <asm/clock.h>
33+
#include <asm/machvec.h>
3334

3435
static LIST_HEAD(clock_list);
3536
static DEFINE_SPINLOCK(clock_lock);
3637
static DEFINE_MUTEX(clock_list_sem);
3738

38-
/*
39-
* Each subtype is expected to define the init routines for these clocks,
40-
* as each subtype (or processor family) will have these clocks at the
41-
* very least. These are all provided through the CPG, which even some of
42-
* the more quirky parts (such as ST40, SH4-202, etc.) still have.
43-
*
44-
* The processor-specific code is expected to register any additional
45-
* clock sources that are of interest.
46-
*/
47-
static struct clk master_clk = {
48-
.name = "master_clk",
49-
.flags = CLK_ENABLE_ON_INIT,
50-
.rate = CONFIG_SH_PCLK_FREQ,
51-
};
52-
53-
static struct clk peripheral_clk = {
54-
.name = "peripheral_clk",
55-
.parent = &master_clk,
56-
.flags = CLK_ENABLE_ON_INIT,
57-
};
58-
59-
static struct clk bus_clk = {
60-
.name = "bus_clk",
61-
.parent = &master_clk,
62-
.flags = CLK_ENABLE_ON_INIT,
63-
};
64-
65-
static struct clk cpu_clk = {
66-
.name = "cpu_clk",
67-
.parent = &master_clk,
68-
.flags = CLK_ENABLE_ON_INIT,
69-
};
70-
71-
/*
72-
* The ordering of these clocks matters, do not change it.
73-
*/
74-
static struct clk *onchip_clocks[] = {
75-
&master_clk,
76-
&peripheral_clk,
77-
&bus_clk,
78-
&cpu_clk,
79-
};
80-
8139
/* Used for clocks that always have same value as the parent clock */
8240
unsigned long followparent_recalc(struct clk *clk)
8341
{
@@ -443,10 +401,6 @@ void clk_put(struct clk *clk)
443401
}
444402
EXPORT_SYMBOL_GPL(clk_put);
445403

446-
int __init __weak arch_clk_init(void)
447-
{
448-
return 0;
449-
}
450404

451405
static int show_clocks(char *buf, char **start, off_t off,
452406
int len, int *eof, void *data)
@@ -533,18 +487,22 @@ subsys_initcall(clk_sysdev_init);
533487

534488
int __init clk_init(void)
535489
{
536-
int i, ret = 0;
537-
538-
BUG_ON(!master_clk.rate);
539-
540-
for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
541-
struct clk *clk = onchip_clocks[i];
490+
int ret;
542491

543-
arch_init_clk_ops(&clk->ops, i);
544-
ret |= clk_register(clk);
492+
ret = arch_clk_init();
493+
if (unlikely(ret)) {
494+
pr_err("%s: CPU clock registration failed.\n", __func__);
495+
return ret;
545496
}
546497

547-
ret |= arch_clk_init();
498+
if (sh_mv.mv_clk_init) {
499+
ret = sh_mv.mv_clk_init();
500+
if (unlikely(ret)) {
501+
pr_err("%s: machvec clock initialization failed.\n",
502+
__func__);
503+
return ret;
504+
}
505+
}
548506

549507
/* Kick the child clocks.. */
550508
recalculate_root_clocks();

‎arch/sh/kernel/cpu/sh4/clock-sh4-202.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ static struct clk *sh4202_onchip_clocks[] = {
152152

153153
int __init arch_clk_init(void)
154154
{
155-
struct clk *clk = clk_get(NULL, "master_clk");
155+
struct clk *clk;
156156
int i, ret = 0;
157157

158+
cpg_clk_init();
159+
160+
clk = clk_get(NULL, "master_clk");
158161
for (i = 0; i < ARRAY_SIZE(sh4202_onchip_clocks); i++) {
159162
struct clk *clkp = sh4202_onchip_clocks[i];
160163

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,8 @@ int __init arch_clk_init(void)
892892
struct clk *clk;
893893
int i;
894894

895+
clk_cpg_init();
896+
895897
clk = clk_get(NULL, "master_clk");
896898
for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
897899
pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ static struct clk *sh7763_onchip_clocks[] = {
9292

9393
int __init arch_clk_init(void)
9494
{
95-
struct clk *clk = clk_get(NULL, "master_clk");
95+
struct clk *clk;
9696
int i, ret = 0;
9797

98+
cpg_clk_init();
99+
100+
clk = clk_get(NULL, "master_clk");
98101
for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
99102
struct clk *clkp = sh7763_onchip_clocks[i];
100103

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ static struct clk *sh7780_onchip_clocks[] = {
9898

9999
int __init arch_clk_init(void)
100100
{
101-
struct clk *clk = clk_get(NULL, "master_clk");
101+
struct clk *clk;
102102
int i, ret = 0;
103103

104+
cpg_clk_init();
105+
106+
clk = clk_get(NULL, "master_clk");
104107
for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
105108
struct clk *clkp = sh7780_onchip_clocks[i];
106109

0 commit comments

Comments
 (0)