#define PMU_HAS_SWI		1
#define PMU_HAS_DWI		0
#define PMU_HAS_LCM_LDO		0
#define PMU_HAS_WLED		1
#define PMU_HAS_REG_BANK	0

enum {
	kDIALOG_ADDR_R	= 0xe8,
	kDIALOG_ADDR_W	= 0xe9,
	kDIALOG_REG_BYTES	= 1,
};

enum {
	kDIALOG_EVENT_COUNT		= 4,
	kDIALOG_STATUS_COUNT		= 4,
	kDIALOG_HIBERNATE_COUNT		= 1,
	kDIALOG_CHIPID_COUNT		= 1,
	kDIALOG_FAULTLOG_COUNT		= 1,
	kDIALOG_GPIO_COUNT		= 8,
	kDIALOG_GPIO_DEB_REG_COUNT	= 3
};

#include "dCommon.h"

enum {
	kDIALOG_CHIP_ID			= 0x00,

	kDIALOG_EVENT_A			= 0x01,
	kDIALOG_EVENT_B			= 0x02,
	kDIALOG_EVENT_C			= 0x03,
	kDIALOG_EVENT_D			= 0x04,

	kDIALOG_STATUS_A		= 0x05,
	kDIALOG_STATUS_B		= 0x06,
	kDIALOG_STATUS_C		= 0x07,
	kDIALOG_STATUS_D		= 0x08,

	kDIALOG_IRQ_MASK_A		= 0x09,
	kDIALOG_IRQ_MASK_B		= 0x0a,
	kDIALOG_IRQ_MASK_C		= 0x0b,
	kDIALOG_IRQ_MASK_D		= 0x0c,

	kDIALOG_SYS_CONTROL		= 0x0d,

	kDIALOG_FAULT_LOG		= 0x0e,

	kD1755_ACTIVE1			= 0x10,
	kD1755_ACTIVE2			= 0x11,
	kD1755_STANDBY1			= 0x12,
	kDIALOG_STANDBY			= kD1755_STANDBY1,
	kD1755_HIBERNATE1		= 0x13,

	kD1755_BUCK1			= 0x14,
	kDIALOG_BUCK1			= kD1755_BUCK1,
	kD1755_BUCK2			= 0x15,
	kD1755_SPECIAL			= 0x16,

	kD1755_LDO1				= 0x17,
	kD1755_LDO2				= 0x18,
	kD1755_LDO3				= 0x19,
	kD1755_LDO4				= 0x1a,
	kD1755_LDO5				= 0x1b,
	kD1755_LDO6				= 0x1c,
	kD1755_LDO7				= 0x1d,
	kD1755_LDO8				= 0x1e,
	kD1755_LDO9				= 0x1f,
	kD1755_LDO10			= 0x20,
	kD1755_LDO11			= 0x21,

	kDIALOG_LDO_CONTROL		= 0x22,
	kDIALOG_BUCK_CONTROL		= 0x23,
	kD1755_BUCK_CONTROL2		= 0x24,
	kDIALOG_BUCK_CONTROL2           = kD1755_BUCK_CONTROL2,

	kDIALOG_WLED_ISET		= 0x25,
	kDIALOG_WLED_CONTROL		= 0x26,
	kDIALOG_WLED_OPTIONS		= kDIALOG_WLED_CONTROL,

	kDIALOG_CHARGE_BUCK_CONTROL = 0x27,
	kD1755_CHARGE_CONTROL_A	= 0x28,
	kD1755_CHARGE_CONTROL_B	= 0x29,
	kD1755_CHARGE_TIME		= 0x2a,
	kDIALOG_CHARGE_CONTROL_ICHG_BAT	= kD1755_CHARGE_CONTROL_A,
	kDIALOG_CHARGE_CONTROL_TIME	= kD1755_CHARGE_CONTROL_B,

