All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Sascha Hauer <s.hauer@pengutronix.de>, dri-devel@lists.freedesktop.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
	kernel@pengutronix.de,
	"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
	"Michael Riesch" <michael.riesch@wolfvision.net>,
	"Sandy Huang" <hjc@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	"Peter Geis" <pgwipeout@gmail.com>
Subject: Re: [PATCH 04/12] drm/rockchip: dw_hdmi: add regulator support
Date: Tue, 7 Dec 2021 17:01:20 +0000	[thread overview]
Message-ID: <d9646a05-2588-339f-24f6-e8cd2f2de746@arm.com> (raw)
In-Reply-To: <20211117143347.314294-5-s.hauer@pengutronix.de>

On 2021-11-17 14:33, Sascha Hauer wrote:
> The RK3568 has HDMI_TX_AVDD0V9 and HDMI_TX_AVDD_1V8 supply inputs needed
> for the HDMI port. add support for these to the driver for boards which
> have them supplied by switchable regulators.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>   .../display/rockchip/rockchip,dw-hdmi.yaml    |  6 ++
>   drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c   | 58 ++++++++++++++++++-
>   2 files changed, 61 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> index 53fa42479d5b7..293b2cfbf739f 100644
> --- a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> +++ b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> @@ -28,6 +28,12 @@ properties:
>     reg-io-width:
>       const: 4
>   
> +  avdd-0v9-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
> +  avdd-1v8-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
>     clocks:
>       minItems: 2
>       items:
> diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> index 29608c25e2d0e..b8fe56c89cdc9 100644
> --- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> +++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> @@ -9,6 +9,7 @@
>   #include <linux/platform_device.h>
>   #include <linux/phy/phy.h>
>   #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>   
>   #include <drm/bridge/dw_hdmi.h>
>   #include <drm/drm_edid.h>
> @@ -83,6 +84,8 @@ struct rockchip_hdmi {
>   	struct clk *vpll_clk;
>   	struct clk *grf_clk;
>   	struct dw_hdmi *hdmi;
> +	struct regulator *avdd_0v9;
> +	struct regulator *avdd_1v8;
>   	struct phy *phy;
>   };
>   
> @@ -222,6 +225,22 @@ static int rockchip_hdmi_parse_dt(struct rockchip_hdmi *hdmi)
>   	hdmi->vpll_clk = hdmi->clks[RK_HDMI_CLK_VPLL].clk;
>   	hdmi->grf_clk = hdmi->clks[RK_HDMI_CLK_GRF].clk;
>   
> +	hdmi->avdd_0v9 = devm_regulator_get_optional(hdmi->dev, "avdd-0v9");

These are clearly *not* optional, unless the HDMI block is magic and can 
still work without physical power. Use devm_regulator_get(), and if the 
real supply is missing from the DT for whatever reason you should get a 
dummy regulator back, which you can then successfully disable and enable 
without all the conditional mess.

Robin.

