Channagoud Kadabi | 571193a | 2014-02-05 13:58:49 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Channagoud Kadabi | afd62bf | 2013-01-08 20:32:52 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation, Inc. nor the names of its |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <debug.h> |
| 31 | #include <board.h> |
| 32 | #include <smem.h> |
| 33 | #include <baseband.h> |
| 34 | |
| 35 | static struct board_data board = {UNKNOWN, |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 36 | 0, |
Sundarajan Srinivasan | 763c0db | 2014-05-20 17:08:36 -0700 | [diff] [blame] | 37 | 0, |
Sridhar Parasuram | c5f035f | 2014-10-22 12:37:36 -0700 | [diff] [blame^] | 38 | 0, |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 39 | HW_PLATFORM_UNKNOWN, |
| 40 | HW_PLATFORM_SUBTYPE_UNKNOWN, |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 41 | LINUX_MACHTYPE_UNKNOWN, |
Deepa Dinamani | b8b1643 | 2012-08-24 15:48:45 -0700 | [diff] [blame] | 42 | BASEBAND_MSM, |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 43 | {{PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}}, |
| 44 | }; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 45 | |
| 46 | static void platform_detect() |
| 47 | { |
| 48 | struct smem_board_info_v6 board_info_v6; |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 49 | struct smem_board_info_v7 board_info_v7; |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 50 | struct smem_board_info_v8 board_info_v8; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 51 | unsigned int board_info_len = 0; |
| 52 | unsigned ret = 0; |
| 53 | unsigned format = 0; |
Lijuan Gao | 9f15286 | 2014-08-18 13:45:24 +0800 | [diff] [blame] | 54 | unsigned pmic_type = 0; |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 55 | uint8_t i; |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 56 | uint16_t format_major = 0; |
| 57 | uint16_t format_minor = 0; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 58 | |
| 59 | ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 60 | &format, sizeof(format), 0); |
| 61 | if (ret) |
| 62 | return; |
| 63 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 64 | /* Extract the major & minor version info, |
| 65 | * Upper two bytes: major info |
| 66 | * Lower two byets: minor info |
| 67 | */ |
| 68 | format_major = (format & 0xffff0000) >> 16; |
| 69 | format_minor = format & 0x0000ffff; |
| 70 | |
| 71 | if (format_major == 0x0) |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 72 | { |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 73 | if (format_minor == 6) |
| 74 | { |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 75 | board_info_len = sizeof(board_info_v6); |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 76 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 77 | ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 78 | &board_info_v6, |
| 79 | board_info_len); |
| 80 | if (ret) |
| 81 | return; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 82 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 83 | board.platform = board_info_v6.board_info_v3.msm_id; |
| 84 | board.platform_version = board_info_v6.board_info_v3.msm_version; |
| 85 | board.platform_hw = board_info_v6.board_info_v3.hw_platform; |
| 86 | board.platform_subtype = board_info_v6.platform_subtype; |
| 87 | } |
| 88 | else if (format_minor == 7) |
| 89 | { |
| 90 | board_info_len = sizeof(board_info_v7); |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 91 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 92 | ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 93 | &board_info_v7, |
| 94 | board_info_len); |
| 95 | if (ret) |
| 96 | return; |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 97 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 98 | board.platform = board_info_v7.board_info_v3.msm_id; |
| 99 | board.platform_version = board_info_v7.board_info_v3.msm_version; |
| 100 | board.platform_hw = board_info_v7.board_info_v3.hw_platform; |
| 101 | board.platform_subtype = board_info_v7.platform_subtype; |
| 102 | board.pmic_info[0].pmic_type = board_info_v7.pmic_type; |
| 103 | board.pmic_info[0].pmic_version = board_info_v7.pmic_version; |
| 104 | } |
| 105 | else if (format_minor >= 8) |
| 106 | { |
| 107 | dprintf(INFO, "Minor socinfo format detected: %u.%u\n", format_major, format_minor); |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 108 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 109 | board_info_len = sizeof(board_info_v8); |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 110 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 111 | ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 112 | &board_info_v8, |
| 113 | board_info_len); |
| 114 | if (ret) |
| 115 | return; |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 116 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 117 | board.platform = board_info_v8.board_info_v3.msm_id; |
| 118 | board.platform_version = board_info_v8.board_info_v3.msm_version; |
| 119 | board.platform_hw = board_info_v8.board_info_v3.hw_platform; |
| 120 | board.platform_subtype = board_info_v8.platform_subtype; |
Maria Yu | ca51ee2 | 2013-06-27 21:45:24 +0800 | [diff] [blame] | 121 | |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 122 | /* |
| 123 | * fill in board.target with variant_id information |
| 124 | * bit no |31 24 | 23 16 | 15 8 |7 0| |
| 125 | * board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform| |
| 126 | * |
| 127 | */ |
| 128 | board.target = (((board_info_v8.platform_subtype & 0xff) << 24) | |
| 129 | (((board_info_v8.platform_version >> 16) & 0xff) << 16) | |
| 130 | ((board_info_v8.platform_version & 0xff) << 8) | |
| 131 | (board_info_v8.board_info_v3.hw_platform & 0xff)); |
| 132 | |
| 133 | for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) { |
| 134 | board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type; |
| 135 | board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version; |
Lijuan Gao | 9f15286 | 2014-08-18 13:45:24 +0800 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * fill in pimc_board_info with pmic type and pmic version information |
| 139 | * bit no |31 24 | 23 16 | 15 8 |7 0| |
| 140 | * pimc_board_info = |Unused | Major version | Minor version|PMIC_MODEL| |
| 141 | * |
| 142 | */ |
| 143 | pmic_type = board_info_v8.pmic_info[i].pmic_type == PMIC_IS_INVALID? 0 : board_info_v8.pmic_info[i].pmic_type; |
| 144 | |
| 145 | board.pmic_info[i].pmic_target = (((board_info_v8.pmic_info[i].pmic_version >> 16) & 0xff) << 16) | |
| 146 | ((board_info_v8.pmic_info[i].pmic_version & 0xff) << 8) | (pmic_type & 0xff); |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 147 | } |
Sundarajan Srinivasan | 763c0db | 2014-05-20 17:08:36 -0700 | [diff] [blame] | 148 | |
| 149 | if (format_minor == 0x9) |
| 150 | board.foundry_id = board_info_v8.foundry_id; |
Sridhar Parasuram | c5f035f | 2014-10-22 12:37:36 -0700 | [diff] [blame^] | 151 | |
| 152 | if (format_minor == 0xA) |
| 153 | board.chip_serial = board_info_v8.chip_serial; |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 154 | } |
Aparna Mallavarapu | 6eb3090 | 2014-05-13 17:03:10 +0530 | [diff] [blame] | 155 | |
| 156 | /* HLOS subtype |
Aparna Mallavarapu | 97850bb | 2014-09-23 20:03:37 +0530 | [diff] [blame] | 157 | * bit no |31 20 | 19 16| 15 8 | 7 0| |
| 158 | * board.platform_hlos_subtype = |reserved | Boot device | DDR detection | subtype| |
| 159 | * | bits | | bits | |
Aparna Mallavarapu | 6eb3090 | 2014-05-13 17:03:10 +0530 | [diff] [blame] | 160 | */ |
Aparna Mallavarapu | 97850bb | 2014-09-23 20:03:37 +0530 | [diff] [blame] | 161 | board.platform_hlos_subtype = (board_get_ddr_subtype() << 8) | (platform_get_boot_dev() << 16); |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 162 | } |
| 163 | else |
| 164 | { |
Channagoud Kadabi | 4f370b4 | 2014-05-21 16:06:59 -0700 | [diff] [blame] | 165 | dprintf(CRITICAL, "Unsupported board info format %u.%u\n", format_major, format_minor); |
Deepa Dinamani | a4ebcff | 2012-06-11 11:59:30 -0700 | [diff] [blame] | 166 | ASSERT(0); |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 170 | void board_init() |
| 171 | { |
| 172 | platform_detect(); |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 173 | target_detect(&board); |
| 174 | target_baseband_detect(&board); |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 177 | uint32_t board_platform_id(void) |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 178 | { |
| 179 | return board.platform; |
| 180 | } |
| 181 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 182 | uint32_t board_target_id() |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 183 | { |
| 184 | return board.target; |
| 185 | } |
| 186 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 187 | uint32_t board_baseband() |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 188 | { |
| 189 | return board.baseband; |
| 190 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 191 | |
| 192 | uint32_t board_hardware_id() |
| 193 | { |
| 194 | return board.platform_hw; |
| 195 | } |
Deepa Dinamani | b8b1643 | 2012-08-24 15:48:45 -0700 | [diff] [blame] | 196 | |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 197 | uint32_t board_hardware_subtype(void) |
| 198 | { |
| 199 | return board.platform_subtype; |
| 200 | } |
| 201 | |
Sundarajan Srinivasan | 763c0db | 2014-05-20 17:08:36 -0700 | [diff] [blame] | 202 | uint32_t board_foundry_id(void) |
| 203 | { |
| 204 | return board.foundry_id; |
| 205 | } |
| 206 | |
Sridhar Parasuram | c5f035f | 2014-10-22 12:37:36 -0700 | [diff] [blame^] | 207 | uint32_t board_chip_serial(void) |
| 208 | { |
| 209 | return board.chip_serial; |
| 210 | } |
| 211 | |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 212 | uint8_t board_pmic_info(struct board_pmic_data *info, uint8_t num_ent) |
Deepa Dinamani | b8b1643 | 2012-08-24 15:48:45 -0700 | [diff] [blame] | 213 | { |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 214 | uint8_t i; |
Deepa Dinamani | b8b1643 | 2012-08-24 15:48:45 -0700 | [diff] [blame] | 215 | |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 216 | for (i = 0; i < num_ent && i < SMEM_MAX_PMIC_DEVICES; i++) { |
| 217 | info->pmic_type = board.pmic_info[i].pmic_type; |
| 218 | info->pmic_version = board.pmic_info[i].pmic_version; |
Lijuan Gao | 9f15286 | 2014-08-18 13:45:24 +0800 | [diff] [blame] | 219 | info->pmic_target = board.pmic_info[i].pmic_target; |
Channagoud Kadabi | bc0e47e | 2013-02-15 19:41:21 -0800 | [diff] [blame] | 220 | info++; |
| 221 | } |
| 222 | |
| 223 | return (i--); |
Deepa Dinamani | b8b1643 | 2012-08-24 15:48:45 -0700 | [diff] [blame] | 224 | } |
Channagoud Kadabi | afd62bf | 2013-01-08 20:32:52 -0800 | [diff] [blame] | 225 | |
Lijuan Gao | 9f15286 | 2014-08-18 13:45:24 +0800 | [diff] [blame] | 226 | uint32_t board_pmic_target(uint8_t num_ent) |
| 227 | { |
| 228 | if (num_ent < SMEM_MAX_PMIC_DEVICES) { |
| 229 | return board.pmic_info[num_ent].pmic_target; |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
Channagoud Kadabi | afd62bf | 2013-01-08 20:32:52 -0800 | [diff] [blame] | 234 | uint32_t board_soc_version() |
| 235 | { |
| 236 | return board.platform_version; |
| 237 | } |
Aparna Mallavarapu | 6eb3090 | 2014-05-13 17:03:10 +0530 | [diff] [blame] | 238 | |
| 239 | uint32_t board_get_ddr_subtype(void) |
| 240 | { |
| 241 | ram_partition ptn_entry; |
| 242 | unsigned int index; |
| 243 | uint32_t ret = 0; |
| 244 | uint32_t len = 0; |
| 245 | unsigned ddr_size = 0; |
| 246 | |
Aparna Mallavarapu | b377b79 | 2014-06-24 19:56:03 +0530 | [diff] [blame] | 247 | /* Make sure RAM partition table is initialized */ |
| 248 | ASSERT(smem_ram_ptable_init_v1()); |
| 249 | |
Aparna Mallavarapu | 6eb3090 | 2014-05-13 17:03:10 +0530 | [diff] [blame] | 250 | len = smem_get_ram_ptable_len(); |
| 251 | |
| 252 | /* Calculating the size of the mem_info_ptr */ |
| 253 | for (index = 0 ; index < len; index++) |
| 254 | { |
| 255 | smem_get_ram_ptable_entry(&ptn_entry, index); |
| 256 | |
| 257 | if((ptn_entry.category == SDRAM) && |
| 258 | (ptn_entry.type == SYS_MEMORY)) |
| 259 | { |
| 260 | ddr_size += ptn_entry.size; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | switch(ddr_size) |
| 265 | { |
| 266 | case DDR_512MB: |
| 267 | ret = SUBTYPE_512MB; |
| 268 | break; |
| 269 | default: |
| 270 | ret = 0; |
| 271 | break; |
| 272 | }; |
| 273 | |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | uint32_t board_hlos_subtype(void) |
| 278 | { |
| 279 | return board.platform_hlos_subtype; |
| 280 | } |