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: Samuel Holland <samuel@sholland.org>
Change-Id: Ib909408a5fdaebe05470fbce48d245dd0bf040eb
diff --git a/plat/allwinner/sun50i_h6/sunxi_power.c b/plat/allwinner/sun50i_h6/sunxi_power.c
index 36e3dbe..08c74f8 100644
--- a/plat/allwinner/sun50i_h6/sunxi_power.c
+++ b/plat/allwinner/sun50i_h6/sunxi_power.c
@@ -31,15 +31,23 @@
int ret;
ret = i2c_write(chip, 0, 0, ®, 1);
+ if (ret == 0)
+ ret = i2c_read(chip, 0, 0, val, 1);
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)
{
- 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)
@@ -47,21 +55,18 @@
int ret;
uint8_t val;
+ /* Switch the AXP805 to master/single-PMIC mode. */
ret = axp_i2c_write(AXP805_ADDR, 0xff, 0x0);
- if (ret) {
- ERROR("PMIC: Cannot put AXP805 to master mode.\n");
- return -EPERM;
- }
+ if (ret)
+ return ret;
ret = axp_i2c_read(AXP805_ADDR, AXP805_ID, &val);
+ if (ret)
+ return ret;
- if (!ret && ((val & 0xcf) == 0x40))
- NOTICE("PMIC: AXP805 detected\n");
- else if (ret) {
- ERROR("PMIC: Cannot communicate with AXP805.\n");
- return -EPERM;
- } else {
- ERROR("PMIC: Non-AXP805 chip attached at AXP805's address.\n");
+ val &= 0xcf;
+ if (val != 0x40) {
+ ERROR("PMIC: Found unknown PMIC %02x\n", val);
return -EINVAL;
}
@@ -72,12 +77,15 @@
{
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 */
i2c_init((void *)SUNXI_R_I2C_BASE);
- NOTICE("PMIC: Probing AXP805\n");
-
ret = axp805_probe();
if (ret)
return ret;