1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15#include <stdint.h> 16 17#include <platsupport/i2c.h> 18#include <platsupport/plat/pmic.h> 19 20#define MAX77686_BUSADDR 0x12 21#define MAX77802_BUSADDR 0x12 22 23typedef struct pmic { 24 i2c_slave_t i2c_slave; 25 i2c_kvslave_t kvslave; 26 void* priv;; 27} pmic_t; 28 29enum ldo_mode { 30 LDO_OFF, 31 LDO_STANDBY, 32 LDO_LOWPWR, 33 LDO_ON 34}; 35 36/** 37 * Initialise the PMIC 38 * @param[in] i2c A handle to the I2C bus that the PMIC is attached to 39 * @param[in] addr The slave address of the device 40 * @param[out] pmic A pmic structure to initialise 41 * @return 0 on success 42 */ 43int pmic_init(i2c_bus_t* i2c, int addr, pmic_t* pmic); 44 45/** 46 * Print the status of of the PMIC and its power rails 47 */ 48void pmic_print_status(pmic_t* pmic); 49 50/** 51 * Returns the number of LDOs that the PMIC controls 52 * @param[in] pmic A handle to the PMIC 53 * @return The number of LDOs that the PMIC controls, 54 * or -1 on failure. 55 */ 56int pmic_nldo(pmic_t* pmic); 57 58/** 59 * Configure a low dropout regulator 60 * @param[in] pmic A handle to the PMIC 61 * @param[in] ldo The LDO number, starting from 1 62 * @param[in] ldo_mode The modes at which the LDO should be switched on 63 * @param[in] mili_volt The number of millivolts that the LDO should drive at 64 * @return On success, returns the actual output millivolts of the 65 * regulator. Otherwise, returns -1. 66 */ 67int pmic_ldo_cfg(pmic_t* pmic, int ldo, enum ldo_mode ldo_mode, int milli_volt); 68 69/** 70 * Configure a low dropout regulator 71 * @param[in] pmic A handle to the PMIC 72 * @param[in] ldo The LDO number, starting from 1 73 * @param[out] ldo_mode If ldo_mode is not NULL and the request is successful, 74 * ldo_mode will contain the current operating mode 75 * configuration of the LDO. 76 * @return On success, returns the actual output millivolts of the 77 * regulator. Otherwise, returns -1. 78 */ 79int pmic_ldo_get_cfg(pmic_t* pmic, int ldo, enum ldo_mode* ldo_mode); 80 81/** 82 * Configures the reset delay of the reset button. 83 * @param[in] pmic A handle to the PMIC 84 * @param[in] ms The number of milli seconds that the delay should be 85 * configured to. 86 * @return On success, returns the actual number of milli seconds 87 * that the delay was programmed to be. Otherwise, returns -1. 88 */ 89int pmic_set_reset_delay(pmic_t* pmic, int ms); 90 91/** 92 * Retrieve the configured reset delay 93 * @param[in] pmic A handle to the PMIC 94 * @return On success, returns the reset delay in milli seconds. 95 * Otherwise, returns -1. 96 */ 97int pmic_get_reset_delay(pmic_t* pmic); 98 99