blob: 9a1c645d889cb584c60fa0ba20cf8030a7925226 [file] [log] [blame]
Steve Sakomanf8f7c952010-07-15 12:53:42 -07001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Steve Sakomanf8f7c952010-07-15 12:53:42 -07006 */
7
Nishanth Menon65418172013-03-26 05:20:53 +00008#ifndef TWL6030_H
9#define TWL6030_H
10
Steve Sakomanf8f7c952010-07-15 12:53:42 -070011#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
Balaji T K13c3c502010-11-25 16:22:04 +053022/* Slave Address 0x48 */
Paul Kocialkowski1db349f2016-02-27 19:18:50 +010023#define TWL6030_PH_STS_BOOT 0x29
24
25#define TWL6030_PH_STS_BOOT0 (1 << 0)
26#define TWL6030_PH_STS_BOOT1 (1 << 1)
27#define TWL6030_PH_STS_BOOT2 (1 << 2)
28#define TWL6030_PH_STS_BOOT3 (1 << 3)
29
30#define TWL6030_VAUX1_CFG_STATE 0x86
31#define TWL6030_VAUX1_CFG_VOLTAGE 0x87
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010032#define TWL6030_VMMC_CFG_STATE 0x9A
33#define TWL6030_VMMC_CFG_VOLTAGE 0x9B
34#define TWL6030_VUSB_CFG_STATE 0xA2
Paul Kocialkowski3f3b12b2016-02-27 19:19:03 +010035#define TWL6030_VUSB_CFG_VOLTAGE 0xA3
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010036
37#define TWL6030_CFG_GRP_P1 (1 << 0)
38#define TWL6030_CFG_STATE_ON (1 << 0)
39#define TWL6030_CFG_STATE_P1 (TWL6030_CFG_GRP_P1 << 5)
Paul Kocialkowski1db349f2016-02-27 19:18:50 +010040#define TWL6030_CFG_VOLTAGE_18 0x09
41#define TWL6030_CFG_VOLTAGE_28 0x13
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010042#define TWL6030_CFG_VOLTAGE_30 0x15
Paul Kocialkowski3f3b12b2016-02-27 19:19:03 +010043#define TWL6030_CFG_VOLTAGE_33 0x18
Balaji T K13c3c502010-11-25 16:22:04 +053044
45#define MISC1 0xE4
46#define VAC_MEAS (1 << 2)
47#define VBAT_MEAS (1 << 1)
48#define BB_MEAS (1 << 0)
49
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010050#define TWL6030_MISC2 0xE5
Paul Kocialkowskie1545d92016-02-27 19:19:04 +010051#define TWL6030_MISC2_VUSB_IN_PMID (1 << 3)
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010052#define TWL6030_MISC2_VUSB_IN_VSYS (1 << 4)
Balaji T K13c3c502010-11-25 16:22:04 +053053
54/* Slave Address 0x49 */
55
Steve Sakomanf8f7c952010-07-15 12:53:42 -070056/* Battery CHARGER REGISTERS */
57#define CONTROLLER_INT_MASK 0xE0
58#define CONTROLLER_CTRL1 0xE1
59#define CONTROLLER_WDG 0xE2
60#define CONTROLLER_STAT1 0xE3
61#define CHARGERUSB_INT_STATUS 0xE4
62#define CHARGERUSB_INT_MASK 0xE5
63#define CHARGERUSB_STATUS_INT1 0xE6
64#define CHARGERUSB_STATUS_INT2 0xE7
65#define CHARGERUSB_CTRL1 0xE8
66#define CHARGERUSB_CTRL2 0xE9
67#define CHARGERUSB_CTRL3 0xEA
68#define CHARGERUSB_STAT1 0xEB
69#define CHARGERUSB_VOREG 0xEC
70#define CHARGERUSB_VICHRG 0xED
71#define CHARGERUSB_CINLIMIT 0xEE
72#define CHARGERUSB_CTRLLIMIT1 0xEF
73
74/* CHARGERUSB_VICHRG */
75#define CHARGERUSB_VICHRG_500 0x4
76#define CHARGERUSB_VICHRG_1500 0xE
77/* CHARGERUSB_CINLIMIT */
78#define CHARGERUSB_CIN_LIMIT_100 0x1
79#define CHARGERUSB_CIN_LIMIT_300 0x5
80#define CHARGERUSB_CIN_LIMIT_500 0x9
81#define CHARGERUSB_CIN_LIMIT_NONE 0xF
82/* CONTROLLER_INT_MASK */
83#define MVAC_FAULT (1 << 6)
84#define MAC_EOC (1 << 5)
85#define MBAT_REMOVED (1 << 4)
86#define MFAULT_WDG (1 << 3)
87#define MBAT_TEMP (1 << 2)
88#define MVBUS_DET (1 << 1)
89#define MVAC_DET (1 << 0)
90/* CHARGERUSB_INT_MASK */
91#define MASK_MCURRENT_TERM (1 << 3)
92#define MASK_MCHARGERUSB_STAT (1 << 2)
93#define MASK_MCHARGERUSB_THMREG (1 << 1)
94#define MASK_MCHARGERUSB_FAULT (1 << 0)
95/* CHARGERUSB_VOREG */
96#define CHARGERUSB_VOREG_3P52 0x01
97#define CHARGERUSB_VOREG_4P0 0x19
98#define CHARGERUSB_VOREG_4P2 0x23
99#define CHARGERUSB_VOREG_4P76 0x3F
Balaji T K13c3c502010-11-25 16:22:04 +0530100/* CHARGERUSB_CTRL1 */
101#define SUSPEND_BOOT (1 << 7)
102#define OPA_MODE (1 << 6)
103#define HZ_MODE (1 << 5)
104#define TERM (1 << 4)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700105/* CHARGERUSB_CTRL2 */
106#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
107#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
108#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
Balaji T K13c3c502010-11-25 16:22:04 +0530109#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700110/* CONTROLLER_CTRL1 */
111#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
112#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K13c3c502010-11-25 16:22:04 +0530113/* CONTROLLER_STAT1 */
114#define CHRG_EXTCHRG_STATZ (1 << 7)
115#define CHRG_DET_N (1 << 5)
116#define VAC_DET (1 << 3)
117#define VBUS_DET (1 << 2)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700118
Balaji T K13c3c502010-11-25 16:22:04 +0530119#define FG_REG_10 0xCA
120#define FG_REG_11 0xCB
121
122#define TOGGLE1 0x90
123#define FGS (1 << 5)
124#define FGR (1 << 4)
125#define GPADCS (1 << 1)
126#define GPADCR (1 << 0)
127
128#define CTRL_P2 0x34
129#define CTRL_P2_SP2 (1 << 2)
130#define CTRL_P2_EOCP2 (1 << 1)
131#define CTRL_P2_BUSY (1 << 0)
132
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300133#define TWL6032_CTRL_P1 0x36
134#define CTRL_P1_SP1 (1 << 3)
135
Balaji T K13c3c502010-11-25 16:22:04 +0530136#define GPCH0_LSB 0x57
137#define GPCH0_MSB 0x58
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700138
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300139#define TWL6032_GPCH0_LSB 0x3b
140
141#define TWL6032_GPSELECT_ISB 0x35
142
143#define USB_PRODUCT_ID_LSB 0x02
144
145#define TWL6030_GPADC_VBAT_CHNL 0x07
146#define TWL6032_GPADC_VBAT_CHNL 0x12
147
148#define TWL6030_GPADC_CTRL 0x2e
149#define TWL6032_GPADC_CTRL2 0x2f
150#define GPADC_CTRL2_CH18_SCALER_EN (1 << 2)
151#define GPADC_CTRL_SCALER_DIV4 (1 << 3)
152
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300153#define TWL6030_VBAT_MULT 40 * 1000
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300154#define TWL6032_VBAT_MULT 25 * 1000
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300155
156#define TWL6030_VBAT_SHIFT (10 + 3)
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300157#define TWL6032_VBAT_SHIFT (12 + 2)
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300158
159enum twl603x_chip_type{
160 chip_TWL6030,
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300161 chip_TWL6032,
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300162 chip_TWL603X_cnt
163};
164
165struct twl6030_data{
166 u8 chip_type;
167 u8 adc_rbase;
168 u8 adc_ctrl;
169 u8 adc_enable;
170 int vbat_mult;
171 int vbat_shift;
172};
173
Nishanth Menon5b04f122013-03-26 05:20:52 +0000174/* Functions to read and write from TWL6030 */
175static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
176{
177 return i2c_write(chip_no, reg, 1, &val, 1);
178}
179
180static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
181{
182 return i2c_read(chip_no, reg, 1, val, 1);
183}
184
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700185void twl6030_init_battery_charging(void);
186void twl6030_usb_device_settings(void);
Balaji T K13c3c502010-11-25 16:22:04 +0530187void twl6030_start_usb_charging(void);
188void twl6030_stop_usb_charging(void);
189int twl6030_get_battery_voltage(void);
190int twl6030_get_battery_current(void);
Paul Kocialkowskib6497482016-02-27 19:18:51 +0100191void twl6030_power_mmc_init(int dev_index);
Nishanth Menon65418172013-03-26 05:20:53 +0000192
193#endif /* TWL6030_H */