Skip to content

Commit e38ba40

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI / PMIC: XPower: optimize I2C-bus accesses
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 and while the kernel holds the semaphore the CPU and GPU power-states must not be changed otherwise the system will freeze. This is a complex process, which is quite expensive. This is all done by iosf_mbi_block_punit_i2c_access(). To ensure that no unguarded I2C-bus accesses happen, iosf_mbi_block_punit_i2c_access() gets called by the I2C-bus-driver for every I2C transfer. Because this is so expensive it is allowed to call iosf_mbi_block_punit_i2c_access() in a nested fashion, so that higher-level code which does multiple I2C-transfers can call it once for a group of transfers, turning the calls done by the I2C-bus-driver into no-ops. Add iosf_mbi_block_punit_i2c_access() calls around groups of register accesses, so that the P-Unit semaphore only needs to be taken once for each group of register accesses. Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e73f0f0 commit e38ba40

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/acpi/pmic/intel_pmic_xpower.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
178178
{
179179
int data, ret;
180180

181-
/* GPIO1 LDO regulator needs special handling */
182-
if (reg == XPOWER_GPI1_CTRL)
183-
return regmap_update_bits(regmap, reg, GPI1_LDO_MASK,
184-
on ? GPI1_LDO_ON : GPI1_LDO_OFF);
185-
186181
ret = iosf_mbi_block_punit_i2c_access();
187182
if (ret)
188183
return ret;
189184

185+
/* GPIO1 LDO regulator needs special handling */
186+
if (reg == XPOWER_GPI1_CTRL) {
187+
ret = regmap_update_bits(regmap, reg, GPI1_LDO_MASK,
188+
on ? GPI1_LDO_ON : GPI1_LDO_OFF);
189+
goto out;
190+
}
191+
190192
if (regmap_read(regmap, reg, &data)) {
191193
ret = -EIO;
192194
goto out;
@@ -234,6 +236,11 @@ static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
234236
return ret;
235237

236238
if (adc_ts_pin_ctrl & AXP288_ADC_TS_CURRENT_ON_OFF_MASK) {
239+
/*
240+
* AXP288_ADC_TS_PIN_CTRL reads are cached by the regmap, so
241+
* this does to a single I2C-transfer, and thus there is no
242+
* need to explicitly call iosf_mbi_block_punit_i2c_access().
243+
*/
237244
ret = regmap_update_bits(regmap, AXP288_ADC_TS_PIN_CTRL,
238245
AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
239246
AXP288_ADC_TS_CURRENT_ON_ONDEMAND);
@@ -244,6 +251,10 @@ static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
244251
usleep_range(6000, 10000);
245252
}
246253

254+
ret = iosf_mbi_block_punit_i2c_access();
255+
if (ret)
256+
return ret;
257+
247258
ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2);
248259
if (ret == 0)
249260
ret = (buf[0] << 4) + ((buf[1] >> 4) & 0x0f);
@@ -254,6 +265,8 @@ static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
254265
AXP288_ADC_TS_CURRENT_ON);
255266
}
256267

268+
iosf_mbi_unblock_punit_i2c_access();
269+
257270
return ret;
258271
}
259272

0 commit comments

Comments
 (0)