blob: fdeb3cabea7327200796c60c7f55401c90d4c936 [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
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.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>
Anatolij Gustschin411e73d2019-03-18 23:29:32 +010024#include "../videomodes.h"
Stefano Babic42f151a2010-10-13 12:17:14 +020025#include "ipu.h"
26#include "mxcfb.h"
Eric Nelson988ad422012-09-23 07:30:54 +000027#include "ipu_regs.h"
Heiko Schocher3c787842019-07-22 06:49:07 +020028#include "display.h"
Heiko Schocher92afc9b2019-07-22 06:49:08 +020029#include <panel.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020030
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +010031#include <dm.h>
32#include <video.h>
33
Eric Nelsonc9e2be62014-04-29 14:37:56 -070034DECLARE_GLOBAL_DATA_PTR;
35
Stefano Babic42f151a2010-10-13 12:17:14 +020036static int mxcfb_map_video_memory(struct fb_info *fbi);
37static int mxcfb_unmap_video_memory(struct fb_info *fbi);
38
Eric Nelson10a6cd12012-10-03 07:27:38 +000039static struct fb_videomode const *gmode;
Marek Vasutff5c108c2011-10-06 00:25:03 +020040static uint8_t gdisp;
41static uint32_t gpixfmt;
Stefano Babic42f151a2010-10-13 12:17:14 +020042
Jeroen Hofsteea175d302014-10-08 22:57:47 +020043static void fb_videomode_to_var(struct fb_var_screeninfo *var,
Stefano Babic42f151a2010-10-13 12:17:14 +020044 const struct fb_videomode *mode)
45{
46 var->xres = mode->xres;
47 var->yres = mode->yres;
48 var->xres_virtual = mode->xres;
49 var->yres_virtual = mode->yres;
50 var->xoffset = 0;
51 var->yoffset = 0;
52 var->pixclock = mode->pixclock;
53 var->left_margin = mode->left_margin;
54 var->right_margin = mode->right_margin;
55 var->upper_margin = mode->upper_margin;
56 var->lower_margin = mode->lower_margin;
57 var->hsync_len = mode->hsync_len;
58 var->vsync_len = mode->vsync_len;
59 var->sync = mode->sync;
60 var->vmode = mode->vmode & FB_VMODE_MASK;
61}
62
63/*
64 * Structure containing the MXC specific framebuffer information.
65 */
66struct mxcfb_info {
Anatolij Gustschin76057ba2020-08-03 15:45:33 +020067 struct udevice *udev;
Stefano Babic42f151a2010-10-13 12:17:14 +020068 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
Stefano Babic42f151a2010-10-13 12:17:14 +0200120static int setup_disp_channel1(struct fb_info *fbi)
121{
122 ipu_channel_params_t params;
123 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
124
125 memset(&params, 0, sizeof(params));
126 params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
127
128 debug("%s called\n", __func__);
129 /*
130 * Assuming interlaced means yuv output, below setting also
131 * valid for mem_dc_sync. FG should have the same vmode as BG.
132 */
133 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
134 params.mem_dp_bg_sync.interlaced = 1;
135 params.mem_dp_bg_sync.out_pixel_fmt =
136 IPU_PIX_FMT_YUV444;
137 } else {
138 if (mxc_fbi->ipu_di_pix_fmt) {
139 params.mem_dp_bg_sync.out_pixel_fmt =
140 mxc_fbi->ipu_di_pix_fmt;
141 } else {
142 params.mem_dp_bg_sync.out_pixel_fmt =
143 IPU_PIX_FMT_RGB666;
144 }
145 }
146 params.mem_dp_bg_sync.in_pixel_fmt = bpp_to_pixfmt(fbi);
147 if (mxc_fbi->alpha_chan_en)
148 params.mem_dp_bg_sync.alpha_chan_en = 1;
149
150 ipu_init_channel(mxc_fbi->ipu_ch, &params);
151
152 return 0;
153}
154
155static int setup_disp_channel2(struct fb_info *fbi)
156{
157 int retval = 0;
158 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
159
160 mxc_fbi->cur_ipu_buf = 1;
161 if (mxc_fbi->alpha_chan_en)
162 mxc_fbi->cur_ipu_alpha_buf = 1;
163
164 fbi->var.xoffset = fbi->var.yoffset = 0;
165
166 debug("%s: %x %d %d %d %lx %lx\n",
167 __func__,
168 mxc_fbi->ipu_ch,
169 fbi->var.xres,
170 fbi->var.yres,
171 fbi->fix.line_length,
172 fbi->fix.smem_start,
173 fbi->fix.smem_start +
174 (fbi->fix.line_length * fbi->var.yres));
175
176 retval = ipu_init_channel_buffer(mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
177 bpp_to_pixfmt(fbi),
178 fbi->var.xres, fbi->var.yres,
179 fbi->fix.line_length,
180 fbi->fix.smem_start +
181 (fbi->fix.line_length * fbi->var.yres),
182 fbi->fix.smem_start,
183 0, 0);
184 if (retval)
185 printf("ipu_init_channel_buffer error %d\n", retval);
186
187 return retval;
188}
189
190/*
191 * Set framebuffer parameters and change the operating mode.
192 *
193 * @param info framebuffer information pointer
194 */
195static int mxcfb_set_par(struct fb_info *fbi)
196{
197 int retval = 0;
198 u32 mem_len;
199 ipu_di_signal_cfg_t sig_cfg;
200 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
201 uint32_t out_pixel_fmt;
202
203 ipu_disable_channel(mxc_fbi->ipu_ch);
204 ipu_uninit_channel(mxc_fbi->ipu_ch);
Stefano Babic42f151a2010-10-13 12:17:14 +0200205
206 mem_len = fbi->var.yres_virtual * fbi->fix.line_length;
207 if (!fbi->fix.smem_start || (mem_len > fbi->fix.smem_len)) {
208 if (fbi->fix.smem_start)
209 mxcfb_unmap_video_memory(fbi);
210
211 if (mxcfb_map_video_memory(fbi) < 0)
212 return -ENOMEM;
213 }
214
215 setup_disp_channel1(fbi);
216
217 memset(&sig_cfg, 0, sizeof(sig_cfg));
218 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
219 sig_cfg.interlaced = 1;
220 out_pixel_fmt = IPU_PIX_FMT_YUV444;
221 } else {
222 if (mxc_fbi->ipu_di_pix_fmt)
223 out_pixel_fmt = mxc_fbi->ipu_di_pix_fmt;
224 else
225 out_pixel_fmt = IPU_PIX_FMT_RGB666;
226 }
227 if (fbi->var.vmode & FB_VMODE_ODD_FLD_FIRST) /* PAL */
228 sig_cfg.odd_field_first = 1;
229 if ((fbi->var.sync & FB_SYNC_EXT) || ext_clk_used)
230 sig_cfg.ext_clk = 1;
231 if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
232 sig_cfg.Hsync_pol = 1;
233 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
234 sig_cfg.Vsync_pol = 1;
235 if (!(fbi->var.sync & FB_SYNC_CLK_LAT_FALL))
236 sig_cfg.clk_pol = 1;
237 if (fbi->var.sync & FB_SYNC_DATA_INVERT)
238 sig_cfg.data_pol = 1;
239 if (!(fbi->var.sync & FB_SYNC_OE_LOW_ACT))
240 sig_cfg.enable_pol = 1;
241 if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
242 sig_cfg.clkidle_en = 1;
243
Jeroen Hofstee98276212014-10-14 20:37:14 +0200244 debug("pixclock = %lu Hz\n", PICOS2KHZ(fbi->var.pixclock) * 1000UL);
Stefano Babic42f151a2010-10-13 12:17:14 +0200245
246 if (ipu_init_sync_panel(mxc_fbi->ipu_di,
247 (PICOS2KHZ(fbi->var.pixclock)) * 1000UL,
248 fbi->var.xres, fbi->var.yres,
249 out_pixel_fmt,
250 fbi->var.left_margin,
251 fbi->var.hsync_len,
252 fbi->var.right_margin,
253 fbi->var.upper_margin,
254 fbi->var.vsync_len,
255 fbi->var.lower_margin,
256 0, sig_cfg) != 0) {
257 puts("mxcfb: Error initializing panel.\n");
258 return -EINVAL;
259 }
260
261 retval = setup_disp_channel2(fbi);
262 if (retval)
263 return retval;
264
265 if (mxc_fbi->blank == FB_BLANK_UNBLANK)
266 ipu_enable_channel(mxc_fbi->ipu_ch);
267
268 return retval;
269}
270
271/*
272 * Check framebuffer variable parameters and adjust to valid values.
273 *
274 * @param var framebuffer variable parameters
275 *
276 * @param info framebuffer information pointer
277 */
278static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
279{
280 u32 vtotal;
281 u32 htotal;
282
283 if (var->xres_virtual < var->xres)
284 var->xres_virtual = var->xres;
285 if (var->yres_virtual < var->yres)
286 var->yres_virtual = var->yres;
287
288 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
289 (var->bits_per_pixel != 16) && (var->bits_per_pixel != 8))
290 var->bits_per_pixel = default_bpp;
291
292 switch (var->bits_per_pixel) {
293 case 8:
294 var->red.length = 3;
295 var->red.offset = 5;
296 var->red.msb_right = 0;
297
298 var->green.length = 3;
299 var->green.offset = 2;
300 var->green.msb_right = 0;
301
302 var->blue.length = 2;
303 var->blue.offset = 0;
304 var->blue.msb_right = 0;
305
306 var->transp.length = 0;
307 var->transp.offset = 0;
308 var->transp.msb_right = 0;
309 break;
310 case 16:
311 var->red.length = 5;
312 var->red.offset = 11;
313 var->red.msb_right = 0;
314
315 var->green.length = 6;
316 var->green.offset = 5;
317 var->green.msb_right = 0;
318
319 var->blue.length = 5;
320 var->blue.offset = 0;
321 var->blue.msb_right = 0;
322
323 var->transp.length = 0;
324 var->transp.offset = 0;
325 var->transp.msb_right = 0;
326 break;
327 case 24:
328 var->red.length = 8;
329 var->red.offset = 16;
330 var->red.msb_right = 0;
331
332 var->green.length = 8;
333 var->green.offset = 8;
334 var->green.msb_right = 0;
335
336 var->blue.length = 8;
337 var->blue.offset = 0;
338 var->blue.msb_right = 0;
339
340 var->transp.length = 0;
341 var->transp.offset = 0;
342 var->transp.msb_right = 0;
343 break;
344 case 32:
345 var->red.length = 8;
346 var->red.offset = 16;
347 var->red.msb_right = 0;
348
349 var->green.length = 8;
350 var->green.offset = 8;
351 var->green.msb_right = 0;
352
353 var->blue.length = 8;
354 var->blue.offset = 0;
355 var->blue.msb_right = 0;
356
357 var->transp.length = 8;
358 var->transp.offset = 24;
359 var->transp.msb_right = 0;
360 break;
361 }
362
363 if (var->pixclock < 1000) {
364 htotal = var->xres + var->right_margin + var->hsync_len +
365 var->left_margin;
366 vtotal = var->yres + var->lower_margin + var->vsync_len +
367 var->upper_margin;
368 var->pixclock = (vtotal * htotal * 6UL) / 100UL;
369 var->pixclock = KHZ2PICOS(var->pixclock);
370 printf("pixclock set for 60Hz refresh = %u ps\n",
371 var->pixclock);
372 }
373
374 var->height = -1;
375 var->width = -1;
376 var->grayscale = 0;
377
378 return 0;
379}
380
381static int mxcfb_map_video_memory(struct fb_info *fbi)
382{
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200383 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
Simon Glassb75b15b2020-12-03 16:55:23 -0700384 struct video_uc_plat *plat = dev_get_uclass_plat(mxc_fbi->udev);
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200385
Stefano Babic42f151a2010-10-13 12:17:14 +0200386 if (fbi->fix.smem_len < fbi->var.yres_virtual * fbi->fix.line_length) {
387 fbi->fix.smem_len = fbi->var.yres_virtual *
388 fbi->fix.line_length;
389 }
Eric Nelsonfe6296f2013-07-26 17:53:45 -0700390 fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100391
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200392 fbi->screen_base = (char *)plat->base;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100393
Stefano Babic61852442011-09-28 11:21:15 +0200394 fbi->fix.smem_start = (unsigned long)fbi->screen_base;
Stefano Babic42f151a2010-10-13 12:17:14 +0200395 if (fbi->screen_base == 0) {
396 puts("Unable to allocate framebuffer memory\n");
397 fbi->fix.smem_len = 0;
398 fbi->fix.smem_start = 0;
399 return -EBUSY;
400 }
401
402 debug("allocated fb @ paddr=0x%08X, size=%d.\n",
403 (uint32_t) fbi->fix.smem_start, fbi->fix.smem_len);
404
405 fbi->screen_size = fbi->fix.smem_len;
Eric Nelsonc9e2be62014-04-29 14:37:56 -0700406
Stefano Babic42f151a2010-10-13 12:17:14 +0200407 /* Clear the screen */
408 memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
409
410 return 0;
411}
412
413static int mxcfb_unmap_video_memory(struct fb_info *fbi)
414{
415 fbi->screen_base = 0;
416 fbi->fix.smem_start = 0;
417 fbi->fix.smem_len = 0;
418 return 0;
419}
420
421/*
422 * Initializes the framebuffer information pointer. After allocating
423 * sufficient memory for the framebuffer structure, the fields are
424 * filled with custom information passed in from the configurable
425 * structures. This includes information such as bits per pixel,
426 * color maps, screen width/height and RGBA offsets.
427 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100428 * Return: Framebuffer structure initialized with our information
Stefano Babic42f151a2010-10-13 12:17:14 +0200429 */
430static struct fb_info *mxcfb_init_fbinfo(void)
431{
432#define BYTES_PER_LONG 4
433#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
434 struct fb_info *fbi;
435 struct mxcfb_info *mxcfbi;
436 char *p;
437 int size = sizeof(struct mxcfb_info) + PADDING +
438 sizeof(struct fb_info);
439
440 debug("%s: %d %d %d %d\n",
441 __func__,
442 PADDING,
443 size,
444 sizeof(struct mxcfb_info),
445 sizeof(struct fb_info));
446 /*
447 * Allocate sufficient memory for the fb structure
448 */
449
450 p = malloc(size);
451 if (!p)
452 return NULL;
453
454 memset(p, 0, size);
455
456 fbi = (struct fb_info *)p;
457 fbi->par = p + sizeof(struct fb_info) + PADDING;
458
459 mxcfbi = (struct mxcfb_info *)fbi->par;
460 debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
461 (unsigned int)fbi, (unsigned int)mxcfbi);
462
463 fbi->var.activate = FB_ACTIVATE_NOW;
464
465 fbi->flags = FBINFO_FLAG_DEFAULT;
466 fbi->pseudo_palette = mxcfbi->pseudo_palette;
467
468 return fbi;
469}
470
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200471extern struct clk *g_ipu_clk;
472
Stefano Babic42f151a2010-10-13 12:17:14 +0200473/*
474 * Probe routine for the framebuffer driver. It is called during the
Jeroen Hofstee98276212014-10-14 20:37:14 +0200475 * driver binding process. The following functions are performed in
Stefano Babic42f151a2010-10-13 12:17:14 +0200476 * this routine: Framebuffer initialization, Memory allocation and
477 * mapping, Framebuffer registration, IPU initialization.
478 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100479 * Return: Appropriate error code to the kernel common code
Stefano Babic42f151a2010-10-13 12:17:14 +0200480 */
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200481static int mxcfb_probe(struct udevice *dev, u32 interface_pix_fmt,
482 uint8_t disp, struct fb_videomode const *mode)
Stefano Babic42f151a2010-10-13 12:17:14 +0200483{
484 struct fb_info *fbi;
485 struct mxcfb_info *mxcfbi;
Stefano Babic42f151a2010-10-13 12:17:14 +0200486
487 /*
488 * Initialize FB structures
489 */
490 fbi = mxcfb_init_fbinfo();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200491 if (!fbi)
492 return -ENOMEM;
493
Stefano Babic42f151a2010-10-13 12:17:14 +0200494 mxcfbi = (struct mxcfb_info *)fbi->par;
495
496 if (!g_dp_in_use) {
497 mxcfbi->ipu_ch = MEM_BG_SYNC;
498 mxcfbi->blank = FB_BLANK_UNBLANK;
499 } else {
500 mxcfbi->ipu_ch = MEM_DC_SYNC;
501 mxcfbi->blank = FB_BLANK_POWERDOWN;
502 }
503
Marek Vasutff5c108c2011-10-06 00:25:03 +0200504 mxcfbi->ipu_di = disp;
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200505 mxcfbi->udev = dev;
Stefano Babic42f151a2010-10-13 12:17:14 +0200506
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200507 if (!ipu_clk_enabled())
508 clk_enable(g_ipu_clk);
509
Stefano Babic42f151a2010-10-13 12:17:14 +0200510 ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
511 ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
Stefano Babic42f151a2010-10-13 12:17:14 +0200512
513 g_dp_in_use = 1;
514
515 mxcfb_info[mxcfbi->ipu_di] = fbi;
516
517 /* Need dummy values until real panel is configured */
Stefano Babic42f151a2010-10-13 12:17:14 +0200518
519 mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
520 fb_videomode_to_var(&fbi->var, mode);
Stefano Babic61852442011-09-28 11:21:15 +0200521 fbi->var.bits_per_pixel = 16;
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200522 fbi->fix.line_length = fbi->var.xres_virtual *
523 (fbi->var.bits_per_pixel / 8);
Stefano Babic61852442011-09-28 11:21:15 +0200524 fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
Stefano Babic42f151a2010-10-13 12:17:14 +0200525
526 mxcfb_check_var(&fbi->var, fbi);
527
528 /* Default Y virtual size is 2x panel size */
529 fbi->var.yres_virtual = fbi->var.yres * 2;
530
Jeroen Hofstee98276212014-10-14 20:37:14 +0200531 /* allocate fb first */
Stefano Babic42f151a2010-10-13 12:17:14 +0200532 if (mxcfb_map_video_memory(fbi) < 0)
533 return -ENOMEM;
534
535 mxcfb_set_par(fbi);
536
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200537#ifdef DEBUG
Stefano Babic42f151a2010-10-13 12:17:14 +0200538 ipu_dump_registers();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200539#endif
Stefano Babic42f151a2010-10-13 12:17:14 +0200540
541 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200542}
543
Eric Nelson988ad422012-09-23 07:30:54 +0000544void ipuv3_fb_shutdown(void)
545{
Anatolij Gustschinfa4211c2017-08-25 15:10:43 +0200546 int i;
Tom Rini47dce762017-09-01 16:17:17 -0400547 struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
Eric Nelson988ad422012-09-23 07:30:54 +0000548
Anatolij Gustschin3e7ad7d2017-09-04 23:33:45 +0200549 if (!ipu_clk_enabled())
550 return;
551
Eric Nelson988ad422012-09-23 07:30:54 +0000552 for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
553 struct fb_info *fbi = mxcfb_info[i];
554 if (fbi) {
555 struct mxcfb_info *mxc_fbi = fbi->par;
556 ipu_disable_channel(mxc_fbi->ipu_ch);
557 ipu_uninit_channel(mxc_fbi->ipu_ch);
558 }
559 }
560 for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
561 __raw_writel(__raw_readl(&stat->int_stat[i]),
562 &stat->int_stat[i]);
563 }
564}
Stefano Babic42f151a2010-10-13 12:17:14 +0200565
Eric Nelson10a6cd12012-10-03 07:27:38 +0000566int ipuv3_fb_init(struct fb_videomode const *mode,
567 uint8_t disp,
568 uint32_t pixfmt)
Stefano Babic61852442011-09-28 11:21:15 +0200569{
570 gmode = mode;
Marek Vasutff5c108c2011-10-06 00:25:03 +0200571 gdisp = disp;
572 gpixfmt = pixfmt;
Stefano Babic61852442011-09-28 11:21:15 +0200573
574 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200575}
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100576
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100577enum {
578 /* Maximum display size we support */
579 LCD_MAX_WIDTH = 1920,
580 LCD_MAX_HEIGHT = 1080,
581 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
582};
583
584static int ipuv3_video_probe(struct udevice *dev)
585{
Simon Glassb75b15b2020-12-03 16:55:23 -0700586 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100587 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Heiko Schocher3c787842019-07-22 06:49:07 +0200588#if defined(CONFIG_DISPLAY)
589 struct udevice *disp_dev;
590#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100591 u32 fb_start, fb_end;
592 int ret;
593
594 debug("%s() plat: base 0x%lx, size 0x%x\n",
595 __func__, plat->base, plat->size);
596
597 ret = ipu_probe();
598 if (ret)
599 return ret;
600
601 ret = ipu_displays_init();
602 if (ret < 0)
603 return ret;
604
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200605 ret = mxcfb_probe(dev, gpixfmt, gdisp, gmode);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100606 if (ret < 0)
607 return ret;
608
Heiko Schocher3c787842019-07-22 06:49:07 +0200609#if defined(CONFIG_DISPLAY)
Michal Suchanekb9813e22022-10-12 21:57:56 +0200610 ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev);
611 if (!ret)
Heiko Schocher3c787842019-07-22 06:49:07 +0200612 ret = display_enable(disp_dev, 16, NULL);
Michal Suchanekb9813e22022-10-12 21:57:56 +0200613 if (ret < 0)
614 return ret;
Heiko Schocher3c787842019-07-22 06:49:07 +0200615#endif
Simon Glass6fd44e62023-02-05 17:54:44 -0700616 if (IS_ENABLED(CONFIG_PANEL)) {
Anatolij Gustschin00878362020-05-26 00:09:22 +0200617 struct udevice *panel_dev;
618
619 ret = uclass_get_device(UCLASS_PANEL, 0, &panel_dev);
620 if (panel_dev)
621 panel_enable_backlight(panel_dev);
622 }
Heiko Schocher3c787842019-07-22 06:49:07 +0200623
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100624 uc_priv->xsize = gmode->xres;
625 uc_priv->ysize = gmode->yres;
626 uc_priv->bpix = LCD_MAX_LOG2_BPP;
627
628 /* Enable dcache for the frame buffer */
629 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
630 fb_end = plat->base + plat->size;
631 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
632 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
633 DCACHE_WRITEBACK);
634 video_set_flush_dcache(dev, true);
635
636 return 0;
637}
638
639struct ipuv3_video_priv {
640 ulong regs;
641};
642
643static int ipuv3_video_bind(struct udevice *dev)
644{
Simon Glassb75b15b2020-12-03 16:55:23 -0700645 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100646
647 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
Marek Vasut28bdd932019-05-06 01:11:32 +0200648 (1 << VIDEO_BPP32) / 8;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100649
650 return 0;
651}
652
653static const struct udevice_id ipuv3_video_ids[] = {
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200654#ifdef CONFIG_ARCH_MX6
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100655 { .compatible = "fsl,imx6q-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200656#endif
657#ifdef CONFIG_ARCH_MX5
Steffen Dirkwinkel4e40f1a2019-04-17 13:57:15 +0200658 { .compatible = "fsl,imx53-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200659#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100660 { }
661};
662
Walter Lozano35f61872020-07-29 12:31:20 -0300663U_BOOT_DRIVER(fsl_imx6q_ipu) = {
664 .name = "fsl_imx6q_ipu",
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100665 .id = UCLASS_VIDEO,
666 .of_match = ipuv3_video_ids,
667 .bind = ipuv3_video_bind,
668 .probe = ipuv3_video_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700669 .priv_auto = sizeof(struct ipuv3_video_priv),
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100670 .flags = DM_FLAG_PRE_RELOC,
671};