Skip to contentSkip to conversation

SPI OF bindings, MMC-over-SPI, chip-selects and so on

RFC/DRAFT In review Anton Vorontsov 3 participants 24 messages May 21, 2008

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

Hi all,

This is just a bait for further discussion of OF/SPI, chip-selects, e.t.c.

I've converted the spi_mpc83xx to the OF driver (using Grant's SPI_MASTER_OF work + some additions), and implemented MMC-over-SPI bindings. This stuff extensively using GPIOs, and I think this will work for the "bridged SPI" too, since the SPI bridge could be represented as GPIO controller (inside the SPI controller node).

Thoughts?

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#1 lore raw

PATCH 1/4 spi_mpc83xx: convert to the OF platform driver

This patch converts the driver to speak OF directly. FSL SPI controllers do not use internal chip-select machines, so boards must use GPIOs for these purposes.

---
 Documentation/powerpc/booting-without-of.txt |    1 +
 drivers/spi/Kconfig                          |    3 +-
 drivers/spi/spi_mpc83xx.c                    |  279 +++++++++++++++++---------
 3 files changed, 184 insertions(+), 99 deletions(-)
Documentation/powerpc/booting-without-of.txt +1 -0
index 8545f82..011bf5e 100644
@@ -1607,6 +1607,7 @@ platforms are moved over to use the flattened-device-tree model.
      controller you have.
    - interrupt-parent : the phandle for the interrupt controller that
      services interrupts for this device.
+   - gpios : (optional) may specify GPIOs used for SPI chip-selects
 
    Example:
 	spi@4c0 {
drivers/spi/Kconfig +2 -1
index 3f0dcae..4c9afeb 100644
@@ -129,7 +129,8 @@ config SPI_MPC52xx_PSC
 
 config SPI_MPC83xx
 	tristate "Freescale MPC8xxx SPI controller"
-	depends on SPI_MASTER && FSL_SOC && EXPERIMENTAL
+	depends on SPI_MASTER && OF_GPIO && FSL_SOC && EXPERIMENTAL
+	select SPI_MASTER_OF
 	help
 	  This enables using the Freescale MPC8xxx SPI controllers in master
 	  mode.
drivers/spi/spi_mpc83xx.c +181 -98

422 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#2 lore raw

Re: [PATCH 1/4] [SPI] spi_mpc83xx: convert to the OF platform driver

Quoted 4 lines · Anton Vorontsov

This patch converts the driver to speak OF directly. FSL SPI controllers do not use internal chip-select machines, so boards must use GPIOs for these purposes.

Mostly this looks good to me, but I didn't look

Quoted 12 lines
---
 Documentation/powerpc/booting-without-of.txt |    1 +
 drivers/spi/Kconfig                          |    3 +-
 drivers/spi/spi_mpc83xx.c                    |  279 +++++++++++++++++---------
 3 files changed, 184 insertions(+), 99 deletions(-)
drivers/spi/spi_mpc83xx.c +0 -1
@@ -536,92 +539,152 @@ static void mpc83xx_spi_cleanup(struct spi_device *spi)
       kfree(spi->controller_state);
 }
 
-static int __init mpc83xx_spi_probe(struct platform_device *dev)

drivers/spi/spi_mpc83xx.c static void mpc83xx_spi_cleanup(struct spi_device *spi) · line 551

Quoted 10 lines
drivers/spi/spi_mpc83xx.c +10 -0
+static unsigned int of_num_children(struct device_node *parent)
+{
+       unsigned int count = 0;
+       struct device_node *child = NULL;
+
+       for_each_child_of_node(parent, child)
+               count++;
+
+       return count;
+}

This smells like it should be in common of code; but I don't think this routine is needed at all (see below)

[...]

drivers/spi/spi_mpc83xx.c static void mpc83xx_spi_cleanup(struct spi_device *spi) · line 602

