From patchwork Fri Oct 19 15:43:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majewski?= X-Patchwork-Id: 192750 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 A16DD2C0093 for ; Sat, 20 Oct 2012 02:46:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6A9D74A4C1; Fri, 19 Oct 2012 17:46:11 +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 25pqPsatCw3a; Fri, 19 Oct 2012 17:46:11 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B44714A54D; Fri, 19 Oct 2012 17:45:38 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 01BC24A4A5 for ; Fri, 19 Oct 2012 17:45:33 +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 vLJQFKzYHGNP for ; Fri, 19 Oct 2012 17:45:31 +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 mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by theia.denx.de (Postfix) with ESMTP id E4A934A4D1 for ; Fri, 19 Oct 2012 17:45:11 +0200 (CEST) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MC500H4PD28WN00@mailout3.samsung.com> for u-boot@lists.denx.de; Sat, 20 Oct 2012 00:45:10 +0900 (KST) X-AuditID: cbfee61a-b7f976d000001eb9-b5-50817586196b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id F5.D4.07865.68571805; Sat, 20 Oct 2012 00:45:10 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MC500FFND1YC320@mmp1.samsung.com> for u-boot@lists.denx.de; Sat, 20 Oct 2012 00:45:10 +0900 (KST) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Fri, 19 Oct 2012 17:43:57 +0200 Message-id: <1350661451-1273-11-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1350661451-1273-1-git-send-email-l.majewski@samsung.com> References: <1350661451-1273-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrIJMWRmVeSWpSXmKPExsVy+t9jAd220sYAg8MHFC3e7u1kd2D0OHtn B2MAYxSXTUpqTmZZapG+XQJXxqR5r5gKpspX/J72i72BcblkFyMHh4SAicSJLr4uRk4gU0zi wr31bF2MXBxCAosYJT6c2QLlLGaS2PBuPTtIFZuAnsTnu0+ZQGwRAQmJX/1XGUGKmAUeMEp8 aVoJlhAWCJV4/qQPzGYRUJXYdG8mE8g2XgE3iZ5P6hDb5CWe3u9jAwlzAoVf/S4HCQsJuEpc aL7LMoGRdwEjwypG0dSC5ILipPRcQ73ixNzi0rx0veT83E2MYI8/k9rBuLLB4hCjAAejEg/v r9sNAUKsiWXFlbmHGCU4mJVEeN3YGwOEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8zZ7pAQICaQn lqRmp6YWpBbBZJk4OKUaGJc6zlknsEbzM1/Ngi8x+RnMVvc3Mk1U2HNoU0YyY+0K5Sdi/9a9 nFuY/j/Ko3/LjMplPsb7mR5eqDu2LiuveLWExup6+Q9H/Wc98Jzg/yZnywu/5UXl3CzhJe9l M2UjsrxC5374N633KM/9rEd/r37YwH+uzTDFv+W0eJncyerM/DiNSKP1pkosxRmJhlrMRcWJ AKkBKpD0AQAA Cc: Jaehoon Chung , Kyungmin Park , Tom Rini Subject: [U-Boot] [PATCH v3 10/24] pmic:battery: Support for Trats Battery at PMIC framework 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 Trats battery is now treated in the same way as other power related devices. This approach allows for more unified handling of all devices responsible for power management. Signed-off-by: Lukasz Majewski Signed-off-by: Kyungmin Park Cc: Stefano Babic --- Changes for v2: - New patch at v2. Changes for v3: - only battery dependent battery_init method added - change code according to struct pmic redesign --- drivers/power/Makefile | 1 + drivers/power/battery/bat_trats.c | 94 +++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 0 deletions(-) create mode 100644 drivers/power/battery/bat_trats.c diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 7016d5b..74a0990 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -38,6 +38,7 @@ COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o COBJS-$(CONFIG_PMIC_MAX8998) += max8998/pmic_max8998.o COBJS-$(CONFIG_PMIC_MAX8997) += max8997/pmic_max8997.o +COBJS-$(CONFIG_POWER_BATTERY_TRATS) += battery/bat_trats.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/power/battery/bat_trats.c b/drivers/power/battery/bat_trats.c new file mode 100644 index 0000000..255a34e --- /dev/null +++ b/drivers/power/battery/bat_trats.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Lukasz Majewski + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include +#include +#include + +static struct battery battery_trats; + +static int power_battery_charge(struct pmic *bat) +{ + struct power_battery *p_bat = bat->pbat; + struct battery *battery = p_bat->bat; + int k; + + if (bat->chrg->chrg_state(p_bat->chrg, CHARGER_ENABLE, 450)) + return -1; + + for (k = 0; bat->chrg->chrg_bat_present(p_bat->chrg) && + bat->chrg->chrg_type(p_bat->muic) && + battery->state_of_chrg < 5; k++) { + udelay(10000000); + puts("."); + bat->fg->fg_battery_update(p_bat->fg, bat); + + if (k == 100) { + debug(" %d [V]", battery->voltage_uV); + puts("\n"); + k = 0; + } + + } + + bat->chrg->chrg_state(p_bat->chrg, CHARGER_DISABLE, 0); + + return 0; +} + +static int power_battery_init_trats(struct pmic *bat_, + struct pmic *fg_, + struct pmic *chrg_, + struct pmic *muic_) +{ + bat_->pbat->fg = fg_; + bat_->pbat->chrg = chrg_; + bat_->pbat->muic = muic_; + + bat_->fg = fg_->fg; + bat_->chrg = chrg_->chrg; + bat_->chrg->chrg_type = muic_->chrg->chrg_type; + return 0; +} + +static struct power_battery power_bat_trats = { + .bat = &battery_trats, + .battery_init = power_battery_init_trats, + .battery_charge = power_battery_charge, +}; + +int power_bat_init(unsigned char bus) +{ + struct pmic *p = pmic_alloc(); + static const char name[] = "BAT_TRATS"; + + debug("Board BAT init\n"); + + p->interface = PMIC_NONE; + p->name = name; + p->bus = bus; + + p->pbat = &power_bat_trats; + return 0; +}