Patchwork [U-Boot,RFC,2/2] ARMV7: OMAP4: Add twl6032 support

login
register
mail settings
Submitter Oleg Kosheliev
Date July 24, 2013, 1:56 p.m.
Message ID <1374674196-26071-3-git-send-email-Oleg.Kosheliev@ti.com>
Download mbox | patch
Permalink /patch/261427/
State Changes Requested
Delegated to: Tom Rini
Headers show

Comments

Oleg Kosheliev - July 24, 2013, 1:56 p.m.
From: Oleg Kosheliev <oleg.kosheliev@ti.com>

Added chip type detection and twl6032
support in the battery control
and charge functions.

Based on Balaji T K <balajitk@ti.com> patches for TI u-boot.

Signed-off-by: Oleg Kosheliev <oleg.kosheliev@ti.com>
---
 drivers/power/twl6030.c |   56 ++++++++++++++++++++++++++++++++++++++++++-----
 include/twl6030.h       |   20 +++++++++++++++++
 2 files changed, 70 insertions(+), 6 deletions(-)
Tom Rini - Aug. 28, 2013, 1:58 p.m.
On Wed, Jul 24, 2013 at 04:56:36PM +0300, Oleg Kosheliev wrote:

> From: Oleg Kosheliev <oleg.kosheliev@ti.com>
> 
> Added chip type detection and twl6032
> support in the battery control
> and charge functions.
> 
> Based on Balaji T K <balajitk@ti.com> patches for TI u-boot.
> 
> Signed-off-by: Oleg Kosheliev <oleg.kosheliev@ti.com>
[snip]
> +	ret = twl6030_i2c_read_u8(TWL6030_CHIP_USB, USB_PRODUCT_ID_LSB, &val);
> +	if (ret) {
> +		printf("twl6030_init_battery_charging(): " \
> +		       "could not determine chip!\n");
> +		return;

Please use puts() and don't split text strings, they can be longer than
80char wide.

[snip]
> +		printf("twl6030_init_battery_charging(): " \
> +		       "unsupported chip type\n");

Same.

Patch

diff --git a/drivers/power/twl6030.c b/drivers/power/twl6030.c
index badcd4a..8d8f1b5 100644
--- a/drivers/power/twl6030.c
+++ b/drivers/power/twl6030.c
@@ -36,6 +36,15 @@  static struct twl6030_data twl6030_info = {
 	.vbat_shift	= TWL6030_VBAT_SHIFT,
 };
 
+static struct twl6030_data twl6032_info = {
+	.chip_type	= chip_TWL6032,
+	.adc_rbase	= TWL6032_GPCH0_LSB,
+	.adc_ctrl	= TWL6032_CTRL_P1,
+	.adc_enable	= CTRL_P1_SP1,
+	.vbat_mult	= TWL6032_VBAT_MULT,
+	.vbat_shift	= TWL6032_VBAT_SHIFT,
+};
+
 static int twl6030_gpadc_read_channel(u8 channel_no)
 {
 	u8 lsb = 0;
@@ -131,6 +140,18 @@  int twl6030_get_battery_voltage(void)
 {
 	int battery_volt = 0;
 	int ret = 0;
+	u8 vbatch;
+
+	if (twl->chip_type == chip_TWL6030) {
+		vbatch = TWL6030_GPADC_VBAT_CHNL;
+	} else {
+		ret = twl6030_i2c_write_u8(TWL6030_CHIP_ADC,
+					   TWL6032_GPSELECT_ISB,
+					   TWL6032_GPADC_VBAT_CHNL);
+		if (ret)
+			return ret;
+		vbatch = 0;
+	}
 
 	/* Start GPADC SW conversion */
 	ret = twl6030_gpadc_sw2_trigger();
@@ -140,7 +161,7 @@  int twl6030_get_battery_voltage(void)
 	}
 
 	/* measure Vbat voltage */
-	battery_volt = twl6030_gpadc_read_channel(7);
+	battery_volt = twl6030_gpadc_read_channel(vbatch);
 	if (battery_volt < 0) {
 		printf("Failed to read battery voltage\n");
 		return ret;
@@ -153,14 +174,37 @@  int twl6030_get_battery_voltage(void)
 
 void twl6030_init_battery_charging(void)
 {
-	u8 stat1 = 0;
+	u8 val = 0;
 	int battery_volt = 0;
 	int ret = 0;
 
-	twl = &twl6030_info;
+	ret = twl6030_i2c_read_u8(TWL6030_CHIP_USB, USB_PRODUCT_ID_LSB, &val);
+	if (ret) {
+		printf("twl6030_init_battery_charging(): " \
+		       "could not determine chip!\n");
+		return;
+	}
+	if (val == 0x30) {
+		twl = &twl6030_info;
+	} else if (val == 0x32) {
+		twl = &twl6032_info;
+	} else {
+		printf("twl6030_init_battery_charging(): " \
+		       "unsupported chip type\n");
+		return;
+	}
 
 	/* Enable VBAT measurement */
-	twl6030_i2c_write_u8(TWL6030_CHIP_PM, MISC1, VBAT_MEAS);
+	if (twl->chip_type == chip_TWL6030) {
+		twl6030_i2c_write_u8(TWL6030_CHIP_PM, MISC1, VBAT_MEAS);
+		twl6030_i2c_write_u8(TWL6030_CHIP_ADC,
+				     TWL6030_GPADC_CTRL,
+				     GPADC_CTRL_SCALER_DIV4);
+	} else {
+		twl6030_i2c_write_u8(TWL6030_CHIP_ADC,
+				     TWL6032_GPADC_CTRL2,
+				     GPADC_CTRL2_CH18_SCALER_EN);
+	}
 
 	/* Enable GPADC module */
 	ret = twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, TOGGLE1, FGS | GPADCS);
@@ -177,10 +221,10 @@  void twl6030_init_battery_charging(void)
 		printf("Main battery voltage too low!\n");
 
 	/* Check for the presence of USB charger */
-	twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, CONTROLLER_STAT1, &stat1);
+	twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, CONTROLLER_STAT1, &val);
 
 	/* check for battery presence indirectly via Fuel gauge */
-	if ((stat1 & VBUS_DET) && (battery_volt < 3300))
+	if ((val & VBUS_DET) && (battery_volt < 3300))
 		twl6030_start_usb_charging();
 
 	return;
diff --git a/include/twl6030.h b/include/twl6030.h
index c0db668..9fd2c8b 100644
--- a/include/twl6030.h
+++ b/include/twl6030.h
@@ -126,15 +126,35 @@ 
 #define CTRL_P2_EOCP2	(1 << 1)
 #define CTRL_P2_BUSY	(1 << 0)
 
+#define TWL6032_CTRL_P1	0x36
+#define CTRL_P1_SP1	(1 << 3)
+
 #define GPCH0_LSB	0x57
 #define GPCH0_MSB	0x58
 
+#define TWL6032_GPCH0_LSB	0x3b
+
+#define TWL6032_GPSELECT_ISB	0x35
+
+#define USB_PRODUCT_ID_LSB	0x02
+
+#define TWL6030_GPADC_VBAT_CHNL	0x07
+#define TWL6032_GPADC_VBAT_CHNL	0x12
+
+#define TWL6030_GPADC_CTRL	0x2e
+#define TWL6032_GPADC_CTRL2	0x2f
+#define GPADC_CTRL2_CH18_SCALER_EN	(1 << 2)
+#define GPADC_CTRL_SCALER_DIV4		(1 << 3)
+
 #define TWL6030_VBAT_MULT	40 * 1000
+#define TWL6032_VBAT_MULT	25 * 1000
 
 #define TWL6030_VBAT_SHIFT	(10 + 3)
+#define TWL6032_VBAT_SHIFT	(12 + 2)
 
 typedef enum {
 	chip_TWL6030,
+	chip_TWL6032,
 	chip_TWL603X_cnt
 }t_TWL603X_chip_type;