platform/x86: ideapad-laptop: Protect GBMD/SBMC calls with mutex

The upcoming changes for Rapid Charge support require two consecutive
SBMC calls to switch charge_types. Hence, a mutex is required.

No functional change intended.

Signed-off-by: Rong Zhang <i@rong.moe>
Acked-by: Ike Panhc <ikepanhc@gmail.com>
Link: https://patch.msgid.link/20251105182832.104946-3-i@rong.moe
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Rong Zhang 2025-11-06 02:28:25 +08:00 committed by Ilpo Järvinen
parent 06c129cac0
commit 85901a0d85
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31

View File

@ -159,6 +159,7 @@ struct ideapad_rfk_priv {
struct ideapad_private {
struct acpi_device *adev;
struct mutex vpc_mutex; /* protects the VPC calls */
struct mutex gbmd_sbmc_mutex; /* protects GBMD/SBMC calls */
struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
struct platform_device *platform_device;
@ -456,37 +457,40 @@ static int debugfs_status_show(struct seq_file *s, void *data)
struct ideapad_private *priv = s->private;
unsigned long value;
guard(mutex)(&priv->vpc_mutex);
scoped_guard(mutex, &priv->vpc_mutex) {
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
seq_printf(s, "Backlight max: %lu\n", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
seq_printf(s, "Backlight now: %lu\n", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
seq_printf(s, "BL power value: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
seq_printf(s, "Backlight max: %lu\n", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
seq_printf(s, "Backlight now: %lu\n", value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
seq_printf(s, "BL power value: %s (%lu)\n", str_on_off(value), value);
seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
seq_printf(s, "Radio status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
seq_printf(s, "Wifi status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
seq_printf(s, "BT status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
seq_printf(s, "3G status: %s (%lu)\n", str_on_off(value), value);
seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
seq_printf(s, "Touchpad status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
seq_printf(s, "Camera status: %s (%lu)\n", str_on_off(value), value);
}
seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
seq_printf(s, "Radio status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
seq_printf(s, "Wifi status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
seq_printf(s, "BT status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
seq_printf(s, "3G status: %s (%lu)\n", str_on_off(value), value);
scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
if (!eval_gbmd(priv->adev->handle, &value))
seq_printf(s, "GBMD: %#010lx\n", value);
}
seq_puts(s, "=====================\n");
if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
seq_printf(s, "Touchpad status: %s (%lu)\n", str_on_off(value), value);
if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
seq_printf(s, "Camera status: %s (%lu)\n", str_on_off(value), value);
seq_puts(s, "=====================\n");
if (!eval_gbmd(priv->adev->handle, &value))
seq_printf(s, "GBMD: %#010lx\n", value);
if (!eval_hals(priv->adev->handle, &value))
seq_printf(s, "HALS: %#010lx\n", value);
@ -623,9 +627,11 @@ static ssize_t conservation_mode_show(struct device *dev,
show_conservation_mode_deprecation_warning(dev);
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
}
return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
}
@ -644,6 +650,8 @@ static ssize_t conservation_mode_store(struct device *dev,
if (err)
return err;
guard(mutex)(&priv->gbmd_sbmc_mutex);
err = exec_sbmc(priv->adev->handle, state ? SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF);
if (err)
return err;
@ -2008,15 +2016,22 @@ static int ideapad_psy_ext_set_prop(struct power_supply *psy,
const union power_supply_propval *val)
{
struct ideapad_private *priv = ext_data;
unsigned long op;
switch (val->intval) {
case POWER_SUPPLY_CHARGE_TYPE_LONGLIFE:
return exec_sbmc(priv->adev->handle, SBMC_CONSERVATION_ON);
op = SBMC_CONSERVATION_ON;
break;
case POWER_SUPPLY_CHARGE_TYPE_STANDARD:
return exec_sbmc(priv->adev->handle, SBMC_CONSERVATION_OFF);
op = SBMC_CONSERVATION_OFF;
break;
default:
return -EINVAL;
}
guard(mutex)(&priv->gbmd_sbmc_mutex);
return exec_sbmc(priv->adev->handle, op);
}
static int ideapad_psy_ext_get_prop(struct power_supply *psy,
@ -2029,9 +2044,11 @@ static int ideapad_psy_ext_get_prop(struct power_supply *psy,
unsigned long result;
int err;
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
}
if (test_bit(GBMD_CONSERVATION_STATE_BIT, &result))
val->intval = POWER_SUPPLY_CHARGE_TYPE_LONGLIFE;
@ -2293,6 +2310,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
if (err)
return err;
err = devm_mutex_init(&pdev->dev, &priv->gbmd_sbmc_mutex);
if (err)
return err;
err = ideapad_check_features(priv);
if (err)
return err;