blob: 04295c92c541128a5283d2e195349fa1dcdfe5c8 [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
35
36#define TWL6030_CFG_GRP_P1 (1 << 0)
37#define TWL6030_CFG_STATE_ON (1 << 0)
38#define TWL6030_CFG_STATE_P1 (TWL6030_CFG_GRP_P1 << 5)
Paul Kocialkowski1db349f2016-02-27 19:18:50 +010039#define TWL6030_CFG_VOLTAGE_18 0x09
40#define TWL6030_CFG_VOLTAGE_28 0x13
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010041#define TWL6030_CFG_VOLTAGE_30 0x15
Balaji T K13c3c502010-11-25 16:22:04 +053042
43#define MISC1 0xE4
44#define VAC_MEAS (1 << 2)
45#define VBAT_MEAS (1 << 1)
46#define BB_MEAS (1 << 0)
47
Paul Kocialkowskib8421a72016-02-27 19:18:49 +010048#define TWL6030_MISC2 0xE5
49#define TWL6030_MISC2_VUSB_IN_VSYS (1 << 4)
Balaji T K13c3c502010-11-25 16:22:04 +053050
51/* Slave Address 0x49 */
52
Steve Sakomanf8f7c952010-07-15 12:53:42 -070053/* Battery CHARGER REGISTERS */
54#define CONTROLLER_INT_MASK 0xE0
55#define CONTROLLER_CTRL1 0xE1
56#define CONTROLLER_WDG 0xE2
57#define CONTROLLER_STAT1 0xE3
58#define CHARGERUSB_INT_STATUS 0xE4
59#define CHARGERUSB_INT_MASK 0xE5
60#define CHARGERUSB_STATUS_INT1 0xE6
61#define CHARGERUSB_STATUS_INT2 0xE7
62#define CHARGERUSB_CTRL1 0xE8
63#define CHARGERUSB_CTRL2 0xE9
64#define CHARGERUSB_CTRL3 0xEA
65#define CHARGERUSB_STAT1 0xEB
66#define CHARGERUSB_VOREG 0xEC
67#define CHARGERUSB_VICHRG 0xED
68#define CHARGERUSB_CINLIMIT 0xEE
69#define CHARGERUSB_CTRLLIMIT1 0xEF
70
71/* CHARGERUSB_VICHRG */
72#define CHARGERUSB_VICHRG_500 0x4
73#define CHARGERUSB_VICHRG_1500 0xE
74/* CHARGERUSB_CINLIMIT */
75#define CHARGERUSB_CIN_LIMIT_100 0x1
76#define CHARGERUSB_CIN_LIMIT_300 0x5
77#define CHARGERUSB_CIN_LIMIT_500 0x9
78#define CHARGERUSB_CIN_LIMIT_NONE 0xF
79/* CONTROLLER_INT_MASK */
80#define MVAC_FAULT (1 << 6)
81#define MAC_EOC (1 << 5)
82#define MBAT_REMOVED (1 << 4)
83#define MFAULT_WDG (1 << 3)
84#define MBAT_TEMP (1 << 2)
85#define MVBUS_DET (1 << 1)
86#define MVAC_DET (1 << 0)
87/* CHARGERUSB_INT_MASK */
88#define MASK_MCURRENT_TERM (1 << 3)
89#define MASK_MCHARGERUSB_STAT (1 << 2)
90#define MASK_MCHARGERUSB_THMREG (1 << 1)
91#define MASK_MCHARGERUSB_FAULT (1 << 0)
92/* CHARGERUSB_VOREG */
93#define CHARGERUSB_VOREG_3P52 0x01
94#define CHARGERUSB_VOREG_4P0 0x19
95#define CHARGERUSB_VOREG_4P2 0x23
96#define CHARGERUSB_VOREG_4P76 0x3F
Balaji T K13c3c502010-11-25 16:22:04 +053097/* CHARGERUSB_CTRL1 */
98#define SUSPEND_BOOT (1 << 7)
99#define OPA_MODE (1 << 6)
100#define HZ_MODE (1 << 5)
101#define TERM (1 << 4)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700102/* CHARGERUSB_CTRL2 */
103#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
104#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
105#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
Balaji T K13c3c502010-11-25 16:22:04 +0530106#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700107/* CONTROLLER_CTRL1 */
108#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
109#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K13c3c502010-11-25 16:22:04 +0530110/* CONTROLLER_STAT1 */
111#define CHRG_EXTCHRG_STATZ (1 << 7)
112#define CHRG_DET_N (1 << 5)
113#define VAC_DET (1 << 3)
114#define VBUS_DET (1 << 2)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700115
Balaji T K13c3c502010-11-25 16:22:04 +0530116#define FG_REG_10 0xCA
117#define FG_REG_11 0xCB
118
119#define TOGGLE1 0x90
120#define FGS (1 << 5)
121#define FGR (1 << 4)
122#define GPADCS (1 << 1)
123#define GPADCR (1 << 0)
124
125#define CTRL_P2 0x34
126#define CTRL_P2_SP2 (1 << 2)
127#define CTRL_P2_EOCP2 (1 << 1)
128#define CTRL_P2_BUSY (1 << 0)
129
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300130#define TWL6032_CTRL_P1 0x36
131#define CTRL_P1_SP1 (1 << 3)
132
Balaji T K13c3c502010-11-25 16:22:04 +0530133#define GPCH0_LSB 0x57
134#define GPCH0_MSB 0x58
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700135
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300136#define TWL6032_GPCH0_LSB 0x3b
137
138#define TWL6032_GPSELECT_ISB 0x35
139
140#define USB_PRODUCT_ID_LSB 0x02
141
142#define TWL6030_GPADC_VBAT_CHNL 0x07
143#define TWL6032_GPADC_VBAT_CHNL 0x12
144
145#define TWL6030_GPADC_CTRL 0x2e
146#define TWL6032_GPADC_CTRL2 0x2f
147#define GPADC_CTRL2_CH18_SCALER_EN (1 << 2)
148#define GPADC_CTRL_SCALER_DIV4 (1 << 3)
149
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300150#define TWL6030_VBAT_MULT 40 * 1000
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300151#define TWL6032_VBAT_MULT 25 * 1000
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300152
153#define TWL6030_VBAT_SHIFT (10 + 3)
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300154#define TWL6032_VBAT_SHIFT (12 + 2)
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300155
156enum twl603x_chip_type{
157 chip_TWL6030,
Oleg Kosheliev5c05da72013-10-08 15:49:56 +0300158 chip_TWL6032,
Oleg Kosheliev8cce7a92013-10-08 15:49:55 +0300159 chip_TWL603X_cnt
160};
161
162struct twl6030_data{
163 u8 chip_type;
164 u8 adc_rbase;
165 u8 adc_ctrl;
166 u8 adc_enable;
167 int vbat_mult;
168 int vbat_shift;
169};
170
Nishanth Menon5b04f122013-03-26 05:20:52 +0000171/* Functions to read and write from TWL6030 */
172static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
173{
174 return i2c_write(chip_no, reg, 1, &val, 1);
175}
176
177static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
178{
179 return i2c_read(chip_no, reg, 1, val, 1);
180}
181
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700182void twl6030_init_battery_charging(void);
183void twl6030_usb_device_settings(void);
Balaji T K13c3c502010-11-25 16:22:04 +0530184void twl6030_start_usb_charging(void);
185void twl6030_stop_usb_charging(void);
186int twl6030_get_battery_voltage(void);
187int twl6030_get_battery_current(void);
Paul Kocialkowskib6497482016-02-27 19:18:51 +0100188void twl6030_power_mmc_init(int dev_index);
Nishanth Menon65418172013-03-26 05:20:53 +0000189
190#endif /* TWL6030_H */