linux/drivers/video/fbdev/sis/sis.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * SiS 300/540/630[S]/730[S],
 * SiS 315[E|PRO]/550/[M]65x/[M]661[F|M]X/740/[M]741[GX]/330/[M]76x[GX],
 * XGI V3XT/V5/V8, Z7
 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3
 *
 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
 */

#ifndef _SIS_H_
#define _SIS_H_

#include <video/sisfb.h>

#include "vgatypes.h"
#include "vstruct.h"

#define VER_MAJOR
#define VER_MINOR
#define VER_LEVEL

#include <linux/spinlock.h>

#ifdef CONFIG_COMPAT
#define SIS_NEW_CONFIG_COMPAT
#endif	/* CONFIG_COMPAT */

#undef SISFBDEBUG

#ifdef SISFBDEBUG
#define DPRINTK
#define TWDEBUG
#else
#define DPRINTK(fmt, args...)
#define TWDEBUG(x)
#endif

#define SISFAIL(x)

/* To be included in pci_ids.h */
#ifndef PCI_DEVICE_ID_SI_650_VGA
#define PCI_DEVICE_ID_SI_650_VGA
#endif
#ifndef PCI_DEVICE_ID_SI_650
#define PCI_DEVICE_ID_SI_650
#endif
#ifndef PCI_DEVICE_ID_SI_651
#define PCI_DEVICE_ID_SI_651
#endif
#ifndef PCI_DEVICE_ID_SI_740
#define PCI_DEVICE_ID_SI_740
#endif
#ifndef PCI_DEVICE_ID_SI_330
#define PCI_DEVICE_ID_SI_330
#endif
#ifndef PCI_DEVICE_ID_SI_660_VGA
#define PCI_DEVICE_ID_SI_660_VGA
#endif
#ifndef PCI_DEVICE_ID_SI_661
#define PCI_DEVICE_ID_SI_661
#endif
#ifndef PCI_DEVICE_ID_SI_741
#define PCI_DEVICE_ID_SI_741
#endif
#ifndef PCI_DEVICE_ID_SI_660
#define PCI_DEVICE_ID_SI_660
#endif
#ifndef PCI_DEVICE_ID_SI_760
#define PCI_DEVICE_ID_SI_760
#endif
#ifndef PCI_DEVICE_ID_SI_761
#define PCI_DEVICE_ID_SI_761
#endif

#ifndef PCI_VENDOR_ID_XGI
#define PCI_VENDOR_ID_XGI
#endif

#ifndef PCI_DEVICE_ID_XGI_20
#define PCI_DEVICE_ID_XGI_20
#endif

#ifndef PCI_DEVICE_ID_XGI_40
#define PCI_DEVICE_ID_XGI_40
#endif

/* To be included in fb.h */
#ifndef FB_ACCEL_SIS_GLAMOUR_2
#define FB_ACCEL_SIS_GLAMOUR_2
#endif
#ifndef FB_ACCEL_SIS_XABRE
#define FB_ACCEL_SIS_XABRE
#endif
#ifndef FB_ACCEL_XGI_VOLARI_V
#define FB_ACCEL_XGI_VOLARI_V
#endif
#ifndef FB_ACCEL_XGI_VOLARI_Z
#define FB_ACCEL_XGI_VOLARI_Z
#endif

/* ivideo->caps */
#define HW_CURSOR_CAP
#define TURBO_QUEUE_CAP
#define AGP_CMD_QUEUE_CAP
#define VM_CMD_QUEUE_CAP
#define MMIO_CMD_QUEUE_CAP

/* For 300 series */
#define TURBO_QUEUE_AREA_SIZE
#define HW_CURSOR_AREA_SIZE_300

/* For 315/Xabre series */
#define COMMAND_QUEUE_AREA_SIZE
#define COMMAND_QUEUE_AREA_SIZE_Z7
#define HW_CURSOR_AREA_SIZE_315
#define COMMAND_QUEUE_THRESHOLD

#define SIS_OH_ALLOC_SIZE
#define SENTINEL

#define SEQ_ADR
#define SEQ_DATA
#define DAC_ADR
#define DAC_DATA
#define CRTC_ADR
#define CRTC_DATA
#define DAC2_ADR
#define DAC2_DATA
#define VB_PART1_ADR
#define VB_PART1_DATA
#define VB_PART2_ADR
#define VB_PART2_DATA
#define VB_PART3_ADR
#define VB_PART3_DATA
#define VB_PART4_ADR
#define VB_PART4_DATA

#define SISSR
#define SISCR
#define SISDACA
#define SISDACD
#define SISPART1
#define SISPART2
#define SISPART3
#define SISPART4
#define SISPART5
#define SISDAC2A
#define SISDAC2D
#define SISMISCR
#define SISMISCW
#define SISINPSTAT
#define SISPEL
#define SISVGAENABLE
#define SISVID
#define SISCAP

#define IND_SIS_PASSWORD
#define IND_SIS_COLOR_MODE
#define IND_SIS_RAMDAC_CONTROL
#define IND_SIS_DRAM_SIZE
#define IND_SIS_MODULE_ENABLE
#define IND_SIS_PCI_ADDRESS_SET
#define IND_SIS_TURBOQUEUE_ADR
#define IND_SIS_TURBOQUEUE_SET
#define IND_SIS_POWER_ON_TRAP
#define IND_SIS_POWER_ON_TRAP2
#define IND_SIS_CMDQUEUE_SET
#define IND_SIS_CMDQUEUE_THRESHOLD

#define IND_SIS_AGP_IO_PAD

#define SIS_CRT2_WENABLE_300
#define SIS_CRT2_WENABLE_315

#define SIS_PASSWORD

#define SIS_INTERLACED_MODE
#define SIS_8BPP_COLOR_MODE
#define SIS_15BPP_COLOR_MODE
#define SIS_16BPP_COLOR_MODE
#define SIS_32BPP_COLOR_MODE

#define SIS_ENABLE_2D

#define SIS_MEM_MAP_IO_ENABLE
#define SIS_PCI_ADDR_ENABLE

#define SIS_AGP_CMDQUEUE_ENABLE
#define SIS_VRAM_CMDQUEUE_ENABLE
#define SIS_MMIO_CMD_ENABLE
#define SIS_CMD_QUEUE_SIZE_512k
#define SIS_CMD_QUEUE_SIZE_1M
#define SIS_CMD_QUEUE_SIZE_2M
#define SIS_CMD_QUEUE_SIZE_4M
#define SIS_CMD_QUEUE_RESET
#define SIS_CMD_AUTO_CORR

#define SIS_CMD_QUEUE_SIZE_Z7_64k
#define SIS_CMD_QUEUE_SIZE_Z7_128k

#define SIS_SIMULTANEOUS_VIEW_ENABLE
#define SIS_MODE_SELECT_CRT2
#define SIS_VB_OUTPUT_COMPOSITE
#define SIS_VB_OUTPUT_SVIDEO
#define SIS_VB_OUTPUT_SCART
#define SIS_VB_OUTPUT_LCD
#define SIS_VB_OUTPUT_CRT2
#define SIS_VB_OUTPUT_HIVISION

#define SIS_VB_OUTPUT_DISABLE
#define SIS_DRIVER_MODE

#define SIS_VB_COMPOSITE
#define SIS_VB_SVIDEO
#define SIS_VB_SCART
#define SIS_VB_LCD
#define SIS_VB_CRT2
#define SIS_CRT1
#define SIS_VB_HIVISION
#define SIS_VB_YPBPR
#define SIS_VB_TV

#define SIS_EXTERNAL_CHIP_MASK
#define SIS_EXTERNAL_CHIP_SIS301
#define SIS_EXTERNAL_CHIP_LVDS
#define SIS_EXTERNAL_CHIP_TRUMPION
#define SIS_EXTERNAL_CHIP_LVDS_CHRONTEL
#define SIS_EXTERNAL_CHIP_CHRONTEL
#define SIS310_EXTERNAL_CHIP_LVDS
#define SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL

#define SIS_AGP_2X

/* vbflags, private entries (others in sisfb.h) */
#define VB_CONEXANT
#define VB_TRUMPION
#define VB_302ELV
#define VB_301
#define VB_301B
#define VB_302B
#define VB_30xBDH
#define VB_LVDS
#define VB_CHRONTEL
#define VB_301LV
#define VB_302LV
#define VB_301C

#define VB_SISBRIDGE
#define VB_VIDEOBRIDGE

/* vbflags2 (static stuff only!) */
#define VB2_SISUMC
#define VB2_301
#define VB2_301B
#define VB2_301C
#define VB2_307T
#define VB2_302B
#define VB2_301LV
#define VB2_302LV
#define VB2_302ELV
#define VB2_307LV
#define VB2_30xBDH
#define VB2_CONEXANT
#define VB2_TRUMPION
#define VB2_LVDS
#define VB2_CHRONTEL

#define VB2_SISLVDSBRIDGE
#define VB2_SISTMDSBRIDGE
#define VB2_SISBRIDGE

#define VB2_SISTMDSLCDABRIDGE
#define VB2_SISLCDABRIDGE

#define VB2_SISHIVISIONBRIDGE
#define VB2_SISYPBPRBRIDGE
#define VB2_SISYPBPRARBRIDGE
#define VB2_SISTAP4SCALER
#define VB2_SISTVBRIDGE

#define VB2_SISVGA2BRIDGE

#define VB2_VIDEOBRIDGE

#define VB2_30xB
#define VB2_30xBLV
#define VB2_30xC
#define VB2_30xCLV
#define VB2_SISEMIBRIDGE
#define VB2_LCD162MHZBRIDGE
#define VB2_LCDOVER1280BRIDGE
#define VB2_LCDOVER1600BRIDGE
#define VB2_RAMDAC202MHZBRIDGE

/* I/O port access functions */

void SiS_SetReg(SISIOADDRESS, u8, u8);
void SiS_SetRegByte(SISIOADDRESS, u8);
void SiS_SetRegShort(SISIOADDRESS, u16);
void SiS_SetRegLong(SISIOADDRESS, u32);
void SiS_SetRegANDOR(SISIOADDRESS, u8, u8, u8);
void SiS_SetRegAND(SISIOADDRESS, u8, u8);
void SiS_SetRegOR(SISIOADDRESS, u8, u8);
u8 SiS_GetReg(SISIOADDRESS, u8);
u8 SiS_GetRegByte(SISIOADDRESS);
u16 SiS_GetRegShort(SISIOADDRESS);
u32 SiS_GetRegLong(SISIOADDRESS);

/* Chrontel TV, DDC and DPMS functions */
/* from init.c */
bool		SiSInitPtr(struct SiS_Private *SiS_Pr);
unsigned short	SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, bool FSTN,
				unsigned short CustomT, int LCDwith, int LCDheight,
				unsigned int VBFlags2);
unsigned short	SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, unsigned int VBFlags2);
unsigned short	SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, unsigned int VBFlags2);

void		SiS_DisplayOn(struct SiS_Private *SiS_Pr);
void		SiS_DisplayOff(struct SiS_Private *SiS_Pr);
void		SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
void		SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
void		SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
unsigned short	SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
bool		SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);

bool		SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
				unsigned short *ModeIdIndex);
unsigned short	SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
unsigned short  SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
unsigned short  SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
unsigned short	SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
unsigned short	SiS_GetOffset(struct SiS_Private *SiS_Pr,unsigned short ModeNo,
				unsigned short ModeIdIndex, unsigned short RRTI);
#ifdef CONFIG_FB_SIS_300
void		SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
				unsigned short *idx2);
unsigned short	SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2);
unsigned short	SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index);
#endif
void		SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
bool		SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
void		SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
void		SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
void		SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
				int yres, struct fb_var_screeninfo *var, bool writeres);

