blob: 581477d6ab5aab1ca3393f18eecde77492e20e5b [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,
Shashank Mittala635abf2012-03-28 18:11:43 -070037 HW_PLATFORM_UNKNOWN,
38 HW_PLATFORM_SUBTYPE_UNKNOWN,
Amol Jadi5c61a952012-05-04 17:05:35 -070039 LINUX_MACHTYPE_UNKNOWN,
Deepa Dinamanib8b16432012-08-24 15:48:45 -070040 BASEBAND_MSM,
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080041 {{PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}, {PMIC_IS_INVALID, 0}},
42};
Shashank Mittala635abf2012-03-28 18:11:43 -070043
44static void platform_detect()
45{
46 struct smem_board_info_v6 board_info_v6;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070047 struct smem_board_info_v7 board_info_v7;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080048 struct smem_board_info_v8 board_info_v8;
Shashank Mittala635abf2012-03-28 18:11:43 -070049 unsigned int board_info_len = 0;
50 unsigned ret = 0;
51 unsigned format = 0;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080052 uint8_t i;
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070053 uint16_t format_major = 0;
54 uint16_t format_minor = 0;
Shashank Mittala635abf2012-03-28 18:11:43 -070055
56 ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
57 &format, sizeof(format), 0);
58 if (ret)
59 return;
60
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070061 /* Extract the major & minor version info,
62 * Upper two bytes: major info
63 * Lower two byets: minor info
64 */
65 format_major = (format & 0xffff0000) >> 16;
66 format_minor = format & 0x0000ffff;
67
68 if (format_major == 0x0)
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070069 {
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070070 if (format_minor == 6)
71 {
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070072 board_info_len = sizeof(board_info_v6);
Shashank Mittala635abf2012-03-28 18:11:43 -070073
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070074 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
75 &board_info_v6,
76 board_info_len);
77 if (ret)
78 return;
Shashank Mittala635abf2012-03-28 18:11:43 -070079
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070080 board.platform = board_info_v6.board_info_v3.msm_id;
81 board.platform_version = board_info_v6.board_info_v3.msm_version;
82 board.platform_hw = board_info_v6.board_info_v3.hw_platform;
83 board.platform_subtype = board_info_v6.platform_subtype;
84 }
85 else if (format_minor == 7)
86 {
87 board_info_len = sizeof(board_info_v7);
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070088
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070089 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
90 &board_info_v7,
91 board_info_len);
92 if (ret)
93 return;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070094
Channagoud Kadabi4f370b42014-05-21 16:06:59 -070095 board.platform = board_info_v7.board_info_v3.msm_id;
96 board.platform_version = board_info_v7.board_info_v3.msm_version;
97 board.platform_hw = board_info_v7.board_info_v3.hw_platform;
98 board.platform_subtype = board_info_v7.platform_subtype;
99 board.pmic_info[0].pmic_type = board_info_v7.pmic_type;
100 board.pmic_info[0].pmic_version = board_info_v7.pmic_version;
101 }
102 else if (format_minor >= 8)
103 {
104 dprintf(INFO, "Minor socinfo format detected: %u.%u\n", format_major, format_minor);
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800105
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700106 board_info_len = sizeof(board_info_v8);
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800107
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700108 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
109 &board_info_v8,
110 board_info_len);
111 if (ret)
112 return;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800113
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700114 board.platform = board_info_v8.board_info_v3.msm_id;
115 board.platform_version = board_info_v8.board_info_v3.msm_version;
116 board.platform_hw = board_info_v8.board_info_v3.hw_platform;
117 board.platform_subtype = board_info_v8.platform_subtype;
Maria Yuca51ee22013-06-27 21:45:24 +0800118
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700119 /*
120 * fill in board.target with variant_id information
121 * bit no |31 24 | 23 16 | 15 8 |7 0|
122 * board.target = |subtype| plat_hw_ver major | plat_hw_ver minor |hw_platform|
123 *
124 */
125 board.target = (((board_info_v8.platform_subtype & 0xff) << 24) |
126 (((board_info_v8.platform_version >> 16) & 0xff) << 16) |
127 ((board_info_v8.platform_version & 0xff) << 8) |
128 (board_info_v8.board_info_v3.hw_platform & 0xff));
129
130 for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
131 board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type;
132 board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version;
133 }
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800134 }
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530135
136 /* HLOS subtype
137 * bit no |31 16 | 15 8 | 7 0|
138 * board.platform_hlos_subtype = |reserved | DDR detection | subtype|
139 * | bits | bits | |
140 */
141 board.platform_hlos_subtype = board_get_ddr_subtype() << 8;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -0700142 }
143 else
144 {
Channagoud Kadabi4f370b42014-05-21 16:06:59 -0700145 dprintf(CRITICAL, "Unsupported board info format %u.%u\n", format_major, format_minor);
Deepa Dinamania4ebcff2012-06-11 11:59:30 -0700146 ASSERT(0);
Shashank Mittala635abf2012-03-28 18:11:43 -0700147 }
148}
149
Shashank Mittala635abf2012-03-28 18:11:43 -0700150void board_init()
151{
152 platform_detect();
Amol Jadi5c61a952012-05-04 17:05:35 -0700153 target_detect(&board);
154 target_baseband_detect(&board);
Shashank Mittala635abf2012-03-28 18:11:43 -0700155}
156
Amol Jadi5c61a952012-05-04 17:05:35 -0700157uint32_t board_platform_id(void)
Shashank Mittala635abf2012-03-28 18:11:43 -0700158{
159 return board.platform;
160}
161
Amol Jadi5c61a952012-05-04 17:05:35 -0700162uint32_t board_target_id()
Shashank Mittala635abf2012-03-28 18:11:43 -0700163{
164 return board.target;
165}
166
Amol Jadi5c61a952012-05-04 17:05:35 -0700167uint32_t board_baseband()
Shashank Mittala635abf2012-03-28 18:11:43 -0700168{
169 return board.baseband;
170}
Neeti Desai465491e2012-07-31 12:53:35 -0700171
172uint32_t board_hardware_id()
173{
174 return board.platform_hw;
175}
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700176
Joel Kingaa335dc2013-06-03 16:11:08 -0700177uint32_t board_hardware_subtype(void)
178{
179 return board.platform_subtype;
180}
181
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800182uint8_t board_pmic_info(struct board_pmic_data *info, uint8_t num_ent)
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700183{
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800184 uint8_t i;
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700185
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800186 for (i = 0; i < num_ent && i < SMEM_MAX_PMIC_DEVICES; i++) {
187 info->pmic_type = board.pmic_info[i].pmic_type;
188 info->pmic_version = board.pmic_info[i].pmic_version;
189 info++;
190 }
191
192 return (i--);
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700193}
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -0800194
195uint32_t board_soc_version()
196{
197 return board.platform_version;
198}
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530199
200uint32_t board_get_ddr_subtype(void)
201{
202 ram_partition ptn_entry;
203 unsigned int index;
204 uint32_t ret = 0;
205 uint32_t len = 0;
206 unsigned ddr_size = 0;
207
Aparna Mallavarapub377b792014-06-24 19:56:03 +0530208 /* Make sure RAM partition table is initialized */
209 ASSERT(smem_ram_ptable_init_v1());
210
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530211 len = smem_get_ram_ptable_len();
212
213 /* Calculating the size of the mem_info_ptr */
214 for (index = 0 ; index < len; index++)
215 {
216 smem_get_ram_ptable_entry(&ptn_entry, index);
217
218 if((ptn_entry.category == SDRAM) &&
219 (ptn_entry.type == SYS_MEMORY))
220 {
221 ddr_size += ptn_entry.size;
222 }
223 }
224
225 switch(ddr_size)
226 {
227 case DDR_512MB:
228 ret = SUBTYPE_512MB;
229 break;
230 default:
231 ret = 0;
232 break;
233 };
234
235 return ret;
236}
237
238uint32_t board_hlos_subtype(void)
239{
240 return board.platform_hlos_subtype;
241}