Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 2 | /* |
| 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <part.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <asm/cache.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 16 | #include <linux/errno.h> |
Eric Nelson | c9e2be6 | 2014-04-29 14:37:56 -0700 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 18 | #include <linux/string.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/fb.h> |
| 21 | #include <asm/io.h> |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 22 | #include <asm/mach-imx/video.h> |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 23 | #include <malloc.h> |
Anatolij Gustschin | 411e73d | 2019-03-18 23:29:32 +0100 | [diff] [blame] | 24 | #include "../videomodes.h" |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 25 | #include "ipu.h" |
| 26 | #include "mxcfb.h" |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 27 | #include "ipu_regs.h" |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 28 | #include "display.h" |
Heiko Schocher | 92afc9b | 2019-07-22 06:49:08 +0200 | [diff] [blame] | 29 | #include <panel.h> |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 30 | |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 31 | #include <dm.h> |
| 32 | #include <video.h> |
| 33 | |
Eric Nelson | c9e2be6 | 2014-04-29 14:37:56 -0700 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 36 | static int mxcfb_map_video_memory(struct fb_info *fbi); |
| 37 | static int mxcfb_unmap_video_memory(struct fb_info *fbi); |
| 38 | |
Eric Nelson | 10a6cd1 | 2012-10-03 07:27:38 +0000 | [diff] [blame] | 39 | static struct fb_videomode const *gmode; |
Marek Vasut | ff5c108c | 2011-10-06 00:25:03 +0200 | [diff] [blame] | 40 | static uint8_t gdisp; |
| 41 | static uint32_t gpixfmt; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 42 | |
Jeroen Hofstee | a175d30 | 2014-10-08 22:57:47 +0200 | [diff] [blame] | 43 | static void fb_videomode_to_var(struct fb_var_screeninfo *var, |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 44 | 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 | */ |
| 66 | struct mxcfb_info { |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 67 | struct udevice *udev; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 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 | |
| 85 | enum { |
| 86 | BOTH_ON, |
| 87 | SRC_ON, |
| 88 | TGT_ON, |
| 89 | BOTH_OFF |
| 90 | }; |
| 91 | |
| 92 | static unsigned long default_bpp = 16; |
| 93 | static unsigned char g_dp_in_use; |
| 94 | static struct fb_info *mxcfb_info[3]; |
| 95 | static int ext_clk_used; |
| 96 | |
| 97 | static 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 120 | static 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(¶ms, 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, ¶ms); |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static 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 | */ |
| 195 | static 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 205 | |
| 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 Hofstee | 9827621 | 2014-10-14 20:37:14 +0200 | [diff] [blame] | 244 | debug("pixclock = %lu Hz\n", PICOS2KHZ(fbi->var.pixclock) * 1000UL); |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 245 | |
| 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 | */ |
| 278 | static 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 | |
| 381 | static int mxcfb_map_video_memory(struct fb_info *fbi) |
| 382 | { |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 383 | struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 384 | struct video_uc_plat *plat = dev_get_uclass_plat(mxc_fbi->udev); |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 385 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 386 | 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 Nelson | fe6296f | 2013-07-26 17:53:45 -0700 | [diff] [blame] | 390 | fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 391 | |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 392 | fbi->screen_base = (char *)plat->base; |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 393 | |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 394 | fbi->fix.smem_start = (unsigned long)fbi->screen_base; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 395 | 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 Nelson | c9e2be6 | 2014-04-29 14:37:56 -0700 | [diff] [blame] | 406 | gd->fb_base = fbi->fix.smem_start; |
| 407 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 408 | /* Clear the screen */ |
| 409 | memset((char *)fbi->screen_base, 0, fbi->fix.smem_len); |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 429 | * Return: Framebuffer structure initialized with our information |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 430 | */ |
| 431 | static 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 Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 472 | extern struct clk *g_ipu_clk; |
| 473 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 474 | /* |
| 475 | * Probe routine for the framebuffer driver. It is called during the |
Jeroen Hofstee | 9827621 | 2014-10-14 20:37:14 +0200 | [diff] [blame] | 476 | * driver binding process. The following functions are performed in |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 477 | * this routine: Framebuffer initialization, Memory allocation and |
| 478 | * mapping, Framebuffer registration, IPU initialization. |
| 479 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 480 | * Return: Appropriate error code to the kernel common code |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 481 | */ |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 482 | static int mxcfb_probe(struct udevice *dev, u32 interface_pix_fmt, |
| 483 | uint8_t disp, struct fb_videomode const *mode) |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 484 | { |
| 485 | struct fb_info *fbi; |
| 486 | struct mxcfb_info *mxcfbi; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 487 | |
| 488 | /* |
| 489 | * Initialize FB structures |
| 490 | */ |
| 491 | fbi = mxcfb_init_fbinfo(); |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 492 | if (!fbi) |
| 493 | return -ENOMEM; |
| 494 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 495 | 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 Vasut | ff5c108c | 2011-10-06 00:25:03 +0200 | [diff] [blame] | 505 | mxcfbi->ipu_di = disp; |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 506 | mxcfbi->udev = dev; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 507 | |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 508 | if (!ipu_clk_enabled()) |
| 509 | clk_enable(g_ipu_clk); |
| 510 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 511 | ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80); |
| 512 | ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0); |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 513 | |
| 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 519 | |
| 520 | mxcfbi->ipu_di_pix_fmt = interface_pix_fmt; |
| 521 | fb_videomode_to_var(&fbi->var, mode); |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 522 | fbi->var.bits_per_pixel = 16; |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 523 | fbi->fix.line_length = fbi->var.xres_virtual * |
| 524 | (fbi->var.bits_per_pixel / 8); |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 525 | fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 526 | |
| 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 Hofstee | 9827621 | 2014-10-14 20:37:14 +0200 | [diff] [blame] | 532 | /* allocate fb first */ |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 533 | if (mxcfb_map_video_memory(fbi) < 0) |
| 534 | return -ENOMEM; |
| 535 | |
| 536 | mxcfb_set_par(fbi); |
| 537 | |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 538 | #ifdef DEBUG |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 539 | ipu_dump_registers(); |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 540 | #endif |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 541 | |
| 542 | return 0; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 543 | } |
| 544 | |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 545 | void ipuv3_fb_shutdown(void) |
| 546 | { |
Anatolij Gustschin | fa4211c | 2017-08-25 15:10:43 +0200 | [diff] [blame] | 547 | int i; |
Tom Rini | 47dce76 | 2017-09-01 16:17:17 -0400 | [diff] [blame] | 548 | struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT; |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 549 | |
Anatolij Gustschin | 3e7ad7d | 2017-09-04 23:33:45 +0200 | [diff] [blame] | 550 | if (!ipu_clk_enabled()) |
| 551 | return; |
| 552 | |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 553 | 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 566 | |
Eric Nelson | 10a6cd1 | 2012-10-03 07:27:38 +0000 | [diff] [blame] | 567 | int ipuv3_fb_init(struct fb_videomode const *mode, |
| 568 | uint8_t disp, |
| 569 | uint32_t pixfmt) |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 570 | { |
| 571 | gmode = mode; |
Marek Vasut | ff5c108c | 2011-10-06 00:25:03 +0200 | [diff] [blame] | 572 | gdisp = disp; |
| 573 | gpixfmt = pixfmt; |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 574 | |
| 575 | return 0; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 576 | } |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 577 | |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 578 | enum { |
| 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 | |
| 585 | static int ipuv3_video_probe(struct udevice *dev) |
| 586 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 587 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 588 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 589 | #if defined(CONFIG_DISPLAY) |
| 590 | struct udevice *disp_dev; |
| 591 | #endif |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 592 | 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 Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 606 | ret = mxcfb_probe(dev, gpixfmt, gdisp, gmode); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 607 | if (ret < 0) |
| 608 | return ret; |
| 609 | |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 610 | #if defined(CONFIG_DISPLAY) |
Michal Suchanek | b9813e2 | 2022-10-12 21:57:56 +0200 | [diff] [blame] | 611 | ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev); |
| 612 | if (!ret) |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 613 | ret = display_enable(disp_dev, 16, NULL); |
Michal Suchanek | b9813e2 | 2022-10-12 21:57:56 +0200 | [diff] [blame] | 614 | if (ret < 0) |
| 615 | return ret; |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 616 | #endif |
Simon Glass | 6fd44e6 | 2023-02-05 17:54:44 -0700 | [diff] [blame] | 617 | if (IS_ENABLED(CONFIG_PANEL)) { |
Anatolij Gustschin | 0087836 | 2020-05-26 00:09:22 +0200 | [diff] [blame] | 618 | 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 Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 624 | |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 625 | 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 Schocher | abb5942 | 2019-07-22 06:49:05 +0200 | [diff] [blame] | 636 | gd->fb_base = fb_start; |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | struct ipuv3_video_priv { |
| 642 | ulong regs; |
| 643 | }; |
| 644 | |
| 645 | static int ipuv3_video_bind(struct udevice *dev) |
| 646 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 647 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 648 | |
| 649 | plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT * |
Marek Vasut | 28bdd93 | 2019-05-06 01:11:32 +0200 | [diff] [blame] | 650 | (1 << VIDEO_BPP32) / 8; |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static const struct udevice_id ipuv3_video_ids[] = { |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 656 | #ifdef CONFIG_ARCH_MX6 |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 657 | { .compatible = "fsl,imx6q-ipu" }, |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 658 | #endif |
| 659 | #ifdef CONFIG_ARCH_MX5 |
Steffen Dirkwinkel | 4e40f1a | 2019-04-17 13:57:15 +0200 | [diff] [blame] | 660 | { .compatible = "fsl,imx53-ipu" }, |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 661 | #endif |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 662 | { } |
| 663 | }; |
| 664 | |
Walter Lozano | 35f6187 | 2020-07-29 12:31:20 -0300 | [diff] [blame] | 665 | U_BOOT_DRIVER(fsl_imx6q_ipu) = { |
| 666 | .name = "fsl_imx6q_ipu", |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 667 | .id = UCLASS_VIDEO, |
| 668 | .of_match = ipuv3_video_ids, |
| 669 | .bind = ipuv3_video_bind, |
| 670 | .probe = ipuv3_video_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 671 | .priv_auto = sizeof(struct ipuv3_video_priv), |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 672 | .flags = DM_FLAG_PRE_RELOC, |
| 673 | }; |