linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: spi-devel-general@lists.sourceforge.net, linux-sh@vger.kernel.org
Subject: Re: [PATCH 2/3] SPI: spi_sh_msiof: consolidate data in 8-bit mode into 32-bit words
Date: Fri, 21 Jan 2011 10:02:56 -0700	[thread overview]
Message-ID: <20110121170256.GC7477@angua.secretlab.ca> (raw)
In-Reply-To: <Pine.LNX.4.64.1101211655270.18867@axis700.grange>

On Fri, Jan 21, 2011 at 04:56:42PM +0100, Guennadi Liakhovetski wrote:
> Instead of sending data 8 bits at a time in 8-bit SPI mode, swap bytes
> and send and receive them 32 bits at a time. Tested with an SD-card,
> with which this patch reduced the number of interrupts by 50%, when
> reading 5MiB of data (there are also small service packets, the number
> of interrupts, produced by 512-byte sectors should, of course, drop by
> 75%), and improved throughput by more than 40%.
> 
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Merged, thanks.

g.

> ---
>  drivers/spi/spi_sh_msiof.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 59 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/spi/spi_sh_msiof.c b/drivers/spi/spi_sh_msiof.c
> index 07b4ead..658bd05 100644
> --- a/drivers/spi/spi_sh_msiof.c
> +++ b/drivers/spi/spi_sh_msiof.c
> @@ -267,6 +267,26 @@ static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p,
>  		sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs);
>  }
>  
> +static void sh_msiof_spi_write_fifo_s32(struct sh_msiof_spi_priv *p,
> +					const void *tx_buf, int words, int fs)
> +{
> +	const u32 *buf_32 = tx_buf;
> +	int k;
> +
> +	for (k = 0; k < words; k++)
> +		sh_msiof_write(p, TFDR, swab32(buf_32[k] << fs));
> +}
> +
> +static void sh_msiof_spi_write_fifo_s32u(struct sh_msiof_spi_priv *p,
> +					 const void *tx_buf, int words, int fs)
> +{
> +	const u32 *buf_32 = tx_buf;
> +	int k;
> +
> +	for (k = 0; k < words; k++)
> +		sh_msiof_write(p, TFDR, swab32(get_unaligned(&buf_32[k]) << fs));
> +}
> +
>  static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
>  				     void *rx_buf, int words, int fs)
>  {
> @@ -317,6 +337,26 @@ static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p,
>  		put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]);
>  }
>  
> +static void sh_msiof_spi_read_fifo_s32(struct sh_msiof_spi_priv *p,
> +				       void *rx_buf, int words, int fs)
> +{
> +	u32 *buf_32 = rx_buf;
> +	int k;
> +
> +	for (k = 0; k < words; k++)
> +		buf_32[k] = swab32(sh_msiof_read(p, RFDR) >> fs);
> +}
> +
> +static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
> +				       void *rx_buf, int words, int fs)
> +{
> +	u32 *buf_32 = rx_buf;
> +	int k;
> +
> +	for (k = 0; k < words; k++)
> +		put_unaligned(swab32(sh_msiof_read(p, RFDR) >> fs), &buf_32[k]);
> +}
> +
>  static int sh_msiof_spi_bits(struct spi_device *spi, struct spi_transfer *t)
>  {
>  	int bits;
> @@ -468,9 +508,17 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
>  	int bytes_done;
>  	int words;
>  	int n;
> +	bool swab;
>  
>  	bits = sh_msiof_spi_bits(spi, t);
>  
> +	if (bits <= 8 && t->len > 15 && !(t->len & 3)) {
> +		bits = 32;
> +		swab = true;
> +	} else {
> +		swab = false;
> +	}
> +
>  	/* setup bytes per word and fifo read/write functions */
>  	if (bits <= 8) {
>  		bytes_per_word = 1;
> @@ -487,6 +535,17 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
>  			rx_fifo = sh_msiof_spi_read_fifo_16u;
>  		else
>  			rx_fifo = sh_msiof_spi_read_fifo_16;
> +	} else if (swab) {
> +		bytes_per_word = 4;
> +		if ((unsigned long)t->tx_buf & 0x03)
> +			tx_fifo = sh_msiof_spi_write_fifo_s32u;
> +		else
> +			tx_fifo = sh_msiof_spi_write_fifo_s32;
> +
> +		if ((unsigned long)t->rx_buf & 0x03)
> +			rx_fifo = sh_msiof_spi_read_fifo_s32u;
> +		else
> +			rx_fifo = sh_msiof_spi_read_fifo_s32;
>  	} else {
>  		bytes_per_word = 4;
>  		if ((unsigned long)t->tx_buf & 0x03)
> -- 
> 1.7.2.3
> 
> 
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
> February 28th, so secure your free ArcSight Logger TODAY! 
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> spi-devel-general mailing list
> spi-devel-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/spi-devel-general

      reply	other threads:[~2011-01-21 17:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21 15:56 [PATCH 2/3] SPI: spi_sh_msiof: consolidate data in 8-bit mode into 32-bit words Guennadi Liakhovetski
2011-01-21 17:02 ` Grant Likely [this message]

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=20110121170256.GC7477@angua.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --cc=g.liakhovetski@gmx.de \
    --cc=linux-sh@vger.kernel.org \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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;
as well as URLs for NNTP newsgroup(s).