2020-05-17 22:35:01

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH 1/2] mmc: host: meson-mx-sdhc: fix manual RX FIFO flushing

For Meson8 and Meson8b SoCs the vendor driver follows the following
pattern:
- for eMMC and SD cards in .set_pdma it sets:
pdma->rxfifo_manual_flush = 1;
- for SDIO cards in .set_pdma it sets:
pdma->rxfifo_manual_flush = 0;
- before syncing the DMA read buffer is sets:
pdma->rxfifo_manual_flush |= 0x02;

Set the second bit of MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH without
clearing the first bit before syncing the DMA read buffer. This fixes a
problem where Meson8 and Meson8b SoCs would read random garbage from SD
cards. It is not clear why it worked for eMMC cards. This manifested in
the following errors when plugging in an SD card:
unrecognised SCR structure version <random number>

Fixes: 53ded1b676d199 ("mmc: host: meson-mx-sdhc: new driver for the Amlogic Meson SDHC host")
Cc: Thomas Graichen <[email protected]>
Signed-off-by: Martin Blumenstingl <[email protected]>
---
drivers/mmc/host/meson-mx-sdhc.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/meson-mx-sdhc.c b/drivers/mmc/host/meson-mx-sdhc.c
index 5c00958d7754..53e3f6a4245a 100644
--- a/drivers/mmc/host/meson-mx-sdhc.c
+++ b/drivers/mmc/host/meson-mx-sdhc.c
@@ -586,10 +586,17 @@ static irqreturn_t meson_mx_sdhc_irq_thread(int irq, void *irq_data)
cmd->data->flags & MMC_DATA_READ) {
meson_mx_sdhc_wait_cmd_ready(host->mmc);

+ /*
+ * If MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH was
+ * previously 0x1 then it has to be set to 0x3. If it
+ * was 0x0 before then it has to be set to 0x2. Without
+ * this reading SD cards sometimes transfers garbage,
+ * which results in cards not being detected due to:
+ * unrecognised SCR structure version <random number>
+ */
val = FIELD_PREP(MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
2);
- regmap_update_bits(host->regmap, MESON_SDHC_PDMA,
- MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
+ regmap_update_bits(host->regmap, MESON_SDHC_PDMA, val,
val);
}

--
2.26.2


2020-05-17 22:35:01

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH 2/2] mmc: host: meson-mx-sdhc: don't use literal 0 to initialize structs

Kbuild test robot reports the following warning in lines 56 and 87 of
drivers/mmc/host/meson-mx-sdhc-clkc.c:
Using plain integer as NULL pointer

Drop the integer value from the struct initialization to fix that
warning. This will still ensure that the compiler will zero out the
struct so it's in a well-defined state.

