Star64_linux/include/linux/spi
Lars-Peter Clausen 6d9eecd418 spi: Add helper functions for setting up transfers
Quite often the pattern used for setting up and transferring a synchronous SPI
transaction looks very much like the following:

	struct spi_message msg;
	struct spi_transfer xfers[] = {
		...
	};

	spi_message_init(&msg);
	spi_message_add_tail(&xfers[0], &msg);
	...
	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);

	ret = spi_sync(&msg);

This patch adds two new helper functions for handling this case. The first
helper function spi_message_init_with_transfers() takes a spi_message and an
array of spi_transfers. It will initialize the message and then call
spi_message_add_tail() for each transfer in the array. E.g. the following

	spi_message_init(&msg);
	spi_message_add_tail(&xfers[0], &msg);
	...
	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);

can be rewritten as

	spi_message_init_with_transfers(&msg, xfers, ARRAY_SIZE(xfers));

The second function spi_sync_transfer() takes a SPI device and an array of
spi_transfers. It will allocate a new spi_message (on the stack) and add all
transfers in the array to the message. Finally it will call spi_sync() on the
message.

E.g. the follwing

	struct spi_message msg;
	struct spi_transfer xfers[] = {
		...
	};

	spi_message_init(&msg);
	spi_message_add_tail(&xfers[0], &msg);
	...
	spi_message_add_tail(&xfers[ARRAY_SIZE(xfers) - 1], &msg);

	ret = spi_sync(spi, &msg);

can be rewritten as

	struct spi_transfer xfers[] = {
		...
	};

	ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));

A coccinelle script to find such instances will follow.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-09 11:02:07 +00:00
..
74x164.h
ad7877.h
ad7879.h
ads7846.h Input: ads7846 - enable pendown GPIO debounce time setting 2012-11-21 13:09:56 -08:00
at73c213.h
at86rf230.h
corgi_lcd.h
ds1305.h
eeprom.h
flash.h
ifx_modem.h
l4f00242t03.h
libertas_spi.h
lms283gf05.h
max7301.h
mc33880.h
mcp23s08.h
mmc_spi.h
mxs-spi.h mmc: spi: Pull out common DMA parts from MXS MMC 2012-08-17 22:54:15 +01:00
pxa2xx_spi.h
rspi.h
s3c24xx.h
sh_hspi.h
sh_msiof.h
spi-tegra.h spi: tegra: add spi driver for SLINK controller 2012-10-30 18:38:35 +00:00
spi.h spi: Add helper functions for setting up transfers 2013-02-09 11:02:07 +00:00
spi_bitbang.h
spi_gpio.h
spi_oc_tiny.h
tdo24m.h
tle62x0.h
tsc2005.h spi: tsc2005: delete soon-obsolete e-mail address 2012-10-17 16:32:46 +09:00
xilinx_spi.h