/*
 * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
 *
 * @APPLE_LICENSE_HEADER_START@
 * 
 * The contents of this file constitute Original Code as defined in and
 * are subject to the Apple Public Source License Version 1.1 (the
 * "License").  You may not use this file except in compliance with the
 * License.  Please obtain a copy of the License at
 * http://www.apple.com/publicsource and read it before using this file.
 * 
 * This Original Code and all software distributed under the License are
 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @APPLE_LICENSE_HEADER_END@
 */


#ifndef __IVAD__
#define __IVAD__

#include <libkern/OSTypes.h>


/*
	IIC device addresses, subaddresses, and register constants
*/

enum {
	iicIVAD				=	0x8C,
	iicEEPROM			=	0xA6
};

enum {
	kIVAD1SupportedModes	= 3,
	kIVAD2SupportedModes	= 5
};

enum {
	kIVADContrast		=	0x00,
	kIVADDrive1			=	0x01,
	kIVADDrive2			=	0x02,
	kIVADDrive3			=	0x03,
	kIVADCutoff1		=	0x04,
	kIVADCutoff2		=	0x05,
	kIVADCutoff3		=	0x06,
	kIVADHPhase			=	0x07,
	kIVADVRamp			=	0x08,
	kIVADVPosition		=	0x09,
	kIVADSCorrection	=	0x0A,
	kIVADKeystone		=	0x0B,
	kIVADEWAmplitude	=	0x0C,
	kIVADHAmplitude		=	0x0D,
	kIVADSidePinBalance	=	0x0E,
	kIVADParallelogram	=	0x0F,
	kIVADVBLDCLevel		=	0x10,
	kIVADBrightness		=	0x11,
	kIVADTilt			=	0x12,
	kIVADPLL1			=	0x13,
	kNumIVADRegisters
};

enum {
	kIVADPWMCutoff1		=	0x00,
	kIVADPWMCutoff2		=	0x01,
	kIVADPWMCutoff3		=	0x02,
	kIVADPWMTilt		=	0x03,
};

enum {
	kVideoEnable		=	0x80,				// (R00)	master enable
	kGainWin			= 	0x40,				// (R10)	gain (brightness) boost
	kDegauss			=	0x80				// (R12)	degauss control
};


struct IVAD {
	UInt8				contrast;
	UInt8				drive1;
	UInt8				drive2;
	UInt8				drive3;
	UInt8				cutoff1;
	UInt8				cutoff2;
	UInt8				cutoff3;
	UInt8				hPhase;					// parameter a.k.a. horizontal position
	UInt8				vRamp;					// parameter a.k.a. vertical size
	UInt8				vPosition;
	UInt8				sCorrection;
	UInt8				keystone;				// parameter a.k.a. trapezoid
	UInt8				ewAmplitude;			// parameter a.k.a. pincushion
	UInt8				hAmplitude;				// parameter a.k.a. horizontal size
	UInt8				sidePinBalance;
	UInt8				parallelogram;
	UInt8				vblDCLevel;
	UInt8				brightness;
	UInt8				tilt;					// parameter a.k.a. rotation
	UInt8				pll1FVC;
};
typedef struct IVAD IVAD;


/*
	EEPROM memory map template
*/

enum {
	kIVADStdTemplateID = 0x5A
};


struct ModalDisplayParams {
	UInt8				horizontalPosition;
	UInt8				horizontalSize;
	UInt8				verticalPosition;
	UInt8				verticalSize;
	UInt8				keystone;
	UInt8				pincushion;
};
typedef struct ModalDisplayParams ModalDisplayParams;

struct ModalWidthDisplayParams {
	UInt32						width;
	ModalDisplayParams			mode;
};
typedef struct ModalWidthDisplayParams ModalWidthDisplayParams;

