blob: 5591ecd07d7188b41f1610355108d4b8cfad18c8 [file] [log] [blame]
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -08001/* Copyright (c) 2012-2013, 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;
Shashank Mittala635abf2012-03-28 18:11:43 -070053
54 ret = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
55 &format, sizeof(format), 0);
56 if (ret)
57 return;
58
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070059 if (format == 6)
60 {
61 board_info_len = sizeof(board_info_v6);
Shashank Mittala635abf2012-03-28 18:11:43 -070062
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070063 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
64 &board_info_v6,
65 board_info_len);
Shashank Mittala635abf2012-03-28 18:11:43 -070066 if (ret)
67 return;
68
69 board.platform = board_info_v6.board_info_v3.msm_id;
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -080070 board.platform_version = board_info_v6.board_info_v3.msm_version;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070071 board.platform_hw = board_info_v6.board_info_v3.hw_platform;
72 board.platform_subtype = board_info_v6.platform_subtype;
73 }
74 else if (format == 7)
75 {
76 board_info_len = sizeof(board_info_v7);
77
78 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
79 &board_info_v7,
80 board_info_len);
81 if (ret)
82 return;
83
84 board.platform = board_info_v7.board_info_v3.msm_id;
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -080085 board.platform_version = board_info_v7.board_info_v3.msm_version;
Deepa Dinamania4ebcff2012-06-11 11:59:30 -070086 board.platform_hw = board_info_v7.board_info_v3.hw_platform;
87 board.platform_subtype = board_info_v7.platform_subtype;
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080088 board.pmic_info[0].pmic_type = board_info_v7.pmic_type;
89 board.pmic_info[0].pmic_version = board_info_v7.pmic_version;
90 }
Channagoud Kadabib0c07872014-01-17 11:50:08 -080091 else if (format == 8 || format == 9)
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -080092 {
93 board_info_len = sizeof(board_info_v8);
94
95 ret = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
96 &board_info_v8,
97 board_info_len);
98 if (ret)
99 return;
100
101 board.platform = board_info_v8.board_info_v3.msm_id;
102 board.platform_version = board_info_v8.board_info_v3.msm_version;
103 board.platform_hw = board_info_v8.board_info_v3.hw_platform;
104 board.platform_subtype = board_info_v8.platform_subtype;
105
Maria Yuca51ee22013-06-27 21:45:24 +0800106 /*
107 * fill in board.target with variant_id information
108 * bit no |31 24 | 23 16| 15 8 |7 0|
109 * board.target =|subtype| major | minor |hw_platform|
110 * Have QRD board.target =| OEM | EVT/DVT|Reserved| QRD |
111 *
112 */
113 if (board_info_v8.board_info_v3.hw_platform == HW_PLATFORM_QRD) {
114 board.target = (((board_info_v8.platform_subtype & 0xff) << 24) |
115 (((board_info_v8.platform_version >> 16) & 0xff) << 16) |
116 ((board_info_v8.platform_version & 0xff) << 8) |
117 ((board_info_v8.board_info_v3.hw_platform & 0xff) << 0));
118 }
119
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800120 for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
121 board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type;
122 board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version;
123 }
Deepa Dinamania4ebcff2012-06-11 11:59:30 -0700124 }
125 else
126 {
127 dprintf(CRITICAL, "Unsupported board info format\n");
128 ASSERT(0);
Shashank Mittala635abf2012-03-28 18:11:43 -0700129 }
130}
131
Shashank Mittala635abf2012-03-28 18:11:43 -0700132void board_init()
133{
134 platform_detect();
Amol Jadi5c61a952012-05-04 17:05:35 -0700135 target_detect(&board);
136 target_baseband_detect(&board);
Shashank Mittala635abf2012-03-28 18:11:43 -0700137}
138
Amol Jadi5c61a952012-05-04 17:05:35 -0700139uint32_t board_platform_id(void)
Shashank Mittala635abf2012-03-28 18:11:43 -0700140{
141 return board.platform;
142}
143
Amol Jadi5c61a952012-05-04 17:05:35 -0700144uint32_t board_target_id()
Shashank Mittala635abf2012-03-28 18:11:43 -0700145{
146 return board.target;
147}
148
Amol Jadi5c61a952012-05-04 17:05:35 -0700149uint32_t board_baseband()
Shashank Mittala635abf2012-03-28 18:11:43 -0700150{
151 return board.baseband;
152}
Neeti Desai465491e2012-07-31 12:53:35 -0700153
154uint32_t board_hardware_id()
155{
156 return board.platform_hw;
157}
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700158
Joel Kingaa335dc2013-06-03 16:11:08 -0700159uint32_t board_hardware_subtype(void)
160{
161 return board.platform_subtype;
162}
163
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800164uint8_t board_pmic_info(struct board_pmic_data *info, uint8_t num_ent)
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700165{
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800166 uint8_t i;
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700167
Channagoud Kadabibc0e47e2013-02-15 19:41:21 -0800168 for (i = 0; i < num_ent && i < SMEM_MAX_PMIC_DEVICES; i++) {
169 info->pmic_type = board.pmic_info[i].pmic_type;
170 info->pmic_version = board.pmic_info[i].pmic_version;
171 info++;
172 }
173
174 return (i--);
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700175}
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -0800176
177uint32_t board_soc_version()
178{
179 return board.platform_version;
180}