Skip to contentSkip to conversation

SPI support for fsl_soc and mpc832x_rdb

PATCH Superseded Anton Vorontsov 4 participants 12 messages Aug 8, 2007 – Aug 12, 2007

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover SPI support for fsl_soc and mpc832x_rdb

Hi all,

This is v3. The only objection I can imagine is about "fsl,device-id". Though in the v2 nobody complained, thus it's stayed intact.

If you want to, complain now. I'll give up and will remove it. ;-)

Changelog:

v2 -> v3
o Device tree:
- completely removed mmc node;
- removed pio-handles and pio-maps.

o board file:
- Instead of par_io_of_config(), now par_io_config_pin() used to configure GPIO pins, which does not require device tree node.

v1 -> v2
o Device tree:
- cosmetic cleanups (@01 -> @1);
- device-id renamed to fsl,device-id;
- removed max-chipselect and sysclk properties from spi node;
- removed chipselect property from mmc node, now reg property used for this purpose, thereby address-cells and size-cells added to the spi node;
- other non-mandatory (device-id, device_type, compatible, ...) properties removed from mmc node, today board file is using of_find_node_by_name(), instead of of_find_compatible_node();
- "qe" mode renamed to "cpu-qe".

o board file <-> fsl_soc interaction
- fsl_soc no longer scans for SPI nodes in the arch initcall. Also it's no longer exports any global variables. Instead, it's export fsl_spi_init function now, which accepts pointer to the fsl_spi_board_info structure;
- board file fills fsl_spi_board_info structure and issues fsl_spi_init(), which register SPI devices and SPI board infos. Various sanity checks also perfromed.

I'd want to note that if spi_mpc83xx will be converted to of_platform_driver then the scheme described above will not work anymore, and I'll have to revert back ugly hacks:
global variables for activate/deactivate_cs functions. I see no other options.

Thanks,

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

PATCH v3 1/2 MPC832x_RDB: update dts to use spi, register mmc_spi stub

mmc_spi already tested to work. When it will hit mainline the only change that will be needed is replacing "spidev" by "mmc_spi".

---
 arch/powerpc/boot/dts/mpc832x_rdb.dts     |    4 ++-
 arch/powerpc/platforms/83xx/mpc832x_rdb.c |   52 +++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletions(-)
