]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/video/fsl_dcu_fb.c
video: fsl_dcu_fb: fix framebuffer to the end of memory
[people/ms/u-boot.git] / drivers / video / fsl_dcu_fb.c
index d4cd38277669cf7495022ca51b87806c83e06093..7f03290b746b11fe8de49525f149fd96b0dddf69 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <asm/io.h>
 #include <common.h>
+#include <fdt_support.h>
 #include <fsl_dcu_fb.h>
 #include <linux/fb.h>
 #include <malloc.h>
@@ -79,6 +80,8 @@
 #define BPP_24_RGB888                  5
 #define BPP_32_ARGB8888                        6
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /*
  * This setting is used for the TWR_LCD_RGB card
  */
@@ -254,11 +257,19 @@ int fsl_dcu_init(unsigned int xres, unsigned int yres,
        struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
        unsigned int div, mode;
 
-       /* Memory allocation for framebuffer */
        info.screen_size =
                info.var.xres * info.var.yres * (info.var.bits_per_pixel / 8);
-       info.screen_base = (char *)memalign(ARCH_DMA_MINALIGN,
-                       roundup(info.screen_size, ARCH_DMA_MINALIGN));
+
+       if (info.screen_size > CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB) {
+               info.screen_size = 0;
+               return -ENOMEM;
+       }
+
+       /* Reserve framebuffer at the end of memory */
+       gd->fb_base = gd->bd->bi_dram[0].start +
+                       gd->bd->bi_dram[0].size - info.screen_size;
+       info.screen_base = (char *)gd->fb_base;
+
        memset(info.screen_base, 0, info.screen_size);
 
        reset_total_layers();
@@ -305,6 +316,11 @@ int fsl_dcu_init(unsigned int xres, unsigned int yres,
        return 0;
 }
 
+ulong board_get_usable_ram_top(ulong total_size)
+{
+       return gd->ram_top - CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB;
+}
+
 void *video_hw_init(void)
 {
        static GraphicDevice ctfb;
@@ -363,3 +379,26 @@ void *video_hw_init(void)
 
        return &ctfb;
 }
+
+#if defined(CONFIG_OF_BOARD_SETUP)
+int fsl_dcu_fixedfb_setup(void *blob)
+{
+       u64 start, size;
+       int ret;
+
+       start = gd->bd->bi_dram[0].start;
+       size = gd->bd->bi_dram[0].size - info.screen_size;
+
+       /*
+        * Align size on section size (1 MiB).
+        */
+       size &= 0xfff00000;
+       ret = fdt_fixup_memory_banks(blob, &start, &size, 1);
+       if (ret) {
+               eprintf("Cannot setup fb: Error reserving memory\n");
+               return ret;
+       }
+
+       return 0;
+}
+#endif