Skip to contentSkip to conversation

backlight: lp855x: use private data for regulator control

PATCH Superseded Milo Kim 3 participants 7 messages Jul 10, 2015 – Jul 12, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Milo Kim

author
#0 lore raw

PATCH v2 1/1 backlight: lp855x: use private data for regulator control

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
 drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
 include/linux/platform_data/lp855x.h |  2 --
 2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +9 -11
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
 	struct device *dev;
 	struct lp855x_platform_data *pdata;
 	struct pwm_device *pwm;
+	struct regulator *supply;	/* regulator for VDD input */
 };
 
 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
 		pdata->rom_data = &rom[0];
 	}
 
-	pdata->supply = devm_regulator_get(dev, "power");
-	if (IS_ERR(pdata->supply)) {
-		if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		pdata->supply = NULL;
-	}
-
 	lp->pdata = pdata;
 
 	return 0;
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
 	else
 		lp->mode = REGISTER_BASED;
 
-	if (lp->pdata->supply) {
-		ret = regulator_enable(lp->pdata->supply);
+	lp->supply = devm_regulator_get(lp->dev, "power");
+	if (IS_ERR(lp->supply))
+		lp->supply = NULL;
+
+	if (lp->supply) {
+		ret = regulator_enable(lp->supply);
 		if (ret < 0) {
 			dev_err(&cl->dev, "failed to enable supply: %d\n", ret);
 			return ret;
@@ -470,8 +468,8 @@ static int lp855x_remove(struct i2c_client *cl)
 
 	lp->bl->props.brightness = 0;
 	backlight_update_status(lp->bl);
-	if (lp->pdata->supply)
-		regulator_disable(lp->pdata->supply);
+	if (lp->supply)
+		regulator_disable(lp->supply);
 	sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group);
 
 	return 0;
include/linux/platform_data/lp855x.h +0 -2
index 9c7fd1e..1b2ba24 100644
@@ -136,7 +136,6 @@ struct lp855x_rom_data {
 		Only valid when mode is PWM_BASED.
  * @size_program : total size of lp855x_rom_data
  * @rom_data : list of new eeprom/eprom registers
- * @supply : regulator that supplies 3V input
  */
 struct lp855x_platform_data {
 	const char *name;
@@ -145,7 +144,6 @@ struct lp855x_platform_data {
 	unsigned int period_ns;
 	int size_program;
 	struct lp855x_rom_data *rom_data;
-	struct regulator *supply;
 };
 
 #endif
Signature · 1 line
1.9.1
#1 lore raw
Quoted 53 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
 drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
 include/linux/platform_data/lp855x.h |  2 --
 2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +1 -7
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
        struct device *dev;
        struct lp855x_platform_data *pdata;
        struct pwm_device *pwm;
+       struct regulator *supply;       /* regulator for VDD input */
 };
 
 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
                pdata->rom_data = &rom[0];
        }
 
-       pdata->supply = devm_regulator_get(dev, "power");
-       if (IS_ERR(pdata->supply)) {
-               if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               pdata->supply = NULL;
-       }
-
        lp->pdata = pdata;
 
        return 0;

drivers/video/backlight/lp855x_bl.c static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) · line 430

Quoted 8 lines
drivers/video/backlight/lp855x_bl.c +3 -2
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
        else
                lp->mode = REGISTER_BASED;
 
-       if (lp->pdata->supply) {
-               ret = regulator_enable(lp->pdata->supply);
+       lp->supply = devm_regulator_get(lp->dev, "power");
+       if (IS_ERR(lp->supply))
+               lp->supply = NULL;

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

Please re-introduce the error handling you removed from parse_dt.

Sean

Quoted 40 lines
drivers/video/backlight/lp855x_bl.c +5 -2
+
+       if (lp->supply) {
+               ret = regulator_enable(lp->supply);
                if (ret < 0) {
                        dev_err(&cl->dev, "failed to enable supply: %d\n", ret);
                        return ret;
@@ -470,8 +468,8 @@ static int lp855x_remove(struct i2c_client *cl)
 
        lp->bl->props.brightness = 0;
        backlight_update_status(lp->bl);
-       if (lp->pdata->supply)
-               regulator_disable(lp->pdata->supply);
+       if (lp->supply)
+               regulator_disable(lp->supply);
        sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group);
 
        return 0;
include/linux/platform_data/lp855x.h +0 -3
index 9c7fd1e..1b2ba24 100644
@@ -136,7 +136,6 @@ struct lp855x_rom_data {
                Only valid when mode is PWM_BASED.
  * @size_program : total size of lp855x_rom_data
  * @rom_data : list of new eeprom/eprom registers
- * @supply : regulator that supplies 3V input
  */
 struct lp855x_platform_data {
        const char *name;
@@ -145,7 +144,6 @@ struct lp855x_platform_data {
        unsigned int period_ns;
        int size_program;
        struct lp855x_rom_data *rom_data;
-       struct regulator *supply;
 };
 
 #endif
--

1.9.1

author
#2 lore raw

Hi Paul,

Quoted 57 lines · Sean Paul
Quoted 56 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
  drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
  include/linux/platform_data/lp855x.h |  2 --
  2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +1 -7
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
         struct device *dev;
         struct lp855x_platform_data *pdata;
         struct pwm_device *pwm;
+       struct regulator *supply;       /* regulator for VDD input */
  };
 
  static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
                 pdata->rom_data = &rom[0];
         }
 
-       pdata->supply = devm_regulator_get(dev, "power");
-       if (IS_ERR(pdata->supply)) {
-               if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               pdata->supply = NULL;
-       }
-
         lp->pdata = pdata;
 
         return 0;
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
         else
                 lp->mode = REGISTER_BASED;
 
Quoted 10 lines

drivers/video/backlight/lp855x_bl.c static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) · line 430

Quoted 5 lines
drivers/video/backlight/lp855x_bl.c +3 -2
-       if (lp->pdata->supply) {
-               ret = regulator_enable(lp->pdata->supply);
+       lp->supply = devm_regulator_get(lp->dev, "power");
+       if (IS_ERR(lp->supply))
+               lp->supply = NULL;

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

This power supply is optional. Even if lp855x can not get regulator driver, it should work. (And I saw same comment in the DT. The 'power-supply' property is optional). So -EPORBE_DEFER is not necessary in _probe().

Best regards,
Milo

#3 lore raw
Quoted 80 lines · Milo

Hi Paul,

Quoted 63 lines · Sean Paul
Quoted 61 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also
from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code
is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
  drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
  include/linux/platform_data/lp855x.h |  2 --
  2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +1 -7
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
         struct device *dev;
         struct lp855x_platform_data *pdata;
         struct pwm_device *pwm;
+       struct regulator *supply;       /* regulator for VDD input */
  };
 
  static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
                 pdata->rom_data = &rom[0];
         }
 
-       pdata->supply = devm_regulator_get(dev, "power");
-       if (IS_ERR(pdata->supply)) {
-               if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               pdata->supply = NULL;
-       }
-
         lp->pdata = pdata;
 
         return 0;
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const
 struct i2c_device_id *id)
         else
                 lp->mode = REGISTER_BASED;
 
