diff mbox

[v2,02/10] mtd: spi-nor: add a new field for spi_nor{}

Message ID 1398657227-20721-3-git-send-email-b32955@freescale.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Huang Shijie April 28, 2014, 3:53 a.m. UTC
We need the SPI NOR child node to store some specific features, such as the
dummy cycles for the DDR Quad read.

But now, we only have the @dev field in the spi_nor{}. The @dev may points to a
spi_device{} for m25p80, while it may points to a platform_deivice{} for the
SPI NOR controller, such as fsl_quadspi.c.

It is not convenient for us to get come information from the SPI NOR flash.

This patch adds a new field @np to spi_nor{}, it points to the child node for
the SPI NOR flash.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 drivers/mtd/devices/m25p80.c  |    1 +
 drivers/mtd/spi-nor/spi-nor.c |    2 +-
 include/linux/mtd/spi-nor.h   |    3 +++
 3 files changed, 5 insertions(+), 1 deletions(-)

Comments

Marek Vasut April 28, 2014, 8:23 p.m. UTC | #1
On Monday, April 28, 2014 at 05:53:39 AM, Huang Shijie wrote:
> We need the SPI NOR child node to store some specific features, such as the
> dummy cycles for the DDR Quad read.
> 
> But now, we only have the @dev field in the spi_nor{}. The @dev may points
> to a spi_device{} for m25p80, while it may points to a platform_deivice{}
> for the SPI NOR controller, such as fsl_quadspi.c.
> 
> It is not convenient for us to get come information from the SPI NOR flash.
> 
> This patch adds a new field @np to spi_nor{}, it points to the child node
> for the SPI NOR flash.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>

Just handle the case where dev->of_node == NULL instead ?

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Huang Shijie April 29, 2014, 5:18 a.m. UTC | #2
On Mon, Apr 28, 2014 at 10:23:26PM +0200, Marek Vasut wrote:
> On Monday, April 28, 2014 at 05:53:39 AM, Huang Shijie wrote:
> > We need the SPI NOR child node to store some specific features, such as the
> > dummy cycles for the DDR Quad read.
> > 
> > But now, we only have the @dev field in the spi_nor{}. The @dev may points
> > to a spi_device{} for m25p80, while it may points to a platform_deivice{}
> > for the SPI NOR controller, such as fsl_quadspi.c.
> > 
> > It is not convenient for us to get come information from the SPI NOR flash.
> > 
> > This patch adds a new field @np to spi_nor{}, it points to the child node
> > for the SPI NOR flash.
> > 
> > Signed-off-by: Huang Shijie <b32955@freescale.com>
> 
> Just handle the case where dev->of_node == NULL instead ?
It is not enough. 

For the m25p80.c, @dev stands for a child node for the SPI master,
and it points to a spi_device{}. Yes, in this case, the dev->of_node is NULL.

But for the fsl_quadspi or other SPI NOR drivers, the @dev stands for the controller
itself, the @dev->of_node is a list of the child nodes, so we can _NOT_ know which
child node we are working at now.


So it's better to add a new field @np for the spi-nor{} which points the
child node we are working at.

thanks
Huang Shijie


--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Huang Shijie April 29, 2014, 6:05 a.m. UTC | #3
On Tue, Apr 29, 2014 at 08:54:24AM +0200, Marek Vasut wrote:
> On Tuesday, April 29, 2014 at 07:18:34 AM, Huang Shijie wrote:
> > For the m25p80.c, @dev stands for a child node for the SPI master,
> > and it points to a spi_device{}. Yes, in this case, the dev->of_node is
> > NULL.
> > 
> > But for the fsl_quadspi or other SPI NOR drivers, the @dev stands for the
> > controller itself, the @dev->of_node is a list of the child nodes, so we
> > can _NOT_ know which child node we are working at now.
> 
> Huh ? The dev is being recycled for two different kind of things ?
yes.

for the SPI bus, the of_register_spi_devices() will allocate a spi_device{}
for each child node for the SPI NOR flash. So in the m25p80.c, the @dev points
to a spi_device{}.

For the simplicity,  we do not allocate any *_device{} for the child
node in the SPI NOR flash driver, such as in the fsl-quadspi.c.

thanks
Huang Shijie

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marek Vasut April 29, 2014, 6:54 a.m. UTC | #4
On Tuesday, April 29, 2014 at 07:18:34 AM, Huang Shijie wrote:
> On Mon, Apr 28, 2014 at 10:23:26PM +0200, Marek Vasut wrote:
> > On Monday, April 28, 2014 at 05:53:39 AM, Huang Shijie wrote:
> > > We need the SPI NOR child node to store some specific features, such as
> > > the dummy cycles for the DDR Quad read.
> > > 
> > > But now, we only have the @dev field in the spi_nor{}. The @dev may
> > > points to a spi_device{} for m25p80, while it may points to a
> > > platform_deivice{} for the SPI NOR controller, such as fsl_quadspi.c.
> > > 
> > > It is not convenient for us to get come information from the SPI NOR
> > > flash.
> > > 
> > > This patch adds a new field @np to spi_nor{}, it points to the child
> > > node for the SPI NOR flash.
> > > 
> > > Signed-off-by: Huang Shijie <b32955@freescale.com>
> > 
> > Just handle the case where dev->of_node == NULL instead ?
> 
> It is not enough.
> 
> For the m25p80.c, @dev stands for a child node for the SPI master,
> and it points to a spi_device{}. Yes, in this case, the dev->of_node is
> NULL.
> 
> But for the fsl_quadspi or other SPI NOR drivers, the @dev stands for the
> controller itself, the @dev->of_node is a list of the child nodes, so we
> can _NOT_ know which child node we are working at now.

Huh ? The dev is being recycled for two different kind of things ?

> So it's better to add a new field @np for the spi-nor{} which points the
> child node we are working at.

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 3a1d9e0..f996c3a 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -215,6 +215,7 @@  static int m25p_probe(struct spi_device *spi)
 	nor->read_reg = m25p80_read_reg;
 
 	nor->dev = &spi->dev;
+	nor->np = spi->dev.of_node;
 	nor->mtd = &flash->mtd;
 	nor->priv = flash;
 
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1a12f81..f374e44 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -891,7 +891,7 @@  int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
 	struct flash_platform_data	*data;
 	struct device *dev = nor->dev;
 	struct mtd_info *mtd = nor->mtd;
-	struct device_node *np = dev->of_node;
+	struct device_node *np = nor->np;
 	int ret;
 	int i;
 
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 5324184..48fe9fc 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -117,6 +117,8 @@  enum spi_nor_ops {
  * @mtd:		point to a mtd_info structure
  * @lock:		the lock for the read/write/erase/lock/unlock operations
  * @dev:		point to a spi device, or a spi nor controller device.
+ * @np:			If exit, it points to a device_node which stands for the
+ *			SPI NOR flash child node.
  * @page_size:		the page size of the SPI NOR
  * @addr_width:		number of address bytes
  * @erase_opcode:	the opcode for erasing a sector
@@ -148,6 +150,7 @@  struct spi_nor {
 	struct mtd_info		*mtd;
 	struct mutex		lock;
 	struct device		*dev;
+	struct device_node	*np;
 	u32			page_size;
 	u8			addr_width;
 	u8			erase_opcode;