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, |
| 212 | |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 213 | /* 9x15 ID */ |
| 214 | [104] = MSM_CPU_9615, |
Rohit Vaswani | 865f2ca | 2011-10-03 17:40:42 -0700 | [diff] [blame] | 215 | [105] = MSM_CPU_9615, |
Rohit Vaswani | 7a83fa9 | 2012-01-11 15:05:39 -0800 | [diff] [blame] | 216 | [106] = MSM_CPU_9615, |
| 217 | [107] = MSM_CPU_9615, |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 218 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 219 | /* 8064 IDs */ |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 220 | [109] = MSM_CPU_8064, |
| 221 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 222 | /* 8930 IDs */ |
| 223 | [116] = MSM_CPU_8930, |
Stepan Moskovchenko | db71cd6 | 2011-11-23 14:28:57 -0800 | [diff] [blame] | 224 | [117] = MSM_CPU_8930, |
| 225 | [118] = MSM_CPU_8930, |
| 226 | [119] = MSM_CPU_8930, |
| 227 | |
| 228 | /* 8627 IDs */ |
| 229 | [120] = MSM_CPU_8627, |
| 230 | [121] = MSM_CPU_8627, |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 231 | |
Jin Hong | 0698b56 | 2011-11-05 13:57:25 -0700 | [diff] [blame] | 232 | /* 8660A ID */ |
| 233 | [122] = MSM_CPU_8960, |
| 234 | |
| 235 | /* 8260A ID */ |
| 236 | [123] = MSM_CPU_8960, |
| 237 | |
| 238 | /* 8060A ID */ |
| 239 | [124] = MSM_CPU_8960, |
| 240 | |
Sathish Ambley | a99d685 | 2011-10-31 15:50:55 -0700 | [diff] [blame] | 241 | /* Copper IDs */ |
| 242 | [126] = MSM_CPU_COPPER, |
| 243 | |
Taniya Das | a04e189 | 2011-11-16 14:49:12 +0530 | [diff] [blame] | 244 | /* 8625 IDs */ |
| 245 | [127] = MSM_CPU_8625, |
| 246 | [128] = MSM_CPU_8625, |
| 247 | [129] = MSM_CPU_8625, |
| 248 | |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 249 | /* 8064 MPQ ID */ |
| 250 | [130] = MSM_CPU_8064, |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 251 | |
Pankaj Kumar | fee56a8 | 2012-04-17 14:26:49 +0530 | [diff] [blame] | 252 | /* 7x25AB IDs */ |
| 253 | [131] = MSM_CPU_7X25AB, |
| 254 | [132] = MSM_CPU_7X25AB, |
| 255 | [133] = MSM_CPU_7X25AB, |
| 256 | |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 257 | /* 9625 IDs */ |
| 258 | [134] = MSM_CPU_9625, |
| 259 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | /* Uninitialized IDs are not known to run Linux. |
| 261 | MSM_CPU_UNKNOWN is set to 0 to ensure these IDs are |
| 262 | considered as unknown CPU. */ |
| 263 | }; |
| 264 | |
| 265 | static enum msm_cpu cur_cpu; |
| 266 | |
| 267 | static struct socinfo_v1 dummy_socinfo = { |
| 268 | .format = 1, |
| 269 | .version = 1, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | uint32_t socinfo_get_id(void) |
| 273 | { |
| 274 | return (socinfo) ? socinfo->v1.id : 0; |
| 275 | } |
| 276 | EXPORT_SYMBOL_GPL(socinfo_get_id); |
| 277 | |
| 278 | uint32_t socinfo_get_version(void) |
| 279 | { |
| 280 | return (socinfo) ? socinfo->v1.version : 0; |
| 281 | } |
| 282 | |
| 283 | char *socinfo_get_build_id(void) |
| 284 | { |
| 285 | return (socinfo) ? socinfo->v1.build_id : NULL; |
| 286 | } |
| 287 | |
| 288 | uint32_t socinfo_get_raw_id(void) |
| 289 | { |
| 290 | return socinfo ? |
| 291 | (socinfo->v1.format >= 2 ? socinfo->v2.raw_id : 0) |
| 292 | : 0; |
| 293 | } |
| 294 | |
| 295 | uint32_t socinfo_get_raw_version(void) |
| 296 | { |
| 297 | return socinfo ? |
| 298 | (socinfo->v1.format >= 2 ? socinfo->v2.raw_version : 0) |
| 299 | : 0; |
| 300 | } |
| 301 | |
| 302 | uint32_t socinfo_get_platform_type(void) |
| 303 | { |
| 304 | return socinfo ? |
| 305 | (socinfo->v1.format >= 3 ? socinfo->v3.hw_platform : 0) |
| 306 | : 0; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | uint32_t socinfo_get_platform_version(void) |
| 311 | { |
| 312 | return socinfo ? |
| 313 | (socinfo->v1.format >= 4 ? socinfo->v4.platform_version : 0) |
| 314 | : 0; |
| 315 | } |
| 316 | |
| 317 | /* This information is directly encoded by the machine id */ |
| 318 | /* Thus no external callers rely on this information at the moment */ |
| 319 | static uint32_t socinfo_get_accessory_chip(void) |
| 320 | { |
| 321 | return socinfo ? |
| 322 | (socinfo->v1.format >= 5 ? socinfo->v5.accessory_chip : 0) |
| 323 | : 0; |
| 324 | } |
| 325 | |
| 326 | uint32_t socinfo_get_platform_subtype(void) |
| 327 | { |
| 328 | return socinfo ? |
| 329 | (socinfo->v1.format >= 6 ? socinfo->v6.hw_platform_subtype : 0) |
| 330 | : 0; |
| 331 | } |
| 332 | |
| 333 | enum msm_cpu socinfo_get_msm_cpu(void) |
| 334 | { |
| 335 | return cur_cpu; |
| 336 | } |
| 337 | EXPORT_SYMBOL_GPL(socinfo_get_msm_cpu); |
| 338 | |
| 339 | static ssize_t |
| 340 | socinfo_show_id(struct sys_device *dev, |
| 341 | struct sysdev_attribute *attr, |
| 342 | char *buf) |
| 343 | { |
| 344 | if (!socinfo) { |
| 345 | pr_err("%s: No socinfo found!\n", __func__); |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_id()); |
| 350 | } |
| 351 | |
| 352 | static ssize_t |
| 353 | socinfo_show_version(struct sys_device *dev, |
| 354 | struct sysdev_attribute *attr, |
| 355 | char *buf) |
| 356 | { |
| 357 | uint32_t version; |
| 358 | |
| 359 | if (!socinfo) { |
| 360 | pr_err("%s: No socinfo found!\n", __func__); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | version = socinfo_get_version(); |
| 365 | return snprintf(buf, PAGE_SIZE, "%u.%u\n", |
| 366 | SOCINFO_VERSION_MAJOR(version), |
| 367 | SOCINFO_VERSION_MINOR(version)); |
| 368 | } |
| 369 | |
| 370 | static ssize_t |
| 371 | socinfo_show_build_id(struct sys_device *dev, |
| 372 | struct sysdev_attribute *attr, |
| 373 | char *buf) |
| 374 | { |
| 375 | if (!socinfo) { |
| 376 | pr_err("%s: No socinfo found!\n", __func__); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", socinfo_get_build_id()); |
| 381 | } |
| 382 | |
| 383 | static ssize_t |
| 384 | socinfo_show_raw_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 | if (socinfo->v1.format < 2) { |
| 393 | pr_err("%s: Raw ID not available!\n", __func__); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_id()); |
| 398 | } |
| 399 | |
| 400 | static ssize_t |
| 401 | socinfo_show_raw_version(struct sys_device *dev, |
| 402 | struct sysdev_attribute *attr, |
| 403 | char *buf) |
| 404 | { |
| 405 | if (!socinfo) { |
| 406 | pr_err("%s: No socinfo found!\n", __func__); |
| 407 | return 0; |
| 408 | } |
| 409 | if (socinfo->v1.format < 2) { |
| 410 | pr_err("%s: Raw version not available!\n", __func__); |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | return snprintf(buf, PAGE_SIZE, "%u\n", socinfo_get_raw_version()); |
| 415 | } |
| 416 | |
| 417 | static ssize_t |
| 418 | socinfo_show_platform_type(struct sys_device *dev, |
| 419 | struct sysdev_attribute *attr, |
| 420 | char *buf) |
| 421 | { |
| 422 | uint32_t hw_type; |
| 423 | |
| 424 | if (!socinfo) { |
| 425 | pr_err("%s: No socinfo found!\n", __func__); |
| 426 | return 0; |
| 427 | } |
| 428 | if (socinfo->v1.format < 3) { |
| 429 | pr_err("%s: platform type not available!\n", __func__); |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | hw_type = socinfo_get_platform_type(); |
| 434 | if (hw_type >= HW_PLATFORM_INVALID) { |
| 435 | pr_err("%s: Invalid hardware platform type found\n", |
| 436 | __func__); |
| 437 | hw_type = HW_PLATFORM_UNKNOWN; |
| 438 | } |
| 439 | |
| 440 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", hw_platform[hw_type]); |
| 441 | } |
| 442 | |
| 443 | static ssize_t |
| 444 | socinfo_show_platform_version(struct sys_device *dev, |
| 445 | struct sysdev_attribute *attr, |
| 446 | char *buf) |
| 447 | { |
| 448 | |
| 449 | if (!socinfo) { |
| 450 | pr_err("%s: No socinfo found!\n", __func__); |
| 451 | return 0; |
| 452 | } |
| 453 | if (socinfo->v1.format < 4) { |
| 454 | pr_err("%s: platform version not available!\n", __func__); |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 459 | socinfo_get_platform_version()); |
| 460 | } |
| 461 | |
| 462 | static ssize_t |
| 463 | socinfo_show_accessory_chip(struct sys_device *dev, |
| 464 | struct sysdev_attribute *attr, |
| 465 | char *buf) |
| 466 | { |
| 467 | if (!socinfo) { |
| 468 | pr_err("%s: No socinfo found!\n", __func__); |
| 469 | return 0; |
| 470 | } |
| 471 | if (socinfo->v1.format < 5) { |
| 472 | pr_err("%s: accessory chip not available!\n", __func__); |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 477 | socinfo_get_accessory_chip()); |
| 478 | } |
| 479 | |
| 480 | static ssize_t |
| 481 | socinfo_show_platform_subtype(struct sys_device *dev, |
| 482 | struct sysdev_attribute *attr, |
| 483 | char *buf) |
| 484 | { |
| 485 | uint32_t hw_subtype; |
| 486 | if (!socinfo) { |
| 487 | pr_err("%s: No socinfo found!\n", __func__); |
| 488 | return 0; |
| 489 | } |
| 490 | if (socinfo->v1.format < 6) { |
| 491 | pr_err("%s: platform subtype not available!\n", __func__); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | hw_subtype = socinfo_get_platform_subtype(); |
| 496 | if (hw_subtype >= PLATFORM_SUBTYPE_INVALID) { |
| 497 | pr_err("%s: Invalid hardware platform sub type found\n", |
| 498 | __func__); |
| 499 | hw_subtype = PLATFORM_SUBTYPE_UNKNOWN; |
| 500 | } |
| 501 | return snprintf(buf, PAGE_SIZE, "%-.32s\n", |
| 502 | hw_platform_subtype[hw_subtype]); |
| 503 | } |
| 504 | |
| 505 | static struct sysdev_attribute socinfo_v1_files[] = { |
| 506 | _SYSDEV_ATTR(id, 0444, socinfo_show_id, NULL), |
| 507 | _SYSDEV_ATTR(version, 0444, socinfo_show_version, NULL), |
| 508 | _SYSDEV_ATTR(build_id, 0444, socinfo_show_build_id, NULL), |
| 509 | }; |
| 510 | |
| 511 | static struct sysdev_attribute socinfo_v2_files[] = { |
| 512 | _SYSDEV_ATTR(raw_id, 0444, socinfo_show_raw_id, NULL), |
| 513 | _SYSDEV_ATTR(raw_version, 0444, socinfo_show_raw_version, NULL), |
| 514 | }; |
| 515 | |
| 516 | static struct sysdev_attribute socinfo_v3_files[] = { |
| 517 | _SYSDEV_ATTR(hw_platform, 0444, socinfo_show_platform_type, NULL), |
| 518 | }; |
| 519 | |
| 520 | static struct sysdev_attribute socinfo_v4_files[] = { |
| 521 | _SYSDEV_ATTR(platform_version, 0444, |
| 522 | socinfo_show_platform_version, NULL), |
| 523 | }; |
| 524 | |
| 525 | static struct sysdev_attribute socinfo_v5_files[] = { |
| 526 | _SYSDEV_ATTR(accessory_chip, 0444, |
| 527 | socinfo_show_accessory_chip, NULL), |
| 528 | }; |
| 529 | |
| 530 | static struct sysdev_attribute socinfo_v6_files[] = { |
| 531 | _SYSDEV_ATTR(platform_subtype, 0444, |
| 532 | socinfo_show_platform_subtype, NULL), |
| 533 | }; |
| 534 | |
| 535 | static struct sysdev_class soc_sysdev_class = { |
| 536 | .name = "soc", |
| 537 | }; |
| 538 | |
| 539 | static struct sys_device soc_sys_device = { |
| 540 | .id = 0, |
| 541 | .cls = &soc_sysdev_class, |
| 542 | }; |
| 543 | |
| 544 | static int __init socinfo_create_files(struct sys_device *dev, |
| 545 | struct sysdev_attribute files[], |
| 546 | int size) |
| 547 | { |
| 548 | int i; |
| 549 | for (i = 0; i < size; i++) { |
| 550 | int err = sysdev_create_file(dev, &files[i]); |
| 551 | if (err) { |
| 552 | pr_err("%s: sysdev_create_file(%s)=%d\n", |
| 553 | __func__, files[i].attr.name, err); |
| 554 | return err; |
| 555 | } |
| 556 | } |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static int __init socinfo_init_sysdev(void) |
| 561 | { |
| 562 | int err; |
| 563 | |
| 564 | if (!socinfo) { |
| 565 | pr_err("%s: No socinfo found!\n", __func__); |
| 566 | return -ENODEV; |
| 567 | } |
| 568 | |
| 569 | err = sysdev_class_register(&soc_sysdev_class); |
| 570 | if (err) { |
| 571 | pr_err("%s: sysdev_class_register fail (%d)\n", |
| 572 | __func__, err); |
| 573 | return err; |
| 574 | } |
| 575 | err = sysdev_register(&soc_sys_device); |
| 576 | if (err) { |
| 577 | pr_err("%s: sysdev_register fail (%d)\n", |
| 578 | __func__, err); |
| 579 | return err; |
| 580 | } |
| 581 | socinfo_create_files(&soc_sys_device, socinfo_v1_files, |
| 582 | ARRAY_SIZE(socinfo_v1_files)); |
| 583 | if (socinfo->v1.format < 2) |
| 584 | return err; |
| 585 | socinfo_create_files(&soc_sys_device, socinfo_v2_files, |
| 586 | ARRAY_SIZE(socinfo_v2_files)); |
| 587 | |
| 588 | if (socinfo->v1.format < 3) |
| 589 | return err; |
| 590 | |
| 591 | socinfo_create_files(&soc_sys_device, socinfo_v3_files, |
| 592 | ARRAY_SIZE(socinfo_v3_files)); |
| 593 | |
| 594 | if (socinfo->v1.format < 4) |
| 595 | return err; |
| 596 | |
| 597 | socinfo_create_files(&soc_sys_device, socinfo_v4_files, |
| 598 | ARRAY_SIZE(socinfo_v4_files)); |
| 599 | |
| 600 | if (socinfo->v1.format < 5) |
| 601 | return err; |
| 602 | |
| 603 | socinfo_create_files(&soc_sys_device, socinfo_v5_files, |
| 604 | ARRAY_SIZE(socinfo_v5_files)); |
| 605 | |
| 606 | if (socinfo->v1.format < 6) |
| 607 | return err; |
| 608 | |
| 609 | return socinfo_create_files(&soc_sys_device, socinfo_v6_files, |
| 610 | ARRAY_SIZE(socinfo_v6_files)); |
| 611 | |
| 612 | } |
| 613 | |
| 614 | arch_initcall(socinfo_init_sysdev); |
| 615 | |
Stephen Boyd | 69a22e4 | 2012-02-22 09:16:07 -0800 | [diff] [blame] | 616 | static void * __init setup_dummy_socinfo(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 617 | { |
| 618 | if (machine_is_msm8960_rumi3() || machine_is_msm8960_sim() || |
| 619 | machine_is_msm8960_cdp()) |
| 620 | dummy_socinfo.id = 87; |
Joel King | dad535a | 2011-09-09 10:59:15 -0700 | [diff] [blame] | 621 | else if (machine_is_apq8064_rumi3() || machine_is_apq8064_sim()) |
Joel King | bf2ff51 | 2011-07-22 13:43:11 -0700 | [diff] [blame] | 622 | dummy_socinfo.id = 109; |
Rohit Vaswani | 8a28b4a | 2011-08-10 19:07:00 -0700 | [diff] [blame] | 623 | else if (machine_is_msm9615_mtp() || machine_is_msm9615_cdp()) |
| 624 | dummy_socinfo.id = 104; |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 625 | else if (early_machine_is_copper()) { |
Sathish Ambley | a99d685 | 2011-10-31 15:50:55 -0700 | [diff] [blame] | 626 | dummy_socinfo.id = 126; |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 627 | strlcpy(dummy_socinfo.build_id, "copper - ", |
| 628 | sizeof(dummy_socinfo.build_id)); |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 629 | } else if (early_machine_is_msm9625()) { |
Joel King | 8e0bf67 | 2012-05-18 15:40:40 -0700 | [diff] [blame] | 630 | dummy_socinfo.id = 134; |
Rohit Vaswani | 47ee9e9 | 2012-04-23 18:42:03 -0700 | [diff] [blame] | 631 | strlcpy(dummy_socinfo.build_id, "msm9625 - ", |
| 632 | sizeof(dummy_socinfo.build_id)); |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 633 | } else if (machine_is_msm8625_rumi3()) |
Taniya Das | a04e189 | 2011-11-16 14:49:12 +0530 | [diff] [blame] | 634 | dummy_socinfo.id = 127; |
Sathish Ambley | 3e265ce | 2012-03-08 16:44:04 -0800 | [diff] [blame] | 635 | strlcat(dummy_socinfo.build_id, "Dummy socinfo", |
| 636 | sizeof(dummy_socinfo.build_id)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 637 | return (void *) &dummy_socinfo; |
| 638 | } |
| 639 | |
| 640 | int __init socinfo_init(void) |
| 641 | { |
| 642 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, sizeof(struct socinfo_v6)); |
| 643 | |
| 644 | if (!socinfo) |
| 645 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 646 | sizeof(struct socinfo_v5)); |
| 647 | |
| 648 | if (!socinfo) |
| 649 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 650 | sizeof(struct socinfo_v4)); |
| 651 | |
| 652 | if (!socinfo) |
| 653 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 654 | sizeof(struct socinfo_v3)); |
| 655 | |
| 656 | if (!socinfo) |
| 657 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 658 | sizeof(struct socinfo_v2)); |
| 659 | |
| 660 | if (!socinfo) |
| 661 | socinfo = smem_alloc(SMEM_HW_SW_BUILD_ID, |
| 662 | sizeof(struct socinfo_v1)); |
| 663 | |
| 664 | if (!socinfo) { |
| 665 | pr_warn("%s: Can't find SMEM_HW_SW_BUILD_ID; falling back on " |
| 666 | "dummy values.\n", __func__); |
| 667 | socinfo = setup_dummy_socinfo(); |
| 668 | } |
| 669 | |
| 670 | WARN(!socinfo_get_id(), "Unknown SOC ID!\n"); |
| 671 | WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id), |
| 672 | "New IDs added! ID => CPU mapping might need an update.\n"); |
| 673 | |
| 674 | if (socinfo->v1.id < ARRAY_SIZE(cpu_of_id)) |
| 675 | cur_cpu = cpu_of_id[socinfo->v1.id]; |
| 676 | |
| 677 | switch (socinfo->v1.format) { |
| 678 | case 1: |
| 679 | pr_info("%s: v%u, id=%u, ver=%u.%u\n", |
| 680 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 681 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 682 | SOCINFO_VERSION_MINOR(socinfo->v1.version)); |
| 683 | break; |
| 684 | case 2: |
| 685 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 686 | "raw_id=%u, raw_ver=%u\n", |
| 687 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 688 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 689 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 690 | socinfo->v2.raw_id, socinfo->v2.raw_version); |
| 691 | break; |
| 692 | case 3: |
| 693 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 694 | "raw_id=%u, raw_ver=%u, hw_plat=%u\n", |
| 695 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 696 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 697 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 698 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 699 | socinfo->v3.hw_platform); |
| 700 | break; |
| 701 | case 4: |
| 702 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 703 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n", |
| 704 | __func__, socinfo->v1.format, socinfo->v1.id, |
| 705 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 706 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 707 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 708 | socinfo->v3.hw_platform, socinfo->v4.platform_version); |
| 709 | break; |
| 710 | case 5: |
| 711 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 712 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n" |
| 713 | " accessory_chip=%u\n", __func__, socinfo->v1.format, |
| 714 | socinfo->v1.id, |
| 715 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 716 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 717 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 718 | socinfo->v3.hw_platform, socinfo->v4.platform_version, |
| 719 | socinfo->v5.accessory_chip); |
| 720 | break; |
| 721 | case 6: |
| 722 | pr_info("%s: v%u, id=%u, ver=%u.%u, " |
| 723 | "raw_id=%u, raw_ver=%u, hw_plat=%u, hw_plat_ver=%u\n" |
| 724 | " accessory_chip=%u hw_plat_subtype=%u\n", __func__, |
| 725 | socinfo->v1.format, |
| 726 | socinfo->v1.id, |
| 727 | SOCINFO_VERSION_MAJOR(socinfo->v1.version), |
| 728 | SOCINFO_VERSION_MINOR(socinfo->v1.version), |
| 729 | socinfo->v2.raw_id, socinfo->v2.raw_version, |
| 730 | socinfo->v3.hw_platform, socinfo->v4.platform_version, |
| 731 | socinfo->v5.accessory_chip, |
| 732 | socinfo->v6.hw_platform_subtype); |
| 733 | break; |
| 734 | default: |
| 735 | pr_err("%s: Unknown format found\n", __func__); |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | return 0; |
| 740 | } |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 741 | |
| 742 | const int get_core_count(void) |
| 743 | { |
| 744 | if (!(read_cpuid_mpidr() & BIT(31))) |
| 745 | return 1; |
| 746 | |
| 747 | if (read_cpuid_mpidr() & BIT(30) && |
| 748 | !machine_is_msm8960_sim() && |
| 749 | !machine_is_apq8064_sim()) |
| 750 | return 1; |
| 751 | |
| 752 | /* 1 + the PART[1:0] field of MIDR */ |
| 753 | return ((read_cpuid_id() >> 4) & 3) + 1; |
| 754 | } |
| 755 | |
| 756 | const int read_msm_cpu_type(void) |
| 757 | { |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 758 | if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 759 | return MSM_CPU_8960; |
| 760 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 761 | if (socinfo_get_msm_cpu() != MSM_CPU_UNKNOWN) |
| 762 | return socinfo_get_msm_cpu(); |
| 763 | |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 764 | switch (read_cpuid_id()) { |
| 765 | case 0x510F02D0: |
| 766 | case 0x510F02D2: |
| 767 | case 0x510F02D4: |
| 768 | return MSM_CPU_8X60; |
| 769 | |
| 770 | case 0x510F04D0: |
| 771 | case 0x510F04D1: |
| 772 | case 0x510F04D2: |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 773 | case 0x511F04D0: |
| 774 | case 0x512F04D0: |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 775 | return MSM_CPU_8960; |
| 776 | |
Stepan Moskovchenko | a8f0a22 | 2011-10-24 18:53:17 -0700 | [diff] [blame] | 777 | case 0x51404D11: /* We can't get here unless we are in bringup */ |
| 778 | return MSM_CPU_8930; |
Stepan Moskovchenko | eff783a | 2011-08-22 19:01:58 -0700 | [diff] [blame] | 779 | |
| 780 | case 0x510F06F0: |
| 781 | return MSM_CPU_8064; |
| 782 | |
| 783 | default: |
| 784 | return MSM_CPU_UNKNOWN; |
| 785 | }; |
| 786 | } |
Stepan Moskovchenko | 70dc7cf | 2011-08-22 19:08:42 -0700 | [diff] [blame] | 787 | |
| 788 | const int cpu_is_krait_v1(void) |
| 789 | { |
| 790 | switch (read_cpuid_id()) { |
| 791 | case 0x510F04D0: |
| 792 | case 0x510F04D1: |
| 793 | case 0x510F04D2: |
| 794 | return 1; |
| 795 | |
| 796 | default: |
| 797 | return 0; |
| 798 | }; |
| 799 | } |