> +	if (IS_ERR(hdmi->avdd_0v9)) {
> +		if (PTR_ERR(hdmi->avdd_0v9) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_0v9);
> +
> +		hdmi->avdd_0v9 = NULL;
> +	}
> +
> +	hdmi->avdd_1v8 = devm_regulator_get_optional(hdmi->dev, "avdd-1v8");
> +	if (IS_ERR(hdmi->avdd_1v8)) {
> +		if (PTR_ERR(hdmi->avdd_1v8) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_1v8);
> +
> +		hdmi->avdd_1v8 = NULL;
> +	}
> +
>   	return 0;
>   }
>   
> @@ -559,11 +578,27 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   		return ret;
>   	}
>   
> +	if (hdmi->avdd_0v9) {
> +		ret = regulator_enable(hdmi->avdd_0v9);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd0v9: %d\n", ret);
> +			goto err_avdd_0v9;
> +		}
> +	}
> +
> +	if (hdmi->avdd_1v8) {
> +		ret = regulator_enable(hdmi->avdd_1v8);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd1v8: %d\n", ret);
> +			goto err_avdd_1v8;
> +		}
> +	}
> +
>   	ret = clk_bulk_prepare_enable(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
>   	if (ret) {
>   		DRM_DEV_ERROR(hdmi->dev, "Failed to enable HDMI vpll: %d\n",
>   			      ret);
> -		return ret;
> +		goto err_clk;
>   	}
>   
>   	if (hdmi->chip_data == &rk3568_chip_data) {
> @@ -587,10 +622,21 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   	 */
>   	if (IS_ERR(hdmi->hdmi)) {
>   		ret = PTR_ERR(hdmi->hdmi);
> -		drm_encoder_cleanup(encoder);
> -		clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +		goto err_bind;
>   	}
>   
> +	return 0;
> +
> +err_bind:
> +	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +	drm_encoder_cleanup(encoder);
> +err_clk:
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +err_avdd_1v8:
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
> +err_avdd_0v9:
>   	return ret;
>   }
>   
> @@ -601,6 +647,12 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
>   
>   	dw_hdmi_unbind(hdmi->hdmi);
>   	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
>   }
>   
>   static const struct component_ops dw_hdmi_rockchip_ops = {
> 

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Sascha Hauer <s.hauer@pengutronix.de>, dri-devel@lists.freedesktop.org
Cc: devicetree@vger.kernel.org,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	Sandy Huang <hjc@rock-chips.com>,
	linux-rockchip@lists.infradead.org,
	Michael Riesch <michael.riesch@wolfvision.net>,
	kernel@pengutronix.de, Peter Geis <pgwipeout@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 04/12] drm/rockchip: dw_hdmi: add regulator support
Date: Tue, 7 Dec 2021 17:01:20 +0000	[thread overview]
Message-ID: <d9646a05-2588-339f-24f6-e8cd2f2de746@arm.com> (raw)
In-Reply-To: <20211117143347.314294-5-s.hauer@pengutronix.de>

On 2021-11-17 14:33, Sascha Hauer wrote:
> The RK3568 has HDMI_TX_AVDD0V9 and HDMI_TX_AVDD_1V8 supply inputs needed
> for the HDMI port. add support for these to the driver for boards which
> have them supplied by switchable regulators.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>   .../display/rockchip/rockchip,dw-hdmi.yaml    |  6 ++
>   drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c   | 58 ++++++++++++++++++-
>   2 files changed, 61 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> index 53fa42479d5b7..293b2cfbf739f 100644
> --- a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> +++ b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> @@ -28,6 +28,12 @@ properties:
>     reg-io-width:
>       const: 4
>   
> +  avdd-0v9-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
> +  avdd-1v8-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
>     clocks:
>       minItems: 2
>       items:
> diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> index 29608c25e2d0e..b8fe56c89cdc9 100644
> --- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> +++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> @@ -9,6 +9,7 @@
>   #include <linux/platform_device.h>
>   #include <linux/phy/phy.h>
>   #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>   
>   #include <drm/bridge/dw_hdmi.h>
>   #include <drm/drm_edid.h>
> @@ -83,6 +84,8 @@ struct rockchip_hdmi {
>   	struct clk *vpll_clk;
>   	struct clk *grf_clk;
>   	struct dw_hdmi *hdmi;
> +	struct regulator *avdd_0v9;
> +	struct regulator *avdd_1v8;
>   	struct phy *phy;
>   };
>   
> @@ -222,6 +225,22 @@ static int rockchip_hdmi_parse_dt(struct rockchip_hdmi *hdmi)
>   	hdmi->vpll_clk = hdmi->clks[RK_HDMI_CLK_VPLL].clk;
>   	hdmi->grf_clk = hdmi->clks[RK_HDMI_CLK_GRF].clk;
>   
> +	hdmi->avdd_0v9 = devm_regulator_get_optional(hdmi->dev, "avdd-0v9");

These are clearly *not* optional, unless the HDMI block is magic and can 
still work without physical power. Use devm_regulator_get(), and if the 
real supply is missing from the DT for whatever reason you should get a 
dummy regulator back, which you can then successfully disable and enable 
without all the conditional mess.

Robin.

> +	if (IS_ERR(hdmi->avdd_0v9)) {
> +		if (PTR_ERR(hdmi->avdd_0v9) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_0v9);
> +
> +		hdmi->avdd_0v9 = NULL;
> +	}
> +
> +	hdmi->avdd_1v8 = devm_regulator_get_optional(hdmi->dev, "avdd-1v8");
> +	if (IS_ERR(hdmi->avdd_1v8)) {
> +		if (PTR_ERR(hdmi->avdd_1v8) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_1v8);
> +
> +		hdmi->avdd_1v8 = NULL;
> +	}
> +
>   	return 0;
>   }
>   
> @@ -559,11 +578,27 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   		return ret;
>   	}
>   
> +	if (hdmi->avdd_0v9) {
> +		ret = regulator_enable(hdmi->avdd_0v9);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd0v9: %d\n", ret);
> +			goto err_avdd_0v9;
> +		}
> +	}
> +
> +	if (hdmi->avdd_1v8) {
> +		ret = regulator_enable(hdmi->avdd_1v8);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd1v8: %d\n", ret);
> +			goto err_avdd_1v8;
> +		}
> +	}
> +
>   	ret = clk_bulk_prepare_enable(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
>   	if (ret) {
>   		DRM_DEV_ERROR(hdmi->dev, "Failed to enable HDMI vpll: %d\n",
>   			      ret);
> -		return ret;
> +		goto err_clk;
>   	}
>   
>   	if (hdmi->chip_data == &rk3568_chip_data) {
> @@ -587,10 +622,21 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   	 */
>   	if (IS_ERR(hdmi->hdmi)) {
>   		ret = PTR_ERR(hdmi->hdmi);
> -		drm_encoder_cleanup(encoder);
> -		clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +		goto err_bind;
>   	}
>   
> +	return 0;
> +
> +err_bind:
> +	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +	drm_encoder_cleanup(encoder);
> +err_clk:
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +err_avdd_1v8:
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
> +err_avdd_0v9:
>   	return ret;
>   }
>   
> @@ -601,6 +647,12 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
>   
>   	dw_hdmi_unbind(hdmi->hdmi);
>   	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
>   }
>   
>   static const struct component_ops dw_hdmi_rockchip_ops = {
> 

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Sascha Hauer <s.hauer@pengutronix.de>, dri-devel@lists.freedesktop.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
	kernel@pengutronix.de,
	"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
	"Michael Riesch" <michael.riesch@wolfvision.net>,
	"Sandy Huang" <hjc@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	"Peter Geis" <pgwipeout@gmail.com>
Subject: Re: [PATCH 04/12] drm/rockchip: dw_hdmi: add regulator support
Date: Tue, 7 Dec 2021 17:01:20 +0000	[thread overview]
Message-ID: <d9646a05-2588-339f-24f6-e8cd2f2de746@arm.com> (raw)
In-Reply-To: <20211117143347.314294-5-s.hauer@pengutronix.de>

On 2021-11-17 14:33, Sascha Hauer wrote:
> The RK3568 has HDMI_TX_AVDD0V9 and HDMI_TX_AVDD_1V8 supply inputs needed
> for the HDMI port. add support for these to the driver for boards which
> have them supplied by switchable regulators.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>   .../display/rockchip/rockchip,dw-hdmi.yaml    |  6 ++
>   drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c   | 58 ++++++++++++++++++-
>   2 files changed, 61 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> index 53fa42479d5b7..293b2cfbf739f 100644
> --- a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> +++ b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> @@ -28,6 +28,12 @@ properties:
>     reg-io-width:
>       const: 4
>   
> +  avdd-0v9-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
> +  avdd-1v8-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
>     clocks:
>       minItems: 2
>       items:
> diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> index 29608c25e2d0e..b8fe56c89cdc9 100644
> --- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> +++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> @@ -9,6 +9,7 @@
>   #include <linux/platform_device.h>
>   #include <linux/phy/phy.h>
>   #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>   
>   #include <drm/bridge/dw_hdmi.h>
>   #include <drm/drm_edid.h>
> @@ -83,6 +84,8 @@ struct rockchip_hdmi {
>   	struct clk *vpll_clk;
>   	struct clk *grf_clk;
>   	struct dw_hdmi *hdmi;
> +	struct regulator *avdd_0v9;
> +	struct regulator *avdd_1v8;
>   	struct phy *phy;
>   };
>   
> @@ -222,6 +225,22 @@ static int rockchip_hdmi_parse_dt(struct rockchip_hdmi *hdmi)
>   	hdmi->vpll_clk = hdmi->clks[RK_HDMI_CLK_VPLL].clk;
>   	hdmi->grf_clk = hdmi->clks[RK_HDMI_CLK_GRF].clk;
>   
> +	hdmi->avdd_0v9 = devm_regulator_get_optional(hdmi->dev, "avdd-0v9");

These are clearly *not* optional, unless the HDMI block is magic and can 
still work without physical power. Use devm_regulator_get(), and if the 
real supply is missing from the DT for whatever reason you should get a 
dummy regulator back, which you can then successfully disable and enable 
without all the conditional mess.

Robin.

> +	if (IS_ERR(hdmi->avdd_0v9)) {
> +		if (PTR_ERR(hdmi->avdd_0v9) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_0v9);
> +
> +		hdmi->avdd_0v9 = NULL;
> +	}
> +
> +	hdmi->avdd_1v8 = devm_regulator_get_optional(hdmi->dev, "avdd-1v8");
> +	if (IS_ERR(hdmi->avdd_1v8)) {
> +		if (PTR_ERR(hdmi->avdd_1v8) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_1v8);
> +
> +		hdmi->avdd_1v8 = NULL;
> +	}
> +
>   	return 0;
>   }
>   
> @@ -559,11 +578,27 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   		return ret;
>   	}
>   
> +	if (hdmi->avdd_0v9) {
> +		ret = regulator_enable(hdmi->avdd_0v9);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd0v9: %d\n", ret);
> +			goto err_avdd_0v9;
> +		}
> +	}
> +
> +	if (hdmi->avdd_1v8) {
> +		ret = regulator_enable(hdmi->avdd_1v8);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd1v8: %d\n", ret);
> +			goto err_avdd_1v8;
> +		}
> +	}
> +
>   	ret = clk_bulk_prepare_enable(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
>   	if (ret) {
>   		DRM_DEV_ERROR(hdmi->dev, "Failed to enable HDMI vpll: %d\n",
>   			      ret);
> -		return ret;
> +		goto err_clk;
>   	}
>   
>   	if (hdmi->chip_data == &rk3568_chip_data) {
> @@ -587,10 +622,21 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   	 */
>   	if (IS_ERR(hdmi->hdmi)) {
>   		ret = PTR_ERR(hdmi->hdmi);
> -		drm_encoder_cleanup(encoder);
> -		clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +		goto err_bind;
>   	}
>   
> +	return 0;
> +
> +err_bind:
> +	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +	drm_encoder_cleanup(encoder);
> +err_clk:
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +err_avdd_1v8:
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
> +err_avdd_0v9:
>   	return ret;
>   }
>   
> @@ -601,6 +647,12 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
>   
>   	dw_hdmi_unbind(hdmi->hdmi);
>   	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
>   }
>   
>   static const struct component_ops dw_hdmi_rockchip_ops = {
> 

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Sascha Hauer <s.hauer@pengutronix.de>, dri-devel@lists.freedesktop.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
	kernel@pengutronix.de,
	"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
	"Michael Riesch" <michael.riesch@wolfvision.net>,
	"Sandy Huang" <hjc@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	"Peter Geis" <pgwipeout@gmail.com>
Subject: Re: [PATCH 04/12] drm/rockchip: dw_hdmi: add regulator support
Date: Tue, 7 Dec 2021 17:01:20 +0000	[thread overview]
Message-ID: <d9646a05-2588-339f-24f6-e8cd2f2de746@arm.com> (raw)
In-Reply-To: <20211117143347.314294-5-s.hauer@pengutronix.de>

On 2021-11-17 14:33, Sascha Hauer wrote:
> The RK3568 has HDMI_TX_AVDD0V9 and HDMI_TX_AVDD_1V8 supply inputs needed
> for the HDMI port. add support for these to the driver for boards which
> have them supplied by switchable regulators.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>   .../display/rockchip/rockchip,dw-hdmi.yaml    |  6 ++
>   drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c   | 58 ++++++++++++++++++-
>   2 files changed, 61 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> index 53fa42479d5b7..293b2cfbf739f 100644
> --- a/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> +++ b/Documentation/devicetree/bindings/display/rockchip/rockchip,dw-hdmi.yaml
> @@ -28,6 +28,12 @@ properties:
>     reg-io-width:
>       const: 4
>   
> +  avdd-0v9-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
> +  avdd-1v8-supply:
> +    description: A 0.9V supply that powers up the SoC internal circuitry.
> +
>     clocks:
>       minItems: 2
>       items:
> diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> index 29608c25e2d0e..b8fe56c89cdc9 100644
> --- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> +++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
> @@ -9,6 +9,7 @@
>   #include <linux/platform_device.h>
>   #include <linux/phy/phy.h>
>   #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>   
>   #include <drm/bridge/dw_hdmi.h>
>   #include <drm/drm_edid.h>
> @@ -83,6 +84,8 @@ struct rockchip_hdmi {
>   	struct clk *vpll_clk;
>   	struct clk *grf_clk;
>   	struct dw_hdmi *hdmi;
> +	struct regulator *avdd_0v9;
> +	struct regulator *avdd_1v8;
>   	struct phy *phy;
>   };
>   
> @@ -222,6 +225,22 @@ static int rockchip_hdmi_parse_dt(struct rockchip_hdmi *hdmi)
>   	hdmi->vpll_clk = hdmi->clks[RK_HDMI_CLK_VPLL].clk;
>   	hdmi->grf_clk = hdmi->clks[RK_HDMI_CLK_GRF].clk;
>   
> +	hdmi->avdd_0v9 = devm_regulator_get_optional(hdmi->dev, "avdd-0v9");

These are clearly *not* optional, unless the HDMI block is magic and can 
still work without physical power. Use devm_regulator_get(), and if the 
real supply is missing from the DT for whatever reason you should get a 
dummy regulator back, which you can then successfully disable and enable 
without all the conditional mess.

Robin.

> +	if (IS_ERR(hdmi->avdd_0v9)) {
> +		if (PTR_ERR(hdmi->avdd_0v9) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_0v9);
> +
> +		hdmi->avdd_0v9 = NULL;
> +	}
> +
> +	hdmi->avdd_1v8 = devm_regulator_get_optional(hdmi->dev, "avdd-1v8");
> +	if (IS_ERR(hdmi->avdd_1v8)) {
> +		if (PTR_ERR(hdmi->avdd_1v8) != -ENODEV)
> +			return PTR_ERR(hdmi->avdd_1v8);
> +
> +		hdmi->avdd_1v8 = NULL;
> +	}
> +
>   	return 0;
>   }
>   
> @@ -559,11 +578,27 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   		return ret;
>   	}
>   
> +	if (hdmi->avdd_0v9) {
> +		ret = regulator_enable(hdmi->avdd_0v9);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd0v9: %d\n", ret);
> +			goto err_avdd_0v9;
> +		}
> +	}
> +
> +	if (hdmi->avdd_1v8) {
> +		ret = regulator_enable(hdmi->avdd_1v8);
> +		if (ret) {
> +			DRM_DEV_ERROR(hdmi->dev, "failed to enable avdd1v8: %d\n", ret);
> +			goto err_avdd_1v8;
> +		}
> +	}
> +
>   	ret = clk_bulk_prepare_enable(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
>   	if (ret) {
>   		DRM_DEV_ERROR(hdmi->dev, "Failed to enable HDMI vpll: %d\n",
>   			      ret);
> -		return ret;
> +		goto err_clk;
>   	}
>   
>   	if (hdmi->chip_data == &rk3568_chip_data) {
> @@ -587,10 +622,21 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
>   	 */
>   	if (IS_ERR(hdmi->hdmi)) {
>   		ret = PTR_ERR(hdmi->hdmi);
> -		drm_encoder_cleanup(encoder);
> -		clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +		goto err_bind;
>   	}
>   
> +	return 0;
> +
> +err_bind:
> +	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +	drm_encoder_cleanup(encoder);
> +err_clk:
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +err_avdd_1v8:
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
> +err_avdd_0v9:
>   	return ret;
>   }
>   
> @@ -601,6 +647,12 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
>   
>   	dw_hdmi_unbind(hdmi->hdmi);
>   	clk_bulk_disable_unprepare(RK_HDMI_NCLOCKS_HDMI, hdmi->clks);
> +
> +	if (hdmi->avdd_1v8)
> +		regulator_disable(hdmi->avdd_1v8);
> +
> +	if (hdmi->avdd_0v9)
> +		regulator_disable(hdmi->avdd_0v9);
>   }
>   
>   static const struct component_ops dw_hdmi_rockchip_ops = {
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-12-07 17:01 UTC|newest]

