blob: 1172970d1e0b261e9e38008c8146028e22000263 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Piotr Wilczeka3c20612013-09-20 15:01:25 +02002/*
3 * Copyright (C) 2013 Samsung Electronics
4 * Piotr Wilczek <p.wilczek@samsung.com>
Piotr Wilczeka3c20612013-09-20 15:01:25 +02005 */
6
7#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Piotr Wilczeka3c20612013-09-20 15:01:25 +02009#include <power/pmic.h>
10#include <power/battery.h>
Przemyslaw Marczake5ef07f2014-01-22 11:24:11 +010011#include <power/max77693_pmic.h>
Piotr Wilczeka3c20612013-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 Glass05400a62014-05-20 06:01:35 -060020 if (bat->chrg->chrg_state(p_bat->chrg, PMIC_CHARGER_ENABLE, 450))
Jaehoon Chung10e80f32016-12-15 20:49:50 +090021 return -EINVAL;
Piotr Wilczeka3c20612013-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}