Skip to content

Commit a005bc6

Browse files
committed
Merge tag 'renesas-clk-for-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas into next/drivers
Renesas ARM Based SoC CPG/MSTP Clock Driver Updates for v4.3 * Add Clock Domain support to the Clock Pulse Generator (CPG) Module Stop (MSTP) Clocks driver using the generic PM Domain. * tag 'renesas-clk-for-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas: clk: shmobile: rz: Add CPG/MSTP Clock Domain support clk: shmobile: rcar-gen2: Add CPG/MSTP Clock Domain support clk: shmobile: r8a7779: Add CPG/MSTP Clock Domain support clk: shmobile: r8a7778: Add CPG/MSTP Clock Domain support clk: shmobile: Add CPG/MSTP Clock Domain support Signed-off-by: Olof Johansson <[email protected]>
2 parents 0bf4135 + f04b486 commit a005bc6

File tree

11 files changed

+213
-11
lines changed

11 files changed

+213
-11
lines changed
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
* Renesas R8A7778 Clock Pulse Generator (CPG)
22

33
The CPG generates core clocks for the R8A7778. It includes two PLLs and
4-
several fixed ratio dividers
4+
several fixed ratio dividers.
5+
The CPG also provides a Clock Domain for SoC devices, in combination with the
6+
CPG Module Stop (MSTP) Clocks.
57

68
Required Properties:
79

@@ -10,10 +12,18 @@ Required Properties:
1012
- #clock-cells: Must be 1
1113
- clock-output-names: The names of the clocks. Supported clocks are
1214
"plla", "pllb", "b", "out", "p", "s", and "s1".
15+
- #power-domain-cells: Must be 0
1316

17+
SoC devices that are part of the CPG/MSTP Clock Domain and can be power-managed
18+
through an MSTP clock should refer to the CPG device node in their
19+
"power-domains" property, as documented by the generic PM domain bindings in
20+
Documentation/devicetree/bindings/power/power_domain.txt.
1421

15-
Example
16-
-------
22+
23+
Examples
24+
--------
25+
26+
- CPG device node:
1727

1828
cpg_clocks: cpg_clocks@ffc80000 {
1929
compatible = "renesas,r8a7778-cpg-clocks";
@@ -22,4 +32,17 @@ Example
2232
clocks = <&extal_clk>;
2333
clock-output-names = "plla", "pllb", "b",
2434
"out", "p", "s", "s1";
35+
#power-domain-cells = <0>;
36+
};
37+
38+
39+
- CPG/MSTP Clock Domain member device node:
40+
41+
sdhi0: sd@ffe4c000 {
42+
compatible = "renesas,sdhi-r8a7778";
43+
reg = <0xffe4c000 0x100>;
44+
interrupts = <0 87 IRQ_TYPE_LEVEL_HIGH>;
45+
clocks = <&mstp3_clks R8A7778_CLK_SDHI0>;
46+
power-domains = <&cpg_clocks>;
47+
status = "disabled";
2548
};
Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
* Renesas R8A7779 Clock Pulse Generator (CPG)
22

33
The CPG generates core clocks for the R8A7779. It includes one PLL and
4-
several fixed ratio dividers
4+
several fixed ratio dividers.
5+
The CPG also provides a Clock Domain for SoC devices, in combination with the
6+
CPG Module Stop (MSTP) Clocks.
57

68
Required Properties:
79

@@ -12,16 +14,36 @@ Required Properties:
1214
- #clock-cells: Must be 1
1315
- clock-output-names: The names of the clocks. Supported clocks are "plla",
1416
"z", "zs", "s", "s1", "p", "b", "out".
17+
- #power-domain-cells: Must be 0
1518

19+
SoC devices that are part of the CPG/MSTP Clock Domain and can be power-managed
20+
through an MSTP clock should refer to the CPG device node in their
21+
"power-domains" property, as documented by the generic PM domain bindings in
22+
Documentation/devicetree/bindings/power/power_domain.txt.
1623

17-
Example
18-
-------
24+
25+
Examples
26+
--------
27+
28+
- CPG device node:
1929

