Browse Source

Merge changes from topic "h616_pmics" into integration

* changes:
  feat(allwinner): adjust H616 L2 cache size in DTB
  feat(allwinner): h616: add support for AXP717 PMIC
  feat(allwinner): h616: add support for AXP313 PMIC
  feat(allwinner): h616: add I2C PMIC support
  refactor(allwinner): h616: prepare for more than one PMIC model
pull/1996/merge
Manish Pandey 3 months ago
committed by TrustedFirmware Code Review
parent
commit
55b4c5ceb2
  1. 8
      plat/allwinner/common/include/sunxi_private.h
  2. 2
      plat/allwinner/common/sunxi_prepare_dtb.c
  3. 5
      plat/allwinner/sun50i_h616/platform.mk
  4. 72
      plat/allwinner/sun50i_h616/sunxi_h616_dtb.c
  5. 213
      plat/allwinner/sun50i_h616/sunxi_power.c

8
plat/allwinner/common/include/sunxi_private.h

@ -58,4 +58,12 @@ static inline void sunxi_prepare_dtb(void *fdt)
}
#endif
#ifdef PLAT_sun50i_h616
void sunxi_soc_fdt_fixup(void *dtb);
#else
static inline void sunxi_soc_fdt_fixup(void *dtb)
{
}
#endif
#endif /* SUNXI_PRIVATE_H */

2
plat/allwinner/common/sunxi_prepare_dtb.c

