Skip to content

Commit b640a60

Browse files
author
Mike Turquette
committed
Merge tag 'sunxi-clk-for-3.16-2' of https://github.com/mripard/linux into clk-next
Rebase of Emilio's clk-sunxi-for-3.16 on top of clk-next Fixed a few compilation warnings exposed by a patch introduced during the 3.16 merge window. Original tag message: Allwinner sunXi SoCs clock changes This pull contains some new code to add support for A31 clocks by Maxime and Boris. It also reworks the driver a bit to avoid having a huge single file when we have a full folder for ourselves, and separating different functional units makes sense.
2 parents 3f6eec9 + 5c89a8b commit b640a60

File tree

8 files changed

+661
-187
lines changed

8 files changed

+661
-187
lines changed

Documentation/devicetree/bindings/clock/sunxi.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ Required properties:
2020
"allwinner,sun5i-a13-ahb-gates-clk" - for the AHB gates on A13
2121
"allwinner,sun5i-a10s-ahb-gates-clk" - for the AHB gates on A10s
2222
"allwinner,sun7i-a20-ahb-gates-clk" - for the AHB gates on A20
23+
"allwinner,sun6i-a31-ar100-clk" - for the AR100 on A31
2324
"allwinner,sun6i-a31-ahb1-mux-clk" - for the AHB1 multiplexer on A31
2425
"allwinner,sun6i-a31-ahb1-gates-clk" - for the AHB1 gates on A31
2526
"allwinner,sun4i-a10-apb0-clk" - for the APB0 clock
27+
"allwinner,sun6i-a31-apb0-clk" - for the APB0 clock on A31
2628
"allwinner,sun4i-a10-apb0-gates-clk" - for the APB0 gates on A10
2729
"allwinner,sun5i-a13-apb0-gates-clk" - for the APB0 gates on A13
2830
"allwinner,sun5i-a10s-apb0-gates-clk" - for the APB0 gates on A10s
31+
"allwinner,sun6i-a31-apb0-gates-clk" - for the APB0 gates on A31
2932
"allwinner,sun7i-a20-apb0-gates-clk" - for the APB0 gates on A20
3033
"allwinner,sun4i-a10-apb1-clk" - for the APB1 clock
3134
"allwinner,sun4i-a10-apb1-mux-clk" - for the APB1 clock muxing
@@ -41,6 +44,7 @@ Required properties:
4144
"allwinner,sun7i-a20-gmac-clk" - for the GMAC clock module on A20/A31
4245
"allwinner,sun4i-a10-usb-clk" - for usb gates + resets on A10 / A20
4346
"allwinner,sun5i-a13-usb-clk" - for usb gates + resets on A13
47+
"allwinner,sun6i-a31-usb-clk" - for usb gates + resets on A31
4448

4549
Required properties for all clocks:
4650
- reg : shall be the control register address for the clock.

drivers/clk/sunxi/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
#
44

55
obj-y += clk-sunxi.o clk-factors.o
6+
obj-y += clk-a10-hosc.o
7+
obj-y += clk-a20-gmac.o
8+
9+
obj-$(CONFIG_MFD_SUN6I_PRCM) += clk-sun6i-ar100.o clk-sun6i-apb0.o clk-sun6i-apb0-gates.o

drivers/clk/sunxi/clk-a10-hosc.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2013 Emilio López
3+
*
4+
* Emilio López <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*/
16+
17+
#include <linux/clk-provider.h>
18+
#include <linux/clkdev.h>
19+
#include <linux/of.h>
20+
#include <linux/of_address.h>
21+
22+
#define SUNXI_OSC24M_GATE 0
23+
24+
static DEFINE_SPINLOCK(hosc_lock);
25+
26+
static void __init sun4i_osc_clk_setup(struct device_node *node)
27+
{
28+
struct clk *clk;
29+
struct clk_fixed_rate *fixed;
30+
struct clk_gate *gate;
31+
const char *clk_name = node->name;
32+
u32 rate;
33+
34+
if (of_property_read_u32(node, "clock-frequency", &rate))
35+
return;
36+
37+
/* allocate fixed-rate and gate clock structs */
38+
fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
39+
if (!fixed)
40+
return;
41+
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
42+
if (!gate)
43+
goto err_free_fixed;
44+
45+
of_property_read_string(node, "clock-output-names", &clk_name);
46+
47+
/* set up gate and fixed rate properties */
48+
gate->reg = of_iomap(node, 0);
49+
gate->bit_idx = SUNXI_OSC24M_GATE;
50+
gate->lock = &hosc_lock;
51+
fixed->fixed_rate = rate;
52+
53+
clk = clk_register_composite(NULL, clk_name,
54+
NULL, 0,
55+
NULL, NULL,
56+
&fixed->hw, &clk_fixed_rate_ops,
57+
&gate->hw, &clk_gate_ops,
58+
CLK_IS_ROOT);
59+
60+
if (IS_ERR(clk))
61+
goto err_free_gate;
62+
63+
of_clk_add_provider(node, of_clk_src_simple_get, clk);
64+
clk_register_clkdev(clk, clk_name, NULL);
65+
66+
return;
67+
68+
err_free_gate:
69+
kfree(gate);
70+
err_free_fixed:
71+
kfree(fixed);
72+
}
73+
CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup);

