[PATCH 6/9] mci: core: fix extract_prv and write to string buffer

Stefan Kerkmann s.kerkmann at pengutronix.de
Tue May 28 08:39:25 PDT 2024


The product revision PRV field has a slightly different position for MMC
and SD cards. As we almost certainly don't want to use the BCD
representation for scripting the PRV is printed in a human friendly
representation.

Signed-off-by: Stefan Kerkmann <s.kerkmann at pengutronix.de>
---
 drivers/mci/mci-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index d1c425dda6..5e686c17d2 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1968,11 +1968,13 @@ static void extract_pnm(struct mci *mci, char pnm[static 7])
  * Extract the product revision from the CID
  * @param mci Instance data
  *
- * The 'PRV' is encoded in bit 63:56 in the CID
+ * The 'PRV' is encoded in bit 63:56 in the CID for SD cards and 55:48 for MMC cards
  */
-static unsigned extract_prv(struct mci *mci)
+static void extract_prv(struct mci *mci, char prv[static 8])
 {
-	return mci->cid[2] >> 24;
+	unsigned prv_bcd = IS_SD(mci) ? UNSTUFF_BITS(mci->cid, 56, 8) : UNSTUFF_BITS(mci->cid, 48, 8);
+
+	snprintf(prv, 8,"%u.%u", prv_bcd >> 4, prv_bcd & 0xf);
 }
 
 /**
@@ -2130,14 +2132,12 @@ static void mci_info(struct device *dev)
 static void mci_parse_cid(struct mci *mci) {
 	struct device *dev = &mci->dev;
 	char buffer[8];
-	unsigned int prv;
 
 	dev_add_param_uint32_fixed(dev, "cid_mid", extract_mid(mci), "0x%02X");
 	dev_add_param_uint32_fixed(dev, "cid_oid", extract_oid(mci), "0x%04X");
 	extract_pnm(mci, buffer);
 	dev_add_param_string_fixed(dev, "cid_pnm", buffer);
-	prv = extract_prv(mci);
-	snprintf(buffer, sizeof(buffer), "%u.%u", (prv >> 4) & 0xf, prv & 0xf);
+	extract_prv(mci, buffer);
 	dev_add_param_string_fixed(dev, "cid_prv", buffer);
 	dev_add_param_uint32_fixed(dev, "cid_psn", extract_psn(mci), "%0u");
 	extract_mdt(mci, buffer);

-- 
2.39.2




More information about the barebox mailing list