Generic MMC-over-SPI binding?

6 messages, 3 authors, 2008-01-09 · open the first message on its own page

Generic MMC-over-SPI binding?

From: Simon Richter <hidden>
Date: 2008-01-08 14:22:00

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

Re: Generic MMC-over-SPI binding?

From: Robert Schwebel <hidden>
Date: 2008-01-08 16:11:20

On Tue, Jan 08, 2008 at 03:22:00PM +0100, Simon Richter wrote:
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.
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
-- 
 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

Re: Generic MMC-over-SPI binding?

From: Simon Richter <hidden>
Date: 2008-01-08 16:29:50

Hi,

Robert Schwebel wrote:
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

Re: Generic MMC-over-SPI binding?

From: Arnd Bergmann <arnd@arndb.de>
Date: 2008-01-08 17:27:13

On Tuesday 08 January 2008, Simon Richter wrote:
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 <><

Re: Generic MMC-over-SPI binding?

From: Simon Richter <hidden>
Date: 2008-01-09 17:17:22

Hi,

Arnd Bergmann wrote:
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).
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

Re: Generic MMC-over-SPI binding?

From: Arnd Bergmann <arnd@arndb.de>
Date: 2008-01-09 21:55:31

On Wednesday 09 January 2008, Simon Richter wrote:
quoted
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
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 <><
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help