@@ -303,75 +303,75 @@ static const struct stratix10_gate_clock agilex_gate_clks[] = {
303
303
static int n5x_clk_register_c_perip (const struct n5x_perip_c_clock * clks ,
304
304
int nums , struct stratix10_clock_data * data )
305
305
{
306
- struct clk * clk ;
306
+ struct clk_hw * hw_clk ;
307
307
void __iomem * base = data -> base ;
308
308
int i ;
309
309
310
310
for (i = 0 ; i < nums ; i ++ ) {
311
- clk = n5x_register_periph (& clks [i ], base );
312
- if (IS_ERR (clk )) {
311
+ hw_clk = n5x_register_periph (& clks [i ], base );
312
+ if (IS_ERR (hw_clk )) {
313
313
pr_err ("%s: failed to register clock %s\n" ,
314
314
__func__ , clks [i ].name );
315
315
continue ;
316
316
}
317
- data -> clk_data .clks [clks [i ].id ] = clk ;
317
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
318
318
}
319
319
return 0 ;
320
320
}
321
321
322
322
static int agilex_clk_register_c_perip (const struct stratix10_perip_c_clock * clks ,
323
323
int nums , struct stratix10_clock_data * data )
324
324
{
325
- struct clk * clk ;
325
+ struct clk_hw * hw_clk ;
326
326
void __iomem * base = data -> base ;
327
327
int i ;
328
328
329
329
for (i = 0 ; i < nums ; i ++ ) {
330
- clk = s10_register_periph (& clks [i ], base );
331
- if (IS_ERR (clk )) {
330
+ hw_clk = s10_register_periph (& clks [i ], base );
331
+ if (IS_ERR (hw_clk )) {
332
332
pr_err ("%s: failed to register clock %s\n" ,
333
333
__func__ , clks [i ].name );
334
334
continue ;
335
335
}
336
- data -> clk_data .clks [clks [i ].id ] = clk ;
336
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
337
337
}
338
338
return 0 ;
339
339
}
340
340
341
341
static int agilex_clk_register_cnt_perip (const struct stratix10_perip_cnt_clock * clks ,
342
342
int nums , struct stratix10_clock_data * data )
343
343
{
344
- struct clk * clk ;
344
+ struct clk_hw * hw_clk ;
345
345
void __iomem * base = data -> base ;
346
346
int i ;
347
347
348
348
for (i = 0 ; i < nums ; i ++ ) {
349
- clk = s10_register_cnt_periph (& clks [i ], base );
350
- if (IS_ERR (clk )) {
349
+ hw_clk = s10_register_cnt_periph (& clks [i ], base );
350
+ if (IS_ERR (hw_clk )) {
351
351
pr_err ("%s: failed to register clock %s\n" ,
352
352
__func__ , clks [i ].name );
353
353
continue ;
354
354
}
355
- data -> clk_data .clks [clks [i ].id ] = clk ;
355
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
356
356
}
357
357
358
358
return 0 ;
359
359
}
360
360
361
361
static int agilex_clk_register_gate (const struct stratix10_gate_clock * clks , int nums , struct stratix10_clock_data * data )
362
362
{
363
- struct clk * clk ;
363
+ struct clk_hw * hw_clk ;
364
364
void __iomem * base = data -> base ;
365
365
int i ;
366
366
367
367
for (i = 0 ; i < nums ; i ++ ) {
368
- clk = s10_register_gate (& clks [i ], base );
369
- if (IS_ERR (clk )) {
368
+ hw_clk = s10_register_gate (& clks [i ], base );
369
+ if (IS_ERR (hw_clk )) {
370
370
pr_err ("%s: failed to register clock %s\n" ,
371
371
__func__ , clks [i ].name );
372
372
continue ;
373
373
}
374
- data -> clk_data .clks [clks [i ].id ] = clk ;
374
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
375
375
}
376
376
377
377
return 0 ;
@@ -380,18 +380,18 @@ static int agilex_clk_register_gate(const struct stratix10_gate_clock *clks,
380
380
static int agilex_clk_register_pll (const struct stratix10_pll_clock * clks ,
381
381
int nums , struct stratix10_clock_data * data )
382
382
{
383
- struct clk * clk ;
383
+ struct clk_hw * hw_clk ;
384
384
void __iomem * base = data -> base ;
385
385
int i ;
386
386
387
387
for (i = 0 ; i < nums ; i ++ ) {
388
- clk = agilex_register_pll (& clks [i ], base );
389
- if (IS_ERR (clk )) {
388
+ hw_clk = agilex_register_pll (& clks [i ], base );
389
+ if (IS_ERR (hw_clk )) {
390
390
pr_err ("%s: failed to register clock %s\n" ,
391
391
__func__ , clks [i ].name );
392
392
continue ;
393
393
}
394
- data -> clk_data .clks [clks [i ].id ] = clk ;
394
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
395
395
}
396
396
397
397
return 0 ;
@@ -400,64 +400,49 @@ static int agilex_clk_register_pll(const struct stratix10_pll_clock *clks,
400
400
static int n5x_clk_register_pll (const struct stratix10_pll_clock * clks ,
401
401
int nums , struct stratix10_clock_data * data )
402
402
{
403
- struct clk * clk ;
403
+ struct clk_hw * hw_clk ;
404
404
void __iomem * base = data -> base ;
405
405
int i ;
406
406
407
407
for (i = 0 ; i < nums ; i ++ ) {
408
- clk = n5x_register_pll (& clks [i ], base );
409
- if (IS_ERR (clk )) {
408
+ hw_clk = n5x_register_pll (& clks [i ], base );
409
+ if (IS_ERR (hw_clk )) {
410
410
pr_err ("%s: failed to register clock %s\n" ,
411
411
__func__ , clks [i ].name );
412
412
continue ;
413
413
}
414
- data -> clk_data .clks [clks [i ].id ] = clk ;
414
+ data -> clk_data .hws [clks [i ].id ] = hw_clk ;
415
415
}
416
416
417
417
return 0 ;
418
418
}
419
419
420
- static struct stratix10_clock_data * __socfpga_agilex_clk_init (struct platform_device * pdev ,
421
- int nr_clks )
420
+ static int agilex_clkmgr_init (struct platform_device * pdev )
422
421
{
423
422
struct device_node * np = pdev -> dev .of_node ;
424
423
struct device * dev = & pdev -> dev ;
425
424
struct stratix10_clock_data * clk_data ;
426
- struct clk * * clk_table ;
427
425
struct resource * res ;
428
426
void __iomem * base ;
429
- int ret ;
427
+ int i , num_clks ;
430
428
431
429
res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
432
430
base = devm_ioremap_resource (dev , res );
433
431
if (IS_ERR (base ))
434
- return ERR_CAST (base );
435
-
436
- clk_data = devm_kzalloc (dev , sizeof (* clk_data ), GFP_KERNEL );
437
- if (!clk_data )
438
- return ERR_PTR (- ENOMEM );
432
+ return PTR_ERR (base );
439
433
440
- clk_data -> base = base ;
441
- clk_table = devm_kcalloc (dev , nr_clks , sizeof (* clk_table ), GFP_KERNEL );
442
- if (!clk_table )
443
- return ERR_PTR (- ENOMEM );
444
-
445
- clk_data -> clk_data .clks = clk_table ;
446
- clk_data -> clk_data .clk_num = nr_clks ;
447
- ret = of_clk_add_provider (np , of_clk_src_onecell_get , & clk_data -> clk_data );
448
- if (ret )
449
- return ERR_PTR (ret );
434
+ num_clks = AGILEX_NUM_CLKS ;
450
435
451
- return clk_data ;
452
- }
436
+ clk_data = devm_kzalloc (dev , struct_size (clk_data , clk_data .hws ,
437
+ num_clks ), GFP_KERNEL );
438
+ if (!clk_data )
439
+ return - ENOMEM ;
453
440
454
- static int agilex_clkmgr_init (struct platform_device * pdev )
455
- {
456
- struct stratix10_clock_data * clk_data ;
441
+ for (i = 0 ; i < num_clks ; i ++ )
442
+ clk_data -> clk_data .hws [i ] = ERR_PTR (- ENOENT );
457
443
458
- clk_data = __socfpga_agilex_clk_init (pdev , AGILEX_NUM_CLKS );
459
- if (IS_ERR (clk_data ))
460
- return PTR_ERR (clk_data );
444
+ clk_data -> base = base ;
445
+ clk_data -> clk_data .num = num_clks ;
461
446
462
447
agilex_clk_register_pll (agilex_pll_clks , ARRAY_SIZE (agilex_pll_clks ), clk_data );
463
448
@@ -470,16 +455,36 @@ static int agilex_clkmgr_init(struct platform_device *pdev)
470
455
471
456
agilex_clk_register_gate (agilex_gate_clks , ARRAY_SIZE (agilex_gate_clks ),
472
457
clk_data );
458
+ of_clk_add_hw_provider (np , of_clk_hw_onecell_get , & clk_data -> clk_data );
473
459
return 0 ;
474
460
}
475
461
476
462
static int n5x_clkmgr_init (struct platform_device * pdev )
477
463
{
464
+ struct device_node * np = pdev -> dev .of_node ;
465
+ struct device * dev = & pdev -> dev ;
478
466
struct stratix10_clock_data * clk_data ;
467
+ struct resource * res ;
468
+ void __iomem * base ;
469
+ int i , num_clks ;
470
+
471
+ res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
472
+ base = devm_ioremap_resource (dev , res );
473
+ if (IS_ERR (base ))
474
+ return PTR_ERR (base );
475
+
476
+ num_clks = AGILEX_NUM_CLKS ;
477
+
478
+ clk_data = devm_kzalloc (dev , struct_size (clk_data , clk_data .hws ,
479
+ num_clks ), GFP_KERNEL );
480
+ if (!clk_data )
481
+ return - ENOMEM ;
482
+
483
+ for (i = 0 ; i < num_clks ; i ++ )
484
+ clk_data -> clk_data .hws [i ] = ERR_PTR (- ENOENT );
479
485
480
- clk_data = __socfpga_agilex_clk_init (pdev , AGILEX_NUM_CLKS );
481
- if (IS_ERR (clk_data ))
482
- return PTR_ERR (clk_data );
486
+ clk_data -> base = base ;
487
+ clk_data -> clk_data .num = num_clks ;
483
488
484
489
n5x_clk_register_pll (agilex_pll_clks , ARRAY_SIZE (agilex_pll_clks ), clk_data );
485
490
@@ -492,6 +497,7 @@ static int n5x_clkmgr_init(struct platform_device *pdev)
492
497
493
498
agilex_clk_register_gate (agilex_gate_clks , ARRAY_SIZE (agilex_gate_clks ),
494
499
clk_data );
500
+ of_clk_add_hw_provider (np , of_clk_hw_onecell_get , & clk_data -> clk_data );
495
501
return 0 ;
496
502
}
497
503
0 commit comments