[U-Boot] [RFC PATCH v2 1/2] ARMV7: OMAP4: Add struct for twl603x data

Oleg Kosheliev oleg.kosheliev at globallogic.com
Tue Oct 8 14:49:55 CEST 2013


From: Oleg Kosheliev <oleg.kosheliev at ti.com>

The data struct is used to support different
PMIC chip types. It contains the chip type and
the data (e.g. registers addresses, adc multiplier)
which is different for twl6030 and twl6032.
Replaced some hardcoded values with the
structure vars.

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

Signed-off-by: Oleg Kosheliev <oleg.kosheliev at ti.com>
---
 drivers/power/twl6030.c |   25 ++++++++++++++++++++-----
 include/twl6030.h       |   18 ++++++++++++++++++
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/drivers/power/twl6030.c b/drivers/power/twl6030.c
index 0858b60..6bf1a33 100644
--- a/drivers/power/twl6030.c
+++ b/drivers/power/twl6030.c
@@ -9,6 +9,17 @@
 
 #include <twl6030.h>
 
+static struct twl6030_data *twl;
+
+static struct twl6030_data twl6030_info = {
+	.chip_type	= chip_TWL6030,
+	.adc_rbase	= GPCH0_LSB,
+	.adc_ctrl	= CTRL_P2,
+	.adc_enable	= CTRL_P2_SP2,
+	.vbat_mult	= TWL6030_VBAT_MULT,
+	.vbat_shift	= TWL6030_VBAT_SHIFT,
+};
+
 static int twl6030_gpadc_read_channel(u8 channel_no)
 {
 	u8 lsb = 0;
@@ -16,12 +27,12 @@ static int twl6030_gpadc_read_channel(u8 channel_no)
 	int ret = 0;
 
 	ret = twl6030_i2c_read_u8(TWL6030_CHIP_ADC,
-				  GPCH0_LSB + channel_no * 2, &lsb);
+				  twl->adc_rbase + channel_no * 2, &lsb);
 	if (ret)
 		return ret;
 
 	ret = twl6030_i2c_read_u8(TWL6030_CHIP_ADC,
-				  GPCH0_MSB + channel_no * 2, &msb);
+				  twl->adc_rbase + 1 + channel_no * 2, &msb);
 	if (ret)
 		return ret;
 
@@ -33,7 +44,8 @@ static int twl6030_gpadc_sw2_trigger(void)
 	u8 val;
 	int ret = 0;
 
-	ret = twl6030_i2c_write_u8(TWL6030_CHIP_ADC, CTRL_P2, CTRL_P2_SP2);
+	ret = twl6030_i2c_write_u8(TWL6030_CHIP_ADC,
+				   twl->adc_ctrl, twl->adc_enable);
 	if (ret)
 		return ret;
 
@@ -41,7 +53,8 @@ static int twl6030_gpadc_sw2_trigger(void)
 	val =  CTRL_P2_BUSY;
 
 	while (!((val & CTRL_P2_EOCP2) && (!(val & CTRL_P2_BUSY)))) {
-		ret = twl6030_i2c_read_u8(TWL6030_CHIP_ADC, CTRL_P2, &val);
+		ret = twl6030_i2c_read_u8(TWL6030_CHIP_ADC,
+					  twl->adc_ctrl, &val);
 		if (ret)
 			return ret;
 		udelay(1000);
@@ -116,7 +129,7 @@ int twl6030_get_battery_voltage(void)
 		printf("Failed to read battery voltage\n");
 		return ret;
 	}
-	battery_volt = (battery_volt * 25 * 1000) >> (10 + 2);
+	battery_volt = (battery_volt * twl->vbat_mult) >> twl->vbat_shift;
 	printf("Battery Voltage: %d mV\n", battery_volt);
 
 	return battery_volt;
@@ -128,6 +141,8 @@ void twl6030_init_battery_charging(void)
 	int battery_volt = 0;
 	int ret = 0;
 
+	twl = &twl6030_info;
+
 	/* Enable VBAT measurement */
 	twl6030_i2c_write_u8(TWL6030_CHIP_PM, MISC1, VBAT_MEAS);
 
diff --git a/include/twl6030.h b/include/twl6030.h
index b4035ba..9399737 100644
--- a/include/twl6030.h
+++ b/include/twl6030.h
@@ -113,6 +113,24 @@
 #define GPCH0_LSB	0x57
 #define GPCH0_MSB	0x58
 
+#define TWL6030_VBAT_MULT	40 * 1000
+
+#define TWL6030_VBAT_SHIFT	(10 + 3)
+
+enum twl603x_chip_type{
+	chip_TWL6030,
+	chip_TWL603X_cnt
+};
+
+struct twl6030_data{
+	u8 chip_type;
+	u8 adc_rbase;
+	u8 adc_ctrl;
+	u8 adc_enable;
+	int vbat_mult;
+	int vbat_shift;
+};
+
 /* Functions to read and write from TWL6030 */
 static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 {
-- 
1.7.9.5



More information about the U-Boot mailing list