@@ -99,7 +99,7 @@ struct ktd202x {
99
99
struct device * dev ;
100
100
struct regmap * regmap ;
101
101
bool enabled ;
102
- int num_leds ;
102
+ unsigned long num_leds ;
103
103
struct ktd202x_led leds [] __counted_by (num_leds );
104
104
};
105
105
@@ -381,39 +381,42 @@ static int ktd202x_blink_mc_set(struct led_classdev *cdev,
381
381
mc -> num_colors );
382
382
}
383
383
384
- static int ktd202x_setup_led_rgb (struct ktd202x * chip , struct device_node * np ,
384
+ static int ktd202x_setup_led_rgb (struct ktd202x * chip , struct fwnode_handle * fwnode ,
385
385
struct ktd202x_led * led , struct led_init_data * init_data )
386
386
{
387
+ struct fwnode_handle * child ;
387
388
struct led_classdev * cdev ;
388
- struct device_node * child ;
389
389
struct mc_subled * info ;
390
390
int num_channels ;
391
391
int i = 0 ;
392
392
393
- num_channels = of_get_available_child_count (np );
393
+ num_channels = 0 ;
394
+ fwnode_for_each_available_child_node (fwnode , child )
395
+ num_channels ++ ;
396
+
394
397
if (!num_channels || num_channels > chip -> num_leds )
395
398
return - EINVAL ;
396
399
397
400
info = devm_kcalloc (chip -> dev , num_channels , sizeof (* info ), GFP_KERNEL );
398
401
if (!info )
399
402
return - ENOMEM ;
400
403
401
- for_each_available_child_of_node ( np , child ) {
404
+ fwnode_for_each_available_child_node ( fwnode , child ) {
402
405
u32 mono_color ;
403
406
u32 reg ;
404
407
int ret ;
405
408
406
- ret = of_property_read_u32 (child , "reg" , & reg );
409
+ ret = fwnode_property_read_u32 (child , "reg" , & reg );
407
410
if (ret != 0 || reg >= chip -> num_leds ) {
408
- dev_err (chip -> dev , "invalid 'reg' of %pOFn \n" , child );
409
- of_node_put (child );
410
- return - EINVAL ;
411
+ dev_err (chip -> dev , "invalid 'reg' of %pfw \n" , child );
412
+ fwnode_handle_put (child );
413
+ return ret ;
411
414
}
412
415
413
- ret = of_property_read_u32 (child , "color" , & mono_color );
416
+ ret = fwnode_property_read_u32 (child , "color" , & mono_color );
414
417
if (ret < 0 && ret != - EINVAL ) {
415
- dev_err (chip -> dev , "failed to parse 'color' of %pOF \n" , child );
416
- of_node_put (child );
418
+ dev_err (chip -> dev , "failed to parse 'color' of %pfw \n" , child );
419
+ fwnode_handle_put (child );
417
420
return ret ;
418
421
}
419
422
@@ -433,16 +436,16 @@ static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct device_node *np,
433
436
return devm_led_classdev_multicolor_register_ext (chip -> dev , & led -> mcdev , init_data );
434
437
}
435
438
436
- static int ktd202x_setup_led_single (struct ktd202x * chip , struct device_node * np ,
439
+ static int ktd202x_setup_led_single (struct ktd202x * chip , struct fwnode_handle * fwnode ,
437
440
struct ktd202x_led * led , struct led_init_data * init_data )
438
441
{
439
442
struct led_classdev * cdev ;
440
443
u32 reg ;
441
444
int ret ;
442
445
443
- ret = of_property_read_u32 ( np , "reg" , & reg );
446
+ ret = fwnode_property_read_u32 ( fwnode , "reg" , & reg );
444
447
if (ret != 0 || reg >= chip -> num_leds ) {
445
- dev_err (chip -> dev , "invalid 'reg' of %pOFn \n" , np );
448
+ dev_err (chip -> dev , "invalid 'reg' of %pfw \n" , fwnode );
446
449
return - EINVAL ;
447
450
}
448
451
led -> index = reg ;
@@ -454,7 +457,7 @@ static int ktd202x_setup_led_single(struct ktd202x *chip, struct device_node *np
454
457
return devm_led_classdev_register_ext (chip -> dev , & led -> cdev , init_data );
455
458
}
456
459
457
- static int ktd202x_add_led (struct ktd202x * chip , struct device_node * np , unsigned int index )
460
+ static int ktd202x_add_led (struct ktd202x * chip , struct fwnode_handle * fwnode , unsigned int index )
458
461
{
459
462
struct ktd202x_led * led = & chip -> leds [index ];
460
463
struct led_init_data init_data = {};
@@ -463,21 +466,21 @@ static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigne
463
466
int ret ;
464
467
465
468
/* Color property is optional in single color case */
466
- ret = of_property_read_u32 ( np , "color" , & color );
469
+ ret = fwnode_property_read_u32 ( fwnode , "color" , & color );
467
470
if (ret < 0 && ret != - EINVAL ) {
468
- dev_err (chip -> dev , "failed to parse 'color' of %pOF \n" , np );
471
+ dev_err (chip -> dev , "failed to parse 'color' of %pfw \n" , fwnode );
469
472
return ret ;
470
473
}
471
474
472
475
led -> chip = chip ;
473
- init_data .fwnode = of_fwnode_handle ( np ) ;
476
+ init_data .fwnode = fwnode ;
474
477
475
478
if (color == LED_COLOR_ID_RGB ) {
476
479
cdev = & led -> mcdev .led_cdev ;
477
- ret = ktd202x_setup_led_rgb (chip , np , led , & init_data );
480
+ ret = ktd202x_setup_led_rgb (chip , fwnode , led , & init_data );
478
481
} else {
479
482
cdev = & led -> cdev ;
480
- ret = ktd202x_setup_led_single (chip , np , led , & init_data );
483
+ ret = ktd202x_setup_led_single (chip , fwnode , led , & init_data );
481
484
}
482
485
483
486
if (ret ) {
@@ -490,15 +493,14 @@ static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigne
490
493
return 0 ;
491
494
}
492
495
493
- static int ktd202x_probe_dt (struct ktd202x * chip )
496
+ static int ktd202x_probe_fw (struct ktd202x * chip )
494
497
{
495
- struct device_node * np = dev_of_node (chip -> dev ), * child ;
498
+ struct fwnode_handle * child ;
499
+ struct device * dev = chip -> dev ;
496
500
int count ;
497
501
int i = 0 ;
498
502
499
- chip -> num_leds = (int )(unsigned long )of_device_get_match_data (chip -> dev );
500
-
501
- count = of_get_available_child_count (np );
503
+ count = device_get_child_node_count (dev );
502
504
if (!count || count > chip -> num_leds )
503
505
return - EINVAL ;
504
506
@@ -507,11 +509,11 @@ static int ktd202x_probe_dt(struct ktd202x *chip)
507
509
/* Allow the device to execute the complete reset */
508
510
usleep_range (200 , 300 );
509
511
510
- for_each_available_child_of_node ( np , child ) {
512
+ device_for_each_child_node ( dev , child ) {
511
513
int ret = ktd202x_add_led (chip , child , i );
512
514
513
515
if (ret ) {
514
- of_node_put (child );
516
+ fwnode_handle_put (child );
515
517
return ret ;
516
518
}
517
519
i ++ ;
@@ -554,6 +556,12 @@ static int ktd202x_probe(struct i2c_client *client)
554
556
return ret ;
555
557
}
556
558
559
+ ret = devm_mutex_init (dev , & chip -> mutex );
560
+ if (ret )
561
+ return ret ;
562
+
563
+ chip -> num_leds = (unsigned long )i2c_get_match_data (client );
564
+
557
565
chip -> regulators [0 ].supply = "vin" ;
558
566
chip -> regulators [1 ].supply = "vio" ;
559
567
ret = devm_regulator_bulk_get (dev , ARRAY_SIZE (chip -> regulators ), chip -> regulators );
@@ -568,7 +576,7 @@ static int ktd202x_probe(struct i2c_client *client)
568
576
return ret ;
569
577
}
570
578
571
- ret = ktd202x_probe_dt (chip );
579
+ ret = ktd202x_probe_fw (chip );
572
580
if (ret < 0 ) {
573
581
regulator_bulk_disable (ARRAY_SIZE (chip -> regulators ), chip -> regulators );
574
582
return ret ;
@@ -580,8 +588,6 @@ static int ktd202x_probe(struct i2c_client *client)
580
588
return ret ;
581
589
}
582
590
583
- mutex_init (& chip -> mutex );
584
-
585
591
return 0 ;
586
592
}
587
593
@@ -590,8 +596,6 @@ static void ktd202x_remove(struct i2c_client *client)
590
596
struct ktd202x * chip = i2c_get_clientdata (client );
591
597
592
598
ktd202x_chip_disable (chip );
593
-
594
- mutex_destroy (& chip -> mutex );
595
599
}
596
600
597
601
static void ktd202x_shutdown (struct i2c_client * client )
@@ -602,10 +606,17 @@ static void ktd202x_shutdown(struct i2c_client *client)
602
606
regmap_write (chip -> regmap , KTD202X_REG_RESET_CONTROL , KTD202X_RSTR_RESET );
603
607
}
604
608
609
+ static const struct i2c_device_id ktd202x_id [] = {
610
+ {"ktd2026" , KTD2026_NUM_LEDS },
611
+ {"ktd2027" , KTD2027_NUM_LEDS },
612
+ {}
613
+ };
614
+ MODULE_DEVICE_TABLE (i2c , ktd202x_id );
615
+
605
616
static const struct of_device_id ktd202x_match_table [] = {
606
617
{ .compatible = "kinetic,ktd2026" , .data = (void * )KTD2026_NUM_LEDS },
607
618
{ .compatible = "kinetic,ktd2027" , .data = (void * )KTD2027_NUM_LEDS },
608
- {},
619
+ {}
609
620
};
610
621
MODULE_DEVICE_TABLE (of , ktd202x_match_table );
611
622
@@ -617,6 +628,7 @@ static struct i2c_driver ktd202x_driver = {
617
628
.probe = ktd202x_probe ,
618
629
.remove = ktd202x_remove ,
619
630
.shutdown = ktd202x_shutdown ,
631
+ .id_table = ktd202x_id ,
620
632
};
621
633
module_i2c_driver (ktd202x_driver );
622
634
0 commit comments