1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
25static DEFINE_SPINLOCK(gmac_lock);
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#define SUN7I_A20_GMAC_GPIT 2
53#define SUN7I_A20_GMAC_MASK 0x3
54#define SUN7I_A20_GMAC_PARENTS 2
55
56static u32 sun7i_a20_gmac_mux_table[SUN7I_A20_GMAC_PARENTS] = {
57 0x00,
58 0x02,
59};
60
61static void __init sun7i_a20_gmac_clk_setup(struct device_node *node)
62{
63 struct clk *clk;
64 struct clk_mux *mux;
65 struct clk_gate *gate;
66 const char *clk_name = node->name;
67 const char *parents[SUN7I_A20_GMAC_PARENTS];
68 void __iomem *reg;
69
70 if (of_property_read_string(node, "clock-output-names", &clk_name))
71 return;
72
73
74 mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
75 if (!mux)
76 return;
77
78 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
79 if (!gate)
80 goto free_mux;
81
82
83 parents[0] = of_clk_get_parent_name(node, 0);
84 parents[1] = of_clk_get_parent_name(node, 1);
85 if (!parents[0] || !parents[1])
86 goto free_gate;
87
88 reg = of_iomap(node, 0);
89 if (!reg)
90 goto free_gate;
91
92
93 gate->reg = reg;
94 gate->bit_idx = SUN7I_A20_GMAC_GPIT;
95 gate->lock = &gmac_lock;
96 mux->reg = reg;
97 mux->mask = SUN7I_A20_GMAC_MASK;
98 mux->table = sun7i_a20_gmac_mux_table;
99 mux->lock = &gmac_lock;
100
101 clk = clk_register_composite(NULL, clk_name,
102 parents, SUN7I_A20_GMAC_PARENTS,
103 &mux->hw, &clk_mux_ops,
104 NULL, NULL,
105 &gate->hw, &clk_gate_ops,
106 0);
107
108 if (IS_ERR(clk))
109 goto iounmap_reg;
110
111 of_clk_add_provider(node, of_clk_src_simple_get, clk);
112 clk_register_clkdev(clk, clk_name, NULL);
113
114 return;
115
116iounmap_reg:
117 iounmap(reg);
118free_gate:
119 kfree(gate);
120free_mux:
121 kfree(mux);
122}
123CLK_OF_DECLARE(sun7i_a20_gmac, "allwinner,sun7i-a20-gmac-clk",
124 sun7i_a20_gmac_clk_setup);
125