blob: 7898699eac876a771614b02dc3013a01c473e0b5 [file] [log] [blame]
Steve Sakoman516799f2010-07-15 12:53:42 -07001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Steve Sakoman516799f2010-07-15 12:53:42 -07006 */
7
Nishanth Menon502dac52013-03-26 05:20:53 +00008#ifndef TWL6030_H
9#define TWL6030_H
10
Steve Sakoman516799f2010-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 K3e664f62010-11-25 16:22:04 +053022/* Slave Address 0x48 */
Balaji T K14fa2dd2011-09-08 06:34:57 +000023#define VMMC_CFG_STATE 0x9A
24#define VMMC_CFG_VOLTATE 0x9B
Balaji T K3e664f62010-11-25 16:22:04 +053025#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
Steve Sakoman516799f2010-07-15 12:53:42 -070036/* 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
Balaji T K3e664f62010-11-25 16:22:04 +053080/* 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)
Steve Sakoman516799f2010-07-15 12:53:42 -070085/* 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)
Balaji T K3e664f62010-11-25 16:22:04 +053089#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakoman516799f2010-07-15 12:53:42 -070090/* CONTROLLER_CTRL1 */
91#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
92#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K3e664f62010-11-25 16:22:04 +053093/* 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)
Steve Sakoman516799f2010-07-15 12:53:42 -070098
Balaji T K3e664f62010-11-25 16:22:04 +053099#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
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300113#define TWL6032_CTRL_P1 0x36
114#define CTRL_P1_SP1 (1 << 3)
115
Balaji T K3e664f62010-11-25 16:22:04 +0530116#define GPCH0_LSB 0x57
117#define GPCH0_MSB 0x58
Steve Sakoman516799f2010-07-15 12:53:42 -0700118
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300119#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
Oleg Koshelievfc889502013-10-08 15:49:55 +0300133#define TWL6030_VBAT_MULT 40 * 1000
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300134#define TWL6032_VBAT_MULT 25 * 1000
Oleg Koshelievfc889502013-10-08 15:49:55 +0300135
136#define TWL6030_VBAT_SHIFT (10 + 3)
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300137#define TWL6032_VBAT_SHIFT (12 + 2)
Oleg Koshelievfc889502013-10-08 15:49:55 +0300138
139enum twl603x_chip_type{
140 chip_TWL6030,
Oleg Kosheliev340e6c82013-10-08 15:49:56 +0300141 chip_TWL6032,
Oleg Koshelievfc889502013-10-08 15:49:55 +0300142 chip_TWL603X_cnt
143};
144
145struct 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
Nishanth Menonebce10e2013-03-26 05:20:52 +0000154/* Functions to read and write from TWL6030 */
155static 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
160static 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
Steve Sakoman516799f2010-07-15 12:53:42 -0700165void twl6030_init_battery_charging(void);
166void twl6030_usb_device_settings(void);
Balaji T K3e664f62010-11-25 16:22:04 +0530167void twl6030_start_usb_charging(void);
168void twl6030_stop_usb_charging(void);
169int twl6030_get_battery_voltage(void);
170int twl6030_get_battery_current(void);
Balaji T K14fa2dd2011-09-08 06:34:57 +0000171void twl6030_power_mmc_init(void);
Nishanth Menon502dac52013-03-26 05:20:53 +0000172
173#endif /* TWL6030_H */