lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240206143711.2410135-4-msp@baylibre.com>
Date: Tue,  6 Feb 2024 15:37:10 +0100
From: Markus Schneider-Pargmann <msp@...libre.com>
To: Nishanth Menon <nm@...com>,
	Vignesh Raghavendra <vigneshr@...com>,
	Tero Kristo <kristo@...nel.org>,
	Rob Herring <robh+dt@...nel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
	Conor Dooley <conor+dt@...nel.org>,
	Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
	Santosh Shilimkar <ssantosh@...nel.org>
Cc: Andrew Davis <afd@...com>,
	linux-arm-kernel@...ts.infradead.org,
	devicetree@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Markus Schneider-Pargmann <msp@...libre.com>
Subject: [PATCH 3/4] soc: ti: k3-socinfo: Add support for nvmem cells

Support nvmem cells to retrieve chip variant, part number and
manufacturer. As multiple different devices depend on these information
it is cleaner to abstract efuse fields with nvmem cells.

If chipvariant nvmem cell is found, the driver assumes nvmem cells are
being used and tries to find the other fields as well. If it can't find
'chipvariant' it will try to create a regmap.

Some prints had to be updated as I don't read the full jtagid anymore.

Signed-off-by: Markus Schneider-Pargmann <msp@...libre.com>
Acked-by: Andrew Davis <afd@...com>
---
 drivers/soc/ti/k3-socinfo.c | 67 +++++++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 21 deletions(-)

diff --git a/drivers/soc/ti/k3-socinfo.c b/drivers/soc/ti/k3-socinfo.c
index 59101bf7cf23..99794aeb6206 100644
--- a/drivers/soc/ti/k3-socinfo.c
+++ b/drivers/soc/ti/k3-socinfo.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/mfd/syscon.h>
+#include <linux/nvmem-consumer.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/regmap.h>
@@ -114,45 +115,68 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
 	struct regmap *regmap;
 	u32 partno_id;
 	u32 variant;
-	u32 jtag_id;
 	u32 mfg;
 	int ret;
 
-	regmap = device_node_to_regmap(node);
-	if (IS_ERR(regmap))
-		return PTR_ERR(regmap);
-
-	ret = regmap_read(regmap, CTRLMMR_WKUP_JTAGID_REG, &jtag_id);
-	if (ret < 0)
-		return ret;
-
-	mfg = (jtag_id & CTRLMMR_WKUP_JTAGID_MFG_MASK) >>
-	       CTRLMMR_WKUP_JTAGID_MFG_SHIFT;
+	ret = nvmem_cell_read_u32(dev, "chipvariant", &variant);
+	if (ret && ret != -ENOENT)
+		return dev_err_probe(dev, ret,
+				     "Failed to read nvmem cell 'chipvariant': %pe",
+				     ERR_PTR(ret));
+
+	if (ret != -ENOENT) {
+		ret = nvmem_cell_read_u32(dev, "chippartno", &partno_id);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "Failed to read nvmem cell 'chippartno': %pe",
+					     ERR_PTR(ret));
+
+		ret = nvmem_cell_read_u32(dev, "chipmanufacturer", &mfg);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "Failed to read nvmem cell 'chipmanufacturer': %pe",
+					     ERR_PTR(ret));
+	} else {
+		u32 jtag_id;
+
+		regmap = device_node_to_regmap(node);
+		if (IS_ERR(regmap))
+			return PTR_ERR(regmap);
+
+		ret = regmap_read(regmap, CTRLMMR_WKUP_JTAGID_REG, &jtag_id);
+		if (ret < 0)
+			return ret;
+
+		mfg = (jtag_id & CTRLMMR_WKUP_JTAGID_MFG_MASK) >>
+		       CTRLMMR_WKUP_JTAGID_MFG_SHIFT;
+
+		variant = (jtag_id & CTRLMMR_WKUP_JTAGID_VARIANT_MASK) >>
+			  CTRLMMR_WKUP_JTAGID_VARIANT_SHIFT;
+
+		partno_id = (jtag_id & CTRLMMR_WKUP_JTAGID_PARTNO_MASK) >>
+			 CTRLMMR_WKUP_JTAGID_PARTNO_SHIFT;
+	}
 
 	if (mfg != CTRLMMR_WKUP_JTAGID_MFG_TI) {
 		dev_err(dev, "Invalid MFG SoC\n");
 		return -ENODEV;
 	}
 
-	variant = (jtag_id & CTRLMMR_WKUP_JTAGID_VARIANT_MASK) >>
-		  CTRLMMR_WKUP_JTAGID_VARIANT_SHIFT;
-
-	partno_id = (jtag_id & CTRLMMR_WKUP_JTAGID_PARTNO_MASK) >>
-		 CTRLMMR_WKUP_JTAGID_PARTNO_SHIFT;
-
 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
 	if (!soc_dev_attr)
 		return -ENOMEM;
 
 	ret = k3_chipinfo_partno_to_names(partno_id, soc_dev_attr);
 	if (ret) {
-		dev_err(dev, "Unknown SoC JTAGID[0x%08X]: %d\n", jtag_id, ret);
+		dev_err(dev, "Unknown SoC JTAGID[variant=0x%X, partno=0x%X]: %d\n",
+			variant, partno_id, ret);
 		goto err;
 	}
 
 	ret = k3_chipinfo_variant_to_sr(partno_id, variant, soc_dev_attr);
 	if (ret) {
-		dev_err(dev, "Unknown SoC SR[0x%08X]: %d\n", jtag_id, ret);
+		dev_err(dev, "Unknown SoC SR[variant=0x%X, partno=0x%X]: %d\n",
+			variant, partno_id, ret);
 		goto err;
 	}
 
@@ -166,9 +190,10 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
 		goto err_free_rev;
 	}
 
-	dev_info(dev, "Family:%s rev:%s JTAGID[0x%08x] Detected\n",
+	dev_info(dev, "Family:%s rev:%s JTAGID[variant=0x%X, partno=0x%X] Detected\n",
 		 soc_dev_attr->family,
-		 soc_dev_attr->revision, jtag_id);
+		 soc_dev_attr->revision,
+		 variant, partno_id);
 
 	return 0;
 
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