	kD1755_BUCK1_PRE1       = 0x2c,
	kDIALOG_BUCK1_PRE1	= kD1755_BUCK1_PRE1,
	kD1755_BUCK1_PRE2       = 0x2d,
	kD1755_BUCK1_PRE3       = 0x2e,
	kD1755_BUCK1_SEL		= 0x2f,
	kDIALOG_BUCK1_SEL       = kD1755_BUCK1_SEL,

	kD1755_SYS_GPIO_1		= 0x50,
	kDIALOG_SYS_GPIO_REG_START	= kD1755_SYS_GPIO_1,
	kD1755_SYS_GPIO_2		= 0x51,
	kD1755_SYS_GPIO_3		= 0x52,
	kD1755_SYS_GPIO_4		= 0x53,
	kD1755_SYS_GPIO_5		= 0x54,
	kD1755_SYS_GPIO_6		= 0x55,
	kD1755_SYS_GPIO_7		= 0x56,
	kD1755_SYS_GPIO_8		= 0x57,

	kD1755_GPIO_DEB1		= 0x59,
	kDIALOG_SYS_GPIO_DEB_REG_START	= kD1755_GPIO_DEB1,
	kD1755_GPIO_DEB2		= 0x5a,
	kD1755_GPIO_DEB3		= 0x5b,	

	kD1755_BUTTON1			= 0x5c,
	kD1755_BUTTON2			= 0x5d,
	kD1755_BUTTON3			= 0x5e,
	
	kDIALOG_SYS_CONFIG		= 0x5f,

	kDIALOG_ADC_CONTROL		= 0x30,
	kDIALOG_ADC_LSB			= 0x31,
	kDIALOG_ADC_MSB			= 0x32,

	kDIALOG_ICHG_AVG		= 0x35,

	kDIALOG_RTC_COUNT_A		= 0x40,
	kDIALOG_RTC_COUNT_B		= 0x41,
	kDIALOG_RTC_COUNT_C		= 0x42,
	kDIALOG_RTC_COUNT_D		= 0x43,
	kDIALOG_RTC_COUNT_E		= 0x44,
	kDIALOG_RTC_COUNT_F		= 0x45,
	kDIALOG_RTC_ALARM_A		= 0x46,
	kDIALOG_RTC_ALARM_B		= 0x47,
	kDIALOG_RTC_ALARM_C		= 0x48,
	kDIALOG_RTC_ALARM_D		= 0x49,
	kDIALOG_RTC_ALARM_E		= 0x4a,
	kDIALOG_RTC_TIMEZONE	= 0x4b,

	kDIALOG_UPCOUNT_A		= 0x4c,
	kDIALOG_UPCOUNT_B		= 0x4d,
	kDIALOG_UPCOUNT_C		= 0x4e,
	kDIALOG_UPCOUNT_D		= 0x4f,

	kDIALOG_MEMBYTE0			= 0x60,
	kDIALOG_MEMBYTE_LAST		= 0x87,

	kD1755_OTP_ISET_USB         = 0xa5,
	kDIALOG_OTP_ISET_BAT	    = 0xac,
	kD1755_OTP_USB_900_LIMIT    = 0xbf,
	kD1755_OTP_USB_500_LIMIT    = 0xc0,
	
	kD1755_TEST_MODE            = 0xe0,
};

