blob: 969ce902395f55b8145be13458ebca49a3f93f0d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Łukasz Majewskid19fa4c2012-11-13 03:22:02 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * Lukasz Majewski <l.majewski@samsung.com>
Łukasz Majewskid19fa4c2012-11-13 03:22:02 +00005 */
6
7#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Łukasz Majewskid19fa4c2012-11-13 03:22:02 +00009#include <power/pmic.h>
10#include <power/power_chrg.h>
11#include <power/max8997_muic.h>
12#include <i2c.h>
13#include <errno.h>
14
15static int power_chrg_get_type(struct pmic *p)
16{
17 unsigned int val;
18 unsigned char charge_type, charger;
19
20 if (pmic_probe(p))
21 return CHARGER_NO;
22
23 pmic_reg_read(p, MAX8997_MUIC_STATUS2, &val);
24 charge_type = val & MAX8997_MUIC_CHG_MASK;
25
26 switch (charge_type) {
27 case MAX8997_MUIC_CHG_NO:
28 charger = CHARGER_NO;
29 break;
30 case MAX8997_MUIC_CHG_USB:
31 case MAX8997_MUIC_CHG_USB_D:
32 charger = CHARGER_USB;
33 break;
34 case MAX8997_MUIC_CHG_TA:
35 case MAX8997_MUIC_CHG_TA_1A:
36 charger = CHARGER_TA;
37 break;
38 case MAX8997_MUIC_CHG_TA_500:
39 charger = CHARGER_TA_500;
40 break;
41 default:
42 charger = CHARGER_UNKNOWN;
43 break;
44 }
45
46 return charger;
47}
48
49static struct power_chrg power_chrg_muic_ops = {
50 .chrg_type = power_chrg_get_type,
51};
52
53int power_muic_init(unsigned int bus)
54{
55 static const char name[] = "MAX8997_MUIC";
56 struct pmic *p = pmic_alloc();
57
58 if (!p) {
59 printf("%s: POWER allocation error!\n", __func__);
60 return -ENOMEM;
61 }
62
63 debug("Board Micro USB Interface Controller init\n");
64
65 p->name = name;
66 p->interface = PMIC_I2C;
67 p->number_of_regs = MUIC_NUM_OF_REGS;
68 p->hw.i2c.addr = MAX8997_MUIC_I2C_ADDR;
69 p->hw.i2c.tx_num = 1;
70 p->bus = bus;
71
72 p->chrg = &power_chrg_muic_ops;
73 return 0;
74}