* [PATCH v2] leds: pca963x: enable low-power state
@ 2016-10-20 0:03 ` Matt Ranostay
2016-10-20 6:08 ` Jacek Anaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Matt Ranostay @ 2016-10-20 0:03 UTC (permalink / raw)
To: linux-leds; +Cc: Matt Ranostay, Tony Lindgren, Jacek Anaszewski
Allow chip to enter low power state when no LEDs are being lit or in
blink mode.
Cc: Tony Lindgren <tony@atomide.com>
Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
Changes from v1:
* remove runtime pm
* count leds that are off, if all then enter low-power state
drivers/leds/leds-pca963x.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 407eba11e187..797dffc42c59 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -179,14 +179,32 @@ static void pca963x_blink(struct pca963x_led *pca963x)
mutex_unlock(&pca963x->chip->mutex);
}
+static int pca963x_power_state(struct pca963x_led *pca963x)
+{
+ int i, leds_on = 0;
+
+ for (i = 0; i < pca963x->chip->chipdef->n_leds; i++) {
+ if (pca963x->chip->leds[i].led_cdev.brightness > 0)
+ leds_on++;
+ }
+
+ return i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE1,
+ leds_on ? 0 : BIT(4));
+}
+
static int pca963x_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct pca963x_led *pca963x;
+ int ret;
pca963x = container_of(led_cdev, struct pca963x_led, led_cdev);
- return pca963x_brightness(pca963x, value);
+ ret = pca963x_brightness(pca963x, value);
+ if (ret < 0)
+ return ret;
+
+ return pca963x_power_state(pca963x);
}
static int pca963x_blink_set(struct led_classdev *led_cdev,
@@ -391,8 +409,8 @@ static int pca963x_probe(struct i2c_client *client,
goto exit;
}
- /* Disable LED all-call address and set normal mode */
- i2c_smbus_write_byte_data(client, PCA963X_MODE1, 0x00);
+ /* Disable LED all-call address, and power down initially */
+ i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
if (pdata) {
/* Configure output: open-drain or totem pole (push-pull) */
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] leds: pca963x: enable low-power state
2016-10-20 0:03 ` [PATCH v2] leds: pca963x: enable low-power state Matt Ranostay
@ 2016-10-20 6:08 ` Jacek Anaszewski
2016-10-20 6:15 ` Matt Ranostay
0 siblings, 1 reply; 3+ messages in thread
From: Jacek Anaszewski @ 2016-10-20 6:08 UTC (permalink / raw)
To: Matt Ranostay, linux-leds
Cc: Matt Ranostay, Tony Lindgren, Peter Meerwald, Ricardo Ribalda
Hi Matt,
Thanks for the update.
Let me cc also authors of the driver.
On 10/20/2016 02:03 AM, Matt Ranostay wrote:
> Allow chip to enter low power state when no LEDs are being lit or in
> blink mode.
>
> Cc: Tony Lindgren <tony@atomide.com>
> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
> Changes from v1:
> * remove runtime pm
> * count leds that are off, if all then enter low-power state
>
> drivers/leds/leds-pca963x.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
> index 407eba11e187..797dffc42c59 100644
> --- a/drivers/leds/leds-pca963x.c
> +++ b/drivers/leds/leds-pca963x.c
> @@ -179,14 +179,32 @@ static void pca963x_blink(struct pca963x_led *pca963x)
> mutex_unlock(&pca963x->chip->mutex);
> }
>
> +static int pca963x_power_state(struct pca963x_led *pca963x)
> +{
> + int i, leds_on = 0;
> +
> + for (i = 0; i < pca963x->chip->chipdef->n_leds; i++) {
> + if (pca963x->chip->leds[i].led_cdev.brightness > 0)
> + leds_on++;
> + }
You could avoid executing this loop on every brightness setting,
if you added a counter and incremented/decremented it when turning
a LED on/off respectively. Then you could write PCA963X_MODE1 on
counter transitions from 0 to 1 and from 1 to 0.
> +
> + return i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE1,
> + leds_on ? 0 : BIT(4));
> +}
> +
> static int pca963x_led_set(struct led_classdev *led_cdev,
> enum led_brightness value)
> {
> struct pca963x_led *pca963x;
> + int ret;
>
> pca963x = container_of(led_cdev, struct pca963x_led, led_cdev);
>
> - return pca963x_brightness(pca963x, value);
> + ret = pca963x_brightness(pca963x, value);
> + if (ret < 0)
> + return ret;
> +
> + return pca963x_power_state(pca963x);
> }
>
> static int pca963x_blink_set(struct led_classdev *led_cdev,
> @@ -391,8 +409,8 @@ static int pca963x_probe(struct i2c_client *client,
> goto exit;
> }
>
> - /* Disable LED all-call address and set normal mode */
> - i2c_smbus_write_byte_data(client, PCA963X_MODE1, 0x00);
> + /* Disable LED all-call address, and power down initially */
> + i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
>
> if (pdata) {
> /* Configure output: open-drain or totem pole (push-pull) */
>
--
Best regards,
Jacek Anaszewski
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] leds: pca963x: enable low-power state
2016-10-20 6:08 ` Jacek Anaszewski
@ 2016-10-20 6:15 ` Matt Ranostay
0 siblings, 0 replies; 3+ messages in thread
From: Matt Ranostay @ 2016-10-20 6:15 UTC (permalink / raw)
To: Jacek Anaszewski
Cc: linux-leds, Matt Ranostay, Tony Lindgren, Peter Meerwald,
Ricardo Ribalda
> On Oct 19, 2016, at 23:08, Jacek Anaszewski <j.anaszewski@samsung.com> wrote:
>
> Hi Matt,
>
> Thanks for the update.
> Let me cc also authors of the driver.
>
>> On 10/20/2016 02:03 AM, Matt Ranostay wrote:
>> Allow chip to enter low power state when no LEDs are being lit or in
>> blink mode.
>>
>> Cc: Tony Lindgren <tony@atomide.com>
>> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>> Changes from v1:
>> * remove runtime pm
>> * count leds that are off, if all then enter low-power state
>>
>> drivers/leds/leds-pca963x.c | 24 +++++++++++++++++++++---
>> 1 file changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
>> index 407eba11e187..797dffc42c59 100644
>> --- a/drivers/leds/leds-pca963x.c
>> +++ b/drivers/leds/leds-pca963x.c
>> @@ -179,14 +179,32 @@ static void pca963x_blink(struct pca963x_led *pca963x)
>> mutex_unlock(&pca963x->chip->mutex);
>> }
>>
>> +static int pca963x_power_state(struct pca963x_led *pca963x)
>> +{
>> + int i, leds_on = 0;
>> +
>> + for (i = 0; i < pca963x->chip->chipdef->n_leds; i++) {
>> + if (pca963x->chip->leds[i].led_cdev.brightness > 0)
>> + leds_on++;
>> + }
>
> You could avoid executing this loop on every brightness setting,
> if you added a counter and incremented/decremented it when turning
> a LED on/off respectively. Then you could write PCA963X_MODE1 on
> counter transitions from 0 to 1 and from 1 to 0.
Thought of that but seems so low bandwidth it wouldn't matter. But have no issue adding a counter if required of course in v3
>
>> +
>> + return i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE1,
>> + leds_on ? 0 : BIT(4));
>> +}
>> +
>> static int pca963x_led_set(struct led_classdev *led_cdev,
>> enum led_brightness value)
>> {
>> struct pca963x_led *pca963x;
>> + int ret;
>>
>> pca963x = container_of(led_cdev, struct pca963x_led, led_cdev);
>>
>> - return pca963x_brightness(pca963x, value);
>> + ret = pca963x_brightness(pca963x, value);
>> + if (ret < 0)
>> + return ret;
>> +
>> + return pca963x_power_state(pca963x);
>> }
>>
>> static int pca963x_blink_set(struct led_classdev *led_cdev,
>> @@ -391,8 +409,8 @@ static int pca963x_probe(struct i2c_client *client,
>> goto exit;
>> }
>>
>> - /* Disable LED all-call address and set normal mode */
>> - i2c_smbus_write_byte_data(client, PCA963X_MODE1, 0x00);
>> + /* Disable LED all-call address, and power down initially */
>> + i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
>>
>> if (pdata) {
>> /* Configure output: open-drain or totem pole (push-pull) */
>>
>
>
> --
> Best regards,
> Jacek Anaszewski
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-20 6:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20161020000405eucas1p1db947d4d5abdb1d0cd8fe65b1bfb69af@eucas1p1.samsung.com>
2016-10-20 0:03 ` [PATCH v2] leds: pca963x: enable low-power state Matt Ranostay
2016-10-20 6:08 ` Jacek Anaszewski
2016-10-20 6:15 ` Matt Ranostay
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.