]> git.sur5r.net Git - u-boot/blob - drivers/power/pmic/muic_max8997.c
powerpc/83xx/km: make local functions and structs static
[u-boot] / drivers / power / pmic / muic_max8997.c
1 /*
2  *  Copyright (C) 2012 Samsung Electronics
3  *  Lukasz Majewski <l.majewski@samsung.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <power/pmic.h>
26 #include <power/power_chrg.h>
27 #include <power/max8997_muic.h>
28 #include <i2c.h>
29 #include <errno.h>
30
31 static int power_chrg_get_type(struct pmic *p)
32 {
33         unsigned int val;
34         unsigned char charge_type, charger;
35
36         if (pmic_probe(p))
37                 return CHARGER_NO;
38
39         pmic_reg_read(p, MAX8997_MUIC_STATUS2, &val);
40         charge_type = val & MAX8997_MUIC_CHG_MASK;
41
42         switch (charge_type) {
43         case MAX8997_MUIC_CHG_NO:
44                 charger = CHARGER_NO;
45                 break;
46         case MAX8997_MUIC_CHG_USB:
47         case MAX8997_MUIC_CHG_USB_D:
48                 charger = CHARGER_USB;
49                 break;
50         case MAX8997_MUIC_CHG_TA:
51         case MAX8997_MUIC_CHG_TA_1A:
52                 charger = CHARGER_TA;
53                 break;
54         case MAX8997_MUIC_CHG_TA_500:
55                 charger = CHARGER_TA_500;
56                 break;
57         default:
58                 charger = CHARGER_UNKNOWN;
59                 break;
60         }
61
62         return charger;
63 }
64
65 static struct power_chrg power_chrg_muic_ops = {
66         .chrg_type = power_chrg_get_type,
67 };
68
69 int power_muic_init(unsigned int bus)
70 {
71         static const char name[] = "MAX8997_MUIC";
72         struct pmic *p = pmic_alloc();
73
74         if (!p) {
75                 printf("%s: POWER allocation error!\n", __func__);
76                 return -ENOMEM;
77         }
78
79         debug("Board Micro USB Interface Controller init\n");
80
81         p->name = name;
82         p->interface = PMIC_I2C;
83         p->number_of_regs = MUIC_NUM_OF_REGS;
84         p->hw.i2c.addr = MAX8997_MUIC_I2C_ADDR;
85         p->hw.i2c.tx_num = 1;
86         p->bus = bus;
87
88         p->chrg = &power_chrg_muic_ops;
89         return 0;
90 }