[U-Boot] [PATCH 1/3] MX28: SPI: Refactor spi_xfer a bit

Stefano Babic sbabic at denx.de
Mon Jul 9 11:37:19 CEST 2012


On 09/07/2012 03:33, Marek Vasut wrote:
> This makes it easier to adapt for addition of DMA support.
> 
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Fabio Estevam <festevam at freescale.com>
> Cc: Otavio Salvador <otavio at ossystems.com.br>
> Cc: Stefano Babic <sbabic at denx.de>
> Cc: Wolfgang Denk <wd at denx.de>
> ---
>  drivers/spi/mxs_spi.c |   31 +++++++++++++++++++++----------
>  1 file changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
> index 7859536..a47b25b 100644
> --- a/drivers/spi/mxs_spi.c
> +++ b/drivers/spi/mxs_spi.c
> @@ -146,20 +146,31 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
>  	struct mxs_spi_slave *mxs_slave = to_mxs_slave(slave);
>  	struct mx28_ssp_regs *ssp_regs = mxs_slave->regs;
>  	int len = bitlen / 8;
> -	const char *tx = dout;
> -	char *rx = din;
>  	char dummy;
> +	int write = 0;
> +	char *data = NULL;
>  
>  	if (bitlen == 0) {
>  		if (flags & SPI_XFER_END) {
> -			rx = &dummy;
> +			din = (void *)&dummy;
>  			len = 1;
>  		} else
>  			return 0;
>  	}
>  
> -	if (!rx && !tx)
> +	if (din && dout) {
> +		/* Half-duplex only */
> +		return -EINVAL;
> +	} else if (!din && !dout) {
> +		/* No data */
>  		return 0;
> +	} else if (dout) {
> +		data = (char *)dout;
> +		write = 1;
> +	} else if (din) {
> +		data = (char *)din;
> +		write = 0;
> +	}

You do not need this if-then-else chain. I think is more readable with :

	if (din && dout) {
		/* Half-duplex only */
		return -EINVAL;
	}
	if (!din && !dout) {
		/* No data */
  		return 0;
	}


Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================



More information about the U-Boot mailing list