blob: c64be38e49267720e146cb4343be696b326d7496 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babic42f151a2010-10-13 12:17:14 +02002/*
3 * Porting to u-boot:
4 *
5 * (C) Copyright 2010
6 * Stefano Babic, DENX Software Engineering, sbabic@denx.de
7 *
8 * MX51 Linux framebuffer:
9 *
10 * (C) Copyright 2004-2010 Freescale Semiconductor, Inc.
Stefano Babic42f151a2010-10-13 12:17:14 +020011 */
12
Stefano Babic42f151a2010-10-13 12:17:14 +020013#include <common.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Eric Nelsonc9e2be62014-04-29 14:37:56 -070015#include <asm/global_data.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020016#include <linux/string.h>
17#include <linux/list.h>
18#include <linux/fb.h>
19#include <asm/io.h>
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +010020#include <asm/mach-imx/video.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020021#include <malloc.h>
Stefano Babic61852442011-09-28 11:21:15 +020022#include <video_fb.h>
Anatolij Gustschin411e73d2019-03-18 23:29:32 +010023#include "../videomodes.h"
Stefano Babic42f151a2010-10-13 12:17:14 +020024#include "ipu.h"
25#include "mxcfb.h"
Eric Nelson988ad422012-09-23 07:30:54 +000026#include "ipu_regs.h"
Heiko Schocher3c787842019-07-22 06:49:07 +020027#include "display.h"
Heiko Schocher92afc9b2019-07-22 06:49:08 +020028#include <panel.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020029
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +010030#include <dm.h>
31#include <video.h>
32
Eric Nelsonc9e2be62014-04-29 14:37:56 -070033DECLARE_GLOBAL_DATA_PTR;
34
Stefano Babic42f151a2010-10-13 12:17:14 +020035static int mxcfb_map_video_memory(struct fb_info *fbi);
36static int mxcfb_unmap_video_memory(struct fb_info *fbi);
37
Stefano Babic61852442011-09-28 11:21:15 +020038/* graphics setup */
39static GraphicDevice panel;
Eric Nelson10a6cd12012-10-03 07:27:38 +000040static struct fb_videomode const *gmode;
Marek Vasutff5c108c2011-10-06 00:25:03 +020041static uint8_t gdisp;
42static uint32_t gpixfmt;
Stefano Babic42f151a2010-10-13 12:17:14 +020043
Jeroen Hofsteea175d302014-10-08 22:57:47 +020044static void fb_videomode_to_var(struct fb_var_screeninfo *var,
Stefano Babic42f151a2010-10-13 12:17:14 +020045 const struct fb_videomode *mode)
46{
47 var->xres = mode->xres;
48 var->yres = mode->yres;
49 var->xres_virtual = mode->xres;
50 var->yres_virtual = mode->yres;
51 var->xoffset = 0;
52 var->yoffset = 0;
53 var->pixclock = mode->pixclock;
54 var->left_margin = mode->left_margin;
55 var->right_margin = mode->right_margin;
56 var->upper_margin = mode->upper_margin;
57 var->lower_margin = mode->lower_margin;
58 var->hsync_len = mode->hsync_len;
59 var->vsync_len = mode->vsync_len;
60 var->sync = mode->sync;
61 var->vmode = mode->vmode & FB_VMODE_MASK;
62}
63
64/*
65 * Structure containing the MXC specific framebuffer information.
66 */
67struct mxcfb_info {
68 int blank;
69 ipu_channel_t ipu_ch;
70 int ipu_di;
71 u32 ipu_di_pix_fmt;
72 unsigned char overlay;
73 unsigned char alpha_chan_en;
74 dma_addr_t alpha_phy_addr0;
75 dma_addr_t alpha_phy_addr1;
76 void *alpha_virt_addr0;
77 void *alpha_virt_addr1;
78 uint32_t alpha_mem_len;
79 uint32_t cur_ipu_buf;
80 uint32_t cur_ipu_alpha_buf;
81
82 u32 pseudo_palette[16];
83};
84
85enum {
86 BOTH_ON,
87 SRC_ON,
88 TGT_ON,
89 BOTH_OFF
90};
91
92static unsigned long default_bpp = 16;
93static unsigned char g_dp_in_use;
94static struct fb_info *mxcfb_info[3];
95static int ext_clk_used;
96
97static uint32_t bpp_to_pixfmt(struct fb_info *fbi)
98{
99 uint32_t pixfmt = 0;
100
101 debug("bpp_to_pixfmt: %d\n", fbi->var.bits_per_pixel);
102
103 if (fbi->var.nonstd)
104 return fbi->var.nonstd;
105
106 switch (fbi->var.bits_per_pixel) {
107 case 24:
108 pixfmt = IPU_PIX_FMT_BGR24;
109 break;
110 case 32:
111 pixfmt = IPU_PIX_FMT_BGR32;
112 break;
113 case 16:
114 pixfmt = IPU_PIX_FMT_RGB565;
115 break;
116 }
117 return pixfmt;
118}
119
120/*
121 * Set fixed framebuffer parameters based on variable settings.
122 *
123 * @param info framebuffer information pointer
124 */
125static int mxcfb_set_fix(struct fb_info *info)
126{
127 struct fb_fix_screeninfo *fix = &info->fix;
128 struct fb_var_screeninfo *var = &info->var;
129
130 fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
131
132 fix->type = FB_TYPE_PACKED_PIXELS;
133 fix->accel = FB_ACCEL_NONE;
134 fix->visual = FB_VISUAL_TRUECOLOR;
135 fix->xpanstep = 1;
136 fix->ypanstep = 1;
137
138 return 0;
139}
140
141static int setup_disp_channel1(struct fb_info *fbi)
142{
143 ipu_channel_params_t params;
144 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
145
146 memset(&params, 0, sizeof(params));
147 params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
148
149 debug("%s called\n", __func__);
150 /*
151 * Assuming interlaced means yuv output, below setting also
152 * valid for mem_dc_sync. FG should have the same vmode as BG.
153 */
154 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
155 params.mem_dp_bg_sync.interlaced = 1;
156 params.mem_dp_bg_sync.out_pixel_fmt =
157 IPU_PIX_FMT_YUV444;
158 } else {
159 if (mxc_fbi->ipu_di_pix_fmt) {
160 params.mem_dp_bg_sync.out_pixel_fmt =
161 mxc_fbi->ipu_di_pix_fmt;
162 } else {
163 params.mem_dp_bg_sync.out_pixel_fmt =
164 IPU_PIX_FMT_RGB666;
165 }
166 }
167 params.mem_dp_bg_sync.in_pixel_fmt = bpp_to_pixfmt(fbi);
168 if (mxc_fbi->alpha_chan_en)
169 params.mem_dp_bg_sync.alpha_chan_en = 1;
170
171 ipu_init_channel(mxc_fbi->ipu_ch, &params);
172
173 return 0;
174}
175
176static int setup_disp_channel2(struct fb_info *fbi)
177{
178 int retval = 0;
179 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
180
181 mxc_fbi->cur_ipu_buf = 1;
182 if (mxc_fbi->alpha_chan_en)
183 mxc_fbi->cur_ipu_alpha_buf = 1;
184
185 fbi->var.xoffset = fbi->var.yoffset = 0;
186
187 debug("%s: %x %d %d %d %lx %lx\n",
188 __func__,
189 mxc_fbi->ipu_ch,
190 fbi->var.xres,
191 fbi->var.yres,
192 fbi->fix.line_length,
193 fbi->fix.smem_start,
194 fbi->fix.smem_start +
195 (fbi->fix.line_length * fbi->var.yres));
196
197 retval = ipu_init_channel_buffer(mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
198 bpp_to_pixfmt(fbi),
199 fbi->var.xres, fbi->var.yres,
200 fbi->fix.line_length,
201 fbi->fix.smem_start +
202 (fbi->fix.line_length * fbi->var.yres),
203 fbi->fix.smem_start,
204 0, 0);
205 if (retval)
206 printf("ipu_init_channel_buffer error %d\n", retval);
207
208 return retval;
209}
210
211/*
212 * Set framebuffer parameters and change the operating mode.
213 *
214 * @param info framebuffer information pointer
215 */
216static int mxcfb_set_par(struct fb_info *fbi)
217{
218 int retval = 0;
219 u32 mem_len;
220 ipu_di_signal_cfg_t sig_cfg;
221 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
222 uint32_t out_pixel_fmt;
223
224 ipu_disable_channel(mxc_fbi->ipu_ch);
225 ipu_uninit_channel(mxc_fbi->ipu_ch);
226 mxcfb_set_fix(fbi);
227
228 mem_len = fbi->var.yres_virtual * fbi->fix.line_length;
229 if (!fbi->fix.smem_start || (mem_len > fbi->fix.smem_len)) {
230 if (fbi->fix.smem_start)
231 mxcfb_unmap_video_memory(fbi);
232
233 if (mxcfb_map_video_memory(fbi) < 0)
234 return -ENOMEM;
235 }
236
237 setup_disp_channel1(fbi);
238
239 memset(&sig_cfg, 0, sizeof(sig_cfg));
240 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
241 sig_cfg.interlaced = 1;
242 out_pixel_fmt = IPU_PIX_FMT_YUV444;
243 } else {
244 if (mxc_fbi->ipu_di_pix_fmt)
245 out_pixel_fmt = mxc_fbi->ipu_di_pix_fmt;
246 else
247 out_pixel_fmt = IPU_PIX_FMT_RGB666;
248 }
249 if (fbi->var.vmode & FB_VMODE_ODD_FLD_FIRST) /* PAL */
250 sig_cfg.odd_field_first = 1;
251 if ((fbi->var.sync & FB_SYNC_EXT) || ext_clk_used)
252 sig_cfg.ext_clk = 1;
253 if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
254 sig_cfg.Hsync_pol = 1;
255 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
256 sig_cfg.Vsync_pol = 1;
257 if (!(fbi->var.sync & FB_SYNC_CLK_LAT_FALL))
258 sig_cfg.clk_pol = 1;
259 if (fbi->var.sync & FB_SYNC_DATA_INVERT)
260 sig_cfg.data_pol = 1;
261 if (!(fbi->var.sync & FB_SYNC_OE_LOW_ACT))
262 sig_cfg.enable_pol = 1;
263 if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
264 sig_cfg.clkidle_en = 1;
265
Jeroen Hofstee98276212014-10-14 20:37:14 +0200266 debug("pixclock = %lu Hz\n", PICOS2KHZ(fbi->var.pixclock) * 1000UL);
Stefano Babic42f151a2010-10-13 12:17:14 +0200267
268 if (ipu_init_sync_panel(mxc_fbi->ipu_di,
269 (PICOS2KHZ(fbi->var.pixclock)) * 1000UL,
270 fbi->var.xres, fbi->var.yres,
271 out_pixel_fmt,
272 fbi->var.left_margin,
273 fbi->var.hsync_len,
274 fbi->var.right_margin,
275 fbi->var.upper_margin,
276 fbi->var.vsync_len,
277 fbi->var.lower_margin,
278 0, sig_cfg) != 0) {
279 puts("mxcfb: Error initializing panel.\n");
280 return -EINVAL;
281 }
282
283 retval = setup_disp_channel2(fbi);
284 if (retval)
285 return retval;
286
287 if (mxc_fbi->blank == FB_BLANK_UNBLANK)
288 ipu_enable_channel(mxc_fbi->ipu_ch);
289
290 return retval;
291}
292
293/*
294 * Check framebuffer variable parameters and adjust to valid values.
295 *
296 * @param var framebuffer variable parameters
297 *
298 * @param info framebuffer information pointer
299 */
300static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
301{
302 u32 vtotal;
303 u32 htotal;
304
305 if (var->xres_virtual < var->xres)
306 var->xres_virtual = var->xres;
307 if (var->yres_virtual < var->yres)
308 var->yres_virtual = var->yres;
309
310 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
311 (var->bits_per_pixel != 16) && (var->bits_per_pixel != 8))
312 var->bits_per_pixel = default_bpp;
313
314 switch (var->bits_per_pixel) {
315 case 8:
316 var->red.length = 3;
317 var->red.offset = 5;
318 var->red.msb_right = 0;
319
320 var->green.length = 3;
321 var->green.offset = 2;
322 var->green.msb_right = 0;
323
324 var->blue.length = 2;
325 var->blue.offset = 0;
326 var->blue.msb_right = 0;
327
328 var->transp.length = 0;
329 var->transp.offset = 0;
330 var->transp.msb_right = 0;
331 break;
332 case 16:
333 var->red.length = 5;
334 var->red.offset = 11;
335 var->red.msb_right = 0;
336
337 var->green.length = 6;
338 var->green.offset = 5;
339 var->green.msb_right = 0;
340
341 var->blue.length = 5;
342 var->blue.offset = 0;
343 var->blue.msb_right = 0;
344
345 var->transp.length = 0;
346 var->transp.offset = 0;
347 var->transp.msb_right = 0;
348 break;
349 case 24:
350 var->red.length = 8;
351 var->red.offset = 16;
352 var->red.msb_right = 0;
353
354 var->green.length = 8;
355 var->green.offset = 8;
356 var->green.msb_right = 0;
357
358 var->blue.length = 8;
359 var->blue.offset = 0;
360 var->blue.msb_right = 0;
361
362 var->transp.length = 0;
363 var->transp.offset = 0;
364 var->transp.msb_right = 0;
365 break;
366 case 32:
367 var->red.length = 8;
368 var->red.offset = 16;
369 var->red.msb_right = 0;
370
371 var->green.length = 8;
372 var->green.offset = 8;
373 var->green.msb_right = 0;
374
375 var->blue.length = 8;
376 var->blue.offset = 0;
377 var->blue.msb_right = 0;
378
379 var->transp.length = 8;
380 var->transp.offset = 24;
381 var->transp.msb_right = 0;
382 break;
383 }
384
385 if (var->pixclock < 1000) {
386 htotal = var->xres + var->right_margin + var->hsync_len +
387 var->left_margin;
388 vtotal = var->yres + var->lower_margin + var->vsync_len +
389 var->upper_margin;
390 var->pixclock = (vtotal * htotal * 6UL) / 100UL;
391 var->pixclock = KHZ2PICOS(var->pixclock);
392 printf("pixclock set for 60Hz refresh = %u ps\n",
393 var->pixclock);
394 }
395
396 var->height = -1;
397 var->width = -1;
398 var->grayscale = 0;
399
400 return 0;
401}
402
403static int mxcfb_map_video_memory(struct fb_info *fbi)
404{
405 if (fbi->fix.smem_len < fbi->var.yres_virtual * fbi->fix.line_length) {
406 fbi->fix.smem_len = fbi->var.yres_virtual *
407 fbi->fix.line_length;
408 }
Eric Nelsonfe6296f2013-07-26 17:53:45 -0700409 fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100410
411#if CONFIG_IS_ENABLED(DM_VIDEO)
412 fbi->screen_base = (char *)gd->video_bottom;
413#else
Eric Nelsonfe6296f2013-07-26 17:53:45 -0700414 fbi->screen_base = (char *)memalign(ARCH_DMA_MINALIGN,
415 fbi->fix.smem_len);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100416#endif
417
Stefano Babic61852442011-09-28 11:21:15 +0200418 fbi->fix.smem_start = (unsigned long)fbi->screen_base;
Stefano Babic42f151a2010-10-13 12:17:14 +0200419 if (fbi->screen_base == 0) {
420 puts("Unable to allocate framebuffer memory\n");
421 fbi->fix.smem_len = 0;
422 fbi->fix.smem_start = 0;
423 return -EBUSY;
424 }
425
426 debug("allocated fb @ paddr=0x%08X, size=%d.\n",
427 (uint32_t) fbi->fix.smem_start, fbi->fix.smem_len);
428
429 fbi->screen_size = fbi->fix.smem_len;
430
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100431#if CONFIG_IS_ENABLED(VIDEO)
Eric Nelsonc9e2be62014-04-29 14:37:56 -0700432 gd->fb_base = fbi->fix.smem_start;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100433#endif
Eric Nelsonc9e2be62014-04-29 14:37:56 -0700434
Stefano Babic42f151a2010-10-13 12:17:14 +0200435 /* Clear the screen */
436 memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
437
438 return 0;
439}
440
441static int mxcfb_unmap_video_memory(struct fb_info *fbi)
442{
443 fbi->screen_base = 0;
444 fbi->fix.smem_start = 0;
445 fbi->fix.smem_len = 0;
446 return 0;
447}
448
449/*
450 * Initializes the framebuffer information pointer. After allocating
451 * sufficient memory for the framebuffer structure, the fields are
452 * filled with custom information passed in from the configurable
453 * structures. This includes information such as bits per pixel,
454 * color maps, screen width/height and RGBA offsets.
455 *
456 * @return Framebuffer structure initialized with our information
457 */
458static struct fb_info *mxcfb_init_fbinfo(void)
459{
460#define BYTES_PER_LONG 4
461#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
462 struct fb_info *fbi;
463 struct mxcfb_info *mxcfbi;
464 char *p;
465 int size = sizeof(struct mxcfb_info) + PADDING +
466 sizeof(struct fb_info);
467
468 debug("%s: %d %d %d %d\n",
469 __func__,
470 PADDING,
471 size,
472 sizeof(struct mxcfb_info),
473 sizeof(struct fb_info));
474 /*
475 * Allocate sufficient memory for the fb structure
476 */
477
478 p = malloc(size);
479 if (!p)
480 return NULL;
481
482 memset(p, 0, size);
483
484 fbi = (struct fb_info *)p;
485 fbi->par = p + sizeof(struct fb_info) + PADDING;
486
487 mxcfbi = (struct mxcfb_info *)fbi->par;
488 debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
489 (unsigned int)fbi, (unsigned int)mxcfbi);
490
491 fbi->var.activate = FB_ACTIVATE_NOW;
492
493 fbi->flags = FBINFO_FLAG_DEFAULT;
494 fbi->pseudo_palette = mxcfbi->pseudo_palette;
495
496 return fbi;
497}
498
499/*
500 * Probe routine for the framebuffer driver. It is called during the
Jeroen Hofstee98276212014-10-14 20:37:14 +0200501 * driver binding process. The following functions are performed in
Stefano Babic42f151a2010-10-13 12:17:14 +0200502 * this routine: Framebuffer initialization, Memory allocation and
503 * mapping, Framebuffer registration, IPU initialization.
504 *
505 * @return Appropriate error code to the kernel common code
506 */
Marek Vasutff5c108c2011-10-06 00:25:03 +0200507static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
Eric Nelson10a6cd12012-10-03 07:27:38 +0000508 struct fb_videomode const *mode)
Stefano Babic42f151a2010-10-13 12:17:14 +0200509{
510 struct fb_info *fbi;
511 struct mxcfb_info *mxcfbi;
512 int ret = 0;
513
514 /*
515 * Initialize FB structures
516 */
517 fbi = mxcfb_init_fbinfo();
518 if (!fbi) {
519 ret = -ENOMEM;
520 goto err0;
521 }
522 mxcfbi = (struct mxcfb_info *)fbi->par;
523
524 if (!g_dp_in_use) {
525 mxcfbi->ipu_ch = MEM_BG_SYNC;
526 mxcfbi->blank = FB_BLANK_UNBLANK;
527 } else {
528 mxcfbi->ipu_ch = MEM_DC_SYNC;
529 mxcfbi->blank = FB_BLANK_POWERDOWN;
530 }
531
Marek Vasutff5c108c2011-10-06 00:25:03 +0200532 mxcfbi->ipu_di = disp;
Stefano Babic42f151a2010-10-13 12:17:14 +0200533
534 ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
535 ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
536 strcpy(fbi->fix.id, "DISP3 BG");
537
538 g_dp_in_use = 1;
539
540 mxcfb_info[mxcfbi->ipu_di] = fbi;
541
542 /* Need dummy values until real panel is configured */
Stefano Babic42f151a2010-10-13 12:17:14 +0200543
544 mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
545 fb_videomode_to_var(&fbi->var, mode);
Stefano Babic61852442011-09-28 11:21:15 +0200546 fbi->var.bits_per_pixel = 16;
547 fbi->fix.line_length = fbi->var.xres * (fbi->var.bits_per_pixel / 8);
548 fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
Stefano Babic42f151a2010-10-13 12:17:14 +0200549
550 mxcfb_check_var(&fbi->var, fbi);
551
552 /* Default Y virtual size is 2x panel size */
553 fbi->var.yres_virtual = fbi->var.yres * 2;
554
555 mxcfb_set_fix(fbi);
556
Jeroen Hofstee98276212014-10-14 20:37:14 +0200557 /* allocate fb first */
Stefano Babic42f151a2010-10-13 12:17:14 +0200558 if (mxcfb_map_video_memory(fbi) < 0)
559 return -ENOMEM;
560
561 mxcfb_set_par(fbi);
562
Stefano Babic61852442011-09-28 11:21:15 +0200563 panel.winSizeX = mode->xres;
564 panel.winSizeY = mode->yres;
565 panel.plnSizeX = mode->xres;
566 panel.plnSizeY = mode->yres;
Stefano Babic42f151a2010-10-13 12:17:14 +0200567
Stefano Babic61852442011-09-28 11:21:15 +0200568 panel.frameAdrs = (u32)fbi->screen_base;
569 panel.memSize = fbi->screen_size;
Stefano Babic42f151a2010-10-13 12:17:14 +0200570
Stefano Babic61852442011-09-28 11:21:15 +0200571 panel.gdfBytesPP = 2;
572 panel.gdfIndex = GDF_16BIT_565RGB;
Stefano Babic42f151a2010-10-13 12:17:14 +0200573
574 ipu_dump_registers();
575
576 return 0;
577
578err0:
579 return ret;
580}
581
Eric Nelson988ad422012-09-23 07:30:54 +0000582void ipuv3_fb_shutdown(void)
583{
Anatolij Gustschinfa4211c2017-08-25 15:10:43 +0200584 int i;
Tom Rini47dce762017-09-01 16:17:17 -0400585 struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
Eric Nelson988ad422012-09-23 07:30:54 +0000586
Anatolij Gustschin3e7ad7d2017-09-04 23:33:45 +0200587 if (!ipu_clk_enabled())
588 return;
589
Eric Nelson988ad422012-09-23 07:30:54 +0000590 for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
591 struct fb_info *fbi = mxcfb_info[i];
592 if (fbi) {
593 struct mxcfb_info *mxc_fbi = fbi->par;
594 ipu_disable_channel(mxc_fbi->ipu_ch);
595 ipu_uninit_channel(mxc_fbi->ipu_ch);
596 }
597 }
598 for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
599 __raw_writel(__raw_readl(&stat->int_stat[i]),
600 &stat->int_stat[i]);
601 }
602}
603
Stefano Babic61852442011-09-28 11:21:15 +0200604void *video_hw_init(void)
Stefano Babic42f151a2010-10-13 12:17:14 +0200605{
606 int ret;
607
608 ret = ipu_probe();
609 if (ret)
610 puts("Error initializing IPU\n");
611
Marek Vasutff5c108c2011-10-06 00:25:03 +0200612 ret = mxcfb_probe(gpixfmt, gdisp, gmode);
Stefano Babic61852442011-09-28 11:21:15 +0200613 debug("Framebuffer at 0x%x\n", (unsigned int)panel.frameAdrs);
Heiko Schocherabb59422019-07-22 06:49:05 +0200614 gd->fb_base = panel.frameAdrs;
Stefano Babic42f151a2010-10-13 12:17:14 +0200615
Stefano Babic61852442011-09-28 11:21:15 +0200616 return (void *)&panel;
617}
Stefano Babic42f151a2010-10-13 12:17:14 +0200618
Eric Nelson10a6cd12012-10-03 07:27:38 +0000619int ipuv3_fb_init(struct fb_videomode const *mode,
620 uint8_t disp,
621 uint32_t pixfmt)
Stefano Babic61852442011-09-28 11:21:15 +0200622{
623 gmode = mode;
Marek Vasutff5c108c2011-10-06 00:25:03 +0200624 gdisp = disp;
625 gpixfmt = pixfmt;
Stefano Babic61852442011-09-28 11:21:15 +0200626
627 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200628}
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100629
630#if CONFIG_IS_ENABLED(DM_VIDEO)
631enum {
632 /* Maximum display size we support */
633 LCD_MAX_WIDTH = 1920,
634 LCD_MAX_HEIGHT = 1080,
635 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
636};
637
638static int ipuv3_video_probe(struct udevice *dev)
639{
640 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
641 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Heiko Schocher3c787842019-07-22 06:49:07 +0200642#if defined(CONFIG_DISPLAY)
643 struct udevice *disp_dev;
644#endif
Heiko Schocher92afc9b2019-07-22 06:49:08 +0200645 struct udevice *panel_dev;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100646 u32 fb_start, fb_end;
647 int ret;
648
649 debug("%s() plat: base 0x%lx, size 0x%x\n",
650 __func__, plat->base, plat->size);
651
652 ret = ipu_probe();
653 if (ret)
654 return ret;
655
656 ret = ipu_displays_init();
657 if (ret < 0)
658 return ret;
659
660 ret = mxcfb_probe(gpixfmt, gdisp, gmode);
661 if (ret < 0)
662 return ret;
663
Heiko Schocher3c787842019-07-22 06:49:07 +0200664#if defined(CONFIG_DISPLAY)
665 ret = uclass_first_device(UCLASS_DISPLAY, &disp_dev);
666 if (disp_dev) {
667 ret = display_enable(disp_dev, 16, NULL);
668 if (ret < 0)
669 return ret;
670 }
671#endif
Heiko Schocher92afc9b2019-07-22 06:49:08 +0200672 ret = uclass_get_device(UCLASS_PANEL, 0, &panel_dev);
673 if (panel_dev)
674 panel_enable_backlight(panel_dev);
Heiko Schocher3c787842019-07-22 06:49:07 +0200675
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100676 uc_priv->xsize = gmode->xres;
677 uc_priv->ysize = gmode->yres;
678 uc_priv->bpix = LCD_MAX_LOG2_BPP;
679
680 /* Enable dcache for the frame buffer */
681 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
682 fb_end = plat->base + plat->size;
683 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
684 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
685 DCACHE_WRITEBACK);
686 video_set_flush_dcache(dev, true);
Heiko Schocherabb59422019-07-22 06:49:05 +0200687 gd->fb_base = fb_start;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100688
689 return 0;
690}
691
692struct ipuv3_video_priv {
693 ulong regs;
694};
695
696static int ipuv3_video_bind(struct udevice *dev)
697{
698 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
699
700 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
Marek Vasut28bdd932019-05-06 01:11:32 +0200701 (1 << VIDEO_BPP32) / 8;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100702
703 return 0;
704}
705
706static const struct udevice_id ipuv3_video_ids[] = {
707 { .compatible = "fsl,imx6q-ipu" },
Steffen Dirkwinkel4e40f1a2019-04-17 13:57:15 +0200708 { .compatible = "fsl,imx53-ipu" },
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100709 { }
710};
711
712U_BOOT_DRIVER(ipuv3_video) = {
713 .name = "ipuv3_video",
714 .id = UCLASS_VIDEO,
715 .of_match = ipuv3_video_ids,
716 .bind = ipuv3_video_bind,
717 .probe = ipuv3_video_probe,
718 .priv_auto_alloc_size = sizeof(struct ipuv3_video_priv),
719 .flags = DM_FLAG_PRE_RELOC,
720};
721#endif /* CONFIG_DM_VIDEO */