/*
 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

/* Savage BIOS definitions */
#ifndef _SAVAGEVBE_H
#define _SAVAGEVBE_H

#define VBE_MODEL_TEXT 	0
#define VBE_MODEL_CGA 	1
#define VBE_MODEL_HERCULES 	2
#define VBE_MODEL_PLANAR 	3
#define VBE_MODEL_PACKED 	4
#define VBE_MODEL_256 	5
#define VBE_MODEL_RGB 	6
#define VBE_MODEL_YUV 	7

/*
 * VESA BIOS calling and completion codes
 */
#define VBE_FN_SUPPORTED    0x4F    /* AL=4F on return from all VBE functions */

#define VBE_SUCCESSFUL      0x00    /* AH=00 means function call successful */
#define VBE_FAILED          0x01    /* AH=01 Function call failed */
#define VBE_HW_NONSUPPORT   0x02    /* AH=01 BIOS supports fn, but HW doesn't */
#define VBE_INVALID_IN_MODE 0x03    /* AH=03 Function invalid in current mode */

#define VBE_RETCODE         0xFFFF  /* AX if VESA fn supported + retcode */
#define VBE_SUCCESS         0x004F  /* AH:AL=004F means 4Fxx VBE call succeeded */

/*
 *  Common BIOS functions
 */

#define BIOS_SET_VBE_MODE       0x4F02
#define BIOS_GET_VBE_MODE       0x4F03
#define BIOS_SVGA_STATE         0x4F04
#define BIOS_LOG_SCANLINE       0x4F06
#define BIOS_VBE_PM_SERVICE     0x4F10
#define S3_EXTBIOS_INFO         0x4F14  /* S3 Extended BIOS services */
#define BIOS_VBE_DDC            0x4F15

/*************************************************************************
 *     Defines for BIOS compliant with S3 (Mobile and Desktop) PCI Video
 *     Bios External Interface Specification, Core Revision 3.02+
 *
 *     e.g. used by Trio3D, GX-3
 *************************************************************************/
 
#define S3_GET_SVGA_BUF          0x0000
#define S3_SAVE_SVGA_STATE       0x0001
#define S3_RESTORE_SVGA_STATE    0x0002
/*
 * For S3_EXTBIOS_INFO (0x4F14) services
 */
#define S3_VBE_INFO         0x0000  /* fn0: Query S3/VBE info */

#define S3_SET_REFRESH      0x0001  /* fn1,sub0: Set Refresh Rate for Mode */
#define S3_GET_REFRESH      0x0101  /* fn1,sub1: Get Refresh Rate for Mode */
#define S3_QUERY_REFRESH    0x0201  /* fn1,sub2: Query Refresh Rates for Mode */

#define S3_QUERY_MODELIST   0x0202  /* fn2,sub2: Query Mode List */
#define S3_GET_EXT_MODEINFO 0x0302  /* fn2,sub3: Get Extended Mode Info */

#define S3_QUERY_ATTACHED   0x0004  /* fn4,sub0: Query detected displays */

#define S3_GET_ACTIVE_DISP  0x0103  /* fn3,sub1: Get Active Display */
#define S3_SET_ACTIVE_DISP  0x0003  /* fn3,sub0: Set Active Display */
#define S3_ALT_SET_ACTIVE_DISP  0x8003  /* fn8003,sub0: Alternate Set Active Display */

#define S3_SET_TV_CONFIG    0x0007  /* fn7,sub0: Set TV Configuration */
#define S3_GET_TV_CONFIG    0x0107  /* fn7,sub1: Get TV Configuration */


#define BIOS_CRT1_ONLY              0x01
#define BIOS_LCD_ONLY               0x02
#define BIOS_TV_NTSC                0x04
#define BIOS_TV_PAL                 0x08
#define BIOS_TV_ONLY                0x0c
#define BIOS_DVI_ONLY               0x20
#define BIOS_DEVICE_MASK            (BIOS_CRT1_ONLY|BIOS_LCD_ONLY|BIOS_TV_ONLY|BIOS_DVI_ONLY)

/*
 *  TV Technology Standards Supported
 *
 *  App format bit masks used when reporting TV standards SUPPORTED.
 *  GET_DEVICE_SUPPORT MBLESC #60
 */
#define S3_TVSTD_SUPPORT_NTSC   0x01
#define S3_TVSTD_SUPPORT_PAL    0x02
#define S3_TVSTD_SUPPORT_NTSCJ  0x04
#define S3_TVSTD_SUPPORT_PAL_M  0x08
#define S3_TVSTD_VALID_MASK     0x0F    /* SavageMX allows PAL-M */

/*
 * TVSIGNAL_TYPE is the specific value that is stored
 * in the hardware device extension.  NOT app format.
 */
typedef enum _TVSIGNAL_TYPE {
    TVSIGNAL_TYPE_COMP      = 0x00,/* undefined/unknown Composite */
    TVSIGNAL_TYPE_AYCOMP    = 0x01,
    TVSIGNAL_TYPE_ACCOMP    = 0x02,
    TVSIGNAL_TYPE_SVIDEO    = 0x03
} TVSIGNAL_TYPE, *PTVSIGNAL_TYPE;

/*
 *  TV Technology Standards Active (In Use)
 *
 *  Note that these are in App format, enumerated rather than bit masks.
 *  GET_TV_STANDARD MBLESC #34
 */
typedef enum _TVTECH_TYPE   {
    TVTECH_TYPE_UNKNOWN = 0x00,
    TVTECH_TYPE_NTSC,    
    TVTECH_TYPE_PAL,     
    TVTECH_TYPE_NTSCJ,   
    TVTECH_TYPE_INVALID
} TVTECH_TYPE, *PTVTECH_TYPE;


/*  TV Configuration Byte */
#define S3_TV_SIG_MASK      0x03    /* MASK for bits 1:0 TV Output Connector */
#define S3_TV_SIG_COMP      0x00    /* Bits[1:0] = [00] Unknown Composite */
#define S3_TV_SIG_AYCOMP    0x01    /* Bits[1:0] = [01] AY Composite output */
#define S3_TV_SIG_ACCOMP    0x02    /* Bits[1:0] = [10] AC Composite output */
#define S3_TV_SIG_SVIDEO    0x03    /* Bits[1:0] = [11] S-Video output */
#define S3_TV_TYPE_MASK     0x0C    /* MASK for bits 3:2 TV Type */
#define S3_TV_TYPE_NTSC_J   0x00    /* Bits[3:2] = [00] Japanese NTSC */
#define S3_TV_TYPE_NTSC_US  0x04    /* Bits[3:2] = [01] U.S. NTSC */
#define S3_TV_TYPE_PAL      0x08    /* Bits[3:2] = [10] PAL */
#define S3_TV_TYPE_EXTENDED 0x0C    /* Bits[3:2] = [11] Extended TV config */
#define S3_TV_FORCEPAN      0x10    /* Bit[4] Force panning 480 NTSC, 600 PAL */
#define S3_TV_UNDERSCAN     0x20    /* Bit[5] Underscan 480 NTSC, 600 PAL */
#define S3_TV_8DOT_TEXT     0x40    /* Bit[6] Force 8-dot text mode. */
                                    /* Bit[7] Reserved. */
#define S3_TV_USCANPAN      0x30    /* Mask for Bits[5:4] */

#define TVChip_BT869    0xB869
#define TVChip_CH7009   0x7009
#define TVChip_CH7005   0x7005
#define TVChip_VT1621   0x1621

#endif

