From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Kosheliev Date: Wed, 24 Jul 2013 16:56:35 +0300 Subject: [U-Boot] [RFC PATCH 1/2] ARMV7: OMAP4: Add struct for twl603x data In-Reply-To: <1374674196-26071-1-git-send-email-Oleg.Kosheliev@ti.com> References: <1374674196-26071-1-git-send-email-Oleg.Kosheliev@ti.com> Message-ID: <1374674196-26071-2-git-send-email-Oleg.Kosheliev@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Oleg Kosheliev 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 patches for TI u-boot. Signed-off-by: Oleg Kosheliev --- 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 d421e60..badcd4a 100644 --- a/drivers/power/twl6030.c +++ b/drivers/power/twl6030.c @@ -25,6 +25,17 @@ #include +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; @@ -32,12 +43,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; @@ -49,7 +60,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; @@ -57,7 +69,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); @@ -132,7 +145,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; @@ -144,6 +157,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 029b21f..c0db668 100644 --- a/include/twl6030.h +++ b/include/twl6030.h @@ -129,6 +129,24 @@ #define GPCH0_LSB 0x57 #define GPCH0_MSB 0x58 +#define TWL6030_VBAT_MULT 40 * 1000 + +#define TWL6030_VBAT_SHIFT (10 + 3) + +typedef enum { + chip_TWL6030, + chip_TWL603X_cnt +}t_TWL603X_chip_type; + +struct twl6030_data{ + t_TWL603X_chip_type 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