Quoted 8 lines
drivers/spi/spi_mpc83xx.c +7 -1
-       if (master == NULL) {
+       bus_num = of_get_property(np, "reg", &size);
+       if (!bus_num || size < sizeof(*bus_num)) {
+               dev_err(dev, "unable to get reg property from OF\n");
+               ret = -EINVAL;
+               goto err_bus_num;
+       }
+       master->bus_num = *bus_num;

Does the driver really need to define its own bus num? I know your using it for binding with a board info structure, but I think there are better ways to do it (I'll elaborate in my reply to your patch that adds support for boardinfo structures). It's better to let the SPI infrastructure assign an SPI bus number. and use other methods to ensure that extra data is provided to the driver. Besides, there is no guarantee that 'reg' will be unique.

Review static void mpc83xx_spi_cleanup(struct spi_device *spi) · line 560

Quoted 2 lines
(quoted diff) +2 -0
+
+       master->num_chipselect = of_num_children(np);

This assumes that there are no gaps in the assigned CS numbers of child nodes, or that the child nodes are an exhaustive list of attached devices, neither of which may be true. num_chipselect should be calculated from the number of GPIOs specified instead.

Cheers,
g.

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

Re: [PATCH 1/4] [SPI] spi_mpc83xx: convert to the OF platform driver

On Wed, May 21, 2008 at 10:50:02AM -0600, Grant Likely wrote:
[..]

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       master->num_chipselect = of_num_children(np);

This assumes that there are no gaps in the assigned CS numbers of child nodes, or that the child nodes are an exhaustive list of attached devices, neither of which may be true. num_chipselect should be calculated from the number of GPIOs specified instead.

[I'm not arguing just a thought.]

- every SPI device must have its own chip-select, otherwise SPI device node should not be a part of a SPI controller node;
- or there is just once device on the SPI bus with chip-select always asserted, no gpios = <> is specified (this case is implemented);
- or the SPI is bridged, gpios = <> should list behind-the-bridge devices' chip-selects, and driver should understand that there is a "special" (bridge) device somewhere on the bus (not implemented).

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#4 lore raw

Re: [PATCH 1/4] [SPI] spi_mpc83xx: convert to the OF platform driver

Quoted 11 lines · Anton Vorontsov

On Wed, May 21, 2008 at 10:50:02AM -0600, Grant Likely wrote:
[..]

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       master->num_chipselect = of_num_children(np);

This assumes that there are no gaps in the assigned CS numbers of child nodes, or that the child nodes are an exhaustive list of attached devices, neither of which may be true. num_chipselect should be calculated from the number of GPIOs specified instead.

[I'm not arguing just a thought.]

:-)

Here's some quick feedback off the top of my head...

Quoted 2 lines

- every SPI device must have its own chip-select, otherwise SPI device node should not be a part of a SPI controller node;

How about this example: Board has SPI controller with 4 CS lines and 4 devices. Board vendor has 3 versions of board with different devices populated (Ver1 has all 4; Ver2 has 1 and 3; Ver3 has 1, 3 and 4). Board firmware drops nodes from tree for non-present devices before booting kernel (not arguing if this is the best way for firmware to behave; but it is valid and legal). Therefore there may be gaps in the CS assignments.

Or how about this one: the SPI devices are off board and are plugged in after boot. They aren't available to be described in the device tree, but are added at a later time in response to some hot plug event. The SPI bus needs to be already set up with the correct number of CS lines.

I don't think you can assume that the device tree data will be exhaustive.

Quoted 5 lines

- or there is just once device on the SPI bus with chip-select always asserted, no gpios = <> is specified (this case is implemented);
- or the SPI is bridged, gpios = <> should list behind-the-bridge devices' chip-selects, and driver should understand that there is a "special" (bridge) device somewhere on the bus (not implemented).

In this case, I think the gpios would be a property of the spi-bridge, not the spi-master. The gpios of the spi-master would have to specify how to address the bridge; not the downstream devices. The bridge; when addressed correctly; would then proceed with addressing the downstream. In other words; the 'reg' of spi-devices attached to a bridge would be an address that the bridge understands, not an address that the master understands.

Cheers,
g.

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

PATCH 2/4 spi_of: add support for dedicated SPI constructors

In reply to Anton Vorontsov

Dedicated (usually the ones that need to fill platform data) constructors will create board info, so SPI core will probe them as normal SPI devices.

---
 drivers/spi/spi_of.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi_of.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)
drivers/spi/spi_of.c +67 -0
index b5ae434..2e1a11f 100644
@@ -11,6 +11,66 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_of.h>
 
+/*
+ * Caller have no idea who is master, i.e. this function does not
+ * accept pointer to the master, instead we use board infos.
+ */
+int of_spi_device_probe_common(struct device_node *np,
+			       struct spi_board_info *spi_binfo,
+			       const char *modalias)
+{
+	struct device_node *parent;
+	const u32 *bus_num;
+	const u32 *chip_select;
+	const u32 *max_speed;
+	int size;
+
+	parent = of_get_parent(np);
+	if (!parent) {
+		pr_err("%s: no parent\n", np->full_name);
+		return -EINVAL;
+	}
+
+	bus_num = of_get_property(parent, "reg", &size);
+	if (!bus_num || size < sizeof(*bus_num)) {
+		pr_err("%s: no reg specified for parent\n", np->full_name);
+		of_node_put(parent);
+		return -EINVAL;
+	}
+	spi_binfo->bus_num = *bus_num;
+	of_node_put(parent);
+
+	chip_select = of_get_property(np, "reg", &size);
+	if (!chip_select || size < sizeof(*chip_select)) {
+		pr_err("%s: no reg (chip-select) specified\n", np->full_name);
+		return -EINVAL;
+	}
+	spi_binfo->chip_select = *chip_select;
+
+	max_speed = of_get_property(np, "max-speed", &size);
+	if (!max_speed || size < sizeof(*max_speed))
+		spi_binfo->max_speed_hz = 100000;
+	else
+		spi_binfo->max_speed_hz = *max_speed;
+
+	strcpy(spi_binfo->modalias, modalias);
+
+	/*
+	 * spi_of_register_devices() should not probe this device, it will
+	 * be managed by the dedicated driver.
+	 */
+	np->data = spi_binfo;
+
+	return 0;
+}
+EXPORT_SYMBOL(of_spi_device_probe_common);
+
+void of_spi_device_remove_common(struct device_node *np)
+{
+	/* For some reason dedicated driver changed its mind. */
+	np->data = NULL;
+}
+
 /**
  * spi_of_register_devices - Register child devices onto the SPI bus
  * @master:	Pointer to spi_master device
@@ -29,6 +89,13 @@ void spi_of_register_devices(struct spi_master *master, struct device_node *np)
 	int len;
 
 	for_each_child_of_node(np, nc) {
+		if (nc->data) {
+			dev_dbg(&master->dev, "%s: device seem to be not "
+				"a simple one, somebody took care of it "
+				"already\n", np->full_name);
+			continue;
+		}
+
 		/* Alloc an spi_device */
 		spi = spi_alloc_device(master);
 		if (!spi) {
include/linux/spi/spi_of.h +5 -0
index c943f98..1ea2d82 100644
@@ -12,6 +12,11 @@
 #include <linux/of.h>
 #include <linux/spi/spi.h>
 
+extern int of_spi_device_probe_common(struct device_node *np,
+				      struct spi_board_info *spi_binfo,
+				      const char *modalias);
+extern void of_spi_device_remove_common(struct device_node *np);
+
 extern void spi_of_register_devices(struct spi_master *master,
 				    struct device_node *np);
 
Signature · 1 line
1.5.5.1
#6 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 15 lines · Anton Vorontsov

Dedicated (usually the ones that need to fill platform data) constructors will create board info, so SPI core will probe them as normal SPI devices.

---
 drivers/spi/spi_of.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi_of.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)
drivers/spi/spi_of.c +0 -0
index b5ae434..2e1a11f 100644
@@ -11,6 +11,66 @@
 #include <linux/spi/spi.h>

drivers/spi/spi_of.c line 21

Quoted 10 lines
drivers/spi/spi_of.c +8 -0
 #include <linux/spi/spi_of.h>
 
+/*
+ * Caller have no idea who is master, i.e. this function does not
+ * accept pointer to the master, instead we use board infos.
+ */
+int of_spi_device_probe_common(struct device_node *np,
+			       struct spi_board_info *spi_binfo,
+			       const char *modalias)
+{

Hm, I might well misunderstand something here, but it looks to me like you are again trying to use both OF _and_ platform (spi_board_info) bindings for your SPI setup? And this is exactly what we are trying to avoid in Grant's series of patches...

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#7 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 19 lines · Guennadi Liakhovetski
Quoted 17 lines · Anton Vorontsov

Dedicated (usually the ones that need to fill platform data) constructors will create board info, so SPI core will probe them as normal SPI devices.

---
 drivers/spi/spi_of.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi_of.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)
drivers/spi/spi_of.c +0 -0
index b5ae434..2e1a11f 100644
@@ -11,6 +11,66 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_of.h>
 
Quoted 12 lines

drivers/spi/spi_of.c line 21

Quoted 8 lines
drivers/spi/spi_of.c +8 -0
+/*
+ * Caller have no idea who is master, i.e. this function does not
+ * accept pointer to the master, instead we use board infos.
+ */
+int of_spi_device_probe_common(struct device_node *np,
+			       struct spi_board_info *spi_binfo,
+			       const char *modalias)
+{

Hm, I might well misunderstand something here, but it looks to me like you are again trying to use both OF _and_ platform (spi_board_info) bindings for your SPI setup?

Yes, you didn't misunderstand. ;-)

Quoted 2 lines

And this is exactly what we are trying to avoid in Grant's series of patches...

I didn't find other way... The show stopper is "master" argument, drivers don't know about masters (and should not, since if they should, then this implies that masters should be registered prior to devices, and that complicates everything).

What is the problem with board infos, btw? I missed that part. Board infos are good because:

1. This is how things work in real life: SPI isn't probe-able bus, so platform code (or board code, or OF helpers) should explicitly probe and create devices.
2. With platform infos we're probing in a Linux usual way (e.g. master's .bus_id + chip_select matching).

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#8 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 11 lines · Anton Vorontsov
Quoted 4 lines · Guennadi Liakhovetski

Hm, I might well misunderstand something here, but it looks to me like you are again trying to use both OF _and_ platform (spi_board_info) bindings for your SPI setup?

Yes, you didn't misunderstand. ;-)

Quoted 2 lines

And this is exactly what we are trying to avoid in Grant's series of patches...

Quoted 6 lines

I didn't find other way... The show stopper is "master" argument, drivers don't know about masters (and should not, since if they should, then this implies that masters should be registered prior to devices, and that complicates everything).

What is the problem with board infos, btw? I missed that part. Board

In short: board infos are not bad as such. I find it bad if you have to use both OF and platform bindings to describe _one_ piece of hardware. For more details you might want to re-read the thread, so, we don't have to discuss the same issues again.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#9 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 18 lines · Guennadi Liakhovetski
Quoted 16 lines · Anton Vorontsov
Quoted 4 lines · Guennadi Liakhovetski

Hm, I might well misunderstand something here, but it looks to me like you are again trying to use both OF _and_ platform (spi_board_info) bindings for your SPI setup?

Yes, you didn't misunderstand. ;-)

Quoted 2 lines

And this is exactly what we are trying to avoid in Grant's series of patches...

I didn't find other way... The show stopper is "master" argument, drivers don't know about masters (and should not, since if they should, then this implies that masters should be registered prior to devices, and that complicates everything).

Quoted 4 lines
Quoted 1 line

What is the problem with board infos, btw? I missed that part. Board

In short: board infos are not bad as such. I find it bad if you have to use both OF and platform bindings to describe _one_ piece of hardware.

This particular discussion isn't about describing hardware (since we're describing it via device tree), but about implementation details, such as:

1. Passing platform_data to the drivers;
2. Creating "SPI Linux devices" from the OF description.

I see there ways:

1. Grant Likely's approach (works great for simple drivers which don't need SPI platform_data).
2. Old board infos approach, there we can do whatever we want.
3. Implementing OF bindings for the every SPI driver that needs platform_data.

I could do "3", let's see what it will look like...

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#10 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 19 lines · Anton Vorontsov
Quoted 18 lines · Guennadi Liakhovetski
Quoted 16 lines · Anton Vorontsov
Quoted 4 lines · Guennadi Liakhovetski

Hm, I might well misunderstand something here, but it looks to me like you are again trying to use both OF _and_ platform (spi_board_info) bindings for your SPI setup?

Yes, you didn't misunderstand. ;-)

Quoted 2 lines

And this is exactly what we are trying to avoid in Grant's series of patches...

I didn't find other way... The show stopper is "master" argument, drivers don't know about masters (and should not, since if they should, then this implies that masters should be registered prior to devices, and that complicates everything).

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

What is the problem with board infos, btw? I missed that part. Board

In short: board infos are not bad as such. I find it bad if you have to use both OF and platform bindings to describe _one_ piece of hardware.

Sonething to note: 'platform bindings' is the wrong terminology. I'd like to be careful here because the term 'platform' is already overloaded and leads to confusion. Specifically, the 'platform bus' doesn't come into play at all here and 'platform code' simply refers to the board specific code in arch/powerpc/platforms. Really, the discussion is between using 'board info' to pass data vs. using the OF api.

Quoted 8 lines

This particular discussion isn't about describing hardware (since we're describing it via device tree), but about implementation details, such as:

