Home | History | Annotate | Download | only in mfd
      1 // SPDX-License-Identifier: GPL-2.0+
      2 /*
      3  * Copyright (C) 2013 Samsung Electronics
      4  * Piotr Wilczek <p.wilczek (at) samsung.com>
      5  */
      6 
      7 #include <common.h>
      8 #include <power/pmic.h>
      9 #include <power/power_chrg.h>
     10 #include <power/max77693_muic.h>
     11 #include <i2c.h>
     12 #include <errno.h>
     13 
     14 static int power_chrg_get_type(struct pmic *p)
     15 {
     16 	unsigned int val;
     17 	unsigned int charge_type, charger;
     18 
     19 	/* if probe failed, return cable none */
     20 	if (pmic_probe(p))
     21 		return CHARGER_NO;
     22 
     23 	pmic_reg_read(p, MAX77693_MUIC_STATUS2, &val);
     24 
     25 	charge_type = val & MAX77693_MUIC_CHG_MASK;
     26 
     27 	switch (charge_type) {
     28 	case MAX77693_MUIC_CHG_NO:
     29 		charger = CHARGER_NO;
     30 		break;
     31 	case MAX77693_MUIC_CHG_USB:
     32 	case MAX77693_MUIC_CHG_USB_D:
     33 		charger = CHARGER_USB;
     34 		break;
     35 	case MAX77693_MUIC_CHG_TA:
     36 	case MAX77693_MUIC_CHG_TA_1A:
     37 		charger = CHARGER_TA;
     38 		break;
     39 	case MAX77693_MUIC_CHG_TA_500:
     40 		charger = CHARGER_TA_500;
     41 		break;
     42 	default:
     43 		charger = CHARGER_UNKNOWN;
     44 		break;
     45 	}
     46 
     47 	return charger;
     48 }
     49 
     50 static struct power_chrg power_chrg_muic_ops = {
     51 	.chrg_type = power_chrg_get_type,
     52 };
     53 
     54 int power_muic_init(unsigned int bus)
     55 {
     56 	static const char name[] = "MAX77693_MUIC";
     57 	struct pmic *p = pmic_alloc();
     58 
     59 	if (!p) {
     60 		printf("%s: POWER allocation error!\n", __func__);
     61 		return -ENOMEM;
     62 	}
     63 
     64 	debug("Board Micro USB Interface Controller init\n");
     65 
     66 	p->name = name;
     67 	p->interface = PMIC_I2C;
     68 	p->number_of_regs = MUIC_NUM_OF_REGS;
     69 	p->hw.i2c.addr = MAX77693_MUIC_I2C_ADDR;
     70 	p->hw.i2c.tx_num = 1;
     71 	p->bus = bus;
     72 
     73 	p->chrg = &power_chrg_muic_ops;
     74 
     75 	return 0;
     76 }
     77