[RFC v4 2/6] mmc: core: allow to match the device tree to apply quirks

From: H. Nikolaus Schaller
Date: Fri Nov 05 2021 - 05:06:15 EST


From: Jérôme Pouiller <jerome.pouiller@xxxxxxxxxx>

MMC subsystem provides a way to apply quirks when a device match some
properties (VID, PID, etc...) Unfortunately, some SDIO devices does not
comply with the SDIO specification and does not provide reliable VID/PID
(eg. Silabs WF200).

So, the drivers for these devices rely on device tree to identify the
device.

This patch allows the MMC to also rely on the device tree to apply a
quirk.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@xxxxxxxxxx>
---
drivers/mmc/core/card.h | 3 +++
drivers/mmc/core/quirks.h | 17 +++++++++++++++++
2 files changed, 20 insertions(+)

diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index 7bd392d55cfa5..a3204c19861a4 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -59,6 +59,9 @@ struct mmc_fixup {
/* for MMC cards */
unsigned int ext_csd_rev;

+ /* Match against functions declared in device tree */
+ const char **of_compatible;
+
void (*vendor_fixup)(struct mmc_card *card, int data);
int data;
};
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index c7ef2d14b359f..ee591fd8aeca2 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -10,6 +10,7 @@
*
*/

+#include <linux/of.h>
#include <linux/mmc/sdio_ids.h>

#include "card.h"
@@ -145,6 +146,19 @@ static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = {
END_FIXUP
};

+static inline bool mmc_fixup_of_compatible_match(struct mmc_card *card,
+ const char *const *compat_list)
+{
+ struct device_node *np;
+
+ for_each_child_of_node(mmc_dev(card->host)->of_node, np) {
+ if (of_device_compatible_match(np, compat_list))
+ return true;
+ }
+
+ return false;
+}
+
static inline void mmc_fixup_device(struct mmc_card *card,
const struct mmc_fixup *table)
{
@@ -173,6 +187,9 @@ static inline void mmc_fixup_device(struct mmc_card *card,
continue;
if (rev < f->rev_start || rev > f->rev_end)
continue;
+ if (f->of_compatible &&
+ !mmc_fixup_of_compatible_match(card, f->of_compatible))
+ continue;

dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup);
f->vendor_fixup(card, f->data);
--
2.33.0