Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Henrik Grimler <henrik@grimler.se>
Link: https://lore.kernel.org/r/20211014133508.1210-1-semen.protsenko@linaro.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

authored by

Sam Protsenko and committed by
Krzysztof Kozlowski
c072c4ef 178d6c1b

+60 -15
+58 -11
drivers/soc/samsung/exynos-chipid.c
··· 17 17 #include <linux/mfd/syscon.h> 18 18 #include <linux/module.h> 19 19 #include <linux/of.h> 20 + #include <linux/of_device.h> 20 21 #include <linux/platform_device.h> 21 22 #include <linux/regmap.h> 22 23 #include <linux/slab.h> ··· 25 24 #include <linux/sys_soc.h> 26 25 27 26 #include "exynos-asv.h" 27 + 28 + struct exynos_chipid_variant { 29 + unsigned int rev_reg; /* revision register offset */ 30 + unsigned int main_rev_shift; /* main revision offset in rev_reg */ 31 + unsigned int sub_rev_shift; /* sub revision offset in rev_reg */ 32 + }; 33 + 34 + struct exynos_chipid_info { 35 + u32 product_id; 36 + u32 revision; 37 + }; 28 38 29 39 static const struct exynos_soc_id { 30 40 const char *name; ··· 62 50 int i; 63 51 64 52 for (i = 0; i < ARRAY_SIZE(soc_ids); i++) 65 - if ((product_id & EXYNOS_MASK) == soc_ids[i].id) 53 + if (product_id == soc_ids[i].id) 66 54 return soc_ids[i].name; 67 55 return NULL; 68 56 } 69 57 58 + static int exynos_chipid_get_chipid_info(struct regmap *regmap, 59 + const struct exynos_chipid_variant *data, 60 + struct exynos_chipid_info *soc_info) 61 + { 62 + int ret; 63 + unsigned int val, main_rev, sub_rev; 64 + 65 + ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &val); 66 + if (ret < 0) 67 + return ret; 68 + soc_info->product_id = val & EXYNOS_MASK; 69 + 70 + if (data->rev_reg != EXYNOS_CHIPID_REG_PRO_ID) { 71 + ret = regmap_read(regmap, data->rev_reg, &val); 72 + if (ret < 0) 73 + return ret; 74 + } 75 + main_rev = (val >> data->main_rev_shift) & EXYNOS_REV_PART_MASK; 76 + sub_rev = (val >> data->sub_rev_shift) & EXYNOS_REV_PART_MASK; 77 + soc_info->revision = (main_rev << EXYNOS_REV_PART_SHIFT) | sub_rev; 78 + 79 + return 0; 80 + } 81 + 70 82 static int exynos_chipid_probe(struct platform_device *pdev) 71 83 { 84 + const struct exynos_chipid_variant *drv_data; 85 + struct exynos_chipid_info soc_info; 72 86 struct soc_device_attribute *soc_dev_attr; 73 87 struct soc_device *soc_dev; 74 88 struct device_node *root; 75 89 struct regmap *regmap; 76 - u32 product_id; 77 - u32 revision; 78 90 int ret; 91 + 92 + drv_data = of_device_get_match_data(&pdev->dev); 93 + if (!drv_data) 94 + return -EINVAL; 79 95 80 96 regmap = device_node_to_regmap(pdev->dev.of_node); 81 97 if (IS_ERR(regmap)) 82 98 return PTR_ERR(regmap); 83 99 84 - ret = regmap_read(regmap, EXYNOS_CHIPID_REG_PRO_ID, &product_id); 100 + ret = exynos_chipid_get_chipid_info(regmap, drv_data, &soc_info); 85 101 if (ret < 0) 86 102 return ret; 87 - 88 - revision = product_id & EXYNOS_REV_MASK; 89 103 90 104 soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), 91 105 GFP_KERNEL); ··· 125 87 of_node_put(root); 126 88 127 89 soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, 128 - "%x", revision); 129 - soc_dev_attr->soc_id = product_id_to_soc_id(product_id); 90 + "%x", soc_info.revision); 91 + soc_dev_attr->soc_id = product_id_to_soc_id(soc_info.product_id); 130 92 if (!soc_dev_attr->soc_id) { 131 93 pr_err("Unknown SoC\n"); 132 94 return -ENODEV; ··· 144 106 platform_set_drvdata(pdev, soc_dev); 145 107 146 108 dev_info(&pdev->dev, "Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n", 147 - soc_dev_attr->soc_id, product_id, revision); 109 + soc_dev_attr->soc_id, soc_info.product_id, soc_info.revision); 148 110 149 111 return 0; 150 112 ··· 163 125 return 0; 164 126 } 165 127 128 + static const struct exynos_chipid_variant exynos4210_chipid_drv_data = { 129 + .rev_reg = 0x0, 130 + .main_rev_shift = 4, 131 + .sub_rev_shift = 0, 132 + }; 133 + 166 134 static const struct of_device_id exynos_chipid_of_device_ids[] = { 167 - { .compatible = "samsung,exynos4210-chipid" }, 168 - {} 135 + { 136 + .compatible = "samsung,exynos4210-chipid", 137 + .data = &exynos4210_chipid_drv_data, 138 + }, 139 + { } 169 140 }; 170 141 MODULE_DEVICE_TABLE(of, exynos_chipid_of_device_ids); 171 142
+2 -4
include/linux/soc/samsung/exynos-chipid.h
··· 9 9 #define __LINUX_SOC_EXYNOS_CHIPID_H 10 10 11 11 #define EXYNOS_CHIPID_REG_PRO_ID 0x00 12 - #define EXYNOS_SUBREV_MASK (0xf << 4) 13 - #define EXYNOS_MAINREV_MASK (0xf << 0) 14 - #define EXYNOS_REV_MASK (EXYNOS_SUBREV_MASK | \ 15 - EXYNOS_MAINREV_MASK) 12 + #define EXYNOS_REV_PART_MASK 0xf 13 + #define EXYNOS_REV_PART_SHIFT 4 16 14 #define EXYNOS_MASK 0xfffff000 17 15 18 16 #define EXYNOS_CHIPID_REG_PKG_ID 0x04