Devicetree
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: Parthiban Nallathambi <parthiban@linumiz.com>,
	Frank Binns <frank.binns@imgtec.com>,
	Matt Coster <matt.coster@imgtec.com>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] drm/imagination: add reset control support
Date: Tue, 26 Nov 2024 10:29:27 +0100	[thread overview]
Message-ID: <74d4fc4c6f08fde2d6759633cb2280ecb18cbd91.camel@pengutronix.de> (raw)
In-Reply-To: <20241125-pvr-reset-v1-2-b437b8052948@linumiz.com>

On Mo, 2024-11-25 at 22:07 +0530, Parthiban Nallathambi wrote:
> On some platforms like Allwinner A133 with GE8300 includes
> reset control from reset control unit. Add reset control
> optionally from the devicetree.
> 
> Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
> ---
>  drivers/gpu/drm/imagination/pvr_device.h |  8 ++++++++
>  drivers/gpu/drm/imagination/pvr_drv.c    |  5 +++++
>  drivers/gpu/drm/imagination/pvr_power.c  | 16 +++++++++++++++-
>  3 files changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h
> index 6d0dfacb677b..21ec7dd64415 100644
> --- a/drivers/gpu/drm/imagination/pvr_device.h
> +++ b/drivers/gpu/drm/imagination/pvr_device.h
> @@ -23,6 +23,7 @@
>  #include <linux/kernel.h>
>  #include <linux/math.h>
>  #include <linux/mutex.h>
> +#include <linux/reset.h>
>  #include <linux/spinlock_types.h>
>  #include <linux/timer.h>
>  #include <linux/types.h>
> @@ -131,6 +132,13 @@ struct pvr_device {
>  	 */
>  	struct clk *mem_clk;
>  
> +	/**
> +	 * @reset: Optional reset control
> +	 *
> +	 * This may be used on some platforms to reset the GPU module/IP.
> +	 */
> +	struct reset_control *reset;
> +
>  	/** @irq: IRQ number. */
>  	int irq;
>  
> diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
> index fb17196e05f4..d9b918410ea9 100644
> --- a/drivers/gpu/drm/imagination/pvr_drv.c
> +++ b/drivers/gpu/drm/imagination/pvr_drv.c
> @@ -36,6 +36,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/reset.h>
>  #include <linux/xarray.h>
>  
>  /**
> @@ -1427,6 +1428,10 @@ pvr_probe(struct platform_device *plat_dev)
>  	pm_runtime_use_autosuspend(&plat_dev->dev);
>  	pvr_watchdog_init(pvr_dev);
>  
> +	pvr_dev->reset = devm_reset_control_get_optional_exclusive(&plat_dev->dev, "ahb");
> +	if (PTR_ERR(pvr_dev->reset) == -EPROBE_DEFER)
> +		return PTR_ERR(pvr_dev->reset);

	pvr_dev->reset = devm_reset_control_get_optional_exclusive(&plat_dev->dev, "ahb");
	if (IS_ERR(pvr_dev->reset))
		return PTR_ERR(pvr_dev->reset);

Please don't ignore errors. devm_reset_control_get_optional_exclusive()
returns NULL if the "ahb" reset control isn't specified in the device
tree, and the reset_control_assert/deassert() functions accept that as
a non-existing reset, see [1].

[1] https://docs.kernel.org/driver-api/reset.html#optional-resets

> +
>  	err = pvr_device_init(pvr_dev);
>  	if (err)
>  		goto err_watchdog_fini;
> diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
> index ba7816fd28ec..a24ed85f36c7 100644
> --- a/drivers/gpu/drm/imagination/pvr_power.c
> +++ b/drivers/gpu/drm/imagination/pvr_power.c
> @@ -15,6 +15,7 @@
>  #include <linux/mutex.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/reset.h>
>  #include <linux/timer.h>
>  #include <linux/types.h>
>  #include <linux/workqueue.h>
> @@ -252,6 +253,9 @@ pvr_power_device_suspend(struct device *dev)
>  	clk_disable_unprepare(pvr_dev->sys_clk);
>  	clk_disable_unprepare(pvr_dev->core_clk);
>  
> +	if (!IS_ERR(pvr_dev->reset))
> +		reset_control_assert(pvr_dev->reset);

	reset_control_assert(pvr_dev->reset);

This just returns 0 if pvr_dev->reset == NULL.

> +
>  err_drm_dev_exit:
>  	drm_dev_exit(idx);
>  
> @@ -270,9 +274,15 @@ pvr_power_device_resume(struct device *dev)
>  	if (!drm_dev_enter(drm_dev, &idx))
>  		return -EIO;
>  
> +	if (!IS_ERR(pvr_dev->reset)) {
> +		err = reset_control_reset(pvr_dev->reset);
> +		if (err)
> +			goto err_drm_dev_exit;
> +	}

	err = reset_control_reset(pvr_dev->reset);
	if (err)
		goto err_drm_dev_exit;

> +
>  	err = clk_prepare_enable(pvr_dev->core_clk);
>  	if (err)
> -		goto err_drm_dev_exit;
> +		goto err_reset_exit;
>  
>  	err = clk_prepare_enable(pvr_dev->sys_clk);
>  	if (err)
> @@ -301,6 +311,10 @@ pvr_power_device_resume(struct device *dev)
>  err_core_clk_disable:
>  	clk_disable_unprepare(pvr_dev->core_clk);
>  
> +err_reset_exit:
> +	if (!IS_ERR(pvr_dev->reset))
> +		reset_control_assert(pvr_dev->reset);

err_reset_exit:
	reset_control_assert(pvr_dev->reset);

> +
>  err_drm_dev_exit:
>  	drm_dev_exit(idx);
>  
> 

regards
Philipp

  reply	other threads:[~2024-11-26  9:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25 16:37 [PATCH 0/2] drm/imagination: add reset handling Parthiban Nallathambi
2024-11-25 16:37 ` [PATCH 1/2] dt-bindings: gpu: add reset control property Parthiban Nallathambi
2024-11-25 18:07   ` Conor Dooley
2024-11-26  3:46     ` Parthiban
2024-11-26  9:32       ` Krzysztof Kozlowski
2024-11-26  9:42         ` Parthiban
2024-11-26  9:32   ` Krzysztof Kozlowski
2024-11-25 16:37 ` [PATCH 2/2] drm/imagination: add reset control support Parthiban Nallathambi
2024-11-26  9:29   ` Philipp Zabel [this message]
2024-11-26  9:48     ` Parthiban

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=74d4fc4c6f08fde2d6759633cb2280ecb18cbd91.camel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=airlied@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frank.binns@imgtec.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matt.coster@imgtec.com \
    --cc=mripard@kernel.org \
    --cc=parthiban@linumiz.com \
    --cc=robh@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox