2021-11-10 17:17:24

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 0/6] mmc: core: extend mmc_fixup_device and transplant ti,wl1251 quirks from to be retired omap_hsmmc

PATCH V2 2021-11-10 18:17:11:
* remove setting card->ocr = 0x80 because it is no longer needed (by H. Nikolaus Schaller <[email protected]>)
* include patch "mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO" by Ulf Hansson <[email protected]>

PATCH V1 2021-11-09 11:59:08:
* merge call of mmc_fixup_device for sdio into other commit (suggested by Ulf Hansson <[email protected]>)
* do not call mmc_fixup_device(card, sdio_card_init_methods) for mmc and sd interfaces, just sdio (suggested by Ulf Hansson <[email protected]>)
* do not use a matching list but a single string constant (suggested by Ulf Hansson <[email protected]>)
* switched to "[PATCH v1]" (suggested by Ulf Hansson <[email protected]>)

RFC V4 2021-11-05 10:05:51:
* remove const from char *const * (Ulf Hansson <[email protected]>)
* use for_each_child_of_node() to scan compatible children (Ulf Hansson <[email protected]>)
(see: https://lore.kernel.org/lkml/CAPDyKFpr0kpRXoUACNNSwe8pL1S9wJPjnX+GFGS1PNezKCDYzQ@mail.gmail.com/)

RFC V3 2021-11-03 14:00:13:
* patches have been split into smaller ones a little further
* propose a new macro for setup of device tree compatible quirks
* directly include patches by [email protected]
in this series

RFC V2 2021-11-01 10:24:26:
* reworked to not misuse mmc_select_card() but add a call to
mmc_fixup_device() right after where host->ops->init_card
was called before to apply the wl1251 specific quirks.
Device tree matching is done by a new table passed to mmc_fixup_device().
suggested by: [email protected]
based on patches by: [email protected]

RFC V1 2021-10-06 13:24:13:


H. Nikolaus Schaller (3):
mmc: core: provide macro and table to match the device tree to apply
quirks
mmc: core: transplant ti,wl1251 quirks from to be retired omap_hsmmc
mmc: host: omap_hsmmc: revert special init for wl1251

Jérôme Pouiller (2):
mmc: core: rewrite mmc_fixup_device()
mmc: core: allow to match the device tree to apply quirks

Ulf Hansson (1):
mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO

drivers/mmc/core/card.h | 36 ++++++++++++++++++++
drivers/mmc/core/quirks.h | 64 +++++++++++++++++++++++++----------
drivers/mmc/core/sdio.c | 5 ++-
drivers/mmc/host/omap_hsmmc.c | 36 --------------------
4 files changed, 87 insertions(+), 54 deletions(-)

--
2.33.0



2021-11-10 17:17:25

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 1/6] mmc: core: rewrite mmc_fixup_device()

From: Jérôme Pouiller <[email protected]>

Currently, mmc_fixup_device() is a bit difficult to read because of
particularly long condition.

Signed-off-by: Jérôme Pouiller <[email protected]>
Signed-off-by: H. Nikolaus Schaller <[email protected]>
---
drivers/mmc/core/quirks.h | 41 +++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index d68e6e513a4f4..c7ef2d14b359f 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -152,22 +152,29 @@ static inline void mmc_fixup_device(struct mmc_card *card,
u64 rev = cid_rev_card(card);

for (f = table; f->vendor_fixup; f++) {
- if ((f->manfid == CID_MANFID_ANY ||
- f->manfid == card->cid.manfid) &&
- (f->oemid == CID_OEMID_ANY ||
- f->oemid == card->cid.oemid) &&
- (f->name == CID_NAME_ANY ||
- !strncmp(f->name, card->cid.prod_name,
- sizeof(card->cid.prod_name))) &&
- (f->cis_vendor == card->cis.vendor ||
- f->cis_vendor == (u16) SDIO_ANY_ID) &&
- (f->cis_device == card->cis.device ||
- f->cis_device == (u16) SDIO_ANY_ID) &&
- (f->ext_csd_rev == EXT_CSD_REV_ANY ||
- f->ext_csd_rev == card->ext_csd.rev) &&
- rev >= f->rev_start && rev <= f->rev_end) {
- dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup);
- f->vendor_fixup(card, f->data);
- }
+ if (f->manfid != CID_MANFID_ANY &&
+ f->manfid != card->cid.manfid)
+ continue;
+ if (f->oemid != CID_OEMID_ANY &&
+ f->oemid != card->cid.oemid)
+ continue;
+ if (f->name != CID_NAME_ANY &&
+ strncmp(f->name, card->cid.prod_name,
+ sizeof(card->cid.prod_name)))
+ continue;
+ if (f->cis_vendor != (u16)SDIO_ANY_ID &&
+ f->cis_vendor != card->cis.vendor)
+ continue;
+ if (f->cis_device != (u16)SDIO_ANY_ID &&
+ f->cis_device != card->cis.device)
+ continue;
+ if (f->ext_csd_rev != EXT_CSD_REV_ANY &&
+ f->ext_csd_rev != card->ext_csd.rev)
+ continue;
+ if (rev < f->rev_start || rev > f->rev_end)
+ continue;
+
+ dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup);
+ f->vendor_fixup(card, f->data);
}
}
--
2.33.0


