Skip to contentSkip to conversation

Generic MMC-over-SPI binding?

DISCUSSION Simon Richter 3 participants 6 messages Jan 8, 2008 – Jan 9, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

in an embedded system similar to the lite5200 board, there is an MMC card socket connected to one of the PSCs. Ideally, I'd like to express this fact via the device tree and have the kernel bind the mmc-spi driver to the SPI interface, but I cannot find any place where to insert this code that I feel comfortable with.

- It is not a board-specific thing, because any board can just use any
SPI bus for MMC.

- The mmc-spi driver appears to be platform independent, so I'm not
sure OF bindings should be added to it.

- The generic device tree scanning does not contain any special cases
yet, so I don't want to add one.

My current thought is to create a new driver that just handles MMC on PSCs in SPI mode by gluing all the relevant drivers together, but that doesn't seem optimal to me either.

Any ideas?

Simon

#1 lore raw
Quoted 12 lines · Simon Richter

in an embedded system similar to the lite5200 board, there is an MMC card socket connected to one of the PSCs. Ideally, I'd like to express this fact via the device tree and have the kernel bind the mmc-spi driver to the SPI interface, but I cannot find any place where to insert this code that I feel comfortable with.

- It is not a board-specific thing, because any board can just use any
SPI bus for MMC.

- The mmc-spi driver appears to be platform independent, so I'm not
sure OF bindings should be added to it.

Quoted 6 lines

- The generic device tree scanning does not contain any special cases
yet, so I don't want to add one.

My current thought is to create a new driver that just handles MMC on PSCs in SPI mode by gluing all the relevant drivers together, but that doesn't seem optimal to me either.

You know this driver?

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/mmc/host/mmc_spi.c;h=365024b83d3da9df9b6e4f7a9d4cf6d216ba523d;hb=HEAD

Or is your question how to express this in the device tree?

Robert

Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#2 lore raw

Hi,

Quoted 1 line · Robert Schwebel

Or is your question how to express this in the device tree?

This. As far as I can see, using the device tree for this is currently unsupported, and everyone who uses the mmc-spi driver just creates a platform device in the board startup code, which strikes me as somewhat redundant, so I think it might be good to move it into the device tree (after all, it is still a hardware device).

Simon

#3 lore raw
In reply to Simon Richter
Quoted 8 lines · Simon Richter

in an embedded system similar to the lite5200 board, there is an MMC card socket connected to one of the PSCs. Ideally, I'd like to express this fact via the device tree and have the kernel bind the mmc-spi driver to the SPI interface, but I cannot find any place where to insert this code that I feel comfortable with.
...
Any ideas?

One way you could do it would be to have an spi_board_info in the way that mpc832x_spi_init does it, but that would not make use of the device tree.

What would probably be a better way is to call spi_new_device() from the mpc52xx_psc_spi driver, with an spi_board_info you generate on the fly for each child of the spi controller.

The important part where this connects to the mmc-spi driver is that you need to set spi_board_info->modalias to "mmc-spi", if the device node can be identified as an mmc card.
We'd have to define a list of valid identifications of SPI devices in the device tree, and teach the SPI drivers how they relate to linux device drivers like mmc-spi.

Since that part of the code would be used by all device tree based SPI master drivers, it should be in a separate module, which can consist of a single exported function, like (paraphrased):

void spi_of_scan_master(struct spi_master *master)

{
	struct device_node *child;
	of_dev_for_each_child(master->dev->node, child) {
		struct spi_board_info *info;
		info = kzalloc(sizeof (*info), GFP_KERNEL);
		if (of_device_is_compatible(child, "spi,mmc"))
			strcpy(info->modalias, "mmc-spi");
		else if (of_device_is_compatible(child, "spi,foo"))
			strcpy(info->modalias, "foo");
		else
			strcpy(info->modalias, "");

		info->irq = irq_of_parse_and_map(child);
		
		spi_new_device(master, child);
	}
}

Then you call that function after registering the master, from mpc52xx_psc_spi_of_probe.

	Arnd <><
#4 lore raw

Hi,

Quoted 3 lines · Arnd Bergmann

The important part where this connects to the mmc-spi driver is that you need to set spi_board_info->modalias to "mmc-spi", if the device node can be identified as an mmc card.

Doing that now, using the code you provided as a base. The SPI child device gets registered, but it appears something is still missing as no messages I could attribute to mmc-spi appear. My suspicion would be that it doesn't like the monolithic kernel for some reason (the mmc-spi driver registers itself as a driver called "mmc_spi", not sure if the modalias handling will catch that; still investigating there).

Quoted 2 lines

Then you call that function after registering the master, from mpc52xx_psc_spi_of_probe.

I've changed mpc52xx_psc_spi_do_probe to have an additional argument for the OF device node of the SPI master; ARCH=ppc can call this with NULL as long as it still exists.

Simon

#5 lore raw
Quoted 10 lines · Simon Richter
Quoted 3 lines

The important part where this connects to the mmc-spi driver is that you need to set spi_board_info->modalias to "mmc-spi", if the device node can be identified as an mmc card.

Doing that now, using the code you provided as a base. The SPI child device gets registered, but it appears something is still missing as no messages I could attribute to mmc-spi appear. My suspicion would be that it doesn't like the monolithic kernel for some reason (the mmc-spi driver registers itself as a driver called "mmc_spi", not sure if the modalias handling will catch that; still investigating there).

Right, the modalias needs to be the same as the driver name, not the module name, so you should change it to mmc_spi as well. For loading the module it would not make a difference because - and _ are treated the same by the module loader, but the device only gets associated with the driver when it matches exactly.

Quoted 6 lines
Quoted 2 lines

Then you call that function after registering the master, from mpc52xx_psc_spi_of_probe.

I've changed mpc52xx_psc_spi_do_probe to have an additional argument for the OF device node of the SPI master; ARCH=ppc can call this with NULL as long as it still exists.

Ok. keeping the code itself in the mpc52xx_psc_spi driver is fine as long as it's relatively small. Other of_platform_drivers for SPI will just have to it the same way.

	Arnd <><