Skip to contentSkip to conversation

spi/mpc5121: register spi child devices of spi node

PATCH In review Anatolij Gustschin 5 participants 19 messages Jul 26, 2010 – Jul 27, 2010 10 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi/mpc5121: register spi child devices of spi node

---
 drivers/spi/mpc512x_psc_spi.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/spi/mpc512x_psc_spi.c +9 -1
index c8d69fc..39e5faf 100644
@@ -27,6 +27,7 @@
 #include <linux/clk.h>
 #include <linux/spi/spi.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_spi.h>
 #include <asm/mpc52xx_psc.h>
 
 struct mpc512x_psc_spi {
@@ -511,6 +512,7 @@ static int __devinit mpc512x_psc_spi_of_probe(struct of_device *op,
 	const u32 *regaddr_p;
 	u64 regaddr64, size64;
 	s16 id = -1;
+	int ret;
 
 	regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
 	if (!regaddr_p) {
@@ -533,8 +535,14 @@ static int __devinit mpc512x_psc_spi_of_probe(struct of_device *op,
 		id = *psc_nump;
 	}
 
-	return mpc512x_psc_spi_do_probe(&op->dev, (u32) regaddr64, (u32) size64,
+	ret = mpc512x_psc_spi_do_probe(&op->dev, (u32) regaddr64, (u32) size64,
 				irq_of_parse_and_map(op->dev.of_node, 0), id);
+
+	if (!ret)
+		of_register_spi_devices(dev_get_drvdata(&op->dev),
+					op->dev.of_node);
+
+	return ret;
 }
 
 static int __devexit mpc512x_psc_spi_of_remove(struct of_device *op)
Signature · 9 lines
1.7.0.4


------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
#2 lore raw
In reply to a message not in the archive

Hi Anatolij,

Quoted 4 lines · Anatolij Gustschin
---
 drivers/spi/mpc512x_psc_spi.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

You should CC Grant Likely on this. He is now the de-facto maintainer of the SPI subsystem.

baruch

Quoted 50 lines
drivers/spi/mpc512x_psc_spi.c +9 -1
index c8d69fc..39e5faf 100644
@@ -27,6 +27,7 @@
 #include <linux/clk.h>
 #include <linux/spi/spi.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_spi.h>
 #include <asm/mpc52xx_psc.h>
 
 struct mpc512x_psc_spi {
@@ -511,6 +512,7 @@ static int __devinit mpc512x_psc_spi_of_probe(struct of_device *op,
 	const u32 *regaddr_p;
 	u64 regaddr64, size64;
 	s16 id = -1;
+	int ret;
 
 	regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
 	if (!regaddr_p) {
@@ -533,8 +535,14 @@ static int __devinit mpc512x_psc_spi_of_probe(struct of_device *op,
 		id = *psc_nump;
 	}
 
-	return mpc512x_psc_spi_do_probe(&op->dev, (u32) regaddr64, (u32) size64,
+	ret = mpc512x_psc_spi_do_probe(&op->dev, (u32) regaddr64, (u32) size64,
 				irq_of_parse_and_map(op->dev.of_node, 0), id);
+
+	if (!ret)
+		of_register_spi_devices(dev_get_drvdata(&op->dev),
+					op->dev.of_node);
+
+	return ret;
 }
 
 static int __devexit mpc512x_psc_spi_of_remove(struct of_device *op)
Signature · 13 lines
1.7.0.4


------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
spi-devel-general mailing list
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Signature · 10 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
#4 lore raw
In reply to a message not in the archive
Quoted 10 lines · Baruch Siach

Hi Anatolij,

Quoted 4 lines · Anatolij Gustschin

---
 drivers/spi/mpc512x_psc_spi.c |   10 +++++++++-

 1 files changed, 9 insertions(+), 1 deletions(-)

You should CC Grant Likely on this. He is now the de-facto maintainer of the SPI subsystem.

He did cc me.

g.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#5 lore raw
In reply to a message not in the archive

There are things wrong with the concept of this particular patch. First, that it's mpc5121-only. Second, that it's not already handled as part of registering the platform's SPI devices.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#7 lore raw
In reply to a message not in the archive
Quoted 4 lines · David Brownell

There are things wrong with the concept of this particular patch.  First, that it's mpc5121-only. Second, that it's not already handled as part of registering the platform's SPI devices.

The reason is that in this use case the platform code doesn't provide a list of spi devices. The list of devices is contained in the flattened device tree, and the data is parsed after the spi bus is created.

But you're right; the fact that each driver has to explicitly call this function is a problem. I plan to write a patch to remove all those calls in each driver and call it from the core spi core instead.

g.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#9 lore raw
In reply to a message not in the archive
Quoted 10 lines
Quoted 3 lines

Second, that it's not already handled as part of
registering the platform's SPI devices.

The reason is that in this use case
the platform code doesn't provide
a list of spi devices.  The list of devices is contained in the
flattened device tree, and the data is parsed after the spi bus is created.

That's part of the (OF) platform code, then ...

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#16 lore raw
In reply to Feng Tang
Quoted 10 lines · Feng Tang
Quoted 6 lines · On Tue, 27 Jul 2010 14:28:57 +0800 David Brownell…

There are things wrong with the concept of this particular patch.  First, that it's mpc5121-only. Second, that it's not already handled as part of registering the platform's SPI devices.

Quoted 8 lines

Hi David, Grant,

This actually brings up another topic: currently spi_register_board_info() has to be called before spi controller(master) get inited. But in some case, to solve some device dependency issue, some spi slave device need be delayed registering, can we adjust it to make register_board_info() be callable after spi controller is inited? Which makes spi bus like general pci/usb bus, where devices/drivers have no registering order limit.

Is spi_alloc_device()/spi_add_device() not suitable for your use-case?

g.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#20 lore raw
In reply to Feng Tang
Quoted 6 lines · Feng Tang

be delayed registering, can we adjust it to make register_board_info()
be callable after spi controller is inited? Which makes spi bus like
general pci/usb bus, where devices/drivers have no registering order limit.

They require parents to be registered before children. In particular: bus segments before devices on them. SPI is no different (nor should it be).

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#15 lore raw
In reply to a message not in the archive
Quoted 6 lines · On Tue, 27 Jul 2010 14:28:57 +0800 David Brownell…

There are things wrong with the concept of this particular patch. First, that it's mpc5121-only. Second, that it's not already handled as part of registering the platform's SPI devices.

Hi David, Grant,

This actually brings up another topic: currently spi_register_board_info() has to be called before spi controller(master) get inited. But in some case, to solve some device dependency issue, some spi slave device need be delayed registering, can we adjust it to make register_board_info() be callable after spi controller is inited? Which makes spi bus like general pci/usb bus, where devices/drivers have no registering order limit.

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#19 lore raw
In reply to Feng Tang
Quoted 4 lines · Feng Tang
Quoted 1 line
Quoted 1 line

know which spi_master it is connecting to, while our platform need kind
of blind registering (just register something to spi-bus).

Sounding worse and worse. each device is going to be connected to one specific controller, not some random one. Get setup right, or the hardware will be impossible to program correctly.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#18 lore raw
In reply to a message not in the archive
Quoted 23 lines · On Tue, 27 Jul 2010 15:00:29 +0800 Grant Likely…
Quoted 12 lines · Feng Tang
Quoted 6 lines · On Tue, 27 Jul 2010 14:28:57 +0800 David Brownell…

There are things wrong with the concept of this particular patch.  First, that it's mpc5121-only. Second, that it's not already handled as part of registering the platform's SPI devices.

Hi David, Grant,

Quoted 8 lines

This actually brings up another topic: currently spi_register_board_info() has to be called before spi controller(master) get inited. But in some case, to solve some device dependency issue, some spi slave device need be delayed registering, can we adjust it to make register_board_info() be callable after spi controller is inited? Which makes spi bus like general pci/usb bus, where devices/drivers have no registering order limit.

Quoted 3 lines

Is spi_alloc_device()/spi_add_device() not suitable for your use-case?

g.

Yes, I've thought about that, but spi_alloc_device() is called when you know which spi_master it is connecting to, while our platform need kind of blind registering (just register something to spi-bus).

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#23 lore raw
In reply to Feng Tang
Quoted 8 lines · Feng Tang

What I want to say is the matching mechanism between spi board info
and spi master, currently they use bus number to match, but there is
a ordering limit now. For general device/driver matching in linux
device model, there is no such limit. Is it possible to remove the order limit?

I have no idea what you mean. Are you proposing to change how SPI busses are identified? Lots of busses are numbered, SPI isn't unique; a device on PCI bus #2 is different from one on bus #1, etc.

What do you mean by "order limit" ????

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#22 lore raw
In reply to a message not in the archive
Quoted 11 lines · On Tue, 27 Jul 2010 15:07:28 +0800 David Brownell…
Quoted 6 lines · Feng Tang

be delayed registering, can we adjust it to make register_board_info()
be callable after spi controller is inited? Which makes spi bus like
general pci/usb bus, where devices/drivers have no registering order limit.

Quoted 4 lines

They require parents to be registered before children. In particular: bus segments before devices on them. SPI is no different (nor should it be).

Sorry, I made a wrong example.

What I want to say is the matching mechanism between spi board info and spi master, currently they use bus number to match, but there is a ordering limit now. For general device/driver matching in linux device model, there is no such limit. Is it possible to remove the order limit?

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#26 lore raw
In reply to Feng Tang
Quoted 8 lines · Feng Tang

In current spi core, spi_register_info() has to be
called before the spi controller driver call spi_register_master(),
then these board info will be matched and used to create a new spi device.

But if spi_register_info() are called after its related spi master is registered, then these info will be ignored
and never get to create a new spi device.

That doesn't seem necessary. Got patch?

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#25 lore raw
In reply to a message not in the archive
Quoted 14 lines · On Tue, 27 Jul 2010 15:27:50 +0800 David Brownell…
Quoted 8 lines · Feng Tang

What I want to say is the matching mechanism between spi board info
and spi master, currently they use bus number to match, but there is
a ordering limit now. For general device/driver matching in linux
device model, there is no such limit. Is it possible to remove the order limit?

Quoted 7 lines

I have no idea what you mean. Are you proposing to change how SPI busses are identified? Lots of busses are numbered, SPI isn't unique; a device on PCI bus #2 is different from one on bus #1, etc.

What do you mean by "order limit" ????

In current spi core, spi_register_info() has to be called before the spi controller driver call spi_register_master(), then these board info will be matched and used to create a new spi device.

But if spi_register_info() are called after its related spi master is registered, then these info will be ignored and never get to create a new spi device.

This is the "order limit" I want to describe :)

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#28 lore raw
In reply to a message not in the archive
Quoted 12 lines · On Tue, 27 Jul 2010 15:44:48 +0800 David Brownell…
Quoted 6 lines · Feng Tang

In current spi core, spi_register_info() has to be called before the spi controller driver call spi_register_master(),
then these board info will be matched and used to create a new spi device.

Quoted 7 lines
Quoted 3 lines

But if spi_register_info() are called after its related spi master is registered, then these info will be ignored
and never get to create a new spi device.

That doesn't seem necessary. Got patch?

I would first discuss it on mail list and get bless from you two.

I will try to make one patch.

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

#10 lore raw

PATCH 1/1 of/spi: call of_register_spi_devices() from spi core code

In reply to a message not in the archive

Move of_register_spi_devices() call from some drivers to spi_register_master(). Also change the function to use the struct device_node pointer from master spi device instead of passing it as function argument.

Since xilinx_spi_of.c and spi_ppc4xx.c drivers do not use spi_register_master(), they still call of_register_spi_devices() directly. Maybe these drivers should be reworked later.

Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
---
 drivers/of/of_spi.c           |    7 +++----
 drivers/spi/mpc52xx_psc_spi.c |    9 +--------
 drivers/spi/mpc52xx_spi.c     |    2 --
 drivers/spi/spi.c             |    5 +++++
 drivers/spi/spi_mpc8xxx.c     |    3 ---
 drivers/spi/spi_ppc4xx.c      |    3 ++-
 drivers/spi/xilinx_spi.c      |    1 +
 drivers/spi/xilinx_spi_of.c   |    2 +-
 include/linux/of_spi.h        |   11 ++++++++---
 9 files changed, 21 insertions(+), 22 deletions(-)
drivers/of/of_spi.c +3 -4
index d504f1d..76a0529 100644
@@ -15,12 +15,11 @@
 /**
  * of_register_spi_devices - Register child devices onto the SPI bus
  * @master:	Pointer to spi_master device
- * @np:		parent node of SPI device nodes
  *
- * Registers an spi_device for each child node of 'np' which has a 'reg'
+ * Registers an spi_device for each child node of master node which has a 'reg'
  * property.
  */
-void of_register_spi_devices(struct spi_master *master, struct device_node *np)
+void of_register_spi_devices(struct spi_master *master)
 {
 	struct spi_device *spi;
 	struct device_node *nc;
@@ -28,7 +27,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
 	int rc;
 	int len;
 
-	for_each_child_of_node(np, nc) {
+	for_each_child_of_node(master->dev.of_node, nc) {
 		/* Alloc an spi_device */
 		spi = spi_alloc_device(master);
 		if (!spi) {
drivers/spi/mpc52xx_psc_spi.c +1 -8
index 7104cb7..a6eb5d4 100644
@@ -17,7 +17,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/of_platform.h>
-#include <linux/of_spi.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/io.h>
@@ -470,7 +469,6 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
 	const u32 *regaddr_p;
 	u64 regaddr64, size64;
 	s16 id = -1;
-	int rc;
 
 	regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
 	if (!regaddr_p) {
@@ -491,13 +489,8 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
 		id = *psc_nump + 1;
 	}
 
-	rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+	return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
 				irq_of_parse_and_map(op->dev.of_node, 0), id);
-	if (rc == 0)
-		of_register_spi_devices(dev_get_drvdata(&op->dev),
-					op->dev.of_node);
-
-	return rc;
 }
 
 static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
drivers/spi/mpc52xx_spi.c +0 -2
index b1a76bf..18e1c86 100644
@@ -18,7 +18,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
-#include <linux/of_spi.h>
 #include <linux/io.h>
 #include <linux/of_gpio.h>
 #include <linux/slab.h>
@@ -512,7 +511,6 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
 	if (rc)
 		goto err_register;
 
-	of_register_spi_devices(master, op->dev.of_node);
 	dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
 
 	return rc;
drivers/spi/spi.c +5 -0
index fdde706..626fa48 100644
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spi/spi.h>
+#include <linux/of_spi.h>
 
 
 /* SPI bustype and spi_master class are registered after board init code
@@ -544,6 +545,10 @@ int spi_register_master(struct spi_master *master)
 	/* populate children from any spi device tables */
 	scan_boardinfo(master);
 	status = 0;
+
+	/* Register devices from the device tree */
+	master->dev.of_node = dev->of_node;
+	of_register_spi_devices(master);
 done:
 	return status;
 }
drivers/spi/spi_mpc8xxx.c +0 -3
index 97ab0a8..89fea11 100644
@@ -38,7 +38,6 @@
 #include <linux/of_platform.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/of_spi.h>
 #include <linux/slab.h>
 
 #include <sysdev/fsl_soc.h>
@@ -1299,8 +1298,6 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
 		goto err;
 	}
 
-	of_register_spi_devices(master, np);
-
 	return 0;
 
 err:
drivers/spi/spi_ppc4xx.c +2 -1
index d53466a..0bcea55 100644
@@ -545,7 +545,8 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
 	}
 
 	dev_info(dev, "driver initialized\n");
-	of_register_spi_devices(master, np);
+	master->dev.of_node = np;
+	of_register_spi_devices(master);
 
 	return 0;
 
drivers/spi/xilinx_spi.c +1 -0
index 1b47363..d101a84 100644
@@ -390,6 +390,7 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 
 	master->bus_num = bus_num;
 	master->num_chipselect = pdata->num_chipselect;
+	master->dev.of_node = dev->of_node;
 
 	xspi->mem = *mem;
 	xspi->irq = irq;
drivers/spi/xilinx_spi_of.c +1 -1
index 4654805..0295bbf 100644
@@ -81,7 +81,7 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
 	dev_set_drvdata(&ofdev->dev, master);
 
 	/* Add any subnodes on the SPI bus */
-	of_register_spi_devices(master, ofdev->dev.of_node);
+	of_register_spi_devices(master);
 
 	return 0;
 }
include/linux/of_spi.h +8 -3
index 5f71ee8..9e3e70f 100644
@@ -9,10 +9,15 @@
 #ifndef __LINUX_OF_SPI_H
 #define __LINUX_OF_SPI_H
 
-#include <linux/of.h>
 #include <linux/spi/spi.h>
 
-extern void of_register_spi_devices(struct spi_master *master,
-				    struct device_node *np);
+#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
+extern void of_register_spi_devices(struct spi_master *master);
+#else
+static inline void of_register_spi_devices(struct spi_master *master)
+{
+	return;
+}
+#endif /* CONFIG_OF_SPI */
 
 #endif /* __LINUX_OF_SPI */
Signature · 1 line
1.7.0.4
#12 lore raw

Re: [PATCH] of/spi: call of_register_spi_devices() from spi core code

In reply to a message not in the archive
Quoted 45 lines · Anatolij Gustschin

Move of_register_spi_devices() call from some drivers to spi_register_master(). Also change the function to use the struct device_node pointer from master spi device instead of passing it as function argument.

Since xilinx_spi_of.c and spi_ppc4xx.c drivers do not use spi_register_master(), they still call of_register_spi_devices() directly. Maybe these drivers should be reworked later.

Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]

---
 drivers/of/of_spi.c           |    7 +++----
 drivers/spi/mpc52xx_psc_spi.c |    9 +--------
 drivers/spi/mpc52xx_spi.c     |    2 --
 drivers/spi/spi.c             |    5 +++++
 drivers/spi/spi_mpc8xxx.c     |    3 ---
 drivers/spi/spi_ppc4xx.c      |    3 ++-
 drivers/spi/xilinx_spi.c      |    1 +
 drivers/spi/xilinx_spi_of.c   |    2 +-
 include/linux/of_spi.h        |   11 ++++++++---

 9 files changed, 21 insertions(+), 22 deletions(-)
drivers/of/of_spi.c +2 -3
index d504f1d..76a0529 100644
@@ -15,12 +15,11 @@
  /**
  * of_register_spi_devices - Register child devices onto the SPI bus
  * @master:    Pointer to spi_master device
- * @np:                parent node of SPI device nodes
  *
- * Registers an spi_device for each child node of 'np' which has a 'reg'
+ * Registers an spi_device for each child node of master node which has a 'reg'
  * property.
  */
-void of_register_spi_devices(struct spi_master *master, struct device_node *np)
+void of_register_spi_devices(struct spi_master *master)
  {
        struct spi_device *spi;
        struct device_node *nc;

drivers/of/of_spi.c void of_register_spi_devices(struct spi_master *master, struct device_node *np) · line 28

Quoted 2 lines
drivers/of/of_spi.c +0 -0
@@ -28,7 +27,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
        int rc;
        int len;

if (!master->dev.of_node)

	return;
Quoted 74 lines
drivers/of/of_spi.c +1 -1
-       for_each_child_of_node(np, nc) {
+       for_each_child_of_node(master->dev.of_node, nc) {
                /* Alloc an spi_device */
                spi = spi_alloc_device(master);
                if (!spi) {
drivers/spi/mpc52xx_psc_spi.c +1 -8
index 7104cb7..a6eb5d4 100644
@@ -17,7 +17,6 @@
  #include <linux/errno.h>
  #include <linux/interrupt.h>
  #include <linux/of_platform.h>
-#include <linux/of_spi.h>
  #include <linux/workqueue.h>
  #include <linux/completion.h>
  #include <linux/io.h>
@@ -470,7 +469,6 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
        const u32 *regaddr_p;
        u64 regaddr64, size64;
        s16 id = -1;
-       int rc;
 
        regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
        if (!regaddr_p) {
@@ -491,13 +489,8 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
                id = *psc_nump + 1;
        }
 
-       rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+       return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
                                irq_of_parse_and_map(op->dev.of_node, 0), id);
-       if (rc == 0)
-               of_register_spi_devices(dev_get_drvdata(&op->dev),
-                                       op->dev.of_node);
-
-       return rc;
  }
 
  static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
drivers/spi/mpc52xx_spi.c +0 -2
index b1a76bf..18e1c86 100644
@@ -18,7 +18,6 @@
  #include <linux/interrupt.h>
  #include <linux/delay.h>
  #include <linux/spi/spi.h>
-#include <linux/of_spi.h>
  #include <linux/io.h>
  #include <linux/of_gpio.h>
  #include <linux/slab.h>
@@ -512,7 +511,6 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
        if (rc)
                goto err_register;
 
-       of_register_spi_devices(master, op->dev.of_node);
        dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
 
        return rc;
drivers/spi/spi.c +1 -0
index fdde706..626fa48 100644
@@ -26,6 +26,7 @@
  #include <linux/slab.h>
  #include <linux/mod_devicetable.h>
  #include <linux/spi/spi.h>
+#include <linux/of_spi.h>
 
 
  /* SPI bustype and spi_master class are registered after board init code

drivers/spi/spi.c int spi_register_master(struct spi_master *master) · line 550

Quoted 6 lines
drivers/spi/spi.c +3 -0
@@ -544,6 +545,10 @@ int spi_register_master(struct spi_master *master)
        /* populate children from any spi device tables */
        scan_boardinfo(master);
        status = 0;
+
+       /* Register devices from the device tree */
+       master->dev.of_node = dev->of_node;

Drop this line. There must be a way for drivers to override the behaviour. On i2c I solved this by still requiring the driver to copy the of_node pointer into the master's dev structure. That gives drivers the option to use another node for the list of spi child devices or to skip broken spi busses.

So this line should still appear in each of the OF-aware SPI bus drivers.

Quoted 30 lines
drivers/spi/spi.c +1 -0
+       of_register_spi_devices(master);

 done:
       return status;
 }

drivers/spi/spi_mpc8xxx.c +0 -3
index 97ab0a8..89fea11 100644
@@ -38,7 +38,6 @@
  #include <linux/of_platform.h>
  #include <linux/gpio.h>
  #include <linux/of_gpio.h>
-#include <linux/of_spi.h>
  #include <linux/slab.h>
 
  #include <sysdev/fsl_soc.h>
@@ -1299,8 +1298,6 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
                goto err;
        }
 
-       of_register_spi_devices(master, np);
-
        return 0;
 

 err:

drivers/spi/spi_ppc4xx.c +0 -0
index d53466a..0bcea55 100644

drivers/spi/spi_ppc4xx.c static int __init spi_ppc4xx_of_probe(struct of_device *op, · line 549

Quoted 6 lines
drivers/spi/spi_ppc4xx.c +2 -1
@@ -545,7 +545,8 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
        }
 
        dev_info(dev, "driver initialized\n");
-       of_register_spi_devices(master, np);
+       master->dev.of_node = np;
+       of_register_spi_devices(master);

You can drop these lines. This drivers calls spi_bitbang_start, which in turn calls spi_register_master().

Quoted 20 lines
drivers/spi/spi_ppc4xx.c +0 -0
        return 0;
 
drivers/spi/xilinx_spi.c +1 -0
index 1b47363..d101a84 100644
@@ -390,6 +390,7 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 
        master->bus_num = bus_num;
        master->num_chipselect = pdata->num_chipselect;
+       master->dev.of_node = dev->of_node;
 
        xspi->mem = *mem;
        xspi->irq = irq;
drivers/spi/xilinx_spi_of.c +0 -0
index 4654805..0295bbf 100644

drivers/spi/xilinx_spi_of.c static int __devinit xilinx_spi_of_probe(struct of_device *ofdev, · line 84

Quoted 5 lines
drivers/spi/xilinx_spi_of.c +1 -1
@@ -81,7 +81,7 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
        dev_set_drvdata(&ofdev->dev, master);
 
        /* Add any subnodes on the SPI bus */
-       of_register_spi_devices(master, ofdev->dev.of_node);
+       of_register_spi_devices(master);

Ditto here, spi_bitbang_start() is used by this driver.

Overall though, this is the right direction. Thanks!

g.

Quoted 30 lines
drivers/spi/xilinx_spi_of.c +0 -0
        return 0;
  }
include/linux/of_spi.h +8 -4
index 5f71ee8..9e3e70f 100644
@@ -9,10 +9,15 @@
  #ifndef __LINUX_OF_SPI_H
  #define __LINUX_OF_SPI_H
 
-#include <linux/of.h>
  #include <linux/spi/spi.h>
 
-extern void of_register_spi_devices(struct spi_master *master,
-                                   struct device_node *np);
+#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
+extern void of_register_spi_devices(struct spi_master *master);
+#else
+static inline void of_register_spi_devices(struct spi_master *master)
+{
+       return;
+}
+#endif /* CONFIG_OF_SPI */
 
  #endif /* __LINUX_OF_SPI */
--

1.7.0.4

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#14 lore raw

PATCH v2 1/1 of/spi: call of_register_spi_devices() from spi core code

In reply to a message not in the archive

Move of_register_spi_devices() call from drivers to spi_register_master(). Also change the function to use the struct device_node pointer from master spi device instead of passing it as function argument.

Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]

---
Changes in v2 as requested by Grant:

- check master->dev.of_node to prevent potential null pointer dereference
- set master->dev.of_node in OF-aware SPI bus drivers
- also drop of_register_spi_devices() in xilinx_spi_of.c and spi_ppc4xx.c drivers

 drivers/of/of_spi.c           |   10 ++++++----
 drivers/spi/mpc512x_psc_spi.c |    1 +
 drivers/spi/mpc52xx_psc_spi.c |   10 ++--------
 drivers/spi/mpc52xx_spi.c     |    3 +--
 drivers/spi/spi.c             |    4 ++++
 drivers/spi/spi_mpc8xxx.c     |    4 +---
 drivers/spi/spi_ppc4xx.c      |    2 +-
 drivers/spi/xilinx_spi.c      |    1 +
 drivers/spi/xilinx_spi_of.c   |    3 ---
 include/linux/of_spi.h        |   11 ++++++++---
 10 files changed, 25 insertions(+), 24 deletions(-)
drivers/of/of_spi.c +6 -4
index d504f1d..1dbce58 100644
@@ -15,12 +15,11 @@
 /**
  * of_register_spi_devices - Register child devices onto the SPI bus
  * @master:	Pointer to spi_master device
- * @np:		parent node of SPI device nodes
  *
- * Registers an spi_device for each child node of 'np' which has a 'reg'
+ * Registers an spi_device for each child node of master node which has a 'reg'
  * property.
  */
-void of_register_spi_devices(struct spi_master *master, struct device_node *np)
+void of_register_spi_devices(struct spi_master *master)
 {
 	struct spi_device *spi;
 	struct device_node *nc;
@@ -28,7 +27,10 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
 	int rc;
 	int len;
 
-	for_each_child_of_node(np, nc) {
+	if (!master->dev.of_node)
+		return;
+
+	for_each_child_of_node(master->dev.of_node, nc) {
 		/* Alloc an spi_device */
 		spi = spi_alloc_device(master);
 		if (!spi) {
drivers/spi/mpc512x_psc_spi.c +1 -0
index c8d69fc..b5539d3 100644
@@ -440,6 +440,7 @@ static int __devinit mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
 	master->setup = mpc512x_psc_spi_setup;
 	master->transfer = mpc512x_psc_spi_transfer;
 	master->cleanup = mpc512x_psc_spi_cleanup;
+	master->dev.of_node = dev->of_node;
 
 	tempp = ioremap(regaddr, size);
 	if (!tempp) {
drivers/spi/mpc52xx_psc_spi.c +2 -8
index 7104cb7..bd81ff9 100644
@@ -17,7 +17,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/of_platform.h>
-#include <linux/of_spi.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/io.h>
@@ -398,6 +397,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
 	master->setup = mpc52xx_psc_spi_setup;
 	master->transfer = mpc52xx_psc_spi_transfer;
 	master->cleanup = mpc52xx_psc_spi_cleanup;
+	master->dev.of_node = dev->of_node;
 
 	mps->psc = ioremap(regaddr, size);
 	if (!mps->psc) {
@@ -470,7 +470,6 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
 	const u32 *regaddr_p;
 	u64 regaddr64, size64;
 	s16 id = -1;
-	int rc;
 
 	regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
 	if (!regaddr_p) {
@@ -491,13 +490,8 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
 		id = *psc_nump + 1;
 	}
 
-	rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+	return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
 				irq_of_parse_and_map(op->dev.of_node, 0), id);
-	if (rc == 0)
-		of_register_spi_devices(dev_get_drvdata(&op->dev),
-					op->dev.of_node);
-
-	return rc;
 }
 
 static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
drivers/spi/mpc52xx_spi.c +1 -2
index b1a76bf..56136ff 100644
@@ -18,7 +18,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
-#include <linux/of_spi.h>
 #include <linux/io.h>
 #include <linux/of_gpio.h>
 #include <linux/slab.h>
@@ -439,6 +438,7 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
 	master->setup = mpc52xx_spi_setup;
 	master->transfer = mpc52xx_spi_transfer;
 	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
+	master->dev.of_node = op->dev.of_node;
 
 	dev_set_drvdata(&op->dev, master);
 
@@ -512,7 +512,6 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
 	if (rc)
 		goto err_register;
 
-	of_register_spi_devices(master, op->dev.of_node);
 	dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
 
 	return rc;
drivers/spi/spi.c +4 -0
index fdde706..a9e5c79 100644
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spi/spi.h>
+#include <linux/of_spi.h>
 
 
 /* SPI bustype and spi_master class are registered after board init code
@@ -544,6 +545,9 @@ int spi_register_master(struct spi_master *master)
 	/* populate children from any spi device tables */
 	scan_boardinfo(master);
 	status = 0;
+
+	/* Register devices from the device tree */
+	of_register_spi_devices(master);
 done:
 	return status;
 }
drivers/spi/spi_mpc8xxx.c +1 -3
index 97ab0a8..aad9ae1 100644
@@ -38,7 +38,6 @@
 #include <linux/of_platform.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/of_spi.h>
 #include <linux/slab.h>
 
 #include <sysdev/fsl_soc.h>
@@ -1009,6 +1008,7 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
 	master->setup = mpc8xxx_spi_setup;
 	master->transfer = mpc8xxx_spi_transfer;
 	master->cleanup = mpc8xxx_spi_cleanup;
+	master->dev.of_node = dev->of_node;
 
 	mpc8xxx_spi = spi_master_get_devdata(master);
 	mpc8xxx_spi->dev = dev;
@@ -1299,8 +1299,6 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
 		goto err;
 	}
 
-	of_register_spi_devices(master, np);
-
 	return 0;
 
 err:
drivers/spi/spi_ppc4xx.c +1 -1
index d53466a..0f5fa7e 100644
@@ -407,6 +407,7 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
 	master = spi_alloc_master(dev, sizeof *hw);
 	if (master == NULL)
 		return -ENOMEM;
+	master->dev.of_node = np;
 	dev_set_drvdata(dev, master);
 	hw = spi_master_get_devdata(master);
 	hw->master = spi_master_get(master);
@@ -545,7 +546,6 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
 	}
 
 	dev_info(dev, "driver initialized\n");
-	of_register_spi_devices(master, np);
 
 	return 0;
 
drivers/spi/xilinx_spi.c +1 -0
index 1b47363..d101a84 100644
@@ -390,6 +390,7 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 
 	master->bus_num = bus_num;
 	master->num_chipselect = pdata->num_chipselect;
+	master->dev.of_node = dev->of_node;
 
 	xspi->mem = *mem;
 	xspi->irq = irq;
drivers/spi/xilinx_spi_of.c +0 -3
index 4654805..87cda09 100644
@@ -80,9 +80,6 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
 
 	dev_set_drvdata(&ofdev->dev, master);
 
-	/* Add any subnodes on the SPI bus */
-	of_register_spi_devices(master, ofdev->dev.of_node);
-
 	return 0;
 }
 
include/linux/of_spi.h +8 -3
index 5f71ee8..9e3e70f 100644
@@ -9,10 +9,15 @@
 #ifndef __LINUX_OF_SPI_H
 #define __LINUX_OF_SPI_H
 
-#include <linux/of.h>
 #include <linux/spi/spi.h>
 
-extern void of_register_spi_devices(struct spi_master *master,
-				    struct device_node *np);
+#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
+extern void of_register_spi_devices(struct spi_master *master);
+#else
+static inline void of_register_spi_devices(struct spi_master *master)
+{
+	return;
+}
+#endif /* CONFIG_OF_SPI */
 
 #endif /* __LINUX_OF_SPI */
Signature · 1 line
1.7.0.4