blob: cf1da6b6a23d160349287661225d39e8b3222eb3 [file] [log] [blame]
Steve Sakoman516799f2010-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#include <config.h>
24#ifdef CONFIG_TWL6030_POWER
25
26#include <twl6030.h>
27
28/* Functions to read and write from TWL6030 */
29static inline int twl6030_i2c_write_u8(u8 chip_no, u8 val, u8 reg)
30{
31 return i2c_write(chip_no, reg, 1, &val, 1);
32}
33
34static inline int twl6030_i2c_read_u8(u8 chip_no, u8 *val, u8 reg)
35{
36 return i2c_read(chip_no, reg, 1, val, 1);
37}
38
39void twl6030_start_usb_charging(void)
40{
41 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VICHRG_1500,
42 CHARGERUSB_VICHRG);
43 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CIN_LIMIT_NONE,
44 CHARGERUSB_CINLIMIT);
45 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MBAT_TEMP,
46 CONTROLLER_INT_MASK);
47 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MASK_MCHARGERUSB_THMREG,
48 CHARGERUSB_INT_MASK);
49 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VOREG_4P0,
50 CHARGERUSB_VOREG);
51 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CTRL2_VITERM_100,
52 CHARGERUSB_CTRL2);
53 /* Enable USB charging */
54 twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CONTROLLER_CTRL1_EN_CHARGER,
55 CONTROLLER_CTRL1);
56 return;
57}
58
59void twl6030_init_battery_charging(void)
60{
61 twl6030_start_usb_charging();
62 return;
63}
64
65void twl6030_usb_device_settings()
66{
67 u8 data = 0;
68
69 /* Select APP Group and set state to ON */
70 twl6030_i2c_write_u8(TWL6030_CHIP_PM, 0x21, VUSB_CFG_STATE);
71
72 twl6030_i2c_read_u8(TWL6030_CHIP_PM, &data, MISC2);
73 data |= 0x10;
74
75 /* Select the input supply for VBUS regulator */
76 twl6030_i2c_write_u8(TWL6030_CHIP_PM, data, MISC2);
77}
78#endif