'-1' is absolutely meaningless value.
This patch changed from meaningless value to error number.
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
return rc;
if (ver != 0x05)
- return -1;
+ return -EINVAL;
return 0;
}
ver &= 0x0f;
if (ver != 0x1)
- return -1;
+ return -EINVAL;
/* Mask all interrupts */
for (i = AXP209_IRQ_ENABLE1; i <= AXP209_IRQ_ENABLE5; i++) {
struct power_battery *p_bat = bat->pbat;
if (bat->chrg->chrg_state(p_bat->chrg, PMIC_CHARGER_ENABLE, 450))
- return -1;
+ return -EINVAL;
return 0;
}
COMPAT_SAMSUNG_EXYNOS_TMU);
if (node < 0) {
debug("EXYNOS_TMU: No node for tmu in device tree\n");
- return -1;
+ return -ENODEV;
}
/*
addr = fdtdec_get_addr(blob, node, "reg");
if (addr == FDT_ADDR_T_NONE) {
debug("%s: Missing tmu-base\n", __func__);
- return -1;
+ return -ENODEV;
}
info->tmu_base = (struct exynos5_tmu_reg *)addr;
if (error) {
debug("fail to get tmu node properties\n");
- return -1;
+ return -EINVAL;
}
#else
/* Non DT support may never be added. Just in case */
- return -1;
+ return -ENODEV;
#endif
return 0;
if (pmic_probe(p)) {
puts("Can't find max17042 fuel gauge\n");
- return -1;
+ return -ENODEV;
}
ret |= pmic_reg_read(p, MAX17042_VFSOC, &val);
if (pmic_probe(p)) {
puts("Can't find max17042 fuel gauge\n");
- return -1;
+ return -ENODEV;
}
ret |= pmic_reg_read(p, MAX17042_STATUS, &val);
if (pmic_probe(p)) {
puts("Can't find max77693 fuel gauge\n");
- return -1;
+ return -ENODEV;
}
ret = max77693_get_soc(&pb->bat->state_of_chrg);
if (pmic_probe(p)) {
puts("Can't find max77693 fuel gauge\n");
- return -1;
+ return -ENODEV;
}
ret = pmic_reg_read(p, MAX77693_STATUS, &val);
unsigned int val;
if (pmic_probe(p))
- return -1;
+ return -ENODEV;
/* unlock write capability */
val = MAX77693_CHG_UNLOCK;
pmic_reg_read(p, MAX77693_CHG_CNFG_00, &val);
val &= ~0x01;
pmic_reg_write(p, MAX77693_CHG_CNFG_00, val);
- return -1;
+ return -ENOTSUPP;
}
if (current < CHARGER_MIN_CURRENT || current > CHARGER_MAX_CURRENT) {
printf("%s: Wrong charge current: %d [mA]\n",
__func__, current);
- return -1;
+ return -EINVAL;
}
/* set charging current */
unsigned int val;
if (pmic_probe(p))
- return -1;
+ return -ENODEV;
pmic_reg_read(p, MAX77693_CHG_INT_OK, &val);
u8 val = 0;
#if defined(CONFIG_DRA7XX)
+ int ret;
/*
* Currently valid for the dra7xx_evm board:
* Set TPS659038 LDO1 to 3.0 V
*/
val = LDO_VOLT_3V0;
- if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val)) {
+ ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val);
+ if (ret) {
printf("tps65903x: could not set LDO1 voltage.\n");
- return 1;
+ return ret;
}
/* TURN ON LDO1 */
val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
- if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val)) {
+ ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val);
+ if (ret) {
printf("tps65903x: could not turn on LDO1.\n");
- return 1;
+ return ret;
}
return 0;
#else
int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
{
if (check_reg(p, reg))
- return -1;
+ return -EINVAL;
hi6553_writeb(reg, (uint8_t)val);
int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
{
if (check_reg(p, reg))
- return -1;
+ return -EINVAL;
*val = (u32)hi6553_readb(reg);
if (ldo < 1 || ldo > 26) {
printf("%s: %d is wrong ldo number\n", __func__, ldo);
- return -1;
+ return -EINVAL;
}
adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
hex = max77686_ldo_volt2hex(ldo, uV);
if (!hex)
- return -1;
+ return -EINVAL;
ret = pmic_reg_read(p, adr, &val);
if (ret)
if (ldo < 1 || 26 < ldo) {
printf("%s: %d is wrong ldo number\n", __func__, ldo);
- return -1;
+ return -EINVAL;
}
adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
if (mode == 0xff) {
printf("%s: %d is not supported on LDO%d\n",
__func__, opmode, ldo);
- return -1;
+ return -ENOTSUPP;
}
ret = pmic_reg_read(p, adr, &val);
size = ARRAY_SIZE(max77686_buck_addr);
if (buck >= size) {
printf("%s: %d is wrong buck number\n", __func__, buck);
- return -1;
+ return -EINVAL;
}
adr = max77686_buck_addr[buck];
if (mode == 0xff) {
printf("%s: %d is not supported on BUCK%d\n",
__func__, opmode, buck);
- return -1;
+ return -ENOTSUPP;
}
ret = pmic_reg_read(p, adr, &val);
if (node < 0) {
debug("PMIC: No node for PMIC Chip in device tree\n");
debug("node = %d\n", node);
- return -1;
+ return -ENODEV;
}
parent = fdt_parent_offset(blob, node);
if (parent < 0) {
debug("%s: Cannot find node parent\n", __func__);
- return -1;
+ return -ENODEV;
}
/* tmp since p->bus is unsigned */
tmp = i2c_get_bus_num_fdt(parent);
if (tmp < 0) {
debug("%s: Cannot find I2C bus\n", __func__);
- return -1;
+ return -ENODEV;
}
p->bus = tmp;
p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9);
u32 val = 0;
if (pmic_probe(p))
- return -1;
+ return -ENODEV;
if (state == PMIC_CHARGER_DISABLE) {
puts("Disable the charger.\n");
val &= ~(MBCHOSTEN | VCHGR_FC);
pmic_reg_write(p, MAX8997_REG_MBCCTRL2, val);
- return -1;
+ return -ENOTSUPP;
}
if (current < CHARGER_MIN_CURRENT || current > CHARGER_MAX_CURRENT) {
printf("%s: Wrong charge current: %d [mA]\n",
__func__, current);
- return -1;
+ return -EINVAL;
}
fc = (current - CHARGER_MIN_CURRENT) / CHARGER_CURRENT_RESOLUTION;
u32 val;
if (pmic_probe(p))
- return -1;
+ return -ENODEV;
pmic_reg_read(p, MAX8997_REG_STATUS4, &val);
if (reg >= p->number_of_regs) {
printf("<reg num> = %d is invalid. Should be less than %d\n",
reg, p->number_of_regs);
- return -1;
+ return -EINVAL;
}
return 0;
u32 val;
if (pmic_reg_read(p, reg, &val))
- return -1;
+ return -ENOTSUPP;
if (on)
val |= out;
val &= ~out;
if (pmic_reg_write(p, reg, val))
- return -1;
+ return -ENOTSUPP;
return 0;
}
if (!p) {
puts("Wrong PMIC name!\n");
- return -1;
+ return -ENODEV;
}
pmic_show_info(p);
int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
{
unsigned char buf[4] = { 0 };
+ int ret;
if (check_reg(p, reg))
- return -1;
+ return -EINVAL;
I2C_SET_BUS(p->bus);
break;
default:
printf("%s: invalid tx_num: %d", __func__, pmic_i2c_tx_num);
- return -1;
+ return -EINVAL;
}
- if (i2c_write(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
- return -1;
-
- return 0;
+ return i2c_write(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num);
}
int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
{
unsigned char buf[4] = { 0 };
u32 ret_val = 0;
+ int ret;
if (check_reg(p, reg))
- return -1;
+ return -EINVAL;
I2C_SET_BUS(p->bus);
- if (i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
- return -1;
+ ret = i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num);
+ if (ret)
+ return ret;
switch (pmic_i2c_tx_num) {
case 3:
break;
default:
printf("%s: invalid tx_num: %d", __func__, pmic_i2c_tx_num);
- return -1;
+ return -EINVAL;
}
memcpy(val, &ret_val, sizeof(ret_val));
debug("Bus: %d PMIC:%s probed!\n", p->bus, p->name);
if (i2c_probe(pmic_i2c_addr)) {
printf("Can't find PMIC:%s\n", p->name);
- return -1;
+ return -ENODEV;
}
return 0;
p->hw.spi.mode);
if (!slave)
- return -1;
+ return -ENODEV;
}
if (check_reg(p, reg))
- return -1;
+ return -EINVAL;
if (spi_claim_bus(slave))
- return -1;
+ return -EBUSY;
pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
err:
spi_release_bus(slave);
- return -1;
+ return -ENOTSUPP;
}
int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
{
- if (pmic_reg(p, reg, &val, 1))
- return -1;
-
- return 0;
+ return pmic_reg(p, reg, &val, 1);
}
int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
{
- if (pmic_reg(p, reg, val, 0))
- return -1;
-
- return 0;
+ return pmic_reg(p, reg, val, 0);
}
ctrl1 = tps6586x_read(SUPPLY_CONTROL1);
ctrl2 = tps6586x_read(SUPPLY_CONTROL2);
if (ctrl1 == -1 || ctrl2 == -1)
- return -1;
+ return -ENOTSUPP;
/* Figure out whether V1 or V2 is selected */
is_v2 = (ctrl1 | ctrl2) & CTRL_SM0_SUPPLY2;
*sm0 = tps6586x_read(is_v2 ? SM0_VOLTAGE_V2 : SM0_VOLTAGE_V1);
*sm1 = tps6586x_read(is_v2 ? SM1_VOLTAGE_V2 : SM1_VOLTAGE_V1);
if (*sm0 == -1 || *sm1 == -1)
- return -1;
+ return -ENOTSUPP;
return 0;
}
/* write v1, v2 and rate, then trigger */
if (tps6586x_write(reg, buff, 3) ||
tps6586x_write(SUPPLY_CONTROL1, &control_bit, 1))
- return -1;
+ return -ENOTSUPP;
return 0;
}
/* get current voltage settings */
if (read_voltages(&sm0, &sm1)) {
debug("%s: Cannot read voltage settings\n", __func__);
- return -1;
+ return -EINVAL;
}
/*
if (min_sm0_over_sm1 != -1 && sm0 < sm1 + min_sm0_over_sm1) {
debug("%s: SM0 is %d, SM1 is %d, but min_sm0_over_sm1 is %d\n",
__func__, sm0, sm1, min_sm0_over_sm1);
- return -1;
+ return -EINVAL;
}
/*
}
debug("%d-%d %d-%d done\n", sm0, sm0_target, sm1, sm1_target);
- return bad ? -1 : 0;
+ return bad ? -EINVAL : 0;
}
int tps6586x_init(struct udevice *dev)