blob: 4d0e0605fa75d69122e2cb6e1154da53358ee92b [file] [log] [blame]
Taniya Dasa04e1892011-11-16 14:49:12 +05301/* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13/*
14 * SOC Info Routines
15 *
16 */
17
18#include <linux/types.h>
19#include <linux/sysdev.h>
20#include <asm/mach-types.h>
21#include <mach/socinfo.h>
22
23#include "smd_private.h"
24
25#define BUILD_ID_LENGTH 32
26
27enum {
28 HW_PLATFORM_UNKNOWN = 0,
29 HW_PLATFORM_SURF = 1,
30 HW_PLATFORM_FFA = 2,
31 HW_PLATFORM_FLUID = 3,
32 HW_PLATFORM_SVLTE_FFA = 4,
33 HW_PLATFORM_SVLTE_SURF = 5,
Jin Hong49753322011-12-15 16:55:37 -080034 HW_PLATFORM_MTP = 8,
Amir Samuelov1b0dc312011-11-17 20:43:33 +020035 HW_PLATFORM_LIQUID = 9,
Zhang Chang Ken59004eb2011-08-08 09:06:58 -040036 /* Dragonboard platform id is assigned as 10 in CDT */
37 HW_PLATFORM_DRAGON = 10,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038 HW_PLATFORM_INVALID
39};
40
41const char *hw_platform[] = {
42 [HW_PLATFORM_UNKNOWN] = "Unknown",
43 [HW_PLATFORM_SURF] = "Surf",
44 [HW_PLATFORM_FFA] = "FFA",
45 [HW_PLATFORM_FLUID] = "Fluid",
46 [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040047 [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF",
Jin Hong49753322011-12-15 16:55:37 -080048 [HW_PLATFORM_MTP] = "MTP",
49 [HW_PLATFORM_LIQUID] = "Liquid",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040050 [HW_PLATFORM_DRAGON] = "Dragon"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051};
52
53enum {
54 ACCESSORY_CHIP_UNKNOWN = 0,
55 ACCESSORY_CHIP_CHARM = 58,
56};
57
58enum {
59 PLATFORM_SUBTYPE_UNKNOWN = 0x0,
60 PLATFORM_SUBTYPE_CHARM = 0x1,
61 PLATFORM_SUBTYPE_STRANGE = 0x2,
62 PLATFORM_SUBTYPE_STRANGE_2A = 0x3,
63 PLATFORM_SUBTYPE_INVALID,
64};
65
66const char *hw_platform_subtype[] = {
67 [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown",
68 [PLATFORM_SUBTYPE_CHARM] = "charm",
69 [PLATFORM_SUBTYPE_STRANGE] = "strange",
70 [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a,"
71};
72
73/* Used to parse shared memory. Must match the modem. */
74struct socinfo_v1 {
75 uint32_t format;
76 uint32_t id;
77 uint32_t version;
78 char build_id[BUILD_ID_LENGTH];
79};
80
81struct socinfo_v2 {
82 struct socinfo_v1 v1;
83
84 /* only valid when format==2 */
85 uint32_t raw_id;
86 uint32_t raw_version;
87};
88
89struct socinfo_v3 {
90 struct socinfo_v2 v2;
91
92 /* only valid when format==3 */
93 uint32_t hw_platform;
94};
95
96struct socinfo_v4 {
97 struct socinfo_v3 v3;
98
99 /* only valid when format==4 */
100 uint32_t platform_version;
101};
102
103struct socinfo_v5 {
104 struct socinfo_v4 v4;
105
106 /* only valid when format==5 */
107 uint32_t accessory_chip;
108};
109
110struct socinfo_v6 {
111 struct socinfo_v5 v5;
112
113 /* only valid when format==6 */
114 uint32_t hw_platform_subtype;
115};
116
Jin Honge795bd22012-08-13 23:06:26 -0700117struct socinfo_v7 {
118 struct socinfo_v6 v6;
119
120 /* only valid when format==7 */
121 uint32_t pmic_model;
122 uint32_t pmic_die_revision;
123};
124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125static union {
126 struct socinfo_v1 v1;
127 struct socinfo_v2 v2;
128 struct socinfo_v3 v3;
129 struct socinfo_v4 v4;
130 struct socinfo_v5 v5;
131 struct socinfo_v6 v6;
Jin Honge795bd22012-08-13 23:06:26 -0700132 struct socinfo_v7 v7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133} *socinfo;
134
135static enum msm_cpu cpu_of_id[] = {
136
137 /* 7x01 IDs */
138 [1] = MSM_CPU_7X01,
139 [16] = MSM_CPU_7X01,
140 [17] = MSM_CPU_7X01,
141 [18] = MSM_CPU_7X01,
142 [19] = MSM_CPU_7X01,
143 [23] = MSM_CPU_7X01,
144 [25] = MSM_CPU_7X01,
145 [26] = MSM_CPU_7X01,
146 [32] = MSM_CPU_7X01,
147 [33] = MSM_CPU_7X01,
148 [34] = MSM_CPU_7X01,
149 [35] = MSM_CPU_7X01,
150
151 /* 7x25 IDs */
152 [20] = MSM_CPU_7X25,
153 [21] = MSM_CPU_7X25, /* 7225 */
154 [24] = MSM_CPU_7X25, /* 7525 */
155 [27] = MSM_CPU_7X25, /* 7625 */
156 [39] = MSM_CPU_7X25,
157 [40] = MSM_CPU_7X25,
158 [41] = MSM_CPU_7X25,
159 [42] = MSM_CPU_7X25,
160 [62] = MSM_CPU_7X25, /* 7625-1 */
161 [63] = MSM_CPU_7X25, /* 7225-1 */
162 [66] = MSM_CPU_7X25, /* 7225-2 */
163
164
165 /* 7x27 IDs */
166 [43] = MSM_CPU_7X27,
167 [44] = MSM_CPU_7X27,
168 [61] = MSM_CPU_7X27,
169 [67] = MSM_CPU_7X27, /* 7227-1 */
170 [68] = MSM_CPU_7X27, /* 7627-1 */
171 [69] = MSM_CPU_7X27, /* 7627-2 */
172
173
174 /* 8x50 IDs */
175 [30] = MSM_CPU_8X50,
176 [36] = MSM_CPU_8X50,
177 [37] = MSM_CPU_8X50,
178 [38] = MSM_CPU_8X50,
179
180 /* 7x30 IDs */
181 [59] = MSM_CPU_7X30,
182 [60] = MSM_CPU_7X30,
183
184 /* 8x55 IDs */
185 [74] = MSM_CPU_8X55,
186 [75] = MSM_CPU_8X55,
187 [85] = MSM_CPU_8X55,
188
189 /* 8x60 IDs */
190 [70] = MSM_CPU_8X60,
191 [71] = MSM_CPU_8X60,
192 [86] = MSM_CPU_8X60,
193
194 /* 8960 IDs */
195 [87] = MSM_CPU_8960,
196
197 /* 7x25A IDs */
198 [88] = MSM_CPU_7X25A,
199 [89] = MSM_CPU_7X25A,
200 [96] = MSM_CPU_7X25A,
201
202 /* 7x27A IDs */
203 [90] = MSM_CPU_7X27A,
204 [91] = MSM_CPU_7X27A,
205 [92] = MSM_CPU_7X27A,
206 [97] = MSM_CPU_7X27A,
207
208 /* FSM9xxx ID */
209 [94] = FSM_CPU_9XXX,
210 [95] = FSM_CPU_9XXX,
211
212 /* 7x25AA ID */
213 [98] = MSM_CPU_7X25AA,
214 [99] = MSM_CPU_7X25AA,
215 [100] = MSM_CPU_7X25AA,
216
Joel Kingbf2ff512011-07-22 13:43:11 -0700217 /* 7x27AA ID */
218 [101] = MSM_CPU_7X27AA,
219 [102] = MSM_CPU_7X27AA,
220 [103] = MSM_CPU_7X27AA,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530221 [136] = MSM_CPU_7X27AA,
Joel Kingbf2ff512011-07-22 13:43:11 -0700222
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700223 /* 9x15 ID */
224 [104] = MSM_CPU_9615,
Rohit Vaswani865f2ca2011-10-03 17:40:42 -0700225 [105] = MSM_CPU_9615,
Rohit Vaswani7a83fa92012-01-11 15:05:39 -0800226 [106] = MSM_CPU_9615,
227 [107] = MSM_CPU_9615,
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700228
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700229 /* 8064 IDs */
Joel Kingbf2ff512011-07-22 13:43:11 -0700230 [109] = MSM_CPU_8064,
231
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700232 /* 8930 IDs */
233 [116] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800234 [117] = MSM_CPU_8930,
235 [118] = MSM_CPU_8930,
236 [119] = MSM_CPU_8930,
237
238 /* 8627 IDs */
239 [120] = MSM_CPU_8627,
240 [121] = MSM_CPU_8627,
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700241
Jin Hong0698b562011-11-05 13:57:25 -0700242 /* 8660A ID */
243 [122] = MSM_CPU_8960,
244
245 /* 8260A ID */
246 [123] = MSM_CPU_8960,
247
248 /* 8060A ID */
249 [124] = MSM_CPU_8960,
250
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700251 /* 8974 IDs */
252 [126] = MSM_CPU_8974,
Sathish Ambleya99d6852011-10-31 15:50:55 -0700253
Taniya Dasa04e1892011-11-16 14:49:12 +0530254 /* 8625 IDs */
255 [127] = MSM_CPU_8625,
256 [128] = MSM_CPU_8625,
257 [129] = MSM_CPU_8625,
258
Joel King8e0bf672012-05-18 15:40:40 -0700259 /* 8064 MPQ ID */
260 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700261
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530262 /* 7x25AB IDs */
263 [131] = MSM_CPU_7X25AB,
264 [132] = MSM_CPU_7X25AB,
265 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530266 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530267
Joel King8e0bf672012-05-18 15:40:40 -0700268 /* 9625 IDs */
269 [134] = MSM_CPU_9625,
270
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700271 /* 8960AB IDs */
272 [138] = MSM_CPU_8960AB,
273 [139] = MSM_CPU_8960AB,
274 [140] = MSM_CPU_8960AB,
275 [141] = MSM_CPU_8960AB,
276
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700277 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700278 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700279 [143] = MSM_CPU_8930AA,
280 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko7494f362012-10-22 18:52:06 -0700281 [160] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700282
Syed Rameez Mustafa36a63712012-08-23 15:47:50 -0700283 /* 8226 IDs */
284 [145] = MSM_CPU_8226,
285
286 /* 8092 IDs */
287 [146] = MSM_CPU_8092,
288
Jay Chokshi91b7d3e2012-09-19 18:28:12 -0700289 /* 8064AB IDs */
290 [153] = MSM_CPU_8064AB,
291
Stepan Moskovchenkob2eca962012-10-16 18:34:17 -0700292 /* 8930AB IDs */
293 [154] = MSM_CPU_8930AB,
294 [155] = MSM_CPU_8930AB,
295 [156] = MSM_CPU_8930AB,
Jay Chokshi72870802013-01-15 13:06:27 -0800296 [157] = MSM_CPU_8930AB,
297
298 /* 8064AA IDs */
299 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkob2eca962012-10-16 18:34:17 -0700300
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700301 /* Uninitialized IDs are not known to run Linux.
302 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
303 considered as unknown CPU. */
304};
305
306static enum msm_cpu cur_cpu;
307
308static struct socinfo_v1 dummy_socinfo = {
309 .format = 1,
310 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700311};
312
313uint32_t socinfo_get_id(void)
314{
315 return (socinfo) ? socinfo->v1.id : 0;
316}
317EXPORT_SYMBOL_GPL(socinfo_get_id);
318
319uint32_t socinfo_get_version(void)
320{
321 return (socinfo) ? socinfo->v1.version : 0;
322}
323
324char *socinfo_get_build_id(void)
325{
326 return (socinfo) ? socinfo->v1.build_id : NULL;
327}
328
329uint32_t socinfo_get_raw_id(void)
330{
331 return socinfo ?
332 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
333 : 0;
334}
335
336uint32_t socinfo_get_raw_version(void)
337{
338 return socinfo ?
339 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
340 : 0;
341}
342
343uint32_t socinfo_get_platform_type(void)
344{
345 return socinfo ?
346 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
347 : 0;
348}
349
350
351uint32_t socinfo_get_platform_version(void)
352{
353 return socinfo ?
354 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
355 : 0;
356}
357
358/* This information is directly encoded by the machine id */
359/* Thus no external callers rely on this information at the moment */
360static uint32_t socinfo_get_accessory_chip(void)
361{
362 return socinfo ?
363 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
364 : 0;
365}
366
367uint32_t socinfo_get_platform_subtype(void)
368{
369 return socinfo ?
370 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
371 : 0;
372}
373
Jin Honge795bd22012-08-13 23:06:26 -0700374enum pmic_model socinfo_get_pmic_model(void)
375{
376 return socinfo ?
377 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
378 : PMIC_MODEL_UNKNOWN)
379 : PMIC_MODEL_UNKNOWN;
380}
381
382uint32_t socinfo_get_pmic_die_revision(void)
383{
384 return socinfo ?
385 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
386 : 0;
387}
388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389enum msm_cpu socinfo_get_msm_cpu(void)
390{
391 return cur_cpu;
392}
393EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
394
395static ssize_t
396socinfo_show_id(struct sys_device *dev,
397 struct sysdev_attribute *attr,
398 char *buf)
399{
400 if (!socinfo) {
401 pr_err("%s: No socinfo found!\n", __func__);
402 return 0;
403 }
404
405 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
406}
407
408static ssize_t
409socinfo_show_version(struct sys_device *dev,
410 struct sysdev_attribute *attr,
411 char *buf)
412{
413 uint32_t version;
414
415 if (!socinfo) {
416 pr_err("%s: No socinfo found!\n", __func__);
417 return 0;
418 }
419
420 version = socinfo_get_version();
421 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
422 SOCINFO_VERSION_MAJOR(version),
423 SOCINFO_VERSION_MINOR(version));
424}
425
426static ssize_t
427socinfo_show_build_id(struct sys_device *dev,
428 struct sysdev_attribute *attr,
429 char *buf)
430{
431 if (!socinfo) {
432 pr_err("%s: No socinfo found!\n", __func__);
433 return 0;
434 }
435
436 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
437}
438
439static ssize_t
440socinfo_show_raw_id(struct sys_device *dev,
441 struct sysdev_attribute *attr,
442 char *buf)
443{
444 if (!socinfo) {
445 pr_err("%s: No socinfo found!\n", __func__);
446 return 0;
447 }
448 if (socinfo->v1.format < 2) {
449 pr_err("%s: Raw ID not available!\n", __func__);
450 return 0;
451 }
452
453 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
454}
455
456static ssize_t
457socinfo_show_raw_version(struct sys_device *dev,
458 struct sysdev_attribute *attr,
459 char *buf)
460{
461 if (!socinfo) {
462 pr_err("%s: No socinfo found!\n", __func__);
463 return 0;
464 }
465 if (socinfo->v1.format < 2) {
466 pr_err("%s: Raw version not available!\n", __func__);
467 return 0;
468 }
469
470 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
471}
472
473static ssize_t
474socinfo_show_platform_type(struct sys_device *dev,
475 struct sysdev_attribute *attr,
476 char *buf)
477{
478 uint32_t hw_type;
479
480 if (!socinfo) {
481 pr_err("%s: No socinfo found!\n", __func__);
482 return 0;
483 }
484 if (socinfo->v1.format < 3) {
485 pr_err("%s: platform type not available!\n", __func__);
486 return 0;
487 }
488
489 hw_type = socinfo_get_platform_type();
490 if (hw_type >= HW_PLATFORM_INVALID) {
491 pr_err("%s: Invalid hardware platform type found\n",
492 __func__);
493 hw_type = HW_PLATFORM_UNKNOWN;
494 }
495
496 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
497}
498
499static ssize_t
500socinfo_show_platform_version(struct sys_device *dev,
501 struct sysdev_attribute *attr,
502 char *buf)
503{
504
505 if (!socinfo) {
506 pr_err("%s: No socinfo found!\n", __func__);
507 return 0;
508 }
509 if (socinfo->v1.format < 4) {
510 pr_err("%s: platform version not available!\n", __func__);
511 return 0;
512 }
513
514 return snprintf(buf, PAGE_SIZE, "%u\n",
515 socinfo_get_platform_version());
516}
517
518static ssize_t
519socinfo_show_accessory_chip(struct sys_device *dev,
520 struct sysdev_attribute *attr,
521 char *buf)
522{
523 if (!socinfo) {
524 pr_err("%s: No socinfo found!\n", __func__);
525 return 0;
526 }
527 if (socinfo->v1.format < 5) {
528 pr_err("%s: accessory chip not available!\n", __func__);
529 return 0;
530 }
531
532 return snprintf(buf, PAGE_SIZE, "%u\n",
533 socinfo_get_accessory_chip());
534}
535
536static ssize_t
537socinfo_show_platform_subtype(struct sys_device *dev,
538 struct sysdev_attribute *attr,
539 char *buf)
540{
541 uint32_t hw_subtype;
542 if (!socinfo) {
543 pr_err("%s: No socinfo found!\n", __func__);
544 return 0;
545 }
546 if (socinfo->v1.format < 6) {
547 pr_err("%s: platform subtype not available!\n", __func__);
548 return 0;
549 }
550
551 hw_subtype = socinfo_get_platform_subtype();
552 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
553 pr_err("%s: Invalid hardware platform sub type found\n",
554 __func__);
555 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
556 }
557 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
558 hw_platform_subtype[hw_subtype]);
559}
560
Jin Honge795bd22012-08-13 23:06:26 -0700561static ssize_t
562socinfo_show_pmic_model(struct sys_device *dev,
563 struct sysdev_attribute *attr,
564 char *buf)
565{
566 if (!socinfo) {
567 pr_err("%s: No socinfo found!\n", __func__);
568 return 0;
569 }
570 if (socinfo->v1.format < 7) {
571 pr_err("%s: pmic_model not available!\n", __func__);
572 return 0;
573 }
574
575 return snprintf(buf, PAGE_SIZE, "%u\n",
576 socinfo_get_pmic_model());
577}
578
579static ssize_t
580socinfo_show_pmic_die_revision(struct sys_device *dev,
581 struct sysdev_attribute *attr,
582 char *buf)
583{
584 if (!socinfo) {
585 pr_err("%s: No socinfo found!\n", __func__);
586 return 0;
587 }
588 if (socinfo->v1.format < 7) {
589 pr_err("%s: pmic_die_revision not available!\n", __func__);
590 return 0;
591 }
592
593 return snprintf(buf, PAGE_SIZE, "%u\n",
594 socinfo_get_pmic_die_revision());
595}
596
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597static struct sysdev_attribute socinfo_v1_files[] = {
598 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
599 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
600 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
601};
602
603static struct sysdev_attribute socinfo_v2_files[] = {
604 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
605 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
606};
607
608static struct sysdev_attribute socinfo_v3_files[] = {
609 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
610};
611
612static struct sysdev_attribute socinfo_v4_files[] = {
613 _SYSDEV_ATTR(platform_version, 0444,
614 socinfo_show_platform_version, NULL),
615};
616
617static struct sysdev_attribute socinfo_v5_files[] = {
618 _SYSDEV_ATTR(accessory_chip, 0444,
619 socinfo_show_accessory_chip, NULL),
620};
621
622static struct sysdev_attribute socinfo_v6_files[] = {
623 _SYSDEV_ATTR(platform_subtype, 0444,
624 socinfo_show_platform_subtype, NULL),
625};
626
Jin Honge795bd22012-08-13 23:06:26 -0700627static struct sysdev_attribute socinfo_v7_files[] = {
628 _SYSDEV_ATTR(pmic_model, 0444,
629 socinfo_show_pmic_model, NULL),
630 _SYSDEV_ATTR(pmic_die_revision, 0444,
631 socinfo_show_pmic_die_revision, NULL),
632};
633
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634static struct sysdev_class soc_sysdev_class = {
635 .name = "soc",
636};
637
638static struct sys_device soc_sys_device = {
639 .id = 0,
640 .cls = &soc_sysdev_class,
641};
642
643static int __init socinfo_create_files(struct sys_device *dev,
644 struct sysdev_attribute files[],
645 int size)
646{
647 int i;
648 for (i = 0; i < size; i++) {
649 int err = sysdev_create_file(dev, &files[i]);
650 if (err) {
651 pr_err("%s: sysdev_create_file(%s)=%d\n",
652 __func__, files[i].attr.name, err);
653 return err;
654 }
655 }
656 return 0;
657}
658
659static int __init socinfo_init_sysdev(void)
660{
661 int err;
662
663 if (!socinfo) {
664 pr_err("%s: No socinfo found!\n", __func__);
665 return -ENODEV;
666 }
667
668 err = sysdev_class_register(&soc_sysdev_class);
669 if (err) {
670 pr_err("%s: sysdev_class_register fail (%d)\n",
671 __func__, err);
672 return err;
673 }
674 err = sysdev_register(&soc_sys_device);
675 if (err) {
676 pr_err("%s: sysdev_register fail (%d)\n",
677 __func__, err);
678 return err;
679 }
680 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
681 ARRAY_SIZE(socinfo_v1_files));
682 if (socinfo->v1.format < 2)
683 return err;
684 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
685 ARRAY_SIZE(socinfo_v2_files));
686
687 if (socinfo->v1.format < 3)
688 return err;
689
690 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
691 ARRAY_SIZE(socinfo_v3_files));
692
693 if (socinfo->v1.format < 4)
694 return err;
695
696 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
697 ARRAY_SIZE(socinfo_v4_files));
698
699 if (socinfo->v1.format < 5)
700 return err;
701
702 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
703 ARRAY_SIZE(socinfo_v5_files));
704
705 if (socinfo->v1.format < 6)
706 return err;
707
Jin Honge795bd22012-08-13 23:06:26 -0700708 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700709 ARRAY_SIZE(socinfo_v6_files));
710
Jin Honge795bd22012-08-13 23:06:26 -0700711 if (socinfo->v1.format < 7)
712 return err;
713
714 return socinfo_create_files(&soc_sys_device, socinfo_v7_files,
715 ARRAY_SIZE(socinfo_v7_files));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716}
717
718arch_initcall(socinfo_init_sysdev);
719
Stephen Boyd69a22e42012-02-22 09:16:07 -0800720static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721{
Syed Rameez Mustafacf645e82012-07-06 19:00:49 -0700722 if (machine_is_msm8960_cdp())
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 dummy_socinfo.id = 87;
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700724 else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp())
725 dummy_socinfo.id = 104;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700726 else if (early_machine_is_msm8974()) {
Sathish Ambleya99d6852011-10-31 15:50:55 -0700727 dummy_socinfo.id = 126;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700728 strlcpy(dummy_socinfo.build_id, "msm8974 - ",
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800729 sizeof(dummy_socinfo.build_id));
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700730 } else if (early_machine_is_msm9625()) {
Joel King8e0bf672012-05-18 15:40:40 -0700731 dummy_socinfo.id = 134;
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700732 strlcpy(dummy_socinfo.build_id, "msm9625 - ",
733 sizeof(dummy_socinfo.build_id));
Syed Rameez Mustafa36a63712012-08-23 15:47:50 -0700734 } else if (early_machine_is_msm8226()) {
735 dummy_socinfo.id = 145;
736 strlcpy(dummy_socinfo.build_id, "msm8226 - ",
737 sizeof(dummy_socinfo.build_id));
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800738 } else if (machine_is_msm8625_rumi3())
Taniya Dasa04e1892011-11-16 14:49:12 +0530739 dummy_socinfo.id = 127;
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800740 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
741 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742 return (void *) &dummy_socinfo;
743}
744
745int __init socinfo_init(void)
746{
Jin Honge795bd22012-08-13 23:06:26 -0700747 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v7));
748
749 if (!socinfo)
750 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
751 sizeof(struct socinfo_v6));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752
753 if (!socinfo)
754 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
755 sizeof(struct socinfo_v5));
756
757 if (!socinfo)
758 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
759 sizeof(struct socinfo_v4));
760
761 if (!socinfo)
762 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
763 sizeof(struct socinfo_v3));
764
765 if (!socinfo)
766 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
767 sizeof(struct socinfo_v2));
768
769 if (!socinfo)
770 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
771 sizeof(struct socinfo_v1));
772
773 if (!socinfo) {
774 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on "
775 "dummy values.\n", __func__);
776 socinfo = setup_dummy_socinfo();
777 }
778
779 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
780 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
781 "New IDs added! ID => CPU mapping might need an update.\n");
782
783 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
784 cur_cpu = cpu_of_id[socinfo->v1.id];
785
786 switch (socinfo->v1.format) {
787 case 1:
788 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
789 __func__, socinfo->v1.format, socinfo->v1.id,
790 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
791 SOCINFO_VERSION_MINOR(socinfo->v1.version));
792 break;
793 case 2:
794 pr_info("%s: v%u, id=%u, ver=%u.%u, "
795 "raw_id=%u, raw_ver=%u\n",
796 __func__, socinfo->v1.format, socinfo->v1.id,
797 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
798 SOCINFO_VERSION_MINOR(socinfo->v1.version),
799 socinfo->v2.raw_id, socinfo->v2.raw_version);
800 break;
801 case 3:
802 pr_info("%s: v%u, id=%u, ver=%u.%u, "
803 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
804 __func__, socinfo->v1.format, socinfo->v1.id,
805 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
806 SOCINFO_VERSION_MINOR(socinfo->v1.version),
807 socinfo->v2.raw_id, socinfo->v2.raw_version,
808 socinfo->v3.hw_platform);
809 break;
810 case 4:
811 pr_info("%s: v%u, id=%u, ver=%u.%u, "
812 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
813 __func__, socinfo->v1.format, socinfo->v1.id,
814 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
815 SOCINFO_VERSION_MINOR(socinfo->v1.version),
816 socinfo->v2.raw_id, socinfo->v2.raw_version,
817 socinfo->v3.hw_platform, socinfo->v4.platform_version);
818 break;
819 case 5:
820 pr_info("%s: v%u, id=%u, ver=%u.%u, "
821 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
822 " accessory_chip=%u\n", __func__, socinfo->v1.format,
823 socinfo->v1.id,
824 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
825 SOCINFO_VERSION_MINOR(socinfo->v1.version),
826 socinfo->v2.raw_id, socinfo->v2.raw_version,
827 socinfo->v3.hw_platform, socinfo->v4.platform_version,
828 socinfo->v5.accessory_chip);
829 break;
830 case 6:
831 pr_info("%s: v%u, id=%u, ver=%u.%u, "
832 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
833 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
834 socinfo->v1.format,
835 socinfo->v1.id,
836 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
837 SOCINFO_VERSION_MINOR(socinfo->v1.version),
838 socinfo->v2.raw_id, socinfo->v2.raw_version,
839 socinfo->v3.hw_platform, socinfo->v4.platform_version,
840 socinfo->v5.accessory_chip,
841 socinfo->v6.hw_platform_subtype);
842 break;
Jin Honge795bd22012-08-13 23:06:26 -0700843 case 7:
844 pr_info("%s: v%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\n",
845 __func__,
846 socinfo->v1.format,
847 socinfo->v1.id,
848 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
849 SOCINFO_VERSION_MINOR(socinfo->v1.version),
850 socinfo->v2.raw_id, socinfo->v2.raw_version,
851 socinfo->v3.hw_platform, socinfo->v4.platform_version,
852 socinfo->v5.accessory_chip,
853 socinfo->v6.hw_platform_subtype,
854 socinfo->v7.pmic_model,
855 socinfo->v7.pmic_die_revision);
856 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857 default:
858 pr_err("%s: Unknown format found\n", __func__);
859 break;
860 }
861
862 return 0;
863}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700864
865const int get_core_count(void)
866{
867 if (!(read_cpuid_mpidr() & BIT(31)))
868 return 1;
869
Jin Hongc5f5d542012-04-12 16:48:51 -0700870 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700871 return 1;
872
873 /* 1 + the PART[1:0] field of MIDR */
874 return ((read_cpuid_id() >> 4) & 3) + 1;
875}
876
877const int read_msm_cpu_type(void)
878{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700879 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
880 return socinfo_get_msm_cpu();
881
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700882 switch (read_cpuid_id()) {
883 case 0x510F02D0:
884 case 0x510F02D2:
885 case 0x510F02D4:
886 return MSM_CPU_8X60;
887
888 case 0x510F04D0:
889 case 0x510F04D1:
890 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700891 case 0x511F04D0:
892 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700893 return MSM_CPU_8960;
894
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700895 case 0x51404D11: /* We can't get here unless we are in bringup */
896 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700897
898 case 0x510F06F0:
899 return MSM_CPU_8064;
900
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -0700901 case 0x511F06F1:
902 case 0x512F06F0:
903 return MSM_CPU_8974;
904
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700905 default:
906 return MSM_CPU_UNKNOWN;
907 };
908}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700909
Jin Hong12b8b432012-07-18 10:00:31 -0700910const int cpu_is_krait(void)
911{
912 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
913}
914
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700915const int cpu_is_krait_v1(void)
916{
917 switch (read_cpuid_id()) {
918 case 0x510F04D0:
919 case 0x510F04D1:
920 case 0x510F04D2:
921 return 1;
922
923 default:
924 return 0;
925 };
926}
Jin Hong12b8b432012-07-18 10:00:31 -0700927
928const int cpu_is_krait_v2(void)
929{
930 switch (read_cpuid_id()) {
931 case 0x511F04D0:
932 case 0x511F04D1:
933 case 0x511F04D2:
934 case 0x511F04D3:
935 case 0x511F04D4:
936
937 case 0x510F06F0:
938 case 0x510F06F1:
939 case 0x510F06F2:
940 return 1;
941
942 default:
943 return 0;
944 };
945}
Joel Kingffb79662012-08-19 12:55:49 -0700946
947const int cpu_is_krait_v3(void)
948{
949 switch (read_cpuid_id()) {
950 case 0x512F04D0:
951 case 0x511F06F0:
952 case 0x511F06F1:
953 case 0x510F05D0:
954 return 1;
955
956 default:
957 return 0;
958 };
959}