All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg-X3B1VOXEql0@public.gmane.org>
To: Martin Guy <martinwguy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v2 1/3] spi: implemented driver for Cirrus EP93xx SPI	controller
Date: Sat, 10 Apr 2010 18:54:43 +0300	[thread overview]
Message-ID: <20100410155443.GG2685@gw.healthdatacare.com> (raw)
In-Reply-To: <l2j56d259a01004091056i91598adub4201b47c4a86a90-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Fri, Apr 09, 2010 at 06:56:49PM +0100, Martin Guy wrote:
> 
> you end up with:
> 
>         while (espi->tx < t->len) {
>                 ep93xx_do_write(espi, t);
> 
>                 while (ep93xx_spi_read_u8(espi, SSPSR) & SSPSR_BSY);
> 
>                 ep93xx_do_read(espi, t);
>         }
> 
> This makes each interrupt routine take about 2ms to complete. I don't
> know if that's unacceptably long or not.

Yeah. It's probably bad thing to spend that much time in interrupt
handler.

> I've coded up a version that works differently, by filling the TX FIFO
> and returning from the IRQ routine - it then get interrupted again
> when the TX FIFO is half empty (and the RX FIFO is half full), at
> which point it empties and fills them
> and waits for another interrupt.
> The end of the transfer has to be handled specially because the
> interrupt is held high as long as the TX FIFO is half empty or less,
> so we have to busy-wait while the final four words are transmitted and
> received, concluding the transfer.
> 
> The result is an increase in MMC card read or write speed from 232kB/s
> to 315kB/s and a decrease in CPU usage from 100% to 55-60%, tested
> with plain 1GB SD card.
> A 2GB MLC card instead gets 323kB/sec in read and 319kB/sec in write (!).
> 
> SDHC cards don't work at all - they are rejected by the MMC-SPI driver
> (eror -38, ENOSYS: Function not implemented), the same as happens with
> the old CIrrus driver.
> 
> I've only changed the ep93xx_spi_read_write() function in your v2
> interrupting driver: the new version is below. Would you see if it
> works with your other SPI hardware?

I tested your version with few SD cards (one of them is SDHC) and
works without any problems (and performance is better). Also tested
with SPI EEPROM through at25 driver and it works well.

However, I would really like to have this code to be simpler and
to be suitable for polling as well. I wrote myself version that is
based on yours and also borrowed this fifo_level thingy from
amba-pl022 driver. I tested it with the same devices and performance
seems to be in par with your version.

Can you try following with your devices?

struct ep93xx_spi {
	...
	size_t	fifo_level;
};

static int ep93xx_spi_read_write(struct ep93xx_spi *espi)
{
        struct spi_message *msg;
        struct spi_transfer *t;
        unsigned long flags;

        spin_lock_irqsave(&espi->lock, flags);
        msg = espi->current_msg;
        spin_unlock_irqrestore(&espi->lock, flags);

        t = msg->state;

        if (espi->tx == 0 && espi->rx == 0)
                espi->fifo_level = 0;

        while ((ep93xx_spi_read_u8(espi, SSPSR) & SSPSR_RNE) &&
                espi->rx < t->len) {
                ep93xx_do_read(espi, t);
                espi->fifo_level--;
        }

        while (espi->fifo_level < 8 && espi->tx < t->len) {
                ep93xx_do_write(espi, t);
                espi->fifo_level++;
        }

        /* is transfer finished? */
        if (espi->tx == t->len && espi->rx == t->len) {
                msg->actual_length += t->len;
                return t->len;
        }

        return 0;
}

Thanks,
MW

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

WARNING: multiple messages have this Message-ID (diff)
From: mika.westerberg@iki.fi (Mika Westerberg)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/3] spi: implemented driver for Cirrus EP93xx SPI controller
Date: Sat, 10 Apr 2010 18:54:43 +0300	[thread overview]
Message-ID: <20100410155443.GG2685@gw.healthdatacare.com> (raw)
In-Reply-To: <l2j56d259a01004091056i91598adub4201b47c4a86a90@mail.gmail.com>

On Fri, Apr 09, 2010 at 06:56:49PM +0100, Martin Guy wrote:
> 
> you end up with:
> 
>         while (espi->tx < t->len) {
>                 ep93xx_do_write(espi, t);
> 
>                 while (ep93xx_spi_read_u8(espi, SSPSR) & SSPSR_BSY);
> 
>                 ep93xx_do_read(espi, t);
>         }
> 
> This makes each interrupt routine take about 2ms to complete. I don't
> know if that's unacceptably long or not.

Yeah. It's probably bad thing to spend that much time in interrupt
handler.

> I've coded up a version that works differently, by filling the TX FIFO
> and returning from the IRQ routine - it then get interrupted again
> when the TX FIFO is half empty (and the RX FIFO is half full), at
> which point it empties and fills them
> and waits for another interrupt.
> The end of the transfer has to be handled specially because the
> interrupt is held high as long as the TX FIFO is half empty or less,
> so we have to busy-wait while the final four words are transmitted and
> received, concluding the transfer.
> 
> The result is an increase in MMC card read or write speed from 232kB/s
> to 315kB/s and a decrease in CPU usage from 100% to 55-60%, tested
> with plain 1GB SD card.
> A 2GB MLC card instead gets 323kB/sec in read and 319kB/sec in write (!).
> 
> SDHC cards don't work at all - they are rejected by the MMC-SPI driver
> (eror -38, ENOSYS: Function not implemented), the same as happens with
> the old CIrrus driver.
> 
> I've only changed the ep93xx_spi_read_write() function in your v2
> interrupting driver: the new version is below. Would you see if it
> works with your other SPI hardware?

I tested your version with few SD cards (one of them is SDHC) and
works without any problems (and performance is better). Also tested
with SPI EEPROM through at25 driver and it works well.

However, I would really like to have this code to be simpler and
to be suitable for polling as well. I wrote myself version that is
based on yours and also borrowed this fifo_level thingy from
amba-pl022 driver. I tested it with the same devices and performance
seems to be in par with your version.

Can you try following with your devices?

struct ep93xx_spi {
	...
	size_t	fifo_level;
};

static int ep93xx_spi_read_write(struct ep93xx_spi *espi)
{
        struct spi_message *msg;
        struct spi_transfer *t;
        unsigned long flags;

        spin_lock_irqsave(&espi->lock, flags);
        msg = espi->current_msg;
        spin_unlock_irqrestore(&espi->lock, flags);

        t = msg->state;

        if (espi->tx == 0 && espi->rx == 0)
                espi->fifo_level = 0;

        while ((ep93xx_spi_read_u8(espi, SSPSR) & SSPSR_RNE) &&
                espi->rx < t->len) {
                ep93xx_do_read(espi, t);
                espi->fifo_level--;
        }

        while (espi->fifo_level < 8 && espi->tx < t->len) {
                ep93xx_do_write(espi, t);
                espi->fifo_level++;
        }

        /* is transfer finished? */
        if (espi->tx == t->len && espi->rx == t->len) {
                msg->actual_length += t->len;
                return t->len;
        }

        return 0;
}

