[PATCH 5/6] spi: bcm2835: add polling mode for transfers below 30us

Mark Brown broonie at kernel.org
Sun Mar 29 21:27:27 PDT 2015


On Sun, Mar 29, 2015 at 04:03:27PM +0200, Martin Sperl wrote:

> +	/* check if we shall run in polling mode */
> +	xfer_time_us = tfr->len * 9 * 1000000 / spi_used_hz;
> +	if (xfer_time_us <= BCM2835_SPI_POLLING_LIMIT_US) {


> +		/* Transfer complete - reset SPI HW */
> +		bcm2835_spi_reset_hw(master);
> +		/* and return without waiting for completion */
> +		return 0;
> +	}

The logic here is fine but it's more common to construct these things by
having separate functions for the different modes of operation.  This
makes the code more straightforward since it's clear that there are
alternative branches being taken which isn't so obvious here as the
polling case is an else within the main transfer function.  You end up
with


	if (polling)
		driver_polling_transfer()
	else if (interrupt)
		driver_interrupt_transfer()
	else
		driver_dma_transfer()

or whatever at the point where the flows branch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-rpi-kernel/attachments/20150329/d4a573f2/attachment.sig>


More information about the linux-rpi-kernel mailing list