blob: 97a9661150f4f439157360562e1cdf303986edf1 [file] [log] [blame]
Łukasz Majewskieba42392012-11-13 03:22:01 +00001/*
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
30static struct battery battery_trats;
31
32static 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++) {
Łukasz Majewski9dfa3d02013-06-25 15:28:15 +020044 udelay(2000000);
45 if (!(k % 5))
46 puts(".");
Łukasz Majewskieba42392012-11-13 03:22:01 +000047 bat->fg->fg_battery_update(p_bat->fg, bat);
48
Łukasz Majewski9dfa3d02013-06-25 15:28:15 +020049 if (k == 200) {
Łukasz Majewskieba42392012-11-13 03:22:01 +000050 debug(" %d [V]", battery->voltage_uV);
51 puts("\n");
52 k = 0;
53 }
54
Łukasz Majewski9dfa3d02013-06-25 15:28:15 +020055 if (ctrlc()) {
56 printf("\nCharging disabled on request.\n");
57 goto exit;
58 }
Łukasz Majewskieba42392012-11-13 03:22:01 +000059 }
Łukasz Majewski9dfa3d02013-06-25 15:28:15 +020060 exit:
Łukasz Majewskieba42392012-11-13 03:22:01 +000061 bat->chrg->chrg_state(p_bat->chrg, CHARGER_DISABLE, 0);
62
63 return 0;
64}
65
66static int power_battery_init_trats(struct pmic *bat_,
67 struct pmic *fg_,
68 struct pmic *chrg_,
69 struct pmic *muic_)
70{
71 bat_->pbat->fg = fg_;
72 bat_->pbat->chrg = chrg_;
73 bat_->pbat->muic = muic_;
74
75 bat_->fg = fg_->fg;
76 bat_->chrg = chrg_->chrg;
77 bat_->chrg->chrg_type = muic_->chrg->chrg_type;
78 return 0;
79}
80
81static struct power_battery power_bat_trats = {
82 .bat = &battery_trats,
83 .battery_init = power_battery_init_trats,
84 .battery_charge = power_battery_charge,
85};
86
87int power_bat_init(unsigned char bus)
88{
89 static const char name[] = "BAT_TRATS";
90 struct pmic *p = pmic_alloc();
91
92 if (!p) {
93 printf("%s: POWER allocation error!\n", __func__);
94 return -ENOMEM;
95 }
96
97 debug("Board BAT init\n");
98
99 p->interface = PMIC_NONE;
100 p->name = name;
101 p->bus = bus;
102
103 p->pbat = &power_bat_trats;
104 return 0;
105}