Skip to contentSkip to conversation

soc: samsung: exynos-chipid: Pass revision reg offsets

PATCH Applied Sam Protsenko 3 participants 5 messages Oct 14, 2021 – Oct 15, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 soc: samsung: exynos-chipid: Pass revision reg offsets

Old Exynos SoCs have both Product ID and Revision ID in one single register, while new SoCs tend to have two separate registers for those IDs. Implement handling of both cases by passing Revision ID register offsets in driver data.

Previously existing macros for Exynos4210 (removed in this patch) were incorrect:

    #define EXYNOS_SUBREV_MASK         (0xf << 4)
    #define EXYNOS_MAINREV_MASK        (0xf << 0)

Actual format of PRO_ID register in Exynos4210 (offset 0x0):

[31:12] Product ID
[9:8] Package information
[7:4] Main Revision Number
[3:0] Sub Revision Number

This patch doesn't change the behavior on existing platforms, so '/sys/devices/soc0/revision' will show the same string as before.

---
Changes in v2:
- Renamed *_rev_bit fields in 'struct exynos_chipid_variant' to

    *_rev_shift

- Renamed EXYNOS_REV_PART_LEN to EXYNOS_REV_PART_MASK
- Renamed EXYNOS_REV_PART_OFF to EXYNOS_REV_PART_SHIFT

Changes in v3:
- Rebased on top of krzk/for-next tree
- Fixed wrong *_rev_shift values in exynos4210_chipid_drv_data
- Implemented reading the register only once in case when both Product ID and Revision ID are stored in the same register
- Tested all possible cases by emulating read register values
- Provided more detailed explanation in commit message

 drivers/soc/samsung/exynos-chipid.c       | 69 +++++++++++++++++++----
 include/linux/soc/samsung/exynos-chipid.h |  6 +-
 2 files changed, 60 insertions(+), 15 deletions(-)
drivers/soc/samsung/exynos-chipid.c +58 -11
index b2627a3a127a..986978e83661 100644
@@ -17,6 +17,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -25,6 +26,17 @@
 
 #include "exynos-asv.h"
 
+struct exynos_chipid_variant {
+	unsigned int rev_reg;		/* revision register offset */
+	unsigned int main_rev_shift;	/* main revision offset in rev_reg */
+	unsigned int sub_rev_shift;	/* sub revision offset in rev_reg */
+};
+
+struct exynos_chipid_info {
+	u32 product_id;
+	u32 revision;
+};
+
 static const struct exynos_soc_id {
 	const char *name;
 	unsigned int id;
@@ -50,31 +62,57 @@ static const char *product_id_to_soc_id(unsigned int product_id)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
-		if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
+		if (product_id == soc_ids[i].id)
 			return soc_ids[i].name;
 	return NULL;
 }
 
+static int exynos_chipid_get_chipid_info(struct regmap *regmap,
+		const struct exynos_chipid_variant *data,
+		struct exynos_chipid_info *soc_info)
+{
+	int ret;
+	unsigned int val, main_rev, sub_rev;
+
+	ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &val);
+	if (ret < 0)
+		return ret;
+	soc_info->product_id = val & EXYNOS_MASK;
+
+	if (data->rev_reg != EXYNOS_CHIPID_REG_PRO_ID) {
+		ret = regmap_read(regmap, data->rev_reg, &val);
+		if (ret < 0)
+			return ret;
+	}
+	main_rev = (val >> data->main_rev_shift) & EXYNOS_REV_PART_MASK;
+	sub_rev = (val >> data->sub_rev_shift) & EXYNOS_REV_PART_MASK;
+	soc_info->revision = (main_rev << EXYNOS_REV_PART_SHIFT) | sub_rev;
+
+	return 0;
+}
+
 static int exynos_chipid_probe(struct platform_device *pdev)
 {
+	const struct exynos_chipid_variant *drv_data;
+	struct exynos_chipid_info soc_info;
 	struct soc_device_attribute *soc_dev_attr;
 	struct soc_device *soc_dev;
 	struct device_node *root;
 	struct regmap *regmap;
-	u32 product_id;
-	u32 revision;
 	int ret;
 
+	drv_data = of_device_get_match_data(&pdev->dev);
+	if (!drv_data)
+		return -EINVAL;
+
 	regmap = device_node_to_regmap(pdev->dev.of_node);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
-	ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &product_id);
+	ret = exynos_chipid_get_chipid_info(regmap, drv_data, &soc_info);
 	if (ret < 0)
 		return ret;
 
