From: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
Cc: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>,
"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>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org,
linux-leds@vger.kernel.org, mfd@lists.linux.dev,
platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org,
linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org,
linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: [RFC PATCH 12/14] hwmon/macsmc: add more types
Date: Thu, 29 Oct 2026 04:52:09 -0400 [thread overview]
Message-ID: <20261029085504.3547-13-atharvatiwarilinuxdev@gmail.com> (raw)
In-Reply-To: <20261029085504.3547-1-atharvatiwarilinuxdev@gmail.com>
SMC keys come in many data types, and Intel Macs use a lot
that macsmc-hwmon couldn't read, such as the signed fixed
point types like sp1e.
Add support for the common integer and fixed point types,
and allow writing fan speeds.
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
drivers/hwmon/macsmc-hwmon.c | 310 +++++++++++++++++++++++++++++++++++
1 file changed, 310 insertions(+)
diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c
index 1500ec2cc..2e74dcd66 100644
--- a/drivers/hwmon/macsmc-hwmon.c
+++ b/drivers/hwmon/macsmc-hwmon.c
@@ -221,6 +221,313 @@ static int macsmc_hwmon_read_key(struct apple_smc *smc,
*val = (long)ioft;
break;
}
+ /* unsigned 8-bit integer */
+ case __SMC_KEY('u', 'i', '8', ' '): {
+ u8 ui8 = 0;
+
+ ret = apple_smc_read_u8(smc, sensor->macsmc_key, &ui8);
+ if (ret)
+ return ret;
+
+ *val = ui8 * scale;
+ break;
+ }
+ /* signed 8-bit integer */
+ case __SMC_KEY('s', 'i', '8', ' '): {
+ s8 si8 = 0;
+
+ ret = apple_smc_read_s8(smc, sensor->macsmc_key, &si8);
+ if (ret)
+ return ret;
+
+ *val = si8 * scale;
+ break;
+ }
+ /* unsigned 16-bit integer */
+ case __SMC_KEY('u', 'i', '1', '6'): {
+ u16 ui16 = 0;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &ui16);
+ if (ret)
+ return ret;
+
+ *val = ui16 * scale;
+ break;
+ }
+ /* signed 16-bit integer */
+ case __SMC_KEY('s', 'i', '1', '6'): {
+ s16 si16 = 0;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &si16);
+ if (ret)
+ return ret;
+
+ *val = si16 * scale;
+ break;
+ }
+ /* unsigned 32-bit integer */
+ case __SMC_KEY('u', 'i', '3', '2'): {
+ u32 ui32 = 0;
+
+ ret = apple_smc_read_u32(smc, sensor->macsmc_key, &ui32);
+ if (ret)
+ return ret;
+
+ *val = ui32 * scale;
+ break;
+ }
+ /* signed 32-bit integer */
+ case __SMC_KEY('s', 'i', '3', '2'): {
+ s32 si32;
+
+ ret = apple_smc_read_s32(smc, sensor->macsmc_key, &si32);
+ if (ret)
+ return ret;
+
+ *val = si32 * scale;
+ break;
+ }
+ /* 2.14 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '2', 'e'): {
+ u16 fp2e;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp2e);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp2e), scale, BIT(14));
+ break;
+ }
+
+ /* 3.13 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '3', 'd'): {
+ u16 fp3d;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp3d);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp3d), scale, BIT(13));
+ break;
+ }
+
+ /* 4.12 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '4', 'c'): {
+ u16 fp4c;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp4c);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp4c), scale, BIT(12));
+ break;
+ }
+
+ /* 5.11 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '5', 'b'): {
+ u16 fp5b;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp5b);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp5b), scale, BIT(11));
+ break;
+ }
+
+ /* 6.10 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '6', 'a'): {
+ u16 fp6a;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp6a);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp6a), scale, BIT(10));
+ break;
+ }
+
+ /* 8.8 unsigned fixed point decimal */
+ case __SMC_KEY('f', 'p', '8', '8'): {
+ u16 fp88;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fp88);
+ if (ret)
+ return ret;
+
+ *val = mult_frac(be16_to_cpu(fp88), scale, BIT(8));
+ break;
+ }
+ /* 14.2 fixed point decimal */
+ case __SMC_KEY('f', 'p', 'e', '2'): {
+ /*
+ * fpe2 is only used for fan stats and fan control
+ * so precision is not needed
+ */
+ u16 fpe2;
+
+ ret = apple_smc_read_u16(smc, sensor->macsmc_key, &fpe2);
+ if (ret)
+ return ret;
+
+ *val = (be16_to_cpu(fpe2) >> 2);
+ break;
+ }
+ /* 1.14 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '1', 'e'): {
+ s16 sp1e;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp1e);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp1e), scale, BIT(14));
+ break;
+ }
+
+ /* 2.13 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '2', 'd'): {
+ s16 sp2d;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp2d);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp2d), scale, BIT(13));
+ break;
+ }
+
+ /* 3.12 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '3', 'c'): {
+ s16 sp3c;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp3c);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp3c), scale, BIT(12));
+ break;
+ }
+
+ /* 4.11 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '4', 'b'): {
+ s16 sp4b;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp4b);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp4b), scale, BIT(11));
+ break;
+ }
+
+ /* 5.10 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '5', 'a'): {
+ s16 sp5a;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp5a);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp5a), scale, BIT(10));
+ break;
+ }
+
+ /* 6.9 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '6', '9'): {
+ s16 sp69;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp69);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp69), scale, BIT(9));
+ break;
+ }
+
+ /* 7.8 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '7', '8'): {
+ s16 sp78;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp78);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp78), scale, BIT(8));
+ break;
+ }
+
+ /* 8.7 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '8', '7'): {
+ s16 sp87;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp87);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp87), scale, BIT(7));
+ break;
+ }
+
+ /* 9.6 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', '9', '6'): {
+ s16 sp96;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &sp96);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(sp96), scale, BIT(6));
+ break;
+ }
+
+ /* 10.5 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', 'a', '5'): {
+ s16 spa5;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &spa5);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(spa5), scale, BIT(5));
+ break;
+ }
+
+ /* 12.3 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', 'c', '3'): {
+ s16 spc3;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &spc3);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(spc3), scale, BIT(3));
+ break;
+ }
+
+ /* 13.2 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', 'd', '2'): {
+ s16 spd2;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &spd2);
+ if (ret)
+ return ret;
+
+ *val = mult_frac((s16)be16_to_cpu(spd2), scale, BIT(2));
+ break;
+ }
+
+ /* 15.0 signed fixed point decimal */
+ case __SMC_KEY('s', 'p', 'f', '0'): {
+ s16 spf0;
+
+ ret = apple_smc_read_s16(smc, sensor->macsmc_key, &spf0);
+ if (ret)
+ return ret;
+
+ *val = (s16)be16_to_cpu(spf0) * scale;
+ break;
+ }
default:
return -EOPNOTSUPP;
}
@@ -263,6 +570,9 @@ static int macsmc_hwmon_write_key(struct apple_smc *smc,
/* unsigned 8-bit integer */
case __SMC_KEY('u', 'i', '8', ' '):
return apple_smc_write_u8(smc, sensor->macsmc_key, val);
+ /* 14.2 fixed point decimal */
+ case __SMC_KEY('f', 'p', 'e', '2'):
+ return apple_smc_write_u16(smc, sensor->macsmc_key, cpu_to_be16(val << 2));
default:
return -EOPNOTSUPP;
}
--
2.55.0
next prev parent reply other threads:[~2026-10-29 9:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 8:51 [RFC PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-10-29 8:51 ` [RFC PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot
2026-10-29 8:51 ` [RFC PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-10-29 9:23 ` sashiko-bot
2026-10-29 12:59 ` Ilpo Järvinen
2026-10-29 8:52 ` [RFC PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-10-29 9:17 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-10-29 9:17 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-10-29 9:16 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-10-29 9:15 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-10-29 9:11 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-10-29 9:16 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-10-29 9:19 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-10-29 9:13 ` sashiko-bot
2026-10-29 8:52 ` Atharva Tiwari [this message]
2026-10-29 9:18 ` [RFC PATCH 12/14] hwmon/macsmc: add more types sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-10-29 9:20 ` sashiko-bot
2026-10-29 8:52 ` [RFC PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-10-29 9:22 ` Sasha Finkelstein
2026-10-29 9:26 ` sashiko-bot
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=20261029085504.3547-13-atharvatiwarilinuxdev@gmail.com \
--to=atharvatiwarilinuxdev@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andy@kernel.org \
--cc=asahi@lists.linux.dev \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=brgl@kernel.org \
--cc=dave.hansen@linux.intel.com \
--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=keyrings@vger.kernel.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-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-watchdog@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=rafael@kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=serge@hallyn.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