xref: /linux/drivers/soc/qcom/socinfo.c (revision e876303c6f18da4c649d97f6d488ee0a850ad384)
1efb448d0SImran Khan // SPDX-License-Identifier: GPL-2.0
2efb448d0SImran Khan /*
3efb448d0SImran Khan  * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
4efb448d0SImran Khan  * Copyright (c) 2017-2019, Linaro Ltd.
5efb448d0SImran Khan  */
6efb448d0SImran Khan 
79c84c1e7SVaishali Thakkar #include <linux/debugfs.h>
8efb448d0SImran Khan #include <linux/err.h>
9efb448d0SImran Khan #include <linux/module.h>
10efb448d0SImran Khan #include <linux/platform_device.h>
11efb448d0SImran Khan #include <linux/random.h>
12efb448d0SImran Khan #include <linux/slab.h>
13efb448d0SImran Khan #include <linux/soc/qcom/smem.h>
14ec001bb7SRobert Marko #include <linux/soc/qcom/socinfo.h>
15efb448d0SImran Khan #include <linux/string.h>
1634ec89e6SKrzysztof Kozlowski #include <linux/stringify.h>
17efb448d0SImran Khan #include <linux/sys_soc.h>
18efb448d0SImran Khan #include <linux/types.h>
19efb448d0SImran Khan 
20734c78e7SDmitry Baryshkov #include <asm/unaligned.h>
21734c78e7SDmitry Baryshkov 
2234ec89e6SKrzysztof Kozlowski #include <dt-bindings/arm/qcom,ids.h>
2334ec89e6SKrzysztof Kozlowski 
24efb448d0SImran Khan /*
25efb448d0SImran Khan  * SoC version type with major number in the upper 16 bits and minor
26efb448d0SImran Khan  * number in the lower 16 bits.
27efb448d0SImran Khan  */
28efb448d0SImran Khan #define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0xffff)
29efb448d0SImran Khan #define SOCINFO_MINOR(ver) ((ver) & 0xffff)
309c84c1e7SVaishali Thakkar #define SOCINFO_VERSION(maj, min)  ((((maj) & 0xffff) << 16)|((min) & 0xffff))
31efb448d0SImran Khan 
3234ec89e6SKrzysztof Kozlowski /* Helper macros to create soc_id table */
3334ec89e6SKrzysztof Kozlowski #define qcom_board_id(id) QCOM_ID_ ## id, __stringify(id)
3434ec89e6SKrzysztof Kozlowski #define qcom_board_id_named(id, name) QCOM_ID_ ## id, (name)
3534ec89e6SKrzysztof Kozlowski 
369c84c1e7SVaishali Thakkar #ifdef CONFIG_DEBUG_FS
37cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_BLOCKS_COUNT        32
38cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_SIZE                4096
39cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_NAME_SIZE           75
40cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_VARIANT_SIZE        20
41cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_OEM_SIZE            32
42cd23d140SVaishali Thakkar 
43cd23d140SVaishali Thakkar /*
44cd23d140SVaishali Thakkar  * SMEM Image table indices
45cd23d140SVaishali Thakkar  */
46cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_BOOT_INDEX     0
47cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_TZ_INDEX       1
48cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_RPM_INDEX      3
49cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_APPS_INDEX     10
50cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_MPSS_INDEX     11
51cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_ADSP_INDEX     12
52cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_CNSS_INDEX     13
53cd23d140SVaishali Thakkar #define SMEM_IMAGE_TABLE_VIDEO_INDEX    14
54cea0585cSNaman Jain #define SMEM_IMAGE_TABLE_DSPS_INDEX     15
55cea0585cSNaman Jain #define SMEM_IMAGE_TABLE_CDSP_INDEX     16
56cea0585cSNaman Jain #define SMEM_IMAGE_TABLE_CDSP1_INDEX    19
57cea0585cSNaman Jain #define SMEM_IMAGE_TABLE_GPDSP_INDEX    20
58cea0585cSNaman Jain #define SMEM_IMAGE_TABLE_GPDSP1_INDEX   21
59cd23d140SVaishali Thakkar #define SMEM_IMAGE_VERSION_TABLE       469
60cd23d140SVaishali Thakkar 
61cd23d140SVaishali Thakkar /*
62cd23d140SVaishali Thakkar  * SMEM Image table names
63cd23d140SVaishali Thakkar  */
64cd23d140SVaishali Thakkar static const char *const socinfo_image_names[] = {
65cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_ADSP_INDEX] = "adsp",
66cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_APPS_INDEX] = "apps",
67cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_BOOT_INDEX] = "boot",
68cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_CNSS_INDEX] = "cnss",
69cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_MPSS_INDEX] = "mpss",
70cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_RPM_INDEX] = "rpm",
71cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_TZ_INDEX] = "tz",
72cd23d140SVaishali Thakkar 	[SMEM_IMAGE_TABLE_VIDEO_INDEX] = "video",
73cea0585cSNaman Jain 	[SMEM_IMAGE_TABLE_DSPS_INDEX] = "dsps",
74cea0585cSNaman Jain 	[SMEM_IMAGE_TABLE_CDSP_INDEX] = "cdsp",
75cea0585cSNaman Jain 	[SMEM_IMAGE_TABLE_CDSP1_INDEX] = "cdsp1",
76cea0585cSNaman Jain 	[SMEM_IMAGE_TABLE_GPDSP_INDEX] = "gpdsp",
77cea0585cSNaman Jain 	[SMEM_IMAGE_TABLE_GPDSP1_INDEX] = "gpdsp1",
78cd23d140SVaishali Thakkar };
79cd23d140SVaishali Thakkar 
809c84c1e7SVaishali Thakkar static const char *const pmic_models[] = {
819c84c1e7SVaishali Thakkar 	[0]  = "Unknown PMIC model",
827fda2b0bSLuca Weiss 	[1]  = "PM8941",
837fda2b0bSLuca Weiss 	[2]  = "PM8841",
847fda2b0bSLuca Weiss 	[3]  = "PM8019",
857fda2b0bSLuca Weiss 	[4]  = "PM8226",
867fda2b0bSLuca Weiss 	[5]  = "PM8110",
877fda2b0bSLuca Weiss 	[6]  = "PMA8084",
887fda2b0bSLuca Weiss 	[7]  = "PMI8962",
897fda2b0bSLuca Weiss 	[8]  = "PMD9635",
909c84c1e7SVaishali Thakkar 	[9]  = "PM8994",
917fda2b0bSLuca Weiss 	[10] = "PMI8994",
929c84c1e7SVaishali Thakkar 	[11] = "PM8916",
937fda2b0bSLuca Weiss 	[12] = "PM8004",
947fda2b0bSLuca Weiss 	[13] = "PM8909/PM8058",
959c84c1e7SVaishali Thakkar 	[14] = "PM8028",
969c84c1e7SVaishali Thakkar 	[15] = "PM8901",
977fda2b0bSLuca Weiss 	[16] = "PM8950/PM8027",
987fda2b0bSLuca Weiss 	[17] = "PMI8950/ISL9519",
992fae3eccSDmitry Baryshkov 	[18] = "PMK8001/PM8921",
1002fae3eccSDmitry Baryshkov 	[19] = "PMI8996/PM8018",
1017fda2b0bSLuca Weiss 	[20] = "PM8998/PM8015",
1027fda2b0bSLuca Weiss 	[21] = "PMI8998/PM8014",
1039c84c1e7SVaishali Thakkar 	[22] = "PM8821",
1049c84c1e7SVaishali Thakkar 	[23] = "PM8038",
1057fda2b0bSLuca Weiss 	[24] = "PM8005/PM8922",
106d50b5cb1SDang Huynh 	[25] = "PM8917/PM8937",
1077fda2b0bSLuca Weiss 	[26] = "PM660L",
1087fda2b0bSLuca Weiss 	[27] = "PM660",
10943053242SDmitry Baryshkov 	[30] = "PM8150",
11043053242SDmitry Baryshkov 	[31] = "PM8150L",
11143053242SDmitry Baryshkov 	[32] = "PM8150B",
11243053242SDmitry Baryshkov 	[33] = "PMK8002",
11343053242SDmitry Baryshkov 	[36] = "PM8009",
114112d96fdSKonrad Dybcio 	[37] = "PMI632",
11587fd343cSBjorn Andersson 	[38] = "PM8150C",
116112d96fdSKonrad Dybcio 	[40] = "PM6150",
11787fd343cSBjorn Andersson 	[41] = "SMB2351",
118112d96fdSKonrad Dybcio 	[44] = "PM8008",
1195257841aSKonrad Dybcio 	[45] = "PM6125",
120112d96fdSKonrad Dybcio 	[46] = "PM7250B",
12176ee15aeSBjorn Andersson 	[47] = "PMK8350",
12276ee15aeSBjorn Andersson 	[48] = "PM8350",
12376ee15aeSBjorn Andersson 	[49] = "PM8350C",
12476ee15aeSBjorn Andersson 	[50] = "PM8350B",
12576ee15aeSBjorn Andersson 	[51] = "PMR735A",
12676ee15aeSBjorn Andersson 	[52] = "PMR735B",
1275155e481SDmitry Baryshkov 	[55] = "PM4125",
12876ee15aeSBjorn Andersson 	[58] = "PM8450",
12976ee15aeSBjorn Andersson 	[65] = "PM8010",
1303b1eba18SKonrad Dybcio 	[69] = "PM8550VS",
1313b1eba18SKonrad Dybcio 	[70] = "PM8550VE",
1323b1eba18SKonrad Dybcio 	[71] = "PM8550B",
1333b1eba18SKonrad Dybcio 	[72] = "PMR735D",
1343b1eba18SKonrad Dybcio 	[73] = "PM8550",
1353b1eba18SKonrad Dybcio 	[74] = "PMK8550",
1369c84c1e7SVaishali Thakkar };
1379c84c1e7SVaishali Thakkar 
1389c84c1e7SVaishali Thakkar struct socinfo_params {
1399c84c1e7SVaishali Thakkar 	u32 raw_device_family;
1409c84c1e7SVaishali Thakkar 	u32 hw_plat_subtype;
1419c84c1e7SVaishali Thakkar 	u32 accessory_chip;
1429c84c1e7SVaishali Thakkar 	u32 raw_device_num;
1439c84c1e7SVaishali Thakkar 	u32 chip_family;
1449c84c1e7SVaishali Thakkar 	u32 foundry_id;
1459c84c1e7SVaishali Thakkar 	u32 plat_ver;
1469c84c1e7SVaishali Thakkar 	u32 raw_ver;
1479c84c1e7SVaishali Thakkar 	u32 hw_plat;
1489c84c1e7SVaishali Thakkar 	u32 fmt;
1490f12fe7fSDmitry Baryshkov 	u32 nproduct_id;
1500f12fe7fSDmitry Baryshkov 	u32 num_clusters;
1510f12fe7fSDmitry Baryshkov 	u32 ncluster_array_offset;
152d9c2a255SNaman Jain 	u32 num_subset_parts;
153d9c2a255SNaman Jain 	u32 nsubset_parts_array_offset;
1540f12fe7fSDmitry Baryshkov 	u32 nmodem_supported;
155f02a5373SNaman Jain 	u32 feature_code;
156f02a5373SNaman Jain 	u32 pcode;
1576bdab60dSNaman Jain 	u32 oem_variant;
158d9c2a255SNaman Jain 	u32 num_func_clusters;
159d9c2a255SNaman Jain 	u32 boot_cluster;
160d9c2a255SNaman Jain 	u32 boot_core;
1619c84c1e7SVaishali Thakkar };
162cd23d140SVaishali Thakkar 
163cd23d140SVaishali Thakkar struct smem_image_version {
164cd23d140SVaishali Thakkar 	char name[SMEM_IMAGE_VERSION_NAME_SIZE];
165cd23d140SVaishali Thakkar 	char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
166cd23d140SVaishali Thakkar 	char pad;
167cd23d140SVaishali Thakkar 	char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
168cd23d140SVaishali Thakkar };
1699c84c1e7SVaishali Thakkar #endif /* CONFIG_DEBUG_FS */
1709c84c1e7SVaishali Thakkar 
171efb448d0SImran Khan struct qcom_socinfo {
172efb448d0SImran Khan 	struct soc_device *soc_dev;
173efb448d0SImran Khan 	struct soc_device_attribute attr;
1749c84c1e7SVaishali Thakkar #ifdef CONFIG_DEBUG_FS
1759c84c1e7SVaishali Thakkar 	struct dentry *dbg_root;
1769c84c1e7SVaishali Thakkar 	struct socinfo_params info;
1779c84c1e7SVaishali Thakkar #endif /* CONFIG_DEBUG_FS */
178efb448d0SImran Khan };
179efb448d0SImran Khan 
180efb448d0SImran Khan struct soc_id {
181efb448d0SImran Khan 	unsigned int id;
182efb448d0SImran Khan 	const char *name;
183efb448d0SImran Khan };
184efb448d0SImran Khan 
185efb448d0SImran Khan static const struct soc_id soc_id[] = {
18640017cebSStephan Gerhold 	{ qcom_board_id(MSM8260) },
18740017cebSStephan Gerhold 	{ qcom_board_id(MSM8660) },
18840017cebSStephan Gerhold 	{ qcom_board_id(APQ8060) },
18934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8960) },
19034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8064) },
19140017cebSStephan Gerhold 	{ qcom_board_id(MSM8930) },
19240017cebSStephan Gerhold 	{ qcom_board_id(MSM8630) },
19340017cebSStephan Gerhold 	{ qcom_board_id(MSM8230) },
19440017cebSStephan Gerhold 	{ qcom_board_id(APQ8030) },
19540017cebSStephan Gerhold 	{ qcom_board_id(MSM8627) },
19640017cebSStephan Gerhold 	{ qcom_board_id(MSM8227) },
19734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8660A) },
19834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8260A) },
19934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8060A) },
20034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8974) },
20140017cebSStephan Gerhold 	{ qcom_board_id(MSM8225) },
20240017cebSStephan Gerhold 	{ qcom_board_id(MSM8625) },
20334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MPQ8064) },
20434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8960AB) },
20534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8060AB) },
20634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8260AB) },
20734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8660AB) },
20840017cebSStephan Gerhold 	{ qcom_board_id(MSM8930AA) },
20940017cebSStephan Gerhold 	{ qcom_board_id(MSM8630AA) },
21040017cebSStephan Gerhold 	{ qcom_board_id(MSM8230AA) },
21134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8626) },
21234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8610) },
21334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8064AB) },
21440017cebSStephan Gerhold 	{ qcom_board_id(MSM8930AB) },
21540017cebSStephan Gerhold 	{ qcom_board_id(MSM8630AB) },
21640017cebSStephan Gerhold 	{ qcom_board_id(MSM8230AB) },
21740017cebSStephan Gerhold 	{ qcom_board_id(APQ8030AB) },
21834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8226) },
21934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8526) },
22040017cebSStephan Gerhold 	{ qcom_board_id(APQ8030AA) },
22134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8110) },
22234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8210) },
22334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8810) },
22434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8212) },
22534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8612) },
22634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8112) },
22740017cebSStephan Gerhold 	{ qcom_board_id(MSM8125) },
22834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8225Q) },
22934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8625Q) },
23034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8125Q) },
23134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8064AA) },
23234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8084) },
23340017cebSStephan Gerhold 	{ qcom_board_id(MSM8130) },
23440017cebSStephan Gerhold 	{ qcom_board_id(MSM8130AA) },
23540017cebSStephan Gerhold 	{ qcom_board_id(MSM8130AB) },
23640017cebSStephan Gerhold 	{ qcom_board_id(MSM8627AA) },
23740017cebSStephan Gerhold 	{ qcom_board_id(MSM8227AA) },
23834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8074) },
23934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8274) },
24034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8674) },
24140017cebSStephan Gerhold 	{ qcom_board_id(MDM9635) },
24234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8974PRO_AC, "MSM8974PRO-AC") },
24334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8126) },
24434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8026) },
24534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8926) },
24679802479SChristian Marangi 	{ qcom_board_id(IPQ8062) },
24779802479SChristian Marangi 	{ qcom_board_id(IPQ8064) },
24879802479SChristian Marangi 	{ qcom_board_id(IPQ8066) },
24979802479SChristian Marangi 	{ qcom_board_id(IPQ8068) },
25034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8326) },
25134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8916) },
25234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8994) },
25334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(APQ8074PRO_AA, "APQ8074PRO-AA") },
25434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(APQ8074PRO_AB, "APQ8074PRO-AB") },
25534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(APQ8074PRO_AC, "APQ8074PRO-AC") },
25634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8274PRO_AA, "MSM8274PRO-AA") },
25734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8274PRO_AB, "MSM8274PRO-AB") },
25834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8274PRO_AC, "MSM8274PRO-AC") },
25934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8674PRO_AA, "MSM8674PRO-AA") },
26034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8674PRO_AB, "MSM8674PRO-AB") },
26134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8674PRO_AC, "MSM8674PRO-AC") },
26234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8974PRO_AA, "MSM8974PRO-AA") },
26334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(MSM8974PRO_AB, "MSM8974PRO-AB") },
26434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8028) },
26534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8128) },
26634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8228) },
26734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8528) },
26834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8628) },
26934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8928) },
27034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8510) },
27134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8512) },
27234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8936) },
27340017cebSStephan Gerhold 	{ qcom_board_id(MDM9640) },
27434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8939) },
27534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8036) },
27634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8039) },
27740017cebSStephan Gerhold 	{ qcom_board_id(MSM8236) },
27840017cebSStephan Gerhold 	{ qcom_board_id(MSM8636) },
27940017cebSStephan Gerhold 	{ qcom_board_id(MSM8909) },
28034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8996) },
28134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8016) },
28234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8216) },
28334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8116) },
28434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8616) },
28534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8992) },
28640017cebSStephan Gerhold 	{ qcom_board_id(APQ8092) },
28734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8094) },
28840017cebSStephan Gerhold 	{ qcom_board_id(MSM8209) },
28940017cebSStephan Gerhold 	{ qcom_board_id(MSM8208) },
29040017cebSStephan Gerhold 	{ qcom_board_id(MDM9209) },
29140017cebSStephan Gerhold 	{ qcom_board_id(MDM9309) },
29240017cebSStephan Gerhold 	{ qcom_board_id(MDM9609) },
29340017cebSStephan Gerhold 	{ qcom_board_id(MSM8239) },
29440017cebSStephan Gerhold 	{ qcom_board_id(MSM8952) },
29540017cebSStephan Gerhold 	{ qcom_board_id(APQ8009) },
296017a7c11SStephan Gerhold 	{ qcom_board_id(MSM8956) },
29740017cebSStephan Gerhold 	{ qcom_board_id(MSM8929) },
29840017cebSStephan Gerhold 	{ qcom_board_id(MSM8629) },
29940017cebSStephan Gerhold 	{ qcom_board_id(MSM8229) },
30040017cebSStephan Gerhold 	{ qcom_board_id(APQ8029) },
30140017cebSStephan Gerhold 	{ qcom_board_id(APQ8056) },
30240017cebSStephan Gerhold 	{ qcom_board_id(MSM8609) },
30340017cebSStephan Gerhold 	{ qcom_board_id(APQ8076) },
304017a7c11SStephan Gerhold 	{ qcom_board_id(MSM8976) },
30579802479SChristian Marangi 	{ qcom_board_id(IPQ8065) },
30679802479SChristian Marangi 	{ qcom_board_id(IPQ8069) },
30740017cebSStephan Gerhold 	{ qcom_board_id(MDM9650) },
30840017cebSStephan Gerhold 	{ qcom_board_id(MDM9655) },
30940017cebSStephan Gerhold 	{ qcom_board_id(MDM9250) },
31040017cebSStephan Gerhold 	{ qcom_board_id(MDM9255) },
31140017cebSStephan Gerhold 	{ qcom_board_id(MDM9350) },
31240017cebSStephan Gerhold 	{ qcom_board_id(APQ8052) },
31334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM9607) },
31434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8096) },
31534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8998) },
31634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8953) },
31740017cebSStephan Gerhold 	{ qcom_board_id(MSM8937) },
31840017cebSStephan Gerhold 	{ qcom_board_id(APQ8037) },
31934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM8207) },
32034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM9207) },
32134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM9307) },
32234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM9628) },
32340017cebSStephan Gerhold 	{ qcom_board_id(MSM8909W) },
32440017cebSStephan Gerhold 	{ qcom_board_id(APQ8009W) },
32540017cebSStephan Gerhold 	{ qcom_board_id(MSM8996L) },
32640017cebSStephan Gerhold 	{ qcom_board_id(MSM8917) },
32734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8053) },
32834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8996SG) },
32940017cebSStephan Gerhold 	{ qcom_board_id(APQ8017) },
33040017cebSStephan Gerhold 	{ qcom_board_id(MSM8217) },
33140017cebSStephan Gerhold 	{ qcom_board_id(MSM8617) },
33234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MSM8996AU) },
33334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8096AU) },
33434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8096SG) },
33540017cebSStephan Gerhold 	{ qcom_board_id(MSM8940) },
33640017cebSStephan Gerhold 	{ qcom_board_id(SDX201) },
33734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM660) },
33834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM630) },
33934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(APQ8098) },
34040017cebSStephan Gerhold 	{ qcom_board_id(MSM8920) },
34134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM845) },
34234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(MDM9206) },
34334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8074) },
34434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA660) },
34534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM658) },
34634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA658) },
34734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA630) },
34840017cebSStephan Gerhold 	{ qcom_board_id(MSM8905) },
34940017cebSStephan Gerhold 	{ qcom_board_id(SDX202) },
35034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM450) },
351911eed82SBhupesh Sharma 	{ qcom_board_id(SM8150) },
35234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA845) },
35334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8072) },
35434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8076) },
35534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8078) },
35634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM636) },
35734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA636) },
35834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDM632) },
35934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA632) },
36034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SDA450) },
36140017cebSStephan Gerhold 	{ qcom_board_id(SDM439) },
36240017cebSStephan Gerhold 	{ qcom_board_id(SDM429) },
36334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM8250) },
364911eed82SBhupesh Sharma 	{ qcom_board_id(SA8155) },
36540017cebSStephan Gerhold 	{ qcom_board_id(SDA439) },
36640017cebSStephan Gerhold 	{ qcom_board_id(SDA429) },
367bad8cdc2SDavid Wronek 	{ qcom_board_id(SM7150) },
368776b29ebSDanila Tikhonov 	{ qcom_board_id(SM7150P) },
36934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8070) },
37034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8071) },
37140017cebSStephan Gerhold 	{ qcom_board_id(QM215) },
37234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8072A) },
37334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8074A) },
37434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8076A) },
37534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8078A) },
37634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM6125) },
37734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8070A) },
37834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ8071A) },
379e9104e73SRobert Marko 	{ qcom_board_id(IPQ8172) },
380e9104e73SRobert Marko 	{ qcom_board_id(IPQ8173) },
381e9104e73SRobert Marko 	{ qcom_board_id(IPQ8174) },
38234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ6018) },
38334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ6028) },
38440017cebSStephan Gerhold 	{ qcom_board_id(SDM429W) },
385f33ca7ecSBhupesh Sharma 	{ qcom_board_id(SM4250) },
38634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ6000) },
38734ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ6010) },
38834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SC7180) },
38934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM6350) },
39040017cebSStephan Gerhold 	{ qcom_board_id(QCM2150) },
39140017cebSStephan Gerhold 	{ qcom_board_id(SDA429W) },
39234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM8350) },
39318290c2eSKonrad Dybcio 	{ qcom_board_id(QCM2290) },
39423b45f8aSDavid Wronek 	{ qcom_board_id(SM7125) },
395f33ca7ecSBhupesh Sharma 	{ qcom_board_id(SM6115) },
3960369a590SRobert Marko 	{ qcom_board_id(IPQ5010) },
3970369a590SRobert Marko 	{ qcom_board_id(IPQ5018) },
3980369a590SRobert Marko 	{ qcom_board_id(IPQ5028) },
39934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SC8280XP) },
40034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(IPQ6005) },
40134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(QRB5165) },
40234ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM8450) },
40334ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM7225) },
40434ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SA8295P) },
40534ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SA8540P) },
406f33ca7ecSBhupesh Sharma 	{ qcom_board_id(QCM4290) },
407f33ca7ecSBhupesh Sharma 	{ qcom_board_id(QCS4290) },
40834ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(SM8450_2, "SM8450") },
40934ec89e6SKrzysztof Kozlowski 	{ qcom_board_id_named(SM8450_3, "SM8450") },
41034ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SC7280) },
41134ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SC7180P) },
41259872d59SLuca Weiss 	{ qcom_board_id(QCM6490) },
4130369a590SRobert Marko 	{ qcom_board_id(IPQ5000) },
4140369a590SRobert Marko 	{ qcom_board_id(IPQ0509) },
4150369a590SRobert Marko 	{ qcom_board_id(IPQ0518) },
41634ec89e6SKrzysztof Kozlowski 	{ qcom_board_id(SM6375) },
417c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9514) },
418c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9550) },
419c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9554) },
420c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9570) },
421c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9574) },
422017a7c11SStephan Gerhold 	{ qcom_board_id(SM8550) },
4230369a590SRobert Marko 	{ qcom_board_id(IPQ5016) },
424c6653d8fSVaradarajan Narayanan 	{ qcom_board_id(IPQ9510) },
425a11bc4a5SBhupesh Sharma 	{ qcom_board_id(QRB4210) },
42618290c2eSKonrad Dybcio 	{ qcom_board_id(QRB2210) },
427c8f349acSDanila Tikhonov 	{ qcom_board_id(SM8475) },
428c8f349acSDanila Tikhonov 	{ qcom_board_id(SM8475P) },
4297fa9c5fcSBartosz Golaszewski 	{ qcom_board_id(SA8775P) },
430759dcdf2SMelody Olvera 	{ qcom_board_id(QRU1000) },
431c8f349acSDanila Tikhonov 	{ qcom_board_id(SM8475_2) },
432759dcdf2SMelody Olvera 	{ qcom_board_id(QDU1000) },
433*e876303cSAbel Vesa 	{ qcom_board_id(X1E80100) },
434f61319e5SNeil Armstrong 	{ qcom_board_id(SM8650) },
43542618de0STengfei Fan 	{ qcom_board_id(SM4450) },
436759dcdf2SMelody Olvera 	{ qcom_board_id(QDU1010) },
437759dcdf2SMelody Olvera 	{ qcom_board_id(QRU1032) },
438759dcdf2SMelody Olvera 	{ qcom_board_id(QRU1052) },
439759dcdf2SMelody Olvera 	{ qcom_board_id(QRU1062) },
440b0bc8c89SKathiravan T 	{ qcom_board_id(IPQ5332) },
441b0bc8c89SKathiravan T 	{ qcom_board_id(IPQ5322) },
4427f6e0028SKathiravan T 	{ qcom_board_id(IPQ5312) },
4437f6e0028SKathiravan T 	{ qcom_board_id(IPQ5302) },
444d7f3a369STengfei Fan 	{ qcom_board_id(QCS8550) },
445d7f3a369STengfei Fan 	{ qcom_board_id(QCM8550) },
446f471f91aSKathiravan T 	{ qcom_board_id(IPQ5300) },
447efb448d0SImran Khan };
448efb448d0SImran Khan 
449efb448d0SImran Khan static const char *socinfo_machine(struct device *dev, unsigned int id)
450efb448d0SImran Khan {
451efb448d0SImran Khan 	int idx;
452efb448d0SImran Khan 
453efb448d0SImran Khan 	for (idx = 0; idx < ARRAY_SIZE(soc_id); idx++) {
454efb448d0SImran Khan 		if (soc_id[idx].id == id)
455efb448d0SImran Khan 			return soc_id[idx].name;
456efb448d0SImran Khan 	}
457efb448d0SImran Khan 
458efb448d0SImran Khan 	return NULL;
459efb448d0SImran Khan }
460efb448d0SImran Khan 
4619c84c1e7SVaishali Thakkar #ifdef CONFIG_DEBUG_FS
4629c84c1e7SVaishali Thakkar 
4639c84c1e7SVaishali Thakkar #define QCOM_OPEN(name, _func)						\
4649c84c1e7SVaishali Thakkar static int qcom_open_##name(struct inode *inode, struct file *file)	\
4659c84c1e7SVaishali Thakkar {									\
4669c84c1e7SVaishali Thakkar 	return single_open(file, _func, inode->i_private);		\
4679c84c1e7SVaishali Thakkar }									\
4689c84c1e7SVaishali Thakkar 									\
4699c84c1e7SVaishali Thakkar static const struct file_operations qcom_ ##name## _ops = {		\
4709c84c1e7SVaishali Thakkar 	.open = qcom_open_##name,					\
4719c84c1e7SVaishali Thakkar 	.read = seq_read,						\
4729c84c1e7SVaishali Thakkar 	.llseek = seq_lseek,						\
4739c84c1e7SVaishali Thakkar 	.release = single_release,					\
4749c84c1e7SVaishali Thakkar }
4759c84c1e7SVaishali Thakkar 
4769c84c1e7SVaishali Thakkar #define DEBUGFS_ADD(info, name)						\
4778333b2c2SStephen Boyd 	debugfs_create_file(__stringify(name), 0444,			\
4789c84c1e7SVaishali Thakkar 			    qcom_socinfo->dbg_root,			\
4799c84c1e7SVaishali Thakkar 			    info, &qcom_ ##name## _ops)
4809c84c1e7SVaishali Thakkar 
4819c84c1e7SVaishali Thakkar 
4829c84c1e7SVaishali Thakkar static int qcom_show_build_id(struct seq_file *seq, void *p)
4839c84c1e7SVaishali Thakkar {
4849c84c1e7SVaishali Thakkar 	struct socinfo *socinfo = seq->private;
4859c84c1e7SVaishali Thakkar 
4869c84c1e7SVaishali Thakkar 	seq_printf(seq, "%s\n", socinfo->build_id);
4879c84c1e7SVaishali Thakkar 
4889c84c1e7SVaishali Thakkar 	return 0;
4899c84c1e7SVaishali Thakkar }
4909c84c1e7SVaishali Thakkar 
4919c84c1e7SVaishali Thakkar static int qcom_show_pmic_model(struct seq_file *seq, void *p)
4929c84c1e7SVaishali Thakkar {
4939c84c1e7SVaishali Thakkar 	struct socinfo *socinfo = seq->private;
4949c84c1e7SVaishali Thakkar 	int model = SOCINFO_MINOR(le32_to_cpu(socinfo->pmic_model));
4959c84c1e7SVaishali Thakkar 
4969c84c1e7SVaishali Thakkar 	if (model < 0)
4979c84c1e7SVaishali Thakkar 		return -EINVAL;
4989c84c1e7SVaishali Thakkar 
4995fb33d89SDan Carpenter 	if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
5009c84c1e7SVaishali Thakkar 		seq_printf(seq, "%s\n", pmic_models[model]);
501e9247e2cSDmitry Baryshkov 	else
502e9247e2cSDmitry Baryshkov 		seq_printf(seq, "unknown (%d)\n", model);
5039c84c1e7SVaishali Thakkar 
5049c84c1e7SVaishali Thakkar 	return 0;
5059c84c1e7SVaishali Thakkar }
5069c84c1e7SVaishali Thakkar 
507734c78e7SDmitry Baryshkov static int qcom_show_pmic_model_array(struct seq_file *seq, void *p)
508734c78e7SDmitry Baryshkov {
509734c78e7SDmitry Baryshkov 	struct socinfo *socinfo = seq->private;
510734c78e7SDmitry Baryshkov 	unsigned int num_pmics = le32_to_cpu(socinfo->num_pmics);
511734c78e7SDmitry Baryshkov 	unsigned int pmic_array_offset = le32_to_cpu(socinfo->pmic_array_offset);
512734c78e7SDmitry Baryshkov 	int i;
513734c78e7SDmitry Baryshkov 	void *ptr = socinfo;
514734c78e7SDmitry Baryshkov 
515734c78e7SDmitry Baryshkov 	ptr += pmic_array_offset;
516734c78e7SDmitry Baryshkov 
517734c78e7SDmitry Baryshkov 	/* No need for bounds checking, it happened at socinfo_debugfs_init */
518734c78e7SDmitry Baryshkov 	for (i = 0; i < num_pmics; i++) {
519734c78e7SDmitry Baryshkov 		unsigned int model = SOCINFO_MINOR(get_unaligned_le32(ptr + 2 * i * sizeof(u32)));
520734c78e7SDmitry Baryshkov 		unsigned int die_rev = get_unaligned_le32(ptr + (2 * i + 1) * sizeof(u32));
521734c78e7SDmitry Baryshkov 
522e6393818SColin Ian King 		if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
523734c78e7SDmitry Baryshkov 			seq_printf(seq, "%s %u.%u\n", pmic_models[model],
524aec8535eSDmitry Baryshkov 				   SOCINFO_MAJOR(die_rev),
525aec8535eSDmitry Baryshkov 				   SOCINFO_MINOR(die_rev));
526734c78e7SDmitry Baryshkov 		else
527734c78e7SDmitry Baryshkov 			seq_printf(seq, "unknown (%d)\n", model);
528734c78e7SDmitry Baryshkov 	}
529734c78e7SDmitry Baryshkov 
530734c78e7SDmitry Baryshkov 	return 0;
531734c78e7SDmitry Baryshkov }
532734c78e7SDmitry Baryshkov 
5339c84c1e7SVaishali Thakkar static int qcom_show_pmic_die_revision(struct seq_file *seq, void *p)
5349c84c1e7SVaishali Thakkar {
5359c84c1e7SVaishali Thakkar 	struct socinfo *socinfo = seq->private;
5369c84c1e7SVaishali Thakkar 
5379c84c1e7SVaishali Thakkar 	seq_printf(seq, "%u.%u\n",
5389c84c1e7SVaishali Thakkar 		   SOCINFO_MAJOR(le32_to_cpu(socinfo->pmic_die_rev)),
5399c84c1e7SVaishali Thakkar 		   SOCINFO_MINOR(le32_to_cpu(socinfo->pmic_die_rev)));
5409c84c1e7SVaishali Thakkar 
5419c84c1e7SVaishali Thakkar 	return 0;
5429c84c1e7SVaishali Thakkar }
5439c84c1e7SVaishali Thakkar 
5440f12fe7fSDmitry Baryshkov static int qcom_show_chip_id(struct seq_file *seq, void *p)
5450f12fe7fSDmitry Baryshkov {
5460f12fe7fSDmitry Baryshkov 	struct socinfo *socinfo = seq->private;
5470f12fe7fSDmitry Baryshkov 
5480f12fe7fSDmitry Baryshkov 	seq_printf(seq, "%s\n", socinfo->chip_id);
5490f12fe7fSDmitry Baryshkov 
5500f12fe7fSDmitry Baryshkov 	return 0;
5510f12fe7fSDmitry Baryshkov }
5520f12fe7fSDmitry Baryshkov 
5539c84c1e7SVaishali Thakkar QCOM_OPEN(build_id, qcom_show_build_id);
5549c84c1e7SVaishali Thakkar QCOM_OPEN(pmic_model, qcom_show_pmic_model);
555734c78e7SDmitry Baryshkov QCOM_OPEN(pmic_model_array, qcom_show_pmic_model_array);
5569c84c1e7SVaishali Thakkar QCOM_OPEN(pmic_die_rev, qcom_show_pmic_die_revision);
5570f12fe7fSDmitry Baryshkov QCOM_OPEN(chip_id, qcom_show_chip_id);
5589c84c1e7SVaishali Thakkar 
559cd23d140SVaishali Thakkar #define DEFINE_IMAGE_OPS(type)					\
560cd23d140SVaishali Thakkar static int show_image_##type(struct seq_file *seq, void *p)		  \
561cd23d140SVaishali Thakkar {								  \
562cd23d140SVaishali Thakkar 	struct smem_image_version *image_version = seq->private;  \
5630d361b0aSStephen Boyd 	if (image_version->type[0] != '\0')			  \
5640d361b0aSStephen Boyd 		seq_printf(seq, "%s\n", image_version->type);	  \
565cd23d140SVaishali Thakkar 	return 0;						  \
566cd23d140SVaishali Thakkar }								  \
567cd23d140SVaishali Thakkar static int open_image_##type(struct inode *inode, struct file *file)	  \
568cd23d140SVaishali Thakkar {									  \
569cd23d140SVaishali Thakkar 	return single_open(file, show_image_##type, inode->i_private); \
570cd23d140SVaishali Thakkar }									  \
571cd23d140SVaishali Thakkar 									  \
572cd23d140SVaishali Thakkar static const struct file_operations qcom_image_##type##_ops = {	  \
573cd23d140SVaishali Thakkar 	.open = open_image_##type,					  \
574cd23d140SVaishali Thakkar 	.read = seq_read,						  \
575cd23d140SVaishali Thakkar 	.llseek = seq_lseek,						  \
576cd23d140SVaishali Thakkar 	.release = single_release,					  \
577cd23d140SVaishali Thakkar }
578cd23d140SVaishali Thakkar 
579cd23d140SVaishali Thakkar DEFINE_IMAGE_OPS(name);
580cd23d140SVaishali Thakkar DEFINE_IMAGE_OPS(variant);
581cd23d140SVaishali Thakkar DEFINE_IMAGE_OPS(oem);
582cd23d140SVaishali Thakkar 
5839c84c1e7SVaishali Thakkar static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo,
584734c78e7SDmitry Baryshkov 				 struct socinfo *info, size_t info_size)
5859c84c1e7SVaishali Thakkar {
586cd23d140SVaishali Thakkar 	struct smem_image_version *versions;
587cd23d140SVaishali Thakkar 	struct dentry *dentry;
5889c84c1e7SVaishali Thakkar 	size_t size;
589cd23d140SVaishali Thakkar 	int i;
590734c78e7SDmitry Baryshkov 	unsigned int num_pmics;
591734c78e7SDmitry Baryshkov 	unsigned int pmic_array_offset;
5929c84c1e7SVaishali Thakkar 
5939c84c1e7SVaishali Thakkar 	qcom_socinfo->dbg_root = debugfs_create_dir("qcom_socinfo", NULL);
5949c84c1e7SVaishali Thakkar 
5959c84c1e7SVaishali Thakkar 	qcom_socinfo->info.fmt = __le32_to_cpu(info->fmt);
5969c84c1e7SVaishali Thakkar 
5978333b2c2SStephen Boyd 	debugfs_create_x32("info_fmt", 0444, qcom_socinfo->dbg_root,
59850f85d16SDmitry Baryshkov 			   &qcom_socinfo->info.fmt);
59950f85d16SDmitry Baryshkov 
6009c84c1e7SVaishali Thakkar 	switch (qcom_socinfo->info.fmt) {
601d9c2a255SNaman Jain 	case SOCINFO_VERSION(0, 19):
602d9c2a255SNaman Jain 		qcom_socinfo->info.num_func_clusters = __le32_to_cpu(info->num_func_clusters);
603d9c2a255SNaman Jain 		qcom_socinfo->info.boot_cluster = __le32_to_cpu(info->boot_cluster);
604d9c2a255SNaman Jain 		qcom_socinfo->info.boot_core = __le32_to_cpu(info->boot_core);
605d9c2a255SNaman Jain 
606d9c2a255SNaman Jain 		debugfs_create_u32("num_func_clusters", 0444, qcom_socinfo->dbg_root,
607d9c2a255SNaman Jain 				   &qcom_socinfo->info.num_func_clusters);
608d9c2a255SNaman Jain 		debugfs_create_u32("boot_cluster", 0444, qcom_socinfo->dbg_root,
609d9c2a255SNaman Jain 				   &qcom_socinfo->info.boot_cluster);
610d9c2a255SNaman Jain 		debugfs_create_u32("boot_core", 0444, qcom_socinfo->dbg_root,
611d9c2a255SNaman Jain 				   &qcom_socinfo->info.boot_core);
612d9c2a255SNaman Jain 		fallthrough;
613158826c7SNaman Jain 	case SOCINFO_VERSION(0, 18):
6146bdab60dSNaman Jain 	case SOCINFO_VERSION(0, 17):
6156bdab60dSNaman Jain 		qcom_socinfo->info.oem_variant = __le32_to_cpu(info->oem_variant);
6166bdab60dSNaman Jain 		debugfs_create_u32("oem_variant", 0444, qcom_socinfo->dbg_root,
6176bdab60dSNaman Jain 				   &qcom_socinfo->info.oem_variant);
6186bdab60dSNaman Jain 		fallthrough;
619f02a5373SNaman Jain 	case SOCINFO_VERSION(0, 16):
620f02a5373SNaman Jain 		qcom_socinfo->info.feature_code = __le32_to_cpu(info->feature_code);
621f02a5373SNaman Jain 		qcom_socinfo->info.pcode = __le32_to_cpu(info->pcode);
622f02a5373SNaman Jain 
623f02a5373SNaman Jain 		debugfs_create_u32("feature_code", 0444, qcom_socinfo->dbg_root,
624f02a5373SNaman Jain 				   &qcom_socinfo->info.feature_code);
625f02a5373SNaman Jain 		debugfs_create_u32("pcode", 0444, qcom_socinfo->dbg_root,
626f02a5373SNaman Jain 				   &qcom_socinfo->info.pcode);
627f02a5373SNaman Jain 		fallthrough;
6280f12fe7fSDmitry Baryshkov 	case SOCINFO_VERSION(0, 15):
6290f12fe7fSDmitry Baryshkov 		qcom_socinfo->info.nmodem_supported = __le32_to_cpu(info->nmodem_supported);
6300f12fe7fSDmitry Baryshkov 
6318333b2c2SStephen Boyd 		debugfs_create_u32("nmodem_supported", 0444, qcom_socinfo->dbg_root,
6320f12fe7fSDmitry Baryshkov 				   &qcom_socinfo->info.nmodem_supported);
633df561f66SGustavo A. R. Silva 		fallthrough;
6340f12fe7fSDmitry Baryshkov 	case SOCINFO_VERSION(0, 14):
6350f12fe7fSDmitry Baryshkov 		qcom_socinfo->info.num_clusters = __le32_to_cpu(info->num_clusters);
6360f12fe7fSDmitry Baryshkov 		qcom_socinfo->info.ncluster_array_offset = __le32_to_cpu(info->ncluster_array_offset);
637d9c2a255SNaman Jain 		qcom_socinfo->info.num_subset_parts = __le32_to_cpu(info->num_subset_parts);
638d9c2a255SNaman Jain 		qcom_socinfo->info.nsubset_parts_array_offset =
639d9c2a255SNaman Jain 			__le32_to_cpu(info->nsubset_parts_array_offset);
6400f12fe7fSDmitry Baryshkov 
6418333b2c2SStephen Boyd 		debugfs_create_u32("num_clusters", 0444, qcom_socinfo->dbg_root,
6420f12fe7fSDmitry Baryshkov 				   &qcom_socinfo->info.num_clusters);
6438333b2c2SStephen Boyd 		debugfs_create_u32("ncluster_array_offset", 0444, qcom_socinfo->dbg_root,
6440f12fe7fSDmitry Baryshkov 				   &qcom_socinfo->info.ncluster_array_offset);
645d9c2a255SNaman Jain 		debugfs_create_u32("num_subset_parts", 0444, qcom_socinfo->dbg_root,
646d9c2a255SNaman Jain 				   &qcom_socinfo->info.num_subset_parts);
647d9c2a255SNaman Jain 		debugfs_create_u32("nsubset_parts_array_offset", 0444, qcom_socinfo->dbg_root,
648d9c2a255SNaman Jain 				   &qcom_socinfo->info.nsubset_parts_array_offset);
649df561f66SGustavo A. R. Silva 		fallthrough;
6500f12fe7fSDmitry Baryshkov 	case SOCINFO_VERSION(0, 13):
6510f12fe7fSDmitry Baryshkov 		qcom_socinfo->info.nproduct_id = __le32_to_cpu(info->nproduct_id);
6520f12fe7fSDmitry Baryshkov 
6538333b2c2SStephen Boyd 		debugfs_create_u32("nproduct_id", 0444, qcom_socinfo->dbg_root,
6540f12fe7fSDmitry Baryshkov 				   &qcom_socinfo->info.nproduct_id);
6550f12fe7fSDmitry Baryshkov 		DEBUGFS_ADD(info, chip_id);
656df561f66SGustavo A. R. Silva 		fallthrough;
6579c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 12):
6589c84c1e7SVaishali Thakkar 		qcom_socinfo->info.chip_family =
6599c84c1e7SVaishali Thakkar 			__le32_to_cpu(info->chip_family);
6609c84c1e7SVaishali Thakkar 		qcom_socinfo->info.raw_device_family =
6619c84c1e7SVaishali Thakkar 			__le32_to_cpu(info->raw_device_family);
6629c84c1e7SVaishali Thakkar 		qcom_socinfo->info.raw_device_num =
6639c84c1e7SVaishali Thakkar 			__le32_to_cpu(info->raw_device_num);
6649c84c1e7SVaishali Thakkar 
6658333b2c2SStephen Boyd 		debugfs_create_x32("chip_family", 0444, qcom_socinfo->dbg_root,
6669c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.chip_family);
6678333b2c2SStephen Boyd 		debugfs_create_x32("raw_device_family", 0444,
6689c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
6699c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.raw_device_family);
6708333b2c2SStephen Boyd 		debugfs_create_x32("raw_device_number", 0444,
6719c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
6729c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.raw_device_num);
673df561f66SGustavo A. R. Silva 		fallthrough;
6749c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 11):
675734c78e7SDmitry Baryshkov 		num_pmics = le32_to_cpu(info->num_pmics);
676734c78e7SDmitry Baryshkov 		pmic_array_offset = le32_to_cpu(info->pmic_array_offset);
677734c78e7SDmitry Baryshkov 		if (pmic_array_offset + 2 * num_pmics * sizeof(u32) <= info_size)
678734c78e7SDmitry Baryshkov 			DEBUGFS_ADD(info, pmic_model_array);
679734c78e7SDmitry Baryshkov 		fallthrough;
6809c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 10):
6819c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 9):
6829c84c1e7SVaishali Thakkar 		qcom_socinfo->info.foundry_id = __le32_to_cpu(info->foundry_id);
6839c84c1e7SVaishali Thakkar 
6848333b2c2SStephen Boyd 		debugfs_create_u32("foundry_id", 0444, qcom_socinfo->dbg_root,
6859c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.foundry_id);
686df561f66SGustavo A. R. Silva 		fallthrough;
6879c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 8):
6889c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 7):
6899c84c1e7SVaishali Thakkar 		DEBUGFS_ADD(info, pmic_model);
6909c84c1e7SVaishali Thakkar 		DEBUGFS_ADD(info, pmic_die_rev);
691df561f66SGustavo A. R. Silva 		fallthrough;
6929c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 6):
6939c84c1e7SVaishali Thakkar 		qcom_socinfo->info.hw_plat_subtype =
6949c84c1e7SVaishali Thakkar 			__le32_to_cpu(info->hw_plat_subtype);
6959c84c1e7SVaishali Thakkar 
6968333b2c2SStephen Boyd 		debugfs_create_u32("hardware_platform_subtype", 0444,
6979c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
6989c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.hw_plat_subtype);
699df561f66SGustavo A. R. Silva 		fallthrough;
7009c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 5):
7019c84c1e7SVaishali Thakkar 		qcom_socinfo->info.accessory_chip =
7029c84c1e7SVaishali Thakkar 			__le32_to_cpu(info->accessory_chip);
7039c84c1e7SVaishali Thakkar 
7048333b2c2SStephen Boyd 		debugfs_create_u32("accessory_chip", 0444,
7059c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
7069c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.accessory_chip);
707df561f66SGustavo A. R. Silva 		fallthrough;
7089c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 4):
7099c84c1e7SVaishali Thakkar 		qcom_socinfo->info.plat_ver = __le32_to_cpu(info->plat_ver);
7109c84c1e7SVaishali Thakkar 
7118333b2c2SStephen Boyd 		debugfs_create_u32("platform_version", 0444,
7129c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
7139c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.plat_ver);
714df561f66SGustavo A. R. Silva 		fallthrough;
7159c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 3):
7169c84c1e7SVaishali Thakkar 		qcom_socinfo->info.hw_plat = __le32_to_cpu(info->hw_plat);
7179c84c1e7SVaishali Thakkar 
7188333b2c2SStephen Boyd 		debugfs_create_u32("hardware_platform", 0444,
7199c84c1e7SVaishali Thakkar 				   qcom_socinfo->dbg_root,
7209c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.hw_plat);
721df561f66SGustavo A. R. Silva 		fallthrough;
7229c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 2):
7239c84c1e7SVaishali Thakkar 		qcom_socinfo->info.raw_ver  = __le32_to_cpu(info->raw_ver);
7249c84c1e7SVaishali Thakkar 
7258333b2c2SStephen Boyd 		debugfs_create_u32("raw_version", 0444, qcom_socinfo->dbg_root,
7269c84c1e7SVaishali Thakkar 				   &qcom_socinfo->info.raw_ver);
727df561f66SGustavo A. R. Silva 		fallthrough;
7289c84c1e7SVaishali Thakkar 	case SOCINFO_VERSION(0, 1):
7299c84c1e7SVaishali Thakkar 		DEBUGFS_ADD(info, build_id);
7309c84c1e7SVaishali Thakkar 		break;
7319c84c1e7SVaishali Thakkar 	}
732cd23d140SVaishali Thakkar 
733cd23d140SVaishali Thakkar 	versions = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_IMAGE_VERSION_TABLE,
734cd23d140SVaishali Thakkar 				 &size);
735cd23d140SVaishali Thakkar 
736cd23d140SVaishali Thakkar 	for (i = 0; i < ARRAY_SIZE(socinfo_image_names); i++) {
737cd23d140SVaishali Thakkar 		if (!socinfo_image_names[i])
738cd23d140SVaishali Thakkar 			continue;
739cd23d140SVaishali Thakkar 
740cd23d140SVaishali Thakkar 		dentry = debugfs_create_dir(socinfo_image_names[i],
741cd23d140SVaishali Thakkar 					    qcom_socinfo->dbg_root);
7428333b2c2SStephen Boyd 		debugfs_create_file("name", 0444, dentry, &versions[i],
743cd23d140SVaishali Thakkar 				    &qcom_image_name_ops);
7448333b2c2SStephen Boyd 		debugfs_create_file("variant", 0444, dentry, &versions[i],
745cd23d140SVaishali Thakkar 				    &qcom_image_variant_ops);
7468333b2c2SStephen Boyd 		debugfs_create_file("oem", 0444, dentry, &versions[i],
747cd23d140SVaishali Thakkar 				    &qcom_image_oem_ops);
748cd23d140SVaishali Thakkar 	}
7499c84c1e7SVaishali Thakkar }
7509c84c1e7SVaishali Thakkar 
7519c84c1e7SVaishali Thakkar static void socinfo_debugfs_exit(struct qcom_socinfo *qcom_socinfo)
7529c84c1e7SVaishali Thakkar {
7539c84c1e7SVaishali Thakkar 	debugfs_remove_recursive(qcom_socinfo->dbg_root);
7549c84c1e7SVaishali Thakkar }
7559c84c1e7SVaishali Thakkar #else
7569c84c1e7SVaishali Thakkar static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo,
757734c78e7SDmitry Baryshkov 				 struct socinfo *info, size_t info_size)
7589c84c1e7SVaishali Thakkar {
7599c84c1e7SVaishali Thakkar }
7609c84c1e7SVaishali Thakkar static void socinfo_debugfs_exit(struct qcom_socinfo *qcom_socinfo) {  }
7619c84c1e7SVaishali Thakkar #endif /* CONFIG_DEBUG_FS */
7629c84c1e7SVaishali Thakkar 
763efb448d0SImran Khan static int qcom_socinfo_probe(struct platform_device *pdev)
764efb448d0SImran Khan {
765efb448d0SImran Khan 	struct qcom_socinfo *qs;
766efb448d0SImran Khan 	struct socinfo *info;
767efb448d0SImran Khan 	size_t item_size;
768efb448d0SImran Khan 
769efb448d0SImran Khan 	info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
770efb448d0SImran Khan 			      &item_size);
771efb448d0SImran Khan 	if (IS_ERR(info)) {
772efb448d0SImran Khan 		dev_err(&pdev->dev, "Couldn't find socinfo\n");
773efb448d0SImran Khan 		return PTR_ERR(info);
774efb448d0SImran Khan 	}
775efb448d0SImran Khan 
776efb448d0SImran Khan 	qs = devm_kzalloc(&pdev->dev, sizeof(*qs), GFP_KERNEL);
777efb448d0SImran Khan 	if (!qs)
778efb448d0SImran Khan 		return -ENOMEM;
779efb448d0SImran Khan 
780efb448d0SImran Khan 	qs->attr.family = "Snapdragon";
781efb448d0SImran Khan 	qs->attr.machine = socinfo_machine(&pdev->dev,
782efb448d0SImran Khan 					   le32_to_cpu(info->id));
78327a34413SSrinivas Kandagatla 	qs->attr.soc_id = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u",
78427a34413SSrinivas Kandagatla 					 le32_to_cpu(info->id));
785efb448d0SImran Khan 	qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u",
786efb448d0SImran Khan 					   SOCINFO_MAJOR(le32_to_cpu(info->ver)),
787efb448d0SImran Khan 					   SOCINFO_MINOR(le32_to_cpu(info->ver)));
788efb448d0SImran Khan 	if (offsetof(struct socinfo, serial_num) <= item_size)
789efb448d0SImran Khan 		qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL,
790efb448d0SImran Khan 							"%u",
791efb448d0SImran Khan 							le32_to_cpu(info->serial_num));
792efb448d0SImran Khan 
793efb448d0SImran Khan 	qs->soc_dev = soc_device_register(&qs->attr);
794efb448d0SImran Khan 	if (IS_ERR(qs->soc_dev))
795efb448d0SImran Khan 		return PTR_ERR(qs->soc_dev);
796efb448d0SImran Khan 
797734c78e7SDmitry Baryshkov 	socinfo_debugfs_init(qs, info, item_size);
7989c84c1e7SVaishali Thakkar 
799efb448d0SImran Khan 	/* Feed the soc specific unique data into entropy pool */
800efb448d0SImran Khan 	add_device_randomness(info, item_size);
801efb448d0SImran Khan 
8029c5a4ec6SAntonio Martorana 	platform_set_drvdata(pdev, qs);
803efb448d0SImran Khan 
804efb448d0SImran Khan 	return 0;
805efb448d0SImran Khan }
806efb448d0SImran Khan 
807c0989f7dSUwe Kleine-König static void qcom_socinfo_remove(struct platform_device *pdev)
808efb448d0SImran Khan {
809efb448d0SImran Khan 	struct qcom_socinfo *qs = platform_get_drvdata(pdev);
810efb448d0SImran Khan 
811efb448d0SImran Khan 	soc_device_unregister(qs->soc_dev);
812efb448d0SImran Khan 
8139c84c1e7SVaishali Thakkar 	socinfo_debugfs_exit(qs);
814efb448d0SImran Khan }
815efb448d0SImran Khan 
816efb448d0SImran Khan static struct platform_driver qcom_socinfo_driver = {
817efb448d0SImran Khan 	.probe = qcom_socinfo_probe,
818c0989f7dSUwe Kleine-König 	.remove_new = qcom_socinfo_remove,
819efb448d0SImran Khan 	.driver  = {
820efb448d0SImran Khan 		.name = "qcom-socinfo",
821efb448d0SImran Khan 	},
822efb448d0SImran Khan };
823efb448d0SImran Khan 
824efb448d0SImran Khan module_platform_driver(qcom_socinfo_driver);
825efb448d0SImran Khan 
826efb448d0SImran Khan MODULE_DESCRIPTION("Qualcomm SoCinfo driver");
827efb448d0SImran Khan MODULE_LICENSE("GPL v2");
828efb448d0SImran Khan MODULE_ALIAS("platform:qcom-socinfo");
829