All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Chris Brandt <chris.brandt@renesas.com>
Cc: Wolfram Sang <wsa@the-dreams.de>,
	Linux I2C <linux-i2c@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Simon Horman <horms+renesas@verge.net.au>
Subject: Re: [PATCH] i2c: riic: remove clock and frequency restrictions
Date: Wed, 18 Oct 2017 16:25:01 +0200	[thread overview]
Message-ID: <CAMuHMdWLh=4mETrwXHZ0LSfx9mtBewaDV6dhHKhvhGJ=ii-Vxg@mail.gmail.com> (raw)
In-Reply-To: <20171018140459.104351-1-chris.brandt@renesas.com>

Hi Chris,

On Wed, Oct 18, 2017 at 4:04 PM, Chris Brandt <chris.brandt@renesas.com> wrote:
> Remove the restriction that the parent clock has to be a specific frequency
> and also allow any speed to be supported.
>
> Signed-off-by: Chris Brandt <chris.brandt@renesas.com>

Thanks for your patch!

> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -288,48 +283,101 @@ static const struct i2c_algorithm riic_algo = {
>         .functionality  = riic_func,
>  };
>
> -static int riic_init_hw(struct riic_dev *riic, u32 spd)
> +static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
>  {

> +       /*
> +        * Determine reference clock rate. We must be able to get the desired
> +        * frequency with only 62 clock ticks max (31 high, 31 low).
> +        * Aim for a duty of 60% LOW, 40% HIGH.
> +        */
> +       total_ticks = rate / t->bus_freq_hz;
> +       if (rate % t->bus_freq_hz)              /* round up */
> +               total_ticks++;

DIV_ROUND_UP()

> +       /*
> +        * Remove clock ticks for rise and fall times. Convert ns to clock
> +        * ticks.
> +        */
> +       brl -= t->scl_fall_ns / (1000000000/rate);
> +       brh -= t->scl_rise_ns / (1000000000/rate);

To avoid losing too much precision by the division, you can rewrite this as
e.g.

    brl -= t->scl_fall_ns * rate / 1000000000;

("scl_fall_ns * rate" should not overflow).
Perhaps DIV_ROUND_UP(), too?

> +       pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n",
> +                rate/total_ticks, ((brl+3)*100)/(brl+brh+6),
> +                t->scl_fall_ns / (1000000000/rate),
> +                t->scl_rise_ns / (1000000000/rate), cks, brl, brh);

Likewise (or: reuse the values from above?).

Gr{oetje,eeting}s,

                        Geert

WARNING: multiple messages have this Message-ID (diff)
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Chris Brandt <chris.brandt@renesas.com>
Cc: Wolfram Sang <wsa@the-dreams.de>,
	Linux I2C <linux-i2c@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Simon Horman <horms+renesas@verge.net.au>
Subject: Re: [PATCH] i2c: riic: remove clock and frequency restrictions
Date: Wed, 18 Oct 2017 16:25:01 +0200	[thread overview]
Message-ID: <CAMuHMdWLh=4mETrwXHZ0LSfx9mtBewaDV6dhHKhvhGJ=ii-Vxg@mail.gmail.com> (raw)
In-Reply-To: <20171018140459.104351-1-chris.brandt@renesas.com>

Hi Chris,

On Wed, Oct 18, 2017 at 4:04 PM, Chris Brandt <chris.brandt@renesas.com> wrote:
> Remove the restriction that the parent clock has to be a specific frequency
> and also allow any speed to be supported.
>
> Signed-off-by: Chris Brandt <chris.brandt@renesas.com>

Thanks for your patch!

> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -288,48 +283,101 @@ static const struct i2c_algorithm riic_algo = {
>         .functionality  = riic_func,
>  };
>
> -static int riic_init_hw(struct riic_dev *riic, u32 spd)
> +static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
>  {

> +       /*
> +        * Determine reference clock rate. We must be able to get the desired
> +        * frequency with only 62 clock ticks max (31 high, 31 low).
> +        * Aim for a duty of 60% LOW, 40% HIGH.
> +        */
> +       total_ticks = rate / t->bus_freq_hz;
> +       if (rate % t->bus_freq_hz)              /* round up */
> +               total_ticks++;

DIV_ROUND_UP()

> +       /*
> +        * Remove clock ticks for rise and fall times. Convert ns to clock
> +        * ticks.
> +        */
> +       brl -= t->scl_fall_ns / (1000000000/rate);
> +       brh -= t->scl_rise_ns / (1000000000/rate);

To avoid losing too much precision by the division, you can rewrite this as
e.g.

    brl -= t->scl_fall_ns * rate / 1000000000;

("scl_fall_ns * rate" should not overflow).
Perhaps DIV_ROUND_UP(), too?

> +       pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n",
> +                rate/total_ticks, ((brl+3)*100)/(brl+brh+6),
> +                t->scl_fall_ns / (1000000000/rate),
> +                t->scl_rise_ns / (1000000000/rate), cks, brl, brh);

Likewise (or: reuse the values from above?).

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2017-10-18 14:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 14:04 [PATCH] i2c: riic: remove clock and frequency restrictions Chris Brandt
2017-10-18 14:25 ` Geert Uytterhoeven [this message]
2017-10-18 14:25   ` Geert Uytterhoeven
2017-10-18 15:10   ` Chris Brandt
2017-10-18 15:14     ` Geert Uytterhoeven
2017-10-18 15:47       ` Chris Brandt
2017-10-18 16:37 ` Wolfram Sang
2017-10-18 16:41   ` Chris Brandt
2017-10-18 16:44     ` Wolfram Sang
2017-10-26 20:36     ` Wolfram Sang
2017-10-27 15:37       ` Chris Brandt

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='CAMuHMdWLh=4mETrwXHZ0LSfx9mtBewaDV6dhHKhvhGJ=ii-Vxg@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=chris.brandt@renesas.com \
    --cc=horms+renesas@verge.net.au \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=wsa@the-dreams.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.