Re: [PATCH] drm: gma500: Convert to GPIO descriptors

2020-07-01 Thread Patrik Jakobsson
On Sun, Jun 28, 2020 at 1:29 AM Linus Walleij  wrote:
>
> Finalize he conversion of GMA500 to use only GPIO descriptors.
> The GPIO look-up-table is associated with the device directly
> in the GMA500 Medfield chip driver since no explicit platform
> type device (such as in x86/platform/intel-mid) exists: the
> GMA500 probes directly from the PCI device. Apparently GPIOs
> 88 and 34 are used on all of these so just go ahead and

Is 88 meant to be 128 here?

> register those for resetting the DSI pipes.
>
> Cc: Patrik Jakobsson 
> Signed-off-by: Linus Walleij 
> ---
>  drivers/gpu/drm/gma500/mdfld_device.c | 20 +
>  drivers/gpu/drm/gma500/mdfld_dsi_dpi.c|  2 +-
>  drivers/gpu/drm/gma500/mdfld_dsi_output.c | 51 ---
>  drivers/gpu/drm/gma500/mdfld_dsi_output.h |  2 +-
>  drivers/gpu/drm/gma500/mdfld_output.h |  2 +-
>  drivers/gpu/drm/gma500/psb_intel_drv.h|  1 -
>  6 files changed, 49 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/mdfld_device.c 
> b/drivers/gpu/drm/gma500/mdfld_device.c
> index b718efccdcf2..be9cf6b1e3b3 100644
> --- a/drivers/gpu/drm/gma500/mdfld_device.c
> +++ b/drivers/gpu/drm/gma500/mdfld_device.c
> @@ -6,6 +6,7 @@
>   **/
>
>  #include 
> +#include 
>
>  #include 
>
> @@ -505,12 +506,31 @@ static const struct psb_offset mdfld_regmap[3] = {
> },
>  };
>
> +/*
> + * The GPIO lines for resetting DSI pipe 0 and 2 are available in the
> + * PCI device :00:0c.0 on the Medfield.
> + */
> +static struct gpiod_lookup_table mdfld_dsi_pipe_gpio_table = {
> +   .table  = {
> +   GPIO_LOOKUP(":00:0c.0", 128, "dsi-pipe0-reset",
> +   GPIO_ACTIVE_HIGH),
> +   GPIO_LOOKUP(":00:0c.0", 34, "dsi-pipe2-reset",
> +   GPIO_ACTIVE_HIGH),
> +   { },
> +   },
> +};
> +
>  static int mdfld_chip_setup(struct drm_device *dev)
>  {
> struct drm_psb_private *dev_priv = dev->dev_private;
> if (pci_enable_msi(dev->pdev))
> dev_warn(dev->dev, "Enabling MSI failed!\n");
> dev_priv->regmap = mdfld_regmap;
> +
> +   /* Associate the GPIO lines with the DRM device */
> +   mdfld_dsi_pipe_gpio_table.dev_id = dev_name(dev->dev);
> +   gpiod_add_lookup_table(_dsi_pipe_gpio_table);
> +
> return mid_chip_setup(dev);
>  }
>
> diff --git a/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c 
> b/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
> index c976a9dd9240..ae1223f631a7 100644
> --- a/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
> +++ b/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
> @@ -955,7 +955,7 @@ struct mdfld_dsi_encoder *mdfld_dsi_dpi_init(struct 
> drm_device *dev,
>
> /* panel hard-reset */
> if (p_funcs->reset) {
> -   ret = p_funcs->reset(pipe);
> +   ret = p_funcs->reset(dev, pipe);
> if (ret) {
> DRM_ERROR("Panel %d hard-reset failed\n", 
> pipe);
> return NULL;
> diff --git a/drivers/gpu/drm/gma500/mdfld_dsi_output.c 
> b/drivers/gpu/drm/gma500/mdfld_dsi_output.c
> index f350ac1ead18..c9478261964a 100644
> --- a/drivers/gpu/drm/gma500/mdfld_dsi_output.c
> +++ b/drivers/gpu/drm/gma500/mdfld_dsi_output.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>
> @@ -432,42 +433,42 @@ static int mdfld_dsi_get_default_config(struct 
> drm_device *dev,
> return 0;
>  }
>
> -int mdfld_dsi_panel_reset(int pipe)
> +int mdfld_dsi_panel_reset(struct drm_device *ddev, int pipe)
>  {
> -   unsigned gpio;
> -   int ret = 0;
> -
> +   struct device *dev = ddev->dev;
> +   struct gpio_desc *gpiod;
> +
> +   /*
> +* Raise the GPIO reset line for the corresponding pipe to HIGH,
> +* this is probably because it is active low so this takes the
> +* respective pipe out of reset. (We have no code to put it back
> +* into reset in this driver.)
> +*/
> switch (pipe) {
> case 0:
> -   gpio = 128;
> +   gpiod = gpiod_get(dev, "dsi-pipe0-reset", GPIOD_OUT_HIGH);
> +   if (IS_ERR(gpiod))
> +   return PTR_ERR(gpiod);
> break;
> case 2:
> -   gpio = 34;
> +   gpiod = gpiod_get(dev, "dsi-pipe2-reset", GPIOD_OUT_HIGH);
> +   if (IS_ERR(gpiod))
> +   return PTR_ERR(gpiod);
> break;
> default:
> -   DRM_ERROR("Invalid output\n");
> +   DRM_DEV_ERROR(dev, "Invalid output pipe\n");
> return -EINVAL;
> }
> +   gpiod_put(gpiod);
>
> -   ret = gpio_request(gpio, "gfx");
> -   if (ret) {
> -   DRM_ERROR("gpio_rqueset failed\n");
> -   return ret;
> -   }
> -

[PATCH] drm: gma500: Convert to GPIO descriptors

2020-06-27 Thread Linus Walleij
Finalize he conversion of GMA500 to use only GPIO descriptors.
The GPIO look-up-table is associated with the device directly
in the GMA500 Medfield chip driver since no explicit platform
type device (such as in x86/platform/intel-mid) exists: the
GMA500 probes directly from the PCI device. Apparently GPIOs
88 and 34 are used on all of these so just go ahead and
register those for resetting the DSI pipes.

Cc: Patrik Jakobsson 
Signed-off-by: Linus Walleij 
---
 drivers/gpu/drm/gma500/mdfld_device.c | 20 +
 drivers/gpu/drm/gma500/mdfld_dsi_dpi.c|  2 +-
 drivers/gpu/drm/gma500/mdfld_dsi_output.c | 51 ---
 drivers/gpu/drm/gma500/mdfld_dsi_output.h |  2 +-
 drivers/gpu/drm/gma500/mdfld_output.h |  2 +-
 drivers/gpu/drm/gma500/psb_intel_drv.h|  1 -
 6 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/gma500/mdfld_device.c 
b/drivers/gpu/drm/gma500/mdfld_device.c
index b718efccdcf2..be9cf6b1e3b3 100644
--- a/drivers/gpu/drm/gma500/mdfld_device.c
+++ b/drivers/gpu/drm/gma500/mdfld_device.c
@@ -6,6 +6,7 @@
  **/
 
 #include 
+#include 
 
 #include 
 
@@ -505,12 +506,31 @@ static const struct psb_offset mdfld_regmap[3] = {
},
 };
 
+/*
+ * The GPIO lines for resetting DSI pipe 0 and 2 are available in the
+ * PCI device :00:0c.0 on the Medfield.
+ */
+static struct gpiod_lookup_table mdfld_dsi_pipe_gpio_table = {
+   .table  = {
+   GPIO_LOOKUP(":00:0c.0", 128, "dsi-pipe0-reset",
+   GPIO_ACTIVE_HIGH),
+   GPIO_LOOKUP(":00:0c.0", 34, "dsi-pipe2-reset",
+   GPIO_ACTIVE_HIGH),
+   { },
+   },
+};
+
 static int mdfld_chip_setup(struct drm_device *dev)
 {
struct drm_psb_private *dev_priv = dev->dev_private;
if (pci_enable_msi(dev->pdev))
dev_warn(dev->dev, "Enabling MSI failed!\n");
dev_priv->regmap = mdfld_regmap;
+
+   /* Associate the GPIO lines with the DRM device */
+   mdfld_dsi_pipe_gpio_table.dev_id = dev_name(dev->dev);
+   gpiod_add_lookup_table(_dsi_pipe_gpio_table);
+
return mid_chip_setup(dev);
 }
 
diff --git a/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c 
b/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
index c976a9dd9240..ae1223f631a7 100644
--- a/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
+++ b/drivers/gpu/drm/gma500/mdfld_dsi_dpi.c
@@ -955,7 +955,7 @@ struct mdfld_dsi_encoder *mdfld_dsi_dpi_init(struct 
drm_device *dev,
 
/* panel hard-reset */
if (p_funcs->reset) {
-   ret = p_funcs->reset(pipe);
+   ret = p_funcs->reset(dev, pipe);
if (ret) {
DRM_ERROR("Panel %d hard-reset failed\n", pipe);
return NULL;
diff --git a/drivers/gpu/drm/gma500/mdfld_dsi_output.c 
b/drivers/gpu/drm/gma500/mdfld_dsi_output.c
index f350ac1ead18..c9478261964a 100644
--- a/drivers/gpu/drm/gma500/mdfld_dsi_output.c
+++ b/drivers/gpu/drm/gma500/mdfld_dsi_output.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -432,42 +433,42 @@ static int mdfld_dsi_get_default_config(struct drm_device 
*dev,
return 0;
 }
 
-int mdfld_dsi_panel_reset(int pipe)
+int mdfld_dsi_panel_reset(struct drm_device *ddev, int pipe)
 {
-   unsigned gpio;
-   int ret = 0;
-
+   struct device *dev = ddev->dev;
+   struct gpio_desc *gpiod;
+
+   /*
+* Raise the GPIO reset line for the corresponding pipe to HIGH,
+* this is probably because it is active low so this takes the
+* respective pipe out of reset. (We have no code to put it back
+* into reset in this driver.)
+*/
switch (pipe) {
case 0:
-   gpio = 128;
+   gpiod = gpiod_get(dev, "dsi-pipe0-reset", GPIOD_OUT_HIGH);
+   if (IS_ERR(gpiod))
+   return PTR_ERR(gpiod);
break;
case 2:
-   gpio = 34;
+   gpiod = gpiod_get(dev, "dsi-pipe2-reset", GPIOD_OUT_HIGH);
+   if (IS_ERR(gpiod))
+   return PTR_ERR(gpiod);
break;
default:
-   DRM_ERROR("Invalid output\n");
+   DRM_DEV_ERROR(dev, "Invalid output pipe\n");
return -EINVAL;
}
+   gpiod_put(gpiod);
 
-   ret = gpio_request(gpio, "gfx");
-   if (ret) {
-   DRM_ERROR("gpio_rqueset failed\n");
-   return ret;
-   }
-
-   ret = gpio_direction_output(gpio, 1);
-   if (ret) {
-   DRM_ERROR("gpio_direction_output failed\n");
-   goto gpio_error;
-   }
+   /* Always read the pipe0 GPIO line, FIXME: explain why! */
+   gpiod = gpiod_get(dev, "dsi-pipe0-reset", GPIOD_ASIS);
+   if (IS_ERR(gpiod))
+