-	revision = product_id & EXYNOS_REV_MASK;
-
 	soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
 				    GFP_KERNEL);
 	if (!soc_dev_attr)
@@ -87,8 +125,8 @@ static int exynos_chipid_probe(struct platform_device *pdev)
 	of_node_put(root);
 
 	soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL,
-						"%x", revision);
-	soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
+						"%x", soc_info.revision);
+	soc_dev_attr->soc_id = product_id_to_soc_id(soc_info.product_id);
 	if (!soc_dev_attr->soc_id) {
 		pr_err("Unknown SoC\n");
 		return -ENODEV;
@@ -106,7 +144,7 @@ static int exynos_chipid_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, soc_dev);
 
 	dev_info(&pdev->dev, "Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
-		 soc_dev_attr->soc_id, product_id, revision);
+		 soc_dev_attr->soc_id, soc_info.product_id, soc_info.revision);
 
 	return 0;
 
@@ -125,9 +163,18 @@ static int exynos_chipid_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct exynos_chipid_variant exynos4210_chipid_drv_data = {
+	.rev_reg	= 0x0,
+	.main_rev_shift	= 4,
+	.sub_rev_shift	= 0,
+};
+
 static const struct of_device_id exynos_chipid_of_device_ids[] = {
-	{ .compatible = "samsung,exynos4210-chipid" },
-	{}
+	{
+		.compatible	= "samsung,exynos4210-chipid",
+		.data		= &exynos4210_chipid_drv_data,
+	},
+	{ }
 };
 MODULE_DEVICE_TABLE(of, exynos_chipid_of_device_ids);
 
include/linux/soc/samsung/exynos-chipid.h +2 -4
index 8bca6763f99c..62f0e2531068 100644
@@ -9,10 +9,8 @@
 #define __LINUX_SOC_EXYNOS_CHIPID_H
 
 #define EXYNOS_CHIPID_REG_PRO_ID	0x00
-#define EXYNOS_SUBREV_MASK		(0xf << 4)
-#define EXYNOS_MAINREV_MASK		(0xf << 0)
-#define EXYNOS_REV_MASK			(EXYNOS_SUBREV_MASK | \
-					 EXYNOS_MAINREV_MASK)
+#define EXYNOS_REV_PART_MASK		0xf
+#define EXYNOS_REV_PART_SHIFT		4
 #define EXYNOS_MASK			0xfffff000
 
 #define EXYNOS_CHIPID_REG_PKG_ID	0x04
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 2/3 dt-bindings: samsung: exynos-chipid: Document Exynos850 compatible

Add compatible string for Exynos850 chip-id. While at it, use enum instead of items/const, to reduce further cluttering of "compatible" list.

---
Changes in v2:
- (none)

Changes in v3:
- Rebased on top of krzk/for-next

 .../devicetree/bindings/arm/samsung/exynos-chipid.yaml       | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/arm/samsung/exynos-chipid.yaml +3 -2
index f99c0c6df21b..bfc352a2fdd6 100644
@@ -11,8 +11,9 @@ maintainers:
 
 properties:
   compatible:
-    items:
-      - const: samsung,exynos4210-chipid
+    enum:
+      - samsung,exynos4210-chipid
+      - samsung,exynos850-chipid
 
   reg:
     maxItems: 1
Signature · 1 line
2.30.2
#2 lore raw

PATCH v3 3/3 soc: samsung: exynos-chipid: Add Exynos850 support

In reply to Sam Protsenko

Add chip-id support for Exynos850 SoC. Despite its "E3830" ID, the actual SoC name is Exynos850 (Exynos3830 name is internal and outdated).

Format of Product_ID register in Exynos850 (offset 0x0):

[31:0] Product ID (identification)

Format of CHIPID_REV register in Exynos850 (offset 0x10):

    [23:20] Main revision
    [19:16] Sub revision

---
Changes in v2:
- Renamed *_rev_bit fields in 'struct exynos_chipid_variant' to

    *_rev_shift

Changes in v3:
- Rebased on top of krzk/for-next
- Added Exynos850 chip-id registers format in commit message

 drivers/soc/samsung/exynos-chipid.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/soc/samsung/exynos-chipid.c +10 -0
index 986978e83661..0aeb24bcc11a 100644
@@ -55,6 +55,7 @@ static const struct exynos_soc_id {
 	{ "EXYNOS5440", 0xE5440000 },
 	{ "EXYNOS5800", 0xE5422000 },
 	{ "EXYNOS7420", 0xE7420000 },
+	{ "EXYNOS850", 0xE3830000 },
 };
 
 static const char *product_id_to_soc_id(unsigned int product_id)
