]>
Commit | Line | Data |
---|---|---|
516799f6 SS |
1 | /* |
2 | * (C) Copyright 2010 | |
3 | * Texas Instruments, <www.ti.com> | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
516799f6 SS |
6 | */ |
7 | ||
502dac55 NM |
8 | #ifndef TWL6030_H |
9 | #define TWL6030_H | |
10 | ||
516799f6 SS |
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 | ||
3e664f6d | 22 | /* Slave Address 0x48 */ |
14fa2dd0 B |
23 | #define VMMC_CFG_STATE 0x9A |
24 | #define VMMC_CFG_VOLTATE 0x9B | |
3e664f6d B |
25 | #define VUSB_CFG_STATE 0xA2 |
26 | ||
27 | #define MISC1 0xE4 | |
28 | #define VAC_MEAS (1 << 2) | |
29 | #define VBAT_MEAS (1 << 1) | |
30 | #define BB_MEAS (1 << 0) | |
31 | ||
32 | #define MISC2 0xE5 | |
33 | ||
34 | /* Slave Address 0x49 */ | |
35 | ||
516799f6 SS |
36 | /* Battery CHARGER REGISTERS */ |
37 | #define CONTROLLER_INT_MASK 0xE0 | |
38 | #define CONTROLLER_CTRL1 0xE1 | |
39 | #define CONTROLLER_WDG 0xE2 | |
40 | #define CONTROLLER_STAT1 0xE3 | |
41 | #define CHARGERUSB_INT_STATUS 0xE4 | |
42 | #define CHARGERUSB_INT_MASK 0xE5 | |
43 | #define CHARGERUSB_STATUS_INT1 0xE6 | |
44 | #define CHARGERUSB_STATUS_INT2 0xE7 | |
45 | #define CHARGERUSB_CTRL1 0xE8 | |
46 | #define CHARGERUSB_CTRL2 0xE9 | |
47 | #define CHARGERUSB_CTRL3 0xEA | |
48 | #define CHARGERUSB_STAT1 0xEB | |
49 | #define CHARGERUSB_VOREG 0xEC | |
50 | #define CHARGERUSB_VICHRG 0xED | |
51 | #define CHARGERUSB_CINLIMIT 0xEE | |
52 | #define CHARGERUSB_CTRLLIMIT1 0xEF | |
53 | ||
54 | /* CHARGERUSB_VICHRG */ | |
55 | #define CHARGERUSB_VICHRG_500 0x4 | |
56 | #define CHARGERUSB_VICHRG_1500 0xE | |
57 | /* CHARGERUSB_CINLIMIT */ | |
58 | #define CHARGERUSB_CIN_LIMIT_100 0x1 | |
59 | #define CHARGERUSB_CIN_LIMIT_300 0x5 | |
60 | #define CHARGERUSB_CIN_LIMIT_500 0x9 | |
61 | #define CHARGERUSB_CIN_LIMIT_NONE 0xF | |
62 | /* CONTROLLER_INT_MASK */ | |
63 | #define MVAC_FAULT (1 << 6) | |
64 | #define MAC_EOC (1 << 5) | |
65 | #define MBAT_REMOVED (1 << 4) | |
66 | #define MFAULT_WDG (1 << 3) | |
67 | #define MBAT_TEMP (1 << 2) | |
68 | #define MVBUS_DET (1 << 1) | |
69 | #define MVAC_DET (1 << 0) | |
70 | /* CHARGERUSB_INT_MASK */ | |
71 | #define MASK_MCURRENT_TERM (1 << 3) | |
72 | #define MASK_MCHARGERUSB_STAT (1 << 2) | |
73 | #define MASK_MCHARGERUSB_THMREG (1 << 1) | |
74 | #define MASK_MCHARGERUSB_FAULT (1 << 0) | |
75 | /* CHARGERUSB_VOREG */ | |
76 | #define CHARGERUSB_VOREG_3P52 0x01 | |
77 | #define CHARGERUSB_VOREG_4P0 0x19 | |
78 | #define CHARGERUSB_VOREG_4P2 0x23 | |
79 | #define CHARGERUSB_VOREG_4P76 0x3F | |
3e664f6d B |
80 | /* CHARGERUSB_CTRL1 */ |
81 | #define SUSPEND_BOOT (1 << 7) | |
82 | #define OPA_MODE (1 << 6) | |
83 | #define HZ_MODE (1 << 5) | |
84 | #define TERM (1 << 4) | |
516799f6 SS |
85 | /* CHARGERUSB_CTRL2 */ |
86 | #define CHARGERUSB_CTRL2_VITERM_50 (0 << 5) | |
87 | #define CHARGERUSB_CTRL2_VITERM_100 (1 << 5) | |
88 | #define CHARGERUSB_CTRL2_VITERM_150 (2 << 5) | |
3e664f6d | 89 | #define CHARGERUSB_CTRL2_VITERM_400 (7 << 5) |
516799f6 SS |
90 | /* CONTROLLER_CTRL1 */ |
91 | #define CONTROLLER_CTRL1_EN_CHARGER (1 << 4) | |
92 | #define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3) | |
3e664f6d B |
93 | /* CONTROLLER_STAT1 */ |
94 | #define CHRG_EXTCHRG_STATZ (1 << 7) | |
95 | #define CHRG_DET_N (1 << 5) | |
96 | #define VAC_DET (1 << 3) | |
97 | #define VBUS_DET (1 << 2) | |
516799f6 | 98 | |
3e664f6d B |
99 | #define FG_REG_10 0xCA |
100 | #define FG_REG_11 0xCB | |
101 | ||
102 | #define TOGGLE1 0x90 | |
103 | #define FGS (1 << 5) | |
104 | #define FGR (1 << 4) | |
105 | #define GPADCS (1 << 1) | |
106 | #define GPADCR (1 << 0) | |
107 | ||
108 | #define CTRL_P2 0x34 | |
109 | #define CTRL_P2_SP2 (1 << 2) | |
110 | #define CTRL_P2_EOCP2 (1 << 1) | |
111 | #define CTRL_P2_BUSY (1 << 0) | |
112 | ||
340e6c83 OK |
113 | #define TWL6032_CTRL_P1 0x36 |
114 | #define CTRL_P1_SP1 (1 << 3) | |
115 | ||
3e664f6d B |
116 | #define GPCH0_LSB 0x57 |
117 | #define GPCH0_MSB 0x58 | |
516799f6 | 118 | |
340e6c83 OK |
119 | #define TWL6032_GPCH0_LSB 0x3b |
120 | ||
121 | #define TWL6032_GPSELECT_ISB 0x35 | |
122 | ||
123 | #define USB_PRODUCT_ID_LSB 0x02 | |
124 | ||
125 | #define TWL6030_GPADC_VBAT_CHNL 0x07 | |
126 | #define TWL6032_GPADC_VBAT_CHNL 0x12 | |
127 | ||
128 | #define TWL6030_GPADC_CTRL 0x2e | |
129 | #define TWL6032_GPADC_CTRL2 0x2f | |
130 | #define GPADC_CTRL2_CH18_SCALER_EN (1 << 2) | |
131 | #define GPADC_CTRL_SCALER_DIV4 (1 << 3) | |
132 | ||
fc889503 | 133 | #define TWL6030_VBAT_MULT 40 * 1000 |
340e6c83 | 134 | #define TWL6032_VBAT_MULT 25 * 1000 |
fc889503 OK |
135 | |
136 | #define TWL6030_VBAT_SHIFT (10 + 3) | |
340e6c83 | 137 | #define TWL6032_VBAT_SHIFT (12 + 2) |
fc889503 OK |
138 | |
139 | enum twl603x_chip_type{ | |
140 | chip_TWL6030, | |
340e6c83 | 141 | chip_TWL6032, |
fc889503 OK |
142 | chip_TWL603X_cnt |
143 | }; | |
144 | ||
145 | struct twl6030_data{ | |
146 | u8 chip_type; | |
147 | u8 adc_rbase; | |
148 | u8 adc_ctrl; | |
149 | u8 adc_enable; | |
150 | int vbat_mult; | |
151 | int vbat_shift; | |
152 | }; | |
153 | ||
ebce10e5 NM |
154 | /* Functions to read and write from TWL6030 */ |
155 | static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val) | |
156 | { | |
157 | return i2c_write(chip_no, reg, 1, &val, 1); | |
158 | } | |
159 | ||
160 | static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val) | |
161 | { | |
162 | return i2c_read(chip_no, reg, 1, val, 1); | |
163 | } | |
164 | ||
516799f6 SS |
165 | void twl6030_init_battery_charging(void); |
166 | void twl6030_usb_device_settings(void); | |
3e664f6d B |
167 | void twl6030_start_usb_charging(void); |
168 | void twl6030_stop_usb_charging(void); | |
169 | int twl6030_get_battery_voltage(void); | |
170 | int twl6030_get_battery_current(void); | |
14fa2dd0 | 171 | void twl6030_power_mmc_init(void); |
502dac55 NM |
172 | |
173 | #endif /* TWL6030_H */ |