blob: fdc8553001c0a1da132cb266f0223235fdbbb64f [file] [log] [blame]
Channagoud Kadabi571193a2014-02-05 13:58:49 -08001/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Shashank Mittala635abf2012-03-28 18:11:43 -07002 *
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 Kadabiafd62bf2013-01-08 20:32:52 -080012 * * Neither the name of The Linux Foundation, Inc. nor the names of its
Shashank Mittala635abf2012-03-28 18:11:43 -070013 * 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
35static struct board_data board = {UNKNOWN,
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080036 0,
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -070037 0,
Shashank Mittala635abf2012-03-28 18:11:43 -070038 HW_PLATFORM_UNKNOWN,
39 HW_PLATFORM_SUBTYPE_UNKNOWN,
Amol Jadi5c61a952012-05-04 17:05:35 -070040 LINUX_MACHTYPE_UNKNOWN,
Deepa Dinamanib8b16432012-08-24 15:48:45 -070041 BASEBAND_MSM,
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080042 {{PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}},
43};
Shashank Mittala635abf2012-03-28 18:11:43 -070044
45static void platform_detect()
46{
47 struct smem_board_info_v6 board_info_v6;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070048 struct smem_board_info_v7 board_info_v7;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080049 struct smem_board_info_v8 board_info_v8;
Shashank Mittala635abf2012-03-28 18:11:43 -070050 unsigned int board_info_len = 0;
51 unsigned ret = 0;
52 unsigned format = 0;
Lijuan Gao9f152862014-08-18 13:45:24 +080053 unsigned pmic_type = 0;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080054 uint8_t i;
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070055 uint16_t format_major = 0;
56 uint16_t format_minor = 0;
Shashank Mittala635abf2012-03-28 18:11:43 -070057
58 ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
59 &format, sizeof(format), 0);
60 if (ret)
61 return;
62
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070063 /* Extract the major & minor version info,
64 * Upper two bytes: major info
65 * Lower two byets: minor info
66 */
67 format_major = (format & 0xffff0000) >> 16;
68 format_minor = format & 0x0000ffff;
69
70 if (format_major == 0x0)
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070071 {
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070072 if (format_minor == 6)
73 {
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070074 board_info_len = sizeof(board_info_v6);
Shashank Mittala635abf2012-03-28 18:11:43 -070075
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070076 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
77 &board_info_v6,
78 board_info_len);
79 if (ret)
80 return;
Shashank Mittala635abf2012-03-28 18:11:43 -070081
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070082 board.platform = board_info_v6.board_info_v3.msm_id;
83 board.platform_version = board_info_v6.board_info_v3.msm_version;
84 board.platform_hw = board_info_v6.board_info_v3.hw_platform;
85 board.platform_subtype = board_info_v6.platform_subtype;
86 }
87 else if (format_minor == 7)
88 {
89 board_info_len = sizeof(board_info_v7);
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070090
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070091 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
92 &board_info_v7,
93 board_info_len);
94 if (ret)
95 return;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070096
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070097 board.platform = board_info_v7.board_info_v3.msm_id;
98 board.platform_version = board_info_v7.board_info_v3.msm_version;
99 board.platform_hw = board_info_v7.board_info_v3.hw_platform;
100 board.platform_subtype = board_info_v7.platform_subtype;
101 board.pmic_info[0].pmic_type = board_info_v7.pmic_type;
102 board.pmic_info[0].pmic_version = board_info_v7.pmic_version;
103 }
104 else if (format_minor >= 8)
105 {
106 dprintf(INFO, "Minor socinfo format detected: %u.%u\n", format_major, format_minor);
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800107
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700108 board_info_len = sizeof(board_info_v8);
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800109
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700110 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
111 &board_info_v8,
112 board_info_len);
113 if (ret)
114 return;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800115
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700116 board.platform = board_info_v8.board_info_v3.msm_id;
117 board.platform_version = board_info_v8.board_info_v3.msm_version;
118 board.platform_hw = board_info_v8.board_info_v3.hw_platform;
119 board.platform_subtype = board_info_v8.platform_subtype;
Maria Yuca51ee22013-06-27 21:45:24 +0800120
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700121 /*
122 * fill in board.target with variant_id information
123 * bit no |31 24 | 23 16 | 15 8 |7 0|
124 * board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform|
125 *
126 */
127 board.target = (((board_info_v8.platform_subtype & 0xff) << 24) |
128 (((board_info_v8.platform_version >> 16) & 0xff) << 16) |
129 ((board_info_v8.platform_version & 0xff) << 8) |
130 (board_info_v8.board_info_v3.hw_platform & 0xff));
131
132 for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
133 board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type;
134 board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version;
Lijuan Gao9f152862014-08-18 13:45:24 +0800135
136 /*
137 * fill in pimc_board_info with pmic type and pmic version information
138 * bit no |31 24 | 23 16 | 15 8 |7 0|
139 * pimc_board_info = |Unused | Major version | Minor version|PMIC_MODEL|
140 *
141 */
142 pmic_type = board_info_v8.pmic_info[i].pmic_type == PMIC_IS_INVALID? 0 : board_info_v8.pmic_info[i].pmic_type;
143
144 board.pmic_info[i].pmic_target = (((board_info_v8.pmic_info[i].pmic_version >> 16) & 0xff) << 16) |
145 ((board_info_v8.pmic_info[i].pmic_version & 0xff) << 8) | (pmic_type & 0xff);
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700146 }
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700147
148 if (format_minor == 0x9)
149 board.foundry_id = board_info_v8.foundry_id;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800150 }
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530151
152 /* HLOS subtype
153 * bit no |31 16 | 15 8 | 7 0|
154 * board.platform_hlos_subtype = |reserved | DDR detection | subtype|
155 * | bits | bits | |
156 */
157 board.platform_hlos_subtype = board_get_ddr_subtype() << 8;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -0700158 }
159 else
160 {
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700161 dprintf(CRITICAL, "Unsupported board info format %u.%u\n", format_major, format_minor);
Deepa Dinamania4ebcff2012-06-11 11:59:30 -0700162 ASSERT(0);
Shashank Mittala635abf2012-03-28 18:11:43 -0700163 }
164}
165
Shashank Mittala635abf2012-03-28 18:11:43 -0700166void board_init()
167{
168 platform_detect();
Amol Jadi5c61a952012-05-04 17:05:35 -0700169 target_detect(&board);
170 target_baseband_detect(&board);
Shashank Mittala635abf2012-03-28 18:11:43 -0700171}
172
Amol Jadi5c61a952012-05-04 17:05:35 -0700173uint32_t board_platform_id(void)
Shashank Mittala635abf2012-03-28 18:11:43 -0700174{
175 return board.platform;
176}
177
Amol Jadi5c61a952012-05-04 17:05:35 -0700178uint32_t board_target_id()
Shashank Mittala635abf2012-03-28 18:11:43 -0700179{
180 return board.target;
181}
182
Amol Jadi5c61a952012-05-04 17:05:35 -0700183uint32_t board_baseband()
Shashank Mittala635abf2012-03-28 18:11:43 -0700184{
185 return board.baseband;
186}
Neeti Desai465491e2012-07-31 12:53:35 -0700187
188uint32_t board_hardware_id()
189{
190 return board.platform_hw;
191}
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700192
Joel Kingaa335dc2013-06-03 16:11:08 -0700193uint32_t board_hardware_subtype(void)
194{
195 return board.platform_subtype;
196}
197
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700198uint32_t board_foundry_id(void)
199{
200 return board.foundry_id;
201}
202
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800203uint8_t board_pmic_info(struct board_pmic_data *info, uint8_t num_ent)
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700204{
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800205 uint8_t i;
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700206
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800207 for (i = 0; i < num_ent && i < SMEM_MAX_PMIC_DEVICES; i++) {
208 info->pmic_type = board.pmic_info[i].pmic_type;
209 info->pmic_version = board.pmic_info[i].pmic_version;
Lijuan Gao9f152862014-08-18 13:45:24 +0800210 info->pmic_target = board.pmic_info[i].pmic_target;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800211 info++;
212 }
213
214 return (i--);
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700215}
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -0800216
Lijuan Gao9f152862014-08-18 13:45:24 +0800217uint32_t board_pmic_target(uint8_t num_ent)
218{
219 if (num_ent < SMEM_MAX_PMIC_DEVICES) {
220 return board.pmic_info[num_ent].pmic_target;
221 }
222 return 0;
223}
224
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -0800225uint32_t board_soc_version()
226{
227 return board.platform_version;
228}
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530229
230uint32_t board_get_ddr_subtype(void)
231{
232 ram_partition ptn_entry;
233 unsigned int index;
234 uint32_t ret = 0;
235 uint32_t len = 0;
236 unsigned ddr_size = 0;
237
Aparna Mallavarapub377b792014-06-24 19:56:03 +0530238 /* Make sure RAM partition table is initialized */
239 ASSERT(smem_ram_ptable_init_v1());
240
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530241 len = smem_get_ram_ptable_len();
242
243 /* Calculating the size of the mem_info_ptr */
244 for (index = 0 ; index < len; index++)
245 {
246 smem_get_ram_ptable_entry(&ptn_entry, index);
247
248 if((ptn_entry.category == SDRAM) &&
249 (ptn_entry.type == SYS_MEMORY))
250 {
251 ddr_size += ptn_entry.size;
252 }
253 }
254
255 switch(ddr_size)
256 {
257 case DDR_512MB:
258 ret = SUBTYPE_512MB;
259 break;
260 default:
261 ret = 0;
262 break;
263 };
264
265 return ret;
266}
267
268uint32_t board_hlos_subtype(void)
269{
270 return board.platform_hlos_subtype;
271}