enum {
	kDIALOG_ADC_CONTROL_MUX_SEL_MASK	= (0xf << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VDD_OUT	= (0x0 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_ICH		= (0x1 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_TBAT	= (0x2 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_ACC_ID	= (0x3 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_VBAT	= (0x4 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_IBAT_OUT	= (0x4 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_BRICK_ID	= (0x6 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_ADC_IN7	= (0x7 << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_TJUNC	= (0xb << 0),
	kDIALOG_ADC_CONTROL_MUX_SEL_IBAT_IN	= (0xe << 0),
	kDIALOG_ADC_CONTROL_MAN_CONV		= (1 << 4),
	kDIALOG_ADC_CONTROL_ADC_REF_EN		= (1 << 5),
	kDIALOG_ADC_CONTROL_AUTO_VDD_OUT_EN	= (1 << 6),
	kDIALOG_ADC_CONTROL_TBAT_ISRC_EN	= (1 << 7),
};

enum {
       kDIALOG_ADC_CONTROL_DEFAULTS    = kDIALOG_ADC_CONTROL_TBAT_ISRC_EN,
};

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

enum {
	kD1755_ACTIVE1_SPECIAL		= (1 << 2),
	kD1755_SPECIAL_HIB_CHG		= (1 << 2),
};

enum {
	kD1755_CHIP_ID_MRC_MASK		= (15 << 0),
	kD1755_CHIP_ID_MRC_AA		= (0 << 0),
	kD1755_CHIP_ID_MRC_AB		= (1 << 0),
	kD1755_CHIP_ID_MRC_AC		= (2 << 0),
	kD1755_CHIP_ID_MRC_AD		= (3 << 0),
	kD1755_CHIP_ID_MRC_AE		= (4 << 0),
	kD1755_CHIP_ID_PROG		= (1 << 4),
	kD1755_CHIP_ID_PID_MASK		= (7 << 5),
};

enum {
	kD1755_EVENT_A_BUTTON1		= (1 << 0),
	kD1755_EVENT_A_BUTTON2		= (1 << 1),
	kD1755_EVENT_A_BUTTON3		= (1 << 2),
	kD1755_EVENT_A_VBUS_DET		= (1 << 3),
	kD1755_EVENT_A_VHP_DET		= (1 << 4),
	kD1755_EVENT_A_ACC_DET		= (1 << 5),
	kD1755_EVENT_A_VBUS_EXT		= (1 << 6),
	kD1755_EVENT_A_VDD_LOW		= (1 << 7),
};

// EVENT_B events are assumed volatile (lost over sleep/wake)
enum {
	kD1755_EVENT_B_SWI		= (1 << 0),
	kD1755_EVENT_B_CHG_PRE		= (1 << 1),
	kD1755_EVENT_B_CHG_FAST		= (1 << 2),
	kD1755_EVENT_B_CHG_END		= (1 << 3),
	kD1755_EVENT_B_TBAT		= (1 << 4),
	kD1755_EVENT_B_EOMC		= (1 << 5),
	kD1755_EVENT_B_FW_OV		= (1 << 6),
	kDIALOG_EVENT_B_HIB		= (1 << 7),
};

enum {
	kD1755_EVENT_C_GPIO1		= (1 << 0),
	kD1755_EVENT_C_GPIO2		= (1 << 1),
	kD1755_EVENT_C_GPIO3		= (1 << 2),
	kD1755_EVENT_C_GPIO4		= (1 << 3),
	kD1755_EVENT_C_GPIO5		= (1 << 4),
	kD1755_EVENT_C_GPIO6		= (1 << 5),
	kD1755_EVENT_C_GPIO7		= (1 << 6),
	kD1755_EVENT_C_GPIO8		= (1 << 7),
};

enum {
	kD1755_EVENT_D_ALARM		= (1 << 0),
	kD1755_EVENT_D_VHP_REM		= (1 << 4),
	kD1755_EVENT_D_VBUS_REM		= (1 << 6),
};

enum {
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_100  = 3,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_110  = 4,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_120  = 5,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_350  = 6,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_400  = 7,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_450  = 8,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_500  = 9,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_550  = 10,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_600  = 11,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_700  = 12,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_900  = 13,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_1100  = 12,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_1300 = 15,
	kDIALOG_CHARGE_BUCK_CONTROL_ISET_BUCK_MASK = 15,

	kDIALOG_CHARGE_BUCK_CONTROL_ISET_VBUS_CHG_BUCK_EN	= (1 << 7),
};

enum {
	kDIALOG_CHARGE_CONTROL_A_ISET_BAT_MASK	 = 0x3f,
	kDIALOG_CHARGE_CONTROL_A_ISET_BAT_SHIFT  = 0,
};

enum {
	kDIALOG_CHARGE_CONTROL_STEP		= 20,
	kDIALOG_CHARGE_CONTROL_MAX		= 1260,
};

enum {
	kDIALOG_CHARGE_CONTROL_TIME_TCTR_MASK	    = 0x78,
	kDIALOG_CHARGE_CONTROL_TIME_TCTR_DISABLED   = 0x00,
	kDIALOG_CHARGE_CONTROL_TIME_PCTR_MASK	    = 0x00,
	kDIALOG_CHARGE_CONTROL_TIME_PCTR_DISABLED   = 0x00,
};

enum {
	kD1755_TEST_MODE_TEST_EN                                = (1 << 0),
	kD1755_TEST_MODE_RESET_PMU                              = (1 << 1),
	kDIALOG_OTP_ISET_BAT_SHIFT				= 0,
};

enum {
	kDIALOG_SYS_CONTROL_STANDBY				= (1 << 0),
	kDIALOG_SYS_CONTROL_HIBERNATE			= (1 << 1),
	kDIALOG_SYS_CONTROL_BAT_PWR_SUSPEND		= (1 << 2),
	kDIALOG_SYS_CONTROL_SWI_EN				= (1 << 4),
	kD1755_SYS_CONTROL_PRO_FET_DIS			= (1 << 5),
	kDIALOG_SYS_CONTROL_BUS_PWR_SUSPEND		= (1 << 6),
	kDIALOG_SYS_CONTROL_CHRG_CONTROLS		= kDIALOG_SYS_CONTROL_BAT_PWR_SUSPEND
											| kDIALOG_SYS_CONTROL_BUS_PWR_SUSPEND,
	kDIALOG_SYS_CONTROL_HIBERNATE_ALWAYS    = kDIALOG_SYS_CONTROL_HIBERNATE 
											| kDIALOG_SYS_CONTROL_BAT_PWR_SUSPEND | kD1755_SYS_CONTROL_PRO_FET_DIS,
};

enum {
	kDIALOG_FAULT_LOG_WDOG		= FAULTLOG_FLAG_MAKE(0, (1 << 5)),
	kDIALOG_FAULT_LOG_RST		= FAULTLOG_FLAG_MAKE(0, (1 << 4)),
	kDIALOG_FAULT_LOG_POR		= FAULTLOG_FLAG_MAKE(0, (1 << 3)),
	kDIALOG_FAULT_LOG_BOOST		= 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_RESET_IN_1	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_RESET_IN_2	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_RESET_IN_3	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_NTC_SHDN	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_BTN_SHUTDOWN	= kDIALOG_NOTEXIST_MASK,
	kDIALOG_FAULT_LOG_TWO_FINGER_RESET	= kDIALOG_NOTEXIST_MASK,
};

enum {
	kD1755_STATUS_A_BUTTON1		= (1 << 0),
	kD1755_STATUS_A_BUTTON2		= (1 << 1),
	kD1755_STATUS_A_BUTTON3		= (1 << 2),
	kD1755_STATUS_A_VBUS_DET	= (1 << 3),
	kD1755_STATUS_A_VHP_DET		= (1 << 4),
	kD1755_STATUS_A_ACC_DET		= (1 << 5),
	kD1755_STATUS_A_VBUS_EXT	= (1 << 6),
	kD1755_STATUS_A_VDD_LOW		= (1 << 7),
};
enum {
	kD1755_STATUS_B_CHG_ATT		= (1 << 0),
	kD1755_STATUS_B_CHG_PRE		= (1 << 1),
	kD1755_STATUS_B_CHG_FAST	= (1 << 2),
	kD1755_STATUS_B_CHG_END		= (1 << 3),
	kD1755_STATUS_B_TBAT		= (1 << 4),
	kD1755_STATUS_B_CHG_TO		= (1 << 5),
	kD1755_STATUS_B_FW_OV		= (1 << 6),
};
enum {
	kD1755_STATUS_C_GPIO1		= (1 << 0),
	kD1755_STATUS_C_GPIO2		= (1 << 1),
	kD1755_STATUS_C_GPIO3		= (1 << 2),
	kD1755_STATUS_C_GPIO4		= (1 << 3),
	kD1755_STATUS_C_GPIO5		= (1 << 4),
	kD1755_STATUS_C_GPIO6		= (1 << 5),
	kD1755_STATUS_C_GPIO7		= (1 << 6),
	kD1755_STATUS_C_GPIO8		= (1 << 7),
};

enum {
	kD1755_EVENT_C_GPIO_FW_DETECT =	kD1755_EVENT_C_GPIO7
};

enum {
	kD1755_EVENT_A_WAKEMASK  = kD1755_EVENT_A_BUTTON1 
							| kD1755_EVENT_A_BUTTON2
							| kD1755_EVENT_A_BUTTON3
							| kD1755_EVENT_A_VBUS_DET 
							| kD1755_EVENT_A_VHP_DET 
							| kD1755_EVENT_A_ACC_DET,
	kD1755_EVENT_B_WAKEMASK  = 0,
	kD1755_EVENT_C_WAKEMASK  = kD1755_EVENT_C_GPIO_FW_DETECT,
	kD1755_EVENT_D_WAKEMASK  = kD1755_EVENT_D_ALARM
							| kD1755_EVENT_D_VHP_REM
							| kD1755_EVENT_D_VBUS_REM,
};

enum {
	kDIALOG_EVENT_HOLD_BUTTON_MASK	= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_BUTTON2),
	kDIALOG_EVENT_MENU_BUTTON_MASK	= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_BUTTON1),
	kDIALOG_EVENT_RINGER_BUTTON_MASK= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_BUTTON3),
	kDIALOG_EVENT_A_BUTTONS		= (kD1755_EVENT_A_BUTTON2 |
					   kD1755_EVENT_A_BUTTON1 |
					   kD1755_EVENT_A_BUTTON3),
	kDIALOG_EVENT_BUTTONS_MASK	= EVENT_FLAG_MAKE(0, kDIALOG_EVENT_A_BUTTONS),
	kDIALOG_EVENT_PWR_BUTTON_MASK   = kDIALOG_EVENT_HOLD_BUTTON_MASK,
	kDIALOG_EVENT_ALARM_MASK	= EVENT_FLAG_MAKE(3, kD1755_EVENT_D_ALARM),
	kDIALOG_EVENT_ACC_DET_MASK	= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_ACC_DET),
	kDIALOG_EVENT_VBUS_DET_MASK	= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_VBUS_DET),
	kDIALOG_EVENT_VHP_DET_MASK	= EVENT_FLAG_MAKE(0, kD1755_EVENT_A_VHP_DET),
	kDIALOG_EVENT_EOMC_MASK		= EVENT_FLAG_MAKE(1, kD1755_EVENT_B_EOMC),
	kDIALOG_EVENT_HIB_MASK		= EVENT_FLAG_MAKE(1, kDIALOG_EVENT_B_HIB),

	kDIALOG_EVENT_CHG_END_MASK	= EVENT_FLAG_MAKE(1, kD1755_EVENT_B_CHG_END),
	kDIALOG_EVENT_TBAT_MASK		= EVENT_FLAG_MAKE(1, kD1755_EVENT_B_TBAT),
	kDIALOG_EVENT_GPIO1_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO1),
	kDIALOG_EVENT_GPIO2_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO2),
	kDIALOG_EVENT_GPIO3_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO3),
	kDIALOG_EVENT_GPIO4_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO4),
	kDIALOG_EVENT_GPIO5_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO5),
	kDIALOG_EVENT_GPIO6_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO6),
	kDIALOG_EVENT_GPIO7_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO7),
	kDIALOG_EVENT_GPIO8_MASK	= EVENT_FLAG_MAKE(2, kD1755_EVENT_C_GPIO8),

	kD1755_EVENT_D_VBUS_REM_MASK	= EVENT_FLAG_MAKE(3, kD1755_EVENT_D_VBUS_REM),

/*
	kDIALOG_EVENT_WAKE_MASK	= ((kD1755_EVENT_A_WAKEMASK << 0)
							 | (kD1755_EVENT_B_WAKEMASK << 8)
							 | (kD1755_EVENT_C_WAKEMASK << 16)
							 | (kD1755_EVENT_D_WAKEMASK << 24)),

	kDIALOG_EVENT_PWRSUPPLY_MASK
							= (((kD1755_EVENT_A_VBUS_DET | kD1755_EVENT_A_VHP_DET) << 0)
							   | (kD1755_EVENT_C_GPIO_FW_DETECT << 16)
							   | ((kD1755_EVENT_D_VHP_REM | kD1755_EVENT_D_VBUS_REM) << 24)),
*/	
	// not on D1755
	kDIALOG_EVENT_ON_MASK		    = 0,
	kDIALOG_EVENT_LDO2_EN_MASK	    = 0,
	kDIALOG_EVENT_GPIO9_MASK	    = 0,
	kDIALOG_EVENT_GPIO10_MASK	    = 0,
	kDIALOG_EVENT_GPIO11_MASK	    = 0,
	kDIALOG_EVENT_GPIO12_MASK	    = 0,
	kDIALOG_EVENT_GPIO13_MASK	    = 0,
	kDIALOG_EVENT_GPIO14_MASK	    = 0,
	kDIALOG_EVENT_GPIO15_MASK	    = 0,
	kDIALOG_EVENT_GPIO16_MASK	    = 0,
	kDIALOG_EVENT_GPIO17_MASK	    = 0,
	kDIALOG_EVENT_GPIO18_MASK	    = 0,
	kDIALOG_EVENT_HOLD_DBL_MASK	    = 0,
	kDIALOG_EVENT_MENU_DBL_MASK	    = 0,
	kDIALOG_EVENT_RINGER_DBL_MASK	    = 0,
};