struct IVAD1_AmodalDisplayParams {
	UInt8				contrast;
	UInt8				brightness;
	UInt8				drive1;
	UInt8				drive2;
	UInt8				drive3;
	UInt8				cutoff1;
	UInt8				cutoff2;
	UInt8				cutoff3;
	UInt8				sCorrection;
	UInt8				sidePinBalance;
	UInt8				parallelogram;
	UInt8				tilt;
	UInt8				vblDCLevel;
	UInt8				pll1FVC;
};
typedef struct IVAD1_AmodalDisplayParams IVAD1_AmodalDisplayParams;

struct IVAD2_AmodalDisplayParams {
	UInt8				contrast;
	UInt8				brightness;
	UInt8				drive1;
	UInt8				drive2;
	UInt8				drive3;
	UInt8				cutoff1;
	UInt8				cutoff2;
	UInt8				cutoff3;
	UInt8				sCorrection;
	UInt8				sidePinBalance;
	UInt8				parallelogram;
	UInt8				tilt;
	UInt8				vblDCLevel;
	UInt8				pll1FVC;
	UInt8				topCornerPincushion;
	UInt8				bottomCornerPincushion;
	UInt8				topCornerBow;
	UInt8				bottomCornerBow;
	UInt8				hehtCompGain;
	UInt8				vehtCompGain;
};
typedef struct IVAD2_AmodalDisplayParams IVAD2_AmodalDisplayParams;

struct BriteScreenParams {
	UInt8				contrast;
	UInt8				brightness;
	UInt8				drive1;
	UInt8				drive2;
	UInt8				drive3;
	UInt8				cutoff1;
	UInt8				cutoff2;
	UInt8				cutoff3;
	Boolean				gainBoost;
};
typedef struct BriteScreenParams BriteScreenParams;


struct AdjustmentRange {
	UInt8				min;
	UInt8				max;
};
typedef struct AdjustmentRange AdjustmentRange;

struct AdjustmentLimits {
	AdjustmentRange		contrast;
	AdjustmentRange		brightness;
	AdjustmentRange		horizontalPosition;
	AdjustmentRange		horizontalSize;
	AdjustmentRange		verticalPosition;
	AdjustmentRange		verticalSize;
	AdjustmentRange		keystone;
	AdjustmentRange		pincushion;
	AdjustmentRange		parallelogram;
	AdjustmentRange		tilt;
};
typedef struct AdjustmentLimits AdjustmentLimits;


struct IVAD1_EEPROM {
	ModalDisplayParams					modeParams[ kIVAD1SupportedModes ];
	AdjustmentLimits					userLimits;
	IVAD1_AmodalDisplayParams			stdParams;
	BriteScreenParams					briteParams;
	UInt8								id;
};
typedef struct IVAD1_EEPROM IVAD1_EEPROM;

struct IVAD2_EEPROM {
	ModalDisplayParams					modeParams[ kIVAD2SupportedModes ];
	UInt8								pad1[ 8 ];
	IVAD2_AmodalDisplayParams			stdParams;
	UInt8								pad2;
	UInt8								autoSizing;
	UInt8								autoWhiteBalance;
	UInt8								id;
	UInt8								jumperCheckData;
	AdjustmentLimits					userLimits;
	BriteScreenParams					briteParams;
};
typedef struct IVAD2_EEPROM IVAD2_EEPROM;


/*
	IVAD user preferences template (for persistent NameRegistry property)
*/

struct IVAD1UserPrefs {
	ModalDisplayParams		modeParams[ kIVAD1SupportedModes ];
	UInt8					contrast;
	UInt8					brightness;
	UInt8					parallelogram;
	UInt8					tilt;
};
typedef struct IVAD1UserPrefs IVAD1UserPrefs;

struct IVAD2UserPrefs {
	UInt8							contrast;
	UInt8							brightness;
	UInt8							parallelogram;
	UInt8							tilt;
	UInt8							pad;
	UInt8							modeParamsCount;
	ModalWidthDisplayParams			modeParams[ kVariableLengthArray ];
};
typedef struct IVAD2UserPrefs IVAD2UserPrefs;

#endif /* __IVAD__ */
