]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/video/mxc_ipuv3_fb.c
karo: merge with Ka-Ro specific tree for secure boot support
[karo-tx-uboot.git] / drivers / video / mxc_ipuv3_fb.c
index a49c9fd07589fb00ab4461a5e610bacfab1449e4..cd95abab837064a5616649a6b85c4e255062a27b 100644 (file)
@@ -4,51 +4,42 @@
  * (C) Copyright 2010
  * Stefano Babic, DENX Software Engineering, sbabic@denx.de
  *
- * MX51 Linux framebuffer:
+ * IPUv3 Linux framebuffer:
  *
- * (C) Copyright 2004-2010 Freescale Semiconductor, Inc.
+ * (C) Copyright 2004-2011 Freescale Semiconductor, Inc.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
+/* #define DEBUG */
 #include <common.h>
 #include <asm/errno.h>
+#include <asm/global_data.h>
 #include <linux/string.h>
 #include <linux/list.h>
 #include <linux/fb.h>
 #include <asm/io.h>
 #include <malloc.h>
+#include <lcd.h>
+#include <ipu.h>
 #include <video_fb.h>
+#include <mxcfb.h>
+
+#include "ipu_regs.h"
 #include "videomodes.h"
-#include "ipu.h"
-#include "mxcfb.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
 static int mxcfb_map_video_memory(struct fb_info *fbi);
 static int mxcfb_unmap_video_memory(struct fb_info *fbi);
 
-/* graphics setup */
-static GraphicDevice panel;
-static struct fb_videomode *gmode;
-static uint8_t gdisp;
-static uint32_t gpixfmt;
+void lcd_initcolregs(void)
+{
+}
+
+void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
+{
+}
 
 static void fb_videomode_to_var(struct fb_var_screeninfo *var,
                         const struct fb_videomode *mode)
@@ -113,14 +104,15 @@ static uint32_t bpp_to_pixfmt(struct fb_info *fbi)
                return fbi->var.nonstd;
 
        switch (fbi->var.bits_per_pixel) {
+       case 24:
+               pixfmt = IPU_PIX_FMT_BGR24;
+               break;
        case 32:
                pixfmt = IPU_PIX_FMT_BGR32;
                break;
-
        case 16:
                pixfmt = IPU_PIX_FMT_RGB565;
                break;
-
        case 8:
                pixfmt = IPU_PIX_FMT_GENERIC;
        }
@@ -320,8 +312,8 @@ static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        if (var->yres_virtual < var->yres)
                var->yres_virtual = var->yres;
 
-       if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 16) &&
-               (var->bits_per_pixel != 8))
+       if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
+           (var->bits_per_pixel != 16) && (var->bits_per_pixel != 8))
                var->bits_per_pixel = default_bpp;
 
        switch (var->bits_per_pixel) {
@@ -342,7 +334,6 @@ static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
                var->transp.offset = 0;
                var->transp.msb_right = 0;
                break;
-
        case 16:
                var->red.length = 5;
                var->red.offset = 11;
@@ -360,7 +351,23 @@ static int mxcfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
                var->transp.offset = 0;
                var->transp.msb_right = 0;
                break;
+       case 24:
+               var->red.length = 8;
+               var->red.offset = 16;
+               var->red.msb_right = 0;
+
+               var->green.length = 8;
+               var->green.offset = 8;
+               var->green.msb_right = 0;
+
+               var->blue.length = 8;
+               var->blue.offset = 0;
+               var->blue.msb_right = 0;
 
+               var->transp.length = 0;
+               var->transp.offset = 0;
+               var->transp.msb_right = 0;
+               break;
        case 32:
                var->red.length = 8;
                var->red.offset = 16;
@@ -404,10 +411,13 @@ static int mxcfb_map_video_memory(struct fb_info *fbi)
                fbi->fix.smem_len = fbi->var.yres_virtual *
                                    fbi->fix.line_length;
        }
+
+       fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
        if (gd->fb_base)
                fbi->screen_base = (void *)gd->fb_base;
        else
-               fbi->screen_base = malloc(fbi->fix.smem_len);
+               fbi->screen_base = (char *)memalign(ARCH_DMA_MINALIGN,
+                                               fbi->fix.smem_len);
        if (fbi->screen_base == NULL) {
                puts("Unable to allocate framebuffer memory\n");
                fbi->fix.smem_len = 0;
@@ -420,8 +430,7 @@ static int mxcfb_map_video_memory(struct fb_info *fbi)
 
        fbi->screen_size = fbi->fix.smem_len;
 
-       /* Clear the screen */
-       memset(fbi->screen_base, 0, fbi->fix.smem_len);
+       gd->fb_base = fbi->fix.smem_start;
 
        return 0;
 }
@@ -483,14 +492,13 @@ static struct fb_info *mxcfb_init_fbinfo(void)
 
 /*
  * Probe routine for the framebuffer driver. It is called during the
- * driver binding process.      The following functions are performed in
+ * driver binding process. The following functions are performed in
  * this routine: Framebuffer initialization, Memory allocation and
  * mapping, Framebuffer registration, IPU initialization.
  *
  * @return      Appropriate error code to the kernel common code
  */
