Commit 4538c498 authored by Samuel Holland's avatar Samuel Holland
Browse files

allwinner: Clean up PMIC-related error handling



- Check the return value from sunxi_init_platform_r_twi().
- Print the PMIC banner before doing anything that might fail.
- Remove double prefixes in error messages.
- Consistently omit the trailing period.
- No need to print the unknown SoC's ID, since we already did that
  earlier in bl31_platform_setup().
- On the other hand, do print the ID of the unknown PMIC.
- Try to keep the messages concise, as the large string size in these
  files was causing the firmware to spill into the next page.
- Downgrade the banner from NOTICE to INFO. It's purely informational,
  and people should be using debug builds on untested hardware anyway.
Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
Change-Id: Ib909408a5fdaebe05470fbce48d245dd0bf040eb
parent c0e109f2
...@@ -232,7 +232,7 @@ static void setup_axp803_rails(const void *fdt) ...@@ -232,7 +232,7 @@ static void setup_axp803_rails(const void *fdt)
/* locate the PMIC DT node, bail out if not found */ /* locate the PMIC DT node, bail out if not found */
node = fdt_node_offset_by_compatible(fdt, -1, "x-powers,axp803"); node = fdt_node_offset_by_compatible(fdt, -1, "x-powers,axp803");
if (node < 0) { if (node < 0) {
WARN("BL31: PMIC: Cannot find AXP803 DT node, skipping initial setup.\n"); WARN("PMIC: No PMIC DT node, skipping setup\n");
return; return;
} }
...@@ -245,7 +245,7 @@ static void setup_axp803_rails(const void *fdt) ...@@ -245,7 +245,7 @@ static void setup_axp803_rails(const void *fdt)
/* descend into the "regulators" subnode */ /* descend into the "regulators" subnode */
node = fdt_subnode_offset(fdt, node, "regulators"); node = fdt_subnode_offset(fdt, node, "regulators");
if (node < 0) { if (node < 0) {
WARN("BL31: PMIC: Cannot find regulators subnode, skipping initial setup.\n"); WARN("PMIC: No regulators DT node, skipping setup\n");
return; return;
} }
...@@ -275,6 +275,7 @@ static void setup_axp803_rails(const void *fdt) ...@@ -275,6 +275,7 @@ static void setup_axp803_rails(const void *fdt)
continue; continue;
} }
} }
/* /*
* If DLDO2 is enabled after DC1SW, the PMIC overheats and shuts * If DLDO2 is enabled after DC1SW, the PMIC overheats and shuts
* down. So always enable DC1SW as the very last regulator. * down. So always enable DC1SW as the very last regulator.
...@@ -291,11 +292,16 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt) ...@@ -291,11 +292,16 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt)
switch (socid) { switch (socid) {
case SUNXI_SOC_H5: case SUNXI_SOC_H5:
NOTICE("PMIC: Assuming H5 reference regulator design\n");
pmic = REF_DESIGN_H5; pmic = REF_DESIGN_H5;
NOTICE("BL31: PMIC: Defaulting to PortL GPIO according to H5 reference design.\n");
break; break;
case SUNXI_SOC_A64: case SUNXI_SOC_A64:
pmic = GENERIC_A64; pmic = GENERIC_A64;
INFO("PMIC: Probing AXP803 on RSB\n");
ret = sunxi_init_platform_r_twi(socid, true); ret = sunxi_init_platform_r_twi(socid, true);
if (ret) if (ret)
return ret; return ret;
...@@ -305,14 +311,12 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt) ...@@ -305,14 +311,12 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt)
return ret; return ret;
pmic = AXP803_RSB; pmic = AXP803_RSB;
NOTICE("BL31: PMIC: Detected AXP803 on RSB.\n");
if (fdt) if (fdt)
setup_axp803_rails(fdt); setup_axp803_rails(fdt);
break; break;
default: default:
NOTICE("BL31: PMIC: No support for Allwinner %x SoC.\n", socid);
return -ENODEV; return -ENODEV;
} }
return 0; return 0;
......
...@@ -31,15 +31,23 @@ int axp_i2c_read(uint8_t chip, uint8_t reg, uint8_t *val) ...@@ -31,15 +31,23 @@ int axp_i2c_read(uint8_t chip, uint8_t reg, uint8_t *val)
int ret; int ret;
ret = i2c_write(chip, 0, 0, &reg, 1); ret = i2c_write(chip, 0, 0, &reg, 1);
if (ret == 0)
ret = i2c_read(chip, 0, 0, val, 1);
if (ret) if (ret)
return ret; ERROR("PMIC: Cannot read AXP805 register %02x\n", reg);
return i2c_read(chip, 0, 0, val, 1); return ret;
} }
int axp_i2c_write(uint8_t chip, uint8_t reg, uint8_t val) int axp_i2c_write(uint8_t chip, uint8_t reg, uint8_t val)
{ {
return i2c_write(chip, reg, 1, &val, 1); int ret;
ret = i2c_write(chip, reg, 1, &val, 1);
if (ret)
ERROR("PMIC: Cannot write AXP805 register %02x\n", reg);
return ret;
} }
static int axp805_probe(void) static int axp805_probe(void)
...@@ -47,21 +55,18 @@ static int axp805_probe(void) ...@@ -47,21 +55,18 @@ static int axp805_probe(void)
int ret; int ret;
uint8_t val; uint8_t val;
/* Switch the AXP805 to master/single-PMIC mode. */
ret = axp_i2c_write(AXP805_ADDR, 0xff, 0x0); ret = axp_i2c_write(AXP805_ADDR, 0xff, 0x0);
if (ret) { if (ret)
ERROR("PMIC: Cannot put AXP805 to master mode.\n"); return ret;
return -EPERM;
}
ret = axp_i2c_read(AXP805_ADDR, AXP805_ID, &val); ret = axp_i2c_read(AXP805_ADDR, AXP805_ID, &val);
if (ret)
return ret;
if (!ret && ((val & 0xcf) == 0x40)) val &= 0xcf;
NOTICE("PMIC: AXP805 detected\n"); if (val != 0x40) {
else if (ret) { ERROR("PMIC: Found unknown PMIC %02x\n", val);
ERROR("PMIC: Cannot communicate with AXP805.\n");
return -EPERM;
} else {
ERROR("PMIC: Non-AXP805 chip attached at AXP805's address.\n");
return -EINVAL; return -EINVAL;
} }
...@@ -72,12 +77,15 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt) ...@@ -72,12 +77,15 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt)
{ {
int ret; int ret;
sunxi_init_platform_r_twi(SUNXI_SOC_H6, false); INFO("PMIC: Probing AXP805 on I2C\n");
ret = sunxi_init_platform_r_twi(SUNXI_SOC_H6, false);
if (ret)
return ret;
/* initialise mi2cv driver */ /* initialise mi2cv driver */
i2c_init((void *)SUNXI_R_I2C_BASE); i2c_init((void *)SUNXI_R_I2C_BASE);
NOTICE("PMIC: Probing AXP805\n");
ret = axp805_probe(); ret = axp805_probe();
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment