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 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 407 | /* Clear the screen */ |
| 408 | memset((char *)fbi->screen_base, 0, fbi->fix.smem_len); |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 428 | * Return: Framebuffer structure initialized with our information |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 429 | */ |
| 430 | static 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 Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 471 | extern struct clk *g_ipu_clk; |
| 472 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 473 | /* |
| 474 | * Probe routine for the framebuffer driver. It is called during the |
Jeroen Hofstee | 9827621 | 2014-10-14 20:37:14 +0200 | [diff] [blame] | 475 | * driver binding process. The following functions are performed in |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 476 | * this routine: Framebuffer initialization, Memory allocation and |
| 477 | * mapping, Framebuffer registration, IPU initialization. |
| 478 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 479 | * Return: Appropriate error code to the kernel common code |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 480 | */ |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 481 | static int mxcfb_probe(struct udevice *dev, u32 interface_pix_fmt, |
| 482 | uint8_t disp, struct fb_videomode const *mode) |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 483 | { |
| 484 | struct fb_info *fbi; |
| 485 | struct mxcfb_info *mxcfbi; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * Initialize FB structures |
| 489 | */ |
| 490 | fbi = mxcfb_init_fbinfo(); |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 491 | if (!fbi) |
| 492 | return -ENOMEM; |
| 493 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 494 | 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 Vasut | ff5c108c | 2011-10-06 00:25:03 +0200 | [diff] [blame] | 504 | mxcfbi->ipu_di = disp; |
Anatolij Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 505 | mxcfbi->udev = dev; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 506 | |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 507 | if (!ipu_clk_enabled()) |
| 508 | clk_enable(g_ipu_clk); |
| 509 | |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 510 | ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80); |
| 511 | ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0); |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 512 | |
| 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 518 | |
| 519 | mxcfbi->ipu_di_pix_fmt = interface_pix_fmt; |
| 520 | fb_videomode_to_var(&fbi->var, mode); |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 521 | fbi->var.bits_per_pixel = 16; |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 522 | fbi->fix.line_length = fbi->var.xres_virtual * |
| 523 | (fbi->var.bits_per_pixel / 8); |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 524 | fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 525 | |
| 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 Hofstee | 9827621 | 2014-10-14 20:37:14 +0200 | [diff] [blame] | 531 | /* allocate fb first */ |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 532 | if (mxcfb_map_video_memory(fbi) < 0) |
| 533 | return -ENOMEM; |
| 534 | |
| 535 | mxcfb_set_par(fbi); |
| 536 | |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 537 | #ifdef DEBUG |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 538 | ipu_dump_registers(); |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 539 | #endif |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 540 | |
| 541 | return 0; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 544 | void ipuv3_fb_shutdown(void) |
| 545 | { |
Anatolij Gustschin | fa4211c | 2017-08-25 15:10:43 +0200 | [diff] [blame] | 546 | int i; |
Tom Rini | 47dce76 | 2017-09-01 16:17:17 -0400 | [diff] [blame] | 547 | struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT; |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 548 | |
Anatolij Gustschin | 3e7ad7d | 2017-09-04 23:33:45 +0200 | [diff] [blame] | 549 | if (!ipu_clk_enabled()) |
| 550 | return; |
| 551 | |
Eric Nelson | 988ad42 | 2012-09-23 07:30:54 +0000 | [diff] [blame] | 552 | 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 Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 565 | |
Eric Nelson | 10a6cd1 | 2012-10-03 07:27:38 +0000 | [diff] [blame] | 566 | int ipuv3_fb_init(struct fb_videomode const *mode, |
| 567 | uint8_t disp, |
| 568 | uint32_t pixfmt) |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 569 | { |
| 570 | gmode = mode; |
Marek Vasut | ff5c108c | 2011-10-06 00:25:03 +0200 | [diff] [blame] | 571 | gdisp = disp; |
| 572 | gpixfmt = pixfmt; |
Stefano Babic | 6185244 | 2011-09-28 11:21:15 +0200 | [diff] [blame] | 573 | |
| 574 | return 0; |
Stefano Babic | 42f151a | 2010-10-13 12:17:14 +0200 | [diff] [blame] | 575 | } |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 576 | |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 577 | enum { |
| 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 | |
| 584 | static int ipuv3_video_probe(struct udevice *dev) |
| 585 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 586 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 587 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 588 | #if defined(CONFIG_DISPLAY) |
| 589 | struct udevice *disp_dev; |
| 590 | #endif |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 591 | 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 Gustschin | 76057ba | 2020-08-03 15:45:33 +0200 | [diff] [blame] | 605 | ret = mxcfb_probe(dev, gpixfmt, gdisp, gmode); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 606 | if (ret < 0) |
| 607 | return ret; |
| 608 | |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 609 | #if defined(CONFIG_DISPLAY) |
Michal Suchanek | b9813e2 | 2022-10-12 21:57:56 +0200 | [diff] [blame] | 610 | ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev); |
| 611 | if (!ret) |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 612 | ret = display_enable(disp_dev, 16, NULL); |
Michal Suchanek | b9813e2 | 2022-10-12 21:57:56 +0200 | [diff] [blame] | 613 | if (ret < 0) |
| 614 | return ret; |
Heiko Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 615 | #endif |
Simon Glass | 6fd44e6 | 2023-02-05 17:54:44 -0700 | [diff] [blame] | 616 | if (IS_ENABLED(CONFIG_PANEL)) { |
Anatolij Gustschin | 0087836 | 2020-05-26 00:09:22 +0200 | [diff] [blame] | 617 | 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 Schocher | 3c78784 | 2019-07-22 06:49:07 +0200 | [diff] [blame] | 623 | |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 624 | 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 | |
| 639 | struct ipuv3_video_priv { |
| 640 | ulong regs; |
| 641 | }; |
| 642 | |
| 643 | static int ipuv3_video_bind(struct udevice *dev) |
| 644 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 645 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 646 | |
| 647 | plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT * |
Marek Vasut | 28bdd93 | 2019-05-06 01:11:32 +0200 | [diff] [blame] | 648 | (1 << VIDEO_BPP32) / 8; |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | static const struct udevice_id ipuv3_video_ids[] = { |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 654 | #ifdef CONFIG_ARCH_MX6 |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 655 | { .compatible = "fsl,imx6q-ipu" }, |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 656 | #endif |
| 657 | #ifdef CONFIG_ARCH_MX5 |
Steffen Dirkwinkel | 4e40f1a | 2019-04-17 13:57:15 +0200 | [diff] [blame] | 658 | { .compatible = "fsl,imx53-ipu" }, |
Anatolij Gustschin | 8329ce3 | 2020-05-25 14:34:17 +0200 | [diff] [blame] | 659 | #endif |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 660 | { } |
| 661 | }; |
| 662 | |
Walter Lozano | 35f6187 | 2020-07-29 12:31:20 -0300 | [diff] [blame] | 663 | U_BOOT_DRIVER(fsl_imx6q_ipu) = { |
| 664 | .name = "fsl_imx6q_ipu", |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 665 | .id = UCLASS_VIDEO, |
| 666 | .of_match = ipuv3_video_ids, |
| 667 | .bind = ipuv3_video_bind, |
| 668 | .probe = ipuv3_video_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 669 | .priv_auto = sizeof(struct ipuv3_video_priv), |
Anatolij Gustschin | 983e2f2a | 2019-03-18 23:29:31 +0100 | [diff] [blame] | 670 | .flags = DM_FLAG_PRE_RELOC, |
| 671 | }; |