1. Passing platform_data to the drivers;
2. Creating "SPI Linux devices" from the OF description.

Quoted 7 lines

I see there ways:

1. Grant Likely's approach (works great for simple drivers which don't need SPI platform_data).
2. Old board infos approach, there we can do whatever we want.
3. Implementing OF bindings for the every SPI driver that needs platform_data.

or perhaps: 4. allow platform code to pass supplementary board info to specific spi devices when appropriate (so the '1.' path is always used, but it can also parse a board info structure if one is provided.
This is different from '2.' which short circuits the spi_of path
entirely).

I concede that sometimes platform code just has to pass data to the driver that cannot be described in the device tree. callback pointers being the most significant example and we do need a sane way to do so.

That being said; in most cases I'd much rather see code added to the driver itself to extract data from the device tree. This has the advantage that the data transformation code stays with the driver where it belongs and it keeps code common as much as possible (discourage duplication of code in the platform directories).

Cheers,
g.

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

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 3 lines · Grant Likely

I concede that sometimes platform code just has to pass data to the driver that cannot be described in the device tree. callback pointers being the most significant example and we do need a sane way to do so.

Sorry, I just cannot understand. So far my understanding was, that OF bindings were there to _completely_ describe hardware, that cannot be autoconfigured or probed. So a _generic_ driver gets all information it needs from the device tree and needs no additional information to handle the hardware.

Now if a driver needs additional information from "platform code" what's the purpose of partial data in the device tree at all? Just use board information as usual.

What good is an OF-binding if it doesn't provide complete information?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#12 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 9 lines · Guennadi Liakhovetski
Quoted 3 lines · Grant Likely

I concede that sometimes platform code just has to pass data to the driver that cannot be described in the device tree. callback pointers being the most significant example and we do need a sane way to do so.

Sorry, I just cannot understand. So far my understanding was, that OF bindings were there to _completely_ describe hardware, that cannot be autoconfigured or probed.

Correct, they describe the hardware... to a level sufficient to identify it usefully and uniquely to an operating system.

Quoted 3 lines

So a _generic_ driver gets all information it
needs from the device tree and needs no additional information to handle the hardware.

Also correct.

Quoted 4 lines

Now if a driver needs additional information from "platform code" what's the purpose of partial data in the device tree at all? Just use board information as usual.

(Note; it must be said that I think the situation is *rare* and should be avoided)

If some behaviour is entirely board specific and doesn't have any possibility of being duplicated on other boards, then it makes sense for the code implementing that behaviour to live with the platform code. For example; consider the example of the ads7846 device driver.
It needs a pointer to a function that will tell it whether or not the
pen is down. This is entirely a board specific kind of thing; it might happen via a GPIO or a key press or a phase of the moon. The device doesn't care; but the driver needs a way to test the state.

The driver needs some method to obtain the pointer to the function. It cannot be encoded in the device tree because it is a function pointer, not raw 'data'. The device tree may have some data that tells the platform code how it is wired up; but the pointer itself cannot be encoded into the device tree. I see two obvious ways to do this. (note: platform code cannot simply export the function because it might be a multiplatform kernel with multiple platforms defining the same function).

1) Pass it in a data structure passed with the device structure
2) Make the device driver call out to a lookup function that returns the function pointer.

Option 1) is basically some form of pdata scheme. Option 2 requires the driver to use some API to go looking for the relevant function. I'm not convinced yet on which method is the best; but I cannot say that platform code must never pass data to drivers that is not directly encoded into the device tree.

Besides, we must always account for the situation where the provided device tree has a bug or the hardware has a quirk and platform code needs to do something to fix it up. Or if you prefer: 99% of the time everything is handled with common code reading the device tree directly; but in the 1% of the time where that does not work (due to bugs or quirks) we have options to insert workaround code.

Quoted 2 lines

What good is an OF-binding if it doesn't provide complete information?

It still increases the amount of common code even if there are rare corner cases that require board specific code.

Cheers,
g.

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

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 4 lines · Grant Likely

If some behaviour is entirely board specific and doesn't have any possibility of being duplicated on other boards, then it makes sense for the code implementing that behaviour to live with the platform code.

Exactly - "entirely board specific" and "doesn't have any possibility of being duplicated on other boards."

Quoted 4 lines
Quoted 1 line

What good is an OF-binding if it doesn't provide complete information?

It still increases the amount of common code even if there are rare corner cases that require board specific code.

Right again - _rare_ corner cases. Whereas we are talking about _all_ SPI busses, maybe apart from those, where the controller itself switches CSs in a well-defined way, and the driver doesn't need any additional information to handle this.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#14 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 12 lines · Guennadi Liakhovetski
Quoted 4 lines · Grant Likely

If some behaviour is entirely board specific and doesn't have any possibility of being duplicated on other boards, then it makes sense for the code implementing that behaviour to live with the platform code.

Exactly - "entirely board specific" and "doesn't have any possibility of being duplicated on other boards."

Quoted 2 lines
Quoted 1 line

What good is an OF-binding if it doesn't provide complete information?

Quoted 7 lines
Quoted 2 lines

It still increases the amount of common code even if there are rare corner cases that require board specific code.

Right again - _rare_ corner cases. Whereas we are talking about _all_ SPI busses, maybe apart from those, where the controller itself switches CSs in a well-defined way, and the driver doesn't need any additional information to handle this.

Ah, I see where we are crossing our wires. I was talking about the case of registering spi devices. I agree that the spi bus should not need any additional information.

Cheers,
g.

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

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 11 lines · Grant Likely
Quoted 5 lines · Guennadi Liakhovetski

Right again - _rare_ corner cases. Whereas we are talking about _all_ SPI busses, maybe apart from those, where the controller itself switches CSs in a well-defined way, and the driver doesn't need any additional information to handle this.

Ah, I see where we are crossing our wires. I was talking about the case of registering spi devices. I agree that the spi bus should not need any additional information.

No, sorry for not making it clear. I wrote "busses" because on those controllers, that control CS themselves _devices_ don't need any additional info. But I meant, that describing SPI _devices_ should be done in only one way or another - either using fdt, or platform data, not both.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#16 lore raw

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

Quoted 10 lines · Guennadi Liakhovetski
Quoted 8 lines · Grant Likely
Quoted 5 lines · Guennadi Liakhovetski

Right again - _rare_ corner cases. Whereas we are talking about _all_ SPI busses, maybe apart from those, where the controller itself switches CSs in a well-defined way, and the driver doesn't need any additional information to handle this.

Quoted 8 lines
Quoted 3 lines

Ah, I see where we are crossing our wires. I was talking about the case of registering spi devices. I agree that the spi bus should not need any additional information.

No, sorry for not making it clear. I wrote "busses" because on those controllers, that control CS themselves _devices_ don't need any additional info. But I meant, that describing SPI _devices_ should be done in only one way or another - either using fdt, or platform data, not both.

Yes, I agree with that too... with the one caveat that platform code should have some method to supplement the data in the device tree *only when it is absolutely necessary to do so*. (note: I say 'platform code' here, not 'platform data'. They are two different things) I make no claims on what that method should be at this time.

Cheers,
g.

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

Re: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors

In reply to Anton Vorontsov
Quoted 60 lines · Anton Vorontsov

Dedicated (usually the ones that need to fill platform data) constructors will create board info, so SPI core will probe them as normal SPI devices.

---
 drivers/spi/spi_of.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi_of.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)
drivers/spi/spi_of.c +43 -0
index b5ae434..2e1a11f 100644
@@ -11,6 +11,66 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_of.h>
 
+/*
+ * Caller have no idea who is master, i.e. this function does not
+ * accept pointer to the master, instead we use board infos.
+ */
+int of_spi_device_probe_common(struct device_node *np,
+                              struct spi_board_info *spi_binfo,
+                              const char *modalias)
+{
+       struct device_node *parent;
+       const u32 *bus_num;
+       const u32 *chip_select;
+       const u32 *max_speed;
+       int size;
+
+       parent = of_get_parent(np);
+       if (!parent) {
+               pr_err("%s: no parent\n", np->full_name);
+               return -EINVAL;
+       }
+
+       bus_num = of_get_property(parent, "reg", &size);
+       if (!bus_num || size < sizeof(*bus_num)) {
+               pr_err("%s: no reg specified for parent\n", np->full_name);
+               of_node_put(parent);
+               return -EINVAL;
+       }
+       spi_binfo->bus_num = *bus_num;
+       of_node_put(parent);
+
+       chip_select = of_get_property(np, "reg", &size);
+       if (!chip_select || size < sizeof(*chip_select)) {
+               pr_err("%s: no reg (chip-select) specified\n", np->full_name);
+               return -EINVAL;
+       }
+       spi_binfo->chip_select = *chip_select;
+
+       max_speed = of_get_property(np, "max-speed", &size);
+       if (!max_speed || size < sizeof(*max_speed))
+               spi_binfo->max_speed_hz = 100000;
+       else
+               spi_binfo->max_speed_hz = *max_speed;
+
+       strcpy(spi_binfo->modalias, modalias);

drivers/spi/spi_of.c line 66

Quoted 10 lines
drivers/spi/spi_of.c +10 -0
+
+       /*
+        * spi_of_register_devices() should not probe this device, it will
+        * be managed by the dedicated driver.
+        */
+       np->data = spi_binfo;
+
+       return 0;
+}
+EXPORT_SYMBOL(of_spi_device_probe_common);

This is mostly a duplication of stuff in spi_of_register_devices() and it short circuits that path. While I'm not hugely fond of boardinfo in general, I'd much rather see it passed via spi_of_register_devices instead of using a different path. I know we've discussed this before and I resisted settling on a solution (like adding a specific platform_data pointer instead of using device_node->data) mostly because I'm being cautious. I still don't know if it would be better to use a device_node value or to have some form of callback into the boards platform code. But, either method would be better than having multiple paths for registering SPI devices which are described in the device tree.

Cheers,
g.

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

PATCH 3/4 MMC-over-SPI OF constructor

In reply to Anton Vorontsov
---
 Documentation/powerpc/booting-without-of.txt |   24 +++++
 drivers/of/Kconfig                           |    6 ++
 drivers/of/Makefile                          |    1 +
 drivers/of/spi_mmc.c                         |  122 ++++++++++++++++++++++++++
 4 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/spi_mmc.c
Documentation/powerpc/booting-without-of.txt +24 -0
index 011bf5e..474f50a 100644
@@ -3113,7 +3113,31 @@ platforms are moved over to use the flattened-device-tree model.
 			};
 		};
 
+    t) MMC-over-SPI
 
+      Required properties:
+      - #address-cells : should be 0;
+      - #size-cells : should be 0;
+      - compatible : "linux,mmc-spi".
+      - linux,modalias  - (optional) permissible value is "mmc_spi", only used
+        if dedicated driver failed to probe.
+      - reg : should specify SPI address (chip-select number).
+      - max-speed : (optional) maximum frequency for this device (Hz).
+      - mmc,ocr-mask : (optional) Linux-specific MMC OCR mask (slot voltage).
+      - gpios : (optional) may specify GPIOs in this order: Write-Protect GPIO,
+        Card-Detect GPIO.
+
+      Example:
+
+	mmc-slot@0 {
+		compatible = "linux,mmc-spi";
+		linux,modalias = "mmc_spi";
+		reg = <0>;
+		max-speed = <50000000>;
+		mmc,ocr-mask = <0x00200000>;
+		gpios = <&sdcsr_pio 6 0   /*  WP */
+			 &sdcsr_pio 7 1>; /* nCD */
+	};
 
 VII - Marvell Discovery mv64[345]6x System Controller chips
 ===========================================================
drivers/of/Kconfig +6 -0
index 3a7a11a..80aaf8b 100644
@@ -13,3 +13,9 @@ config OF_I2C
 	depends on PPC_OF && I2C
 	help
 	  OpenFirmware I2C accessors
+
+config OF_MMC_SPI
+	def_bool y if MMC_SPI
+	depends on OF_GPIO
+	help
+	  OpenFirmware MMC-over-SPI constructor
drivers/of/Makefile +1 -0
index 548772e..f6ee8b3 100644
@@ -2,3 +2,4 @@ obj-y = base.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
+obj-$(CONFIG_OF_MMC_SPI)	+= spi_mmc.o
drivers/of/spi_mmc.c new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#19 lore raw

PATCH 4/4 86xx: mpc8610_hpcd: support for MMC-over-SPI and PIXIS' GPIOs

In reply to Anton Vorontsov

This patch implements support for PIXIS' GPIOs and adds appropriate nodes to support MMC-over-SPI.

---
 arch/powerpc/boot/dts/mpc8610_hpcd.dts     |   32 ++++++++
 arch/powerpc/platforms/86xx/Kconfig        |    2 +
 arch/powerpc/platforms/86xx/mpc8610_hpcd.c |  119 ++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+), 0 deletions(-)
arch/powerpc/boot/dts/mpc8610_hpcd.dts +32 -0
index 44e9287..e3bf5e6 100644
@@ -100,8 +100,18 @@
 		};
 
 		board-control@3,0 {
+			#address-cells = <1>;
+			#size-cells = <1>;
 			compatible = "fsl,fpga-pixis";
+			ranges = <0 3 0 0x20>;
 			reg = <3 0 0x20>;
+
+			sdcsr_pio: gpio-controller@a {
+				#gpio-cells = <2>;
+				compatible = "fsl,fpga-pixis-pio";
+				reg = <0xa 1>;
+				gpio-controller;
+			};
 		};
 	};
 
@@ -193,6 +203,28 @@
 			reg = <0xe4000 0x100>;
 		};
 
+		spi@7000 {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			compatible = "fsl,mpc8610-spi", "fsl,spi", "simple-bus";
+			cell-index = <0>;
+			reg = <0x7000 0x40>;
+			interrupts = <59 2>;
+			interrupt-parent = <&mpic>;
+			mode = "cpu";
+			/* gpios = <&sdcsr_pio 0 1>; */
+
+			mmc-slot@0 {
+				compatible = "linux,mmc-spi";
+				linux,modalias = "mmc_spi";
+				reg = <0>;
+				max-speed = <50000000>;
+				mmc,ocr-mask = <0x00200000>;
+				gpios = <&sdcsr_pio 6 0   /*  WP */
+					 &sdcsr_pio 7 1>; /* nCD */
+			};
+		};
+
 		i2s@16000 {
 			compatible = "fsl,mpc8610-ssi";
 			cell-index = <0>;
arch/powerpc/platforms/86xx/Kconfig +2 -0
index 39c02af..a7eb89c 100644
@@ -22,6 +22,8 @@ config MPC8610_HPCD
 	bool "Freescale MPC8610 HPCD"
 	select DEFAULT_UIMAGE
 	select FSL_ULI1575
+	select GENERIC_GPIO
+	select HAVE_GPIO_LIB
 	help
 	  This option enables support for the MPC8610 HPCD board.
 
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +119 -0

131 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#20 lore raw
In reply to Anton Vorontsov
Quoted 8 lines · Anton Vorontsov

This is just a bait for further discussion of OF/SPI, chip-selects, e.t.c.

I've converted the spi_mpc83xx to the OF driver (using Grant's SPI_MASTER_OF work + some additions), and implemented MMC-over-SPI bindings. This stuff extensively using GPIOs, and I think this will work for the "bridged SPI" too, since the SPI bridge could be represented as GPIO controller (inside the SPI controller node).

Yes, but do you really _want_ to represent them as GPIOs? Firstly they are not really "G" P, secondly, they are not even "I", rather only "O". And do you really want to register your SPI CS lines to the whole system for everyone's (ab)use?...

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

#21 lore raw
Quoted 5 lines · Guennadi Liakhovetski
Quoted 3 lines · Anton Vorontsov

This is just a bait for further discussion of OF/SPI, chip-selects, e.t.c.

Quoted 8 lines
Quoted 5 lines

I've converted the spi_mpc83xx to the OF driver (using Grant's SPI_MASTER_OF work + some additions), and implemented MMC-over-SPI bindings. This stuff extensively using GPIOs, and I think this will work for the "bridged SPI" too, since the SPI bridge could be represented as GPIO controller (inside the SPI controller node).

Yes, but do you really _want_ to represent them as GPIOs? Firstly they are not really "G" P, secondly, they are not even "I", rather only "O".

"General Purpose Input/Output" implies that lines could be only I or only O, or both. (plus "dedicated function", though, here David Brownell will probably disagree ;-) GPIOs are really general.

Quoted 3 lines

And do
you really want to register your SPI CS lines to the whole system for everyone's (ab)use?...

This is represented via device tree, so the only abusers could be hardware designers. :-)

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#22 lore raw
In reply to Anton Vorontsov
Quoted 10 lines · Anton Vorontsov

Hi all,

This is just a bait for further discussion of OF/SPI, chip-selects, e.t.c.

I've converted the spi_mpc83xx to the OF driver (using Grant's SPI_MASTER_OF work + some additions), and implemented MMC-over-SPI bindings. This stuff extensively using GPIOs, and I think this will work for the "bridged SPI" too, since the SPI bridge could be represented as GPIO controller (inside the SPI controller node).

The GPIOs case doesn't bother me too much. If the controller supports GPIO chip selects (and pretty much all of them could I think) then the SPI master driver just needs to specify that it supports N chip selects and have a gpios property that lists all the relevant GPIOs (just like you've done). So I think this bit is looking good.

More complex cases would still probably need some form of spi-bridge node (and most likely requiring changes to the SPI infrastructure to make bridging easy; but that is just driver details).

The board info handling I think requires more thought... (details in another email)

Cheers,
g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#23 lore raw
In reply to Anton Vorontsov
Quoted 4 lines · Anton Vorontsov

Hi all,

This is just a bait for further discussion of OF/SPI, chip-selects, e.t.c.

BTW; [email protected] should probably be CC'd on the next posting of this series.

Cheers,
g.

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