mxc_ipuv3_fb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // SPDX-License-Identifier: GPL-2.0+
  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.
  11. */
  12. #include <common.h>
  13. #include <part.h>
  14. #include <asm/cache.h>
  15. #include <linux/errno.h>
  16. #include <asm/global_data.h>
  17. #include <linux/string.h>
  18. #include <linux/list.h>
  19. #include <linux/fb.h>
  20. #include <asm/io.h>
  21. #include <asm/mach-imx/video.h>
  22. #include <malloc.h>
  23. #include <video_fb.h>
  24. #include "../videomodes.h"
  25. #include "ipu.h"
  26. #include "mxcfb.h"
  27. #include "ipu_regs.h"
  28. #include "display.h"
  29. #include <panel.h>
  30. #include <dm.h>
  31. #include <video.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. static int mxcfb_map_video_memory(struct fb_info *fbi);
  34. static int mxcfb_unmap_video_memory(struct fb_info *fbi);
  35. /* graphics setup */
  36. static GraphicDevice panel;
  37. static struct fb_videomode const *gmode;
  38. static uint8_t gdisp;
  39. static uint32_t gpixfmt;
  40. static void fb_videomode_to_var(struct fb_var_screeninfo *var,
  41. const struct fb_videomode *mode)
  42. {
  43. var->xres = mode->xres;
  44. var->yres = mode->yres;
  45. var->xres_virtual = mode->xres;
  46. var->yres_virtual = mode->yres;
  47. var->xoffset = 0;
  48. var->yoffset = 0;
  49. var->pixclock = mode->pixclock;
  50. var->left_margin = mode->left_margin;
  51. var->right_margin = mode->right_margin;
  52. var->upper_margin = mode->upper_margin;
  53. var->lower_margin = mode->lower_margin;
  54. var->hsync_len = mode->hsync_len;
  55. var->vsync_len = mode->vsync_len;
  56. var->sync = mode->sync;
  57. var->vmode = mode->vmode & FB_VMODE_MASK;
  58. }
  59. /*
  60. * Structure containing the MXC specific framebuffer information.
  61. */
  62. struct mxcfb_info {
  63. int blank;
  64. ipu_channel_t ipu_ch;
  65. int ipu_di;
  66. u32 ipu_di_pix_fmt;
  67. unsigned char overlay;
  68. unsigned char alpha_chan_en;
  69. dma_addr_t alpha_phy_addr0;
  70. dma_addr_t alpha_phy_addr1;
  71. void *alpha_virt_addr0;
  72. void *alpha_virt_addr1;
  73. uint32_t alpha_mem_len;
  74. uint32_t cur_ipu_buf;
  75. uint32_t cur_ipu_alpha_buf;
  76. u32 pseudo_palette[16];
  77. };
  78. enum {
  79. BOTH_ON,
  80. SRC_ON,
  81. TGT_ON,
  82. BOTH_OFF
  83. };
  84. static unsigned long default_bpp = 16;
  85. static unsigned char g_dp_in_use;
  86. static struct fb_info *mxcfb_info[3];
  87. static int ext_clk_used;
  88. static uint32_t bpp_to_pixfmt(struct fb_info *fbi)
  89. {
  90. uint32_t pixfmt = 0;
  91. debug("bpp_to_pixfmt: %d\n", fbi->var.bits_per_pixel);
  92. if (fbi->var.nonstd)
  93. return fbi->var.nonstd;
  94. switch (fbi->var.bits_per_pixel) {
  95. case 24:
  96. pixfmt = IPU_PIX_FMT_BGR24;
  97. break;
  98. case 32:
  99. pixfmt = IPU_PIX_FMT_BGR32;
  100. break;
  101. case 16:
  102. pixfmt = IPU_PIX_FMT_RGB565;
  103. break;
  104. }
  105. return pixfmt;
  106. }
  107. /*
  108. * Set fixed framebuffer parameters based on variable settings.
  109. *
  110. * @param info framebuffer information pointer
  111. */
  112. static int mxcfb_set_fix(struct fb_info *info)
  113. {
  114. struct fb_fix_screeninfo *fix = &info->fix;
  115. struct fb_var_screeninfo *var = &info->var;
  116. fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
  117. fix->type = FB_TYPE_PACKED_PIXELS;
  118. fix->accel = FB_ACCEL_NONE;
  119. fix->visual = FB_VISUAL_TRUECOLOR;
  120. fix->xpanstep = 1;
  121. fix->ypanstep = 1;
  122. return 0;
  123. }
  124. static int setup_disp_channel1(struct fb_info *fbi)
  125. {
  126. ipu_channel_params_t params;
  127. struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
  128. memset(&params, 0, sizeof(params));
  129. params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
  130. debug("%s called\n", __func__);
  131. /*
  132. * Assuming interlaced means yuv output, below setting also
  133. * valid for mem_dc_sync. FG should have the same vmode as BG.
  134. */
  135. if (fbi->var.vmode & FB_VMODE_INTERLACED) {
  136. params.mem_dp_bg_sync.interlaced = 1;
  137. params.mem_dp_bg_sync.out_pixel_fmt =
  138. IPU_PIX_FMT_YUV444;
  139. } else {
  140. if (mxc_fbi->ipu_di_pix_fmt) {
  141. params.mem_dp_bg_sync.out_pixel_fmt =
  142. mxc_fbi->ipu_di_pix_fmt;
  143. } else {
  144. params.mem_dp_bg_sync.out_pixel_fmt =
  145. IPU_PIX_FMT_RGB666;
  146. }
  147. }
  148. params.mem_dp_bg_sync.in_pixel_fmt = bpp_to_pixfmt(fbi);
  149. if (mxc_fbi->alpha_chan_en)
  150. params.mem_dp_bg_sync.alpha_chan_en = 1;
  151. ipu_init_channel(mxc_fbi->ipu_ch, &params);
  152. return 0;
  153. }
  154. static int setup_disp_channel2(struct fb_info *fbi)
  155. {
  156. int retval = 0;
  157. struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
  158. mxc_fbi->cur_ipu_buf = 1;
  159. if (mxc_fbi->alpha_chan_en)
  160. mxc_fbi->cur_ipu_alpha_buf = 1;
  161. fbi->var.xoffset = fbi->var.yoffset = 0;
  162. debug("%s: %x %d %d %d %lx %lx\n",
  163. __func__,
  164. mxc_fbi->ipu_ch,
  165. fbi->var.xres,
  166. fbi->var.yres,
  167. fbi->fix.line_length,
  168. fbi->fix.smem_start,
  169. fbi->fix.smem_start +
  170. (fbi->fix.line_length * fbi->var.yres));
  171. retval = ipu_init_channel_buffer(mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
  172. bpp_to_pixfmt(fbi),
  173. fbi->var.xres, fbi->var.yres,
  174. fbi->fix.line_length,
  175. fbi->fix.smem_start +
  176. (fbi->fix.line_length * fbi->var.yres),
  177. fbi->fix.smem_start,
  178. 0, 0);
  179. if (retval)
  180. printf("ipu_init_channel_buffer error %d\n", retval);
  181. return retval;
  182. }
  183. /*
  184. * Set framebuffer parameters and change the operating mode.
  185. *
  186. * @param info framebuffer information pointer
  187. */
  188. static int mxcfb_set_par(struct fb_info *fbi)
  189. {
  190. int retval = 0;
  191. u32 mem_len;
  192. ipu_di_signal_cfg_t sig_cfg;
  193. struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
  194. uint32_t out_pixel_fmt;
  195. ipu_disable_channel(mxc_fbi->ipu_ch);
  196. ipu_uninit_channel(mxc_fbi->ipu_ch);
  197. mxcfb_set_fix(fbi);
  198. mem_len = fbi->var.yres_virtual * fbi->fix.line_length;
  199. if (!fbi->fix.smem_start || (mem_len > fbi->fix.smem_len)) {
  200. if (fbi->fix.smem_start)
  201. mxcfb_unmap_video_memory(fbi);
  202. if (mxcfb_map_video_memory(fbi) < 0)
  203. return -ENOMEM;
  204. }
  205. setup_disp_channel1(fbi);
  206. memset(&sig_cfg, 0, sizeof(sig_cfg));
  207. if (fbi->var.vmode & FB_VMODE_INTERLACED) {
  208. sig_cfg.interlaced = 1;
  209. out_pixel_fmt = IPU_PIX_FMT_YUV444;
  210. } else {
  211. if (mxc_fbi->ipu_di_pix_fmt)
  212. out_pixel_fmt = mxc_fbi->ipu_di_pix_fmt;
  213. else
  214. out_pixel_fmt = IPU_PIX_FMT_RGB666;
  215. }
  216. if (fbi->var.vmode & FB_VMODE_ODD_FLD_FIRST) /* PAL */
  217. sig_cfg.odd_field_first = 1;
  218. if ((fbi->var.sync & FB_SYNC_EXT) || ext_clk_used)
  219. sig_cfg.ext_clk = 1;
  220. if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
  221. sig_cfg.Hsync_pol = 1;
  222. if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
  223. sig_cfg.Vsync_pol = 1;
  224. if (!(fbi->var.sync & FB_SYNC_CLK_LAT_FALL))
  225. sig_cfg.clk_pol = 1;
  226. if (fbi->var.sync & FB_SYNC_DATA_INVERT)
  227. sig_cfg.data_pol = 1;
  228. if (!(fbi->var.sync & FB_SYNC_OE_LOW_ACT))
  229. sig_cfg.enable_pol = 1;
  230. if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
  231. sig_cfg.clkidle_en = 1;
  232. debug("pixclock = %lu Hz\n", PICOS2KHZ(fbi->var.pixclock) * 1000UL);
  233. if (ipu_init_sync_panel(mxc_fbi->ipu_di,
  234. (PICOS2KHZ(fbi->var.pixclock)) * 1000UL,
  235. fbi->var.xres, fbi->var.yres,
  236. out_pixel_fmt,
  237. fbi->var.left_margin,
  238. fbi->var.hsync_len,
  239. fbi->var.right_margin,
  240. fbi->var.upper_margin,
  241. fbi->var.vsync_len,
  242. fbi->var.lower_margin,
  243. 0, sig_cfg) != 0) {
  244. puts("mxcfb: Error initializing panel.\n");
  245. return -EINVAL;
  246. }
  247. retval = setup_disp_channel2(fbi);
  248. if (retval)
  249. return retval;
  250. if (mxc_fbi->blank == FB_BLANK_UNBLANK)
  251. ipu_enable_channel(mxc_fbi->ipu_ch);
  252. return retval;
  253. }
  254. /*
  255. * Check framebuffer variable parameters and adjust to valid values.
  256. *
  257. * @param var framebuffer variable parameters
  258. *
  259. * @param info framebuffer information pointer
  260. */
  261. static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  262. {
  263. u32 vtotal;
  264. u32 htotal;
  265. if (var->xres_virtual < var->xres)
  266. var->xres_virtual = var->xres;
  267. if (var->yres_virtual < var->yres)
  268. var->yres_virtual = var->yres;
  269. if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
  270. (var->bits_per_pixel != 16) && (var->bits_per_pixel != 8))
  271. var->bits_per_pixel = default_bpp;
  272. switch (var->bits_per_pixel) {
  273. case 8:
  274. var->red.length = 3;
  275. var->red.offset = 5;
  276. var->red.msb_right = 0;
  277. var->green.length = 3;
  278. var->green.offset = 2;
  279. var->green.msb_right = 0;
  280. var->blue.length = 2;
  281. var->blue.offset = 0;
  282. var->blue.msb_right = 0;
  283. var->transp.length = 0;
  284. var->transp.offset = 0;
  285. var->transp.msb_right = 0;
  286. break;
  287. case 16:
  288. var->red.length = 5;
  289. var->red.offset = 11;
  290. var->red.msb_right = 0;
  291. var->green.length = 6;
  292. var->green.offset = 5;
  293. var->green.msb_right = 0;
  294. var->blue.length = 5;
  295. var->blue.offset = 0;
  296. var->blue.msb_right = 0;
  297. var->transp.length = 0;
  298. var->transp.offset = 0;
  299. var->transp.msb_right = 0;
  300. break;
  301. case 24:
  302. var->red.length = 8;
  303. var->red.offset = 16;
  304. var->red.msb_right = 0;
  305. var->green.length = 8;
  306. var->green.offset = 8;
  307. var->green.msb_right = 0;
  308. var->blue.length = 8;
  309. var->blue.offset = 0;
  310. var->blue.msb_right = 0;
  311. var->transp.length = 0;
  312. var->transp.offset = 0;
  313. var->transp.msb_right = 0;
  314. break;
  315. case 32:
  316. var->red.length = 8;
  317. var->red.offset = 16;
  318. var->red.msb_right = 0;
  319. var->green.length = 8;
  320. var->green.offset = 8;
  321. var->green.msb_right = 0;
  322. var->blue.length = 8;
  323. var->blue.offset = 0;
  324. var->blue.msb_right = 0;
  325. var->transp.length = 8;
  326. var->transp.offset = 24;
  327. var->transp.msb_right = 0;
  328. break;
  329. }
  330. if (var->pixclock < 1000) {
  331. htotal = var->xres + var->right_margin + var->hsync_len +
  332. var->left_margin;
  333. vtotal = var->yres + var->lower_margin + var->vsync_len +
  334. var->upper_margin;
  335. var->pixclock = (vtotal * htotal * 6UL) / 100UL;
  336. var->pixclock = KHZ2PICOS(var->pixclock);
  337. printf("pixclock set for 60Hz refresh = %u ps\n",
  338. var->pixclock);
  339. }
  340. var->height = -1;
  341. var->width = -1;
  342. var->grayscale = 0;
  343. return 0;
  344. }
  345. static int mxcfb_map_video_memory(struct fb_info *fbi)
  346. {
  347. if (fbi->fix.smem_len < fbi->var.yres_virtual * fbi->fix.line_length) {
  348. fbi->fix.smem_len = fbi->var.yres_virtual *
  349. fbi->fix.line_length;
  350. }
  351. fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
  352. #if CONFIG_IS_ENABLED(DM_VIDEO)
  353. fbi->screen_base = (char *)gd->video_bottom;
  354. #else
  355. fbi->screen_base = (char *)memalign(ARCH_DMA_MINALIGN,
  356. fbi->fix.smem_len);
  357. #endif
  358. fbi->fix.smem_start = (unsigned long)fbi->screen_base;
  359. if (fbi->screen_base == 0) {
  360. puts("Unable to allocate framebuffer memory\n");
  361. fbi->fix.smem_len = 0;
  362. fbi->fix.smem_start = 0;
  363. return -EBUSY;
  364. }
  365. debug("allocated fb @ paddr=0x%08X, size=%d.\n",
  366. (uint32_t) fbi->fix.smem_start, fbi->fix.smem_len);
  367. fbi->screen_size = fbi->fix.smem_len;
  368. #if CONFIG_IS_ENABLED(VIDEO)
  369. gd->fb_base = fbi->fix.smem_start;
  370. #endif
  371. /* Clear the screen */
  372. memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
  373. return 0;
  374. }
  375. static int mxcfb_unmap_video_memory(struct fb_info *fbi)
  376. {
  377. fbi->screen_base = 0;
  378. fbi->fix.smem_start = 0;
  379. fbi->fix.smem_len = 0;
  380. return 0;
  381. }
  382. /*
  383. * Initializes the framebuffer information pointer. After allocating
  384. * sufficient memory for the framebuffer structure, the fields are
  385. * filled with custom information passed in from the configurable
  386. * structures. This includes information such as bits per pixel,
  387. * color maps, screen width/height and RGBA offsets.
  388. *
  389. * @return Framebuffer structure initialized with our information
  390. */
  391. static struct fb_info *mxcfb_init_fbinfo(void)
  392. {
  393. #define BYTES_PER_LONG 4
  394. #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
  395. struct fb_info *fbi;
  396. struct mxcfb_info *mxcfbi;
  397. char *p;
  398. int size = sizeof(struct mxcfb_info) + PADDING +
  399. sizeof(struct fb_info);
  400. debug("%s: %d %d %d %d\n",
  401. __func__,
  402. PADDING,
  403. size,
  404. sizeof(struct mxcfb_info),
  405. sizeof(struct fb_info));
  406. /*
  407. * Allocate sufficient memory for the fb structure
  408. */
  409. p = malloc(size);
  410. if (!p)
  411. return NULL;
  412. memset(p, 0, size);
  413. fbi = (struct fb_info *)p;
  414. fbi->par = p + sizeof(struct fb_info) + PADDING;
  415. mxcfbi = (struct mxcfb_info *)fbi->par;
  416. debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
  417. (unsigned int)fbi, (unsigned int)mxcfbi);
  418. fbi->var.activate = FB_ACTIVATE_NOW;
  419. fbi->flags = FBINFO_FLAG_DEFAULT;
  420. fbi->pseudo_palette = mxcfbi->pseudo_palette;
  421. return fbi;
  422. }
  423. /*
  424. * Probe routine for the framebuffer driver. It is called during the
  425. * driver binding process. The following functions are performed in
  426. * this routine: Framebuffer initialization, Memory allocation and
  427. * mapping, Framebuffer registration, IPU initialization.
  428. *
  429. * @return Appropriate error code to the kernel common code
  430. */
  431. static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
  432. struct fb_videomode const *mode)
  433. {
  434. struct fb_info *fbi;
  435. struct mxcfb_info *mxcfbi;
  436. int ret = 0;
  437. /*
  438. * Initialize FB structures
  439. */
  440. fbi = mxcfb_init_fbinfo();
  441. if (!fbi) {
  442. ret = -ENOMEM;
  443. goto err0;
  444. }
  445. mxcfbi = (struct mxcfb_info *)fbi->par;
  446. if (!g_dp_in_use) {
  447. mxcfbi->ipu_ch = MEM_BG_SYNC;
  448. mxcfbi->blank = FB_BLANK_UNBLANK;
  449. } else {
  450. mxcfbi->ipu_ch = MEM_DC_SYNC;
  451. mxcfbi->blank = FB_BLANK_POWERDOWN;
  452. }
  453. mxcfbi->ipu_di = disp;
  454. ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
  455. ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
  456. strcpy(fbi->fix.id, "DISP3 BG");
  457. g_dp_in_use = 1;
  458. mxcfb_info[mxcfbi->ipu_di] = fbi;
  459. /* Need dummy values until real panel is configured */
  460. mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
  461. fb_videomode_to_var(&fbi->var, mode);
  462. fbi->var.bits_per_pixel = 16;
  463. fbi->fix.line_length = fbi->var.xres * (fbi->var.bits_per_pixel / 8);
  464. fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
  465. mxcfb_check_var(&fbi->var, fbi);
  466. /* Default Y virtual size is 2x panel size */
  467. fbi->var.yres_virtual = fbi->var.yres * 2;
  468. mxcfb_set_fix(fbi);
  469. /* allocate fb first */
  470. if (mxcfb_map_video_memory(fbi) < 0)
  471. return -ENOMEM;
  472. mxcfb_set_par(fbi);
  473. panel.winSizeX = mode->xres;
  474. panel.winSizeY = mode->yres;
  475. panel.plnSizeX = mode->xres;
  476. panel.plnSizeY = mode->yres;
  477. panel.frameAdrs = (u32)fbi->screen_base;
  478. panel.memSize = fbi->screen_size;
  479. panel.gdfBytesPP = 2;
  480. panel.gdfIndex = GDF_16BIT_565RGB;
  481. ipu_dump_registers();
  482. return 0;
  483. err0:
  484. return ret;
  485. }
  486. void ipuv3_fb_shutdown(void)
  487. {
  488. int i;
  489. struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
  490. if (!ipu_clk_enabled())
  491. return;
  492. for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
  493. struct fb_info *fbi = mxcfb_info[i];
  494. if (fbi) {
  495. struct mxcfb_info *mxc_fbi = fbi->par;
  496. ipu_disable_channel(mxc_fbi->ipu_ch);
  497. ipu_uninit_channel(mxc_fbi->ipu_ch);
  498. }
  499. }
  500. for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
  501. __raw_writel(__raw_readl(&stat->int_stat[i]),
  502. &stat->int_stat[i]);
  503. }
  504. }
  505. void *video_hw_init(void)
  506. {
  507. int ret;
  508. ret = ipu_probe();
  509. if (ret)
  510. puts("Error initializing IPU\n");
  511. ret = mxcfb_probe(gpixfmt, gdisp, gmode);
  512. debug("Framebuffer at 0x%x\n", (unsigned int)panel.frameAdrs);
  513. gd->fb_base = panel.frameAdrs;
  514. return (void *)&panel;
  515. }
  516. int ipuv3_fb_init(struct fb_videomode const *mode,
  517. uint8_t disp,
  518. uint32_t pixfmt)
  519. {
  520. gmode = mode;
  521. gdisp = disp;
  522. gpixfmt = pixfmt;
  523. return 0;
  524. }
  525. #if CONFIG_IS_ENABLED(DM_VIDEO)
  526. enum {
  527. /* Maximum display size we support */
  528. LCD_MAX_WIDTH = 1920,
  529. LCD_MAX_HEIGHT = 1080,
  530. LCD_MAX_LOG2_BPP = VIDEO_BPP16,
  531. };
  532. static int ipuv3_video_probe(struct udevice *dev)
  533. {
  534. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  535. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  536. #if defined(CONFIG_DISPLAY)
  537. struct udevice *disp_dev;
  538. #endif
  539. struct udevice *panel_dev;
  540. u32 fb_start, fb_end;
  541. int ret;
  542. debug("%s() plat: base 0x%lx, size 0x%x\n",
  543. __func__, plat->base, plat->size);
  544. ret = ipu_probe();
  545. if (ret)
  546. return ret;
  547. ret = ipu_displays_init();
  548. if (ret < 0)
  549. return ret;
  550. ret = mxcfb_probe(gpixfmt, gdisp, gmode);
  551. if (ret < 0)
  552. return ret;
  553. #if defined(CONFIG_DISPLAY)
  554. ret = uclass_first_device(UCLASS_DISPLAY, &disp_dev);
  555. if (disp_dev) {
  556. ret = display_enable(disp_dev, 16, NULL);
  557. if (ret < 0)
  558. return ret;
  559. }
  560. #endif
  561. ret = uclass_get_device(UCLASS_PANEL, 0, &panel_dev);
  562. if (panel_dev)
  563. panel_enable_backlight(panel_dev);
  564. uc_priv->xsize = gmode->xres;
  565. uc_priv->ysize = gmode->yres;
  566. uc_priv->bpix = LCD_MAX_LOG2_BPP;
  567. /* Enable dcache for the frame buffer */
  568. fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
  569. fb_end = plat->base + plat->size;
  570. fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
  571. mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
  572. DCACHE_WRITEBACK);
  573. video_set_flush_dcache(dev, true);
  574. gd->fb_base = fb_start;
  575. return 0;
  576. }
  577. struct ipuv3_video_priv {
  578. ulong regs;
  579. };
  580. static int ipuv3_video_bind(struct udevice *dev)
  581. {
  582. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  583. plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
  584. (1 << VIDEO_BPP32) / 8;
  585. return 0;
  586. }
  587. static const struct udevice_id ipuv3_video_ids[] = {
  588. { .compatible = "fsl,imx6q-ipu" },
  589. { .compatible = "fsl,imx53-ipu" },
  590. { }
  591. };
  592. U_BOOT_DRIVER(ipuv3_video) = {
  593. .name = "ipuv3_video",
  594. .id = UCLASS_VIDEO,
  595. .of_match = ipuv3_video_ids,
  596. .bind = ipuv3_video_bind,
  597. .probe = ipuv3_video_probe,
  598. .priv_auto_alloc_size = sizeof(struct ipuv3_video_priv),
  599. .flags = DM_FLAG_PRE_RELOC,
  600. };
  601. #endif /* CONFIG_DM_VIDEO */