2030
cpg_clocks: cpg_clocks@ffc80000 {
2131
compatible = "renesas,r8a7779-cpg-clocks";
22-
reg = <0 0xffc80000 0 0x30>;
32+
reg = <0xffc80000 0x30>;
2333
clocks = <&extal_clk>;
2434
#clock-cells = <1>;
2535
clock-output-names = "plla", "z", "zs", "s", "s1", "p",
2636
"b", "out";
37+
#power-domain-cells = <0>;
38+
};
39+
40+
41+
- CPG/MSTP Clock Domain member device node:
42+
43+
sata: sata@fc600000 {
44+
compatible = "renesas,sata-r8a7779", "renesas,rcar-sata";
45+
reg = <0xfc600000 0x2000>;
46+
interrupts = <0 100 IRQ_TYPE_LEVEL_HIGH>;
47+
clocks = <&mstp1_clks R8A7779_CLK_SATA>;
48+
power-domains = <&cpg_clocks>;
2749
};

Documentation/devicetree/bindings/clock/renesas,rcar-gen2-cpg-clocks.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The CPG generates core clocks for the R-Car Gen2 SoCs. It includes three PLLs
44
and several fixed ratio dividers.
5+
The CPG also provides a Clock Domain for SoC devices, in combination with the
6+
CPG Module Stop (MSTP) Clocks.
57

68
Required Properties:
79

@@ -20,10 +22,18 @@ Required Properties:
2022
- clock-output-names: The names of the clocks. Supported clocks are "main",
2123
"pll0", "pll1", "pll3", "lb", "qspi", "sdh", "sd0", "sd1", "z", "rcan", and
2224
"adsp"
25+
- #power-domain-cells: Must be 0
2326

27+
SoC devices that are part of the CPG/MSTP Clock Domain and can be power-managed
28+
through an MSTP clock should refer to the CPG device node in their
29+
"power-domains" property, as documented by the generic PM domain bindings in
30+
Documentation/devicetree/bindings/power/power_domain.txt.
2431

25-
Example
26-
-------
32+
33+
Examples
34+
--------
35+
36+
- CPG device node:
2737

2838
cpg_clocks: cpg_clocks@e6150000 {
2939
compatible = "renesas,r8a7790-cpg-clocks",
@@ -34,4 +44,16 @@ Example
3444
clock-output-names = "main", "pll0, "pll1", "pll3",
3545
"lb", "qspi", "sdh", "sd0", "sd1", "z",
3646
"rcan", "adsp";
47+
#power-domain-cells = <0>;
48+
};
49+
50+
51+
- CPG/MSTP Clock Domain member device node:
52+
53+
thermal@e61f0000 {
54+
compatible = "renesas,thermal-r8a7790", "renesas,rcar-thermal";
55+
reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>;
56+
interrupts = <0 69 IRQ_TYPE_LEVEL_HIGH>;
57+
clocks = <&mstp5_clks R8A7790_CLK_THERMAL>;
58+
power-domains = <&cpg_clocks>;
3759
};

Documentation/devicetree/bindings/clock/renesas,rz-cpg-clocks.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The CPG generates core clocks for the RZ SoCs. It includes the PLL, variable
44
CPU and GPU clocks, and several fixed ratio dividers.
5+
The CPG also provides a Clock Domain for SoC devices, in combination with the
6+
CPG Module Stop (MSTP) Clocks.
57

68
Required Properties:
79

@@ -14,10 +16,18 @@ Required Properties:
1416
- #clock-cells: Must be 1
1517
- clock-output-names: The names of the clocks. Supported clocks are "pll",
1618
"i", and "g"
19+
- #power-domain-cells: Must be 0
1720

21+
SoC devices that are part of the CPG/MSTP Clock Domain and can be power-managed
22+
through an MSTP clock should refer to the CPG device node in their
23+
"power-domains" property, as documented by the generic PM domain bindings in
24+
Documentation/devicetree/bindings/power/power_domain.txt.
1825

