blob: 0c02b517a937748030b053b0b20e019f51eadf89 [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>
Jeff Hugo5ba15fe2013-05-06 14:24:24 -060030#include <mach/msm_smem.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031
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,
David Ng32dfa3c2013-03-19 16:55:54 -070047 HW_PLATFORM_QRD = 11,
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053048 HW_PLATFORM_HRD = 13,
49 HW_PLATFORM_DTV = 14,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050 HW_PLATFORM_INVALID
51};
52
53const char *hw_platform[] = {
54 [HW_PLATFORM_UNKNOWN] = "Unknown",
55 [HW_PLATFORM_SURF] = "Surf",
56 [HW_PLATFORM_FFA] = "FFA",
57 [HW_PLATFORM_FLUID] = "Fluid",
58 [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040059 [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF",
Jin Hong49753322011-12-15 16:55:37 -080060 [HW_PLATFORM_MTP] = "MTP",
61 [HW_PLATFORM_LIQUID] = "Liquid",
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053062 [HW_PLATFORM_DRAGON] = "Dragon",
David Ng32dfa3c2013-03-19 16:55:54 -070063 [HW_PLATFORM_QRD] = "QRD",
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053064 [HW_PLATFORM_HRD] = "HRD",
65 [HW_PLATFORM_DTV] = "DTV",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066};
67
68enum {
69 ACCESSORY_CHIP_UNKNOWN = 0,
70 ACCESSORY_CHIP_CHARM = 58,
71};
72
73enum {
74 PLATFORM_SUBTYPE_UNKNOWN = 0x0,
75 PLATFORM_SUBTYPE_CHARM = 0x1,
76 PLATFORM_SUBTYPE_STRANGE = 0x2,
77 PLATFORM_SUBTYPE_STRANGE_2A = 0x3,
78 PLATFORM_SUBTYPE_INVALID,
79};
80
81const char *hw_platform_subtype[] = {
82 [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown",
83 [PLATFORM_SUBTYPE_CHARM] = "charm",
84 [PLATFORM_SUBTYPE_STRANGE] = "strange",
85 [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a,"
86};
87
88/* Used to parse shared memory. Must match the modem. */
89struct socinfo_v1 {
90 uint32_t format;
91 uint32_t id;
92 uint32_t version;
93 char build_id[BUILD_ID_LENGTH];
94};
95
96struct socinfo_v2 {
97 struct socinfo_v1 v1;
98
99 /* only valid when format==2 */
100 uint32_t raw_id;
101 uint32_t raw_version;
102};
103
104struct socinfo_v3 {
105 struct socinfo_v2 v2;
106
107 /* only valid when format==3 */
108 uint32_t hw_platform;
109};
110
111struct socinfo_v4 {
112 struct socinfo_v3 v3;
113
114 /* only valid when format==4 */
115 uint32_t platform_version;
116};
117
118struct socinfo_v5 {
119 struct socinfo_v4 v4;
120
121 /* only valid when format==5 */
122 uint32_t accessory_chip;
123};
124
125struct socinfo_v6 {
126 struct socinfo_v5 v5;
127
128 /* only valid when format==6 */
129 uint32_t hw_platform_subtype;
130};
131
Jin Hong9b556c32012-08-13 23:06:26 -0700132struct socinfo_v7 {
133 struct socinfo_v6 v6;
134
135 /* only valid when format==7 */
136 uint32_t pmic_model;
137 uint32_t pmic_die_revision;
138};
139
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800140struct socinfo_v8 {
141 struct socinfo_v7 v7;
142
143 /* only valid when format==8*/
144 uint32_t pmic_model_1;
145 uint32_t pmic_die_revision_1;
146 uint32_t pmic_model_2;
147 uint32_t pmic_die_revision_2;
148};
149
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150static union {
151 struct socinfo_v1 v1;
152 struct socinfo_v2 v2;
153 struct socinfo_v3 v3;
154 struct socinfo_v4 v4;
155 struct socinfo_v5 v5;
156 struct socinfo_v6 v6;
Jin Hong9b556c32012-08-13 23:06:26 -0700157 struct socinfo_v7 v7;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800158 struct socinfo_v8 v8;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159} *socinfo;
160
161static enum msm_cpu cpu_of_id[] = {
162
163 /* 7x01 IDs */
164 [1] = MSM_CPU_7X01,
165 [16] = MSM_CPU_7X01,
166 [17] = MSM_CPU_7X01,
167 [18] = MSM_CPU_7X01,
168 [19] = MSM_CPU_7X01,
169 [23] = MSM_CPU_7X01,
170 [25] = MSM_CPU_7X01,
171 [26] = MSM_CPU_7X01,
172 [32] = MSM_CPU_7X01,
173 [33] = MSM_CPU_7X01,
174 [34] = MSM_CPU_7X01,
175 [35] = MSM_CPU_7X01,
176
177 /* 7x25 IDs */
178 [20] = MSM_CPU_7X25,
179 [21] = MSM_CPU_7X25, /* 7225 */
180 [24] = MSM_CPU_7X25, /* 7525 */
181 [27] = MSM_CPU_7X25, /* 7625 */
182 [39] = MSM_CPU_7X25,
183 [40] = MSM_CPU_7X25,
184 [41] = MSM_CPU_7X25,
185 [42] = MSM_CPU_7X25,
186 [62] = MSM_CPU_7X25, /* 7625-1 */
187 [63] = MSM_CPU_7X25, /* 7225-1 */
188 [66] = MSM_CPU_7X25, /* 7225-2 */
189
190
191 /* 7x27 IDs */
192 [43] = MSM_CPU_7X27,
193 [44] = MSM_CPU_7X27,
194 [61] = MSM_CPU_7X27,
195 [67] = MSM_CPU_7X27, /* 7227-1 */
196 [68] = MSM_CPU_7X27, /* 7627-1 */
197 [69] = MSM_CPU_7X27, /* 7627-2 */
198
199
200 /* 8x50 IDs */
201 [30] = MSM_CPU_8X50,
202 [36] = MSM_CPU_8X50,
203 [37] = MSM_CPU_8X50,
204 [38] = MSM_CPU_8X50,
205
206 /* 7x30 IDs */
207 [59] = MSM_CPU_7X30,
208 [60] = MSM_CPU_7X30,
209
210 /* 8x55 IDs */
211 [74] = MSM_CPU_8X55,
212 [75] = MSM_CPU_8X55,
213 [85] = MSM_CPU_8X55,
214
215 /* 8x60 IDs */
216 [70] = MSM_CPU_8X60,
217 [71] = MSM_CPU_8X60,
218 [86] = MSM_CPU_8X60,
219
220 /* 8960 IDs */
221 [87] = MSM_CPU_8960,
222
223 /* 7x25A IDs */
224 [88] = MSM_CPU_7X25A,
225 [89] = MSM_CPU_7X25A,
226 [96] = MSM_CPU_7X25A,
227
228 /* 7x27A IDs */
229 [90] = MSM_CPU_7X27A,
230 [91] = MSM_CPU_7X27A,
231 [92] = MSM_CPU_7X27A,
232 [97] = MSM_CPU_7X27A,
233
234 /* FSM9xxx ID */
235 [94] = FSM_CPU_9XXX,
236 [95] = FSM_CPU_9XXX,
237
238 /* 7x25AA ID */
239 [98] = MSM_CPU_7X25AA,
240 [99] = MSM_CPU_7X25AA,
241 [100] = MSM_CPU_7X25AA,
242
Joel Kingbf2ff512011-07-22 13:43:11 -0700243 /* 7x27AA ID */
244 [101] = MSM_CPU_7X27AA,
245 [102] = MSM_CPU_7X27AA,
246 [103] = MSM_CPU_7X27AA,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530247 [136] = MSM_CPU_7X27AA,
Joel Kingbf2ff512011-07-22 13:43:11 -0700248
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700249 /* 9x15 ID */
250 [104] = MSM_CPU_9615,
Rohit Vaswani865f2ca2011-10-03 17:40:42 -0700251 [105] = MSM_CPU_9615,
Rohit Vaswani7a83fa92012-01-11 15:05:39 -0800252 [106] = MSM_CPU_9615,
253 [107] = MSM_CPU_9615,
Abhimanyu Kapur45149122013-03-20 01:07:52 -0700254 [171] = MSM_CPU_9615,
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700255
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700256 /* 8064 IDs */
Joel Kingbf2ff512011-07-22 13:43:11 -0700257 [109] = MSM_CPU_8064,
258
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700259 /* 8930 IDs */
260 [116] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800261 [117] = MSM_CPU_8930,
262 [118] = MSM_CPU_8930,
263 [119] = MSM_CPU_8930,
David Ngc103f1c2013-02-12 18:49:25 -0800264 [179] = MSM_CPU_8930,
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800265
266 /* 8627 IDs */
267 [120] = MSM_CPU_8627,
268 [121] = MSM_CPU_8627,
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700269
Jin Hong0698b562011-11-05 13:57:25 -0700270 /* 8660A ID */
271 [122] = MSM_CPU_8960,
272
273 /* 8260A ID */
274 [123] = MSM_CPU_8960,
275
276 /* 8060A ID */
277 [124] = MSM_CPU_8960,
278
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700279 /* 8974 IDs */
280 [126] = MSM_CPU_8974,
Stepan Moskovchenko22dce832013-03-25 14:36:52 -0700281 [184] = MSM_CPU_8974,
Stepan Moskovchenko2f06d832013-05-06 12:52:32 -0700282 [185] = MSM_CPU_8974,
283 [186] = MSM_CPU_8974,
Sathish Ambleya99d6852011-10-31 15:50:55 -0700284
Taniya Dasa04e1892011-11-16 14:49:12 +0530285 /* 8625 IDs */
286 [127] = MSM_CPU_8625,
287 [128] = MSM_CPU_8625,
288 [129] = MSM_CPU_8625,
Kaushal Kumar1f8876a2012-08-21 14:53:50 +0530289 [137] = MSM_CPU_8625,
Kaushal Kumarc84b9c22012-10-12 12:47:55 +0530290 [167] = MSM_CPU_8625,
Taniya Dasa04e1892011-11-16 14:49:12 +0530291
Joel King8e0bf672012-05-18 15:40:40 -0700292 /* 8064 MPQ ID */
293 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700294
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530295 /* 7x25AB IDs */
296 [131] = MSM_CPU_7X25AB,
297 [132] = MSM_CPU_7X25AB,
298 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530299 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530300
Joel King8e0bf672012-05-18 15:40:40 -0700301 /* 9625 IDs */
302 [134] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800303 [148] = MSM_CPU_9625,
Abhimanyu Kapur0e088bb2013-01-08 18:41:17 -0800304 [149] = MSM_CPU_9625,
305 [150] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800306 [151] = MSM_CPU_9625,
307 [152] = MSM_CPU_9625,
308 [173] = MSM_CPU_9625,
309 [174] = MSM_CPU_9625,
310 [175] = MSM_CPU_9625,
Joel King8e0bf672012-05-18 15:40:40 -0700311
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700312 /* 8960AB IDs */
313 [138] = MSM_CPU_8960AB,
314 [139] = MSM_CPU_8960AB,
315 [140] = MSM_CPU_8960AB,
316 [141] = MSM_CPU_8960AB,
317
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700318 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700319 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700320 [143] = MSM_CPU_8930AA,
321 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko9e83cb92012-10-22 18:52:06 -0700322 [160] = MSM_CPU_8930AA,
David Ngc103f1c2013-02-12 18:49:25 -0800323 [180] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700324
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700325 /* 8226 IDs */
326 [145] = MSM_CPU_8226,
327
Ravi Kumar V754282d2012-08-31 22:32:20 +0530328 /* 8092 IDs */
329 [146] = MSM_CPU_8092,
330
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800331 /* 8610 IDs */
332 [147] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700333 [161] = MSM_CPU_8610,
334 [162] = MSM_CPU_8610,
335 [163] = MSM_CPU_8610,
336 [164] = MSM_CPU_8610,
David Nge7b76b82013-04-10 14:59:52 -0700337 [165] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700338 [166] = MSM_CPU_8610,
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700339
Jay Chokshib2de5092012-09-19 18:28:12 -0700340 /* 8064AB IDs */
341 [153] = MSM_CPU_8064AB,
342
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700343 /* 8930AB IDs */
344 [154] = MSM_CPU_8930AB,
345 [155] = MSM_CPU_8930AB,
346 [156] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530347 [157] = MSM_CPU_8930AB,
David Ngc103f1c2013-02-12 18:49:25 -0800348 [181] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530349
350 /* 8625Q IDs */
351 [168] = MSM_CPU_8625Q,
352 [169] = MSM_CPU_8625Q,
353 [170] = MSM_CPU_8625Q,
354
Jay Chokshif9294742013-01-15 13:06:27 -0800355 /* 8064AA IDs */
356 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700357
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700358 /* 8084 IDs */
359 [178] = MSM_CPU_8084,
Stepan Moskovchenko55dfdc32013-01-24 15:48:23 -0800360
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700361 /* krypton IDs */
362 [187] = MSM_CPU_KRYPTON,
363
Rohit Vaswanic3df8b92013-03-20 19:11:15 -0700364 /* FSM9900 ID */
365 [188] = FSM_CPU_9900,
366
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700367 /* Uninitialized IDs are not known to run Linux.
368 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
369 considered as unknown CPU. */
370};
371
372static enum msm_cpu cur_cpu;
373
374static struct socinfo_v1 dummy_socinfo = {
375 .format = 1,
376 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377};
378
379uint32_t socinfo_get_id(void)
380{
381 return (socinfo) ? socinfo->v1.id : 0;
382}
383EXPORT_SYMBOL_GPL(socinfo_get_id);
384
385uint32_t socinfo_get_version(void)
386{
387 return (socinfo) ? socinfo->v1.version : 0;
388}
389
390char *socinfo_get_build_id(void)
391{
392 return (socinfo) ? socinfo->v1.build_id : NULL;
393}
394
395uint32_t socinfo_get_raw_id(void)
396{
397 return socinfo ?
398 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
399 : 0;
400}
401
402uint32_t socinfo_get_raw_version(void)
403{
404 return socinfo ?
405 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
406 : 0;
407}
408
409uint32_t socinfo_get_platform_type(void)
410{
411 return socinfo ?
412 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
413 : 0;
414}
415
416
417uint32_t socinfo_get_platform_version(void)
418{
419 return socinfo ?
420 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
421 : 0;
422}
423
424/* This information is directly encoded by the machine id */
425/* Thus no external callers rely on this information at the moment */
426static uint32_t socinfo_get_accessory_chip(void)
427{
428 return socinfo ?
429 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
430 : 0;
431}
432
433uint32_t socinfo_get_platform_subtype(void)
434{
435 return socinfo ?
436 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
437 : 0;
438}
439
Jin Hong9b556c32012-08-13 23:06:26 -0700440enum pmic_model socinfo_get_pmic_model(void)
441{
442 return socinfo ?
443 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
444 : PMIC_MODEL_UNKNOWN)
445 : PMIC_MODEL_UNKNOWN;
446}
447
448uint32_t socinfo_get_pmic_die_revision(void)
449{
450 return socinfo ?
451 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
452 : 0;
453}
454
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800455static uint32_t socinfo_get_format(void)
456{
457 return socinfo ? socinfo->v1.format : 0;
458}
459
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700460enum msm_cpu socinfo_get_msm_cpu(void)
461{
462 return cur_cpu;
463}
464EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
465
466static ssize_t
467socinfo_show_id(struct sys_device *dev,
468 struct sysdev_attribute *attr,
469 char *buf)
470{
471 if (!socinfo) {
472 pr_err("%s: No socinfo found!\n", __func__);
473 return 0;
474 }
475
476 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
477}
478
479static ssize_t
480socinfo_show_version(struct sys_device *dev,
481 struct sysdev_attribute *attr,
482 char *buf)
483{
484 uint32_t version;
485
486 if (!socinfo) {
487 pr_err("%s: No socinfo found!\n", __func__);
488 return 0;
489 }
490
491 version = socinfo_get_version();
492 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
493 SOCINFO_VERSION_MAJOR(version),
494 SOCINFO_VERSION_MINOR(version));
495}
496
497static ssize_t
498socinfo_show_build_id(struct sys_device *dev,
499 struct sysdev_attribute *attr,
500 char *buf)
501{
502 if (!socinfo) {
503 pr_err("%s: No socinfo found!\n", __func__);
504 return 0;
505 }
506
507 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
508}
509
510static ssize_t
511socinfo_show_raw_id(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 ID not available!\n", __func__);
521 return 0;
522 }
523
524 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
525}
526
527static ssize_t
528socinfo_show_raw_version(struct sys_device *dev,
529 struct sysdev_attribute *attr,
530 char *buf)
531{
532 if (!socinfo) {
533 pr_err("%s: No socinfo found!\n", __func__);
534 return 0;
535 }
536 if (socinfo->v1.format < 2) {
537 pr_err("%s: Raw version not available!\n", __func__);
538 return 0;
539 }
540
541 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
542}
543
544static ssize_t
545socinfo_show_platform_type(struct sys_device *dev,
546 struct sysdev_attribute *attr,
547 char *buf)
548{
549 uint32_t hw_type;
550
551 if (!socinfo) {
552 pr_err("%s: No socinfo found!\n", __func__);
553 return 0;
554 }
555 if (socinfo->v1.format < 3) {
556 pr_err("%s: platform type not available!\n", __func__);
557 return 0;
558 }
559
560 hw_type = socinfo_get_platform_type();
561 if (hw_type >= HW_PLATFORM_INVALID) {
562 pr_err("%s: Invalid hardware platform type found\n",
563 __func__);
564 hw_type = HW_PLATFORM_UNKNOWN;
565 }
566
567 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
568}
569
570static ssize_t
571socinfo_show_platform_version(struct sys_device *dev,
572 struct sysdev_attribute *attr,
573 char *buf)
574{
575
576 if (!socinfo) {
577 pr_err("%s: No socinfo found!\n", __func__);
578 return 0;
579 }
580 if (socinfo->v1.format < 4) {
581 pr_err("%s: platform version not available!\n", __func__);
582 return 0;
583 }
584
585 return snprintf(buf, PAGE_SIZE, "%u\n",
586 socinfo_get_platform_version());
587}
588
589static ssize_t
590socinfo_show_accessory_chip(struct sys_device *dev,
591 struct sysdev_attribute *attr,
592 char *buf)
593{
594 if (!socinfo) {
595 pr_err("%s: No socinfo found!\n", __func__);
596 return 0;
597 }
598 if (socinfo->v1.format < 5) {
599 pr_err("%s: accessory chip not available!\n", __func__);
600 return 0;
601 }
602
603 return snprintf(buf, PAGE_SIZE, "%u\n",
604 socinfo_get_accessory_chip());
605}
606
607static ssize_t
608socinfo_show_platform_subtype(struct sys_device *dev,
609 struct sysdev_attribute *attr,
610 char *buf)
611{
612 uint32_t hw_subtype;
613 if (!socinfo) {
614 pr_err("%s: No socinfo found!\n", __func__);
615 return 0;
616 }
617 if (socinfo->v1.format < 6) {
618 pr_err("%s: platform subtype not available!\n", __func__);
619 return 0;
620 }
621
622 hw_subtype = socinfo_get_platform_subtype();
623 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
624 pr_err("%s: Invalid hardware platform sub type found\n",
625 __func__);
626 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
627 }
628 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
629 hw_platform_subtype[hw_subtype]);
630}
631
Jin Hong9b556c32012-08-13 23:06:26 -0700632static ssize_t
633socinfo_show_pmic_model(struct sys_device *dev,
634 struct sysdev_attribute *attr,
635 char *buf)
636{
637 if (!socinfo) {
638 pr_err("%s: No socinfo found!\n", __func__);
639 return 0;
640 }
641 if (socinfo->v1.format < 7) {
642 pr_err("%s: pmic_model not available!\n", __func__);
643 return 0;
644 }
645
646 return snprintf(buf, PAGE_SIZE, "%u\n",
647 socinfo_get_pmic_model());
648}
649
650static ssize_t
651socinfo_show_pmic_die_revision(struct sys_device *dev,
652 struct sysdev_attribute *attr,
653 char *buf)
654{
655 if (!socinfo) {
656 pr_err("%s: No socinfo found!\n", __func__);
657 return 0;
658 }
659 if (socinfo->v1.format < 7) {
660 pr_err("%s: pmic_die_revision not available!\n", __func__);
661 return 0;
662 }
663
664 return snprintf(buf, PAGE_SIZE, "%u\n",
665 socinfo_get_pmic_die_revision());
666}
667
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800668static ssize_t
669msm_get_vendor(struct device *dev,
670 struct device_attribute *attr,
671 char *buf)
672{
673 return snprintf(buf, PAGE_SIZE, "Qualcomm\n");
674}
675
676static ssize_t
677msm_get_raw_id(struct device *dev,
678 struct device_attribute *attr,
679 char *buf)
680{
681 return snprintf(buf, PAGE_SIZE, "%u\n",
682 socinfo_get_raw_id());
683}
684
685static ssize_t
686msm_get_raw_version(struct device *dev,
687 struct device_attribute *attr,
688 char *buf)
689{
690 return snprintf(buf, PAGE_SIZE, "%u\n",
691 socinfo_get_raw_version());
692}
693
694static ssize_t
695msm_get_build_id(struct device *dev,
696 struct device_attribute *attr,
697 char *buf)
698{
699 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
700 socinfo_get_build_id());
701}
702
703static ssize_t
704msm_get_hw_platform(struct device *dev,
705 struct device_attribute *attr,
706 char *buf)
707{
708 uint32_t hw_type;
709 hw_type = socinfo_get_platform_type();
710
711 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
712 hw_platform[hw_type]);
713}
714
715static ssize_t
716msm_get_platform_version(struct device *dev,
717 struct device_attribute *attr,
718 char *buf)
719{
720 return snprintf(buf, PAGE_SIZE, "%u\n",
721 socinfo_get_platform_version());
722}
723
724static ssize_t
725msm_get_accessory_chip(struct device *dev,
726 struct device_attribute *attr,
727 char *buf)
728{
729 return snprintf(buf, PAGE_SIZE, "%u\n",
730 socinfo_get_accessory_chip());
731}
732
733static ssize_t
734msm_get_platform_subtype(struct device *dev,
735 struct device_attribute *attr,
736 char *buf)
737{
738 uint32_t hw_subtype;
739 hw_subtype = socinfo_get_platform_subtype();
740 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
741 hw_platform_subtype[hw_subtype]);
742}
743
744static ssize_t
745msm_get_pmic_model(struct device *dev,
746 struct device_attribute *attr,
747 char *buf)
748{
749 return snprintf(buf, PAGE_SIZE, "%u\n",
750 socinfo_get_pmic_model());
751}
752
753static ssize_t
754msm_get_pmic_die_revision(struct device *dev,
755 struct device_attribute *attr,
756 char *buf)
757{
758 return snprintf(buf, PAGE_SIZE, "%u\n",
759 socinfo_get_pmic_die_revision());
760}
761
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762static struct sysdev_attribute socinfo_v1_files[] = {
763 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
764 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
765 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
766};
767
768static struct sysdev_attribute socinfo_v2_files[] = {
769 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
770 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
771};
772
773static struct sysdev_attribute socinfo_v3_files[] = {
774 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
775};
776
777static struct sysdev_attribute socinfo_v4_files[] = {
778 _SYSDEV_ATTR(platform_version, 0444,
779 socinfo_show_platform_version, NULL),
780};
781
782static struct sysdev_attribute socinfo_v5_files[] = {
783 _SYSDEV_ATTR(accessory_chip, 0444,
784 socinfo_show_accessory_chip, NULL),
785};
786
787static struct sysdev_attribute socinfo_v6_files[] = {
788 _SYSDEV_ATTR(platform_subtype, 0444,
789 socinfo_show_platform_subtype, NULL),
790};
791
Jin Hong9b556c32012-08-13 23:06:26 -0700792static struct sysdev_attribute socinfo_v7_files[] = {
793 _SYSDEV_ATTR(pmic_model, 0444,
794 socinfo_show_pmic_model, NULL),
795 _SYSDEV_ATTR(pmic_die_revision, 0444,
796 socinfo_show_pmic_die_revision, NULL),
797};
798
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800799static struct device_attribute msm_soc_attr_raw_version =
800 __ATTR(raw_version, S_IRUGO, msm_get_raw_version, NULL);
801
802static struct device_attribute msm_soc_attr_raw_id =
803 __ATTR(raw_id, S_IRUGO, msm_get_raw_id, NULL);
804
805static struct device_attribute msm_soc_attr_vendor =
806 __ATTR(vendor, S_IRUGO, msm_get_vendor, NULL);
807
808static struct device_attribute msm_soc_attr_build_id =
809 __ATTR(build_id, S_IRUGO, msm_get_build_id, NULL);
810
811static struct device_attribute msm_soc_attr_hw_platform =
812 __ATTR(hw_platform, S_IRUGO, msm_get_hw_platform, NULL);
813
814
815static struct device_attribute msm_soc_attr_platform_version =
816 __ATTR(platform_version, S_IRUGO,
817 msm_get_platform_version, NULL);
818
819static struct device_attribute msm_soc_attr_accessory_chip =
820 __ATTR(accessory_chip, S_IRUGO,
821 msm_get_accessory_chip, NULL);
822
823static struct device_attribute msm_soc_attr_platform_subtype =
824 __ATTR(platform_subtype, S_IRUGO,
825 msm_get_platform_subtype, NULL);
826
827static struct device_attribute msm_soc_attr_pmic_model =
828 __ATTR(pmic_model, S_IRUGO,
829 msm_get_pmic_model, NULL);
830
831static struct device_attribute msm_soc_attr_pmic_die_revision =
832 __ATTR(pmic_die_revision, S_IRUGO,
833 msm_get_pmic_die_revision, NULL);
834
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835static struct sysdev_class soc_sysdev_class = {
836 .name = "soc",
837};
838
839static struct sys_device soc_sys_device = {
840 .id = 0,
841 .cls = &soc_sysdev_class,
842};
843
844static int __init socinfo_create_files(struct sys_device *dev,
845 struct sysdev_attribute files[],
846 int size)
847{
848 int i;
849 for (i = 0; i < size; i++) {
850 int err = sysdev_create_file(dev, &files[i]);
851 if (err) {
852 pr_err("%s: sysdev_create_file(%s)=%d\n",
853 __func__, files[i].attr.name, err);
854 return err;
855 }
856 }
857 return 0;
858}
859
Stephen Boyd69a22e42012-02-22 09:16:07 -0800860static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700861{
Stepan Moskovchenko070a05d2013-04-02 18:07:17 -0700862 if (early_machine_is_mpq8092()) {
Ravi Kumar V754282d2012-08-31 22:32:20 +0530863 dummy_socinfo.id = 146;
864 strlcpy(dummy_socinfo.build_id, "mpq8092 - ",
865 sizeof(dummy_socinfo.build_id));
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700866 } else if (early_machine_is_apq8084()) {
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800867 dummy_socinfo.id = 178;
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700868 strlcpy(dummy_socinfo.build_id, "apq8084 - ",
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800869 sizeof(dummy_socinfo.build_id));
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700870 } else if (early_machine_is_msmkrypton()) {
871 dummy_socinfo.id = 187;
872 strlcpy(dummy_socinfo.build_id, "msmkrypton - ",
873 sizeof(dummy_socinfo.build_id));
Ravi Kumar V754282d2012-08-31 22:32:20 +0530874 }
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800875 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
876 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 return (void *) &dummy_socinfo;
878}
879
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800880static void __init populate_soc_sysfs_files(struct device *msm_soc_device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881{
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800882 uint32_t legacy_format = socinfo_get_format();
Jin Hong9b556c32012-08-13 23:06:26 -0700883
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800884 device_create_file(msm_soc_device, &msm_soc_attr_vendor);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800886 switch (legacy_format) {
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800887 case 8:
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800888 case 7:
889 device_create_file(msm_soc_device,
890 &msm_soc_attr_pmic_model);
891 device_create_file(msm_soc_device,
892 &msm_soc_attr_pmic_die_revision);
893 case 6:
894 device_create_file(msm_soc_device,
895 &msm_soc_attr_platform_subtype);
896 case 5:
897 device_create_file(msm_soc_device,
898 &msm_soc_attr_accessory_chip);
899 case 4:
900 device_create_file(msm_soc_device,
901 &msm_soc_attr_platform_version);
902 case 3:
903 device_create_file(msm_soc_device,
904 &msm_soc_attr_hw_platform);
905 case 2:
906 device_create_file(msm_soc_device,
907 &msm_soc_attr_raw_id);
908 device_create_file(msm_soc_device,
909 &msm_soc_attr_raw_version);
910 case 1:
911 device_create_file(msm_soc_device,
912 &msm_soc_attr_build_id);
913 break;
914 default:
915 pr_err("%s:Unknown socinfo format:%u\n", __func__,
916 legacy_format);
917 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700918 }
919
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800920 return;
921}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800923static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
924{
925 uint32_t soc_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800927 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id());
928 soc_dev_attr->machine = "Snapdragon";
929 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
930 SOCINFO_VERSION_MAJOR(soc_version),
931 SOCINFO_VERSION_MINOR(soc_version));
932 return;
933
934}
935
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -0800936static int __init socinfo_init_sysdev(void)
937{
938 int err;
939 struct device *msm_soc_device;
940 struct soc_device *soc_dev;
941 struct soc_device_attribute *soc_dev_attr;
942
943 if (!socinfo) {
944 pr_err("%s: No socinfo found!\n", __func__);
945 return -ENODEV;
946 }
947
948 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
949 if (!soc_dev_attr) {
950 pr_err("%s: Soc Device alloc failed!\n", __func__);
951 return -ENOMEM;
952 }
953
954 soc_info_populate(soc_dev_attr);
955 soc_dev = soc_device_register(soc_dev_attr);
956 if (IS_ERR_OR_NULL(soc_dev)) {
957 kfree(soc_dev_attr);
958 pr_err("%s: Soc device register failed\n", __func__);
959 return -EIO;
960 }
961
962 msm_soc_device = soc_device_to_device(soc_dev);
963 populate_soc_sysfs_files(msm_soc_device);
964 err = sysdev_class_register(&soc_sysdev_class);
965 if (err) {
966 pr_err("%s: sysdev_class_register fail (%d)\n",
967 __func__, err);
968 return err;
969 }
970 err = sysdev_register(&soc_sys_device);
971 if (err) {
972 pr_err("%s: sysdev_register fail (%d)\n",
973 __func__, err);
974 return err;
975 }
976 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
977 ARRAY_SIZE(socinfo_v1_files));
978 if (socinfo->v1.format < 2)
979 return err;
980 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
981 ARRAY_SIZE(socinfo_v2_files));
982
983 if (socinfo->v1.format < 3)
984 return err;
985
986 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
987 ARRAY_SIZE(socinfo_v3_files));
988
989 if (socinfo->v1.format < 4)
990 return err;
991
992 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
993 ARRAY_SIZE(socinfo_v4_files));
994
995 if (socinfo->v1.format < 5)
996 return err;
997
998 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
999 ARRAY_SIZE(socinfo_v5_files));
1000
1001 if (socinfo->v1.format < 6)
1002 return err;
1003
1004 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
1005 ARRAY_SIZE(socinfo_v6_files));
1006
1007 if (socinfo->v1.format < 7)
1008 return err;
1009
1010 socinfo_create_files(&soc_sys_device, socinfo_v7_files,
1011 ARRAY_SIZE(socinfo_v7_files));
1012
1013 return 0;
1014}
1015
1016arch_initcall(socinfo_init_sysdev);
1017
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001018static void socinfo_print(void)
1019{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001020 switch (socinfo->v1.format) {
1021 case 1:
1022 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
1023 __func__, socinfo->v1.format, socinfo->v1.id,
1024 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1025 SOCINFO_VERSION_MINOR(socinfo->v1.version));
1026 break;
1027 case 2:
1028 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1029 "raw_id=%u, raw_ver=%u\n",
1030 __func__, socinfo->v1.format, socinfo->v1.id,
1031 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1032 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1033 socinfo->v2.raw_id, socinfo->v2.raw_version);
1034 break;
1035 case 3:
1036 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1037 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
1038 __func__, socinfo->v1.format, socinfo->v1.id,
1039 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1040 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1041 socinfo->v2.raw_id, socinfo->v2.raw_version,
1042 socinfo->v3.hw_platform);
1043 break;
1044 case 4:
1045 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1046 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
1047 __func__, socinfo->v1.format, socinfo->v1.id,
1048 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1049 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1050 socinfo->v2.raw_id, socinfo->v2.raw_version,
1051 socinfo->v3.hw_platform, socinfo->v4.platform_version);
1052 break;
1053 case 5:
1054 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1055 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1056 " accessory_chip=%u\n", __func__, socinfo->v1.format,
1057 socinfo->v1.id,
1058 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1059 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1060 socinfo->v2.raw_id, socinfo->v2.raw_version,
1061 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1062 socinfo->v5.accessory_chip);
1063 break;
1064 case 6:
1065 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1066 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1067 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
1068 socinfo->v1.format,
1069 socinfo->v1.id,
1070 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1071 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1072 socinfo->v2.raw_id, socinfo->v2.raw_version,
1073 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1074 socinfo->v5.accessory_chip,
1075 socinfo->v6.hw_platform_subtype);
1076 break;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001077 case 8:
Jin Hong9b556c32012-08-13 23:06:26 -07001078 case 7:
1079 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",
1080 __func__,
1081 socinfo->v1.format,
1082 socinfo->v1.id,
1083 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1084 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1085 socinfo->v2.raw_id, socinfo->v2.raw_version,
1086 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1087 socinfo->v5.accessory_chip,
1088 socinfo->v6.hw_platform_subtype,
1089 socinfo->v7.pmic_model,
1090 socinfo->v7.pmic_die_revision);
1091 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001092 default:
1093 pr_err("%s: Unknown format found\n", __func__);
1094 break;
1095 }
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001096}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001097
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001098int __init socinfo_init(void)
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001099{
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001100 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v8));
1101
1102 if (!socinfo)
1103 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1104 sizeof(struct socinfo_v7));
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001105
1106 if (!socinfo)
1107 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1108 sizeof(struct socinfo_v6));
1109
1110 if (!socinfo)
1111 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1112 sizeof(struct socinfo_v5));
1113
1114 if (!socinfo)
1115 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1116 sizeof(struct socinfo_v4));
1117
1118 if (!socinfo)
1119 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1120 sizeof(struct socinfo_v3));
1121
1122 if (!socinfo)
1123 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1124 sizeof(struct socinfo_v2));
1125
1126 if (!socinfo)
1127 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1128 sizeof(struct socinfo_v1));
1129
1130 if (!socinfo) {
1131 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n",
1132 __func__);
1133 socinfo = setup_dummy_socinfo();
1134 }
1135
1136 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
1137 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
1138 "New IDs added! ID => CPU mapping might need an update.\n");
1139
1140 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
1141 cur_cpu = cpu_of_id[socinfo->v1.id];
1142
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -08001143 boot_stats_init();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001144 socinfo_print();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001145
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001146 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001147}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001148
1149const int get_core_count(void)
1150{
1151 if (!(read_cpuid_mpidr() & BIT(31)))
1152 return 1;
1153
Jin Hongc5f5d542012-04-12 16:48:51 -07001154 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001155 return 1;
1156
1157 /* 1 + the PART[1:0] field of MIDR */
1158 return ((read_cpuid_id() >> 4) & 3) + 1;
1159}
1160
1161const int read_msm_cpu_type(void)
1162{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001163 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
1164 return socinfo_get_msm_cpu();
1165
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001166 switch (read_cpuid_id()) {
1167 case 0x510F02D0:
1168 case 0x510F02D2:
1169 case 0x510F02D4:
1170 return MSM_CPU_8X60;
1171
1172 case 0x510F04D0:
1173 case 0x510F04D1:
1174 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001175 case 0x511F04D0:
1176 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001177 return MSM_CPU_8960;
1178
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001179 case 0x51404D11: /* We can't get here unless we are in bringup */
1180 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001181
1182 case 0x510F06F0:
1183 return MSM_CPU_8064;
1184
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001185 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001186 case 0x511F06F2:
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001187 case 0x512F06F0:
1188 return MSM_CPU_8974;
1189
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001190 default:
1191 return MSM_CPU_UNKNOWN;
1192 };
1193}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001194
Jin Hong12b8b432012-07-18 10:00:31 -07001195const int cpu_is_krait(void)
1196{
1197 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
1198}
1199
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001200const int cpu_is_krait_v1(void)
1201{
1202 switch (read_cpuid_id()) {
1203 case 0x510F04D0:
1204 case 0x510F04D1:
1205 case 0x510F04D2:
1206 return 1;
1207
1208 default:
1209 return 0;
1210 };
1211}
Jin Hong12b8b432012-07-18 10:00:31 -07001212
1213const int cpu_is_krait_v2(void)
1214{
1215 switch (read_cpuid_id()) {
1216 case 0x511F04D0:
1217 case 0x511F04D1:
1218 case 0x511F04D2:
1219 case 0x511F04D3:
1220 case 0x511F04D4:
1221
1222 case 0x510F06F0:
1223 case 0x510F06F1:
1224 case 0x510F06F2:
1225 return 1;
1226
1227 default:
1228 return 0;
1229 };
1230}
Joel King824bd1f2012-08-19 12:55:49 -07001231
1232const int cpu_is_krait_v3(void)
1233{
1234 switch (read_cpuid_id()) {
1235 case 0x512F04D0:
1236 case 0x511F06F0:
1237 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001238 case 0x511F06F2:
Joel King824bd1f2012-08-19 12:55:49 -07001239 case 0x510F05D0:
1240 return 1;
1241
1242 default:
1243 return 0;
1244 };
1245}