blob: 66853439edb1e340a94f0d89decd2271ed4b72ca [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Steve Sakoman516799f2010-07-15 12:53:42 -07002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
Steve Sakoman516799f2010-07-15 12:53:42 -07005 */
6
Nishanth Menon502dac52013-03-26 05:20:53 +00007#ifndef TWL6030_H
8#define TWL6030_H
9
Steve Sakoman516799f2010-07-15 12:53:42 -070010#include <common.h>
11#include <i2c.h>
12
13/* I2C chip addresses */
14#define TWL6030_CHIP_PM 0x48
15
16#define TWL6030_CHIP_USB 0x49
17#define TWL6030_CHIP_ADC 0x49
18#define TWL6030_CHIP_CHARGER 0x49
19#define TWL6030_CHIP_PWM 0x49
20
Balaji T K3e664f62010-11-25 16:22:04 +053021/* Slave Address 0x48 */
Paul Kocialkowski461484c2016-02-27 19:19:13 +010022#define TWL6030_STS_HW_CONDITIONS 0x21
23
24#define TWL6030_STS_HW_CONDITIONS_PWRON (1 << 0)
25
Paul Kocialkowskid6a20422016-02-27 19:19:12 +010026#define TWL6030_PHOENIX_DEV_ON 0x25
27
28#define TWL6030_PHOENIX_APP_DEVOFF (1 << 0)
29#define TWL6030_PHOENIX_CON_DEVOFF (1 << 1)
30#define TWL6030_PHOENIX_MOD_DEVOFF (1 << 2)
31
Paul Kocialkowskid7b6a752016-02-27 19:18:50 +010032#define TWL6030_PH_STS_BOOT 0x29
33
34#define TWL6030_PH_STS_BOOT0 (1 << 0)
35#define TWL6030_PH_STS_BOOT1 (1 << 1)
36#define TWL6030_PH_STS_BOOT2 (1 << 2)
37#define TWL6030_PH_STS_BOOT3 (1 << 3)
38
39#define TWL6030_VAUX1_CFG_STATE 0x86
40#define TWL6030_VAUX1_CFG_VOLTAGE 0x87
Paul Kocialkowskic5dbae72016-02-27 19:18:49 +010041#define TWL6030_VMMC_CFG_STATE 0x9A
42#define TWL6030_VMMC_CFG_VOLTAGE 0x9B
43#define TWL6030_VUSB_CFG_STATE 0xA2
Paul Kocialkowski0343f712016-02-27 19:19:03 +010044#define TWL6030_VUSB_CFG_VOLTAGE 0xA3
Paul Kocialkowskic5dbae72016-02-27 19:18:49 +010045
46#define TWL6030_CFG_GRP_P1 (1 << 0)
47#define TWL6030_CFG_STATE_ON (1 << 0)
48#define TWL6030_CFG_STATE_P1 (TWL6030_CFG_GRP_P1 << 5)
Paul Kocialkowskid7b6a752016-02-27 19:18:50 +010049#define TWL6030_CFG_VOLTAGE_18 0x09
50#define TWL6030_CFG_VOLTAGE_28 0x13
Paul Kocialkowskic5dbae72016-02-27 19:18:49 +010051#define TWL6030_CFG_VOLTAGE_30 0x15
Paul Kocialkowski0343f712016-02-27 19:19:03 +010052#define TWL6030_CFG_VOLTAGE_33 0x18
Balaji T K3e664f62010-11-25 16:22:04 +053053
54#define MISC1 0xE4
55#define VAC_MEAS (1 << 2)
56#define VBAT_MEAS (1 << 1)
57#define BB_MEAS (1 << 0)
58
Paul Kocialkowskic5dbae72016-02-27 19:18:49 +010059#define TWL6030_MISC2 0xE5
Paul Kocialkowski6313c652016-02-27 19:19:04 +010060#define TWL6030_MISC2_VUSB_IN_PMID (1 << 3)
Paul Kocialkowskic5dbae72016-02-27 19:18:49 +010061#define TWL6030_MISC2_VUSB_IN_VSYS (1 << 4)
Balaji T K3e664f62010-11-25 16:22:04 +053062
63/* Slave Address 0x49 */
64
Paul Kocialkowski461484c2016-02-27 19:19:13 +010065#define TWL6030_CONTROLLER_STAT1 0xE3
66
67#define TWL6030_CONTROLLER_STAT1_VAC_DET (1 << 3)
68#define TWL6030_CONTROLLER_STAT1_VBUS_DET (1 << 2)
69
Steve Sakoman516799f2010-07-15 12:53:42 -070070/* Battery CHARGER REGISTERS */
71#define CONTROLLER_INT_MASK 0xE0
72#define CONTROLLER_CTRL1 0xE1
73#define CONTROLLER_WDG 0xE2
74#define CONTROLLER_STAT1 0xE3
75#define CHARGERUSB_INT_STATUS 0xE4
76#define CHARGERUSB_INT_MASK 0xE5
77#define CHARGERUSB_STATUS_INT1 0xE6
78#define CHARGERUSB_STATUS_INT2 0xE7
79#define CHARGERUSB_CTRL1 0xE8
80#define CHARGERUSB_CTRL2 0xE9
81#define CHARGERUSB_CTRL3 0xEA
82#define CHARGERUSB_STAT1 0xEB
83#define CHARGERUSB_VOREG 0xEC
84#define CHARGERUSB_VICHRG 0xED
85#define CHARGERUSB_CINLIMIT 0xEE
86#define CHARGERUSB_CTRLLIMIT1 0xEF
87
88/* CHARGERUSB_VICHRG */
89#define CHARGERUSB_VICHRG_500 0x4
90#define CHARGERUSB_VICHRG_1500 0xE
91/* CHARGERUSB_CINLIMIT */
92#define CHARGERUSB_CIN_LIMIT_100 0x1
93#define CHARGERUSB_CIN_LIMIT_300 0x5
94#define CHARGERUSB_CIN_LIMIT_500 0x9
95#define CHARGERUSB_CIN_LIMIT_NONE 0xF
96/* CONTROLLER_INT_MASK */
97#define MVAC_FAULT (1 << 6)
98#define MAC_EOC (1 << 5)
99#define MBAT_REMOVED (1 << 4)
100#define MFAULT_WDG (1 << 3)
101#define MBAT_TEMP (1 << 2)
102#define MVBUS_DET (1 << 1)
103#define MVAC_DET (1 << 0)
104/* CHARGERUSB_INT_MASK */
105#define MASK_MCURRENT_TERM (1 << 3)
106#define MASK_MCHARGERUSB_STAT (1 << 2)
107#define MASK_MCHARGERUSB_THMREG (1 << 1)
108#define MASK_MCHARGERUSB_FAULT (1 << 0)
109/* CHARGERUSB_VOREG */
110#define CHARGERUSB_VOREG_3P52 0x01
111#define CHARGERUSB_VOREG_4P0 0x19
112#define CHARGERUSB_VOREG_4P2 0x23
113#define CHARGERUSB_VOREG_4P76 0x3F
Balaji T K3e664f62010-11-25 16:22:04 +0530114/* CHARGERUSB_CTRL1 */
115#define SUSPEND_BOOT (1 << 7)
116#define OPA_MODE (1 << 6)
117#define HZ_MODE (1 << 5)
118#define TERM (1 << 4)
Steve Sakoman516799f2010-07-15 12:53:42 -0700119/* CHARGERUSB_CTRL2 */
120#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
121#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
122#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
Balaji T K3e664f62010-11-25 16:22:04 +0530123#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakoman516799f2010-07-15 12:53:42 -0700124/* CONTROLLER_CTRL1 */
125#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
126#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K3e664f62010-11-25 16:22:04 +0530127/* CONTROLLER_STAT1 */
128#define CHRG_EXTCHRG_STATZ (1 << 7)
129#define CHRG_DET_N (1 << 5)
130#define VAC_DET (1 << 3)
131#define VBUS_DET (1 << 2)
Steve Sakoman516799f2010-07-15 12:53:42 -0700132
Balaji T K3e664f62010-11-25 16:22:04 +0530133#define FG_REG_10 0xCA
134#define FG_REG_11 0xCB
135
136#define TOGGLE1 0x90
137#define FGS (1 << 5)
138#define FGR (1 << 4)
139#define GPADCS (1 << 1)
140#define GPADCR (1 << 0)
141
142#define CTRL_P2 0x34
143#define CTRL_P2_SP2 (1 << 2)
144#define CTRL_P2_EOCP2 (1 << 1)
145#define CTRL_P2_BUSY (1 << 0)
146
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300147#define TWL6032_CTRL_P1 0x36
148#define CTRL_P1_SP1 (1 << 3)
149
Balaji T K3e664f62010-11-25 16:22:04 +0530150#define GPCH0_LSB 0x57
151#define GPCH0_MSB 0x58
Steve Sakoman516799f2010-07-15 12:53:42 -0700152
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300153#define TWL6032_GPCH0_LSB 0x3b
154
155#define TWL6032_GPSELECT_ISB 0x35
156
157#define USB_PRODUCT_ID_LSB 0x02
158
159#define TWL6030_GPADC_VBAT_CHNL 0x07
160#define TWL6032_GPADC_VBAT_CHNL 0x12
161
162#define TWL6030_GPADC_CTRL 0x2e
163#define TWL6032_GPADC_CTRL2 0x2f
164#define GPADC_CTRL2_CH18_SCALER_EN (1 << 2)
165#define GPADC_CTRL_SCALER_DIV4 (1 << 3)
166
Oleg Koshelievfc889502013-10-08 15:49:55 +0300167#define TWL6030_VBAT_MULT 40 * 1000
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300168#define TWL6032_VBAT_MULT 25 * 1000
Oleg Koshelievfc889502013-10-08 15:49:55 +0300169
170#define TWL6030_VBAT_SHIFT (10 + 3)
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300171#define TWL6032_VBAT_SHIFT (12 + 2)
Oleg Koshelievfc889502013-10-08 15:49:55 +0300172
173enum twl603x_chip_type{
174 chip_TWL6030,
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300175 chip_TWL6032,
Oleg Koshelievfc889502013-10-08 15:49:55 +0300176 chip_TWL603X_cnt
177};
178
179struct twl6030_data{
180 u8 chip_type;
181 u8 adc_rbase;
182 u8 adc_ctrl;
183 u8 adc_enable;
184 int vbat_mult;
185 int vbat_shift;
186};
187
Nishanth Menonebce10e2013-03-26 05:20:52 +0000188/* Functions to read and write from TWL6030 */
189static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
190{
191 return i2c_write(chip_no, reg, 1, &val, 1);
192}
193
194static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
195{
196 return i2c_read(chip_no, reg, 1, val, 1);
197}
198
Paul Kocialkowski461484c2016-02-27 19:19:13 +0100199/*
200 * Power
201 */
202
Paul Kocialkowskid6a20422016-02-27 19:19:12 +0100203void twl6030_power_off(void);
Steve Sakoman516799f2010-07-15 12:53:42 -0700204void twl6030_init_battery_charging(void);
205void twl6030_usb_device_settings(void);
Balaji T K3e664f62010-11-25 16:22:04 +0530206void twl6030_start_usb_charging(void);
207void twl6030_stop_usb_charging(void);
208int twl6030_get_battery_voltage(void);
209int twl6030_get_battery_current(void);
Paul Kocialkowskia85362f2016-02-27 19:18:51 +0100210void twl6030_power_mmc_init(int dev_index);
Nishanth Menon502dac52013-03-26 05:20:53 +0000211
Paul Kocialkowski461484c2016-02-27 19:19:13 +0100212/*
213 * Input
214 */
215
216int twl6030_input_power_button(void);
217int twl6030_input_charger(void);
218int twl6030_input_usb(void);
219
Nishanth Menon502dac52013-03-26 05:20:53 +0000220#endif /* TWL6030_H */