* (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+
*/
+/* #define DEBUG */
#include <common.h>
#include <asm/errno.h>
#include <asm/global_data.h>
#include <linux/fb.h>
#include <asm/io.h>
#include <malloc.h>
+#include <lcd.h>
+#include <ipu.h>
#include <video_fb.h>
-#include "videomodes.h"
-#include "ipu.h"
-#include "mxcfb.h"
+#include <mxcfb.h>
+
#include "ipu_regs.h"
+#include "videomodes.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)
+{
+}
static void fb_videomode_to_var(struct fb_var_screeninfo *var,
const struct fb_videomode *mode)
case 16:
pixfmt = IPU_PIX_FMT_RGB565;
break;
+ case 8:
+ pixfmt = IPU_PIX_FMT_GENERIC;
}
return pixfmt;
}
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(¶ms, 0, sizeof(params));
params.mem_dp_bg_sync.di = mxc_fbi->ipu_di;
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)
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,
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),
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);
if (fbi->var.sync & FB_SYNC_CLK_IDLE_EN)
sig_cfg.clkidle_en = 1;
- debug("pixclock = %lu Hz\n", 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,
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);
fbi->fix.smem_len = fbi->var.yres_virtual *
fbi->fix.line_length;
}
+
fbi->fix.smem_len = roundup(fbi->fix.smem_len, ARCH_DMA_MINALIGN);
- fbi->screen_base = (char *)memalign(ARCH_DMA_MINALIGN,
- 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 = (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;
- 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);
gd->fb_base = fbi->fix.smem_start;
- /* Clear the screen */
- memset((char *)fbi->screen_base, 0, fbi->fix.smem_len);
-
return 0;
}
*/
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));
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;
*
* @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;
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);
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;
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;
+ulong calc_fbsize(void)
+{
+ return (panel_info.vl_col * panel_info.vl_row *
+ NBITS(panel_info.vl_bpix)) / 8;
}
void ipuv3_fb_shutdown(void)
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_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);
}