Commit eba423910c78ca822653dfebe113664ef352ce94

Authored by Łukasz Majewski
Committed by Anatolij Gustschin
1 parent bd8479e8de

pmic:battery: Support for Trats Battery at PMIC framework

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>

Showing 3 changed files with 149 additions and 1 deletions Side-by-side Diff

... ... @@ -294,7 +294,8 @@
294 294 LIBS-y += drivers/pci/libpci.o
295 295 LIBS-y += drivers/pcmcia/libpcmcia.o
296 296 LIBS-y += drivers/power/libpower.o \
297   - drivers/power/pmic/libpmic.o
  297 + drivers/power/pmic/libpmic.o \
  298 + drivers/power/battery/libbattery.o
298 299 LIBS-y += drivers/spi/libspi.o
299 300 LIBS-y += drivers/dfu/libdfu.o
300 301 ifeq ($(CPU),mpc83xx)
drivers/power/battery/Makefile
  1 +#
  2 +# Copyright (C) 2012 Samsung Electronics
  3 +# Lukasz Majewski <l.majewski@samsung.com>
  4 +#
  5 +# See file CREDITS for list of people who contributed to this
  6 +# project.
  7 +#
  8 +# This program is free software; you can redistribute it and/or
  9 +# modify it under the terms of the GNU General Public License as
  10 +# published by the Free Software Foundation; either version 2 of
  11 +# the License, or (at your option) any later version.
  12 +#
  13 +# This program is distributed in the hope that it will be useful,
  14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 +# GNU General Public License for more details.
  17 +#
  18 +# You should have received a copy of the GNU General Public License
  19 +# along with this program; if not, write to the Free Software
  20 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 +# MA 02111-1307 USA
  22 +#
  23 +
  24 +include $(TOPDIR)/config.mk
  25 +
  26 +LIB := $(obj)libbattery.o
  27 +
  28 +COBJS-$(CONFIG_POWER_BATTERY_TRATS) += bat_trats.o
  29 +
  30 +COBJS := $(COBJS-y)
  31 +SRCS := $(COBJS:.o=.c)
  32 +OBJS := $(addprefix $(obj),$(COBJS))
  33 +
  34 +all: $(LIB)
  35 +
  36 +$(LIB): $(obj).depend $(OBJS)
  37 + $(call cmd_link_o_target, $(OBJS))
  38 +
  39 +
  40 +#########################################################################
  41 +
  42 +# defines $(obj).depend target
  43 +include $(SRCTREE)/rules.mk
  44 +
  45 +sinclude $(obj).depend
  46 +
  47 +########################################################################
drivers/power/battery/bat_trats.c
  1 +/*
  2 + * Copyright (C) 2012 Samsung Electronics
  3 + * Lukasz Majewski <l.majewski@samsung.com>
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + */
  23 +
  24 +#include <common.h>
  25 +#include <power/pmic.h>
  26 +#include <power/battery.h>
  27 +#include <power/max8997_pmic.h>
  28 +#include <errno.h>
  29 +
  30 +static struct battery battery_trats;
  31 +
  32 +static int power_battery_charge(struct pmic *bat)
  33 +{
  34 + struct power_battery *p_bat = bat->pbat;
  35 + struct battery *battery = p_bat->bat;
  36 + int k;
  37 +
  38 + if (bat->chrg->chrg_state(p_bat->chrg, CHARGER_ENABLE, 450))
  39 + return -1;
  40 +
  41 + for (k = 0; bat->chrg->chrg_bat_present(p_bat->chrg) &&
  42 + bat->chrg->chrg_type(p_bat->muic) &&
  43 + battery->state_of_chrg < 100; k++) {
  44 + udelay(10000000);
  45 + puts(".");
  46 + bat->fg->fg_battery_update(p_bat->fg, bat);
  47 +
  48 + if (k == 100) {
  49 + debug(" %d [V]", battery->voltage_uV);
  50 + puts("\n");
  51 + k = 0;
  52 + }
  53 +
  54 + }
  55 +
  56 + bat->chrg->chrg_state(p_bat->chrg, CHARGER_DISABLE, 0);
  57 +
  58 + return 0;
  59 +}
  60 +
  61 +static int power_battery_init_trats(struct pmic *bat_,
  62 + struct pmic *fg_,
  63 + struct pmic *chrg_,
  64 + struct pmic *muic_)
  65 +{
  66 + bat_->pbat->fg = fg_;
  67 + bat_->pbat->chrg = chrg_;
  68 + bat_->pbat->muic = muic_;
  69 +
  70 + bat_->fg = fg_->fg;
  71 + bat_->chrg = chrg_->chrg;
  72 + bat_->chrg->chrg_type = muic_->chrg->chrg_type;
  73 + return 0;
  74 +}
  75 +
  76 +static struct power_battery power_bat_trats = {
  77 + .bat = &battery_trats,
  78 + .battery_init = power_battery_init_trats,
  79 + .battery_charge = power_battery_charge,
  80 +};
  81 +
  82 +int power_bat_init(unsigned char bus)
  83 +{
  84 + static const char name[] = "BAT_TRATS";
  85 + struct pmic *p = pmic_alloc();
  86 +
  87 + if (!p) {
  88 + printf("%s: POWER allocation error!\n", __func__);
  89 + return -ENOMEM;
  90 + }
  91 +
  92 + debug("Board BAT init\n");
  93 +
  94 + p->interface = PMIC_NONE;
  95 + p->name = name;
  96 + p->bus = bus;
  97 +
  98 + p->pbat = &power_bat_trats;
  99 + return 0;
  100 +}