blob: a8ae50c6c339b8f9ff78ebb7b1c35b0b149d210e [file] [log] [blame]
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001/* 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
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -080018#include <linux/err.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21#include <linux/sys_soc.h>
22#include <linux/slab.h>
23#include <linux/stat.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include <linux/sysdev.h>
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -080025#include <linux/types.h>
26
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#include <asm/mach-types.h>
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -080028
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#include <mach/socinfo.h>
30
31#include "smd_private.h"
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -080032#include "boot_stats.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
34#define BUILD_ID_LENGTH 32
35
36enum {
37 HW_PLATFORM_UNKNOWN = 0,
38 HW_PLATFORM_SURF = 1,
39 HW_PLATFORM_FFA = 2,
40 HW_PLATFORM_FLUID = 3,
41 HW_PLATFORM_SVLTE_FFA = 4,
42 HW_PLATFORM_SVLTE_SURF = 5,
Jin Hong49753322011-12-15 16:55:37 -080043 HW_PLATFORM_MTP = 8,
Amir Samuelov1b0dc312011-11-17 20:43:33 +020044 HW_PLATFORM_LIQUID = 9,
Zhang Chang Ken59004eb2011-08-08 09:06:58 -040045 /* Dragonboard platform id is assigned as 10 in CDT */
46 HW_PLATFORM_DRAGON = 10,
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053047 HW_PLATFORM_HRD = 13,
48 HW_PLATFORM_DTV = 14,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049 HW_PLATFORM_INVALID
50};
51
52const char *hw_platform[] = {
53 [HW_PLATFORM_UNKNOWN] = "Unknown",
54 [HW_PLATFORM_SURF] = "Surf",
55 [HW_PLATFORM_FFA] = "FFA",
56 [HW_PLATFORM_FLUID] = "Fluid",
57 [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040058 [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF",
Jin Hong49753322011-12-15 16:55:37 -080059 [HW_PLATFORM_MTP] = "MTP",
60 [HW_PLATFORM_LIQUID] = "Liquid",
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053061 [HW_PLATFORM_DRAGON] = "Dragon",
62 [HW_PLATFORM_HRD] = "HRD",
63 [HW_PLATFORM_DTV] = "DTV",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064};
65
66enum {
67 ACCESSORY_CHIP_UNKNOWN = 0,
68 ACCESSORY_CHIP_CHARM = 58,
69};
70
71enum {
72 PLATFORM_SUBTYPE_UNKNOWN = 0x0,
73 PLATFORM_SUBTYPE_CHARM = 0x1,
74 PLATFORM_SUBTYPE_STRANGE = 0x2,
75 PLATFORM_SUBTYPE_STRANGE_2A = 0x3,
76 PLATFORM_SUBTYPE_INVALID,
77};
78
79const char *hw_platform_subtype[] = {
80 [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown",
81 [PLATFORM_SUBTYPE_CHARM] = "charm",
82 [PLATFORM_SUBTYPE_STRANGE] = "strange",
83 [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a,"
84};
85
86/* Used to parse shared memory. Must match the modem. */
87struct socinfo_v1 {
88 uint32_t format;
89 uint32_t id;
90 uint32_t version;
91 char build_id[BUILD_ID_LENGTH];
92};
93
94struct socinfo_v2 {
95 struct socinfo_v1 v1;
96
97 /* only valid when format==2 */
98 uint32_t raw_id;
99 uint32_t raw_version;
100};
101
102struct socinfo_v3 {
103 struct socinfo_v2 v2;
104
105 /* only valid when format==3 */
106 uint32_t hw_platform;
107};
108
109struct socinfo_v4 {
110 struct socinfo_v3 v3;
111
112 /* only valid when format==4 */
113 uint32_t platform_version;
114};
115
116struct socinfo_v5 {
117 struct socinfo_v4 v4;
118
119 /* only valid when format==5 */
120 uint32_t accessory_chip;
121};
122
123struct socinfo_v6 {
124 struct socinfo_v5 v5;
125
126 /* only valid when format==6 */
127 uint32_t hw_platform_subtype;
128};
129
Jin Hong9b556c32012-08-13 23:06:26 -0700130struct socinfo_v7 {
131 struct socinfo_v6 v6;
132
133 /* only valid when format==7 */
134 uint32_t pmic_model;
135 uint32_t pmic_die_revision;
136};
137
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800138struct socinfo_v8 {
139 struct socinfo_v7 v7;
140
141 /* only valid when format==8*/
142 uint32_t pmic_model_1;
143 uint32_t pmic_die_revision_1;
144 uint32_t pmic_model_2;
145 uint32_t pmic_die_revision_2;
146};
147
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148static union {
149 struct socinfo_v1 v1;
150 struct socinfo_v2 v2;
151 struct socinfo_v3 v3;
152 struct socinfo_v4 v4;
153 struct socinfo_v5 v5;
154 struct socinfo_v6 v6;
Jin Hong9b556c32012-08-13 23:06:26 -0700155 struct socinfo_v7 v7;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800156 struct socinfo_v8 v8;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157} *socinfo;
158
159static enum msm_cpu cpu_of_id[] = {
160
161 /* 7x01 IDs */
162 [1] = MSM_CPU_7X01,
163 [16] = MSM_CPU_7X01,
164 [17] = MSM_CPU_7X01,
165 [18] = MSM_CPU_7X01,
166 [19] = MSM_CPU_7X01,
167 [23] = MSM_CPU_7X01,
168 [25] = MSM_CPU_7X01,
169 [26] = MSM_CPU_7X01,
170 [32] = MSM_CPU_7X01,
171 [33] = MSM_CPU_7X01,
172 [34] = MSM_CPU_7X01,
173 [35] = MSM_CPU_7X01,
174
175 /* 7x25 IDs */
176 [20] = MSM_CPU_7X25,
177 [21] = MSM_CPU_7X25, /* 7225 */
178 [24] = MSM_CPU_7X25, /* 7525 */
179 [27] = MSM_CPU_7X25, /* 7625 */
180 [39] = MSM_CPU_7X25,
181 [40] = MSM_CPU_7X25,
182 [41] = MSM_CPU_7X25,
183 [42] = MSM_CPU_7X25,
184 [62] = MSM_CPU_7X25, /* 7625-1 */
185 [63] = MSM_CPU_7X25, /* 7225-1 */
186 [66] = MSM_CPU_7X25, /* 7225-2 */
187
188
189 /* 7x27 IDs */
190 [43] = MSM_CPU_7X27,
191 [44] = MSM_CPU_7X27,
192 [61] = MSM_CPU_7X27,
193 [67] = MSM_CPU_7X27, /* 7227-1 */
194 [68] = MSM_CPU_7X27, /* 7627-1 */
195 [69] = MSM_CPU_7X27, /* 7627-2 */
196
197
198 /* 8x50 IDs */
199 [30] = MSM_CPU_8X50,
200 [36] = MSM_CPU_8X50,
201 [37] = MSM_CPU_8X50,
202 [38] = MSM_CPU_8X50,
203
204 /* 7x30 IDs */
205 [59] = MSM_CPU_7X30,
206 [60] = MSM_CPU_7X30,
207
208 /* 8x55 IDs */
209 [74] = MSM_CPU_8X55,
210 [75] = MSM_CPU_8X55,
211 [85] = MSM_CPU_8X55,
212
213 /* 8x60 IDs */
214 [70] = MSM_CPU_8X60,
215 [71] = MSM_CPU_8X60,
216 [86] = MSM_CPU_8X60,
217
218 /* 8960 IDs */
219 [87] = MSM_CPU_8960,
220
221 /* 7x25A IDs */
222 [88] = MSM_CPU_7X25A,
223 [89] = MSM_CPU_7X25A,
224 [96] = MSM_CPU_7X25A,
225
226 /* 7x27A IDs */
227 [90] = MSM_CPU_7X27A,
228 [91] = MSM_CPU_7X27A,
229 [92] = MSM_CPU_7X27A,
230 [97] = MSM_CPU_7X27A,
231
232 /* FSM9xxx ID */
233 [94] = FSM_CPU_9XXX,
234 [95] = FSM_CPU_9XXX,
235
236 /* 7x25AA ID */
237 [98] = MSM_CPU_7X25AA,
238 [99] = MSM_CPU_7X25AA,
239 [100] = MSM_CPU_7X25AA,
240
Joel Kingbf2ff512011-07-22 13:43:11 -0700241 /* 7x27AA ID */
242 [101] = MSM_CPU_7X27AA,
243 [102] = MSM_CPU_7X27AA,
244 [103] = MSM_CPU_7X27AA,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530245 [136] = MSM_CPU_7X27AA,
Joel Kingbf2ff512011-07-22 13:43:11 -0700246
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700247 /* 9x15 ID */
248 [104] = MSM_CPU_9615,
Rohit Vaswani865f2ca2011-10-03 17:40:42 -0700249 [105] = MSM_CPU_9615,
Rohit Vaswani7a83fa92012-01-11 15:05:39 -0800250 [106] = MSM_CPU_9615,
251 [107] = MSM_CPU_9615,
Abhimanyu Kapur45149122013-03-20 01:07:52 -0700252 [171] = MSM_CPU_9615,
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700253
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700254 /* 8064 IDs */
Joel Kingbf2ff512011-07-22 13:43:11 -0700255 [109] = MSM_CPU_8064,
256
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700257 /* 8930 IDs */
258 [116] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800259 [117] = MSM_CPU_8930,
260 [118] = MSM_CPU_8930,
261 [119] = MSM_CPU_8930,
David Ngc103f1c2013-02-12 18:49:25 -0800262 [179] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800263
264 /* 8627 IDs */
265 [120] = MSM_CPU_8627,
266 [121] = MSM_CPU_8627,
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700267
Jin Hong0698b562011-11-05 13:57:25 -0700268 /* 8660A ID */
269 [122] = MSM_CPU_8960,
270
271 /* 8260A ID */
272 [123] = MSM_CPU_8960,
273
274 /* 8060A ID */
275 [124] = MSM_CPU_8960,
276
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700277 /* 8974 IDs */
278 [126] = MSM_CPU_8974,
Sathish Ambleya99d6852011-10-31 15:50:55 -0700279
Taniya Dasa04e1892011-11-16 14:49:12 +0530280 /* 8625 IDs */
281 [127] = MSM_CPU_8625,
282 [128] = MSM_CPU_8625,
283 [129] = MSM_CPU_8625,
Kaushal Kumar1f8876a2012-08-21 14:53:50 +0530284 [137] = MSM_CPU_8625,
Kaushal Kumarc84b9c22012-10-12 12:47:55 +0530285 [167] = MSM_CPU_8625,
Taniya Dasa04e1892011-11-16 14:49:12 +0530286
Joel King8e0bf672012-05-18 15:40:40 -0700287 /* 8064 MPQ ID */
288 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700289
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530290 /* 7x25AB IDs */
291 [131] = MSM_CPU_7X25AB,
292 [132] = MSM_CPU_7X25AB,
293 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530294 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530295
Joel King8e0bf672012-05-18 15:40:40 -0700296 /* 9625 IDs */
297 [134] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800298 [148] = MSM_CPU_9625,
Abhimanyu Kapur0e088bb2013-01-08 18:41:17 -0800299 [149] = MSM_CPU_9625,
300 [150] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800301 [151] = MSM_CPU_9625,
302 [152] = MSM_CPU_9625,
303 [173] = MSM_CPU_9625,
304 [174] = MSM_CPU_9625,
305 [175] = MSM_CPU_9625,
Joel King8e0bf672012-05-18 15:40:40 -0700306
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700307 /* 8960AB IDs */
308 [138] = MSM_CPU_8960AB,
309 [139] = MSM_CPU_8960AB,
310 [140] = MSM_CPU_8960AB,
311 [141] = MSM_CPU_8960AB,
312
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700313 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700314 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700315 [143] = MSM_CPU_8930AA,
316 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko9e83cb92012-10-22 18:52:06 -0700317 [160] = MSM_CPU_8930AA,
David Ngc103f1c2013-02-12 18:49:25 -0800318 [180] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700319
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700320 /* 8226 IDs */
321 [145] = MSM_CPU_8226,
322
Ravi Kumar V754282d2012-08-31 22:32:20 +0530323 /* 8092 IDs */
324 [146] = MSM_CPU_8092,
325
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800326 /* 8610 IDs */
327 [147] = MSM_CPU_8610,
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700328
Jay Chokshib2de5092012-09-19 18:28:12 -0700329 /* 8064AB IDs */
330 [153] = MSM_CPU_8064AB,
331
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700332 /* 8930AB IDs */
333 [154] = MSM_CPU_8930AB,
334 [155] = MSM_CPU_8930AB,
335 [156] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530336 [157] = MSM_CPU_8930AB,
David Ngc103f1c2013-02-12 18:49:25 -0800337 [181] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530338
339 /* 8625Q IDs */
340 [168] = MSM_CPU_8625Q,
341 [169] = MSM_CPU_8625Q,
342 [170] = MSM_CPU_8625Q,
343
Jay Chokshif9294742013-01-15 13:06:27 -0800344 /* 8064AA IDs */
345 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700346
Stepan Moskovchenko55dfdc32013-01-24 15:48:23 -0800347 /* zinc IDs */
348 [178] = MSM_CPU_ZINC,
349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700350 /* Uninitialized IDs are not known to run Linux.
351 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
352 considered as unknown CPU. */
353};
354
355static enum msm_cpu cur_cpu;
356
357static struct socinfo_v1 dummy_socinfo = {
358 .format = 1,
359 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700360};
361
362uint32_t socinfo_get_id(void)
363{
364 return (socinfo) ? socinfo->v1.id : 0;
365}
366EXPORT_SYMBOL_GPL(socinfo_get_id);
367
368uint32_t socinfo_get_version(void)
369{
370 return (socinfo) ? socinfo->v1.version : 0;
371}
372
373char *socinfo_get_build_id(void)
374{
375 return (socinfo) ? socinfo->v1.build_id : NULL;
376}
377
378uint32_t socinfo_get_raw_id(void)
379{
380 return socinfo ?
381 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
382 : 0;
383}
384
385uint32_t socinfo_get_raw_version(void)
386{
387 return socinfo ?
388 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
389 : 0;
390}
391
392uint32_t socinfo_get_platform_type(void)
393{
394 return socinfo ?
395 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
396 : 0;
397}
398
399
400uint32_t socinfo_get_platform_version(void)
401{
402 return socinfo ?
403 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
404 : 0;
405}
406
407/* This information is directly encoded by the machine id */
408/* Thus no external callers rely on this information at the moment */
409static uint32_t socinfo_get_accessory_chip(void)
410{
411 return socinfo ?
412 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
413 : 0;
414}
415
416uint32_t socinfo_get_platform_subtype(void)
417{
418 return socinfo ?
419 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
420 : 0;
421}
422
Jin Hong9b556c32012-08-13 23:06:26 -0700423enum pmic_model socinfo_get_pmic_model(void)
424{
425 return socinfo ?
426 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
427 : PMIC_MODEL_UNKNOWN)
428 : PMIC_MODEL_UNKNOWN;
429}
430
431uint32_t socinfo_get_pmic_die_revision(void)
432{
433 return socinfo ?
434 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
435 : 0;
436}
437
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800438static uint32_t socinfo_get_format(void)
439{
440 return socinfo ? socinfo->v1.format : 0;
441}
442
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700443enum msm_cpu socinfo_get_msm_cpu(void)
444{
445 return cur_cpu;
446}
447EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
448
449static ssize_t
450socinfo_show_id(struct sys_device *dev,
451 struct sysdev_attribute *attr,
452 char *buf)
453{
454 if (!socinfo) {
455 pr_err("%s: No socinfo found!\n", __func__);
456 return 0;
457 }
458
459 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
460}
461
462static ssize_t
463socinfo_show_version(struct sys_device *dev,
464 struct sysdev_attribute *attr,
465 char *buf)
466{
467 uint32_t version;
468
469 if (!socinfo) {
470 pr_err("%s: No socinfo found!\n", __func__);
471 return 0;
472 }
473
474 version = socinfo_get_version();
475 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
476 SOCINFO_VERSION_MAJOR(version),
477 SOCINFO_VERSION_MINOR(version));
478}
479
480static ssize_t
481socinfo_show_build_id(struct sys_device *dev,
482 struct sysdev_attribute *attr,
483 char *buf)
484{
485 if (!socinfo) {
486 pr_err("%s: No socinfo found!\n", __func__);
487 return 0;
488 }
489
490 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
491}
492
493static ssize_t
494socinfo_show_raw_id(struct sys_device *dev,
495 struct sysdev_attribute *attr,
496 char *buf)
497{
498 if (!socinfo) {
499 pr_err("%s: No socinfo found!\n", __func__);
500 return 0;
501 }
502 if (socinfo->v1.format < 2) {
503 pr_err("%s: Raw ID not available!\n", __func__);
504 return 0;
505 }
506
507 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
508}
509
510static ssize_t
511socinfo_show_raw_version(struct sys_device *dev,
512 struct sysdev_attribute *attr,
513 char *buf)
514{
515 if (!socinfo) {
516 pr_err("%s: No socinfo found!\n", __func__);
517 return 0;
518 }
519 if (socinfo->v1.format < 2) {
520 pr_err("%s: Raw version not available!\n", __func__);
521 return 0;
522 }
523
524 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
525}
526
527static ssize_t
528socinfo_show_platform_type(struct sys_device *dev,
529 struct sysdev_attribute *attr,
530 char *buf)
531{
532 uint32_t hw_type;
533
534 if (!socinfo) {
535 pr_err("%s: No socinfo found!\n", __func__);
536 return 0;
537 }
538 if (socinfo->v1.format < 3) {
539 pr_err("%s: platform type not available!\n", __func__);
540 return 0;
541 }
542
543 hw_type = socinfo_get_platform_type();
544 if (hw_type >= HW_PLATFORM_INVALID) {
545 pr_err("%s: Invalid hardware platform type found\n",
546 __func__);
547 hw_type = HW_PLATFORM_UNKNOWN;
548 }
549
550 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
551}
552
553static ssize_t
554socinfo_show_platform_version(struct sys_device *dev,
555 struct sysdev_attribute *attr,
556 char *buf)
557{
558
559 if (!socinfo) {
560 pr_err("%s: No socinfo found!\n", __func__);
561 return 0;
562 }
563 if (socinfo->v1.format < 4) {
564 pr_err("%s: platform version not available!\n", __func__);
565 return 0;
566 }
567
568 return snprintf(buf, PAGE_SIZE, "%u\n",
569 socinfo_get_platform_version());
570}
571
572static ssize_t
573socinfo_show_accessory_chip(struct sys_device *dev,
574 struct sysdev_attribute *attr,
575 char *buf)
576{
577 if (!socinfo) {
578 pr_err("%s: No socinfo found!\n", __func__);
579 return 0;
580 }
581 if (socinfo->v1.format < 5) {
582 pr_err("%s: accessory chip not available!\n", __func__);
583 return 0;
584 }
585
586 return snprintf(buf, PAGE_SIZE, "%u\n",
587 socinfo_get_accessory_chip());
588}
589
590static ssize_t
591socinfo_show_platform_subtype(struct sys_device *dev,
592 struct sysdev_attribute *attr,
593 char *buf)
594{
595 uint32_t hw_subtype;
596 if (!socinfo) {
597 pr_err("%s: No socinfo found!\n", __func__);
598 return 0;
599 }
600 if (socinfo->v1.format < 6) {
601 pr_err("%s: platform subtype not available!\n", __func__);
602 return 0;
603 }
604
605 hw_subtype = socinfo_get_platform_subtype();
606 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
607 pr_err("%s: Invalid hardware platform sub type found\n",
608 __func__);
609 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
610 }
611 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
612 hw_platform_subtype[hw_subtype]);
613}
614
Jin Hong9b556c32012-08-13 23:06:26 -0700615static ssize_t
616socinfo_show_pmic_model(struct sys_device *dev,
617 struct sysdev_attribute *attr,
618 char *buf)
619{
620 if (!socinfo) {
621 pr_err("%s: No socinfo found!\n", __func__);
622 return 0;
623 }
624 if (socinfo->v1.format < 7) {
625 pr_err("%s: pmic_model not available!\n", __func__);
626 return 0;
627 }
628
629 return snprintf(buf, PAGE_SIZE, "%u\n",
630 socinfo_get_pmic_model());
631}
632
633static ssize_t
634socinfo_show_pmic_die_revision(struct sys_device *dev,
635 struct sysdev_attribute *attr,
636 char *buf)
637{
638 if (!socinfo) {
639 pr_err("%s: No socinfo found!\n", __func__);
640 return 0;
641 }
642 if (socinfo->v1.format < 7) {
643 pr_err("%s: pmic_die_revision not available!\n", __func__);
644 return 0;
645 }
646
647 return snprintf(buf, PAGE_SIZE, "%u\n",
648 socinfo_get_pmic_die_revision());
649}
650
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800651static ssize_t
652msm_get_vendor(struct device *dev,
653 struct device_attribute *attr,
654 char *buf)
655{
656 return snprintf(buf, PAGE_SIZE, "Qualcomm\n");
657}
658
659static ssize_t
660msm_get_raw_id(struct device *dev,
661 struct device_attribute *attr,
662 char *buf)
663{
664 return snprintf(buf, PAGE_SIZE, "%u\n",
665 socinfo_get_raw_id());
666}
667
668static ssize_t
669msm_get_raw_version(struct device *dev,
670 struct device_attribute *attr,
671 char *buf)
672{
673 return snprintf(buf, PAGE_SIZE, "%u\n",
674 socinfo_get_raw_version());
675}
676
677static ssize_t
678msm_get_build_id(struct device *dev,
679 struct device_attribute *attr,
680 char *buf)
681{
682 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
683 socinfo_get_build_id());
684}
685
686static ssize_t
687msm_get_hw_platform(struct device *dev,
688 struct device_attribute *attr,
689 char *buf)
690{
691 uint32_t hw_type;
692 hw_type = socinfo_get_platform_type();
693
694 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
695 hw_platform[hw_type]);
696}
697
698static ssize_t
699msm_get_platform_version(struct device *dev,
700 struct device_attribute *attr,
701 char *buf)
702{
703 return snprintf(buf, PAGE_SIZE, "%u\n",
704 socinfo_get_platform_version());
705}
706
707static ssize_t
708msm_get_accessory_chip(struct device *dev,
709 struct device_attribute *attr,
710 char *buf)
711{
712 return snprintf(buf, PAGE_SIZE, "%u\n",
713 socinfo_get_accessory_chip());
714}
715
716static ssize_t
717msm_get_platform_subtype(struct device *dev,
718 struct device_attribute *attr,
719 char *buf)
720{
721 uint32_t hw_subtype;
722 hw_subtype = socinfo_get_platform_subtype();
723 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
724 hw_platform_subtype[hw_subtype]);
725}
726
727static ssize_t
728msm_get_pmic_model(struct device *dev,
729 struct device_attribute *attr,
730 char *buf)
731{
732 return snprintf(buf, PAGE_SIZE, "%u\n",
733 socinfo_get_pmic_model());
734}
735
736static ssize_t
737msm_get_pmic_die_revision(struct device *dev,
738 struct device_attribute *attr,
739 char *buf)
740{
741 return snprintf(buf, PAGE_SIZE, "%u\n",
742 socinfo_get_pmic_die_revision());
743}
744
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700745static struct sysdev_attribute socinfo_v1_files[] = {
746 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
747 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
748 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
749};
750
751static struct sysdev_attribute socinfo_v2_files[] = {
752 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
753 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
754};
755
756static struct sysdev_attribute socinfo_v3_files[] = {
757 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
758};
759
760static struct sysdev_attribute socinfo_v4_files[] = {
761 _SYSDEV_ATTR(platform_version, 0444,
762 socinfo_show_platform_version, NULL),
763};
764
765static struct sysdev_attribute socinfo_v5_files[] = {
766 _SYSDEV_ATTR(accessory_chip, 0444,
767 socinfo_show_accessory_chip, NULL),
768};
769
770static struct sysdev_attribute socinfo_v6_files[] = {
771 _SYSDEV_ATTR(platform_subtype, 0444,
772 socinfo_show_platform_subtype, NULL),
773};
774
Jin Hong9b556c32012-08-13 23:06:26 -0700775static struct sysdev_attribute socinfo_v7_files[] = {
776 _SYSDEV_ATTR(pmic_model, 0444,
777 socinfo_show_pmic_model, NULL),
778 _SYSDEV_ATTR(pmic_die_revision, 0444,
779 socinfo_show_pmic_die_revision, NULL),
780};
781
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800782static struct device_attribute msm_soc_attr_raw_version =
783 __ATTR(raw_version, S_IRUGO, msm_get_raw_version, NULL);
784
785static struct device_attribute msm_soc_attr_raw_id =
786 __ATTR(raw_id, S_IRUGO, msm_get_raw_id, NULL);
787
788static struct device_attribute msm_soc_attr_vendor =
789 __ATTR(vendor, S_IRUGO, msm_get_vendor, NULL);
790
791static struct device_attribute msm_soc_attr_build_id =
792 __ATTR(build_id, S_IRUGO, msm_get_build_id, NULL);
793
794static struct device_attribute msm_soc_attr_hw_platform =
795 __ATTR(hw_platform, S_IRUGO, msm_get_hw_platform, NULL);
796
797
798static struct device_attribute msm_soc_attr_platform_version =
799 __ATTR(platform_version, S_IRUGO,
800 msm_get_platform_version, NULL);
801
802static struct device_attribute msm_soc_attr_accessory_chip =
803 __ATTR(accessory_chip, S_IRUGO,
804 msm_get_accessory_chip, NULL);
805
806static struct device_attribute msm_soc_attr_platform_subtype =
807 __ATTR(platform_subtype, S_IRUGO,
808 msm_get_platform_subtype, NULL);
809
810static struct device_attribute msm_soc_attr_pmic_model =
811 __ATTR(pmic_model, S_IRUGO,
812 msm_get_pmic_model, NULL);
813
814static struct device_attribute msm_soc_attr_pmic_die_revision =
815 __ATTR(pmic_die_revision, S_IRUGO,
816 msm_get_pmic_die_revision, NULL);
817
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818static struct sysdev_class soc_sysdev_class = {
819 .name = "soc",
820};
821
822static struct sys_device soc_sys_device = {
823 .id = 0,
824 .cls = &soc_sysdev_class,
825};
826
827static int __init socinfo_create_files(struct sys_device *dev,
828 struct sysdev_attribute files[],
829 int size)
830{
831 int i;
832 for (i = 0; i < size; i++) {
833 int err = sysdev_create_file(dev, &files[i]);
834 if (err) {
835 pr_err("%s: sysdev_create_file(%s)=%d\n",
836 __func__, files[i].attr.name, err);
837 return err;
838 }
839 }
840 return 0;
841}
842
Stephen Boyd69a22e42012-02-22 09:16:07 -0800843static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844{
Syed Rameez Mustafacf645e82012-07-06 19:00:49 -0700845 if (machine_is_msm8960_cdp())
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700846 dummy_socinfo.id = 87;
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700847 else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp())
848 dummy_socinfo.id = 104;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700849 else if (early_machine_is_msm8974()) {
Sathish Ambleya99d6852011-10-31 15:50:55 -0700850 dummy_socinfo.id = 126;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700851 strlcpy(dummy_socinfo.build_id, "msm8974 - ",
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800852 sizeof(dummy_socinfo.build_id));
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700853 } else if (early_machine_is_msm9625()) {
Joel King8e0bf672012-05-18 15:40:40 -0700854 dummy_socinfo.id = 134;
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700855 strlcpy(dummy_socinfo.build_id, "msm9625 - ",
856 sizeof(dummy_socinfo.build_id));
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700857 } else if (early_machine_is_msm8226()) {
858 dummy_socinfo.id = 145;
859 strlcpy(dummy_socinfo.build_id, "msm8226 - ",
860 sizeof(dummy_socinfo.build_id));
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800861 } else if (machine_is_msm8625_rumi3())
Taniya Dasa04e1892011-11-16 14:49:12 +0530862 dummy_socinfo.id = 127;
Ravi Kumar V754282d2012-08-31 22:32:20 +0530863 else if (early_machine_is_mpq8092()) {
864 dummy_socinfo.id = 146;
865 strlcpy(dummy_socinfo.build_id, "mpq8092 - ",
866 sizeof(dummy_socinfo.build_id));
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800867 } else if (early_machine_is_msm8610()) {
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700868 dummy_socinfo.id = 147;
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800869 strlcpy(dummy_socinfo.build_id, "msm8610 - ",
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700870 sizeof(dummy_socinfo.build_id));
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800871 } else if (early_machine_is_msmzinc()) {
872 dummy_socinfo.id = 178;
873 strlcpy(dummy_socinfo.build_id, "msmzinc - ",
874 sizeof(dummy_socinfo.build_id));
Ravi Kumar V754282d2012-08-31 22:32:20 +0530875 }
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800876 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
877 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 return (void *) &dummy_socinfo;
879}
880
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800881static void __init populate_soc_sysfs_files(struct device *msm_soc_device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700882{
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800883 uint32_t legacy_format = socinfo_get_format();
Jin Hong9b556c32012-08-13 23:06:26 -0700884
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800885 device_create_file(msm_soc_device, &msm_soc_attr_vendor);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700886
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800887 switch (legacy_format) {
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800888 case 8:
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800889 case 7:
890 device_create_file(msm_soc_device,
891 &msm_soc_attr_pmic_model);
892 device_create_file(msm_soc_device,
893 &msm_soc_attr_pmic_die_revision);
894 case 6:
895 device_create_file(msm_soc_device,
896 &msm_soc_attr_platform_subtype);
897 case 5:
898 device_create_file(msm_soc_device,
899 &msm_soc_attr_accessory_chip);
900 case 4:
901 device_create_file(msm_soc_device,
902 &msm_soc_attr_platform_version);
903 case 3:
904 device_create_file(msm_soc_device,
905 &msm_soc_attr_hw_platform);
906 case 2:
907 device_create_file(msm_soc_device,
908 &msm_soc_attr_raw_id);
909 device_create_file(msm_soc_device,
910 &msm_soc_attr_raw_version);
911 case 1:
912 device_create_file(msm_soc_device,
913 &msm_soc_attr_build_id);
914 break;
915 default:
916 pr_err("%s:Unknown socinfo format:%u\n", __func__,
917 legacy_format);
918 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700919 }
920
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800921 return;
922}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800924static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
925{
926 uint32_t soc_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700927
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800928 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id());
929 soc_dev_attr->machine = "Snapdragon";
930 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
931 SOCINFO_VERSION_MAJOR(soc_version),
932 SOCINFO_VERSION_MINOR(soc_version));
933 return;
934
935}
936
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -0800937static int __init socinfo_init_sysdev(void)
938{
939 int err;
940 struct device *msm_soc_device;
941 struct soc_device *soc_dev;
942 struct soc_device_attribute *soc_dev_attr;
943
944 if (!socinfo) {
945 pr_err("%s: No socinfo found!\n", __func__);
946 return -ENODEV;
947 }
948
949 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
950 if (!soc_dev_attr) {
951 pr_err("%s: Soc Device alloc failed!\n", __func__);
952 return -ENOMEM;
953 }
954
955 soc_info_populate(soc_dev_attr);
956 soc_dev = soc_device_register(soc_dev_attr);
957 if (IS_ERR_OR_NULL(soc_dev)) {
958 kfree(soc_dev_attr);
959 pr_err("%s: Soc device register failed\n", __func__);
960 return -EIO;
961 }
962
963 msm_soc_device = soc_device_to_device(soc_dev);
964 populate_soc_sysfs_files(msm_soc_device);
965 err = sysdev_class_register(&soc_sysdev_class);
966 if (err) {
967 pr_err("%s: sysdev_class_register fail (%d)\n",
968 __func__, err);
969 return err;
970 }
971 err = sysdev_register(&soc_sys_device);
972 if (err) {
973 pr_err("%s: sysdev_register fail (%d)\n",
974 __func__, err);
975 return err;
976 }
977 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
978 ARRAY_SIZE(socinfo_v1_files));
979 if (socinfo->v1.format < 2)
980 return err;
981 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
982 ARRAY_SIZE(socinfo_v2_files));
983
984 if (socinfo->v1.format < 3)
985 return err;
986
987 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
988 ARRAY_SIZE(socinfo_v3_files));
989
990 if (socinfo->v1.format < 4)
991 return err;
992
993 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
994 ARRAY_SIZE(socinfo_v4_files));
995
996 if (socinfo->v1.format < 5)
997 return err;
998
999 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
1000 ARRAY_SIZE(socinfo_v5_files));
1001
1002 if (socinfo->v1.format < 6)
1003 return err;
1004
1005 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
1006 ARRAY_SIZE(socinfo_v6_files));
1007
1008 if (socinfo->v1.format < 7)
1009 return err;
1010
1011 socinfo_create_files(&soc_sys_device, socinfo_v7_files,
1012 ARRAY_SIZE(socinfo_v7_files));
1013
1014 return 0;
1015}
1016
1017arch_initcall(socinfo_init_sysdev);
1018
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001019static void socinfo_print(void)
1020{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001021 switch (socinfo->v1.format) {
1022 case 1:
1023 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
1024 __func__, socinfo->v1.format, socinfo->v1.id,
1025 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1026 SOCINFO_VERSION_MINOR(socinfo->v1.version));
1027 break;
1028 case 2:
1029 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1030 "raw_id=%u, raw_ver=%u\n",
1031 __func__, socinfo->v1.format, socinfo->v1.id,
1032 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1033 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1034 socinfo->v2.raw_id, socinfo->v2.raw_version);
1035 break;
1036 case 3:
1037 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1038 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
1039 __func__, socinfo->v1.format, socinfo->v1.id,
1040 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1041 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1042 socinfo->v2.raw_id, socinfo->v2.raw_version,
1043 socinfo->v3.hw_platform);
1044 break;
1045 case 4:
1046 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1047 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
1048 __func__, socinfo->v1.format, socinfo->v1.id,
1049 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1050 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1051 socinfo->v2.raw_id, socinfo->v2.raw_version,
1052 socinfo->v3.hw_platform, socinfo->v4.platform_version);
1053 break;
1054 case 5:
1055 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1056 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1057 " accessory_chip=%u\n", __func__, socinfo->v1.format,
1058 socinfo->v1.id,
1059 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1060 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1061 socinfo->v2.raw_id, socinfo->v2.raw_version,
1062 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1063 socinfo->v5.accessory_chip);
1064 break;
1065 case 6:
1066 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1067 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1068 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
1069 socinfo->v1.format,
1070 socinfo->v1.id,
1071 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1072 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1073 socinfo->v2.raw_id, socinfo->v2.raw_version,
1074 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1075 socinfo->v5.accessory_chip,
1076 socinfo->v6.hw_platform_subtype);
1077 break;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001078 case 8:
Jin Hong9b556c32012-08-13 23:06:26 -07001079 case 7:
1080 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",
1081 __func__,
1082 socinfo->v1.format,
1083 socinfo->v1.id,
1084 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1085 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1086 socinfo->v2.raw_id, socinfo->v2.raw_version,
1087 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1088 socinfo->v5.accessory_chip,
1089 socinfo->v6.hw_platform_subtype,
1090 socinfo->v7.pmic_model,
1091 socinfo->v7.pmic_die_revision);
1092 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093 default:
1094 pr_err("%s: Unknown format found\n", __func__);
1095 break;
1096 }
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001097}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001098
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001099int __init socinfo_init(void)
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001100{
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001101 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v8));
1102
1103 if (!socinfo)
1104 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1105 sizeof(struct socinfo_v7));
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001106
1107 if (!socinfo)
1108 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1109 sizeof(struct socinfo_v6));
1110
1111 if (!socinfo)
1112 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1113 sizeof(struct socinfo_v5));
1114
1115 if (!socinfo)
1116 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1117 sizeof(struct socinfo_v4));
1118
1119 if (!socinfo)
1120 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1121 sizeof(struct socinfo_v3));
1122
1123 if (!socinfo)
1124 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1125 sizeof(struct socinfo_v2));
1126
1127 if (!socinfo)
1128 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1129 sizeof(struct socinfo_v1));
1130
1131 if (!socinfo) {
1132 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n",
1133 __func__);
1134 socinfo = setup_dummy_socinfo();
1135 }
1136
1137 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
1138 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
1139 "New IDs added! ID => CPU mapping might need an update.\n");
1140
1141 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
1142 cur_cpu = cpu_of_id[socinfo->v1.id];
1143
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -08001144 boot_stats_init();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001145 socinfo_print();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001146
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001147 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001148}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001149
1150const int get_core_count(void)
1151{
1152 if (!(read_cpuid_mpidr() & BIT(31)))
1153 return 1;
1154
Jin Hongc5f5d542012-04-12 16:48:51 -07001155 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001156 return 1;
1157
1158 /* 1 + the PART[1:0] field of MIDR */
1159 return ((read_cpuid_id() >> 4) & 3) + 1;
1160}
1161
1162const int read_msm_cpu_type(void)
1163{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001164 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
1165 return socinfo_get_msm_cpu();
1166
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001167 switch (read_cpuid_id()) {
1168 case 0x510F02D0:
1169 case 0x510F02D2:
1170 case 0x510F02D4:
1171 return MSM_CPU_8X60;
1172
1173 case 0x510F04D0:
1174 case 0x510F04D1:
1175 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001176 case 0x511F04D0:
1177 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001178 return MSM_CPU_8960;
1179
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001180 case 0x51404D11: /* We can't get here unless we are in bringup */
1181 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001182
1183 case 0x510F06F0:
1184 return MSM_CPU_8064;
1185
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001186 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001187 case 0x511F06F2:
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001188 case 0x512F06F0:
1189 return MSM_CPU_8974;
1190
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001191 default:
1192 return MSM_CPU_UNKNOWN;
1193 };
1194}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001195
Jin Hong12b8b432012-07-18 10:00:31 -07001196const int cpu_is_krait(void)
1197{
1198 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
1199}
1200
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001201const int cpu_is_krait_v1(void)
1202{
1203 switch (read_cpuid_id()) {
1204 case 0x510F04D0:
1205 case 0x510F04D1:
1206 case 0x510F04D2:
1207 return 1;
1208
1209 default:
1210 return 0;
1211 };
1212}
Jin Hong12b8b432012-07-18 10:00:31 -07001213
1214const int cpu_is_krait_v2(void)
1215{
1216 switch (read_cpuid_id()) {
1217 case 0x511F04D0:
1218 case 0x511F04D1:
1219 case 0x511F04D2:
1220 case 0x511F04D3:
1221 case 0x511F04D4:
1222
1223 case 0x510F06F0:
1224 case 0x510F06F1:
1225 case 0x510F06F2:
1226 return 1;
1227
1228 default:
1229 return 0;
1230 };
1231}
Joel King824bd1f2012-08-19 12:55:49 -07001232
1233const int cpu_is_krait_v3(void)
1234{
1235 switch (read_cpuid_id()) {
1236 case 0x512F04D0:
1237 case 0x511F06F0:
1238 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001239 case 0x511F06F2:
Joel King824bd1f2012-08-19 12:55:49 -07001240 case 0x510F05D0:
1241 return 1;
1242
1243 default:
1244 return 0;
1245 };
1246}