From patchwork Fri Nov 9 07:42:15 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: 197972 X-Patchwork-Delegate: agust@denx.de 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 734E42C00C8 for ; Fri, 9 Nov 2012 18:44:53 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D06B4AA05; Fri, 9 Nov 2012 08:44:38 +0100 (CET) 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 72HL9ZjdbPxx; Fri, 9 Nov 2012 08:44:37 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 02D6C4A8F5; Fri, 9 Nov 2012 08:43:52 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6F2D84A72A for ; Fri, 9 Nov 2012 08:43:47 +0100 (CET) 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 vqrM0wfV0JvZ for ; Fri, 9 Nov 2012 08:43:46 +0100 (CET) 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 mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by theia.denx.de (Postfix) with ESMTP id BEFB54A842 for ; Fri, 9 Nov 2012 08:43:11 +0100 (CET) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MD7007UUMR20BV0@mailout2.samsung.com> for u-boot@lists.denx.de; Fri, 09 Nov 2012 16:43:11 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-7a-509cb40eb296 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 7B.DF.12699.E04BC905; Fri, 09 Nov 2012 16:43:11 +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 <0MD700H3CMQZYP10@mmp1.samsung.com> for u-boot@lists.denx.de; Fri, 09 Nov 2012 16:43:10 +0900 (KST) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Fri, 09 Nov 2012 08:42:15 +0100 Message-id: <1352446951-12558-11-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1352446951-12558-1-git-send-email-l.majewski@samsung.com> References: <1352446951-12558-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAV3+LXMCDH7NZLV4u7eT3YHR4+yd HYwBjFFcNimpOZllqUX6dglcGe9+zGApWK9XcXjPddYGxkeqXYycHBICJhKP9xxmg7DFJC7c Ww9mCwksYpSY+8+ri5ELyF7MJPHwyyywBJuAnsTnu0+ZQGwRAQmJX/1XGUGKmAV2MEo0nzwL ViQsECqx8ORPsCIWAVWJc283gdm8Au4SF7tOM0Fsk5d4er8PrJ4TKL7z4iKozW4SvfMfM01g 5F3AyLCKUTS1ILmgOCk910ivODG3uDQvXS85P3cTI9jrz6R3MK5qsDjEKMDBqMTDm/hgdoAQ a2JZcWXuIUYJDmYlEd65mXMChHhTEiurUovy44tKc1KLDzFKc7AoifM2e6QECAmkJ5akZqem FqQWwWSZODilGhiXbnBm2NzzN4Eh83uo6+6Z841DQn6uCdyx5L54sP+B4ny5zJOPJ6Q5mq0P F3UTebxCsekfo2RN6kKRLVLvErYUc8+vtmH6oxUw53d24XvmH7/DZ8xs7GA5fPTim11fNwju fLGcc80B4cAf0zdOy01ad7rL+Lb/r0XCP7bZufp5n/21suvVtHtcSizFGYmGWsxFxYkAIW0l rvYBAAA= Cc: Tom Rini , Kyungmin Park Subject: [U-Boot] [PATCH v6 10/26] 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 Changes for v4: - Adding ./power/battery/Makefile - Introduce the libbattery.o at Makefile - Change the state of charge value from 5 to 100 Changes for v5: - None Changes for v6: - None --- Makefile | 3 +- drivers/power/battery/Makefile | 47 ++++++++++++++++++ drivers/power/battery/bat_trats.c | 94 +++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletions(-) create mode 100644 drivers/power/battery/Makefile create mode 100644 drivers/power/battery/bat_trats.c diff --git a/Makefile b/Makefile index aa8ace8..2a8a098 100644 --- a/Makefile +++ b/Makefile @@ -294,7 +294,8 @@ LIBS-y += drivers/net/phy/libphy.o LIBS-y += drivers/pci/libpci.o LIBS-y += drivers/pcmcia/libpcmcia.o LIBS-y += drivers/power/libpower.o \ - drivers/power/pmic/libpmic.o + drivers/power/pmic/libpmic.o \ + drivers/power/battery/libbattery.o LIBS-y += drivers/spi/libspi.o LIBS-y += drivers/dfu/libdfu.o ifeq ($(CPU),mpc83xx) diff --git a/drivers/power/battery/Makefile b/drivers/power/battery/Makefile new file mode 100644 index 0000000..b176701 --- /dev/null +++ b/drivers/power/battery/Makefile @@ -0,0 +1,47 @@ +# +# 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 $(TOPDIR)/config.mk + +LIB := $(obj)libbattery.o + +COBJS-$(CONFIG_POWER_BATTERY_TRATS) += bat_trats.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################## diff --git a/drivers/power/battery/bat_trats.c b/drivers/power/battery/bat_trats.c new file mode 100644 index 0000000..3cdf9b5 --- /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 < 100; 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; +}