[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK00qKCsFijpK1Sj8edyUfMWByYURrdRKpnhuCxxwj6TAyP5UA@mail.gmail.com>
Date: Fri, 17 Nov 2023 18:49:59 +0800
From: Victor Shih <victorshihgli@...il.com>
To: Ulf Hansson <ulf.hansson@...aro.org>
Cc: adrian.hunter@...el.com, linux-mmc@...r.kernel.org,
linux-kernel@...r.kernel.org, benchuanggli@...il.com,
HL.Liu@...esyslogic.com.tw, Greg.tu@...esyslogic.com.tw,
takahiro.akashi@...aro.org, dlunev@...omium.org,
Ben Chuang <ben.chuang@...esyslogic.com.tw>,
Victor Shih <victor.shih@...esyslogic.com.tw>
Subject: Re: [PATCH V12 13/23] mmc: sdhci-uhs2: add set_timeout()
On Tue, Oct 3, 2023 at 6:55 PM Ulf Hansson <ulf.hansson@...aro.org> wrote:
>
> On Fri, 15 Sept 2023 at 11:44, Victor Shih <victorshihgli@...il.com> wrote:
> >
> > From: Victor Shih <victor.shih@...esyslogic.com.tw>
> >
> > This is a UHS-II version of sdhci's set_timeout() operation.
>
> This needs more explanations and justifications.
>
> Other than that, the patch looks good to me!
>
> Kind regards
> Uffe
>
Hi, Ulf
I will try to update this in version 13.
Thanks, Victor Shih
> >
> > Signed-off-by: Ben Chuang <ben.chuang@...esyslogic.com.tw>
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@...aro.org>
> > Signed-off-by: Victor Shih <victor.shih@...esyslogic.com.tw>
> > Acked-by: Adrian Hunter <adrian.hunter@...el.com>
> > ---
> >
> > Updates in V8:
> > - Initialization be combined with declaration and realigned
> > in sdhci_calc_timeout_uhs2().
> > - Forward declare struct mmc_command in sdhci_uhs2.h.
> >
> > Updates in V6:
> > - Use GENMASK() and FIELD_PREP() in some case.
> > - Use sdhci_uhs2_mode() to simplify code.
> > - Remove unnecessary functions.
> >
> > ---
> >
> > drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++
> > drivers/mmc/host/sdhci-uhs2.h | 2 +
> > 2 files changed, 74 insertions(+)
> >
> > diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c
> > index 92fb69b7e209..d519e6ce6199 100644
> > --- a/drivers/mmc/host/sdhci-uhs2.c
> > +++ b/drivers/mmc/host/sdhci-uhs2.c
> > @@ -13,6 +13,7 @@
> > #include <linux/delay.h>
> > #include <linux/module.h>
> > #include <linux/iopoll.h>
> > +#include <linux/bitfield.h>
> >
> > #include "sdhci.h"
> > #include "sdhci-uhs2.h"
> > @@ -142,6 +143,77 @@ static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, un
> > }
> > }
> >
> > +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, u8 *dead_lock)
> > +{
> > + /* timeout in us */
> > + unsigned int dead_lock_timeout = 1 * 1000 * 1000;
> > + unsigned int cmd_res_timeout = 5 * 1000;
> > + unsigned int current_timeout;
> > + u8 count;
> > +
> > + /*
> > + * Figure out needed cycles.
> > + * We do this in steps in order to fit inside a 32 bit int.
> > + * The first step is the minimum timeout, which will have a
> > + * minimum resolution of 6 bits:
> > + * (1) 2^13*1000 > 2^22,
> > + * (2) host->timeout_clk < 2^16
> > + * =>
> > + * (1) / (2) > 2^6
> > + */
> > + count = 0;
> > + current_timeout = (1 << 13) * 1000 / host->timeout_clk;
> > + while (current_timeout < cmd_res_timeout) {
> > + count++;
> > + current_timeout <<= 1;
> > + if (count >= 0xF)
> > + break;
> > + }
> > +
> > + if (count >= 0xF) {
> > + DBG("%s: Too large timeout 0x%x requested for CMD_RES!\n",
> > + mmc_hostname(host->mmc), count);
> > + count = 0xE;
> > + }
> > + *cmd_res = count;
> > +
> > + count = 0;
> > + current_timeout = (1 << 13) * 1000 / host->timeout_clk;
> > + while (current_timeout < dead_lock_timeout) {
> > + count++;
> > + current_timeout <<= 1;
> > + if (count >= 0xF)
> > + break;
> > + }
> > +
> > + if (count >= 0xF) {
> > + DBG("%s: Too large timeout 0x%x requested for DEADLOCK!\n",
> > + mmc_hostname(host->mmc), count);
> > + count = 0xE;
> > + }
> > + *dead_lock = count;
> > +
> > + return count;
> > +}
> > +
> > +static void __sdhci_uhs2_set_timeout(struct sdhci_host *host)
> > +{
> > + u8 cmd_res, dead_lock;
> > +
> > + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock);
> > + cmd_res |= FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock);
> > + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL);
> > +}
> > +
> > +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
> > +{
> > + __sdhci_set_timeout(host, cmd);
> > +
> > + if (sdhci_uhs2_mode(host))
> > + __sdhci_uhs2_set_timeout(host);
> > +}
> > +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout);
> > +
> > /*****************************************************************************\
> > * *
> > * MMC callbacks *
> > diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h
> > index 8253d50f7852..ccf4e1834c2d 100644
> > --- a/drivers/mmc/host/sdhci-uhs2.h
> > +++ b/drivers/mmc/host/sdhci-uhs2.h
> > @@ -175,9 +175,11 @@
> > #define SDHCI_UHS2_VENDOR_PTR 0xE8
> >
> > struct sdhci_host;
> > +struct mmc_command;
> >
> > void sdhci_uhs2_dump_regs(struct sdhci_host *host);
> > bool sdhci_uhs2_mode(struct sdhci_host *host);
> > void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask);
> > +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd);
> >
> > #endif /* __SDHCI_UHS2_H */
> > --
> > 2.25.1
> >
Powered by blists - more mailing lists