@ -34,6 +34,8 @@ void sunxi_prepare_dtb(void *fdt)
}
#endif
sunxi_soc_fdt_fixup(fdt);
if (sunxi_psci_is_scpi()) {
ret = fdt_add_cpu_idle_states(fdt, sunxi_idle_states);
if (ret < 0) {

5
plat/allwinner/sun50i_h616/platform.mk

@ -18,5 +18,8 @@ ifeq (${SUNXI_PSCI_USE_SCPI}, 1)
$(error "H616 does not support SCPI PSCI ops")
endif
BL31_SOURCES += drivers/allwinner/axp/axp805.c \
BL31_SOURCES += common/fdt_wrappers.c \
drivers/allwinner/axp/axp805.c \
drivers/allwinner/sunxi_rsb.c \
drivers/mentor/i2c/mi2cv.c \
${AW_PLAT}/${PLAT}/sunxi_h616_dtb.c

72
plat/allwinner/sun50i_h616/sunxi_h616_dtb.c

@ -0,0 +1,72 @@
/*
* Copyright (c) 2024, ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Amend the device tree to adjust the L2 cache size, which is different
* between the revisions of the H616 chips: earlier versions have 256 KB of L2,
* later versions 1 MB.
* Read the cache ID registers and adjust the size and number of sets entries
* in the L2 cache DT node.
*/
#include <common/fdt_wrappers.h>
#include <lib/utils_def.h>
#include <libfdt.h>
#define CACHE_L1D 0x0
#define CACHE_L1I 0x1
#define CACHE_L2U 0x2
#define CCSIDR_SETS_SHIFT 13
#define CCSIDR_SETS_MASK GENMASK(14, 0)
#define CCSIDR_ASSOC_SHIFT 3
#define CCSIDR_ASSOC_MASK GENMASK(9, 0)
#define CCSIDR_LSIZE_SHIFT 0
#define CCSIDR_LSIZE_MASK GENMASK(2, 0)
static uint32_t armv8_get_ccsidr(unsigned int sel)
{
uint32_t reg;
__asm__ volatile ("msr CSSELR_EL1, %0\n" :: "r" (sel));
__asm__ volatile ("mrs %0, CCSIDR_EL1\n" : "=r" (reg));
return reg;
}
void sunxi_soc_fdt_fixup(void *dtb)
{
int node = fdt_path_offset(dtb, "/cpus/cpu@0");
uint32_t phandle, ccsidr, cell;
int sets, line_size, assoc;
int ret;
if (node < 0) {
return;
}
ret = fdt_read_uint32(dtb, node, "next-level-cache", &phandle);
if (ret != 0) {
return;
}
node = fdt_node_offset_by_phandle(dtb, phandle);
if (ret != 0) {
return;
}
ccsidr = armv8_get_ccsidr(CACHE_L2U);
sets = ((ccsidr >> CCSIDR_SETS_SHIFT) & CCSIDR_SETS_MASK) + 1;
line_size = 16U << ((ccsidr >> CCSIDR_LSIZE_SHIFT) & CCSIDR_LSIZE_MASK);
assoc = ((ccsidr >> CCSIDR_ASSOC_SHIFT) & CCSIDR_ASSOC_MASK) + 1;
cell = cpu_to_fdt32(sets);
fdt_setprop(dtb, node, "cache-sets", &cell, sizeof(cell));
cell = cpu_to_fdt32(line_size);
fdt_setprop(dtb, node, "cache-line-size", &cell, sizeof(cell));
cell = cpu_to_fdt32(sets * assoc * line_size);
fdt_setprop(dtb, node, "cache-size", &cell, sizeof(cell));
}

213
plat/allwinner/sun50i_h616/sunxi_power.c

@ -10,97 +10,254 @@
#include <arch_helpers.h>
#include <common/debug.h>
#include <common/fdt_wrappers.h>
#include <drivers/allwinner/axp.h>
#include <drivers/allwinner/sunxi_rsb.h>
#include <drivers/mentor/mi2cv.h>
#include <lib/mmio.h>
#include <libfdt.h>
#include <sunxi_cpucfg.h>
#include <sunxi_def.h>
#include <sunxi_mmap.h>
#include <sunxi_private.h>
#define AXP305_I2C_ADDR 0x36
#define AXP305_HW_ADDR 0x745
#define AXP305_RT_ADDR 0x3a
static uint16_t pmic_bus_addr;
static uint8_t rsb_rt_addr;
static bool is_using_rsb(void)
{
return rsb_rt_addr != 0;
}
static enum pmic_type {
UNKNOWN,
AXP305,
AXP313,
AXP717,
} pmic;
static uint8_t get_rsb_rt_address(uint16_t hw_addr)
{
switch (hw_addr) {
case 0x3a3: return 0x2d;
case 0x745: return 0x3a;
}
return 0;
}
int axp_read(uint8_t reg)
{
return rsb_read(AXP305_RT_ADDR, reg);
uint8_t val;
int ret;
if (is_using_rsb()) {
return rsb_read(rsb_rt_addr, reg);
}
ret = i2c_write(pmic_bus_addr, 0, 0, &reg, 1);
if (ret == 0) {
ret = i2c_read(pmic_bus_addr, 0, 0, &val, 1);
}
if (ret) {
ERROR("PMIC: Cannot read PMIC register %02x\n", reg);
return ret;
}
return val;
}
int axp_write(uint8_t reg, uint8_t val)
{
return rsb_write(AXP305_RT_ADDR, reg, val);
int ret;
if (is_using_rsb()) {
return rsb_write(rsb_rt_addr, reg, val);
}
ret = i2c_write(pmic_bus_addr, reg, 1, &val, 1);
if (ret) {
ERROR("PMIC: Cannot write PMIC register %02x\n", reg);
}
return ret;
}
static int rsb_init(void)
static int rsb_init(int rsb_hw_addr)
{
int ret;
ret = rsb_init_controller();
if (ret)
if (ret) {
return ret;
}
/* Switch to the recommended 3 MHz bus clock. */
ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000);
if (ret)
if (ret) {
return ret;
}
/* Initiate an I2C transaction to switch the PMIC to RSB mode. */
ret = rsb_set_device_mode(AXP20X_MODE_RSB << 16 | AXP20X_MODE_REG << 8);
if (ret)
if (ret) {
return ret;
}
/* Associate the 8-bit runtime address with the 12-bit bus address. */
ret = rsb_assign_runtime_address(AXP305_HW_ADDR, AXP305_RT_ADDR);
if (ret)
ret = rsb_assign_runtime_address(rsb_hw_addr, rsb_rt_addr);
if (ret) {
return ret;
}
return axp_check_id();
return 0;
}
int sunxi_pmic_setup(uint16_t socid, const void *fdt)
static int pmic_bus_init(uint16_t socid, uint16_t rsb_hw_addr)
{
int ret;
INFO("PMIC: Probing AXP305 on RSB\n");
ret = sunxi_init_platform_r_twi(socid, true);
ret = sunxi_init_platform_r_twi(socid, is_using_rsb());
if (ret) {
INFO("Could not init platform bus: %d\n", ret);
pmic = UNKNOWN;
return ret;
}
ret = rsb_init();
if (is_using_rsb()) {
ret = rsb_init(rsb_hw_addr);
if (ret) {
pmic = UNKNOWN;
return ret;
}
} else {
/* initialise mi2cv driver */
i2c_init((void *)SUNXI_R_I2C_BASE);
}
return 0;
}
int sunxi_pmic_setup(uint16_t socid, const void *fdt)
{
int node, parent, ret;
uint32_t reg;
node = fdt_node_offset_by_compatible(fdt, 0, "x-powers,axp806");
if (node >= 0) {
pmic = AXP305;
}
if (pmic == UNKNOWN) {
node = fdt_node_offset_by_compatible(fdt, 0, "x-powers,axp313a");
if (node >= 0) {
pmic = AXP313;
}
}
if (pmic == UNKNOWN) {
node = fdt_node_offset_by_compatible(fdt, 0, "x-powers,axp717");
if (node >= 0) {
pmic = AXP717;
}
}
if (pmic == UNKNOWN) {
INFO("PMIC: No known PMIC in DT, skipping setup.\n");
return -ENODEV;
}
if (fdt_read_uint32(fdt, node, "reg", &reg)) {
ERROR("PMIC: PMIC DT node does not contain reg property.\n");
return -EINVAL;
}
pmic_bus_addr = reg;
parent = fdt_parent_offset(fdt, node);
ret = fdt_node_check_compatible(fdt, parent, "allwinner,sun8i-a23-rsb");
if (ret == 0) {
rsb_rt_addr = get_rsb_rt_address(pmic_bus_addr);
if (rsb_rt_addr == 0) {
ERROR("PMIC: no mapping for RSB address 0x%x\n",
pmic_bus_addr);
return -EINVAL;
}
}
INFO("Probing for PMIC on %s:\n", is_using_rsb() ? "RSB" : "I2C");
ret = pmic_bus_init(socid, pmic_bus_addr);
if (ret) {
INFO("Could not init RSB: %d\n", ret);
return ret;
}
pmic = AXP305;
axp_setup_regulators(fdt);
ret = axp_read(0x03);
switch (ret & 0xcf) {
case 0x40: /* AXP305 */
if (pmic == AXP305) {
INFO("PMIC: found AXP305, setting up regulators\n");
axp_setup_regulators(fdt);
} else {
pmic = UNKNOWN;
}
break;
case 0x48: /* AXP1530 */
case 0x4b: /* AXP313A */
case 0x4c: /* AXP313B */
if (pmic == AXP313) {
INFO("PMIC: found AXP313\n");
/* no regulators to set up */
} else {
pmic = UNKNOWN;
}
break;
case 0xcf: /* version reg not implemented on AXP717 */
if (pmic == AXP717) {
INFO("PMIC: found AXP717\n");
/* no regulators to set up, U-Boot takes care of this */
} else {
pmic = UNKNOWN;
}
break;
}
/* Switch the PMIC back to I2C mode. */
ret = axp_write(AXP20X_MODE_REG, AXP20X_MODE_I2C);
if (ret)
return ret;
if (is_using_rsb()) {
/* Switch the PMIC back to I2C mode. */
return rsb_write(rsb_rt_addr, AXP20X_MODE_REG, AXP20X_MODE_I2C);
}
if (pmic == UNKNOWN) {
INFO("Incompatible or unknown PMIC found.\n");
return -ENODEV;
}
return 0;
}
void sunxi_power_down(void)
{
int ret;
if (pmic == UNKNOWN) {
return;
}
/* Re-initialise after rich OS might have used it. */
ret = pmic_bus_init(SUNXI_SOC_H616, pmic_bus_addr);
if (ret) {
return;
}
switch (pmic) {
case AXP305:
/* Re-initialise after rich OS might have used it. */
sunxi_init_platform_r_twi(SUNXI_SOC_H616, true);
rsb_init();
axp_power_off();
axp_setbits(0x32, BIT(7));
break;
case AXP313:
axp_setbits(0x1a, BIT(7));
break;
case AXP717:
axp_setbits(0x27, BIT(0));
break;
default:
break;

Loading…
Cancel
Save