/*
 * File Name       : /drivers/video/qfbhw.c
 * Function        : QVGA FraemBuffer H/W Driver
 * Release Version : Ver 1.00
 * Release Date    : 2005/05/25
 *
 * Copyright (C) NEC Electronics Corporation 2005
 *
 *
 * 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 Free Softwere
 * Foundation; either version 2 of 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 warrnty 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.
 *
 */

/*
 * Copyright 2006,2007 Sony Corporation. 
 */

//#define PRINT_IMG_AHB_ERROR 1         /* every time message */
#define PRINT_IMG_AHB_ERROR 2	/* only first time message */
#define IMG_AHB_ERROR_REASON 1	/* report IMG address regs */

#if ENABLE_3D
#define PILE_3D_SCREEN	1
#endif	/* ENABLE_3D */

#define DPM_IMG_RESUME  1	/* ENABLE IMG initialaize   in resume  */

#define PRINT_ROT_PARAMS 0	/* 0:none,1:reading frame,2:all parameters on console */

#if 0 // move to include/linux/mp200_mem.h
#define ENABLE_FRAMECACHE 1	/* enable framecache */
#endif				/* CONFIG_MP201 */
#define ENABLE_DITHER 1		/* enable dither */
#define __YUV420 1

#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <linux/sched.h>
#include <asm/arch/qfb.h>
#include "xcommon.h"
#define MP200_FB 1
#include <asm/arch/img.h>
#include "lcdc.h"
#if ENABLE_FRAMECACHE
#include "fifo.h"
#endif
#include <asm/arch/gpiocore.h>
#if UNRESET_LCD
#include <asm/arch/pmu.h>
#endif				/* UNRESET_LCD */

#define MASK_LCD_POWER_ON	0x27
#define DATA_LCD_POWER_ON	0x06	/* clear LCDRST, on LCD_BL, disable LCD_EN_POC, LCD suspend clear */

extern ulong DispBuf;		/* paddr */
extern ulong FrameBufA;		/* paddr */
extern ulong FrameBufB;		/* paddr */
extern char *FrameBufAV;	/* vaddr */
extern char *FrameBufBV;	/* vaddr */
extern ulong FrameBufLength;
#if ENABLE_3D
extern GLXWindowTable *pGLXWindowTable;	/* pointer to GLXWindowTable */
#endif	/* ENABLE_3D */
extern BLD_SCRN_LIST *pBldScreenList;	/* pointer to BLD_SCRN_LIST */
extern char *IMGMmioV;		/* vaddr */
extern char *LCDCMmioV;		/* vaddr */

#if ENABLE_FRAMECACHE
extern char *FIFOMmioV;		/* vaddr */
#endif

extern int index_BldScreenList;	/* index of BLD_SCRN_LIST */
extern int override_BldScreenList;	/* TRUE : possible to override
					   BLD_SCRN_LIST */

extern Xv_Attr XvAttribute;	/* overlay parameter */
extern interFb_bufaddr *pinterFb_bufaddr;	/* pointer to interFb_bufaddr */
extern InterFb_BufInfo *pInterFb_BufInfo;	/* pointer to InterFb_BufInfo for buffer 0 - 2 */

#ifdef LOWER_ROT_SCREEN
extern unsigned short qfb_t_color;
#endif				/* LOWER_ROT_SCREEN */

/*  for IMG definition */
#ifdef CONFIG_FB_MP200_18BPP
#if ENABLE_DITHER		/* enable dither */
#define IMG_MODE_YUV422_TO_RGB		0x0000703C	/* enable dither */
#define IMG_MODE_YUV420_TO_RGB		0x0000703F	/* enable dither */

