Skip to contentSkip to conversation

simple SPI controller on PXA2xx SSP port, refresh

PATCH/RFC David Brownell 2 participants 7 messages Nov 4, 2005 – Nov 5, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines

Some question on SPI subsystem:

I really get confused on the structure on the whole system. e.g. the platform_data and controller_data in board_info. What are thier purposes?

Normally you'd just use platform_data ... which might hold things like resistance and capacitance settings for that particular board; or details about which SPI chip variant was present. It gets stored in the struct device (spi_device->dev) as "platform_data".

Stephen persuaded me to add controller_data too, which is stored in "struct spi_device". His PXA SPI controller driver uses that for a structure holding what I'd call DMA tuning information, plus a function that tweaks the GPIO used for a chipselect. Treat it as readonly.

Controller drivers can have two different kinds of state in each
spi_device: static, and dynamic/runtime. The names used for them are IMO very confusing (platform_data and controller_data) since they don't mean the same as those names do in board_info. I'd take a patch to provide better names for those two. :)

Quoted 3 lines

Also i found that spi_register_board_info is declared as __init, that mean i can not register board info as a module, is it because there is no 'real' probe on SPI bus?

Combine that lack of probe with the fact that SPI isn't hotpluggable, and that's pretty much why. You need a table of SPI devices present on a given board; that boardinfo should be defined just once, in the relevant arch/arm/mach-imx/board-*.c file. The table never changes, so there'd be no point in code to change it after board init is done. (Other than wasting some memory!)

You could also use spi_new_device()/spi_unregister_device() if for some reason you want to define new boardinfo in a module. You'd need some out-of-band data to determine what devices are present.

- Dave

p.s. There's a minor refresh to the SPI code coming up soonish; just
fine tuning, and catching up to 2.6.14-git which has removed a pointless parameter from device_driver.{suspend,resume}() calls.

#1 lore raw
Quoted 10 lines · David Brownell

Stephen persuaded me to add controller_data too, which is stored in "struct spi_device". His PXA SPI controller driver uses that for a structure holding what I'd call DMA tuning information, plus a function that tweaks the GPIO used for a chipselect. Treat it as readonly.

Controller drivers can have two different kinds of state in each
spi_device: static, and dynamic/runtime. The names used for them are IMO very confusing (platform_data and controller_data) since they don't mean the same as those names do in board_info. I'd take a patch to provide better names for those two. :)

I agree, the names are bad... How about modifying struct spi_board_info to

struct spi_board_info {
...

	void *slave_data;
	void *master_data; 

...
};

-Stephen

#2 lore raw
Quoted 12 lines · Stephen Street
Quoted 10 lines · David Brownell

Stephen persuaded me to add controller_data too, which is stored in "struct spi_device". His PXA SPI controller driver uses that for a structure holding what I'd call DMA tuning information, plus a function that tweaks the GPIO used for a chipselect. Treat it as readonly.

Controller drivers can have two different kinds of state in each
spi_device: static, and dynamic/runtime. The names used for them are IMO very confusing (platform_data and controller_data) since they don't mean the same as those names do in board_info. I'd take a patch to provide better names for those two. :)

Quoted 8 lines

I agree, the names are bad... How about modifying struct spi_board_info to

struct spi_board_info {
...

	void *slave_data;
	void *master_data; 

I'd be confused. They're both slave-specific ... and owned by the master/controller driver.

Instead, how about "controller_data" changing to match its role in board_info (static info, not dynamic), and "platform_data" becoming something like "controller_state"?

- Dave

Quoted 8 lines

...
};

-Stephen

#3 lore raw
Quoted 2 lines · David Brownell

I'd be confused. They're both slave-specific ... and owned by the master/controller driver.

I'm using the spi_board_info.platform_data to pass configuration information to the spi_device (slave) driver and spi_board_info.controller_data to pass SPI bus configuration for the specific slave device. This allows different bus configurations for each attached SPI device. The following is a concrete example:

/* CS8415A configuration information and board interface setup */

static struct cs8415a_platform_data cs8415a_platform_info = {
	.enabled = 0,
	.muted = 1,
	.channel = 0,
	.pll_lock_delay = 100, 
	.irq_flags = SA_SHIRQ,
	.mask_interrupt = cs8415a_mask_interrupt,
	.unmask_interrupt = cs8415a_unmask_interrupt,
	.service_requested = cs8415a_service_requested,
};

/* PXA2XX SPI bus setup for CS8415A */

static struct pxa2xx_spi_chip cs8415a_chip_info = {
	.tx_threshold = 12,
	.rx_threshold = 4,
	.dma_burst_size = 8,
	.timeout_microsecs = 64,
	.cs_control = cs8415a_cs_control,
};
static struct spi_board_info streetracer_spi_board_info[] __initdata = {
	{
		.modalias = "cs8415a",
		.max_speed_hz = 3686400,
		.bus_num = 2,
		.chip_select = 0,
		.platform_data = &cs8415a_platform_info,
		.controller_data = &cs8415a_chip_info,
		.irq = STREETRACER_APCI_IRQ,
	},
};

IMHO the confusion is coming from the fact that struct spi_board_info is being used to pass related, but implementation dependent, configuration information to both the master and the slave simultaneously. Maybe we are asking spi_board_info to carry to much information?

Quoted 3 lines

Instead, how about "controller_data" changing to match its role in board_info (static info, not dynamic), and "platform_data" becoming something like "controller_state"?

If you mean spi_device.controller_data becomes
spi_device.controller_state, yes!

-Stephen

#4 lore raw
Quoted 9 lines · Stephen Street
Quoted 2 lines · David Brownell

I'd be confused. They're both slave-specific ... and owned by the master/controller driver.

I'm using the spi_board_info.platform_data to pass configuration information to the spi_device (slave) driver and spi_board_info.controller_data to pass SPI bus configuration for the specific slave device. This allows different bus configurations for each attached SPI device.

That's not what I thought we were talking about. Stepping back, what's confusing is that there are three different kinds of per-device data, and the names are used inconsistently:

spi_device.dev.platform_data ... from board_info.platform_data
This is for the driver of the spi_device ... board-specific data that'd be the same for PXA or OMAP or PPC805 or whatever

spi_device.platform_data ... from board_info.controller_data
This is static controller-specific information, which you were using for things like chipselect functions and fifo tuning. (I had proposed to name this as "controller_data" in the spi_device too.)

spi_device.controller_data ... runtime state for the controller
This is dynamic controller-specific information, which you were using for things like copies of register settings that set up clock speed and SPI mode for the device. (I had proposed to rename this as "controller_state".)

I don't know how much board_info.controller_data would be used by other kinds of SPI controller (that is, not PXA), but it seems to me that could also be stored in platform_data for the controller itself (if we wanted to simplify things).

Quoted 4 lines

IMHO the confusion is coming from the fact that struct spi_board_info is being used to pass related, but implementation dependent, configuration information to both the master and the slave simultaneously. Maybe we are asking spi_board_info to carry to much information?

It'd probably be a lot simpler to get rid of board_info.controller_data since that could just as easily be passed through the controller's own platform_data ...

Quoted 6 lines
Quoted 3 lines

Instead, how about "controller_data" changing to match its role in board_info (static info, not dynamic), and "platform_data" becoming something like "controller_state"?

If you mean spi_device.controller_data becomes
spi_device.controller_state, yes!

Good. We agree on one half of my proposal. :)

Now as for board_info.controller_data and its clone in spi_device, how about if I just delete that ... so that it'd be provided in the platform_device.dev.platform_data for the controller? That'd also let you substitute a typed pointer for a void* one, usually a sign of goodness.

- Dave

#5 lore raw
Quoted 8 lines · David Brownell

That's not what I thought we were talking about. Stepping back, what's confusing is that there are three different kinds of per-device data, and the names are used inconsistently:

spi_device.dev.platform_data ... from board_info.platform_data
This is for the driver of the spi_device ... board-specific data that'd be the same for PXA or OMAP or PPC805 or whatever

Quoted 5 lines

spi_device.platform_data ... from board_info.controller_data
This is static controller-specific information, which you were using for things like chipselect functions and fifo tuning. (I had proposed to name this as "controller_data" in the spi_device too.)

Yes.

Quoted 7 lines

spi_device.controller_data ... runtime state for the controller
This is dynamic controller-specific information, which you were using for things like copies of register settings that set up clock speed and SPI mode for the device. (I had proposed to rename this as "controller_state".)

