1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2013 Samsung Electronics
4 * Piotr Wilczek <p.wilczek@samsung.com>
5 */
6
7 #include <common.h>
8 #include <power/pmic.h>
9 #include <power/battery.h>
10 #include <power/max77693_pmic.h>
11 #include <errno.h>
12
13 static struct battery battery_trats;
14
power_battery_charge(struct pmic * bat)15 static int power_battery_charge(struct pmic *bat)
16 {
17 struct power_battery *p_bat = bat->pbat;
18
19 if (bat->chrg->chrg_state(p_bat->chrg, PMIC_CHARGER_ENABLE, 450))
20 return -EINVAL;
21
22 return 0;
23 }
24
power_battery_init_trats2(struct pmic * bat_,struct pmic * fg_,struct pmic * chrg_,struct pmic * muic_)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
power_bat_init(unsigned char bus)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 }
65