From: Sasha Finkelstein <k@chaosmail.tech>
To: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
"Antoine Sidem" <sidemantoine@gmail.com>,
"Aditya Garg" <aditya.garg@linux.dev>,
"Andre Eikmeyer" <dev@deq.rocks>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Linus Walleij" <linusw@kernel.org>,
"Bartosz Golaszewski" <brgl@kernel.org>,
"Sven Peter" <sven@kernel.org>, "Janne Grunau" <j@jannau.net>,
"Neal Gompa" <neal@gompa.dev>,
"Guenter Roeck" <linux@roeck-us.net>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
"Pavel Machek" <pavel@kernel.org>,
"Griffin Kroah-Hartman" <griffin@kroah.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Sebastian Reichel" <sre@kernel.org>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Wim Van Sebroeck" <wim@linux-watchdog.org>,
"Jarkko Sakkinen" <jarkko@kernel.org>,
"Mimi Zohar" <zohar@linux.ibm.com>,
"Roberto Sassu" <roberto.sassu@huawei.com>,
"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
"Eric Snowberg" <eric.snowberg@oracle.com>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
mfd@lists.linux.dev, platform-driver-x86@vger.kernel.org,
linux-pm@vger.kernel.org
Subject: Re: [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power
Date: Fri, 4 Dec 2026 15:42:41 +0100 [thread overview]
Message-ID: <F379E15F-8BD2-4F94-AF34-06FA7670B238@chaosmail.tech> (raw)
In-Reply-To: <20261204131619.5059-11-atharvatiwarilinuxdev@gmail.com>
On Dec 4, 2026, at 14:12, Atharva Tiwari <atharvatiwarilinuxdev@gmail.com> 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
next prev parent reply other threads:[~2026-12-04 14:42 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-12-04 14:07 ` Andy Shevchenko
2026-12-04 16:45 ` Sven Peter
2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-12-04 14:19 ` Andy Shevchenko
2026-12-04 14:52 ` Aditya Garg
2026-12-04 17:23 ` Andy Shevchenko
2026-12-04 18:34 ` Aditya Garg
2026-12-04 19:57 ` Atharva Tiwari
2026-12-04 20:23 ` Andy Shevchenko
2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-12-04 14:12 ` Andy Shevchenko
2026-12-04 14:48 ` Aditya Garg
2026-12-04 17:06 ` Andy Shevchenko
2026-12-04 17:10 ` Aditya Garg
2026-12-04 17:18 ` Andy Shevchenko
2026-12-04 17:26 ` Sven Peter
2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-12-04 14:42 ` Sasha Finkelstein [this message]
2026-12-04 19:41 ` Atharva Tiwari
2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-12-04 14:08 ` Andy Shevchenko
2026-12-04 14:56 ` Aditya Garg
2026-12-04 17:14 ` Andy Shevchenko
2026-12-04 18:51 ` Aditya Garg
2026-12-04 20:02 ` Andy Shevchenko
2026-12-04 20:13 ` Andy Shevchenko
2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-12-04 13:40 ` Sasha Finkelstein
2026-12-04 19:43 ` Atharva Tiwari
2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F379E15F-8BD2-4F94-AF34-06FA7670B238@chaosmail.tech \
--to=k@chaosmail.tech \
--cc=aditya.garg@linux.dev \
--cc=alexandre.belloni@bootlin.com \
--cc=andy@kernel.org \
--cc=asahi@lists.linux.dev \
--cc=atharvatiwarilinuxdev@gmail.com \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=brgl@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=dev@deq.rocks \
--cc=dlechner@baylibre.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=griffin@kroah.com \
--cc=hansg@kernel.org \
--cc=hpa@zytor.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=j@jannau.net \
--cc=jarkko@kernel.org \
--cc=jic23@kernel.org \
--cc=jmorris@namei.org \
--cc=lee@kernel.org \
--cc=lenb@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mfd@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=neal@gompa.dev \
--cc=nuno.sa@analog.com \
--cc=paul@paul-moore.com \
--cc=pavel@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=pv4k@odayny.com \
--cc=rafael@kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=sidemantoine@gmail.com \
--cc=sre@kernel.org \
--cc=sven@kernel.org \
--cc=tglx@kernel.org \
--cc=wim@linux-watchdog.org \
--cc=x86@kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®