lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <74d4fc4c6f08fde2d6759633cb2280ecb18cbd91.camel@pengutronix.de>
Date: Tue, 26 Nov 2024 10:29:27 +0100
From: Philipp Zabel <p.zabel@...gutronix.de>
To: Parthiban Nallathambi <parthiban@...umiz.com>, Frank Binns
 <frank.binns@...tec.com>, Matt Coster <matt.coster@...tec.com>, David
 Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>, Maarten
 Lankhorst <maarten.lankhorst@...ux.intel.com>, Maxime Ripard
 <mripard@...nel.org>,  Thomas Zimmermann <tzimmermann@...e.de>, Rob Herring
 <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,  Conor Dooley
 <conor+dt@...nel.org>
Cc: dri-devel@...ts.freedesktop.org, devicetree@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] drm/imagination: add reset control support

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@...umiz.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