arch/powerpc/boot/dts/mpc832x_rdb.dts +3 -1
index e9c332f..664dd16 100644
@@ -207,15 +207,17 @@
 
 		spi@4c0 {
 			device_type = "spi";
+			fsl,device-id = <1>;
 			compatible = "fsl_spi";
 			reg = <4c0 40>;
 			interrupts = <2>;
 			interrupt-parent = <&qeic>;
-			mode = "cpu";
+			mode = "cpu-qe";
 		};
 
 		spi@500 {
 			device_type = "spi";
+			fsl,device-id = <2>;
 			compatible = "fsl_spi";
 			reg = <500 40>;
 			interrupts = <1>;
arch/powerpc/platforms/83xx/mpc832x_rdb.c +52 -0

70 lines not on this page · raw message

Signature · 1 line
1.5.0.6
#8 lore raw

PATCH v3 2/2 fsl_soc: add support for fsl_spi

In reply to Anton Vorontsov
---
 arch/powerpc/sysdev/fsl_soc.c |   88 +++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/sysdev/fsl_soc.h |   12 ++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +88 -0
index 727453d..0771700 100644
@@ -23,6 +23,7 @@
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/phy.h>
+#include <linux/spi/spi.h>
 #include <linux/fsl_devices.h>
 #include <linux/fs_enet_pd.h>
 #include <linux/fs_uart_pd.h>
@@ -1186,3 +1187,90 @@ err:
 arch_initcall(cpm_smc_uart_of_init);
 
 #endif /* CONFIG_8xx */
+
+int fsl_spi_init(struct fsl_spi_board_info *binfo)
+{
+	struct device_node *np;
+	unsigned int i;
+	u32 sysclk;
+
+	np = of_find_node_by_type(NULL, "qe");
+	if (!np)
+		return -ENODEV;
+
+	sysclk = *(u32 *)of_get_property(np, "bus-frequency", NULL);
+
+	for (np = NULL, i = 1;
+	     (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
+	     i++) {
+		int ret = 0;
+		unsigned int j;
+		const char *devid;
+		const char *mode;
+		struct resource res[2];
+		struct platform_device *pdev = NULL;
+		struct fsl_spi_platform_data pdata = {
+			.activate_cs = binfo->activate_cs,
+			.deactivate_cs = binfo->deactivate_cs,
+		};
+
+		memset(res, 0, sizeof(res));
+
+		devid = of_get_property(np, "fsl,device-id", NULL);
+		mode = of_get_property(np, "mode", NULL);
+		if (!devid || !mode)
+			goto err;
+
+		pdata.sysclk = sysclk;
+		pdata.bus_num = *(u32 *)devid;
+
+		for (j = 0; j < binfo->num_board_infos; j++) {
+			if (binfo->board_infos[j].bus_num == pdata.bus_num)
+				pdata.max_chipselect++;
+		}
+
+		if (!pdata.max_chipselect)
+			goto err;
+
+		if (!strcmp(mode, "cpu-qe"))
+			pdata.qe_mode = 1;
+
+		ret = of_address_to_resource(np, 0, &res[0]);
+		if (ret)
+			goto err;
+
+		res[1].start = res[2].end = irq_of_parse_and_map(np, 0);
+		if (res[1].start == NO_IRQ)
+			goto err;
+
+		res[1].name = "mpc83xx_spi";
+		res[1].flags = IORESOURCE_IRQ;;
+
+		pdev = platform_device_alloc("mpc83xx_spi", i);
+		if (!pdev)
+			goto err;
+
+		ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+		if (ret)
+			goto unreg;
+
+		ret = platform_device_add_resources(pdev, res,
+						    ARRAY_SIZE(res));
+		if (ret)
+			goto unreg;
+
+		ret = platform_device_register(pdev);
+		if (ret)
+			goto unreg;
+
+		continue;
+unreg:
+		platform_device_del(pdev);
+err:
+		continue;
+	}
+
+	return spi_register_board_info(binfo->board_infos,
+				       binfo->num_board_infos);
+}
+EXPORT_SYMBOL(fsl_spi_init);
arch/powerpc/sysdev/fsl_soc.h +12 -0
index 04e145b..a83998d 100644
@@ -8,5 +8,17 @@ extern phys_addr_t get_immrbase(void);
 extern u32 get_brgfreq(void);
 extern u32 get_baudrate(void);
 
+struct spi_board_info;
+
+struct fsl_spi_board_info {
+	struct spi_board_info *board_infos;
+	unsigned int num_board_infos;
+
+	void (*activate_cs)(u8 cs, u8 polarity);
+	void (*deactivate_cs)(u8 cs, u8 polarity);
+};
+
+extern int fsl_spi_init(struct fsl_spi_board_info *info);
+
 #endif
 #endif
Signature · 1 line
1.5.0.6
#2 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

In reply to Anton Vorontsov
Quoted 15 lines · Anton Vorontsov

mmc_spi already tested to work. When it will hit mainline the only change that will be needed is replacing "spidev" by "mmc_spi".

---
 arch/powerpc/boot/dts/mpc832x_rdb.dts     |    4 ++-
 arch/powerpc/platforms/83xx/mpc832x_rdb.c |   52 +++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletions(-)
arch/powerpc/boot/dts/mpc832x_rdb.dts +0 -0
index e9c332f..664dd16 100644

arch/powerpc/boot/dts/mpc832x_rdb.dts line 210

Quoted 4 lines
arch/powerpc/boot/dts/mpc832x_rdb.dts +1 -0
@@ -207,15 +207,17 @@
 
 		spi@4c0 {
 			device_type = "spi";
+			fsl,device-id = <1>;

Hrm... Freescale is using these 'fsl,device-id' properties, I'm guessing they're basically the same thing as the 'cell-index' used in the EMAC binding.

We should co-ordinate better on this, if it's to become a convention...

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

Re: [PATCH v3 2/2] [POWERPC] fsl_soc: add support for fsl_spi

In reply to Anton Vorontsov
Quoted 20 lines · Anton Vorontsov
---
 arch/powerpc/sysdev/fsl_soc.c |   88 ++++++++++++++++++++++++++++++ 
+++++++++++
 arch/powerpc/sysdev/fsl_soc.h |   12 ++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +1 -0
index 727453d..0771700 100644
@@ -23,6 +23,7 @@
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/phy.h>
+#include <linux/spi/spi.h>
 #include <linux/fsl_devices.h>
 #include <linux/fs_enet_pd.h>
 #include <linux/fs_uart_pd.h>

arch/powerpc/sysdev/fsl_soc.c err: · line 1191

Quoted 5 lines
arch/powerpc/sysdev/fsl_soc.c +2 -0
@@ -1186,3 +1187,90 @@ err:
 arch_initcall(cpm_smc_uart_of_init);
 
 #endif /* CONFIG_8xx */
+
+int fsl_spi_init(struct fsl_spi_board_info *binfo)

Do we really need a struct, can we not just pass the 4 params as args to the function?

May need to a typedef to linux/fsl_device.h for the chipselect call back.

- k

#10 lore raw
In reply to Anton Vorontsov
Quoted 6 lines · Anton Vorontsov

Hi all,

This is v3. The only objection I can imagine is about "fsl,device-id". Though in the v2 nobody complained, thus it's stayed intact.

If you want to, complain now. I'll give up and will remove it. ;-)

:), here's my complaint for it.

We should just use the physical address of the bus register base as the id. We do the same thing for the MII phy bus driver for gianfar.

- k

#3 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

In reply to David Gibson
Quoted 6 lines

Hrm... Freescale is using these 'fsl,device-id' properties, I'm guessing they're basically the same thing as the 'cell-index' used in the EMAC binding.

We should co-ordinate better on this, if it's to become a convention...

That means we shouldn't coordinate on this, right?

Segher

#11 lore raw
In reply to Anton Vorontsov
Quoted 1 line

- cosmetic cleanups (@01 -> @1);

That's a correctness fix, not just cosmetics.

Quoted 3 lines

- other non-mandatory (device-id, device_type, compatible, ...) properties removed from mmc node, today board file is using of_find_node_by_name(), instead of of_find_compatible_node();

That's the wrong way around -- a driver (or platform code, same thing) isn't using "compatible", while it should, so you remove "compatible"?

Segher

#4 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

In reply to Segher Boessenkool
Quoted 8 lines · Segher Boessenkool
Quoted 6 lines

Hrm... Freescale is using these 'fsl,device-id' properties, I'm guessing they're basically the same thing as the 'cell-index' used in the EMAC binding.

We should co-ordinate better on this, if it's to become a convention...

That means we shouldn't coordinate on this, right?

Heh. Either one is kind of ugly, I'll grant you.

But, many SoCs do have a notion of device "number", which is relevant for programming other general control registers in places. We need to encode it somehow, and it would be good to have a consistent way of doing it.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

We should co-ordinate better on this, if it's to become a convention...

That means we shouldn't coordinate on this, right?

Heh. Either one is kind of ugly, I'll grant you.

But, many SoCs do have a notion of device "number", which is relevant for programming other general control registers in places. We need to encode it somehow, and it would be good to have a consistent way of doing it.

I'm not convinced there isn't a more direct way to represent the relevant relationships.

Either way, we don't have enough experience with this stuff yet to know what works well and what doesn't (at least, I don't, and I haven't seen any evidence that others do); so I'd prefer to keep this in per-device bindings for now; it should be there anyhow, but once we do have experience with it we could do some recommendation.

Segher

#6 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

Quoted 15 lines · Segher Boessenkool
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

We should co-ordinate better on this, if it's to become a convention...

That means we shouldn't coordinate on this, right?

Heh. Either one is kind of ugly, I'll grant you.

But, many SoCs do have a notion of device "number", which is relevant for programming other general control registers in places. We need to encode it somehow, and it would be good to have a consistent way of doing it.

I'm not convinced there isn't a more direct way to represent the relevant relationships.

Quoted 6 lines

Either way, we don't have enough experience with this stuff yet to know what works well and what doesn't (at least, I don't, and I haven't seen any evidence that others do); so I'd prefer to keep this in per-device bindings for now; it should be there anyhow, but once we do have experience with it we could do some recommendation.

Well of course it will remain in the per-device bindings. But just because these are in different per-device bindings doesn't mean we can't *try* to use consistent property names for similar things...

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw

Re: [PATCH v3 1/2] [POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub

Quoted 15 lines
Quoted 8 lines
Quoted 4 lines

But, many SoCs do have a notion of device "number", which is relevant for programming other general control registers in places. We need to encode it somehow, and it would be good to have a consistent way of doing it.

I'm not convinced there isn't a more direct way to represent the relevant relationships.

Quoted 6 lines

Either way, we don't have enough experience with this stuff yet to know what works well and what doesn't (at least, I don't, and I haven't seen any evidence that others do); so I'd prefer to keep this in per-device bindings for now; it should be there anyhow, but once we do have experience with it we could do some recommendation.

Quoted 3 lines

Well of course it will remain in the per-device bindings. But just because these are in different per-device bindings doesn't mean we can't *try* to use consistent property names for similar things...

Sure, if those properties do exactly the same thing, identical names are a good thing. Until we're reasonably certain that this is a good way to do things I'd rather people experiment a bit instead of all cluster around a random thing that would be labeled "de facto standard".

:-)

Segher