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

Submitted by Oleg Kosheliev on Oct. 8, 2013, 12:49 p.m.

Details

Message ID 1381236596-25128-2-git-send-email-Oleg.Kosheliev@globallogic.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Oleg Kosheliev Oct. 8, 2013, 12:49 p.m.
From: Oleg Kosheliev <oleg.kosheliev@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@ti.com> patches for TI u-boot.

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

Comments

Tom Rini Dec. 4, 2013, 10:03 p.m.
On Tue, Oct 08, 2013 at 03:49:55PM +0300, Oleg Kosheliev wrote:

> From: Oleg Kosheliev <oleg.kosheliev@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@ti.com> patches for TI u-boot.
> 
> Signed-off-by: Oleg Kosheliev <oleg.kosheliev@ti.com>

Since I don't see anything else needed, change wise, ignoring RFC and..
Applied to u-boot-ti/master, thanks!

Patch hide | download patch | download mbox

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)
 {