1 From e46cb6d0c760a5b15e38138845fad99628fafcb8 Mon Sep 17 00:00:00 2001
2 From: Eddie James <eajames@linux.ibm.com>
3 Date: Fri, 16 Jul 2021 17:03:29 -0500
4 Subject: [PATCH] leds: pca955x: Implement the default-state property
6 In order to retain the LED state after a system reboot, check the
7 documented default-state device tree property during initialization.
8 Modify the behavior of the probe according to the property.
10 Signed-off-by: Eddie James <eajames@linux.ibm.com>
11 Signed-off-by: Pavel Machek <pavel@ucw.cz>
13 drivers/leds/leds-pca955x.c | 54 +++++++++++++++++++++++++++++++------
14 1 file changed, 46 insertions(+), 8 deletions(-)
16 --- a/drivers/leds/leds-pca955x.c
17 +++ b/drivers/leds/leds-pca955x.c
18 @@ -129,6 +129,7 @@ struct pca955x_led {
19 int led_num; /* 0 .. 15 potentially */
23 const char *default_trigger;
26 @@ -439,6 +440,7 @@ pca955x_get_pdata(struct i2c_client *cli
28 device_for_each_child_node(&client->dev, child) {
34 @@ -457,6 +459,18 @@ pca955x_get_pdata(struct i2c_client *cli
35 fwnode_property_read_u32(child, "type", &led->type);
36 fwnode_property_read_string(child, "linux,default-trigger",
37 &led->default_trigger);
39 + if (!fwnode_property_read_string(child, "default-state",
41 + if (!strcmp(state, "keep"))
42 + led->default_state = LEDS_GPIO_DEFSTATE_KEEP;
43 + else if (!strcmp(state, "on"))
44 + led->default_state = LEDS_GPIO_DEFSTATE_ON;
46 + led->default_state = LEDS_GPIO_DEFSTATE_OFF;
48 + led->default_state = LEDS_GPIO_DEFSTATE_OFF;
52 pdata->num_leds = chip->bits;
53 @@ -485,6 +499,7 @@ static int pca955x_probe(struct i2c_clie
55 struct pca955x_platform_data *pdata;
57 + bool keep_pwm = false;
59 chip = &pca955x_chipdefs[id->driver_data];
60 adapter = client->adapter;
61 @@ -565,14 +580,35 @@ static int pca955x_probe(struct i2c_clie
62 led->brightness_set_blocking = pca955x_led_set;
63 led->brightness_get = pca955x_led_get;
65 + if (pdata->leds[i].default_state ==
66 + LEDS_GPIO_DEFSTATE_OFF) {
67 + err = pca955x_led_set(led, LED_OFF);
70 + } else if (pdata->leds[i].default_state ==
71 + LEDS_GPIO_DEFSTATE_ON) {
72 + err = pca955x_led_set(led, LED_FULL);
77 err = devm_led_classdev_register(&client->dev, led);
82 - err = pca955x_led_set(led, LED_OFF);
86 + * For default-state == "keep", let the core update the
87 + * brightness from the hardware, then check the
88 + * brightness to see if it's using PWM1. If so, PWM1
89 + * should not be written below.
91 + if (pdata->leds[i].default_state ==
92 + LEDS_GPIO_DEFSTATE_KEEP) {
93 + if (led->brightness != LED_FULL &&
94 + led->brightness != LED_OFF &&
95 + led->brightness != LED_HALF)
101 @@ -581,10 +617,12 @@ static int pca955x_probe(struct i2c_clie
105 - /* PWM1 is used for variable brightness, default to OFF */
106 - err = pca955x_write_pwm(client, 1, 0);
110 + /* PWM1 is used for variable brightness, default to OFF */
111 + err = pca955x_write_pwm(client, 1, 0);
116 /* Set to fast frequency so we do not see flashing */
117 err = pca955x_write_psc(client, 0, 0);