allwinner: h6: power: Switch to using the AXP driver

Chip ID checking and poweroff work just like they did before.
Regulators are now enabled just like on A64/H5.

This changes the signatures of the low-level register read/write
functions to match the interface expected by the common driver.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Change-Id: I14d63d171a094fa1375904928270fa3e21761646
This commit is contained in:
Samuel Holland 2019-10-20 21:34:38 -05:00
parent f6d9c4cafa
commit fb23b104c0
4 changed files with 20 additions and 25 deletions

View File

@ -1,5 +1,5 @@
# #
# Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. # Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
# #
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -20,7 +20,8 @@ PLAT_BL_COMMON_SOURCES := drivers/ti/uart/${ARCH}/16550_console.S \
${AW_PLAT}/common/plat_helpers.S \ ${AW_PLAT}/common/plat_helpers.S \
${AW_PLAT}/common/sunxi_common.c ${AW_PLAT}/common/sunxi_common.c
BL31_SOURCES += drivers/arm/gic/common/gic_common.c \ BL31_SOURCES += drivers/allwinner/axp/common.c \
drivers/arm/gic/common/gic_common.c \
drivers/arm/gic/v2/gicv2_helpers.c \ drivers/arm/gic/v2/gicv2_helpers.c \
drivers/arm/gic/v2/gicv2_main.c \ drivers/arm/gic/v2/gicv2_main.c \
drivers/delay_timer/delay_timer.c \ drivers/delay_timer/delay_timer.c \

View File

@ -8,5 +8,4 @@
include plat/allwinner/common/allwinner-common.mk include plat/allwinner/common/allwinner-common.mk
BL31_SOURCES += drivers/allwinner/axp/axp803.c \ BL31_SOURCES += drivers/allwinner/axp/axp803.c \
drivers/allwinner/axp/common.c \
drivers/allwinner/sunxi_rsb.c drivers/allwinner/sunxi_rsb.c

View File

@ -7,4 +7,5 @@
# The differences between the platform are covered by the include files. # The differences between the platform are covered by the include files.
include plat/allwinner/common/allwinner-common.mk include plat/allwinner/common/allwinner-common.mk
BL31_SOURCES += drivers/mentor/i2c/mi2cv.c BL31_SOURCES += drivers/allwinner/axp/axp805.c \
drivers/mentor/i2c/mi2cv.c

View File

@ -10,6 +10,7 @@
#include <arch_helpers.h> #include <arch_helpers.h>
#include <common/debug.h> #include <common/debug.h>
#include <drivers/allwinner/axp.h>
#include <drivers/delay_timer.h> #include <drivers/delay_timer.h>
#include <drivers/mentor/mi2cv.h> #include <drivers/mentor/mi2cv.h>
#include <lib/mmio.h> #include <lib/mmio.h>
@ -19,31 +20,33 @@
#include <sunxi_private.h> #include <sunxi_private.h>
#define AXP805_ADDR 0x36 #define AXP805_ADDR 0x36
#define AXP805_ID 0x03
static enum pmic_type { static enum pmic_type {
UNKNOWN, UNKNOWN,
AXP805, AXP805,
} pmic; } pmic;
int axp_i2c_read(uint8_t chip, uint8_t reg, uint8_t *val) int axp_read(uint8_t reg)
{ {
uint8_t val;
int ret; int ret;
ret = i2c_write(chip, 0, 0, &reg, 1); ret = i2c_write(AXP805_ADDR, 0, 0, &reg, 1);
if (ret == 0) if (ret == 0)
ret = i2c_read(chip, 0, 0, val, 1); ret = i2c_read(AXP805_ADDR, 0, 0, &val, 1);
if (ret) if (ret) {
ERROR("PMIC: Cannot read AXP805 register %02x\n", reg); ERROR("PMIC: Cannot read AXP805 register %02x\n", reg);
return ret;
}
return ret; return val;
} }
int axp_i2c_write(uint8_t chip, uint8_t reg, uint8_t val) int axp_write(uint8_t reg, uint8_t val)
{ {
int ret; int ret;
ret = i2c_write(chip, reg, 1, &val, 1); ret = i2c_write(AXP805_ADDR, reg, 1, &val, 1);
if (ret) if (ret)
ERROR("PMIC: Cannot write AXP805 register %02x\n", reg); ERROR("PMIC: Cannot write AXP805 register %02x\n", reg);
@ -53,23 +56,16 @@ int axp_i2c_write(uint8_t chip, uint8_t reg, uint8_t val)
static int axp805_probe(void) static int axp805_probe(void)
{ {
int ret; int ret;
uint8_t val;
/* Switch the AXP805 to master/single-PMIC mode. */ /* Switch the AXP805 to master/single-PMIC mode. */
ret = axp_i2c_write(AXP805_ADDR, 0xff, 0x0); ret = axp_write(0xff, 0x0);
if (ret) if (ret)
return ret; return ret;
ret = axp_i2c_read(AXP805_ADDR, AXP805_ID, &val); ret = axp_check_id();
if (ret) if (ret)
return ret; return ret;
val &= 0xcf;
if (val != 0x40) {
ERROR("PMIC: Found unknown PMIC %02x\n", val);
return -EINVAL;
}
return 0; return 0;
} }
@ -91,22 +87,20 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt)
return ret; return ret;
pmic = AXP805; pmic = AXP805;
axp_setup_regulators(fdt);
return 0; return 0;
} }
void sunxi_power_down(void) void sunxi_power_down(void)
{ {
uint8_t val;
switch (pmic) { switch (pmic) {
case AXP805: case AXP805:
/* Re-initialise after rich OS might have used it. */ /* Re-initialise after rich OS might have used it. */
sunxi_init_platform_r_twi(SUNXI_SOC_H6, false); sunxi_init_platform_r_twi(SUNXI_SOC_H6, false);
/* initialise mi2cv driver */ /* initialise mi2cv driver */
i2c_init((void *)SUNXI_R_I2C_BASE); i2c_init((void *)SUNXI_R_I2C_BASE);
axp_i2c_read(AXP805_ADDR, 0x32, &val); axp_power_off();
axp_i2c_write(AXP805_ADDR, 0x32, val | 0x80);
break; break;
default: default:
break; break;