Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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. |
| 12 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 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, |
| 36 | HW_PLATFORM_UNKNOWN, |
| 37 | HW_PLATFORM_SUBTYPE_UNKNOWN, |
| 38 | LINUX_MACHTYPE_UNKNOWN,}; |
| 39 | |
| 40 | static void platform_detect() |
| 41 | { |
| 42 | struct smem_board_info_v6 board_info_v6; |
| 43 | unsigned int board_info_len = 0; |
| 44 | unsigned ret = 0; |
| 45 | unsigned format = 0; |
| 46 | |
| 47 | ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 48 | &format, sizeof(format), 0); |
| 49 | if (ret) |
| 50 | return; |
| 51 | |
| 52 | if (format == 6) { |
| 53 | board_info_len = sizeof(board_info_v6); |
| 54 | |
| 55 | ret = |
| 56 | smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 57 | &board_info_v6, |
| 58 | board_info_len); |
| 59 | if (ret) |
| 60 | return; |
| 61 | |
| 62 | board.platform = board_info_v6.board_info_v3.msm_id; |
| 63 | board.platform_hw = |
| 64 | board_info_v6.board_info_v3.hw_platform; |
| 65 | board.platform_subtype = |
| 66 | board_info_v6.platform_subtype; |
| 67 | } else { |
| 68 | dprintf(CRITICAL, "Unsupported board info format.\n"); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | static void target_detect() |
| 73 | { |
| 74 | unsigned platform_id; |
| 75 | unsigned platform_hw; |
| 76 | unsigned target_id; |
| 77 | |
| 78 | platform_id = board.platform; |
| 79 | platform_hw = board.platform_hw; |
| 80 | |
| 81 | /* Detect the board we are running on */ |
| 82 | if ((platform_id == MSM8960) || (platform_id == MSM8660A) |
| 83 | || (platform_id == MSM8260A) || (platform_id == APQ8060A)) { |
| 84 | switch (platform_hw) { |
| 85 | case HW_PLATFORM_SURF: |
| 86 | target_id = LINUX_MACHTYPE_8960_CDP; |
| 87 | break; |
| 88 | case HW_PLATFORM_MTP: |
| 89 | target_id = LINUX_MACHTYPE_8960_MTP; |
| 90 | break; |
| 91 | case HW_PLATFORM_FLUID: |
| 92 | target_id = LINUX_MACHTYPE_8960_FLUID; |
| 93 | break; |
| 94 | case HW_PLATFORM_LIQUID: |
| 95 | target_id = LINUX_MACHTYPE_8960_LIQUID; |
| 96 | break; |
| 97 | default: |
| 98 | target_id = LINUX_MACHTYPE_8960_CDP; |
| 99 | } |
| 100 | } else if ((platform_id == MSM8230) || (platform_id == MSM8630) |
| 101 | || (platform_id == MSM8930) || (platform_id == APQ8030)) { |
| 102 | switch (platform_hw) { |
| 103 | case HW_PLATFORM_SURF: |
| 104 | target_id = LINUX_MACHTYPE_8930_CDP; |
| 105 | break; |
| 106 | case HW_PLATFORM_MTP: |
| 107 | target_id = LINUX_MACHTYPE_8930_MTP; |
| 108 | break; |
| 109 | case HW_PLATFORM_FLUID: |
| 110 | target_id = LINUX_MACHTYPE_8930_FLUID; |
| 111 | break; |
| 112 | default: |
| 113 | target_id = LINUX_MACHTYPE_8930_CDP; |
| 114 | } |
| 115 | } else if ((platform_id == MSM8227) || (platform_id == MSM8627)) { |
| 116 | switch (platform_hw) { |
| 117 | case HW_PLATFORM_SURF: |
| 118 | target_id = LINUX_MACHTYPE_8627_CDP; |
| 119 | break; |
| 120 | case HW_PLATFORM_MTP: |
| 121 | target_id = LINUX_MACHTYPE_8627_MTP; |
| 122 | break; |
| 123 | default: |
| 124 | target_id = LINUX_MACHTYPE_8627_CDP; |
| 125 | } |
Amol Jadi | 6d7f1d2 | 2012-04-13 15:33:41 -0700 | [diff] [blame^] | 126 | } else if (platform_id == MPQ8064) { |
| 127 | switch (platform_hw) { |
| 128 | case HW_PLATFORM_SURF: |
| 129 | target_id = LINUX_MACHTYPE_8064_MPQ_CDP; |
| 130 | break; |
| 131 | case HW_PLATFORM_HRD: |
| 132 | target_id = LINUX_MACHTYPE_8064_HRD; |
| 133 | break; |
| 134 | case HW_PLATFORM_DTV: |
| 135 | target_id = LINUX_MACHTYPE_8064_DTV; |
| 136 | break; |
| 137 | default: |
| 138 | target_id = LINUX_MACHTYPE_8064_MPQ_CDP; |
| 139 | } |
| 140 | } else if ((platform_id == APQ8064)) { |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 141 | switch (platform_hw) { |
| 142 | case HW_PLATFORM_SURF: |
| 143 | target_id = LINUX_MACHTYPE_8064_CDP; |
| 144 | break; |
| 145 | case HW_PLATFORM_MTP: |
| 146 | target_id = LINUX_MACHTYPE_8064_MTP; |
| 147 | break; |
| 148 | case HW_PLATFORM_LIQUID: |
| 149 | target_id = LINUX_MACHTYPE_8064_LIQUID; |
| 150 | break; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 151 | default: |
| 152 | target_id = LINUX_MACHTYPE_8064_CDP; |
| 153 | } |
| 154 | } else { |
| 155 | dprintf(CRITICAL, "platform_id (%d) is not identified.\n", |
| 156 | platform_id); |
| 157 | ASSERT(0); |
| 158 | } |
| 159 | board.target = target_id; |
| 160 | } |
| 161 | |
| 162 | static void baseband_detect() |
| 163 | { |
| 164 | unsigned baseband = BASEBAND_MSM; |
| 165 | unsigned platform_subtype; |
| 166 | unsigned platform_id; |
| 167 | |
| 168 | platform_id = board.platform; |
| 169 | platform_subtype = board.platform_subtype; |
| 170 | |
| 171 | /* Check for MDM or APQ baseband variants. Default to MSM */ |
| 172 | if (platform_subtype == HW_PLATFORM_SUBTYPE_MDM) |
| 173 | baseband = BASEBAND_MDM; |
| 174 | else if (platform_id == APQ8060) |
| 175 | baseband = BASEBAND_APQ; |
| 176 | else if (platform_id == APQ8064) |
| 177 | baseband = BASEBAND_APQ; |
Amol Jadi | 6d7f1d2 | 2012-04-13 15:33:41 -0700 | [diff] [blame^] | 178 | else if (platform_id == MPQ8064) |
| 179 | baseband = BASEBAND_APQ; |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 180 | else |
| 181 | baseband = BASEBAND_MSM; |
| 182 | |
| 183 | board.baseband = baseband; |
| 184 | } |
| 185 | |
| 186 | void board_init() |
| 187 | { |
| 188 | platform_detect(); |
| 189 | target_detect(); |
| 190 | baseband_detect(); |
| 191 | } |
| 192 | |
| 193 | unsigned board_platform_id(void) |
| 194 | { |
| 195 | return board.platform; |
| 196 | } |
| 197 | |
| 198 | unsigned board_target_id() |
| 199 | { |
| 200 | return board.target; |
| 201 | } |
| 202 | |
| 203 | unsigned board_baseband() |
| 204 | { |
| 205 | return board.baseband; |
| 206 | } |