blob: f6f600329f034d95c1ef1e412f05283299cb2fda [file] [log] [blame]
Mayank Grover1b6da5d2017-12-19 16:05:46 +05301/* Copyright (c) 2012-2014,2017-2018 The Linux Foundation. All rights reserved.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -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.
12 * * Neither the name of The Linux Foundation 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#include <debug.h>
Lijuan Gao9f152862014-08-18 13:45:24 +080030#include <list.h>
Mayank Grover1b6da5d2017-12-19 16:05:46 +053031#include <bits.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070032
33#ifndef __DEVICE_TREE__
34#define __DEVICE_TREE__
35
36#define DEV_TREE_SUCCESS 0
37#define DEV_TREE_MAGIC 0x54444351 /* "QCDT" */
38#define DEV_TREE_MAGIC_LEN 4
Joel Kingaa335dc2013-06-03 16:11:08 -070039#define DEV_TREE_VERSION_V1 1
40#define DEV_TREE_VERSION_V2 2
Lijuan Gao9f152862014-08-18 13:45:24 +080041#define DEV_TREE_VERSION_V3 3
42
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070043#define DEV_TREE_HEADER_SIZE 12
44
Channagoud Kadabi11682e92013-02-28 11:21:46 -080045#define DTB_MAGIC 0xedfe0dd0
46#define DTB_OFFSET 0x2C
47
Dima Zavin77e41f32013-03-06 16:10:43 -080048#define DTB_PAD_SIZE 1024
Mayank Grover1b6da5d2017-12-19 16:05:46 +053049#define DTBO_TABLE_MAGIC 0xD7B7AB1E
50#define DTBO_CUSTOM_MAX 4
51#define PLATFORM_FOUNDRY_SHIFT 16
52#define SOC_MASK (0xffff)
53#define VARIANT_MASK (0x000000ff)
54#define VARIANT_MINOR_MASK (0x0000ff00)
55#define VARIANT_MAJOR_MASK (0x00ff0000)
56#define PMIC_MODEL_MASK (0x000000ff)
57#define PMIC_REV_MASK (0xffffff00)
58#define PMIC_SHIFT_IDX (2)
59#define PLATFORM_SUBTYPE_SHIFT_ID (0x18)
60#define FOUNDRY_ID_MASK (0x00ff0000)
Mayank Groverb61c0c22018-09-04 15:09:32 +053061#define MAX_SUPPORTED_DTBO_IMG_BUF (8388608) /* 8MB 8 * 1024 * 1024 */
62#define DTBO_IMG_BUF (10485760) /* 10MB 10 * 1024 * 1024 */
Channagoud Kadabia4dbe332013-09-05 17:44:11 -070063/*
64 * For DTB V1: The DTB entries would be of the format
65 * qcom,msm-id = <msm8974, CDP, rev_1>; (3 * sizeof(uint32_t))
66 * For DTB V2: The DTB entries would be of the format
67 * qcom,msm-id = <msm8974, rev_1>; (2 * sizeof(uint32_t))
68 * qcom,board-id = <CDP, subtype_ID>; (2 * sizeof(uint32_t))
69 * The macros below are defined based on these.
70 */
71#define DT_ENTRY_V1_SIZE 0xC
72#define PLAT_ID_SIZE 0x8
73#define BOARD_ID_SIZE 0x8
Lijuan Gao9f152862014-08-18 13:45:24 +080074#define PMIC_ID_SIZE 0x8
75
Mayank Grover1b6da5d2017-12-19 16:05:46 +053076typedef enum {
77 NONE_MATCH,
78 PMIC_MATCH_BEST_REV_IDX0,
79 PMIC_MATCH_EXACT_REV_IDX0,
80 PMIC_MATCH_BEST_REV_IDX1,
81 PMIC_MATCH_EXACT_REV_IDX1,
82 PMIC_MATCH_BEST_REV_IDX2,
83 PMIC_MATCH_EXACT_REV_IDX2,
84 PMIC_MATCH_BEST_REV_IDX3,
85 PMIC_MATCH_EXACT_REV_IDX3,
86 VARIANT_MINOR_BEST_MATCH,
87 VARIANT_MINOR_EXACT_MATCH,
88 VARIANT_MAJOR_BEST_MATCH,
89 VARIANT_MAJOR_EXACT_MATCH,
90 VERSION_BEST_MATCH,
91 VERSION_EXACT_MATCH,
92 FOUNDRYID_DEFAULT_MATCH,
93 FOUNDRYID_EXACT_MATCH,
94 PMIC_MATCH_DEFAULT_MODEL_IDX0,
95 PMIC_MATCH_EXACT_MODEL_IDX0,
96 PMIC_MATCH_DEFAULT_MODEL_IDX1,
97 PMIC_MATCH_EXACT_MODEL_IDX1,
98 PMIC_MATCH_DEFAULT_MODEL_IDX2,
99 PMIC_MATCH_EXACT_MODEL_IDX2,
100 PMIC_MATCH_DEFAULT_MODEL_IDX3,
101 PMIC_MATCH_EXACT_MODEL_IDX3,
102 SUBTYPE_DEFAULT_MATCH,
103 SUBTYPE_EXACT_MATCH,
104 VARIANT_MATCH,
105 SOC_MATCH,
106 MAX_MATCH,
107}dt_match_params;
108
109#define TOTAL_MATCH_BITS 6
110#define ALL_BITS_SET (BIT (SOC_MATCH) | BIT (VARIANT_MATCH) | \
111 BIT (SUBTYPE_EXACT_MATCH) | BIT (FOUNDRYID_EXACT_MATCH) \
112 | BIT (PMIC_MATCH_EXACT_MODEL_IDX0) | \
113 BIT (PMIC_MATCH_EXACT_MODEL_IDX1))
114
115typedef enum {
116 PMIC_IDX0,
117 PMIC_IDX1,
118 PMIC_IDX2,
119 PMIC_IDX3,
120 MAX_PMIC_IDX,
121}pmic_indexes;
122
123
124typedef struct dt_info
125{
126 uint32_t dt_platform_id;
127 uint32_t dt_soc_rev;
128 uint32_t dt_foundry_id;
129 uint32_t dt_variant_id;
130 uint32_t dt_variant_major;
131 uint32_t dt_variant_minor;
132 uint32_t dt_platform_subtype;
133 uint32_t dt_pmic_model[MAX_PMIC_IDX];
134 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
135 uint32_t dt_match_val;
136 void *dtb;
137}dt_info;
138
139typedef struct pmic_info
140{
141 uint32_t dt_pmic_model[MAX_PMIC_IDX];
142 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
143 uint32_t dt_match_val;
144}pmic_info;
Lijuan Gao9f152862014-08-18 13:45:24 +0800145
146struct dt_entry_v2
147{
148 uint32_t platform_id;
149 uint32_t variant_id;
150 uint32_t board_hw_subtype;
151 uint32_t soc_rev;
152 uint32_t offset;
153 uint32_t size;
154};
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700155
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700156struct dt_entry
157{
158 uint32_t platform_id;
159 uint32_t variant_id;
Joel Kingaa335dc2013-06-03 16:11:08 -0700160 uint32_t board_hw_subtype;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700161 uint32_t soc_rev;
Lijuan Gao9f152862014-08-18 13:45:24 +0800162 uint32_t pmic_rev[4];
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700163 uint32_t offset;
164 uint32_t size;
165};
166
167struct dt_table
168{
169 uint32_t magic;
170 uint32_t version;
171 uint32_t num_entries;
172};
173
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700174struct plat_id
175{
176 uint32_t platform_id;
177 uint32_t soc_rev;
178};
179
180struct board_id
181{
182 uint32_t variant_id;
183 uint32_t platform_subtype;
184};
185
Lijuan Gao9f152862014-08-18 13:45:24 +0800186struct pmic_id
187{
188 uint32_t pmic_version[4];
189};
190
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700191struct dt_mem_node_info
192{
193 uint32_t offset;
194 uint32_t mem_info_cnt;
195 uint32_t addr_cell_size;
196 uint32_t size_cell_size;
197};
198
Lijuan Gao9f152862014-08-18 13:45:24 +0800199enum dt_entry_info
200{
201 DTB_FOUNDRY = 0,
202 DTB_SOC,
203 DTB_MAJOR_MINOR,
204 DTB_PMIC0,
205 DTB_PMIC1,
206 DTB_PMIC2,
207 DTB_PMIC3,
208 DTB_PMIC_MODEL,
Lijuan Gaof8e95722014-12-23 03:03:12 -0500209 DTB_PANEL_TYPE,
210 DTB_BOOT_DEVICE,
Lijuan Gao9f152862014-08-18 13:45:24 +0800211};
212
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700213enum dt_err_codes
214{
215 DT_OP_SUCCESS,
216 DT_OP_FAILURE = -1,
217};
218
Lijuan Gao9f152862014-08-18 13:45:24 +0800219typedef struct dt_entry_node {
220 struct list_node node;
221 struct dt_entry * dt_entry_m;
222}dt_node;
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700223
Mayank Grover1b6da5d2017-12-19 16:05:46 +0530224struct dtbo_table_hdr {
225 uint32_t magic; //dtb table magic
226 uint32_t total_size; //Includes dt_table_hdr + all dt_table_entry and all dtb/dtbo
227 uint32_t hdr_size; //sizeof(dt_table_hdr)
228 uint32_t dt_entry_size; //sizeof(dt_table_entry)
229 uint32_t dt_entry_count; //number of dt_table_entry
230 uint32_t dt_entry_offset; //offset to the first dt_table_entry
231 uint32_t page_size; //flash pagesize we assume
232 uint32_t reserved[1]; //must zeros
233};
234
235struct dtbo_table_entry {
236 uint32_t dt_size;
237 uint32_t dt_offset; //offset from head of dt_table_hdr
238 uint32_t id; //optional, must zero if unused
239 uint32_t revision; //optional, must zero if unused
240 uint32_t custom[DTBO_CUSTOM_MAX]; //optional, must zero if unused
241};
242
Mayank Groverb61c0c22018-09-04 15:09:32 +0530243typedef enum dtbo_error
244{
245 DTBO_ERROR = 0,
246 DTBO_NOT_SUPPORTED = 1,
247 DTBO_SUCCESS = 2
248}dtbo_error;
249
250dtbo_error load_validate_dtbo_image(void **dtbo_img, uint32_t *dtbo_img_size);
Deepa Dinamani87252952013-09-09 13:58:27 -0700251int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *dt_hdr_size);
Joel Kingaa335dc2013-06-03 16:11:08 -0700252int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info);
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700253int update_device_tree(void *fdt, const char *, void *, unsigned);
254int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t size, uint64_t addr);
Matthew Qinbb7923d2015-02-09 10:56:09 +0800255void *dev_tree_appended(void *kernel, uint32_t kernel_size, uint32_t dtb_offset, void *tags);
lijuang0cce8bf2018-08-23 10:56:42 +0800256int get_dtbo_idx (void);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700257#endif