@@ -46,7 +46,17 @@ struct clk_double_div {
4646 u8 shift2 ;
4747};
4848
49+ struct clk_pm_cpu {
50+ struct clk_hw hw ;
51+ void __iomem * reg_mux ;
52+ u8 shift_mux ;
53+ u32 mask_mux ;
54+ void __iomem * reg_div ;
55+ u8 shift_div ;
56+ };
57+
4958#define to_clk_double_div (_hw ) container_of(_hw, struct clk_double_div, hw)
59+ #define to_clk_pm_cpu (_hw ) container_of(_hw, struct clk_pm_cpu, hw)
5060
5161struct clk_periph_data {
5262 const char * name ;
@@ -55,6 +65,7 @@ struct clk_periph_data {
5565 struct clk_hw * mux_hw ;
5666 struct clk_hw * rate_hw ;
5767 struct clk_hw * gate_hw ;
68+ struct clk_hw * muxrate_hw ;
5869 bool is_double_div ;
5970};
6071
@@ -81,6 +92,7 @@ static const struct clk_div_table clk_table2[] = {
8192};
8293
8394static const struct clk_ops clk_double_div_ops ;
95+ static const struct clk_ops clk_pm_cpu_ops ;
8496
8597#define PERIPH_GATE (_name , _bit ) \
8698struct clk_gate gate_##_name = { \
@@ -122,6 +134,18 @@ struct clk_divider rate_##_name = { \
122134 } \
123135};
124136
137+ #define PERIPH_PM_CPU (_name , _shift1 , _reg , _shift2 ) \
138+ struct clk_pm_cpu muxrate_##_name = { \
139+ .reg_mux = (void *)TBG_SEL, \
140+ .mask_mux = 3, \
141+ .shift_mux = _shift1, \
142+ .reg_div = (void *)_reg, \
143+ .shift_div = _shift2, \
144+ .hw.init = &(struct clk_init_data){ \
145+ .ops = &clk_pm_cpu_ops, \
146+ } \
147+ };
148+
125149#define PERIPH_CLK_FULL_DD (_name , _bit , _shift , _reg1 , _reg2 , _shift1 , _shift2 )\
126150static PERIPH_GATE(_name, _bit); \
127151static PERIPH_MUX(_name, _shift); \
@@ -136,10 +160,6 @@ static PERIPH_DIV(_name, _reg, _shift1, _table);
136160static PERIPH_GATE(_name, _bit); \
137161static PERIPH_DIV(_name, _reg, _shift, _table);
138162
139- #define PERIPH_CLK_MUX_DIV (_name , _shift , _reg , _shift_div , _table ) \
140- static PERIPH_MUX(_name, _shift); \
141- static PERIPH_DIV(_name, _reg, _shift_div, _table);
142-
143163#define PERIPH_CLK_MUX_DD (_name , _shift , _reg1 , _reg2 , _shift1 , _shift2 )\
144164static PERIPH_MUX(_name, _shift); \
145165static PERIPH_DOUBLEDIV(_name, _reg1, _reg2, _shift1, _shift2);
@@ -180,13 +200,12 @@ static PERIPH_DOUBLEDIV(_name, _reg1, _reg2, _shift1, _shift2);
180200 .rate_hw = &rate_##_name.hw, \
181201 }
182202
183- #define REF_CLK_MUX_DIV (_name ) \
203+ #define REF_CLK_PM_CPU (_name ) \
184204 { .name = #_name, \
185205 .parent_names = (const char *[]){ "TBG-A-P", \
186206 "TBG-B-P", "TBG-A-S", "TBG-B-S"}, \
187207 .num_parents = 4, \
188- .mux_hw = &mux_##_name.hw, \
189- .rate_hw = &rate_##_name.hw, \
208+ .muxrate_hw = &muxrate_##_name.hw, \
190209 }
191210
192211#define REF_CLK_MUX_DD (_name ) \
@@ -216,7 +235,7 @@ PERIPH_CLK_FULL_DD(ddr_fclk, 21, 16, DIV_SEL0, DIV_SEL0, 15, 12);
216235PERIPH_CLK_FULL (trace , 22 , 18 , DIV_SEL0 , 20 , clk_table6 );
217236PERIPH_CLK_FULL (counter , 23 , 20 , DIV_SEL0 , 23 , clk_table6 );
218237PERIPH_CLK_FULL_DD (eip97 , 24 , 24 , DIV_SEL2 , DIV_SEL2 , 22 , 19 );
219- PERIPH_CLK_MUX_DIV (cpu , 22 , DIV_SEL0 , 28 , clk_table6 );
238+ static PERIPH_PM_CPU (cpu , 22 , DIV_SEL0 , 28 ) ;
220239
221240static struct clk_periph_data data_nb [] = {
222241 REF_CLK_FULL_DD (mmc ),
@@ -235,7 +254,7 @@ static struct clk_periph_data data_nb[] = {
235254 REF_CLK_FULL (trace ),
236255 REF_CLK_FULL (counter ),
237256 REF_CLK_FULL_DD (eip97 ),
238- REF_CLK_MUX_DIV (cpu ),
257+ REF_CLK_PM_CPU (cpu ),
239258 { },
240259};
241260
@@ -297,6 +316,37 @@ static const struct clk_ops clk_double_div_ops = {
297316 .recalc_rate = clk_double_div_recalc_rate ,
298317};
299318
319+ static u8 clk_pm_cpu_get_parent (struct clk_hw * hw )
320+ {
321+ struct clk_pm_cpu * pm_cpu = to_clk_pm_cpu (hw );
322+ int num_parents = clk_hw_get_num_parents (hw );
323+ u32 val ;
324+
325+ val = readl (pm_cpu -> reg_mux ) >> pm_cpu -> shift_mux ;
326+ val &= pm_cpu -> mask_mux ;
327+
328+ if (val >= num_parents )
329+ return - EINVAL ;
330+
331+ return val ;
332+ }
333+
334+ static unsigned long clk_pm_cpu_recalc_rate (struct clk_hw * hw ,
335+ unsigned long parent_rate )
336+ {
337+ struct clk_pm_cpu * pm_cpu = to_clk_pm_cpu (hw );
338+ unsigned int div ;
339+
340+ div = get_div (pm_cpu -> reg_div , pm_cpu -> shift_div );
341+
342+ return DIV_ROUND_UP_ULL ((u64 )parent_rate , div );
343+ }
344+
345+ static const struct clk_ops clk_pm_cpu_ops = {
346+ .get_parent = clk_pm_cpu_get_parent ,
347+ .recalc_rate = clk_pm_cpu_recalc_rate ,
348+ };
349+
300350static const struct of_device_id armada_3700_periph_clock_of_match [] = {
301351 { .compatible = "marvell,armada-3700-periph-clock-nb" ,
302352 .data = data_nb , },
@@ -356,6 +406,20 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
356406 }
357407 }
358408
409+ if (data -> muxrate_hw ) {
410+ struct clk_pm_cpu * pmcpu_clk ;
411+ struct clk_hw * muxrate_hw = data -> muxrate_hw ;
412+
413+ pmcpu_clk = to_clk_pm_cpu (muxrate_hw );
414+ pmcpu_clk -> reg_mux = reg + (u64 )pmcpu_clk -> reg_mux ;
415+ pmcpu_clk -> reg_div = reg + (u64 )pmcpu_clk -> reg_div ;
416+
417+ mux_hw = muxrate_hw ;
418+ rate_hw = muxrate_hw ;
419+ mux_ops = muxrate_hw -> init -> ops ;
420+ rate_ops = muxrate_hw -> init -> ops ;
421+ }
422+
359423 * hw = clk_hw_register_composite (dev , data -> name , data -> parent_names ,
360424 data -> num_parents , mux_hw ,
361425 mux_ops , rate_hw , rate_ops ,
0 commit comments