Quoted 11 lines

drivers/video/backlight/lp855x_bl.c static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) · line 430

Quoted 5 lines
drivers/video/backlight/lp855x_bl.c +3 -2
-       if (lp->pdata->supply) {
-               ret = regulator_enable(lp->pdata->supply);
+       lp->supply = devm_regulator_get(lp->dev, "power");
+       if (IS_ERR(lp->supply))
+               lp->supply = NULL;

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

Quoted 4 lines

This power supply is optional. Even if lp855x can not get regulator driver, it should work. (And I saw same comment in the DT. The 'power-supply' property is optional). So -EPORBE_DEFER is not necessary in _probe().

I respectfully disagree. devm_regulator_get can return EPROBE_DEFER if the regulator is valid (and specified in the dt), but not ready to be used yet. In this case, your patch will assume it doesn't exist and will never use it. This Is Bad.

Sean

Quoted 2 lines

Best regards,
Milo

author
#4 lore raw

Hi Paul,

Quoted 86 lines · Sean Paul
Quoted 80 lines · Milo

Hi Paul,

Quoted 63 lines · Sean Paul
Quoted 61 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also
from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code
is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
   drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
   include/linux/platform_data/lp855x.h |  2 --
   2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +1 -7
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
          struct device *dev;
          struct lp855x_platform_data *pdata;
          struct pwm_device *pwm;
+       struct regulator *supply;       /* regulator for VDD input */
   };
 
   static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
                  pdata->rom_data = &rom[0];
          }
 
-       pdata->supply = devm_regulator_get(dev, "power");
-       if (IS_ERR(pdata->supply)) {
-               if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               pdata->supply = NULL;
-       }
-
          lp->pdata = pdata;
 
          return 0;
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const
 struct i2c_device_id *id)
          else
                  lp->mode = REGISTER_BASED;
 
Quoted 11 lines

drivers/video/backlight/lp855x_bl.c static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) · line 430

