Taniya Das | a04e189 | 2011-11-16 14:49:12 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 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 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/sysdev.h> |
| 20 | #include <asm/mach-types.h> |
| 21 | #include <mach/socinfo.h> |
| 22 | |
| 23 | #include "smd_private.h" |
| 24 | |
| 25 | #define BUILD_ID_LENGTH 32 |
| 26 | |
| 27 | enum { |
| 28 | HW_PLATFORM_UNKNOWN = 0, |
| 29 | HW_PLATFORM_SURF = 1, |
| 30 | HW_PLATFORM_FFA = 2, |
| 31 | HW_PLATFORM_FLUID = 3, |
| 32 | HW_PLATFORM_SVLTE_FFA = 4, |
| 33 | HW_PLATFORM_SVLTE_SURF = 5, |
Jin Hong | 4975332 | 2011-12-15 16:55:37 -0800 | [diff] [blame] | 34 | HW_PLATFORM_MTP = 8, |
Amir Samuelov | 1b0dc31 | 2011-11-17 20:43:33 +0200 | [diff] [blame] | 35 | HW_PLATFORM_LIQUID = 9, |
Zhang Chang Ken | 59004eb | 2011-08-08 09:06:58 -0400 | [diff] [blame] | 36 | /* Dragonboard platform id is assigned as 10 in CDT */ |
| 37 | HW_PLATFORM_DRAGON = 10, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | HW_PLATFORM_INVALID |
| 39 | }; |
| 40 | |
| 41 | const char *hw_platform[] = { |
| 42 | [HW_PLATFORM_UNKNOWN] = "Unknown", |
| 43 | [HW_PLATFORM_SURF] = "Surf", |
| 44 | [HW_PLATFORM_FFA] = "FFA", |
| 45 | [HW_PLATFORM_FLUID] = "Fluid", |
| 46 | [HW_PLATFORM_SVLTE_FFA] = "SVLTE_FFA", |
Zhang Chang Ken | ef05b17 | 2011-07-27 15:28:13 -0400 | [diff] [blame] | 47 | [HW_PLATFORM_SVLTE_SURF] = "SLVTE_SURF", |
Jin Hong | 4975332 | 2011-12-15 16:55:37 -0800 | [diff] [blame] | 48 | [HW_PLATFORM_MTP] = "MTP", |
| 49 | [HW_PLATFORM_LIQUID] = "Liquid", |
Zhang Chang Ken | ef05b17 | 2011-07-27 15:28:13 -0400 | [diff] [blame] | 50 | [HW_PLATFORM_DRAGON] = "Dragon" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | enum { |
| 54 | ACCESSORY_CHIP_UNKNOWN = 0, |
| 55 | ACCESSORY_CHIP_CHARM = 58, |
| 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | PLATFORM_SUBTYPE_UNKNOWN = 0x0, |
| 60 | PLATFORM_SUBTYPE_CHARM = 0x1, |
| 61 | PLATFORM_SUBTYPE_STRANGE = 0x2, |
| 62 | PLATFORM_SUBTYPE_STRANGE_2A = 0x3, |
| 63 | PLATFORM_SUBTYPE_INVALID, |
| 64 | }; |
| 65 | |
| 66 | const char *hw_platform_subtype[] = { |
| 67 | [PLATFORM_SUBTYPE_UNKNOWN] = "Unknown", |
| 68 | [PLATFORM_SUBTYPE_CHARM] = "charm", |
| 69 | [PLATFORM_SUBTYPE_STRANGE] = "strange", |
| 70 | [PLATFORM_SUBTYPE_STRANGE_2A] = "strange_2a," |
| 71 | }; |
| 72 | |
| 73 | /* Used to parse shared memory. Must match the modem. */ |
| 74 | struct socinfo_v1 { |
| 75 | uint32_t format; |
| 76 | uint32_t id; |
| 77 | uint32_t version; |
| 78 | char build_id[BUILD_ID_LENGTH]; |
| 79 | }; |
| 80 | |
| 81 | struct socinfo_v2 { |
| 82 | struct socinfo_v1 v1; |
| 83 | |
| 84 | /* only valid when format==2 */ |
| 85 | uint32_t raw_id; |
| 86 | uint32_t raw_version; |
| 87 | }; |
| 88 | |
| 89 | struct socinfo_v3 { |
| 90 | struct socinfo_v2 v2; |
| 91 | |
| 92 | /* only valid when format==3 */ |
| 93 | uint32_t hw_platform; |
| 94 | }; |
| 95 | |
| 96 | struct socinfo_v4 { |
| 97 | struct socinfo_v3 v3; |
| 98 | |
| 99 | /* only valid when format==4 */ |
| 100 | uint32_t platform_version; |
| 101 | }; |
| 102 | |
| 103 | struct socinfo_v5 { |
| 104 | struct socinfo_v4 v4; |
| 105 | |
| 106 | /* only valid when format==5 */ |
| 107 | uint32_t accessory_chip; |
| 108 | }; |
| 109 | |
| 110 | struct socinfo_v6 { |
| 111 | struct socinfo_v5 v5; |
| 112 | |
| 113 | /* only valid when format==6 */ |
| 114 | uint32_t hw_platform_subtype; |
| 115 | }; |
| 116 | |
| 117 | static union { |
| 118 | struct socinfo_v1 v1; |
| 119 | struct socinfo_v2 v2; |
| 120 | struct socinfo_v3 v3; |
| 121 | struct socinfo_v4 v4; |
| 122 | struct socinfo_v5 v5; |
| 123 | struct socinfo_v6 v6; |
| 124 | } *socinfo; |
| 125 | |
| 126 | static enum msm_cpu cpu_of_id[] = { |
| 127 | |
| 128 | /* 7x01 IDs */ |
| 129 | [1] = MSM_CPU_7X01, |
| 130 | [16] = MSM_CPU_7X01, |
| 131 | [17] = MSM_CPU_7X01, |
| 132 | [18] = MSM_CPU_7X01, |
| 133 | [19] = MSM_CPU_7X01, |
| 134 | [23] = MSM_CPU_7X01, |
| 135 | [25] = MSM_CPU_7X01, |
| 136 | [26] = MSM_CPU_7X01, |
| 137 | [32] = MSM_CPU_7X01, |
| 138 | [33] = MSM_CPU_7X01, |
| 139 | [34] = MSM_CPU_7X01, |
| 140 | [35] = MSM_CPU_7X01, |
| 141 | |
| 142 | /* 7x25 IDs */ |
| 143 | [20] = MSM_CPU_7X25, |
| 144 | [21] = MSM_CPU_7X25, /* 7225 */ |
| 145 | [24] = MSM_CPU_7X25, /* 7525 */ |
| 146 | [27] = MSM_CPU_7X25, /* 7625 */ |
| 147 | [39] = MSM_CPU_7X25, |
| 148 | [40] = MSM_CPU_7X25, |
| 149 | [41] = MSM_CPU_7X25, |
| 150 | [42] = MSM_CPU_7X25, |
| 151 | [62] = MSM_CPU_7X25, /* 7625-1 */ |
| 152 | [63] = MSM_CPU_7X25, /* 7225-1 */ |
| 153 | [66] = MSM_CPU_7X25, /* 7225-2 */ |
| 154 | |
| 155 | |
| 156 | /* 7x27 IDs */ |
| 157 | [43] = MSM_CPU_7X27, |
| 158 | [44] = MSM_CPU_7X27, |
| 159 | [61] = MSM_CPU_7X27, |
| 160 | [67] = MSM_CPU_7X27, /* 7227-1 */ |
| 161 | [68] = MSM_CPU_7X27, /* 7627-1 */ |
| 162 | [69] = MSM_CPU_7X27, /* 7627-2 */ |
| 163 | |
| 164 | |
| 165 | /* 8x50 IDs */ |
| 166 | [30] = MSM_CPU_8X50, |
| 167 | [36] = MSM_CPU_8X50, |
| 168 | [37] = MSM_CPU_8X50, |
| 169 | [38] = MSM_CPU_8X50, |
| 170 | |
| 171 | /* 7x30 IDs */ |
| 172 | [59] = MSM_CPU_7X30, |
| 173 | [60] = MSM_CPU_7X30, |
| 174 | |
| 175 | /* 8x55 IDs */ |
| 176 | [74] = MSM_CPU_8X55, |
| 177 | [75] = MSM_CPU_8X55, |
| 178 | [85] = MSM_CPU_8X55, |
| 179 | |
| 180 | /* 8x60 IDs */ |
| 181 | [70] = MSM_CPU_8X60, |
| 182 | [71] = MSM_CPU_8X60, |
| 183 | [86] = MSM_CPU_8X60, |
| 184 | |
| 185 | /* 8960 IDs */ |
| 186 | [87] = MSM_CPU_8960, |
| 187 | |
| 188 | /* 7x25A IDs */ |
| 189 | [88] = MSM_CPU_7X25A, |
| 190 | [89] = MSM_CPU_7X25A, |
| 191 | [96] = MSM_CPU_7X25A, |
| 192 | |
| 193 | /* 7x27A IDs */ |
| 194 | [90] = MSM_CPU_7X27A, |
| 195 | [91] = MSM_CPU_7X27A, |
| 196 | [92] = MSM_CPU_7X27A, |
| 197 | [97] = MSM_CPU_7X27A, |
| 198 | |
| 199 | /* FSM9xxx ID */ |
| 200 | [94] = FSM_CPU_9XXX, |
| 201 | [95] = FSM_CPU_9XXX, |
| 202 | |
| 203 | /* 7x25AA ID */ |
| 204 | [98] = MSM_CPU_7X25AA, |
| 205 | [99] = MSM_CPU_7X25AA, |
| 206 | [100] = MSM_CPU_7X25AA, |
| 207 | |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 208 | /* 7x27AA ID */ |
| 209 | [101] = MSM_CPU_7X27AA, |
| 210 | [102] = MSM_CPU_7X27AA, |
| 211 | [103] = MSM_CPU_7X27AA, |
Kaushal Kumar | dc0beb9 | 2012-06-29 19:31:05 +0530 | [diff] [blame] | 212 | [136] = MSM_CPU_7X27AA, |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 213 | |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 214 | /* 9x15 ID */ |
| 215 | [104] = MSM_CPU_9615, |
Rohit Vaswani | 865f2ca | 2011-10-03 17:40:42 -0700 | [diff] [blame] | 216 | [105] = MSM_CPU_9615, |
Rohit Vaswani | 7a83fa9 | 2012-01-11 15:05:39 -0800 | [diff] [blame] | 217 | [106] = MSM_CPU_9615, |
| 218 | [107] = MSM_CPU_9615, |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 219 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 220 | /* 8064 IDs */ |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 221 | [109] = MSM_CPU_8064, |
| 222 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 223 | /* 8930 IDs */ |
| 224 | [116] = MSM_CPU_8930, |
Stepan Moskovchenko | db71cd6 | 2011-11-23 14:28:57 -0800 | [diff] [blame] | 225 | [117] = MSM_CPU_8930, |
| 226 | [118] = MSM_CPU_8930, |
| 227 | [119] = MSM_CPU_8930, |
| 228 | |
| 229 | /* 8627 IDs */ |
| 230 | [120] = MSM_CPU_8627, |
| 231 | [121] = MSM_CPU_8627, |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 232 | |
Jin Hong | 0698b56 | 2011-11-05 13:57:25 -0700 | [diff] [blame] | 233 | /* 8660A ID */ |
| 234 | [122] = MSM_CPU_8960, |
| 235 | |
| 236 | /* 8260A ID */ |
| 237 | [123] = MSM_CPU_8960, |
| 238 | |
| 239 | /* 8060A ID */ |
| 240 | [124] = MSM_CPU_8960, |
| 241 | |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 242 | /* 8974 IDs */ |
| 243 | [126] = MSM_CPU_8974, |
Sathish Ambley | a99d685 | 2011-10-31 15:50:55 -0700 | [diff] [blame] | 244 | |
Taniya Das | a04e189 | 2011-11-16 14:49:12 +0530 | [diff] [blame] | 245 | /* 8625 IDs */ |
| 246 | [127] = MSM_CPU_8625, |
| 247 | [128] = MSM_CPU_8625, |
| 248 | [129] = MSM_CPU_8625, |
| 249 | |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 250 | /* 8064 MPQ ID */ |
| 251 | [130] = MSM_CPU_8064, |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 252 | |
Pankaj Kumar | fee56a8 | 2012-04-17 14:26:49 +0530 | [diff] [blame] | 253 | /* 7x25AB IDs */ |
| 254 | [131] = MSM_CPU_7X25AB, |
| 255 | [132] = MSM_CPU_7X25AB, |
| 256 | [133] = MSM_CPU_7X25AB, |
Kaushal Kumar | dc0beb9 | 2012-06-29 19:31:05 +0530 | [diff] [blame] | 257 | [135] = MSM_CPU_7X25AB, |
Pankaj Kumar | fee56a8 | 2012-04-17 14:26:49 +0530 | [diff] [blame] | 258 | |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 259 | /* 9625 IDs */ |
| 260 | [134] = MSM_CPU_9625, |
| 261 | |
Stepan Moskovchenko | ec6a803 | 2012-07-06 15:42:01 -0700 | [diff] [blame] | 262 | /* 8960AB IDs */ |
| 263 | [138] = MSM_CPU_8960AB, |
| 264 | [139] = MSM_CPU_8960AB, |
| 265 | [140] = MSM_CPU_8960AB, |
| 266 | [141] = MSM_CPU_8960AB, |
| 267 | |
Stepan Moskovchenko | 8f362fe | 2012-07-12 19:19:52 -0700 | [diff] [blame] | 268 | /* 8930AA IDs */ |
Stepan Moskovchenko | 8b38bb3 | 2012-07-06 16:57:34 -0700 | [diff] [blame] | 269 | [142] = MSM_CPU_8930AA, |
Stepan Moskovchenko | 8f362fe | 2012-07-12 19:19:52 -0700 | [diff] [blame] | 270 | [143] = MSM_CPU_8930AA, |
| 271 | [144] = MSM_CPU_8930AA, |
Stepan Moskovchenko | 8b38bb3 | 2012-07-06 16:57:34 -0700 | [diff] [blame] | 272 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 273 | /* Uninitialized IDs are not known to run Linux. |
| 274 | MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are |
| 275 | considered as unknown CPU. */ |
| 276 | }; |
| 277 | |
| 278 | static enum msm_cpu cur_cpu; |
| 279 | |
| 280 | static struct socinfo_v1 dummy_socinfo = { |
| 281 | .format = 1, |
| 282 | .version = 1, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | uint32_t socinfo_get_id(void) |
| 286 | { |
| 287 | return (socinfo) ? socinfo->v1.id : 0; |
| 288 | } |
| 289 | EXPORT_SYMBOL_GPL(socinfo_get_id); |
| 290 | |
| 291 | uint32_t socinfo_get_version(void) |
| 292 | { |
| 293 | return (socinfo) ? socinfo->v1.version : 0; |
| 294 | } |
| 295 | |
| 296 | char *socinfo_get_build_id(void) |
| 297 | { |
| 298 | return (socinfo) ? socinfo->v1.build_id : NULL; |
| 299 | } |
| 300 | |
| 301 | uint32_t socinfo_get_raw_id(void) |
| 302 | { |
| 303 | return socinfo ? |
| 304 | (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0) |
| 305 | : 0; |
| 306 | } |
| 307 | |
| 308 | uint32_t socinfo_get_raw_version(void) |
| 309 | { |
| 310 | return socinfo ? |
| 311 | (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0) |
| 312 | : 0; |
| 313 | } |
| 314 | |
| 315 | uint32_t socinfo_get_platform_type(void) |
| 316 | { |
| 317 | return socinfo ? |
| 318 | (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0) |
| 319 | : 0; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | uint32_t socinfo_get_platform_version(void) |
| 324 | { |
| 325 | return socinfo ? |
| 326 | (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0) |
| 327 | : 0; |
| 328 | } |
| 329 | |
| 330 | /* This information is directly encoded by the machine id */ |
| 331 | /* Thus no external callers rely on this information at the moment */ |
| 332 | static uint32_t socinfo_get_accessory_chip(void) |
| 333 | { |
| 334 | return socinfo ? |
| 335 | (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0) |
| 336 | : 0; |
| 337 | } |
| 338 | |
| 339 | uint32_t socinfo_get_platform_subtype(void) |
| 340 | { |
| 341 | return socinfo ? |
| 342 | (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0) |
| 343 | : 0; |
| 344 | } |
| 345 | |
| 346 | enum msm_cpu socinfo_get_msm_cpu(void) |
| 347 | { |
| 348 | return cur_cpu; |
| 349 | } |
| 350 | EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu); |
| 351 | |
| 352 | static ssize_t |
| 353 | socinfo_show_id(struct sys_device *dev, |
| 354 | struct sysdev_attribute *attr, |
| 355 | char *buf) |
| 356 | { |
| 357 | if (!socinfo) { |
| 358 | pr_err("%s: No socinfo found!\n", __func__); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id()); |
| 363 | } |
| 364 | |
| 365 | static ssize_t |
| 366 | socinfo_show_version(struct sys_device *dev, |
| 367 | struct sysdev_attribute *attr, |
| 368 | char *buf) |
| 369 | { |
| 370 | uint32_t version; |
| 371 | |
| 372 | if (!socinfo) { |
| 373 | pr_err("%s: No socinfo found!\n", __func__); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | version = socinfo_get_version(); |
| 378 | return snprintf(buf, PAGE_SIZE, "%u.%u\n", |
| 379 | SOCINFO_VERSION_MAJOR(version), |
| 380 | SOCINFO_VERSION_MINOR(version)); |
| 381 | } |
| 382 | |
| 383 | static ssize_t |
| 384 | socinfo_show_build_id(struct sys_device *dev, |
| 385 | struct sysdev_attribute *attr, |
| 386 | char *buf) |
| 387 | { |
| 388 | if (!socinfo) { |
| 389 | pr_err("%s: No socinfo found!\n", __func__); |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id()); |
| 394 | } |
| 395 | |
| 396 | static ssize_t |
| 397 | socinfo_show_raw_id(struct sys_device *dev, |
| 398 | struct sysdev_attribute *attr, |
| 399 | char *buf) |
| 400 | { |
| 401 | if (!socinfo) { |
| 402 | pr_err("%s: No socinfo found!\n", __func__); |
| 403 | return 0; |
| 404 | } |
| 405 | if (socinfo->v1.format < 2) { |
| 406 | pr_err("%s: Raw ID not available!\n", __func__); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id()); |
| 411 | } |
| 412 | |
| 413 | static ssize_t |
| 414 | socinfo_show_raw_version(struct sys_device *dev, |
| 415 | struct sysdev_attribute *attr, |
| 416 | char *buf) |
| 417 | { |
| 418 | if (!socinfo) { |
| 419 | pr_err("%s: No socinfo found!\n", __func__); |
| 420 | return 0; |
| 421 | } |
| 422 | if (socinfo->v1.format < 2) { |
| 423 | pr_err("%s: Raw version not available!\n", __func__); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version()); |
| 428 | } |
| 429 | |
| 430 | static ssize_t |
| 431 | socinfo_show_platform_type(struct sys_device *dev, |
| 432 | struct sysdev_attribute *attr, |
| 433 | char *buf) |
| 434 | { |
| 435 | uint32_t hw_type; |
| 436 | |
| 437 | if (!socinfo) { |
| 438 | pr_err("%s: No socinfo found!\n", __func__); |
| 439 | return 0; |
| 440 | } |
| 441 | if (socinfo->v1.format < 3) { |
| 442 | pr_err("%s: platform type not available!\n", __func__); |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | hw_type = socinfo_get_platform_type(); |
| 447 | if (hw_type >= HW_PLATFORM_INVALID) { |
| 448 | pr_err("%s: Invalid hardware platform type found\n", |
| 449 | __func__); |
| 450 | hw_type = HW_PLATFORM_UNKNOWN; |
| 451 | } |
| 452 | |
| 453 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]); |
| 454 | } |
| 455 | |
| 456 | static ssize_t |
| 457 | socinfo_show_platform_version(struct sys_device *dev, |
| 458 | struct sysdev_attribute *attr, |
| 459 | char *buf) |
| 460 | { |
| 461 | |
| 462 | if (!socinfo) { |
| 463 | pr_err("%s: No socinfo found!\n", __func__); |
| 464 | return 0; |
| 465 | } |
| 466 | if (socinfo->v1.format < 4) { |
| 467 | pr_err("%s: platform version not available!\n", __func__); |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 472 | socinfo_get_platform_version()); |
| 473 | } |
| 474 | |
| 475 | static ssize_t |
| 476 | socinfo_show_accessory_chip(struct sys_device *dev, |
| 477 | struct sysdev_attribute *attr, |
| 478 | char *buf) |
| 479 | { |
| 480 | if (!socinfo) { |
| 481 | pr_err("%s: No socinfo found!\n", __func__); |
| 482 | return 0; |
| 483 | } |
| 484 | if (socinfo->v1.format < 5) { |
| 485 | pr_err("%s: accessory chip not available!\n", __func__); |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 490 | socinfo_get_accessory_chip()); |
| 491 | } |
| 492 | |
| 493 | static ssize_t |
| 494 | socinfo_show_platform_subtype(struct sys_device *dev, |
| 495 | struct sysdev_attribute *attr, |
| 496 | char *buf) |
| 497 | { |
| 498 | uint32_t hw_subtype; |
| 499 | if (!socinfo) { |
| 500 | pr_err("%s: No socinfo found!\n", __func__); |
| 501 | return 0; |
| 502 | } |
| 503 | if (socinfo->v1.format < 6) { |
| 504 | pr_err("%s: platform subtype not available!\n", __func__); |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | hw_subtype = socinfo_get_platform_subtype(); |
| 509 | if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) { |
| 510 | pr_err("%s: Invalid hardware platform sub type found\n", |
| 511 | __func__); |
| 512 | hw_subtype = PLATFORM_SUBTYPE_UNKNOWN; |
| 513 | } |
| 514 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", |
| 515 | hw_platform_subtype[hw_subtype]); |
| 516 | } |
| 517 | |
| 518 | static struct sysdev_attribute socinfo_v1_files[] = { |
| 519 | _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL), |
| 520 | _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL), |
| 521 | _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL), |
| 522 | }; |
| 523 | |
| 524 | static struct sysdev_attribute socinfo_v2_files[] = { |
| 525 | _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL), |
| 526 | _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL), |
| 527 | }; |
| 528 | |
| 529 | static struct sysdev_attribute socinfo_v3_files[] = { |
| 530 | _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL), |
| 531 | }; |
| 532 | |
| 533 | static struct sysdev_attribute socinfo_v4_files[] = { |
| 534 | _SYSDEV_ATTR(platform_version, 0444, |
| 535 | socinfo_show_platform_version, NULL), |
| 536 | }; |
| 537 | |
| 538 | static struct sysdev_attribute socinfo_v5_files[] = { |
| 539 | _SYSDEV_ATTR(accessory_chip, 0444, |
| 540 | socinfo_show_accessory_chip, NULL), |
| 541 | }; |
| 542 | |
| 543 | static struct sysdev_attribute socinfo_v6_files[] = { |
| 544 | _SYSDEV_ATTR(platform_subtype, 0444, |
| 545 | socinfo_show_platform_subtype, NULL), |
| 546 | }; |
| 547 | |
| 548 | static struct sysdev_class soc_sysdev_class = { |
| 549 | .name = "soc", |
| 550 | }; |
| 551 | |
| 552 | static struct sys_device soc_sys_device = { |
| 553 | .id = 0, |
| 554 | .cls = &soc_sysdev_class, |
| 555 | }; |
| 556 | |
| 557 | static int __init socinfo_create_files(struct sys_device *dev, |
| 558 | struct sysdev_attribute files[], |
| 559 | int size) |
| 560 | { |
| 561 | int i; |
| 562 | for (i = 0; i < size; i++) { |
| 563 | int err = sysdev_create_file(dev, &files[i]); |
| 564 | if (err) { |
| 565 | pr_err("%s: sysdev_create_file(%s)=%d\n", |
| 566 | __func__, files[i].attr.name, err); |
| 567 | return err; |
| 568 | } |
| 569 | } |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static int __init socinfo_init_sysdev(void) |
| 574 | { |
| 575 | int err; |
| 576 | |
| 577 | if (!socinfo) { |
| 578 | pr_err("%s: No socinfo found!\n", __func__); |
| 579 | return -ENODEV; |
| 580 | } |
| 581 | |
| 582 | err = sysdev_class_register(&soc_sysdev_class); |
| 583 | if (err) { |
| 584 | pr_err("%s: sysdev_class_register fail (%d)\n", |
| 585 | __func__, err); |
| 586 | return err; |
| 587 | } |
| 588 | err = sysdev_register(&soc_sys_device); |
| 589 | if (err) { |
| 590 | pr_err("%s: sysdev_register fail (%d)\n", |
| 591 | __func__, err); |
| 592 | return err; |
| 593 | } |
| 594 | socinfo_create_files(&soc_sys_device, socinfo_v1_files, |
| 595 | ARRAY_SIZE(socinfo_v1_files)); |
| 596 | if (socinfo->v1.format < 2) |
| 597 | return err; |
| 598 | socinfo_create_files(&soc_sys_device, socinfo_v2_files, |
| 599 | ARRAY_SIZE(socinfo_v2_files)); |
| 600 | |
| 601 | if (socinfo->v1.format < 3) |
| 602 | return err; |
| 603 | |
| 604 | socinfo_create_files(&soc_sys_device, socinfo_v3_files, |
| 605 | ARRAY_SIZE(socinfo_v3_files)); |
| 606 | |
| 607 | if (socinfo->v1.format < 4) |
| 608 | return err; |
| 609 | |
| 610 | socinfo_create_files(&soc_sys_device, socinfo_v4_files, |
| 611 | ARRAY_SIZE(socinfo_v4_files)); |
| 612 | |
| 613 | if (socinfo->v1.format < 5) |
| 614 | return err; |
| 615 | |
| 616 | socinfo_create_files(&soc_sys_device, socinfo_v5_files, |
| 617 | ARRAY_SIZE(socinfo_v5_files)); |
| 618 | |
| 619 | if (socinfo->v1.format < 6) |
| 620 | return err; |
| 621 | |
| 622 | return socinfo_create_files(&soc_sys_device, socinfo_v6_files, |
| 623 | ARRAY_SIZE(socinfo_v6_files)); |
| 624 | |
| 625 | } |
| 626 | |
| 627 | arch_initcall(socinfo_init_sysdev); |
| 628 | |
Stephen Boyd | 69a22e4 | 2012-02-22 09:16:07 -0800 | [diff] [blame] | 629 | static void * __init setup_dummy_socinfo(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 630 | { |
| 631 | if (machine_is_msm8960_rumi3() || machine_is_msm8960_sim() || |
| 632 | machine_is_msm8960_cdp()) |
| 633 | dummy_socinfo.id = 87; |
Joel King | dad535a | 2011-09-09 10:59:15 -0700 | [diff] [blame] | 634 | else if (machine_is_apq8064_rumi3() || machine_is_apq8064_sim()) |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 635 | dummy_socinfo.id = 109; |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 636 | else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp()) |
| 637 | dummy_socinfo.id = 104; |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 638 | else if (early_machine_is_msm8974()) { |
Sathish Ambley | a99d685 | 2011-10-31 15:50:55 -0700 | [diff] [blame] | 639 | dummy_socinfo.id = 126; |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 640 | strlcpy(dummy_socinfo.build_id, "msm8974 - ", |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 641 | sizeof(dummy_socinfo.build_id)); |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 642 | } else if (early_machine_is_msm9625()) { |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 643 | dummy_socinfo.id = 134; |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 644 | strlcpy(dummy_socinfo.build_id, "msm9625 - ", |
| 645 | sizeof(dummy_socinfo.build_id)); |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 646 | } else if (machine_is_msm8625_rumi3()) |
Taniya Das | a04e189 | 2011-11-16 14:49:12 +0530 | [diff] [blame] | 647 | dummy_socinfo.id = 127; |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 648 | strlcat(dummy_socinfo.build_id, "Dummy socinfo", |
| 649 | sizeof(dummy_socinfo.build_id)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 650 | return (void *) &dummy_socinfo; |
| 651 | } |
| 652 | |
| 653 | int __init socinfo_init(void) |
| 654 | { |
| 655 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v6)); |
| 656 | |
| 657 | if (!socinfo) |
| 658 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 659 | sizeof(struct socinfo_v5)); |
| 660 | |
| 661 | if (!socinfo) |
| 662 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 663 | sizeof(struct socinfo_v4)); |
| 664 | |
| 665 | if (!socinfo) |
| 666 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 667 | sizeof(struct socinfo_v3)); |
| 668 | |
| 669 | if (!socinfo) |
| 670 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 671 | sizeof(struct socinfo_v2)); |
| 672 | |
| 673 | if (!socinfo) |
| 674 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 675 | sizeof(struct socinfo_v1)); |
| 676 | |
| 677 | if (!socinfo) { |
| 678 | pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on " |
| 679 | "dummy values.\n", __func__); |
| 680 | socinfo = setup_dummy_socinfo(); |
| 681 | } |
| 682 | |
| 683 | WARN(!socinfo_get_id(), "Unknown SOC ID!\n"); |
| 684 | WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id), |
| 685 | "New IDs added! ID => CPU mapping might need an update.\n"); |
| 686 | |
| 687 | if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id)) |
| 688 | cur_cpu = cpu_of_id[socinfo->v1.id]; |
| 689 | |
| 690 | switch (socinfo->v1.format) { |
| 691 | case 1: |
| 692 | pr_info("%s: v%u, id=%u, ver=%u.%u\n", |
| 693 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 694 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 695 | SOCINFO_VERSION_MINOR(socinfo->v1.version)); |
| 696 | break; |
| 697 | case 2: |
| 698 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 699 | "raw_id=%u, raw_ver=%u\n", |
| 700 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 701 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 702 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 703 | socinfo->v2.raw_id, socinfo->v2.raw_version); |
| 704 | break; |
| 705 | case 3: |
| 706 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 707 | "raw_id=%u, raw_ver=%u, hw_plat=%u\n", |
| 708 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 709 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 710 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 711 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 712 | socinfo->v3.hw_platform); |
| 713 | break; |
| 714 | case 4: |
| 715 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 716 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n", |
| 717 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 718 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 719 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 720 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 721 | socinfo->v3.hw_platform, socinfo->v4.platform_version); |
| 722 | break; |
| 723 | case 5: |
| 724 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 725 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n" |
| 726 | " accessory_chip=%u\n", __func__, socinfo->v1.format, |
| 727 | socinfo->v1.id, |
| 728 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 729 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 730 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 731 | socinfo->v3.hw_platform, socinfo->v4.platform_version, |
| 732 | socinfo->v5.accessory_chip); |
| 733 | break; |
| 734 | case 6: |
| 735 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 736 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n" |
| 737 | " accessory_chip=%u hw_plat_subtype=%u\n", __func__, |
| 738 | socinfo->v1.format, |
| 739 | socinfo->v1.id, |
| 740 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 741 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 742 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 743 | socinfo->v3.hw_platform, socinfo->v4.platform_version, |
| 744 | socinfo->v5.accessory_chip, |
| 745 | socinfo->v6.hw_platform_subtype); |
| 746 | break; |
| 747 | default: |
| 748 | pr_err("%s: Unknown format found\n", __func__); |
| 749 | break; |
| 750 | } |
| 751 | |
| 752 | return 0; |
| 753 | } |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 754 | |
| 755 | const int get_core_count(void) |
| 756 | { |
| 757 | if (!(read_cpuid_mpidr() & BIT(31))) |
| 758 | return 1; |
| 759 | |
| 760 | if (read_cpuid_mpidr() & BIT(30) && |
| 761 | !machine_is_msm8960_sim() && |
| 762 | !machine_is_apq8064_sim()) |
| 763 | return 1; |
| 764 | |
| 765 | /* 1 + the PART[1:0] field of MIDR */ |
| 766 | return ((read_cpuid_id() >> 4) & 3) + 1; |
| 767 | } |
| 768 | |
| 769 | const int read_msm_cpu_type(void) |
| 770 | { |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 771 | if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 772 | return MSM_CPU_8960; |
| 773 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 774 | if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN) |
| 775 | return socinfo_get_msm_cpu(); |
| 776 | |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 777 | switch (read_cpuid_id()) { |
| 778 | case 0x510F02D0: |
| 779 | case 0x510F02D2: |
| 780 | case 0x510F02D4: |
| 781 | return MSM_CPU_8X60; |
| 782 | |
| 783 | case 0x510F04D0: |
| 784 | case 0x510F04D1: |
| 785 | case 0x510F04D2: |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 786 | case 0x511F04D0: |
| 787 | case 0x512F04D0: |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 788 | return MSM_CPU_8960; |
| 789 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 790 | case 0x51404D11: /* We can't get here unless we are in bringup */ |
| 791 | return MSM_CPU_8930; |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 792 | |
| 793 | case 0x510F06F0: |
| 794 | return MSM_CPU_8064; |
| 795 | |
| 796 | default: |
| 797 | return MSM_CPU_UNKNOWN; |
| 798 | }; |
| 799 | } |
Stepan Moskovchenko | 70dc7cf | 2011-08-22 19:08:42 -0700 | [diff] [blame] | 800 | |
Jin Hong | 12b8b43 | 2012-07-18 10:00:31 -0700 | [diff] [blame] | 801 | const int cpu_is_krait(void) |
| 802 | { |
| 803 | return ((read_cpuid_id() & 0xFF00FC00) == 0x51000400); |
| 804 | } |
| 805 | |
Stepan Moskovchenko | 70dc7cf | 2011-08-22 19:08:42 -0700 | [diff] [blame] | 806 | const int cpu_is_krait_v1(void) |
| 807 | { |
| 808 | switch (read_cpuid_id()) { |
| 809 | case 0x510F04D0: |
| 810 | case 0x510F04D1: |
| 811 | case 0x510F04D2: |
| 812 | return 1; |
| 813 | |
| 814 | default: |
| 815 | return 0; |
| 816 | }; |
| 817 | } |
Jin Hong | 12b8b43 | 2012-07-18 10:00:31 -0700 | [diff] [blame] | 818 | |
| 819 | const int cpu_is_krait_v2(void) |
| 820 | { |
| 821 | switch (read_cpuid_id()) { |
| 822 | case 0x511F04D0: |
| 823 | case 0x511F04D1: |
| 824 | case 0x511F04D2: |
| 825 | case 0x511F04D3: |
| 826 | case 0x511F04D4: |
| 827 | |
| 828 | case 0x510F06F0: |
| 829 | case 0x510F06F1: |
| 830 | case 0x510F06F2: |
| 831 | return 1; |
| 832 | |
| 833 | default: |
| 834 | return 0; |
| 835 | }; |
| 836 | } |