Ćukasz Majewski | eba4239 | 2012-11-13 03:22:01 +0000 | [diff] [blame^] | 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 | } |