2021-11-10 17:17:41

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 3/6] mmc: core: provide macro and table to match the device tree to apply quirks

This (initially empty) table allows to match quirks early based
on .compatible of the child node of some mmc/sdio interface.

This allows to add quirks based on device tree instead of having
card specific code in the host ops.

A new macro SDIO_FIXUP_COMPATIBLE makes the definition readable.

And we call mmc_fixup_device(sdio_card_init_methods) just after
where host->ops->init_card() can be optionally called.

Signed-off-by: H. Nikolaus Schaller <[email protected]>
---
drivers/mmc/core/card.h | 15 +++++++++++++++
drivers/mmc/core/quirks.h | 4 ++++
drivers/mmc/core/sdio.c | 1 +
3 files changed, 20 insertions(+)

diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index 483e7f2f1039e..216faf5ad1021 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -122,6 +122,21 @@ struct mmc_fixup {
_vendor, _device, \
_fixup, _data, EXT_CSD_REV_ANY) \

+#define SDIO_FIXUP_COMPATIBLE(_compatible, _fixup, _data) \
+ { \
+ .name = CID_NAME_ANY, \
+ .manfid = CID_MANFID_ANY, \
+ .oemid = CID_OEMID_ANY, \
+ .rev_start = 0, \
+ .rev_end = -1ull, \
+ .cis_vendor = SDIO_ANY_ID, \
+ .cis_device = SDIO_ANY_ID, \
+ .vendor_fixup = (_fixup), \
+ .data = (_data), \
+ .ext_csd_rev = EXT_CSD_REV_ANY, \
+ .of_compatible = _compatible, \
+ }
+
#define cid_rev(hwrev, fwrev, year, month) \
(((u64) hwrev) << 40 | \
((u64) fwrev) << 32 | \
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index 4a767f2fbaaaa..a23df65332cdf 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -146,6 +146,10 @@ static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = {
END_FIXUP
};

+static const struct mmc_fixup __maybe_unused sdio_card_init_methods[] = {
+ END_FIXUP
+};
+
static inline bool mmc_fixup_of_compatible_match(struct mmc_card *card,
const char *compatible)
{
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 68edf7a615be5..cf8ee66990508 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -707,6 +707,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
*/
if (host->ops->init_card)
host->ops->init_card(host, card);
+ mmc_fixup_device(card, sdio_card_init_methods);

/*
* If the host and card support UHS-I mode request the card
--
2.33.0


2021-11-10 17:17:42

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 5/6] mmc: core: transplant ti,wl1251 quirks from to be retired omap_hsmmc

The TiWi WL1251 WiFi chip needs special setup of the sdio
interface before it can be probed.

So far, this is done in omap_hsmmc_init_card() in omap_hsmmc.c
which makes it useable only if connected to omap devices
which use the omap_hsmmc. The OpenPandora is the most promient
example.

There are plans to switch to a newer sdhci-omap driver and
retire omap_hsmmc. Hence this quirk must be reworked or moved
somewhere else. Ideally to some location that is not dependent
on the specific SoC mmc host driver.

This is achieved by the new mmc_fixup_device() option introduced
by ("mmc: allow to match the device tree to apply quirks") to match
through device tree compatible string.

This quirk will be called early right after where host->ops->init_card()
and thus omap_hsmmc_init_card() was previously called.

Note that we do not need to transplant

card->ocr = 0x80;

because we rely on ("mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO").

Signed-off-by: H. Nikolaus Schaller <[email protected]>
---
drivers/mmc/core/card.h | 18 ++++++++++++++++++
drivers/mmc/core/quirks.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index 216faf5ad1021..99045e138ba48 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -168,6 +168,24 @@ static inline void __maybe_unused add_limit_rate_quirk(struct mmc_card *card,
card->quirk_max_rate = data;
}

+static inline void __maybe_unused wl1251_quirk(struct mmc_card *card,
+ int data)
+{
+ /*
+ * We have TI wl1251 attached to this mmc. Pass this
+ * information to the SDIO core because it can't be
+ * probed by normal methods.
+ */
+
+ dev_info(card->host->parent, "found wl1251\n");
+ card->quirks |= MMC_QUIRK_NONSTD_SDIO;
+ card->cccr.wide_bus = 1;
+ card->cis.vendor = 0x104c;
+ card->cis.device = 0x9066;
+ card->cis.blksize = 512;
+ card->cis.max_dtr = 24000000;
+}
+
/*
* Quirk add/remove for MMC products.
*/
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index a23df65332cdf..20f5687272778 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -147,6 +147,8 @@ static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = {
};

static const struct mmc_fixup __maybe_unused sdio_card_init_methods[] = {
+ SDIO_FIXUP_COMPATIBLE("ti,wl1251", wl1251_quirk, 0),
+
END_FIXUP
};

--
2.33.0


2021-11-10 17:17:48

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 4/6] mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO

