public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] MX28: SPI: Refactor spi_xfer a bit
Date: Mon, 09 Jul 2012 11:37:19 +0200	[thread overview]
Message-ID: <4FFAA64F.4010203@denx.de> (raw)
In-Reply-To: <1341797627-27782-1-git-send-email-marex@denx.de>

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@denx.de>
> Cc: Fabio Estevam <festevam@freescale.com>
> Cc: Otavio Salvador <otavio@ossystems.com.br>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Wolfgang Denk <wd@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
=====================================================================

  parent reply	other threads:[~2012-07-09  9:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-09  1:33 [U-Boot] [PATCH 1/3] MX28: SPI: Refactor spi_xfer a bit Marek Vasut
2012-07-09  1:33 ` [U-Boot] [PATCH 2/3] MX28: SPI: Pull out the PIO transfer function Marek Vasut
2012-07-09  1:33 ` [U-Boot] [PATCH 3/3] MX28: SPI: Add DMA transfer support Marek Vasut
2012-07-09  9:37 ` Stefano Babic [this message]
2012-07-09 10:13   ` [U-Boot] [PATCH 1/3] MX28: SPI: Refactor spi_xfer a bit Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FFAA64F.4010203@denx.de \
    --to=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox