Steve Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Texas Instruments, <www.ti.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Steve Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Nishanth Menon | 6541817 | 2013-03-26 05:20:53 +0000 | [diff] [blame] | 8 | #ifndef TWL6030_H |
| 9 | #define TWL6030_H |
| 10 | |
Steve Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 11 | #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 K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 22 | /* Slave Address 0x48 */ |
Balaji T K | f843d33 | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 23 | #define VMMC_CFG_STATE 0x9A |
| 24 | #define VMMC_CFG_VOLTATE 0x9B |
Balaji T K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 25 | #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 Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 36 | /* 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 K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 80 | /* 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 Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 85 | /* 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 K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 89 | #define CHARGERUSB_CTRL2_VITERM_400 (7 << 5) |
Steve Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 90 | /* CONTROLLER_CTRL1 */ |
| 91 | #define CONTROLLER_CTRL1_EN_CHARGER (1 << 4) |
| 92 | #define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3) |
Balaji T K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 93 | /* 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 Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 98 | |
Balaji T K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 99 | #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 Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 115 | |
Oleg Kosheliev | 8cce7a9 | 2013-10-08 15:49:55 +0300 | [diff] [blame^] | 116 | #define TWL6030_VBAT_MULT 40 * 1000 |
| 117 | |
| 118 | #define TWL6030_VBAT_SHIFT (10 + 3) |
| 119 | |
| 120 | enum twl603x_chip_type{ |
| 121 | chip_TWL6030, |
| 122 | chip_TWL603X_cnt |
| 123 | }; |
| 124 | |
| 125 | struct twl6030_data{ |
| 126 | u8 chip_type; |
| 127 | u8 adc_rbase; |
| 128 | u8 adc_ctrl; |
| 129 | u8 adc_enable; |
| 130 | int vbat_mult; |
| 131 | int vbat_shift; |
| 132 | }; |
| 133 | |
Nishanth Menon | 5b04f12 | 2013-03-26 05:20:52 +0000 | [diff] [blame] | 134 | /* Functions to read and write from TWL6030 */ |
| 135 | static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val) |
| 136 | { |
| 137 | return i2c_write(chip_no, reg, 1, &val, 1); |
| 138 | } |
| 139 | |
| 140 | static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val) |
| 141 | { |
| 142 | return i2c_read(chip_no, reg, 1, val, 1); |
| 143 | } |
| 144 | |
Steve Sakoman | f8f7c95 | 2010-07-15 12:53:42 -0700 | [diff] [blame] | 145 | void twl6030_init_battery_charging(void); |
| 146 | void twl6030_usb_device_settings(void); |
Balaji T K | 13c3c50 | 2010-11-25 16:22:04 +0530 | [diff] [blame] | 147 | void twl6030_start_usb_charging(void); |
| 148 | void twl6030_stop_usb_charging(void); |
| 149 | int twl6030_get_battery_voltage(void); |
| 150 | int twl6030_get_battery_current(void); |
Balaji T K | f843d33 | 2011-09-08 06:34:57 +0000 | [diff] [blame] | 151 | void twl6030_power_mmc_init(void); |
Nishanth Menon | 6541817 | 2013-03-26 05:20:53 +0000 | [diff] [blame] | 152 | |
| 153 | #endif /* TWL6030_H */ |