2018-07-21 13:41:12 +01:00
|
|
|
/*
|
2019-10-20 21:12:20 +01:00
|
|
|
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
|
2018-07-21 13:41:12 +01:00
|
|
|
* Copyright (c) 2018, Icenowy Zheng <icenowy@aosc.io>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
2018-07-22 14:30:14 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
|
|
|
|
#include <arch_helpers.h>
|
|
|
|
#include <common/debug.h>
|
2019-10-21 03:34:38 +01:00
|
|
|
#include <drivers/allwinner/axp.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
#include <drivers/delay_timer.h>
|
|
|
|
#include <drivers/mentor/mi2cv.h>
|
|
|
|
#include <lib/mmio.h>
|
|
|
|
|
2018-10-14 22:13:53 +01:00
|
|
|
#include <sunxi_def.h>
|
2018-07-22 14:30:14 +01:00
|
|
|
#include <sunxi_mmap.h>
|
2018-10-14 12:02:02 +01:00
|
|
|
#include <sunxi_private.h>
|
2018-07-22 14:30:14 +01:00
|
|
|
|
|
|
|
#define AXP805_ADDR 0x36
|
|
|
|
|
2019-10-20 21:12:20 +01:00
|
|
|
static enum pmic_type {
|
|
|
|
UNKNOWN,
|
2018-07-22 14:30:14 +01:00
|
|
|
AXP805,
|
2019-10-20 21:12:20 +01:00
|
|
|
} pmic;
|
2018-07-22 14:30:14 +01:00
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
int axp_read(uint8_t reg)
|
2018-07-22 14:30:14 +01:00
|
|
|
{
|
2019-10-21 03:34:38 +01:00
|
|
|
uint8_t val;
|
2018-07-22 14:30:14 +01:00
|
|
|
int ret;
|
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
ret = i2c_write(AXP805_ADDR, 0, 0, ®, 1);
|
2019-10-20 21:28:14 +01:00
|
|
|
if (ret == 0)
|
2019-10-21 03:34:38 +01:00
|
|
|
ret = i2c_read(AXP805_ADDR, 0, 0, &val, 1);
|
|
|
|
if (ret) {
|
2019-10-20 21:28:14 +01:00
|
|
|
ERROR("PMIC: Cannot read AXP805 register %02x\n", reg);
|
2019-10-21 03:34:38 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2018-07-22 14:30:14 +01:00
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
return val;
|
2018-07-22 14:30:14 +01:00
|
|
|
}
|
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
int axp_write(uint8_t reg, uint8_t val)
|
2018-07-22 14:30:14 +01:00
|
|
|
{
|
2019-10-20 21:28:14 +01:00
|
|
|
int ret;
|
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
ret = i2c_write(AXP805_ADDR, reg, 1, &val, 1);
|
2019-10-20 21:28:14 +01:00
|
|
|
if (ret)
|
|
|
|
ERROR("PMIC: Cannot write AXP805 register %02x\n", reg);
|
|
|
|
|
|
|
|
return ret;
|
2018-07-22 14:30:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int axp805_probe(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2019-10-20 21:28:14 +01:00
|
|
|
/* Switch the AXP805 to master/single-PMIC mode. */
|
2019-10-21 03:34:38 +01:00
|
|
|
ret = axp_write(0xff, 0x0);
|
2019-10-20 21:28:14 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-07-22 14:30:14 +01:00
|
|
|
|
2019-10-21 03:34:38 +01:00
|
|
|
ret = axp_check_id();
|
2019-10-20 21:28:14 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-07-22 14:30:14 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-21 13:41:12 +01:00
|
|
|
|
2018-09-08 19:18:37 +01:00
|
|
|
int sunxi_pmic_setup(uint16_t socid, const void *fdt)
|
2018-07-21 13:41:12 +01:00
|
|
|
{
|
2018-07-22 14:30:14 +01:00
|
|
|
int ret;
|
|
|
|
|
2019-10-20 21:28:14 +01:00
|
|
|
INFO("PMIC: Probing AXP805 on I2C\n");
|
|
|
|
|
|
|
|
ret = sunxi_init_platform_r_twi(SUNXI_SOC_H6, false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-10-14 22:13:53 +01:00
|
|
|
/* initialise mi2cv driver */
|
|
|
|
i2c_init((void *)SUNXI_R_I2C_BASE);
|
2018-07-22 14:30:14 +01:00
|
|
|
|
|
|
|
ret = axp805_probe();
|
|
|
|
if (ret)
|
2019-10-20 21:12:20 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
pmic = AXP805;
|
2019-10-21 03:34:38 +01:00
|
|
|
axp_setup_regulators(fdt);
|
2018-07-21 13:41:12 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-22 14:52:50 +01:00
|
|
|
|
2019-10-20 21:06:57 +01:00
|
|
|
void sunxi_power_down(void)
|
2018-07-22 14:52:50 +01:00
|
|
|
{
|
|
|
|
switch (pmic) {
|
|
|
|
case AXP805:
|
2018-10-14 22:13:53 +01:00
|
|
|
/* Re-initialise after rich OS might have used it. */
|
|
|
|
sunxi_init_platform_r_twi(SUNXI_SOC_H6, false);
|
|
|
|
/* initialise mi2cv driver */
|
|
|
|
i2c_init((void *)SUNXI_R_I2C_BASE);
|
2019-10-21 03:34:38 +01:00
|
|
|
axp_power_off();
|
2018-07-22 14:52:50 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|