linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder.schrempf@exceet.de>
To: linux-mtd@lists.infradead.org, boris.brezillon@bootlin.com,
	linux-spi@vger.kernel.org
Cc: dwmw2@infradead.org, computersforpeace@gmail.com,
	marek.vasut@gmail.com, richard@nod.at, miquel.raynal@bootlin.com,
	broonie@kernel.org, david.wolfe@nxp.com, fabio.estevam@nxp.com,
	prabhakar.kushwaha@nxp.com, yogeshnarayan.gaur@nxp.com,
	han.xu@nxp.com, shawnguo@kernel.org,
	Frieder Schrempf <frieder.schrempf@exceet.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 01/12] spi: spi-mem: Extend the SPI mem interface to set a custom memory name
Date: Thu,  5 Jul 2018 13:14:57 +0200	[thread overview]
Message-ID: <1530789310-16254-2-git-send-email-frieder.schrempf@exceet.de> (raw)
In-Reply-To: <1530789310-16254-1-git-send-email-frieder.schrempf@exceet.de>

When porting (Q)SPI controller drivers from the MTD layer to the SPI
layer, the naming scheme for the memory devices changes. To be able
to keep compatibility with the old drivers naming scheme, a function
is added to the SPI mem interface to let controller drivers set a
custom name for the memory.

Example for the FSL QSPI driver:

Name with the old driver: 21e0000.qspi,
or with multiple devices: 21e0000.qspi-0, 21e0000.qspi-1, ...

