Commit 516799f6777caab2151ed276a3c198940962f06a

Authored by Steve Sakoman
Committed by Sandeep Paulraj
1 parent d708395d2f

ARMV7: Add support for the TWL6030 I2C power chip used in OMAP4 systems

This patch add the basic infrastructure for the TWL6030 driver and enables
support in the two existing OMAP4 boards, Panda and OMAP4430 SDP

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

Showing 5 changed files with 176 additions and 0 deletions Side-by-side Diff

drivers/power/Makefile
... ... @@ -26,6 +26,7 @@
26 26 LIB := $(obj)libpower.a
27 27  
28 28 COBJS-$(CONFIG_TWL4030_POWER) += twl4030.o
  29 +COBJS-$(CONFIG_TWL6030_POWER) += twl6030.o
29 30  
30 31 COBJS := $(COBJS-y)
31 32 SRCS := $(COBJS:.o=.c)
drivers/power/twl6030.c
  1 +/*
  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 */
  29 +static 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 +
  34 +static 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 +
  39 +void 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 +
  59 +void twl6030_init_battery_charging(void)
  60 +{
  61 + twl6030_start_usb_charging();
  62 + return;
  63 +}
  64 +
  65 +void 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
include/configs/omap4_panda.h
... ... @@ -103,6 +103,9 @@
103 103 #define CONFIG_DRIVER_OMAP34XX_I2C 1
104 104 #define CONFIG_I2C_MULTI_BUS 1
105 105  
  106 +/* TWL6030 */
  107 +#define CONFIG_TWL6030_POWER 1
  108 +
106 109 /* MMC */
107 110 #define CONFIG_MMC 1
108 111 #define CONFIG_OMAP3_MMC 1
include/configs/omap4_sdp4430.h
... ... @@ -104,6 +104,9 @@
104 104 #define CONFIG_DRIVER_OMAP34XX_I2C 1
105 105 #define CONFIG_I2C_MULTI_BUS 1
106 106  
  107 +/* TWL6030 */
  108 +#define CONFIG_TWL6030_POWER 1
  109 +
107 110 /* MMC */
108 111 #define CONFIG_MMC 1
109 112 #define CONFIG_OMAP3_MMC 1
  1 +/*
  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 +
  24 +#include <common.h>
  25 +#include <i2c.h>
  26 +
  27 +/* I2C chip addresses */
  28 +#define TWL6030_CHIP_PM 0x48
  29 +
  30 +#define TWL6030_CHIP_USB 0x49
  31 +#define TWL6030_CHIP_ADC 0x49
  32 +#define TWL6030_CHIP_CHARGER 0x49
  33 +#define TWL6030_CHIP_PWM 0x49
  34 +
  35 +/* Battery CHARGER REGISTERS */
  36 +#define CONTROLLER_INT_MASK 0xE0
  37 +#define CONTROLLER_CTRL1 0xE1
  38 +#define CONTROLLER_WDG 0xE2
  39 +#define CONTROLLER_STAT1 0xE3
  40 +#define CHARGERUSB_INT_STATUS 0xE4
  41 +#define CHARGERUSB_INT_MASK 0xE5
  42 +#define CHARGERUSB_STATUS_INT1 0xE6
  43 +#define CHARGERUSB_STATUS_INT2 0xE7
  44 +#define CHARGERUSB_CTRL1 0xE8
  45 +#define CHARGERUSB_CTRL2 0xE9
  46 +#define CHARGERUSB_CTRL3 0xEA
  47 +#define CHARGERUSB_STAT1 0xEB
  48 +#define CHARGERUSB_VOREG 0xEC
  49 +#define CHARGERUSB_VICHRG 0xED
  50 +#define CHARGERUSB_CINLIMIT 0xEE
  51 +#define CHARGERUSB_CTRLLIMIT1 0xEF
  52 +
  53 +/* CHARGERUSB_VICHRG */
  54 +#define CHARGERUSB_VICHRG_500 0x4
  55 +#define CHARGERUSB_VICHRG_1500 0xE
  56 +/* CHARGERUSB_CINLIMIT */
  57 +#define CHARGERUSB_CIN_LIMIT_100 0x1
  58 +#define CHARGERUSB_CIN_LIMIT_300 0x5
  59 +#define CHARGERUSB_CIN_LIMIT_500 0x9
  60 +#define CHARGERUSB_CIN_LIMIT_NONE 0xF
  61 +/* CONTROLLER_INT_MASK */
  62 +#define MVAC_FAULT (1 << 6)
  63 +#define MAC_EOC (1 << 5)
  64 +#define MBAT_REMOVED (1 << 4)
  65 +#define MFAULT_WDG (1 << 3)
  66 +#define MBAT_TEMP (1 << 2)
  67 +#define MVBUS_DET (1 << 1)
  68 +#define MVAC_DET (1 << 0)
  69 +/* CHARGERUSB_INT_MASK */
  70 +#define MASK_MCURRENT_TERM (1 << 3)
  71 +#define MASK_MCHARGERUSB_STAT (1 << 2)
  72 +#define MASK_MCHARGERUSB_THMREG (1 << 1)
  73 +#define MASK_MCHARGERUSB_FAULT (1 << 0)
  74 +/* CHARGERUSB_VOREG */
  75 +#define CHARGERUSB_VOREG_3P52 0x01
  76 +#define CHARGERUSB_VOREG_4P0 0x19
  77 +#define CHARGERUSB_VOREG_4P2 0x23
  78 +#define CHARGERUSB_VOREG_4P76 0x3F
  79 +/* CHARGERUSB_CTRL2 */
  80 +#define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
  81 +#define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
  82 +#define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
  83 +/* CONTROLLER_CTRL1 */
  84 +#define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
  85 +#define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
  86 +
  87 +#define VUSB_CFG_STATE 0xA2
  88 +#define MISC2 0xE5
  89 +
  90 +void twl6030_init_battery_charging(void);
  91 +void twl6030_usb_device_settings(void);