Thanks,
MW

  parent reply	other threads:[~2010-04-10 15:54 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-18 16:59 [PATCH v2 0/3] spi: driver for Cirrus EP93xx SPI controller Mika Westerberg
2010-03-18 16:59 ` Mika Westerberg
     [not found] ` <cover.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>
2010-03-18 17:00   ` [PATCH v2 1/3] spi: implemented " Mika Westerberg
2010-03-18 17:00     ` Mika Westerberg
     [not found]   ` <c222c3df9c94d9ec919817f640a953e4f45ae99b.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>
2010-03-18 17:00     ` [PATCH v2 3/3] ep93xx: SPI driver platform support code Mika Westerberg
2010-03-18 17:00       ` Mika Westerberg
2010-03-18 17:27     ` [PATCH v2 2/3] ep93xx: added chip revision reading function H Hartley Sweeten
2010-03-18 17:27       ` [spi-devel-general] " H Hartley Sweeten
     [not found]       ` <0D753D10438DA54287A00B02708426976368AC725D-gaq956PjLg32KbjnnMDalRurcAul1UnsRrxOEX5GOmysTnJN9+BGXg@public.gmane.org>
2010-03-25  9:06         ` Mika Westerberg
2010-03-25  9:06           ` [spi-devel-general] " Mika Westerberg
     [not found]           ` <20100325090638.GA20512-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-03-25 17:20             ` H Hartley Sweeten
2010-03-25 17:20               ` [spi-devel-general] " H Hartley Sweeten
     [not found]               ` <0D753D10438DA54287A00B02708426976368F66FD1-gaq956PjLg32KbjnnMDalRurcAul1UnsRrxOEX5GOmysTnJN9+BGXg@public.gmane.org>
2010-03-26 15:40                 ` Martin Guy
2010-03-26 15:40                   ` [spi-devel-general] " Martin Guy
     [not found]   ` <9de3769ae253830fb0eebc98d299137c59c69b8c.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>
2010-03-18 17:00     ` Mika Westerberg
2010-03-18 17:00       ` Mika Westerberg
2010-03-20 18:07       ` Martin Guy
2010-03-20 18:25         ` Daniel Mack
2010-03-20 18:40           ` Martin Guy
2010-03-20 19:31             ` H Hartley Sweeten
2010-03-20 19:48               ` Martin Guy
2010-03-20 18:31         ` Mika Westerberg
2010-03-20 19:42           ` H Hartley Sweeten
2010-03-21 18:45             ` Mika Westerberg
2010-03-25 13:49     ` [PATCH v2 1/3] spi: implemented driver for Cirrus EP93xx SPI controller Martin Guy
2010-03-25 13:49       ` Martin Guy
     [not found]       ` <56d259a01003250649ubf0e32ejc15e4f3b45ec43cd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-25 18:43         ` Mika Westerberg
2010-03-25 18:43           ` Mika Westerberg
     [not found]           ` <20100325184316.GB20512-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-01  0:15             ` Martin Guy
2010-04-01  0:15               ` Martin Guy
     [not found]               ` <s2n56d259a01003311715ke5b93a96v9d453ec32f08ec29-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-01  3:00                 ` Ryan Mallon
2010-04-01  3:00                   ` Ryan Mallon
2010-04-01  6:26                 ` Mika Westerberg
2010-04-01  6:26                   ` Mika Westerberg
2010-04-06  5:44                 ` Mika Westerberg
2010-04-06  5:44                   ` Mika Westerberg
     [not found]                   ` <20100406054418.GA27465-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-06 12:50                     ` Martin Guy
2010-04-06 12:50                       ` Martin Guy
     [not found]                       ` <s2g56d259a01004060550me72bd64cr35e4a83c495d6909-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-06 18:18                         ` Mika Westerberg
2010-04-06 18:18                           ` Mika Westerberg
     [not found]                           ` <20100406181839.GA2685-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-06 21:28                             ` Martin Guy
2010-04-06 21:28                               ` Martin Guy
     [not found]                               ` <x2r56d259a01004061428raffb32e9o1d42570c79c0ee56-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-09 17:56                                 ` Martin Guy
2010-04-09 17:56                                   ` Martin Guy
     [not found]                                   ` <l2j56d259a01004091056i91598adub4201b47c4a86a90-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-09 18:08                                     ` Martin Guy
2010-04-09 18:08                                       ` Martin Guy
2010-04-10 15:54                                     ` Mika Westerberg [this message]
2010-04-10 15:54                                       ` Mika Westerberg
     [not found]                                       ` <20100410155443.GG2685-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-11 14:24                                         ` Martin Guy
2010-04-11 14:24                                           ` Martin Guy
2010-04-12 10:03                                         ` Martin Guy
2010-04-12 10:03                                           ` Martin Guy

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=20100410155443.GG2685@gw.healthdatacare.com \
    --to=mika.westerberg-x3b1voxeql0@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=martinwguy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.