From patchwork Tue Oct 8 12:49:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Kosheliev X-Patchwork-Id: 281465 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 344C42C0091 for ; Tue, 8 Oct 2013 23:54:34 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E725B4A0D2; Tue, 8 Oct 2013 14:54:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JtIrff11uJJn; Tue, 8 Oct 2013 14:54:29 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 697CA4A0D3; Tue, 8 Oct 2013 14:54:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2AE784A0A5 for ; Tue, 8 Oct 2013 14:54:09 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eNJPbSc89ZV5 for ; Tue, 8 Oct 2013 14:54:04 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from exprod5og108.obsmtp.com (exprod5og108.obsmtp.com [64.18.0.186]) by theia.denx.de (Postfix) with ESMTPS id 3200F4A0AE for ; Tue, 8 Oct 2013 14:53:52 +0200 (CEST) Received: from mail-ee0-f45.google.com ([74.125.83.45]) (using TLSv1) by exprod5ob108.postini.com ([64.18.4.12]) with SMTP ID DSNKUlQAXUZy2BfS+zPKIbsNpSZFN/jvhi1W@postini.com; Tue, 08 Oct 2013 05:53:59 PDT Received: by mail-ee0-f45.google.com with SMTP id c50so4009356eek.18 for ; Tue, 08 Oct 2013 05:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=3Lavrd61z5k2DAEWK50cByXgotU8zweKNF2xQrTV/5U=; b=YQRPDSN0a50Cs1Q2PkPXiL0LA5XHlAdb9EmqE2K7zbgHKPWh3u2oDyBETTvBIDbjfU cjmryoxvmON2UT9kkySPLOts1bmU0I40hy2YfXnDA7ofQlhgJt4TeXGC98GW2J0dbbS7 toLzgVda9tUj7/2e4N4LG1q3Jz0G7T/R/kzsc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3Lavrd61z5k2DAEWK50cByXgotU8zweKNF2xQrTV/5U=; b=CiF5ougS6aNVY5kKz6Gp2/+iuP4MvSnj/jHXhIpW+WMLDgvJVZ9BEOqLfI3tF9arit +sYtFtY3RiFRLniz08DQ4zToUsJG1i+xGJi7rFH1M9U+YhiTH0UAFRfNZykDWRgQRM6x hhwH0+gF73QRqpuium68tmQmBQYayXnsvZ6Uzrh308A8gkFDBdHKmBA4cNhSfF28mq9s A+cXrbKGoAXc2BBsIjGvpnsMaD0WAJYpPBAtdLneIpo4MfzHclNzb0ZPGII48mXwWZ3R kmV9++ytbJpwz9eP/PoyJdagx5KgrmUEtk4RJwfGZBicuTZpz2oVroiQeV3wyDYy7jpA BKCw== X-Gm-Message-State: ALoCoQl+fB6gvbCsn9MSqrctMKRcg6mfkuJXyUF1T1vqiWX+FvG9sJNCkjoSGEbK1j47YDUd88w1NxlQKMoMwSolabqvteDVumC8HAzU0+dI9mi/oSazBu9sZBesjEUphQOsDp/DJuIwK7PtP3VaVAMkvDn0VBt2yw== X-Received: by 10.14.109.66 with SMTP id r42mr2170015eeg.43.1381236828545; Tue, 08 Oct 2013 05:53:48 -0700 (PDT) X-Received: by 10.14.109.66 with SMTP id r42mr2170002eeg.43.1381236828464; Tue, 08 Oct 2013 05:53:48 -0700 (PDT) Received: from uglx0186028.synapse.com ([195.238.92.36]) by mx.google.com with ESMTPSA id j7sm75653645eeo.15.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Oct 2013 05:53:48 -0700 (PDT) From: Oleg Kosheliev To: u-boot@lists.denx.de Date: Tue, 8 Oct 2013 15:49:55 +0300 Message-Id: <1381236596-25128-2-git-send-email-Oleg.Kosheliev@globallogic.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1381236596-25128-1-git-send-email-Oleg.Kosheliev@globallogic.com> References: <1381236596-25128-1-git-send-email-Oleg.Kosheliev@globallogic.com> Subject: [U-Boot] [RFC PATCH v2 1/2] ARMV7: OMAP4: Add struct for twl603x data X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@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 0858b60..6bf1a33 100644 --- a/drivers/power/twl6030.c +++ b/drivers/power/twl6030.c @@ -9,6 +9,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; @@ -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) {