drm/tilcdc: Switch to using GPIO descriptors

Message ID 20191203130916.155779-1-linus.walleij@linaro.org
State New
Headers show
Series
  • drm/tilcdc: Switch to using GPIO descriptors
Related show

Commit Message

Linus Walleij Dec. 3, 2019, 1:09 p.m.
The TI LCDC picks a GPIO line from the device tree to use
for DPMS power on/off. We can switch this to use a GPIO
descriptor pretty easily. Make sure to request the GPIO
"as is" so that the DPMS state that we start (boot) in is
preserved.

Cc: Jyri Sarha <jsarha@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: David Lechner <david@lechnology.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpu/drm/tilcdc/tilcdc_tfp410.c | 30 ++++++++++++--------------
 1 file changed, 14 insertions(+), 16 deletions(-)

Comments

David Lechner Dec. 3, 2019, 3:50 p.m. | #1
On 12/3/19 7:09 AM, Linus Walleij wrote:
> The TI LCDC picks a GPIO line from the device tree to use
> for DPMS power on/off. We can switch this to use a GPIO
> descriptor pretty easily. Make sure to request the GPIO
> "as is" so that the DPMS state that we start (boot) in is
> preserved.
> 
> Cc: Jyri Sarha <jsarha@ti.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: David Lechner <david@lechnology.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---

Reviewed-by: David Lechner <david@lechnology.com>
Jyri Sarha Dec. 3, 2019, 6:29 p.m. | #2
On 03/12/2019 15:09, Linus Walleij wrote:
> The TI LCDC picks a GPIO line from the device tree to use
> for DPMS power on/off. We can switch this to use a GPIO
> descriptor pretty easily. Make sure to request the GPIO
> "as is" so that the DPMS state that we start (boot) in is
> preserved.
> 

Hmmm, I have been considering ditching this driver all together since no
mainline platform has ever used it. Also, if anybody ever wants to
connect tfp410 to tilcdc, he should use drm/bridge/ti-tfp410.c instead.

But since the patch is there, maybe I should pick it up, and remove the
bundled driver later a bit later.

BR,
Jyri

