blob: 039b22086a93ca6498efafdff00a2393e70be687 [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 gd->fb_base = fbi->fix.smem_start;
407
Stefano Babic42f151a2010-10-13 12:17:14 +0200408 /* Clear the screen */
409 memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
410
411 return 0;
412}
413
414static int mxcfb_unmap_video_memory(struct fb_info *fbi)
415{
416 fbi->screen_base = 0;
417 fbi->fix.smem_start = 0;
418 fbi->fix.smem_len = 0;
419 return 0;
420}
421
422/*
423 * Initializes the framebuffer information pointer. After allocating
424 * sufficient memory for the framebuffer structure, the fields are
425 * filled with custom information passed in from the configurable
426 * structures. This includes information such as bits per pixel,
427 * color maps, screen width/height and RGBA offsets.
428 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100429 * Return: Framebuffer structure initialized with our information
Stefano Babic42f151a2010-10-13 12:17:14 +0200430 */
431static struct fb_info *mxcfb_init_fbinfo(void)
432{
433#define BYTES_PER_LONG 4
434#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
435 struct fb_info *fbi;
436 struct mxcfb_info *mxcfbi;
437 char *p;
438 int size = sizeof(struct mxcfb_info) + PADDING +
439 sizeof(struct fb_info);
440
441 debug("%s: %d %d %d %d\n",
442 __func__,
443 PADDING,
444 size,
445 sizeof(struct mxcfb_info),
446 sizeof(struct fb_info));
447 /*
448 * Allocate sufficient memory for the fb structure
449 */
450
451 p = malloc(size);
452 if (!p)
453 return NULL;
454
455 memset(p, 0, size);
456
457 fbi = (struct fb_info *)p;
458 fbi->par = p + sizeof(struct fb_info) + PADDING;
459
460 mxcfbi = (struct mxcfb_info *)fbi->par;
461 debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
462 (unsigned int)fbi, (unsigned int)mxcfbi);
463
464 fbi->var.activate = FB_ACTIVATE_NOW;
465
466 fbi->flags = FBINFO_FLAG_DEFAULT;
467 fbi->pseudo_palette = mxcfbi->pseudo_palette;
468
469 return fbi;
470}
471
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200472extern struct clk *g_ipu_clk;
473
Stefano Babic42f151a2010-10-13 12:17:14 +0200474/*
475 * Probe routine for the framebuffer driver. It is called during the
Jeroen Hofstee98276212014-10-14 20:37:14 +0200476 * driver binding process. The following functions are performed in
Stefano Babic42f151a2010-10-13 12:17:14 +0200477 * this routine: Framebuffer initialization, Memory allocation and
478 * mapping, Framebuffer registration, IPU initialization.
479 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100480 * Return: Appropriate error code to the kernel common code
Stefano Babic42f151a2010-10-13 12:17:14 +0200481 */
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200482static int mxcfb_probe(struct udevice *dev, u32 interface_pix_fmt,
483 uint8_t disp, struct fb_videomode const *mode)
Stefano Babic42f151a2010-10-13 12:17:14 +0200484{
485 struct fb_info *fbi;
486 struct mxcfb_info *mxcfbi;
Stefano Babic42f151a2010-10-13 12:17:14 +0200487
488 /*
489 * Initialize FB structures
490 */
491 fbi = mxcfb_init_fbinfo();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200492 if (!fbi)
493 return -ENOMEM;
494
Stefano Babic42f151a2010-10-13 12:17:14 +0200495 mxcfbi = (struct mxcfb_info *)fbi->par;
496
497 if (!g_dp_in_use) {
498 mxcfbi->ipu_ch = MEM_BG_SYNC;
499 mxcfbi->blank = FB_BLANK_UNBLANK;
500 } else {
501 mxcfbi->ipu_ch = MEM_DC_SYNC;
502 mxcfbi->blank = FB_BLANK_POWERDOWN;
503 }
504
Marek Vasutff5c108c2011-10-06 00:25:03 +0200505 mxcfbi->ipu_di = disp;
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200506 mxcfbi->udev = dev;
Stefano Babic42f151a2010-10-13 12:17:14 +0200507
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200508 if (!ipu_clk_enabled())
509 clk_enable(g_ipu_clk);
510
Stefano Babic42f151a2010-10-13 12:17:14 +0200511 ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
512 ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
Stefano Babic42f151a2010-10-13 12:17:14 +0200513
514 g_dp_in_use = 1;
515
516 mxcfb_info[mxcfbi->ipu_di] = fbi;
517
518 /* Need dummy values until real panel is configured */
Stefano Babic42f151a2010-10-13 12:17:14 +0200519
520 mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
521 fb_videomode_to_var(&fbi->var, mode);
Stefano Babic61852442011-09-28 11:21:15 +0200522 fbi->var.bits_per_pixel = 16;
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200523 fbi->fix.line_length = fbi->var.xres_virtual *
524 (fbi->var.bits_per_pixel / 8);
Stefano Babic61852442011-09-28 11:21:15 +0200525 fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
Stefano Babic42f151a2010-10-13 12:17:14 +0200526
527 mxcfb_check_var(&fbi->var, fbi);
528
529 /* Default Y virtual size is 2x panel size */
530 fbi->var.yres_virtual = fbi->var.yres * 2;
531
Jeroen Hofstee98276212014-10-14 20:37:14 +0200532 /* allocate fb first */
Stefano Babic42f151a2010-10-13 12:17:14 +0200533 if (mxcfb_map_video_memory(fbi) < 0)
534 return -ENOMEM;
535
536 mxcfb_set_par(fbi);
537
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200538#ifdef DEBUG
Stefano Babic42f151a2010-10-13 12:17:14 +0200539 ipu_dump_registers();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200540#endif
Stefano Babic42f151a2010-10-13 12:17:14 +0200541
542 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200543}
544
Eric Nelson988ad422012-09-23 07:30:54 +0000545void ipuv3_fb_shutdown(void)
546{
Anatolij Gustschinfa4211c2017-08-25 15:10:43 +0200547 int i;
Tom Rini47dce762017-09-01 16:17:17 -0400548 struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
Eric Nelson988ad422012-09-23 07:30:54 +0000549
Anatolij Gustschin3e7ad7d2017-09-04 23:33:45 +0200550 if (!ipu_clk_enabled())
551 return;
552
Eric Nelson988ad422012-09-23 07:30:54 +0000553 for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
554 struct fb_info *fbi = mxcfb_info[i];
555 if (fbi) {
556 struct mxcfb_info *mxc_fbi = fbi->par;
557 ipu_disable_channel(mxc_fbi->ipu_ch);
558 ipu_uninit_channel(mxc_fbi->ipu_ch);
559 }
560 }
561 for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
562 __raw_writel(__raw_readl(&stat->int_stat[i]),
563 &stat->int_stat[i]);
564 }
565}
Stefano Babic42f151a2010-10-13 12:17:14 +0200566
Eric Nelson10a6cd12012-10-03 07:27:38 +0000567int ipuv3_fb_init(struct fb_videomode const *mode,
568 uint8_t disp,
569 uint32_t pixfmt)
Stefano Babic61852442011-09-28 11:21:15 +0200570{
571 gmode = mode;
Marek Vasutff5c108c2011-10-06 00:25:03 +0200572 gdisp = disp;
573 gpixfmt = pixfmt;
Stefano Babic61852442011-09-28 11:21:15 +0200574
575 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200576}
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100577
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100578enum {
579 /* Maximum display size we support */
580 LCD_MAX_WIDTH = 1920,
581 LCD_MAX_HEIGHT = 1080,
582 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
583};
584
585static int ipuv3_video_probe(struct udevice *dev)
586{
Simon Glassb75b15b2020-12-03 16:55:23 -0700587 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100588 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Heiko Schocher3c787842019-07-22 06:49:07 +0200589#if defined(CONFIG_DISPLAY)
590 struct udevice *disp_dev;
591#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100592 u32 fb_start, fb_end;
593 int ret;
594
595 debug("%s() plat: base 0x%lx, size 0x%x\n",
596 __func__, plat->base, plat->size);
597
598 ret = ipu_probe();
599 if (ret)
600 return ret;
601
602 ret = ipu_displays_init();
603 if (ret < 0)
604 return ret;
605
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200606 ret = mxcfb_probe(dev, gpixfmt, gdisp, gmode);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100607 if (ret < 0)
608 return ret;
609
Heiko Schocher3c787842019-07-22 06:49:07 +0200610#if defined(CONFIG_DISPLAY)
Michal Suchanekb9813e22022-10-12 21:57:56 +0200611 ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev);
612 if (!ret)
Heiko Schocher3c787842019-07-22 06:49:07 +0200613 ret = display_enable(disp_dev, 16, NULL);
Michal Suchanekb9813e22022-10-12 21:57:56 +0200614 if (ret < 0)
615 return ret;
Heiko Schocher3c787842019-07-22 06:49:07 +0200616#endif
Simon Glass6fd44e62023-02-05 17:54:44 -0700617 if (IS_ENABLED(CONFIG_PANEL)) {
Anatolij Gustschin00878362020-05-26 00:09:22 +0200618 struct udevice *panel_dev;
619
620 ret = uclass_get_device(UCLASS_PANEL, 0, &panel_dev);
621 if (panel_dev)
622 panel_enable_backlight(panel_dev);
623 }
Heiko Schocher3c787842019-07-22 06:49:07 +0200624
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100625 uc_priv->xsize = gmode->xres;
626 uc_priv->ysize = gmode->yres;
627 uc_priv->bpix = LCD_MAX_LOG2_BPP;
628
629 /* Enable dcache for the frame buffer */
630 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
631 fb_end = plat->base + plat->size;
632 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
633 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
634 DCACHE_WRITEBACK);
635 video_set_flush_dcache(dev, true);
Heiko Schocherabb59422019-07-22 06:49:05 +0200636 gd->fb_base = fb_start;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100637
638 return 0;
639}
640
641struct ipuv3_video_priv {
642 ulong regs;
643};
644
645static int ipuv3_video_bind(struct udevice *dev)
646{
Simon Glassb75b15b2020-12-03 16:55:23 -0700647 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100648
649 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
Marek Vasut28bdd932019-05-06 01:11:32 +0200650 (1 << VIDEO_BPP32) / 8;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100651
652 return 0;
653}
654
655static const struct udevice_id ipuv3_video_ids[] = {
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200656#ifdef CONFIG_ARCH_MX6
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100657 { .compatible = "fsl,imx6q-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200658#endif
659#ifdef CONFIG_ARCH_MX5
Steffen Dirkwinkel4e40f1a2019-04-17 13:57:15 +0200660 { .compatible = "fsl,imx53-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200661#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100662 { }
663};
664
Walter Lozano35f61872020-07-29 12:31:20 -0300665U_BOOT_DRIVER(fsl_imx6q_ipu) = {
666 .name = "fsl_imx6q_ipu",
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100667 .id = UCLASS_VIDEO,
668 .of_match = ipuv3_video_ids,
669 .bind = ipuv3_video_bind,
670 .probe = ipuv3_video_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700671 .priv_auto = sizeof(struct ipuv3_video_priv),
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100672 .flags = DM_FLAG_PRE_RELOC,
673};