backlight/ld9040.c: regulator control in the lcd driver
This patch supports regulator power control in the driver.
Current ld9040 driver was controlled power on/off sequence by callback function
in the board file. But, by doing this, there's no need to register lcd power
on/off callback function in the board file.
---
drivers/video/backlight/ld9040.c | 88
++++++++++++++++++++++++++++++++-----
1 files changed, 76 insertions(+), 12 deletions(-)
(quoted diff) +0 -0
b/drivers/video/backlight/ld9040.c
index da9a5ce..9698f48 100644
--- a/drivers/video/backlight/ld9040.c
+++ b/drivers/video/backlight/ld9040.c
@@ -31,6 +31,7 @@
#include <linux/lcd.h>
#include <linux/backlight.h>
#include <linux/module.h>
+#include <linux/regulator/consumer.h>
#include "ld9040_gamma.h"
@@ -53,8 +54,60 @@ struct ld9040 {
struct lcd_device *ld;
struct backlight_device *bd;
struct lcd_platform_data *lcd_pd;+
+ struct mutex lock;
+ struct regulator *reg_vdd3;
+ struct regulator *reg_vci;
+ bool enabled;
};
+static void ld9040_regulator_enable(struct ld9040 *lcd)
+{
+ int ret = 0;
+ struct lcd_platform_data *pd = NULL;
+
+ pd = lcd->lcd_pd;
+ mutex_lock(&lcd->lock);
+ if (!lcd->enabled) {
+ if (lcd->reg_vdd3)
+ ret = regulator_enable(lcd->reg_vdd3);
+ if (ret)
+ goto out;
+
+ if (lcd->reg_vci)
+ ret = regulator_enable(lcd->reg_vci);
+ if (ret)
+ goto out;
+
+ lcd->enabled = true;
+ }
+ mdelay(pd->power_on_delay);
+out:
+ mutex_unlock(&lcd->lock);
+}
+
+static void ld9040_regulator_disable(struct ld9040 *lcd)
+{
+ int ret = 0;
+
+ mutex_lock(&lcd->lock);
+ if (lcd->enabled) {
+ if (lcd->reg_vci)
+ regulator_disable(lcd->reg_vci);
+ if (ret)
+ goto out;
+
+ if (lcd->reg_vdd3)
+ regulator_disable(lcd->reg_vdd3);
+ if (ret)
+ goto out;
+
+ lcd->enabled = false;
+ }
+out:
+ mutex_unlock(&lcd->lock);
+}
+
static const unsigned short seq_swreset[] = {
0x01, COMMAND_ONLY,
ENDDEF, 0x00@@ -532,13 +585,8 @@ static int ld9040_power_on(struct ld9040 *lcd)
return -EFAULT;
}- if (!pd->power_on) {
- dev_err(lcd->dev, "power_on is NULL.\n");
- return -EFAULT;
- } else {
- pd->power_on(lcd->ld, 1);
- mdelay(pd->power_on_delay);
- }
+ /* lcd power on */
+ ld9040_regulator_enable(lcd);
if (!pd->reset) {
dev_err(lcd->dev, "reset is NULL.\n");@@ -582,11 +630,8 @@ static int ld9040_power_off(struct ld9040 *lcd)
mdelay(pd->power_off_delay);
- if (!pd->power_on) {
- dev_err(lcd->dev, "power_on is NULL.\n");
- return -EFAULT;
- } else
- pd->power_on(lcd->ld, 0);
+ /* lcd power off */
+ ld9040_regulator_disable(lcd);
return 0;
}
@@ -693,6 +738,20 @@ static int ld9040_probe(struct spi_device *spi)
goto out_free_lcd;
}+ mutex_init(&lcd->lock);
+
+ lcd->reg_vdd3 = regulator_get(lcd->dev, "vdd");
+ if (IS_ERR(lcd->reg_vdd3)) {
+ dev_info(lcd->dev, "no %s regulator found\n", "vdd");
+ lcd->reg_vdd3 = NULL;
+ }
+
+ lcd->reg_vci = regulator_get(lcd->dev, "vci");
+ if (IS_ERR(lcd->reg_vci)) {
+ dev_info(lcd->dev, "no %s regulator found\n", "vci");
+ lcd->reg_vci = NULL;
+ }
+
ld = lcd_device_register("ld9040", &spi->dev, lcd,&ld9040_lcd_ops);
if (IS_ERR(ld)) {
ret = PTR_ERR(ld);@@ -739,6 +798,9 @@ static int ld9040_probe(struct spi_device *spi)
out_unregister_lcd:
lcd_device_unregister(lcd->ld);
out_free_lcd:
+ regulator_put(lcd->reg_vci);
+ regulator_put(lcd->reg_vdd3);
+
kfree(lcd);
return ret;}
@@ -750,6 +812,8 @@ static int __devexit ld9040_remove(struct spi_device *spi)
ld9040_power(lcd, FB_BLANK_POWERDOWN);
backlight_device_unregister(lcd->bd);
lcd_device_unregister(lcd->ld);+ regulator_put(lcd->reg_vci);
+ regulator_put(lcd->reg_vdd3);
kfree(lcd);
return 0;Signature · 12 lines
1.7.4.1 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111202/5e869ca5/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-backlight-ld9040.c-regulator-control-in-the-driver.patch Type: application/octet-stream Size: 4063 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111202/5e869ca5/attachment-0001.obj>
On Fri, Dec 2, 2011 at 8:45 AM, leedonghwa <[email protected]> wrote:
[From your mail headers]
Quoted 1 line
X-Mailer: Microsoft Office Outlook 12.0
No please. That mailer does not work, all your whitespace is screwed up.
Consult: Documentation/email-clients.txt
Quoted 1 line
This patch supports regulator power control in the driver.
Always CC the regulator maintainers on patches like this please.
Quoted 11 lines
+????????
lcd->reg_vdd3=regulator_get(lcd->dev, "vdd"); +???????? if (IS_ERR(lcd->reg_vdd3)) {
+??????????????????dev_info(lcd->dev, "no %s regulator found\n", "vdd"); +??????????????????lcd->reg_vdd3= NULL;
+???????? }
+
+????????lcd->reg_vci=regulator_get(lcd->dev, "vci"); +???????? if (IS_ERR(lcd->reg_vci)) {
+??????????????????dev_info(lcd->dev, "no %s regulator found\n", "vci"); +??????????????????lcd->reg_vci= NULL;
+???????? }
As explained in earlier discussion with Mark regarding the SMSC911x driver regulator, treat these as errors and do not fail "gracefully" like this.
Reference:
http://marc.info/?l=linux-netdev&m=131914562120725&w=2
Yours,
Linus Walleij
Quoted 24 lines · Linus Walleij
On Fri, Dec 2, 2011 at 8:45 AM, leedonghwa <[email protected]> wrote:
[From your mail headers]
Quoted 1 line
X-Mailer: Microsoft Office Outlook 12.0
No please. That mailer does not work, all your whitespace is screwed up.
Consult:Documentation/email-clients.txtQuoted 1 line
This patch supports regulator power control in the driver.
Always CC the regulator maintainers on patches like this please.
Review
Quoted 11 lines
(quoted diff) +11
-0+ lcd->reg_vdd3 = regulator_get(lcd->dev, "vdd"); + if (IS_ERR(lcd->reg_vdd3)) { + dev_info(lcd->dev, "no %s regulator found\n", "vdd"); + lcd->reg_vdd3 = NULL; + } + + lcd->reg_vci = regulator_get(lcd->dev, "vci"); + if (IS_ERR(lcd->reg_vci)) { + dev_info(lcd->dev, "no %s regulator found\n", "vci"); + lcd->reg_vci = NULL; + }
Quoted 6 lines
As explained in earlier discussion with Mark regarding the SMSC911x driver regulator, treat these as errors and do not fail "gracefully" like this.
Reference:
http://marc.info/?l=linux-netdev&m=131914562120725&w=2
As mentioned at commit message, the lcd regulator is optional part and refer the mmc codes
host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
if (IS_ERR(host->vmmc)) {
pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
host->vmmc = NULL;
} else {
regulator_enable(host->vmmc);
}Previous time, these codes are located at board file, but more boards are used, it has same codes for all boards. so move it to drivers.
In our case, it has the regulator but some boards don't.
Umm then how to handle the regulator gracefully?
Thank you,
Kyungmin Park
Quoted 9 lines
Yours,
Linus Walleij_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 32 lines · Kyungmin Park
Quoted 1 line
[leedonghwa]
[Me]
Quoted 12 lines
Quoted 11 lines
+ ? ? ? ?
lcd->reg_vdd3=regulator_get(lcd->dev, "vdd");
+ ? ? ? ? if (IS_ERR(lcd->reg_vdd3)) {
+ ? ? ? ? ? ? ? ? ?dev_info(lcd->dev, "no %s regulator found\n", "vdd");
+ ? ? ? ? ? ? ? ? ?lcd->reg_vdd3= NULL;
+ ? ? ? ? }
+
+ ? ? ? ?lcd->reg_vci=regulator_get(lcd->dev, "vci");
+ ? ? ? ? if (IS_ERR(lcd->reg_vci)) {
+ ? ? ? ? ? ? ? ? ?dev_info(lcd->dev, "no %s regulator found\n", "vci");
+ ? ? ? ? ? ? ? ? ?lcd->reg_vci= NULL;
+ ? ? ? ? }Quoted 6 lines
As explained in earlier discussion with Mark regarding the SMSC911x driver regulator, treat these as errors and do not fail "gracefully" like this.
Reference:
http://marc.info/?l=linux-netdev&m=131914562120725&w=2As mentioned at commit message, the lcd regulator is optional part and refer the mmc codes
? ? ? ?host->vmmc =
regulator_get(mmc_dev(mmc), "vmmc");
? ? ? ?if (IS_ERR(host->vmmc)) {
? ? ? ? ? ? ? ?pr_info("%s: no vmmc regulator found\n",mmc_hostname(mmc)); ? ? ? ? ? ? ? ?host->vmmc = NULL;
? ? ? ?} else {
? ? ? ? ? ? ? ?regulator_enable(host->vmmc);
? ? ? ?}
Quoted 2 lines
Previous time, these codes are located at board file, but more boards are used, it has same codes for all boards. so move it to drivers.
I know. This was brought up in the aforementioned discussion, but the above is also wrong, simply. See:
http://marc.info/?l=linux-netdev&m=131914562120667&w=2
http://marc.info/?l=linux-netdev&m=131914562120690&w=2
http://marc.info/?l=linux-netdev&m=131914562120725&w=2
http://marc.info/?l=linux-netdev&m=131963332527416&w=2
Quoted 3 lines
In our case, it has the regulator but some boards don't.
Umm then how to handle the regulator gracefully?
Mark suggest using a fixed-voltage regulator for boards where the power is always on. The voltage level itself is optional. See:
http://marc.info/?l=linux-netdev&m=131963332527416&w=2
Other approaches is to use dummy regulators, or not call regulator_has_full_constraints(), which means the regulator core will provide dummy regulators anyways. See:
http://marc.info/?l=linux-netdev&m=131973043527112&w=2
http://marc.info/?l=linux-netdev&m=131975178703166&w=2
Whole thread of discussion:
http://marc.info/?l=linux-netdev&w=2&r=1&s=smsc911x&q=b
Yours,
Linus Walleij
Quoted 47 lines · Linus Walleij
Quoted 35 lines · Kyungmin Park
Quoted 1 line
[leedonghwa]
[Me]
Quoted 14 lines
Review
Quoted 13 lines
(quoted diff) +3
-0+ lcd->reg_vdd3 = regulator_get(lcd->dev, "vdd"); + if (IS_ERR(lcd->reg_vdd3)) { + dev_info(lcd->dev, "no %s regulator found\n","vdd");
(quoted diff) +6
-0+ lcd->reg_vdd3 = NULL; + } + + lcd->reg_vci = regulator_get(lcd->dev, "vci"); + if (IS_ERR(lcd->reg_vci)) { + dev_info(lcd->dev, "no %s regulator found\n","vci");
(quoted diff) +2
-0+ lcd->reg_vci = NULL; + }Quoted 6 lines
As explained in earlier discussion with Mark regarding the SMSC911x driver regulator, treat these as errors and do not fail "gracefully" like this.
Reference:
http://marc.info/?l=linux-netdev&m=131914562120725&w=2As mentioned at commit message, the lcd regulator is optional part and refer the mmc codes
host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); if (IS_ERR(host->vmmc)) { pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); host->vmmc = NULL; } else { regulator_enable(host->vmmc); }Quoted 2 lines
Previous time, these codes are located at board file, but more boards are used, it has same codes for all boards. so move it to drivers.
I know. This was brought up in the aforementioned discussion, but the above is also wrong, simply. See:
http://marc.info/?l=linux-netdev&m=131914562120667&w=2
http://marc.info/?l=linux-netdev&m=131914562120690&w=2
http://marc.info/?l=linux-netdev&m=131914562120725&w=2
http://marc.info/?l=linux-netdev&m=131963332527416&w=2
Quoted 8 lines
Quoted 3 lines
In our case, it has the regulator but some boards don't.
Umm then how to handle the regulator gracefully?
Mark suggest using a fixed-voltage regulator for boards where the power is always on. The voltage level itself is optional. See:
http://marc.info/?l=linux-netdev&m=131963332527416&w=2
Make sense, okay send the updated patch
Quoted 19 lines
Other approaches is to use dummy regulators, or not call
regulator_has_full_constraints(), which means the regulator core will provide dummy regulators anyways. See:
http://marc.info/?l=linux-netdev&m=131973043527112&w=2
http://marc.info/?l=linux-netdev&m=131975178703166&w=2Whole thread of discussion:
http://marc.info/?l=linux-netdev&w=2&r=1&s=smsc911x&q=bYours,
Linus Walleij_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 11 lines · Kyungmin Park
As mentioned at commit message, the lcd regulator is optional part and refer the mmc codes
host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); if (IS_ERR(host->vmmc)) { pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); host->vmmc = NULL; } else { regulator_enable(host->vmmc); }
Quoted 2 lines
Previous time, these codes are located at board file, but more boards are used, it has same codes for all boards. so move it to drivers.
In the case of MMC the MMC guys told us that this supply was entirely optional for MMC operation, it wasn't an essential supply for the MMC device to run it just enabled more features. For supplies like that it's OK for the regulator to fail, the driver should just not do whatever things are enabled by having that supply.
Quoted 13 lines · Mark Brown
Quoted 10 lines · Kyungmin Park
As mentioned at commit message, the lcd regulator is optional part and refer the mmc codes
? ? ? ?
host->vmmc=regulator_get(mmc_dev(mmc), "vmmc");
? ? ? ? if (IS_ERR(host->vmmc)) {
? ? ? ? ? ? ? ?pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); ? ? ? ? ? ? ? ?host->vmmc= NULL;
? ? ? ? } else {
? ? ? ? ? ? ? ?regulator_enable(host->vmmc);
? ? ? ? }
Quoted 8 lines
Quoted 2 lines
Previous time, these codes are located at board file, but more boards are used, it has same codes for all boards. so move it to drivers.
In the case of MMC the MMC guys told us that this supply was entirely optional for MMC operation, it wasn't an essential supply for the MMC device to run it just enabled more features. ?For supplies like that it's OK for the regulator to fail, the driver should just not do whatever things are enabled by having that supply.
I don't think that's true. You *must* have some voltage on VMMC to power the card, the optional part is regulating that voltage to different levels as requested by the card internal machinery when talking to it. All MMC/SD cards can run on a fixed voltage, something like 3.8V I think.
In line with our previous discussions I think this should actually be defined as a fixed voltage regulator in case it cannot be controlled, because there sure as hell is a voltage there on all systems.
Yours,
Linus Walleij
Quoted 9 lines · Linus Walleij
I don't think that's true. You *must* have some voltage on VMMC to power the card, the optional part is regulating that voltage to different levels as requested by the card internal machinery when talking to it. All MMC/SD cards can run on a fixed voltage, something like 3.8V I think.
In line with our previous discussions I think this should actually be defined as a fixed voltage regulator in case it cannot be controlled, because there sure as hell is a voltage there on all systems.
I have to say that I was very suspicious of this claim at the time but there was so much pain associated with the MMC stuff that it just got left to slide. Similarly with the use of regulator_get_exclusive() to vary the voltage, I'd *really* expect that the code would be able to cope with shared supplies.