xref: /rk3399_rockchip-uboot/include/twl6030.h (revision d6a2042dbcd4a3a3d8282c77a5882104a5c399a7)
1 /*
2  * (C) Copyright 2010
3  * Texas Instruments, <www.ti.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef TWL6030_H
9 #define TWL6030_H
10 
11 #include <common.h>
12 #include <i2c.h>
13 
14 /* I2C chip addresses */
15 #define TWL6030_CHIP_PM		0x48
16 
17 #define TWL6030_CHIP_USB	0x49
18 #define TWL6030_CHIP_ADC	0x49
19 #define TWL6030_CHIP_CHARGER	0x49
20 #define TWL6030_CHIP_PWM	0x49
21 
22 /* Slave Address 0x48 */
23 #define TWL6030_PHOENIX_DEV_ON		0x25
24 
25 #define TWL6030_PHOENIX_APP_DEVOFF	(1 << 0)
26 #define TWL6030_PHOENIX_CON_DEVOFF	(1 << 1)
27 #define TWL6030_PHOENIX_MOD_DEVOFF	(1 << 2)
28 
29 #define TWL6030_PH_STS_BOOT		0x29
30 
31 #define TWL6030_PH_STS_BOOT0		(1 << 0)
32 #define TWL6030_PH_STS_BOOT1		(1 << 1)
33 #define TWL6030_PH_STS_BOOT2		(1 << 2)
34 #define TWL6030_PH_STS_BOOT3		(1 << 3)
35 
36 #define TWL6030_VAUX1_CFG_STATE		0x86
37 #define TWL6030_VAUX1_CFG_VOLTAGE	0x87
38 #define TWL6030_VMMC_CFG_STATE		0x9A
39 #define TWL6030_VMMC_CFG_VOLTAGE	0x9B
40 #define TWL6030_VUSB_CFG_STATE		0xA2
41 #define TWL6030_VUSB_CFG_VOLTAGE	0xA3
42 
43 #define TWL6030_CFG_GRP_P1		(1 << 0)
44 #define TWL6030_CFG_STATE_ON		(1 << 0)
45 #define TWL6030_CFG_STATE_P1		(TWL6030_CFG_GRP_P1 << 5)
46 #define TWL6030_CFG_VOLTAGE_18		0x09
47 #define TWL6030_CFG_VOLTAGE_28		0x13
48 #define TWL6030_CFG_VOLTAGE_30		0x15
49 #define TWL6030_CFG_VOLTAGE_33		0x18
50 
51 #define MISC1			0xE4
52 #define VAC_MEAS		(1 << 2)
53 #define VBAT_MEAS		(1 << 1)
54 #define BB_MEAS			(1 << 0)
55 
56 #define TWL6030_MISC2			0xE5
57 #define TWL6030_MISC2_VUSB_IN_PMID	(1 << 3)
58 #define TWL6030_MISC2_VUSB_IN_VSYS	(1 << 4)
59 
60 /* Slave Address 0x49 */
61 
62 /* Battery CHARGER REGISTERS */
63 #define CONTROLLER_INT_MASK	0xE0
64 #define CONTROLLER_CTRL1	0xE1
65 #define CONTROLLER_WDG		0xE2
66 #define CONTROLLER_STAT1	0xE3
67 #define CHARGERUSB_INT_STATUS	0xE4
68 #define CHARGERUSB_INT_MASK	0xE5
69 #define CHARGERUSB_STATUS_INT1	0xE6
70 #define CHARGERUSB_STATUS_INT2	0xE7
71 #define CHARGERUSB_CTRL1	0xE8
72 #define CHARGERUSB_CTRL2	0xE9
73 #define CHARGERUSB_CTRL3	0xEA
74 #define CHARGERUSB_STAT1	0xEB
75 #define CHARGERUSB_VOREG	0xEC
76 #define CHARGERUSB_VICHRG	0xED
77 #define CHARGERUSB_CINLIMIT	0xEE
78 #define CHARGERUSB_CTRLLIMIT1	0xEF
79 
80 /* CHARGERUSB_VICHRG */
81 #define CHARGERUSB_VICHRG_500		0x4
82 #define CHARGERUSB_VICHRG_1500		0xE
83 /* CHARGERUSB_CINLIMIT */
84 #define CHARGERUSB_CIN_LIMIT_100	0x1
85 #define CHARGERUSB_CIN_LIMIT_300	0x5
86 #define CHARGERUSB_CIN_LIMIT_500	0x9
87 #define CHARGERUSB_CIN_LIMIT_NONE	0xF
88 /* CONTROLLER_INT_MASK */
89 #define MVAC_FAULT		(1 << 6)
90 #define MAC_EOC			(1 << 5)
91 #define MBAT_REMOVED		(1 << 4)
92 #define MFAULT_WDG		(1 << 3)
93 #define MBAT_TEMP		(1 << 2)
94 #define MVBUS_DET		(1 << 1)
95 #define MVAC_DET		(1 << 0)
96 /* CHARGERUSB_INT_MASK */
97 #define MASK_MCURRENT_TERM		(1 << 3)
98 #define MASK_MCHARGERUSB_STAT		(1 << 2)
99 #define MASK_MCHARGERUSB_THMREG		(1 << 1)
100 #define MASK_MCHARGERUSB_FAULT		(1 << 0)
101 /* CHARGERUSB_VOREG */
102 #define CHARGERUSB_VOREG_3P52		0x01
103 #define CHARGERUSB_VOREG_4P0		0x19
104 #define CHARGERUSB_VOREG_4P2		0x23
105 #define CHARGERUSB_VOREG_4P76		0x3F
106 /* CHARGERUSB_CTRL1 */
107 #define SUSPEND_BOOT		(1 << 7)
108 #define OPA_MODE		(1 << 6)
109 #define HZ_MODE			(1 << 5)
110 #define TERM			(1 << 4)
111 /* CHARGERUSB_CTRL2 */
112 #define CHARGERUSB_CTRL2_VITERM_50	(0 << 5)
113 #define CHARGERUSB_CTRL2_VITERM_100	(1 << 5)
114 #define CHARGERUSB_CTRL2_VITERM_150	(2 << 5)
115 #define CHARGERUSB_CTRL2_VITERM_400	(7 << 5)
116 /* CONTROLLER_CTRL1 */
117 #define CONTROLLER_CTRL1_EN_CHARGER	(1 << 4)
118 #define CONTROLLER_CTRL1_SEL_CHARGER	(1 << 3)
119 /* CONTROLLER_STAT1 */
120 #define CHRG_EXTCHRG_STATZ	(1 << 7)
121 #define CHRG_DET_N		(1 << 5)
122 #define VAC_DET			(1 << 3)
123 #define VBUS_DET		(1 << 2)
124 
125 #define FG_REG_10	0xCA
126 #define FG_REG_11	0xCB
127 
128 #define TOGGLE1		0x90
129 #define FGS		(1 << 5)
130 #define FGR		(1 << 4)
131 #define GPADCS		(1 << 1)
132 #define GPADCR		(1 << 0)
133 
134 #define CTRL_P2		0x34
135 #define CTRL_P2_SP2	(1 << 2)
136 #define CTRL_P2_EOCP2	(1 << 1)
137 #define CTRL_P2_BUSY	(1 << 0)
138 
139 #define TWL6032_CTRL_P1	0x36
140 #define CTRL_P1_SP1	(1 << 3)
141 
142 #define GPCH0_LSB	0x57
143 #define GPCH0_MSB	0x58
144 
145 #define TWL6032_GPCH0_LSB	0x3b
146 
147 #define TWL6032_GPSELECT_ISB	0x35
148 
149 #define USB_PRODUCT_ID_LSB	0x02
150 
151 #define TWL6030_GPADC_VBAT_CHNL	0x07
152 #define TWL6032_GPADC_VBAT_CHNL	0x12
153 
154 #define TWL6030_GPADC_CTRL	0x2e
155 #define TWL6032_GPADC_CTRL2	0x2f
156 #define GPADC_CTRL2_CH18_SCALER_EN	(1 << 2)
157 #define GPADC_CTRL_SCALER_DIV4		(1 << 3)
158 
159 #define TWL6030_VBAT_MULT	40 * 1000
160 #define TWL6032_VBAT_MULT	25 * 1000
161 
162 #define TWL6030_VBAT_SHIFT	(10 + 3)
163 #define TWL6032_VBAT_SHIFT	(12 + 2)
164 
165 enum twl603x_chip_type{
166 	chip_TWL6030,
167 	chip_TWL6032,
168 	chip_TWL603X_cnt
169 };
170 
171 struct twl6030_data{
172 	u8 chip_type;
173 	u8 adc_rbase;
174 	u8 adc_ctrl;
175 	u8 adc_enable;
176 	int vbat_mult;
177 	int vbat_shift;
178 };
179 
180 /* Functions to read and write from TWL6030 */
181 static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
182 {
183 	return i2c_write(chip_no, reg, 1, &val, 1);
184 }
185 
186 static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
187 {
188 	return i2c_read(chip_no, reg, 1, val, 1);
189 }
190 
191 void twl6030_power_off(void);
192 void twl6030_init_battery_charging(void);
193 void twl6030_usb_device_settings(void);
194 void twl6030_start_usb_charging(void);
195 void twl6030_stop_usb_charging(void);
196 int twl6030_get_battery_voltage(void);
197 int twl6030_get_battery_current(void);
198 void twl6030_power_mmc_init(int dev_index);
199 
200 #endif /* TWL6030_H */
201