Thread overview: 201+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 14:33 [PATCH v1 00/12] drm/rockchip: RK356x VOP2 support Sascha Hauer
2021-11-17 14:33 ` Sascha Hauer
2021-11-17 14:33 ` Sascha Hauer
2021-11-17 14:33 ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 01/12] dt-bindings: display: rockchip: Add compatible for rk3568 HDMI Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-27 15:07   ` Heiko Stuebner
2021-11-27 15:07     ` Heiko Stuebner
2021-11-27 15:07     ` Heiko Stuebner
2021-11-27 15:07     ` Heiko Stuebner
2021-11-17 14:33 ` [PATCH 02/12] drm/rockchip: dw_hdmi: Do not leave clock enabled in error case Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 03/12] drm/rockchip: dw_hdmi: add rk3568 support Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 04/12] drm/rockchip: dw_hdmi: add regulator support Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-29 22:46   ` Rob Herring
2021-11-29 22:46     ` Rob Herring
2021-11-29 22:46     ` Rob Herring
2021-11-29 22:46     ` Rob Herring
2021-12-07 17:01   ` Robin Murphy [this message]
2021-12-07 17:01     ` Robin Murphy
2021-12-07 17:01     ` Robin Murphy
2021-12-07 17:01     ` Robin Murphy
2021-11-17 14:33 ` [PATCH 05/12] of: graph: Allow disabled endpoints Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 06/12] dt-bindings: " Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 07/12] dt-bindings: display: rockchip: Add binding for VOP2 Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 16:10   ` Rob Herring
2021-11-17 16:10     ` Rob Herring
2021-11-17 16:10     ` Rob Herring
2021-11-17 16:10     ` Rob Herring
2021-11-17 14:33 ` [PATCH 08/12] arm64: dts: rockchip: rk356x: Add VOP2 nodes Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-25 20:25   ` Johan Jonker
2021-11-25 20:25     ` Johan Jonker
2021-11-25 20:25     ` Johan Jonker
2021-11-25 20:25     ` Johan Jonker
2021-11-26  7:40     ` Sascha Hauer
2021-11-26  7:40       ` Sascha Hauer
2021-11-26  7:40       ` Sascha Hauer
2021-11-26  7:40       ` Sascha Hauer
2021-11-26  8:15       ` Heiko Stübner
2021-11-26  8:15         ` Heiko Stübner
2021-11-26  8:15         ` Heiko Stübner
2021-11-26  8:15         ` Heiko Stübner
2021-11-17 14:33 ` [PATCH 09/12] arm64: dts: rockchip: rk356x: Add HDMI nodes Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 15:13   ` Rob Herring
2021-11-17 15:13     ` Rob Herring
2021-11-17 15:13     ` Rob Herring
2021-11-17 15:13     ` Rob Herring
2021-12-01 16:04     ` Sascha Hauer
2021-12-01 16:04       ` Sascha Hauer
2021-12-01 16:04       ` Sascha Hauer
2021-12-01 16:04       ` Sascha Hauer
2021-11-17 14:33 ` [PATCH 10/12] arm64: dts: rockchip: rk3568-evb: Enable VOP2 and hdmi Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 15:19   ` Rob Herring
2021-11-17 15:19     ` Rob Herring
2021-11-17 15:19     ` Rob Herring
2021-11-17 15:19     ` Rob Herring
2021-12-02 15:34     ` Sascha Hauer
2021-12-02 15:34       ` Sascha Hauer
2021-12-02 15:34       ` Sascha Hauer
2021-12-02 15:34       ` Sascha Hauer
2021-12-02 15:41       ` Heiko Stübner
2021-12-02 15:41         ` Heiko Stübner
2021-12-02 15:41         ` Heiko Stübner
2021-12-02 15:41         ` Heiko Stübner
2021-12-02 16:09         ` Sascha Hauer
2021-12-02 16:09           ` Sascha Hauer
2021-12-02 16:09           ` Sascha Hauer
2021-12-02 16:09           ` Sascha Hauer
2021-11-17 15:20   ` Michael Riesch
2021-11-17 15:20     ` Michael Riesch
2021-11-17 15:20     ` Michael Riesch
2021-11-17 15:20     ` Michael Riesch
2021-11-17 15:44   ` [PATCH] arm64: dts: rockchip: enable vop2 and hdmi tx on quartz64a Michael Riesch
2021-11-17 15:44     ` Michael Riesch
2021-11-17 15:44     ` Michael Riesch
2021-11-17 15:44     ` Michael Riesch
2021-11-25 19:44     ` Johan Jonker
2021-11-25 19:44       ` Johan Jonker
2021-11-25 19:44       ` Johan Jonker
2021-11-25 19:44       ` Johan Jonker
2021-11-17 14:33 ` [PATCH 11/12] drm/rockchip: Make VOP driver optional Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:40   ` Heiko Stübner
2021-11-17 14:40     ` Heiko Stübner
2021-11-17 14:40     ` Heiko Stübner
2021-11-17 14:40     ` Heiko Stübner
2021-11-17 14:50     ` Sascha Hauer
2021-11-17 14:50       ` Sascha Hauer
2021-11-17 14:50       ` Sascha Hauer
2021-11-17 14:50       ` Sascha Hauer
2021-11-17 15:16       ` Heiko Stübner
2021-11-17 15:16         ` Heiko Stübner
2021-11-17 15:16         ` Heiko Stübner
2021-11-17 15:16         ` Heiko Stübner
2021-11-17 14:33 ` [PATCH 12/12] drm: rockchip: Add VOP2 driver Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 14:33   ` Sascha Hauer
2021-11-17 18:05   ` Nicolas Frattaroli
2021-11-17 18:05     ` Nicolas Frattaroli
2021-11-17 18:05     ` Nicolas Frattaroli
2021-11-17 18:05     ` Nicolas Frattaroli
2021-11-17 18:38     ` Dan Johansen
2021-11-17 19:45     ` Sascha Hauer
2021-11-17 19:45       ` Sascha Hauer
2021-11-17 19:45       ` Sascha Hauer
2021-11-17 19:45       ` Sascha Hauer
2021-11-26  6:44   ` kernel test robot
2021-11-26  6:44     ` kernel test robot
2021-11-26  6:44     ` kernel test robot
2021-11-26  6:44     ` kernel test robot
2021-11-26  6:44     ` kernel test robot
2021-11-17 14:54 ` [PATCH v1 00/12] drm/rockchip: RK356x VOP2 support Rob Herring
2021-11-17 14:54   ` Rob Herring
2021-11-17 14:54   ` Rob Herring
2021-11-17 14:54   ` Rob Herring
2021-11-17 15:41   ` Sascha Hauer
2021-11-17 15:41     ` Sascha Hauer
2021-11-17 15:41     ` Sascha Hauer
2021-11-17 15:41     ` Sascha Hauer
2021-11-18  1:27 ` Kever Yang
2021-11-18  1:27   ` Kever Yang
2021-11-18  1:27   ` Kever Yang
2021-11-18  1:27   ` Kever Yang
2021-11-18  9:26   ` Heiko Stübner
2021-11-18  9:26     ` Heiko Stübner
2021-11-18  9:26     ` Heiko Stübner
2021-11-18  9:26     ` Heiko Stübner
2021-11-18  9:53     ` Daniel Stone
2021-11-18  9:53       ` Daniel Stone
2021-11-18  9:53       ` Daniel Stone
2021-11-18  9:53       ` Daniel Stone
2021-11-18 10:50       ` Kever Yang
2021-11-18 10:50         ` Kever Yang
2021-11-18 10:50         ` Kever Yang
2021-11-18 10:50         ` Kever Yang
2021-11-18 11:08         ` Michael Riesch
2021-11-18 11:08           ` Michael Riesch
2021-11-18 11:08           ` Michael Riesch
2021-11-18 11:08           ` Michael Riesch
2021-11-18 12:07         ` Daniel Stone
2021-11-18 12:07           ` Daniel Stone
2021-11-18 12:07           ` Daniel Stone
2021-11-18 12:07           ` Daniel Stone
2021-11-18 13:14           ` Andy Yan
2021-11-18 13:14             ` Andy Yan
2021-11-18 13:14             ` Andy Yan
2021-11-18 13:14             ` Andy Yan
2021-11-18 13:24             ` Daniel Stone
2021-11-18 13:24               ` Daniel Stone
2021-11-18 13:24               ` Daniel Stone
2021-11-18 13:24               ` Daniel Stone
2021-11-18 10:03     ` Sascha Hauer
2021-11-18 10:03       ` Sascha Hauer
2021-11-18 10:03       ` Sascha Hauer
2021-11-18 10:03       ` Sascha Hauer
2021-11-21 23:18 ` Alex Bee
2021-11-21 23:18   ` Alex Bee
2021-11-21 23:18   ` Alex Bee
2021-11-21 23:18   ` Alex Bee
2021-11-22  8:10   ` Sascha Hauer
2021-11-22  8:10     ` Sascha Hauer
2021-11-22  8:10     ` Sascha Hauer
2021-11-22  8:10     ` Sascha Hauer
2021-11-22 17:47     ` Alex Bee
2021-11-22 17:47       ` Alex Bee
2021-11-22 17:47       ` Alex Bee
2021-11-22 17:47       ` Alex Bee
2021-11-22 19:21       ` Robin Murphy
2021-11-22 19:21         ` Robin Murphy
2021-11-22 19:21         ` Robin Murphy
2021-11-22 19:21         ` Robin Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9646a05-2588-339f-24f6-e8cd2f2de746@arm.com \
    --to=robin.murphy@arm.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=heiko@sntech.de \
    --cc=hjc@rock-chips.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=michael.riesch@wolfvision.net \
    --cc=pgwipeout@gmail.com \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.