uboot-mediatek: update to U-Boot 2024.01 release
[openwrt/staging/wigyori.git] / package / boot / uboot-mediatek / patches / 100-29-board-mediatek-wire-up-NMBM-support.patch
1 From 6792b57b3ba61ca6d69ea4a13a58bed65fc5da87 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sun, 7 Aug 2022 04:04:46 +0200
4 Subject: [PATCH] board: mediatek: wire-up NMBM support
5
6 ---
7 board/mediatek/mt7622/mt7622_rfb.c | 38 +++++++++++++++++++++
8 board/mediatek/mt7629/mt7629_rfb.c | 38 +++++++++++++++++++++
9 board/mediatek/mt7981/mt7981_rfb.c | 52 ++++++++++++++++++++++++++++
10 board/mediatek/mt7986/mt7986_rfb.c | 54 ++++++++++++++++++++++++++++++
11 4 files changed, 182 insertions(+)
12
13 --- a/board/mediatek/mt7622/mt7622_rfb.c
14 +++ b/board/mediatek/mt7622/mt7622_rfb.c
15 @@ -10,6 +10,11 @@
16 #include <init.h>
17 #include <asm/global_data.h>
18
19 +#include <mtd.h>
20 +#include <linux/mtd/mtd.h>
21 +#include <nmbm/nmbm.h>
22 +#include <nmbm/nmbm-mtd.h>
23 +
24 DECLARE_GLOBAL_DATA_PTR;
25
26 int board_init(void)
27 @@ -23,3 +28,36 @@ int board_late_init(void)
28 env_relocate();
29 return 0;
30 }
31 +
32 +int board_nmbm_init(void)
33 +{
34 +#ifdef CONFIG_ENABLE_NAND_NMBM
35 + struct mtd_info *lower, *upper;
36 + int ret;
37 +
38 + printf("\n");
39 + printf("Initializing NMBM ...\n");
40 +
41 + mtd_probe_devices();
42 +
43 + lower = get_mtd_device_nm("spi-nand0");
44 + if (IS_ERR(lower) || !lower) {
45 + printf("Lower MTD device 'spi-nand0' not found\n");
46 + return 0;
47 + }
48 +
49 + ret = nmbm_attach_mtd(lower,
50 + NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
51 + CONFIG_NMBM_MAX_RATIO,
52 + CONFIG_NMBM_MAX_BLOCKS, &upper);
53 +
54 + printf("\n");
55 +
56 + if (ret)
57 + return 0;
58 +
59 + add_mtd_device(upper);
60 +#endif
61 +
62 + return 0;
63 +}
64 --- a/board/mediatek/mt7629/mt7629_rfb.c
65 +++ b/board/mediatek/mt7629/mt7629_rfb.c
66 @@ -6,6 +6,11 @@
67 #include <common.h>
68 #include <asm/global_data.h>
69
70 +#include <mtd.h>
71 +#include <linux/mtd/mtd.h>
72 +#include <nmbm/nmbm.h>
73 +#include <nmbm/nmbm-mtd.h>
74 +
75 DECLARE_GLOBAL_DATA_PTR;
76
77 int board_init(void)
78 @@ -20,3 +25,36 @@ uint32_t spl_nand_get_uboot_raw_page(voi
79 {
80 return CONFIG_SPL_PAD_TO;
81 }
82 +
83 +int board_nmbm_init(void)
84 +{
85 +#ifdef CONFIG_ENABLE_NAND_NMBM
86 + struct mtd_info *lower, *upper;
87 + int ret;
88 +
89 + printf("\n");
90 + printf("Initializing NMBM ...\n");
91 +
92 + mtd_probe_devices();
93 +
94 + lower = get_mtd_device_nm("spi-nand0");
95 + if (IS_ERR(lower) || !lower) {
96 + printf("Lower MTD device 'spi-nand0' not found\n");
97 + return 0;
98 + }
99 +
100 + ret = nmbm_attach_mtd(lower,
101 + NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
102 + CONFIG_NMBM_MAX_RATIO,
103 + CONFIG_NMBM_MAX_BLOCKS, &upper);
104 +
105 + printf("\n");
106 +
107 + if (ret)
108 + return 0;
109 +
110 + add_mtd_device(upper);
111 +#endif
112 +
113 + return 0;
114 +}
115 --- a/board/mediatek/mt7981/mt7981_rfb.c
116 +++ b/board/mediatek/mt7981/mt7981_rfb.c
117 @@ -4,7 +4,58 @@
118 * Author: Sam Shih <sam.shih@mediatek.com>
119 */
120
121 +#include <common.h>
122 +#include <config.h>
123 +#include <env.h>
124 +#include <init.h>
125 +#include <asm/global_data.h>
126 +
127 +#include <mtd.h>
128 +#include <linux/mtd/mtd.h>
129 +#include <nmbm/nmbm.h>
130 +#include <nmbm/nmbm-mtd.h>
131 +
132 +DECLARE_GLOBAL_DATA_PTR;
133 +
134 int board_init(void)
135 {
136 return 0;
137 }
138 +
139 +int board_late_init(void)
140 +{
141 + gd->env_valid = 1; //to load environment variable from persistent store
142 + env_relocate();
143 + return 0;
144 +}
145 +
146 +int board_nmbm_init(void)
147 +{
148 +#ifdef CONFIG_ENABLE_NAND_NMBM
149 + struct mtd_info *lower, *upper;
150 + int ret;
151 +
152 + printf("\n");
153 + printf("Initializing NMBM ...\n");
154 +
155 + mtd_probe_devices();
156 +
157 + lower = get_mtd_device_nm("spi-nand0");
158 + if (IS_ERR(lower) || !lower) {
159 + printf("Lower MTD device 'spi-nand0' not found\n");
160 + return 0;
161 + }
162 +
163 + ret = nmbm_attach_mtd(lower, NMBM_F_CREATE, CONFIG_NMBM_MAX_RATIO,
164 + CONFIG_NMBM_MAX_BLOCKS, &upper);
165 +
166 + printf("\n");
167 +
168 + if (ret)
169 + return 0;
170 +
171 + add_mtd_device(upper);
172 +#endif
173 +
174 + return 0;
175 +}
176 --- a/board/mediatek/mt7986/mt7986_rfb.c
177 +++ b/board/mediatek/mt7986/mt7986_rfb.c
178 @@ -4,7 +4,60 @@
179 * Author: Sam Shih <sam.shih@mediatek.com>
180 */
181
182 +#include <common.h>
183 +#include <config.h>
184 +#include <env.h>
185 +#include <init.h>
186 +#include <asm/global_data.h>
187 +
188 +#include <mtd.h>
189 +#include <linux/mtd/mtd.h>
190 +#include <nmbm/nmbm.h>
191 +#include <nmbm/nmbm-mtd.h>
192 +
193 +DECLARE_GLOBAL_DATA_PTR;
194 +
195 int board_init(void)
196 {
197 return 0;
198 }
199 +
200 +int board_late_init(void)
201 +{
202 + gd->env_valid = 1; //to load environment variable from persistent store
203 + env_relocate();
204 + return 0;
205 +}
206 +
207 +int board_nmbm_init(void)
208 +{
209 +#ifdef CONFIG_ENABLE_NAND_NMBM
210 + struct mtd_info *lower, *upper;
211 + int ret;
212 +
213 + printf("\n");
214 + printf("Initializing NMBM ...\n");
215 +
216 + mtd_probe_devices();
217 +
218 + lower = get_mtd_device_nm("spi-nand0");
219 + if (IS_ERR(lower) || !lower) {
220 + printf("Lower MTD device 'spi-nand0' not found\n");
221 + return 0;
222 + }
223 +
224 + ret = nmbm_attach_mtd(lower,
225 + NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
226 + CONFIG_NMBM_MAX_RATIO,
227 + CONFIG_NMBM_MAX_BLOCKS, &upper);
228 +
229 + printf("\n");
230 +
231 + if (ret)
232 + return 0;
233 +
234 + add_mtd_device(upper);
235 +#endif
236 +
237 + return 0;
238 +}