blob: e68393c95d52a33abf26647a411ad758e466df1c [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
51#define TWL6030_MISC2_VUSB_IN_VSYS (1 << 4)
Balaji T K13c3c502010-11-25 16:22:04 +053052
53/* Slave Address 0x49 */
54
Steve Sakomanf8f7c952010-07-15 12:53:42 -070055/* Battery CHARGER REGISTERS */
56#define CONTROLLER_INT_MASK 0xE0
57#define CONTROLLER_CTRL1 0xE1
58#define CONTROLLER_WDG 0xE2
59#define CONTROLLER_STAT1 0xE3
60#define CHARGERUSB_INT_STATUS 0xE4
61#define CHARGERUSB_INT_MASK 0xE5
62#define CHARGERUSB_STATUS_INT1 0xE6
63#define CHARGERUSB_STATUS_INT2 0xE7
64#define CHARGERUSB_CTRL1 0xE8
65#define CHARGERUSB_CTRL2 0xE9
66#define CHARGERUSB_CTRL3 0xEA
67#define CHARGERUSB_STAT1 0xEB
68#define CHARGERUSB_VOREG 0xEC
69#define CHARGERUSB_VICHRG 0xED
70#define CHARGERUSB_CINLIMIT 0xEE
71#define CHARGERUSB_CTRLLIMIT1 0xEF
72
73/* CHARGERUSB_VICHRG */
74#define CHARGERUSB_VICHRG_500 0x4
75#define CHARGERUSB_VICHRG_1500 0xE
76/* CHARGERUSB_CINLIMIT */
77#define CHARGERUSB_CIN_LIMIT_100 0x1
78#define CHARGERUSB_CIN_LIMIT_300 0x5
79#define CHARGERUSB_CIN_LIMIT_500 0x9
80#define CHARGERUSB_CIN_LIMIT_NONE 0xF
81/* CONTROLLER_INT_MASK */
82#define MVAC_FAULT (1 << 6)
83#define MAC_EOC (1 << 5)
84#define MBAT_REMOVED (1 << 4)
85#define MFAULT_WDG (1 << 3)
86#define MBAT_TEMP (1 << 2)
87#define MVBUS_DET (1 << 1)
88#define MVAC_DET (1 << 0)
89/* CHARGERUSB_INT_MASK */
90#define MASK_MCURRENT_TERM (1 << 3)
91#define MASK_MCHARGERUSB_STAT (1 << 2)
92#define MASK_MCHARGERUSB_THMREG (1 << 1)
93#define MASK_MCHARGERUSB_FAULT (1 << 0)
94/* CHARGERUSB_VOREG */
95#define CHARGERUSB_VOREG_3P52 0x01
96#define CHARGERUSB_VOREG_4P0 0x19
97#define CHARGERUSB_VOREG_4P2 0x23
98#define CHARGERUSB_VOREG_4P76 0x3F
Balaji T K13c3c502010-11-25 16:22:04 +053099/* CHARGERUSB_CTRL1 */
100#define SUSPEND_BOOT (1 << 7)
101#define OPA_MODE (1 << 6)
102#define HZ_MODE (1 << 5)
103#define TERM (1 << 4)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700104/* CHARGERUSB_CTRL2 */
105#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
106#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
107#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
Balaji T K13c3c502010-11-25 16:22:04 +0530108#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700109/* CONTROLLER_CTRL1 */
110#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
111#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K13c3c502010-11-25 16:22:04 +0530112/* CONTROLLER_STAT1 */
113#define CHRG_EXTCHRG_STATZ (1 << 7)
114#define CHRG_DET_N (1 << 5)
115#define VAC_DET (1 << 3)
116#define VBUS_DET (1 << 2)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700117
Balaji T K13c3c502010-11-25 16:22:04 +0530118#define FG_REG_10 0xCA
119#define FG_REG_11 0xCB
120
121#define TOGGLE1 0x90
122#define FGS (1 << 5)
123#define FGR (1 << 4)
124#define GPADCS (1 << 1)
125#define GPADCR (1 << 0)
126
127#define CTRL_P2 0x34
128#define CTRL_P2_SP2 (1 << 2)
129#define CTRL_P2_EOCP2 (1 << 1)
130#define CTRL_P2_BUSY (1 << 0)
131
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300132#define TWL6032_CTRL_P1 0x36
133#define CTRL_P1_SP1 (1 << 3)
134
Balaji T K13c3c502010-11-25 16:22:04 +0530135#define GPCH0_LSB 0x57
136#define GPCH0_MSB 0x58
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700137
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300138#define TWL6032_GPCH0_LSB 0x3b
139
140#define TWL6032_GPSELECT_ISB 0x35
141
142#define USB_PRODUCT_ID_LSB 0x02
143
144#define TWL6030_GPADC_VBAT_CHNL 0x07
145#define TWL6032_GPADC_VBAT_CHNL 0x12
146
147#define TWL6030_GPADC_CTRL 0x2e
148#define TWL6032_GPADC_CTRL2 0x2f
149#define GPADC_CTRL2_CH18_SCALER_EN (1 << 2)
150#define GPADC_CTRL_SCALER_DIV4 (1 << 3)
151
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300152#define TWL6030_VBAT_MULT 40 * 1000
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300153#define TWL6032_VBAT_MULT 25 * 1000
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300154
155#define TWL6030_VBAT_SHIFT (10 + 3)
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300156#define TWL6032_VBAT_SHIFT (12 + 2)
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300157
158enum twl603x_chip_type{
159 chip_TWL6030,
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300160 chip_TWL6032,
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300161 chip_TWL603X_cnt
162};
163
164struct twl6030_data{
165 u8 chip_type;
166 u8 adc_rbase;
167 u8 adc_ctrl;
168 u8 adc_enable;
169 int vbat_mult;
170 int vbat_shift;
171};
172
Nishanth Menon5b04f122013-03-26 05:20:52 +0000173/* Functions to read and write from TWL6030 */
174static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
175{
176 return i2c_write(chip_no, reg, 1, &val, 1);
177}
178
179static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
180{
181 return i2c_read(chip_no, reg, 1, val, 1);
182}
183
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700184void twl6030_init_battery_charging(void);
185void twl6030_usb_device_settings(void);
Balaji T K13c3c502010-11-25 16:22:04 +0530186void twl6030_start_usb_charging(void);
187void twl6030_stop_usb_charging(void);
188int twl6030_get_battery_voltage(void);
189int twl6030_get_battery_current(void);
Paul Kocialkowskib6497482016-02-27 19:18:51 +0100190void twl6030_power_mmc_init(int dev_index);
Nishanth Menon65418172013-03-26 05:20:53 +0000191
192#endif /* TWL6030_H */