diff mbox series

[06/60] drm/bridge: simple-bridge: Add support for enable GPIO

Message ID 20190707181937.6250-3-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series drm/omap: Replace custom display drivers with drm_bridge and drm_panel | expand

Commit Message

Laurent Pinchart July 7, 2019, 6:18 p.m. UTC
If an enable GPIO is declared in the firmware, assert it when enabling
the bridge and deassert it when disabling it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/bridge/simple-bridge.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Andrzej Hajda July 9, 2019, 2:32 p.m. UTC | #1
On 07.07.2019 20:18, Laurent Pinchart wrote:
> If an enable GPIO is declared in the firmware, assert it when enabling
> the bridge and deassert it when disabling it.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


Hmm, simple becomes less simple. I guess we will end-up with sth similar
to panel-simple. And then we can merge both :)


Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

 --
Regards
Andrzej


> ---
>  drivers/gpu/drm/bridge/simple-bridge.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/simple-bridge.c b/drivers/gpu/drm/bridge/simple-bridge.c
> index bff240cf283d..a7edf3c39627 100644
> --- a/drivers/gpu/drm/bridge/simple-bridge.c
> +++ b/drivers/gpu/drm/bridge/simple-bridge.c
> @@ -6,6 +6,7 @@
>   * Maxime Ripard <maxime.ripard@free-electrons.com>
>   */
>  
> +#include <linux/gpio/consumer.h>
>  #include <linux/module.h>
>  #include <linux/of_device.h>
>  #include <linux/of_graph.h>
> @@ -29,6 +30,7 @@ struct simple_bridge {
>  
>  	struct i2c_adapter	*ddc;
>  	struct regulator	*vdd;
> +	struct gpio_desc	*enable;
>  };
>  
>  static inline struct simple_bridge *
> @@ -135,19 +137,23 @@ static int simple_bridge_attach(struct drm_bridge *bridge)
>  static void simple_bridge_enable(struct drm_bridge *bridge)
>  {
>  	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
> -	int ret = 0;
> +	int ret;
>  
> -	if (sbridge->vdd)
> +	if (sbridge->vdd) {
>  		ret = regulator_enable(sbridge->vdd);
> +		if (ret)
> +			DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
> +	}
>  
> -	if (ret)
> -		DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
> +	gpiod_set_value_cansleep(sbridge->enable, 1);
>  }
>  
>  static void simple_bridge_disable(struct drm_bridge *bridge)
>  {
>  	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
>  
> +	gpiod_set_value_cansleep(sbridge->enable, 0);
> +
>  	if (sbridge->vdd)
>  		regulator_disable(sbridge->vdd);
>  }
> @@ -200,6 +206,14 @@ static int simple_bridge_probe(struct platform_device *pdev)
>  		dev_dbg(&pdev->dev, "No vdd regulator found: %d\n", ret);
>  	}
>  
> +	sbridge->enable = devm_gpiod_get_optional(&pdev->dev, "enable",
> +						  GPIOD_OUT_LOW);
> +	if (IS_ERR(sbridge->enable)) {
> +		if (PTR_ERR(sbridge->enable) != -EPROBE_DEFER)
> +			dev_err(&pdev->dev, "Unable to retrieve enable GPIO\n");
> +		return PTR_ERR(sbridge->enable);
> +	}
> +
>  	sbridge->ddc = simple_bridge_retrieve_ddc(&pdev->dev);
>  	if (IS_ERR(sbridge->ddc)) {
>  		if (PTR_ERR(sbridge->ddc) == -ENODEV) {
Stefan Agner July 26, 2019, 1:19 p.m. UTC | #2
On 2019-07-07 20:18, Laurent Pinchart wrote:
> If an enable GPIO is declared in the firmware, assert it when enabling
> the bridge and deassert it when disabling it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

This also comes in handy for the ADV7123, which has a power save pin.

Looks good to me.

Reviewed-by: Stefan Agner <stefan@agner.ch>

--
Stefan

> ---
>  drivers/gpu/drm/bridge/simple-bridge.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/simple-bridge.c
> b/drivers/gpu/drm/bridge/simple-bridge.c
> index bff240cf283d..a7edf3c39627 100644
> --- a/drivers/gpu/drm/bridge/simple-bridge.c
> +++ b/drivers/gpu/drm/bridge/simple-bridge.c
> @@ -6,6 +6,7 @@
>   * Maxime Ripard <maxime.ripard@free-electrons.com>
>   */
>  
> +#include <linux/gpio/consumer.h>
>  #include <linux/module.h>
>  #include <linux/of_device.h>
>  #include <linux/of_graph.h>
> @@ -29,6 +30,7 @@ struct simple_bridge {
>  
>  	struct i2c_adapter	*ddc;
>  	struct regulator	*vdd;
> +	struct gpio_desc	*enable;
>  };
>  
>  static inline struct simple_bridge *
> @@ -135,19 +137,23 @@ static int simple_bridge_attach(struct drm_bridge *bridge)
>  static void simple_bridge_enable(struct drm_bridge *bridge)
>  {
>  	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
> -	int ret = 0;
> +	int ret;
>  
> -	if (sbridge->vdd)
> +	if (sbridge->vdd) {
>  		ret = regulator_enable(sbridge->vdd);
> +		if (ret)
> +			DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
> +	}
>  
> -	if (ret)
> -		DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
> +	gpiod_set_value_cansleep(sbridge->enable, 1);
>  }
>  
>  static void simple_bridge_disable(struct drm_bridge *bridge)
>  {
>  	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
>  
> +	gpiod_set_value_cansleep(sbridge->enable, 0);
> +
>  	if (sbridge->vdd)
>  		regulator_disable(sbridge->vdd);
>  }
> @@ -200,6 +206,14 @@ static int simple_bridge_probe(struct
> platform_device *pdev)
>  		dev_dbg(&pdev->dev, "No vdd regulator found: %d\n", ret);
>  	}
>  
> +	sbridge->enable = devm_gpiod_get_optional(&pdev->dev, "enable",
> +						  GPIOD_OUT_LOW);
> +	if (IS_ERR(sbridge->enable)) {
> +		if (PTR_ERR(sbridge->enable) != -EPROBE_DEFER)
> +			dev_err(&pdev->dev, "Unable to retrieve enable GPIO\n");
> +		return PTR_ERR(sbridge->enable);
> +	}
> +
>  	sbridge->ddc = simple_bridge_retrieve_ddc(&pdev->dev);
>  	if (IS_ERR(sbridge->ddc)) {
>  		if (PTR_ERR(sbridge->ddc) == -ENODEV) {
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/simple-bridge.c b/drivers/gpu/drm/bridge/simple-bridge.c
index bff240cf283d..a7edf3c39627 100644
--- a/drivers/gpu/drm/bridge/simple-bridge.c
+++ b/drivers/gpu/drm/bridge/simple-bridge.c
@@ -6,6 +6,7 @@ 
  * Maxime Ripard <maxime.ripard@free-electrons.com>
  */
 
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/of_graph.h>
@@ -29,6 +30,7 @@  struct simple_bridge {
 
 	struct i2c_adapter	*ddc;
 	struct regulator	*vdd;
+	struct gpio_desc	*enable;
 };
 
 static inline struct simple_bridge *
@@ -135,19 +137,23 @@  static int simple_bridge_attach(struct drm_bridge *bridge)
 static void simple_bridge_enable(struct drm_bridge *bridge)
 {
 	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
-	int ret = 0;
+	int ret;
 
-	if (sbridge->vdd)
+	if (sbridge->vdd) {
 		ret = regulator_enable(sbridge->vdd);
+		if (ret)
+			DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
+	}
 
-	if (ret)
-		DRM_ERROR("Failed to enable vdd regulator: %d\n", ret);
+	gpiod_set_value_cansleep(sbridge->enable, 1);
 }
 
 static void simple_bridge_disable(struct drm_bridge *bridge)
 {
 	struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge);
 
+	gpiod_set_value_cansleep(sbridge->enable, 0);
+
 	if (sbridge->vdd)
 		regulator_disable(sbridge->vdd);
 }
@@ -200,6 +206,14 @@  static int simple_bridge_probe(struct platform_device *pdev)
 		dev_dbg(&pdev->dev, "No vdd regulator found: %d\n", ret);
 	}
 
+	sbridge->enable = devm_gpiod_get_optional(&pdev->dev, "enable",
+						  GPIOD_OUT_LOW);
+	if (IS_ERR(sbridge->enable)) {
+		if (PTR_ERR(sbridge->enable) != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Unable to retrieve enable GPIO\n");
+		return PTR_ERR(sbridge->enable);
+	}
+
 	sbridge->ddc = simple_bridge_retrieve_ddc(&pdev->dev);
 	if (IS_ERR(sbridge->ddc)) {
 		if (PTR_ERR(sbridge->ddc) == -ENODEV) {