#define kDIALOG_EVENT_GPIOn_MASK(n)	EVENT_FLAG_MAKE(2, (1 << (n)))

// All events that are masked during shutdown - inverse of the wake mask,
// events that wake up the system
static static const eventRegisters kDialogEventIntMasks = {
	~kD1755_EVENT_A_WAKEMASK,
	~kD1755_EVENT_B_WAKEMASK,
	~kD1755_EVENT_C_WAKEMASK,
	~kD1755_EVENT_D_WAKEMASK
};

// All wake events without the buttons
static const eventRegisters kDialogEventNotButtonMasks = {
	kD1755_EVENT_A_WAKEMASK & ~kDIALOG_EVENT_A_BUTTONS,
	kD1755_EVENT_B_WAKEMASK,
	kD1755_EVENT_C_WAKEMASK,
	kD1755_EVENT_D_WAKEMASK
};

// All events that do defer shutdown
static const eventRegisters kDialogEventRestartMask = { 
	kDIALOG_EVENT_HOLD_BUTTON_MASK | kDIALOG_EVENT_ACC_DET_MASK,
	0,
	0,
	kD1755_EVENT_D_ALARM
};

// All events indicating external power supply
static const eventRegisters kDialogEventPwrsupplyMask = {
	kD1755_EVENT_A_VBUS_DET | kD1755_EVENT_A_VHP_DET,
	0,
	kD1755_EVENT_C_GPIO_FW_DETECT,
	kD1755_EVENT_D_VHP_REM | kD1755_EVENT_D_VBUS_REM
};
static const eventRegisters kDialogEventUSBMask = {
	kD1755_EVENT_A_VBUS_DET,
	0,
	0,
	kD1755_EVENT_D_VBUS_REM
};
static const eventRegisters kDialogEventFWMask = {
	kD1755_EVENT_A_VHP_DET,
	0,
	kD1755_EVENT_C_GPIO_FW_DETECT,
	kD1755_EVENT_D_VHP_REM
};
enum {
	kDialogEventPwrsupplyCount = 5,
	kDialogEventUSBCount = 2,
	kDialogEventFWCount = 3,
};

enum {
	kDIALOG_SYS_CONFIG_RESET_TIMER_MASK  = (3 << 3),
	kDIALOG_SYS_CONFIG_RESET_TIMER_4S    = (0 << 3),
	kDIALOG_SYS_CONFIG_RESET_TIMER_6S    = (1 << 3),
	kDIALOG_SYS_CONFIG_RESET_TIMER_8S    = (2 << 3),
	kDIALOG_SYS_CONFIG_RESET_TIMER_10S   = (3 << 3),
	
	kDIALOG_SYS_CONFIG_WDOG_MODE_100MS   = (0 << 1),
	kDIALOG_SYS_CONFIG_WDOG_MODE_250MS   = (1 << 1),
	kDIALOG_SYS_CONFIG_WDOG_MODE_500MS   = (2 << 1),
	kDIALOG_SYS_CONFIG_WDOG_MODE_1000MS  = (3 << 1),
	
	kDIALOG_SYS_CONFIG_WDOG_EN	    = (1 << 0),
	
	kDIALOG_SYS_CONFIG_WDOG_ACTIVE	    = 0,
};

enum {
	kDIALOG_STATUS_USB_MASK		 = STATUS_FLAG_MAKE(0, kD1755_STATUS_A_VBUS_DET),
	kDIALOG_STATUS_ACC_DET_MASK	 = STATUS_FLAG_MAKE(0, kD1755_STATUS_A_ACC_DET),
//	kDIALOG_STATUS_FW_MASK		 = ((kD1755_STATUS_A_VHP_DET << 0) | (kD1755_EVENT_C_GPIO_FW_DETECT << 16)),
//	kDIALOG_STATUS_CHARGING_MASK	 = ((kD1755_STATUS_B_CHG_PRE | kD1755_STATUS_B_CHG_FAST) << 8),
	kDIALOG_STATUS_CHG_TO_MASK	 = STATUS_FLAG_MAKE(1, kD1755_STATUS_B_CHG_TO),
	kDIALOG_STATUS_CHG_END_MASK	 = STATUS_FLAG_MAKE(1, kD1755_STATUS_B_CHG_END),
	kDIALOG_STATUS_TBAT_MASK	 = STATUS_FLAG_MAKE(1, kD1755_STATUS_B_TBAT),
	kDIALOG_STATUS_CHG_ATT_MASK	 = STATUS_FLAG_MAKE(1, kD1755_STATUS_B_CHG_ATT),
#define	kDIALOG_STATUS_GPIO_MASK(gpio)	   STATUS_FLAG_MAKE(2, (1 << (gpio)))

	kDIALOG_STATUS_HOLD_BUTTON_MASK	    = STATUS_FLAG_MAKE(0, kD1755_STATUS_A_BUTTON2),
	kDIALOG_STATUS_MENU_BUTTON_MASK	    = STATUS_FLAG_MAKE(0, kD1755_STATUS_A_BUTTON1),
	kDIALOG_STATUS_RINGER_BUTTON_MASK   = STATUS_FLAG_MAKE(0, kD1755_STATUS_A_BUTTON3),
};

static const statusRegisters kDialogStatusFWMask = {kD1755_STATUS_A_VHP_DET, 0, kD1755_EVENT_C_GPIO_FW_DETECT, 0};
static const statusRegisters kDialogStatusChargingMask = {0, kD1755_STATUS_B_CHG_PRE | kD1755_STATUS_B_CHG_FAST, 0, 0};

enum {
	kDIALOG_SYS_GPIO_DIRECTION_MASK          = (7 << 5),
	kDIALOG_SYS_GPIO_DIRECTION_OUT           = (0 << 5),
	kDIALOG_SYS_GPIO_DIRECTION_IN_LEVEL_HIGH = (1 << 5),
	kDIALOG_SYS_GPIO_DIRECTION_IN_LEVEL_LOW	= (2 << 5),

	kDIALOG_SYS_GPIO_OUTPUT_LEVEL_LOW		= (0 << 1),
	kDIALOG_SYS_GPIO_OUTPUT_LEVEL_HIGH		= (1 << 1),
	kDIALOG_SYS_GPIO_OUTPUT_32KHZ			= (1 << 2),
};

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

