Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Piotr Wilczek | a3c2061 | 2013-09-20 15:01:25 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Samsung Electronics |
| 4 | * Piotr Wilczek <p.wilczek@samsung.com> |
Piotr Wilczek | a3c2061 | 2013-09-20 15:01:25 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <power/pmic.h> |
| 9 | #include <power/battery.h> |
Przemyslaw Marczak | e5ef07f | 2014-01-22 11:24:11 +0100 | [diff] [blame] | 10 | #include <power/max77693_pmic.h> |
Piotr Wilczek | a3c2061 | 2013-09-20 15:01:25 +0200 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | |
| 13 | static struct battery battery_trats; |
| 14 | |
| 15 | static int power_battery_charge(struct pmic *bat) |
| 16 | { |
| 17 | struct power_battery *p_bat = bat->pbat; |
| 18 | |
Simon Glass | 05400a6 | 2014-05-20 06:01:35 -0600 | [diff] [blame] | 19 | if (bat->chrg->chrg_state(p_bat->chrg, PMIC_CHARGER_ENABLE, 450)) |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 20 | return -EINVAL; |
Piotr Wilczek | a3c2061 | 2013-09-20 15:01:25 +0200 | [diff] [blame] | 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static int power_battery_init_trats2(struct pmic *bat_, |
| 26 | struct pmic *fg_, |
| 27 | struct pmic *chrg_, |
| 28 | struct pmic *muic_) |
| 29 | { |
| 30 | bat_->pbat->fg = fg_; |
| 31 | bat_->pbat->chrg = chrg_; |
| 32 | bat_->pbat->muic = muic_; |
| 33 | |
| 34 | bat_->fg = fg_->fg; |
| 35 | bat_->chrg = chrg_->chrg; |
| 36 | bat_->chrg->chrg_type = muic_->chrg->chrg_type; |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static struct power_battery power_bat_trats2 = { |
| 41 | .bat = &battery_trats, |
| 42 | .battery_init = power_battery_init_trats2, |
| 43 | .battery_charge = power_battery_charge, |
| 44 | }; |
| 45 | |
| 46 | int power_bat_init(unsigned char bus) |
| 47 | { |
| 48 | static const char name[] = "BAT_TRATS2"; |
| 49 | struct pmic *p = pmic_alloc(); |
| 50 | |
| 51 | if (!p) { |
| 52 | printf("%s: POWER allocation error!\n", __func__); |
| 53 | return -ENOMEM; |
| 54 | } |
| 55 | |
| 56 | debug("Board BAT init\n"); |
| 57 | |
| 58 | p->interface = PMIC_NONE; |
| 59 | p->name = name; |
| 60 | p->bus = bus; |
| 61 | |
| 62 | p->pbat = &power_bat_trats2; |
| 63 | return 0; |
| 64 | } |