19-
Example
20-
-------
26+
27+
Examples
28+
--------
29+
30+
- CPG device node:
2131

2232
cpg_clocks: cpg_clocks@fcfe0000 {
2333
#clock-cells = <1>;
@@ -26,4 +36,19 @@ Example
2636
reg = <0xfcfe0000 0x18>;
2737
clocks = <&extal_clk>, <&usb_x1_clk>;
2838
clock-output-names = "pll", "i", "g";
39+
#power-domain-cells = <0>;
40+
};
41+
42+
43+
- CPG/MSTP Clock Domain member device node:
44+
45+
mtu2: timer@fcff0000 {
46+
compatible = "renesas,mtu2-r7s72100", "renesas,mtu2";
47+
reg = <0xfcff0000 0x400>;
48+
interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>;
49+
interrupt-names = "tgi0a";
50+
clocks = <&mstp3_clks R7S72100_CLK_MTU2>;
51+
clock-names = "fck";
52+
power-domains = <&cpg_clocks>;
53+
status = "disabled";
2954
};

arch/arm/mach-shmobile/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config ARCH_SHMOBILE
44

55
config PM_RCAR
66
bool
7+
select PM_GENERIC_DOMAINS if PM
78

89
config PM_RMOBILE
910
bool
@@ -50,6 +51,7 @@ config ARCH_EMEV2
5051

5152
config ARCH_R7S72100
5253
bool "RZ/A1H (R7S72100)"
54+
select PM_GENERIC_DOMAINS if PM
5355
select SYS_SUPPORTS_SH_MTU2
5456

5557
config ARCH_R8A73A4

drivers/clk/shmobile/clk-mstp.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* R-Car MSTP clocks
33
*
44
* Copyright (C) 2013 Ideas On Board SPRL
5+
* Copyright (C) 2015 Glider bvba
56
*
67
* Contact: Laurent Pinchart <[email protected]>
78
*
@@ -10,11 +11,16 @@
1011
* the Free Software Foundation; version 2 of the License.
1112
*/
1213

14+
#include <linux/clk.h>
1315
#include <linux/clk-provider.h>
1416
#include <linux/clkdev.h>
17+
#include <linux/clk/shmobile.h>
18+
#include <linux/device.h>
1519
#include <linux/io.h>
1620
#include <linux/of.h>
1721
#include <linux/of_address.h>
22+
#include <linux/pm_clock.h>
23+
#include <linux/pm_domain.h>
1824
#include <linux/spinlock.h>
1925

2026
/*
@@ -236,3 +242,84 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)
236242
of_clk_add_provider(np, of_clk_src_onecell_get, &group->data);
237243
}
238244
CLK_OF_DECLARE(cpg_mstp_clks, "renesas,cpg-mstp-clocks", cpg_mstp_clocks_init);
245+
246+
247+
#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
248+
int cpg_mstp_attach_dev(struct generic_pm_domain *domain, struct device *dev)
249+
{
250+
struct device_node *np = dev->of_node;
251+
struct of_phandle_args clkspec;
252+
struct clk *clk;
253+
int i = 0;
254+
int error;
255+
256+
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
257+
&clkspec)) {
258+
if (of_device_is_compatible(clkspec.np,
259+
"renesas,cpg-mstp-clocks"))
260+
goto found;
261+
262+
of_node_put(clkspec.np);
263+
i++;
264+
}
265+
266+
return 0;
267+
268+
found:
269+
clk = of_clk_get_from_provider(&clkspec);
270+
of_node_put(clkspec.np);
271+
272+
if (IS_ERR(clk))
273+
return PTR_ERR(clk);
274+
275+
error = pm_clk_create(dev);
276+
if (error) {
277+
dev_err(dev, "pm_clk_create failed %d\n", error);
278+
goto fail_put;
279+
}
280+
281+
error = pm_clk_add_clk(dev, clk);
282+
if (error) {
283+
dev_err(dev, "pm_clk_add_clk %pC failed %d\n", clk, error);
284+
goto fail_destroy;
285+
}
286+
287+
return 0;
288+
289+
fail_destroy:
290+
pm_clk_destroy(dev);
291+
fail_put:
292+
clk_put(clk);
293+
return error;
294+
}
295+
296+
void cpg_mstp_detach_dev(struct generic_pm_domain *domain, struct device *dev)
297+
{
298+
if (!list_empty(&dev->power.subsys_data->clock_list))
299+
pm_clk_destroy(dev);
300+
}
301+
302+
void __init cpg_mstp_add_clk_domain(struct device_node *np)
303+
{
304+
struct generic_pm_domain *pd;
305+
u32 ncells;
306+
307+
if (of_property_read_u32(np, "#power-domain-cells", &ncells)) {
308+
pr_warn("%s lacks #power-domain-cells\n", np->full_name);
309+
return;
310+
}
311+
312+
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
313+
if (!pd)
314+
return;
315+
316+
pd->name = np->name;
317+
318+
pd->flags = GENPD_FLAG_PM_CLK;
319+
pm_genpd_init(pd, &simple_qos_governor, false);
320+
pd->attach_dev = cpg_mstp_attach_dev;
321+
pd->detach_dev = cpg_mstp_detach_dev;
322+
323+
of_genpd_add_provider_simple(np, pd);
324+
}
325+
#endif /* !CONFIG_PM_GENERIC_DOMAINS_OF */

