2019-09-09 13:35:31

by Andreas Kemnade

[permalink] [raw]
Subject: [PATCH 0/2] backlight_lm3630a: add enable_gpios property

To be able to handle the HWEN pin of the lm3630a, add
an enable gpio to the driver and a property.

Tested on Kobo Clara HD

Andreas Kemnade (2):
backlight: lm3630a: add an enable gpio for the HWEN pin
dt-bindings: backlight: lm3630a: add enable_gpios

.../leds/backlight/lm3630a-backlight.yaml | 4 ++++
drivers/video/backlight/lm3630a_bl.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)

--
2.20.1


2019-09-09 18:14:04

by Andreas Kemnade

[permalink] [raw]
Subject: [PATCH 2/2] dt-bindings: backlight: lm3630a: add enable_gpios

add enable-gpios to describe HWEN pin

Signed-off-by: Andreas Kemnade <[email protected]>
---
.../devicetree/bindings/leds/backlight/lm3630a-backlight.yaml | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml b/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
index dc129d9a329e..a9656d72b668 100644
--- a/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
+++ b/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
@@ -29,6 +29,10 @@ properties:
'#size-cells':
const: 0

+ enable-gpios:
+ description: GPIO to use to enable/disable the backlight (HWEN pin).
+ maxItems: 1
+
required:
- compatible
- reg
--
2.20.1

2019-09-09 18:14:04

by Andreas Kemnade

[permalink] [raw]
Subject: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

For now just enable it in the probe function to allow i2c
access and disable it on remove. Disabling also means resetting
the register values to default.

Tested on Kobo Clara HD.

Signed-off-by: Andreas Kemnade <[email protected]>
---
drivers/video/backlight/lm3630a_bl.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
index b04b35d007a2..3b45a1733198 100644
--- a/drivers/video/backlight/lm3630a_bl.c
+++ b/drivers/video/backlight/lm3630a_bl.c
@@ -12,6 +12,8 @@
#include <linux/uaccess.h>
#include <linux/interrupt.h>
#include <linux/regmap.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio.h>
#include <linux/pwm.h>
#include <linux/platform_data/lm3630a_bl.h>

@@ -48,6 +50,7 @@ struct lm3630a_chip {
struct lm3630a_platform_data *pdata;
struct backlight_device *bleda;
struct backlight_device *bledb;
+ struct gpio_desc *enable_gpio;
struct regmap *regmap;
struct pwm_device *pwmd;
};
@@ -506,6 +509,14 @@ static int lm3630a_probe(struct i2c_client *client,
return -ENOMEM;
pchip->dev = &client->dev;

+ pchip->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
+ GPIOD_ASIS);
+ if (IS_ERR(pchip->enable_gpio)) {
+ rval = PTR_ERR(pchip->enable_gpio);
+ return rval;
+ }
+
+
pchip->regmap = devm_regmap_init_i2c(client, &lm3630a_regmap);
if (IS_ERR(pchip->regmap)) {
rval = PTR_ERR(pchip->regmap);
@@ -535,6 +546,10 @@ static int lm3630a_probe(struct i2c_client *client,
}
pchip->pdata = pdata;

+ if (pchip->enable_gpio) {
+ gpiod_set_value_cansleep(pchip->enable_gpio, 1);
+ usleep_range(1000, 2000);
+ }
/* chip initialize */
rval = lm3630a_chip_init(pchip);
if (rval < 0) {
@@ -586,6 +601,9 @@ static int lm3630a_remove(struct i2c_client *client)
if (rval < 0)
dev_err(pchip->dev, "i2c failed to access register\n");

+ if (pchip->enable_gpio)
+ gpiod_set_value_cansleep(pchip->enable_gpio, 0);
+
if (pchip->irq) {
free_irq(pchip->irq, pchip);
flush_workqueue(pchip->irqthread);
--
2.20.1

2019-09-09 22:57:31

by Daniel Thompson

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

On Sun, Sep 08, 2019 at 10:37:03PM +0200, Andreas Kemnade wrote:
> For now just enable it in the probe function to allow i2c
> access and disable it on remove. Disabling also means resetting
> the register values to default.
>
> Tested on Kobo Clara HD.
>
> Signed-off-by: Andreas Kemnade <[email protected]>
> ---
> drivers/video/backlight/lm3630a_bl.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
> index b04b35d007a2..3b45a1733198 100644
> --- a/drivers/video/backlight/lm3630a_bl.c
> +++ b/drivers/video/backlight/lm3630a_bl.c
> @@ -12,6 +12,8 @@
> #include <linux/uaccess.h>
> #include <linux/interrupt.h>
> #include <linux/regmap.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/gpio.h>
> #include <linux/pwm.h>
> #include <linux/platform_data/lm3630a_bl.h>
>
> @@ -48,6 +50,7 @@ struct lm3630a_chip {
> struct lm3630a_platform_data *pdata;
> struct backlight_device *bleda;
> struct backlight_device *bledb;
> + struct gpio_desc *enable_gpio;
> struct regmap *regmap;
> struct pwm_device *pwmd;
> };
> @@ -506,6 +509,14 @@ static int lm3630a_probe(struct i2c_client *client,
> return -ENOMEM;
> pchip->dev = &client->dev;
>
> + pchip->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
> + GPIOD_ASIS);

Initializing GPIOD_ASIS doesn't look right to me.

If you initialize ASIS then the driver must configure the pin as an
output... far easier just to set GPIOD_OUT_HIGH during the get.

Note also that the call to this function should also be moved *below*
the calls parse the DT.


> + if (IS_ERR(pchip->enable_gpio)) {
> + rval = PTR_ERR(pchip->enable_gpio);
> + return rval;
> + }
> +
> +
> pchip->regmap = devm_regmap_init_i2c(client, &lm3630a_regmap);
> if (IS_ERR(pchip->regmap)) {
> rval = PTR_ERR(pchip->regmap);
> @@ -535,6 +546,10 @@ static int lm3630a_probe(struct i2c_client *client,
> }
> pchip->pdata = pdata;
>
> + if (pchip->enable_gpio) {
> + gpiod_set_value_cansleep(pchip->enable_gpio, 1);

Not needed, use GPIOD_OUT_HIGH instead.


> + usleep_range(1000, 2000);

Not needed, this sleep is already part of lm3630a_chip_init().


> + }
> /* chip initialize */
> rval = lm3630a_chip_init(pchip);
> if (rval < 0) {
> @@ -586,6 +601,9 @@ static int lm3630a_remove(struct i2c_client *client)
> if (rval < 0)
> dev_err(pchip->dev, "i2c failed to access register\n");
>
> + if (pchip->enable_gpio)
> + gpiod_set_value_cansleep(pchip->enable_gpio, 0);
> +

Is this needed?

This is a remove path, not a power management path, and we have no idea
what the original status of the pin was anyway?


> if (pchip->irq) {
> free_irq(pchip->irq, pchip);
> flush_workqueue(pchip->irqthread);
> --
> 2.20.1
>

2019-09-09 22:57:59

by Daniel Thompson

[permalink] [raw]
Subject: Re: [PATCH 2/2] dt-bindings: backlight: lm3630a: add enable_gpios

On Sun, Sep 08, 2019 at 10:37:04PM +0200, Andreas Kemnade wrote:
> add enable-gpios to describe HWEN pin
>
> Signed-off-by: Andreas Kemnade <[email protected]>

Looks like patches are in the wrong order. Changes to bindings must
appear in patchsets *before* the Linux implementation of the bindings.


> ---
> .../devicetree/bindings/leds/backlight/lm3630a-backlight.yaml | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml b/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
> index dc129d9a329e..a9656d72b668 100644
> --- a/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
> +++ b/Documentation/devicetree/bindings/leds/backlight/lm3630a-backlight.yaml
> @@ -29,6 +29,10 @@ properties:
> '#size-cells':
> const: 0
>
> + enable-gpios:
> + description: GPIO to use to enable/disable the backlight (HWEN pin).
> + maxItems: 1
> +
> required:
> - compatible
> - reg

Please add enable-gpios to one of the examples.


Daniel.

2019-09-10 12:31:20

by Daniel Thompson

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

On Mon, Sep 09, 2019 at 10:13:49PM +0200, Andreas Kemnade wrote:
> On Mon, 9 Sep 2019 11:57:29 +0100
> Daniel Thompson <[email protected]> wrote:
>
> > On Sun, Sep 08, 2019 at 10:37:03PM +0200, Andreas Kemnade wrote:
> > > For now just enable it in the probe function to allow i2c
> > > access and disable it on remove. Disabling also means resetting
> > > the register values to default.
> > >
> > > Tested on Kobo Clara HD.
> > >
> > > Signed-off-by: Andreas Kemnade <[email protected]>
> > > ---
> > > drivers/video/backlight/lm3630a_bl.c | 18 ++++++++++++++++++
> > > 1 file changed, 18 insertions(+)
> > >
> > > diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
> > > index b04b35d007a2..3b45a1733198 100644
> > > --- a/drivers/video/backlight/lm3630a_bl.c
> > > +++ b/drivers/video/backlight/lm3630a_bl.c
> > > @@ -12,6 +12,8 @@
> > > #include <linux/uaccess.h>
> > > #include <linux/interrupt.h>
> > > #include <linux/regmap.h>
> > > +#include <linux/gpio/consumer.h>
> > > +#include <linux/gpio.h>
> > > #include <linux/pwm.h>
> > > #include <linux/platform_data/lm3630a_bl.h>
> > >
> > > @@ -48,6 +50,7 @@ struct lm3630a_chip {
> > > struct lm3630a_platform_data *pdata;
> > > struct backlight_device *bleda;
> > > struct backlight_device *bledb;
> > > + struct gpio_desc *enable_gpio;
> > > struct regmap *regmap;
> > > struct pwm_device *pwmd;
> > > };
> > > @@ -506,6 +509,14 @@ static int lm3630a_probe(struct i2c_client *client,
> > > return -ENOMEM;
> > > pchip->dev = &client->dev;
> > >
> > > + pchip->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
> > > + GPIOD_ASIS);
> >
> > Initializing GPIOD_ASIS doesn't look right to me.
> >
> > If you initialize ASIS then the driver must configure the pin as an
> > output... far easier just to set GPIOD_OUT_HIGH during the get.
> >
> > Note also that the call to this function should also be moved *below*
> > the calls parse the DT.
> >
> oops, must have forgotten that, and had good luck here.
> >
> > > + if (IS_ERR(pchip->enable_gpio)) {
> > > + rval = PTR_ERR(pchip->enable_gpio);
> > > + return rval;
> > > + }
> > > +
> > > +
> > > pchip->regmap = devm_regmap_init_i2c(client, &lm3630a_regmap);
> > > if (IS_ERR(pchip->regmap)) {
> > > rval = PTR_ERR(pchip->regmap);
> > > @@ -535,6 +546,10 @@ static int lm3630a_probe(struct i2c_client *client,
> > > }
> > > pchip->pdata = pdata;
> > >
> > > + if (pchip->enable_gpio) {
> > > + gpiod_set_value_cansleep(pchip->enable_gpio, 1);
> >
> > Not needed, use GPIOD_OUT_HIGH instead.
> >
> >
> > > + usleep_range(1000, 2000);
> >
> > Not needed, this sleep is already part of lm3630a_chip_init().
> >
> you are right.
> >
> > > + }
> > > /* chip initialize */
> > > rval = lm3630a_chip_init(pchip);
> > > if (rval < 0) {
> > > @@ -586,6 +601,9 @@ static int lm3630a_remove(struct i2c_client *client)
> > > if (rval < 0)
> > > dev_err(pchip->dev, "i2c failed to access register\n");
> > >
> > > + if (pchip->enable_gpio)
> > > + gpiod_set_value_cansleep(pchip->enable_gpio, 0);
> > > +
> >
> > Is this needed?
> >
> > This is a remove path, not a power management path, and we have no idea
> > what the original status of the pin was anyway?
> >
>
> Looking at Ishdn on page 5 of the datasheet, switching it off everytime
> possible seems not needed. We would need to call chip_init() everytime
> we enable the gpio or live with default values.
> Therefore I did decide to not put it into any power management path.
> But switching it on and not switching it off feels so unbalanced.

Either the power consumed by the controller when strings aren't lit up
matters, in which case the driver should implement proper power
management or it doesn't matter and changing the pin state isn't needed.

I'm happy with either of the above but this looks like a third way,
where eager users could hack in a bit of extra power management by
forcing drivers to unbind.


Daniel.

2019-09-10 18:41:17

by Andreas Kemnade

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

On Mon, 9 Sep 2019 11:57:29 +0100
Daniel Thompson <[email protected]> wrote:

> On Sun, Sep 08, 2019 at 10:37:03PM +0200, Andreas Kemnade wrote:
> > For now just enable it in the probe function to allow i2c
> > access and disable it on remove. Disabling also means resetting
> > the register values to default.
> >
> > Tested on Kobo Clara HD.
> >
> > Signed-off-by: Andreas Kemnade <[email protected]>
> > ---
> > drivers/video/backlight/lm3630a_bl.c | 18 ++++++++++++++++++
> > 1 file changed, 18 insertions(+)
> >
> > diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
> > index b04b35d007a2..3b45a1733198 100644
> > --- a/drivers/video/backlight/lm3630a_bl.c
> > +++ b/drivers/video/backlight/lm3630a_bl.c
> > @@ -12,6 +12,8 @@
> > #include <linux/uaccess.h>
> > #include <linux/interrupt.h>
> > #include <linux/regmap.h>
> > +#include <linux/gpio/consumer.h>
> > +#include <linux/gpio.h>
> > #include <linux/pwm.h>
> > #include <linux/platform_data/lm3630a_bl.h>
> >
> > @@ -48,6 +50,7 @@ struct lm3630a_chip {
> > struct lm3630a_platform_data *pdata;
> > struct backlight_device *bleda;
> > struct backlight_device *bledb;
> > + struct gpio_desc *enable_gpio;
> > struct regmap *regmap;
> > struct pwm_device *pwmd;
> > };
> > @@ -506,6 +509,14 @@ static int lm3630a_probe(struct i2c_client *client,
> > return -ENOMEM;
> > pchip->dev = &client->dev;
> >
> > + pchip->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
> > + GPIOD_ASIS);
>
> Initializing GPIOD_ASIS doesn't look right to me.
>
> If you initialize ASIS then the driver must configure the pin as an
> output... far easier just to set GPIOD_OUT_HIGH during the get.
>
> Note also that the call to this function should also be moved *below*
> the calls parse the DT.
>
oops, must have forgotten that, and had good luck here.
>
> > + if (IS_ERR(pchip->enable_gpio)) {
> > + rval = PTR_ERR(pchip->enable_gpio);
> > + return rval;
> > + }
> > +
> > +
> > pchip->regmap = devm_regmap_init_i2c(client, &lm3630a_regmap);
> > if (IS_ERR(pchip->regmap)) {
> > rval = PTR_ERR(pchip->regmap);
> > @@ -535,6 +546,10 @@ static int lm3630a_probe(struct i2c_client *client,
> > }
> > pchip->pdata = pdata;
> >
> > + if (pchip->enable_gpio) {
> > + gpiod_set_value_cansleep(pchip->enable_gpio, 1);
>
> Not needed, use GPIOD_OUT_HIGH instead.
>
>
> > + usleep_range(1000, 2000);
>
> Not needed, this sleep is already part of lm3630a_chip_init().
>
you are right.
>
> > + }
> > /* chip initialize */
> > rval = lm3630a_chip_init(pchip);
> > if (rval < 0) {
> > @@ -586,6 +601,9 @@ static int lm3630a_remove(struct i2c_client *client)
> > if (rval < 0)
> > dev_err(pchip->dev, "i2c failed to access register\n");
> >
> > + if (pchip->enable_gpio)
> > + gpiod_set_value_cansleep(pchip->enable_gpio, 0);
> > +
>
> Is this needed?
>
> This is a remove path, not a power management path, and we have no idea
> what the original status of the pin was anyway?
>

Looking at Ishdn on page 5 of the datasheet, switching it off everytime
possible seems not needed. We would need to call chip_init() everytime
we enable the gpio or live with default values.
Therefore I did decide to not put it into any power management path. But
switching it on and not switching it off feels so unbalanced.

Regards,
Andreas

2019-09-10 19:37:51

by Andreas Kemnade

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

On Tue, 10 Sep 2019 11:21:56 +0100
Daniel Thompson <[email protected]> wrote:

[...]
> > > Is this needed?
> > >
> > > This is a remove path, not a power management path, and we have no idea
> > > what the original status of the pin was anyway?
> > >
> >
> > Looking at Ishdn on page 5 of the datasheet, switching it off everytime
> > possible seems not needed. We would need to call chip_init() everytime
> > we enable the gpio or live with default values.
> > Therefore I did decide to not put it into any power management path.
> > But switching it on and not switching it off feels so unbalanced.
>
> Either the power consumed by the controller when strings aren't lit up
> matters, in which case the driver should implement proper power
> management or it doesn't matter and changing the pin state isn't needed.
>
> I'm happy with either of the above but this looks like a third way,
> where eager users could hack in a bit of extra power management by
> forcing drivers to unbind.
>
I think I will take the simple way. I am quite sure that the power
consumption with HWEN on and leds off does not matter. If someone
later comes up and finds out that I misread the datasheet, things
are prepared to be improved.
At least the hardware can be properly described in the devicetree.

Regards,
Andreas


Attachments:
(No filename) (849.00 B)
OpenPGP digital signature

2019-09-15 16:58:39

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

Hi!

> > > > Is this needed?
> > > >
> > > > This is a remove path, not a power management path, and we have no idea
> > > > what the original status of the pin was anyway?
> > > >
> > >
> > > Looking at Ishdn on page 5 of the datasheet, switching it off everytime
> > > possible seems not needed. We would need to call chip_init() everytime
> > > we enable the gpio or live with default values.
> > > Therefore I did decide to not put it into any power management path.
> > > But switching it on and not switching it off feels so unbalanced.
> >
> > Either the power consumed by the controller when strings aren't lit up
> > matters, in which case the driver should implement proper power
> > management or it doesn't matter and changing the pin state isn't needed.
> >
> > I'm happy with either of the above but this looks like a third way,
> > where eager users could hack in a bit of extra power management by
> > forcing drivers to unbind.
> >
> I think I will take the simple way. I am quite sure that the power
> consumption with HWEN on and leds off does not matter. If someone
> later comes up and finds out that I misread the datasheet, things
> are prepared to be improved.

Dunno.. if the power consumption does not matter, why does the chip have the enable
pin in the first place, and why do we bother supporting it? We could hardcode the
pin to enabled as well..
Pavel


--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2019-09-15 19:41:14

by Andreas Kemnade

[permalink] [raw]
Subject: Re: [PATCH 1/2] backlight: lm3630a: add an enable gpio for the HWEN pin

Hi,

On Sun, 15 Sep 2019 18:52:04 +0200
Pavel Machek <[email protected]> wrote:

> Hi!
>
> > > > > Is this needed?
> > > > >
> > > > > This is a remove path, not a power management path, and we have no idea
> > > > > what the original status of the pin was anyway?
> > > > >
> > > >
> > > > Looking at Ishdn on page 5 of the datasheet, switching it off everytime
> > > > possible seems not needed. We would need to call chip_init() everytime
> > > > we enable the gpio or live with default values.
> > > > Therefore I did decide to not put it into any power management path.
> > > > But switching it on and not switching it off feels so unbalanced.
> > >
> > > Either the power consumed by the controller when strings aren't lit up
> > > matters, in which case the driver should implement proper power
> > > management or it doesn't matter and changing the pin state isn't needed.
> > >
> > > I'm happy with either of the above but this looks like a third way,
> > > where eager users could hack in a bit of extra power management by
> > > forcing drivers to unbind.
> > >
> > I think I will take the simple way. I am quite sure that the power
> > consumption with HWEN on and leds off does not matter. If someone
> > later comes up and finds out that I misread the datasheet, things
> > are prepared to be improved.
>
> Dunno.. if the power consumption does not matter, why does the chip have the enable
> pin in the first place, and why do we bother supporting it? We could hardcode the
> pin to enabled as well..

Well, I agree having the pin and no power saving seems not to make
sense. Two points here: I think it is a good idea to properly describe
the hardware in the devicetree. What to do with that information is
another thing.
A problem is that at the moment I cannot easily measure consumption
of the chip. Hmm, even testing a solution which disables the pin while
the chip is not in use, is not so easy.
But wait...
I could use a wrong gpio but one that I can easily monitor to check if
the pin is toggled. And set the real pin to high by some other means.
And then use the real gpio to check if timings are correct (waiting
enough after enabling the chip, e.g.

Regards,
Andreas