diff mbox series

mmc: sprd: Fix eMMC init failure after hw reset

Message ID 20231204064934.21236-1-wenchao.chen@unisoc.com
State New
Headers show
Series mmc: sprd: Fix eMMC init failure after hw reset | expand

Commit Message

Wenchao Chen Dec. 4, 2023, 6:49 a.m. UTC
Some eMMC devices that do not close the auto clk gate
after hw reset will cause eMMC initialization to fail.

Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
---
 drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Ulf Hansson Dec. 7, 2023, 1:58 p.m. UTC | #1
On Mon, 4 Dec 2023 at 07:50, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
>
> Some eMMC devices that do not close the auto clk gate
> after hw reset will cause eMMC initialization to fail.
>
> Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>

I assume we want this tagged for stable kernels too, but do we have a
corresponding fixes commit that we can point out?

Kind regards
Uffe

> ---
>  drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> index 6b8a57e2d20f..bed57a1c64b5 100644
> --- a/drivers/mmc/host/sdhci-sprd.c
> +++ b/drivers/mmc/host/sdhci-sprd.c
> @@ -239,15 +239,19 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
>         div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
>         sdhci_enable_clk(host, div);
>
> +       val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> +       mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
>         /* Enable CLK_AUTO when the clock is greater than 400K. */
>         if (clk > 400000) {
> -               val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> -               mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
> -                       SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
>                 if (mask != (val & mask)) {
>                         val |= mask;
>                         sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
>                 }
> +       } else {
> +               if (val & mask) {
> +                       val &= ~mask;
> +                       sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> +               }
>         }
>  }
>
> --
> 2.17.1
>
Wenchao Chen Dec. 8, 2023, 11:52 a.m. UTC | #2
On Thu, 7 Dec 2023 at 21:59, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Mon, 4 Dec 2023 at 07:50, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
> >
> > Some eMMC devices that do not close the auto clk gate
> > after hw reset will cause eMMC initialization to fail.
> >
> > Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
>
> I assume we want this tagged for stable kernels too, but do we have a
> corresponding fixes commit that we can point out?
>
> Kind regards
> Uffe
>

Hi Uffe
Sorry, I forgot to add fixes commit.

Fixes: ff874dbc4f86 ("mmc: sdhci-sprd: Disable CLK_AUTO when the clock
is less than 400K")

Thanks

> > ---
> >  drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> > index 6b8a57e2d20f..bed57a1c64b5 100644
> > --- a/drivers/mmc/host/sdhci-sprd.c
> > +++ b/drivers/mmc/host/sdhci-sprd.c
> > @@ -239,15 +239,19 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
> >         div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
> >         sdhci_enable_clk(host, div);
> >
> > +       val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> > +       mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> >         /* Enable CLK_AUTO when the clock is greater than 400K. */
> >         if (clk > 400000) {
> > -               val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> > -               mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
> > -                       SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> >                 if (mask != (val & mask)) {
> >                         val |= mask;
> >                         sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> >                 }
> > +       } else {
> > +               if (val & mask) {
> > +                       val &= ~mask;
> > +                       sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> > +               }
> >         }
> >  }
> >
> > --
> > 2.17.1
> >
Baolin Wang Dec. 12, 2023, 2:57 a.m. UTC | #3
On 12/8/2023 7:52 PM, Wenchao Chen wrote:
> On Thu, 7 Dec 2023 at 21:59, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>>
>> On Mon, 4 Dec 2023 at 07:50, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
>>>
>>> Some eMMC devices that do not close the auto clk gate
>>> after hw reset will cause eMMC initialization to fail.
>>>
>>> Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
>>
>> I assume we want this tagged for stable kernels too, but do we have a
>> corresponding fixes commit that we can point out?
>>
>> Kind regards
>> Uffe
>>
> 
> Hi Uffe
> Sorry, I forgot to add fixes commit.
> 
> Fixes: ff874dbc4f86 ("mmc: sdhci-sprd: Disable CLK_AUTO when the clock
> is less than 400K")

With the Fixes tag, looks goo to me.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

>>> ---
>>>   drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
>>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
>>> index 6b8a57e2d20f..bed57a1c64b5 100644
>>> --- a/drivers/mmc/host/sdhci-sprd.c
>>> +++ b/drivers/mmc/host/sdhci-sprd.c
>>> @@ -239,15 +239,19 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
>>>          div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
>>>          sdhci_enable_clk(host, div);
>>>
>>> +       val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
>>> +       mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
>>>          /* Enable CLK_AUTO when the clock is greater than 400K. */
>>>          if (clk > 400000) {
>>> -               val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
>>> -               mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
>>> -                       SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
>>>                  if (mask != (val & mask)) {
>>>                          val |= mask;
>>>                          sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
>>>                  }
>>> +       } else {
>>> +               if (val & mask) {
>>> +                       val &= ~mask;
>>> +                       sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
>>> +               }
>>>          }
>>>   }
>>>
>>> --
>>> 2.17.1
>>>
Wenchao Chen Jan. 3, 2024, 1:40 a.m. UTC | #4
Gentle ping.

Thanks,
Wenchao.Chen

