All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	linux-mmc <linux-mmc@vger.kernel.org>, Simon <horms@verge.net.au>,
	Magnus <magnus.damm@gmail.com>,
	Linux-SH <linux-sh@vger.kernel.org>,
	Laurent <laurent.pinchart@ideasonboard.com>,
	kobayashi <keita.kobayashi.ym@renesas.com>
Subject: Re: [PATCH 3/3 v3] mmc: sh_mmcif: calculate best clock with parent clock
Date: Wed, 22 Apr 2015 08:18:17 +0000	[thread overview]
Message-ID: <CAPDyKFrxJaWpn6UqP7aE-uM2cexPejgvG9WOtkTn8=cw1yzqtg@mail.gmail.com> (raw)
In-Reply-To: <CAMuHMdVcHT-QaPc94CS85B5aX_8xe9LTxzGJzY3a5LriQq+wHQ@mail.gmail.com>

On 22 April 2015 at 09:49, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Morimoto-san,
>
> On Wed, Apr 22, 2015 at 3:04 AM, Kuninori Morimoto
> <kuninori.morimoto.gx@renesas.com> wrote:
>>> > +static const struct sh_mmcif_parent_clk mmcif_gen2_parent_clk = {
>>> > +       .max = 97500000,
>>> > +       .min = 12187500,
>>> > +       .clkdiv_map = 0x3ff,
>>>
>>> Shouldn't this come from private data in the CPG clock driver, which supplies
>>> the parent clock? Then the mmcif driver will be independent from the parent
>>> clock.
>>
>> As Laurent mentioned in other feedback, parent clock (= CFG::MMCxCKCR)
>> is div6, and it can set 1/1 - 1/64 (= 780000000 - 12187500)
>> But, MMC can use 1/8 - 1/64 (= 97500000 - 12187500), we don't know this limit
>> came from. we thought that having limit on DIV6 is not good idea.
>
> So the upper limit is a limitation of the MMCIF hardware, while the lower
> limit is a limitation of the CPG.
>
> Then the upper limit should be either in the driver (as you did, using
> different compatible values), or it can be described in DT.
> (cfr. "git grep max.*freq -- arch/arm/boot/dts/").
> Personally, I'm leaning towards the latter.
>
> IMHO the lower limit doesn't belong here.
>
>>> > +               /* FIXME */
>>> > +               if (pclk->max != pclk->min * (pclk->max / pclk->min)) {
>>> > +                       dev_err(&host->pd->dev, "not assumed parent clk\n");
>>> > +                       return;
>>> > +               }
>>>
>>> Why?
>>
>> This time, max/min = 97500000/12187500 = 8.
>> But, we don't know the future.
>> It will be non-assumed result if it was below or similar
>> max = 91406250
>> min = 12187500 (max = min * 15/2)
>
> You can still calculate a divisor if max is not an integer multiple of min,
> can't you?
>
> And currently the check above cannot trigger, as you have hardcoded values
> in the driver source that don't trigger it.
>
>>> > +               parent_freq = 0;
>>> > +               clkdiv = 0;
>>> > +               diff_min = ~0;
>>> > +               for (i = pclk->max / pclk->min; i > 0; i--) {
>>> > +                       for (j = fls(pclk->clkdiv_map); j >= 0; j--) {
>>> > +                               if (!((1 << j) & pclk->clkdiv_map))
>>> > +                                       continue;
>>> > +
>>> > +                               myclk = ((pclk->min * i) / (1 << (j + 1)));
>>> > +                               diff = (myclk > clk) ? myclk - clk : clk - myclk;
>>> > +
>>> > +                               if (diff <= diff_min) {
>>> > +                                       parent_freq = pclk->min * i;
>>> > +                                       clkdiv = j;
>>> > +                                       diff_min = diff;
>>> > +                               }
>>> > +                       }
>>> > +               }
>>>
>>> Shouldn't the above be handled by the CPG clock driver, through a clk API?
>>
>> I don't think so.
>> it calculates best of parent clock (= from CPG) and divider (= from MMC)
>> Why CPG driver need to care about MMC's divider ??
>
> The MMCIF driver shouldn't need to be aware of the possible values supported
> by the CPG driver.
>
> Can't you loop over all MMC dividers, and
>   1. calculate the needed parent clock rate for that MMC divider,
>   2. use clk_set_rate_range()[*] to find a (close) parent clock rate,
>   3. calculate the effective clock rate based on MMC divider and parent
>      clock rate.
> and use the best effective clock rate found?
>
> [*] It's a pity the clk API doesn't seem to have a function to query or check
>     clock rates without actually setting them. Or am I missing something?

What about clk_round_rate(), can't that be used?

Kind regards
Uffe

WARNING: multiple messages have this Message-ID (diff)
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	linux-mmc <linux-mmc@vger.kernel.org>, Simon <horms@verge.net.au>,
	Magnus <magnus.damm@gmail.com>,
	Linux-SH <linux-sh@vger.kernel.org>,
	Laurent <laurent.pinchart@ideasonboard.com>,
	kobayashi <keita.kobayashi.ym@renesas.com>
Subject: Re: [PATCH 3/3 v3] mmc: sh_mmcif: calculate best clock with parent clock
Date: Wed, 22 Apr 2015 10:18:17 +0200	[thread overview]
Message-ID: <CAPDyKFrxJaWpn6UqP7aE-uM2cexPejgvG9WOtkTn8=cw1yzqtg@mail.gmail.com> (raw)
In-Reply-To: <CAMuHMdVcHT-QaPc94CS85B5aX_8xe9LTxzGJzY3a5LriQq+wHQ@mail.gmail.com>

On 22 April 2015 at 09:49, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Morimoto-san,
>
> On Wed, Apr 22, 2015 at 3:04 AM, Kuninori Morimoto
> <kuninori.morimoto.gx@renesas.com> wrote:
>>> > +static const struct sh_mmcif_parent_clk mmcif_gen2_parent_clk = {
>>> > +       .max = 97500000,
>>> > +       .min = 12187500,
>>> > +       .clkdiv_map = 0x3ff,
>>>
>>> Shouldn't this come from private data in the CPG clock driver, which supplies
>>> the parent clock? Then the mmcif driver will be independent from the parent
>>> clock.
>>
>> As Laurent mentioned in other feedback, parent clock (= CFG::MMCxCKCR)
>> is div6, and it can set 1/1 - 1/64 (= 780000000 - 12187500)
>> But, MMC can use 1/8 - 1/64 (= 97500000 - 12187500), we don't know this limit
>> came from. we thought that having limit on DIV6 is not good idea.
>
> So the upper limit is a limitation of the MMCIF hardware, while the lower
> limit is a limitation of the CPG.
>
> Then the upper limit should be either in the driver (as you did, using
> different compatible values), or it can be described in DT.
> (cfr. "git grep max.*freq -- arch/arm/boot/dts/").
> Personally, I'm leaning towards the latter.
>
> IMHO the lower limit doesn't belong here.
>
>>> > +               /* FIXME */
>>> > +               if (pclk->max != pclk->min * (pclk->max / pclk->min)) {
>>> > +                       dev_err(&host->pd->dev, "not assumed parent clk\n");
>>> > +                       return;
>>> > +               }
>>>
>>> Why?
>>
>> This time, max/min = 97500000/12187500 = 8.
>> But, we don't know the future.
>> It will be non-assumed result if it was below or similar
>> max = 91406250
>> min = 12187500 (max = min * 15/2)
>
> You can still calculate a divisor if max is not an integer multiple of min,
> can't you?
>
> And currently the check above cannot trigger, as you have hardcoded values
> in the driver source that don't trigger it.
>
>>> > +               parent_freq = 0;
>>> > +               clkdiv = 0;
>>> > +               diff_min = ~0;
>>> > +               for (i = pclk->max / pclk->min; i > 0; i--) {
>>> > +                       for (j = fls(pclk->clkdiv_map); j >= 0; j--) {
>>> > +                               if (!((1 << j) & pclk->clkdiv_map))
>>> > +                                       continue;
>>> > +
>>> > +                               myclk = ((pclk->min * i) / (1 << (j + 1)));
>>> > +                               diff = (myclk > clk) ? myclk - clk : clk - myclk;
>>> > +
>>> > +                               if (diff <= diff_min) {
>>> > +                                       parent_freq = pclk->min * i;
>>> > +                                       clkdiv = j;
>>> > +                                       diff_min = diff;
>>> > +                               }
>>> > +                       }
>>> > +               }
>>>
>>> Shouldn't the above be handled by the CPG clock driver, through a clk API?
>>
>> I don't think so.
>> it calculates best of parent clock (= from CPG) and divider (= from MMC)
>> Why CPG driver need to care about MMC's divider ??
>
> The MMCIF driver shouldn't need to be aware of the possible values supported
> by the CPG driver.
>
> Can't you loop over all MMC dividers, and
>   1. calculate the needed parent clock rate for that MMC divider,
>   2. use clk_set_rate_range()[*] to find a (close) parent clock rate,
>   3. calculate the effective clock rate based on MMC divider and parent
>      clock rate.
> and use the best effective clock rate found?
>
> [*] It's a pity the clk API doesn't seem to have a function to query or check
>     clock rates without actually setting them. Or am I missing something?

What about clk_round_rate(), can't that be used?

Kind regards
Uffe

  reply	other threads:[~2015-04-22  8:18 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <873840a4ch.wl%kuninori.morimoto.gx@renesas.com>
2015-04-21  3:49 ` mmc: sh_mmcif: add PLL support Kuninori Morimoto
2015-04-21  3:50   ` [PATCH 1/3] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto
2015-04-21  3:50   ` [PATCH 2/3] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto
2015-04-21  3:51   ` [PATCH 3/3] mmc: sh_mmcif: calculate best clock with PLL Kuninori Morimoto
2015-04-21  7:43     ` Kuninori Morimoto
2015-04-21  7:51       ` Laurent Pinchart
2015-04-21  7:58         ` Kuninori Morimoto
2015-04-21  7:53 ` [PATCH 0/3 v2] mmc: sh_mmcif: add PLL support Kuninori Morimoto
2015-04-21  7:54   ` [PATCH 1/3 v2] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto
2015-04-21  7:54   ` [PATCH 2/3 v2] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto
2015-04-21  7:55   ` [PATCH 3/3 v2] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto
2015-04-21  8:23   ` [PATCH 0/3 v2] mmc: sh_mmcif: add PLL support Kuninori Morimoto
2015-04-21  8:26 ` [PATCH 0/3 v3] " Kuninori Morimoto
2015-04-21  8:26   ` [PATCH 1/3 v3] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto
2015-04-21 10:07     ` Geert Uytterhoeven
2015-04-21 10:07       ` Geert Uytterhoeven
2015-04-21  8:27   ` [PATCH 2/3 v3] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto
2015-04-21 10:07     ` Geert Uytterhoeven
2015-04-21 10:07       ` Geert Uytterhoeven
2015-04-21  8:31   ` [PATCH 3/3 v3] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto
2015-04-21  8:31     ` Kuninori Morimoto
2015-04-21 10:31     ` Geert Uytterhoeven
2015-04-21 10:31       ` Geert Uytterhoeven
2015-04-21 13:07       ` Laurent Pinchart
2015-04-21 13:07         ` Laurent Pinchart
2015-04-22  1:05         ` Kuninori Morimoto
2015-05-04  1:04           ` Laurent Pinchart
2015-05-04  1:04             ` Laurent Pinchart
2015-05-11  2:15             ` Kuninori Morimoto
2015-05-11  2:15               ` Kuninori Morimoto
2015-04-22  1:04       ` Kuninori Morimoto
2015-04-22  7:49         ` Geert Uytterhoeven
2015-04-22  7:49           ` Geert Uytterhoeven
2015-04-22  8:18           ` Ulf Hansson [this message]
2015-04-22  8:18             ` Ulf Hansson
2015-04-22  8:22             ` Geert Uytterhoeven
2015-04-22  8:22               ` Geert Uytterhoeven
2015-04-22  9:16               ` Kuninori Morimoto
2015-04-23  8:11 ` [PATCH 0/7 v4] mmc: sh_mmcif: add parent clk support Kuninori Morimoto
2015-04-23  8:13   ` [PATCH 1/7 v4] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto
2015-04-23  8:14   ` [PATCH 2/7 v4] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto
2015-04-23  8:15   ` [PATCH 3/7 v4] mmc: sh_mmcif: remove unnecessary int clk from struct sh_mmcif_host Kuninori Morimoto
2015-04-23  8:15     ` Kuninori Morimoto
2015-04-23 10:01     ` Geert Uytterhoeven
2015-04-23 10:01       ` Geert Uytterhoeven
2015-04-23  8:16   ` [PATCH 4/7 v4] mmc: sh_mmcif: separate sh_mmcif_clk_update() into setup and prepare Kuninori Morimoto
2015-04-23 10:00     ` Geert Uytterhoeven
2015-04-23 10:00       ` Geert Uytterhoeven
2015-04-23  8:17   ` [PATCH 5/7 v4] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto
2015-04-23  8:17     ` Kuninori Morimoto
2015-05-12 10:22     ` Laurent Pinchart
2015-05-12 10:22       ` Laurent Pinchart
2015-05-13  0:08       ` Kuninori Morimoto
2015-04-23  8:18   ` [PATCH 6/7 v4] ARM: shmobile: r8a7790: add MMCIF parent clock range Kuninori Morimoto
2015-05-07  5:26     ` Simon Horman
2015-05-07  5:26       ` Simon Horman
2015-05-11  2:53       ` Kuninori Morimoto
2015-05-11  5:39         ` Simon Horman
2015-05-11  5:39           ` Simon Horman
2015-04-23  8:18   ` [PATCH 7/7 v4] ARM: shmobile: r8a7791: " Kuninori Morimoto
2015-04-23 10:07   ` [PATCH 0/7 v4] mmc: sh_mmcif: add parent clk support Laurent Pinchart
2015-04-23 10:07     ` Laurent Pinchart
2015-05-05  8:33     ` Ulf Hansson
2015-05-05  8:33       ` Ulf Hansson
2015-05-13  2:16 ` [PATCH 0/3 v5] " Kuninori Morimoto
2015-05-13  2:17   ` [PATCH 1/3 v5] mmc: sh_mmcif: add sh_mmcif_host_to_dev() macro and use it Kuninori Morimoto
2015-05-13  2:17     ` Kuninori Morimoto
2015-05-13  2:18   ` [PATCH 2/3 v5] mmc: sh_mmcif: use sh_mmcif_xxx prefix for all functions Kuninori Morimoto
2015-05-13  2:18   ` [PATCH 3/3 v5] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto
2015-05-13  2:18     ` Kuninori Morimoto
2015-05-13  7:55     ` Geert Uytterhoeven
2015-05-13  7:55       ` Geert Uytterhoeven
2015-05-13  8:37       ` Kuninori Morimoto
2015-05-13  8:43         ` Geert Uytterhoeven
2015-05-13  8:43           ` Geert Uytterhoeven
2015-05-13  9:27           ` Kuninori Morimoto
2015-05-14  7:20 ` [PATCH 0/3 v6] mmc: sh_mmcif: add parent clk support Kuninori Morimoto
2015-05-14  7:21   ` [PATCH 1/5 v6] mmc: sh_mmcif: add sh_mmcif_host_to_dev() macro and use it Kuninori Morimoto
2015-05-14  7:21     ` Kuninori Morimoto
2015-05-14  7:21   ` [PATCH 2/5 v6] mmc: sh_mmcif: use sh_mmcif_xxx prefix for all functions Kuninori Morimoto
2015-05-14  7:22   ` [PATCH 3/5 v6] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto
2015-05-14  7:22     ` Kuninori Morimoto
2015-05-14  7:23   ` [PATCH 4/5 v6] ARM: shmobile: r8a7790: add MMCIF max-frequency Kuninori Morimoto
2015-05-14  7:23   ` [PATCH 5/5 v6] ARM: shmobile: r8a7791: " Kuninori Morimoto
2015-05-22 14:01   ` [PATCH 0/3 v6] mmc: sh_mmcif: add parent clk support Ulf Hansson
2015-05-22 14:01     ` Ulf Hansson
2015-05-25  0:24     ` Kuninori Morimoto
2015-05-25  0:50       ` Simon Horman
2015-05-25  0:50         ` Simon Horman
2015-05-25  0:26     ` Simon Horman
2015-05-25  0:26       ` Simon Horman
2015-05-25  0:38       ` Kuninori Morimoto
2015-05-25  8:44     ` Ulf Hansson
2015-05-25  8:44       ` Ulf Hansson
2015-05-25  9:38       ` Kuninori Morimoto

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='CAPDyKFrxJaWpn6UqP7aE-uM2cexPejgvG9WOtkTn8=cw1yzqtg@mail.gmail.com' \
    --to=ulf.hansson@linaro.org \
    --cc=geert@linux-m68k.org \
    --cc=horms@verge.net.au \
    --cc=keita.kobayashi.ym@renesas.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    /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.