blob: 1172970d1e0b261e9e38008c8146028e22000263 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Piotr Wilczeka88aab62013-09-20 15:01:25 +02002/*
3 * Copyright (C) 2013 Samsung Electronics
4 * Piotr Wilczek <p.wilczek@samsung.com>
Piotr Wilczeka88aab62013-09-20 15:01:25 +02005 */
6
7#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Piotr Wilczeka88aab62013-09-20 15:01:25 +02009#include <power/pmic.h>
10#include <power/battery.h>
Przemyslaw Marczak7f39b062014-01-22 11:24:11 +010011#include <power/max77693_pmic.h>
Piotr Wilczeka88aab62013-09-20 15:01:25 +020012#include <errno.h>
13
14static struct battery battery_trats;
15
16static int power_battery_charge(struct pmic *bat)
17{
18 struct power_battery *p_bat = bat->pbat;
19
Simon Glass78a36c32014-05-20 06:01:35 -060020 if (bat->chrg->chrg_state(p_bat->chrg, PMIC_CHARGER_ENABLE, 450))
Jaehoon Chung505cf472016-12-15 20:49:50 +090021 return -EINVAL;
Piotr Wilczeka88aab62013-09-20 15:01:25 +020022
23 return 0;
24}
25
26static int power_battery_init_trats2(struct pmic *bat_,
27 struct pmic *fg_,
28 struct pmic *chrg_,
29 struct pmic *muic_)
30{
31 bat_->pbat->fg = fg_;
32 bat_->pbat->chrg = chrg_;
33 bat_->pbat->muic = muic_;
34
35 bat_->fg = fg_->fg;
36 bat_->chrg = chrg_->chrg;
37 bat_->chrg->chrg_type = muic_->chrg->chrg_type;
38 return 0;
39}
40
41static struct power_battery power_bat_trats2 = {
42 .bat = &battery_trats,
43 .battery_init = power_battery_init_trats2,
44 .battery_charge = power_battery_charge,
45};
46
47int power_bat_init(unsigned char bus)
48{
49 static const char name[] = "BAT_TRATS2";
50 struct pmic *p = pmic_alloc();
51
52 if (!p) {
53 printf("%s: POWER allocation error!\n", __func__);
54 return -ENOMEM;
55 }
56
57 debug("Board BAT init\n");
58
59 p->interface = PMIC_NONE;
60 p->name = name;
61 p->bus = bus;
62
63 p->pbat = &power_bat_trats2;
64 return 0;
65}