@@ -48,6 +48,20 @@ static struct clk_init_data init = {
48
48
.num_parents = ARRAY_SIZE (lan966x_gck_pdata ),
49
49
};
50
50
51
+ struct clk_gate_soc_desc {
52
+ const char * name ;
53
+ int bit_idx ;
54
+ };
55
+
56
+ static const struct clk_gate_soc_desc clk_gate_desc [] = {
57
+ { "uhphs" , 11 },
58
+ { "udphs" , 10 },
59
+ { "mcramc" , 9 },
60
+ { "hmatrix" , 8 },
61
+ { }
62
+ };
63
+
64
+ static DEFINE_SPINLOCK (clk_gate_lock );
51
65
static void __iomem * base ;
52
66
53
67
static int lan966x_gck_enable (struct clk_hw * hw )
@@ -188,11 +202,37 @@ static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i)
188
202
return & priv -> hw ;
189
203
};
190
204
205
+ static int lan966x_gate_clk_register (struct device * dev ,
206
+ struct clk_hw_onecell_data * hw_data ,
207
+ void __iomem * gate_base )
208
+ {
209
+ int i ;
210
+
211
+ for (i = GCK_GATE_UHPHS ; i < N_CLOCKS ; ++ i ) {
212
+ int idx = i - GCK_GATE_UHPHS ;
213
+
214
+ hw_data -> hws [i ] =
215
+ devm_clk_hw_register_gate (dev , clk_gate_desc [idx ].name ,
216
+ "lan966x" , 0 , base ,
217
+ clk_gate_desc [idx ].bit_idx ,
218
+ 0 , & clk_gate_lock );
219
+
220
+ if (IS_ERR (hw_data -> hws [i ]))
221
+ return dev_err_probe (dev , PTR_ERR (hw_data -> hws [i ]),
222
+ "failed to register %s clock\n" ,
223
+ clk_gate_desc [idx ].name );
224
+ }
225
+
226
+ return 0 ;
227
+ }
228
+
191
229
static int lan966x_clk_probe (struct platform_device * pdev )
192
230
{
193
231
struct clk_hw_onecell_data * hw_data ;
194
232
struct device * dev = & pdev -> dev ;
195
- int i ;
233
+ void __iomem * gate_base ;
234
+ struct resource * res ;
235
+ int i , ret ;
196
236
197
237
hw_data = devm_kzalloc (dev , struct_size (hw_data , hws , N_CLOCKS ),
198
238
GFP_KERNEL );
@@ -205,9 +245,9 @@ static int lan966x_clk_probe(struct platform_device *pdev)
205
245
206
246
init .ops = & lan966x_gck_ops ;
207
247
208
- hw_data -> num = N_CLOCKS ;
248
+ hw_data -> num = GCK_GATE_UHPHS ;
209
249
210
- for (i = 0 ; i < N_CLOCKS ; i ++ ) {
250
+ for (i = 0 ; i < GCK_GATE_UHPHS ; i ++ ) {
211
251
init .name = clk_names [i ];
212
252
hw_data -> hws [i ] = lan966x_gck_clk_register (dev , i );
213
253
if (IS_ERR (hw_data -> hws [i ])) {
@@ -217,6 +257,19 @@ static int lan966x_clk_probe(struct platform_device *pdev)
217
257
}
218
258
}
219
259
260
+ res = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
261
+ if (res ) {
262
+ gate_base = devm_ioremap_resource (& pdev -> dev , res );
263
+ if (IS_ERR (gate_base ))
264
+ return PTR_ERR (gate_base );
265
+
266
+ hw_data -> num = N_CLOCKS ;
267
+
268
+ ret = lan966x_gate_clk_register (dev , hw_data , gate_base );
269
+ if (ret )
270
+ return ret ;
271
+ }
272
+
220
273
return devm_of_clk_add_hw_provider (dev , of_clk_hw_onecell_get , hw_data );
221
274
}
222
275
0 commit comments