On Tue, 12 Dec 2023 at 10:57, Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
>
>
>
> On 12/8/2023 7:52 PM, Wenchao Chen wrote:
> > On Thu, 7 Dec 2023 at 21:59, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >>
> >> On Mon, 4 Dec 2023 at 07:50, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
> >>>
> >>> Some eMMC devices that do not close the auto clk gate
> >>> after hw reset will cause eMMC initialization to fail.
> >>>
> >>> Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
> >>
> >> I assume we want this tagged for stable kernels too, but do we have a
> >> corresponding fixes commit that we can point out?
> >>
> >> Kind regards
> >> Uffe
> >>
> >
> > Hi Uffe
> > Sorry, I forgot to add fixes commit.
> >
> > Fixes: ff874dbc4f86 ("mmc: sdhci-sprd: Disable CLK_AUTO when the clock
> > is less than 400K")
>
> With the Fixes tag, looks goo to me.
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> >>> ---
> >>>   drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
> >>>   1 file changed, 7 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> >>> index 6b8a57e2d20f..bed57a1c64b5 100644
> >>> --- a/drivers/mmc/host/sdhci-sprd.c
> >>> +++ b/drivers/mmc/host/sdhci-sprd.c
> >>> @@ -239,15 +239,19 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
> >>>          div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
> >>>          sdhci_enable_clk(host, div);
> >>>
> >>> +       val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> >>> +       mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> >>>          /* Enable CLK_AUTO when the clock is greater than 400K. */
> >>>          if (clk > 400000) {
> >>> -               val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> >>> -               mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
> >>> -                       SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> >>>                  if (mask != (val & mask)) {
> >>>                          val |= mask;
> >>>                          sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> >>>                  }
> >>> +       } else {
> >>> +               if (val & mask) {
> >>> +                       val &= ~mask;
> >>> +                       sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> >>> +               }
> >>>          }
> >>>   }
> >>>
> >>> --
> >>> 2.17.1
> >>>
Ulf Hansson Jan. 3, 2024, 10:27 a.m. UTC | #5
On Wed, 3 Jan 2024 at 02:41, Wenchao Chen <wenchao.chen666@gmail.com> wrote:
>
> Gentle ping.

Thanks for pinging and sorry for the delay!

Patch applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe

>
> Thanks,
> Wenchao.Chen
>
> On Tue, 12 Dec 2023 at 10:57, Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
> >
> >
> >
> > On 12/8/2023 7:52 PM, Wenchao Chen wrote:
> > > On Thu, 7 Dec 2023 at 21:59, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > >>
> > >> On Mon, 4 Dec 2023 at 07:50, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
> > >>>
> > >>> Some eMMC devices that do not close the auto clk gate
> > >>> after hw reset will cause eMMC initialization to fail.
> > >>>
> > >>> Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
> > >>
> > >> I assume we want this tagged for stable kernels too, but do we have a
> > >> corresponding fixes commit that we can point out?
> > >>
> > >> Kind regards
> > >> Uffe
> > >>
> > >
> > > Hi Uffe
> > > Sorry, I forgot to add fixes commit.
> > >
> > > Fixes: ff874dbc4f86 ("mmc: sdhci-sprd: Disable CLK_AUTO when the clock
> > > is less than 400K")
> >
> > With the Fixes tag, looks goo to me.
> > Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> >
> > >>> ---
> > >>>   drivers/mmc/host/sdhci-sprd.c | 10 +++++++---
> > >>>   1 file changed, 7 insertions(+), 3 deletions(-)
> > >>>
> > >>> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> > >>> index 6b8a57e2d20f..bed57a1c64b5 100644
> > >>> --- a/drivers/mmc/host/sdhci-sprd.c
> > >>> +++ b/drivers/mmc/host/sdhci-sprd.c
> > >>> @@ -239,15 +239,19 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
> > >>>          div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
> > >>>          sdhci_enable_clk(host, div);
> > >>>
> > >>> +       val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> > >>> +       mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> > >>>          /* Enable CLK_AUTO when the clock is greater than 400K. */
> > >>>          if (clk > 400000) {
> > >>> -               val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
> > >>> -               mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
> > >>> -                       SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
> > >>>                  if (mask != (val & mask)) {
> > >>>                          val |= mask;
> > >>>                          sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> > >>>                  }
> > >>> +       } else {
> > >>> +               if (val & mask) {
> > >>> +                       val &= ~mask;
> > >>> +                       sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
> > >>> +               }
> > >>>          }
> > >>>   }
> > >>>
> > >>> --
> > >>> 2.17.1
> > >>>
diff mbox series

Patch

diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
index 6b8a57e2d20f..bed57a1c64b5 100644
--- a/drivers/mmc/host/sdhci-sprd.c
+++ b/drivers/mmc/host/sdhci-sprd.c
@@ -239,15 +239,19 @@  static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
 	div = ((div & 0x300) >> 2) | ((div & 0xFF) << 8);
 	sdhci_enable_clk(host, div);
 
+	val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
+	mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
 	/* Enable CLK_AUTO when the clock is greater than 400K. */
 	if (clk > 400000) {
-		val = sdhci_readl(host, SDHCI_SPRD_REG_32_BUSY_POSI);
-		mask = SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN |
-			SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN;
 		if (mask != (val & mask)) {
 			val |= mask;
 			sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
 		}
+	} else {
+		if (val & mask) {
+			val &= ~mask;
+			sdhci_writel(host, val, SDHCI_SPRD_REG_32_BUSY_POSI);
+		}
 	}
 }