#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB	\
        (0x0000503C | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   enable dither,
								   smooth filter */

#define IMG_MODE_ZOOM_YUV420_TO_RGB	\
        (0x0000503F | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   enable dither,
								   smooth filter */
#else				/* SMOOTH_FILTER */
#define IMG_MODE_ZOOM_YUV422_TO_RGB	0x0000503C	/* with zoom, enable
							   dither */
#define IMG_MODE_ZOOM_YUV420_TO_RGB	0x0000503F	/* with zoom, enable
							   dither */
#endif				/* SMOOTH_FILTER */

#else				/* ENABLE_DITHER */

#define IMG_MODE_YUV422_TO_RGB		0x00007024
#define IMG_MODE_YUV420_TO_RGB		0x00007027

#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB \
        (0x00005024 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   smooth filter */
#define IMG_MODE_ZOOM_YUV420_TO_RGB \
        (0x00005027 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   smooth filter
								 */
#else				/* SMOOTH_FILTER */
#define IMG_MODE_ZOOM_YUV422_TO_RGB	0x00005024	/* with zoom */
#define IMG_MODE_ZOOM_YUV420_TO_RGB	0x00005027	/* with zoom */
#endif				/* SMOOTH_FILTER */

#endif				/* ENABLE_DITHER */

#define IMG_MODE_RGB565_TO_RGB		0x00000027
#define IMG_MODE_OPAQUE_RGB565RGB_TO_RGB	0x00092027
#else				/* CONFIG_FB_MP200_18BPP */
#ifdef LOWER_ROT_SCREEN
#if ENABLE_DITHER		/* enable dither */
#define IMG_MODE_YUV422_TO_RGB          0x0000701A	/* enable dither */
#define IMG_MODE_YUV420_TO_RGB          0x0000701F	/* enable dither */
#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB     \
        (0x0000501A | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV422)
								   to D(RGB) with
								   zoom, enable
								   dither, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV422RGB_TO_RGB  \
        (0x0001501A | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV422)F(RGB)
								   to D(RGB) with
								   zoom, enable
								   dither, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV420_TO_RGB     \
        (0x0000501F | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV420) to
								   D(RGB) with
								   zoom, enable
								   dither, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV420RGB_TO_RGB  \
        (0x0001501F | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV420)F(RGB)
								   to D(RGB) with
								   zoom, enable
								   dither, smooth
								   filter */
#else				/* SMOOTH_FILTER */
#define IMG_MODE_ZOOM_YUV422_TO_RGB     0x0000501A	/* B(YUV422) to D(RGB) with
							   zoom, enable dither */
#define IMG_MODE_ZOOM_YUV422RGB_TO_RGB  0x0001501A	/* B(YUV422)F(RGB) to D(RGB)
							   with zoom, enable dither
							 */
#define IMG_MODE_ZOOM_YUV420_TO_RGB     0x0000501F	/* B(YUV420)       to D(RGB)
							   with zoom, enable dither
							 */
#define IMG_MODE_ZOOM_YUV420RGB_TO_RGB  0x0001501F	/* B(YUV420)F(RGB) to D(RGB)
							   with zoom, enable dither
							 */
#endif				/* SMOOTH_FILTER */

#else				/* ENABLE_DITHER */

#define IMG_MODE_YUV422_TO_RGB          0x00007004	/* B(YUV422) to D(RGB) */
#define IMG_MODE_YUV420_TO_RGB          0x00007007	/* B(YUV420) to D(RGB) */

#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB \
        (0x00005004 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV422)
								   to D(RGB) with
								   zoom, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV422RGB_TO_RGB \
        (0x00015004 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV422)F(RGB)
								   to D(RGB) with
								   zoom, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV420_TO_RGB \
        (0x00005007 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV420)
								   to D(RGB) with
								   zoom, smooth
								   filter */
#define IMG_MODE_ZOOM_YUV420RGB_TO_RGB \
        (0x00015007 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* B(YUV420)F(RGB)
								   to D(RGB) with
								   zoom, smooth
								   filter */
#else				/* SMOOTH_FILTER */
#define IMG_MODE_ZOOM_YUV422_TO_RGB     0x00005004	/* B(YUV422)       to D(RGB)
							   with zoom */
#define IMG_MODE_ZOOM_YUV422RGB_TO_RGB  0x00015004	/* B(YUV422)F(RGB) to D(RGB)
							   with zoom */
#define IMG_MODE_ZOOM_YUV420_TO_RGB     0x00005007	/* B(YUV420)       to D(RGB)
							   with zoom */
#define IMG_MODE_ZOOM_YUV420RGB_TO_RGB  0x00015007	/* B(YUV420)F(RGB) to D(RGB)
							   with zoom */
#endif				/* SMOOTH_FILTER */
#endif				/* ENABLE_DITHER */

#else				/* LOWER_ROT_SCREEN */

#if ENABLE_DITHER		/* enable dither */
#define IMG_MODE_YUV422_TO_RGB		0x0000701A	/* enable dither */
#define IMG_MODE_YUV420_TO_RGB		0x0000701F	/* enable dither */

#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB \
        (0x0000501A | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   enable dither,
								   smooth filter
								 */
#define IMG_MODE_ZOOM_YUV420_TO_RGB \
        (0x0000501F | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   enable dither,
								   smooth filter
								 */
#else				/* SMOOTH_FILTER */

#define IMG_MODE_ZOOM_YUV422_TO_RGB	0x0000501A	/* with zoom, enable dither
							 */
#define IMG_MODE_ZOOM_YUV420_TO_RGB	0x0000501F	/* with zoom, enable dither
							 */
#endif				/* SMOOTH_FILTER */

#else				/* ENABLE_DITHER */
#define IMG_MODE_YUV422_TO_RGB		0x00007004
#define IMG_MODE_YUV420_TO_RGB		0x00007007
#ifdef SMOOTH_FILTER
#define IMG_MODE_ZOOM_YUV422_TO_RGB \
        (0x00005004 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   smooth filter
								 */
#define IMG_MODE_ZOOM_YUV420_TO_RGB \
        (0x00005007 | IMG_RFILTER_B_BIT | IMG_RFILTER_F_BIT)	/* with zoom,
								   smooth filter
								 */
#else				/*SMOOTH_FILTER */
#define IMG_MODE_ZOOM_YUV422_TO_RGB	0x00005004	/* with zoom */
#define IMG_MODE_ZOOM_YUV420_TO_RGB	0x00005007	/* with zoom */
#endif				/* SMOOTH_FILTER */
#endif				/* ENABLE_DITHER */
#endif				/* LOWER_ROT_SCREEN */
#define IMG_MODE_RGB565_TO_RGB          0x00000007	/* B(RGB)       to D(RGB) */
#define IMG_MODE_RGB565RGB_TO_RGB       0x00012007	/* B(RGB)F(RGB) to D(RGB) */
#define IMG_MODE_OPAQUE_RGB565RGB_TO_RGB	0x00092007
#endif				/* CONFIG_FB_MP200_18BPP */

#ifdef CONFIG_MP200_IMG
typedef struct mp200_img_req_fb {
	struct mp200_img_req *next;	/* needless setting (use IMG driver) */
	struct mp200_img_req *prev;	/* needless setting (use IMG driver) */
	int status;		/* needless setting (use IMG driver) */
	img_callback_func callback;	/* set: callback function            */
	int lastLayer;		/* set: 0: continuance BldScreenList */

	/*      1: BldScreenList.transfer == BLD_SCRN_TYPE_ENDMARK */
	unsigned long data;	/* set: optional data                */
	MP200_IMG_REG_INFO img_reg_info[IMG_REG_INFO_MAX];	/* set: IMG register
								   data           */
	/* MAX 50 pair (data, reg)     data = set IMG register data          */
	/*                             reg  = IMG register address offset    */
	/* end decision: IMG_REQ = 0x00000001 (data=0x00000001, reg=IMG_REQ) */
	/*               or reg=-1(0xFFFFFFFF)                               */
} MP200_IMG_REQ_FB;
struct mp200_img_req_fb qIMG_req[3];

extern void img_irq_handler(struct mp200_img_req *p, int flag);
extern void mp200_img_preferred_regist(struct mp200_img_req *p);

#define ImgRequest(DATA, REG)                                           \
do{                                                                     \
        qIMG_req[index_qIMG_req].img_reg_info[index_req].reg  = (REG);  \
        qIMG_req[index_qIMG_req].img_reg_info[index_req].data = (DATA); \
        index_req++;                                                    \
}while(0)
#else				/* CONFIG_MP200_IMG */
#define ImgRequest(DATA, REG)  writel((DATA), IMGMmioV + (REG));
#endif				/* CONFIG_MP200_IMG */

/* for LCDC definition */

#ifdef CONFIG_SONY_ICX1087  /* 2006.05.15 ish */

#if ENABLE_FRAMECACHE
#define LCD_CONTROL_VAL				0x00000040
#else				/* ENABLE_FRAMECACHE */
#define LCD_CONTROL_VAL				0x00000140
#endif

#else

#if ENABLE_FRAMECACHE
#define LCD_CONTROL_VAL				0x00000046
#else				/* ENABLE_FRAMECACHE */
#define LCD_CONTROL_VAL				0x00000146
#endif				/* ENABLE_FRAMECACHE */

#endif /* CONFIG_SONY_ICX1087 */

#define LCD_FLAME_A				0x00000001
#define LCD_FLAME_B				0x00000002


#ifdef CONFIG_SONY_ICX1087  /* 2006.05.15 ish */

#define LCD_HAREA_VAL   FRONT_WIDTH
#define LCD_HBLANK_VAL 12
#define LCD_VAREA_VAL  (FRONT_HEIGHT+1)
#define LCD_VBLANK_VAL 12

#else

#define LCD_HAREA_VAL				FRONT_WIDTH
#define LCD_HBLANK_VAL				24
#define LCD_VAREA_VAL				FRONT_HEIGHT
#define LCD_VBLANK_VAL				4

#endif /* CONFIG_SONY_ICX1087 */



#if ENABLE_FRAMECACHE
/* for FIFO definition */
/*
	bit
	7:4	Master ID            d:LCDC
	3	Master ID Enable     0:Disable 1:Enable
	2	frame cache B Enable 0:Disable 1:Enable(need bit1 = 1)
	1	frame cache A Enable 0:Disable 1:Enable(need bit1 = 1)
	0	frame cache Enable   0:Disable 1:Enable
*/
#ifdef CONFIG_MP201
#define FIF_FCCTRL_VAL				0x0000009f
#else
#define FIF_FCCTRL_VAL				0x000000df
#endif				/* CONFIG_MP201 */
#endif				/* ENABLE_FRAMECACHE */

enum framenum { FB_FRAME_NO_A, FB_FRAME_NO_B };

static enum framenum DispFrame = FB_FRAME_NO_A;

#ifndef CONFIG_MP200_IMG
#if (PRINT_IMG_AHB_ERROR == 2)
static bool first_img_error = 1;	/* error message count */
#endif
#endif				/* !defined(CONFIG_MP200_IMG) */

extern int ROT_readingframe;	/* 040702 readingframe loaded at end of ROT */

bool init_hw(void);
bool mix_image(int pram1);

static void exclude(void);
#ifdef CONFIG_MP200_IMG
void unexclude(void);
#else				/* CONFIG_MP200_IMG */
static void unexclude(void);
#endif				/* CONFIG_MP200_IMG */

#ifndef CONFIG_MP200_IMG
#if DPM_IMG_RESUME
bool init_img(void);
#else				/* DPM_IMG_RESUME */
static bool init_img(void);
#endif				/* DPM_IMG_RESUME */
#endif				/* CONFIG_MP200_IMG */
static bool init_lcdc(void);
#if ENABLE_FRAMECACHE
static void init_fifo(void);
#endif
static inline void change_frame(void);
static inline void start_lcd(void);
static inline void stop_lcd(void);

/* initialize hardware(img, lcdc)
   input : none
   output: status */
bool init_hw()
{
	bool bRet;

#ifndef CONFIG_MP200_IMG
	/* initialize img */
	bRet = init_img();
	if (!bRet)
		return bRet;
#endif				/* !defined(CONFIG_MP200_IMG) */

	/* initialize lcdc */
	bRet = init_lcdc();
	if (!bRet)
		return bRet;

	return 1;
}

#ifndef CONFIG_MP200_IMG
#if DPM_IMG_RESUME
bool init_img()
#else				/* DPM_IMG_RESUME */
static bool init_img()
#endif				/* DPM_IMG_RESUME */
{
	unsigned long ulRegVal32;

#if UNRESET_LCD
	/* Unreset IMG */
	mp200_pmu_clkctrl_off(MP200_CLKCTRL_IMG);
	mp200_pmu_clkctrl_off(MP200_CLKCTRL_IMGPCLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_IMG_CLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_IMG_PCLK);
	mp200_pmu_unreset_device(MP200_RESETDEVICE_IMG);
	mp200_pmu_clkctrl_on(MP200_CLKCTRL_IMG);
	mp200_pmu_clkctrl_on(MP200_CLKCTRL_IMGPCLK);
#endif				/* UNRESET_LCD */

	/* check img working */
	ulRegVal32 = readl(IMGMmioV + IMG_ACK);
	if ((ulRegVal32 & IMG_ACK_BIT) == IMG_ACK_BIT) {
		printk(KERN_ERR "fb: cannot use img\n");
		return 0;
	}
	/* Interuppt Enable Clear */
	writel(IMG_ENCLRSTAT_BIT | IMG_ENCLRERROR_BIT | IMG_ENCLRSTOP_BIT,
	       IMGMmioV + IMG_ENCLR);
	/* Interuppt Status Clear */
	writel(IMG_FFCLRSTAT_BIT | IMG_FFCLRERROR_BIT | IMG_FFCLRSTOP_BIT,
	       IMGMmioV + IMG_FFCLR);

	return 1;
}
#endif				/* !defined(CONFIG_MP200_IMG) */

static bool init_lcdc()
{
	int retvalue;
#ifdef CONFIG_MP201
	unsigned int lcd_write_data;
	unsigned int lcd_write_mask;
#endif				/* CONFIG_MP201 */
#if ENABLE_FRAMECACHE
	/* frame cache settings */
	init_fifo();
#endif

#if UNRESET_LCD
	/* Unreset LCD */
	mp200_pmu_clkctrl_off(MP200_CLKCTRL_LCD);
	mp200_pmu_clkctrl_off(MP200_CLKCTRL_LCDPCLK);
#ifdef CONFIG_MP201
	mp200_pmu_clkctrl_off(MP200_CLKCTRL_TFDPCLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_TFD_PCLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_TFD_LCLK);
#endif				/* CONFIG_MP201 */
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_LCD_CLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_LCD_PCLK);
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_LCD_LCLK);
#ifndef CONFIG_MP201
	mp200_pmu_open_clockgate(MP200_CLOCKGATE_LCD_MCMADS_CLK);
#endif				/* CONFIG_MP201 */
	mp200_pmu_unreset_device(MP200_RESETDEVICE_LCD);
#ifdef CONFIG_MP201
	mp200_pmu_unreset_device(MP200_RESETDEVICE_TFD);
	mp200_pmu_clkctrl_on(MP200_CLKCTRL_TFDPCLK);
#endif				/* CONFIG_MP201 */
	mp200_pmu_clkctrl_on(MP200_CLKCTRL_LCD);
	mp200_pmu_clkctrl_on(MP200_CLKCTRL_LCDPCLK);
#endif				/* UNRESET_LCD */

	/* frame buffer clear */
	memset_io((char __iomem *)FrameBufAV, 0, FrameBufLength);
	memset_io((char __iomem *)FrameBufBV, 0, FrameBufLength);

	DispFrame = FB_FRAME_NO_A;

	writel(LCD_CONTROL_VAL, LCDCMmioV + LCD_CONTROL);
	writel(LCD_FLAME_A, LCDCMmioV + LCD_FRAMESEL);

	/* Set frame buffer A/B/C physical address */
	writel(FrameBufA, LCDCMmioV + LCD_AREAADR_A);
	writel(FrameBufB, LCDCMmioV + LCD_AREAADR_B);
	writel(FRAMECACHE_START, LCDCMmioV + LCD_AREAADR_C);

#ifdef CONFIG_SONY_ICX1087  /* 2006.05.15 ish */

    writel(LCD_HAREA_VAL + LCD_HBLANK_VAL + 12, LCDCMmioV + LCD_HTOTAL);
    writel(LCD_HAREA_VAL, LCDCMmioV + LCD_HAREA);
    writel(8, LCDCMmioV + LCD_HEDGE1);
	writel(LCD_HBLANK_VAL, LCDCMmioV + LCD_HEDGE2);
	writel(LCD_VAREA_VAL + LCD_VBLANK_VAL, LCDCMmioV + LCD_VTOTAL);
	writel(LCD_VAREA_VAL, LCDCMmioV + LCD_VAREA);
    writel(8, LCDCMmioV + LCD_VEDGE1);
	writel(10, LCDCMmioV + LCD_VEDGE2);

#else
    
	writel(LCD_HAREA_VAL + LCD_HBLANK_VAL, LCDCMmioV + LCD_HTOTAL);
	writel(LCD_HAREA_VAL, LCDCMmioV + LCD_HAREA);
	writel(LCD_HAREA_VAL, LCDCMmioV + LCD_HEDGE1);
	writel(LCD_HAREA_VAL + LCD_HBLANK_VAL, LCDCMmioV + LCD_HEDGE2);
	writel(LCD_VAREA_VAL + LCD_VBLANK_VAL, LCDCMmioV + LCD_VTOTAL);
	writel(LCD_VAREA_VAL, LCDCMmioV + LCD_VAREA);
	writel(LCD_VAREA_VAL, LCDCMmioV + LCD_VEDGE1);
	writel(LCD_VAREA_VAL + LCD_VBLANK_VAL, LCDCMmioV + LCD_VEDGE2);
    
#endif  /* CONFIG_SONY_ICX1087 */

#ifdef CONFIG_FB_MP200_18BPP
	writel(LCD_HAREA_VAL / 16 * 36, LCDCMmioV + LCD_HOFFSET);
#else				/* CONFIG_FB_MP200_18BPP */
	writel(LCD_HAREA_VAL / 16 * 32, LCDCMmioV + LCD_HOFFSET);
#endif				/* CONFIG_FB_MP200_18BPP */

	/* Interrupt Enable Clear */
	writel(LCD_LCDSTOPMASK_BIT | LCD_UNDERRUNMASK_BIT |
	       LCD_LCDVSMASK_BIT | LCD_DMAERRMASK_BIT | LCD_DMASTOPMASK_BIT,
	       LCDCMmioV + LCD_INTENCLR);

	/* Interrupt Status Clear */
	writel(LCD_LCDSTOPCLR_BIT | LCD_UNDERRUNCLR_BIT |
	       LCD_DMASTOPCLR_BIT | LCD_DMAERRCLR_BIT | LCD_LCDVSCLR_BIT,
	       LCDCMmioV + LCD_INTFFCLR);

	start_lcd();


#ifdef CONFIG_SONY_ICX1087  /* 2006.05.15 ish */
    
    /* LCD RST : GPIO36=High (NOTE: controls LED) */
    mp200_gio_set_mode_output_high32(0x00000010);
    mp200_gio_write_outputs_high32(0x00000010, 0x00000010);
    
    /* Set pwc gpio 14,15 to output pin */
    gpiocore_pwc_write(GPIOCORE_PWC_IOSEL2, 0xC0, 0xC0);

    /* LCD RST : PWC_GPIO15=High */
    gpiocore_pwc_write(GPIOCORE_PWC_IOOUT2, 0x80, 0x80);

    msleep(20);

    /* LCD PCI : GPIO35=High  (NOTE: controls LED) */
    mp200_gio_set_mode_output_high32(0x00000008);
    mp200_gio_write_outputs_high32(0x00000008, 0x00000008);

    /* LCD PCI : PWC_GPIO14=High */
    gpiocore_pwc_write(GPIOCORE_PWC_IOOUT2, 0x40, 0x40);

    /* Back Light ON : GPIO33=High */
    mp200_gio_set_mode_output_high32(0x00000002);
    mp200_gio_write_outputs_high32(0x00000002, 0x00000002);
    
#else
    
#ifdef CONFIG_MP201
	/* Power & BackLight */
	lcd_write_mask = (unsigned int)((1 << PWC_INT_LED_ON) | (1 << PWC_INT_LCD_OE));
	lcd_write_data = lcd_write_mask;
	retvalue = gpiocore_pwc_write(GPIOCORE_PWC_IOOUT2, lcd_write_data, lcd_write_mask);
#else
	/* Power */
	retvalue = gpiocore_write(GPIOCORE_GP_O, GPIOCORE_GPIO_P4, 1);
	/* Reset */
	if (retvalue == 0)
		retvalue = gpiocore_write(GPIOCORE_GP_O, GPIOCORE_GPIO_P3, 1);
	/* BackLight */
	if (retvalue == 0)
		retvalue = gpiocore_write(GPIOCORE_GP_O, GPIOCORE_GPIO_P5, 1);
#endif				/* CONFIG_MP201 */
	if (retvalue < 0)
		printk(KERN_ERR "fb: cannot use gpiocore:%x\n", retvalue);

#endif
    
	return 1;
}

#if ENABLE_FRAMECACHE
static void init_fifo()
{
	writel(FrameBufA, FIFOMmioV + FIF_FRAMEAADDR);
	writel(FrameBufB, FIFOMmioV + FIF_FRAMEBADDR);
	writel(FRAMECACHE_LENGTH, FIFOMmioV + FIF_FRAMESIZE);
	writel(FRAMECACHE_START, FIFOMmioV + FIF_FCBASEADDR);
	writel(FIF_FCCTRL_VAL, FIFOMmioV + FIF_FCCTRL);
}
#endif				/* ENABLE_FRAMECACHE */

#if ENABLE_3D
#ifdef PILE_3D_SCREEN
/* extern from qfb.c */
extern ulong GLXSmem;		/* paddr */
extern char *GLXSmemV;		/* vaddr */

static void qfb_copy_rect(unsigned char *src_top, unsigned long src_x,	/* pixel */
			  unsigned long src_y,	/* pixel */
			  unsigned long src_pitch,	/* byte */
			  unsigned char *dest_top, unsigned long dest_x,	/* pixel */
			  unsigned long dest_y,	/* pixel */
			  unsigned long dest_pitch,	/* byte */
			  unsigned long width,	/* pixel */
			  unsigned long height)
{				/* pixel */
	unsigned short *srcp, *destp;	/* pointer of target pixel */
	unsigned char *srclp, *destlp;	/* start point of target line */
	int ix, iy;

	srclp = src_top + (src_y * src_pitch) + (src_x * BITS_PER_PIXEL / 8);
	destlp =
	    dest_top + (dest_y * dest_pitch) + (dest_x * BITS_PER_PIXEL / 8);
	for (iy = 0; iy < height;
	     iy++, srclp += src_pitch, destlp += dest_pitch) {
		srcp = (unsigned short *)srclp;
		destp = (unsigned short *)destlp;
		for (ix = 0; ix < width; ix++, srcp++, destp++) {
			*destp = *srcp;
		}
	}
}
#endif				/* PILE_3D_SCREEN */
#endif	/* ENABLE_3D */

bool mix_image(int pram1)
{
#ifndef CONFIG_MP200_IMG
	unsigned long ulRegVal32;
#endif				/* !defined(CONFIG_MP200_IMG) */
	unsigned long ulImgMode = 0;
	unsigned long ulSrcStarAddrYRGB, ulSrcStarAddrU, ulDestStarAddr,
	    ulSrcScreenWidth, src_x, src_y, src_width, src_height, dest_x,
	    dest_y, dest_width, dest_height;
#if defined(LOWER_ROT_SCREEN) || defined(PILE_3D_SCREEN)
	unsigned long ulSrcStarAddrYRGB_F, ulSrcStarAddrU_F, ulSrcScreenWidth_F,
	    src_x_F, src_y_F, src_width_F, src_height_F;
#endif

#ifdef CONFIG_MP200_IMG
	int index_req = 0;
	int index_qIMG_req = index_BldScreenList;
#else				/* CONFIG_MP200_IMG */
	if (pram1 == 1) {
		/* check Interuppt Status */
		ulRegVal32 = readl(IMGMmioV + IMG_STATUS);

		if ((ulRegVal32 & IMG_ERROR_BIT) == IMG_ERROR_BIT) {
			writel(IMG_FFCLRERROR_BIT, IMGMmioV + IMG_FFCLR);
#if (PRINT_IMG_AHB_ERROR == 1)
			printk(KERN_INFO "fb:img AHB ERROR.\n");
#ifdef IMG_AHB_ERROR_REASON
			printk(KERN_INFO "IMG_SRCYRGBADR_B:%lx\n",
			       readl(IMGMmioV + IMG_SRCYRGBADR_B));
			printk(KERN_INFO "IMG_SRCUVADR_B:%lx\n",
			       readl(IMGMmioV + IMG_SRCUVADR_B));
#endif				/* IMG_AHB_ERROR_REASON */
#endif
#if (PRINT_IMG_AHB_ERROR == 2)
			if (first_img_error) {
				printk(KERN_INFO "fb:img AHB ERROR.\n");
				first_img_error = 0;
#ifdef IMG_AHB_ERROR_REASON
				printk(KERN_INFO "IMG_SRCYRGBADR_B:%x\n",
				       readl(IMGMmioV + IMG_SRCYRGBADR_B));
				printk(KERN_INFO "IMG_SRCUVADR_B:%x\n",
				       readl(IMGMmioV + IMG_SRCUVADR_B));
#endif				/* IMG_AHB_ERROR_REASON */
			}
#endif
			return 1;
		}
		if ((ulRegVal32 & IMG_STOP_BIT) == IMG_STOP_BIT) {
			writel(IMG_FFCLRSTOP_BIT, IMGMmioV + IMG_FFCLR);
			printk(KERN_INFO "fb:img AHB RETRY/SPLIT.\n");
			return 1;
		}
		if ((ulRegVal32 & IMG_STAT_BIT) == IMG_STAT_BIT) {
			writel(IMG_FFCLRSTAT_BIT, IMGMmioV + IMG_FFCLR);
			unexclude();
		}
	}
	/* check img working */
	ulRegVal32 = readl(IMGMmioV + IMG_ACK);
	if ((ulRegVal32 & IMG_ACK_BIT) == IMG_ACK_BIT) {
		printk(KERN_ERR "fb: img working now\n");
		goto error_ret;
	}
#endif				/* CONFIG_MP200_IMG */

#ifdef PILE_3D_SCREEN
      LOOP_COPY_DIRECT:
#endif
	if (pBldScreenList[index_BldScreenList].transfer ==
	    BLD_SCRN_TYPE_ENDMARK) {
		change_frame();
		index_BldScreenList = 0;
		override_BldScreenList = 1;
		return 1;
	}

	exclude();

	src_x = pBldScreenList[index_BldScreenList].src_x;
	src_y = pBldScreenList[index_BldScreenList].src_y;
	dest_width = pBldScreenList[index_BldScreenList].width;
	dest_height = pBldScreenList[index_BldScreenList].height;
	dest_x = pBldScreenList[index_BldScreenList].dest_x;
	dest_y = pBldScreenList[index_BldScreenList].dest_y;
#ifdef LOWER_ROT_SCREEN
	ulSrcStarAddrYRGB_F = 0;
	ulSrcStarAddrU_F = 0;
	ulSrcScreenWidth_F = 0;
	src_x_F = dest_x;
	src_y_F = dest_y;
	src_width_F = dest_width;
	src_height_F = dest_height;
#endif

	switch (pBldScreenList[index_BldScreenList].image) {
	case BLD_SCRN_TYPE_IMAGE_2D:
		/* Input Data format = RGB565 */
		ulImgMode = IMG_MODE_RGB565_TO_RGB;
		src_width = pBldScreenList[index_BldScreenList].width;
		src_height = pBldScreenList[index_BldScreenList].height;
		ulSrcScreenWidth = FRONT_WIDTH_V * BYTES_PER_PIXEL;
		ulSrcStarAddrYRGB =
		    DispBuf + src_x * BYTES_PER_PIXEL +
		    src_y * ulSrcScreenWidth;
		break;

#if ENABLE_3D
	case BLD_SCRN_TYPE_IMAGE_3D:
		{
			int index =
			    pBldScreenList[index_BldScreenList].
			    index_GLXWindowTable;

#ifdef PILE_3D_SCREEN
			if (src_x % 2 == 0 && dest_x % 2 == 0
			    && dest_width % 2 == 0) {
#endif				/* PILE_3D_SCREEN */
				/* Input Data format = RGB565 */
				ulImgMode = IMG_MODE_RGB565_TO_RGB;
				src_width =
				    pBldScreenList[index_BldScreenList].width;
				src_height =
				    pBldScreenList[index_BldScreenList].height;
				ulSrcScreenWidth = pGLXWindowTable[index].pitch;
				ulSrcStarAddrYRGB =
				    pGLXWindowTable[index].writtenframe +
				    (src_x + pGLXWindowTable[index].x) * 2 +
				    (src_y +
				     pGLXWindowTable[index].y) *
				    ulSrcScreenWidth;
#ifdef PILE_3D_SCREEN
			} else if (src_x % 2 == 0 && dest_x % 2 == 1
				   && dest_width % 2 == 0) {
				/* Input Data format = RGB565 */
				ulImgMode = IMG_MODE_OPAQUE_RGB565RGB_TO_RGB;

				dest_x--;
				dest_width += 2;
				src_x_F = src_x;
				src_y_F = src_y;
				src_x = dest_x;
				src_y = dest_y;
				src_width = dest_width;
				src_height = dest_height;
				ulSrcScreenWidth =
				    FRONT_WIDTH * BITS_PER_PIXEL / 8;
				if (DispFrame == FB_FRAME_NO_A) {
					ulSrcStarAddrYRGB =
					    FrameBufB +
					    src_x * BITS_PER_PIXEL / 8 +
					    src_y * FRONT_WIDTH *
					    BITS_PER_PIXEL / 8;
				} else {
					ulSrcStarAddrYRGB =
					    FrameBufA +
					    src_x * BITS_PER_PIXEL / 8 +
					    src_y * FRONT_WIDTH *
					    BITS_PER_PIXEL / 8;
				}

				src_width_F =
				    pBldScreenList[index_BldScreenList].width;
				src_height_F = src_height;
				ulSrcScreenWidth_F =
				    pGLXWindowTable[index].pitch;
				ulSrcStarAddrYRGB_F =
				    pGLXWindowTable[index].writtenframe +
				    (src_x_F + pGLXWindowTable[index].x) * 2 +
				    (src_y_F +
				     pGLXWindowTable[index].y) *
				    ulSrcScreenWidth_F;
				ImgRequest(src_width_F, IMG_SRCHSIZE_F);
				ImgRequest(src_height_F, IMG_SRCVSIZE_F);
				ImgRequest(ulSrcScreenWidth_F, IMG_SRCSIZE_F);
				ImgRequest(ulSrcStarAddrYRGB_F,
					   IMG_SRCYRGBADR_F);

				ImgRequest(1, IMG_OFFSETX_F);
				ImgRequest(0, IMG_OFFSETY_F);
				ImgRequest(256, IMG_HSTEP);
				ImgRequest(256, IMG_VSTEP);
				ImgRequest(64, IMG_HFOLD);
				ImgRequest(64, IMG_VFOLD);
			} else {
				unsigned char *srcp, *destp;
				int src_pitch = pGLXWindowTable[index].pitch;
				int dest_pitch =
				    FRONT_WIDTH * BITS_PER_PIXEL / 8;

				srcp =
				    GLXSmemV +
				    (pGLXWindowTable[index].writtenframe -
				     GLXSmem);
				if (DispFrame == FB_FRAME_NO_A) {
					destp = FrameBufBV;
				} else {
					destp = FrameBufAV;
				}

				/* Write any error processes if it is necessary
				 */

				qfb_copy_rect(srcp, src_x, src_y, src_pitch,
					      destp, dest_x, dest_y, dest_pitch,
					      dest_width, dest_height);

				index_BldScreenList++;
				unexclude();
				goto LOOP_COPY_DIRECT;
			}
#endif				/* PILE_3D_SCREEN */
			break;
		}
#endif	/* ENABLE_3D */

	case BLD_SCRN_TYPE_IMAGE_ROT_OVL:
		/* YUV420 and YUV422 */
		if (pInterFb_BufInfo[ROT_readingframe].f_Rotator & 0x01) {
			ulSrcScreenWidth =
			    pInterFb_BufInfo[ROT_readingframe].Height;
			src_width = pInterFb_BufInfo[ROT_readingframe].Height;
			src_height = pInterFb_BufInfo[ROT_readingframe].Width;
		} else {
			ulSrcScreenWidth =
			    pInterFb_BufInfo[ROT_readingframe].Width;
			src_width = pInterFb_BufInfo[ROT_readingframe].Width;
			src_height = pInterFb_BufInfo[ROT_readingframe].Height;
		}

#if __YUV420
		/* Input Data format = YUV420 */
#ifdef LOWER_ROT_SCREEN
		ulImgMode = IMG_MODE_ZOOM_YUV420RGB_TO_RGB;
#else				/* LOWER_ROT_SCREEN */
		ulImgMode = IMG_MODE_YUV420_TO_RGB;
#endif				/* LOWER_ROT_SCREEN */
		ulSrcStarAddrU =
		    pInterFb_BufInfo[ROT_readingframe].bufAddr_CbCr +
		    src_x + src_y / 2 * ulSrcScreenWidth;
#else				/* __YUV420 */
		/* Input Data format = YUV422 */
#ifdef LOWER_ROT_SCREEN
		ulImgMode = IMG_MODE_ZOOM_YUV422RGB_TO_RGB;
#else				/* LOWER_ROT_SCREEN */
		ulImgMode = IMG_MODE_YUV422_TO_RGB;
#endif				/* LOWER_ROT_SCREEN */
		ulSrcStarAddrU =
		    pInterFb_BufInfo[ROT_readingframe].bufAddr_CbCr +
		    src_x + src_y * ulSrcScreenWidth;
#endif				/* __YUV420 */

		/* YUV420 and YUV422 */
		ulSrcStarAddrYRGB =
		    pInterFb_BufInfo[ROT_readingframe].bufAddr_Y +
		    src_x + src_y * ulSrcScreenWidth;
		ImgRequest(ulSrcStarAddrU, IMG_SRCUVADR_B);
#if PRINT_ROT_PARAMS
		printk(KERN_INFO
		       "*** mix_image: pinterFb_bufaddr->readingframe = %d\n",
		       ROT_readingframe);
#endif
#if PRINT_ROT_PARAMS==2
		printk(KERN_INFO
		       "*** mix_image: pInterFb_BufInfo[%ld].Width = %d\n",
		       ROT_readingframe,
		       pInterFb_BufInfo[ROT_readingframe].Width);
		printk(KERN_INFO
		       "*** mix_image: pInterFb_BufInfo[%ld].Height = %d\n",
		       ROT_readingframe,
		       pInterFb_BufInfo[ROT_readingframe].Height);
		printk(KERN_INFO
		       "*** mix_image: pInterFb_BufInfo[%ld].bufAddr_CbCr = 0x%lx\n",
		       ROT_readingframe,
		       pInterFb_BufInfo[ROT_readingframe].bufAddr_CbCr);
		printk(KERN_INFO
		       "*** mix_image: pInterFb_BufInfo[%ld].bufAddr_Y = 0x%lx\n",
		       ROT_readingframe,
		       pInterFb_BufInfo[ROT_readingframe].bufAddr_Y);

#if __YUV420
		printk(KERN_INFO "*** mix_image: set 0x%lx to IMG_MODE\n",
		       IMG_MODE_YUV420_TO_RGB);
#else				/* __YUV420 */
		printk(KERN_INFO "*** mix_image: set 0x%lx to IMG_MODE\n",
		       IMG_MODE_YUV422_TO_RGB);
#endif				/* __YUV420 */
		printk(KERN_INFO "*** mix_image: set 0x%lx to IMG_SRCUVADR_B\n",
		       ulSrcStarAddrU);
		printk(KERN_INFO
		       "*** mix_image: set 0x%lx to IMG_SRCYRGBADR_B\n",
		       ulSrcStarAddrYRGB);
		printk(KERN_INFO "*** mix_image: set 0x%lx to IMG_SRCSIZE_B\n",
		       ulSrcScreenWidth);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_DSTSIZE\n",
		       FRONT_WIDTH * BITS_PER_PIXEL / 8);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_SRCHSIZE_B\n",
		       src_width);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_DSTHSIZE\n",
		       dest_width);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_SRCVSIZE_B\n",
		       src_height);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_DSTVSIZE\n",
		       dest_height);
#endif				/* PRINT_ROT_PARAMS */

		/* OFFSETX/Y */
		ImgRequest(0, IMG_OFFSETX_F);
		ImgRequest(0, IMG_OFFSETY_F);
		/* H/VSTEP */
		ImgRequest((src_width * 256 / dest_width), IMG_HSTEP);
		ImgRequest((src_height * 256 / dest_height), IMG_VSTEP);
		/* H/VFOLD */
		ImgRequest((dest_width * 64 / src_width), IMG_HFOLD);
		ImgRequest((dest_height * 64 / src_height), IMG_VFOLD);

#if PRINT_ROT_PARAMS==2
		printk(KERN_INFO "*** mix_image: set %ld to IMG_SRCHSIZE_B\n",
		       src_width);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_DSTHSIZE\n",
		       dest_width);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_SRCVSIZE_B\n",
		       src_height);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_DSTVSIZE\n",
		       dest_height);
		printk(KERN_INFO "*** mix_image: set %ld to IMG_HSTEP\n",
		       (src_width * 256 / dest_width));
		printk(KERN_INFO "*** mix_image: set %ld to IMG_VSTEP\n",
		       (src_height * 256 / dest_width));
		printk(KERN_INFO "*** mix_image: set %ld to IMG_HFOLD\n",
		       (dest_width * 64 / src_width));
		printk(KERN_INFO "*** mix_image: set %ld to IMG_VFOLD\n\n",
		       (dest_height * 64 / src_width));
