Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Hans de Goede and committed by
Sebastian Reichel
213e19d6 964b3e9b

+17 -7
+17 -7
drivers/power/supply/axp288_fuel_gauge.c
··· 661 661 } 662 662 } 663 663 664 + ret = iosf_mbi_block_punit_i2c_access(); 665 + if (ret < 0) 666 + goto out_free_iio_chan; 667 + 664 668 /* 665 669 * On some devices the fuelgauge and charger parts of the axp288 are 666 670 * not used, check that the fuelgauge is enabled (CC_CTRL != 0). 667 671 */ 668 672 ret = regmap_read(axp20x->regmap, AXP20X_CC_CTRL, &val); 669 673 if (ret < 0) 670 - goto out_free_iio_chan; 674 + goto unblock_punit_i2c_access; 671 675 if (val == 0) { 672 676 ret = -ENODEV; 673 - goto out_free_iio_chan; 677 + goto unblock_punit_i2c_access; 674 678 } 675 679 676 680 ret = fuel_gauge_reg_readb(info, AXP288_FG_DES_CAP1_REG); 677 681 if (ret < 0) 678 - goto out_free_iio_chan; 682 + goto unblock_punit_i2c_access; 679 683 680 684 if (!(ret & FG_DES_CAP1_VALID)) { 681 685 dev_err(&pdev->dev, "axp288 not configured by firmware\n"); 682 686 ret = -ENODEV; 683 - goto out_free_iio_chan; 687 + goto unblock_punit_i2c_access; 684 688 } 685 689 686 690 ret = fuel_gauge_reg_readb(info, AXP20X_CHRG_CTRL1); 687 691 if (ret < 0) 688 - goto out_free_iio_chan; 692 + goto unblock_punit_i2c_access; 689 693 switch ((ret & CHRG_CCCV_CV_MASK) >> CHRG_CCCV_CV_BIT_POS) { 690 694 case CHRG_CCCV_CV_4100MV: 691 695 info->max_volt = 4100; ··· 707 703 708 704 ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE); 709 705 if (ret < 0) 710 - goto out_free_iio_chan; 706 + goto unblock_punit_i2c_access; 711 707 info->pwr_op = ret; 712 708 713 709 ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG); 714 710 if (ret < 0) 715 - goto out_free_iio_chan; 711 + goto unblock_punit_i2c_access; 716 712 info->low_cap = ret; 713 + 714 + unblock_punit_i2c_access: 715 + iosf_mbi_unblock_punit_i2c_access(); 716 + /* In case we arrive here by goto because of a register access error */ 717 + if (ret < 0) 718 + goto out_free_iio_chan; 717 719 718 720 psy_cfg.drv_data = info; 719 721 info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg);