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