#endif				/* PRINT_ROT_PARAMS */

#ifdef LOWER_ROT_SCREEN
		ulSrcScreenWidth_F = FRONT_WIDTH_V * BITS_PER_PIXEL / 8;
		if (DispFrame == FB_FRAME_NO_A) {
			ulSrcStarAddrYRGB_F =
			    FrameBufB + src_x_F * BITS_PER_PIXEL / 8 +
			    src_y_F * ulSrcScreenWidth_F;
		} else {
			ulSrcStarAddrYRGB_F =
			    FrameBufA + src_x_F * BITS_PER_PIXEL / 8 +
			    src_y_F * ulSrcScreenWidth_F;
		}

		ImgRequest(qfb_t_color, IMG_MASKCOLR_F);
		ImgRequest(IMG_ALPHA_F_BIT, IMG_ALPHA_F);

		ImgRequest(ulSrcStarAddrYRGB_F, IMG_SRCYRGBADR_F);
		ImgRequest(ulSrcScreenWidth_F, IMG_SRCSIZE_F);
		ImgRequest(src_width_F, IMG_SRCHSIZE_F);
		ImgRequest(src_height_F, IMG_SRCVSIZE_F);
		ImgRequest(0x00000001, IMG_PEL_ENDIAN);
#endif				/* LOWER_ROT_SCREEN */

		break;

	case BLD_SCRN_TYPE_IMAGE_XV_OVL:
	case BLD_SCRN_TYPE_IMAGE_CURSOR:
	default:
		printk(KERN_ERR "fb: invalid data format\n");
		goto error_ret;
	}

	ImgRequest(ulImgMode, IMG_MODE);
	ImgRequest(ulSrcStarAddrYRGB, IMG_SRCYRGBADR_B);

	ImgRequest(ulSrcScreenWidth, IMG_SRCSIZE_B);
	ImgRequest(FRONT_WIDTH * BITS_PER_PIXEL / 8, IMG_DSTSIZE);

	ImgRequest(src_width, IMG_SRCHSIZE_B);
	ImgRequest(dest_width, IMG_DSTHSIZE);

	ImgRequest(src_height, IMG_SRCVSIZE_B);
	ImgRequest(dest_height, IMG_DSTVSIZE);

	if (DispFrame == FB_FRAME_NO_A) {
		ulDestStarAddr = FrameBufB + dest_x * BITS_PER_PIXEL / 8
		    + dest_y * FRONT_WIDTH * BITS_PER_PIXEL / 8;
	} else {
		ulDestStarAddr = FrameBufA + dest_x * BITS_PER_PIXEL / 8
		    + dest_y * FRONT_WIDTH * BITS_PER_PIXEL / 8;
	}
	ImgRequest(ulDestStarAddr, IMG_DSTYRGBADR);

	ImgRequest(IMG_ENSETSTAT_BIT | IMG_ENSETERROR_BIT | IMG_ENSETSTOP_BIT,
		   IMG_ENSET);

	/* Start IMG */

	index_BldScreenList++;
	ImgRequest(IMG_REQ_BIT, IMG_REQ);