drivers/clk/sunxi/clk-a20-gmac.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2013 Emilio López
3+
* Emilio López <[email protected]>
4+
*
5+
* Copyright 2013 Chen-Yu Tsai
6+
* Chen-Yu Tsai <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*/
18+
19+
#include <linux/clk-provider.h>
20+
#include <linux/clkdev.h>
21+
#include <linux/of.h>
22+
#include <linux/of_address.h>
23+
#include <linux/slab.h>
24+
25+
static DEFINE_SPINLOCK(gmac_lock);
26+
27+
/**
28+
* sun7i_a20_gmac_clk_setup - Setup function for A20/A31 GMAC clock module
29+
*
30+
* This clock looks something like this
31+
* ________________________
32+
* MII TX clock from PHY >-----|___________ _________|----> to GMAC core
33+
* GMAC Int. RGMII TX clk >----|___________\__/__gate---|----> to PHY
34+
* Ext. 125MHz RGMII TX clk >--|__divider__/ |
35+
* |________________________|
36+
*
37+
* The external 125 MHz reference is optional, i.e. GMAC can use its
38+
* internal TX clock just fine. The A31 GMAC clock module does not have
39+
* the divider controls for the external reference.
40+
*
41+
* To keep it simple, let the GMAC use either the MII TX clock for MII mode,
42+
* and its internal TX clock for GMII and RGMII modes. The GMAC driver should
43+
* select the appropriate source and gate/ungate the output to the PHY.
44+
*
45+
* Only the GMAC should use this clock. Altering the clock so that it doesn't
46+
* match the GMAC's operation parameters will result in the GMAC not being
47+
* able to send traffic out. The GMAC driver should set the clock rate and
48+
* enable/disable this clock to configure the required state. The clock
49+
* driver then responds by auto-reparenting the clock.
50+
*/
51+
52+
#define SUN7I_A20_GMAC_GPIT 2
53+
#define SUN7I_A20_GMAC_MASK 0x3
54+
#define SUN7I_A20_GMAC_PARENTS 2
55+
56+
static void __init sun7i_a20_gmac_clk_setup(struct device_node *node)
57+
{
58+
struct clk *clk;
59+
struct clk_mux *mux;
60+
struct clk_gate *gate;
61+
const char *clk_name = node->name;
62+
const char *parents[SUN7I_A20_GMAC_PARENTS];
63+
void *reg;
64+
65+
if (of_property_read_string(node, "clock-output-names", &clk_name))
66+
return;
67+
68+
/* allocate mux and gate clock structs */
69+
mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
70+
if (!mux)
71+
return;
72+
73+
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
74+
if (!gate)
75+
goto free_mux;
76+
77+
/* gmac clock requires exactly 2 parents */
78+
parents[0] = of_clk_get_parent_name(node, 0);
79+
parents[1] = of_clk_get_parent_name(node, 1);
80+
if (!parents[0] || !parents[1])
81+
goto free_gate;
82+
83+
reg = of_iomap(node, 0);
84+
if (!reg)
85+
goto free_gate;
86+
87+
/* set up gate and fixed rate properties */
88+
gate->reg = reg;
89+
gate->bit_idx = SUN7I_A20_GMAC_GPIT;
90+
gate->lock = &gmac_lock;
91+
mux->reg = reg;
92+
mux->mask = SUN7I_A20_GMAC_MASK;
93+
mux->flags = CLK_MUX_INDEX_BIT;
94+
mux->lock = &gmac_lock;
95+
96+
clk = clk_register_composite(NULL, clk_name,
97+
parents, SUN7I_A20_GMAC_PARENTS,
98+
&mux->hw, &clk_mux_ops,
99+
NULL, NULL,
100+
&gate->hw, &clk_gate_ops,
101+
0);
102+
103+
if (IS_ERR(clk))
104+
goto iounmap_reg;
105+
106+
of_clk_add_provider(node, of_clk_src_simple_get, clk);
107+
clk_register_clkdev(clk, clk_name, NULL);
108+
109+
return;
110+
111+
iounmap_reg:
112+
iounmap(reg);
113+
free_gate:
114+
kfree(gate);
115+
free_mux:
116+
kfree(mux);
117+
}
118+
CLK_OF_DECLARE(sun7i_a20_gmac, "allwinner,sun7i-a20-gmac-clk",
119+
sun7i_a20_gmac_clk_setup);
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (C) 2014 Free Electrons
3+
*
4+
* License Terms: GNU General Public License v2
5+
* Author: Boris BREZILLON <[email protected]>
6+
*
7+
* Allwinner A31 APB0 clock gates driver
8+
*
9+
*/
10+
11+
#include <linux/clk-provider.h>
12+
#include <linux/module.h>
13+
#include <linux/of.h>
14+
#include <linux/platform_device.h>
15+
16+
#define SUN6I_APB0_GATES_MAX_SIZE 32
17+
18+
static int sun6i_a31_apb0_gates_clk_probe(struct platform_device *pdev)
19+
{
20+
struct device_node *np = pdev->dev.of_node;
21+
struct clk_onecell_data *clk_data;
22+
const char *clk_parent;
23+
const char *clk_name;
24+
struct resource *r;
25+
void __iomem *reg;
26+
int gate_id;
27+
int ngates;
28+
int i;
29+
30+
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
31+
reg = devm_ioremap_resource(&pdev->dev, r);
32+
if (!reg)
33+
return PTR_ERR(reg);
34+
35+
clk_parent = of_clk_get_parent_name(np, 0);
36+
if (!clk_parent)
37+
return -EINVAL;
38+
39+
ngates = of_property_count_strings(np, "clock-output-names");
40+
if (ngates < 0)
41+
return ngates;
42+
43+
if (!ngates || ngates > SUN6I_APB0_GATES_MAX_SIZE)
44+
return -EINVAL;
45+
46+
clk_data = devm_kzalloc(&pdev->dev, sizeof(struct clk_onecell_data),
47+
GFP_KERNEL);
48+
if (!clk_data)
49+
return -ENOMEM;
50+
51+
clk_data->clks = devm_kzalloc(&pdev->dev,
52+
SUN6I_APB0_GATES_MAX_SIZE *
53+
sizeof(struct clk *),
54+
GFP_KERNEL);
55+
if (!clk_data->clks)
56+
return -ENOMEM;
57+
58+
for (i = 0; i < ngates; i++) {
59+
of_property_read_string_index(np, "clock-output-names",
60+
i, &clk_name);
61+
62+
gate_id = i;
63+
of_property_read_u32_index(np, "clock-indices", i, &gate_id);
64+
65+
WARN_ON(gate_id >= SUN6I_APB0_GATES_MAX_SIZE);
66+
if (gate_id >= SUN6I_APB0_GATES_MAX_SIZE)
67+
continue;
68+
69+
clk_data->clks[gate_id] = clk_register_gate(&pdev->dev,
70+
clk_name,
71+
clk_parent, 0,
72+
reg, gate_id,
73+
0, NULL);
74+
WARN_ON(IS_ERR(clk_data->clks[gate_id]));
75+
}
76+
77+
clk_data->clk_num = ngates;
78+
79+
return of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
80+
}
81+
82+
const struct of_device_id sun6i_a31_apb0_gates_clk_dt_ids[] = {
83+
{ .compatible = "allwinner,sun6i-a31-apb0-gates-clk" },
84+
{ /* sentinel */ }
85+
};
86+
87+
static struct platform_driver sun6i_a31_apb0_gates_clk_driver = {
88+
.driver = {
89+
.name = "sun6i-a31-apb0-gates-clk",
90+
.owner = THIS_MODULE,
91+
.of_match_table = sun6i_a31_apb0_gates_clk_dt_ids,
92+
},
93+
.probe = sun6i_a31_apb0_gates_clk_probe,
94+
};
95+
module_platform_driver(sun6i_a31_apb0_gates_clk_driver);
96+
97+
MODULE_AUTHOR("Boris BREZILLON <[email protected]>");
98+
MODULE_DESCRIPTION("Allwinner A31 APB0 gate clocks driver");
99+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)