]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/video/mxc_ipuv3_fb.c
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / drivers / video / mxc_ipuv3_fb.c
index fd74370ed48775b811eab7a7bc8e88b582a75c5c..d7232ad1d62be8baf8131e6d79c3b211a90d25f0 100644 (file)
@@ -4,9 +4,9 @@
  * (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.
  *
  * SPDX-License-Identifier:    GPL-2.0+
  */
 #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 "videomodes.h"
-#include "ipu.h"
-#include "mxcfb.h"
-#include "ipu_regs.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 const *gmode;
-static uint8_t gdisp;
-static uint32_t gpixfmt;
+void lcd_initcolregs(void)
+{
+}
+
+void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
+{
+}
 
-void fb_videomode_to_var(struct fb_var_screeninfo *var,
+static void fb_videomode_to_var(struct fb_var_screeninfo *var,
                         const struct fb_videomode *mode)
 {
        var->xres = mode->xres;
@@ -105,6 +109,8 @@ static uint32_t bpp_to_pixfmt(struct fb_info *fbi)
        case 16:
                pixfmt = IPU_PIX_FMT_RGB565;
                break;
+       case 8:
+               pixfmt = IPU_PIX_FMT_GENERIC;
        }
        return pixfmt;
 }
@@ -133,7 +139,7 @@ static int mxcfb_set_fix(struct fb_info *info)
 static int setup_disp_channel1(struct fb_info *fbi)
 {
        ipu_channel_params_t params;
-       struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
+       struct mxcfb_info *mxc_fbi = fbi->par;
 
        memset(&params, 0, sizeof(params));
        params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
@@ -168,7 +174,7 @@ static int setup_disp_channel1(struct fb_info *fbi)
 static int setup_disp_channel2(struct fb_info *fbi)
 {
        int retval = 0;
-       struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
+       struct mxcfb_info *mxc_fbi = fbi->par;
 
        mxc_fbi->cur_ipu_buf = 1;
        if (mxc_fbi->alpha_chan_en)
@@ -176,7 +182,7 @@ static int setup_disp_channel2(struct fb_info *fbi)
 
        fbi->var.xoffset = fbi->var.yoffset = 0;
 
-       debug("%s: %x %d %d %d %lx %lx\n",
+       debug("%s: ch: %08x xres: %d yres: %d line_length: %d mem: %08lx .. %08lx\n",
                __func__,
                mxc_fbi->ipu_ch,
                fbi->var.xres,
@@ -184,7 +190,7 @@ static int setup_disp_channel2(struct fb_info *fbi)
                fbi->fix.line_length,
                fbi->fix.smem_start,
                fbi->fix.smem_start +
-               (fbi->fix.line_length * fbi->var.yres));
+               (fbi->fix.line_length * fbi->var.yres) - 1);
 
        retval = ipu_init_channel_buffer(mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
                                         bpp_to_pixfmt(fbi),
@@ -210,7 +216,7 @@ static int mxcfb_set_par(struct fb_info *fbi)
        int retval = 0;
        u32 mem_len;
        ipu_di_signal_cfg_t sig_cfg;
-       struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;
+       struct mxcfb_info *mxc_fbi = fbi->par;
        uint32_t out_pixel_fmt;
 
        ipu_disable_channel(mxc_fbi->ipu_ch);
@@ -255,10 +261,11 @@ static int mxcfb_set_par(struct fb_info *fbi)
        if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
                sig_cfg.clkidle_en = 1;
 
-       debug("pixclock = %ul Hz\n",
-               (u32) (PICOS2KHZ(fbi->var.pixclock) * 1000UL));
+       debug("pixclock = %lu.%03lu MHz\n",
+               PICOS2KHZ(fbi->var.pixclock) / 1000,
+               PICOS2KHZ(fbi->var.pixclock) % 1000);
 
-       if (ipu_init_sync_panel(mxc_fbi->ipu_di,
+       retval = ipu_init_sync_panel(mxc_fbi->ipu_di,
                                (PICOS2KHZ(fbi->var.pixclock)) * 1000UL,
                                fbi->var.xres, fbi->var.yres,
                                out_pixel_fmt,
@@ -268,9 +275,10 @@ static int mxcfb_set_par(struct fb_info *fbi)
                                fbi->var.upper_margin,
                                fbi->var.vsync_len,
                                fbi->var.lower_margin,
-                               0, sig_cfg) != 0) {
-               puts("mxcfb: Error initializing panel.\n");
-               return -EINVAL;
+                               0, sig_cfg);
+       if (retval != 0) {
+               printf("mxc_ipuv3_fb: Error %d initializing panel\n", retval);
+               return retval;
        }
 
        retval = setup_disp_channel2(fbi);
@@ -399,24 +407,22 @@ static int mxcfb_map_video_memory(struct fb_info *fbi)
                fbi->fix.smem_len = fbi->var.yres_virtual *
                                    fbi->fix.line_length;
        }
-
-       fbi->screen_base = (char *)malloc(fbi->fix.smem_len);
-       fbi->fix.smem_start = (unsigned long)fbi->screen_base;
-       if (fbi->screen_base == 0) {
+       if (gd->fb_base)
+               fbi->screen_base = (void *)gd->fb_base;
+       else
+               fbi->screen_base = malloc(fbi->fix.smem_len);
+       if (fbi->screen_base == NULL) {
                puts("Unable to allocate framebuffer memory\n");
                fbi->fix.smem_len = 0;
-               fbi->fix.smem_start = 0;
                return -EBUSY;
        }
+       fbi->fix.smem_start = (unsigned long)fbi->screen_base;
 
        debug("allocated fb @ paddr=0x%08X, size=%d.\n",
                (uint32_t) fbi->fix.smem_start, fbi->fix.smem_len);
 
        fbi->screen_size = fbi->fix.smem_len;
 
-       /* Clear the screen */
-       memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
-
        return 0;
 }
 
@@ -439,17 +445,14 @@ static int mxcfb_unmap_video_memory(struct fb_info *fbi)
  */
 static struct fb_info *mxcfb_init_fbinfo(void)
 {
-#define BYTES_PER_LONG 4
-#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
        struct fb_info *fbi;
        struct mxcfb_info *mxcfbi;
-       char *p;
-       int size = sizeof(struct mxcfb_info) + PADDING +
+       void *p;
+       int size = ALIGN(sizeof(struct mxcfb_info), sizeof(long)) +
                sizeof(struct fb_info);
 
-       debug("%s: %d %d %d %d\n",
+       debug("%s: %d %d %d\n",
                __func__,
-               PADDING,
                size,
                sizeof(struct mxcfb_info),
                sizeof(struct fb_info));
@@ -463,12 +466,12 @@ static struct fb_info *mxcfb_init_fbinfo(void)
 
        memset(p, 0, size);
 
-       fbi = (struct fb_info *)p;
-       fbi->par = p + sizeof(struct fb_info) + PADDING;
+       fbi = p;
+       fbi->par = p + ALIGN(sizeof(struct fb_info), sizeof(long));
 
-       mxcfbi = (struct mxcfb_info *)fbi->par;
-       debug("Framebuffer structures at: fbi=0x%x mxcfbi=0x%x\n",
-               (unsigned int)fbi, (unsigned int)mxcfbi);
+       mxcfbi = fbi->par;
+       debug("Framebuffer structures at: fbi=%p mxcfbi=%p\n",
+               fbi, mxcfbi);
 
        fbi->var.activate = FB_ACTIVATE_NOW;
 
@@ -486,22 +489,19 @@ static struct fb_info *mxcfb_init_fbinfo(void)
  *
  * @return      Appropriate error code to the kernel common code
  */
-static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
-                       struct fb_videomode const *mode)
+static int mxcfb_probe(u32 interface_pix_fmt, struct fb_videomode *mode, int di)
 {
        struct fb_info *fbi;
        struct mxcfb_info *mxcfbi;
-       int ret = 0;
 
        /*
         * Initialize FB structures
         */
        fbi = mxcfb_init_fbinfo();
-       if (!fbi) {
-               ret = -ENOMEM;
-               goto err0;
-       }
-       mxcfbi = (struct mxcfb_info *)fbi->par;
+       if (!fbi)
+               return -ENOMEM;
+
+       mxcfbi = fbi->par;
 
        if (!g_dp_in_use) {
                mxcfbi->ipu_ch = MEM_BG_SYNC;
@@ -511,7 +511,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);
@@ -522,10 +522,12 @@ 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 = 16;
+       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;
 
@@ -536,80 +538,43 @@ static int mxcfb_probe(u32 interface_pix_fmt, uint8_t disp,
 
        mxcfb_set_fix(fbi);
 
-       /* alocate fb first */
+       /* allocate fb first */
        if (mxcfb_map_video_memory(fbi) < 0)
                return -ENOMEM;
 
        mxcfb_set_par(fbi);
 
-       panel.winSizeX = mode->xres;
-       panel.winSizeY = mode->yres;
-       panel.plnSizeX = mode->xres;
-       panel.plnSizeY = mode->yres;
+       lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
 
-       panel.frameAdrs = (u32)fbi->screen_base;
-       panel.memSize = fbi->screen_size;
-
-       panel.gdfBytesPP = 2;
-       panel.gdfIndex = GDF_16BIT_565RGB;
+       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;
-
-err0:
-       return ret;
 }
 
-void ipuv3_fb_shutdown(void)
+ulong calc_fbsize(void)
 {
-       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);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(stat->int_stat); i++) {
-               __raw_writel(__raw_readl(&stat->int_stat[i]),
-                            &stat->int_stat[i]);
-       }
+       return (panel_info.vl_col * panel_info.vl_row *
+               NBITS(panel_info.vl_bpix)) / 8;
 }
 
-void *video_hw_init(void)
+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)
 {
        int ret;
 
-       ret = ipu_probe();
-       if (ret)
-               puts("Error initializing IPU\n");
-
-       ret = mxcfb_probe(gpixfmt, gdisp, gmode);
-       debug("Framebuffer at 0x%x\n", (unsigned int)panel.frameAdrs);
-
-       return (void *)&panel;
-}
-
-void video_set_lut(unsigned int index, /* color number */
-                       unsigned char r,    /* red */
-                       unsigned char g,    /* green */
-                       unsigned char b     /* blue */
-                       )
-{
-       return;
-}
+       default_bpp = bpp;
 
-int ipuv3_fb_init(struct fb_videomode const *mode,
-                 uint8_t disp,
-                 uint32_t pixfmt)
-{
-       gmode = mode;
-       gdisp = disp;
-       gpixfmt = pixfmt;
+       ret = ipu_probe(di, di_clk_parent, di_clk_val);
+       if (ret) {
+               printf("Error initializing IPU\n");
+               return ret;
+       }
 
-       return 0;
+       return mxcfb_probe(interface_pix_fmt, mode, di);
 }