All of lore.kernel.org
 help / color / mirror / Atom feed
From: Troy Kisky <troy.kisky@boundarydevices.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] spi: mxc_spi: Fix pre and post divider calculation
Date: Fri, 03 May 2013 13:47:33 -0700	[thread overview]
Message-ID: <51842265.7010103@boundarydevices.com> (raw)
In-Reply-To: <51835215.90602@de.bosch.com>

On 5/2/2013 10:58 PM, Dirk Behme wrote:
> Do you want to say you propose
>
> post_div = pre_div / 16;
> pre_div = 16;
>
> ?
yes, that's what I said
>
> If so:
>
> First, I agree that we have to use the same dividers in both lines.
>
> But, second, this would mean that you use /16 as max pre_div. For the 
> i.MX6 case where clk_src is 60MHz this would result in a pre-divided 
> clock of 3.75Mhz (instead of 4MHz with /15).

That does sound better for i.MX6, what about other processors using this 
file?

>
> So using /15 or /16 is just a decision of which end clocks most 
> probably are needed.
>
> If you want to be able to configure 4MHz, 2MHz, 1MHz, 500kHz etc then 
> /15 is the better choice.
>
> If you want to be able to configure 3.75Mhz, 1.875MHz, 937.5kHz, 
> 468.75kHz etc then /16 is the better choice.
>
> I vote for /15 as done by my patch.

Thanks for explaining. The downside of using /15 is that you can't get 
the slowest clock possible.
How about restructuring the code to improve both. Calculate post_div first.

pre_div = DIV_ROUND_UP(clk_src, max_hz);
/* fls(1) = 1, fls(0x80000000) = 32, fls(16) = 5 */
post_div = fls(pre_div - 1);
if (post_div > 4)
     post_div -= 4;
else
     post_div = 0;

if (post_div >= 16) {
            printf("Error: no divider for the freq: %d\n",
                                         max_hz);
            return -1;
}
pre_div = (pre_div + (1 << post_div) - 1) >> post_div;
_________________________
Checking values for largest divisor possible (16 << 15) = (1<<19) gives
post_div = 15;
pre_div = 16;

Checking 1st illegal divisor (0x80001) gives
post_div = 16;

Checking divisor 0xe0 gives
post_div = 4;
pre_div = 0xe;

Checking divisor 0xe1 gives
post_div = 4;
pre_div = 0xf;

Checking divisor 0x100 gives
post_div = 4;
pre_div = 0x10;

Checking divisor 0x101 gives
post_div = 5;
pre_div = 9;
_________________________________________
Code is simpler and more accurate

Troy

  reply	other threads:[~2013-05-03 20:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 10:59 [U-Boot] [PATCH] spi: mxc_spi: Fix pre and post divider calculation Dirk Behme
2013-05-02 18:38 ` Troy Kisky
2013-05-03  5:58   ` Dirk Behme
2013-05-03 20:47     ` Troy Kisky [this message]
2013-05-04 10:06       ` Dirk Behme
2013-05-06 18:26         ` Troy Kisky

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=51842265.7010103@boundarydevices.com \
    --to=troy.kisky@boundarydevices.com \
    --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 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.