/*
 * Copyright (C) 2014 Apple Inc. All rights reserved.
 *
 * This document is the property of Apple Inc.
 * It is considered confidential and proprietary.
 *
 * This document may not be reproduced or transmitted in any form,
 * in whole or in part, without the express written permission of
 * Apple Inc.
 *
 */

#ifndef __DIALOG_D2231_H
#define __DIALOG_D2231_H

#define PMU_HAS_SWI		0
#define PMU_HAS_DWI		0
#define PMU_HAS_LCM_LDO		0
#define PMU_HAS_BIST_ADC	0
#define PMU_HAS_CHG_ABCC_FLAG	1
#define PMU_HAS_VIB		0
#define PMU_HAS_RAM		0
#define PMU_HAS_WLED		0
#define PMU_HAS_32K_RTC		0
#define PMU_HAS_ACCUMULATORS	1
#define PMU_HAS_SYS		0
#define PMU_HAS_WDT		0
#define PMU_HAS_CHARGER		1
#define PMU_HAS_ISET_BAT_2BYTES	1

enum {
	kDIALOG_ADDR_R		= 0xeb,
	kDIALOG_ADDR_W		= 0xea,
	kDIALOG_REG_BYTES	= 2,
};

enum {
	kDIALOG_EVENT_COUNT		= 6,
	kDIALOG_STATUS_COUNT		= 7,
	kDIALOG_FAULTLOG_COUNT		= 1,
	kDIALOG_CHIPID_COUNT		= 9,
	kDIALOG_GPIO_COUNT		= 6,
};

#include "dCommon.h"

enum {
	kDIALOG_MASK_REV_CODE		= 0x0000,
	kDIALOG_TRIM_REL_CODE		= 0x0001,
	kDIALOG_PLATFORM_ID		= 0x0002,
	kDIALOG_PARITY			= 0x0003,
	kDIALOG_DEVICE_ID1		= 0x0004,
	kDIALOG_DEVICE_ID2		= 0x0005,
	kDIALOG_DEVICE_ID3		= 0x0006,
	kDIALOG_DEVICE_ID4		= 0x0007,
	kDIALOG_DEVICE_ID5		= 0x0008,
	kDIALOG_CHIP_ID			= kDIALOG_MASK_REV_CODE,
	
	kDIALOG_SYS_CONTROL		= 0x0010,
	
	kDIALOG_SYS_CONFIG		= 0x0020,
	kD2231_SYS_CONF_B		= 0x0021,
	kD2231_SYS_CONF_C		= 0x0022,
	kD2231_BG_TRIM0			= 0x0023,
	kD2231_BG_TRI1			= 0x0024,
	kD2231_BG_CONFIG		= 0x0025,
	kD2231_COMP_TRIM		= 0x0026,
	kD2231_OSC_CTRL0		= 0x0027,
	kD2231_OSC_TRIM			= 0x0028,
	kD2231_LDO_CORE_TRIM		= 0x0029,
	kD2231_ON_BUFFER_TRIM		= 0x002a,
	kD2231_SYS_CONF_E		= 0x002b,
	kD2231_SYS_CONF_F		= 0x002c,

	kDIALOG_FAULT_LOG		= 0x0040,
	
	// the event registers are named A-L but are numbered 0-5
	kDIALOG_EVENT_A			= 0x0050,
	kDIALOG_EVENT_C			= 0x0051,
	kDIALOG_EVENT_D			= 0x0052,
	kDIALOG_EVENT_I			= 0x0053,
	kDIALOG_EVENT_J			= 0x0054,
	kDIALOG_EVENT_L			= 0x0055,

	// the status registers are named A-M but are numbered 0-6
	kDIALOG_STATUS_A		= 0x0060,
	kDIALOG_STATUS_C		= 0x0061,
	kDIALOG_STATUS_D		= 0x0062,
	kDIALOG_STATUS_I		= 0x0063,
	kDIALOG_STATUS_J		= 0x0064,
	kDIALOG_STATUS_L		= 0x0065,
	kDIALOG_STATUS_M		= 0x0066,

	// the mask registers are named A-L but are numbered 0-5
	kDIALOG_IRQ_MASK_A		= 0x0070,
	kDIALOG_IRQ_MASK_C		= 0x0071,
	kDIALOG_IRQ_MASK_D		= 0x0072,
	kDIALOG_IRQ_MASK_I		= 0x0073,
	kDIALOG_IRQ_MASK_J		= 0x0074,
	kDIALOG_IRQ_MASK_L		= 0x0075,

//	GPIO Control

	kD2231_GPIO1			= 0x0170,
	kDIALOG_SYS_GPIO_REG_START	= kD2231_GPIO1,
	kD2231_GPIO2			= 0x0171,
	kD2231_GPIO3			= 0x0172,
	kD2231_GPIO4			= 0x0173,
	kD2231_GPIO5			= 0x0174,
	kD2231_GPIO6			= 0x0175,

	kD2231_GPIO_DEB1		= 0x0190,
	kD2231_GPIO_DEB2		= 0x0191,
	kD2231_GPIO_DEB3		= 0x0192,

//	Temperature Sensor Control

	kD2231_TVCENTER1_RISE		= 0x01ac,
	kD2231_TVCENTER2_RISE		= 0x01ad,
	kD2231_TCBUCK_RISE		= 0x01ae,
	kD2231_TLINCHG_RISE		= 0x01af,
	kD2231_TMID_DIE_RISE		= 0x01b0,
	kD2231_TLDO_VDDREF_CHG_RISE	= 0x01b1,
	kD2231_TVCENTER1_FALL		= 0x01b2,
	kD2231_TVCENTER2_FALL		= 0x01b3,
	kD2231_TCBUCK_FALL		= 0x01b4,
	kD2231_TLINCHG_FALL		= 0x01b5,
	kD2231_TMID_DIE_FALL		= 0x01b6,
	kD2231_TLDO_VDDREF_CHG_FALL	= 0x01b7,
	kDIALOG_T_OFFSET_MSB		= 0x01b8,
	kDIALOG_T_OFFSET_LSB		= 0x01b9,

//	Charging Control
	
	kD2231_ISET_BUCK		= 0x01ec,
	kD2231_ISET_BUCK_SHADOW		= 0x04ed,
	kD2231_ISET_BUCK_LV_ABSMAX	= 0x01ee,
	kD2231_ISET_BUCK_HV_ABSMAX	= 0x01ef,
	kD2231_ISET_BUCK_ACTUAL		= 0x01f0,
	kD2231_ISET_BUCK_ALT		= 0x01f1,
	kDIALOG_CHARGE_BUCK_CONTROL	= kD2231_ISET_BUCK,
	kDIALOG_CHARGE_BUCK_STATUS	= kD2231_ISET_BUCK_ACTUAL,
	kD2231_ICHG_PRE_MSB		= 0x01f2,
	kD2231_ICHG_PRE_LSB		= 0x01f3,
	kD2231_ICHG_BAT_MSB		= 0x01f4,
	kD2231_ICHG_BAT_LSB		= 0x01f5,
	kD2231_ICHG_BAT_MAX_MSB		= 0x01f6,
	kD2231_ICHG_BAT_MAX_LSB		= 0x01f7,
	kD2231_CHG_VSET_MSB		= 0x01f8,
	kD2231_CHG_VSET_LSB		= 0x01f9,
	kD2231_CHG_VSET_ABSAX_MSB	= 0x01fa,
	kD2231_CHG_VSET_ABS_MAX_LSB	= 0x01fb,
	kD2231_CHG_CTRL_A		= 0x01fc,
	kD2231_CHG_CTRL_B		= 0x01fd,
	kD2231_CHG_CTRL_C		= 0x01fe,
	kD2231_CHG_CTRL_D		= 0x01ff,
	kD2231_CHG_TIME			= 0x0200,
	kD2231_CHG_TIME_PRE		= 0x0201,
	kDIALOG_CHARGE_CONTROL_ICHG_BAT_MSB	= kD2231_ICHG_BAT_MSB,
	kDIALOG_CHARGE_CONTROL_TIME	= kD2231_CHG_CTRL_A,
	kDIALOG_OTP_ISET_BAT_MSB		= kD2231_ICHG_BAT_MAX_MSB,
	kDIALOG_CHARGE_CONTROL_EN	= kD2231_CHG_CTRL_B,
	kD2231_ICHG_BAT_ACTUAL_MSB	= 0x0203,
	kD2231_ICHG_BAT_ACTUAL_LSB	= 0x0204,
	kDIALOG_CHARGE_STATUS_MSB	= kD2231_ICHG_BAT_ACTUAL_MSB,
	kD2231_CHG_VSET_TRIM		= 0x0205,
	kD2231_CHG_BAT_TRIM0		= 0x0206,
	kD2231_CHG_BAT_TRIM1		= 0x0207,
	kD2231_CHG_BAT_TRIM2		= 0x0208,
	kD2231_CHG_BAT_TRIM3		= 0x0209,
	kD2231_CHG_BAT_TRIM4		= 0x020a,
	kD2231_CHG_BAT_TRIM5		= 0x020b,
	kD2231_CHG_TRIM3		= 0x020c,
	kD2231_CHG_TRIM4		= 0x020d,
	kD2231_OVP_TRIM1		= 0x020e,
	kD2231_OVP_TRIM3		= 0x0210,
	kD2231_OVP_TRIM4		= 0x0211,
	kD2231_OVP_TRIM6		= 0x0213,
	kD2231_OVP_TRIM7		= 0x0214,
	kD2231_OVP_TRIM9		= 0x0216,
	kD2231_OVP_TRIM10		= 0x0217,
	kD2231_OVP_TRIM11		= 0x0218,
	kD2231_OVP_TRIM12		= 0x0219,
	kD2231_OVP_TRIM13		= 0x021a,
	kD2231_OVP_TRIM14		= 0x021b,
	kD2231_OVP_ILIM_SET_MIN		= 0x021c,
	kD2231_OVP_DIGI_TRIM1		= 0x021d,
	kD2231_OVP_DIGI_TRIM2		= 0x021e,
	kD2231_OVP_DIGI_TRIM3		= 0x021f,
	kD2231_ICHG_END			= 0x0220,
	
	kDIALOG_TBAT_0			= 0x0221,
	kDIALOG_TBAT_1			= 0x0222,
	kDIALOG_TBAT_2			= 0x0223,
	kDIALOG_TBAT_3			= 0x0224,
	kDIALOG_TBAT_4			= 0x0225,
	kDIALOG_TBAT_MAX		= 0x0226,
	kD2231_TBAT_THYS_1_0		= 0x0227,
	kD2231_TBAT_THYS_3_2		= 0x0228,
	kD2231_TBAT_THYS_MAX_4		= 0x0229,
	kD2231_ICHG_TBAT_MSB_0		= 0x022a,
	kD2231_ICHG_TBAT_LSB_0		= 0x022b,
	kD2231_ICHG_TBAT_MSB_1		= 0x022c,
	kD2231_ICHG_TBAT_LSB_1		= 0x022d,
	kD2231_ICHG_TBAT_MSB_2		= 0x022e,
	kD2231_ICHG_TBAT_LSB_2		= 0x022f,
	kD2231_ICHG_TBAT_MSB_3		= 0x0230,
	kD2231_ICHG_TBAT_LSB_3		= 0x0231,
	kD2231_ICHG_TBAT_MSB_4		= 0x0232,
	kD2231_ICHG_TBAT_LSB_4		= 0x0233,
	kD2231_ICHG_LOW_VBAT_0		= 0x0234,
	kD2231_ICHG_LOW_VBAT_1		= 0x0235,
	kD2231_ICHG_LOW_VBAT_2		= 0x0236,
	kD2231_ICHG_LOW_VBAT_3		= 0x0237,
	kD2231_ICHG_LOW_VBAT_4		= 0x0238,
	kD2231_ICHG_LOW_VBAT_5		= 0x0239,
	kD2231_ICHG_LOW_VBAT_6		= 0x023a,
	kD2231_ICHG_LOW_VBAT_7		= 0x023b,
	kD2231_ICHG_AVG			= 0x023d,
	kD2231_ICHG6A_AVG		= 0x023d,
	kDIALOG_ICHG_AVG		= kD2231_ICHG_AVG,
	kD2231_CHG_BUCK_MODE		= 0x023e,
	kD2231_CHG_BUCK_FSM_TRIM0	= 0x023f,
	kD2231_CHG_BUCK_FSM_TRIM1	= 0x0240,
	kD2231_CHG_BUCK_FSM_TRIM2	= 0x0241,
	kD2231_CHG_BUCK_FSM_TRIM3	= 0x0242,
	kD2231_CHG_BUCK_FSM_TRIM4	= 0x0243,
	kD2231_CHG_BUCK_CLK_TRIM	= 0x0244,
	kD2231_CHG_BUCK_ANA_TRIM0	= 0x0245,
	kD2231_CHG_BUCK_ANA_TRIM1	= 0x0246,
	kD2231_CHG_BUCK_ANA_TRIM2	= 0x0247,
	kD2231_CHG_BUCK_ANA_TRIM3	= 0x0248,
	kD2231_CVT_CONTROL		= 0x024c,
	kD2231_CVT_ISET_0_MSB		= 0x024d,
	kD2231_CVT_ISET_0_LSB		= 0x024e,
	kD2231_CVT_ISET_1_MSB		= 0x024f,
	kD2231_CVT_ISET_1_LSB		= 0x0250,
	kD2231_CVT_ISET_2_MSB		= 0x0251,
	kD2231_CVT_ISET_2_LSB		= 0x0252,
	kD2231_CVT_ISET_3_MSB		= 0x0253,
	kD2231_CVT_ISET_3_LSB		= 0x0254,
	kD2231_CVT_ISET_4_MSB		= 0x0255,
	kD2231_CVT_ISET_4_LSB		= 0x0256,
	kD2231_CVT_ISET_5_MSB		= 0x0257,
	kD2231_CVT_ISET_5_LSB		= 0x0258,
	kD2231_CVT_ISET_6_MSB		= 0x0259,
	kD2231_CVT_ISET_6_LSB		= 0x025a,
	kD2231_CVT_ISET_7_MSB		= 0x025b,
	kD2231_CVT_ISET_7_LSB		= 0x025c,
	kD2231_CVT_VSET_0_MSB		= 0x025d,
	kD2231_CVT_VSET_0_LSB		= 0x025e,
	kD2231_CVT_VSET_1_MSB		= 0x025f,
	kD2231_CVT_VSET_1_LSB		= 0x0260,
	kD2231_CVT_VSET_2_MSB		= 0x0261,
	kD2231_CVT_VSET_2_LSB		= 0x0262,
	kD2231_CVT_VSET_3_MSB		= 0x0263,
	kD2231_CVT_VSET_3_LSB		= 0x0264,
	kD2231_CVT_VSET_4_MSB		= 0x0265,
	kD2231_CVT_VSET_4_LSB		= 0x0266,
	kD2231_CVT_VSET_5_MSB		= 0x0267,
	kD2231_CVT_VSET_5_LSB		= 0x0268,
	kD2231_CVT_VSET_6_MSB		= 0x0269,
	kD2231_CVT_VSET_6_LSB		= 0x026a,
	kD2231_CVT_VSET_7_MSB		= 0x026b,
	kD2231_CVT_VSET_7_LSB		= 0x026c,
	kD2231_CVT_CC_CV_1_TR1_SEL	= 0x026d,
	kD2231_CVT_CC_CV_1_TR2_SEL	= 0x026e,
	kD2231_CVT_CC_CV_1_TR3_SEL	= 0x026f,
	kD2231_CVT_CC_CV_1_TR4_SEL	= 0x0270,
	kD2231_CVT_CC_CV_1_TR5_SEL	= 0x0271,
	kD2231_CVT_CC_CV_2_TR1_SEL	= 0x0272,
	kD2231_CVT_CC_CV_2_TR2_SEL	= 0x0273,
	kD2231_CVT_CC_CV_2_TR3_SEL	= 0x0274,
	kD2231_CVT_CC_CV_2_TR4_SEL	= 0x0275,
	kD2231_CVT_CC_CV_2_TR5_SEL	= 0x0276,
	kD2231_CVT_CC_CV_3_TR1_SEL	= 0x0277,
	kD2231_CVT_CC_CV_3_TR2_SEL	= 0x0278,
	kD2231_CVT_CC_CV_3_TR3_SEL	= 0x0279,
	kD2231_CVT_CC_CV_3_TR4_SEL	= 0x027a,
	kD2231_CVT_CC_CV_3_TR5_SEL	= 0x027b,
	kD2231_CVT_CC_CV_4_TR1_SEL	= 0x027c,
	kD2231_CVT_CC_CV_4_TR2_SEL	= 0x027d,
	kD2231_CVT_CC_CV_4_TR3_SEL	= 0x027e,
	kD2231_CVT_CC_CV_4_TR4_SEL	= 0x027f,
	kD2231_CVT_CC_CV_4_TR5_SEL	= 0x0280,
	kD2231_CVT_ISET_DEF_0_MSB	= 0x0281,
	kD2231_CVT_ISET_DEF_0_LSB	= 0x0282,
	kD2231_CVT_ISET_DEF_1_MSB	= 0x0283,
	kD2231_CVT_ISET_DEF_1_LSB	= 0x0284,
	kD2231_CVT_ISET_DEF_2_MSB	= 0x0285,
	kD2231_CVT_ISET_DEF_2_LSB	= 0x0286,
	kD2231_CVT_ISET_DEF_3_MSB	= 0x0287,
	kD2231_CVT_ISET_DEF_3_LSB	= 0x0288,
	kD2231_CVT_VSET_DEF_0_MSB	= 0x0289,
	kD2231_CVT_VSET_DEF_0_LSB	= 0x028a,
	kD2231_CVT_VSET_DEF_1_MSB	= 0x028b,
	kD2231_CVT_VSET_DEF_1_LSB	= 0x028c,
	kD2231_CVT_VSET_DEF_2_MSB	= 0x028d,
	kD2231_CVT_VSET_DEF_2_LSB	= 0x028e,
	kD2231_CVT_VBAT_CONV_K		= 0x028f,
	kD2231_CVT_VBAT_CONV_OFF_MSB	= 0x0290,
	kD2231_CVT_VBAT_CONV_OFF_LSB	= 0x0291,
	kD2231_CVT_IBAT_CONV_K		= 0x0292,
	kD2231_CVT_VBAT_CONV_OFF	= 0x0293,
	kD2231_CVT_ACTUAL_ICHG		= 0x0294,
	kD2231_CVT_ACTUAL_VSET		= 0x0295,
	kD2231_CVT_ACTUAL_STATUS	= 0x0296,

// GPADC Control and Results

