Re: [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power

From: Sasha Finkelstein

Date: Fri Dec 04 2026 - 09:43:09 EST


On Dec 4, 2026, at 14:12, Atharva Tiwari <atharvatiwarilinuxdev@xxxxxxxxx> wrote:
>
> Make macsmc-power work on Intel Macs, as a replacement for
> acpi-sbs. It exposes a lot more sensors than acpi-sbs, such
> as voltage, current, power, temperature, charge and health
> info, and also the adapter state.
>
> [...]
>
> +#include <linux/acpi.h>

I do not see a dependency on CONFIG_ACPI. And it should not have one
anyway, AS does not need ACPI.

> +static int macsmc_battery_acpi_read(struct apple_smc *smc, smc_key key, int *val,
> + int scale)
> +{
> + int ret;
> + struct apple_smc_key_info info;
> +
> + ret = apple_smc_get_key_info(smc, key, &info);
> + if (ret)
> + return ret;
> +
> + switch (info.type_code) {
> + /* 32-bit IEEE 754 float */
> + case __SMC_KEY('f', 'l', 't', ' '): {
> + int flt_ = 0;
> +
> + ret = macsmc_battery_acpi_read_f32_scaled(smc, key, &flt_, scale);
> + if (ret)
> + return ret;
> +
> + *val = flt_;
> + break;
> + }
> +
> + /* 3.13 fixed point decimal */

Is Apple actually using every single one of those formats?


> case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16);
> - val->intval = vu16 * 1000;
> + if (power->smc->is_acpi)
> + val->intval = swab16(vu16) * 1000;
> + else
> + val->intval = vu16 * 1000;
> break;

This pattern happens way too often to leave open-coded.


> case POWER_SUPPLY_PROP_POWER_NOW:
> - ret = apple_smc_read_s32(power->smc, SMC_KEY(B0AP), &vs32);
> - val->intval = vs32 * 1000;
> + if (power->smc->is_acpi) {
> + if (power->has_b0ap) {
> + ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(B0AP),
> + &val->intval, 1000000);
> + if (ret < 0)
> + return ret;
> +
> + val->intval = -val->intval;
> + } else {
> + ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16);
> + if (ret < 0)
> + return ret;
> +
> + ret = apple_smc_read_s16(power->smc, SMC_KEY(B0AC), &vs16);
> + if (ret < 0)
> + return ret;
> +
> + val->intval = (s16)swab16(vs16) * swab16(vu16);
> + }
> + } else {
> + ret = apple_smc_read_s32(power->smc, SMC_KEY(B0AP), &vs32);
> + val->intval = vs32 * 1000;
> + }
> break;

Please put this somewhere else and not inline

> switch (psp) {
> case POWER_SUPPLY_PROP_ONLINE:
> - ret = apple_smc_read_u32(power->smc, SMC_KEY(CHIS), &vu32);
> - val->intval = !!vu32;
> + if (power->smc->is_acpi) {
> + if (power->has_battery) {
> + acpi_status status;
> + unsigned long long adapter_status;
> +
> + status = acpi_evaluate_integer(power->adapter->handle,
> + "_PSR", NULL, &adapter_status);
> + if (ACPI_FAILURE(status))
> + return -EIO;
> +
> + val->intval = !!adapter_status;
> + } else
> + val->intval = 1;
> + } else {
> + ret = apple_smc_read_u32(power->smc, SMC_KEY(CHIS), &vu32);
> + val->intval = !!vu32;
> + }
> + break;

Same

> + if (smc->is_acpi) {
> + props[nprops++] = POWER_SUPPLY_PROP_STATUS;
> + props[nprops++] = POWER_SUPPLY_PROP_PRESENT;
> + props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY_LEVEL;
> + props[nprops++] = POWER_SUPPLY_PROP_TEMP;
> + props[nprops++] = POWER_SUPPLY_PROP_CYCLE_COUNT;
> + props[nprops++] = POWER_SUPPLY_PROP_HEALTH;
> + props[nprops++] = POWER_SUPPLY_PROP_SCOPE;
>
> [...]
>
> + props[nprops++] = POWER_SUPPLY_PROP_STATUS;
> + props[nprops++] = POWER_SUPPLY_PROP_PRESENT;
> + props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY;
> + props[nprops++] = POWER_SUPPLY_PROP_CAPACITY_LEVEL;
> + props[nprops++] = POWER_SUPPLY_PROP_TEMP;
> + props[nprops++] = POWER_SUPPLY_PROP_CYCLE_COUNT;
> + props[nprops++] = POWER_SUPPLY_PROP_HEALTH;
> + props[nprops++] = POWER_SUPPLY_PROP_SCOPE;

They are the same picture