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