Fixes: 53ded1b676d199 ("mmc: host: meson-mx-sdhc: new driver for the Amlogic Meson SDHC host")
Reported-by: kbuild test robot <[email protected]>
Signed-off-by: Martin Blumenstingl <[email protected]>
---
drivers/mmc/host/meson-mx-sdhc-clkc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/meson-mx-sdhc-clkc.c b/drivers/mmc/host/meson-mx-sdhc-clkc.c
index ab0d6c68a078..e1f29b279123 100644
--- a/drivers/mmc/host/meson-mx-sdhc-clkc.c
+++ b/drivers/mmc/host/meson-mx-sdhc-clkc.c
@@ -53,7 +53,7 @@ static int meson_mx_sdhc_clk_hw_register(struct device *dev,
const struct clk_ops *ops,
struct clk_hw *hw)
{
- struct clk_init_data init = { 0 };
+ struct clk_init_data init = { };
char clk_name[32];

snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(dev),
@@ -84,7 +84,7 @@ static int meson_mx_sdhc_gate_clk_hw_register(struct device *dev,
int meson_mx_sdhc_register_clkc(struct device *dev, void __iomem *base,
struct clk_bulk_data *clk_bulk_data)
{
- struct clk_parent_data div_parent = { 0 };
+ struct clk_parent_data div_parent = { };
struct meson_mx_sdhc_clkc *clkc_data;
int ret;

--
2.26.2

2020-05-18 11:26:37

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH 1/2] mmc: host: meson-mx-sdhc: fix manual RX FIFO flushing

On Mon, 18 May 2020 at 00:29, Martin Blumenstingl
<[email protected]> wrote:
>
> For Meson8 and Meson8b SoCs the vendor driver follows the following
> pattern:
> - for eMMC and SD cards in .set_pdma it sets:
> pdma->rxfifo_manual_flush = 1;
> - for SDIO cards in .set_pdma it sets:
> pdma->rxfifo_manual_flush = 0;
> - before syncing the DMA read buffer is sets:
> pdma->rxfifo_manual_flush |= 0x02;
>
> Set the second bit of MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH without
> clearing the first bit before syncing the DMA read buffer. This fixes a
> problem where Meson8 and Meson8b SoCs would read random garbage from SD
> cards. It is not clear why it worked for eMMC cards. This manifested in
> the following errors when plugging in an SD card:
> unrecognised SCR structure version <random number>
>
> Fixes: 53ded1b676d199 ("mmc: host: meson-mx-sdhc: new driver for the Amlogic Meson SDHC host")
> Cc: Thomas Graichen <[email protected]>
> Signed-off-by: Martin Blumenstingl <[email protected]>

Applied for next, thanks!

Kind regards
Uffe


> ---
> drivers/mmc/host/meson-mx-sdhc.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/meson-mx-sdhc.c b/drivers/mmc/host/meson-mx-sdhc.c
> index 5c00958d7754..53e3f6a4245a 100644
> --- a/drivers/mmc/host/meson-mx-sdhc.c
> +++ b/drivers/mmc/host/meson-mx-sdhc.c
> @@ -586,10 +586,17 @@ static irqreturn_t meson_mx_sdhc_irq_thread(int irq, void *irq_data)
> cmd->data->flags & MMC_DATA_READ) {
> meson_mx_sdhc_wait_cmd_ready(host->mmc);
>
> + /*
> + * If MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH was
> + * previously 0x1 then it has to be set to 0x3. If it
> + * was 0x0 before then it has to be set to 0x2. Without
> + * this reading SD cards sometimes transfers garbage,
> + * which results in cards not being detected due to:
> + * unrecognised SCR structure version <random number>
> + */
> val = FIELD_PREP(MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
> 2);
> - regmap_update_bits(host->regmap, MESON_SDHC_PDMA,
> - MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
> + regmap_update_bits(host->regmap, MESON_SDHC_PDMA, val,
> val);
> }
>
> --
> 2.26.2
>

2020-05-18 23:33:57

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH 2/2] mmc: host: meson-mx-sdhc: don't use literal 0 to initialize structs

On Mon, 18 May 2020 at 00:29, Martin Blumenstingl
<[email protected]> wrote:
>
> Kbuild test robot reports the following warning in lines 56 and 87 of
> drivers/mmc/host/meson-mx-sdhc-clkc.c:
> Using plain integer as NULL pointer
>
> Drop the integer value from the struct initialization to fix that
> warning. This will still ensure that the compiler will zero out the
> struct so it's in a well-defined state.
>
> Fixes: 53ded1b676d199 ("mmc: host: meson-mx-sdhc: new driver for the Amlogic Meson SDHC host")
> Reported-by: kbuild test robot <[email protected]>
> Signed-off-by: Martin Blumenstingl <[email protected]>

Applied for next, thanks!

Kind regards
Uffe


> ---
> drivers/mmc/host/meson-mx-sdhc-clkc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/meson-mx-sdhc-clkc.c b/drivers/mmc/host/meson-mx-sdhc-clkc.c
> index ab0d6c68a078..e1f29b279123 100644
> --- a/drivers/mmc/host/meson-mx-sdhc-clkc.c
> +++ b/drivers/mmc/host/meson-mx-sdhc-clkc.c
> @@ -53,7 +53,7 @@ static int meson_mx_sdhc_clk_hw_register(struct device *dev,
> const struct clk_ops *ops,
> struct clk_hw *hw)
> {
> - struct clk_init_data init = { 0 };
> + struct clk_init_data init = { };
> char clk_name[32];
>
> snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(dev),
> @@ -84,7 +84,7 @@ static int meson_mx_sdhc_gate_clk_hw_register(struct device *dev,
> int meson_mx_sdhc_register_clkc(struct device *dev, void __iomem *base,
> struct clk_bulk_data *clk_bulk_data)
> {
> - struct clk_parent_data div_parent = { 0 };
> + struct clk_parent_data div_parent = { };
> struct meson_mx_sdhc_clkc *clkc_data;
> int ret;
>
> --
> 2.26.2
>

2020-05-25 07:58:03

by Thomas Graichen

[permalink] [raw]
Subject: Re: [PATCH 1/2] mmc: host: meson-mx-sdhc: fix manual RX FIFO flushing

On Mon, May 18, 2020 at 12:29 AM Martin Blumenstingl
<[email protected]> wrote:
>
> For Meson8 and Meson8b SoCs the vendor driver follows the following
> pattern:
> - for eMMC and SD cards in .set_pdma it sets:
> pdma->rxfifo_manual_flush = 1;
> - for SDIO cards in .set_pdma it sets:
> pdma->rxfifo_manual_flush = 0;
> - before syncing the DMA read buffer is sets:
> pdma->rxfifo_manual_flush |= 0x02;
>
> Set the second bit of MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH without
> clearing the first bit before syncing the DMA read buffer. This fixes a
> problem where Meson8 and Meson8b SoCs would read random garbage from SD
> cards. It is not clear why it worked for eMMC cards. This manifested in
> the following errors when plugging in an SD card:
> unrecognised SCR structure version <random number>
>
> Fixes: 53ded1b676d199 ("mmc: host: meson-mx-sdhc: new driver for the Amlogic Meson SDHC host")
> Cc: Thomas Graichen <[email protected]>
> Signed-off-by: Martin Blumenstingl <[email protected]>

Tested-by: thomas graichen <[email protected]>

BEFORE: on my meson8 based mxiii i got the above error and the sd card
was not useable

AFTER: no more error and sd cards works fine

> ---
> drivers/mmc/host/meson-mx-sdhc.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/meson-mx-sdhc.c b/drivers/mmc/host/meson-mx-sdhc.c
> index 5c00958d7754..53e3f6a4245a 100644
> --- a/drivers/mmc/host/meson-mx-sdhc.c
> +++ b/drivers/mmc/host/meson-mx-sdhc.c
> @@ -586,10 +586,17 @@ static irqreturn_t meson_mx_sdhc_irq_thread(int irq, void *irq_data)
> cmd->data->flags & MMC_DATA_READ) {
> meson_mx_sdhc_wait_cmd_ready(host->mmc);
>
> + /*
> + * If MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH was
> + * previously 0x1 then it has to be set to 0x3. If it
> + * was 0x0 before then it has to be set to 0x2. Without
> + * this reading SD cards sometimes transfers garbage,
> + * which results in cards not being detected due to:
> + * unrecognised SCR structure version <random number>
> + */
> val = FIELD_PREP(MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
> 2);
> - regmap_update_bits(host->regmap, MESON_SDHC_PDMA,
> - MESON_SDHC_PDMA_RXFIFO_MANUAL_FLUSH,
> + regmap_update_bits(host->regmap, MESON_SDHC_PDMA, val,
> val);
> }
>
> --
> 2.26.2
>