blob: 6c06b4407d996bc0b1163035af70366e6e2cd0d3 [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)
61#define DTBO_IMG_BUF (8388608) /* 8MB 8 * 1024 * 1024 */
Channagoud Kadabia4dbe332013-09-05 17:44:11 -070062/*
63 * For DTB V1: The DTB entries would be of the format
64 * qcom,msm-id = <msm8974, CDP, rev_1>; (3 * sizeof(uint32_t))
65 * For DTB V2: The DTB entries would be of the format
66 * qcom,msm-id = <msm8974, rev_1>; (2 * sizeof(uint32_t))
67 * qcom,board-id = <CDP, subtype_ID>; (2 * sizeof(uint32_t))
68 * The macros below are defined based on these.
69 */
70#define DT_ENTRY_V1_SIZE 0xC
71#define PLAT_ID_SIZE 0x8
72#define BOARD_ID_SIZE 0x8
Lijuan Gao9f152862014-08-18 13:45:24 +080073#define PMIC_ID_SIZE 0x8
74
Mayank Grover1b6da5d2017-12-19 16:05:46 +053075typedef enum {
76 NONE_MATCH,
77 PMIC_MATCH_BEST_REV_IDX0,
78 PMIC_MATCH_EXACT_REV_IDX0,
79 PMIC_MATCH_BEST_REV_IDX1,
80 PMIC_MATCH_EXACT_REV_IDX1,
81 PMIC_MATCH_BEST_REV_IDX2,
82 PMIC_MATCH_EXACT_REV_IDX2,
83 PMIC_MATCH_BEST_REV_IDX3,
84 PMIC_MATCH_EXACT_REV_IDX3,
85 VARIANT_MINOR_BEST_MATCH,
86 VARIANT_MINOR_EXACT_MATCH,
87 VARIANT_MAJOR_BEST_MATCH,
88 VARIANT_MAJOR_EXACT_MATCH,
89 VERSION_BEST_MATCH,
90 VERSION_EXACT_MATCH,
91 FOUNDRYID_DEFAULT_MATCH,
92 FOUNDRYID_EXACT_MATCH,
93 PMIC_MATCH_DEFAULT_MODEL_IDX0,
94 PMIC_MATCH_EXACT_MODEL_IDX0,
95 PMIC_MATCH_DEFAULT_MODEL_IDX1,
96 PMIC_MATCH_EXACT_MODEL_IDX1,
97 PMIC_MATCH_DEFAULT_MODEL_IDX2,
98 PMIC_MATCH_EXACT_MODEL_IDX2,
99 PMIC_MATCH_DEFAULT_MODEL_IDX3,
100 PMIC_MATCH_EXACT_MODEL_IDX3,
101 SUBTYPE_DEFAULT_MATCH,
102 SUBTYPE_EXACT_MATCH,
103 VARIANT_MATCH,
104 SOC_MATCH,
105 MAX_MATCH,
106}dt_match_params;
107
108#define TOTAL_MATCH_BITS 6
109#define ALL_BITS_SET (BIT (SOC_MATCH) | BIT (VARIANT_MATCH) | \
110 BIT (SUBTYPE_EXACT_MATCH) | BIT (FOUNDRYID_EXACT_MATCH) \
111 | BIT (PMIC_MATCH_EXACT_MODEL_IDX0) | \
112 BIT (PMIC_MATCH_EXACT_MODEL_IDX1))
113
114typedef enum {
115 PMIC_IDX0,
116 PMIC_IDX1,
117 PMIC_IDX2,
118 PMIC_IDX3,
119 MAX_PMIC_IDX,
120}pmic_indexes;
121
122
123typedef struct dt_info
124{
125 uint32_t dt_platform_id;
126 uint32_t dt_soc_rev;
127 uint32_t dt_foundry_id;
128 uint32_t dt_variant_id;
129 uint32_t dt_variant_major;
130 uint32_t dt_variant_minor;
131 uint32_t dt_platform_subtype;
132 uint32_t dt_pmic_model[MAX_PMIC_IDX];
133 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
134 uint32_t dt_match_val;
135 void *dtb;
136}dt_info;
137
138typedef struct pmic_info
139{
140 uint32_t dt_pmic_model[MAX_PMIC_IDX];
141 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
142 uint32_t dt_match_val;
143}pmic_info;
Lijuan Gao9f152862014-08-18 13:45:24 +0800144
145struct dt_entry_v2
146{
147 uint32_t platform_id;
148 uint32_t variant_id;
149 uint32_t board_hw_subtype;
150 uint32_t soc_rev;
151 uint32_t offset;
152 uint32_t size;
153};
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700154
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700155struct dt_entry
156{
157 uint32_t platform_id;
158 uint32_t variant_id;
Joel Kingaa335dc2013-06-03 16:11:08 -0700159 uint32_t board_hw_subtype;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700160 uint32_t soc_rev;
Lijuan Gao9f152862014-08-18 13:45:24 +0800161 uint32_t pmic_rev[4];
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700162 uint32_t offset;
163 uint32_t size;
164};
165
166struct dt_table
167{
168 uint32_t magic;
169 uint32_t version;
170 uint32_t num_entries;
171};
172
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700173struct plat_id
174{
175 uint32_t platform_id;
176 uint32_t soc_rev;
177};
178
179struct board_id
180{
181 uint32_t variant_id;
182 uint32_t platform_subtype;
183};
184
Lijuan Gao9f152862014-08-18 13:45:24 +0800185struct pmic_id
186{
187 uint32_t pmic_version[4];
188};
189
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700190struct dt_mem_node_info
191{
192 uint32_t offset;
193 uint32_t mem_info_cnt;
194 uint32_t addr_cell_size;
195 uint32_t size_cell_size;
196};
197
Lijuan Gao9f152862014-08-18 13:45:24 +0800198enum dt_entry_info
199{
200 DTB_FOUNDRY = 0,
201 DTB_SOC,
202 DTB_MAJOR_MINOR,
203 DTB_PMIC0,
204 DTB_PMIC1,
205 DTB_PMIC2,
206 DTB_PMIC3,
207 DTB_PMIC_MODEL,
Lijuan Gaof8e95722014-12-23 03:03:12 -0500208 DTB_PANEL_TYPE,
209 DTB_BOOT_DEVICE,
Lijuan Gao9f152862014-08-18 13:45:24 +0800210};
211
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700212enum dt_err_codes
213{
214 DT_OP_SUCCESS,
215 DT_OP_FAILURE = -1,
216};
217
Lijuan Gao9f152862014-08-18 13:45:24 +0800218typedef struct dt_entry_node {
219 struct list_node node;
220 struct dt_entry * dt_entry_m;
221}dt_node;
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700222
Mayank Grover1b6da5d2017-12-19 16:05:46 +0530223struct dtbo_table_hdr {
224 uint32_t magic; //dtb table magic
225 uint32_t total_size; //Includes dt_table_hdr + all dt_table_entry and all dtb/dtbo
226 uint32_t hdr_size; //sizeof(dt_table_hdr)
227 uint32_t dt_entry_size; //sizeof(dt_table_entry)
228 uint32_t dt_entry_count; //number of dt_table_entry
229 uint32_t dt_entry_offset; //offset to the first dt_table_entry
230 uint32_t page_size; //flash pagesize we assume
231 uint32_t reserved[1]; //must zeros
232};
233
234struct dtbo_table_entry {
235 uint32_t dt_size;
236 uint32_t dt_offset; //offset from head of dt_table_hdr
237 uint32_t id; //optional, must zero if unused
238 uint32_t revision; //optional, must zero if unused
239 uint32_t custom[DTBO_CUSTOM_MAX]; //optional, must zero if unused
240};
241
Deepa Dinamani87252952013-09-09 13:58:27 -0700242int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *dt_hdr_size);
Joel Kingaa335dc2013-06-03 16:11:08 -0700243int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info);
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700244int update_device_tree(void *fdt, const char *, void *, unsigned);
245int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t size, uint64_t addr);
Matthew Qinbb7923d2015-02-09 10:56:09 +0800246void *dev_tree_appended(void *kernel, uint32_t kernel_size, uint32_t dtb_offset, void *tags);
lijuang0cce8bf2018-08-23 10:56:42 +0800247int get_dtbo_idx (void);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700248#endif