linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Guy <martinwguy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mika Westerberg <mika.westerberg-X3B1VOXEql0@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: Thu, 25 Mar 2010 13:49:32 +0000	[thread overview]
Message-ID: <56d259a01003250649ubf0e32ejc15e4f3b45ec43cd@mail.gmail.com> (raw)
In-Reply-To: <9de3769ae253830fb0eebc98d299137c59c69b8c.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>

On 3/18/10, Mika Westerberg <mika.westerberg-X3B1VOXEql0@public.gmane.org> wrote:
> This patch adds an SPI master driver for the Cirrus EP93xx SPI controller found
>  in EP93xx chips (EP9301, EP9302, EP9307, EP9312 and EP9315).
>
>  Driver currently supports only interrupt driven mode but in future we may add
>  polling mode support as well.
>
>  Signed-off-by: Mika Westerberg <mika.westerberg-X3B1VOXEql0@public.gmane.org>
>  ---

>  diff --git a/drivers/spi/ep93xx_spi.c b/drivers/spi/ep93xx_spi.c
>  new file mode 100644
>  index 0000000..17935f3
>  --- /dev/null
>  +++ b/drivers/spi/ep93xx_spi.c

>  +/**
>  + * ep93xx_spi_calc_divisors() - calculates SPI clock divisors
>  + * @espi: ep93xx SPI controller struct
>  + * @chip: divisors are calculated for this chip
>  + * @rate: maximum rate (in Hz) that this chip supports

Isn't that
>  + * @rate: desired SPI output clock rate

>  + *
>  + * Function calculates cpsr (clock pre-scaler) and scr divisors based on
>  + * given @rate and places them to @chip->div_cpsr and @chip->div_scr. If,
>  + * for some reason, divisors cannot be calculated nothing is stored and
>  + * %-EINVAL is returned.
>  + */
>  +static int ep93xx_spi_calc_divisors(const struct ep93xx_spi *espi,
>  +                                   struct ep93xx_spi_chip *chip,
>  +                                   unsigned long rate)
>  +{
...
>  +       /*
>  +        * Calculate divisors so that we can get speed according the
>  +        * following formula:
>  +        *      rate = max_speed / (cpsr * (1 + scr))
>  +        * where max_speed is same as SPI clock rate.
>  +        *
>  +        * cpsr must be even number and starts from 2, scr can be any number
>  +        * between 0 and 255.
>  +        */
>  +       for (cpsr = 2; cpsr <= 254; cpsr += 2) {
>  +               for (scr = 0; scr <= 255; scr++) {
>  +                       if ((espi->max_rate / (cpsr * (scr + 1))) < rate) {

Shouldn't that be

>  +                       if (clk_get_rate(espi->clk) / (cpsr * (scr + 1)) <= rate) {

since max_rate is the maximum usable rate, which is sspclk / 2, so the
existing code seems like it would set the divisors to give twice the
requested frequency.

Conversely, if an exact divisor of the master clock rate is requested
(such as 1843200), the "<" would give the next lower rate instead of
the requested rate so for the highest rates the doubling and this
halving would cancel out, while for lower rates you could get up to
twice the requested clock frequecy.

>  +static int __init ep93xx_spi_probe(struct platform_device *pdev)
>  +{
...
>  +       espi->max_rate = clk_get_rate(espi->clk) / 2;
>  +       espi->min_rate = clk_get_rate(espi->clk) / (254 * 255);

Isn't that
>  +       espi->min_rate = clk_get_rate(espi->clk) / (254 * 256);

since the output SPI clock frequency is sspclk / (cpsr * (1 + scr))
where cpsr = 2..254 step 2, scr = 1..255

I also notice that the code recalculates the clock divisors, programs
them ad resotres them for every transfer, even if the frequency etc is
always the same.
I don't know if this makes much difference to speed in normal
operation but it does make the debug output incredibly verbose,
halving transfer speeds when SPI debug is enabled.

Is there a suitable place to be lazy about this, so as to avoid doing
this if the transfer parameters are the same on successive operations?

Thanks

    M

------------------------------------------------------------------------------
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

  parent reply	other threads:[~2010-03-25 13:49 UTC|newest]

Thread overview: 22+ 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
     [not found] ` <cover.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>
2010-03-18 17:00   ` [PATCH v2 1/3] spi: implemented " Mika Westerberg
     [not found]   ` <9de3769ae253830fb0eebc98d299137c59c69b8c.1268930557.git.mika.westerberg-X3B1VOXEql0@public.gmane.org>
2010-03-18 17:00     ` [PATCH v2 2/3] ep93xx: added chip revision reading function Mika Westerberg
2010-03-25 13:49     ` Martin Guy [this message]
     [not found]       ` <56d259a01003250649ubf0e32ejc15e4f3b45ec43cd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-25 18:43         ` [PATCH v2 1/3] spi: implemented driver for Cirrus EP93xx SPI controller Mika Westerberg
     [not found]           ` <20100325184316.GB20512-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
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  6:26                 ` Mika Westerberg
2010-04-06  5:44                 ` Mika Westerberg
     [not found]                   ` <20100406054418.GA27465-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-06 12:50                     ` Martin Guy
     [not found]                       ` <s2g56d259a01004060550me72bd64cr35e4a83c495d6909-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-06 18:18                         ` Mika Westerberg
     [not found]                           ` <20100406181839.GA2685-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-06 21:28                             ` Martin Guy
     [not found]                               ` <x2r56d259a01004061428raffb32e9o1d42570c79c0ee56-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-09 17:56                                 ` Martin Guy
     [not found]                                   ` <l2j56d259a01004091056i91598adub4201b47c4a86a90-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-09 18:08                                     ` Martin Guy
2010-04-10 15:54                                     ` Mika Westerberg
     [not found]                                       ` <20100410155443.GG2685-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-04-11 14:24                                         ` Martin Guy
2010-04-12 10:03                                         ` Martin Guy
     [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:27     ` [PATCH v2 2/3] ep93xx: added chip revision reading function H Hartley Sweeten
     [not found]       ` <0D753D10438DA54287A00B02708426976368AC725D-gaq956PjLg32KbjnnMDalRurcAul1UnsRrxOEX5GOmysTnJN9+BGXg@public.gmane.org>
2010-03-25  9:06         ` Mika Westerberg
     [not found]           ` <20100325090638.GA20512-WfG2TfFPcQ9S6P4I59wummXnswh1EIUO@public.gmane.org>
2010-03-25 17:20             ` H Hartley Sweeten
     [not found]               ` <0D753D10438DA54287A00B02708426976368F66FD1-gaq956PjLg32KbjnnMDalRurcAul1UnsRrxOEX5GOmysTnJN9+BGXg@public.gmane.org>
2010-03-26 15:40                 ` 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=56d259a01003250649ubf0e32ejc15e4f3b45ec43cd@mail.gmail.com \
    --to=martinwguy-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=mika.westerberg-X3B1VOXEql0@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 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).