	kDIALOG_ADC_CONTROL		= 0x03ec,
	kDIALOG_ADC_CONTROL2		= 0x03ed,
	kD2231_ADC_CTRL3		= 0x03ee,
	kDIALOG_ADC_LSB			= 0x03ef,
	kDIALOG_ADC_MSB			= 0x03f0,
	kD2231_ADC_TEMP_CTRL1		= 0x03f1,
	kD2231_ADC_FSM_TRIM0		= 0x03f2,
	kD2231_ADC_FSM_TRIM1		= 0x03f3,
	kD2231_ADC_FSM_TRIM2		= 0x03f4,
	kD2231_ADC_FSM_TRIM3		= 0x03f5,
	kD2231_ADC_ANA_TRIM0		= 0x03f6,
	kD2231_ADC_ANA_TRIM1		= 0x03f7,
	kD2231_VCC_MAIN_MON		= 0x03f8,
	kDIALOG_IBUS_ACCUM1		= 0x03fa,
	kDIALOG_IBUS_ACCUM2		= 0x03fb,
	kDIALOG_IBUS_ACCUM3		= 0x03fc,
	kDIALOG_VBUS_ACCUM1		= 0x03fd,
	kDIALOG_VBUS_ACCUM2		= 0x03fe,
	kDIALOG_VBUS_ACCUM3		= 0x03ff,
	kDIALOG_TDIE_ACCUM1		= 0x0400,
	kDIALOG_TDIE_ACCUM2		= 0x0401,
	kDIALOG_TDIE_ACCUM3		= 0x0402,
	kDIALOG_IBUS_COUNT1		= 0x0403,
	kDIALOG_IBUS_COUNT2		= 0x0404,
	kD2231_IBUSCAL_1		= 0x0405,
	kD2231_IBUSCAL_2		= 0x0406,
	kD2231_IBUSCAL_3		= 0x0407,
	kD2231_IBUSCAL_4		= 0x0408,
	kD2231_IBUSCAL_5		= 0x0409,
	kD2231_IBUSCAL_6		= 0x040a,
	kD2231_IBUSCAL_7		= 0x040b,
	kD2231_IBUSCAL_8		= 0x040c,


//	Reserved Spare Registers

	kD2231_SPARE_RW0		= 0x1080,
	kD2231_SPARE_RW_LAST		= 0x1007,
	kD2231_DEBUG_DIG_3		= 0x7223,
	kD2231_REG_OTP0			= 0x7c00,
	kD2231_REG_OTP511		= 0x7dff,

//	Misc

    kDIALOG_TEST_ACCESS			= 0x7000,
        kDIALOG_TEST_ACCESS_ENA	= 0x1D,
        kDIALOG_TEST_ACCESS_DIS	= 0x00,
};

enum {
// <rdar://problem/21879203> J99 EVT not recognizing lightning connection
    kDIALOG_OTP_RELOAD_CONF			= kD2231_SYS_CONF_E,
    kDIALOG_OTP_SKIP_RELOAD_TO_ACT	= (1<<6),
};

// -------------------------------------------------------------------
//
// -------------------------------------------------------------------

// Synthetic Accumulator Registers 
enum {
	kDIALOG_ACCUMULATOR_SEL_COUNT   = 2,
	kDIALOG_IBUS_ACCUMULATOR	= 0,
	kDIALOG_VBUS_ACCUMULATOR	= 1,
	kDIALOG_IBUCK0_ACCUMULATOR	= 0,
	kDIALOG_IBUCK1_ACCUMULATOR	= 0,
};

enum {
	kD2231_EVENT_A_TBAT		= (1 << 7),
	kD2231_EVENT_A_VBUS_EXT_REM	= (1 << 6),
	kD2231_EVENT_A_VDD_LOW		= (1 << 5),
	kD2231_EVENT_A_CHG_HV_ATT	= (1 << 4),
	kD2231_EVENT_A_VBUS_EXT_DET	= (1 << 3),
	kD2231_EVENT_A_HV_MODE		= (1 << 2),
	kD2231_EVENT_A_CHG_BUCK_LIMITED	= (1 << 1),
	kD2231_EVENT_A_VCENTER_DET	= (1 << 0),
};

enum {
	kD2231_EVENT_C_CHG_SLOW		= (1 << 7),
	kD2231_EVENT_C_CHG_BUCK_FLG	= (1 << 6),
	kD2231_EVENT_C_CHG_ABCC_ACT	= (1 << 5),
	kD2231_EVENT_C_CHG_TIMEOUT	= (1 << 4),
	kD2231_EVENT_C_CHG_PRECHG_TIMEOUT	= (1 << 3),
	kD2231_EVENT_C_CHG_END		= (1 << 2),
	kD2231_EVENT_C_CHG_FAST		= (1 << 1),
	kD2231_EVENT_C_CHG_PRE		= (1 << 0),
};

enum {
	kD2231_EVENT_D_GPIO6		= (1 << 5),
	kD2231_EVENT_D_GPIO5		= (1 << 4),
	kD2231_EVENT_D_GPIO4		= (1 << 3),
	kD2231_EVENT_D_GPIO3		= (1 << 2),
	kD2231_EVENT_D_GPIO2		= (1 << 1),
	kD2231_EVENT_D_GPIO1		= (1 << 0),
};

enum {
	kD2231_EVENT_I_VDDREF_CHG_FALL	= (1 << 5),
	kD2231_EVENT_I_TMID_DIE_FALL	= (1 << 4),
	kD2231_EVENT_I_TLINCHG_FALL	= (1 << 3),
	kD2231_EVENT_I_TVCENTER2_FALL	= (1 << 2),
	kD2231_EVENT_I_TVCENTER1_FALL	= (1 << 1),
	kD2231_EVENT_I_TBUCK_FALL	= (1 << 0),
};

enum {
	kD2231_EVENT_J_VDDREF_CHG_RISE	= (1 << 5),
	kD2231_EVENT_J_TMID_DIE_RISE	= (1 << 4),
	kD2231_EVENT_J_TLINCHG_RISE	= (1 << 3),
	kD2231_EVENT_J_TVCENTER2_RISE	= (1 << 2),
	kD2231_EVENT_J_TVCENTER1_RISE	= (1 << 1),
	kD2231_EVENT_J_TBUCK_RISE	= (1 << 0),
};

enum {
	kD2231_EVENT_L_FAULTY_ADAPTER	= (1 << 6),
	kD2231_EVENT_L_IBUS_OVERFLOW	= (1 << 5),
	kD2231_EVENT_L_VBUS_OV		= (1 << 4),
	kD2231_EVENT_L_CVT_RESTART	= (1 << 3),
	kD2231_EVENT_L_CVT_INCORRECT_CFG	= (1 << 2),
	kD2231_EVENT_L_EOMC			= (1 << 1),
};

enum {
	kD2231_STATUS_A_TBAT		= (1 << 7),
	kD2231_STATUS_A_VDD_LOW		= (1 << 5),
	kD2231_STATUS_A_CHG_HV_ATT	= (1 << 4),
	kD2231_STATUS_A_VBUS_EXT_DET	= (1 << 3),
	kD2231_STATUS_A_HV_MODE		= (1 << 2),
	kD2231_STATUS_A_CHG_BUCK_ILIMITED	= (1 << 1),
	kD2231_STATUS_A_VCENTER_DET	= (1 << 0),
};

enum {
	kD2231_STATUS_C_CHG_SLOW	= (1 << 7),
	kD2231_STATUS_C_CHG_BUCK_FLG	= (1 << 6),
	kD2231_STATUS_C_CHG_ABCC_ACT	= (1 << 5),
	kD2231_STATUS_C_CHG_TIMEOUT	= (1 << 4),
	kD2231_STATUS_C_CHG_PRECHG_TIMEOUT	= (1 << 3),
	kD2231_STATUS_C_CHG_END		= (1 << 2),
	kD2231_STATUS_C_CHG_FAST	= (1 << 1),
	kD2231_STATUS_C_CHG_PRE		= (1 << 0),
};

