1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2017-2019, Linaro Ltd.
5 */
6
7 #include <linux/debugfs.h>
8 #include <linux/err.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/random.h>
12 #include <linux/slab.h>
13 #include <linux/soc/qcom/smem.h>
14 #include <linux/soc/qcom/socinfo.h>
15 #include <linux/string.h>
16 #include <linux/stringify.h>
17 #include <linux/sys_soc.h>
18 #include <linux/types.h>
19
20 #include <linux/unaligned.h>
21
22 #include <dt-bindings/arm/qcom,ids.h>
23
24 /* Helper macros to create soc_id table */
25 #define qcom_board_id(id) QCOM_ID_ ## id, __stringify(id)
26 #define qcom_board_id_named(id, name) QCOM_ID_ ## id, (name)
27
28 #ifdef CONFIG_DEBUG_FS
29 #define SMEM_IMAGE_VERSION_BLOCKS_COUNT 32
30 #define SMEM_IMAGE_VERSION_SIZE 4096
31 #define SMEM_IMAGE_VERSION_NAME_SIZE 75
32 #define SMEM_IMAGE_VERSION_VARIANT_SIZE 20
33 #define SMEM_IMAGE_VERSION_OEM_SIZE 32
34
35 /*
36 * SMEM Image table indices
37 */
38 #define SMEM_IMAGE_TABLE_BOOT_INDEX 0
39 #define SMEM_IMAGE_TABLE_TZ_INDEX 1
40 #define SMEM_IMAGE_TABLE_RPM_INDEX 3
41 #define SMEM_IMAGE_TABLE_APPS_INDEX 10
42 #define SMEM_IMAGE_TABLE_MPSS_INDEX 11
43 #define SMEM_IMAGE_TABLE_ADSP_INDEX 12
44 #define SMEM_IMAGE_TABLE_CNSS_INDEX 13
45 #define SMEM_IMAGE_TABLE_VIDEO_INDEX 14
46 #define SMEM_IMAGE_TABLE_DSPS_INDEX 15
47 #define SMEM_IMAGE_TABLE_CDSP_INDEX 16
48 #define SMEM_IMAGE_TABLE_CDSP1_INDEX 19
49 #define SMEM_IMAGE_TABLE_GPDSP_INDEX 20
50 #define SMEM_IMAGE_TABLE_GPDSP1_INDEX 21
51 #define SMEM_IMAGE_VERSION_TABLE 469
52
53 /*
54 * SMEM Image table names
55 */
56 static const char *const socinfo_image_names[] = {
57 [SMEM_IMAGE_TABLE_ADSP_INDEX] = "adsp",
58 [SMEM_IMAGE_TABLE_APPS_INDEX] = "apps",
59 [SMEM_IMAGE_TABLE_BOOT_INDEX] = "boot",
60 [SMEM_IMAGE_TABLE_CNSS_INDEX] = "cnss",
61 [SMEM_IMAGE_TABLE_MPSS_INDEX] = "mpss",
62 [SMEM_IMAGE_TABLE_RPM_INDEX] = "rpm",
63 [SMEM_IMAGE_TABLE_TZ_INDEX] = "tz",
64 [SMEM_IMAGE_TABLE_VIDEO_INDEX] = "video",
65 [SMEM_IMAGE_TABLE_DSPS_INDEX] = "dsps",
66 [SMEM_IMAGE_TABLE_CDSP_INDEX] = "cdsp",
67 [SMEM_IMAGE_TABLE_CDSP1_INDEX] = "cdsp1",
68 [SMEM_IMAGE_TABLE_GPDSP_INDEX] = "gpdsp",
69 [SMEM_IMAGE_TABLE_GPDSP1_INDEX] = "gpdsp1",
70 };
71
72 static const char *const pmic_models[] = {
73 [0] = "Unknown PMIC model",
74 [1] = "PM8941",
75 [2] = "PM8841",
76 [3] = "PM8019",
77 [4] = "PM8226",
78 [5] = "PM8110",
79 [6] = "PMA8084",
80 [7] = "PMI8962",
81 [8] = "PMD9635",
82 [9] = "PM8994",
83 [10] = "PMI8994",
84 [11] = "PM8916",
85 [12] = "PM8004",
86 [13] = "PM8909/PM8058",
87 [14] = "PM8028",
88 [15] = "PM8901",
89 [16] = "PM8950/PM8027",
90 [17] = "PMI8950/ISL9519",
91 [18] = "PMK8001/PM8921",
92 [19] = "PMI8996/PM8018",
93 [20] = "PM8998/PM8015",
94 [21] = "PMI8998/PM8014",
95 [22] = "PM8821",
96 [23] = "PM8038",
97 [24] = "PM8005/PM8922",
98 [25] = "PM8917/PM8937",
99 [26] = "PM660L",
100 [27] = "PM660",
101 [30] = "PM8150",
102 [31] = "PM8150L",
103 [32] = "PM8150B",
104 [33] = "PMK8002",
105 [36] = "PM8009",
106 [37] = "PMI632",
107 [38] = "PM8150C",
108 [40] = "PM6150",
109 [41] = "SMB2351",
110 [44] = "PM8008",
111 [45] = "PM6125",
112 [46] = "PM7250B",
113 [47] = "PMK8350",
114 [48] = "PM8350",
115 [49] = "PM8350C",
116 [50] = "PM8350B",
117 [51] = "PMR735A",
118 [52] = "PMR735B",
119 [54] = "PM6350",
120 [55] = "PM4125",
121 [58] = "PM8450",
122 [65] = "PM8010",
123 [69] = "PM8550VS",
124 [70] = "PM8550VE",
125 [71] = "PM8550B",
126 [72] = "PMR735D",
127 [73] = "PM8550",
128 [74] = "PMK8550",
129 [82] = "PMC8380",
130 [83] = "SMB2360",
131 };
132
133 struct socinfo_params {
134 u32 raw_device_family;
135 u32 hw_plat_subtype;
136 u32 accessory_chip;
137 u32 raw_device_num;
138 u32 chip_family;
139 u32 foundry_id;
140 u32 plat_ver;
141 u32 raw_ver;
142 u32 hw_plat;
143 u32 fmt;
144 u32 nproduct_id;
145 u32 num_clusters;
146 u32 ncluster_array_offset;
147 u32 num_subset_parts;
148 u32 nsubset_parts_array_offset;
149 u32 nmodem_supported;
150 u32 feature_code;
151 u32 pcode;
152 u32 oem_variant;
153 u32 num_func_clusters;
154 u32 boot_cluster;
155 u32 boot_core;
156 };
157
158 struct smem_image_version {
159 char name[SMEM_IMAGE_VERSION_NAME_SIZE];
160 char variant[SMEM_IMAGE_VERSION_VARIANT_SIZE];
161 char pad;
162 char oem[SMEM_IMAGE_VERSION_OEM_SIZE];
163 };
164 #endif /* CONFIG_DEBUG_FS */
165
166 struct qcom_socinfo {
167 struct soc_device *soc_dev;
168 struct soc_device_attribute attr;
169 #ifdef CONFIG_DEBUG_FS
170 struct dentry *dbg_root;
171 struct socinfo_params info;
172 #endif /* CONFIG_DEBUG_FS */
173 };
174
175 struct soc_id {
176 unsigned int id;
177 const char *name;
178 };
179
180 static const struct soc_id soc_id[] = {
181 { qcom_board_id(MSM8260) },
182 { qcom_board_id(MSM8660) },
183 { qcom_board_id(APQ8060) },
184 { qcom_board_id(MSM8960) },
185 { qcom_board_id(APQ8064) },
186 { qcom_board_id(MSM8930) },
187 { qcom_board_id(MSM8630) },
188 { qcom_board_id(MSM8230) },
189 { qcom_board_id(APQ8030) },
190 { qcom_board_id(MSM8627) },
191 { qcom_board_id(MSM8227) },
192 { qcom_board_id(MSM8660A) },
193 { qcom_board_id(MSM8260A) },
194 { qcom_board_id(APQ8060A) },
195 { qcom_board_id(MSM8974) },
196 { qcom_board_id(MSM8225) },
197 { qcom_board_id(MSM8625) },
198 { qcom_board_id(MPQ8064) },
199 { qcom_board_id(MSM8960AB) },
200 { qcom_board_id(APQ8060AB) },
201 { qcom_board_id(MSM8260AB) },
202 { qcom_board_id(MSM8660AB) },
203 { qcom_board_id(MSM8930AA) },
204 { qcom_board_id(MSM8630AA) },
205 { qcom_board_id(MSM8230AA) },
206 { qcom_board_id(MSM8626) },
207 { qcom_board_id(MSM8610) },
208 { qcom_board_id(APQ8064AB) },
209 { qcom_board_id(MSM8930AB) },
210 { qcom_board_id(MSM8630AB) },
211 { qcom_board_id(MSM8230AB) },
212 { qcom_board_id(APQ8030AB) },
213 { qcom_board_id(MSM8226) },
214 { qcom_board_id(MSM8526) },
215 { qcom_board_id(APQ8030AA) },
216 { qcom_board_id(MSM8110) },
217 { qcom_board_id(MSM8210) },
218 { qcom_board_id(MSM8810) },
219 { qcom_board_id(MSM8212) },
220 { qcom_board_id(MSM8612) },
221 { qcom_board_id(MSM8112) },
222 { qcom_board_id(MSM8125) },
223 { qcom_board_id(MSM8225Q) },
224 { qcom_board_id(MSM8625Q) },
225 { qcom_board_id(MSM8125Q) },
226 { qcom_board_id(APQ8064AA) },
227 { qcom_board_id(APQ8084) },
228 { qcom_board_id(MSM8130) },
229 { qcom_board_id(MSM8130AA) },
230 { qcom_board_id(MSM8130AB) },
231 { qcom_board_id(MSM8627AA) },
232 { qcom_board_id(MSM8227AA) },
233 { qcom_board_id(APQ8074) },
234 { qcom_board_id(MSM8274) },
235 { qcom_board_id(MSM8674) },
236 { qcom_board_id(MDM9635) },
237 { qcom_board_id_named(MSM8974PRO_AC, "MSM8974PRO-AC") },
238 { qcom_board_id(MSM8126) },
239 { qcom_board_id(APQ8026) },
240 { qcom_board_id(MSM8926) },
241 { qcom_board_id(IPQ8062) },
242 { qcom_board_id(IPQ8064) },
243 { qcom_board_id(IPQ8066) },
244 { qcom_board_id(IPQ8068) },
245 { qcom_board_id(MSM8326) },
246 { qcom_board_id(MSM8916) },
247 { qcom_board_id(MSM8994) },
248 { qcom_board_id_named(APQ8074PRO_AA, "APQ8074PRO-AA") },
249 { qcom_board_id_named(APQ8074PRO_AB, "APQ8074PRO-AB") },
250 { qcom_board_id_named(APQ8074PRO_AC, "APQ8074PRO-AC") },
251 { qcom_board_id_named(MSM8274PRO_AA, "MSM8274PRO-AA") },
252 { qcom_board_id_named(MSM8274PRO_AB, "MSM8274PRO-AB") },
253 { qcom_board_id_named(MSM8274PRO_AC, "MSM8274PRO-AC") },
254 { qcom_board_id_named(MSM8674PRO_AA, "MSM8674PRO-AA") },
255 { qcom_board_id_named(MSM8674PRO_AB, "MSM8674PRO-AB") },
256 { qcom_board_id_named(MSM8674PRO_AC, "MSM8674PRO-AC") },
257 { qcom_board_id_named(MSM8974PRO_AA, "MSM8974PRO-AA") },
258 { qcom_board_id_named(MSM8974PRO_AB, "MSM8974PRO-AB") },
259 { qcom_board_id(APQ8028) },
260 { qcom_board_id(MSM8128) },
261 { qcom_board_id(MSM8228) },
262 { qcom_board_id(MSM8528) },
263 { qcom_board_id(MSM8628) },
264 { qcom_board_id(MSM8928) },
265 { qcom_board_id(MSM8510) },
266 { qcom_board_id(MSM8512) },
267 { qcom_board_id(MSM8936) },
268 { qcom_board_id(MDM9640) },
269 { qcom_board_id(MSM8939) },
270 { qcom_board_id(APQ8036) },
271 { qcom_board_id(APQ8039) },
272 { qcom_board_id(MSM8236) },
273 { qcom_board_id(MSM8636) },
274 { qcom_board_id(MSM8909) },
275 { qcom_board_id(MSM8996) },
276 { qcom_board_id(APQ8016) },
277 { qcom_board_id(MSM8216) },
278 { qcom_board_id(MSM8116) },
279 { qcom_board_id(MSM8616) },
280 { qcom_board_id(MSM8992) },
281 { qcom_board_id(APQ8092) },
282 { qcom_board_id(APQ8094) },
283 { qcom_board_id(MSM8209) },
284 { qcom_board_id(MSM8208) },
285 { qcom_board_id(MDM9209) },
286 { qcom_board_id(MDM9309) },
287 { qcom_board_id(MDM9609) },
288 { qcom_board_id(MSM8239) },
289 { qcom_board_id(MSM8952) },
290 { qcom_board_id(APQ8009) },
291 { qcom_board_id(MSM8956) },
292 { qcom_board_id(MSM8929) },
293 { qcom_board_id(MSM8629) },
294 { qcom_board_id(MSM8229) },
295 { qcom_board_id(APQ8029) },
296 { qcom_board_id(APQ8056) },
297 { qcom_board_id(MSM8609) },
298 { qcom_board_id(APQ8076) },
299 { qcom_board_id(MSM8976) },
300 { qcom_board_id(IPQ8065) },
301 { qcom_board_id(IPQ8069) },
302 { qcom_board_id(MDM9650) },
303 { qcom_board_id(MDM9655) },
304 { qcom_board_id(MDM9250) },
305 { qcom_board_id(MDM9255) },
306 { qcom_board_id(MDM9350) },
307 { qcom_board_id(APQ8052) },
308 { qcom_board_id(MDM9607) },
309 { qcom_board_id(APQ8096) },
310 { qcom_board_id(MSM8998) },
311 { qcom_board_id(MSM8953) },
312 { qcom_board_id(MSM8937) },
313 { qcom_board_id(APQ8037) },
314 { qcom_board_id(MDM8207) },
315 { qcom_board_id(MDM9207) },
316 { qcom_board_id(MDM9307) },
317 { qcom_board_id(MDM9628) },
318 { qcom_board_id(MSM8909W) },
319 { qcom_board_id(APQ8009W) },
320 { qcom_board_id(MSM8996L) },
321 { qcom_board_id(MSM8917) },
322 { qcom_board_id(APQ8053) },
323 { qcom_board_id(MSM8996SG) },
324 { qcom_board_id(APQ8017) },
325 { qcom_board_id(MSM8217) },
326 { qcom_board_id(MSM8617) },
327 { qcom_board_id(MSM8996AU) },
328 { qcom_board_id(APQ8096AU) },
329 { qcom_board_id(APQ8096SG) },
330 { qcom_board_id(MSM8940) },
331 { qcom_board_id(SDX201) },
332 { qcom_board_id(SDM660) },
333 { qcom_board_id(SDM630) },
334 { qcom_board_id(APQ8098) },
335 { qcom_board_id(MSM8920) },
336 { qcom_board_id(SDM845) },
337 { qcom_board_id(MDM9206) },
338 { qcom_board_id(IPQ8074) },
339 { qcom_board_id(SDA660) },
340 { qcom_board_id(SDM658) },
341 { qcom_board_id(SDA658) },
342 { qcom_board_id(SDA630) },
343 { qcom_board_id(MSM8905) },
344 { qcom_board_id(SDX202) },
345 { qcom_board_id(SDM670) },
346 { qcom_board_id(SDM450) },
347 { qcom_board_id(SM8150) },
348 { qcom_board_id(SDA845) },
349 { qcom_board_id(IPQ8072) },
350 { qcom_board_id(IPQ8076) },
351 { qcom_board_id(IPQ8078) },
352 { qcom_board_id(SDM636) },
353 { qcom_board_id(SDA636) },
354 { qcom_board_id(SDM632) },
355 { qcom_board_id(SDA632) },
356 { qcom_board_id(SDA450) },
357 { qcom_board_id(SDM439) },
358 { qcom_board_id(SDM429) },
359 { qcom_board_id(SM8250) },
360 { qcom_board_id(SA8155) },
361 { qcom_board_id(SDA439) },
362 { qcom_board_id(SDA429) },
363 { qcom_board_id(SM7150) },
364 { qcom_board_id(SM7150P) },
365 { qcom_board_id(IPQ8070) },
366 { qcom_board_id(IPQ8071) },
367 { qcom_board_id(QM215) },
368 { qcom_board_id(IPQ8072A) },
369 { qcom_board_id(IPQ8074A) },
370 { qcom_board_id(IPQ8076A) },
371 { qcom_board_id(IPQ8078A) },
372 { qcom_board_id(SM6125) },
373 { qcom_board_id(IPQ8070A) },
374 { qcom_board_id(IPQ8071A) },
375 { qcom_board_id(IPQ8172) },
376 { qcom_board_id(IPQ8173) },
377 { qcom_board_id(IPQ8174) },
378 { qcom_board_id(IPQ6018) },
379 { qcom_board_id(IPQ6028) },
380 { qcom_board_id(SDM429W) },
381 { qcom_board_id(SM4250) },
382 { qcom_board_id(IPQ6000) },
383 { qcom_board_id(IPQ6010) },
384 { qcom_board_id(SC7180) },
385 { qcom_board_id(SM6350) },
386 { qcom_board_id(QCM2150) },
387 { qcom_board_id(SDA429W) },
388 { qcom_board_id(SM8350) },
389 { qcom_board_id(QCM2290) },
390 { qcom_board_id(SM7125) },
391 { qcom_board_id(SM6115) },
392 { qcom_board_id(IPQ5010) },
393 { qcom_board_id(IPQ5018) },
394 { qcom_board_id(IPQ5028) },
395 { qcom_board_id(SC8280XP) },
396 { qcom_board_id(IPQ6005) },
397 { qcom_board_id(QRB5165) },
398 { qcom_board_id(SM8450) },
399 { qcom_board_id(SM7225) },
400 { qcom_board_id(SA8295P) },
401 { qcom_board_id(SA8540P) },
402 { qcom_board_id(QCM4290) },
403 { qcom_board_id(QCS4290) },
404 { qcom_board_id(SM7325) },
405 { qcom_board_id_named(SM8450_2, "SM8450") },
406 { qcom_board_id_named(SM8450_3, "SM8450") },
407 { qcom_board_id(SC7280) },
408 { qcom_board_id(SC7180P) },
409 { qcom_board_id(QCM6490) },
410 { qcom_board_id(SM7325P) },
411 { qcom_board_id(IPQ5000) },
412 { qcom_board_id(IPQ0509) },
413 { qcom_board_id(IPQ0518) },
414 { qcom_board_id(SM6375) },
415 { qcom_board_id(IPQ9514) },
416 { qcom_board_id(IPQ9550) },
417 { qcom_board_id(IPQ9554) },
418 { qcom_board_id(IPQ9570) },
419 { qcom_board_id(IPQ9574) },
420 { qcom_board_id(SM8550) },
421 { qcom_board_id(IPQ5016) },
422 { qcom_board_id(IPQ9510) },
423 { qcom_board_id(QRB4210) },
424 { qcom_board_id(QRB2210) },
425 { qcom_board_id(SAR2130P) },
426 { qcom_board_id(SM8475) },
427 { qcom_board_id(SM8475P) },
428 { qcom_board_id(SA8255P) },
429 { qcom_board_id(SA8775P) },
430 { qcom_board_id(QRU1000) },
431 { qcom_board_id(SM8475_2) },
432 { qcom_board_id(QDU1000) },
433 { qcom_board_id(X1E80100) },
434 { qcom_board_id(SM8650) },
435 { qcom_board_id(SM4450) },
436 { qcom_board_id(SAR1130P) },
437 { qcom_board_id(QDU1010) },
438 { qcom_board_id(QRU1032) },
439 { qcom_board_id(QRU1052) },
440 { qcom_board_id(QRU1062) },
441 { qcom_board_id(IPQ5332) },
442 { qcom_board_id(IPQ5322) },
443 { qcom_board_id(IPQ5312) },
444 { qcom_board_id(IPQ5302) },
445 { qcom_board_id(QCS8550) },
446 { qcom_board_id(QCM8550) },
447 { qcom_board_id(IPQ5300) },
448 { qcom_board_id(IPQ5321) },
449 { qcom_board_id(IPQ5424) },
450 { qcom_board_id(IPQ5404) },
451 { qcom_board_id(QCS9100) },
452 { qcom_board_id(QCS8300) },
453 { qcom_board_id(QCS8275) },
454 { qcom_board_id(QCS9075) },
455 { qcom_board_id(QCS615) },
456 };
457
socinfo_machine(struct device * dev,unsigned int id)458 static const char *socinfo_machine(struct device *dev, unsigned int id)
459 {
460 int idx;
461
462 for (idx = 0; idx < ARRAY_SIZE(soc_id); idx++) {
463 if (soc_id[idx].id == id)
464 return soc_id[idx].name;
465 }
466
467 return NULL;
468 }
469
470 #ifdef CONFIG_DEBUG_FS
471
472 #define QCOM_OPEN(name, _func) \
473 static int qcom_open_##name(struct inode *inode, struct file *file) \
474 { \
475 return single_open(file, _func, inode->i_private); \
476 } \
477 \
478 static const struct file_operations qcom_ ##name## _ops = { \
479 .open = qcom_open_##name, \
480 .read = seq_read, \
481 .llseek = seq_lseek, \
482 .release = single_release, \
483 }
484
485 #define DEBUGFS_ADD(info, name) \
486 debugfs_create_file(__stringify(name), 0444, \
487 qcom_socinfo->dbg_root, \
488 info, &qcom_ ##name## _ops)
489
490
qcom_show_build_id(struct seq_file * seq,void * p)491 static int qcom_show_build_id(struct seq_file *seq, void *p)
492 {
493 struct socinfo *socinfo = seq->private;
494
495 seq_printf(seq, "%s\n", socinfo->build_id);
496
497 return 0;
498 }
499
qcom_show_pmic_model(struct seq_file * seq,void * p)500 static int qcom_show_pmic_model(struct seq_file *seq, void *p)
501 {
502 struct socinfo *socinfo = seq->private;
503 int model = SOCINFO_MINOR(le32_to_cpu(socinfo->pmic_model));
504
505 if (model < 0)
506 return -EINVAL;
507
508 if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
509 seq_printf(seq, "%s\n", pmic_models[model]);
510 else
511 seq_printf(seq, "unknown (%d)\n", model);
512
513 return 0;
514 }
515
qcom_show_pmic_model_array(struct seq_file * seq,void * p)516 static int qcom_show_pmic_model_array(struct seq_file *seq, void *p)
517 {
518 struct socinfo *socinfo = seq->private;
519 unsigned int num_pmics = le32_to_cpu(socinfo->num_pmics);
520 unsigned int pmic_array_offset = le32_to_cpu(socinfo->pmic_array_offset);
521 int i;
522 void *ptr = socinfo;
523
524 ptr += pmic_array_offset;
525
526 /* No need for bounds checking, it happened at socinfo_debugfs_init */
527 for (i = 0; i < num_pmics; i++) {
528 unsigned int model = SOCINFO_MINOR(get_unaligned_le32(ptr + 2 * i * sizeof(u32)));
529 unsigned int die_rev = get_unaligned_le32(ptr + (2 * i + 1) * sizeof(u32));
530
531 if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
532 seq_printf(seq, "%s %u.%u\n", pmic_models[model],
533 SOCINFO_MAJOR(die_rev),
534 SOCINFO_MINOR(die_rev));
535 else
536 seq_printf(seq, "unknown (%d)\n", model);
537 }
538
539 return 0;
540 }
541
qcom_show_pmic_die_revision(struct seq_file * seq,void * p)542 static int qcom_show_pmic_die_revision(struct seq_file *seq, void *p)
543 {
544 struct socinfo *socinfo = seq->private;
545
546 seq_printf(seq, "%u.%u\n",
547 SOCINFO_MAJOR(le32_to_cpu(socinfo->pmic_die_rev)),
548 SOCINFO_MINOR(le32_to_cpu(socinfo->pmic_die_rev)));
549
550 return 0;
551 }
552
qcom_show_chip_id(struct seq_file * seq,void * p)553 static int qcom_show_chip_id(struct seq_file *seq, void *p)
554 {
555 struct socinfo *socinfo = seq->private;
556
557 seq_printf(seq, "%s\n", socinfo->chip_id);
558
559 return 0;
560 }
561
562 QCOM_OPEN(build_id, qcom_show_build_id);
563 QCOM_OPEN(pmic_model, qcom_show_pmic_model);
564 QCOM_OPEN(pmic_model_array, qcom_show_pmic_model_array);
565 QCOM_OPEN(pmic_die_rev, qcom_show_pmic_die_revision);
566 QCOM_OPEN(chip_id, qcom_show_chip_id);
567
568 #define DEFINE_IMAGE_OPS(type) \
569 static int show_image_##type(struct seq_file *seq, void *p) \
570 { \
571 struct smem_image_version *image_version = seq->private; \
572 if (image_version->type[0] != '\0') \
573 seq_printf(seq, "%s\n", image_version->type); \
574 return 0; \
575 } \
576 static int open_image_##type(struct inode *inode, struct file *file) \
577 { \
578 return single_open(file, show_image_##type, inode->i_private); \
579 } \
580 \
581 static const struct file_operations qcom_image_##type##_ops = { \
582 .open = open_image_##type, \
583 .read = seq_read, \
584 .llseek = seq_lseek, \
585 .release = single_release, \
586 }
587
588 DEFINE_IMAGE_OPS(name);
589 DEFINE_IMAGE_OPS(variant);
590 DEFINE_IMAGE_OPS(oem);
591
socinfo_debugfs_init(struct qcom_socinfo * qcom_socinfo,struct socinfo * info,size_t info_size)592 static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo,
593 struct socinfo *info, size_t info_size)
594 {
595 struct smem_image_version *versions;
596 struct dentry *dentry;
597 size_t size;
598 int i;
599 unsigned int num_pmics;
600 unsigned int pmic_array_offset;
601
602 qcom_socinfo->dbg_root = debugfs_create_dir("qcom_socinfo", NULL);
603
604 qcom_socinfo->info.fmt = __le32_to_cpu(info->fmt);
605
606 debugfs_create_x32("info_fmt", 0444, qcom_socinfo->dbg_root,
607 &qcom_socinfo->info.fmt);
608
609 switch (qcom_socinfo->info.fmt) {
610 case SOCINFO_VERSION(0, 19):
611 qcom_socinfo->info.num_func_clusters = __le32_to_cpu(info->num_func_clusters);
612 qcom_socinfo->info.boot_cluster = __le32_to_cpu(info->boot_cluster);
613 qcom_socinfo->info.boot_core = __le32_to_cpu(info->boot_core);
614
615 debugfs_create_u32("num_func_clusters", 0444, qcom_socinfo->dbg_root,
616 &qcom_socinfo->info.num_func_clusters);
617 debugfs_create_u32("boot_cluster", 0444, qcom_socinfo->dbg_root,
618 &qcom_socinfo->info.boot_cluster);
619 debugfs_create_u32("boot_core", 0444, qcom_socinfo->dbg_root,
620 &qcom_socinfo->info.boot_core);
621 fallthrough;
622 case SOCINFO_VERSION(0, 18):
623 case SOCINFO_VERSION(0, 17):
624 qcom_socinfo->info.oem_variant = __le32_to_cpu(info->oem_variant);
625 debugfs_create_u32("oem_variant", 0444, qcom_socinfo->dbg_root,
626 &qcom_socinfo->info.oem_variant);
627 fallthrough;
628 case SOCINFO_VERSION(0, 16):
629 qcom_socinfo->info.feature_code = __le32_to_cpu(info->feature_code);
630 qcom_socinfo->info.pcode = __le32_to_cpu(info->pcode);
631
632 debugfs_create_u32("feature_code", 0444, qcom_socinfo->dbg_root,
633 &qcom_socinfo->info.feature_code);
634 debugfs_create_u32("pcode", 0444, qcom_socinfo->dbg_root,
635 &qcom_socinfo->info.pcode);
636 fallthrough;
637 case SOCINFO_VERSION(0, 15):
638 qcom_socinfo->info.nmodem_supported = __le32_to_cpu(info->nmodem_supported);
639
640 debugfs_create_u32("nmodem_supported", 0444, qcom_socinfo->dbg_root,
641 &qcom_socinfo->info.nmodem_supported);
642 fallthrough;
643 case SOCINFO_VERSION(0, 14):
644 qcom_socinfo->info.num_clusters = __le32_to_cpu(info->num_clusters);
645 qcom_socinfo->info.ncluster_array_offset = __le32_to_cpu(info->ncluster_array_offset);
646 qcom_socinfo->info.num_subset_parts = __le32_to_cpu(info->num_subset_parts);
647 qcom_socinfo->info.nsubset_parts_array_offset =
648 __le32_to_cpu(info->nsubset_parts_array_offset);
649
650 debugfs_create_u32("num_clusters", 0444, qcom_socinfo->dbg_root,
651 &qcom_socinfo->info.num_clusters);
652 debugfs_create_u32("ncluster_array_offset", 0444, qcom_socinfo->dbg_root,
653 &qcom_socinfo->info.ncluster_array_offset);
654 debugfs_create_u32("num_subset_parts", 0444, qcom_socinfo->dbg_root,
655 &qcom_socinfo->info.num_subset_parts);
656 debugfs_create_u32("nsubset_parts_array_offset", 0444, qcom_socinfo->dbg_root,
657 &qcom_socinfo->info.nsubset_parts_array_offset);
658 fallthrough;
659 case SOCINFO_VERSION(0, 13):
660 qcom_socinfo->info.nproduct_id = __le32_to_cpu(info->nproduct_id);
661
662 debugfs_create_u32("nproduct_id", 0444, qcom_socinfo->dbg_root,
663 &qcom_socinfo->info.nproduct_id);
664 DEBUGFS_ADD(info, chip_id);
665 fallthrough;
666 case SOCINFO_VERSION(0, 12):
667 qcom_socinfo->info.chip_family =
668 __le32_to_cpu(info->chip_family);
669 qcom_socinfo->info.raw_device_family =
670 __le32_to_cpu(info->raw_device_family);
671 qcom_socinfo->info.raw_device_num =
672 __le32_to_cpu(info->raw_device_num);
673
674 debugfs_create_x32("chip_family", 0444, qcom_socinfo->dbg_root,
675 &qcom_socinfo->info.chip_family);
676 debugfs_create_x32("raw_device_family", 0444,
677 qcom_socinfo->dbg_root,
678 &qcom_socinfo->info.raw_device_family);
679 debugfs_create_x32("raw_device_number", 0444,
680 qcom_socinfo->dbg_root,
681 &qcom_socinfo->info.raw_device_num);
682 fallthrough;
683 case SOCINFO_VERSION(0, 11):
684 num_pmics = le32_to_cpu(info->num_pmics);
685 pmic_array_offset = le32_to_cpu(info->pmic_array_offset);
686 if (pmic_array_offset + 2 * num_pmics * sizeof(u32) <= info_size)
687 DEBUGFS_ADD(info, pmic_model_array);
688 fallthrough;
689 case SOCINFO_VERSION(0, 10):
690 case SOCINFO_VERSION(0, 9):
691 qcom_socinfo->info.foundry_id = __le32_to_cpu(info->foundry_id);
692
693 debugfs_create_u32("foundry_id", 0444, qcom_socinfo->dbg_root,
694 &qcom_socinfo->info.foundry_id);
695 fallthrough;
696 case SOCINFO_VERSION(0, 8):
697 case SOCINFO_VERSION(0, 7):
698 DEBUGFS_ADD(info, pmic_model);
699 DEBUGFS_ADD(info, pmic_die_rev);
700 fallthrough;
701 case SOCINFO_VERSION(0, 6):
702 qcom_socinfo->info.hw_plat_subtype =
703 __le32_to_cpu(info->hw_plat_subtype);
704
705 debugfs_create_u32("hardware_platform_subtype", 0444,
706 qcom_socinfo->dbg_root,
707 &qcom_socinfo->info.hw_plat_subtype);
708 fallthrough;
709 case SOCINFO_VERSION(0, 5):
710 qcom_socinfo->info.accessory_chip =
711 __le32_to_cpu(info->accessory_chip);
712
713 debugfs_create_u32("accessory_chip", 0444,
714 qcom_socinfo->dbg_root,
715 &qcom_socinfo->info.accessory_chip);
716 fallthrough;
717 case SOCINFO_VERSION(0, 4):
718 qcom_socinfo->info.plat_ver = __le32_to_cpu(info->plat_ver);
719
720 debugfs_create_u32("platform_version", 0444,
721 qcom_socinfo->dbg_root,
722 &qcom_socinfo->info.plat_ver);
723 fallthrough;
724 case SOCINFO_VERSION(0, 3):
725 qcom_socinfo->info.hw_plat = __le32_to_cpu(info->hw_plat);
726
727 debugfs_create_u32("hardware_platform", 0444,
728 qcom_socinfo->dbg_root,
729 &qcom_socinfo->info.hw_plat);
730 fallthrough;
731 case SOCINFO_VERSION(0, 2):
732 qcom_socinfo->info.raw_ver = __le32_to_cpu(info->raw_ver);
733
734 debugfs_create_u32("raw_version", 0444, qcom_socinfo->dbg_root,
735 &qcom_socinfo->info.raw_ver);
736 fallthrough;
737 case SOCINFO_VERSION(0, 1):
738 DEBUGFS_ADD(info, build_id);
739 break;
740 }
741
742 versions = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_IMAGE_VERSION_TABLE,
743 &size);
744
745 for (i = 0; i < ARRAY_SIZE(socinfo_image_names); i++) {
746 if (!socinfo_image_names[i])
747 continue;
748
749 dentry = debugfs_create_dir(socinfo_image_names[i],
750 qcom_socinfo->dbg_root);
751 debugfs_create_file("name", 0444, dentry, &versions[i],
752 &qcom_image_name_ops);
753 debugfs_create_file("variant", 0444, dentry, &versions[i],
754 &qcom_image_variant_ops);
755 debugfs_create_file("oem", 0444, dentry, &versions[i],
756 &qcom_image_oem_ops);
757 }
758 }
759
socinfo_debugfs_exit(struct qcom_socinfo * qcom_socinfo)760 static void socinfo_debugfs_exit(struct qcom_socinfo *qcom_socinfo)
761 {
762 debugfs_remove_recursive(qcom_socinfo->dbg_root);
763 }
764 #else
socinfo_debugfs_init(struct qcom_socinfo * qcom_socinfo,struct socinfo * info,size_t info_size)765 static void socinfo_debugfs_init(struct qcom_socinfo *qcom_socinfo,
766 struct socinfo *info, size_t info_size)
767 {
768 }
socinfo_debugfs_exit(struct qcom_socinfo * qcom_socinfo)769 static void socinfo_debugfs_exit(struct qcom_socinfo *qcom_socinfo) { }
770 #endif /* CONFIG_DEBUG_FS */
771
qcom_socinfo_probe(struct platform_device * pdev)772 static int qcom_socinfo_probe(struct platform_device *pdev)
773 {
774 struct qcom_socinfo *qs;
775 struct socinfo *info;
776 size_t item_size;
777
778 info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
779 &item_size);
780 if (IS_ERR(info)) {
781 dev_err(&pdev->dev, "Couldn't find socinfo\n");
782 return PTR_ERR(info);
783 }
784
785 qs = devm_kzalloc(&pdev->dev, sizeof(*qs), GFP_KERNEL);
786 if (!qs)
787 return -ENOMEM;
788
789 qs->attr.family = "Snapdragon";
790 qs->attr.machine = socinfo_machine(&pdev->dev,
791 le32_to_cpu(info->id));
792 qs->attr.soc_id = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u",
793 le32_to_cpu(info->id));
794 qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u",
795 SOCINFO_MAJOR(le32_to_cpu(info->ver)),
796 SOCINFO_MINOR(le32_to_cpu(info->ver)));
797 if (!qs->attr.soc_id || !qs->attr.revision)
798 return -ENOMEM;
799
800 if (offsetofend(struct socinfo, serial_num) <= item_size) {
801 qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL,
802 "%u",
803 le32_to_cpu(info->serial_num));
804 if (!qs->attr.serial_number)
805 return -ENOMEM;
806 }
807
808 qs->soc_dev = soc_device_register(&qs->attr);
809 if (IS_ERR(qs->soc_dev))
810 return PTR_ERR(qs->soc_dev);
811
812 socinfo_debugfs_init(qs, info, item_size);
813
814 /* Feed the soc specific unique data into entropy pool */
815 add_device_randomness(info, item_size);
816
817 platform_set_drvdata(pdev, qs);
818
819 return 0;
820 }
821
qcom_socinfo_remove(struct platform_device * pdev)822 static void qcom_socinfo_remove(struct platform_device *pdev)
823 {
824 struct qcom_socinfo *qs = platform_get_drvdata(pdev);
825
826 soc_device_unregister(qs->soc_dev);
827
828 socinfo_debugfs_exit(qs);
829 }
830
831 static struct platform_driver qcom_socinfo_driver = {
832 .probe = qcom_socinfo_probe,
833 .remove = qcom_socinfo_remove,
834 .driver = {
835 .name = "qcom-socinfo",
836 },
837 };
838
839 module_platform_driver(qcom_socinfo_driver);
840
841 MODULE_DESCRIPTION("Qualcomm SoCinfo driver");
842 MODULE_LICENSE("GPL v2");
843 MODULE_ALIAS("platform:qcom-socinfo");
844