blob: 8e7adba9f74c8a1c50dbff606fb67ad7c6c64823 [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>
Abhimanyu Kapur5ce3f432014-03-05 20:56:37 -080024#include <linux/string.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <linux/sysdev.h>
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -080026#include <linux/types.h>
27
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#include <asm/mach-types.h>
Abhimanyu Kapur5ce3f432014-03-05 20:56:37 -080029#include <asm/system_misc.h>
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -080030
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031#include <mach/socinfo.h>
Jeff Hugo5ba15fe2013-05-06 14:24:24 -060032#include <mach/msm_smem.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -080034#include "boot_stats.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035
36#define BUILD_ID_LENGTH 32
Yulian Shandoroved2265b2013-08-16 00:46:59 -070037#define SMEM_IMAGE_VERSION_BLOCKS_COUNT 32
38#define SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE 128
39#define SMEM_IMAGE_VERSION_SIZE 4096
40#define SMEM_IMAGE_VERSION_NAME_SIZE 75
Yulian Shandoroved2265b2013-08-16 00:46:59 -070041#define SMEM_IMAGE_VERSION_VARIANT_SIZE 20
42#define SMEM_IMAGE_VERSION_VARIANT_OFFSET 75
43#define SMEM_IMAGE_VERSION_OEM_SIZE 32
44#define SMEM_IMAGE_VERSION_OEM_OFFSET 96
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -070045#define SMEM_IMAGE_VERSION_PARTITION_APPS 10
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
47enum {
48 HW_PLATFORM_UNKNOWN = 0,
49 HW_PLATFORM_SURF = 1,
50 HW_PLATFORM_FFA = 2,
51 HW_PLATFORM_FLUID = 3,
52 HW_PLATFORM_SVLTE_FFA = 4,
53 HW_PLATFORM_SVLTE_SURF = 5,
Jin Hong49753322011-12-15 16:55:37 -080054 HW_PLATFORM_MTP = 8,
Amir Samuelov1b0dc312011-11-17 20:43:33 +020055 HW_PLATFORM_LIQUID = 9,
Zhang Chang Ken59004eb2011-08-08 09:06:58 -040056 /* Dragonboard platform id is assigned as 10 in CDT */
57 HW_PLATFORM_DRAGON = 10,
David Ng32dfa3c2013-03-19 16:55:54 -070058 HW_PLATFORM_QRD = 11,
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053059 HW_PLATFORM_HRD = 13,
60 HW_PLATFORM_DTV = 14,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061 HW_PLATFORM_INVALID
62};
63
64const char *hw_platform[] = {
65 [HW_PLATFORM_UNKNOWN] = "Unknown",
66 [HW_PLATFORM_SURF] = "Surf",
67 [HW_PLATFORM_FFA] = "FFA",
68 [HW_PLATFORM_FLUID] = "Fluid",
69 [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA",
Zhang Chang Kenef05b172011-07-27 15:28:13 -040070 [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF",
Jin Hong49753322011-12-15 16:55:37 -080071 [HW_PLATFORM_MTP] = "MTP",
72 [HW_PLATFORM_LIQUID] = "Liquid",
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053073 [HW_PLATFORM_DRAGON] = "Dragon",
David Ng32dfa3c2013-03-19 16:55:54 -070074 [HW_PLATFORM_QRD] = "QRD",
ChandraMouli Bothsaeae28bb2012-09-20 09:57:37 +053075 [HW_PLATFORM_HRD] = "HRD",
76 [HW_PLATFORM_DTV] = "DTV",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077};
78
79enum {
80 ACCESSORY_CHIP_UNKNOWN = 0,
81 ACCESSORY_CHIP_CHARM = 58,
82};
83
84enum {
Maria Yu0b563c22013-06-07 20:24:09 +080085 PLATFORM_SUBTYPE_QRD = 0x0,
86 PLATFORM_SUBTYPE_SKUAA = 0x1,
87 PLATFORM_SUBTYPE_SKUF = 0x2,
88 PLATFORM_SUBTYPE_SKUAB = 0x3,
Jie Cheng04ad8302013-08-01 16:17:54 +080089 PLATFORM_SUBTYPE_SKUG = 0x5,
Maria Yu0b563c22013-06-07 20:24:09 +080090 PLATFORM_SUBTYPE_QRD_INVALID,
91};
92
93const char *qrd_hw_platform_subtype[] = {
94 [PLATFORM_SUBTYPE_QRD] = "QRD",
95 [PLATFORM_SUBTYPE_SKUAA] = "SKUAA",
96 [PLATFORM_SUBTYPE_SKUF] = "SKUF",
97 [PLATFORM_SUBTYPE_SKUAB] = "SKUAB",
Jie Cheng04ad8302013-08-01 16:17:54 +080098 [PLATFORM_SUBTYPE_SKUG] = "SKUG",
Maria Yu8ac65722013-08-20 16:43:51 +080099 [PLATFORM_SUBTYPE_QRD_INVALID] = "INVALID",
Maria Yu0b563c22013-06-07 20:24:09 +0800100};
101
102enum {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103 PLATFORM_SUBTYPE_UNKNOWN = 0x0,
104 PLATFORM_SUBTYPE_CHARM = 0x1,
105 PLATFORM_SUBTYPE_STRANGE = 0x2,
106 PLATFORM_SUBTYPE_STRANGE_2A = 0x3,
107 PLATFORM_SUBTYPE_INVALID,
108};
109
110const char *hw_platform_subtype[] = {
111 [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown",
112 [PLATFORM_SUBTYPE_CHARM] = "charm",
113 [PLATFORM_SUBTYPE_STRANGE] = "strange",
114 [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a,"
115};
116
117/* Used to parse shared memory. Must match the modem. */
118struct socinfo_v1 {
119 uint32_t format;
120 uint32_t id;
121 uint32_t version;
122 char build_id[BUILD_ID_LENGTH];
123};
124
125struct socinfo_v2 {
126 struct socinfo_v1 v1;
127
128 /* only valid when format==2 */
129 uint32_t raw_id;
130 uint32_t raw_version;
131};
132
133struct socinfo_v3 {
134 struct socinfo_v2 v2;
135
136 /* only valid when format==3 */
137 uint32_t hw_platform;
138};
139
140struct socinfo_v4 {
141 struct socinfo_v3 v3;
142
143 /* only valid when format==4 */
144 uint32_t platform_version;
145};
146
147struct socinfo_v5 {
148 struct socinfo_v4 v4;
149
150 /* only valid when format==5 */
151 uint32_t accessory_chip;
152};
153
154struct socinfo_v6 {
155 struct socinfo_v5 v5;
156
157 /* only valid when format==6 */
158 uint32_t hw_platform_subtype;
159};
160
Jin Hong9b556c32012-08-13 23:06:26 -0700161struct socinfo_v7 {
162 struct socinfo_v6 v6;
163
164 /* only valid when format==7 */
165 uint32_t pmic_model;
166 uint32_t pmic_die_revision;
167};
168
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800169struct socinfo_v8 {
170 struct socinfo_v7 v7;
171
172 /* only valid when format==8*/
173 uint32_t pmic_model_1;
174 uint32_t pmic_die_revision_1;
175 uint32_t pmic_model_2;
176 uint32_t pmic_die_revision_2;
177};
178
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179static union {
180 struct socinfo_v1 v1;
181 struct socinfo_v2 v2;
182 struct socinfo_v3 v3;
183 struct socinfo_v4 v4;
184 struct socinfo_v5 v5;
185 struct socinfo_v6 v6;
Jin Hong9b556c32012-08-13 23:06:26 -0700186 struct socinfo_v7 v7;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -0800187 struct socinfo_v8 v8;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188} *socinfo;
189
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800190static struct msm_soc_info cpu_of_id[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191
192 /* 7x01 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800193 [0] = {MSM_CPU_UNKNOWN, "Unknown CPU"},
194 [1] = {MSM_CPU_7X01, "MSM7X01"},
195 [16] = {MSM_CPU_7X01, "MSM7X01"},
196 [17] = {MSM_CPU_7X01, "MSM7X01"},
197 [18] = {MSM_CPU_7X01, "MSM7X01"},
198 [19] = {MSM_CPU_7X01, "MSM7X01"},
199 [23] = {MSM_CPU_7X01, "MSM7X01"},
200 [25] = {MSM_CPU_7X01, "MSM7X01"},
201 [26] = {MSM_CPU_7X01, "MSM7X01"},
202 [32] = {MSM_CPU_7X01, "MSM7X01"},
203 [33] = {MSM_CPU_7X01, "MSM7X01"},
204 [34] = {MSM_CPU_7X01, "MSM7X01"},
205 [35] = {MSM_CPU_7X01, "MSM7X01"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206
207 /* 7x25 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800208 [20] = {MSM_CPU_7X25, "MSM7X25"},
209 [21] = {MSM_CPU_7X25, "MSM7X25"},
210 [24] = {MSM_CPU_7X25, "MSM7X25"},
211 [27] = {MSM_CPU_7X25, "MSM7X25"},
212 [39] = {MSM_CPU_7X25, "MSM7X25"},
213 [40] = {MSM_CPU_7X25, "MSM7X25"},
214 [41] = {MSM_CPU_7X25, "MSM7X25"},
215 [42] = {MSM_CPU_7X25, "MSM7X25"},
216 [62] = {MSM_CPU_7X25, "MSM7X25"},
217 [63] = {MSM_CPU_7X25, "MSM7X25"},
218 [66] = {MSM_CPU_7X25, "MSM7X25"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219
220
221 /* 7x27 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800222 [43] = {MSM_CPU_7X27, "MSM7X27"},
223 [44] = {MSM_CPU_7X27, "MSM7X27"},
224 [61] = {MSM_CPU_7X27, "MSM7X27"},
225 [67] = {MSM_CPU_7X27, "MSM7X27"},
226 [68] = {MSM_CPU_7X27, "MSM7X27"},
227 [69] = {MSM_CPU_7X27, "MSM7X27"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228
229
230 /* 8x50 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800231 [30] = {MSM_CPU_8X50, "MSM8X50"},
232 [36] = {MSM_CPU_8X50, "MSM8X50"},
233 [37] = {MSM_CPU_8X50, "MSM8X50"},
234 [38] = {MSM_CPU_8X50, "MSM8X50"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235
236 /* 7x30 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800237 [59] = {MSM_CPU_7X30, "MSM7X30"},
238 [60] = {MSM_CPU_7X30, "MSM7X30"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239
240 /* 8x55 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800241 [74] = {MSM_CPU_8X55, "MSM8X55"},
242 [75] = {MSM_CPU_8X55, "MSM8X55"},
243 [85] = {MSM_CPU_8X55, "MSM8X55"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700244
245 /* 8x60 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800246 [70] = {MSM_CPU_8X60, "MSM8X60"},
247 [71] = {MSM_CPU_8X60, "MSM8X60"},
248 [86] = {MSM_CPU_8X60, "MSM8X60"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700249
250 /* 8960 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800251 [87] = {MSM_CPU_8960, "MSM8960"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700252
253 /* 7x25A IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800254 [88] = {MSM_CPU_7X25A, "MSM7X25A"},
255 [89] = {MSM_CPU_7X25A, "MSM7X25A"},
256 [96] = {MSM_CPU_7X25A, "MSM7X25A"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257
258 /* 7x27A IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800259 [90] = {MSM_CPU_7X27A, "MSM7X27A"},
260 [91] = {MSM_CPU_7X27A, "MSM7X27A"},
261 [92] = {MSM_CPU_7X27A, "MSM7X27A"},
262 [97] = {MSM_CPU_7X27A, "MSM7X27A"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700263
264 /* FSM9xxx ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800265 [94] = {FSM_CPU_9XXX, "FSM9XXX"},
266 [95] = {FSM_CPU_9XXX, "FSM9XXX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267
268 /* 7x25AA ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800269 [98] = {MSM_CPU_7X25AA, "MSM7X25AA"},
270 [99] = {MSM_CPU_7X25AA, "MSM7X25AA"},
271 [100] = {MSM_CPU_7X25AA, "MSM7X25AA"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272
Joel Kingbf2ff512011-07-22 13:43:11 -0700273 /* 7x27AA ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800274 [101] = {MSM_CPU_7X27AA, "MSM7X27AA"},
275 [102] = {MSM_CPU_7X27AA, "MSM7X27AA"},
276 [103] = {MSM_CPU_7X27AA, "MSM7X27AA"},
277 [136] = {MSM_CPU_7X27AA, "MSM7X27AA"},
Joel Kingbf2ff512011-07-22 13:43:11 -0700278
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700279 /* 9x15 ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800280 [104] = {MSM_CPU_9615, "MSM9615"},
281 [105] = {MSM_CPU_9615, "MSM9615"},
282 [106] = {MSM_CPU_9615, "MSM9615"},
283 [107] = {MSM_CPU_9615, "MSM9615"},
284 [171] = {MSM_CPU_9615, "MSM9615"},
Rohit Vaswani8a28b4a2011-08-10 19:07:00 -0700285
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700286 /* 8064 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800287 [109] = {MSM_CPU_8064, "APQ8064"},
Joel Kingbf2ff512011-07-22 13:43:11 -0700288
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700289 /* 8930 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800290 [116] = {MSM_CPU_8930, "MSM8930"},
291 [117] = {MSM_CPU_8930, "MSM8930"},
292 [118] = {MSM_CPU_8930, "MSM8930"},
293 [119] = {MSM_CPU_8930, "MSM8930"},
294 [179] = {MSM_CPU_8930, "MSM8930"},
Stepan Moskovchenkodb71cd62011-11-23 14:28:57 -0800295
296 /* 8627 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800297 [120] = {MSM_CPU_8627, "MSM8627"},
298 [121] = {MSM_CPU_8627, "MSM8627"},
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -0700299
Jin Hong0698b562011-11-05 13:57:25 -0700300 /* 8660A ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800301 [122] = {MSM_CPU_8960, "MSM8960"},
Jin Hong0698b562011-11-05 13:57:25 -0700302
303 /* 8260A ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800304 [123] = {MSM_CPU_8960, "MSM8960"},
Jin Hong0698b562011-11-05 13:57:25 -0700305
306 /* 8060A ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800307 [124] = {MSM_CPU_8960, "MSM8960"},
Jin Hong0698b562011-11-05 13:57:25 -0700308
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700309 /* 8974 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800310 [126] = {MSM_CPU_8974, "MSM8974"},
311 [184] = {MSM_CPU_8974, "MSM8974"},
312 [185] = {MSM_CPU_8974, "MSM8974"},
313 [186] = {MSM_CPU_8974, "MSM8974"},
Sathish Ambleya99d6852011-10-31 15:50:55 -0700314
Stepan Moskovchenko015c4982013-05-06 12:52:32 -0700315 /* 8974AA IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800316 [208] = {MSM_CPU_8974PRO_AA, "MSM8974PRO-AA"},
317 [211] = {MSM_CPU_8974PRO_AA, "MSM8974PRO-AA"},
318 [214] = {MSM_CPU_8974PRO_AA, "MSM8974PRO-AA"},
319 [217] = {MSM_CPU_8974PRO_AA, "MSM8974PRO-AA"},
Stepan Moskovchenko015c4982013-05-06 12:52:32 -0700320
321 /* 8974AB IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800322 [209] = {MSM_CPU_8974PRO_AB, "MSM8974PRO-AB"},
323 [212] = {MSM_CPU_8974PRO_AB, "MSM8974PRO-AB"},
324 [215] = {MSM_CPU_8974PRO_AB, "MSM8974PRO-AB"},
325 [218] = {MSM_CPU_8974PRO_AB, "MSM8974PRO-AB"},
Stepan Moskovchenko015c4982013-05-06 12:52:32 -0700326
327 /* 8974AC IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800328 [194] = {MSM_CPU_8974PRO_AC, "MSM8974PRO-AC"},
329 [210] = {MSM_CPU_8974PRO_AC, "MSM8974PRO-AC"},
330 [213] = {MSM_CPU_8974PRO_AC, "MSM8974PRO-AC"},
331 [216] = {MSM_CPU_8974PRO_AC, "MSM8974PRO-AC"},
Stepan Moskovchenko015c4982013-05-06 12:52:32 -0700332
Taniya Dasa04e1892011-11-16 14:49:12 +0530333 /* 8625 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800334 [127] = {MSM_CPU_8625, "MSM8625"},
335 [128] = {MSM_CPU_8625, "MSM8625"},
336 [129] = {MSM_CPU_8625, "MSM8625"},
337 [137] = {MSM_CPU_8625, "MSM8625"},
338 [167] = {MSM_CPU_8625, "MSM8625"},
Taniya Dasa04e1892011-11-16 14:49:12 +0530339
Joel King8e0bf672012-05-18 15:40:40 -0700340 /* 8064 MPQ ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800341 [130] = {MSM_CPU_8064, "APQ8064"},
Rohit Vaswani47ee9e92012-04-23 18:42:03 -0700342
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530343 /* 7x25AB IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800344 [131] = {MSM_CPU_7X25AB, "MSM7X25AB"},
345 [132] = {MSM_CPU_7X25AB, "MSM7X25AB"},
346 [133] = {MSM_CPU_7X25AB, "MSM7X25AB"},
347 [135] = {MSM_CPU_7X25AB, "MSM7X25AB"},
Pankaj Kumarfee56a82012-04-17 14:26:49 +0530348
Joel King8e0bf672012-05-18 15:40:40 -0700349 /* 9625 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800350 [134] = {MSM_CPU_9625, "MSM9625"},
351 [148] = {MSM_CPU_9625, "MSM9625"},
352 [149] = {MSM_CPU_9625, "MSM9625"},
353 [150] = {MSM_CPU_9625, "MSM9625"},
354 [151] = {MSM_CPU_9625, "MSM9625"},
355 [152] = {MSM_CPU_9625, "MSM9625"},
356 [173] = {MSM_CPU_9625, "MSM9625"},
357 [174] = {MSM_CPU_9625, "MSM9625"},
358 [175] = {MSM_CPU_9625, "MSM9625"},
Joel King8e0bf672012-05-18 15:40:40 -0700359
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700360 /* 8960AB IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800361 [138] = {MSM_CPU_8960AB, "MSM8960AB"},
362 [139] = {MSM_CPU_8960AB, "MSM8960AB"},
363 [140] = {MSM_CPU_8960AB, "MSM8960AB"},
364 [141] = {MSM_CPU_8960AB, "MSM8960AB"},
Stepan Moskovchenkoec6a8032012-07-06 15:42:01 -0700365
Stepan Moskovchenko8f362fe2012-07-12 19:19:52 -0700366 /* 8930AA IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800367 [142] = {MSM_CPU_8930AA, "MSM8930AA"},
368 [143] = {MSM_CPU_8930AA, "MSM8930AA"},
369 [144] = {MSM_CPU_8930AA, "MSM8930AA"},
370 [160] = {MSM_CPU_8930AA, "MSM8930AA"},
371 [180] = {MSM_CPU_8930AA, "MSM8930AA"},
Stepan Moskovchenko8b38bb32012-07-06 16:57:34 -0700372
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700373 /* 8226 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800374 [145] = {MSM_CPU_8226, "MSM8626"},
375 [158] = {MSM_CPU_8226, "MSM8226"},
376 [159] = {MSM_CPU_8226, "MSM8526"},
377 [198] = {MSM_CPU_8226, "MSM8126"},
378 [199] = {MSM_CPU_8226, "APQ8026"},
379 [200] = {MSM_CPU_8226, "MSM8926"},
380 [205] = {MSM_CPU_8226, "MSM8326"},
381 [219] = {MSM_CPU_8226, "APQ8028"},
382 [220] = {MSM_CPU_8226, "MSM8128"},
383 [221] = {MSM_CPU_8226, "MSM8228"},
384 [222] = {MSM_CPU_8226, "MSM8528"},
385 [223] = {MSM_CPU_8226, "MSM8628"},
386 [224] = {MSM_CPU_8226, "MSM8928"},
Syed Rameez Mustafad6084d32012-08-23 15:47:50 -0700387
Ravi Kumar V754282d2012-08-31 22:32:20 +0530388 /* 8092 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800389 [146] = {MSM_CPU_8092, "MSM8092"},
Ravi Kumar V754282d2012-08-31 22:32:20 +0530390
Syed Rameez Mustafa3971c142013-01-09 19:04:53 -0800391 /* 8610 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800392 [147] = {MSM_CPU_8610, "MSM8610"},
393 [161] = {MSM_CPU_8610, "MSM8110"},
394 [162] = {MSM_CPU_8610, "MSM8210"},
395 [163] = {MSM_CPU_8610, "MSM8810"},
396 [164] = {MSM_CPU_8610, "MSM8212"},
397 [165] = {MSM_CPU_8610, "MSM8612"},
398 [166] = {MSM_CPU_8610, "MSM8112"},
399 [225] = {MSM_CPU_8610, "MSM8510"},
400 [226] = {MSM_CPU_8610, "MSM8512"},
Syed Rameez Mustafa158d6682012-09-21 18:25:50 -0700401
Jay Chokshib2de5092012-09-19 18:28:12 -0700402 /* 8064AB IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800403 [153] = {MSM_CPU_8064AB, "APQ8064AB"},
Jay Chokshib2de5092012-09-19 18:28:12 -0700404
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700405 /* 8930AB IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800406 [154] = {MSM_CPU_8930AB, "MSM8930AB"},
407 [155] = {MSM_CPU_8930AB, "MSM8930AB"},
408 [156] = {MSM_CPU_8930AB, "MSM8930AB"},
409 [157] = {MSM_CPU_8930AB, "MSM8930AB"},
410 [181] = {MSM_CPU_8930AB, "MSM8930AB"},
Utsab Bose89b32992012-11-08 11:15:45 +0530411
412 /* 8625Q IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800413 [168] = {MSM_CPU_8625Q, "MSM8225Q"},
414 [169] = {MSM_CPU_8625Q, "MSM8625Q"},
415 [170] = {MSM_CPU_8625Q, "MSM8125Q"},
Utsab Bose89b32992012-11-08 11:15:45 +0530416
Jay Chokshif9294742013-01-15 13:06:27 -0800417 /* 8064AA IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800418 [172] = {MSM_CPU_8064AA, "APQ8064AA"},
Stepan Moskovchenkoa03e7612012-10-16 18:34:17 -0700419
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -0700420 /* 8084 IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800421 [178] = {MSM_CPU_8084, "APQ8084"},
Stepan Moskovchenko55dfdc32013-01-24 15:48:23 -0800422
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700423 /* krypton IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800424 [187] = {MSM_CPU_KRYPTON, "MSMKRYPTON"},
Abhimanyu Kapur37bea772013-04-11 18:19:38 -0700425
Rohit Vaswanic3df8b92013-03-20 19:11:15 -0700426 /* FSM9900 ID */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800427 [188] = {FSM_CPU_9900, "FSM9900"},
Rohit Vaswanic3df8b92013-03-20 19:11:15 -0700428
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700429 /* Samarium IDs */
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -0800430 [195] = {MSM_CPU_SAMARIUM, "MSMSAMARIUM"},
Jay Chokshieb3e8b62013-05-10 17:33:54 -0700431
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700432 /* Uninitialized IDs are not known to run Linux.
433 MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are
434 considered as unknown CPU. */
435};
436
437static enum msm_cpu cur_cpu;
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700438static int current_image;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439
440static struct socinfo_v1 dummy_socinfo = {
441 .format = 1,
442 .version = 1,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700443};
444
445uint32_t socinfo_get_id(void)
446{
447 return (socinfo) ? socinfo->v1.id : 0;
448}
449EXPORT_SYMBOL_GPL(socinfo_get_id);
450
451uint32_t socinfo_get_version(void)
452{
453 return (socinfo) ? socinfo->v1.version : 0;
454}
455
456char *socinfo_get_build_id(void)
457{
458 return (socinfo) ? socinfo->v1.build_id : NULL;
459}
460
Abhimanyu Kapur5ce3f432014-03-05 20:56:37 -0800461static char *msm_read_hardware_id(void)
462{
463 static char msm_soc_str[128] = "Qualcomm ";
464 static bool string_generated = false;
465
466 if (string_generated)
467 return msm_soc_str;
468 if (!socinfo)
469 goto err_path;
470 if (!cpu_of_id[socinfo->v1.id].soc_id_string)
471 goto err_path;
472
473 string_generated = true;
474 return strncat(msm_soc_str, cpu_of_id[socinfo->v1.id].soc_id_string,
475 sizeof(msm_soc_str) - strlen(msm_soc_str));
476err_path:
477 return "UNKNOWN SOC TYPE";
478}
479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480uint32_t socinfo_get_raw_id(void)
481{
482 return socinfo ?
483 (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0)
484 : 0;
485}
486
487uint32_t socinfo_get_raw_version(void)
488{
489 return socinfo ?
490 (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0)
491 : 0;
492}
493
494uint32_t socinfo_get_platform_type(void)
495{
496 return socinfo ?
497 (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0)
498 : 0;
499}
500
501
502uint32_t socinfo_get_platform_version(void)
503{
504 return socinfo ?
505 (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0)
506 : 0;
507}
508
509/* This information is directly encoded by the machine id */
510/* Thus no external callers rely on this information at the moment */
511static uint32_t socinfo_get_accessory_chip(void)
512{
513 return socinfo ?
514 (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0)
515 : 0;
516}
517
518uint32_t socinfo_get_platform_subtype(void)
519{
520 return socinfo ?
521 (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0)
522 : 0;
523}
524
Jin Hong9b556c32012-08-13 23:06:26 -0700525enum pmic_model socinfo_get_pmic_model(void)
526{
527 return socinfo ?
528 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_model
529 : PMIC_MODEL_UNKNOWN)
530 : PMIC_MODEL_UNKNOWN;
531}
532
533uint32_t socinfo_get_pmic_die_revision(void)
534{
535 return socinfo ?
536 (socinfo->v1.format >= 7 ? socinfo->v7.pmic_die_revision : 0)
537 : 0;
538}
539
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700540static char *socinfo_get_image_version_base_address(void)
541{
542 return smem_alloc(SMEM_IMAGE_VERSION_TABLE, SMEM_IMAGE_VERSION_SIZE);
543}
544
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800545static uint32_t socinfo_get_format(void)
546{
547 return socinfo ? socinfo->v1.format : 0;
548}
549
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700550enum msm_cpu socinfo_get_msm_cpu(void)
551{
552 return cur_cpu;
553}
554EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu);
555
556static ssize_t
557socinfo_show_id(struct sys_device *dev,
558 struct sysdev_attribute *attr,
559 char *buf)
560{
561 if (!socinfo) {
562 pr_err("%s: No socinfo found!\n", __func__);
563 return 0;
564 }
565
566 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id());
567}
568
569static ssize_t
570socinfo_show_version(struct sys_device *dev,
571 struct sysdev_attribute *attr,
572 char *buf)
573{
574 uint32_t version;
575
576 if (!socinfo) {
577 pr_err("%s: No socinfo found!\n", __func__);
578 return 0;
579 }
580
581 version = socinfo_get_version();
582 return snprintf(buf, PAGE_SIZE, "%u.%u\n",
583 SOCINFO_VERSION_MAJOR(version),
584 SOCINFO_VERSION_MINOR(version));
585}
586
587static ssize_t
588socinfo_show_build_id(struct sys_device *dev,
589 struct sysdev_attribute *attr,
590 char *buf)
591{
592 if (!socinfo) {
593 pr_err("%s: No socinfo found!\n", __func__);
594 return 0;
595 }
596
597 return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id());
598}
599
600static ssize_t
601socinfo_show_raw_id(struct sys_device *dev,
602 struct sysdev_attribute *attr,
603 char *buf)
604{
605 if (!socinfo) {
606 pr_err("%s: No socinfo found!\n", __func__);
607 return 0;
608 }
609 if (socinfo->v1.format < 2) {
610 pr_err("%s: Raw ID not available!\n", __func__);
611 return 0;
612 }
613
614 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id());
615}
616
617static ssize_t
618socinfo_show_raw_version(struct sys_device *dev,
619 struct sysdev_attribute *attr,
620 char *buf)
621{
622 if (!socinfo) {
623 pr_err("%s: No socinfo found!\n", __func__);
624 return 0;
625 }
626 if (socinfo->v1.format < 2) {
627 pr_err("%s: Raw version not available!\n", __func__);
628 return 0;
629 }
630
631 return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version());
632}
633
634static ssize_t
635socinfo_show_platform_type(struct sys_device *dev,
636 struct sysdev_attribute *attr,
637 char *buf)
638{
639 uint32_t hw_type;
640
641 if (!socinfo) {
642 pr_err("%s: No socinfo found!\n", __func__);
643 return 0;
644 }
645 if (socinfo->v1.format < 3) {
646 pr_err("%s: platform type not available!\n", __func__);
647 return 0;
648 }
649
650 hw_type = socinfo_get_platform_type();
651 if (hw_type >= HW_PLATFORM_INVALID) {
652 pr_err("%s: Invalid hardware platform type found\n",
653 __func__);
654 hw_type = HW_PLATFORM_UNKNOWN;
655 }
656
657 return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]);
658}
659
660static ssize_t
661socinfo_show_platform_version(struct sys_device *dev,
662 struct sysdev_attribute *attr,
663 char *buf)
664{
665
666 if (!socinfo) {
667 pr_err("%s: No socinfo found!\n", __func__);
668 return 0;
669 }
670 if (socinfo->v1.format < 4) {
671 pr_err("%s: platform version not available!\n", __func__);
672 return 0;
673 }
674
675 return snprintf(buf, PAGE_SIZE, "%u\n",
676 socinfo_get_platform_version());
677}
678
679static ssize_t
680socinfo_show_accessory_chip(struct sys_device *dev,
681 struct sysdev_attribute *attr,
682 char *buf)
683{
684 if (!socinfo) {
685 pr_err("%s: No socinfo found!\n", __func__);
686 return 0;
687 }
688 if (socinfo->v1.format < 5) {
689 pr_err("%s: accessory chip not available!\n", __func__);
690 return 0;
691 }
692
693 return snprintf(buf, PAGE_SIZE, "%u\n",
694 socinfo_get_accessory_chip());
695}
696
697static ssize_t
698socinfo_show_platform_subtype(struct sys_device *dev,
699 struct sysdev_attribute *attr,
700 char *buf)
701{
702 uint32_t hw_subtype;
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -0700703 WARN_ONCE(1, "Deprecated, use platform_subtype_id instead\n");
704
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700705 if (!socinfo) {
706 pr_err("%s: No socinfo found!\n", __func__);
707 return 0;
708 }
709 if (socinfo->v1.format < 6) {
710 pr_err("%s: platform subtype not available!\n", __func__);
711 return 0;
712 }
713
714 hw_subtype = socinfo_get_platform_subtype();
Maria Yu0b563c22013-06-07 20:24:09 +0800715 if (HW_PLATFORM_QRD == socinfo_get_platform_type()) {
716 if (hw_subtype >= PLATFORM_SUBTYPE_QRD_INVALID) {
717 pr_err("%s: Invalid hardware platform sub type for qrd found\n",
718 __func__);
Maria Yu8ac65722013-08-20 16:43:51 +0800719 hw_subtype = PLATFORM_SUBTYPE_QRD_INVALID;
Maria Yu0b563c22013-06-07 20:24:09 +0800720 }
721 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
722 qrd_hw_platform_subtype[hw_subtype]);
723 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724 if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) {
725 pr_err("%s: Invalid hardware platform sub type found\n",
Maria Yu0b563c22013-06-07 20:24:09 +0800726 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700727 hw_subtype = PLATFORM_SUBTYPE_UNKNOWN;
728 }
729 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
730 hw_platform_subtype[hw_subtype]);
731}
732
Jin Hong9b556c32012-08-13 23:06:26 -0700733static ssize_t
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -0700734socinfo_show_platform_subtype_id(struct sys_device *dev,
735 struct sysdev_attribute *attr,
736 char *buf)
737{
738 uint32_t hw_subtype;
739
740 hw_subtype = socinfo_get_platform_subtype();
741 return snprintf(buf, PAGE_SIZE, "%u\n",
742 hw_subtype);
743}
744
745static ssize_t
Jin Hong9b556c32012-08-13 23:06:26 -0700746socinfo_show_pmic_model(struct sys_device *dev,
747 struct sysdev_attribute *attr,
748 char *buf)
749{
750 if (!socinfo) {
751 pr_err("%s: No socinfo found!\n", __func__);
752 return 0;
753 }
754 if (socinfo->v1.format < 7) {
755 pr_err("%s: pmic_model not available!\n", __func__);
756 return 0;
757 }
758
759 return snprintf(buf, PAGE_SIZE, "%u\n",
760 socinfo_get_pmic_model());
761}
762
763static ssize_t
764socinfo_show_pmic_die_revision(struct sys_device *dev,
765 struct sysdev_attribute *attr,
766 char *buf)
767{
768 if (!socinfo) {
769 pr_err("%s: No socinfo found!\n", __func__);
770 return 0;
771 }
772 if (socinfo->v1.format < 7) {
773 pr_err("%s: pmic_die_revision not available!\n", __func__);
774 return 0;
775 }
776
777 return snprintf(buf, PAGE_SIZE, "%u\n",
778 socinfo_get_pmic_die_revision());
779}
780
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800781static ssize_t
782msm_get_vendor(struct device *dev,
783 struct device_attribute *attr,
784 char *buf)
785{
786 return snprintf(buf, PAGE_SIZE, "Qualcomm\n");
787}
788
789static ssize_t
790msm_get_raw_id(struct device *dev,
791 struct device_attribute *attr,
792 char *buf)
793{
794 return snprintf(buf, PAGE_SIZE, "%u\n",
795 socinfo_get_raw_id());
796}
797
798static ssize_t
799msm_get_raw_version(struct device *dev,
800 struct device_attribute *attr,
801 char *buf)
802{
803 return snprintf(buf, PAGE_SIZE, "%u\n",
804 socinfo_get_raw_version());
805}
806
807static ssize_t
808msm_get_build_id(struct device *dev,
809 struct device_attribute *attr,
810 char *buf)
811{
812 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
813 socinfo_get_build_id());
814}
815
816static ssize_t
817msm_get_hw_platform(struct device *dev,
818 struct device_attribute *attr,
819 char *buf)
820{
821 uint32_t hw_type;
822 hw_type = socinfo_get_platform_type();
823
824 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
825 hw_platform[hw_type]);
826}
827
828static ssize_t
829msm_get_platform_version(struct device *dev,
830 struct device_attribute *attr,
831 char *buf)
832{
833 return snprintf(buf, PAGE_SIZE, "%u\n",
834 socinfo_get_platform_version());
835}
836
837static ssize_t
838msm_get_accessory_chip(struct device *dev,
839 struct device_attribute *attr,
840 char *buf)
841{
842 return snprintf(buf, PAGE_SIZE, "%u\n",
843 socinfo_get_accessory_chip());
844}
845
846static ssize_t
847msm_get_platform_subtype(struct device *dev,
848 struct device_attribute *attr,
849 char *buf)
850{
851 uint32_t hw_subtype;
852 hw_subtype = socinfo_get_platform_subtype();
Maria Yu8ac65722013-08-20 16:43:51 +0800853 if (HW_PLATFORM_QRD == socinfo_get_platform_type()) {
854 if (hw_subtype >= PLATFORM_SUBTYPE_QRD_INVALID) {
855 pr_err("%s: Invalid hardware platform sub type for qrd found\n",
856 __func__);
857 hw_subtype = PLATFORM_SUBTYPE_QRD_INVALID;
858 }
859 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
860 qrd_hw_platform_subtype[hw_subtype]);
861 }
862
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800863 return snprintf(buf, PAGE_SIZE, "%-.32s\n",
864 hw_platform_subtype[hw_subtype]);
865}
866
867static ssize_t
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -0700868msm_get_platform_subtype_id(struct device *dev,
869 struct device_attribute *attr,
870 char *buf)
871{
872 uint32_t hw_subtype;
873 hw_subtype = socinfo_get_platform_subtype();
874 return snprintf(buf, PAGE_SIZE, "%u\n",
875 hw_subtype);
876}
877
878static ssize_t
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -0800879msm_get_pmic_model(struct device *dev,
880 struct device_attribute *attr,
881 char *buf)
882{
883 return snprintf(buf, PAGE_SIZE, "%u\n",
884 socinfo_get_pmic_model());
885}
886
887static ssize_t
888msm_get_pmic_die_revision(struct device *dev,
889 struct device_attribute *attr,
890 char *buf)
891{
892 return snprintf(buf, PAGE_SIZE, "%u\n",
893 socinfo_get_pmic_die_revision());
894}
895
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700896static ssize_t
897msm_get_image_version(struct device *dev,
898 struct device_attribute *attr,
899 char *buf)
900{
901 char *string_address;
902
903 string_address = socinfo_get_image_version_base_address();
904 if (string_address == NULL) {
905 pr_err("%s : Failed to get image version base address",
906 __func__);
907 return snprintf(buf, SMEM_IMAGE_VERSION_NAME_SIZE, "Unknown");
908 }
909 string_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
Yulian Shandorovdac3d682013-11-28 21:11:47 +0200910 return snprintf(buf, SMEM_IMAGE_VERSION_NAME_SIZE, "%-.75s\n",
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700911 string_address);
912}
913
914static ssize_t
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -0700915msm_set_image_version(struct device *dev,
916 struct device_attribute *attr,
917 const char *buf,
918 size_t count)
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700919{
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -0700920 char *store_address;
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700921
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -0700922 if (current_image != SMEM_IMAGE_VERSION_PARTITION_APPS)
923 return count;
924 store_address = socinfo_get_image_version_base_address();
925 if (store_address == NULL) {
926 pr_err("%s : Failed to get image version base address",
927 __func__);
928 return count;
929 }
930 store_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
931 snprintf(store_address, SMEM_IMAGE_VERSION_NAME_SIZE, "%-.75s", buf);
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700932 return count;
933}
934
935static ssize_t
936msm_get_image_variant(struct device *dev,
937 struct device_attribute *attr,
938 char *buf)
939{
940 char *string_address;
941
942 string_address = socinfo_get_image_version_base_address();
943 if (string_address == NULL) {
944 pr_err("%s : Failed to get image version base address",
945 __func__);
946 return snprintf(buf, SMEM_IMAGE_VERSION_VARIANT_SIZE,
947 "Unknown");
948 }
949 string_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
950 string_address += SMEM_IMAGE_VERSION_VARIANT_OFFSET;
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -0700951 return snprintf(buf, SMEM_IMAGE_VERSION_VARIANT_SIZE, "%-.20s\n",
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700952 string_address);
953}
954
955static ssize_t
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -0700956msm_set_image_variant(struct device *dev,
957 struct device_attribute *attr,
958 const char *buf,
959 size_t count)
960{
961 char *store_address;
962
963 if (current_image != SMEM_IMAGE_VERSION_PARTITION_APPS)
964 return count;
965 store_address = socinfo_get_image_version_base_address();
966 if (store_address == NULL) {
967 pr_err("%s : Failed to get image version base address",
968 __func__);
969 return count;
970 }
971 store_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
972 store_address += SMEM_IMAGE_VERSION_VARIANT_OFFSET;
973 snprintf(store_address, SMEM_IMAGE_VERSION_VARIANT_SIZE, "%-.20s", buf);
974 return count;
975}
976
977static ssize_t
Yulian Shandoroved2265b2013-08-16 00:46:59 -0700978msm_get_image_crm_version(struct device *dev,
979 struct device_attribute *attr,
980 char *buf)
981{
982 char *string_address;
983
984 string_address = socinfo_get_image_version_base_address();
985 if (string_address == NULL) {
986 pr_err("%s : Failed to get image version base address",
987 __func__);
988 return snprintf(buf, SMEM_IMAGE_VERSION_OEM_SIZE, "Unknown");
989 }
990 string_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
991 string_address += SMEM_IMAGE_VERSION_OEM_OFFSET;
992 return snprintf(buf, SMEM_IMAGE_VERSION_OEM_SIZE, "%-.32s\n",
993 string_address);
994}
995
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996static struct sysdev_attribute socinfo_v1_files[] = {
997 _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL),
998 _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL),
999 _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL),
1000};
1001
1002static struct sysdev_attribute socinfo_v2_files[] = {
1003 _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL),
1004 _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL),
1005};
1006
1007static struct sysdev_attribute socinfo_v3_files[] = {
1008 _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL),
1009};
1010
1011static struct sysdev_attribute socinfo_v4_files[] = {
1012 _SYSDEV_ATTR(platform_version, 0444,
1013 socinfo_show_platform_version, NULL),
1014};
1015
1016static struct sysdev_attribute socinfo_v5_files[] = {
1017 _SYSDEV_ATTR(accessory_chip, 0444,
1018 socinfo_show_accessory_chip, NULL),
1019};
1020
1021static struct sysdev_attribute socinfo_v6_files[] = {
1022 _SYSDEV_ATTR(platform_subtype, 0444,
1023 socinfo_show_platform_subtype, NULL),
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -07001024 _SYSDEV_ATTR(platform_subtype_id, 0444,
1025 socinfo_show_platform_subtype_id, NULL),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001026};
1027
Jin Hong9b556c32012-08-13 23:06:26 -07001028static struct sysdev_attribute socinfo_v7_files[] = {
1029 _SYSDEV_ATTR(pmic_model, 0444,
1030 socinfo_show_pmic_model, NULL),
1031 _SYSDEV_ATTR(pmic_die_revision, 0444,
1032 socinfo_show_pmic_die_revision, NULL),
1033};
1034
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001035static ssize_t
1036msm_set_image_crm_version(struct device *dev,
1037 struct device_attribute *attr,
1038 const char *buf,
1039 size_t count)
1040{
1041 char *store_address;
1042
1043 if (current_image != SMEM_IMAGE_VERSION_PARTITION_APPS)
1044 return count;
1045 store_address = socinfo_get_image_version_base_address();
1046 if (store_address == NULL) {
1047 pr_err("%s : Failed to get image version base address",
1048 __func__);
1049 return count;
1050 }
1051 store_address += current_image * SMEM_IMAGE_VERSION_SINGLE_BLOCK_SIZE;
1052 store_address += SMEM_IMAGE_VERSION_OEM_OFFSET;
1053 snprintf(store_address, SMEM_IMAGE_VERSION_OEM_SIZE, "%-.32s", buf);
1054 return count;
1055}
1056
1057static ssize_t
1058msm_get_image_number(struct device *dev,
1059 struct device_attribute *attr,
1060 char *buf)
1061{
1062 return snprintf(buf, PAGE_SIZE, "%d\n",
1063 current_image);
1064}
1065
1066static ssize_t
1067msm_select_image(struct device *dev, struct device_attribute *attr,
1068 const char *buf, size_t count)
1069{
1070 int ret, digit;
1071
1072 ret = kstrtoint(buf, 10, &digit);
1073 if (ret)
1074 return ret;
1075 if (0 <= digit && digit < SMEM_IMAGE_VERSION_BLOCKS_COUNT)
1076 current_image = digit;
1077 else
1078 current_image = 0;
1079 return count;
1080}
1081
1082
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001083static struct device_attribute msm_soc_attr_raw_version =
1084 __ATTR(raw_version, S_IRUGO, msm_get_raw_version, NULL);
1085
1086static struct device_attribute msm_soc_attr_raw_id =
1087 __ATTR(raw_id, S_IRUGO, msm_get_raw_id, NULL);
1088
1089static struct device_attribute msm_soc_attr_vendor =
1090 __ATTR(vendor, S_IRUGO, msm_get_vendor, NULL);
1091
1092static struct device_attribute msm_soc_attr_build_id =
1093 __ATTR(build_id, S_IRUGO, msm_get_build_id, NULL);
1094
1095static struct device_attribute msm_soc_attr_hw_platform =
1096 __ATTR(hw_platform, S_IRUGO, msm_get_hw_platform, NULL);
1097
1098
1099static struct device_attribute msm_soc_attr_platform_version =
1100 __ATTR(platform_version, S_IRUGO,
1101 msm_get_platform_version, NULL);
1102
1103static struct device_attribute msm_soc_attr_accessory_chip =
1104 __ATTR(accessory_chip, S_IRUGO,
1105 msm_get_accessory_chip, NULL);
1106
1107static struct device_attribute msm_soc_attr_platform_subtype =
1108 __ATTR(platform_subtype, S_IRUGO,
1109 msm_get_platform_subtype, NULL);
1110
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -07001111/* Platform Subtype String is being deprecated. Use Platform
1112 * Subtype ID instead.
1113 */
1114static struct device_attribute msm_soc_attr_platform_subtype_id =
1115 __ATTR(platform_subtype_id, S_IRUGO,
1116 msm_get_platform_subtype_id, NULL);
1117
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001118static struct device_attribute msm_soc_attr_pmic_model =
1119 __ATTR(pmic_model, S_IRUGO,
1120 msm_get_pmic_model, NULL);
1121
1122static struct device_attribute msm_soc_attr_pmic_die_revision =
1123 __ATTR(pmic_die_revision, S_IRUGO,
1124 msm_get_pmic_die_revision, NULL);
1125
Yulian Shandoroved2265b2013-08-16 00:46:59 -07001126static struct device_attribute image_version =
1127 __ATTR(image_version, S_IRUGO | S_IWUSR,
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001128 msm_get_image_version, msm_set_image_version);
Yulian Shandoroved2265b2013-08-16 00:46:59 -07001129
1130static struct device_attribute image_variant =
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001131 __ATTR(image_variant, S_IRUGO | S_IWUSR,
1132 msm_get_image_variant, msm_set_image_variant);
Yulian Shandoroved2265b2013-08-16 00:46:59 -07001133
1134static struct device_attribute image_crm_version =
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001135 __ATTR(image_crm_version, S_IRUGO | S_IWUSR,
1136 msm_get_image_crm_version, msm_set_image_crm_version);
1137
1138static struct device_attribute select_image =
Yulian Shandorov162e8fd2013-11-01 22:37:26 +02001139 __ATTR(select_image, S_IRUGO | S_IWUSR,
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001140 msm_get_image_number, msm_select_image);
Yulian Shandoroved2265b2013-08-16 00:46:59 -07001141
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001142static struct sysdev_class soc_sysdev_class = {
1143 .name = "soc",
1144};
1145
1146static struct sys_device soc_sys_device = {
1147 .id = 0,
1148 .cls = &soc_sysdev_class,
1149};
1150
1151static int __init socinfo_create_files(struct sys_device *dev,
1152 struct sysdev_attribute files[],
1153 int size)
1154{
1155 int i;
1156 for (i = 0; i < size; i++) {
1157 int err = sysdev_create_file(dev, &files[i]);
1158 if (err) {
1159 pr_err("%s: sysdev_create_file(%s)=%d\n",
1160 __func__, files[i].attr.name, err);
1161 return err;
1162 }
1163 }
1164 return 0;
1165}
1166
Stephen Boyd69a22e42012-02-22 09:16:07 -08001167static void * __init setup_dummy_socinfo(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168{
Stepan Moskovchenko070a05d2013-04-02 18:07:17 -07001169 if (early_machine_is_mpq8092()) {
Ravi Kumar V754282d2012-08-31 22:32:20 +05301170 dummy_socinfo.id = 146;
1171 strlcpy(dummy_socinfo.build_id, "mpq8092 - ",
1172 sizeof(dummy_socinfo.build_id));
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -07001173 } else if (early_machine_is_apq8084()) {
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -08001174 dummy_socinfo.id = 178;
Stepan Moskovchenkoe90cd652013-04-18 12:54:47 -07001175 strlcpy(dummy_socinfo.build_id, "apq8084 - ",
Stepan Moskovchenkof07190a2013-01-24 15:48:49 -08001176 sizeof(dummy_socinfo.build_id));
Abhimanyu Kapur37bea772013-04-11 18:19:38 -07001177 } else if (early_machine_is_msmkrypton()) {
1178 dummy_socinfo.id = 187;
1179 strlcpy(dummy_socinfo.build_id, "msmkrypton - ",
1180 sizeof(dummy_socinfo.build_id));
Jay Chokshieb3e8b62013-05-10 17:33:54 -07001181 } else if (early_machine_is_msmsamarium()) {
1182 dummy_socinfo.id = 195;
1183 strlcpy(dummy_socinfo.build_id, "msmsamarium - ",
1184 sizeof(dummy_socinfo.build_id));
Ravi Kumar V754282d2012-08-31 22:32:20 +05301185 }
Sathish Ambley3e265ce2012-03-08 16:44:04 -08001186 strlcat(dummy_socinfo.build_id, "Dummy socinfo",
1187 sizeof(dummy_socinfo.build_id));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001188 return (void *) &dummy_socinfo;
1189}
1190
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001191static void __init populate_soc_sysfs_files(struct device *msm_soc_device)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001192{
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001193 uint32_t legacy_format = socinfo_get_format();
Jin Hong9b556c32012-08-13 23:06:26 -07001194
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001195 device_create_file(msm_soc_device, &msm_soc_attr_vendor);
Yulian Shandoroved2265b2013-08-16 00:46:59 -07001196 device_create_file(msm_soc_device, &image_version);
1197 device_create_file(msm_soc_device, &image_variant);
1198 device_create_file(msm_soc_device, &image_crm_version);
Yulian Shandorov4c2d6c62013-10-09 06:51:36 -07001199 device_create_file(msm_soc_device, &select_image);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001200
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001201 switch (legacy_format) {
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001202 case 8:
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001203 case 7:
1204 device_create_file(msm_soc_device,
1205 &msm_soc_attr_pmic_model);
1206 device_create_file(msm_soc_device,
1207 &msm_soc_attr_pmic_die_revision);
1208 case 6:
1209 device_create_file(msm_soc_device,
1210 &msm_soc_attr_platform_subtype);
Abhimanyu Kapur41a01eb2013-08-26 22:06:10 -07001211 device_create_file(msm_soc_device,
1212 &msm_soc_attr_platform_subtype_id);
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001213 case 5:
1214 device_create_file(msm_soc_device,
1215 &msm_soc_attr_accessory_chip);
1216 case 4:
1217 device_create_file(msm_soc_device,
1218 &msm_soc_attr_platform_version);
1219 case 3:
1220 device_create_file(msm_soc_device,
1221 &msm_soc_attr_hw_platform);
1222 case 2:
1223 device_create_file(msm_soc_device,
1224 &msm_soc_attr_raw_id);
1225 device_create_file(msm_soc_device,
1226 &msm_soc_attr_raw_version);
1227 case 1:
1228 device_create_file(msm_soc_device,
1229 &msm_soc_attr_build_id);
1230 break;
1231 default:
1232 pr_err("%s:Unknown socinfo format:%u\n", __func__,
1233 legacy_format);
1234 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001235 }
1236
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001237 return;
1238}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001239
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001240static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
1241{
1242 uint32_t soc_version = socinfo_get_version();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001243
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001244 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", socinfo_get_id());
1245 soc_dev_attr->machine = "Snapdragon";
1246 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
1247 SOCINFO_VERSION_MAJOR(soc_version),
1248 SOCINFO_VERSION_MINOR(soc_version));
1249 return;
1250
1251}
1252
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001253static int __init socinfo_init_sysdev(void)
1254{
1255 int err;
1256 struct device *msm_soc_device;
1257 struct soc_device *soc_dev;
1258 struct soc_device_attribute *soc_dev_attr;
1259
1260 if (!socinfo) {
1261 pr_err("%s: No socinfo found!\n", __func__);
1262 return -ENODEV;
1263 }
1264
1265 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
1266 if (!soc_dev_attr) {
1267 pr_err("%s: Soc Device alloc failed!\n", __func__);
1268 return -ENOMEM;
1269 }
1270
1271 soc_info_populate(soc_dev_attr);
1272 soc_dev = soc_device_register(soc_dev_attr);
1273 if (IS_ERR_OR_NULL(soc_dev)) {
1274 kfree(soc_dev_attr);
1275 pr_err("%s: Soc device register failed\n", __func__);
1276 return -EIO;
1277 }
1278
1279 msm_soc_device = soc_device_to_device(soc_dev);
1280 populate_soc_sysfs_files(msm_soc_device);
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001281
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001282 err = sysdev_class_register(&soc_sysdev_class);
1283 if (err) {
1284 pr_err("%s: sysdev_class_register fail (%d)\n",
1285 __func__, err);
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001286 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001287 }
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001288
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001289 err = sysdev_register(&soc_sys_device);
1290 if (err) {
1291 pr_err("%s: sysdev_register fail (%d)\n",
1292 __func__, err);
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001293 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001294 }
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001295
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001296 socinfo_create_files(&soc_sys_device, socinfo_v1_files,
1297 ARRAY_SIZE(socinfo_v1_files));
1298 if (socinfo->v1.format < 2)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001299 goto socinfo_init_err;
1300
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001301 socinfo_create_files(&soc_sys_device, socinfo_v2_files,
1302 ARRAY_SIZE(socinfo_v2_files));
1303
1304 if (socinfo->v1.format < 3)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001305 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001306
1307 socinfo_create_files(&soc_sys_device, socinfo_v3_files,
1308 ARRAY_SIZE(socinfo_v3_files));
1309
1310 if (socinfo->v1.format < 4)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001311 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001312
1313 socinfo_create_files(&soc_sys_device, socinfo_v4_files,
1314 ARRAY_SIZE(socinfo_v4_files));
1315
1316 if (socinfo->v1.format < 5)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001317 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001318
1319 socinfo_create_files(&soc_sys_device, socinfo_v5_files,
1320 ARRAY_SIZE(socinfo_v5_files));
1321
1322 if (socinfo->v1.format < 6)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001323 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001324
1325 socinfo_create_files(&soc_sys_device, socinfo_v6_files,
1326 ARRAY_SIZE(socinfo_v6_files));
1327
1328 if (socinfo->v1.format < 7)
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001329 goto socinfo_init_err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001330
1331 socinfo_create_files(&soc_sys_device, socinfo_v7_files,
1332 ARRAY_SIZE(socinfo_v7_files));
1333
1334 return 0;
Syed Rameez Mustafae81dc932013-10-16 13:52:58 -07001335
1336socinfo_init_err:
1337 kfree(soc_dev_attr);
1338 return err;
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001339}
1340
1341arch_initcall(socinfo_init_sysdev);
1342
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001343static void socinfo_print(void)
1344{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001345 switch (socinfo->v1.format) {
1346 case 1:
1347 pr_info("%s: v%u, id=%u, ver=%u.%u\n",
1348 __func__, socinfo->v1.format, socinfo->v1.id,
1349 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1350 SOCINFO_VERSION_MINOR(socinfo->v1.version));
1351 break;
1352 case 2:
1353 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1354 "raw_id=%u, raw_ver=%u\n",
1355 __func__, socinfo->v1.format, socinfo->v1.id,
1356 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1357 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1358 socinfo->v2.raw_id, socinfo->v2.raw_version);
1359 break;
1360 case 3:
1361 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1362 "raw_id=%u, raw_ver=%u, hw_plat=%u\n",
1363 __func__, socinfo->v1.format, socinfo->v1.id,
1364 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1365 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1366 socinfo->v2.raw_id, socinfo->v2.raw_version,
1367 socinfo->v3.hw_platform);
1368 break;
1369 case 4:
1370 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1371 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n",
1372 __func__, socinfo->v1.format, socinfo->v1.id,
1373 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1374 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1375 socinfo->v2.raw_id, socinfo->v2.raw_version,
1376 socinfo->v3.hw_platform, socinfo->v4.platform_version);
1377 break;
1378 case 5:
1379 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1380 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1381 " accessory_chip=%u\n", __func__, socinfo->v1.format,
1382 socinfo->v1.id,
1383 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1384 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1385 socinfo->v2.raw_id, socinfo->v2.raw_version,
1386 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1387 socinfo->v5.accessory_chip);
1388 break;
1389 case 6:
1390 pr_info("%s: v%u, id=%u, ver=%u.%u, "
1391 "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n"
1392 " accessory_chip=%u hw_plat_subtype=%u\n", __func__,
1393 socinfo->v1.format,
1394 socinfo->v1.id,
1395 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1396 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1397 socinfo->v2.raw_id, socinfo->v2.raw_version,
1398 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1399 socinfo->v5.accessory_chip,
1400 socinfo->v6.hw_platform_subtype);
1401 break;
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001402 case 8:
Jin Hong9b556c32012-08-13 23:06:26 -07001403 case 7:
1404 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",
1405 __func__,
1406 socinfo->v1.format,
1407 socinfo->v1.id,
1408 SOCINFO_VERSION_MAJOR(socinfo->v1.version),
1409 SOCINFO_VERSION_MINOR(socinfo->v1.version),
1410 socinfo->v2.raw_id, socinfo->v2.raw_version,
1411 socinfo->v3.hw_platform, socinfo->v4.platform_version,
1412 socinfo->v5.accessory_chip,
1413 socinfo->v6.hw_platform_subtype,
1414 socinfo->v7.pmic_model,
1415 socinfo->v7.pmic_die_revision);
1416 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001417 default:
1418 pr_err("%s: Unknown format found\n", __func__);
1419 break;
1420 }
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001421}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001422
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001423int __init socinfo_init(void)
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001424{
Abhimanyu Kapur781c03d2013-02-21 16:20:23 -08001425 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v8));
1426
1427 if (!socinfo)
1428 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1429 sizeof(struct socinfo_v7));
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001430
1431 if (!socinfo)
1432 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1433 sizeof(struct socinfo_v6));
1434
1435 if (!socinfo)
1436 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1437 sizeof(struct socinfo_v5));
1438
1439 if (!socinfo)
1440 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1441 sizeof(struct socinfo_v4));
1442
1443 if (!socinfo)
1444 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1445 sizeof(struct socinfo_v3));
1446
1447 if (!socinfo)
1448 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1449 sizeof(struct socinfo_v2));
1450
1451 if (!socinfo)
1452 socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID,
1453 sizeof(struct socinfo_v1));
1454
1455 if (!socinfo) {
1456 pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n",
1457 __func__);
1458 socinfo = setup_dummy_socinfo();
1459 }
1460
1461 WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001462
Abhimanyu Kapur5ce3f432014-03-05 20:56:37 -08001463 if (socinfo_get_id() >= ARRAY_SIZE(cpu_of_id))
1464 BUG_ON("New IDs added! ID => CPU mapping might need an update.\n");
1465
1466 else
Abhimanyu Kapur92f7968e2014-03-05 19:43:39 -08001467 cur_cpu = cpu_of_id[socinfo->v1.id].generic_soc_type;
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001468
Abhimanyu Kapurcf3ed152013-03-01 19:32:19 -08001469 boot_stats_init();
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001470 socinfo_print();
Abhimanyu Kapur5ce3f432014-03-05 20:56:37 -08001471 arch_read_hardware_id = msm_read_hardware_id;
Abhimanyu Kapur440cdde2012-12-04 00:05:40 -08001472
Abhimanyu Kapur91a0a502013-01-11 19:24:59 -08001473 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001474}
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001475
1476const int get_core_count(void)
1477{
1478 if (!(read_cpuid_mpidr() & BIT(31)))
1479 return 1;
1480
Jin Hongc5f5d542012-04-12 16:48:51 -07001481 if (read_cpuid_mpidr() & BIT(30))
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001482 return 1;
1483
1484 /* 1 + the PART[1:0] field of MIDR */
1485 return ((read_cpuid_id() >> 4) & 3) + 1;
1486}
1487
1488const int read_msm_cpu_type(void)
1489{
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001490 if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN)
1491 return socinfo_get_msm_cpu();
1492
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001493 switch (read_cpuid_id()) {
1494 case 0x510F02D0:
1495 case 0x510F02D2:
1496 case 0x510F02D4:
1497 return MSM_CPU_8X60;
1498
1499 case 0x510F04D0:
1500 case 0x510F04D1:
1501 case 0x510F04D2:
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001502 case 0x511F04D0:
1503 case 0x512F04D0:
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001504 return MSM_CPU_8960;
1505
Stepan Moskovchenkoa8f0a222011-10-24 18:53:17 -07001506 case 0x51404D11: /* We can't get here unless we are in bringup */
1507 return MSM_CPU_8930;
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001508
1509 case 0x510F06F0:
1510 return MSM_CPU_8064;
1511
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001512 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001513 case 0x511F06F2:
Stepan Moskovchenko02c4d0c2012-07-26 14:33:02 -07001514 case 0x512F06F0:
1515 return MSM_CPU_8974;
1516
Stepan Moskovchenkoeff783a2011-08-22 19:01:58 -07001517 default:
1518 return MSM_CPU_UNKNOWN;
1519 };
1520}
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001521
Jin Hong12b8b432012-07-18 10:00:31 -07001522const int cpu_is_krait(void)
1523{
1524 return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400);
1525}
1526
Stepan Moskovchenko70dc7cf2011-08-22 19:08:42 -07001527const int cpu_is_krait_v1(void)
1528{
1529 switch (read_cpuid_id()) {
1530 case 0x510F04D0:
1531 case 0x510F04D1:
1532 case 0x510F04D2:
1533 return 1;
1534
1535 default:
1536 return 0;
1537 };
1538}
Jin Hong12b8b432012-07-18 10:00:31 -07001539
1540const int cpu_is_krait_v2(void)
1541{
1542 switch (read_cpuid_id()) {
1543 case 0x511F04D0:
1544 case 0x511F04D1:
1545 case 0x511F04D2:
1546 case 0x511F04D3:
1547 case 0x511F04D4:
1548
1549 case 0x510F06F0:
1550 case 0x510F06F1:
1551 case 0x510F06F2:
1552 return 1;
1553
1554 default:
1555 return 0;
1556 };
1557}
Joel King824bd1f2012-08-19 12:55:49 -07001558
1559const int cpu_is_krait_v3(void)
1560{
1561 switch (read_cpuid_id()) {
1562 case 0x512F04D0:
1563 case 0x511F06F0:
1564 case 0x511F06F1:
Matt Wagantallbdff7fe2013-01-08 13:36:40 -08001565 case 0x511F06F2:
Joel King824bd1f2012-08-19 12:55:49 -07001566 case 0x510F05D0:
1567 return 1;
1568
1569 default:
1570 return 0;
1571 };
1572}