My understanding also. Let's at least do the renames.

Quoted 6 lines

Now as for board_info.controller_data and its clone in spi_device, how about if I just delete that ... so that it'd be provided in the platform_device.dev.platform_data for the controller? That'd also let you substitute a typed pointer for a void* one, usually a sign of goodness.

This is where I am having the problem. I'm resisting removing the board_info.controller_data (or what ever we decide to call it) because the current code makes it easy to the have different master settings (fifo threshold, chip select control) for each spi_device attached to the master. If we move this to the platform_device.dev.platform_data this then the master will have to maintain a table indexed by the chip_select to track the per spi_device master configuration information.

On the other hand if this is too confusing, then let make the API simpler and the implementation more complex. Your call.

Bigger code snippet from my board init.

static struct cs8415a_platform_data cs8415a_platform_info = {
	.enabled = 0,
	.muted = 1,
	.channel = 0,
	.pll_lock_delay = 100,
	.irq_flags = SA_SHIRQ,
	.mask_interrupt = cs8415a_mask_interrupt,
	.unmask_interrupt = cs8415a_unmask_interrupt,
	.service_requested = cs8415a_service_requested,
};
static struct pxa2xx_spi_chip cs8415a_chip_info = {
	.tx_threshold = 12,
	.rx_threshold = 4,
	.dma_burst_size = 8,
	.timeout_microsecs = 64,
	.cs_control = cs8415a_cs_control,
};
static struct pxa2xx_spi_chip cs8405a_chip_info = {
	.tx_threshold = 12,
	.rx_threshold = 4,
	.dma_burst_size = 8,
	.timeout_microsecs = 64,
	.cs_control = cs8405a_cs_control,
};
static struct pxa2xx_spi_chip cs4341_chip_info = {
	.tx_threshold = 8,
	.rx_threshold = 8,
	.timeout_microsecs = 1000,
	.cs_control = cs4341_cs_control,
};
static struct spi_board_info streetracer_spi_board_info[] __initdata = {
	{
		.modalias = "cs8415a",
		.max_speed_hz = 3686400,
		.bus_num = 2,
		.chip_select = 0,
		.platform_data = &cs8415a_platform_info,
		.controller_data = &cs8415a_chip_info,
		.irq = STREETRACER_APCI_IRQ,
	},
	{
		.modalias = "cs8405a",
		.max_speed_hz = 3686400,
		.bus_num = 2,
		.chip_select = 1,
		.controller_data = &cs8405a_chip_info,
		.irq = STREETRACER_APCI_IRQ,
	},
	{
		.modalias = "cs4341",
		.max_speed_hz = 3686400,
		.bus_num = 2,
		.chip_select = 2,
		.controller_data = &cs4341_chip_info,
	},
};

Occupying some spare cycles is the idea that what we really need is the ability to sub-class spi_device and spi_master via structure embedding. This would be in the spirit of the 2.6 driver model and would map to the platform_device model better. It would however, mean losing the spi_board_info structure. Feel free to take a large hammer to me, if this is really off base.

-Stephen

#6 lore raw
Quoted 1 line · Stephen Street

My understanding also. Let's at least do the renames.

Consider it done.

I'll leave "controller_data" in board_info and spi_device too. You're right ... plus, we need to let that be separate from the controller platform_data for hotplugging usage, spi_new_device() and such.

Quoted 4 lines

Occupying some spare cycles is the idea that what we really need is the ability to sub-class spi_device and spi_master via structure embedding. This would be in the spirit of the 2.6 driver model and would map to the platform_device model better.

Not really. "Struture embedding" is used more by bus infrastruture than by driver infrastructure ... and even there, it's more often done by sharing storage. And spi_master supports that usage:

	/* at the top of probe(dev) */
        struct spi_master       *master;
        struct MYSOC_DATA       *data;

        master = spi_alloc_master(dev, sizeof *data);
        if (!master)
                return -ENODEV;

        data = class_get_devdata(&master->cdev);

That's because spi_master is a class view of the underlying "dev", used to access the controller hardware. (Likely a platform_device created as part of board setup.)

A difference for normal spi_device nodes is that the drivers you'd presumably want to "subclass" spi_device isn't responsible for creating the device note. It might however create a class device node, and that could end up looking much like that spi_master snippet.

- Dave