• L
    spi: Add helper functions for setting up transfers · 6d9eecd4
    Lars-Peter Clausen 提交于
    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: NLars-Peter Clausen <lars@metafoo.de>
    Reviewed-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
    Signed-off-by: NJonathan Cameron <jic23@kernel.org>
    6d9eecd4
spi.h 32.6 KB