linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO
@ 2014-03-01  5:00 Alexandre Courbot
  2014-03-01  5:00 ` [PATCH 2/2] drm/panel: remove redundant regulator_disable() Alexandre Courbot
  2014-03-14 11:01 ` [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Thierry Reding
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Courbot @ 2014-03-01  5:00 UTC (permalink / raw)
  To: David Airlie, Thierry Reding
  Cc: dri-devel, linux-kernel, gnurou, Alexandre Courbot

Use the new GPIO descriptor interface to handle the panel's enable GPIO.
This considerably simplifies the code.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/drm/panel/panel-simple.c | 69 ++++++++++--------------------------
 1 file changed, 18 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 94cbf06..d1cabfa 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -22,9 +22,8 @@
  */
 
 #include <linux/backlight.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
-#include <linux/of_gpio.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
@@ -44,9 +43,6 @@ struct panel_desc {
 	} size;
 };
 
-/* TODO: convert to gpiod_*() API once it's been merged */
-#define GPIO_ACTIVE_LOW	(1 << 0)
-
 struct panel_simple {
 	struct drm_panel base;
 	bool enabled;
@@ -57,8 +53,7 @@ struct panel_simple {
 	struct regulator *supply;
 	struct i2c_adapter *ddc;
 
-	unsigned long enable_gpio_flags;
-	int enable_gpio;
+	struct gpio_desc *enable_gpio;
 };
 
 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
@@ -110,12 +105,8 @@ static int panel_simple_disable(struct drm_panel *panel)
 		backlight_update_status(p->backlight);
 	}
 
-	if (gpio_is_valid(p->enable_gpio)) {
-		if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
-			gpio_set_value(p->enable_gpio, 1);
-		else
-			gpio_set_value(p->enable_gpio, 0);
-	}
+	if (p->enable_gpio)
+		gpiod_set_value(p->enable_gpio, 0);
 
 	regulator_disable(p->supply);
 	p->enabled = false;
@@ -137,12 +128,8 @@ static int panel_simple_enable(struct drm_panel *panel)
 		return err;
 	}
 
-	if (gpio_is_valid(p->enable_gpio)) {
-		if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
-			gpio_set_value(p->enable_gpio, 0);
-		else
-			gpio_set_value(p->enable_gpio, 1);
-	}
+	if (p->enable_gpio)
+		gpiod_set_value(p->enable_gpio, 1);
 
 	if (p->backlight) {
 		p->backlight->props.power = FB_BLANK_UNBLANK;
@@ -185,7 +172,6 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 {
 	struct device_node *backlight, *ddc;
 	struct panel_simple *panel;
-	enum of_gpio_flags flags;
 	int err;
 
 	panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
@@ -199,30 +185,19 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 	if (IS_ERR(panel->supply))
 		return PTR_ERR(panel->supply);
 
-	panel->enable_gpio = of_get_named_gpio_flags(dev->of_node,
-						     "enable-gpios", 0,
-						     &flags);
-	if (gpio_is_valid(panel->enable_gpio)) {
-		unsigned int value;
-
-		if (flags & OF_GPIO_ACTIVE_LOW)
-			panel->enable_gpio_flags |= GPIO_ACTIVE_LOW;
-
-		err = gpio_request(panel->enable_gpio, "enable");
+	panel->enable_gpio = devm_gpiod_get(dev, "enable");
+	if (!IS_ERR(panel->enable_gpio)) {
+		err = gpiod_direction_output(panel->enable_gpio, 0);
 		if (err < 0) {
-			dev_err(dev, "failed to request GPIO#%u: %d\n",
-				panel->enable_gpio, err);
+			dev_err(dev, "failed to setup enable GPIO: %d\n", err);
 			return err;
 		}
-
-		value = (panel->enable_gpio_flags & GPIO_ACTIVE_LOW) != 0;
-
-		err = gpio_direction_output(panel->enable_gpio, value);
-		if (err < 0) {
-			dev_err(dev, "failed to setup GPIO%u: %d\n",
-				panel->enable_gpio, err);
-			goto free_gpio;
-		}
+	} else if (PTR_ERR(panel->enable_gpio) == -ENOENT) {
+		panel->enable_gpio = NULL;
+	} else {
+		err = PTR_ERR(panel->enable_gpio);
+		dev_err(dev, "failed to request enable GPIO: %d\n", err);
+		return err;
 	}
 
 	backlight = of_parse_phandle(dev->of_node, "backlight", 0);
@@ -230,10 +205,8 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 		panel->backlight = of_find_backlight_by_node(backlight);
 		of_node_put(backlight);
 
-		if (!panel->backlight) {
-			err = -EPROBE_DEFER;
-			goto free_gpio;
-		}
+		if (!panel->backlight)
+			return -EPROBE_DEFER;
 	}
 
 	ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
@@ -265,9 +238,6 @@ free_ddc:
 free_backlight:
 	if (panel->backlight)
 		put_device(&panel->backlight->dev);
-free_gpio:
-	if (gpio_is_valid(panel->enable_gpio))
-		gpio_free(panel->enable_gpio);
 
 	return err;
 }
@@ -287,9 +257,6 @@ static int panel_simple_remove(struct device *dev)
 	if (panel->backlight)
 		put_device(&panel->backlight->dev);
 
-	if (gpio_is_valid(panel->enable_gpio))
-		gpio_free(panel->enable_gpio);
-
 	regulator_disable(panel->supply);
 
 	return 0;
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/panel: remove redundant regulator_disable()
  2014-03-01  5:00 [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Alexandre Courbot
@ 2014-03-01  5:00 ` Alexandre Courbot
  2014-03-14 11:01 ` [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Thierry Reding
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2014-03-01  5:00 UTC (permalink / raw)
  To: David Airlie, Thierry Reding
  Cc: dri-devel, linux-kernel, gnurou, Alexandre Courbot

regulator_disable() is already performed by panel_simple_disable(),
which is called by panel_simple_remove().

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/drm/panel/panel-simple.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index d1cabfa..35d1518 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -257,8 +257,6 @@ static int panel_simple_remove(struct device *dev)
 	if (panel->backlight)
 		put_device(&panel->backlight->dev);
 
-	regulator_disable(panel->supply);
-
 	return 0;
 }
 
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO
  2014-03-01  5:00 [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Alexandre Courbot
  2014-03-01  5:00 ` [PATCH 2/2] drm/panel: remove redundant regulator_disable() Alexandre Courbot
@ 2014-03-14 11:01 ` Thierry Reding
  1 sibling, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2014-03-14 11:01 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: David Airlie, Thierry Reding, gnurou, linux-kernel, dri-devel

[-- Attachment #1: Type: text/plain, Size: 523 bytes --]

On Sat, Mar 01, 2014 at 02:00:58PM +0900, Alexandre Courbot wrote:
> Use the new GPIO descriptor interface to handle the panel's enable GPIO.
> This considerably simplifies the code.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/gpu/drm/panel/panel-simple.c | 69 ++++++++++--------------------------
>  1 file changed, 18 insertions(+), 51 deletions(-)

Both patches applied, with a slightly modified version of how this patch
handles the optional enable GPIO.

Thanks,
Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-14 11:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-01  5:00 [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Alexandre Courbot
2014-03-01  5:00 ` [PATCH 2/2] drm/panel: remove redundant regulator_disable() Alexandre Courbot
2014-03-14 11:01 ` [PATCH 1/2] drm/panel: use gpiod interface for enable GPIO Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).