linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Alexander Usyskin <alexander.usyskin@intel.com>
Cc: "Mark Brown" <broonie@kernel.org>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Oded Gabbay" <ogabbay@kernel.org>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Tomas Winkler" <tomas.winkler@intel.com>,
	"Vitaly Lubart" <vitaly.lubart@intel.com>,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v6 07/12] spi: intel-dg: wake card on operations
Date: Mon, 16 Sep 2024 14:00:50 -0400	[thread overview]
Message-ID: <ZuhyUjDTiMeHSCKO@intel.com> (raw)
In-Reply-To: <20240916134928.3654054-8-alexander.usyskin@intel.com>

On Mon, Sep 16, 2024 at 04:49:23PM +0300, Alexander Usyskin wrote:
> Enable runtime PM in spi driver to notify graphics driver that
> whole card should be kept awake while spi operations are
> performed through this driver.
> 
> CC: Lucas De Marchi <lucas.demarchi@intel.com>
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> ---
>  drivers/spi/spi-intel-dg.c | 44 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
> index c76b0a70f8d8..a14fc3190520 100644
> --- a/drivers/spi/spi-intel-dg.c
> +++ b/drivers/spi/spi-intel-dg.c
> @@ -12,11 +12,14 @@
>  #include <linux/module.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/partitions.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/string.h>
>  #include <linux/slab.h>
>  #include <linux/sizes.h>
>  #include <linux/types.h>
>  
> +#define INTEL_DG_SPI_RPM_TIMEOUT 500
> +
>  struct intel_dg_spi {
>  	struct kref refcnt;
>  	struct mtd_info mtd;
> @@ -471,6 +474,12 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
>  	total_len = info->len;
>  	addr = info->addr;
>  
> +	ret = pm_runtime_resume_and_get(mtd->dev.parent);
> +	if (ret < 0) {
> +		dev_err(&mtd->dev, "rpm: get failed %d\n", ret);

If I understood correctly,
this is the device = &aux_dev->dev;
which is the drm->pdev.dev
?

This is to ensure that the graphics driver is not going to runtime suspend,
right?

> +		return ret;
> +	}
> +
>  	mutex_lock(&spi->lock);
>  
>  	while (total_len > 0) {
> @@ -512,6 +521,8 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
>  
>  out:
>  	mutex_unlock(&spi->lock);
> +	pm_runtime_mark_last_busy(mtd->dev.parent);
> +	pm_runtime_put_autosuspend(mtd->dev.parent);
>  	return ret;
>  }
>  
> @@ -545,6 +556,12 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
>  	if (len > spi->regions[idx].size - from)
>  		len = spi->regions[idx].size - from;
>  
> +	ret = pm_runtime_resume_and_get(mtd->dev.parent);
> +	if (ret < 0) {
> +		dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
> +		return ret;
> +	}
> +
>  	mutex_lock(&spi->lock);
>  
>  	ret = spi_read(spi, region, from, len, buf);
> @@ -557,6 +574,8 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
>  	*retlen = ret;
>  
>  	mutex_unlock(&spi->lock);
> +	pm_runtime_mark_last_busy(mtd->dev.parent);
> +	pm_runtime_put_autosuspend(mtd->dev.parent);
>  	return 0;
>  }
>  
> @@ -590,6 +609,12 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
>  	if (len > spi->regions[idx].size - to)
>  		len = spi->regions[idx].size - to;
>  
> +	ret = pm_runtime_resume_and_get(mtd->dev.parent);
> +	if (ret < 0) {
> +		dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
> +		return ret;
> +	}
> +
>  	mutex_lock(&spi->lock);
>  
>  	ret = spi_write(spi, region, to, len, buf);
> @@ -602,6 +627,8 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
>  	*retlen = ret;
>  
>  	mutex_unlock(&spi->lock);
> +	pm_runtime_mark_last_busy(mtd->dev.parent);
> +	pm_runtime_put_autosuspend(mtd->dev.parent);
>  	return 0;
>  }
>  
> @@ -747,6 +774,17 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
>  		}
>  	}
>  
> +	pm_runtime_enable(device);
> +
> +	pm_runtime_set_autosuspend_delay(device, INTEL_DG_SPI_RPM_TIMEOUT);
> +	pm_runtime_use_autosuspend(device);

