From e74921ac4137ba5d4e52300a49cf1c677b541a5a Mon Sep 17 00:00:00 2001 From: Mukesh Ojha Date: Fri, 7 Jan 2022 17:51:04 +0530 Subject: [PATCH 1/2] soc: qcom: socinfo: Add revision 16 support in socinfo structure Below are some new fields are getting updated in socinfo structure from bootloader under revision 16. e.g esku; nproduct_code; npartnamemap_offset; nnum_partname_mapping; Add the change in socinfo driver to accommodate this. Change-Id: I11b5182c15af32da61cddbf4bb45d5aef390135a Signed-off-by: Mukesh Ojha Signed-off-by: Srinivasarao Pathipati --- drivers/soc/qcom/socinfo.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c index 562f35ce68a4..511f08848720 100644 --- a/drivers/soc/qcom/socinfo.c +++ b/drivers/soc/qcom/socinfo.c @@ -167,6 +167,11 @@ static struct socinfo { __le32 ndefective_parts_array_offset; /* Version 15 */ __le32 nmodem_supported; + /* Version 16 */ + __le32 esku; + __le32 nproduct_code; + __le32 npartnamemap_offset; + __le32 nnum_partname_mapping; } *socinfo; /* sysfs attributes */ @@ -959,6 +964,7 @@ static void socinfo_populate_sysfs(struct qcom_socinfo *qcom_socinfo) int i = 0; switch (socinfo_format) { + case SOCINFO_VERSION(0, 16): case SOCINFO_VERSION(0, 15): msm_custom_socinfo_attrs[i++] = &dev_attr_nmodem_supported.attr; case SOCINFO_VERSION(0, 14): @@ -1200,6 +1206,29 @@ static void socinfo_print(void) socinfo->nmodem_supported); break; + case SOCINFO_VERSION(0, 16): + pr_info("v%u.%u, id=%u, ver=%u.%u, raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n accessory_chip=%u, hw_plat_subtype=%u, pmic_model=%u, pmic_die_revision=%u foundry_id=%u serial_number=%u num_pmics=%u chip_family=0x%x raw_device_family=0x%x raw_device_number=0x%x nproduct_id=0x%x num_clusters=0x%x ncluster_array_offset=0x%x num_defective_parts=0x%x ndefective_parts_array_offset=0x%x nmodem_supported=0x%x\n", + f_maj, f_min, socinfo->id, v_maj, v_min, + socinfo->raw_id, socinfo->raw_ver, + socinfo->hw_plat, + socinfo->plat_ver, + socinfo->accessory_chip, + socinfo->hw_plat_subtype, + socinfo->pmic_model, + socinfo->pmic_die_rev, + socinfo->foundry_id, + socinfo->serial_num, + socinfo->num_pmics, + socinfo->chip_family, + socinfo->raw_device_family, + socinfo->raw_device_num, + socinfo->nproduct_id, + socinfo->num_clusters, + socinfo->ncluster_array_offset, + socinfo->num_defective_parts, + socinfo->ndefective_parts_array_offset, + socinfo->nmodem_supported); + default: pr_err("Unknown format found: v%u.%u\n", f_maj, f_min); break; From f81d2d30c4007bb009b2e7d819608396b96b9b26 Mon Sep 17 00:00:00 2001 From: Mukesh Ojha Date: Wed, 19 Jan 2022 21:56:57 +0530 Subject: [PATCH 2/2] soc: qcom: socinfo: Add sku sysfs support Add the support to get the sku information from userspace. Change-Id: I39b60fcc430308cd75e67fa400ad9515b5ad4b65 Signed-off-by: Mukesh Ojha Signed-off-by: Srinivasarao Pathipati --- drivers/soc/qcom/socinfo.c | 112 ++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c index 511f08848720..fc369c48f6df 100644 --- a/drivers/soc/qcom/socinfo.c +++ b/drivers/soc/qcom/socinfo.c @@ -34,6 +34,7 @@ #define SMEM_IMAGE_VERSION_TABLE 469 static uint32_t socinfo_format; +static const char *sku; enum { HW_PLATFORM_UNKNOWN = 0, @@ -121,6 +122,51 @@ static const char * const hw_platform_subtype[] = { [PLATFORM_SUBTYPE_INVALID] = "Invalid", }; +enum { + /* External SKU */ + SKU_UNKNOWN = 0x0, + SKU_AA = 0x1, + SKU_AB = 0x2, + SKU_AC = 0x3, + SKU_AD = 0x4, + SKU_AE = 0x5, + SKU_AF = 0x6, + SKU_EXT_RESERVE, + + /* Internal SKU */ + SKU_Y0 = 0xf1, + SKU_Y1 = 0xf2, + SKU_Y2 = 0xf3, + SKU_Y3 = 0xf4, + SKU_Y4 = 0xf5, + SKU_Y5 = 0xf6, + SKU_Y6 = 0xf7, + SKU_Y7 = 0xf8, + SKU_INT_RESERVE, +}; + +static const char * const hw_platform_esku[] = { + [SKU_UNKNOWN] = "Unknown", + [SKU_AA] = "AA", + [SKU_AB] = "AB", + [SKU_AC] = "AC", + [SKU_AD] = "AD", + [SKU_AE] = "AE", + [SKU_AF] = "AF", +}; + +#define SKU_INT_MASK 0x0f +static const char * const hw_platform_isku[] = { + [SKU_Y0 & SKU_INT_MASK] = "Y0", + [SKU_Y1 & SKU_INT_MASK] = "Y1", + [SKU_Y2 & SKU_INT_MASK] = "Y2", + [SKU_Y3 & SKU_INT_MASK] = "Y3", + [SKU_Y4 & SKU_INT_MASK] = "Y4", + [SKU_Y5 & SKU_INT_MASK] = "Y5", + [SKU_Y6 & SKU_INT_MASK] = "Y6", + [SKU_Y7 & SKU_INT_MASK] = "Y7", +}; + /* Socinfo SMEM item structure */ static struct socinfo { __le32 fmt; @@ -367,6 +413,35 @@ static uint32_t socinfo_get_nmodem_supported(void) : 0; } +/* Version 16 */ +static uint32_t socinfo_get_eskuid(void) +{ + return socinfo ? + (socinfo_format >= SOCINFO_VERSION(0, 16) ? + le32_to_cpu(socinfo->esku) : 0) + : 0; +} + +static const char *socinfo_get_esku_mapping(void) +{ + uint32_t id = socinfo_get_eskuid(); + + if (id > SKU_UNKNOWN && id < SKU_EXT_RESERVE) + return hw_platform_esku[id]; + else if (id >= SKU_Y0 && id < SKU_INT_RESERVE) + return hw_platform_isku[id & SKU_INT_MASK]; + + return NULL; +} + +static uint32_t socinfo_get_nproduct_code(void) +{ + return socinfo ? + (socinfo_format >= SOCINFO_VERSION(0, 16) ? + le32_to_cpu(socinfo->nproduct_code) : 0) + : 0; +} + /* Version 2 */ static ssize_t msm_get_raw_id(struct device *dev, @@ -617,6 +692,27 @@ msm_get_nmodem_supported(struct device *dev, } ATTR_DEFINE(nmodem_supported); +/* Version 16 */ +static ssize_t +msm_get_sku(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", sku ? sku : "Unknown"); +} +ATTR_DEFINE(sku); + +static ssize_t +msm_get_esku(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const char *esku = socinfo_get_esku_mapping(); + + return sysfs_emit(buf, "%s\n", esku ? esku : "Unknown"); +} +ATTR_DEFINE(esku); + struct qcom_socinfo { struct soc_device *soc_dev; struct soc_device_attribute attr; @@ -965,6 +1061,8 @@ static void socinfo_populate_sysfs(struct qcom_socinfo *qcom_socinfo) switch (socinfo_format) { case SOCINFO_VERSION(0, 16): + msm_custom_socinfo_attrs[i++] = &dev_attr_sku.attr; + msm_custom_socinfo_attrs[i++] = &dev_attr_esku.attr; case SOCINFO_VERSION(0, 15): msm_custom_socinfo_attrs[i++] = &dev_attr_nmodem_supported.attr; case SOCINFO_VERSION(0, 14): @@ -1207,7 +1305,7 @@ static void socinfo_print(void) break; case SOCINFO_VERSION(0, 16): - pr_info("v%u.%u, id=%u, ver=%u.%u, raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n accessory_chip=%u, hw_plat_subtype=%u, pmic_model=%u, pmic_die_revision=%u foundry_id=%u serial_number=%u num_pmics=%u chip_family=0x%x raw_device_family=0x%x raw_device_number=0x%x nproduct_id=0x%x num_clusters=0x%x ncluster_array_offset=0x%x num_defective_parts=0x%x ndefective_parts_array_offset=0x%x nmodem_supported=0x%x\n", + pr_info("v%u.%u, id=%u, ver=%u.%u, raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n accessory_chip=%u, hw_plat_subtype=%u, pmic_model=%u, pmic_die_revision=%u foundry_id=%u serial_number=%u num_pmics=%u chip_family=0x%x raw_device_family=0x%x raw_device_number=0x%x nproduct_id=0x%x num_clusters=0x%x ncluster_array_offset=0x%x num_defective_parts=0x%x ndefective_parts_array_offset=0x%x nmodem_supported=0x%x sku=%s\n", f_maj, f_min, socinfo->id, v_maj, v_min, socinfo->raw_id, socinfo->raw_ver, socinfo->hw_plat, @@ -1227,7 +1325,8 @@ static void socinfo_print(void) socinfo->ncluster_array_offset, socinfo->num_defective_parts, socinfo->ndefective_parts_array_offset, - socinfo->nmodem_supported); + socinfo->nmodem_supported, + sku ? sku : "Unknown"); default: pr_err("Unknown format found: v%u.%u\n", f_maj, f_min); @@ -1266,6 +1365,7 @@ static int qcom_socinfo_probe(struct platform_device *pdev) struct qcom_socinfo *qs; struct socinfo *info; size_t item_size; + const char *machine, *esku; info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, &item_size); @@ -1290,6 +1390,14 @@ static int qcom_socinfo_probe(struct platform_device *pdev) SOCINFO_MINOR(le32_to_cpu(info->ver))); qs->attr.soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id()); + if (socinfo_format >= SOCINFO_VERSION(0, 16)) { + machine = socinfo_machine(le32_to_cpu(info->id)); + esku = socinfo_get_esku_mapping(); + if (machine && esku) + sku = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%u-%s", + machine, socinfo_get_nproduct_code(), esku); + } + qsocinfo = qs; init_rwsem(&qs->current_image_rwsem); socinfo_populate_sysfs(qs);