All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 02/13] mmc: tmio: Switch to clock framework
Date: Fri, 2 Nov 2018 15:42:12 +0100	[thread overview]
Message-ID: <15491143-a6ee-0cad-5b98-0e8443ffdcbd@gmail.com> (raw)
In-Reply-To: <CAK7LNARYoaBBf-Dr6M5Rjyy2PZNv5Qbn46N_fbMavewjxcRr4w@mail.gmail.com>

On 11/02/2018 03:19 AM, Masahiro Yamada wrote:
> On Thu, Nov 1, 2018 at 8:38 PM Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>>
>> On Thu, Nov 1, 2018 at 6:39 PM Marek Vasut <marek.vasut@gmail.com> wrote:
>>>
>>> Switch the driver to using clk_get_rate()/clk_set_rate() instead of
>>> caching the mclk frequency in it's private data. This is required on
>>> the SDHI variant of the controller, where the upstream mclk need to
>>> be adjusted when using UHS modes.
>>
>> No.
>>
>> What you need to do is move tmio_sd_set_clk_rate()
>> to a platform hook.
>>
>> See Linux commit 0196c8db8363f7627df6f78615271ae0ba430500
>>
>>
>>
>>
>>> Platforms which do not support clock framework or do not support it
>>> in eg. SPL default to 100 MHz clock.
>>
>> This is bad.
>> You never know whether the default clock is 100 MHz or not.
>>
>>
>>
>>> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
>>> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>>> ---
>>> V2: Fix build on certain platforms using SPL without clock framework
>>> ---
>>>  drivers/mmc/renesas-sdhi.c | 14 ++++++--------
>>>  drivers/mmc/tmio-common.c  | 21 ++++++++++++++++++---
>>>  drivers/mmc/tmio-common.h  |  2 +-
>>>  drivers/mmc/uniphier-sd.c  | 13 +++++--------
>>>  4 files changed, 30 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c
>>> index f8dc5f57ce..1590f496d7 100644
>>> --- a/drivers/mmc/renesas-sdhi.c
>>> +++ b/drivers/mmc/renesas-sdhi.c
>>> @@ -333,7 +333,6 @@ static int renesas_sdhi_probe(struct udevice *dev)
>>>         struct tmio_sd_priv *priv = dev_get_priv(dev);
>>>         u32 quirks = dev_get_driver_data(dev);
>>>         struct fdt_resource reg_res;
>>> -       struct clk clk;
>>>         DECLARE_GLOBAL_DATA_PTR;
>>>         int ret;
>>>
>>> @@ -350,22 +349,21 @@ static int renesas_sdhi_probe(struct udevice *dev)
>>>                         quirks |= TMIO_SD_CAP_16BIT;
>>>         }
>>>
>>> -       ret = clk_get_by_index(dev, 0, &clk);
>>> +       ret = clk_get_by_index(dev, 0, &priv->clk);
>>>         if (ret < 0) {
>>>                 dev_err(dev, "failed to get host clock\n");
>>>                 return ret;
>>>         }
>>>
>>>         /* set to max rate */
>>> -       priv->mclk = clk_set_rate(&clk, ULONG_MAX);
>>> -       if (IS_ERR_VALUE(priv->mclk)) {
>>> +       ret = clk_set_rate(&priv->clk, 200000000);
>>> +       if (ret < 0) {
>>>                 dev_err(dev, "failed to set rate for host clock\n");
>>> -               clk_free(&clk);
>>> -               return priv->mclk;
>>> +               clk_free(&priv->clk);
>>> +               return ret;
>>>         }
>>>
>>> -       ret = clk_enable(&clk);
>>> -       clk_free(&clk);
>>> +       ret = clk_enable(&priv->clk);
>>>         if (ret) {
>>>                 dev_err(dev, "failed to enable host clock\n");
>>>                 return ret;
>>> diff --git a/drivers/mmc/tmio-common.c b/drivers/mmc/tmio-common.c
>>> index 5f927c6150..611fc5fdbc 100644
>>> --- a/drivers/mmc/tmio-common.c
>>> +++ b/drivers/mmc/tmio-common.c
>>> @@ -551,16 +551,28 @@ static void tmio_sd_set_ddr_mode(struct tmio_sd_priv *priv,
>>>         tmio_sd_writel(priv, tmp, TMIO_SD_IF_MODE);
>>>  }
>>>
>>> +static ulong tmio_sd_clk_get_rate(struct tmio_sd_priv *priv)
>>> +{
>>> +#if CONFIG_IS_ENABLED(CLK)
>>> +       return clk_get_rate(&priv->clk);
>>> +#else
>>> +       return 100000000;
>>> +#endif
>>> +}
>>>  static void tmio_sd_set_clk_rate(struct tmio_sd_priv *priv,
>>>                                      struct mmc *mmc)
>>>  {
>>>         unsigned int divisor;
>>>         u32 val, tmp;
>>> +       ulong mclk;
>>>
>>>         if (!mmc->clock)
>>>                 return;
>>>
>>> -       divisor = DIV_ROUND_UP(priv->mclk, mmc->clock);
>>> +       mclk = tmio_sd_clk_get_rate(priv);
>>> +
>>> +       divisor = DIV_ROUND_UP(mclk, mmc->clock);
>>>
>>>         if (divisor <= 1)
>>>                 val = (priv->caps & TMIO_SD_CAP_RCAR) ?
>>> @@ -704,6 +716,7 @@ int tmio_sd_probe(struct udevice *dev, u32 quirks)
>>>         struct tmio_sd_priv *priv = dev_get_priv(dev);
>>>         struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
>>>         fdt_addr_t base;
>>> +       ulong mclk;
>>>         int ret;
>>>
>>>         base = devfdt_get_addr(dev);
>>> @@ -744,10 +757,12 @@ int tmio_sd_probe(struct udevice *dev, u32 quirks)
>>>
>>>         tmio_sd_host_init(priv);
>>>
>>> +       mclk = tmio_sd_clk_get_rate(priv);
>>> +
>>>         plat->cfg.voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
>>> -       plat->cfg.f_min = priv->mclk /
>>> +       plat->cfg.f_min = mclk /
>>>                         (priv->caps & TMIO_SD_CAP_DIV1024 ? 1024 : 512);
>>> -       plat->cfg.f_max = priv->mclk;
>>> +       plat->cfg.f_max = mclk;
>>>         plat->cfg.b_max = U32_MAX; /* max value of TMIO_SD_SECCNT */
>>>
>>>         upriv->mmc = &plat->mmc;
>>> diff --git a/drivers/mmc/tmio-common.h b/drivers/mmc/tmio-common.h
>>> index 792b1ba5ae..fcdee4df57 100644
>>> --- a/drivers/mmc/tmio-common.h
>>> +++ b/drivers/mmc/tmio-common.h
>>> @@ -117,7 +117,7 @@ struct tmio_sd_plat {
>>>
>>>  struct tmio_sd_priv {
>>>         void __iomem                    *regbase;
>>> -       unsigned long                   mclk;
>>> +       struct clk                      clk;
>>>         unsigned int                    version;
>>>         u32                             caps;
>>>  #define TMIO_SD_CAP_NONREMOVABLE       BIT(0)  /* Nonremovable e.g. eMMC */
>>> diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c
>>> index 813c28494c..870d1c9929 100644
>>> --- a/drivers/mmc/uniphier-sd.c
>>> +++ b/drivers/mmc/uniphier-sd.c
>>> @@ -38,28 +38,25 @@ static int uniphier_sd_probe(struct udevice *dev)
>>>         struct clk clk;
>>>         int ret;
>>>
>>> -       ret = clk_get_by_index(dev, 0, &clk);
>>> +       ret = clk_get_by_index(dev, 0, &priv->clk);
>>>         if (ret < 0) {
>>>                 dev_err(dev, "failed to get host clock\n");
>>>                 return ret;
>>>         }
>>>
>>>         /* set to max rate */
>>> -       priv->mclk = clk_set_rate(&clk, ULONG_MAX);
>>> -       if (IS_ERR_VALUE(priv->mclk)) {
>>> +       ret = clk_set_rate(&priv->clk, ULONG_MAX);
>>> +       if (ret < 0) {
>>>                 dev_err(dev, "failed to set rate for host clock\n");
>>> -               clk_free(&clk);
>>> -               return priv->mclk;
>>> +               clk_free(&priv->clk);
>>> +               return ret;
>>>         }
>>>
>>>         ret = clk_enable(&clk);
>>> -       clk_free(&clk);
>>>         if (ret) {
>>>                 dev_err(dev, "failed to enable host clock\n");
>>>                 return ret;
>>>         }
>>> -#else
>>> -       priv->mclk = 100000000;
>>>  #endif
>>>
>>>         return tmio_sd_probe(dev, 0);
> 
> 
> Finally, I figure out why this patch breaks my boards.
> 
> 
> 
> 
> diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c
> index 870d1c9..d8eca30 100644
> --- a/drivers/mmc/uniphier-sd.c
> +++ b/drivers/mmc/uniphier-sd.c
> @@ -35,7 +35,6 @@ static int uniphier_sd_probe(struct udevice *dev)
>  {
>         struct tmio_sd_priv *priv = dev_get_priv(dev);
>  #ifndef CONFIG_SPL_BUILD
> -       struct clk clk;
>         int ret;
> 
>         ret = clk_get_by_index(dev, 0, &priv->clk);
> @@ -52,7 +51,7 @@ static int uniphier_sd_probe(struct udevice *dev)
>                 return ret;
>         }
> 
> -       ret = clk_enable(&clk);
> +       ret = clk_enable(&priv->clk);
>         if (ret) {
>                 dev_err(dev, "failed to enable host clock\n");
>                 return ret;

Thanks, added.

I'll also turn the clk_get_rate() into a callback and implement it
differently on socionext and renesas platforms to avoid polluting the
core code.

-- 
Best regards,
Marek Vasut

  reply	other threads:[~2018-11-02 14:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31 17:15 [U-Boot] [PATCH 01/13] mmc: tmio: Simplify pinmux handling Marek Vasut
2018-10-31 17:15 ` [U-Boot] [PATCH 02/13] mmc: tmio: Switch to clock framework Marek Vasut
2018-11-01  9:38   ` [U-Boot] [PATCH V2 " Marek Vasut
2018-11-01 11:38     ` Masahiro Yamada
2018-11-02  2:19       ` Masahiro Yamada
2018-11-02 14:42         ` Marek Vasut [this message]
2018-11-02  2:24     ` Masahiro Yamada
2018-11-02 14:43       ` Marek Vasut
2018-10-31 17:15 ` [U-Boot] [PATCH 03/13] mmc: tmio: Do not set divider to 1 in DDR mode Marek Vasut
2018-11-01 11:39   ` Masahiro Yamada
2018-11-01 12:09     ` Marek Vasut
2018-10-31 17:15 ` [U-Boot] [PATCH 04/13] mmc: tmio: Configure clock before any other IOS Marek Vasut
2018-10-31 17:15 ` [U-Boot] [PATCH 05/13] mmc: tmio: Keep generating clock when clock are enabled Marek Vasut
2018-11-01 11:46   ` Masahiro Yamada
2018-11-01 12:10     ` Marek Vasut
2018-10-31 17:15 ` [U-Boot] [PATCH 06/13] mmc: tmio: Preinitialize regulator to 3.3V Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 07/13] mmc: tmio: Improve error handling Marek Vasut
2018-11-01 11:43   ` Masahiro Yamada
2018-10-31 17:16 ` [U-Boot] [PATCH 08/13] mmc: tmio: Silence transfer errors when tuning Marek Vasut
2018-11-01 11:42   ` Masahiro Yamada
2018-11-01 12:11     ` Marek Vasut
2018-11-02  3:59       ` Masahiro Yamada
2018-11-02 14:27         ` Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 09/13] mmc: tmio: sdhi: Touch SCC only when UHS capable Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 10/13] mmc: tmio: sdhi: Clear HS400 settings when reseting SCC Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 11/13] mmc: tmio: sdhi: Implement waiting for DAT0 line state Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 12/13] mmc: tmio: sdhi: Switch CPG settings in UHS modes Marek Vasut
2018-10-31 17:16 ` [U-Boot] [PATCH 13/13] mmc: tmio: sdhi: Merge DTCNTL access into single register write Marek Vasut
2018-11-01 11:38 ` [U-Boot] [PATCH 01/13] mmc: tmio: Simplify pinmux handling Masahiro Yamada
2018-11-01 12:12   ` Marek Vasut
2018-11-02  3:58     ` Masahiro Yamada
2018-11-02 14:20       ` Marek Vasut
2018-11-02 14:35         ` Masahiro Yamada

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=15491143-a6ee-0cad-5b98-0e8443ffdcbd@gmail.com \
    --to=marek.vasut@gmail.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.