📄 voyager.c
字号:
/*
* linux/drivers/video/voyager.c -- Silicon Motion, Inc. Voyager GX frame buffer device
*
* Copyright (C) 2003 Silicon Motion, Inc.
* Ge Wang, gewang@siliconmotion.com
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include <linux/config.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <asm/io.h>
#ifdef CONFIG_FB_SM501_KERNEL_2_4_X
#include <asm/irq.h>
#include <asm/pgtable.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <video/fbcon.h>
#include <video/fbcon-cfb8.h>
#include <video/fbcon-cfb16.h>
#include <video/fbcon-cfb32.h>
#endif //CONFIG_FB_SM501_KERNEL_2_4_X
#include "voyager.h"
#include "sm501hw.h"
#include "smi2d.h"
char *SMI_RegBaseAddress; // point to virtual Memory Map IO starting address
char *SMI_VRAMBaseAddress; // point to virtual video memory starting address
static struct par_info hw; // used to record hardware information
// Mode table.
mode_table_t mode_table[] =
{
//----------------------------------------------------------------------------------------
// H. H. H. H. H. V. V. V. V. V. Pixel H. V.
// tot. disp. sync sync sync tot. disp. sync sync sinc clock freq. freq.
// end start wdth polarity end start hght polarity
//----------------------------------------------------------------------------------------
// 640 x 480
{ 800, 640, 656, 96, NEGATIVE, 525, 480, 490, 2, NEGATIVE, 25175000, 31469, 60 },
{ 832, 640, 664, 40, NEGATIVE, 520, 480, 489, 3, NEGATIVE, 31500000, 37861, 72 },
{ 840, 640, 656, 64, NEGATIVE, 500, 480, 481, 3, NEGATIVE, 31500000, 37500, 75 },
{ 832, 640, 696, 56, NEGATIVE, 509, 480, 481, 3, NEGATIVE, 36000000, 43269, 85 },
// 800 x 600
{ 1024, 800, 824, 72, POSITIVE, 625, 600, 601, 2, POSITIVE, 36000000, 35156, 56 },
{ 1056, 800, 840, 128, POSITIVE, 628, 600, 601, 4, POSITIVE, 40000000, 37879, 60 },
{ 1040, 800, 856, 120, POSITIVE, 666, 600, 637, 6, POSITIVE, 50000000, 48077, 72 },
{ 1056, 800, 816, 80, POSITIVE, 625, 600, 601, 3, POSITIVE, 49500000, 46875, 75 },
{ 1048, 800, 832, 64, POSITIVE, 631, 600, 601, 3, POSITIVE, 56250000, 53674, 85 },
// 1024 x 768
{ 1344, 1024, 1048, 136, NEGATIVE, 806, 768, 771, 6, NEGATIVE, 65000000, 48363, 60 },
{ 1328, 1024, 1048, 136, NEGATIVE, 806, 768, 771, 6, NEGATIVE, 75000000, 56476, 70 },
{ 1312, 1024, 1040, 96, POSITIVE, 800, 768, 769, 3, POSITIVE, 78750000, 60023, 75 },
{ 1376, 1024, 1072, 96, POSITIVE, 808, 768, 769, 3, POSITIVE, 94500000, 68677, 85 },
// End of table.
{ 0, 0, 0, 0, NEGATIVE, 0, 0, 0, 0, NEGATIVE, 0, 0, 0 },
};
/**********************************************************************
*
* regRead8
*
* Purpose
* Read the value of the 8-bit register specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to read
*
* [out]
* None
*
* Returns
* Value of 8-bit register specified by nOffset
*
**********************************************************************/
unsigned char regRead8(unsigned long nOffset)
{
return *(volatile unsigned char *)(SMI_RegBaseAddress+nOffset);
}
/**********************************************************************
*
* regRead16
*
* Purpose
* Read the value of the 16-bit register specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to read
*
* [out]
* None
*
* Returns
* Value of 16-bit register specified by nOffset
*
**********************************************************************/
unsigned short regRead16(unsigned long nOffset)
{
return *(volatile unsigned short *)(SMI_RegBaseAddress+nOffset);
}
/**********************************************************************
*
* regRead32
*
* Purpose
* Read the value of the 32-bit register specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to read
*
* [out]
* None
*
* Returns
* Value of 32-bit register specified by nOffset
*
**********************************************************************/
unsigned long regRead32(unsigned long nOffset)
{
return *(volatile unsigned long *)(SMI_RegBaseAddress+nOffset);
}
/**********************************************************************
*
* regWrite8
*
* Purpose
* Write the 8-bit value, nData, to the 8-bit register specified by
* nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void regWrite8(unsigned long nOffset, unsigned char nData)
{
*(volatile unsigned char *)(SMI_RegBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* regWrite16
*
* Purpose
* Write the 16-bit value, nData, to the 16-bit register specified by
* nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void regWrite16(unsigned long nOffset, unsigned short nData)
{
*(volatile unsigned short *)(SMI_RegBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* regWrite32
*
* Purpose
* Write the 32-bit value, nData, to the 32-bit register specified by
* nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of register to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void regWrite32(unsigned long nOffset, unsigned long nData)
{
*(volatile unsigned long *)(SMI_RegBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* memRead8
*
* Purpose
* Read the value of the 8-bit memory location specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to read
*
* [out]
* None
*
* Returns
* Value of 8-bit memory location specified by nOffset
*
**********************************************************************/
unsigned char memRead8(unsigned long nOffset)
{
return *(volatile unsigned char *)(SMI_VRAMBaseAddress+nOffset);
}
/**********************************************************************
*
* memRead16
*
* Purpose
* Read the value of the 16-bit memory location specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to read
*
* [out]
* None
*
* Returns
* Value of 16-bit memory location specified by nOffset
*
**********************************************************************/
unsigned short memRead16(unsigned long nOffset)
{
return *(volatile unsigned short *)(SMI_VRAMBaseAddress+nOffset);
}
/**********************************************************************
*
* memRead32
*
* Purpose
* Read the value of the 32-bit memory location specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to read
*
* [out]
* None
*
* Returns
* Value of 32-bit memory location specified by nOffset
*
**********************************************************************/
unsigned long memRead32(unsigned long nOffset)
{
return *(volatile unsigned long *)(SMI_VRAMBaseAddress+nOffset);
}
/**********************************************************************
*
* memWrite8
*
* Purpose
* Write the 8-bit value, nData, to the 8-bit memory location
* specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void memWrite8(unsigned long nOffset, unsigned char nData)
{
*(volatile unsigned char *)(SMI_VRAMBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* memWrite16
*
* Purpose
* Write the 16-bit value, nData, to the 16-bit memory location
* specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void memWrite16(unsigned long nOffset, unsigned short nData)
{
*(volatile unsigned short *)(SMI_VRAMBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* memWrite32
*
* Purpose
* Write the 32-bit value, nData, to the 32-bit memory location
* specified by nOffset
*
* Parameters
* [in]
* nOffset - zero-based offset of memory location to write
* nData - value to be written
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void memWrite32(unsigned long nOffset, unsigned long nData)
{
*(volatile unsigned long *)(SMI_VRAMBaseAddress+nOffset) = nData;
}
/**********************************************************************
*
* panelPlaneEnable
*
* Purpose
* Enable panel graphics plane
*
* Parameters
* [in]
* None
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void panelPlaneEnable(void)
{
unsigned long panel_ctrl = 0;
panel_ctrl = regRead32(PANEL_DISPLAY_CTRL);
panel_ctrl = FIELD_SET(panel_ctrl, PANEL_DISPLAY_CTRL, PLANE, ENABLE);
regWrite32(PANEL_DISPLAY_CTRL, panel_ctrl);
}
/**********************************************************************
*
* panelPlaneDisable
*
* Purpose
* Disable panel graphics plane
*
* Parameters
* [in]
* None
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
void panelPlaneDisable(void)
{
unsigned long panel_ctrl = 0;
panel_ctrl = regRead32(PANEL_DISPLAY_CTRL);
panel_ctrl = FIELD_SET(panel_ctrl, PANEL_DISPLAY_CTRL, PLANE, DISABLE);
regWrite32(PANEL_DISPLAY_CTRL, panel_ctrl);
}
/**********************************************************************
*
* panelWaitVSync
*
* Purpose
* Wait for the specified number of panel Vsyncs
*
* Parameters
* [in]
* vsync_count - Number of Vsyncs to wait
*
* [out]
* None
*
* Returns
* Nothing
*
**********************************************************************/
static void panelWaitVSync(int vsync_count)
{
unsigned long status;
unsigned long timeout;
while (vsync_count-- > 0)
{
/* Wait for end of vsync */
timeout = 0;
do
{
status = FIELD_GET(regRead32(CMD_INTPR_STATUS),
CMD_INTPR_STATUS,
PANEL_SYNC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -