Commit 213e19d6 authored by Hans de Goede's avatar Hans de Goede Committed by Sebastian Reichel

power: supply: axp288_fuel_gauge: Take the P-Unit semaphore only once during probe()

The I2C-bus to the XPower AXP288 is shared between the Linux kernel and
the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock"
before it may use the bus. If not explicitly taken by the I2C-driver,
then this semaphore is automatically taken by the I2C-bus-driver for
each I2C-transfer and this is a quite expensive operation.

Explicitly take the semaphore in probe() around the register-accesses
done during probe, so that this only needs to be done once, rather then
once per register-access.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 964b3e9b
...@@ -661,31 +661,35 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) ...@@ -661,31 +661,35 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
} }
} }
ret = iosf_mbi_block_punit_i2c_access();
if (ret < 0)
goto out_free_iio_chan;
/* /*
* On some devices the fuelgauge and charger parts of the axp288 are * On some devices the fuelgauge and charger parts of the axp288 are
* not used, check that the fuelgauge is enabled (CC_CTRL != 0). * not used, check that the fuelgauge is enabled (CC_CTRL != 0).
*/ */
ret = regmap_read(axp20x->regmap, AXP20X_CC_CTRL, &val); ret = regmap_read(axp20x->regmap, AXP20X_CC_CTRL, &val);
if (ret < 0) if (ret < 0)
goto out_free_iio_chan; goto unblock_punit_i2c_access;
if (val == 0) { if (val == 0) {
ret = -ENODEV; ret = -ENODEV;
goto out_free_iio_chan; goto unblock_punit_i2c_access;
} }
ret = fuel_gauge_reg_readb(info, AXP288_FG_DES_CAP1_REG); ret = fuel_gauge_reg_readb(info, AXP288_FG_DES_CAP1_REG);
if (ret < 0) if (ret < 0)
goto out_free_iio_chan; goto unblock_punit_i2c_access;
if (!(ret & FG_DES_CAP1_VALID)) { if (!(ret & FG_DES_CAP1_VALID)) {
dev_err(&pdev->dev, "axp288 not configured by firmware\n"); dev_err(&pdev->dev, "axp288 not configured by firmware\n");
ret = -ENODEV; ret = -ENODEV;
goto out_free_iio_chan; goto unblock_punit_i2c_access;
} }
ret = fuel_gauge_reg_readb(info, AXP20X_CHRG_CTRL1); ret = fuel_gauge_reg_readb(info, AXP20X_CHRG_CTRL1);
if (ret < 0) if (ret < 0)
goto out_free_iio_chan; goto unblock_punit_i2c_access;
switch ((ret & CHRG_CCCV_CV_MASK) >> CHRG_CCCV_CV_BIT_POS) { switch ((ret & CHRG_CCCV_CV_MASK) >> CHRG_CCCV_CV_BIT_POS) {
case CHRG_CCCV_CV_4100MV: case CHRG_CCCV_CV_4100MV:
info->max_volt = 4100; info->max_volt = 4100;
...@@ -703,14 +707,20 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) ...@@ -703,14 +707,20 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE); ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE);
if (ret < 0) if (ret < 0)
goto out_free_iio_chan; goto unblock_punit_i2c_access;
info->pwr_op = ret; info->pwr_op = ret;
ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG); ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG);
if (ret < 0) if (ret < 0)
goto out_free_iio_chan; goto unblock_punit_i2c_access;
info->low_cap = ret; info->low_cap = ret;
unblock_punit_i2c_access:
iosf_mbi_unblock_punit_i2c_access();
/* In case we arrive here by goto because of a register access error */
if (ret < 0)
goto out_free_iio_chan;
psy_cfg.drv_data = info; psy_cfg.drv_data = info;
info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg); info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg);
if (IS_ERR(info->bat)) { if (IS_ERR(info->bat)) {
......
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