blob: 817c2dca5a2b4fbf7ae0333dce40247e490f2ddc [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
117static union {
118 struct socinfo_v1 v1;
119 struct socinfo_v2 v2;
120 struct socinfo_v3 v3;
121 struct socinfo_v4 v4;
122 struct socinfo_v5 v5;
123 struct socinfo_v6 v6;
124} *socinfo;
125
126static enum msm_cpu cpu_of_id[] = {
127
128 /* 7x01 IDs */
129 [1] = MSM_CPU_7X01,
130 [16] = MSM_CPU_7X01,
131 [17] = MSM_CPU_7X01,
132 [18] = MSM_CPU_7X01,
133 [19] = MSM_CPU_7X01,
134 [23] = MSM_CPU_7X01,
135 [25] = MSM_CPU_7X01,
136 [26] = MSM_CPU_7X01,
137 [32] = MSM_CPU_7X01,
138 [33] = MSM_CPU_7X01,
139 [34] = MSM_CPU_7X01,
140 [35] = MSM_CPU_7X01,
141
142 /* 7x25 IDs */
143 [20] = MSM_CPU_7X25,
144 [21] = MSM_CPU_7X25, /* 7225 */
145 [24] = MSM_CPU_7X25, /* 7525 */
146 [27] = MSM_CPU_7X25, /* 7625 */
147 [39] = MSM_CPU_7X25,
148 [40] = MSM_CPU_7X25,
149 [41] = MSM_CPU_7X25,
150 [42] = MSM_CPU_7X25,
151 [62] = MSM_CPU_7X25, /* 7625-1 */
152 [63] = MSM_CPU_7X25, /* 7225-1 */
153 [66] = MSM_CPU_7X25, /* 7225-2 */
154
155
156 /* 7x27 IDs */
157 [43] = MSM_CPU_7X27,
158 [44] = MSM_CPU_7X27,
159 [61] = MSM_CPU_7X27,
160 [67] = MSM_CPU_7X27, /* 7227-1 */
161 [68] = MSM_CPU_7X27, /* 7627-1 */
162 [69] = MSM_CPU_7X27, /* 7627-2 */
163
164
165 /* 8x50 IDs */
166 [30] = MSM_CPU_8X50,
167 [36] = MSM_CPU_8X50,
168 [37] = MSM_CPU_8X50,
169 [38] = MSM_CPU_8X50,
170
171 /* 7x30 IDs */
172 [59] = MSM_CPU_7X30,
173 [60] = MSM_CPU_7X30,
174
175 /* 8x55 IDs */
176 [74] = MSM_CPU_8X55,
177 [75] = MSM_CPU_8X55,
178 [85] = MSM_CPU_8X55,
179
180 /* 8x60 IDs */
181 [70] = MSM_CPU_8X60,
182 [71] = MSM_CPU_8X60,
183 [86] = MSM_CPU_8X60,
184
185 /* 8960 IDs */
186 [87] = MSM_CPU_8960,
187
188 /* 7x25A IDs */
189 [88] = MSM_CPU_7X25A,
190 [89] = MSM_CPU_7X25A,
191 [96] = MSM_CPU_7X25A,
192
193 /* 7x27A IDs */
194 [90] = MSM_CPU_7X27A,
195 [91] = MSM_CPU_7X27A,
196 [92] = MSM_CPU_7X27A,
197 [97] = MSM_CPU_7X27A,
198
199 /* FSM9xxx ID */
200 [94] = FSM_CPU_9XXX,
201 [95] = FSM_CPU_9XXX,
202
203 /* 7x25AA ID */
204 [98] = MSM_CPU_7X25AA,
205 [99] = MSM_CPU_7X25AA,
206 [100] = MSM_CPU_7X25AA,
207
Joel Kingbf2ff512011-07-22 13:43:11 -0700208 /* 7x27AA ID */
209 [101] = MSM_CPU_7X27AA,
210 [102] = MSM_CPU_7X27AA,
211 [103] = MSM_CPU_7X27AA,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530212 [136] = MSM_CPU_7X27AA,
Joel Kingbf2ff512011-07-22 13:43:11 -0700213
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700214 /* 9x15 ID */
215 [104] = MSM_CPU_9615,
Rohit Vaswani865f2ca2011-10-03 17:40:42 -0700216 [105] = MSM_CPU_9615,
Rohit Vaswani7a83fa92012-01-11 15:05:39 -0800217 [106] = MSM_CPU_9615,
218 [107] = MSM_CPU_9615,
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700219
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700220 /* 8064 IDs */
Joel Kingbf2ff512011-07-22 13:43:11 -0700221 [109] = MSM_CPU_8064,
222
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700223 /* 8930 IDs */
224 [116] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800225 [117] = MSM_CPU_8930,
226 [118] = MSM_CPU_8930,
227 [119] = MSM_CPU_8930,
228
229 /* 8627 IDs */
230 [120] = MSM_CPU_8627,
231 [121] = MSM_CPU_8627,
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700232
Jin Hong0698b562011-11-05 13:57:25 -0700233 /* 8660A ID */
234 [122] = MSM_CPU_8960,
235
236 /* 8260A ID */
237 [123] = MSM_CPU_8960,
238
239 /* 8060A ID */
240 [124] = MSM_CPU_8960,
241
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700242 /* 8974 IDs */
243 [126] = MSM_CPU_8974,
Sathish Ambleya99d6852011-10-31 15:50:55 -0700244
Taniya Dasa04e1892011-11-16 14:49:12 +0530245 /* 8625 IDs */
246 [127] = MSM_CPU_8625,
247 [128] = MSM_CPU_8625,
248 [129] = MSM_CPU_8625,
249
Joel King8e0bf672012-05-18 15:40:40 -0700250 /* 8064 MPQ ID */
251 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700252
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530253 /* 7x25AB IDs */
254 [131] = MSM_CPU_7X25AB,
255 [132] = MSM_CPU_7X25AB,
256 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530257 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530258
Joel King8e0bf672012-05-18 15:40:40 -0700259 /* 9625 IDs */
260 [134] = MSM_CPU_9625,
261
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700262 /* 8960AB IDs */
263 [138] = MSM_CPU_8960AB,
264 [139] = MSM_CPU_8960AB,
265 [140] = MSM_CPU_8960AB,
266 [141] = MSM_CPU_8960AB,
267
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700268 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700269 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700270 [143] = MSM_CPU_8930AA,
271 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700272
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 /* Uninitialized IDs are not known to run Linux.
274 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
275 considered as unknown CPU. */
276};
277
278static enum msm_cpu cur_cpu;
279
280static struct socinfo_v1 dummy_socinfo = {
281 .format = 1,
282 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283};
284
285uint32_t socinfo_get_id(void)
286{
287 return (socinfo) ? socinfo->v1.id : 0;
288}
289EXPORT_SYMBOL_GPL(socinfo_get_id);
290
291uint32_t socinfo_get_version(void)
292{
293 return (socinfo) ? socinfo->v1.version : 0;
294}
295
296char *socinfo_get_build_id(void)
297{
298 return (socinfo) ? socinfo->v1.build_id : NULL;
299}
300
301uint32_t socinfo_get_raw_id(void)
302{
303 return socinfo ?
304 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
305 : 0;
306}
307
308uint32_t socinfo_get_raw_version(void)
309{
310 return socinfo ?
311 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
312 : 0;
313}
314
315uint32_t socinfo_get_platform_type(void)
316{
317 return socinfo ?
318 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
319 : 0;
320}
321
322
323uint32_t socinfo_get_platform_version(void)
324{
325 return socinfo ?
326 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
327 : 0;
328}
329
330/* This information is directly encoded by the machine id */
331/* Thus no external callers rely on this information at the moment */
332static uint32_t socinfo_get_accessory_chip(void)
333{
334 return socinfo ?
335 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
336 : 0;
337}
338
339uint32_t socinfo_get_platform_subtype(void)
340{
341 return socinfo ?
342 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
343 : 0;
344}
345
346enum msm_cpu socinfo_get_msm_cpu(void)
347{
348 return cur_cpu;
349}
350EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
351
352static ssize_t
353socinfo_show_id(struct sys_device *dev,
354 struct sysdev_attribute *attr,
355 char *buf)
356{
357 if (!socinfo) {
358 pr_err("%s: No socinfo found!\n", __func__);
359 return 0;
360 }
361
362 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
363}
364
365static ssize_t
366socinfo_show_version(struct sys_device *dev,
367 struct sysdev_attribute *attr,
368 char *buf)
369{
370 uint32_t version;
371
372 if (!socinfo) {
373 pr_err("%s: No socinfo found!\n", __func__);
374 return 0;
375 }
376
377 version = socinfo_get_version();
378 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
379 SOCINFO_VERSION_MAJOR(version),
380 SOCINFO_VERSION_MINOR(version));
381}
382
383static ssize_t
384socinfo_show_build_id(struct sys_device *dev,
385 struct sysdev_attribute *attr,
386 char *buf)
387{
388 if (!socinfo) {
389 pr_err("%s: No socinfo found!\n", __func__);
390 return 0;
391 }
392
393 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
394}
395
396static ssize_t
397socinfo_show_raw_id(struct sys_device *dev,
398 struct sysdev_attribute *attr,
399 char *buf)
400{
401 if (!socinfo) {
402 pr_err("%s: No socinfo found!\n", __func__);
403 return 0;
404 }
405 if (socinfo->v1.format < 2) {
406 pr_err("%s: Raw ID not available!\n", __func__);
407 return 0;
408 }
409
410 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
411}
412
413static ssize_t
414socinfo_show_raw_version(struct sys_device *dev,
415 struct sysdev_attribute *attr,
416 char *buf)
417{
418 if (!socinfo) {
419 pr_err("%s: No socinfo found!\n", __func__);
420 return 0;
421 }
422 if (socinfo->v1.format < 2) {
423 pr_err("%s: Raw version not available!\n", __func__);
424 return 0;
425 }
426
427 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
428}
429
430static ssize_t
431socinfo_show_platform_type(struct sys_device *dev,
432 struct sysdev_attribute *attr,
433 char *buf)
434{
435 uint32_t hw_type;
436
437 if (!socinfo) {
438 pr_err("%s: No socinfo found!\n", __func__);
439 return 0;
440 }
441 if (socinfo->v1.format < 3) {
442 pr_err("%s: platform type not available!\n", __func__);
443 return 0;
444 }
445
446 hw_type = socinfo_get_platform_type();
447 if (hw_type >= HW_PLATFORM_INVALID) {
448 pr_err("%s: Invalid hardware platform type found\n",
449 __func__);
450 hw_type = HW_PLATFORM_UNKNOWN;
451 }
452
453 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
454}
455
456static ssize_t
457socinfo_show_platform_version(struct sys_device *dev,
458 struct sysdev_attribute *attr,
459 char *buf)
460{
461
462 if (!socinfo) {
463 pr_err("%s: No socinfo found!\n", __func__);
464 return 0;
465 }
466 if (socinfo->v1.format < 4) {
467 pr_err("%s: platform version not available!\n", __func__);
468 return 0;
469 }
470
471 return snprintf(buf, PAGE_SIZE, "%u\n",
472 socinfo_get_platform_version());
473}
474
475static ssize_t
476socinfo_show_accessory_chip(struct sys_device *dev,
477 struct sysdev_attribute *attr,
478 char *buf)
479{
480 if (!socinfo) {
481 pr_err("%s: No socinfo found!\n", __func__);
482 return 0;
483 }
484 if (socinfo->v1.format < 5) {
485 pr_err("%s: accessory chip not available!\n", __func__);
486 return 0;
487 }
488
489 return snprintf(buf, PAGE_SIZE, "%u\n",
490 socinfo_get_accessory_chip());
491}
492
493static ssize_t
494socinfo_show_platform_subtype(struct sys_device *dev,
495 struct sysdev_attribute *attr,
496 char *buf)
497{
498 uint32_t hw_subtype;
499 if (!socinfo) {
500 pr_err("%s: No socinfo found!\n", __func__);
501 return 0;
502 }
503 if (socinfo->v1.format < 6) {
504 pr_err("%s: platform subtype not available!\n", __func__);
505 return 0;
506 }
507
508 hw_subtype = socinfo_get_platform_subtype();
509 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
510 pr_err("%s: Invalid hardware platform sub type found\n",
511 __func__);
512 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
513 }
514 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
515 hw_platform_subtype[hw_subtype]);
516}
517
518static struct sysdev_attribute socinfo_v1_files[] = {
519 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
520 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
521 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
522};
523
524static struct sysdev_attribute socinfo_v2_files[] = {
525 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
526 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
527};
528
529static struct sysdev_attribute socinfo_v3_files[] = {
530 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
531};
532
533static struct sysdev_attribute socinfo_v4_files[] = {
534 _SYSDEV_ATTR(platform_version, 0444,
535 socinfo_show_platform_version, NULL),
536};
537
538static struct sysdev_attribute socinfo_v5_files[] = {
539 _SYSDEV_ATTR(accessory_chip, 0444,
540 socinfo_show_accessory_chip, NULL),
541};
542
543static struct sysdev_attribute socinfo_v6_files[] = {
544 _SYSDEV_ATTR(platform_subtype, 0444,
545 socinfo_show_platform_subtype, NULL),
546};
547
548static struct sysdev_class soc_sysdev_class = {
549 .name = "soc",
550};
551
552static struct sys_device soc_sys_device = {
553 .id = 0,
554 .cls = &soc_sysdev_class,
555};
556
557static int __init socinfo_create_files(struct sys_device *dev,
558 struct sysdev_attribute files[],
559 int size)
560{
561 int i;
562 for (i = 0; i < size; i++) {
563 int err = sysdev_create_file(dev, &files[i]);
564 if (err) {
565 pr_err("%s: sysdev_create_file(%s)=%d\n",
566 __func__, files[i].attr.name, err);
567 return err;
568 }
569 }
570 return 0;
571}
572
573static int __init socinfo_init_sysdev(void)
574{
575 int err;
576
577 if (!socinfo) {
578 pr_err("%s: No socinfo found!\n", __func__);
579 return -ENODEV;
580 }
581
582 err = sysdev_class_register(&soc_sysdev_class);
583 if (err) {
584 pr_err("%s: sysdev_class_register fail (%d)\n",
585 __func__, err);
586 return err;
587 }
588 err = sysdev_register(&soc_sys_device);
589 if (err) {
590 pr_err("%s: sysdev_register fail (%d)\n",
591 __func__, err);
592 return err;
593 }
594 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
595 ARRAY_SIZE(socinfo_v1_files));
596 if (socinfo->v1.format < 2)
597 return err;
598 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
599 ARRAY_SIZE(socinfo_v2_files));
600
601 if (socinfo->v1.format < 3)
602 return err;
603
604 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
605 ARRAY_SIZE(socinfo_v3_files));
606
607 if (socinfo->v1.format < 4)
608 return err;
609
610 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
611 ARRAY_SIZE(socinfo_v4_files));
612
613 if (socinfo->v1.format < 5)
614 return err;
615
616 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
617 ARRAY_SIZE(socinfo_v5_files));
618
619 if (socinfo->v1.format < 6)
620 return err;
621
622 return socinfo_create_files(&soc_sys_device, socinfo_v6_files,
623 ARRAY_SIZE(socinfo_v6_files));
624
625}
626
627arch_initcall(socinfo_init_sysdev);
628
Stephen Boyd69a22e42012-02-22 09:16:07 -0800629static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700630{
631 if (machine_is_msm8960_rumi3() || machine_is_msm8960_sim() ||
632 machine_is_msm8960_cdp())
633 dummy_socinfo.id = 87;
Joel Kingdad535a2011-09-09 10:59:15 -0700634 else if (machine_is_apq8064_rumi3() || machine_is_apq8064_sim())
Joel Kingbf2ff512011-07-22 13:43:11 -0700635 dummy_socinfo.id = 109;
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700636 else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp())
637 dummy_socinfo.id = 104;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700638 else if (early_machine_is_msm8974()) {
Sathish Ambleya99d6852011-10-31 15:50:55 -0700639 dummy_socinfo.id = 126;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700640 strlcpy(dummy_socinfo.build_id, "msm8974 - ",
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800641 sizeof(dummy_socinfo.build_id));
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700642 } else if (early_machine_is_msm9625()) {
Joel King8e0bf672012-05-18 15:40:40 -0700643 dummy_socinfo.id = 134;
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700644 strlcpy(dummy_socinfo.build_id, "msm9625 - ",
645 sizeof(dummy_socinfo.build_id));
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800646 } else if (machine_is_msm8625_rumi3())
Taniya Dasa04e1892011-11-16 14:49:12 +0530647 dummy_socinfo.id = 127;
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800648 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
649 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 return (void *) &dummy_socinfo;
651}
652
653int __init socinfo_init(void)
654{
655 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v6));
656
657 if (!socinfo)
658 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
659 sizeof(struct socinfo_v5));
660
661 if (!socinfo)
662 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
663 sizeof(struct socinfo_v4));
664
665 if (!socinfo)
666 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
667 sizeof(struct socinfo_v3));
668
669 if (!socinfo)
670 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
671 sizeof(struct socinfo_v2));
672
673 if (!socinfo)
674 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
675 sizeof(struct socinfo_v1));
676
677 if (!socinfo) {
678 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on "
679 "dummy values.\n", __func__);
680 socinfo = setup_dummy_socinfo();
681 }
682
683 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
684 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
685 "New IDs added! ID => CPU mapping might need an update.\n");
686
687 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
688 cur_cpu = cpu_of_id[socinfo->v1.id];
689
690 switch (socinfo->v1.format) {
691 case 1:
692 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
693 __func__, socinfo->v1.format, socinfo->v1.id,
694 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
695 SOCINFO_VERSION_MINOR(socinfo->v1.version));
696 break;
697 case 2:
698 pr_info("%s: v%u, id=%u, ver=%u.%u, "
699 "raw_id=%u, raw_ver=%u\n",
700 __func__, socinfo->v1.format, socinfo->v1.id,
701 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
702 SOCINFO_VERSION_MINOR(socinfo->v1.version),
703 socinfo->v2.raw_id, socinfo->v2.raw_version);
704 break;
705 case 3:
706 pr_info("%s: v%u, id=%u, ver=%u.%u, "
707 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
708 __func__, socinfo->v1.format, socinfo->v1.id,
709 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
710 SOCINFO_VERSION_MINOR(socinfo->v1.version),
711 socinfo->v2.raw_id, socinfo->v2.raw_version,
712 socinfo->v3.hw_platform);
713 break;
714 case 4:
715 pr_info("%s: v%u, id=%u, ver=%u.%u, "
716 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
717 __func__, socinfo->v1.format, socinfo->v1.id,
718 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
719 SOCINFO_VERSION_MINOR(socinfo->v1.version),
720 socinfo->v2.raw_id, socinfo->v2.raw_version,
721 socinfo->v3.hw_platform, socinfo->v4.platform_version);
722 break;
723 case 5:
724 pr_info("%s: v%u, id=%u, ver=%u.%u, "
725 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
726 " accessory_chip=%u\n", __func__, socinfo->v1.format,
727 socinfo->v1.id,
728 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
729 SOCINFO_VERSION_MINOR(socinfo->v1.version),
730 socinfo->v2.raw_id, socinfo->v2.raw_version,
731 socinfo->v3.hw_platform, socinfo->v4.platform_version,
732 socinfo->v5.accessory_chip);
733 break;
734 case 6:
735 pr_info("%s: v%u, id=%u, ver=%u.%u, "
736 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
737 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
738 socinfo->v1.format,
739 socinfo->v1.id,
740 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
741 SOCINFO_VERSION_MINOR(socinfo->v1.version),
742 socinfo->v2.raw_id, socinfo->v2.raw_version,
743 socinfo->v3.hw_platform, socinfo->v4.platform_version,
744 socinfo->v5.accessory_chip,
745 socinfo->v6.hw_platform_subtype);
746 break;
747 default:
748 pr_err("%s: Unknown format found\n", __func__);
749 break;
750 }
751
752 return 0;
753}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700754
755const int get_core_count(void)
756{
757 if (!(read_cpuid_mpidr() & BIT(31)))
758 return 1;
759
760 if (read_cpuid_mpidr() & BIT(30) &&
761 !machine_is_msm8960_sim() &&
762 !machine_is_apq8064_sim())
763 return 1;
764
765 /* 1 + the PART[1:0] field of MIDR */
766 return ((read_cpuid_id() >> 4) & 3) + 1;
767}
768
769const int read_msm_cpu_type(void)
770{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700771 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3())
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700772 return MSM_CPU_8960;
773
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700774 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
775 return socinfo_get_msm_cpu();
776
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700777 switch (read_cpuid_id()) {
778 case 0x510F02D0:
779 case 0x510F02D2:
780 case 0x510F02D4:
781 return MSM_CPU_8X60;
782
783 case 0x510F04D0:
784 case 0x510F04D1:
785 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700786 case 0x511F04D0:
787 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700788 return MSM_CPU_8960;
789
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700790 case 0x51404D11: /* We can't get here unless we are in bringup */
791 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700792
793 case 0x510F06F0:
794 return MSM_CPU_8064;
795
796 default:
797 return MSM_CPU_UNKNOWN;
798 };
799}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700800
Jin Hong12b8b432012-07-18 10:00:31 -0700801const int cpu_is_krait(void)
802{
803 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
804}
805
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700806const int cpu_is_krait_v1(void)
807{
808 switch (read_cpuid_id()) {
809 case 0x510F04D0:
810 case 0x510F04D1:
811 case 0x510F04D2:
812 return 1;
813
814 default:
815 return 0;
816 };
817}
Jin Hong12b8b432012-07-18 10:00:31 -0700818
819const int cpu_is_krait_v2(void)
820{
821 switch (read_cpuid_id()) {
822 case 0x511F04D0:
823 case 0x511F04D1:
824 case 0x511F04D2:
825 case 0x511F04D3:
826 case 0x511F04D4:
827
828 case 0x510F06F0:
829 case 0x510F06F1:
830 case 0x510F06F2:
831 return 1;
832
833 default:
834 return 0;
835 };
836}