blob: e9d05c93946a8d069abf75703eff1da323a26458 [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>
Wang Huan4779d4a2014-09-05 13:52:48 +080011#include <asm/io.h>
12#include <common.h>
Igor Opaniuk295ef9d2019-06-10 14:47:50 +030013#include <dm.h>
Stefan Agnerec954232017-04-11 11:12:10 +053014#include <fdt_support.h>
Wang Huan4779d4a2014-09-05 13:52:48 +080015#include <fsl_dcu_fb.h>
16#include <linux/fb.h>
17#include <malloc.h>
Igor Opaniuk295ef9d2019-06-10 14:47:50 +030018#include <video.h>
Wang Huan4779d4a2014-09-05 13:52:48 +080019#include <video_fb.h>
20#include "videomodes.h"
21
22/* Convert the X,Y resolution pair into a single number */
23#define RESOLUTION(x, y) (((u32)(x) << 16) | (y))
24
25#ifdef CONFIG_SYS_FSL_DCU_LE
26#define dcu_read32 in_le32
27#define dcu_write32 out_le32
28#elif defined(CONFIG_SYS_FSL_DCU_BE)
29#define dcu_read32 in_be32
30#define dcu_write32 out_be32
31#endif
32
33#define DCU_MODE_BLEND_ITER(x) ((x) << 20)
34#define DCU_MODE_RASTER_EN (1 << 14)
35#define DCU_MODE_NORMAL 1
36#define DCU_MODE_COLORBAR 3
37#define DCU_BGND_R(x) ((x) << 16)
38#define DCU_BGND_G(x) ((x) << 8)
39#define DCU_BGND_B(x) (x)
40#define DCU_DISP_SIZE_DELTA_Y(x) ((x) << 16)
41#define DCU_DISP_SIZE_DELTA_X(x) (x)
42#define DCU_HSYN_PARA_BP(x) ((x) << 22)
43#define DCU_HSYN_PARA_PW(x) ((x) << 11)
44#define DCU_HSYN_PARA_FP(x) (x)
45#define DCU_VSYN_PARA_BP(x) ((x) << 22)
46#define DCU_VSYN_PARA_PW(x) ((x) << 11)
47#define DCU_VSYN_PARA_FP(x) (x)
Stefan Agnerf5e97b42017-04-11 11:12:11 +053048#define DCU_SYN_POL_INV_PXCK_FALL (1 << 6)
Wang Huan4779d4a2014-09-05 13:52:48 +080049#define DCU_SYN_POL_NEG_REMAIN (0 << 5)
50#define DCU_SYN_POL_INV_VS_LOW (1 << 1)
51#define DCU_SYN_POL_INV_HS_LOW (1)
52#define DCU_THRESHOLD_LS_BF_VS(x) ((x) << 16)
53#define DCU_THRESHOLD_OUT_BUF_HIGH(x) ((x) << 8)
54#define DCU_THRESHOLD_OUT_BUF_LOW(x) (x)
55#define DCU_UPDATE_MODE_MODE (1 << 31)
56#define DCU_UPDATE_MODE_READREG (1 << 30)
57
58#define DCU_CTRLDESCLN_1_HEIGHT(x) ((x) << 16)
59#define DCU_CTRLDESCLN_1_WIDTH(x) (x)
60#define DCU_CTRLDESCLN_2_POSY(x) ((x) << 16)
61#define DCU_CTRLDESCLN_2_POSX(x) (x)
62#define DCU_CTRLDESCLN_4_EN (1 << 31)
63#define DCU_CTRLDESCLN_4_TILE_EN (1 << 30)
64#define DCU_CTRLDESCLN_4_DATA_SEL_CLUT (1 << 29)
65#define DCU_CTRLDESCLN_4_SAFETY_EN (1 << 28)
66#define DCU_CTRLDESCLN_4_TRANS(x) ((x) << 20)
67#define DCU_CTRLDESCLN_4_BPP(x) ((x) << 16)
68#define DCU_CTRLDESCLN_4_RLE_EN (1 << 15)
69#define DCU_CTRLDESCLN_4_LUOFFS(x) ((x) << 4)
70#define DCU_CTRLDESCLN_4_BB_ON (1 << 2)
71#define DCU_CTRLDESCLN_4_AB(x) (x)
72#define DCU_CTRLDESCLN_5_CKMAX_R(x) ((x) << 16)
73#define DCU_CTRLDESCLN_5_CKMAX_G(x) ((x) << 8)
74#define DCU_CTRLDESCLN_5_CKMAX_B(x) (x)
75#define DCU_CTRLDESCLN_6_CKMIN_R(x) ((x) << 16)
76#define DCU_CTRLDESCLN_6_CKMIN_G(x) ((x) << 8)
77#define DCU_CTRLDESCLN_6_CKMIN_B(x) (x)
78#define DCU_CTRLDESCLN_7_TILE_VER(x) ((x) << 16)
79#define DCU_CTRLDESCLN_7_TILE_HOR(x) (x)
80#define DCU_CTRLDESCLN_8_FG_FCOLOR(x) (x)
81#define DCU_CTRLDESCLN_9_BG_BCOLOR(x) (x)
82
83#define BPP_16_RGB565 4
84#define BPP_24_RGB888 5
85#define BPP_32_ARGB8888 6
86
Stefan Agnerec954232017-04-11 11:12:10 +053087DECLARE_GLOBAL_DATA_PTR;
88
Wang Huan4779d4a2014-09-05 13:52:48 +080089/*
90 * This setting is used for the TWR_LCD_RGB card
91 */
92static struct fb_videomode fsl_dcu_mode_480_272 = {
93 .name = "480x272-60",
94 .refresh = 60,
95 .xres = 480,
96 .yres = 272,
97 .pixclock = 91996,
98 .left_margin = 2,
99 .right_margin = 2,
100 .upper_margin = 1,
101 .lower_margin = 1,
102 .hsync_len = 41,
103 .vsync_len = 2,
104 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
105 .vmode = FB_VMODE_NONINTERLACED
106};
107
108/*
109 * This setting is used for Siliconimage SiI9022A HDMI
110 */
Stefan Agnercb2c2292017-04-11 11:12:13 +0530111static struct fb_videomode fsl_dcu_cea_mode_640_480 = {
Wang Huan4779d4a2014-09-05 13:52:48 +0800112 .name = "640x480-60",
113 .refresh = 60,
114 .xres = 640,
115 .yres = 480,
116 .pixclock = 39722,
117 .left_margin = 48,
118 .right_margin = 16,
119 .upper_margin = 33,
120 .lower_margin = 10,
121 .hsync_len = 96,
122 .vsync_len = 2,
123 .sync = 0,
124 .vmode = FB_VMODE_NONINTERLACED,
125};
126
Stefan Agnercb2c2292017-04-11 11:12:13 +0530127static struct fb_videomode fsl_dcu_mode_640_480 = {
128 .name = "640x480-60",
129 .refresh = 60,
130 .xres = 640,
131 .yres = 480,
132 .pixclock = 25175,
133 .left_margin = 40,
134 .right_margin = 24,
135 .upper_margin = 32,
136 .lower_margin = 11,
137 .hsync_len = 96,
138 .vsync_len = 2,
139 .sync = 0,
140 .vmode = FB_VMODE_NONINTERLACED,
141};
142
143static struct fb_videomode fsl_dcu_mode_800_480 = {
144 .name = "800x480-60",
145 .refresh = 60,
146 .xres = 800,
147 .yres = 480,
148 .pixclock = 33260,
149 .left_margin = 216,
150 .right_margin = 40,
151 .upper_margin = 35,
152 .lower_margin = 10,
153 .hsync_len = 128,
154 .vsync_len = 2,
155 .sync = 0,
156 .vmode = FB_VMODE_NONINTERLACED,
157};
158
159static struct fb_videomode fsl_dcu_mode_1024_600 = {
160 .name = "1024x600-60",
161 .refresh = 60,
162 .xres = 1024,
163 .yres = 600,
164 .pixclock = 48000,
165 .left_margin = 104,
166 .right_margin = 43,
167 .upper_margin = 24,
168 .lower_margin = 20,
169 .hsync_len = 5,
170 .vsync_len = 5,
171 .sync = 0,
172 .vmode = FB_VMODE_NONINTERLACED,
173};
174
Wang Huan4779d4a2014-09-05 13:52:48 +0800175/*
176 * DCU register map
177 */
178struct dcu_reg {
179 u32 desc_cursor[4];
180 u32 mode;
181 u32 bgnd;
182 u32 disp_size;
183 u32 hsyn_para;
184 u32 vsyn_para;
185 u32 synpol;
186 u32 threshold;
187 u32 int_status;
188 u32 int_mask;
189 u32 colbar[8];
190 u32 div_ratio;
191 u32 sign_calc[2];
192 u32 crc_val;
193 u8 res_064[0x6c-0x64];
194 u32 parr_err_status1;
195 u8 res_070[0x7c-0x70];
196 u32 parr_err_status3;
197 u32 mparr_err_status1;
198 u8 res_084[0x90-0x84];
199 u32 mparr_err_status3;
200 u32 threshold_inp_buf[2];
201 u8 res_09c[0xa0-0x9c];
202 u32 luma_comp;
203 u32 chroma_red;
204 u32 chroma_green;
205 u32 chroma_blue;
206 u32 crc_pos;
207 u32 lyr_intpol_en;
208 u32 lyr_luma_comp;
209 u32 lyr_chrm_red;
210 u32 lyr_chrm_grn;
211 u32 lyr_chrm_blue;
212 u8 res_0c4[0xcc-0xc8];
213 u32 update_mode;
214 u32 underrun;
215 u8 res_0d4[0x100-0xd4];
216 u32 gpr;
217 u32 slr_l[2];
218 u32 slr_disp_size;
219 u32 slr_hvsync_para;
220 u32 slr_pol;
221 u32 slr_l_transp[2];
222 u8 res_120[0x200-0x120];
223 u32 ctrldescl[DCU_LAYER_MAX_NUM][16];
224};
225
Wang Huan4779d4a2014-09-05 13:52:48 +0800226static void reset_total_layers(void)
227{
228 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
229 int i;
230
231 for (i = 0; i < DCU_LAYER_MAX_NUM; i++) {
232 dcu_write32(&regs->ctrldescl[i][0], 0);
233 dcu_write32(&regs->ctrldescl[i][1], 0);
234 dcu_write32(&regs->ctrldescl[i][2], 0);
235 dcu_write32(&regs->ctrldescl[i][3], 0);
236 dcu_write32(&regs->ctrldescl[i][4], 0);
237 dcu_write32(&regs->ctrldescl[i][5], 0);
238 dcu_write32(&regs->ctrldescl[i][6], 0);
239 dcu_write32(&regs->ctrldescl[i][7], 0);
240 dcu_write32(&regs->ctrldescl[i][8], 0);
241 dcu_write32(&regs->ctrldescl[i][9], 0);
242 dcu_write32(&regs->ctrldescl[i][10], 0);
243 }
Wang Huan4779d4a2014-09-05 13:52:48 +0800244}
245
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300246static int layer_ctrldesc_init(struct fb_info fbinfo,
247 int index, u32 pixel_format)
Wang Huan4779d4a2014-09-05 13:52:48 +0800248{
249 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
250 unsigned int bpp = BPP_24_RGB888;
251
252 dcu_write32(&regs->ctrldescl[index][0],
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300253 DCU_CTRLDESCLN_1_HEIGHT(fbinfo.var.yres) |
254 DCU_CTRLDESCLN_1_WIDTH(fbinfo.var.xres));
Wang Huan4779d4a2014-09-05 13:52:48 +0800255
256 dcu_write32(&regs->ctrldescl[index][1],
257 DCU_CTRLDESCLN_2_POSY(0) |
258 DCU_CTRLDESCLN_2_POSX(0));
259
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300260 dcu_write32(&regs->ctrldescl[index][2],
261 (unsigned int)fbinfo.screen_base);
Wang Huan4779d4a2014-09-05 13:52:48 +0800262
263 switch (pixel_format) {
264 case 16:
265 bpp = BPP_16_RGB565;
266 break;
267 case 24:
268 bpp = BPP_24_RGB888;
269 break;
270 case 32:
271 bpp = BPP_32_ARGB8888;
272 break;
273 default:
274 printf("unsupported color depth: %u\n", pixel_format);
275 }
276
277 dcu_write32(&regs->ctrldescl[index][3],
278 DCU_CTRLDESCLN_4_EN |
279 DCU_CTRLDESCLN_4_TRANS(0xff) |
280 DCU_CTRLDESCLN_4_BPP(bpp) |
281 DCU_CTRLDESCLN_4_AB(0));
282
283 dcu_write32(&regs->ctrldescl[index][4],
284 DCU_CTRLDESCLN_5_CKMAX_R(0xff) |
285 DCU_CTRLDESCLN_5_CKMAX_G(0xff) |
286 DCU_CTRLDESCLN_5_CKMAX_B(0xff));
287 dcu_write32(&regs->ctrldescl[index][5],
288 DCU_CTRLDESCLN_6_CKMIN_R(0) |
289 DCU_CTRLDESCLN_6_CKMIN_G(0) |
290 DCU_CTRLDESCLN_6_CKMIN_B(0));
291
292 dcu_write32(&regs->ctrldescl[index][6],
293 DCU_CTRLDESCLN_7_TILE_VER(0) |
294 DCU_CTRLDESCLN_7_TILE_HOR(0));
295
296 dcu_write32(&regs->ctrldescl[index][7], DCU_CTRLDESCLN_8_FG_FCOLOR(0));
297 dcu_write32(&regs->ctrldescl[index][8], DCU_CTRLDESCLN_9_BG_BCOLOR(0));
298
Wang Huan4779d4a2014-09-05 13:52:48 +0800299 return 0;
300}
301
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300302int fsl_dcu_init(struct fb_info *fbinfo, unsigned int xres,
303 unsigned int yres, unsigned int pixel_format)
Wang Huan4779d4a2014-09-05 13:52:48 +0800304{
305 struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
306 unsigned int div, mode;
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300307/*
308 * When DM_VIDEO is enabled reservation of framebuffer is done
309 * in advance during bind() call.
310 */
311#if !CONFIG_IS_ENABLED(DM_VIDEO)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300312 fbinfo->screen_size = fbinfo->var.xres * fbinfo->var.yres *
313 (fbinfo->var.bits_per_pixel / 8);
Stefan Agnerec954232017-04-11 11:12:10 +0530314
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300315 if (fbinfo->screen_size > CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB) {
316 fbinfo->screen_size = 0;
Stefan Agnerec954232017-04-11 11:12:10 +0530317 return -ENOMEM;
318 }
Stefan Agnerec954232017-04-11 11:12:10 +0530319 /* Reserve framebuffer at the end of memory */
320 gd->fb_base = gd->bd->bi_dram[0].start +
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300321 gd->bd->bi_dram[0].size - fbinfo->screen_size;
322 fbinfo->screen_base = (char *)gd->fb_base;
Stefan Agnerec954232017-04-11 11:12:10 +0530323
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300324 memset(fbinfo->screen_base, 0, fbinfo->screen_size);
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300325#endif
Wang Huan4779d4a2014-09-05 13:52:48 +0800326
327 reset_total_layers();
Wang Huan4779d4a2014-09-05 13:52:48 +0800328
329 dcu_write32(&regs->disp_size,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300330 DCU_DISP_SIZE_DELTA_Y(fbinfo->var.yres) |
331 DCU_DISP_SIZE_DELTA_X(fbinfo->var.xres / 16));
Wang Huan4779d4a2014-09-05 13:52:48 +0800332
333 dcu_write32(&regs->hsyn_para,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300334 DCU_HSYN_PARA_BP(fbinfo->var.left_margin) |
335 DCU_HSYN_PARA_PW(fbinfo->var.hsync_len) |
336 DCU_HSYN_PARA_FP(fbinfo->var.right_margin));
Wang Huan4779d4a2014-09-05 13:52:48 +0800337
338 dcu_write32(&regs->vsyn_para,
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300339 DCU_VSYN_PARA_BP(fbinfo->var.upper_margin) |
340 DCU_VSYN_PARA_PW(fbinfo->var.vsync_len) |
341 DCU_VSYN_PARA_FP(fbinfo->var.lower_margin));
Wang Huan4779d4a2014-09-05 13:52:48 +0800342
343 dcu_write32(&regs->synpol,
344 DCU_SYN_POL_INV_PXCK_FALL |
345 DCU_SYN_POL_NEG_REMAIN |
346 DCU_SYN_POL_INV_VS_LOW |
347 DCU_SYN_POL_INV_HS_LOW);
348
349 dcu_write32(&regs->bgnd,
350 DCU_BGND_R(0) | DCU_BGND_G(0) | DCU_BGND_B(0));
351
352 dcu_write32(&regs->mode,
Stefan Agnera6d6d532017-04-11 11:12:12 +0530353 DCU_MODE_BLEND_ITER(2) |
Wang Huan4779d4a2014-09-05 13:52:48 +0800354 DCU_MODE_RASTER_EN);
355
356 dcu_write32(&regs->threshold,
357 DCU_THRESHOLD_LS_BF_VS(0x3) |
358 DCU_THRESHOLD_OUT_BUF_HIGH(0x78) |
359 DCU_THRESHOLD_OUT_BUF_LOW(0));
360
361 mode = dcu_read32(&regs->mode);
362 dcu_write32(&regs->mode, mode | DCU_MODE_NORMAL);
363
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300364 layer_ctrldesc_init(*fbinfo, 0, pixel_format);
Wang Huan4779d4a2014-09-05 13:52:48 +0800365
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300366 div = dcu_set_pixel_clock(fbinfo->var.pixclock);
Stefan Agnerf5e97b42017-04-11 11:12:11 +0530367 dcu_write32(&regs->div_ratio, (div - 1));
368
369 dcu_write32(&regs->update_mode, DCU_UPDATE_MODE_READREG);
370
Wang Huan4779d4a2014-09-05 13:52:48 +0800371 return 0;
372}
373
Stefan Agnerec954232017-04-11 11:12:10 +0530374ulong board_get_usable_ram_top(ulong total_size)
375{
376 return gd->ram_top - CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB;
377}
378
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300379int fsl_probe_common(struct fb_info *fbinfo, unsigned int *win_x,
380 unsigned int *win_y)
Wang Huan4779d4a2014-09-05 13:52:48 +0800381{
Wang Huan4779d4a2014-09-05 13:52:48 +0800382 const char *options;
383 unsigned int depth = 0, freq = 0;
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300384
Wang Huan4779d4a2014-09-05 13:52:48 +0800385 struct fb_videomode *fsl_dcu_mode_db = &fsl_dcu_mode_480_272;
386
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300387 if (!video_get_video_mode(win_x, win_y, &depth, &freq,
Wang Huan4779d4a2014-09-05 13:52:48 +0800388 &options))
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300389 return -EINVAL;
Wang Huan4779d4a2014-09-05 13:52:48 +0800390
391 /* Find the monitor port, which is a required option */
392 if (!options)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300393 return -EINVAL;
394
Wang Huan4779d4a2014-09-05 13:52:48 +0800395 if (strncmp(options, "monitor=", 8) != 0)
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300396 return -EINVAL;
Wang Huan4779d4a2014-09-05 13:52:48 +0800397
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300398 switch (RESOLUTION(*win_x, *win_y)) {
Wang Huan4779d4a2014-09-05 13:52:48 +0800399 case RESOLUTION(480, 272):
400 fsl_dcu_mode_db = &fsl_dcu_mode_480_272;
401 break;
402 case RESOLUTION(640, 480):
Stefan Agnercb2c2292017-04-11 11:12:13 +0530403 if (!strncmp(options, "monitor=hdmi", 12))
404 fsl_dcu_mode_db = &fsl_dcu_cea_mode_640_480;
405 else
406 fsl_dcu_mode_db = &fsl_dcu_mode_640_480;
407 break;
408 case RESOLUTION(800, 480):
409 fsl_dcu_mode_db = &fsl_dcu_mode_800_480;
410 break;
411 case RESOLUTION(1024, 600):
412 fsl_dcu_mode_db = &fsl_dcu_mode_1024_600;
Wang Huan4779d4a2014-09-05 13:52:48 +0800413 break;
414 default:
415 printf("unsupported resolution %ux%u\n",
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300416 *win_x, *win_y);
Wang Huan4779d4a2014-09-05 13:52:48 +0800417 }
418
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300419 fbinfo->var.xres = fsl_dcu_mode_db->xres;
420 fbinfo->var.yres = fsl_dcu_mode_db->yres;
421 fbinfo->var.bits_per_pixel = 32;
422 fbinfo->var.pixclock = fsl_dcu_mode_db->pixclock;
423 fbinfo->var.left_margin = fsl_dcu_mode_db->left_margin;
424 fbinfo->var.right_margin = fsl_dcu_mode_db->right_margin;
425 fbinfo->var.upper_margin = fsl_dcu_mode_db->upper_margin;
426 fbinfo->var.lower_margin = fsl_dcu_mode_db->lower_margin;
427 fbinfo->var.hsync_len = fsl_dcu_mode_db->hsync_len;
428 fbinfo->var.vsync_len = fsl_dcu_mode_db->vsync_len;
429 fbinfo->var.sync = fsl_dcu_mode_db->sync;
430 fbinfo->var.vmode = fsl_dcu_mode_db->vmode;
431 fbinfo->fix.line_length = fbinfo->var.xres *
432 fbinfo->var.bits_per_pixel / 8;
433
434 return platform_dcu_init(fbinfo, *win_x, *win_y,
435 options + 8, fsl_dcu_mode_db);
436}
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300437
438#ifndef CONFIG_DM_VIDEO
439static struct fb_info info;
440
441#if defined(CONFIG_OF_BOARD_SETUP)
442int fsl_dcu_fixedfb_setup(void *blob)
443{
444 u64 start, size;
445 int ret;
446
447 start = gd->bd->bi_dram[0].start;
448 size = gd->bd->bi_dram[0].size - info.screen_size;
449
450 /*
451 * Align size on section size (1 MiB).
452 */
453 size &= 0xfff00000;
454 ret = fdt_fixup_memory_banks(blob, &start, &size, 1);
455 if (ret) {
456 eprintf("Cannot setup fb: Error reserving memory\n");
457 return ret;
458 }
459
460 return 0;
461}
462#endif
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300463
464void *video_hw_init(void)
465{
466 static GraphicDevice ctfb;
Wang Huan4779d4a2014-09-05 13:52:48 +0800467
Igor Opaniuk9a0270f2019-06-10 14:47:49 +0300468 if (fsl_probe_common(&info, &ctfb.winSizeX, &ctfb.winSizeY) < 0)
Wang Huan4779d4a2014-09-05 13:52:48 +0800469 return NULL;
470
471 ctfb.frameAdrs = (unsigned int)info.screen_base;
472 ctfb.plnSizeX = ctfb.winSizeX;
473 ctfb.plnSizeY = ctfb.winSizeY;
474
475 ctfb.gdfBytesPP = 4;
476 ctfb.gdfIndex = GDF_32BIT_X888RGB;
477
478 ctfb.memSize = info.screen_size;
479
480 return &ctfb;
481}
Stefan Agnerec954232017-04-11 11:12:10 +0530482
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300483#else /* ifndef CONFIG_DM_VIDEO */
484
485static int fsl_dcu_video_probe(struct udevice *dev)
Stefan Agnerec954232017-04-11 11:12:10 +0530486{
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300487 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
488 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
489 struct fb_info fbinfo = { 0 };
490 unsigned int win_x;
491 unsigned int win_y;
492 u32 fb_start, fb_end;
493 int ret = 0;
Stefan Agnerec954232017-04-11 11:12:10 +0530494
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300495 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
496 fb_end = plat->base + plat->size;
497 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
Stefan Agnerec954232017-04-11 11:12:10 +0530498
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300499 fbinfo.screen_base = (char *)fb_start;
500 fbinfo.screen_size = plat->size;
501
502 ret = fsl_probe_common(&fbinfo, &win_x, &win_y);
503 if (ret < 0)
Stefan Agnerec954232017-04-11 11:12:10 +0530504 return ret;
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300505
506 uc_priv->bpix = VIDEO_BPP32;
507 uc_priv->xsize = win_x;
508 uc_priv->ysize = win_y;
509
510 /* Enable dcache for the frame buffer */
511 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
512 DCACHE_WRITEBACK);
513 video_set_flush_dcache(dev, true);
514 return ret;
515}
516
517static int fsl_dcu_video_bind(struct udevice *dev)
518{
519 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
520 unsigned int win_x;
521 unsigned int win_y;
522 unsigned int depth = 0, freq = 0;
523 const char *options;
524 int ret = 0;
525
526 ret = video_get_video_mode(&win_x, &win_y, &depth, &freq, &options);
527 if (ret < 0)
528 return ret;
529
530 plat->size = win_x * win_y * 32;
Stefan Agnerec954232017-04-11 11:12:10 +0530531
532 return 0;
533}
Igor Opaniuk295ef9d2019-06-10 14:47:50 +0300534
535static const struct udevice_id fsl_dcu_video_ids[] = {
536 { .compatible = "fsl,vf610-dcu" },
537 { /* sentinel */ }
538};
539
540U_BOOT_DRIVER(fsl_dcu_video) = {
541 .name = "fsl_dcu_video",
542 .id = UCLASS_VIDEO,
543 .of_match = fsl_dcu_video_ids,
544 .bind = fsl_dcu_video_bind,
545 .probe = fsl_dcu_video_probe,
546 .flags = DM_FLAG_PRE_RELOC,
547};
548#endif /* ifndef CONFIG_DM_VIDEO */