-static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
-                       struct fb_videomode *mode)
+static int mxcfb_probe(u32 interface_pix_fmt, struct fb_videomode *mode, int di)
 {
        struct fb_info *fbi;
        struct mxcfb_info *mxcfbi;
@@ -512,7 +520,7 @@ static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
                mxcfbi->blank = FB_BLANK_POWERDOWN;
        }
 
-       mxcfbi->ipu_di = disp;
+       mxcfbi->ipu_di = di;
 
        ipu_disp_set_global_alpha(mxcfbi->ipu_ch, 1, 0x80);
        ipu_disp_set_color_key(mxcfbi->ipu_ch, 0, 0);
@@ -523,14 +531,20 @@ static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
        mxcfb_info[mxcfbi->ipu_di] = fbi;
 
        /* Need dummy values until real panel is configured */
+       fbi->var.xres = panel_info.vl_col;
+       fbi->var.yres = panel_info.vl_row;
 
        mxcfbi->ipu_di_pix_fmt = interface_pix_fmt;
        fb_videomode_to_var(&fbi->var, mode);
-       fbi->var.bits_per_pixel = default_bpp;
+       fbi->var.bits_per_pixel = NBITS(panel_info.vl_bpix);
        fbi->fix.line_length = fbi->var.xres * (fbi->var.bits_per_pixel / 8);
        fbi->fix.smem_len = fbi->var.yres_virtual * fbi->fix.line_length;
 
        mxcfb_check_var(&fbi->var, fbi);
+
+       /* Default Y virtual size is 2x panel size */
+       fbi->var.yres_virtual = fbi->var.yres * 2;
+
        mxcfb_set_fix(fbi);
 
        /* allocate fb first */
@@ -539,74 +553,58 @@ static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
 
        mxcfb_set_par(fbi);
 
-       panel.winSizeX = mode->xres;
-       panel.winSizeY = mode->yres;
-       panel.plnSizeX = mode->xres;
-       panel.plnSizeY = mode->yres;
-
-       panel.frameAdrs = (u32)fbi->screen_base;
-       panel.memSize = fbi->screen_size;
-
-       switch (fbi->var.bits_per_pixel) {
-       case 8:
-               panel.gdfBytesPP = 1;
-               panel.gdfIndex = GDF__8BIT_INDEX;
-               break;
-
-       case 16:
-               panel.gdfBytesPP = 2;
-               panel.gdfIndex = GDF_16BIT_565RGB;
-               break;
-
-       case 32:
-               panel.gdfBytesPP = 4;
-               panel.gdfIndex = GDF_32BIT_X888RGB;
-               break;
+       lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
 
-       default:
-               hang();
-       }
+       debug("MXC IPUV3 configured\n"
+               "XRES = %d YRES = %d BitsXpixel = %d\n",
+               panel_info.vl_col,
+               panel_info.vl_row,
+               panel_info.vl_bpix);
 
        ipu_dump_registers();
 
        return 0;
 }
 
-void mxcfb_disable(void)
+ulong calc_fbsize(void)
 {
-       ipu_disable_channel(MEM_BG_SYNC);
-       ipu_uninit_channel(MEM_BG_SYNC);
+       return (panel_info.vl_col * panel_info.vl_row *
+               NBITS(panel_info.vl_bpix)) / 8;
 }
 
-void *video_hw_init(void)
+void ipuv3_fb_shutdown(void)
 {
-       int ret;
-
-       ret = ipu_probe();
-       if (ret)
-               puts("Error initializing IPU\n");
-
-       ret = mxcfb_probe(gpixfmt, gdisp, gmode);
-       debug("Framebuffer at 0x%08x\n", panel.frameAdrs);
-
-       return &panel;
+       int i;
+       struct ipu_stat *stat = (struct ipu_stat *)IPU_STAT;
+
+       for (i = 0; i < ARRAY_SIZE(mxcfb_info); i++) {
+               struct fb_info *fbi = mxcfb_info[i];
+               if (fbi) {
+                       struct mxcfb_info *mxc_fbi = fbi->par;
+                       ipu_disable_channel(mxc_fbi->ipu_ch);
+                       ipu_uninit_channel(mxc_fbi->ipu_ch);
+               }
+       }
+       clk_enable(g_ipu_clk);
+       for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
+               __raw_writel(__raw_readl(&stat->int_stat[i]),
+                            &stat->int_stat[i]);
+       }
+       clk_disable(g_ipu_clk);
 }
 
-void video_set_lut(unsigned int index, /* color number */
-                       unsigned char r,    /* red */
-                       unsigned char g,    /* green */
-                       unsigned char b     /* blue */
-                       )
+int ipuv3_fb_init(struct fb_videomode *mode, int di, unsigned int interface_pix_fmt,
+               ipu_di_clk_parent_t di_clk_parent, unsigned long di_clk_val, int bpp)
 {
-       return;
-}
+       int ret;
 
-int mx5_fb_init(struct fb_videomode *mode, uint8_t disp, uint32_t pixfmt, int bpp)
-{
-       gmode = mode;
-       gdisp = disp;
-       gpixfmt = pixfmt;
        default_bpp = bpp;
 
-       return 0;
+       ret = ipu_probe(di, di_clk_parent, di_clk_val);
+       if (ret) {
+               printf("Error initializing IPU\n");
+               return ret;
+       }
+
+       return mxcfb_probe(interface_pix_fmt, mode, di);
 }