8
8
9
9
#include <linux/adi-axi-common.h>
10
10
#include <linux/bits.h>
11
- #include <linux/platform_device.h>
12
11
#include <linux/clk.h>
13
12
#include <linux/clk-provider.h>
14
- #include <linux/slab .h>
13
+ #include <linux/err .h>
15
14
#include <linux/io.h>
16
- #include <linux/of.h>
17
15
#include <linux/module.h>
18
16
#include <linux/mod_devicetable.h>
19
- #include <linux/err.h>
17
+ #include <linux/of.h>
18
+ #include <linux/platform_device.h>
19
+ #include <linux/slab.h>
20
20
21
21
#define AXI_CLKGEN_V2_REG_RESET 0x40
22
22
#define AXI_CLKGEN_V2_REG_CLKSEL 0x44
@@ -96,7 +96,7 @@ static uint32_t axi_clkgen_lookup_filter(unsigned int m)
96
96
}
97
97
}
98
98
99
- static const uint32_t axi_clkgen_lock_table [] = {
99
+ static const u32 axi_clkgen_lock_table [] = {
100
100
0x060603e8 , 0x060603e8 , 0x080803e8 , 0x0b0b03e8 ,
101
101
0x0e0e03e8 , 0x111103e8 , 0x131303e8 , 0x161603e8 ,
102
102
0x191903e8 , 0x1c1c03e8 , 0x1f1f0384 , 0x1f1f0339 ,
@@ -108,7 +108,7 @@ static const uint32_t axi_clkgen_lock_table[] = {
108
108
0x1f1f012c , 0x1f1f0113 , 0x1f1f0113 , 0x1f1f0113 ,
109
109
};
110
110
111
- static uint32_t axi_clkgen_lookup_lock (unsigned int m )
111
+ static u32 axi_clkgen_lookup_lock (unsigned int m )
112
112
{
113
113
if (m < ARRAY_SIZE (axi_clkgen_lock_table ))
114
114
return axi_clkgen_lock_table [m ];
@@ -130,8 +130,9 @@ static const struct axi_clkgen_limits axi_clkgen_zynq_default_limits = {
130
130
};
131
131
132
132
static void axi_clkgen_calc_params (const struct axi_clkgen_limits * limits ,
133
- unsigned long fin , unsigned long fout ,
134
- unsigned int * best_d , unsigned int * best_m , unsigned int * best_dout )
133
+ unsigned long fin , unsigned long fout ,
134
+ unsigned int * best_d , unsigned int * best_m ,
135
+ unsigned int * best_dout )
135
136
{
136
137
unsigned long d , d_min , d_max , _d_min , _d_max ;
137
138
unsigned long m , m_min , m_max ;
@@ -198,9 +199,9 @@ struct axi_clkgen_div_params {
198
199
};
199
200
200
201
static void axi_clkgen_calc_clk_params (unsigned int divider ,
201
- unsigned int frac_divider , struct axi_clkgen_div_params * params )
202
+ unsigned int frac_divider ,
203
+ struct axi_clkgen_div_params * params )
202
204
{
203
-
204
205
memset (params , 0x0 , sizeof (* params ));
205
206
206
207
if (divider == 1 ) {
@@ -228,21 +229,21 @@ static void axi_clkgen_calc_clk_params(unsigned int divider,
228
229
if (params -> edge == 0 || frac_divider == 1 )
229
230
params -> low -- ;
230
231
if (((params -> edge == 0 ) ^ (frac_divider == 1 )) ||
231
- (divider == 2 && frac_divider == 1 ))
232
+ (divider == 2 && frac_divider == 1 ))
232
233
params -> frac_wf_f = 1 ;
233
234
234
235
params -> frac_phase = params -> edge * 4 + frac_divider / 2 ;
235
236
}
236
237
}
237
238
238
239
static void axi_clkgen_write (struct axi_clkgen * axi_clkgen ,
239
- unsigned int reg , unsigned int val )
240
+ unsigned int reg , unsigned int val )
240
241
{
241
242
writel (val , axi_clkgen -> base + reg );
242
243
}
243
244
244
245
static void axi_clkgen_read (struct axi_clkgen * axi_clkgen ,
245
- unsigned int reg , unsigned int * val )
246
+ unsigned int reg , unsigned int * val )
246
247
{
247
248
* val = readl (axi_clkgen -> base + reg );
248
249
}
@@ -263,7 +264,7 @@ static int axi_clkgen_wait_non_busy(struct axi_clkgen *axi_clkgen)
263
264
}
264
265
265
266
static int axi_clkgen_mmcm_read (struct axi_clkgen * axi_clkgen ,
266
- unsigned int reg , unsigned int * val )
267
+ unsigned int reg , unsigned int * val )
267
268
{
268
269
unsigned int reg_val ;
269
270
int ret ;
@@ -287,7 +288,8 @@ static int axi_clkgen_mmcm_read(struct axi_clkgen *axi_clkgen,
287
288
}
288
289
289
290
static int axi_clkgen_mmcm_write (struct axi_clkgen * axi_clkgen ,
290
- unsigned int reg , unsigned int val , unsigned int mask )
291
+ unsigned int reg , unsigned int val ,
292
+ unsigned int mask )
291
293
{
292
294
unsigned int reg_val = 0 ;
293
295
int ret ;
@@ -308,8 +310,7 @@ static int axi_clkgen_mmcm_write(struct axi_clkgen *axi_clkgen,
308
310
return 0 ;
309
311
}
310
312
311
- static void axi_clkgen_mmcm_enable (struct axi_clkgen * axi_clkgen ,
312
- bool enable )
313
+ static void axi_clkgen_mmcm_enable (struct axi_clkgen * axi_clkgen , bool enable )
313
314
{
314
315
unsigned int val = AXI_CLKGEN_V2_RESET_ENABLE ;
315
316
@@ -325,31 +326,31 @@ static struct axi_clkgen *clk_hw_to_axi_clkgen(struct clk_hw *clk_hw)
325
326
}
326
327
327
328
static void axi_clkgen_set_div (struct axi_clkgen * axi_clkgen ,
328
- unsigned int reg1 , unsigned int reg2 , unsigned int reg3 ,
329
- struct axi_clkgen_div_params * params )
329
+ unsigned int reg1 , unsigned int reg2 ,
330
+ unsigned int reg3 ,
331
+ struct axi_clkgen_div_params * params )
330
332
{
331
333
axi_clkgen_mmcm_write (axi_clkgen , reg1 ,
332
- (params -> high << 6 ) | params -> low , 0xefff );
334
+ (params -> high << 6 ) | params -> low , 0xefff );
333
335
axi_clkgen_mmcm_write (axi_clkgen , reg2 ,
334
- (params -> frac << 12 ) | (params -> frac_en << 11 ) |
335
- (params -> frac_wf_r << 10 ) | (params -> edge << 7 ) |
336
- (params -> nocount << 6 ), 0x7fff );
336
+ (params -> frac << 12 ) | (params -> frac_en << 11 ) |
337
+ (params -> frac_wf_r << 10 ) | (params -> edge << 7 ) |
338
+ (params -> nocount << 6 ), 0x7fff );
337
339
if (reg3 != 0 ) {
338
340
axi_clkgen_mmcm_write (axi_clkgen , reg3 ,
339
- (params -> frac_phase << 11 ) | (params -> frac_wf_f << 10 ), 0x3c00 );
341
+ (params -> frac_phase << 11 ) | (params -> frac_wf_f << 10 ),
342
+ 0x3c00 );
340
343
}
341
344
}
342
345
343
- static int axi_clkgen_set_rate (struct clk_hw * clk_hw ,
344
- unsigned long rate , unsigned long parent_rate )
346
+ static int axi_clkgen_set_rate (struct clk_hw * clk_hw , unsigned long rate ,
347
+ unsigned long parent_rate )
345
348
{
346
349
struct axi_clkgen * axi_clkgen = clk_hw_to_axi_clkgen (clk_hw );
347
350
const struct axi_clkgen_limits * limits = & axi_clkgen -> limits ;
348
351
unsigned int d , m , dout ;
349
352
struct axi_clkgen_div_params params ;
350
- uint32_t power = 0 ;
351
- uint32_t filter ;
352
- uint32_t lock ;
353
+ u32 power = 0 , filter , lock ;
353
354
354
355
if (parent_rate == 0 || rate == 0 )
355
356
return - EINVAL ;
@@ -369,22 +370,22 @@ static int axi_clkgen_set_rate(struct clk_hw *clk_hw,
369
370
370
371
axi_clkgen_calc_clk_params (dout >> 3 , dout & 0x7 , & params );
371
372
axi_clkgen_set_div (axi_clkgen , MMCM_REG_CLKOUT0_1 , MMCM_REG_CLKOUT0_2 ,
372
- MMCM_REG_CLKOUT5_2 , & params );
373
+ MMCM_REG_CLKOUT5_2 , & params );
373
374
374
375
axi_clkgen_calc_clk_params (d , 0 , & params );
375
376
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_CLK_DIV ,
376
- (params .edge << 13 ) | (params .nocount << 12 ) |
377
- (params .high << 6 ) | params .low , 0x3fff );
377
+ (params .edge << 13 ) | (params .nocount << 12 ) |
378
+ (params .high << 6 ) | params .low , 0x3fff );
378
379
379
380
axi_clkgen_calc_clk_params (m >> 3 , m & 0x7 , & params );
380
381
axi_clkgen_set_div (axi_clkgen , MMCM_REG_CLK_FB1 , MMCM_REG_CLK_FB2 ,
381
- MMCM_REG_CLKOUT6_2 , & params );
382
+ MMCM_REG_CLKOUT6_2 , & params );
382
383
383
384
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_LOCK1 , lock & 0x3ff , 0x3ff );
384
385
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_LOCK2 ,
385
- (((lock >> 16 ) & 0x1f ) << 10 ) | 0x1 , 0x7fff );
386
+ (((lock >> 16 ) & 0x1f ) << 10 ) | 0x1 , 0x7fff );
386
387
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_LOCK3 ,
387
- (((lock >> 24 ) & 0x1f ) << 10 ) | 0x3e9 , 0x7fff );
388
+ (((lock >> 24 ) & 0x1f ) << 10 ) | 0x3e9 , 0x7fff );
388
389
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_FILTER1 , filter >> 16 , 0x9900 );
389
390
axi_clkgen_mmcm_write (axi_clkgen , MMCM_REG_FILTER2 , filter , 0x9900 );
390
391
@@ -413,7 +414,7 @@ static int axi_clkgen_determine_rate(struct clk_hw *hw,
413
414
}
414
415
415
416
static unsigned int axi_clkgen_get_div (struct axi_clkgen * axi_clkgen ,
416
- unsigned int reg1 , unsigned int reg2 )
417
+ unsigned int reg1 , unsigned int reg2 )
417
418
{
418
419
unsigned int val1 , val2 ;
419
420
unsigned int div ;
@@ -440,17 +441,17 @@ static unsigned int axi_clkgen_get_div(struct axi_clkgen *axi_clkgen,
440
441
}
441
442
442
443
static unsigned long axi_clkgen_recalc_rate (struct clk_hw * clk_hw ,
443
- unsigned long parent_rate )
444
+ unsigned long parent_rate )
444
445
{
445
446
struct axi_clkgen * axi_clkgen = clk_hw_to_axi_clkgen (clk_hw );
446
447
unsigned int d , m , dout ;
447
448
unsigned long long tmp ;
448
449
unsigned int val ;
449
450
450
451
dout = axi_clkgen_get_div (axi_clkgen , MMCM_REG_CLKOUT0_1 ,
451
- MMCM_REG_CLKOUT0_2 );
452
+ MMCM_REG_CLKOUT0_2 );
452
453
m = axi_clkgen_get_div (axi_clkgen , MMCM_REG_CLK_FB1 ,
453
- MMCM_REG_CLK_FB2 );
454
+ MMCM_REG_CLK_FB2 );
454
455
455
456
axi_clkgen_mmcm_read (axi_clkgen , MMCM_REG_CLK_DIV , & val );
456
457
if (val & MMCM_CLK_DIV_NOCOUNT )
@@ -623,7 +624,7 @@ static int axi_clkgen_probe(struct platform_device *pdev)
623
624
624
625
clk_name = pdev -> dev .of_node -> name ;
625
626
of_property_read_string (pdev -> dev .of_node , "clock-output-names" ,
626
- & clk_name );
627
+ & clk_name );
627
628
628
629
init .name = clk_name ;
629
630
init .ops = & axi_clkgen_ops ;
0 commit comments