linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Wei Yongjun <weiyongjun1@huawei.com>,
	Mark Brown <broonie@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH -next 3/4] spi: mockup: Add runtime device tree overlay interface
Date: Mon, 29 Aug 2022 16:29:50 -0500	[thread overview]
Message-ID: <8c436553-e35c-4e46-1407-24184fd113ba@gmail.com> (raw)
In-Reply-To: <20220826144341.532265-4-weiyongjun1@huawei.com>

comment inline below, plus adding to cc: and to: list

On 8/26/22 09:43, Wei Yongjun wrote:
> Add a runtime device tree overlay interface for device need dts file.
> With it its possible to use device tree overlays without having to use
> a per-platform overlay manager.

Why is an overlay needed?  The documentation in patch 4 shows providing
a dtb as an argument to the qemu-system-x86_64 command, which should be
sufficient to supply the appropriate dtb.

-Frank

> 
> Add a new device by command:
> $ cat test.dtbo > /sys/class/spi_master/spi0/overlay_fdto
> 
> Remove the device by command:
> $ echo remove > /sys/class/spi_master/spi0/overlay_fdto
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  drivers/spi/Kconfig      |  2 ++
>  drivers/spi/spi-mockup.c | 48 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index e0f0fa2746ad..4b7c84ddb367 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -1161,6 +1161,8 @@ config SPI_TLE62X0
>  config SPI_MOCKUP
>  	tristate "SPI controller Testing Driver"
>  	depends on OF
> +	select OF_EARLY_FLATTREE
> +	select OF_RESOLVE
>  	select BPF_EVENTS
>  	help
>  	  This enables SPI controller testing driver, which provides a way to
> diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
> index 7a93b194ee53..404ad821bf6a 100644
> --- a/drivers/spi/spi-mockup.c
> +++ b/drivers/spi/spi-mockup.c
> @@ -21,6 +21,9 @@
>  struct mockup_spi {
>  	struct mutex lock;
>  	struct spi_device *devs[MOCKUP_CHIPSELECT_MAX];
> +
> +	void *fdto;
> +	int ovcs_id;
>  };
>  
>  static struct spi_master *to_spi_master(struct device *dev)
> @@ -145,9 +148,53 @@ delete_device_store(struct device *dev, struct device_attribute *attr,
>  }
>  static DEVICE_ATTR_WO(delete_device);
>  
> +static ssize_t
> +overlay_fdto_store(struct device *dev, struct device_attribute *attr,
> +		   const char *buf, size_t count)
> +{
> +	struct spi_master *master = to_spi_master(dev);
> +	struct mockup_spi *mock = spi_master_get_devdata(master);
> +	int ret;
> +
> +	mutex_lock(&mock->lock);
> +
> +	if (strncmp(buf, "remove\n", count) == 0) {
> +		if (mock->ovcs_id < 0) {
> +			ret = -ENOENT;
> +			goto out_unlock;
> +		}
> +		of_overlay_remove(&mock->ovcs_id);
> +		kfree(mock->fdto);
> +		mock->ovcs_id = -1;
> +		mock->fdto = NULL;
> +	} else {
> +		if (mock->ovcs_id >= 0) {
> +			ret = -EINVAL;
> +			goto out_unlock;
> +		}
> +		mock->fdto = kmemdup(buf, count, GFP_KERNEL);
> +		if (!mock->fdto) {
> +			ret = -ENOMEM;
> +			goto out_unlock;
> +		}
> +		ret = of_overlay_fdt_apply(mock->fdto, count, &mock->ovcs_id);
> +		if (ret < 0)
> +			goto out_unlock;
> +	}
> +
> +	mutex_unlock(&mock->lock);
> +	return count;
> +
> +out_unlock:
> +	mutex_unlock(&mock->lock);
> +	return ret;
> +}
> +static DEVICE_ATTR_WO(overlay_fdto);
> +
>  static struct attribute *spi_mockup_attrs[] = {
>  	&dev_attr_new_device.attr,
>  	&dev_attr_delete_device.attr,
> +	&dev_attr_overlay_fdto.attr,
>  	NULL
>  };
>  ATTRIBUTE_GROUPS(spi_mockup);
> @@ -227,6 +274,7 @@ static int spi_mockup_probe(struct platform_device *pdev)
>  
>  	mock = spi_master_get_devdata(master);
>  	mutex_init(&mock->lock);
> +	mock->ovcs_id = -1;
>  
>  	ret = spi_register_master(master);
>  	if (ret) {


  reply	other threads:[~2022-08-29 21:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 14:43 [PATCH -next 0/4] spi: Introduce BPF based SPI mockup controller Wei Yongjun
2022-08-26 14:43 ` [PATCH -next 1/4] spi: mockup: Add SPI controller testing driver Wei Yongjun
2022-08-30 19:11   ` Mark Brown
2022-08-31  4:39     ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 2/4] spi: mockup: Add writeable tracepoint for spi transfer Wei Yongjun
2022-08-30 18:14   ` Mark Brown
2022-08-31  4:43     ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 3/4] spi: mockup: Add runtime device tree overlay interface Wei Yongjun
2022-08-29 21:29   ` Frank Rowand [this message]
2022-08-30  3:05     ` weiyongjun (A)
2022-08-30 10:27   ` Mark Brown
2022-08-30 19:24     ` Frank Rowand
2022-08-31  4:44       ` weiyongjun (A)
2022-08-26 14:43 ` [PATCH -next 4/4] spi: mockup: Add documentation Wei Yongjun
2022-08-30 18:21   ` Mark Brown
2022-08-30 19:08 ` [PATCH -next 0/4] spi: Introduce BPF based SPI mockup controller Mark Brown
2022-09-01 10:38   ` Mark Brown
2022-09-01 12:23   ` weiyongjun (A)

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=8c436553-e35c-4e46-1407-24184fd113ba@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=weiyongjun1@huawei.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).