@@ -129,6 +129,7 @@ struct pca955x_led {
129
129
int led_num ; /* 0 .. 15 potentially */
130
130
char name [32 ];
131
131
u32 type ;
132
+ int default_state ;
132
133
const char * default_trigger ;
133
134
};
134
135
@@ -439,6 +440,7 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
439
440
440
441
device_for_each_child_node (& client -> dev , child ) {
441
442
const char * name ;
443
+ const char * state ;
442
444
u32 reg ;
443
445
int res ;
444
446
@@ -457,6 +459,18 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
457
459
fwnode_property_read_u32 (child , "type" , & led -> type );
458
460
fwnode_property_read_string (child , "linux,default-trigger" ,
459
461
& led -> default_trigger );
462
+
463
+ if (!fwnode_property_read_string (child , "default-state" ,
464
+ & state )) {
465
+ if (!strcmp (state , "keep" ))
466
+ led -> default_state = LEDS_GPIO_DEFSTATE_KEEP ;
467
+ else if (!strcmp (state , "on" ))
468
+ led -> default_state = LEDS_GPIO_DEFSTATE_ON ;
469
+ else
470
+ led -> default_state = LEDS_GPIO_DEFSTATE_OFF ;
471
+ } else {
472
+ led -> default_state = LEDS_GPIO_DEFSTATE_OFF ;
473
+ }
460
474
}
461
475
462
476
pdata -> num_leds = chip -> bits ;
@@ -485,6 +499,7 @@ static int pca955x_probe(struct i2c_client *client,
485
499
int i , err ;
486
500
struct pca955x_platform_data * pdata ;
487
501
int ngpios = 0 ;
502
+ bool keep_pwm = false;
488
503
489
504
chip = & pca955x_chipdefs [id -> driver_data ];
490
505
adapter = client -> adapter ;
@@ -565,14 +580,35 @@ static int pca955x_probe(struct i2c_client *client,
565
580
led -> brightness_set_blocking = pca955x_led_set ;
566
581
led -> brightness_get = pca955x_led_get ;
567
582
583
+ if (pdata -> leds [i ].default_state ==
584
+ LEDS_GPIO_DEFSTATE_OFF ) {
585
+ err = pca955x_led_set (led , LED_OFF );
586
+ if (err )
587
+ return err ;
588
+ } else if (pdata -> leds [i ].default_state ==
589
+ LEDS_GPIO_DEFSTATE_ON ) {
590
+ err = pca955x_led_set (led , LED_FULL );
591
+ if (err )
592
+ return err ;
593
+ }
594
+
568
595
err = devm_led_classdev_register (& client -> dev , led );
569
596
if (err )
570
597
return err ;
571
598
572
- /* Turn off LED */
573
- err = pca955x_led_set (led , LED_OFF );
574
- if (err )
575
- return err ;
599
+ /*
600
+ * For default-state == "keep", let the core update the
601
+ * brightness from the hardware, then check the
602
+ * brightness to see if it's using PWM1. If so, PWM1
603
+ * should not be written below.
604
+ */
605
+ if (pdata -> leds [i ].default_state ==
606
+ LEDS_GPIO_DEFSTATE_KEEP ) {
607
+ if (led -> brightness != LED_FULL &&
608
+ led -> brightness != LED_OFF &&
609
+ led -> brightness != LED_HALF )
610
+ keep_pwm = true;
611
+ }
576
612
}
577
613
}
578
614
@@ -581,10 +617,12 @@ static int pca955x_probe(struct i2c_client *client,
581
617
if (err )
582
618
return err ;
583
619
584
- /* PWM1 is used for variable brightness, default to OFF */
585
- err = pca955x_write_pwm (client , 1 , 0 );
586
- if (err )
587
- return err ;
620
+ if (!keep_pwm ) {
621
+ /* PWM1 is used for variable brightness, default to OFF */
622
+ err = pca955x_write_pwm (client , 1 , 0 );
623
+ if (err )
624
+ return err ;
625
+ }
588
626
589
627
/* Set to fast frequency so we do not see flashing */
590
628
err = pca955x_write_psc (client , 0 , 0 );
0 commit comments