@@ -169,10 +170,19 @@ static const struct exynos_chipid_variant exynos4210_chipid_drv_data = {
 	.sub_rev_shift	= 0,
 };
 
+static const struct exynos_chipid_variant exynos850_chipid_drv_data = {
+	.rev_reg	= 0x10,
+	.main_rev_shift	= 20,
+	.sub_rev_shift	= 16,
+};
+
 static const struct of_device_id exynos_chipid_of_device_ids[] = {
 	{
 		.compatible	= "samsung,exynos4210-chipid",
 		.data		= &exynos4210_chipid_drv_data,
+	}, {
+		.compatible	= "samsung,exynos850-chipid",
+		.data		= &exynos850_chipid_drv_data,
 	},
 	{ }
 };
Signature · 1 line
2.30.2
#3 lore raw
In reply to Sam Protsenko

Hi Sam,

Quoted 37 lines · Sam Protsenko

Old Exynos SoCs have both Product ID and Revision ID in one single register, while new SoCs tend to have two separate registers for those IDs. Implement handling of both cases by passing Revision ID register offsets in driver data.

Previously existing macros for Exynos4210 (removed in this patch) were incorrect:

    #define EXYNOS_SUBREV_MASK         (0xf << 4)
    #define EXYNOS_MAINREV_MASK        (0xf << 0)

Actual format of PRO_ID register in Exynos4210 (offset 0x0):

[31:12] Product ID
[9:8] Package information
[7:4] Main Revision Number
[3:0] Sub Revision Number

This patch doesn't change the behavior on existing platforms, so '/sys/devices/soc0/revision' will show the same string as before.

---
Changes in v2:
- Renamed *_rev_bit fields in 'struct exynos_chipid_variant' to

    *_rev_shift

- Renamed EXYNOS_REV_PART_LEN to EXYNOS_REV_PART_MASK
- Renamed EXYNOS_REV_PART_OFF to EXYNOS_REV_PART_SHIFT

Changes in v3:
- Rebased on top of krzk/for-next tree
- Fixed wrong *_rev_shift values in exynos4210_chipid_drv_data
- Implemented reading the register only once in case when both Product ID and Revision ID are stored in the same register
- Tested all possible cases by emulating read register values
- Provided more detailed explanation in commit message

Quoted 4 lines
 drivers/soc/samsung/exynos-chipid.c       | 69 +++++++++++++++++++----
 include/linux/soc/samsung/exynos-chipid.h |  6 +-
 2 files changed, 60 insertions(+), 15 deletions(-)

I tested this on exynos4412-i9300 and an exynos5420 tablet that is not yet in mainline. /sys/devices/soc0/* looks identical, I have:

$ cat /sys/devices/soc0/{family,revision,soc_id}
Samsung Exynos
11
EXYNOS4412

and

$ cat /sys/devices/soc0/{family,revision,soc_id}
Samsung Exynos
20
EXYNOS5420

before and after these patches. The printed PRO_ID in dmesg changed though, before I had:

[    0.894683] soc soc0: Exynos: CPU[EXYNOS4412] PRO_ID[0xe4412211] REV[0x11] Detected
[    4.964215] soc soc0: Exynos: CPU[EXYNOS5420] PRO_ID[0xe5420020] REV[0x20] Detected

But after it looks like package information and revision is missing from the reported PRO_ID:

[    0.885515] soc soc0: Exynos: CPU[EXYNOS4412] PRO_ID[0xe4412000] REV[0x11] Detected
[    4.965560] soc soc0: Exynos: CPU[EXYNOS5420] PRO_ID[0xe5420000] REV[0x20] Detected

Best regards,
Henrik Grimler

#4 lore raw
In reply to Sam Protsenko
Quoted 9 lines · Sam Protsenko

Old Exynos SoCs have both Product ID and Revision ID in one single register, while new SoCs tend to have two separate registers for those IDs. Implement handling of both cases by passing Revision ID register offsets in driver data.

Previously existing macros for Exynos4210 (removed in this patch) were incorrect:

[...]

Applied, thanks!

[1/3] soc: samsung: exynos-chipid: Pass revision reg offsets

      commit: c072c4ef7ef09e1d6470c48cf52570487589b76a
[2/3] dt-bindings: samsung: exynos-chipid: Document Exynos850 compatible
      commit: 0a0124065fcd6b5e42968edbe33f85c7846d3f8c
[3/3] soc: samsung: exynos-chipid: Add Exynos850 support
      commit: 81a51eb6be3dbb76790b7353ec8dfaadfc751782

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>