1*516799f6SSteve Sakoman /* 2*516799f6SSteve Sakoman * (C) Copyright 2010 3*516799f6SSteve Sakoman * Texas Instruments, <www.ti.com> 4*516799f6SSteve Sakoman * 5*516799f6SSteve Sakoman * See file CREDITS for list of people who contributed to this 6*516799f6SSteve Sakoman * project. 7*516799f6SSteve Sakoman * 8*516799f6SSteve Sakoman * This program is free software; you can redistribute it and/or 9*516799f6SSteve Sakoman * modify it under the terms of the GNU General Public License as 10*516799f6SSteve Sakoman * published by the Free Software Foundation; either version 2 of 11*516799f6SSteve Sakoman * the License, or (at your option) any later version. 12*516799f6SSteve Sakoman * 13*516799f6SSteve Sakoman * This program is distributed in the hope that it will be useful, 14*516799f6SSteve Sakoman * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*516799f6SSteve Sakoman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*516799f6SSteve Sakoman * GNU General Public License for more details. 17*516799f6SSteve Sakoman * 18*516799f6SSteve Sakoman * You should have received a copy of the GNU General Public License 19*516799f6SSteve Sakoman * along with this program; if not, write to the Free Software 20*516799f6SSteve Sakoman * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*516799f6SSteve Sakoman * MA 02111-1307 USA 22*516799f6SSteve Sakoman */ 23*516799f6SSteve Sakoman #include <config.h> 24*516799f6SSteve Sakoman #ifdef CONFIG_TWL6030_POWER 25*516799f6SSteve Sakoman 26*516799f6SSteve Sakoman #include <twl6030.h> 27*516799f6SSteve Sakoman 28*516799f6SSteve Sakoman /* Functions to read and write from TWL6030 */ 29*516799f6SSteve Sakoman static inline int twl6030_i2c_write_u8(u8 chip_no, u8 val, u8 reg) 30*516799f6SSteve Sakoman { 31*516799f6SSteve Sakoman return i2c_write(chip_no, reg, 1, &val, 1); 32*516799f6SSteve Sakoman } 33*516799f6SSteve Sakoman 34*516799f6SSteve Sakoman static inline int twl6030_i2c_read_u8(u8 chip_no, u8 *val, u8 reg) 35*516799f6SSteve Sakoman { 36*516799f6SSteve Sakoman return i2c_read(chip_no, reg, 1, val, 1); 37*516799f6SSteve Sakoman } 38*516799f6SSteve Sakoman 39*516799f6SSteve Sakoman void twl6030_start_usb_charging(void) 40*516799f6SSteve Sakoman { 41*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VICHRG_1500, 42*516799f6SSteve Sakoman CHARGERUSB_VICHRG); 43*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CIN_LIMIT_NONE, 44*516799f6SSteve Sakoman CHARGERUSB_CINLIMIT); 45*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MBAT_TEMP, 46*516799f6SSteve Sakoman CONTROLLER_INT_MASK); 47*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MASK_MCHARGERUSB_THMREG, 48*516799f6SSteve Sakoman CHARGERUSB_INT_MASK); 49*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VOREG_4P0, 50*516799f6SSteve Sakoman CHARGERUSB_VOREG); 51*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CTRL2_VITERM_100, 52*516799f6SSteve Sakoman CHARGERUSB_CTRL2); 53*516799f6SSteve Sakoman /* Enable USB charging */ 54*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CONTROLLER_CTRL1_EN_CHARGER, 55*516799f6SSteve Sakoman CONTROLLER_CTRL1); 56*516799f6SSteve Sakoman return; 57*516799f6SSteve Sakoman } 58*516799f6SSteve Sakoman 59*516799f6SSteve Sakoman void twl6030_init_battery_charging(void) 60*516799f6SSteve Sakoman { 61*516799f6SSteve Sakoman twl6030_start_usb_charging(); 62*516799f6SSteve Sakoman return; 63*516799f6SSteve Sakoman } 64*516799f6SSteve Sakoman 65*516799f6SSteve Sakoman void twl6030_usb_device_settings() 66*516799f6SSteve Sakoman { 67*516799f6SSteve Sakoman u8 data = 0; 68*516799f6SSteve Sakoman 69*516799f6SSteve Sakoman /* Select APP Group and set state to ON */ 70*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_PM, 0x21, VUSB_CFG_STATE); 71*516799f6SSteve Sakoman 72*516799f6SSteve Sakoman twl6030_i2c_read_u8(TWL6030_CHIP_PM, &data, MISC2); 73*516799f6SSteve Sakoman data |= 0x10; 74*516799f6SSteve Sakoman 75*516799f6SSteve Sakoman /* Select the input supply for VBUS regulator */ 76*516799f6SSteve Sakoman twl6030_i2c_write_u8(TWL6030_CHIP_PM, data, MISC2); 77*516799f6SSteve Sakoman } 78*516799f6SSteve Sakoman #endif 79