enum {
	kDIALOG_WLED_CONTROL_WLED_ENABLE1	= (1 << 0),
	kDIALOG_WLED_CONTROL_WLED_ENABLE2	= (1 << 1),
	kDIALOG_WLED_CONTROL_WLED_RAMP_EN	= (1 << 2),
	kDIALOG_WLED_CONTROL_WLED_SWI_EN	= (1 << 3),
	kDIALOG_WLED_CONTROL_BOOST_FREQ		= (1 << 4),
	kDIALOG_WLED_CONTROL_BOOST_ILIMIT_710	= (0 << 5),
	kDIALOG_WLED_CONTROL_BOOST_ILIMIT_1000	= (1 << 5),
	
	kDIALOG_WLED_OPTIONS_DEFAULT = kDIALOG_WLED_CONTROL_BOOST_ILIMIT_710,
	kDIALOG_WLED_OPTIONS_xWI_EN = kDIALOG_WLED_CONTROL_WLED_SWI_EN,
	kDIALOG_WLED_OPTIONS_MASK = (kDIALOG_WLED_CONTROL_WLED_RAMP_EN|
				    kDIALOG_WLED_CONTROL_BOOST_FREQ|
				    kDIALOG_WLED_CONTROL_BOOST_ILIMIT_1000),
};

enum {
	kDIALOG_RTC_COUNT_A_SEC_MASK = (0x3f),
	kDIALOG_RTC_COUNT_A_MONITOR  = (1 << 6),
};

enum {
	kDIALOG_RTC_ALARM_E_YEAR_MASK = (0x3f),
	kDIALOG_RTC_ALARM_E_ALARM_ON  = (1 << 6)
};

enum {
	kDIALOG_BUCK_CONTROL_BUCK1_GO		= (1 << 6),
	kDIALOG_BUCK_CONTROL_BUCK1_SWI_EN	= (1 << 7)
};

enum {
	kDIALOG_BUCK_CONTROL2_HIB_CLK		= (1 << 7),
};

#define NUM_LDOS 12
static const struct ldo_params ldo_1755[NUM_LDOS] = {
{ 2500, 50, 0x15, 0x1f, 0x1, kD1755_LDO1,  kD1755_ACTIVE1, 0x08 },      // LDO1 
{ 1500, 50, 0x24, 0x3f, 0x0, kD1755_LDO2,  kD1755_ACTIVE1, 0x10 },      // LDO2 
{ 2500, 50, 0x10, 0x1f, 0x0, kD1755_LDO3,  kD1755_ACTIVE1, 0x20 },      // LDO3 
{ 1800, 50, 0x1e, 0x1f, 0x0, kD1755_LDO4,  kD1755_ACTIVE1, 0x40 },      // LDO4 
{ 2500, 50, 0x16, 0x1f, 0x2, kD1755_LDO5,  kD1755_ACTIVE1, 0x80 },      // LDO5 
{ 2500, 50, 0x16, 0x1f, 0x4, kD1755_LDO6,  kD1755_ACTIVE2, 0x01 },      // LDO6 
{ 1500, 100,0x1f, 0x1f, 0x0, kD1755_LDO7,  kD1755_ACTIVE2, 0x02 },      // LDO7 
{ 2000, 50, 0x1f, 0x1f, 0x0, kD1755_LDO8,  kD1755_ACTIVE2, 0x04 },      // LDO8 
{ 1200, 25, 0x0c, 0x0f, 0x0, kD1755_LDO9,  kD1755_ACTIVE2, 0x80 },      // LDO9 
{ 1700, 50, 0x1a, 0x1f, 0x0, kD1755_LDO10, kD1755_ACTIVE2, 0x10 },      // LDO10
{ 1700, 50, 0x1a, 0x1f, 0x0, kD1755_LDO11, kD1755_ACTIVE2, 0x20 },      // LDO11
{ 0,    0,  0,    0,    0x0, 0,		   kD1755_ACTIVE2, 0x40	},	// 12 - WDIG_EN
};
#define LDOP ldo_1755

#define WLED_ISET_BITS (8)
