xref: /openbmc/u-boot/include/twl6030.h (revision ea818dbb)
1 /*
2  * (C) Copyright 2010
3  * Texas Instruments, <www.ti.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 
24 #ifndef TWL6030_H
25 #define TWL6030_H
26 
27 #include <common.h>
28 #include <i2c.h>
29 
30 /* I2C chip addresses */
31 #define TWL6030_CHIP_PM		0x48
32 
33 #define TWL6030_CHIP_USB	0x49
34 #define TWL6030_CHIP_ADC	0x49
35 #define TWL6030_CHIP_CHARGER	0x49
36 #define TWL6030_CHIP_PWM	0x49
37 
38 /* Slave Address 0x48 */
39 #define VMMC_CFG_STATE		0x9A
40 #define VMMC_CFG_VOLTATE	0x9B
41 #define VUSB_CFG_STATE		0xA2
42 
43 #define MISC1			0xE4
44 #define VAC_MEAS		(1 << 2)
45 #define VBAT_MEAS		(1 << 1)
46 #define BB_MEAS			(1 << 0)
47 
48 #define MISC2			0xE5
49 
50 /* Slave Address 0x49 */
51 
52 /* Battery CHARGER REGISTERS */
53 #define CONTROLLER_INT_MASK	0xE0
54 #define CONTROLLER_CTRL1	0xE1
55 #define CONTROLLER_WDG		0xE2
56 #define CONTROLLER_STAT1	0xE3
57 #define CHARGERUSB_INT_STATUS	0xE4
58 #define CHARGERUSB_INT_MASK	0xE5
59 #define CHARGERUSB_STATUS_INT1	0xE6
60 #define CHARGERUSB_STATUS_INT2	0xE7
61 #define CHARGERUSB_CTRL1	0xE8
62 #define CHARGERUSB_CTRL2	0xE9
63 #define CHARGERUSB_CTRL3	0xEA
64 #define CHARGERUSB_STAT1	0xEB
65 #define CHARGERUSB_VOREG	0xEC
66 #define CHARGERUSB_VICHRG	0xED
67 #define CHARGERUSB_CINLIMIT	0xEE
68 #define CHARGERUSB_CTRLLIMIT1	0xEF
69 
70 /* CHARGERUSB_VICHRG */
71 #define CHARGERUSB_VICHRG_500		0x4
72 #define CHARGERUSB_VICHRG_1500		0xE
73 /* CHARGERUSB_CINLIMIT */
74 #define CHARGERUSB_CIN_LIMIT_100	0x1
75 #define CHARGERUSB_CIN_LIMIT_300	0x5
76 #define CHARGERUSB_CIN_LIMIT_500	0x9
77 #define CHARGERUSB_CIN_LIMIT_NONE	0xF
78 /* CONTROLLER_INT_MASK */
79 #define MVAC_FAULT		(1 << 6)
80 #define MAC_EOC			(1 << 5)
81 #define MBAT_REMOVED		(1 << 4)
82 #define MFAULT_WDG		(1 << 3)
83 #define MBAT_TEMP		(1 << 2)
84 #define MVBUS_DET		(1 << 1)
85 #define MVAC_DET		(1 << 0)
86 /* CHARGERUSB_INT_MASK */
87 #define MASK_MCURRENT_TERM		(1 << 3)
88 #define MASK_MCHARGERUSB_STAT		(1 << 2)
89 #define MASK_MCHARGERUSB_THMREG		(1 << 1)
90 #define MASK_MCHARGERUSB_FAULT		(1 << 0)
91 /* CHARGERUSB_VOREG */
92 #define CHARGERUSB_VOREG_3P52		0x01
93 #define CHARGERUSB_VOREG_4P0		0x19
94 #define CHARGERUSB_VOREG_4P2		0x23
95 #define CHARGERUSB_VOREG_4P76		0x3F
96 /* CHARGERUSB_CTRL1 */
97 #define SUSPEND_BOOT		(1 << 7)
98 #define OPA_MODE		(1 << 6)
99 #define HZ_MODE			(1 << 5)
100 #define TERM			(1 << 4)
101 /* CHARGERUSB_CTRL2 */
102 #define CHARGERUSB_CTRL2_VITERM_50	(0 << 5)
103 #define CHARGERUSB_CTRL2_VITERM_100	(1 << 5)
104 #define CHARGERUSB_CTRL2_VITERM_150	(2 << 5)
105 #define CHARGERUSB_CTRL2_VITERM_400	(7 << 5)
106 /* CONTROLLER_CTRL1 */
107 #define CONTROLLER_CTRL1_EN_CHARGER	(1 << 4)
108 #define CONTROLLER_CTRL1_SEL_CHARGER	(1 << 3)
109 /* CONTROLLER_STAT1 */
110 #define CHRG_EXTCHRG_STATZ	(1 << 7)
111 #define CHRG_DET_N		(1 << 5)
112 #define VAC_DET			(1 << 3)
113 #define VBUS_DET		(1 << 2)
114 
115 #define FG_REG_10	0xCA
116 #define FG_REG_11	0xCB
117 
118 #define TOGGLE1		0x90
119 #define FGS		(1 << 5)
120 #define FGR		(1 << 4)
121 #define GPADCS		(1 << 1)
122 #define GPADCR		(1 << 0)
123 
124 #define CTRL_P2		0x34
125 #define CTRL_P2_SP2	(1 << 2)
126 #define CTRL_P2_EOCP2	(1 << 1)
127 #define CTRL_P2_BUSY	(1 << 0)
128 
129 #define GPCH0_LSB	0x57
130 #define GPCH0_MSB	0x58
131 
132 /* Functions to read and write from TWL6030 */
133 static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
134 {
135 	return i2c_write(chip_no, reg, 1, &val, 1);
136 }
137 
138 static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
139 {
140 	return i2c_read(chip_no, reg, 1, val, 1);
141 }
142 
143 void twl6030_init_battery_charging(void);
144 void twl6030_usb_device_settings(void);
145 void twl6030_start_usb_charging(void);
146 void twl6030_stop_usb_charging(void);
147 int twl6030_get_battery_voltage(void);
148 int twl6030_get_battery_current(void);
149 void twl6030_power_mmc_init(void);
150 
151 #endif /* TWL6030_H */
152