forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/clk/socfpga/clk-periph-s10.c
....@@ -4,6 +4,7 @@
44 */
55 #include <linux/slab.h>
66 #include <linux/clk-provider.h>
7
+#include <linux/io.h>
78
89 #include "stratix10-clk.h"
910 #include "clk.h"
....@@ -48,16 +49,21 @@
4849 {
4950 struct socfpga_periph_clk *socfpgaclk = to_periph_clk(hwclk);
5051 u32 clk_src, mask;
51
- u8 parent;
52
+ u8 parent = 0;
5253
54
+ /* handle the bypass first */
5355 if (socfpgaclk->bypass_reg) {
5456 mask = (0x1 << socfpgaclk->bypass_shift);
5557 parent = ((readl(socfpgaclk->bypass_reg) & mask) >>
5658 socfpgaclk->bypass_shift);
57
- } else {
59
+ if (parent)
60
+ return parent;
61
+ }
62
+
63
+ if (socfpgaclk->hw.reg) {
5864 clk_src = readl(socfpgaclk->hw.reg);
5965 parent = (clk_src >> CLK_MGR_FREE_SHIFT) &
60
- CLK_MGR_FREE_MASK;
66
+ CLK_MGR_FREE_MASK;
6167 }
6268 return parent;
6369 }
....@@ -72,27 +78,29 @@
7278 .get_parent = clk_periclk_get_parent,
7379 };
7480
75
-struct clk *s10_register_periph(const char *name, const char *parent_name,
76
- const char * const *parent_names,
77
- u8 num_parents, unsigned long flags,
78
- void __iomem *reg, unsigned long offset)
81
+struct clk *s10_register_periph(const struct stratix10_perip_c_clock *clks,
82
+ void __iomem *reg)
7983 {
8084 struct clk *clk;
8185 struct socfpga_periph_clk *periph_clk;
82
- struct clk_init_data init = {};
86
+ struct clk_init_data init;
87
+ const char *name = clks->name;
88
+ const char *parent_name = clks->parent_name;
8389
8490 periph_clk = kzalloc(sizeof(*periph_clk), GFP_KERNEL);
8591 if (WARN_ON(!periph_clk))
8692 return NULL;
8793
88
- periph_clk->hw.reg = reg + offset;
94
+ periph_clk->hw.reg = reg + clks->offset;
8995
9096 init.name = name;
9197 init.ops = &peri_c_clk_ops;
92
- init.flags = flags;
98
+ init.flags = clks->flags;
9399
94
- init.num_parents = num_parents;
95
- init.parent_names = parent_names ? parent_names : &parent_name;
100
+ init.num_parents = clks->num_parents;
101
+ init.parent_names = parent_name ? &parent_name : NULL;
102
+ if (init.parent_names == NULL)
103
+ init.parent_data = clks->parent_data;
96104
97105 periph_clk->hw.hw.init = &init;
98106
....@@ -104,39 +112,39 @@
104112 return clk;
105113 }
106114
107
-struct clk *s10_register_cnt_periph(const char *name, const char *parent_name,
108
- const char * const *parent_names,
109
- u8 num_parents, unsigned long flags,
110
- void __iomem *regbase, unsigned long offset,
111
- u8 fixed_divider, unsigned long bypass_reg,
112
- unsigned long bypass_shift)
115
+struct clk *s10_register_cnt_periph(const struct stratix10_perip_cnt_clock *clks,
116
+ void __iomem *regbase)
113117 {
114118 struct clk *clk;
115119 struct socfpga_periph_clk *periph_clk;
116
- struct clk_init_data init = {};
120
+ struct clk_init_data init;
121
+ const char *name = clks->name;
122
+ const char *parent_name = clks->parent_name;
117123
118124 periph_clk = kzalloc(sizeof(*periph_clk), GFP_KERNEL);
119125 if (WARN_ON(!periph_clk))
120126 return NULL;
121127
122
- if (offset)
123
- periph_clk->hw.reg = regbase + offset;
128
+ if (clks->offset)
129
+ periph_clk->hw.reg = regbase + clks->offset;
124130 else
125131 periph_clk->hw.reg = NULL;
126132
127
- if (bypass_reg)
128
- periph_clk->bypass_reg = regbase + bypass_reg;
133
+ if (clks->bypass_reg)
134
+ periph_clk->bypass_reg = regbase + clks->bypass_reg;
129135 else
130136 periph_clk->bypass_reg = NULL;
131
- periph_clk->bypass_shift = bypass_shift;
132
- periph_clk->fixed_div = fixed_divider;
137
+ periph_clk->bypass_shift = clks->bypass_shift;
138
+ periph_clk->fixed_div = clks->fixed_divider;
133139
134140 init.name = name;
135141 init.ops = &peri_cnt_clk_ops;
136
- init.flags = flags;
142
+ init.flags = clks->flags;
137143
138
- init.num_parents = num_parents;
139
- init.parent_names = parent_names ? parent_names : &parent_name;
144
+ init.num_parents = clks->num_parents;
145
+ init.parent_names = parent_name ? &parent_name : NULL;
146
+ if (init.parent_names == NULL)
147
+ init.parent_data = clks->parent_data;
140148
141149 periph_clk->hw.hw.init = &init;
142150