blob: 928f5cb5fa6b08abb86c1a50ad2b7c559f97bae6 [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,
Stepan Moskovchenkof5c55ae2013-05-06 12:52:32 -0700327 [158] = MSM_CPU_8226,
328 [159] = MSM_CPU_8226,
329 [198] = MSM_CPU_8226,
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700330
Ravi Kumar V754282d2012-08-31 22:32:20 +0530331 /* 8092 IDs */
332 [146] = MSM_CPU_8092,
333
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800334 /* 8610 IDs */
335 [147] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700336 [161] = MSM_CPU_8610,
337 [162] = MSM_CPU_8610,
338 [163] = MSM_CPU_8610,
339 [164] = MSM_CPU_8610,
David Nge7b76b82013-04-10 14:59:52 -0700340 [165] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700341 [166] = MSM_CPU_8610,
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700342
Jay Chokshib2de5092012-09-19 18:28:12 -0700343 /* 8064AB IDs */
344 [153] = MSM_CPU_8064AB,
345
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700346 /* 8930AB IDs */
347 [154] = MSM_CPU_8930AB,
348 [155] = MSM_CPU_8930AB,
349 [156] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530350 [157] = MSM_CPU_8930AB,
David Ngc103f1c2013-02-12 18:49:25 -0800351 [181] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530352
353 /* 8625Q IDs */
354 [168] = MSM_CPU_8625Q,
355 [169] = MSM_CPU_8625Q,
356 [170] = MSM_CPU_8625Q,
357
Jay Chokshif9294742013-01-15 13:06:27 -0800358 /* 8064AA IDs */
359 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700360
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700361 /* 8084 IDs */
362 [178] = MSM_CPU_8084,
Stepan Moskovchenko55dfdc32013-01-24 15:48:23 -0800363
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700364 /* krypton IDs */
365 [187] = MSM_CPU_KRYPTON,
366
Rohit Vaswanic3df8b92013-03-20 19:11:15 -0700367 /* FSM9900 ID */
368 [188] = FSM_CPU_9900,
369
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700370 /* Samarium IDs */
371 [195] = MSM_CPU_SAMARIUM,
372
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700373 /* Uninitialized IDs are not known to run Linux.
374 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
375 considered as unknown CPU. */
376};
377
378static enum msm_cpu cur_cpu;
379
380static struct socinfo_v1 dummy_socinfo = {
381 .format = 1,
382 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700383};
384
385uint32_t socinfo_get_id(void)
386{
387 return (socinfo) ? socinfo->v1.id : 0;
388}
389EXPORT_SYMBOL_GPL(socinfo_get_id);
390
391uint32_t socinfo_get_version(void)
392{
393 return (socinfo) ? socinfo->v1.version : 0;
394}
395
396char *socinfo_get_build_id(void)
397{
398 return (socinfo) ? socinfo->v1.build_id : NULL;
399}
400
401uint32_t socinfo_get_raw_id(void)
402{
403 return socinfo ?
404 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
405 : 0;
406}
407
408uint32_t socinfo_get_raw_version(void)
409{
410 return socinfo ?
411 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
412 : 0;
413}
414
415uint32_t socinfo_get_platform_type(void)
416{
417 return socinfo ?
418 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
419 : 0;
420}
421
422
423uint32_t socinfo_get_platform_version(void)
424{
425 return socinfo ?
426 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
427 : 0;
428}
429
430/* This information is directly encoded by the machine id */
431/* Thus no external callers rely on this information at the moment */
432static uint32_t socinfo_get_accessory_chip(void)
433{
434 return socinfo ?
435 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
436 : 0;
437}
438
439uint32_t socinfo_get_platform_subtype(void)
440{
441 return socinfo ?
442 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
443 : 0;
444}
445
Jin Hong9b556c32012-08-13 23:06:26 -0700446enum pmic_model socinfo_get_pmic_model(void)
447{
448 return socinfo ?
449 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
450 : PMIC_MODEL_UNKNOWN)
451 : PMIC_MODEL_UNKNOWN;
452}
453
454uint32_t socinfo_get_pmic_die_revision(void)
455{
456 return socinfo ?
457 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
458 : 0;
459}
460
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800461static uint32_t socinfo_get_format(void)
462{
463 return socinfo ? socinfo->v1.format : 0;
464}
465
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466enum msm_cpu socinfo_get_msm_cpu(void)
467{
468 return cur_cpu;
469}
470EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
471
472static ssize_t
473socinfo_show_id(struct sys_device *dev,
474 struct sysdev_attribute *attr,
475 char *buf)
476{
477 if (!socinfo) {
478 pr_err("%s: No socinfo found!\n", __func__);
479 return 0;
480 }
481
482 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
483}
484
485static ssize_t
486socinfo_show_version(struct sys_device *dev,
487 struct sysdev_attribute *attr,
488 char *buf)
489{
490 uint32_t version;
491
492 if (!socinfo) {
493 pr_err("%s: No socinfo found!\n", __func__);
494 return 0;
495 }
496
497 version = socinfo_get_version();
498 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
499 SOCINFO_VERSION_MAJOR(version),
500 SOCINFO_VERSION_MINOR(version));
501}
502
503static ssize_t
504socinfo_show_build_id(struct sys_device *dev,
505 struct sysdev_attribute *attr,
506 char *buf)
507{
508 if (!socinfo) {
509 pr_err("%s: No socinfo found!\n", __func__);
510 return 0;
511 }
512
513 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
514}
515
516static ssize_t
517socinfo_show_raw_id(struct sys_device *dev,
518 struct sysdev_attribute *attr,
519 char *buf)
520{
521 if (!socinfo) {
522 pr_err("%s: No socinfo found!\n", __func__);
523 return 0;
524 }
525 if (socinfo->v1.format < 2) {
526 pr_err("%s: Raw ID not available!\n", __func__);
527 return 0;
528 }
529
530 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
531}
532
533static ssize_t
534socinfo_show_raw_version(struct sys_device *dev,
535 struct sysdev_attribute *attr,
536 char *buf)
537{
538 if (!socinfo) {
539 pr_err("%s: No socinfo found!\n", __func__);
540 return 0;
541 }
542 if (socinfo->v1.format < 2) {
543 pr_err("%s: Raw version not available!\n", __func__);
544 return 0;
545 }
546
547 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
548}
549
550static ssize_t
551socinfo_show_platform_type(struct sys_device *dev,
552 struct sysdev_attribute *attr,
553 char *buf)
554{
555 uint32_t hw_type;
556
557 if (!socinfo) {
558 pr_err("%s: No socinfo found!\n", __func__);
559 return 0;
560 }
561 if (socinfo->v1.format < 3) {
562 pr_err("%s: platform type not available!\n", __func__);
563 return 0;
564 }
565
566 hw_type = socinfo_get_platform_type();
567 if (hw_type >= HW_PLATFORM_INVALID) {
568 pr_err("%s: Invalid hardware platform type found\n",
569 __func__);
570 hw_type = HW_PLATFORM_UNKNOWN;
571 }
572
573 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
574}
575
576static ssize_t
577socinfo_show_platform_version(struct sys_device *dev,
578 struct sysdev_attribute *attr,
579 char *buf)
580{
581
582 if (!socinfo) {
583 pr_err("%s: No socinfo found!\n", __func__);
584 return 0;
585 }
586 if (socinfo->v1.format < 4) {
587 pr_err("%s: platform version not available!\n", __func__);
588 return 0;
589 }
590
591 return snprintf(buf, PAGE_SIZE, "%u\n",
592 socinfo_get_platform_version());
593}
594
595static ssize_t
596socinfo_show_accessory_chip(struct sys_device *dev,
597 struct sysdev_attribute *attr,
598 char *buf)
599{
600 if (!socinfo) {
601 pr_err("%s: No socinfo found!\n", __func__);
602 return 0;
603 }
604 if (socinfo->v1.format < 5) {
605 pr_err("%s: accessory chip not available!\n", __func__);
606 return 0;
607 }
608
609 return snprintf(buf, PAGE_SIZE, "%u\n",
610 socinfo_get_accessory_chip());
611}
612
613static ssize_t
614socinfo_show_platform_subtype(struct sys_device *dev,
615 struct sysdev_attribute *attr,
616 char *buf)
617{
618 uint32_t hw_subtype;
619 if (!socinfo) {
620 pr_err("%s: No socinfo found!\n", __func__);
621 return 0;
622 }
623 if (socinfo->v1.format < 6) {
624 pr_err("%s: platform subtype not available!\n", __func__);
625 return 0;
626 }
627
628 hw_subtype = socinfo_get_platform_subtype();
629 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
630 pr_err("%s: Invalid hardware platform sub type found\n",
631 __func__);
632 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
633 }
634 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
635 hw_platform_subtype[hw_subtype]);
636}
637
Jin Hong9b556c32012-08-13 23:06:26 -0700638static ssize_t
639socinfo_show_pmic_model(struct sys_device *dev,
640 struct sysdev_attribute *attr,
641 char *buf)
642{
643 if (!socinfo) {
644 pr_err("%s: No socinfo found!\n", __func__);
645 return 0;
646 }
647 if (socinfo->v1.format < 7) {
648 pr_err("%s: pmic_model not available!\n", __func__);
649 return 0;
650 }
651
652 return snprintf(buf, PAGE_SIZE, "%u\n",
653 socinfo_get_pmic_model());
654}
655
656static ssize_t
657socinfo_show_pmic_die_revision(struct sys_device *dev,
658 struct sysdev_attribute *attr,
659 char *buf)
660{
661 if (!socinfo) {
662 pr_err("%s: No socinfo found!\n", __func__);
663 return 0;
664 }
665 if (socinfo->v1.format < 7) {
666 pr_err("%s: pmic_die_revision not available!\n", __func__);
667 return 0;
668 }
669
670 return snprintf(buf, PAGE_SIZE, "%u\n",
671 socinfo_get_pmic_die_revision());
672}
673
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800674static ssize_t
675msm_get_vendor(struct device *dev,
676 struct device_attribute *attr,
677 char *buf)
678{
679 return snprintf(buf, PAGE_SIZE, "Qualcomm\n");
680}
681
682static ssize_t
683msm_get_raw_id(struct device *dev,
684 struct device_attribute *attr,
685 char *buf)
686{
687 return snprintf(buf, PAGE_SIZE, "%u\n",
688 socinfo_get_raw_id());
689}
690
691static ssize_t
692msm_get_raw_version(struct device *dev,
693 struct device_attribute *attr,
694 char *buf)
695{
696 return snprintf(buf, PAGE_SIZE, "%u\n",
697 socinfo_get_raw_version());
698}
699
700static ssize_t
701msm_get_build_id(struct device *dev,
702 struct device_attribute *attr,
703 char *buf)
704{
705 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
706 socinfo_get_build_id());
707}
708
709static ssize_t
710msm_get_hw_platform(struct device *dev,
711 struct device_attribute *attr,
712 char *buf)
713{
714 uint32_t hw_type;
715 hw_type = socinfo_get_platform_type();
716
717 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
718 hw_platform[hw_type]);
719}
720
721static ssize_t
722msm_get_platform_version(struct device *dev,
723 struct device_attribute *attr,
724 char *buf)
725{
726 return snprintf(buf, PAGE_SIZE, "%u\n",
727 socinfo_get_platform_version());
728}
729
730static ssize_t
731msm_get_accessory_chip(struct device *dev,
732 struct device_attribute *attr,
733 char *buf)
734{
735 return snprintf(buf, PAGE_SIZE, "%u\n",
736 socinfo_get_accessory_chip());
737}
738
739static ssize_t
740msm_get_platform_subtype(struct device *dev,
741 struct device_attribute *attr,
742 char *buf)
743{
744 uint32_t hw_subtype;
745 hw_subtype = socinfo_get_platform_subtype();
746 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
747 hw_platform_subtype[hw_subtype]);
748}
749
750static ssize_t
751msm_get_pmic_model(struct device *dev,
752 struct device_attribute *attr,
753 char *buf)
754{
755 return snprintf(buf, PAGE_SIZE, "%u\n",
756 socinfo_get_pmic_model());
757}
758
759static ssize_t
760msm_get_pmic_die_revision(struct device *dev,
761 struct device_attribute *attr,
762 char *buf)
763{
764 return snprintf(buf, PAGE_SIZE, "%u\n",
765 socinfo_get_pmic_die_revision());
766}
767
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768static struct sysdev_attribute socinfo_v1_files[] = {
769 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
770 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
771 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
772};
773
774static struct sysdev_attribute socinfo_v2_files[] = {
775 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
776 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
777};
778
779static struct sysdev_attribute socinfo_v3_files[] = {
780 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
781};
782
783static struct sysdev_attribute socinfo_v4_files[] = {
784 _SYSDEV_ATTR(platform_version, 0444,
785 socinfo_show_platform_version, NULL),
786};
787
788static struct sysdev_attribute socinfo_v5_files[] = {
789 _SYSDEV_ATTR(accessory_chip, 0444,
790 socinfo_show_accessory_chip, NULL),
791};
792
793static struct sysdev_attribute socinfo_v6_files[] = {
794 _SYSDEV_ATTR(platform_subtype, 0444,
795 socinfo_show_platform_subtype, NULL),
796};
797
Jin Hong9b556c32012-08-13 23:06:26 -0700798static struct sysdev_attribute socinfo_v7_files[] = {
799 _SYSDEV_ATTR(pmic_model, 0444,
800 socinfo_show_pmic_model, NULL),
801 _SYSDEV_ATTR(pmic_die_revision, 0444,
802 socinfo_show_pmic_die_revision, NULL),
803};
804
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800805static struct device_attribute msm_soc_attr_raw_version =
806 __ATTR(raw_version, S_IRUGO, msm_get_raw_version, NULL);
807
808static struct device_attribute msm_soc_attr_raw_id =
809 __ATTR(raw_id, S_IRUGO, msm_get_raw_id, NULL);
810
811static struct device_attribute msm_soc_attr_vendor =
812 __ATTR(vendor, S_IRUGO, msm_get_vendor, NULL);
813
814static struct device_attribute msm_soc_attr_build_id =
815 __ATTR(build_id, S_IRUGO, msm_get_build_id, NULL);
816
817static struct device_attribute msm_soc_attr_hw_platform =
818 __ATTR(hw_platform, S_IRUGO, msm_get_hw_platform, NULL);
819
820
821static struct device_attribute msm_soc_attr_platform_version =
822 __ATTR(platform_version, S_IRUGO,
823 msm_get_platform_version, NULL);
824
825static struct device_attribute msm_soc_attr_accessory_chip =
826 __ATTR(accessory_chip, S_IRUGO,
827 msm_get_accessory_chip, NULL);
828
829static struct device_attribute msm_soc_attr_platform_subtype =
830 __ATTR(platform_subtype, S_IRUGO,
831 msm_get_platform_subtype, NULL);
832
833static struct device_attribute msm_soc_attr_pmic_model =
834 __ATTR(pmic_model, S_IRUGO,
835 msm_get_pmic_model, NULL);
836
837static struct device_attribute msm_soc_attr_pmic_die_revision =
838 __ATTR(pmic_die_revision, S_IRUGO,
839 msm_get_pmic_die_revision, NULL);
840
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841static struct sysdev_class soc_sysdev_class = {
842 .name = "soc",
843};
844
845static struct sys_device soc_sys_device = {
846 .id = 0,
847 .cls = &soc_sysdev_class,
848};
849
850static int __init socinfo_create_files(struct sys_device *dev,
851 struct sysdev_attribute files[],
852 int size)
853{
854 int i;
855 for (i = 0; i < size; i++) {
856 int err = sysdev_create_file(dev, &files[i]);
857 if (err) {
858 pr_err("%s: sysdev_create_file(%s)=%d\n",
859 __func__, files[i].attr.name, err);
860 return err;
861 }
862 }
863 return 0;
864}
865
Stephen Boyd69a22e42012-02-22 09:16:07 -0800866static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867{
Stepan Moskovchenko070a05d2013-04-02 18:07:17 -0700868 if (early_machine_is_mpq8092()) {
Ravi Kumar V754282d2012-08-31 22:32:20 +0530869 dummy_socinfo.id = 146;
870 strlcpy(dummy_socinfo.build_id, "mpq8092 - ",
871 sizeof(dummy_socinfo.build_id));
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700872 } else if (early_machine_is_apq8084()) {
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800873 dummy_socinfo.id = 178;
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700874 strlcpy(dummy_socinfo.build_id, "apq8084 - ",
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800875 sizeof(dummy_socinfo.build_id));
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700876 } else if (early_machine_is_msmkrypton()) {
877 dummy_socinfo.id = 187;
878 strlcpy(dummy_socinfo.build_id, "msmkrypton - ",
879 sizeof(dummy_socinfo.build_id));
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700880 } else if (early_machine_is_msmsamarium()) {
881 dummy_socinfo.id = 195;
882 strlcpy(dummy_socinfo.build_id, "msmsamarium - ",
883 sizeof(dummy_socinfo.build_id));
Ravi Kumar V754282d2012-08-31 22:32:20 +0530884 }
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800885 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
886 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 return (void *) &dummy_socinfo;
888}
889
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800890static void __init populate_soc_sysfs_files(struct device *msm_soc_device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891{
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800892 uint32_t legacy_format = socinfo_get_format();
Jin Hong9b556c32012-08-13 23:06:26 -0700893
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800894 device_create_file(msm_soc_device, &msm_soc_attr_vendor);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800896 switch (legacy_format) {
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800897 case 8:
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800898 case 7:
899 device_create_file(msm_soc_device,
900 &msm_soc_attr_pmic_model);
901 device_create_file(msm_soc_device,
902 &msm_soc_attr_pmic_die_revision);
903 case 6:
904 device_create_file(msm_soc_device,
905 &msm_soc_attr_platform_subtype);
906 case 5:
907 device_create_file(msm_soc_device,
908 &msm_soc_attr_accessory_chip);
909 case 4:
910 device_create_file(msm_soc_device,
911 &msm_soc_attr_platform_version);
912 case 3:
913 device_create_file(msm_soc_device,
914 &msm_soc_attr_hw_platform);
915 case 2:
916 device_create_file(msm_soc_device,
917 &msm_soc_attr_raw_id);
918 device_create_file(msm_soc_device,
919 &msm_soc_attr_raw_version);
920 case 1:
921 device_create_file(msm_soc_device,
922 &msm_soc_attr_build_id);
923 break;
924 default:
925 pr_err("%s:Unknown socinfo format:%u\n", __func__,
926 legacy_format);
927 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928 }
929
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800930 return;
931}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800933static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
934{
935 uint32_t soc_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700936
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800937 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id());
938 soc_dev_attr->machine = "Snapdragon";
939 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
940 SOCINFO_VERSION_MAJOR(soc_version),
941 SOCINFO_VERSION_MINOR(soc_version));
942 return;
943
944}
945
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -0800946static int __init socinfo_init_sysdev(void)
947{
948 int err;
949 struct device *msm_soc_device;
950 struct soc_device *soc_dev;
951 struct soc_device_attribute *soc_dev_attr;
952
953 if (!socinfo) {
954 pr_err("%s: No socinfo found!\n", __func__);
955 return -ENODEV;
956 }
957
958 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
959 if (!soc_dev_attr) {
960 pr_err("%s: Soc Device alloc failed!\n", __func__);
961 return -ENOMEM;
962 }
963
964 soc_info_populate(soc_dev_attr);
965 soc_dev = soc_device_register(soc_dev_attr);
966 if (IS_ERR_OR_NULL(soc_dev)) {
967 kfree(soc_dev_attr);
968 pr_err("%s: Soc device register failed\n", __func__);
969 return -EIO;
970 }
971
972 msm_soc_device = soc_device_to_device(soc_dev);
973 populate_soc_sysfs_files(msm_soc_device);
974 err = sysdev_class_register(&soc_sysdev_class);
975 if (err) {
976 pr_err("%s: sysdev_class_register fail (%d)\n",
977 __func__, err);
978 return err;
979 }
980 err = sysdev_register(&soc_sys_device);
981 if (err) {
982 pr_err("%s: sysdev_register fail (%d)\n",
983 __func__, err);
984 return err;
985 }
986 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
987 ARRAY_SIZE(socinfo_v1_files));
988 if (socinfo->v1.format < 2)
989 return err;
990 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
991 ARRAY_SIZE(socinfo_v2_files));
992
993 if (socinfo->v1.format < 3)
994 return err;
995
996 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
997 ARRAY_SIZE(socinfo_v3_files));
998
999 if (socinfo->v1.format < 4)
1000 return err;
1001
1002 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
1003 ARRAY_SIZE(socinfo_v4_files));
1004
1005 if (socinfo->v1.format < 5)
1006 return err;
1007
1008 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
1009 ARRAY_SIZE(socinfo_v5_files));
1010
1011 if (socinfo->v1.format < 6)
1012 return err;
1013
1014 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
1015 ARRAY_SIZE(socinfo_v6_files));
1016
1017 if (socinfo->v1.format < 7)
1018 return err;
1019
1020 socinfo_create_files(&soc_sys_device, socinfo_v7_files,
1021 ARRAY_SIZE(socinfo_v7_files));
1022
1023 return 0;
1024}
1025
1026arch_initcall(socinfo_init_sysdev);
1027
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001028static void socinfo_print(void)
1029{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001030 switch (socinfo->v1.format) {
1031 case 1:
1032 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
1033 __func__, socinfo->v1.format, socinfo->v1.id,
1034 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1035 SOCINFO_VERSION_MINOR(socinfo->v1.version));
1036 break;
1037 case 2:
1038 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1039 "raw_id=%u, raw_ver=%u\n",
1040 __func__, socinfo->v1.format, socinfo->v1.id,
1041 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1042 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1043 socinfo->v2.raw_id, socinfo->v2.raw_version);
1044 break;
1045 case 3:
1046 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1047 "raw_id=%u, raw_ver=%u, hw_plat=%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);
1053 break;
1054 case 4:
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 __func__, socinfo->v1.format, 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 break;
1063 case 5:
1064 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1065 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1066 " accessory_chip=%u\n", __func__, socinfo->v1.format,
1067 socinfo->v1.id,
1068 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1069 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1070 socinfo->v2.raw_id, socinfo->v2.raw_version,
1071 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1072 socinfo->v5.accessory_chip);
1073 break;
1074 case 6:
1075 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1076 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1077 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
1078 socinfo->v1.format,
1079 socinfo->v1.id,
1080 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1081 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1082 socinfo->v2.raw_id, socinfo->v2.raw_version,
1083 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1084 socinfo->v5.accessory_chip,
1085 socinfo->v6.hw_platform_subtype);
1086 break;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001087 case 8:
Jin Hong9b556c32012-08-13 23:06:26 -07001088 case 7:
1089 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",
1090 __func__,
1091 socinfo->v1.format,
1092 socinfo->v1.id,
1093 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1094 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1095 socinfo->v2.raw_id, socinfo->v2.raw_version,
1096 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1097 socinfo->v5.accessory_chip,
1098 socinfo->v6.hw_platform_subtype,
1099 socinfo->v7.pmic_model,
1100 socinfo->v7.pmic_die_revision);
1101 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001102 default:
1103 pr_err("%s: Unknown format found\n", __func__);
1104 break;
1105 }
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001106}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001107
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001108int __init socinfo_init(void)
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001109{
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001110 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v8));
1111
1112 if (!socinfo)
1113 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1114 sizeof(struct socinfo_v7));
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001115
1116 if (!socinfo)
1117 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1118 sizeof(struct socinfo_v6));
1119
1120 if (!socinfo)
1121 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1122 sizeof(struct socinfo_v5));
1123
1124 if (!socinfo)
1125 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1126 sizeof(struct socinfo_v4));
1127
1128 if (!socinfo)
1129 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1130 sizeof(struct socinfo_v3));
1131
1132 if (!socinfo)
1133 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1134 sizeof(struct socinfo_v2));
1135
1136 if (!socinfo)
1137 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1138 sizeof(struct socinfo_v1));
1139
1140 if (!socinfo) {
1141 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n",
1142 __func__);
1143 socinfo = setup_dummy_socinfo();
1144 }
1145
1146 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
1147 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
1148 "New IDs added! ID => CPU mapping might need an update.\n");
1149
1150 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
1151 cur_cpu = cpu_of_id[socinfo->v1.id];
1152
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -08001153 boot_stats_init();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001154 socinfo_print();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001155
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001156 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001157}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001158
1159const int get_core_count(void)
1160{
1161 if (!(read_cpuid_mpidr() & BIT(31)))
1162 return 1;
1163
Jin Hongc5f5d542012-04-12 16:48:51 -07001164 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001165 return 1;
1166
1167 /* 1 + the PART[1:0] field of MIDR */
1168 return ((read_cpuid_id() >> 4) & 3) + 1;
1169}
1170
1171const int read_msm_cpu_type(void)
1172{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001173 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
1174 return socinfo_get_msm_cpu();
1175
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001176 switch (read_cpuid_id()) {
1177 case 0x510F02D0:
1178 case 0x510F02D2:
1179 case 0x510F02D4:
1180 return MSM_CPU_8X60;
1181
1182 case 0x510F04D0:
1183 case 0x510F04D1:
1184 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001185 case 0x511F04D0:
1186 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001187 return MSM_CPU_8960;
1188
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001189 case 0x51404D11: /* We can't get here unless we are in bringup */
1190 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001191
1192 case 0x510F06F0:
1193 return MSM_CPU_8064;
1194
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001195 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001196 case 0x511F06F2:
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001197 case 0x512F06F0:
1198 return MSM_CPU_8974;
1199
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001200 default:
1201 return MSM_CPU_UNKNOWN;
1202 };
1203}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001204
Jin Hong12b8b432012-07-18 10:00:31 -07001205const int cpu_is_krait(void)
1206{
1207 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
1208}
1209
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001210const int cpu_is_krait_v1(void)
1211{
1212 switch (read_cpuid_id()) {
1213 case 0x510F04D0:
1214 case 0x510F04D1:
1215 case 0x510F04D2:
1216 return 1;
1217
1218 default:
1219 return 0;
1220 };
1221}
Jin Hong12b8b432012-07-18 10:00:31 -07001222
1223const int cpu_is_krait_v2(void)
1224{
1225 switch (read_cpuid_id()) {
1226 case 0x511F04D0:
1227 case 0x511F04D1:
1228 case 0x511F04D2:
1229 case 0x511F04D3:
1230 case 0x511F04D4:
1231
1232 case 0x510F06F0:
1233 case 0x510F06F1:
1234 case 0x510F06F2:
1235 return 1;
1236
1237 default:
1238 return 0;
1239 };
1240}
Joel King824bd1f2012-08-19 12:55:49 -07001241
1242const int cpu_is_krait_v3(void)
1243{
1244 switch (read_cpuid_id()) {
1245 case 0x512F04D0:
1246 case 0x511F06F0:
1247 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001248 case 0x511F06F2:
Joel King824bd1f2012-08-19 12:55:49 -07001249 case 0x510F05D0:
1250 return 1;
1251
1252 default:
1253 return 0;
1254 };
1255}