From: Ulf Hansson <[email protected]>

The mmc core takes a specific path to support initializing of a
non-standard SDIO card. This is triggered by looking for the card-quirk,
MMC_QUIRK_NONSTD_SDIO.

In mmc_sdio_init_card() this gets rather messy, as it causes the code to
bail out earlier, compared to the usual path. This leads to that the OCR
doesn't get saved properly in card->ocr. Fortunately, only omap_hsmmc has
been using the MMC_QUIRK_NONSTD_SDIO and is dealing with the issue, by
assigning a hardcoded value (0x80) to card->ocr from an ->init_card() ops.

To make the behaviour consistent, let's instead rely on the core to save
the OCR in card->ocr during initialization.

Reported-by: H. Nikolaus Schaller <[email protected]>
Signed-off-by: Ulf Hansson <[email protected]>
Signed-off-by: H. Nikolaus Schaller <[email protected]>
---
drivers/mmc/core/sdio.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index cf8ee66990508..41164748723d2 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -709,6 +709,8 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
host->ops->init_card(host, card);
mmc_fixup_device(card, sdio_card_init_methods);

+ card->ocr = ocr_card;
+
/*
* If the host and card support UHS-I mode request the card
* to switch to 1.8V signaling level. No 1.8v signalling if
@@ -821,7 +823,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
goto mismatch;
}
}
- card->ocr = ocr_card;
+
mmc_fixup_device(card, sdio_fixup_methods);

if (card->type == MMC_TYPE_SD_COMBO) {
--
2.33.0


2021-11-10 17:17:52

by H. Nikolaus Schaller

[permalink] [raw]
Subject: [PATCH v2 6/6] mmc: host: omap_hsmmc: revert special init for wl1251

Replaces: commit f6498b922e57 ("mmc: host: omap_hsmmc: add code for special init of wl1251 to get rid of pandora_wl1251_init_card")
Requires: commit ("mmc: core: transplant ti,wl1251 quirks from to be retired omap_hsmmc")

After moving the wl1251 quirks from omap_hsmmc_init_card() to wl1251_quirk()
and sdio_card_init_methods[] we can remove omap_hsmmc_init_card() completely.

This also removes the specialization on the combination of omap_hsmmc and wl1251.

Related-to: commit f6498b922e57 ("mmc: host: omap_hsmmc: add code for special init of wl1251 to get rid of pandora_wl1251_init_card")
Related-to: commit 2398c41d6432 ("omap: pdata-quirks: remove openpandora quirks for mmc3 and wl1251")
Related-to: commit f9d50fef4b64 ("ARM: OMAP2+: omap3-pandora: add wifi support")
Signed-off-by: H. Nikolaus Schaller <[email protected]>
---
drivers/mmc/host/omap_hsmmc.c | 36 -----------------------------------
1 file changed, 36 deletions(-)

diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 6960e305e0a39..9749639ea8977 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1504,41 +1504,6 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
omap_hsmmc_set_bus_mode(host);
}

-static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
-{
- struct omap_hsmmc_host *host = mmc_priv(mmc);
-
- if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) {
- struct device_node *np = mmc_dev(mmc)->of_node;
-
- /*
- * REVISIT: should be moved to sdio core and made more
- * general e.g. by expanding the DT bindings of child nodes
- * to provide a mechanism to provide this information:
- * Documentation/devicetree/bindings/mmc/mmc-card.txt
- */
-
- np = of_get_compatible_child(np, "ti,wl1251");
- if (np) {
- /*
- * We have TI wl1251 attached to MMC3. Pass this
- * information to the SDIO core because it can't be
- * probed by normal methods.
- */
-
- dev_info(host->dev, "found wl1251\n");
- card->quirks |= MMC_QUIRK_NONSTD_SDIO;
- card->cccr.wide_bus = 1;
- card->cis.vendor = 0x104c;
- card->cis.device = 0x9066;
- card->cis.blksize = 512;
- card->cis.max_dtr = 24000000;
- card->ocr = 0x80;
- of_node_put(np);
- }
- }
-}
-
static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
{
struct omap_hsmmc_host *host = mmc_priv(mmc);
@@ -1667,7 +1632,6 @@ static struct mmc_host_ops omap_hsmmc_ops = {
.set_ios = omap_hsmmc_set_ios,
.get_cd = mmc_gpio_get_cd,
.get_ro = mmc_gpio_get_ro,
- .init_card = omap_hsmmc_init_card,
.enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
};

--
2.33.0


2021-11-10 17:20:50

by H. Nikolaus Schaller

[permalink] [raw]
Subject: Re: [PATCH v2 4/6] mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO

> Am 10.11.2021 um 18:17 schrieb H. Nikolaus Schaller <[email protected]>:
>
> From: Ulf Hansson <[email protected]>
>
> The mmc core takes a specific path to support initializing of a
> non-standard SDIO card. This is triggered by looking for the card-quirk,
> MMC_QUIRK_NONSTD_SDIO.
>
> if (card->type == MMC_TYPE_SD_COMBO) {
> --
> 2.33.0
>

Sorry, I just recognised after pressing the send button that with "early"
you probably meant this to be 1/6... Should I resubmit?

BR,
Nikolaus



2021-11-11 09:22:06

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2 4/6] mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO

On Wed, 10 Nov 2021 at 18:20, H. Nikolaus Schaller <[email protected]> wrote:
>
> > Am 10.11.2021 um 18:17 schrieb H. Nikolaus Schaller <[email protected]>:
> >
> > From: Ulf Hansson <[email protected]>
> >
> > The mmc core takes a specific path to support initializing of a
> > non-standard SDIO card. This is triggered by looking for the card-quirk,
> > MMC_QUIRK_NONSTD_SDIO.
> >
> > if (card->type == MMC_TYPE_SD_COMBO) {
> > --
> > 2.33.0
> >
>
> Sorry, I just recognised after pressing the send button that with "early"
> you probably meant this to be 1/6... Should I resubmit?

No need to re-submit, this works fine!

Kind regards
Uffe

2021-11-11 12:10:58

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] mmc: core: extend mmc_fixup_device and transplant ti,wl1251 quirks from to be retired omap_hsmmc

On Wed, 10 Nov 2021 at 18:17, H. Nikolaus Schaller <[email protected]> wrote:
>
> PATCH V2 2021-11-10 18:17:11:
> * remove setting card->ocr = 0x80 because it is no longer needed (by H. Nikolaus Schaller <[email protected]>)
> * include patch "mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO" by Ulf Hansson <[email protected]>
>
> PATCH V1 2021-11-09 11:59:08:
> * merge call of mmc_fixup_device for sdio into other commit (suggested by Ulf Hansson <[email protected]>)
> * do not call mmc_fixup_device(card, sdio_card_init_methods) for mmc and sd interfaces, just sdio (suggested by Ulf Hansson <[email protected]>)
> * do not use a matching list but a single string constant (suggested by Ulf Hansson <[email protected]>)
> * switched to "[PATCH v1]" (suggested by Ulf Hansson <[email protected]>)
>
> RFC V4 2021-11-05 10:05:51:
> * remove const from char *const * (Ulf Hansson <[email protected]>)
> * use for_each_child_of_node() to scan compatible children (Ulf Hansson <[email protected]>)
> (see: https://lore.kernel.org/lkml/CAPDyKFpr0kpRXoUACNNSwe8pL1S9wJPjnX+GFGS1PNezKCDYzQ@mail.gmail.com/)
>
> RFC V3 2021-11-03 14:00:13:
> * patches have been split into smaller ones a little further
> * propose a new macro for setup of device tree compatible quirks
> * directly include patches by [email protected]
> in this series
>
> RFC V2 2021-11-01 10:24:26:
> * reworked to not misuse mmc_select_card() but add a call to
> mmc_fixup_device() right after where host->ops->init_card
> was called before to apply the wl1251 specific quirks.
> Device tree matching is done by a new table passed to mmc_fixup_device().
> suggested by: [email protected]
> based on patches by: [email protected]
>
> RFC V1 2021-10-06 13:24:13:
>
>
> H. Nikolaus Schaller (3):
> mmc: core: provide macro and table to match the device tree to apply
> quirks
> mmc: core: transplant ti,wl1251 quirks from to be retired omap_hsmmc
> mmc: host: omap_hsmmc: revert special init for wl1251
>
> Jérôme Pouiller (2):
> mmc: core: rewrite mmc_fixup_device()
> mmc: core: allow to match the device tree to apply quirks
>
> Ulf Hansson (1):
> mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO
>
> drivers/mmc/core/card.h | 36 ++++++++++++++++++++
> drivers/mmc/core/quirks.h | 64 +++++++++++++++++++++++++----------
> drivers/mmc/core/sdio.c | 5 ++-
> drivers/mmc/host/omap_hsmmc.c | 36 --------------------
> 4 files changed, 87 insertions(+), 54 deletions(-)
>

This looks good to me, I will queue it up as soon as rc1 is out, thanks!

Kind regards
Uffe

2021-11-11 13:50:40

by H. Nikolaus Schaller

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] mmc: core: extend mmc_fixup_device and transplant ti,wl1251 quirks from to be retired omap_hsmmc



> Am 11.11.2021 um 13:10 schrieb Ulf Hansson <[email protected]>:
>
> On Wed, 10 Nov 2021 at 18:17, H. Nikolaus Schaller <[email protected]> wrote:
>>
>>
>> drivers/mmc/core/card.h | 36 ++++++++++++++++++++
>> drivers/mmc/core/quirks.h | 64 +++++++++++++++++++++++++----------
>> drivers/mmc/core/sdio.c | 5 ++-
>> drivers/mmc/host/omap_hsmmc.c | 36 --------------------
>> 4 files changed, 87 insertions(+), 54 deletions(-)
>>
>
> This looks good to me, I will queue it up as soon as rc1 is out, thanks!

Thanks!

Best regards,
Nikolaus


2021-11-11 14:11:10

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] mmc: core: extend mmc_fixup_device and transplant ti,wl1251 quirks from to be retired omap_hsmmc

* H. Nikolaus Schaller <[email protected]> [211111 13:51]:
>
>
> > Am 11.11.2021 um 13:10 schrieb Ulf Hansson <[email protected]>:
> >
> > On Wed, 10 Nov 2021 at 18:17, H. Nikolaus Schaller <[email protected]> wrote:
> >>
> >>
> >> drivers/mmc/core/card.h | 36 ++++++++++++++++++++
> >> drivers/mmc/core/quirks.h | 64 +++++++++++++++++++++++++----------
> >> drivers/mmc/core/sdio.c | 5 ++-
> >> drivers/mmc/host/omap_hsmmc.c | 36 --------------------
> >> 4 files changed, 87 insertions(+), 54 deletions(-)
> >>
> >
> > This looks good to me, I will queue it up as soon as rc1 is out, thanks!
>
> Thanks!

Thanks for sorting this out!

Tony