If the above assumption is right, then I don't believe you
should change the device settings in here.

But if you tell me that this 'device' is the spi one, and not
the graphics dgfx, then I believe this code would be missing
the runtime pm suspend/resume functions.

> +
> +	ret = pm_runtime_resume_and_get(device);
> +	if (ret < 0) {
> +		dev_err(device, "rpm: get failed %d\n", ret);
> +		goto err_norpm;
> +	}
> +
>  	spi->base = devm_ioremap_resource(device, &ispi->bar);
>  	if (IS_ERR(spi->base)) {
>  		dev_err(device, "mmio not mapped\n");
> @@ -769,9 +807,13 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
>  
>  	dev_set_drvdata(&aux_dev->dev, spi);
>  
> +	pm_runtime_put(device);
>  	return 0;
>  
>  err:
> +	pm_runtime_put(device);
> +err_norpm:
> +	pm_runtime_disable(device);
>  	kref_put(&spi->refcnt, intel_dg_spi_release);
>  	return ret;
>  }
> @@ -783,6 +825,8 @@ static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
>  	if (!spi)
>  		return;
>  
> +	pm_runtime_disable(&aux_dev->dev);
> +
>  	mtd_device_unregister(&spi->mtd);
>  
>  	dev_set_drvdata(&aux_dev->dev, NULL);
> -- 
> 2.34.1
> 

  reply	other threads:[~2024-09-16 18:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
2024-09-18 13:33   ` Mark Brown
2024-09-19  9:54     ` Winkler, Tomas
2024-09-19 10:32       ` Mark Brown
2024-09-21 13:00         ` Winkler, Tomas
2024-09-23  8:02           ` Tvrtko Ursulin
2024-09-23 12:49           ` Mark Brown
2024-09-25 12:31             ` Usyskin, Alexander
2024-09-25 13:12               ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 02/12] spi: intel-dg: implement region enumeration Alexander Usyskin
2024-09-18 13:35   ` Mark Brown
2024-09-19  9:55     ` Winkler, Tomas
2024-09-19 10:34       ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 03/12] spi: intel-dg: implement spi access functions Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 04/12] spi: intel-dg: spi register with mtd Alexander Usyskin
2024-09-18 13:38   ` Mark Brown
2024-09-19 10:01     ` Winkler, Tomas
2024-09-19 10:43       ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 05/12] spi: intel-dg: implement mtd access handlers Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 06/12] spi: intel-dg: align 64bit read and write Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 07/12] spi: intel-dg: wake card on operations Alexander Usyskin
2024-09-16 18:00   ` Rodrigo Vivi [this message]
2024-09-16 13:49 ` [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics Alexander Usyskin
2024-09-23  8:31   ` Jani Nikula
2024-09-23 11:33     ` Usyskin, Alexander
2024-09-16 13:49 ` [PATCH v6 09/12] drm/i915/spi: add intel_spi_region map Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 10/12] drm/i915/spi: add support for access mode Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 11/12] drm/xe/spi: add on-die spi device Alexander Usyskin
2024-09-16 18:04   ` Rodrigo Vivi
2024-09-16 13:49 ` [PATCH v6 12/12] drm/xe/spi: add support for access mode Alexander Usyskin
2024-09-18 13:45 ` [PATCH v6 00/12] spi: add driver for Intel discrete graphics Mark Brown
2024-09-19  6:56   ` Usyskin, Alexander
2024-09-19  8:31     ` Mark Brown

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=ZuhyUjDTiMeHSCKO@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=airlied@gmail.com \
    --cc=alexander.usyskin@intel.com \
    --cc=broonie@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-spi@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tomas.winkler@intel.com \
    --cc=tursulin@ursulin.net \
    --cc=tzimmermann@suse.de \
    --cc=vitaly.lubart@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).