blob: 029b21f7108d369f7f04cd392430ddea70e7cf2c [file] [log] [blame]
Steve Sakomanf8f7c952010-07-15 12:53:42 -07001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Nishanth Menon65418172013-03-26 05:20:53 +000024#ifndef TWL6030_H
25#define TWL6030_H
26
Steve Sakomanf8f7c952010-07-15 12:53:42 -070027#include <common.h>
28#include <i2c.h>
29
30/* I2C chip addresses */
31#define TWL6030_CHIP_PM 0x48
32
33#define TWL6030_CHIP_USB 0x49
34#define TWL6030_CHIP_ADC 0x49
35#define TWL6030_CHIP_CHARGER 0x49
36#define TWL6030_CHIP_PWM 0x49
37
Balaji T K13c3c502010-11-25 16:22:04 +053038/* Slave Address 0x48 */
Balaji T Kf843d332011-09-08 06:34:57 +000039#define VMMC_CFG_STATE 0x9A
40#define VMMC_CFG_VOLTATE 0x9B
Balaji T K13c3c502010-11-25 16:22:04 +053041#define VUSB_CFG_STATE 0xA2
42
43#define MISC1 0xE4
44#define VAC_MEAS (1 << 2)
45#define VBAT_MEAS (1 << 1)
46#define BB_MEAS (1 << 0)
47
48#define MISC2 0xE5
49
50/* Slave Address 0x49 */
51
Steve Sakomanf8f7c952010-07-15 12:53:42 -070052/* Battery CHARGER REGISTERS */
53#define CONTROLLER_INT_MASK 0xE0
54#define CONTROLLER_CTRL1 0xE1
55#define CONTROLLER_WDG 0xE2
56#define CONTROLLER_STAT1 0xE3
57#define CHARGERUSB_INT_STATUS 0xE4
58#define CHARGERUSB_INT_MASK 0xE5
59#define CHARGERUSB_STATUS_INT1 0xE6
60#define CHARGERUSB_STATUS_INT2 0xE7
61#define CHARGERUSB_CTRL1 0xE8
62#define CHARGERUSB_CTRL2 0xE9
63#define CHARGERUSB_CTRL3 0xEA
64#define CHARGERUSB_STAT1 0xEB
65#define CHARGERUSB_VOREG 0xEC
66#define CHARGERUSB_VICHRG 0xED
67#define CHARGERUSB_CINLIMIT 0xEE
68#define CHARGERUSB_CTRLLIMIT1 0xEF
69
70/* CHARGERUSB_VICHRG */
71#define CHARGERUSB_VICHRG_500 0x4
72#define CHARGERUSB_VICHRG_1500 0xE
73/* CHARGERUSB_CINLIMIT */
74#define CHARGERUSB_CIN_LIMIT_100 0x1
75#define CHARGERUSB_CIN_LIMIT_300 0x5
76#define CHARGERUSB_CIN_LIMIT_500 0x9
77#define CHARGERUSB_CIN_LIMIT_NONE 0xF
78/* CONTROLLER_INT_MASK */
79#define MVAC_FAULT (1 << 6)
80#define MAC_EOC (1 << 5)
81#define MBAT_REMOVED (1 << 4)
82#define MFAULT_WDG (1 << 3)
83#define MBAT_TEMP (1 << 2)
84#define MVBUS_DET (1 << 1)
85#define MVAC_DET (1 << 0)
86/* CHARGERUSB_INT_MASK */
87#define MASK_MCURRENT_TERM (1 << 3)
88#define MASK_MCHARGERUSB_STAT (1 << 2)
89#define MASK_MCHARGERUSB_THMREG (1 << 1)
90#define MASK_MCHARGERUSB_FAULT (1 << 0)
91/* CHARGERUSB_VOREG */
92#define CHARGERUSB_VOREG_3P52 0x01
93#define CHARGERUSB_VOREG_4P0 0x19
94#define CHARGERUSB_VOREG_4P2 0x23
95#define CHARGERUSB_VOREG_4P76 0x3F
Balaji T K13c3c502010-11-25 16:22:04 +053096/* CHARGERUSB_CTRL1 */
97#define SUSPEND_BOOT (1 << 7)
98#define OPA_MODE (1 << 6)
99#define HZ_MODE (1 << 5)
100#define TERM (1 << 4)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700101/* CHARGERUSB_CTRL2 */
102#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
103#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
104#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
Balaji T K13c3c502010-11-25 16:22:04 +0530105#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700106/* CONTROLLER_CTRL1 */
107#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
108#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
Balaji T K13c3c502010-11-25 16:22:04 +0530109/* CONTROLLER_STAT1 */
110#define CHRG_EXTCHRG_STATZ (1 << 7)
111#define CHRG_DET_N (1 << 5)
112#define VAC_DET (1 << 3)
113#define VBUS_DET (1 << 2)
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700114
Balaji T K13c3c502010-11-25 16:22:04 +0530115#define FG_REG_10 0xCA
116#define FG_REG_11 0xCB
117
118#define TOGGLE1 0x90
119#define FGS (1 << 5)
120#define FGR (1 << 4)
121#define GPADCS (1 << 1)
122#define GPADCR (1 << 0)
123
124#define CTRL_P2 0x34
125#define CTRL_P2_SP2 (1 << 2)
126#define CTRL_P2_EOCP2 (1 << 1)
127#define CTRL_P2_BUSY (1 << 0)
128
129#define GPCH0_LSB 0x57
130#define GPCH0_MSB 0x58
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700131
Nishanth Menon5b04f122013-03-26 05:20:52 +0000132/* Functions to read and write from TWL6030 */
133static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
134{
135 return i2c_write(chip_no, reg, 1, &val, 1);
136}
137
138static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
139{
140 return i2c_read(chip_no, reg, 1, val, 1);
141}
142
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700143void twl6030_init_battery_charging(void);
144void twl6030_usb_device_settings(void);
Balaji T K13c3c502010-11-25 16:22:04 +0530145void twl6030_start_usb_charging(void);
146void twl6030_stop_usb_charging(void);
147int twl6030_get_battery_voltage(void);
148int twl6030_get_battery_current(void);
Balaji T Kf843d332011-09-08 06:34:57 +0000149void twl6030_power_mmc_init(void);
Nishanth Menon65418172013-03-26 05:20:53 +0000150
151#endif /* TWL6030_H */