#ifdef CONFIG_MP200_IMG
	if (pBldScreenList[index_BldScreenList].transfer ==
	    BLD_SCRN_TYPE_ENDMARK) {
		qIMG_req[index_qIMG_req].lastLayer = 1;
	} else {
		qIMG_req[index_qIMG_req].lastLayer = 0;
	}
	qIMG_req[index_qIMG_req].callback = (void *)img_irq_handler;

	mp200_img_preferred_regist((struct mp200_img_req
				    *)(&qIMG_req[index_qIMG_req]));
#endif				/* CONFIG_MP200_IMG */

	return 1;

      error_ret:
	index_BldScreenList = 0;
	override_BldScreenList = 1;
	return 0;
}

static inline void change_frame()
{
	if (DispFrame == FB_FRAME_NO_B) {
		/* switch frame A */
		writel(LCD_FLAME_A, LCDCMmioV + LCD_FRAMESEL);
		DispFrame = FB_FRAME_NO_A;
	} else {
		/* switch frame B */
		writel(LCD_FLAME_B, LCDCMmioV + LCD_FRAMESEL);
		DispFrame = FB_FRAME_NO_B;
	}
}

static inline void start_lcd()
{
	writel(LCD_BUSSEL_AHB, LCDCMmioV + LCD_BUSSEL);
	writel(LCD_LCDOUT_BIT, LCDCMmioV + LCD_LCDOUT);
}