Quoted 5 lines
drivers/video/backlight/lp855x_bl.c +3 -2
-       if (lp->pdata->supply) {
-               ret = regulator_enable(lp->pdata->supply);
+       lp->supply = devm_regulator_get(lp->dev, "power");
+       if (IS_ERR(lp->supply))
+               lp->supply = NULL;

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

Quoted 4 lines

This power supply is optional. Even if lp855x can not get regulator driver, it should work. (And I saw same comment in the DT. The 'power-supply' property is optional). So -EPORBE_DEFER is not necessary in _probe().

Quoted 4 lines

I respectfully disagree. devm_regulator_get can return EPROBE_DEFER if the regulator is valid (and specified in the dt), but not ready to be used yet. In this case, your patch will assume it doesn't exist and will never use it. This Is Bad.

So do you think this power supply should be mandatory in this driver?

Best regards,
Milo

author
#5 lore raw

Hi Paul,

Quoted 89 lines · Milo

Hi Paul,

Quoted 86 lines · Sean Paul
Quoted 84 lines · Milo

Hi Paul,

Quoted 63 lines · Sean Paul
Quoted 61 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also
from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code
is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
    drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
    include/linux/platform_data/lp855x.h |  2 --
    2 files changed, 9 insertions(+), 13 deletions(-)
drivers/video/backlight/lp855x_bl.c +1 -7
index a26d3bb..277d5ca 100644
@@ -73,6 +73,7 @@ struct lp855x {
           struct device *dev;
           struct lp855x_platform_data *pdata;
           struct pwm_device *pwm;
+       struct regulator *supply;       /* regulator for VDD input */
    };
 
    static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)
@@ -384,13 +385,6 @@ static int lp855x_parse_dt(struct lp855x *lp)
                   pdata->rom_data = &rom[0];
           }
 
-       pdata->supply = devm_regulator_get(dev, "power");
-       if (IS_ERR(pdata->supply)) {
-               if (PTR_ERR(pdata->supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               pdata->supply = NULL;
-       }
-
           lp->pdata = pdata;
 
           return 0;
@@ -431,8 +425,12 @@ static int lp855x_probe(struct i2c_client *cl, const
 struct i2c_device_id *id)
           else
                   lp->mode = REGISTER_BASED;
 
Quoted 11 lines

drivers/video/backlight/lp855x_bl.c static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) · line 430

Quoted 5 lines
drivers/video/backlight/lp855x_bl.c +3 -2
-       if (lp->pdata->supply) {
-               ret = regulator_enable(lp->pdata->supply);
+       lp->supply = devm_regulator_get(lp->dev, "power");
+       if (IS_ERR(lp->supply))
+               lp->supply = NULL;

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

This power supply is optional. Even if lp855x can not get regulator driver, it should work. (And I saw same comment in the DT. The 'power-supply' property is optional). So -EPORBE_DEFER is not necessary in _probe().

Quoted 6 lines
Quoted 4 lines

I respectfully disagree. devm_regulator_get can return EPROBE_DEFER if the regulator is valid (and specified in the dt), but not ready to be used yet. In this case, your patch will assume it doesn't exist and will never use it. This Is Bad.

So do you think this power supply should be mandatory in this driver?

The devm_regulator_get_optinonal() seems the right API for this case. Let me take a look at and get back to you.

Best regards,
Milo

maintainer
#6 lore raw
Quoted 40 lines · Milo
Quoted 39 lines · Milo

Hi Paul,

Quoted 36 lines · Sean Paul
Quoted 35 lines · Milo

Hi Paul,

Quoted 31 lines · Sean Paul
Quoted 29 lines · Milo Kim

LP855x backlight device can be enabled by external VDD input. The 'supply' data is used for this purpose.
It's kind of private data which runs internally, so there is no reason to expose to the platform data.

And devm_regulator_get() is moved from _parse_dt() to _probe(). Regulator consumer(lp855x) can control regulator not only from DT but also
from platform data configuration in a source file such like board-*.c.

If 'power' regulator driver is not ready, lp855x should continue to work because the power supply control is optional. So -EPROBE_DEFER return code
is removed.

v1->v2:
Keeps optional property '<name>-supply' in LP855x DT binding.

---
    drivers/video/backlight/lp855x_bl.c  | 20 +++++++++-----------
    include/linux/platform_data/lp855x.h |  2 --
    2 files changed, 9 insertions(+), 13 deletions(-)

[.....]

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines
Quoted 5 lines

Hi Milo,
You removed the probe deferral handling on the regulator and broke probe deferral in cases where the regulator isn't ready.

This power supply is optional. Even if lp855x can not get regulator driver, it should work. (And I saw same comment in the DT. The 'power-supply' property is optional). So -EPORBE_DEFER is not necessary in _probe().

I respectfully disagree. devm_regulator_get can return EPROBE_DEFER if the regulator is valid (and specified in the dt), but not ready to be used yet. In this case, your patch will assume it doesn't exist and will never use it. This Is Bad.

Quoted 4 lines
Quoted 1 line

So do you think this power supply should be mandatory in this driver?

The devm_regulator_get_optinonal() seems the right API for this case. Let me take a look at and get back to you.

The devm_regulator_get_optinonal() looks better. But, I am not sure. Please review devm_regulator_get_optinonal() carefully, before sending the V3 patch.

Best regards,
Jingoo Han

Quoted 3 lines

Best regards,
Milo