Commit e46cb6d0 authored by Eddie James's avatar Eddie James Committed by Pavel Machek

leds: pca955x: Implement the default-state property

In order to retain the LED state after a system reboot, check the
documented default-state device tree property during initialization.
Modify the behavior of the probe according to the property.
Signed-off-by: default avatarEddie James <eajames@linux.ibm.com>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent 7086625f
...@@ -129,6 +129,7 @@ struct pca955x_led { ...@@ -129,6 +129,7 @@ struct pca955x_led {
int led_num; /* 0 .. 15 potentially */ int led_num; /* 0 .. 15 potentially */
char name[32]; char name[32];
u32 type; u32 type;
int default_state;
const char *default_trigger; const char *default_trigger;
}; };
...@@ -439,6 +440,7 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) ...@@ -439,6 +440,7 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
device_for_each_child_node(&client->dev, child) { device_for_each_child_node(&client->dev, child) {
const char *name; const char *name;
const char *state;
u32 reg; u32 reg;
int res; int res;
...@@ -457,6 +459,18 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) ...@@ -457,6 +459,18 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
fwnode_property_read_u32(child, "type", &led->type); fwnode_property_read_u32(child, "type", &led->type);
fwnode_property_read_string(child, "linux,default-trigger", fwnode_property_read_string(child, "linux,default-trigger",
&led->default_trigger); &led->default_trigger);
if (!fwnode_property_read_string(child, "default-state",
&state)) {
if (!strcmp(state, "keep"))
led->default_state = LEDS_GPIO_DEFSTATE_KEEP;
else if (!strcmp(state, "on"))
led->default_state = LEDS_GPIO_DEFSTATE_ON;
else
led->default_state = LEDS_GPIO_DEFSTATE_OFF;
} else {
led->default_state = LEDS_GPIO_DEFSTATE_OFF;
}
} }
pdata->num_leds = chip->bits; pdata->num_leds = chip->bits;
...@@ -485,6 +499,7 @@ static int pca955x_probe(struct i2c_client *client, ...@@ -485,6 +499,7 @@ static int pca955x_probe(struct i2c_client *client,
int i, err; int i, err;
struct pca955x_platform_data *pdata; struct pca955x_platform_data *pdata;
int ngpios = 0; int ngpios = 0;
bool keep_pwm = false;
chip = &pca955x_chipdefs[id->driver_data]; chip = &pca955x_chipdefs[id->driver_data];
adapter = client->adapter; adapter = client->adapter;
...@@ -565,14 +580,35 @@ static int pca955x_probe(struct i2c_client *client, ...@@ -565,14 +580,35 @@ static int pca955x_probe(struct i2c_client *client,
led->brightness_set_blocking = pca955x_led_set; led->brightness_set_blocking = pca955x_led_set;
led->brightness_get = pca955x_led_get; led->brightness_get = pca955x_led_get;
if (pdata->leds[i].default_state ==
LEDS_GPIO_DEFSTATE_OFF) {
err = pca955x_led_set(led, LED_OFF);
if (err)
return err;
} else if (pdata->leds[i].default_state ==
LEDS_GPIO_DEFSTATE_ON) {
err = pca955x_led_set(led, LED_FULL);
if (err)
return err;
}
err = devm_led_classdev_register(&client->dev, led); err = devm_led_classdev_register(&client->dev, led);
if (err) if (err)
return err; return err;
/* Turn off LED */ /*
err = pca955x_led_set(led, LED_OFF); * For default-state == "keep", let the core update the
if (err) * brightness from the hardware, then check the
return err; * brightness to see if it's using PWM1. If so, PWM1
* should not be written below.
*/
if (pdata->leds[i].default_state ==
LEDS_GPIO_DEFSTATE_KEEP) {
if (led->brightness != LED_FULL &&
led->brightness != LED_OFF &&
led->brightness != LED_HALF)
keep_pwm = true;
}
} }
} }
...@@ -581,10 +617,12 @@ static int pca955x_probe(struct i2c_client *client, ...@@ -581,10 +617,12 @@ static int pca955x_probe(struct i2c_client *client,
if (err) if (err)
return err; return err;
/* PWM1 is used for variable brightness, default to OFF */ if (!keep_pwm) {
err = pca955x_write_pwm(client, 1, 0); /* PWM1 is used for variable brightness, default to OFF */
if (err) err = pca955x_write_pwm(client, 1, 0);
return err; if (err)
return err;
}
/* Set to fast frequency so we do not see flashing */ /* Set to fast frequency so we do not see flashing */
err = pca955x_write_psc(client, 0, 0); err = pca955x_write_psc(client, 0, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment