Re: [PATCH v7 4/4] drm/mediatek: set dpi pin mode to gpio low to avoid leakage current

CK Hu
2020-02-25T07:33:34Z

Hi, Jitao:

On Tue, 2020-02-25 at 14:46 +0800, Jitao Shi wrote:
> Config dpi pins mode to output and pull low when dpi is disabled.
> Aovid leakage current from some dpi pins (Hsync Vsync DE ... ).
>
> Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
> ---
> drivers/gpu/drm/mediatek/mtk_dpi.c | 33 ++++++++++++++++++++++++++++--
> 1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c b/drivers/gpu/drm/mediatek/mtk_dpi.c
> index c3e631b93c2e..ca570040ffdf 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dpi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
> @@ -10,7 +10,9 @@
> #include <linux/kernel.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> #include <linux/of_graph.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
> #include <linux/types.h>
>
> @@ -74,6 +76,9 @@ struct mtk_dpi {
> enum mtk_dpi_out_yc_map yc_map;
> enum mtk_dpi_out_bit_num bit_num;
> enum mtk_dpi_out_channel_swap channel_swap;
> + struct pinctrl *pinctrl;
> + struct pinctrl_state *pins_gpio;
> + struct pinctrl_state *pins_dpi;
> int refcount;
> u32 pclk_sample;
> };
> @@ -387,6 +392,9 @@ static void mtk_dpi_power_off(struct mtk_dpi *dpi)
> if (--dpi->refcount != 0)
> return;
>
> + if (dpi->pinctrl && dpi->pins_gpio)
> + pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio);
> +
> mtk_dpi_disable(dpi);
> clk_disable_unprepare(dpi->pixel_clk);
> clk_disable_unprepare(dpi->engine_clk);
> @@ -411,6 +419,9 @@ static int mtk_dpi_power_on(struct mtk_dpi *dpi)
> goto err_pixel;
> }
>
> + if (dpi->pinctrl && dpi->pins_dpi)
> + pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi);
> +
> mtk_dpi_enable(dpi);
> return 0;
>
> @@ -716,8 +727,26 @@ static int mtk_dpi_probe(struct platform_device *pdev)
>
> dpi->dev = dev;
> dpi->conf = (struct mtk_dpi_conf *)of_device_get_match_data(dev);
> - dpi->pclk_sample = of_property_read_u32_index(dev->of_node,
> - "pclk-sample");
> + of_property_read_u32_index(dev->of_node, "pclk-sample", 1,
> + &dpi->pclk_sample);

Why this exists in this patch?

> +
> + dpi->pinctrl = devm_pinctrl_get(&pdev->dev);
> + if (IS_ERR(dpi->pinctrl))
> + dev_dbg(&pdev->dev, "Cannot find pinctrl!\n");

I think you should set dpi->pinctrl to NULL when error, and check
dpi->pinctrl before you use it, such as pinctrl_lookup_state().

Regards,
CK

> +
> + dpi->pins_gpio = pinctrl_lookup_state(dpi->pinctrl, "gpiomode");
> + if (IS_ERR(dpi->pins_gpio)) {
> + dpi->pins_gpio = NULL;
> + dev_dbg(&pdev->dev, "Cannot find pinctrl gpiomode!\n");
> + }
> + if (dpi->pinctrl && dpi->pins_gpio)
> + pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio);
> +
> + dpi->pins_dpi = pinctrl_lookup_state(dpi->pinctrl, "dpimode");
> + if (IS_ERR(dpi->pins_dpi)) {
> + dpi->pins_dpi = NULL;
> + dev_dbg(&pdev->dev, "Cannot find pinctrl dpimode!\n");
> + }
>
> mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> dpi->regs = devm_ioremap_resource(dev, mem);