static inline void stop_lcd()
{
	writel(0, LCDCMmioV + LCD_LCDOUT);
}

static void exclude()
{
	if (pBldScreenList[index_BldScreenList].exclude) {
		switch (pBldScreenList[index_BldScreenList].image) {
#if ENABLE_3D
		case BLD_SCRN_TYPE_IMAGE_3D:
			{
				int i =
				    pBldScreenList[index_BldScreenList].
				    index_GLXWindowTable;
				pGLXWindowTable[i].readingframe =
				    pGLXWindowTable[i].writtenframe;
				pGLXWindowTable[i].swapinhibit = 1;
				pGLXWindowTable[i].readingframe =
				    pGLXWindowTable[i].writtenframe;
				break;
			}
#endif	/* ENABLE_3D */
		default:
			break;
		}
	}
}

#ifdef CONFIG_MP200_IMG
void unexclude()
#else				/* CONFIG_MP200_IMG */
static void unexclude()
#endif				/* CONFIG_MP200_IMG */
{
	if (index_BldScreenList > 0) {
		if (pBldScreenList[index_BldScreenList - 1].unexclude) {
			switch (pBldScreenList[index_BldScreenList - 1].image) {
#if ENABLE_3D
			case BLD_SCRN_TYPE_IMAGE_3D:
				{
					int i =
					    pBldScreenList[index_BldScreenList -
							   1].
					    index_GLXWindowTable;
					pGLXWindowTable[i].updated &= 2;
					pGLXWindowTable[i].swapinhibit = 0;
					break;
				}
#endif	/* ENABLE_3D */
			default:
				break;
			}
		}
	}
}