> Cc: Jyri Sarha <jsarha@ti.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: David Lechner <david@lechnology.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/gpu/drm/tilcdc/tilcdc_tfp410.c | 30 ++++++++++++--------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
> index 530edb3b51cc..41cd9a7c4316 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
> @@ -4,9 +4,8 @@
>   * Author: Rob Clark <robdclark@gmail.com>
>   */
>  
> -#include <linux/gpio.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/mod_devicetable.h>
> -#include <linux/of_gpio.h>
>  #include <linux/pinctrl/consumer.h>
>  #include <linux/platform_device.h>
>  
> @@ -21,7 +20,7 @@
>  struct tfp410_module {
>  	struct tilcdc_module base;
>  	struct i2c_adapter *i2c;
> -	int gpio;
> +	struct gpio_desc *power_gpiod;
>  };
>  #define to_tfp410_module(x) container_of(x, struct tfp410_module, base)
>  
> @@ -58,10 +57,10 @@ static void tfp410_encoder_dpms(struct drm_encoder *encoder, int mode)
>  
>  	if (mode == DRM_MODE_DPMS_ON) {
>  		DBG("Power on");
> -		gpio_direction_output(tfp410_encoder->mod->gpio, 1);
> +		gpiod_direction_output(tfp410_encoder->mod->power_gpiod, 1);
>  	} else {
>  		DBG("Power off");
> -		gpio_direction_output(tfp410_encoder->mod->gpio, 0);
> +		gpiod_direction_output(tfp410_encoder->mod->power_gpiod, 0);
>  	}
>  
>  	tfp410_encoder->dpms = mode;
> @@ -318,17 +317,17 @@ static int tfp410_probe(struct platform_device *pdev)
>  
>  	of_node_put(i2c_node);
>  
> -	tfp410_mod->gpio = of_get_named_gpio_flags(node, "powerdn-gpio",
> -			0, NULL);
> -	if (tfp410_mod->gpio < 0) {
> -		dev_warn(&pdev->dev, "No power down GPIO\n");
> -	} else {
> -		ret = gpio_request(tfp410_mod->gpio, "DVI_PDn");
> -		if (ret) {
> -			dev_err(&pdev->dev, "could not get DVI_PDn gpio\n");
> -			goto fail_adapter;
> -		}
> +	tfp410_mod->power_gpiod = devm_gpiod_get_optional(&pdev->dev,
> +							  "powerdn",
> +							  GPIOD_ASIS);
> +	if (IS_ERR(tfp410_mod->power_gpiod)) {
> +		dev_err(&pdev->dev, "could not get DVI_PDn gpio\n");
> +		goto fail_adapter;
>  	}
> +	if (!tfp410_mod->power_gpiod)
> +		dev_warn(&pdev->dev, "No power down GPIO\n");
> +	else
> +		gpiod_set_consumer_name(tfp410_mod->power_gpiod, "DVI_PDn");
>  
>  	return 0;
>  
> @@ -346,7 +345,6 @@ static int tfp410_remove(struct platform_device *pdev)
>  	struct tfp410_module *tfp410_mod = to_tfp410_module(mod);
>  
>  	i2c_put_adapter(tfp410_mod->i2c);
> -	gpio_free(tfp410_mod->gpio);
>  
>  	tilcdc_module_cleanup(mod);
>  
>
Sam Ravnborg Dec. 4, 2019, 2:30 p.m. | #3
Hi Jyri.

On Tue, Dec 03, 2019 at 08:29:45PM +0200, Jyri Sarha wrote:
> On 03/12/2019 15:09, Linus Walleij wrote:
> > The TI LCDC picks a GPIO line from the device tree to use
> > for DPMS power on/off. We can switch this to use a GPIO
> > descriptor pretty easily. Make sure to request the GPIO
> > "as is" so that the DPMS state that we start (boot) in is
> > preserved.
> > 
> 
> Hmmm, I have been considering ditching this driver all together since no
> mainline platform has ever used it. Also, if anybody ever wants to
> connect tfp410 to tilcdc, he should use drm/bridge/ti-tfp410.c instead.
> 
> But since the patch is there, maybe I should pick it up, and remove the
> bundled driver later a bit later.

IMO much better to just get rid of it now - as there is anyway no users.
No reason to patch code that is essential dead.
You just postpone the task for no gain.

	Sam

Patch

diff --git a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
index 530edb3b51cc..41cd9a7c4316 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
@@ -4,9 +4,8 @@ 
  * Author: Rob Clark <robdclark@gmail.com>
  */
 
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/mod_devicetable.h>
-#include <linux/of_gpio.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 
@@ -21,7 +20,7 @@ 
 struct tfp410_module {
 	struct tilcdc_module base;
 	struct i2c_adapter *i2c;
-	int gpio;
+	struct gpio_desc *power_gpiod;
 };
 #define to_tfp410_module(x) container_of(x, struct tfp410_module, base)
 
@@ -58,10 +57,10 @@  static void tfp410_encoder_dpms(struct drm_encoder *encoder, int mode)
 
 	if (mode == DRM_MODE_DPMS_ON) {
 		DBG("Power on");
-		gpio_direction_output(tfp410_encoder->mod->gpio, 1);
+		gpiod_direction_output(tfp410_encoder->mod->power_gpiod, 1);
 	} else {
 		DBG("Power off");
-		gpio_direction_output(tfp410_encoder->mod->gpio, 0);
+		gpiod_direction_output(tfp410_encoder->mod->power_gpiod, 0);
 	}
 
 	tfp410_encoder->dpms = mode;
@@ -318,17 +317,17 @@  static int tfp410_probe(struct platform_device *pdev)
 
 	of_node_put(i2c_node);
 
-	tfp410_mod->gpio = of_get_named_gpio_flags(node, "powerdn-gpio",
-			0, NULL);
-	if (tfp410_mod->gpio < 0) {
-		dev_warn(&pdev->dev, "No power down GPIO\n");
-	} else {
-		ret = gpio_request(tfp410_mod->gpio, "DVI_PDn");
-		if (ret) {
-			dev_err(&pdev->dev, "could not get DVI_PDn gpio\n");
-			goto fail_adapter;
-		}
+	tfp410_mod->power_gpiod = devm_gpiod_get_optional(&pdev->dev,
+							  "powerdn",
+							  GPIOD_ASIS);
+	if (IS_ERR(tfp410_mod->power_gpiod)) {
+		dev_err(&pdev->dev, "could not get DVI_PDn gpio\n");
+		goto fail_adapter;
 	}
+	if (!tfp410_mod->power_gpiod)
+		dev_warn(&pdev->dev, "No power down GPIO\n");
+	else
+		gpiod_set_consumer_name(tfp410_mod->power_gpiod, "DVI_PDn");
 
 	return 0;
 
@@ -346,7 +345,6 @@  static int tfp410_remove(struct platform_device *pdev)
 	struct tfp410_module *tfp410_mod = to_tfp410_module(mod);
 
 	i2c_put_adapter(tfp410_mod->i2c);
-	gpio_free(tfp410_mod->gpio);
 
 	tilcdc_module_cleanup(mod);