enum {
	kD2231_STATUS_D_GPIO6		= (1 << 5),
	kD2231_STATUS_D_GPIO5		= (1 << 4),
	kD2231_STATUS_D_GPIO4		= (1 << 3),
	kD2231_STATUS_D_GPIO3		= (1 << 2),
	kD2231_STATUS_D_GPIO2		= (1 << 1),
	kD2231_STATUS_D_GPIO1		= (1 << 0),
};


enum {
	kD2231_STATUS_I_VDDREF_CHG_FALL	= (1 << 5),
	kD2231_STATUS_I_TMID_DIE_FALL	= (1 << 4),
	kD2231_STATUS_I_TLINCHG_FALL	= (1 << 3),
	kD2231_STATUS_I_TVCENTER2_FALL	= (1 << 2),
	kD2231_STATUS_I_TVCENTER1_FALL	= (1 << 1),
	kD2231_STATUS_I_TBUCK_FALL	= (1 << 0),
};

enum {
	kD2231_STATUS_J_VDDREF_CHG_RISE	= (1 << 5),
	kD2231_STATUS_J_TMID_DIE_RISE	= (1 << 4),
	kD2231_STATUS_J_TLINCHG_RISE	= (1 << 3),
	kD2231_STATUS_J_TVCENTER2_RISE	= (1 << 2),
	kD2231_STATUS_J_TVCENTER1_RISE	= (1 << 1),
	kD2231_STATUS_J_TBUCK_RISE	= (1 << 0),
};

enum {
	kD2231_STATUS_L_FAULTY_ADAPTER	= (1 << 6),
	kD2231_STATUS_L_IBUS_OVERFLOW	= (1 << 5),
	kD2231_STATUS_L_VBUS_OV		= (1 << 4),
	kD2231_STATUS_L_CVT_INCORRECT_CFG	= (1 << 2),
};

enum {
	kD2231_STATUS_M_CHG_ATT		= (1 << 0),
};

enum {
    kD2231_CHG_CTRL_B_HV_CHG_ALLOW      = ( 1<<1 ),
    kD2231_CHG_CTRL_B_HV_CHG_ALLOW_MASK = ( 1<<1 ),
};



enum {
	// N.B. as above, event register letters do not directly map to indexes

	kDIALOG_EVENT_HOLD_BUTTON_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_MENU_BUTTON_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_RINGER_BUTTON_MASK= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_BUTTON4_MASK= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_BUTTONS_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_PWR_BUTTON_MASK	= kDIALOG_NOTEXIST_MASK,
	
	kDIALOG_EVENT_ALARM_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_ACC_DET_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_VBUS_DET_MASK	= EVENT_FLAG_MAKE(0, kD2231_EVENT_A_VBUS_EXT_DET),
	kDIALOG_EVENT_VBUS_EXT_REM_MASK	= EVENT_FLAG_MAKE(0, kD2231_EVENT_A_VBUS_EXT_REM),
	kDIALOG_EVENT_EOMC_MASK		= EVENT_FLAG_MAKE(5, kD2231_EVENT_L_EOMC),
	kDIALOG_EVENT_HIB_MASK		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_ABCC_MASK		= EVENT_FLAG_MAKE(1, kD2231_EVENT_C_CHG_ABCC_ACT),
	
	kDIALOG_EVENT_CHG_END_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_C_CHG_END),
	kDIALOG_EVENT_TBAT_MASK		= EVENT_FLAG_MAKE(0, kD2231_EVENT_A_TBAT),
	
	kDIALOG_EVENT_GPIO1_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO1),
	kDIALOG_EVENT_GPIO2_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO2),
	kDIALOG_EVENT_GPIO3_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO3),
	kDIALOG_EVENT_GPIO4_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO4),
	kDIALOG_EVENT_GPIO5_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO5),
	kDIALOG_EVENT_GPIO6_MASK	= EVENT_FLAG_MAKE(2, kD2231_EVENT_D_GPIO6),
	kDIALOG_EVENT_GPIO7_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO8_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO9_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO10_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO11_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO12_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO13_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO14_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO15_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO16_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO17_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO18_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO19_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO20_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_GPIO21_MASK	= kDIALOG_NOTEXIST_MASK,

	kDIALOG_EVENT_HOLD_DBL_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_MENU_DBL_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_RINGER_DBL_MASK	= kDIALOG_NOTEXIST_MASK,

	kDIALOG_EVENT_VHP_DET_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_ON_MASK		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_EVENT_LDO2_EN_MASK	= kDIALOG_NOTEXIST_MASK,
};

enum {
	// N.B. as above, status register letters do not directly map to indexes
	kDIALOG_STATUS_USB_MASK		= STATUS_FLAG_MAKE(0, kD2231_STATUS_A_VBUS_EXT_DET),
	kDIALOG_STATUS_VBUS_MASK	= STATUS_FLAG_MAKE(0, kD2231_STATUS_A_VCENTER_DET),
	kDIALOG_STATUS_FW_MASK		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_STATUS_ACC_DET_MASK	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_STATUS_CHARGING_MASK	= STATUS_FLAG_MAKE(1, kD2231_STATUS_C_CHG_PRE | kD2231_STATUS_C_CHG_FAST),
	kDIALOG_STATUS_CHG_TO_MASK	= STATUS_FLAG_MAKE(1, kD2231_STATUS_C_CHG_TIMEOUT),
	kDIALOG_STATUS_CHG_END_MASK	= STATUS_FLAG_MAKE(1, kD2231_STATUS_C_CHG_END),
	kDIALOG_STATUS_TBAT_MASK	= STATUS_FLAG_MAKE(0, kD2231_STATUS_A_TBAT),
	kDIALOG_STATUS_CHG_ATT_MASK     = STATUS_FLAG_MAKE(6, kD2231_STATUS_M_CHG_ATT),
	kDIALOG_STATUS_ABCC_MASK	= STATUS_FLAG_MAKE(1, kD2231_STATUS_C_CHG_ABCC_ACT),
#define	kDIALOG_STATUS_GPIO_MASK(gpio)	  STATUS_FLAG_MAKE(2 + (gpio)/8, (1 << ((gpio) % 8)))
};

static const statusRegisters kDialogStatusFWMask = {0, 0, 0, 0, 0, 0};
static const statusRegisters kDialogStatusChargingMask = {0, kD2231_STATUS_C_CHG_PRE | kD2231_STATUS_C_CHG_FAST, 0, 0, 0, 0};

enum {
	kD2231_EVENT_A_WAKEMASK = (kD2231_EVENT_A_VBUS_EXT_DET | kD2231_EVENT_A_VBUS_EXT_REM | kD2231_EVENT_A_VCENTER_DET),
	kD2231_EVENT_C_WAKEMASK = (kD2231_EVENT_C_CHG_TIMEOUT | kD2231_EVENT_C_CHG_PRECHG_TIMEOUT | kD2231_EVENT_C_CHG_END),
	kD2231_EVENT_D_WAKEMASK = (kD2231_EVENT_D_GPIO6 | kD2231_EVENT_D_GPIO5 | kD2231_EVENT_D_GPIO4 | kD2231_EVENT_D_GPIO3 | kD2231_EVENT_D_GPIO2 | kD2231_EVENT_D_GPIO1),
	kD2231_EVENT_I_WAKEMASK = 0,
	kD2231_EVENT_J_WAKEMASK = 0,
	kD2231_EVENT_L_WAKEMASK = 0,
};

// All events that are masked during shutdown - inverse of the wake mask,
// events that wake up the system
static const eventRegisters kDialogEventIntMasks = {
	~kD2231_EVENT_A_WAKEMASK,
	~kD2231_EVENT_C_WAKEMASK,
	~kD2231_EVENT_D_WAKEMASK,
	~kD2231_EVENT_I_WAKEMASK,
	~kD2231_EVENT_J_WAKEMASK,
	~kD2231_EVENT_L_WAKEMASK,
};


// All wake events without the buttons
static const eventRegisters kDialogEventNotButtonMasks = {
	kD2231_EVENT_A_WAKEMASK,
	kD2231_EVENT_C_WAKEMASK,
	kD2231_EVENT_D_WAKEMASK,
	kD2231_EVENT_I_WAKEMASK,
	kD2231_EVENT_J_WAKEMASK,
	kD2231_EVENT_L_WAKEMASK,
};

// All events indicating external power supply
static const eventRegisters kDialogEventPwrsupplyMask = {
	kD2231_EVENT_A_VBUS_EXT_DET | kD2231_EVENT_A_VCENTER_DET,
	0,
	0,
	0,
	0,
	0,
};

static const eventRegisters kDialogEventUSBMask = {
// in d2231.h only include kD2231_EVENT_A_VBUS_EXT_DET: VCENTER can come and go while charger still usable
	kD2231_EVENT_A_VBUS_EXT_DET,
	kD2231_EVENT_C_CHG_ABCC_ACT,
	0,
	0,
	0,
	0,
};

static const eventRegisters kDialogEventFWMask = {
	0,
	0,
	0,
	0,
	0,
	0,
};

enum {
	kDialogEventPwrsupplyCount = 2,
	kDialogEventUSBCount = 2,
	kDialogEventFWCount = 0,
};

enum {
	kDIALOG_SYS_CONTROL_BAT_PWR_SUSPEND	= (1 << 2),
	kDIALOG_SYS_CONTROL_CHRG_CONTROLS	= kDIALOG_SYS_CONTROL_BAT_PWR_SUSPEND,
	kDIALOG_SYS_CONTROL_HIBERNATE_ALWAYS    = 0,
};

enum {
	kDIALOG_FAULT_LOG_RST			= FAULTLOG_FLAG_MAKE(0, (1 << 3)),
	kDIALOG_FAULT_LOG_POR			= FAULTLOG_FLAG_MAKE(0, (1 << 2)),
	kDIALOG_FAULT_LOG_OVER_TEMP		= FAULTLOG_FLAG_MAKE(0, (1 << 1)),
	kDIALOG_FAULT_LOG_VDD_UNDER		= FAULTLOG_FLAG_MAKE(0, (1 << 0)),

	kDIALOG_FAULT_LOG_WDOG			= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_RESET_IN_3		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_RESET_IN_2		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_RESET_IN_1		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_BTN_SHUTDOWN		= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_TWO_FINGER_RESET	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_NTC_SHDN		= kDIALOG_NOTEXIST_MASK,
};

enum {
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_MIN  = 0x08,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_100  = 0x0a,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_200  = 0x14,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_500  = 0x32,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_1000 = 0x64,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_2000 = 0xc8,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_2100 = 0xd2,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_2560 = 0xff,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_MAX  = 0xff,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_MASK = 0xff,
};

enum {
	kDIALOG_CHARGE_BUCK_CONTROL_MIN		   = 80,
	kDIALOG_CHARGE_BUCK_CONTROL_STEP_PER_100MA = 10,
	kDIALOG_CHARGE_BUCK_CONTROL_MAX		   = 2550,
};

enum {
	kDIALOG_CHARGE_CONTROL_A_ISET_BAT_MASK	 = 0x3ff,
	kDIALOG_CHARGE_CONTROL_A_ISET_BAT_SHIFT  = 0,
	kDIALOG_OTP_ISET_BAT_SHIFT		= kDIALOG_CHARGE_CONTROL_A_ISET_BAT_SHIFT,
	kDIALOG_CHARGE_CONTROL_B_CHG_SUSP	= (1 << 5),
	kDIALOG_CHARGE_CONTROL_CHG_HIB		= 0,
};

enum {
	kDIALOG_CHARGE_CONTROL_STEP		= 10,
	kDIALOG_CHARGE_CONTROL_MAX		= 6390,
};

enum {
	kDIALOG_CHARGE_CONTROL_ALT_USB_DIS	= (1 << 6),
	kDIALOG_CHARGE_CONTROL_CHG_BUCK_EN	= (1 << 7),
};

enum {
	kDIALOG_CHARGE_CONTROL_TIME_TCTR_MASK	    = 0xFF,
	kDIALOG_CHARGE_CONTROL_TIME_TCTR_DISABLED   = 0x00,
	kDIALOG_CHARGE_CONTROL_TIME_PCTR_MASK	    = 0x00,	// TODO
	kDIALOG_CHARGE_CONTROL_TIME_PCTR_DISABLED   = 0x00,
};

enum {
	kDIALOG_ADC_LSB_ADC_OVL			= (1 << 7),
	kDIALOG_ADC_LSB_MANADC_ERROR		= (1 << 6),
};

enum {
	kDIALOG_ADC_CONTROL_MAN_CONV		= (1 << 7),
	kDIALOG_ADC_CONTROL_MUX_SEL_MASK	= (0x1f << 0),

	kDIALOG_ADC_CONTROL_MUX_SEL_VDD_OUT	= (0 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_ICH_1A	= (1 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_TBAT	= (2 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VBAT	= (3 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_IBUS_IN_LG	= (4 << 0),
		kDIALOG_ADC_CONTROL_MUX_SEL_VIBUS	= kDIALOG_ADC_CONTROL_MUX_SEL_IBUS_IN_LG,
	kDIALOG_ADC_CONTROL_MUX_SEL_ADC_IN_P	= (5 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_ADC_IN_N	= (6 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_TJUNC	= (7 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_IBUS_IN_HG	= (8 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VBUS	= (10 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VCENTER_TEMP1	= (13 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_LINCHG_TEMP		= (14 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_CHG_BUCK_TEMP	= (15 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VCENTER_TEMP2	= (16 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_MID_DIE_TEMP	= (17 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_LV_LDO_TEMP		= (18 << 0),
		kDIALOG_ADC_CONTROL_MUX_SEL_TINT_START	= kDIALOG_ADC_CONTROL_MUX_SEL_VCENTER_TEMP1,
		kDIALOG_ADC_CONTROL_MUX_SEL_TINT_END	= kDIALOG_ADC_CONTROL_MUX_SEL_LV_LDO_TEMP,
	kDIALOG_ADC_CONTROL_MUX_SEL_ICH_6A	= (29 << 0),
		kDIALOG_ADC_CONTROL_MUX_SEL_ICH	= kDIALOG_ADC_CONTROL_MUX_SEL_ICH_6A,

	kDIALOG_ADC_CONTROL2_AUTO_VDD_OUT_EN	= (1 << 7),
	kDIALOG_ADC_CONTROL2_ICH6A_EN		= (1 << 1),
	kDIALOG_ADC_CONTROL2_IBUS_EN		= (1 << 0),
};

enum {
	kDIALOG_ADC_CONTROL_DEFAULTS	= 0,
	kDIALOG_ADC_CONTROL2_DEFAULTS	= 0,
};

enum {
	kDIALOG_ADC_RESOLUTION_BITS	= 10,
	kDIALOG_ADC_FULL_SCALE_MV	= 1500,
	kDIALOG_ADC_BRICK_ID_OFFSET_MV	= 40,
};


enum {
	kDIALOG_SYS_GPIO_OUTPUT_LEVEL_LOW		= (0 << 1),
	kDIALOG_SYS_GPIO_OUTPUT_LEVEL_HIGH		= (1 << 1),

	kDIALOG_SYS_GPIO_DIRECTION_MASK			= (1 << 6) | (1 << 1),
	kDIALOG_SYS_GPIO_DIRECTION_OUT			= (1 << 6),
	kDIALOG_SYS_GPIO_DIRECTION_IN_LEVEL_HIGH	= (0 << 6) | (0 << 1),
	kDIALOG_SYS_GPIO_DIRECTION_IN_LEVEL_LOW		= (0 << 6) | (1 << 1),

	kDIALOG_SYS_GPIO_DIRECTION_OUT_32KHZ		= kDIALOG_SYS_GPIO_DIRECTION_OUT,   // not supported
};

#define IS_GPIO_OUTPUT(gpio) (((gpio)&kDIALOG_SYS_GPIO_DIRECTION_OUT) == kDIALOG_SYS_GPIO_DIRECTION_OUT)

#define NUM_LDOS 0
static const struct ldo_params ldo_d2231[NUM_LDOS] = {
};
#define LDOP ldo_d2231


#endif /* __DIALOG_D2231_H */
