blob: 41509f790220e29e053b008c27b6f3bc261ff86b [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
Stepan Moskovchenko015c4982013-05-06 12:52:32 -0700285 /* 8974AA IDs */
286 [208] = MSM_CPU_8974PRO_AA,
287 [211] = MSM_CPU_8974PRO_AA,
288 [214] = MSM_CPU_8974PRO_AA,
289 [217] = MSM_CPU_8974PRO_AA,
290
291 /* 8974AB IDs */
292 [209] = MSM_CPU_8974PRO_AB,
293 [212] = MSM_CPU_8974PRO_AB,
294 [215] = MSM_CPU_8974PRO_AB,
295 [218] = MSM_CPU_8974PRO_AB,
296
297 /* 8974AC IDs */
298 [194] = MSM_CPU_8974PRO_AC,
299 [210] = MSM_CPU_8974PRO_AC,
300 [213] = MSM_CPU_8974PRO_AC,
301 [216] = MSM_CPU_8974PRO_AC,
302
Taniya Dasa04e1892011-11-16 14:49:12 +0530303 /* 8625 IDs */
304 [127] = MSM_CPU_8625,
305 [128] = MSM_CPU_8625,
306 [129] = MSM_CPU_8625,
Kaushal Kumar1f8876a2012-08-21 14:53:50 +0530307 [137] = MSM_CPU_8625,
Kaushal Kumarc84b9c22012-10-12 12:47:55 +0530308 [167] = MSM_CPU_8625,
Taniya Dasa04e1892011-11-16 14:49:12 +0530309
Joel King8e0bf672012-05-18 15:40:40 -0700310 /* 8064 MPQ ID */
311 [130] = MSM_CPU_8064,
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700312
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530313 /* 7x25AB IDs */
314 [131] = MSM_CPU_7X25AB,
315 [132] = MSM_CPU_7X25AB,
316 [133] = MSM_CPU_7X25AB,
Kaushal Kumardc0beb92012-06-29 19:31:05 +0530317 [135] = MSM_CPU_7X25AB,
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530318
Joel King8e0bf672012-05-18 15:40:40 -0700319 /* 9625 IDs */
320 [134] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800321 [148] = MSM_CPU_9625,
Abhimanyu Kapur0e088bb2013-01-08 18:41:17 -0800322 [149] = MSM_CPU_9625,
323 [150] = MSM_CPU_9625,
Abhimanyu Kapur430add82013-01-28 13:51:01 -0800324 [151] = MSM_CPU_9625,
325 [152] = MSM_CPU_9625,
326 [173] = MSM_CPU_9625,
327 [174] = MSM_CPU_9625,
328 [175] = MSM_CPU_9625,
Joel King8e0bf672012-05-18 15:40:40 -0700329
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700330 /* 8960AB IDs */
331 [138] = MSM_CPU_8960AB,
332 [139] = MSM_CPU_8960AB,
333 [140] = MSM_CPU_8960AB,
334 [141] = MSM_CPU_8960AB,
335
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700336 /* 8930AA IDs */
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700337 [142] = MSM_CPU_8930AA,
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700338 [143] = MSM_CPU_8930AA,
339 [144] = MSM_CPU_8930AA,
Stepan Moskovchenko9e83cb92012-10-22 18:52:06 -0700340 [160] = MSM_CPU_8930AA,
David Ngc103f1c2013-02-12 18:49:25 -0800341 [180] = MSM_CPU_8930AA,
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700342
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700343 /* 8226 IDs */
344 [145] = MSM_CPU_8226,
Stepan Moskovchenkof5c55ae2013-05-06 12:52:32 -0700345 [158] = MSM_CPU_8226,
346 [159] = MSM_CPU_8226,
347 [198] = MSM_CPU_8226,
Syed Rameez Mustafabd714672013-05-20 15:19:37 -0700348 [199] = MSM_CPU_8226,
349 [200] = MSM_CPU_8226,
350 [205] = MSM_CPU_8226,
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700351
Ravi Kumar V754282d2012-08-31 22:32:20 +0530352 /* 8092 IDs */
353 [146] = MSM_CPU_8092,
354
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800355 /* 8610 IDs */
356 [147] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700357 [161] = MSM_CPU_8610,
358 [162] = MSM_CPU_8610,
359 [163] = MSM_CPU_8610,
360 [164] = MSM_CPU_8610,
David Nge7b76b82013-04-10 14:59:52 -0700361 [165] = MSM_CPU_8610,
Abhimanyu Kapur35bc0842013-04-19 20:02:58 -0700362 [166] = MSM_CPU_8610,
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700363
Jay Chokshib2de5092012-09-19 18:28:12 -0700364 /* 8064AB IDs */
365 [153] = MSM_CPU_8064AB,
366
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700367 /* 8930AB IDs */
368 [154] = MSM_CPU_8930AB,
369 [155] = MSM_CPU_8930AB,
370 [156] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530371 [157] = MSM_CPU_8930AB,
David Ngc103f1c2013-02-12 18:49:25 -0800372 [181] = MSM_CPU_8930AB,
Utsab Bose89b32992012-11-08 11:15:45 +0530373
374 /* 8625Q IDs */
375 [168] = MSM_CPU_8625Q,
376 [169] = MSM_CPU_8625Q,
377 [170] = MSM_CPU_8625Q,
378
Jay Chokshif9294742013-01-15 13:06:27 -0800379 /* 8064AA IDs */
380 [172] = MSM_CPU_8064AA,
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700381
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700382 /* 8084 IDs */
383 [178] = MSM_CPU_8084,
Stepan Moskovchenko55dfdc32013-01-24 15:48:23 -0800384
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700385 /* krypton IDs */
386 [187] = MSM_CPU_KRYPTON,
387
Rohit Vaswanic3df8b92013-03-20 19:11:15 -0700388 /* FSM9900 ID */
389 [188] = FSM_CPU_9900,
390
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700391 /* Samarium IDs */
392 [195] = MSM_CPU_SAMARIUM,
393
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394 /* Uninitialized IDs are not known to run Linux.
395 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
396 considered as unknown CPU. */
397};
398
399static enum msm_cpu cur_cpu;
400
401static struct socinfo_v1 dummy_socinfo = {
402 .format = 1,
403 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404};
405
406uint32_t socinfo_get_id(void)
407{
408 return (socinfo) ? socinfo->v1.id : 0;
409}
410EXPORT_SYMBOL_GPL(socinfo_get_id);
411
412uint32_t socinfo_get_version(void)
413{
414 return (socinfo) ? socinfo->v1.version : 0;
415}
416
417char *socinfo_get_build_id(void)
418{
419 return (socinfo) ? socinfo->v1.build_id : NULL;
420}
421
422uint32_t socinfo_get_raw_id(void)
423{
424 return socinfo ?
425 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
426 : 0;
427}
428
429uint32_t socinfo_get_raw_version(void)
430{
431 return socinfo ?
432 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
433 : 0;
434}
435
436uint32_t socinfo_get_platform_type(void)
437{
438 return socinfo ?
439 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
440 : 0;
441}
442
443
444uint32_t socinfo_get_platform_version(void)
445{
446 return socinfo ?
447 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
448 : 0;
449}
450
451/* This information is directly encoded by the machine id */
452/* Thus no external callers rely on this information at the moment */
453static uint32_t socinfo_get_accessory_chip(void)
454{
455 return socinfo ?
456 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
457 : 0;
458}
459
460uint32_t socinfo_get_platform_subtype(void)
461{
462 return socinfo ?
463 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
464 : 0;
465}
466
Jin Hong9b556c32012-08-13 23:06:26 -0700467enum pmic_model socinfo_get_pmic_model(void)
468{
469 return socinfo ?
470 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
471 : PMIC_MODEL_UNKNOWN)
472 : PMIC_MODEL_UNKNOWN;
473}
474
475uint32_t socinfo_get_pmic_die_revision(void)
476{
477 return socinfo ?
478 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
479 : 0;
480}
481
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800482static uint32_t socinfo_get_format(void)
483{
484 return socinfo ? socinfo->v1.format : 0;
485}
486
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487enum msm_cpu socinfo_get_msm_cpu(void)
488{
489 return cur_cpu;
490}
491EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
492
493static ssize_t
494socinfo_show_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
503 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
504}
505
506static ssize_t
507socinfo_show_version(struct sys_device *dev,
508 struct sysdev_attribute *attr,
509 char *buf)
510{
511 uint32_t version;
512
513 if (!socinfo) {
514 pr_err("%s: No socinfo found!\n", __func__);
515 return 0;
516 }
517
518 version = socinfo_get_version();
519 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
520 SOCINFO_VERSION_MAJOR(version),
521 SOCINFO_VERSION_MINOR(version));
522}
523
524static ssize_t
525socinfo_show_build_id(struct sys_device *dev,
526 struct sysdev_attribute *attr,
527 char *buf)
528{
529 if (!socinfo) {
530 pr_err("%s: No socinfo found!\n", __func__);
531 return 0;
532 }
533
534 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
535}
536
537static ssize_t
538socinfo_show_raw_id(struct sys_device *dev,
539 struct sysdev_attribute *attr,
540 char *buf)
541{
542 if (!socinfo) {
543 pr_err("%s: No socinfo found!\n", __func__);
544 return 0;
545 }
546 if (socinfo->v1.format < 2) {
547 pr_err("%s: Raw ID not available!\n", __func__);
548 return 0;
549 }
550
551 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
552}
553
554static ssize_t
555socinfo_show_raw_version(struct sys_device *dev,
556 struct sysdev_attribute *attr,
557 char *buf)
558{
559 if (!socinfo) {
560 pr_err("%s: No socinfo found!\n", __func__);
561 return 0;
562 }
563 if (socinfo->v1.format < 2) {
564 pr_err("%s: Raw version not available!\n", __func__);
565 return 0;
566 }
567
568 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
569}
570
571static ssize_t
572socinfo_show_platform_type(struct sys_device *dev,
573 struct sysdev_attribute *attr,
574 char *buf)
575{
576 uint32_t hw_type;
577
578 if (!socinfo) {
579 pr_err("%s: No socinfo found!\n", __func__);
580 return 0;
581 }
582 if (socinfo->v1.format < 3) {
583 pr_err("%s: platform type not available!\n", __func__);
584 return 0;
585 }
586
587 hw_type = socinfo_get_platform_type();
588 if (hw_type >= HW_PLATFORM_INVALID) {
589 pr_err("%s: Invalid hardware platform type found\n",
590 __func__);
591 hw_type = HW_PLATFORM_UNKNOWN;
592 }
593
594 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
595}
596
597static ssize_t
598socinfo_show_platform_version(struct sys_device *dev,
599 struct sysdev_attribute *attr,
600 char *buf)
601{
602
603 if (!socinfo) {
604 pr_err("%s: No socinfo found!\n", __func__);
605 return 0;
606 }
607 if (socinfo->v1.format < 4) {
608 pr_err("%s: platform version not available!\n", __func__);
609 return 0;
610 }
611
612 return snprintf(buf, PAGE_SIZE, "%u\n",
613 socinfo_get_platform_version());
614}
615
616static ssize_t
617socinfo_show_accessory_chip(struct sys_device *dev,
618 struct sysdev_attribute *attr,
619 char *buf)
620{
621 if (!socinfo) {
622 pr_err("%s: No socinfo found!\n", __func__);
623 return 0;
624 }
625 if (socinfo->v1.format < 5) {
626 pr_err("%s: accessory chip not available!\n", __func__);
627 return 0;
628 }
629
630 return snprintf(buf, PAGE_SIZE, "%u\n",
631 socinfo_get_accessory_chip());
632}
633
634static ssize_t
635socinfo_show_platform_subtype(struct sys_device *dev,
636 struct sysdev_attribute *attr,
637 char *buf)
638{
639 uint32_t hw_subtype;
640 if (!socinfo) {
641 pr_err("%s: No socinfo found!\n", __func__);
642 return 0;
643 }
644 if (socinfo->v1.format < 6) {
645 pr_err("%s: platform subtype not available!\n", __func__);
646 return 0;
647 }
648
649 hw_subtype = socinfo_get_platform_subtype();
650 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
651 pr_err("%s: Invalid hardware platform sub type found\n",
652 __func__);
653 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
654 }
655 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
656 hw_platform_subtype[hw_subtype]);
657}
658
Jin Hong9b556c32012-08-13 23:06:26 -0700659static ssize_t
660socinfo_show_pmic_model(struct sys_device *dev,
661 struct sysdev_attribute *attr,
662 char *buf)
663{
664 if (!socinfo) {
665 pr_err("%s: No socinfo found!\n", __func__);
666 return 0;
667 }
668 if (socinfo->v1.format < 7) {
669 pr_err("%s: pmic_model not available!\n", __func__);
670 return 0;
671 }
672
673 return snprintf(buf, PAGE_SIZE, "%u\n",
674 socinfo_get_pmic_model());
675}
676
677static ssize_t
678socinfo_show_pmic_die_revision(struct sys_device *dev,
679 struct sysdev_attribute *attr,
680 char *buf)
681{
682 if (!socinfo) {
683 pr_err("%s: No socinfo found!\n", __func__);
684 return 0;
685 }
686 if (socinfo->v1.format < 7) {
687 pr_err("%s: pmic_die_revision not available!\n", __func__);
688 return 0;
689 }
690
691 return snprintf(buf, PAGE_SIZE, "%u\n",
692 socinfo_get_pmic_die_revision());
693}
694
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800695static ssize_t
696msm_get_vendor(struct device *dev,
697 struct device_attribute *attr,
698 char *buf)
699{
700 return snprintf(buf, PAGE_SIZE, "Qualcomm\n");
701}
702
703static ssize_t
704msm_get_raw_id(struct device *dev,
705 struct device_attribute *attr,
706 char *buf)
707{
708 return snprintf(buf, PAGE_SIZE, "%u\n",
709 socinfo_get_raw_id());
710}
711
712static ssize_t
713msm_get_raw_version(struct device *dev,
714 struct device_attribute *attr,
715 char *buf)
716{
717 return snprintf(buf, PAGE_SIZE, "%u\n",
718 socinfo_get_raw_version());
719}
720
721static ssize_t
722msm_get_build_id(struct device *dev,
723 struct device_attribute *attr,
724 char *buf)
725{
726 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
727 socinfo_get_build_id());
728}
729
730static ssize_t
731msm_get_hw_platform(struct device *dev,
732 struct device_attribute *attr,
733 char *buf)
734{
735 uint32_t hw_type;
736 hw_type = socinfo_get_platform_type();
737
738 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
739 hw_platform[hw_type]);
740}
741
742static ssize_t
743msm_get_platform_version(struct device *dev,
744 struct device_attribute *attr,
745 char *buf)
746{
747 return snprintf(buf, PAGE_SIZE, "%u\n",
748 socinfo_get_platform_version());
749}
750
751static ssize_t
752msm_get_accessory_chip(struct device *dev,
753 struct device_attribute *attr,
754 char *buf)
755{
756 return snprintf(buf, PAGE_SIZE, "%u\n",
757 socinfo_get_accessory_chip());
758}
759
760static ssize_t
761msm_get_platform_subtype(struct device *dev,
762 struct device_attribute *attr,
763 char *buf)
764{
765 uint32_t hw_subtype;
766 hw_subtype = socinfo_get_platform_subtype();
767 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
768 hw_platform_subtype[hw_subtype]);
769}
770
771static ssize_t
772msm_get_pmic_model(struct device *dev,
773 struct device_attribute *attr,
774 char *buf)
775{
776 return snprintf(buf, PAGE_SIZE, "%u\n",
777 socinfo_get_pmic_model());
778}
779
780static ssize_t
781msm_get_pmic_die_revision(struct device *dev,
782 struct device_attribute *attr,
783 char *buf)
784{
785 return snprintf(buf, PAGE_SIZE, "%u\n",
786 socinfo_get_pmic_die_revision());
787}
788
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700789static struct sysdev_attribute socinfo_v1_files[] = {
790 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
791 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
792 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
793};
794
795static struct sysdev_attribute socinfo_v2_files[] = {
796 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
797 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
798};
799
800static struct sysdev_attribute socinfo_v3_files[] = {
801 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
802};
803
804static struct sysdev_attribute socinfo_v4_files[] = {
805 _SYSDEV_ATTR(platform_version, 0444,
806 socinfo_show_platform_version, NULL),
807};
808
809static struct sysdev_attribute socinfo_v5_files[] = {
810 _SYSDEV_ATTR(accessory_chip, 0444,
811 socinfo_show_accessory_chip, NULL),
812};
813
814static struct sysdev_attribute socinfo_v6_files[] = {
815 _SYSDEV_ATTR(platform_subtype, 0444,
816 socinfo_show_platform_subtype, NULL),
817};
818
Jin Hong9b556c32012-08-13 23:06:26 -0700819static struct sysdev_attribute socinfo_v7_files[] = {
820 _SYSDEV_ATTR(pmic_model, 0444,
821 socinfo_show_pmic_model, NULL),
822 _SYSDEV_ATTR(pmic_die_revision, 0444,
823 socinfo_show_pmic_die_revision, NULL),
824};
825
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800826static struct device_attribute msm_soc_attr_raw_version =
827 __ATTR(raw_version, S_IRUGO, msm_get_raw_version, NULL);
828
829static struct device_attribute msm_soc_attr_raw_id =
830 __ATTR(raw_id, S_IRUGO, msm_get_raw_id, NULL);
831
832static struct device_attribute msm_soc_attr_vendor =
833 __ATTR(vendor, S_IRUGO, msm_get_vendor, NULL);
834
835static struct device_attribute msm_soc_attr_build_id =
836 __ATTR(build_id, S_IRUGO, msm_get_build_id, NULL);
837
838static struct device_attribute msm_soc_attr_hw_platform =
839 __ATTR(hw_platform, S_IRUGO, msm_get_hw_platform, NULL);
840
841
842static struct device_attribute msm_soc_attr_platform_version =
843 __ATTR(platform_version, S_IRUGO,
844 msm_get_platform_version, NULL);
845
846static struct device_attribute msm_soc_attr_accessory_chip =
847 __ATTR(accessory_chip, S_IRUGO,
848 msm_get_accessory_chip, NULL);
849
850static struct device_attribute msm_soc_attr_platform_subtype =
851 __ATTR(platform_subtype, S_IRUGO,
852 msm_get_platform_subtype, NULL);
853
854static struct device_attribute msm_soc_attr_pmic_model =
855 __ATTR(pmic_model, S_IRUGO,
856 msm_get_pmic_model, NULL);
857
858static struct device_attribute msm_soc_attr_pmic_die_revision =
859 __ATTR(pmic_die_revision, S_IRUGO,
860 msm_get_pmic_die_revision, NULL);
861
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862static struct sysdev_class soc_sysdev_class = {
863 .name = "soc",
864};
865
866static struct sys_device soc_sys_device = {
867 .id = 0,
868 .cls = &soc_sysdev_class,
869};
870
871static int __init socinfo_create_files(struct sys_device *dev,
872 struct sysdev_attribute files[],
873 int size)
874{
875 int i;
876 for (i = 0; i < size; i++) {
877 int err = sysdev_create_file(dev, &files[i]);
878 if (err) {
879 pr_err("%s: sysdev_create_file(%s)=%d\n",
880 __func__, files[i].attr.name, err);
881 return err;
882 }
883 }
884 return 0;
885}
886
Stephen Boyd69a22e42012-02-22 09:16:07 -0800887static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888{
Stepan Moskovchenko070a05d2013-04-02 18:07:17 -0700889 if (early_machine_is_mpq8092()) {
Ravi Kumar V754282d2012-08-31 22:32:20 +0530890 dummy_socinfo.id = 146;
891 strlcpy(dummy_socinfo.build_id, "mpq8092 - ",
892 sizeof(dummy_socinfo.build_id));
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700893 } else if (early_machine_is_apq8084()) {
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800894 dummy_socinfo.id = 178;
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700895 strlcpy(dummy_socinfo.build_id, "apq8084 - ",
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -0800896 sizeof(dummy_socinfo.build_id));
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700897 } else if (early_machine_is_msmkrypton()) {
898 dummy_socinfo.id = 187;
899 strlcpy(dummy_socinfo.build_id, "msmkrypton - ",
900 sizeof(dummy_socinfo.build_id));
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700901 } else if (early_machine_is_msmsamarium()) {
902 dummy_socinfo.id = 195;
903 strlcpy(dummy_socinfo.build_id, "msmsamarium - ",
904 sizeof(dummy_socinfo.build_id));
Ravi Kumar V754282d2012-08-31 22:32:20 +0530905 }
Sathish Ambley3e265ce2012-03-08 16:44:04 -0800906 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
907 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908 return (void *) &dummy_socinfo;
909}
910
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800911static void __init populate_soc_sysfs_files(struct device *msm_soc_device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912{
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800913 uint32_t legacy_format = socinfo_get_format();
Jin Hong9b556c32012-08-13 23:06:26 -0700914
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800915 device_create_file(msm_soc_device, &msm_soc_attr_vendor);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800917 switch (legacy_format) {
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800918 case 8:
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800919 case 7:
920 device_create_file(msm_soc_device,
921 &msm_soc_attr_pmic_model);
922 device_create_file(msm_soc_device,
923 &msm_soc_attr_pmic_die_revision);
924 case 6:
925 device_create_file(msm_soc_device,
926 &msm_soc_attr_platform_subtype);
927 case 5:
928 device_create_file(msm_soc_device,
929 &msm_soc_attr_accessory_chip);
930 case 4:
931 device_create_file(msm_soc_device,
932 &msm_soc_attr_platform_version);
933 case 3:
934 device_create_file(msm_soc_device,
935 &msm_soc_attr_hw_platform);
936 case 2:
937 device_create_file(msm_soc_device,
938 &msm_soc_attr_raw_id);
939 device_create_file(msm_soc_device,
940 &msm_soc_attr_raw_version);
941 case 1:
942 device_create_file(msm_soc_device,
943 &msm_soc_attr_build_id);
944 break;
945 default:
946 pr_err("%s:Unknown socinfo format:%u\n", __func__,
947 legacy_format);
948 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949 }
950
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800951 return;
952}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700953
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800954static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
955{
956 uint32_t soc_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700957
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800958 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id());
959 soc_dev_attr->machine = "Snapdragon";
960 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
961 SOCINFO_VERSION_MAJOR(soc_version),
962 SOCINFO_VERSION_MINOR(soc_version));
963 return;
964
965}
966
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -0800967static int __init socinfo_init_sysdev(void)
968{
969 int err;
970 struct device *msm_soc_device;
971 struct soc_device *soc_dev;
972 struct soc_device_attribute *soc_dev_attr;
973
974 if (!socinfo) {
975 pr_err("%s: No socinfo found!\n", __func__);
976 return -ENODEV;
977 }
978
979 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
980 if (!soc_dev_attr) {
981 pr_err("%s: Soc Device alloc failed!\n", __func__);
982 return -ENOMEM;
983 }
984
985 soc_info_populate(soc_dev_attr);
986 soc_dev = soc_device_register(soc_dev_attr);
987 if (IS_ERR_OR_NULL(soc_dev)) {
988 kfree(soc_dev_attr);
989 pr_err("%s: Soc device register failed\n", __func__);
990 return -EIO;
991 }
992
993 msm_soc_device = soc_device_to_device(soc_dev);
994 populate_soc_sysfs_files(msm_soc_device);
995 err = sysdev_class_register(&soc_sysdev_class);
996 if (err) {
997 pr_err("%s: sysdev_class_register fail (%d)\n",
998 __func__, err);
999 return err;
1000 }
1001 err = sysdev_register(&soc_sys_device);
1002 if (err) {
1003 pr_err("%s: sysdev_register fail (%d)\n",
1004 __func__, err);
1005 return err;
1006 }
1007 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
1008 ARRAY_SIZE(socinfo_v1_files));
1009 if (socinfo->v1.format < 2)
1010 return err;
1011 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
1012 ARRAY_SIZE(socinfo_v2_files));
1013
1014 if (socinfo->v1.format < 3)
1015 return err;
1016
1017 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
1018 ARRAY_SIZE(socinfo_v3_files));
1019
1020 if (socinfo->v1.format < 4)
1021 return err;
1022
1023 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
1024 ARRAY_SIZE(socinfo_v4_files));
1025
1026 if (socinfo->v1.format < 5)
1027 return err;
1028
1029 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
1030 ARRAY_SIZE(socinfo_v5_files));
1031
1032 if (socinfo->v1.format < 6)
1033 return err;
1034
1035 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
1036 ARRAY_SIZE(socinfo_v6_files));
1037
1038 if (socinfo->v1.format < 7)
1039 return err;
1040
1041 socinfo_create_files(&soc_sys_device, socinfo_v7_files,
1042 ARRAY_SIZE(socinfo_v7_files));
1043
1044 return 0;
1045}
1046
1047arch_initcall(socinfo_init_sysdev);
1048
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001049static void socinfo_print(void)
1050{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001051 switch (socinfo->v1.format) {
1052 case 1:
1053 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
1054 __func__, socinfo->v1.format, socinfo->v1.id,
1055 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1056 SOCINFO_VERSION_MINOR(socinfo->v1.version));
1057 break;
1058 case 2:
1059 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1060 "raw_id=%u, raw_ver=%u\n",
1061 __func__, socinfo->v1.format, socinfo->v1.id,
1062 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1063 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1064 socinfo->v2.raw_id, socinfo->v2.raw_version);
1065 break;
1066 case 3:
1067 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1068 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
1069 __func__, socinfo->v1.format, 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);
1074 break;
1075 case 4:
1076 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1077 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
1078 __func__, socinfo->v1.format, socinfo->v1.id,
1079 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1080 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1081 socinfo->v2.raw_id, socinfo->v2.raw_version,
1082 socinfo->v3.hw_platform, socinfo->v4.platform_version);
1083 break;
1084 case 5:
1085 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1086 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1087 " accessory_chip=%u\n", __func__, socinfo->v1.format,
1088 socinfo->v1.id,
1089 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1090 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1091 socinfo->v2.raw_id, socinfo->v2.raw_version,
1092 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1093 socinfo->v5.accessory_chip);
1094 break;
1095 case 6:
1096 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1097 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1098 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
1099 socinfo->v1.format,
1100 socinfo->v1.id,
1101 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1102 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1103 socinfo->v2.raw_id, socinfo->v2.raw_version,
1104 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1105 socinfo->v5.accessory_chip,
1106 socinfo->v6.hw_platform_subtype);
1107 break;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001108 case 8:
Jin Hong9b556c32012-08-13 23:06:26 -07001109 case 7:
1110 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",
1111 __func__,
1112 socinfo->v1.format,
1113 socinfo->v1.id,
1114 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1115 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1116 socinfo->v2.raw_id, socinfo->v2.raw_version,
1117 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1118 socinfo->v5.accessory_chip,
1119 socinfo->v6.hw_platform_subtype,
1120 socinfo->v7.pmic_model,
1121 socinfo->v7.pmic_die_revision);
1122 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001123 default:
1124 pr_err("%s: Unknown format found\n", __func__);
1125 break;
1126 }
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001127}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001128
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001129int __init socinfo_init(void)
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001130{
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001131 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v8));
1132
1133 if (!socinfo)
1134 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1135 sizeof(struct socinfo_v7));
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001136
1137 if (!socinfo)
1138 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1139 sizeof(struct socinfo_v6));
1140
1141 if (!socinfo)
1142 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1143 sizeof(struct socinfo_v5));
1144
1145 if (!socinfo)
1146 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1147 sizeof(struct socinfo_v4));
1148
1149 if (!socinfo)
1150 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1151 sizeof(struct socinfo_v3));
1152
1153 if (!socinfo)
1154 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1155 sizeof(struct socinfo_v2));
1156
1157 if (!socinfo)
1158 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1159 sizeof(struct socinfo_v1));
1160
1161 if (!socinfo) {
1162 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n",
1163 __func__);
1164 socinfo = setup_dummy_socinfo();
1165 }
1166
1167 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
1168 WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
1169 "New IDs added! ID => CPU mapping might need an update.\n");
1170
1171 if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id))
1172 cur_cpu = cpu_of_id[socinfo->v1.id];
1173
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -08001174 boot_stats_init();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001175 socinfo_print();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001176
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001177 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001178}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001179
1180const int get_core_count(void)
1181{
1182 if (!(read_cpuid_mpidr() & BIT(31)))
1183 return 1;
1184
Jin Hongc5f5d542012-04-12 16:48:51 -07001185 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001186 return 1;
1187
1188 /* 1 + the PART[1:0] field of MIDR */
1189 return ((read_cpuid_id() >> 4) & 3) + 1;
1190}
1191
1192const int read_msm_cpu_type(void)
1193{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001194 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
1195 return socinfo_get_msm_cpu();
1196
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001197 switch (read_cpuid_id()) {
1198 case 0x510F02D0:
1199 case 0x510F02D2:
1200 case 0x510F02D4:
1201 return MSM_CPU_8X60;
1202
1203 case 0x510F04D0:
1204 case 0x510F04D1:
1205 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001206 case 0x511F04D0:
1207 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001208 return MSM_CPU_8960;
1209
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001210 case 0x51404D11: /* We can't get here unless we are in bringup */
1211 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001212
1213 case 0x510F06F0:
1214 return MSM_CPU_8064;
1215
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001216 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001217 case 0x511F06F2:
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001218 case 0x512F06F0:
1219 return MSM_CPU_8974;
1220
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001221 default:
1222 return MSM_CPU_UNKNOWN;
1223 };
1224}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001225
Jin Hong12b8b432012-07-18 10:00:31 -07001226const int cpu_is_krait(void)
1227{
1228 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
1229}
1230
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001231const int cpu_is_krait_v1(void)
1232{
1233 switch (read_cpuid_id()) {
1234 case 0x510F04D0:
1235 case 0x510F04D1:
1236 case 0x510F04D2:
1237 return 1;
1238
1239 default:
1240 return 0;
1241 };
1242}
Jin Hong12b8b432012-07-18 10:00:31 -07001243
1244const int cpu_is_krait_v2(void)
1245{
1246 switch (read_cpuid_id()) {
1247 case 0x511F04D0:
1248 case 0x511F04D1:
1249 case 0x511F04D2:
1250 case 0x511F04D3:
1251 case 0x511F04D4:
1252
1253 case 0x510F06F0:
1254 case 0x510F06F1:
1255 case 0x510F06F2:
1256 return 1;
1257
1258 default:
1259 return 0;
1260 };
1261}
Joel King824bd1f2012-08-19 12:55:49 -07001262
1263const int cpu_is_krait_v3(void)
1264{
1265 switch (read_cpuid_id()) {
1266 case 0x512F04D0:
1267 case 0x511F06F0:
1268 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001269 case 0x511F06F2:
Joel King824bd1f2012-08-19 12:55:49 -07001270 case 0x510F05D0:
1271 return 1;
1272
1273 default:
1274 return 0;
1275 };
1276}