From edf387b6d1a6993103ec95ed934a6daf559535f4 Mon Sep 17 00:00:00 2001 From: Vladimir Zapolskiy Date: Sat, 11 Oct 2014 16:46:26 +0300 Subject: backlight: pwm: Clean-up pwm requested using legacy API If PWM device is requested by means of legacy API pwm_request(), its resources are not freed on module unbind, which may cause an oops on access, e.g. by reading /sys/kernel/debug/pwm. Reported-by: Dmitry Eremin-Solenikov Signed-off-by: Vladimir Zapolskiy Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index cb5ae4c08469..3a145a643e0d 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -34,6 +34,7 @@ struct pwm_bl_data { struct regulator *power_supply; struct gpio_desc *enable_gpio; unsigned int scale; + bool legacy; int (*notify)(struct device *, int brightness); void (*notify_after)(struct device *, @@ -274,7 +275,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->pwm = devm_pwm_get(&pdev->dev, NULL); if (IS_ERR(pb->pwm)) { dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); - + pb->legacy = true; pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); if (IS_ERR(pb->pwm)) { dev_err(&pdev->dev, "unable to request legacy PWM\n"); @@ -339,6 +340,8 @@ static int pwm_backlight_remove(struct platform_device *pdev) if (pb->exit) pb->exit(&pdev->dev); + if (pb->legacy) + pwm_free(pb->pwm); return 0; } -- cgit v1.2.3-59-g8ed1b From 47726656dd67a2487bd7fafec1a73472da1db956 Mon Sep 17 00:00:00 2001 From: Sean Paul Date: Tue, 2 Dec 2014 17:39:11 -0800 Subject: backlight: lp855x: Refactor DT parsing code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch refactors the dt parsing code to avoid setting platform_data, instead just setting lp->pdata directly. This facilitates easier probe deferral since the current scheme would require us to clear out dev->platform_data before deferring. Cc: Stéphane Marchesin Signed-off-by: Sean Paul Acked-by: Milo Kim Acked-by: Bryan Wu Signed-off-by: Lee Jones --- drivers/video/backlight/lp855x_bl.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 25fb8e3d75b1..257b3badd8e4 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -341,8 +341,10 @@ static const struct attribute_group lp855x_attr_group = { }; #ifdef CONFIG_OF -static int lp855x_parse_dt(struct device *dev, struct device_node *node) +static int lp855x_parse_dt(struct lp855x *lp) { + struct device *dev = lp->dev; + struct device_node *node = dev->of_node; struct lp855x_platform_data *pdata; int rom_length; @@ -381,12 +383,12 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node) pdata->rom_data = &rom[0]; } - dev->platform_data = pdata; + lp->pdata = pdata; return 0; } #else -static int lp855x_parse_dt(struct device *dev, struct device_node *node) +static int lp855x_parse_dt(struct lp855x *lp) { return -EINVAL; } @@ -395,18 +397,8 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node) static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) { struct lp855x *lp; - struct lp855x_platform_data *pdata = dev_get_platdata(&cl->dev); - struct device_node *node = cl->dev.of_node; int ret; - if (!pdata) { - ret = lp855x_parse_dt(&cl->dev, node); - if (ret < 0) - return ret; - - pdata = dev_get_platdata(&cl->dev); - } - if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; @@ -414,16 +406,23 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) if (!lp) return -ENOMEM; - if (pdata->period_ns > 0) - lp->mode = PWM_BASED; - else - lp->mode = REGISTER_BASED; - lp->client = cl; lp->dev = &cl->dev; - lp->pdata = pdata; lp->chipname = id->name; lp->chip_id = id->driver_data; + lp->pdata = dev_get_platdata(&cl->dev); + + if (!lp->pdata) { + ret = lp855x_parse_dt(lp); + if (ret < 0) + return ret; + } + + if (lp->pdata->period_ns > 0) + lp->mode = PWM_BASED; + else + lp->mode = REGISTER_BASED; + i2c_set_clientdata(cl, lp); ret = lp855x_configure(lp); -- cgit v1.2.3-59-g8ed1b From 829b030e58f8349a63909c0fff2fa1913d79314c Mon Sep 17 00:00:00 2001 From: Sean Paul Date: Tue, 2 Dec 2014 17:39:12 -0800 Subject: backlight: lp855x: Add supply regulator to lp855x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a supply regulator to the lp855x platform data to facilitate powering on/off the 3V rail attached to the controller. Cc: Stéphane Marchesin Cc: Aaron Durbin Signed-off-by: Sean Paul Acked-by: Milo Kim Acked-by: Bryan Wu Acked-by: Jingoo Han Signed-off-by: Lee Jones --- .../devicetree/bindings/video/backlight/lp855x.txt | 2 ++ drivers/video/backlight/lp855x_bl.c | 18 ++++++++++++++++++ include/linux/platform_data/lp855x.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/Documentation/devicetree/bindings/video/backlight/lp855x.txt b/Documentation/devicetree/bindings/video/backlight/lp855x.txt index 96e83a56048e..0a3ecbc3a1b9 100644 --- a/Documentation/devicetree/bindings/video/backlight/lp855x.txt +++ b/Documentation/devicetree/bindings/video/backlight/lp855x.txt @@ -12,6 +12,7 @@ Optional properties: - pwm-period: PWM period value. Set only PWM input mode used (u32) - rom-addr: Register address of ROM area to be updated (u8) - rom-val: Register value to be updated (u8) + - power-supply: Regulator which controls the 3V rail Example: @@ -56,6 +57,7 @@ Example: backlight@2c { compatible = "ti,lp8557"; reg = <0x2c>; + power-supply = <&backlight_vdd>; dev-ctrl = /bits/ 8 <0x41>; init-brt = /bits/ 8 <0x0a>; diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 257b3badd8e4..a26d3bb25650 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -17,6 +17,7 @@ #include #include #include +#include /* LP8550/1/2/3/6 Registers */ #define LP855X_BRIGHTNESS_CTRL 0x00 @@ -383,6 +384,13 @@ 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; @@ -423,6 +431,14 @@ 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); + if (ret < 0) { + dev_err(&cl->dev, "failed to enable supply: %d\n", ret); + return ret; + } + } + i2c_set_clientdata(cl, lp); ret = lp855x_configure(lp); @@ -454,6 +470,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); sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); return 0; diff --git a/include/linux/platform_data/lp855x.h b/include/linux/platform_data/lp855x.h index 1b2ba24e4e03..9c7fd1efe495 100644 --- a/include/linux/platform_data/lp855x.h +++ b/include/linux/platform_data/lp855x.h @@ -136,6 +136,7 @@ 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; @@ -144,6 +145,7 @@ struct lp855x_platform_data { unsigned int period_ns; int size_program; struct lp855x_rom_data *rom_data; + struct regulator *supply; }; #endif -- cgit v1.2.3-59-g8ed1b From 3d6969a641d01cc9b6aa199a6f01eb1802522baf Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 3 Dec 2014 11:14:00 -0800 Subject: MAINTAINERS: Remove my name from Backlight subsystem Signed-off-by: Bryan Wu Signed-off-by: Lee Jones --- MAINTAINERS | 1 - 1 file changed, 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 3c6427190be2..fc6c57b7a3ae 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1861,7 +1861,6 @@ F: drivers/net/wireless/b43legacy/ BACKLIGHT CLASS/SUBSYSTEM M: Jingoo Han -M: Bryan Wu M: Lee Jones S: Maintained F: drivers/video/backlight/ -- cgit v1.2.3-59-g8ed1b