Name with the new driver without spi_mem_get_name: spi4.0

Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
---
Changes in v2:
==============
* Add a name field to struct spi_mem and fill it while probing

 drivers/spi/spi-mem.c       | 30 ++++++++++++++++++++++++++++++
 include/linux/spi/spi-mem.h |  7 ++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 990770d..048101c 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -311,6 +311,26 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 EXPORT_SYMBOL_GPL(spi_mem_exec_op);
 
 /**
+ * spi_mem_get_name() - Let drivers using the SPI mem interface specify a
+ *			custom name for the memory to avoid compatibility
+ *			issues with ported drivers.
+ * @mem: the SPI memory
+ *
+ * When porting (Q)SPI controller drivers from the MTD layer to the SPI
+ * layer, the naming scheme for the memory devices changes. To be able to
+ * keep compatibility with the old drivers naming scheme, this function can
+ * be used to get a custom name from the controller driver.
+ * If no custom name is available, the name of the SPI device is returned.
+ *
+ * Return: a char array that contains the name for the flash memory
+ */
+const char *spi_mem_get_name(struct spi_mem *mem)
+{
+	return mem->name;
+}
+EXPORT_SYMBOL_GPL(spi_mem_get_name);
+
+/**
  * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to
  *			      match controller limitations
  * @mem: the SPI memory
@@ -344,6 +364,7 @@ static inline struct spi_mem_driver *to_spi_mem_drv(struct device_driver *drv)
 static int spi_mem_probe(struct spi_device *spi)
 {
 	struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver);
+	struct spi_controller *ctlr = spi->controller;
 	struct spi_mem *mem;
 
 	mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL);
@@ -351,6 +372,15 @@ static int spi_mem_probe(struct spi_device *spi)
 		return -ENOMEM;
 
 	mem->spi = spi;
+
+	if (ctlr->mem_ops && ctlr->mem_ops->get_name)
+		mem->name = ctlr->mem_ops->get_name(mem);
+	else
+		mem->name = dev_name(&spi->dev);
+
+	if (IS_ERR_OR_NULL(mem->name))
+		return PTR_ERR(mem->name);
+
 	spi_set_drvdata(spi, mem);
 
 	return memdrv->probe(mem);
diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
index 4fa34a2..c3f82d1 100644
--- a/include/linux/spi/spi-mem.h
+++ b/include/linux/spi/spi-mem.h
@@ -124,7 +124,8 @@ struct spi_mem_op {
 /**
  * struct spi_mem - describes a SPI memory device
  * @spi: the underlying SPI device
- * @drvpriv: spi_mem_drviver private data
+ * @drvpriv: spi_mem_driver private data
+ * @name: name of the SPI memory device
  *
  * Extra information that describe the SPI memory device and may be needed by
  * the controller to properly handle this device should be placed here.
@@ -135,6 +136,7 @@ struct spi_mem_op {
 struct spi_mem {
 	struct spi_device *spi;
 	void *drvpriv;
+	char *name;
 };
 
 /**
@@ -178,6 +180,7 @@ struct spi_controller_mem_ops {
 			    const struct spi_mem_op *op);
 	int (*exec_op)(struct spi_mem *mem,
 		       const struct spi_mem_op *op);
+	const char *(*get_name)(struct spi_mem *mem);
 };
 
 /**
@@ -236,6 +239,8 @@ bool spi_mem_supports_op(struct spi_mem *mem,
 int spi_mem_exec_op(struct spi_mem *mem,
 		    const struct spi_mem_op *op);
 
+const char *spi_mem_get_name(struct spi_mem *mem);
+
 int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
 				       struct module *owner);
 
-- 
2.7.4

  reply	other threads:[~2018-07-05 11:14 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05 11:14 [PATCH v2 00/12] Port the FSL QSPI driver to the SPI framework Frieder Schrempf
2018-07-05 11:14 ` Frieder Schrempf [this message]
2018-07-05 12:39   ` [PATCH v2 01/12] spi: spi-mem: Extend the SPI mem interface to set a custom memory name Boris Brezillon
2018-07-05 12:50     ` Frieder Schrempf
2018-07-05 11:14 ` [PATCH v2 02/12] mtd: m25p80: Call spi_mem_get_name() to let controller set a custom name Frieder Schrempf
2018-07-05 12:56   ` Boris Brezillon
2018-07-05 13:06     ` Frieder Schrempf
2018-07-05 11:14 ` [PATCH v2 03/12] spi: Add a driver for the Freescale/NXP QuadSPI controller Frieder Schrempf
     [not found]   ` <7e95c72c-2cd1-f138-a687-6cca362c95b7@exceet.de>
2018-08-02 13:09     ` Questions about " Frieder Schrempf
2018-08-02 21:58       ` Han Xu
2018-08-04 13:37         ` Boris Brezillon
2018-09-03  9:02           ` Frieder Schrempf
2018-09-12 17:04             ` Han Xu
2018-09-12 18:40               ` Frieder Schrempf
2018-09-12 21:04                 ` Han Xu
2018-09-13  7:00                   ` Frieder Schrempf
2018-09-18 22:42                     ` Lukasz Majewski
2018-09-19  6:49                       ` Frieder Schrempf
2018-09-19 11:02                         ` Lukasz Majewski
2018-09-20  1:17                           ` Huang Shijie
2018-09-20 15:00                           ` Lukasz Majewski
2018-09-20 15:41                             ` Frieder Schrempf
2018-09-20 20:37                               ` Lukasz Majewski
2018-09-20 22:13                               ` Lukasz Majewski
2018-09-25  6:49                                 ` Frieder Schrempf
2018-09-25  8:53                                   ` Lukasz Majewski
2018-09-06 11:11           ` Yogesh Narayan Gaur
2018-09-06 11:36             ` Boris Brezillon
2018-09-06 12:22               ` Yogesh Narayan Gaur
2018-07-05 11:15 ` [PATCH v2 04/12] dt-bindings: spi: Move the bindings for the FSL QSPI driver Frieder Schrempf
2018-07-11 15:54   ` Rob Herring
2018-07-12  8:11     ` Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 05/12] dt-bindings: spi: Adjust " Frieder Schrempf
2018-07-11 16:05   ` Rob Herring
2018-07-12  8:13     ` Frieder Schrempf
2018-07-12 15:20       ` Rob Herring
2018-07-16  7:04         ` Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 06/12] ARM: dts: Reflect change of FSL QSPI driver and remove unused properties Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 07/12] arm64: " Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 08/12] ARM: defconfig: Use the new FSL QSPI driver under the SPI framework Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 09/12] mtd: fsl-quadspi: Remove the driver as it was replaced by spi-fsl-qspi.c Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 10/12] ARM: dts: ls1021a: Remove fsl,qspi-has-second-chip as it is not used Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 11/12] ARM64: dts: ls1046a: " Frieder Schrempf
2018-07-05 11:15 ` [PATCH v2 12/12] MAINTAINERS: Move the Freescale QSPI driver to the SPI framework Frieder Schrempf
2018-07-06  5:08 ` [PATCH v2 00/12] Port the FSL " Yogesh Narayan Gaur
2018-10-31 13:40 ` Boris Brezillon
2018-10-31 13:54   ` Schrempf Frieder
2018-10-31 14:31     ` Boris Brezillon
2018-10-31 16:03       ` Yogesh Narayan Gaur
2018-10-31 16:09         ` Schrempf Frieder
2018-11-08  8:15       ` Schrempf Frieder
2018-11-08  8:19         ` Boris Brezillon
2018-11-08  8:35           ` Schrempf Frieder
2018-11-08  8:57           ` Schrempf Frieder

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=1530789310-16254-2-git-send-email-frieder.schrempf@exceet.de \
    --to=frieder.schrempf@exceet.de \
    --cc=boris.brezillon@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=david.wolfe@nxp.com \
    --cc=dwmw2@infradead.org \
    --cc=fabio.estevam@nxp.com \
    --cc=han.xu@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=prabhakar.kushwaha@nxp.com \
    --cc=richard@nod.at \
    --cc=shawnguo@kernel.org \
    --cc=yogeshnarayan.gaur@nxp.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).