blob: b4035ba4fe750d98b187afa77523ca48f9ba325c [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 */
Balaji T Kf843d332011-09-08 06:34:57 +000023#define VMMC_CFG_STATE 0x9A
24#define VMMC_CFG_VOLTATE 0x9B
Balaji T K13c3c502010-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 Sakomanf8f7c952010-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 K13c3c502010-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 Sakomanf8f7c952010-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 K13c3c502010-11-25 16:22:04 +053089#define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
Steve Sakomanf8f7c952010-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 K13c3c502010-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 Sakomanf8f7c952010-07-15 12:53:42 -070098
Balaji T K13c3c502010-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
113#define GPCH0_LSB 0x57
114#define GPCH0_MSB 0x58
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700115
Nishanth Menon5b04f122013-03-26 05:20:52 +0000116/* Functions to read and write from TWL6030 */
117static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
118{
119 return i2c_write(chip_no, reg, 1, &val, 1);
120}
121
122static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
123{
124 return i2c_read(chip_no, reg, 1, val, 1);
125}
126
Steve Sakomanf8f7c952010-07-15 12:53:42 -0700127void twl6030_init_battery_charging(void);
128void twl6030_usb_device_settings(void);
Balaji T K13c3c502010-11-25 16:22:04 +0530129void twl6030_start_usb_charging(void);
130void twl6030_stop_usb_charging(void);
131int twl6030_get_battery_voltage(void);
132int twl6030_get_battery_current(void);
Balaji T Kf843d332011-09-08 06:34:57 +0000133void twl6030_power_mmc_init(void);
Nishanth Menon65418172013-03-26 05:20:53 +0000134
135#endif /* TWL6030_H */