drivers/clk/shmobile/clk-r8a7778.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static void __init r8a7778_cpg_clocks_init(struct device_node *np)
124124
}
125125

126126
of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data);
127+
128+
cpg_mstp_add_clk_domain(np);
127129
}
128130

129131
CLK_OF_DECLARE(r8a7778_cpg_clks, "renesas,r8a7778-cpg-clocks",

drivers/clk/shmobile/clk-r8a7779.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ static void __init r8a7779_cpg_clocks_init(struct device_node *np)
168168
}
169169

170170
of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data);
171+
172+
cpg_mstp_add_clk_domain(np);
171173
}
172174
CLK_OF_DECLARE(r8a7779_cpg_clks, "renesas,r8a7779-cpg-clocks",
173175
r8a7779_cpg_clocks_init);

drivers/clk/shmobile/clk-rcar-gen2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ static void __init rcar_gen2_cpg_clocks_init(struct device_node *np)
415415
}
416416

417417
of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data);
418+
419+
cpg_mstp_add_clk_domain(np);
418420
}
419421
CLK_OF_DECLARE(rcar_gen2_cpg_clks, "renesas,rcar-gen2-cpg-clocks",
420422
rcar_gen2_cpg_clocks_init);

drivers/clk/shmobile/clk-rz.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/clk-provider.h>
13+
#include <linux/clk/shmobile.h>
1314
#include <linux/init.h>
1415
#include <linux/kernel.h>
1516
#include <linux/of.h>
@@ -99,5 +100,7 @@ static void __init rz_cpg_clocks_init(struct device_node *np)
99100
}
100101

101102
of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data);
103+
104+
cpg_mstp_add_clk_domain(np);
102105
}
103106
CLK_OF_DECLARE(rz_cpg_clks, "renesas,rz-cpg-clocks", rz_cpg_clocks_init);

include/linux/clk/shmobile.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@
1616

1717
#include <linux/types.h>
1818

19+
struct device;
20+
struct device_node;
21+
struct generic_pm_domain;
22+
1923
void r8a7778_clocks_init(u32 mode);
2024
void r8a7779_clocks_init(u32 mode);
2125
void rcar_gen2_clocks_init(u32 mode);
2226

27+
#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
28+
void cpg_mstp_add_clk_domain(struct device_node *np);
29+
int cpg_mstp_attach_dev(struct generic_pm_domain *domain, struct device *dev);
30+
void cpg_mstp_detach_dev(struct generic_pm_domain *domain, struct device *dev);
31+
#else
32+
static inline void cpg_mstp_add_clk_domain(struct device_node *np) {}
33+
#endif
34+
2335
#endif

0 commit comments

Comments
 (0)