Input: Make ADS7846 independent on regulator
Subsystems (2)
PATCH 1/1 Input: Make ADS7846 independent on regulator
In case regulator was not found, ADS7846 failed to probe.
This fixes a problem on some Sharp Zaurus devices, where there is no regulator present and yet the touchscreen is used.
--- drivers/input/touchscreen/ads7846.c | 50 +++++++++++++++++++++++------------ 1 files changed, 33 insertions(+), 17 deletions(-)
drivers/input/touchscreen/ads7846.c +33 -17
@@ -791,7 +791,10 @@ static void ads7846_disable(struct ads7846 *ts) } } -regulator_disable (ts->reg); +#ifdef CONFIG_REGULATOR +if (ts->reg) +regulator_disable (ts->reg); +#endif /* we know the chip's in lowpower mode since we always * leave it that way after every request
@@ -804,7 +807,10 @@ static void ads7846_enable(struct ads7846 *ts)if (!ts->disabled)return ; -regulator_enable (ts->reg); +#ifdef CONFIG_REGULATOR +if (ts->reg) +regulator_enable (ts->reg); +#endif ts->disabled =0 ; ts->irq_disabled =0 ;
@@ -1161,18 +1167,21 @@ static int __devinit ads7846_probe(struct spi_device *spi) ts->last_msg = m; +#ifdef CONFIG_REGULATOR ts->reg =regulator_get (&spi->dev,"vcc" ); -if (IS_ERR (ts->reg)) { - err =PTR_ERR (ts->reg); -dev_err (&spi->dev,"unable to get regulator: %d\n" , err); - goto err_free_gpio; - } - - err =regulator_enable (ts->reg); -if (err) { -dev_err (&spi->dev,"unable to enable regulator: %d\n" , err); - goto err_put_regulator; +if (IS_ERR (ts->reg)) + ts->reg =NULL ; +else { + err =regulator_enable (ts->reg); +if (err) { +dev_err (&spi->dev,"unable to enable regulator: %d\n" , + err); + goto err_put_regulator; + } } +#else + ts->reg =NULL ; +#endif if (request_irq (spi->irq, ads7846_irq,IRQF_TRIGGER_FALLING , spi->dev.driver->name, ts)) {
@@ -1218,10 +1227,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) err_free_irq:free_irq (spi->irq, ts); err_disable_regulator: -regulator_disable (ts->reg); +#ifdef CONFIG_REGULATOR +if (ts->reg) +regulator_disable (ts->reg); err_put_regulator: -regulator_put (ts->reg); - err_free_gpio: +if (ts->reg) +regulator_put (ts->reg); +#endif if (ts->gpio_pendown !=-1 )gpio_free (ts->gpio_pendown); err_cleanup_filter:
@@ -1251,8 +1263,12 @@ static int __devexit ads7846_remove(struct spi_device *spi)/* suspend left the IRQ disabled */ enable_irq (ts->spi->irq); -regulator_disable (ts->reg); -regulator_put (ts->reg); +#ifdef CONFIG_REGULATOR +if (ts->reg) { +regulator_disable (ts->reg); +regulator_put (ts->reg); + } +#endif if (ts->gpio_pendown !=-1 )gpio_free (ts->gpio_pendown);
Signature · 1 line
1.7.1
Dmitry Torokhov
maintainerHi Marek,
Quoted 5 lines · Marek Vasut
In case regulator was not found, ADS7846 failed to probe.
This fixes a problem on some Sharp Zaurus devices, where there is no regulator present and yet the touchscreen is used.
Too many ifdefs to my taste... Can we have ads7846_regulator_enable() and friends stubbed out in case !CONFIG_REGULATOR?
Signature · 1 line
Dmitry
Dne So 31. ?ervence 2010 08:33:29 Dmitry Torokhov napsal(a):
Quoted 10 lines
Hi Marek,
Quoted 4 lines · Marek Vasut
In case regulator was not found, ADS7846 failed to probe.
This fixes a problem on some Sharp Zaurus devices, where there is no regulator present and yet the touchscreen is used.
Too many ifdefs to my taste... Can we have
ads7846_regulator_enable()and friends stubbed out in case !CONFIG_REGULATOR?
Hi,
I believe you should ask the regulator guys about these. We can certainly just remove the ifdefs (I was thinking about it, because it poluted the code quality quite a bit). Just removing the ifdefs shouldn't cause any harm.
Cheers
2010/7/31 Marek Vasut <[email protected]>:
Quoted 13 lines
This fixes a problem on some Sharp Zaurus devices, where there is no regulator present and yet the touchscreen is used.
Signed-off-by Marek Vasut <[email protected]>---
?drivers/input/touchscreen/ads7846.c | ? 50 +++++++++++++++++++++++------------ ?1 files changed, 33 insertions(+), 17 deletions(-)drivers/input/touchscreen/ads7846.c +0
-0
drivers/input/touchscreen/ads7846.c static void ads7846_disable(struct ads7846 *ts) · line 794
Quoted 5 lines
drivers/input/touchscreen/ads7846.c +1
-1@@ -791,7 +791,10 @@ static void ads7846_disable(struct ads7846 *ts) ? ? ? ? ? ? ? ?} ? ? ? ?} - ? ? ? regulator_disable(ts->reg); +#ifdef CONFIG_REGULATOR
Skip the #ifdef, if the regulators are configured out, there will be a stub providing NULL for all get_regulator() calls anyway.
drivers/input/touchscreen/ads7846.c static void ads7846_enable(struct ads7846 *ts) · line 810
Quoted 12 lines
drivers/input/touchscreen/ads7846.c +3
-0+ ? ? ? if (ts->reg) + ? ? ? ? ? ? ? regulator_disable(ts->reg); +#endif ? ? ? ?/* we know the chip's in lowpower mode since we always ? ? ? ? * leave it that way after every request
drivers/input/touchscreen/ads7846.c +1
-1@@ -804,7 +807,10 @@ static void ads7846_enable(struct ads7846 *ts) ? ? ? ?if (!ts->disabled) ? ? ? ? ? ? ? ?return; - ? ? ? regulator_enable(ts->reg); +#ifdef CONFIG_REGULATOR
Skip the #ifdef.
drivers/input/touchscreen/ads7846.c static int __devinit ads7846_probe(struct spi_device *spi) · line 1170
Quoted 11 lines
drivers/input/touchscreen/ads7846.c +4
-0+ ? ? ? if (ts->reg) + ? ? ? ? ? ? ? regulator_enable(ts->reg); +#endif ? ? ? ?ts->disabled = 0; ? ? ? ?ts->irq_disabled = 0;@@ -1161,18 +1167,21 @@ static int __devinit ads7846_probe(struct spi_device *spi) ? ? ? ?ts->last_msg = m; +#ifdef CONFIG_REGULATOR
Skip the #ifdef.
Quoted 14 lines
drivers/input/touchscreen/ads7846.c +3
-10? ? ? ?ts->reg = regulator_get(&spi->dev, "vcc"); - ? ? ? if (IS_ERR(ts->reg)) { - ? ? ? ? ? ? ? err = PTR_ERR(ts->reg); - ? ? ? ? ? ? ? dev_err(&spi->dev, "unable to get regulator: %d\n", err); - ? ? ? ? ? ? ? goto err_free_gpio; - ? ? ? } - - ? ? ? err = regulator_enable(ts->reg); - ? ? ? if (err) { - ? ? ? ? ? ? ? dev_err(&spi->dev, "unable to enable regulator: %d\n", err); - ? ? ? ? ? ? ? goto err_put_regulator; + ? ? ? if (IS_ERR(ts->reg)) + ? ? ? ? ? ? ? ts->reg = NULL; + ? ? ? else {
drivers/input/touchscreen/ads7846.c static int __devinit ads7846_probe(struct spi_device *spi) · line 1184
Quoted 10 lines
drivers/input/touchscreen/ads7846.c +9
-0+ ? ? ? ? ? ? ? err = regulator_enable(ts->reg); + ? ? ? ? ? ? ? if (err) { + ? ? ? ? ? ? ? ? ? ? ? dev_err(&spi->dev, "unable to enable regulator: %d\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? err); + ? ? ? ? ? ? ? ? ? ? ? goto err_put_regulator; + ? ? ? ? ? ? ? } ? ? ? ?} +#else + ? ? ? ts->reg = NULL; +#endif
Delete the #else/#endif clause entirely.
Quoted 9 lines
drivers/input/touchscreen/ads7846.c +0
-0? ? ? ?if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING, ? ? ? ? ? ? ? ? ? ? ? ?spi->dev.driver->name, ts)) {@@ -1218,10 +1227,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)?err_free_irq:
? ? ? ?free_irq(spi->irq, ts);
?err_disable_regulator:
- ? ? ?regulator_disable(ts->reg);
+#ifdefCONFIG_REGULATOR
Skip the #ifdef.
Quoted 15 lines
+ ? ? ? if (
ts->reg)
+ ? ? ? ? ? ? ?regulator_disable(ts->reg);
?err_put_regulator:
- ? ? ?regulator_put(ts->reg);
-err_free_gpio:
+ ? ? ? if (ts->reg)
+ ? ? ? ? ? ? ?regulator_put(ts->reg);
+#endif
? ? ? ?if (ts->gpio_pendown!= -1)
? ? ? ? ? ? ? ?gpio_free(ts->gpio_pendown);
?err_cleanup_filter:drivers/input/touchscreen/ads7846.c +0
-0@@ -1251,8 +1263,12 @@ static int __devexit ads7846_remove(struct spi_device *spi)? ? ? ?/* suspend left the IRQ disabled */
? ? ? ?enable_irq(ts->spi->irq);
Quoted 3 lines
- ? ? ?
regulator_disable(ts->reg);
- ? ? ?regulator_put(ts->reg);
+#ifdefCONFIG_REGULATOR
Skip the #ifdef.
Quoted 10 lines
+ ? ? ? if (
ts->reg) {
+ ? ? ? ? ? ? ?regulator_disable(ts->reg);
+ ? ? ? ? ? ? ?regulator_put(ts->reg);
+ ? ? ? }
+#endif? ? ? ?if (
ts->gpio_pendown!= -1)
? ? ? ? ? ? ? ?gpio_free(ts->gpio_pendown);
--
1.7.1
Yours,
Linus Walleij
Quoted 6 lines · Linus Walleij
2010/7/31 Marek Vasut <[email protected]>:
Quoted 1 line
+#ifdef
CONFIG_REGULATORSkip the #ifdef, if the regulators are configured out, there will be a stub providing NULL for all
get_regulator()calls anyway.
While ifdefs on CONFIG_REGULATOR should indeed be skipped I'd not expect the stubs to be returning NULL for anything (but then as discussed elsewhere this whole approach of doing everything in the drivers is a poor one).