pmic:battery: Support for Trats Battery at PMIC framework
authorŁukasz Majewski <l.majewski@samsung.com>
Tue, 13 Nov 2012 03:22:01 +0000 (03:22 +0000)
committerAnatolij Gustschin <agust@denx.de>
Wed, 14 Nov 2012 10:21:10 +0000 (11:21 +0100)
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 <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
Makefile
drivers/power/battery/Makefile [new file with mode: 0644]
drivers/power/battery/bat_trats.c [new file with mode: 0644]

index f78656adff1773541315beb0173a3da8cd246735..0f18e6cf3dd757f1b5c64c116ca090cd5a17b8c6 100644 (file)
--- 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 (file)
index 0000000..b176701
--- /dev/null
@@ -0,0 +1,47 @@
+#
+# Copyright (C) 2012 Samsung Electronics
+# Lukasz Majewski <l.majewski@samsung.com>
+#
+# 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 (file)
index 0000000..ca0d214
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * 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 <common.h>
+#include <power/pmic.h>
+#include <power/battery.h>
+#include <power/max8997_pmic.h>
+#include <errno.h>
+
+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)
+{
+       static const char name[] = "BAT_TRATS";
+       struct pmic *p = pmic_alloc();
+
+       if (!p) {
+               printf("%s: POWER allocation error!\n", __func__);
+               return -ENOMEM;
+       }
+
+       debug("Board BAT init\n");
+
+       p->interface = PMIC_NONE;
+       p->name = name;
+       p->bus = bus;
+
+       p->pbat = &power_bat_trats;
+       return 0;
+}