blob: dc5b24c98bb82baf1c65ca05b2ce27a83730d563 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huan4779d4a2014-09-05 13:52:48 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Igor Opaniuk9a0270f2019-06-10 14:47:49 +03004 * Copyright 2019 Toradex AG
Wang Huan4779d4a2014-09-05 13:52:48 +08005 *
6 * FSL DCU Framebuffer driver
Wang Huan4779d4a2014-09-05 13:52:48 +08007 */
8
Simon Glass6980b6b2019-11-14 12:57:45 -07009#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Wang Huan4779d4a2014-09-05 13:52:48 +080012#include <asm/io.h>
13#include <common.h>
Igor Opaniuk295ef9d2019-06-10 14:47:50 +030014#include <dm.h>
Stefan Agnerec954232017-04-11 11:12:10 +053015#include <fdt_support.h>
Wang Huan4779d4a2014-09-05 13:52:48 +080016#include <fsl_dcu_fb.h>
17#include <linux/fb.h>
18#include <malloc.h>
Igor Opaniuk295ef9d2019-06-10 14:47:50 +030019#include <video.h>
Wang Huan4779d4a2014-09-05 13:52:48 +080020#include <video_fb.h>
21#include "videomodes.h"
22
23/* Convert the X,Y resolution pair into a single number */
24#define RESOLUTION(x, y) (((u32)(x) << 16) | (y))
25
26#ifdef CONFIG_SYS_FSL_DCU_LE
27#define dcu_read32 in_le32
28#define dcu_write32 out_le32
29#elif defined(CONFIG_SYS_FSL_DCU_BE)
30#define dcu_read32 in_be32
31#define dcu_write32 out_be32
32#endif
33
34#define DCU_MODE_BLEND_ITER(x) ((x) << 20)
35#define DCU_MODE_RASTER_EN (1 << 14)
36#define DCU_MODE_NORMAL 1
37#define DCU_MODE_COLORBAR 3
38#define DCU_BGND_R(x) ((x) << 16)
39#define DCU_BGND_G(x) ((x) << 8)
40#define DCU_BGND_B(x) (x)
41#define DCU_DISP_SIZE_DELTA_Y(x) ((x) << 16)
42#define DCU_DISP_SIZE_DELTA_X(x) (x)
43#define DCU_HSYN_PARA_BP(x) ((x) << 22)
44#define DCU_HSYN_PARA_PW(x) ((x) << 11)
45#define DCU_HSYN_PARA_FP(x) (x)
46#define DCU_VSYN_PARA_BP(x) ((x) << 22)
47#define DCU_VSYN_PARA_PW(x) ((x) << 11)
48#define DCU_VSYN_PARA_FP(x) (x)
Stefan Agnerf5e97b42017-04-11 11:12:11 +053049#define DCU_SYN_POL_INV_PXCK_FALL (1 << 6)
Wang Huan4779d4a2014-09-05 13:52:48 +080050#define DCU_SYN_POL_NEG_REMAIN (0 << 5)
51#define DCU_SYN_POL_INV_VS_LOW (1 << 1)
52#define DCU_SYN_POL_INV_HS_LOW (1)
53#define DCU_THRESHOLD_LS_BF_VS(x) ((x) << 16)
54#define DCU_THRESHOLD_OUT_BUF_HIGH(x) ((x) << 8)
55#define DCU_THRESHOLD_OUT_BUF_LOW(x) (x)
56#define DCU_UPDATE_MODE_MODE (1 << 31)
57#define DCU_UPDATE_MODE_READREG (1 << 30)
58
59#define DCU_CTRLDESCLN_1_HEIGHT(x) ((x) << 16)
60#define DCU_CTRLDESCLN_1_WIDTH(x) (x)
61#define DCU_CTRLDESCLN_2_POSY(x) ((x) << 16)
62#define DCU_CTRLDESCLN_2_POSX(x) (x)
63#define DCU_CTRLDESCLN_4_EN (1 << 31)
64#define DCU_CTRLDESCLN_4_TILE_EN (1 << 30)
65#define DCU_CTRLDESCLN_4_DATA_SEL_CLUT (1 << 29)
66#define DCU_CTRLDESCLN_4_SAFETY_EN (1 << 28)
67#define DCU_CTRLDESCLN_4_TRANS(x) ((x) << 20)
68#define DCU_CTRLDESCLN_4_BPP(x) ((x) << 16)
69#define DCU_CTRLDESCLN_4_RLE_EN (1 << 15)
70#define DCU_CTRLDESCLN_4_LUOFFS(x) ((x) << 4)
71#define DCU_CTRLDESCLN_4_BB_ON (1 << 2)
72#define DCU_CTRLDESCLN_4_AB(x) (x)
73#define DCU_CTRLDESCLN_5_CKMAX_R(x) ((x) << 16)
74#define DCU_CTRLDESCLN_5_CKMAX_G(x) ((x) << 8)
75#define DCU_CTRLDESCLN_5_CKMAX_B(x) (x)
76#define DCU_CTRLDESCLN_6_CKMIN_R(x) ((x) << 16)
77#define DCU_CTRLDESCLN_6_CKMIN_G(x) ((x) << 8)
78#define DCU_CTRLDESCLN_6_CKMIN_B(x) (x)
79#define DCU_CTRLDESCLN_7_TILE_VER(x) ((x) << 16)
80#define DCU_CTRLDESCLN_7_TILE_HOR(x) (x)
81#define DCU_CTRLDESCLN_8_FG_FCOLOR(x) (x)
82#define DCU_CTRLDESCLN_9_BG_BCOLOR(x) (x)
83
84#define BPP_16_RGB565 4
85#define BPP_24_RGB888 5
86#define BPP_32_ARGB8888 6
87
Stefan Agnerec954232017-04-11 11:12:10 +053088DECLARE_GLOBAL_DATA_PTR;
89
Wang Huan4779d4a2014-09-05 13:52:48 +080090/*
91 * This setting is used for the TWR_LCD_RGB card
92 */
93static struct fb_videomode fsl_dcu_mode_480_272 = {
94 .name = "480x272-60",
95 .refresh = 60,
96 .xres = 480,
97 .yres = 272,
98 .pixclock = 91996,
99 .left_margin = 2,
100 .right_margin = 2,
101 .upper_margin = 1,
102 .lower_margin = 1,
103 .hsync_len = 41,
104 .vsync_len = 2,
105 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
106 .vmode = FB_VMODE_NONINTERLACED
107};
108
109/*
110 * This setting is used for Siliconimage SiI9022A HDMI
111 */
Stefan Agnercb2c2292017-04-11 11:12:13 +0530112static struct fb_videomode fsl_dcu_cea_mode_640_480 = {
Wang Huan4779d4a2014-09-05 13:52:48 +0800113 .name = "640x480-60",
114 .refresh = 60,
115 .xres = 640,
116 .yres = 480,
117 .pixclock = 39722,
118 .left_margin = 48,
119 .right_margin = 16,
120 .upper_margin = 33,
121 .lower_margin = 10,
122 .hsync_len = 96,
123 .vsync_len = 2,
124 .sync = 0,
125 .vmode = FB_VMODE_NONINTERLACED,
126};
127
Stefan Agnercb2c2292017-04-11 11:12:13 +0530128static struct fb_videomode fsl_dcu_mode_640_480 = {
129 .name = "640x480-60",
130 .refresh = 60,
131 .xres = 640,
132 .yres = 480,
133 .pixclock = 25175,
134 .left_margin = 40,
135 .right_margin = 24,
136 .upper_margin = 32,
137 .lower_margin = 11,
138 .hsync_len = 96,
139 .vsync_len = 2,
140 .sync = 0,
141 .vmode = FB_VMODE_NONINTERLACED,
142};
143
144static struct fb_videomode fsl_dcu_mode_800_480 = {
145 .name = "800x480-60",
146 .refresh = 60,
147 .xres = 800,
148 .yres = 480,
149 .pixclock = 33260,
150 .left_margin = 216,
151 .right_margin = 40,
152 .upper_margin = 35,
153 .lower_margin = 10,
154 .hsync_len = 128,
155 .vsync_len = 2,
156 .sync = 0,
157 .vmode = FB_VMODE_NONINTERLACED,
158};
159
160static struct fb_videomode fsl_dcu_mode_1024_600 = {
161 .name = "1024x600-60",
162 .refresh = 60,
163 .xres = 1024,
164 .yres = 600,
165 .pixclock = 48000,
166 .left_margin = 104,
167 .right_margin = 43,
168 .upper_margin = 24,
169 .lower_margin = 20,
170 .hsync_len = 5,
171 .vsync_len = 5,
172 .sync = 0,
173 .vmode = FB_VMODE_NONINTERLACED,
174};
175
Wang Huan4779d4a2014-09-05 13:52:48 +0800176/*
177 * DCU register map
178 */
179struct dcu_reg {
180 u32 desc_cursor[4];
181 u32 mode;
182 u32 bgnd;
183 u32 disp_size;
184 u32 hsyn_para;
185 u32 vsyn_para;
186 u32 synpol;
187 u32 threshold;
188 u32 int_status;
189 u32 int_mask;
190 u32 colbar[8];
191 u32 div_ratio;
192 u32 sign_calc[2];
193 u32 crc_val;
194 u8 res_064[0x6c-0x64];
195 u32 parr_err_status1;
196 u8 res_070[0x7c-0x70];
197 u32 parr_err_status3;
198 u32 mparr_err_status1;
199 u8 res_084[0x90-0x84];
200 u32 mparr_err_status3;
201 u32 threshold_inp_buf[2];
202 u8 res_09c[0xa0-0x9c];
203 u32 luma_comp;
204 u32 chroma_red;
205 u32 chroma_green;
206 u32 chroma_blue;
207 u32 crc_pos;
208 u32 lyr_intpol_en;
209 u32 lyr_luma_comp;
210 u32 lyr_chrm_red;
211 u32 lyr_chrm_grn;
212 u32 lyr_chrm_blue;
213 u8 res_0c4[0xcc-0xc8];
214 u32 update_mode;
215 u32 underrun;
216 u8 res_0d4[0x100-0xd4];
217 u32 gpr;
218 u32 slr_l[2];
219 u32 slr_disp_size;
220 u32 slr_hvsync_para;
221 u32 slr_pol;
222 u32 slr_l_transp[2];
223 u8 res_120[0x200-0x120];
224 u32 ctrldescl[DCU_LAYER_MAX_NUM][16];
225};
226
Wang Huan4779d4a2014-09-05 13:52:48 +0800227static void reset_total_layers(void)
228{
229 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
230 int i;
231
232 for (i = 0; i < DCU_LAYER_MAX_NUM; i++) {
233 dcu_write32(&regs->ctrldescl[i][0], 0);
234 dcu_write32(&regs->ctrldescl[i][1], 0);
235 dcu_write32(&regs->ctrldescl[i][2], 0);
236 dcu_write32(&regs->ctrldescl[i][3], 0);
237 dcu_write32(&regs->ctrldescl[i][4], 0);
238 dcu_write32(&regs->ctrldescl[i][5], 0);
239 dcu_write32(&regs->ctrldescl[i][6], 0);
240 dcu_write32(&regs->ctrldescl[i][7], 0);
241 dcu_write32(&regs->ctrldescl[i][8], 0);
242 dcu_write32(&regs->ctrldescl[i][9], 0);
243 dcu_write32(&regs->ctrldescl[i][10], 0);
244 }
Wang Huan4779d4a2014-09-05 13:52:48 +0800245}
246
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300247static int layer_ctrldesc_init(struct fb_info fbinfo,
248 int index, u32 pixel_format)
Wang Huan4779d4a2014-09-05 13:52:48 +0800249{
250 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
251 unsigned int bpp = BPP_24_RGB888;
252
253 dcu_write32(&regs->ctrldescl[index][0],
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300254 DCU_CTRLDESCLN_1_HEIGHT(fbinfo.var.yres) |
255 DCU_CTRLDESCLN_1_WIDTH(fbinfo.var.xres));
Wang Huan4779d4a2014-09-05 13:52:48 +0800256
257 dcu_write32(&regs->ctrldescl[index][1],
258 DCU_CTRLDESCLN_2_POSY(0) |
259 DCU_CTRLDESCLN_2_POSX(0));
260
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300261 dcu_write32(&regs->ctrldescl[index][2],
262 (unsigned int)fbinfo.screen_base);
Wang Huan4779d4a2014-09-05 13:52:48 +0800263
264 switch (pixel_format) {
265 case 16:
266 bpp = BPP_16_RGB565;
267 break;
268 case 24:
269 bpp = BPP_24_RGB888;
270 break;
271 case 32:
272 bpp = BPP_32_ARGB8888;
273 break;
274 default:
275 printf("unsupported color depth: %u\n", pixel_format);
276 }
277
278 dcu_write32(&regs->ctrldescl[index][3],
279 DCU_CTRLDESCLN_4_EN |
280 DCU_CTRLDESCLN_4_TRANS(0xff) |
281 DCU_CTRLDESCLN_4_BPP(bpp) |
282 DCU_CTRLDESCLN_4_AB(0));
283
284 dcu_write32(&regs->ctrldescl[index][4],
285 DCU_CTRLDESCLN_5_CKMAX_R(0xff) |
286 DCU_CTRLDESCLN_5_CKMAX_G(0xff) |
287 DCU_CTRLDESCLN_5_CKMAX_B(0xff));
288 dcu_write32(&regs->ctrldescl[index][5],
289 DCU_CTRLDESCLN_6_CKMIN_R(0) |
290 DCU_CTRLDESCLN_6_CKMIN_G(0) |
291 DCU_CTRLDESCLN_6_CKMIN_B(0));
292
293 dcu_write32(&regs->ctrldescl[index][6],
294 DCU_CTRLDESCLN_7_TILE_VER(0) |
295 DCU_CTRLDESCLN_7_TILE_HOR(0));
296
297 dcu_write32(&regs->ctrldescl[index][7], DCU_CTRLDESCLN_8_FG_FCOLOR(0));
298 dcu_write32(&regs->ctrldescl[index][8], DCU_CTRLDESCLN_9_BG_BCOLOR(0));
299
Wang Huan4779d4a2014-09-05 13:52:48 +0800300 return 0;
301}
302
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300303int fsl_dcu_init(struct fb_info *fbinfo, unsigned int xres,
304 unsigned int yres, unsigned int pixel_format)
Wang Huan4779d4a2014-09-05 13:52:48 +0800305{
306 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
307 unsigned int div, mode;
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300308/*
309 * When DM_VIDEO is enabled reservation of framebuffer is done
310 * in advance during bind() call.
311 */
312#if !CONFIG_IS_ENABLED(DM_VIDEO)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300313 fbinfo->screen_size = fbinfo->var.xres * fbinfo->var.yres *
314 (fbinfo->var.bits_per_pixel / 8);
Stefan Agnerec954232017-04-11 11:12:10 +0530315
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300316 if (fbinfo->screen_size > CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB) {
317 fbinfo->screen_size = 0;
Stefan Agnerec954232017-04-11 11:12:10 +0530318 return -ENOMEM;
319 }
Stefan Agnerec954232017-04-11 11:12:10 +0530320 /* Reserve framebuffer at the end of memory */
321 gd->fb_base = gd->bd->bi_dram[0].start +
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300322 gd->bd->bi_dram[0].size - fbinfo->screen_size;
323 fbinfo->screen_base = (char *)gd->fb_base;
Stefan Agnerec954232017-04-11 11:12:10 +0530324
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300325 memset(fbinfo->screen_base, 0, fbinfo->screen_size);
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300326#endif
Wang Huan4779d4a2014-09-05 13:52:48 +0800327
328 reset_total_layers();
Wang Huan4779d4a2014-09-05 13:52:48 +0800329
330 dcu_write32(&regs->disp_size,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300331 DCU_DISP_SIZE_DELTA_Y(fbinfo->var.yres) |
332 DCU_DISP_SIZE_DELTA_X(fbinfo->var.xres / 16));
Wang Huan4779d4a2014-09-05 13:52:48 +0800333
334 dcu_write32(&regs->hsyn_para,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300335 DCU_HSYN_PARA_BP(fbinfo->var.left_margin) |
336 DCU_HSYN_PARA_PW(fbinfo->var.hsync_len) |
337 DCU_HSYN_PARA_FP(fbinfo->var.right_margin));
Wang Huan4779d4a2014-09-05 13:52:48 +0800338
339 dcu_write32(&regs->vsyn_para,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300340 DCU_VSYN_PARA_BP(fbinfo->var.upper_margin) |
341 DCU_VSYN_PARA_PW(fbinfo->var.vsync_len) |
342 DCU_VSYN_PARA_FP(fbinfo->var.lower_margin));
Wang Huan4779d4a2014-09-05 13:52:48 +0800343
344 dcu_write32(&regs->synpol,
345 DCU_SYN_POL_INV_PXCK_FALL |
346 DCU_SYN_POL_NEG_REMAIN |
347 DCU_SYN_POL_INV_VS_LOW |
348 DCU_SYN_POL_INV_HS_LOW);
349
350 dcu_write32(&regs->bgnd,
351 DCU_BGND_R(0) | DCU_BGND_G(0) | DCU_BGND_B(0));
352
353 dcu_write32(&regs->mode,
Stefan Agnera6d6d532017-04-11 11:12:12 +0530354 DCU_MODE_BLEND_ITER(2) |
Wang Huan4779d4a2014-09-05 13:52:48 +0800355 DCU_MODE_RASTER_EN);
356
357 dcu_write32(&regs->threshold,
358 DCU_THRESHOLD_LS_BF_VS(0x3) |
359 DCU_THRESHOLD_OUT_BUF_HIGH(0x78) |
360 DCU_THRESHOLD_OUT_BUF_LOW(0));
361
362 mode = dcu_read32(&regs->mode);
363 dcu_write32(&regs->mode, mode | DCU_MODE_NORMAL);
364
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300365 layer_ctrldesc_init(*fbinfo, 0, pixel_format);
Wang Huan4779d4a2014-09-05 13:52:48 +0800366
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300367 div = dcu_set_pixel_clock(fbinfo->var.pixclock);
Stefan Agnerf5e97b42017-04-11 11:12:11 +0530368 dcu_write32(&regs->div_ratio, (div - 1));
369
370 dcu_write32(&regs->update_mode, DCU_UPDATE_MODE_READREG);
371
Wang Huan4779d4a2014-09-05 13:52:48 +0800372 return 0;
373}
374
Stefan Agnerec954232017-04-11 11:12:10 +0530375ulong board_get_usable_ram_top(ulong total_size)
376{
377 return gd->ram_top - CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB;
378}
379
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300380int fsl_probe_common(struct fb_info *fbinfo, unsigned int *win_x,
381 unsigned int *win_y)
Wang Huan4779d4a2014-09-05 13:52:48 +0800382{
Wang Huan4779d4a2014-09-05 13:52:48 +0800383 const char *options;
384 unsigned int depth = 0, freq = 0;
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300385
Wang Huan4779d4a2014-09-05 13:52:48 +0800386 struct fb_videomode *fsl_dcu_mode_db = &fsl_dcu_mode_480_272;
387
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300388 if (!video_get_video_mode(win_x, win_y, &depth, &freq,
Wang Huan4779d4a2014-09-05 13:52:48 +0800389 &options))
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300390 return -EINVAL;
Wang Huan4779d4a2014-09-05 13:52:48 +0800391
392 /* Find the monitor port, which is a required option */
393 if (!options)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300394 return -EINVAL;
395
Wang Huan4779d4a2014-09-05 13:52:48 +0800396 if (strncmp(options, "monitor=", 8) != 0)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300397 return -EINVAL;
Wang Huan4779d4a2014-09-05 13:52:48 +0800398
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300399 switch (RESOLUTION(*win_x, *win_y)) {
Wang Huan4779d4a2014-09-05 13:52:48 +0800400 case RESOLUTION(480, 272):
401 fsl_dcu_mode_db = &fsl_dcu_mode_480_272;
402 break;
403 case RESOLUTION(640, 480):
Stefan Agnercb2c2292017-04-11 11:12:13 +0530404 if (!strncmp(options, "monitor=hdmi", 12))
405 fsl_dcu_mode_db = &fsl_dcu_cea_mode_640_480;
406 else
407 fsl_dcu_mode_db = &fsl_dcu_mode_640_480;
408 break;
409 case RESOLUTION(800, 480):
410 fsl_dcu_mode_db = &fsl_dcu_mode_800_480;
411 break;
412 case RESOLUTION(1024, 600):
413 fsl_dcu_mode_db = &fsl_dcu_mode_1024_600;
Wang Huan4779d4a2014-09-05 13:52:48 +0800414 break;
415 default:
416 printf("unsupported resolution %ux%u\n",
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300417 *win_x, *win_y);
Wang Huan4779d4a2014-09-05 13:52:48 +0800418 }
419
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300420 fbinfo->var.xres = fsl_dcu_mode_db->xres;
421 fbinfo->var.yres = fsl_dcu_mode_db->yres;
422 fbinfo->var.bits_per_pixel = 32;
423 fbinfo->var.pixclock = fsl_dcu_mode_db->pixclock;
424 fbinfo->var.left_margin = fsl_dcu_mode_db->left_margin;
425 fbinfo->var.right_margin = fsl_dcu_mode_db->right_margin;
426 fbinfo->var.upper_margin = fsl_dcu_mode_db->upper_margin;
427 fbinfo->var.lower_margin = fsl_dcu_mode_db->lower_margin;
428 fbinfo->var.hsync_len = fsl_dcu_mode_db->hsync_len;
429 fbinfo->var.vsync_len = fsl_dcu_mode_db->vsync_len;
430 fbinfo->var.sync = fsl_dcu_mode_db->sync;
431 fbinfo->var.vmode = fsl_dcu_mode_db->vmode;
432 fbinfo->fix.line_length = fbinfo->var.xres *
433 fbinfo->var.bits_per_pixel / 8;
434
435 return platform_dcu_init(fbinfo, *win_x, *win_y,
436 options + 8, fsl_dcu_mode_db);
437}
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300438
439#ifndef CONFIG_DM_VIDEO
440static struct fb_info info;
441
442#if defined(CONFIG_OF_BOARD_SETUP)
443int fsl_dcu_fixedfb_setup(void *blob)
444{
445 u64 start, size;
446 int ret;
447
448 start = gd->bd->bi_dram[0].start;
449 size = gd->bd->bi_dram[0].size - info.screen_size;
450
451 /*
452 * Align size on section size (1 MiB).
453 */
454 size &= 0xfff00000;
455 ret = fdt_fixup_memory_banks(blob, &start, &size, 1);
456 if (ret) {
457 eprintf("Cannot setup fb: Error reserving memory\n");
458 return ret;
459 }
460
461 return 0;
462}
463#endif
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300464
465void *video_hw_init(void)
466{
467 static GraphicDevice ctfb;
Wang Huan4779d4a2014-09-05 13:52:48 +0800468
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300469 if (fsl_probe_common(&info, &ctfb.winSizeX, &ctfb.winSizeY) < 0)
Wang Huan4779d4a2014-09-05 13:52:48 +0800470 return NULL;
471
472 ctfb.frameAdrs = (unsigned int)info.screen_base;
473 ctfb.plnSizeX = ctfb.winSizeX;
474 ctfb.plnSizeY = ctfb.winSizeY;
475
476 ctfb.gdfBytesPP = 4;
477 ctfb.gdfIndex = GDF_32BIT_X888RGB;
478
479 ctfb.memSize = info.screen_size;
480
481 return &ctfb;
482}
Stefan Agnerec954232017-04-11 11:12:10 +0530483
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300484#else /* ifndef CONFIG_DM_VIDEO */
485
486static int fsl_dcu_video_probe(struct udevice *dev)
Stefan Agnerec954232017-04-11 11:12:10 +0530487{
Simon Glassb75b15b2020-12-03 16:55:23 -0700488 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300489 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
490 struct fb_info fbinfo = { 0 };
491 unsigned int win_x;
492 unsigned int win_y;
493 u32 fb_start, fb_end;
494 int ret = 0;
Stefan Agnerec954232017-04-11 11:12:10 +0530495
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300496 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
497 fb_end = plat->base + plat->size;
498 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
Stefan Agnerec954232017-04-11 11:12:10 +0530499
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300500 fbinfo.screen_base = (char *)fb_start;
501 fbinfo.screen_size = plat->size;
502
503 ret = fsl_probe_common(&fbinfo, &win_x, &win_y);
504 if (ret < 0)
Stefan Agnerec954232017-04-11 11:12:10 +0530505 return ret;
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300506
507 uc_priv->bpix = VIDEO_BPP32;
508 uc_priv->xsize = win_x;
509 uc_priv->ysize = win_y;
510
511 /* Enable dcache for the frame buffer */
512 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
513 DCACHE_WRITEBACK);
514 video_set_flush_dcache(dev, true);
515 return ret;
516}
517
518static int fsl_dcu_video_bind(struct udevice *dev)
519{
Simon Glassb75b15b2020-12-03 16:55:23 -0700520 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300521 unsigned int win_x;
522 unsigned int win_y;
523 unsigned int depth = 0, freq = 0;
524 const char *options;
525 int ret = 0;
526
527 ret = video_get_video_mode(&win_x, &win_y, &depth, &freq, &options);
528 if (ret < 0)
529 return ret;
530
531 plat->size = win_x * win_y * 32;
Stefan Agnerec954232017-04-11 11:12:10 +0530532
533 return 0;
534}
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300535
536static const struct udevice_id fsl_dcu_video_ids[] = {
537 { .compatible = "fsl,vf610-dcu" },
538 { /* sentinel */ }
539};
540
541U_BOOT_DRIVER(fsl_dcu_video) = {
542 .name = "fsl_dcu_video",
543 .id = UCLASS_VIDEO,
544 .of_match = fsl_dcu_video_ids,
545 .bind = fsl_dcu_video_bind,
546 .probe = fsl_dcu_video_probe,
547 .flags = DM_FLAG_PRE_RELOC,
548};
549#endif /* ifndef CONFIG_DM_VIDEO */