blob: cef87274cdfceed72f4060fac8ff759922d4b2df [file] [log] [blame]
Taniya Dasc4e26c22013-03-16 14:53:06 +05301/* Copyright (c) 2009-2013, The Linux Foundation. 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,
Taniya Dasc4e26c22013-03-16 14:53:06 +053038 HW_PLATFORM_QRD = 11,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039 HW_PLATFORM_INVALID
40};
41
42const char *hw_platform[] = {
43 [HW_PLATFORM_UNKNOWN] = "Unknown",
44 [HW_PLATFORM_SURF] = "Surf",
45 [HW_PLATFORM_FFA] = "FFA",
46 [HW_PLATFORM_FLUID] = "Fluid",
47 [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040048 [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF",
Jin Hong49753322011-12-15 16:55:37 -080049 [HW_PLATFORM_MTP] = "MTP",
50 [HW_PLATFORM_LIQUID] = "Liquid",
Taniya Dasad1fd862013-05-06 17:56:44 +053051 [HW_PLATFORM_DRAGON] = "Dragon",
52 [HW_PLATFORM_QRD] = "QRD",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053};
54
55enum {
56 ACCESSORY_CHIP_UNKNOWN = 0,
57 ACCESSORY_CHIP_CHARM = 58,
58};
59
60enum {
61 PLATFORM_SUBTYPE_UNKNOWN = 0x0,
62 PLATFORM_SUBTYPE_CHARM = 0x1,
63 PLATFORM_SUBTYPE_STRANGE = 0x2,
64 PLATFORM_SUBTYPE_STRANGE_2A = 0x3,
65 PLATFORM_SUBTYPE_INVALID,
66};
67
68const char *hw_platform_subtype[] = {
69 [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown",
70 [PLATFORM_SUBTYPE_CHARM] = "charm",
71 [PLATFORM_SUBTYPE_STRANGE] = "strange",
72 [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a,"
73};
74
75/* Used to parse shared memory. Must match the modem. */
76struct socinfo_v1 {
77 uint32_t format;
78 uint32_t id;
79 uint32_t version;
80 char build_id[BUILD_ID_LENGTH];
81};
82
83struct socinfo_v2 {
84 struct socinfo_v1 v1;
85
86 /* only valid when format==2 */
87 uint32_t raw_id;
88 uint32_t raw_version;
89};
90
91struct socinfo_v3 {
92 struct socinfo_v2 v2;
93
94 /* only valid when format==3 */
95 uint32_t hw_platform;
96};
97
98struct socinfo_v4 {
99 struct socinfo_v3 v3;
100
101 /* only valid when format==4 */
102 uint32_t platform_version;
103};
104
105struct socinfo_v5 {
106 struct socinfo_v4 v4;
107
108 /* only valid when format==5 */
109 uint32_t accessory_chip;
110};
111
112struct socinfo_v6 {
113 struct socinfo_v5 v5;
114
115 /* only valid when format==6 */
116 uint32_t hw_platform_subtype;
117};
118
Jin Honge795bd22012-08-13 23:06:26 -0700119struct socinfo_v7 {
120 struct socinfo_v6 v6;
121
122 /* only valid when format==7 */
123 uint32_t pmic_model;
124 uint32_t pmic_die_revision;
125};
126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127static union {
128 struct socinfo_v1 v1;
129 struct socinfo_v2 v2;
130 struct socinfo_v3 v3;
131 struct socinfo_v4 v4;
132 struct socinfo_v5 v5;
133 struct socinfo_v6 v6;
Jin Honge795bd22012-08-13 23:06:26 -0700134 struct socinfo_v7 v7;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135} *socinfo;
136
137static enum msm_cpu cpu_of_id[] = {
138
139 /* 7x01 IDs */
140 [1] = MSM_CPU_7X01,
141 [16] = MSM_CPU_7X01,
142 [17] = MSM_CPU_7X01,
143 [18] = MSM_CPU_7X01,
144 [19] = MSM_CPU_7X01,
145 [23] = MSM_CPU_7X01,
146 [25] = MSM_CPU_7X01,
147 [26] = MSM_CPU_7X01,
148 [32] = MSM_CPU_7X01,
149 [33] = MSM_CPU_7X01,
150 [34] = MSM_CPU_7X01,
151 [35] = MSM_CPU_7X01,
152
153 /* 7x25 IDs */
154 [20] = MSM_CPU_7X25,
155 [21] = MSM_CPU_7X25, /* 7225 */
156 [24] = MSM_CPU_7X25, /* 7525 */
157 [27] = MSM_CPU_7X25, /* 7625 */
158 [39] = MSM_CPU_7X25,
159 [40] = MSM_CPU_7X25,
160 [41] = MSM_CPU_7X25,
161 [42] = MSM_CPU_7X25,
162 [62] = MSM_CPU_7X25, /* 7625-1 */
163 [63] = MSM_CPU_7X25, /* 7225-1 */
164 [66] = MSM_CPU_7X25, /* 7225-2 */
165
166
167 /* 7x27 IDs */
168 [43] = MSM_CPU_7X27,
169 [44] = MSM_CPU_7X27,
170 [61] = MSM_CPU_7X27,
171 [67] = MSM_CPU_7X27, /* 7227-1 */
172 [68] = MSM_CPU_7X27, /* 7627-1 */
173 [69] = MSM_CPU_7X27, /* 7627-2 */
174
175
176 /* 8x50 IDs */
177 [30] = MSM_CPU_8X50,
178 [36] = MSM_CPU_8X50,
179 [37] = MSM_CPU_8X50,
180 [38] = MSM_CPU_8X50,
181
182 /* 7x30 IDs */
183 [59] = MSM_CPU_7X30,
184 [60] = MSM_CPU_7X30,
185
186 /* 8x55 IDs */
187 [74] = MSM_CPU_8X55,
188 [75] = MSM_CPU_8X55,
189 [85] = MSM_CPU_8X55,
190
191 /* 8x60 IDs */
192 [70] = MSM_CPU_8X60,
193 [71] = MSM_CPU_8X60,
194 [86] = MSM_CPU_8X60,
195
196 /* 8960 IDs */
197 [87] = MSM_CPU_8960,
198
199 /* 7x25A IDs */
200 [88] = MSM_CPU_7X25A,
201 [89] = MSM_CPU_7X25A,
202 [96] = MSM_CPU_7X25A,
203
204 /* 7x27A IDs */
205 [90] = MSM_CPU_7X27A,
206 [91] = MSM_CPU_7X27A,
207 [92] = MSM_CPU_7X27A,
208 [97] = MSM_CPU_7X27A,
209
210 /* FSM9xxx ID */
211 [94] = FSM_CPU_9XXX,
212 [95] = FSM_CPU_9XXX,
213
214 /* 7x25AA ID */
215 [98] = MSM_CPU_7X25AA,
216 [99] = MSM_CPU_7X25AA,
217 [100] = MSM_CPU_7X25AA,
218
Joel Kingbf2ff512011-07-22 13:43:11 -0700219 /* 7x27AA ID */
220 [101] = MSM_CPU_7X27AA,
221 [102] = MSM_CPU_7X27AA,
222 [103] = MSM_CPU_7X27AA,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530223 [136] = MSM_CPU_7X27AA,
Joel Kingbf2ff512011-07-22 13:43:11 -0700224
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700225 /* 9x15 ID */
226 [104] = MSM_CPU_9615,
Rohit Vaswani865f2ca2011-10-03 17:40:42 -0700227 [105] = MSM_CPU_9615,
Rohit Vaswani7a83fa92012-01-11 15:05:39 -0800228 [106] = MSM_CPU_9615,
229 [107] = MSM_CPU_9615,
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700230
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700231 /* 8064 IDs */
Joel Kingbf2ff512011-07-22 13:43:11 -0700232 [109] = MSM_CPU_8064,
233
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700234 /* 8930 IDs */
235 [116] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800236 [117] = MSM_CPU_8930,
237 [118] = MSM_CPU_8930,
238 [119] = MSM_CPU_8930,
David Ng7ea5a252013-02-12 18:49:25 -0800239 [179] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800240
241 /* 8627 IDs */
242 [120] = MSM_CPU_8627,
243 [121] = MSM_CPU_8627,
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700244
Jin Hong0698b562011-11-05 13:57:25 -0700245 /* 8660A ID */
246 [122] = MSM_CPU_8960,
247
248 /* 8260A ID */
249 [123] = MSM_CPU_8960,
250
251 /* 8060A ID */
252 [124] = MSM_CPU_8960,
253
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700254 /* 8974 IDs */
255 [126] = MSM_CPU_8974,
Sathish Ambleya99d6852011-10-31 15:50:55 -0700256
Taniya Dasa04e1892011-11-16 14:49:12 +0530257 /* 8625 IDs */
258 [127] = MSM_CPU_8625,
259 [128] = MSM_CPU_8625,
260 [129] = MSM_CPU_8625,
261
Joel King8e0bf672012-05-18 15:40:40 -0700262 /* 8064 MPQ ID */
263 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700264
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530265 /* 7x25AB IDs */
266 [131] = MSM_CPU_7X25AB,
267 [132] = MSM_CPU_7X25AB,
268 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530269 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530270
Joel King8e0bf672012-05-18 15:40:40 -0700271 /* 9625 IDs */
272 [134] = MSM_CPU_9625,
273
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700274 /* 8960AB IDs */
275 [138] = MSM_CPU_8960AB,
276 [139] = MSM_CPU_8960AB,
277 [140] = MSM_CPU_8960AB,
278 [141] = MSM_CPU_8960AB,
279
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700280 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700281 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700282 [143] = MSM_CPU_8930AA,
283 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko7494f362012-10-22 18:52:06 -0700284 [160] = MSM_CPU_8930AA,
David Ng7ea5a252013-02-12 18:49:25 -0800285 [180] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700286
Syed Rameez Mustafa36a63712012-08-23 15:47:50 -0700287 /* 8226 IDs */
288 [145] = MSM_CPU_8226,
289
290 /* 8092 IDs */
291 [146] = MSM_CPU_8092,
292
Jay Chokshi91b7d3e2012-09-19 18:28:12 -0700293 /* 8064AB IDs */
294 [153] = MSM_CPU_8064AB,
295
Stepan Moskovchenkob2eca962012-10-16 18:34:17 -0700296 /* 8930AB IDs */
297 [154] = MSM_CPU_8930AB,
298 [155] = MSM_CPU_8930AB,
299 [156] = MSM_CPU_8930AB,
Jay Chokshi72870802013-01-15 13:06:27 -0800300 [157] = MSM_CPU_8930AB,
David Ng7ea5a252013-02-12 18:49:25 -0800301 [181] = MSM_CPU_8930AB,
Jay Chokshi72870802013-01-15 13:06:27 -0800302
303 /* 8064AA IDs */
304 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkob2eca962012-10-16 18:34:17 -0700305
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306 /* Uninitialized IDs are not known to run Linux.
307 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
308 considered as unknown CPU. */
309};
310
311static enum msm_cpu cur_cpu;
312
313static struct socinfo_v1 dummy_socinfo = {
314 .format = 1,
315 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316};
317
318uint32_t socinfo_get_id(void)
319{
320 return (socinfo) ? socinfo->v1.id : 0;
321}
322EXPORT_SYMBOL_GPL(socinfo_get_id);
323
324uint32_t socinfo_get_version(void)
325{
326 return (socinfo) ? socinfo->v1.version : 0;
327}
328
329char *socinfo_get_build_id(void)
330{
331 return (socinfo) ? socinfo->v1.build_id : NULL;
332}
333
334uint32_t socinfo_get_raw_id(void)
335{
336 return socinfo ?
337 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
338 : 0;
339}
340
341uint32_t socinfo_get_raw_version(void)
342{
343 return socinfo ?
344 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
345 : 0;
346}
347
348uint32_t socinfo_get_platform_type(void)
349{
350 return socinfo ?
351 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
352 : 0;
353}
354
355
356uint32_t socinfo_get_platform_version(void)
357{
358 return socinfo ?
359 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
360 : 0;
361}
362
363/* This information is directly encoded by the machine id */
364/* Thus no external callers rely on this information at the moment */
365static uint32_t socinfo_get_accessory_chip(void)
366{
367 return socinfo ?
368 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
369 : 0;
370}
371
372uint32_t socinfo_get_platform_subtype(void)
373{
374 return socinfo ?
375 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
376 : 0;
377}
378
Jin Honge795bd22012-08-13 23:06:26 -0700379enum pmic_model socinfo_get_pmic_model(void)
380{
381 return socinfo ?
382 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
383 : PMIC_MODEL_UNKNOWN)
384 : PMIC_MODEL_UNKNOWN;
385}
386
387uint32_t socinfo_get_pmic_die_revision(void)
388{
389 return socinfo ?
390 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
391 : 0;
392}
393
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394enum msm_cpu socinfo_get_msm_cpu(void)
395{
396 return cur_cpu;
397}
398EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
399
400static ssize_t
401socinfo_show_id(struct sys_device *dev,
402 struct sysdev_attribute *attr,
403 char *buf)
404{
405 if (!socinfo) {
406 pr_err("%s: No socinfo found!\n", __func__);
407 return 0;
408 }
409
410 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
411}
412
413static ssize_t
414socinfo_show_version(struct sys_device *dev,
415 struct sysdev_attribute *attr,
416 char *buf)
417{
418 uint32_t version;
419
420 if (!socinfo) {
421 pr_err("%s: No socinfo found!\n", __func__);
422 return 0;
423 }
424
425 version = socinfo_get_version();
426 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
427 SOCINFO_VERSION_MAJOR(version),
428 SOCINFO_VERSION_MINOR(version));
429}
430
431static ssize_t
432socinfo_show_build_id(struct sys_device *dev,
433 struct sysdev_attribute *attr,
434 char *buf)
435{
436 if (!socinfo) {
437 pr_err("%s: No socinfo found!\n", __func__);
438 return 0;
439 }
440
441 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
442}
443
444static ssize_t
445socinfo_show_raw_id(struct sys_device *dev,
446 struct sysdev_attribute *attr,
447 char *buf)
448{
449 if (!socinfo) {
450 pr_err("%s: No socinfo found!\n", __func__);
451 return 0;
452 }
453 if (socinfo->v1.format < 2) {
454 pr_err("%s: Raw ID not available!\n", __func__);
455 return 0;
456 }
457
458 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
459}
460
461static ssize_t
462socinfo_show_raw_version(struct sys_device *dev,
463 struct sysdev_attribute *attr,
464 char *buf)
465{
466 if (!socinfo) {
467 pr_err("%s: No socinfo found!\n", __func__);
468 return 0;
469 }
470 if (socinfo->v1.format < 2) {
471 pr_err("%s: Raw version not available!\n", __func__);
472 return 0;
473 }
474
475 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
476}
477
478static ssize_t
479socinfo_show_platform_type(struct sys_device *dev,
480 struct sysdev_attribute *attr,
481 char *buf)
482{
483 uint32_t hw_type;
484
485 if (!socinfo) {
486 pr_err("%s: No socinfo found!\n", __func__);
487 return 0;
488 }
489 if (socinfo->v1.format < 3) {
490 pr_err("%s: platform type not available!\n", __func__);
491 return 0;
492 }
493
494 hw_type = socinfo_get_platform_type();
495 if (hw_type >= HW_PLATFORM_INVALID) {
496 pr_err("%s: Invalid hardware platform type found\n",
497 __func__);
498 hw_type = HW_PLATFORM_UNKNOWN;
499 }
500
501 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
502}
503
504static ssize_t
505socinfo_show_platform_version(struct sys_device *dev,
506 struct sysdev_attribute *attr,
507 char *buf)
508{
509
510 if (!socinfo) {
511 pr_err("%s: No socinfo found!\n", __func__);
512 return 0;
513 }
514 if (socinfo->v1.format < 4) {
515 pr_err("%s: platform version not available!\n", __func__);
516 return 0;
517 }
518
519 return snprintf(buf, PAGE_SIZE, "%u\n",
520 socinfo_get_platform_version());
521}
522
523static ssize_t
524socinfo_show_accessory_chip(struct sys_device *dev,
525 struct sysdev_attribute *attr,
526 char *buf)
527{
528 if (!socinfo) {
529 pr_err("%s: No socinfo found!\n", __func__);
530 return 0;
531 }
532 if (socinfo->v1.format < 5) {
533 pr_err("%s: accessory chip not available!\n", __func__);
534 return 0;
535 }
536
537 return snprintf(buf, PAGE_SIZE, "%u\n",
538 socinfo_get_accessory_chip());
539}
540
541static ssize_t
542socinfo_show_platform_subtype(struct sys_device *dev,
543 struct sysdev_attribute *attr,
544 char *buf)
545{
546 uint32_t hw_subtype;
547 if (!socinfo) {
548 pr_err("%s: No socinfo found!\n", __func__);
549 return 0;
550 }
551 if (socinfo->v1.format < 6) {
552 pr_err("%s: platform subtype not available!\n", __func__);
553 return 0;
554 }
555
556 hw_subtype = socinfo_get_platform_subtype();
557 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
558 pr_err("%s: Invalid hardware platform sub type found\n",
559 __func__);
560 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
561 }
562 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
563 hw_platform_subtype[hw_subtype]);
564}
565
Jin Honge795bd22012-08-13 23:06:26 -0700566static ssize_t
567socinfo_show_pmic_model(struct sys_device *dev,
568 struct sysdev_attribute *attr,
569 char *buf)
570{
571 if (!socinfo) {
572 pr_err("%s: No socinfo found!\n", __func__);
573 return 0;
574 }
575 if (socinfo->v1.format < 7) {
576 pr_err("%s: pmic_model not available!\n", __func__);
577 return 0;
578 }
579
580 return snprintf(buf, PAGE_SIZE, "%u\n",
581 socinfo_get_pmic_model());
582}
583
584static ssize_t
585socinfo_show_pmic_die_revision(struct sys_device *dev,
586 struct sysdev_attribute *attr,
587 char *buf)
588{
589 if (!socinfo) {
590 pr_err("%s: No socinfo found!\n", __func__);
591 return 0;
592 }
593 if (socinfo->v1.format < 7) {
594 pr_err("%s: pmic_die_revision not available!\n", __func__);
595 return 0;
596 }
597
598 return snprintf(buf, PAGE_SIZE, "%u\n",
599 socinfo_get_pmic_die_revision());
600}
601
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700602static struct sysdev_attribute socinfo_v1_files[] = {
603 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
604 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
605 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
606};
607
608static struct sysdev_attribute socinfo_v2_files[] = {
609 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
610 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
611};
612
613static struct sysdev_attribute socinfo_v3_files[] = {
614 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
615};
616
617static struct sysdev_attribute socinfo_v4_files[] = {
618 _SYSDEV_ATTR(platform_version, 0444,
619 socinfo_show_platform_version, NULL),
620};
621
622static struct sysdev_attribute socinfo_v5_files[] = {
623 _SYSDEV_ATTR(accessory_chip, 0444,
624 socinfo_show_accessory_chip, NULL),
625};
626
627static struct sysdev_attribute socinfo_v6_files[] = {
628 _SYSDEV_ATTR(platform_subtype, 0444,
629 socinfo_show_platform_subtype, NULL),
630};
631
Jin Honge795bd22012-08-13 23:06:26 -0700632static struct sysdev_attribute socinfo_v7_files[] = {
633 _SYSDEV_ATTR(pmic_model, 0444,
634 socinfo_show_pmic_model, NULL),
635 _SYSDEV_ATTR(pmic_die_revision, 0444,
636 socinfo_show_pmic_die_revision, NULL),
637};
638
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639static struct sysdev_class soc_sysdev_class = {
640 .name = "soc",
641};
642
643static struct sys_device soc_sys_device = {
644 .id = 0,
645 .cls = &soc_sysdev_class,
646};
647
648static int __init socinfo_create_files(struct sys_device *dev,
649 struct sysdev_attribute files[],
650 int size)
651{
652 int i;
653 for (i = 0; i < size; i++) {
654 int err = sysdev_create_file(dev, &files[i]);
655 if (err) {
656 pr_err("%s: sysdev_create_file(%s)=%d\n",
657 __func__, files[i].attr.name, err);
658 return err;
659 }
660 }
661 return 0;
662}
663
664static int __init socinfo_init_sysdev(void)
665{
666 int err;
667
668 if (!socinfo) {
669 pr_err("%s: No socinfo found!\n", __func__);
670 return -ENODEV;
671 }
672
673 err = sysdev_class_register(&soc_sysdev_class);
674 if (err) {
675 pr_err("%s: sysdev_class_register fail (%d)\n",
676 __func__, err);
677 return err;
678 }
679 err = sysdev_register(&soc_sys_device);
680 if (err) {
681 pr_err("%s: sysdev_register fail (%d)\n",
682 __func__, err);
683 return err;
684 }
685 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
686 ARRAY_SIZE(socinfo_v1_files));
687 if (socinfo->v1.format < 2)
688 return err;
689 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
690 ARRAY_SIZE(socinfo_v2_files));
691
692 if (socinfo->v1.format < 3)
693 return err;
694
695 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
696 ARRAY_SIZE(socinfo_v3_files));
697
698 if (socinfo->v1.format < 4)
699 return err;
700
701 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
702 ARRAY_SIZE(socinfo_v4_files));
703
704 if (socinfo->v1.format < 5)
705 return err;
706
707 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
708 ARRAY_SIZE(socinfo_v5_files));
709
710 if (socinfo->v1.format < 6)
711 return err;
712
Jin Honge795bd22012-08-13 23:06:26 -0700713 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700714 ARRAY_SIZE(socinfo_v6_files));
715
Jin Honge795bd22012-08-13 23:06:26 -0700716 if (socinfo->v1.format < 7)
717 return err;
718
719 return socinfo_create_files(&soc_sys_device, socinfo_v7_files,
720 ARRAY_SIZE(socinfo_v7_files));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721}
722
723arch_initcall(socinfo_init_sysdev);
724
Stephen Boyd69a22e42012-02-22 09:16:07 -0800725static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726{
Syed Rameez Mustafacf645e82012-07-06 19:00:49 -0700727 if (machine_is_msm8960_cdp())
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700728 dummy_socinfo.id = 87;
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700729 else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp())
730 dummy_socinfo.id = 104;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700731 else if (early_machine_is_msm8974()) {
Sathish Ambleya99d6852011-10-31 15:50:55 -0700732 dummy_socinfo.id = 126;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700733 strlcpy(dummy_socinfo.build_id, "msm8974 - ",
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800734 sizeof(dummy_socinfo.build_id));
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700735 } else if (early_machine_is_msm9625()) {
Joel King8e0bf672012-05-18 15:40:40 -0700736 dummy_socinfo.id = 134;
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700737 strlcpy(dummy_socinfo.build_id, "msm9625 - ",
738 sizeof(dummy_socinfo.build_id));
Syed Rameez Mustafa36a63712012-08-23 15:47:50 -0700739 } else if (early_machine_is_msm8226()) {
740 dummy_socinfo.id = 145;
741 strlcpy(dummy_socinfo.build_id, "msm8226 - ",
742 sizeof(dummy_socinfo.build_id));
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800743 } else if (machine_is_msm8625_rumi3())
Taniya Dasa04e1892011-11-16 14:49:12 +0530744 dummy_socinfo.id = 127;
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800745 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
746 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700747 return (void *) &dummy_socinfo;
748}
749
750int __init socinfo_init(void)
751{
Jin Honge795bd22012-08-13 23:06:26 -0700752 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v7));
753
754 if (!socinfo)
755 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
756 sizeof(struct socinfo_v6));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757
758 if (!socinfo)
759 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
760 sizeof(struct socinfo_v5));
761
762 if (!socinfo)
763 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
764 sizeof(struct socinfo_v4));
765
766 if (!socinfo)
767 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
768 sizeof(struct socinfo_v3));
769
770 if (!socinfo)
771 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
772 sizeof(struct socinfo_v2));
773
774 if (!socinfo)
775 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
776 sizeof(struct socinfo_v1));
777
778 if (!socinfo) {
779 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on "
780 "dummy values.\n", __func__);
781 socinfo = setup_dummy_socinfo();
782 }
783
784 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
785 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
786 "New IDs added! ID => CPU mapping might need an update.\n");
787
788 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
789 cur_cpu = cpu_of_id[socinfo->v1.id];
790
791 switch (socinfo->v1.format) {
792 case 1:
793 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
794 __func__, socinfo->v1.format, socinfo->v1.id,
795 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
796 SOCINFO_VERSION_MINOR(socinfo->v1.version));
797 break;
798 case 2:
799 pr_info("%s: v%u, id=%u, ver=%u.%u, "
800 "raw_id=%u, raw_ver=%u\n",
801 __func__, socinfo->v1.format, socinfo->v1.id,
802 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
803 SOCINFO_VERSION_MINOR(socinfo->v1.version),
804 socinfo->v2.raw_id, socinfo->v2.raw_version);
805 break;
806 case 3:
807 pr_info("%s: v%u, id=%u, ver=%u.%u, "
808 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
809 __func__, socinfo->v1.format, socinfo->v1.id,
810 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
811 SOCINFO_VERSION_MINOR(socinfo->v1.version),
812 socinfo->v2.raw_id, socinfo->v2.raw_version,
813 socinfo->v3.hw_platform);
814 break;
815 case 4:
816 pr_info("%s: v%u, id=%u, ver=%u.%u, "
817 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
818 __func__, socinfo->v1.format, socinfo->v1.id,
819 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
820 SOCINFO_VERSION_MINOR(socinfo->v1.version),
821 socinfo->v2.raw_id, socinfo->v2.raw_version,
822 socinfo->v3.hw_platform, socinfo->v4.platform_version);
823 break;
824 case 5:
825 pr_info("%s: v%u, id=%u, ver=%u.%u, "
826 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
827 " accessory_chip=%u\n", __func__, socinfo->v1.format,
828 socinfo->v1.id,
829 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
830 SOCINFO_VERSION_MINOR(socinfo->v1.version),
831 socinfo->v2.raw_id, socinfo->v2.raw_version,
832 socinfo->v3.hw_platform, socinfo->v4.platform_version,
833 socinfo->v5.accessory_chip);
834 break;
835 case 6:
836 pr_info("%s: v%u, id=%u, ver=%u.%u, "
837 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
838 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
839 socinfo->v1.format,
840 socinfo->v1.id,
841 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
842 SOCINFO_VERSION_MINOR(socinfo->v1.version),
843 socinfo->v2.raw_id, socinfo->v2.raw_version,
844 socinfo->v3.hw_platform, socinfo->v4.platform_version,
845 socinfo->v5.accessory_chip,
846 socinfo->v6.hw_platform_subtype);
847 break;
Jin Honge795bd22012-08-13 23:06:26 -0700848 case 7:
849 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",
850 __func__,
851 socinfo->v1.format,
852 socinfo->v1.id,
853 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
854 SOCINFO_VERSION_MINOR(socinfo->v1.version),
855 socinfo->v2.raw_id, socinfo->v2.raw_version,
856 socinfo->v3.hw_platform, socinfo->v4.platform_version,
857 socinfo->v5.accessory_chip,
858 socinfo->v6.hw_platform_subtype,
859 socinfo->v7.pmic_model,
860 socinfo->v7.pmic_die_revision);
861 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 default:
863 pr_err("%s: Unknown format found\n", __func__);
864 break;
865 }
866
867 return 0;
868}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700869
870const int get_core_count(void)
871{
872 if (!(read_cpuid_mpidr() & BIT(31)))
873 return 1;
874
Jin Hongc5f5d542012-04-12 16:48:51 -0700875 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700876 return 1;
877
878 /* 1 + the PART[1:0] field of MIDR */
879 return ((read_cpuid_id() >> 4) & 3) + 1;
880}
881
882const int read_msm_cpu_type(void)
883{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700884 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
885 return socinfo_get_msm_cpu();
886
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700887 switch (read_cpuid_id()) {
888 case 0x510F02D0:
889 case 0x510F02D2:
890 case 0x510F02D4:
891 return MSM_CPU_8X60;
892
893 case 0x510F04D0:
894 case 0x510F04D1:
895 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700896 case 0x511F04D0:
897 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700898 return MSM_CPU_8960;
899
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700900 case 0x51404D11: /* We can't get here unless we are in bringup */
901 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700902
903 case 0x510F06F0:
904 return MSM_CPU_8064;
905
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -0700906 case 0x511F06F1:
907 case 0x512F06F0:
908 return MSM_CPU_8974;
909
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -0700910 default:
911 return MSM_CPU_UNKNOWN;
912 };
913}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700914
Jin Hong12b8b432012-07-18 10:00:31 -0700915const int cpu_is_krait(void)
916{
917 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
918}
919
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -0700920const int cpu_is_krait_v1(void)
921{
922 switch (read_cpuid_id()) {
923 case 0x510F04D0:
924 case 0x510F04D1:
925 case 0x510F04D2:
926 return 1;
927
928 default:
929 return 0;
930 };
931}
Jin Hong12b8b432012-07-18 10:00:31 -0700932
933const int cpu_is_krait_v2(void)
934{
935 switch (read_cpuid_id()) {
936 case 0x511F04D0:
937 case 0x511F04D1:
938 case 0x511F04D2:
939 case 0x511F04D3:
940 case 0x511F04D4:
941
942 case 0x510F06F0:
943 case 0x510F06F1:
944 case 0x510F06F2:
945 return 1;
946
947 default:
948 return 0;
949 };
950}
Joel Kingffb79662012-08-19 12:55:49 -0700951
952const int cpu_is_krait_v3(void)
953{
954 switch (read_cpuid_id()) {
955 case 0x512F04D0:
956 case 0x511F06F0:
957 case 0x511F06F1:
958 case 0x510F05D0:
959 return 1;
960
961 default:
962 return 0;
963 };
964}