blob: 8b01a1be1129c7835f5b140c2b6453bcbc5ce6cb [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 Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass655306c2020-05-10 11:39:58 -060015#include <part.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <asm/cache.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090017#include <linux/errno.h>
Eric Nelsonc9e2be62014-04-29 14:37:56 -070018#include <asm/global_data.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020019#include <linux/string.h>
20#include <linux/list.h>
21#include <linux/fb.h>
22#include <asm/io.h>
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +010023#include <asm/mach-imx/video.h>
Stefano Babic42f151a2010-10-13 12:17:14 +020024#include <malloc.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
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 {
Anatolij Gustschin76057ba2020-08-03 15:45:33 +020068 struct udevice *udev;
Stefano Babic42f151a2010-10-13 12:17:14 +020069 int blank;
70 ipu_channel_t ipu_ch;
71 int ipu_di;
72 u32 ipu_di_pix_fmt;
73 unsigned char overlay;
74 unsigned char alpha_chan_en;
75 dma_addr_t alpha_phy_addr0;
76 dma_addr_t alpha_phy_addr1;
77 void *alpha_virt_addr0;
78 void *alpha_virt_addr1;
79 uint32_t alpha_mem_len;
80 uint32_t cur_ipu_buf;
81 uint32_t cur_ipu_alpha_buf;
82
83 u32 pseudo_palette[16];
84};
85
86enum {
87 BOTH_ON,
88 SRC_ON,
89 TGT_ON,
90 BOTH_OFF
91};
92
93static unsigned long default_bpp = 16;
94static unsigned char g_dp_in_use;
95static struct fb_info *mxcfb_info[3];
96static int ext_clk_used;
97
98static uint32_t bpp_to_pixfmt(struct fb_info *fbi)
99{
100 uint32_t pixfmt = 0;
101
102 debug("bpp_to_pixfmt: %d\n", fbi->var.bits_per_pixel);
103
104 if (fbi->var.nonstd)
105 return fbi->var.nonstd;
106
107 switch (fbi->var.bits_per_pixel) {
108 case 24:
109 pixfmt = IPU_PIX_FMT_BGR24;
110 break;
111 case 32:
112 pixfmt = IPU_PIX_FMT_BGR32;
113 break;
114 case 16:
115 pixfmt = IPU_PIX_FMT_RGB565;
116 break;
117 }
118 return pixfmt;
119}
120
Stefano Babic42f151a2010-10-13 12:17:14 +0200121static int setup_disp_channel1(struct fb_info *fbi)
122{
123 ipu_channel_params_t params;
124 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
125
126 memset(&params, 0, sizeof(params));
127 params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
128
129 debug("%s called\n", __func__);
130 /*
131 * Assuming interlaced means yuv output, below setting also
132 * valid for mem_dc_sync. FG should have the same vmode as BG.
133 */
134 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
135 params.mem_dp_bg_sync.interlaced = 1;
136 params.mem_dp_bg_sync.out_pixel_fmt =
137 IPU_PIX_FMT_YUV444;
138 } else {
139 if (mxc_fbi->ipu_di_pix_fmt) {
140 params.mem_dp_bg_sync.out_pixel_fmt =
141 mxc_fbi->ipu_di_pix_fmt;
142 } else {
143 params.mem_dp_bg_sync.out_pixel_fmt =
144 IPU_PIX_FMT_RGB666;
145 }
146 }
147 params.mem_dp_bg_sync.in_pixel_fmt = bpp_to_pixfmt(fbi);
148 if (mxc_fbi->alpha_chan_en)
149 params.mem_dp_bg_sync.alpha_chan_en = 1;
150
151 ipu_init_channel(mxc_fbi->ipu_ch, &params);
152
153 return 0;
154}
155
156static int setup_disp_channel2(struct fb_info *fbi)
157{
158 int retval = 0;
159 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
160
161 mxc_fbi->cur_ipu_buf = 1;
162 if (mxc_fbi->alpha_chan_en)
163 mxc_fbi->cur_ipu_alpha_buf = 1;
164
165 fbi->var.xoffset = fbi->var.yoffset = 0;
166
167 debug("%s: %x %d %d %d %lx %lx\n",
168 __func__,
169 mxc_fbi->ipu_ch,
170 fbi->var.xres,
171 fbi->var.yres,
172 fbi->fix.line_length,
173 fbi->fix.smem_start,
174 fbi->fix.smem_start +
175 (fbi->fix.line_length * fbi->var.yres));
176
177 retval = ipu_init_channel_buffer(mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
178 bpp_to_pixfmt(fbi),
179 fbi->var.xres, fbi->var.yres,
180 fbi->fix.line_length,
181 fbi->fix.smem_start +
182 (fbi->fix.line_length * fbi->var.yres),
183 fbi->fix.smem_start,
184 0, 0);
185 if (retval)
186 printf("ipu_init_channel_buffer error %d\n", retval);
187
188 return retval;
189}
190
191/*
192 * Set framebuffer parameters and change the operating mode.
193 *
194 * @param info framebuffer information pointer
195 */
196static int mxcfb_set_par(struct fb_info *fbi)
197{
198 int retval = 0;
199 u32 mem_len;
200 ipu_di_signal_cfg_t sig_cfg;
201 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
202 uint32_t out_pixel_fmt;
203
204 ipu_disable_channel(mxc_fbi->ipu_ch);
205 ipu_uninit_channel(mxc_fbi->ipu_ch);
Stefano Babic42f151a2010-10-13 12:17:14 +0200206
207 mem_len = fbi->var.yres_virtual * fbi->fix.line_length;
208 if (!fbi->fix.smem_start || (mem_len > fbi->fix.smem_len)) {
209 if (fbi->fix.smem_start)
210 mxcfb_unmap_video_memory(fbi);
211
212 if (mxcfb_map_video_memory(fbi) < 0)
213 return -ENOMEM;
214 }
215
216 setup_disp_channel1(fbi);
217
218 memset(&sig_cfg, 0, sizeof(sig_cfg));
219 if (fbi->var.vmode & FB_VMODE_INTERLACED) {
220 sig_cfg.interlaced = 1;
221 out_pixel_fmt = IPU_PIX_FMT_YUV444;
222 } else {
223 if (mxc_fbi->ipu_di_pix_fmt)
224 out_pixel_fmt = mxc_fbi->ipu_di_pix_fmt;
225 else
226 out_pixel_fmt = IPU_PIX_FMT_RGB666;
227 }
228 if (fbi->var.vmode & FB_VMODE_ODD_FLD_FIRST) /* PAL */
229 sig_cfg.odd_field_first = 1;
230 if ((fbi->var.sync & FB_SYNC_EXT) || ext_clk_used)
231 sig_cfg.ext_clk = 1;
232 if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
233 sig_cfg.Hsync_pol = 1;
234 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
235 sig_cfg.Vsync_pol = 1;
236 if (!(fbi->var.sync & FB_SYNC_CLK_LAT_FALL))
237 sig_cfg.clk_pol = 1;
238 if (fbi->var.sync & FB_SYNC_DATA_INVERT)
239 sig_cfg.data_pol = 1;
240 if (!(fbi->var.sync & FB_SYNC_OE_LOW_ACT))
241 sig_cfg.enable_pol = 1;
242 if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
243 sig_cfg.clkidle_en = 1;
244
Jeroen Hofstee98276212014-10-14 20:37:14 +0200245 debug("pixclock = %lu Hz\n", PICOS2KHZ(fbi->var.pixclock) * 1000UL);
Stefano Babic42f151a2010-10-13 12:17:14 +0200246
247 if (ipu_init_sync_panel(mxc_fbi->ipu_di,
248 (PICOS2KHZ(fbi->var.pixclock)) * 1000UL,
249 fbi->var.xres, fbi->var.yres,
250 out_pixel_fmt,
251 fbi->var.left_margin,
252 fbi->var.hsync_len,
253 fbi->var.right_margin,
254 fbi->var.upper_margin,
255 fbi->var.vsync_len,
256 fbi->var.lower_margin,
257 0, sig_cfg) != 0) {
258 puts("mxcfb: Error initializing panel.\n");
259 return -EINVAL;
260 }
261
262 retval = setup_disp_channel2(fbi);
263 if (retval)
264 return retval;
265
266 if (mxc_fbi->blank == FB_BLANK_UNBLANK)
267 ipu_enable_channel(mxc_fbi->ipu_ch);
268
269 return retval;
270}
271
272/*
273 * Check framebuffer variable parameters and adjust to valid values.
274 *
275 * @param var framebuffer variable parameters
276 *
277 * @param info framebuffer information pointer
278 */
279static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
280{
281 u32 vtotal;
282 u32 htotal;
283
284 if (var->xres_virtual < var->xres)
285 var->xres_virtual = var->xres;
286 if (var->yres_virtual < var->yres)
287 var->yres_virtual = var->yres;
288
289 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
290 (var->bits_per_pixel != 16) && (var->bits_per_pixel != 8))
291 var->bits_per_pixel = default_bpp;
292
293 switch (var->bits_per_pixel) {
294 case 8:
295 var->red.length = 3;
296 var->red.offset = 5;
297 var->red.msb_right = 0;
298
299 var->green.length = 3;
300 var->green.offset = 2;
301 var->green.msb_right = 0;
302
303 var->blue.length = 2;
304 var->blue.offset = 0;
305 var->blue.msb_right = 0;
306
307 var->transp.length = 0;
308 var->transp.offset = 0;
309 var->transp.msb_right = 0;
310 break;
311 case 16:
312 var->red.length = 5;
313 var->red.offset = 11;
314 var->red.msb_right = 0;
315
316 var->green.length = 6;
317 var->green.offset = 5;
318 var->green.msb_right = 0;
319
320 var->blue.length = 5;
321 var->blue.offset = 0;
322 var->blue.msb_right = 0;
323
324 var->transp.length = 0;
325 var->transp.offset = 0;
326 var->transp.msb_right = 0;
327 break;
328 case 24:
329 var->red.length = 8;
330 var->red.offset = 16;
331 var->red.msb_right = 0;
332
333 var->green.length = 8;
334 var->green.offset = 8;
335 var->green.msb_right = 0;
336
337 var->blue.length = 8;
338 var->blue.offset = 0;
339 var->blue.msb_right = 0;
340
341 var->transp.length = 0;
342 var->transp.offset = 0;
343 var->transp.msb_right = 0;
344 break;
345 case 32:
346 var->red.length = 8;
347 var->red.offset = 16;
348 var->red.msb_right = 0;
349
350 var->green.length = 8;
351 var->green.offset = 8;
352 var->green.msb_right = 0;
353
354 var->blue.length = 8;
355 var->blue.offset = 0;
356 var->blue.msb_right = 0;
357
358 var->transp.length = 8;
359 var->transp.offset = 24;
360 var->transp.msb_right = 0;
361 break;
362 }
363
364 if (var->pixclock < 1000) {
365 htotal = var->xres + var->right_margin + var->hsync_len +
366 var->left_margin;
367 vtotal = var->yres + var->lower_margin + var->vsync_len +
368 var->upper_margin;
369 var->pixclock = (vtotal * htotal * 6UL) / 100UL;
370 var->pixclock = KHZ2PICOS(var->pixclock);
371 printf("pixclock set for 60Hz refresh = %u ps\n",
372 var->pixclock);
373 }
374
375 var->height = -1;
376 var->width = -1;
377 var->grayscale = 0;
378
379 return 0;
380}
381
382static int mxcfb_map_video_memory(struct fb_info *fbi)
383{
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200384 struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
Simon Glassb75b15b2020-12-03 16:55:23 -0700385 struct video_uc_plat *plat = dev_get_uclass_plat(mxc_fbi->udev);
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200386
Stefano Babic42f151a2010-10-13 12:17:14 +0200387 if (fbi->fix.smem_len < fbi->var.yres_virtual * fbi->fix.line_length) {
388 fbi->fix.smem_len = fbi->var.yres_virtual *
389 fbi->fix.line_length;
390 }
Eric Nelsonfe6296f2013-07-26 17:53:45 -0700391 fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100392
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200393 fbi->screen_base = (char *)plat->base;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100394
Stefano Babic61852442011-09-28 11:21:15 +0200395 fbi->fix.smem_start = (unsigned long)fbi->screen_base;
Stefano Babic42f151a2010-10-13 12:17:14 +0200396 if (fbi->screen_base == 0) {
397 puts("Unable to allocate framebuffer memory\n");
398 fbi->fix.smem_len = 0;
399 fbi->fix.smem_start = 0;
400 return -EBUSY;
401 }
402
403 debug("allocated fb @ paddr=0x%08X, size=%d.\n",
404 (uint32_t) fbi->fix.smem_start, fbi->fix.smem_len);
405
406 fbi->screen_size = fbi->fix.smem_len;
Eric Nelsonc9e2be62014-04-29 14:37:56 -0700407 gd->fb_base = fbi->fix.smem_start;
408
Stefano Babic42f151a2010-10-13 12:17:14 +0200409 /* Clear the screen */
410 memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
411
412 return 0;
413}
414
415static int mxcfb_unmap_video_memory(struct fb_info *fbi)
416{
417 fbi->screen_base = 0;
418 fbi->fix.smem_start = 0;
419 fbi->fix.smem_len = 0;
420 return 0;
421}
422
423/*
424 * Initializes the framebuffer information pointer. After allocating
425 * sufficient memory for the framebuffer structure, the fields are
426 * filled with custom information passed in from the configurable
427 * structures. This includes information such as bits per pixel,
428 * color maps, screen width/height and RGBA offsets.
429 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100430 * Return: Framebuffer structure initialized with our information
Stefano Babic42f151a2010-10-13 12:17:14 +0200431 */
432static struct fb_info *mxcfb_init_fbinfo(void)
433{
434#define BYTES_PER_LONG 4
435#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
436 struct fb_info *fbi;
437 struct mxcfb_info *mxcfbi;
438 char *p;
439 int size = sizeof(struct mxcfb_info) + PADDING +
440 sizeof(struct fb_info);
441
442 debug("%s: %d %d %d %d\n",
443 __func__,
444 PADDING,
445 size,
446 sizeof(struct mxcfb_info),
447 sizeof(struct fb_info));
448 /*
449 * Allocate sufficient memory for the fb structure
450 */
451
452 p = malloc(size);
453 if (!p)
454 return NULL;
455
456 memset(p, 0, size);
457
458 fbi = (struct fb_info *)p;
459 fbi->par = p + sizeof(struct fb_info) + PADDING;
460
461 mxcfbi = (struct mxcfb_info *)fbi->par;
462 debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
463 (unsigned int)fbi, (unsigned int)mxcfbi);
464
465 fbi->var.activate = FB_ACTIVATE_NOW;
466
467 fbi->flags = FBINFO_FLAG_DEFAULT;
468 fbi->pseudo_palette = mxcfbi->pseudo_palette;
469
470 return fbi;
471}
472
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200473extern struct clk *g_ipu_clk;
474
Stefano Babic42f151a2010-10-13 12:17:14 +0200475/*
476 * Probe routine for the framebuffer driver. It is called during the
Jeroen Hofstee98276212014-10-14 20:37:14 +0200477 * driver binding process. The following functions are performed in
Stefano Babic42f151a2010-10-13 12:17:14 +0200478 * this routine: Framebuffer initialization, Memory allocation and
479 * mapping, Framebuffer registration, IPU initialization.
480 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100481 * Return: Appropriate error code to the kernel common code
Stefano Babic42f151a2010-10-13 12:17:14 +0200482 */
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200483static int mxcfb_probe(struct udevice *dev, u32 interface_pix_fmt,
484 uint8_t disp, struct fb_videomode const *mode)
Stefano Babic42f151a2010-10-13 12:17:14 +0200485{
486 struct fb_info *fbi;
487 struct mxcfb_info *mxcfbi;
Stefano Babic42f151a2010-10-13 12:17:14 +0200488
489 /*
490 * Initialize FB structures
491 */
492 fbi = mxcfb_init_fbinfo();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200493 if (!fbi)
494 return -ENOMEM;
495
Stefano Babic42f151a2010-10-13 12:17:14 +0200496 mxcfbi = (struct mxcfb_info *)fbi->par;
497
498 if (!g_dp_in_use) {
499 mxcfbi->ipu_ch = MEM_BG_SYNC;
500 mxcfbi->blank = FB_BLANK_UNBLANK;
501 } else {
502 mxcfbi->ipu_ch = MEM_DC_SYNC;
503 mxcfbi->blank = FB_BLANK_POWERDOWN;
504 }
505
Marek Vasutff5c108c2011-10-06 00:25:03 +0200506 mxcfbi->ipu_di = disp;
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200507 mxcfbi->udev = dev;
Stefano Babic42f151a2010-10-13 12:17:14 +0200508
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200509 if (!ipu_clk_enabled())
510 clk_enable(g_ipu_clk);
511
Stefano Babic42f151a2010-10-13 12:17:14 +0200512 ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
513 ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
Stefano Babic42f151a2010-10-13 12:17:14 +0200514
515 g_dp_in_use = 1;
516
517 mxcfb_info[mxcfbi->ipu_di] = fbi;
518
519 /* Need dummy values until real panel is configured */
Stefano Babic42f151a2010-10-13 12:17:14 +0200520
521 mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
522 fb_videomode_to_var(&fbi->var, mode);
Stefano Babic61852442011-09-28 11:21:15 +0200523 fbi->var.bits_per_pixel = 16;
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200524 fbi->fix.line_length = fbi->var.xres_virtual *
525 (fbi->var.bits_per_pixel / 8);
Stefano Babic61852442011-09-28 11:21:15 +0200526 fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
Stefano Babic42f151a2010-10-13 12:17:14 +0200527
528 mxcfb_check_var(&fbi->var, fbi);
529
530 /* Default Y virtual size is 2x panel size */
531 fbi->var.yres_virtual = fbi->var.yres * 2;
532
Jeroen Hofstee98276212014-10-14 20:37:14 +0200533 /* allocate fb first */
Stefano Babic42f151a2010-10-13 12:17:14 +0200534 if (mxcfb_map_video_memory(fbi) < 0)
535 return -ENOMEM;
536
537 mxcfb_set_par(fbi);
538
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200539#ifdef DEBUG
Stefano Babic42f151a2010-10-13 12:17:14 +0200540 ipu_dump_registers();
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200541#endif
Stefano Babic42f151a2010-10-13 12:17:14 +0200542
543 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200544}
545
Eric Nelson988ad422012-09-23 07:30:54 +0000546void ipuv3_fb_shutdown(void)
547{
Anatolij Gustschinfa4211c2017-08-25 15:10:43 +0200548 int i;
Tom Rini47dce762017-09-01 16:17:17 -0400549 struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
Eric Nelson988ad422012-09-23 07:30:54 +0000550
Anatolij Gustschin3e7ad7d2017-09-04 23:33:45 +0200551 if (!ipu_clk_enabled())
552 return;
553
Eric Nelson988ad422012-09-23 07:30:54 +0000554 for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
555 struct fb_info *fbi = mxcfb_info[i];
556 if (fbi) {
557 struct mxcfb_info *mxc_fbi = fbi->par;
558 ipu_disable_channel(mxc_fbi->ipu_ch);
559 ipu_uninit_channel(mxc_fbi->ipu_ch);
560 }
561 }
562 for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
563 __raw_writel(__raw_readl(&stat->int_stat[i]),
564 &stat->int_stat[i]);
565 }
566}
Stefano Babic42f151a2010-10-13 12:17:14 +0200567
Eric Nelson10a6cd12012-10-03 07:27:38 +0000568int ipuv3_fb_init(struct fb_videomode const *mode,
569 uint8_t disp,
570 uint32_t pixfmt)
Stefano Babic61852442011-09-28 11:21:15 +0200571{
572 gmode = mode;
Marek Vasutff5c108c2011-10-06 00:25:03 +0200573 gdisp = disp;
574 gpixfmt = pixfmt;
Stefano Babic61852442011-09-28 11:21:15 +0200575
576 return 0;
Stefano Babic42f151a2010-10-13 12:17:14 +0200577}
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100578
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100579enum {
580 /* Maximum display size we support */
581 LCD_MAX_WIDTH = 1920,
582 LCD_MAX_HEIGHT = 1080,
583 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
584};
585
586static int ipuv3_video_probe(struct udevice *dev)
587{
Simon Glassb75b15b2020-12-03 16:55:23 -0700588 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100589 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Heiko Schocher3c787842019-07-22 06:49:07 +0200590#if defined(CONFIG_DISPLAY)
591 struct udevice *disp_dev;
592#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100593 u32 fb_start, fb_end;
594 int ret;
595
596 debug("%s() plat: base 0x%lx, size 0x%x\n",
597 __func__, plat->base, plat->size);
598
599 ret = ipu_probe();
600 if (ret)
601 return ret;
602
603 ret = ipu_displays_init();
604 if (ret < 0)
605 return ret;
606
Anatolij Gustschin76057ba2020-08-03 15:45:33 +0200607 ret = mxcfb_probe(dev, gpixfmt, gdisp, gmode);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100608 if (ret < 0)
609 return ret;
610
Heiko Schocher3c787842019-07-22 06:49:07 +0200611#if defined(CONFIG_DISPLAY)
Michal Suchanekb9813e22022-10-12 21:57:56 +0200612 ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev);
613 if (!ret)
Heiko Schocher3c787842019-07-22 06:49:07 +0200614 ret = display_enable(disp_dev, 16, NULL);
Michal Suchanekb9813e22022-10-12 21:57:56 +0200615 if (ret < 0)
616 return ret;
Heiko Schocher3c787842019-07-22 06:49:07 +0200617#endif
Anatolij Gustschin00878362020-05-26 00:09:22 +0200618 if (CONFIG_IS_ENABLED(PANEL)) {
619 struct udevice *panel_dev;
620
621 ret = uclass_get_device(UCLASS_PANEL, 0, &panel_dev);
622 if (panel_dev)
623 panel_enable_backlight(panel_dev);
624 }
Heiko Schocher3c787842019-07-22 06:49:07 +0200625
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100626 uc_priv->xsize = gmode->xres;
627 uc_priv->ysize = gmode->yres;
628 uc_priv->bpix = LCD_MAX_LOG2_BPP;
629
630 /* Enable dcache for the frame buffer */
631 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
632 fb_end = plat->base + plat->size;
633 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
634 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
635 DCACHE_WRITEBACK);
636 video_set_flush_dcache(dev, true);
Heiko Schocherabb59422019-07-22 06:49:05 +0200637 gd->fb_base = fb_start;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100638
639 return 0;
640}
641
642struct ipuv3_video_priv {
643 ulong regs;
644};
645
646static int ipuv3_video_bind(struct udevice *dev)
647{
Simon Glassb75b15b2020-12-03 16:55:23 -0700648 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100649
650 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
Marek Vasut28bdd932019-05-06 01:11:32 +0200651 (1 << VIDEO_BPP32) / 8;
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100652
653 return 0;
654}
655
656static const struct udevice_id ipuv3_video_ids[] = {
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200657#ifdef CONFIG_ARCH_MX6
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100658 { .compatible = "fsl,imx6q-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200659#endif
660#ifdef CONFIG_ARCH_MX5
Steffen Dirkwinkel4e40f1a2019-04-17 13:57:15 +0200661 { .compatible = "fsl,imx53-ipu" },
Anatolij Gustschin8329ce32020-05-25 14:34:17 +0200662#endif
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100663 { }
664};
665
Walter Lozano35f61872020-07-29 12:31:20 -0300666U_BOOT_DRIVER(fsl_imx6q_ipu) = {
667 .name = "fsl_imx6q_ipu",
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100668 .id = UCLASS_VIDEO,
669 .of_match = ipuv3_video_ids,
670 .bind = ipuv3_video_bind,
671 .probe = ipuv3_video_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700672 .priv_auto = sizeof(struct ipuv3_video_priv),
Anatolij Gustschin983e2f2a2019-03-18 23:29:31 +0100673 .flags = DM_FLAG_PRE_RELOC,
674};