/* From init301.c: */
extern void		SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex, int chkcrt2mode);
extern void		SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
extern void		SiS_SetYPbPr(struct SiS_Private *SiS_Pr);
extern void		SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
extern void		SiS_UnLockCRT2(struct SiS_Private *SiS_Pr);
extern void		SiS_DisableBridge(struct SiS_Private *);
extern bool		SiS_SetCRT2Group(struct SiS_Private *, unsigned short);
extern unsigned short	SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
extern void		SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
extern unsigned short	SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex);
extern unsigned short	SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax);
extern unsigned short	SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
				unsigned short ModeIdIndex, unsigned short RRTI);
extern bool		SiS_IsVAMode(struct SiS_Private *);
extern bool		SiS_IsDualEdge(struct SiS_Private *);

#ifdef CONFIG_FB_SIS_300
extern unsigned int	sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
extern void		sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg,
				unsigned int val);
#endif
#ifdef CONFIG_FB_SIS_315
extern void		sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg,
				unsigned char val);
extern unsigned int	sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg);
#endif


/* MMIO access macros */
#define MMIO_IN8(base, offset)
#define MMIO_IN16(base, offset)
#define MMIO_IN32(base, offset)

#define MMIO_OUT8(base, offset, val)
#define MMIO_OUT16(base, offset, val)
#define MMIO_OUT32(base, offset, val)

/* Queue control MMIO registers */
#define Q_BASE_ADDR
#define Q_WRITE_PTR
#define Q_READ_PTR
#define Q_STATUS

#define MMIO_QUEUE_PHYBASE
#define MMIO_QUEUE_WRITEPORT
#define MMIO_QUEUE_READPORT

#ifndef FB_BLANK_UNBLANK
#define FB_BLANK_UNBLANK
#endif
#ifndef FB_BLANK_NORMAL
#define FB_BLANK_NORMAL
#endif
#ifndef FB_BLANK_VSYNC_SUSPEND
#define FB_BLANK_VSYNC_SUSPEND
#endif
#ifndef FB_BLANK_HSYNC_SUSPEND
#define FB_BLANK_HSYNC_SUSPEND
#endif
#ifndef FB_BLANK_POWERDOWN
#define FB_BLANK_POWERDOWN
#endif

enum _SIS_LCD_TYPE {};

enum _SIS_CMDTYPE {};

struct SIS_OH {};

struct SIS_OHALLOC {};

struct SIS_HEAP {};

/* Our "par" */
struct sis_video_info {};

/* from sis_accel.c */
extern void	fbcon_sis_fillrect(struct fb_info *info,
				const struct fb_fillrect *rect);
extern void	fbcon_sis_copyarea(struct fb_info *info,
				const struct fb_copyarea *area);
extern int	fbcon_sis_sync(struct fb_info *info);

/* Internal 2D accelerator functions */
extern int	sisfb_initaccel(struct sis_video_info *ivideo);
extern void	sisfb_syncaccel(struct sis_video_info *ivideo);

/* Internal general routines */
#ifdef CONFIG_FB_SIS_300
unsigned int	sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
void		sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val);
unsigned int	sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg);
#endif
#ifdef CONFIG_FB_SIS_315
void		sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val);
unsigned int	sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg);
#endif

/* SiS-specific exported functions */
void			sis_malloc(struct sis_memreq *req);
void			sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req);
void			sis_free(u32 base);
void			sis_free_new(struct pci_dev *pdev, u32 base);

/* Routines from init.c/init301.c */
extern unsigned short	SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, bool FSTN, unsigned short CustomT,
				int LCDwith, int LCDheight, unsigned int VBFlags2);
extern unsigned short	SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, unsigned int VBFlags2);
extern unsigned short	SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay,
				int VDisplay, int Depth, unsigned int VBFlags2);
extern void		SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
extern bool		SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
extern void		SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
extern void		SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);

extern bool		SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);

extern bool		sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
				int *htotal, int *vtotal, unsigned char rateindex);
extern int		sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
				unsigned char modeno, unsigned char rateindex);
extern int		sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
				unsigned char rateindex, struct fb_var_screeninfo *var);


#endif