Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc
@ 2026-12-04 13:12 Atharva Tiwari
  2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
                   ` (14 more replies)
  0 siblings, 15 replies; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

applesmc is very old, and all of its code is lumped into one
driver. Fan control, sensors, the light sensor, the motion
sensor and the keyboard backlight in a single file
with its own way of talking to the SMC. It is hard to extend
and to support new machines.

This series adds Intel Mac support to the macsmc drivers that
were written for Apple Silicon (the Asahi implementation).
The SMC works the same way on both platforms, so we share a
lot of code with Asahi. Only the way of talking to the SMC
differs.

To make that work, patch 1 splits the macsmc driver into a
common core and a backend. The existing RTKit code moves into
its own backend. Patch 2 adds an ACPI backend for Intel Macs
with I/O port, MMIO and interrupt support. After that, each
function gets its own small driver using the standard kernel
interfaces (hwmon, IIO, LEDs, power supply, RTC, watchdog),
instead of one large driver doing everything.

On Intel Macs these drivers replace applesmc (hwmon, light
sensor, motion sensor and keyboard backlight) and acpi-sbs
(battery and adapter). They are mutually exclusive with the
drivers they replace, so only one is used at a time.

The series is organised as follows:

  1      Split macsmc into a core and backends
  2      ACPI backend for Intel Macs
  3-6    New drivers: watchdog, IIO light and accelerometer,
         keyboard backlight LED
  7-9    RTC support for T2 Macs, a T2 detection flag, and
         disabling the broken ACPI RTCs
  10-11  Power supply support, replacing acpi-sbs
  12-13  hwmon support for Intel Macs
  14     ioctl for userspace access to SMC keys


Tested-on: MacBookPro16,1 , iMac20,1 , MacBookAir4,2 , MacBookPro12,1 ,
MacBookPro15,1, MacBookPro9,2, MacBookAir5,2.

Atharva Tiwari (14):
  treewide: Add backend for macsmc
  platform/x86: add backend for macsmc in intel macs
  watchdog: add driver for apple smc
  iio/light: add new driver for macsmc
  iio/accel: add driver for apple SMS
  leds: add support for macsmc kbl
  rtc: add support for x86 macs in macsmc-rtc
  treewide: Add a flag to detect the Apple T2 chip
  treewide: disable other rtc's in t2 macs
  power/supply: add support for x86 macs in macsmc-power
  acpi: disable battery and adapter for x86 apple machines
  hwmon/macsmc: add more types
  hwmon: add support for x86 macs in macsmc-hwmon
  mfd/macsmc: add ioctl to access smc keys

 MAINTAINERS                                   |    2 +-
 arch/x86/kernel/quirks.c                      |   37 +
 arch/x86/kernel/rtc.c                         |    5 +
 drivers/acpi/acpi_tad.c                       |    5 +
 drivers/acpi/sbs.c                            |    5 +-
 drivers/acpi/x86/utils.c                      |    5 +
 drivers/gpio/Kconfig                          |    2 +-
 drivers/gpio/gpio-macsmc.c                    |   13 +-
 drivers/hwmon/Kconfig                         |    7 +-
 drivers/hwmon/macsmc-hwmon.c                  | 1152 ++++++++++++++++-
 drivers/iio/accel/Kconfig                     |   10 +
 drivers/iio/accel/Makefile                    |    1 +
 drivers/iio/accel/macsmc-accel.c              |  260 ++++
 drivers/iio/light/Kconfig                     |   11 +
 drivers/iio/light/Makefile                    |    1 +
 drivers/iio/light/macsmc-light.c              |  209 +++
 drivers/leds/Kconfig                          |   11 +
 drivers/leds/Makefile                         |    1 +
 drivers/leds/leds-macsmc.c                    |   91 ++
 drivers/mfd/Kconfig                           |   15 +-
 drivers/mfd/Makefile                          |    2 +-
 drivers/mfd/macsmc-core.c                     |  347 +++++
 drivers/platform/x86/Kconfig                  |   10 +
 drivers/platform/x86/Makefile                 |    1 +
 drivers/platform/x86/macsmc-acpi.c            |  695 ++++++++++
 drivers/power/reset/Kconfig                   |    2 +-
 drivers/power/supply/Kconfig                  |    2 +-
 drivers/power/supply/macsmc-power.c           |  803 +++++++++---
 drivers/rtc/Kconfig                           |    2 +-
 drivers/rtc/rtc-cmos.c                        |    5 +
 drivers/rtc/rtc-macsmc.c                      |  132 +-
 drivers/soc/apple/Kconfig                     |   14 +
 drivers/soc/apple/Makefile                    |    2 +
 .../macsmc.c => soc/apple/macsmc-rtkit.c}     |  185 ++-
 drivers/watchdog/Kconfig                      |   11 +
 drivers/watchdog/Makefile                     |    1 +
 drivers/watchdog/macsmc_wdt.c                 |  158 +++
 include/linux/mfd/macsmc.h                    |  153 +--
 include/linux/platform_data/x86/apple.h       |    5 +
 include/uapi/linux/macsmc.h                   |  119 ++
 .../platform_certs/keyring_handler.h          |    8 -
 security/integrity/platform_certs/load_uefi.c |   38 +-
 42 files changed, 4090 insertions(+), 448 deletions(-)
 create mode 100644 drivers/iio/accel/macsmc-accel.c
 create mode 100644 drivers/iio/light/macsmc-light.c
 create mode 100644 drivers/leds/leds-macsmc.c
 create mode 100644 drivers/mfd/macsmc-core.c
 create mode 100644 drivers/platform/x86/macsmc-acpi.c
 rename drivers/{mfd/macsmc.c => soc/apple/macsmc-rtkit.c} (70%)
 create mode 100644 drivers/watchdog/macsmc_wdt.c
 create mode 100644 include/uapi/linux/macsmc.h

-- 
2.55.0


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH 01/14] treewide: Add backend for macsmc
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 13:56   ` sashiko-bot
                     ` (2 more replies)
  2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
                   ` (13 subsequent siblings)
  14 siblings, 3 replies; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Split the Apple SMC driver into a common core and a backend
that handles the actual communication. The existing RTKit
code moves to its own backend, and nothing changes for
Apple Silicon.

This lets the same SMC drivers run on other kinds of
hardware, starting with Intel Macs, as a replacement for
applesmc.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 MAINTAINERS                                   |   2 +-
 drivers/gpio/Kconfig                          |   2 +-
 drivers/gpio/gpio-macsmc.c                    |  13 +-
 drivers/hwmon/Kconfig                         |   2 +-
 drivers/mfd/Kconfig                           |  15 +-
 drivers/mfd/Makefile                          |   2 +-
 drivers/mfd/macsmc-core.c                     | 164 ++++++++++++++++
 drivers/power/reset/Kconfig                   |   2 +-
 drivers/power/supply/Kconfig                  |   2 +-
 drivers/power/supply/macsmc-power.c           |   4 +-
 drivers/rtc/Kconfig                           |   2 +-
 drivers/soc/apple/Kconfig                     |  14 ++
 drivers/soc/apple/Makefile                    |   2 +
 .../macsmc.c => soc/apple/macsmc-rtkit.c}     | 185 ++++++++----------
 include/linux/mfd/macsmc.h                    |  92 ++++++---
 15 files changed, 337 insertions(+), 166 deletions(-)
 create mode 100644 drivers/mfd/macsmc-core.c
 rename drivers/{mfd/macsmc.c => soc/apple/macsmc-rtkit.c} (70%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 03649f08c..1e5ae12ce 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2727,7 +2727,7 @@ F:	drivers/input/touchscreen/apple_z2.c
 F:	drivers/iommu/apple-dart.c
 F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
-F:	drivers/mfd/macsmc.c
+F:	drivers/mfd/macsmc-core.c
 F:	drivers/nvme/host/apple.c
 F:	drivers/nvmem/apple-efuses.c
 F:	drivers/nvmem/apple-spmi-nvmem.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 55e428002..63a2b1e2e 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1582,7 +1582,7 @@ config GPIO_LP87565
 
 config GPIO_MACSMC
 	tristate "Apple Mac SMC GPIO"
-	depends on MFD_MACSMC
+	depends on MACSMC_RTKIT
 	help
 	  Support for GPIOs controlled by the SMC microcontroller on Apple Mac
 	  systems.
diff --git a/drivers/gpio/gpio-macsmc.c b/drivers/gpio/gpio-macsmc.c
index b0952d066..8c7a942ad 100644
--- a/drivers/gpio/gpio-macsmc.c
+++ b/drivers/gpio/gpio-macsmc.c
@@ -97,20 +97,9 @@ static int macsmc_gpio_find_first_gpio_index(struct macsmc_gpio *smcgp)
 {
 	struct apple_smc *smc = smcgp->smc;
 	smc_key key = macsmc_gpio_key(0);
-	smc_key first_key, last_key;
 	int start, count, ret;
 
-	/* Return early if the key is out of bounds */
-	ret = apple_smc_get_key_by_index(smc, 0, &first_key);
-	if (ret)
-		return ret;
-	if (key <= first_key)
-		return -ENODEV;
-
-	ret = apple_smc_get_key_by_index(smc, smc->key_count - 1, &last_key);
-	if (ret)
-		return ret;
-	if (key > last_key)
+	if (key <= smc->first_key || key > smc->last_key)
 		return -ENODEV;
 
 	/* Binary search to find index of first SMC key bigger or equal to key */
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 18c682e1a..91ca7031c 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1245,7 +1245,7 @@ config SENSORS_LTQ_CPUTEMP
 
 config SENSORS_MACSMC_HWMON
 	tristate "Apple SMC (Apple Silicon)"
-	depends on MFD_MACSMC && OF
+	depends on MFD_MACSMC_CORE
 	help
 	  This driver enables hwmon support for current, power, temperature,
 	  and voltage sensors, as well as fan speed reporting and control
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 87ed55c15..c58cc3315 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -339,24 +339,15 @@ config MFD_LOCHNAGAR
 	help
 	  Support for Cirrus Logic Lochnagar audio development board.
 
-config MFD_MACSMC
-	tristate "Apple Silicon System Management Controller (SMC)"
-	depends on ARCH_APPLE || COMPILE_TEST
-	depends on OF
-	depends on APPLE_RTKIT
+config MFD_MACSMC_CORE
+	tristate "Apple System Management Controller (SMC) Core"
 	select MFD_CORE
 	help
-	  The System Management Controller (SMC) on Apple Silicon machines is a
+	  The System Management Controller (SMC) on Apple machines is a
 	  piece of hardware that exposes various functionalities such as
 	  temperature sensors, voltage/power meters, shutdown/reboot handling,
 	  GPIOs and more.
 
-	  Communication happens via a shared mailbox using the RTKit protocol
-	  which is also used for other co-processors. The SMC protocol then
-	  allows reading and writing many different keys which implement the
-	  various features. The MFD core device handles this protocol and
-	  exposes it to the sub-devices.
-
 config MFD_MADERA
 	tristate "Cirrus Logic Madera codecs"
 	select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f8101d2a9..0b0ccf91e 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -22,7 +22,7 @@ obj-$(CONFIG_MFD_CS42L43_SDW)	+= cs42l43-sdw.o
 obj-$(CONFIG_MFD_ENE_KB3930)	+= ene-kb3930.o
 obj-$(CONFIG_MFD_EXYNOS_LPASS)	+= exynos-lpass.o
 obj-$(CONFIG_MFD_GATEWORKS_GSC)	+= gateworks-gsc.o
-obj-$(CONFIG_MFD_MACSMC)	+= macsmc.o
+obj-$(CONFIG_MFD_MACSMC_CORE)	+= macsmc-core.o
 
 obj-$(CONFIG_MFD_TI_LP873X)	+= lp873x.o
 obj-$(CONFIG_MFD_TI_LP87565)	+= lp87565.o
diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
new file mode 100644
index 000000000..b8905c834
--- /dev/null
+++ b/drivers/mfd/macsmc-core.c
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC core framework
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+static const struct mfd_cell apple_smc_rtkit_devs[] = {
+	MFD_CELL_NAME("macsmc-input"),
+	MFD_CELL_NAME("macsmc-power"),
+	MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-gpio"),
+	MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"),
+	MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),
+	MFD_CELL_OF("macsmc-rtc", NULL, NULL, 0, 0, "apple,smc-rtc"),
+};
+
+/*
+ * There isn't device tree on acpi backend, so we need to use
+ * apple_smc_key_exists to register mfd devs
+ */
+static const struct mfd_cell apple_smc_acpi_common[] = {
+	MFD_CELL_NAME("macsmc-hwmon"),
+	MFD_CELL_NAME("macsmc-power"),
+};
+
+static const struct mfd_cell apple_smc_acpi_rtc[] = {
+	MFD_CELL_NAME("macsmc-rtc"),
+};
+
+int apple_smc_read(struct apple_smc *smc, smc_key key, void *buf, size_t size)
+{
+	guard(mutex)(&smc->mutex);
+	return smc->be->read(smc->be_cookie, key, buf, size);
+}
+EXPORT_SYMBOL(apple_smc_read);
+
+int apple_smc_write(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
+{
+	guard(mutex)(&smc->mutex);
+	return smc->be->write(smc->be_cookie, key, buf, size);
+}
+EXPORT_SYMBOL(apple_smc_write);
+
+int apple_smc_enter_atomic(struct apple_smc *smc)
+{
+	guard(mutex)(&smc->mutex);
+	return smc->be->enter_atomic(smc->be_cookie);
+}
+EXPORT_SYMBOL(apple_smc_enter_atomic);
+
+int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
+{
+	guard(spinlock_irqsave)(&smc->lock);
+	return smc->be->write_atomic(smc->be_cookie, key, buf, size);
+}
+EXPORT_SYMBOL(apple_smc_write_atomic);
+
+int apple_smc_rw(struct apple_smc *smc, smc_key key, const void *wbuf, size_t wsize,
+		void *rbuf, size_t rsize)
+{
+	guard(mutex)(&smc->mutex);
+	return smc->be->rw(smc->be_cookie, key, wbuf, wsize, rbuf, rsize);
+}
+EXPORT_SYMBOL(apple_smc_rw);
+
+int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key)
+{
+	guard(mutex)(&smc->mutex);
+	int ret;
+
+	ret = smc->be->get_key_by_index(smc->be_cookie, index, key);
+	*key = swab32(*key);
+
+	return ret;
+}
+EXPORT_SYMBOL(apple_smc_get_key_by_index);
+
+int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_key_info *info)
+{
+	guard(mutex)(&smc->mutex);
+	return smc->be->get_key_info(smc->be_cookie, key, info);
+}
+EXPORT_SYMBOL(apple_smc_get_key_info);
+
+static void apple_smc_disable_notifications(void *data)
+{
+	struct apple_smc *smc = data;
+
+	guard(mutex)(&smc->mutex);
+	smc->be->disable_notifications(smc->be_cookie);
+}
+
+int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
+		void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi)
+{
+	struct apple_smc *smc;
+	__be32 count;
+	int ret;
+
+	smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
+	if (!smc)
+		return -ENOMEM;
+
+	smc->dev = dev;
+	smc->be_cookie = cookie;
+	smc->be = ops;
+	smc->is_acpi = is_acpi;
+	smc->event_handlers = event_handlers;
+	mutex_init(&smc->mutex);
+	spin_lock_init(&smc->lock);
+
+	ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
+	if (ret < 0)
+		return ret;
+	smc->key_count = be32_to_cpu(count);
+
+	ret = apple_smc_get_key_by_index(smc, 0, &smc->first_key);
+	if (ret < 0)
+		return ret;
+
+	ret = apple_smc_get_key_by_index(smc, smc->key_count - 1, &smc->last_key);
+	if (ret < 0)
+		return ret;
+
+	dev_set_drvdata(dev, smc);
+
+	ret = devm_add_action_or_reset(dev, apple_smc_disable_notifications, smc);
+	if (ret)
+		return ret;
+
+	if (smc->is_acpi) {
+		ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common,
+			ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL);
+		if (ret < 0)
+			return ret;
+
+		if (apple_smc_key_exists(smc, SMC_KEY(CLKO))) {
+			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_rtc,
+				ARRAY_SIZE(apple_smc_acpi_rtc), NULL, 0, NULL);
+			if (ret < 0)
+				return ret;
+		}
+
+	} else
+		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
+			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
+	if (ret < 0)
+		return ret;
+
+	dev_info(dev, "Successfully Initialized (%d keys First key: %p4ch Last key: %p4ch)\n",
+			smc->key_count, &smc->first_key, &smc->last_key);
+	return 0;
+}
+EXPORT_SYMBOL(apple_smc_probe);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC core");
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index bce996bbe..14d62afc1 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -142,7 +142,7 @@ config POWER_RESET_MCF_RCM
 
 config POWER_RESET_MACSMC
 	tristate "Apple SMC reset/power-off driver"
-	depends on MFD_MACSMC
+	depends on MACSMC_RTKIT
 	help
 	  This driver supports reset and power-off on Apple Mac machines
 	  that implement this functionality via the SMC.
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index b89ef40df..6e944cc59 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -1193,7 +1193,7 @@ config FUEL_GAUGE_MM8013
 
 config MACSMC_POWER
 	tristate "Apple SMC Battery and Power Driver"
-	depends on MFD_MACSMC
+	depends on MFD_MACSMC_CORE
 	help
 	  This driver provides support for the battery and AC adapter on
 	  Apple Silicon machines. It exposes battery telemetry (voltage,
diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c
index ef735f863..ced37a701 100644
--- a/drivers/power/supply/macsmc-power.c
+++ b/drivers/power/supply/macsmc-power.c
@@ -859,7 +859,7 @@ static int macsmc_power_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	power->nb.notifier_call = macsmc_power_event;
-	blocking_notifier_chain_register(&smc->event_handlers, &power->nb);
+	blocking_notifier_chain_register(smc->event_handlers, &power->nb);
 
 	return 0;
 }
@@ -868,7 +868,7 @@ static void macsmc_power_remove(struct platform_device *pdev)
 {
 	struct macsmc_power *power = dev_get_drvdata(&pdev->dev);
 
-	blocking_notifier_chain_unregister(&power->smc->event_handlers, &power->nb);
+	blocking_notifier_chain_unregister(power->smc->event_handlers, &power->nb);
 }
 
 static const struct platform_device_id macsmc_power_id[] = {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 05b9233b9..8cc27891b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -2096,7 +2096,7 @@ config RTC_DRV_WILCO_EC
 
 config RTC_DRV_MACSMC
 	tristate "Apple Mac System Management Controller RTC"
-	depends on MFD_MACSMC
+	depends on MFD_MACSMC_CORE
 	help
 	  If you say yes here you get support for RTC functions
 	  inside Apple SPMI PMUs accessed through the SoC's
diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig
index db30c0ade..e89bc9cb4 100644
--- a/drivers/soc/apple/Kconfig
+++ b/drivers/soc/apple/Kconfig
@@ -52,6 +52,20 @@ config APPLE_TUNABLE
 	tristate
 	depends on ARCH_APPLE || COMPILE_TEST
 
+config MACSMC_RTKIT
+	tristate "Apple Silicon System Management Controller (SMC) Backend"
+	depends on ARCH_APPLE || COMPILE_TEST
+	depends on OF
+	depends on APPLE_RTKIT
+	depends on MFD_MACSMC_CORE
+	help
+	  MACSMC RTKIT allows communicatation with the System Management
+	  Controller on M-series Macs. It is required to use GPIO, control fans
+	  and to control battery start and end threshold.
+
+	  Say 'y' here if you have an Apple Soc
+
+
 endmenu
 
 endif
diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile
index 0481f7f43..7227cf69e 100644
--- a/drivers/soc/apple/Makefile
+++ b/drivers/soc/apple/Makefile
@@ -13,3 +13,5 @@ apple-sart-y = sart.o
 
 obj-$(CONFIG_APPLE_TUNABLE) += apple-tunable.o
 apple-tunable-y = tunable.o
+
+obj-$(CONFIG_MACSMC_RTKIT) += macsmc-rtkit.o
diff --git a/drivers/mfd/macsmc.c b/drivers/soc/apple/macsmc-rtkit.c
similarity index 70%
rename from drivers/mfd/macsmc.c
rename to drivers/soc/apple/macsmc-rtkit.c
index 514cba7dc..eaebeb1be 100644
--- a/drivers/mfd/macsmc.c
+++ b/drivers/soc/apple/macsmc-rtkit.c
@@ -11,7 +11,6 @@
 #include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/math.h>
-#include <linux/mfd/core.h>
 #include <linux/mfd/macsmc.h>
 #include <linux/notifier.h>
 #include <linux/of.h>
@@ -27,14 +26,6 @@
 #define SMC_SHMEM_SIZE			0x1000
 #define SMC_MAX_SIZE			255
 
-#define SMC_MSG_READ_KEY		0x10
-#define SMC_MSG_WRITE_KEY		0x11
-#define SMC_MSG_GET_KEY_BY_INDEX	0x12
-#define SMC_MSG_GET_KEY_INFO		0x13
-#define SMC_MSG_INITIALIZE		0x17
-#define SMC_MSG_NOTIFICATION		0x18
-#define SMC_MSG_RW_KEY			0x20
-
 #define SMC_DATA			GENMASK_ULL(63, 32)
 #define SMC_WSIZE			GENMASK_ULL(31, 24)
 #define SMC_SIZE			GENMASK_ULL(23, 16)
@@ -44,24 +35,35 @@
 
 #define SMC_TIMEOUT_MS		500
 
-static const struct mfd_cell apple_smc_devs[] = {
-	MFD_CELL_NAME("macsmc-input"),
-	MFD_CELL_NAME("macsmc-power"),
-	MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-gpio"),
-	MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"),
-	MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),
-	MFD_CELL_OF("macsmc-rtc", NULL, NULL, 0, 0, "apple,smc-rtc"),
+struct apple_smc_rtkit {
+	struct device *dev;
+
+	struct blocking_notifier_head event_handlers;
+
+	struct apple_rtkit *rtk;
+
+	struct completion init_done;
+	enum apple_smc_boot_stage boot_stage;
+
+	struct resource *sram;
+	void __iomem *sram_base;
+	struct apple_rtkit_shmem shmem;
+
+	unsigned int msg_id;
+
+	bool atomic_mode;
+	bool atomic_pending;
+	struct completion cmd_done;
+	u64 cmd_ret;
 };
 
-static int apple_smc_cmd_locked(struct apple_smc *smc, u64 cmd, u64 arg,
+static int apple_smc_rtkit_cmd_locked(struct apple_smc_rtkit *smc, u64 cmd, u64 arg,
 				  u64 size, u64 wsize, u32 *ret_data)
 {
 	u8 result;
 	int ret;
 	u64 msg;
 
-	lockdep_assert_held(&smc->mutex);
-
 	if (smc->boot_stage != APPLE_SMC_INITIALIZED)
 		return -EIO;
 	if (smc->atomic_mode)
@@ -103,15 +105,7 @@ static int apple_smc_cmd_locked(struct apple_smc *smc, u64 cmd, u64 arg,
 	return FIELD_GET(SMC_SIZE, smc->cmd_ret);
 }
 
-static int apple_smc_cmd(struct apple_smc *smc, u64 cmd, u64 arg,
-			 u64 size, u64 wsize, u32 *ret_data)
-{
-	guard(mutex)(&smc->mutex);
-
-	return apple_smc_cmd_locked(smc, cmd, arg, size, wsize, ret_data);
-}
-
-static int apple_smc_rw_locked(struct apple_smc *smc, smc_key key,
+static int apple_smc_rtkit_rw_locked(struct apple_smc_rtkit *smc, smc_key key,
 				const void *wbuf, size_t wsize,
 				void *rbuf, size_t rsize)
 {
@@ -120,8 +114,6 @@ static int apple_smc_rw_locked(struct apple_smc *smc, smc_key key,
 	int ret;
 	u64 cmd;
 
-	lockdep_assert_held(&smc->mutex);
-
 	if (rsize > SMC_MAX_SIZE)
 		return -EINVAL;
 	if (wsize > SMC_MAX_SIZE)
@@ -149,7 +141,7 @@ static int apple_smc_rw_locked(struct apple_smc *smc, smc_key key,
 		return -EINVAL;
 	}
 
-	ret = apple_smc_cmd_locked(smc, cmd, key, smc_size, smc_wsize, &rdata);
+	ret = apple_smc_rtkit_cmd_locked(smc, cmd, key, smc_size, smc_wsize, &rdata);
 	if (ret < 0)
 		return ret;
 
@@ -169,48 +161,42 @@ static int apple_smc_rw_locked(struct apple_smc *smc, smc_key key,
 	return ret;
 }
 
-int apple_smc_read(struct apple_smc *smc, smc_key key, void *buf, size_t size)
+static int apple_smc_rtkit_read(void *cookie, smc_key key, void *buf, size_t size)
 {
-	guard(mutex)(&smc->mutex);
+	struct apple_smc_rtkit *smc = cookie;
 
-	return apple_smc_rw_locked(smc, key, NULL, 0, buf, size);
+	return apple_smc_rtkit_rw_locked(smc, key, NULL, 0, buf, size);
 }
-EXPORT_SYMBOL(apple_smc_read);
 
-int apple_smc_write(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
+static int apple_smc_rtkit_write(void *cookie, smc_key key, const void *buf, size_t size)
 {
-	guard(mutex)(&smc->mutex);
+	struct apple_smc_rtkit *smc = cookie;
 
-	return apple_smc_rw_locked(smc, key, buf, size, NULL, 0);
+	return apple_smc_rtkit_rw_locked(smc, key, buf, size, NULL, 0);
 }
-EXPORT_SYMBOL(apple_smc_write);
 
-int apple_smc_rw(struct apple_smc *smc, smc_key key, const void *wbuf, size_t wsize,
+static int apple_smc_rtkit_rw(void *cookie, smc_key key, const void *wbuf, size_t wsize,
 		 void *rbuf, size_t rsize)
 {
-	guard(mutex)(&smc->mutex);
+	struct apple_smc_rtkit *smc = cookie;
 
-	return apple_smc_rw_locked(smc, key, wbuf, wsize, rbuf, rsize);
+	return apple_smc_rtkit_rw_locked(smc, key, wbuf, wsize, rbuf, rsize);
 }
-EXPORT_SYMBOL(apple_smc_rw);
 
-int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key)
+static int apple_smc_rtkit_get_key_by_index(void *cookie, int index, smc_key *key)
 {
-	int ret;
+	struct apple_smc_rtkit *smc = cookie;
 
-	ret = apple_smc_cmd(smc, SMC_MSG_GET_KEY_BY_INDEX, index, 0, 0, key);
-
-	*key = swab32(*key);
-	return ret;
+	return apple_smc_rtkit_cmd_locked(smc, SMC_MSG_GET_KEY_BY_INDEX, index, 0, 0, key);
 }
-EXPORT_SYMBOL(apple_smc_get_key_by_index);
 
-int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_key_info *info)
+static int apple_smc_rtkit_get_key_info(void *cookie, smc_key key, struct apple_smc_key_info *info)
 {
+	struct apple_smc_rtkit *smc = cookie;
 	u8 key_info[6];
 	int ret;
 
-	ret = apple_smc_cmd(smc, SMC_MSG_GET_KEY_INFO, key, 0, 0, NULL);
+	ret = apple_smc_rtkit_cmd_locked(smc, SMC_MSG_GET_KEY_INFO, key, 0, 0, NULL);
 	if (ret >= 0 && info) {
 		memcpy_fromio(key_info, smc->shmem.iomem, sizeof(key_info));
 		info->size = key_info[0];
@@ -219,12 +205,9 @@ int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_
 	}
 	return ret;
 }
-EXPORT_SYMBOL(apple_smc_get_key_info);
 
-int apple_smc_enter_atomic(struct apple_smc *smc)
+static int apple_smc_rtkit_enter_atomic(void *cookie)
 {
-	guard(mutex)(&smc->mutex);
-
 	/*
 	 * Disable notifications since this is called before shutdown and no
 	 * notification handler will be able to handle the notification
@@ -233,19 +216,19 @@ int apple_smc_enter_atomic(struct apple_smc *smc)
 	 * We can't use apple_smc_write_flag here since that would try to lock
 	 * smc->mutex again.
 	 */
+	struct apple_smc_rtkit *smc = cookie;
 	const u8 flag = 0;
 
-	apple_smc_rw_locked(smc, SMC_KEY(NTAP), &flag, sizeof(flag), NULL, 0);
+	apple_smc_rtkit_rw_locked(smc, SMC_KEY(NTAP), &flag, sizeof(flag), NULL, 0);
 
 	smc->atomic_mode = true;
 
 	return 0;
 }
-EXPORT_SYMBOL(apple_smc_enter_atomic);
 
-int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
+static int apple_smc_rtkit_write_atomic(void *cookie, smc_key key, const void *buf, size_t size)
 {
-	guard(spinlock_irqsave)(&smc->lock);
+	struct apple_smc_rtkit *smc = cookie;
 	u8 result;
 	int ret;
 	u64 msg;
@@ -293,11 +276,28 @@ int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf,
 
 	return FIELD_GET(SMC_SIZE, smc->cmd_ret);
 }
-EXPORT_SYMBOL(apple_smc_write_atomic);
+
+static void apple_smc_rtkit_disable_notifications(void *cookie)
+{
+	const u8 flag = 0;
+
+	apple_smc_rtkit_write(cookie, SMC_KEY(NTAP), &flag, sizeof(flag));
+}
+
+static const struct apple_smc_backend_ops apple_smc_rtkit_backend_ops = {
+	.read = apple_smc_rtkit_read,
+	.write = apple_smc_rtkit_write,
+	.enter_atomic = apple_smc_rtkit_enter_atomic,
+	.write_atomic = apple_smc_rtkit_write_atomic,
+	.rw = apple_smc_rtkit_rw,
+	.get_key_by_index = apple_smc_rtkit_get_key_by_index,
+	.get_key_info = apple_smc_rtkit_get_key_info,
+	.disable_notifications = apple_smc_rtkit_disable_notifications,
+};
 
 static void apple_smc_rtkit_crashed(void *cookie, const void *bfr, size_t bfr_len)
 {
-	struct apple_smc *smc = cookie;
+	struct apple_smc_rtkit *smc = cookie;
 
 	smc->boot_stage = APPLE_SMC_ERROR_CRASHED;
 	dev_err(smc->dev, "SMC crashed! Your system will reboot in a few seconds...\n");
@@ -305,7 +305,7 @@ static void apple_smc_rtkit_crashed(void *cookie, const void *bfr, size_t bfr_le
 
 static int apple_smc_rtkit_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
 {
-	struct apple_smc *smc = cookie;
+	struct apple_smc_rtkit *smc = cookie;
 	size_t bfr_end;
 
 	if (!bfr->iova) {
@@ -332,7 +332,7 @@ static int apple_smc_rtkit_shmem_setup(void *cookie, struct apple_rtkit_shmem *b
 
 static bool apple_smc_rtkit_recv_early(void *cookie, u8 endpoint, u64 message)
 {
-	struct apple_smc *smc = cookie;
+	struct apple_smc_rtkit *smc = cookie;
 
 	if (endpoint != SMC_ENDPOINT) {
 		dev_warn(smc->dev, "Received message for unknown endpoint 0x%x\n", endpoint);
@@ -368,7 +368,7 @@ static bool apple_smc_rtkit_recv_early(void *cookie, u8 endpoint, u64 message)
 
 static void apple_smc_rtkit_recv(void *cookie, u8 endpoint, u64 message)
 {
-	struct apple_smc *smc = cookie;
+	struct apple_smc_rtkit *smc = cookie;
 
 	if (endpoint != SMC_ENDPOINT) {
 		dev_warn(smc->dev, "Received message for unknown endpoint 0x%x\n", endpoint);
@@ -392,32 +392,24 @@ static const struct apple_rtkit_ops apple_smc_rtkit_ops = {
 
 static void apple_smc_rtkit_shutdown(void *data)
 {
-	struct apple_smc *smc = data;
+	struct apple_smc_rtkit *smc = data;
 
 	/* Shut down SMC firmware, if it's not completely wedged */
 	if (apple_rtkit_is_running(smc->rtk))
 		apple_rtkit_quiesce(smc->rtk);
 }
 
-static void apple_smc_disable_notifications(void *data)
-{
-	struct apple_smc *smc = data;
-
-	apple_smc_write_flag(smc, SMC_KEY(NTAP), false);
-}
-
-static int apple_smc_probe(struct platform_device *pdev)
+static int apple_smc_rtkit_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct apple_smc *smc;
-	__be32 count;
+	struct apple_smc_rtkit *smc;
+	const u8 flag = 1;
 	int ret;
 
 	smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
 	if (!smc)
 		return -ENOMEM;
 
-	mutex_init(&smc->mutex);
 	smc->dev = &pdev->dev;
 	smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram);
 	if (IS_ERR(smc->sram_base))
@@ -458,49 +450,32 @@ static int apple_smc_probe(struct platform_device *pdev)
 		return -EIO;
 	}
 
-	dev_set_drvdata(&pdev->dev, smc);
 	BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
 
-	ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
-	if (ret >= 0 && ret != sizeof(count))
-		ret = -EINVAL;
-	if (ret < 0)
-		return dev_err_probe(smc->dev, ret, "Failed to get key count");
-	smc->key_count = be32_to_cpu(count);
-
 	/* Enable notifications */
-	apple_smc_write_flag(smc, SMC_KEY(NTAP), true);
-	ret = devm_add_action_or_reset(dev, apple_smc_disable_notifications, smc);
-	if (ret)
-		return ret;
+	apple_smc_rtkit_rw_locked(smc, SMC_KEY(NTAP), &flag, sizeof(flag), NULL, 0);
 
-	ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE,
-				   apple_smc_devs, ARRAY_SIZE(apple_smc_devs),
-				   NULL, 0, NULL);
-	if (ret)
-		return dev_err_probe(smc->dev, ret, "Failed to register sub-devices");
-
-
-	return 0;
+	return apple_smc_probe(dev, &apple_smc_rtkit_backend_ops, smc,
+			&smc->event_handlers, false);
 }
 
-static const struct of_device_id apple_smc_of_match[] = {
+static const struct of_device_id apple_smc_rtkit_of_match[] = {
 	{ .compatible = "apple,t8103-smc" },
 	{ .compatible = "apple,smc" },
 	{},
 };
-MODULE_DEVICE_TABLE(of, apple_smc_of_match);
+MODULE_DEVICE_TABLE(of, apple_smc_rtkit_of_match);
 
-static struct platform_driver apple_smc_driver = {
+static struct platform_driver apple_smc_rtkit_driver = {
 	.driver = {
-		.name = "macsmc",
-		.of_match_table = apple_smc_of_match,
+		.name = "macsmc-rtkit",
+		.of_match_table = apple_smc_rtkit_of_match,
 	},
-	.probe = apple_smc_probe,
+	.probe = apple_smc_rtkit_probe,
 };
-module_platform_driver(apple_smc_driver);
+module_platform_driver(apple_smc_rtkit_driver);
 
 MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
 MODULE_AUTHOR("Sven Peter <sven@kernel.org>");
 MODULE_LICENSE("Dual MIT/GPL");
-MODULE_DESCRIPTION("Apple SMC driver");
+MODULE_DESCRIPTION("Apple SMC RTKIT Backend driver");
diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h
index cc09ecce0..cdd040f0c 100644
--- a/include/linux/mfd/macsmc.h
+++ b/include/linux/mfd/macsmc.h
@@ -47,6 +47,25 @@ typedef u32 smc_key;
 #define APPLE_SMC_WRITABLE BIT(6)
 #define APPLE_SMC_FUNCTION BIT(4)
 
+#define SMC_MSG_READ_KEY                0x10
+#define SMC_MSG_WRITE_KEY               0x11
+#define SMC_MSG_GET_KEY_BY_INDEX        0x12
+#define SMC_MSG_GET_KEY_INFO            0x13
+#define SMC_MSG_INITIALIZE              0x17
+#define SMC_MSG_NOTIFICATION            0x18
+#define SMC_MSG_RW_KEY                  0x20
+
+#define SMC_INT_SHUTDOWN                0x40
+#define SMC_INT_BRIDGEOS_CRASH          0x41
+#define SMC_INT_ALS_CHANGE              0x2A
+#define SMC_INT_CMD_DONE                0x4B
+#define SMC_INT_THERMAL_LEVEL           0x54
+#define SMC_INT_PLATFORM_FUNCTION       0x55
+#define SMC_INT_SMS_DROP                0x60
+#define SMC_INT_SMS_ORIENTATION 0x69
+#define SMC_INT_SMS_SHOCK               0x6F
+#define SMC_INT_PLIMIT_CHANGED          0x80
+
 /**
  * struct apple_smc_key_info - Information for a SMC key as returned by SMC
  * @type_code: FourCC code indicating the type for this key.
@@ -80,24 +99,41 @@ enum apple_smc_boot_stage {
 	APPLE_SMC_ERROR_CRASHED
 };
 
+/**
+ * struct apple_smc_backend_ops - SMC backend interface
+ * @read: Read SMC key data
+ * @write: Write SMC key data
+ * @enter_atomic: Enter atomic access mode
+ * @write_atomic: Atomic write to SMC key
+ * @rw: Combined write/read transaction
+ * @get_key_by_index: Resolve key by index
+ * @get_key_info: Get metadata for key
+ * @disable_notifications: Disable notfications on removal
+ */
+struct apple_smc_backend_ops {
+	int (*read)(void *cookie, smc_key key, void *buf, size_t size);
+	int (*write)(void *cookie, smc_key key, const void *buf, size_t size);
+	int (*enter_atomic)(void *cookie);
+	int (*write_atomic)(void *cookie, smc_key key, const void *buf, size_t size);
+	int (*rw)(void *cookie, smc_key key, const void *wbuf, size_t wsize,
+		  void *rbuf, size_t rsize);
+	int (*get_key_by_index)(void *cookie, int index, smc_key *key);
+	int (*get_key_info)(void *cookie, smc_key key,
+			    struct apple_smc_key_info *info);
+	void (*disable_notifications)(void *cookie);
+};
+
+
 /**
  * struct apple_smc
  * @dev: Underlying device struct for the physical backend device
  * @key_count: Number of available SMC keys
  * @first_key: First valid SMC key
  * @last_key: Last valid SMC key
- * @event_handlers: Notifier call chain for events received from SMC
- * @rtk: Pointer to Apple RTKit instance
- * @init_done: Completion for initialization
- * @boot_stage: Current boot stage of SMC
- * @sram: Pointer to SRAM resource
- * @sram_base: SRAM base address
- * @shmem: RTKit shared memory structure for SRAM
- * @msg_id: Current message id for commands, will be incremented for each command
- * @atomic_mode: Flag set when atomic mode is entered
- * @atomic_pending: Flag indicating pending atomic command
- * @cmd_done: Completion for command execution in non-atomic mode
- * @cmd_ret: Return value from SMC for last command
+ * @event_handlers: Pointer to Notifier call chain from the backend
+ * @be: Backend operations for SMC access
+ * @be_cookie: Backend context passed to ops callbacks
+ * @is_acpi: Is the backend ACPI based
  * @mutex: Mutex for non-atomic mode
  * @lock: Spinlock for atomic mode
  */
@@ -108,23 +144,11 @@ struct apple_smc {
 	smc_key first_key;
 	smc_key last_key;
 
-	struct blocking_notifier_head event_handlers;
-
-	struct apple_rtkit *rtk;
+	struct blocking_notifier_head *event_handlers;
+	const struct apple_smc_backend_ops *be;
+	void *be_cookie;
 
-	struct completion init_done;
-	enum apple_smc_boot_stage boot_stage;
-
-	struct resource *sram;
-	void __iomem *sram_base;
-	struct apple_rtkit_shmem shmem;
-
-	unsigned int msg_id;
-
-	bool atomic_mode;
-	bool atomic_pending;
-	struct completion cmd_done;
-	u64 cmd_ret;
+	bool is_acpi;
 
 	struct mutex mutex;
 	spinlock_t lock;
@@ -225,6 +249,18 @@ static inline bool apple_smc_key_exists(struct apple_smc *smc, smc_key key)
 	return apple_smc_get_key_info(smc, key, NULL) >= 0;
 }
 
+/**
+ * apple_smc_probe - Initialize Apple SMC device
+ * @dev: Device for the SMC instance
+ * @ops: Backend operations for SMC access
+ * @cookie: Opaque backend context
+ * @event_handlers: Pointer to Notifier call chain from backend
+ * @is_acpi: Is the backend ACPI based.
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
+		void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi);
+
 #define APPLE_SMC_TYPE_OPS(type) \
 	static inline int apple_smc_read_##type(struct apple_smc *smc, smc_key key, type *p) \
 	{ \
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  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 13:12 ` Atharva Tiwari
  2026-12-04 13:58   ` sashiko-bot
  2026-12-04 14:19   ` Andy Shevchenko
  2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
                   ` (12 subsequent siblings)
  14 siblings, 2 replies; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Add a backend that talks to the SMC on Intel Macs over ACPI.
It supports the old I/O port interface, and also MMIO and
interrupt-driven completion, which applesmc doesn't have.
If an interrupt is missed it falls back to polling.

This is the base that lets the macsmc drivers replace
applesmc.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/platform/x86/Kconfig       |  10 +
 drivers/platform/x86/Makefile      |   1 +
 drivers/platform/x86/macsmc-acpi.c | 695 +++++++++++++++++++++++++++++
 3 files changed, 706 insertions(+)
 create mode 100644 drivers/platform/x86/macsmc-acpi.c

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 4851bf451..00474f31b 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -202,6 +202,16 @@ config ADV_SWBUTTON
 	  To compile this driver as a module, choose M here. The module will
 	  be called adv_swbutton.
 
+config MACSMC_ACPI
+	tristate "Apple SMC (System Management Controller) ACPI Backend"
+	depends on MFD_MACSMC_CORE && ACPI
+	help
+	  This driver allows communication with the SMC (System Management Controller)
+	  on Intel-Macs. It is used to control fans, control battery, and more.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called macsmc_acpi.
+
 config APPLE_GMUX
 	tristate "Apple Gmux Driver"
 	depends on ACPI && PCI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index cab20a414..933aed4a8 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -28,6 +28,7 @@ obj-y				+= amd/
 obj-$(CONFIG_ADV_SWBUTTON)	+= adv_swbutton.o
 
 # Apple
+obj-$(CONFIG_MACSMC_ACPI)	+= macsmc-acpi.o
 obj-$(CONFIG_APPLE_GMUX)	+= apple-gmux.o
 
 # ASUS
diff --git a/drivers/platform/x86/macsmc-acpi.c b/drivers/platform/x86/macsmc-acpi.c
new file mode 100644
index 000000000..8a93245c9
--- /dev/null
+++ b/drivers/platform/x86/macsmc-acpi.c
@@ -0,0 +1,695 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC ACPI backend
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ *
+ * PIO code taken from drivers/hwmon/applesmc.c:
+ * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ */
+
+#include <linux/acpi.h>
+#include <linux/bits.h>
+#include <linux/byteorder/generic.h>
+#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/devm-helpers.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/iopoll.h>
+#include <linux/kfifo.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/reboot.h>
+#include <linux/spinlock.h>
+#include <linux/time.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <linux/workqueue.h>
+
+#define SMC_IO_DATA_PORT	0
+#define SMC_IO_CMD_PORT		4
+#define SMC_IO_NR_PORTS		32
+
+#define SMC_IO_STATUS_AWAITING_DATA	BIT(0)
+#define SMC_IO_STATUS_IB_CLOSED		BIT(1)
+#define SMC_IO_STATUS_BUSY		BIT(2)
+#define SMC_IO_STATUS_IRQ_PENDING	BIT(6)
+#define SMC_IO_INT_PLIMIT		0x10
+#define SMC_IO_INT_PLIMIT_GPU		0x14
+#define SMC_IO_INT_ID_PORT		0x1F
+
+#define SMC_MMIO_KEY_DATA		0
+#define SMC_MMIO_KEY_INFO_SIZE		(SMC_MMIO_KEY_DATA + 5)
+#define SMC_MMIO_KEY_INFO_FLAGS		(SMC_MMIO_KEY_DATA + 6)
+#define SMC_MMIO_KEY_INTERRUPT_STATUS	0x4000
+#define SMC_MMIO_KEY_STATUS		0x4005
+#define SMC_MMIO_KEY_NAME		0x78
+#define SMC_MMIO_KEY_DATA_LEN		0x7D
+#define SMC_MMIO_KEY_SMC_ID		0x7E
+#define SMC_MMIO_KEY_CMD		0x7F
+#define SMC_MMIO_MIN_SIZE		0x4006
+#define SMC_MMIO_STATUS_DONE		BIT(5)
+#define SMC_MMIO_IRQ_PENDING		BIT(5)
+
+#define SMC_TIMEOUT_MS			1000
+
+struct apple_smc_acpi {
+	struct device *dev;
+
+	u8 __iomem *iomem_base;
+	u32 iomem_base_addr, iomem_base_size;
+	bool is_mmio;
+
+	u16 port_base;
+	bool has_port;
+
+	int irq;
+	bool has_interrupt;
+	bool interrupt_enabled;
+	struct completion cmd_done;
+
+	struct blocking_notifier_head event_handlers;
+	struct work_struct shutdown_work;
+	struct work_struct notifier_work;
+
+	DECLARE_KFIFO(event_fifo, u8, 64);
+	/* Protects event_fifo, shared between the IRQ handler and notifier_work */
+	spinlock_t event_lock;
+};
+
+
+static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
+{
+	u8 status;
+	int ret;
+
+	if (smc->interrupt_enabled) {
+		reinit_completion(&smc->cmd_done);
+		if (wait_for_completion_timeout(&smc->cmd_done,
+					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
+			return 0;
+
+		smc->interrupt_enabled = 0;
+		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
+	}
+
+	ret = read_poll_timeout(inb, status, (status & mask) == val,
+				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
+				false, smc->port_base + SMC_IO_CMD_PORT);
+	if (ret)
+		dev_dbg(smc->dev, "port/wait: timeout value:%u, mask:%u\n", val, mask);
+
+	return ret;
+}
+
+static int apple_smc_acpi_port_write_byte(struct apple_smc_acpi *smc, u8 buf)
+{
+	int ret;
+
+	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_IB_CLOSED);
+	if (ret)
+		return ret;
+
+	ret = apple_smc_acpi_port_wait(smc, SMC_IO_STATUS_BUSY, SMC_IO_STATUS_BUSY);
+	if (ret)
+		return ret;
+
+	outb(buf, smc->port_base + SMC_IO_DATA_PORT);
+	return 0;
+}
+
+static int apple_smc_acpi_port_write_cmd(struct apple_smc_acpi *smc, u8 buf)
+{
+	int ret;
+
+	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_IB_CLOSED);
+	if (ret)
+		return ret;
+
+	outb(buf, smc->port_base + SMC_IO_CMD_PORT);
+	return 0;
+}
+
+static int apple_smc_acpi_port_write_key(struct apple_smc_acpi *smc, smc_key key)
+{
+	int i;
+
+	for (i = 3; i >= 0; i--) {
+		if (apple_smc_acpi_port_write_byte(smc, (key >> (i * 8)) & 0xff))
+			return -EIO;
+	}
+	return 0;
+}
+
+static int apple_smc_acpi_port_valid(struct apple_smc_acpi *smc)
+{
+	int ret;
+
+	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
+	if (!ret)
+		return ret;
+
+	ret = apple_smc_acpi_port_write_cmd(smc, SMC_MSG_READ_KEY);
+	if (ret)
+		return ret;
+
+	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
+}
+
+static int apple_smc_acpi_port_read(struct apple_smc_acpi *smc, u8 cmd, smc_key key,
+				u8 *buffer, size_t len)
+{
+	int ret;
+
+	ret = apple_smc_acpi_port_valid(smc);
+	if (ret)
+		return ret;
+
+	if (apple_smc_acpi_port_write_cmd(smc, cmd) || apple_smc_acpi_port_write_key(smc, key)) {
+		dev_dbg(smc->dev, "port/read: read argument failed, key: 0x%X, cmd: 0x%X\n",
+				key, cmd);
+		return -EIO;
+	}
+
+	if (apple_smc_acpi_port_write_byte(smc, len)) {
+		dev_dbg(smc->dev, "port/read: read len failed, key: 0x%X, len: 0x%zX\n", key, len);
+		return -EIO;
+	}
+
+	for (ret = 0; ret < len; ret++) {
+		if (apple_smc_acpi_port_wait(smc,
+				SMC_IO_STATUS_AWAITING_DATA | SMC_IO_STATUS_BUSY,
+				SMC_IO_STATUS_AWAITING_DATA | SMC_IO_STATUS_BUSY)) {
+			dev_dbg(smc->dev, "port/read: read failed, key: 0x%X\n", key);
+			return -EIO;
+		}
+		buffer[ret] = inb(smc->port_base + SMC_IO_DATA_PORT);
+	}
+
+	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
+}
+
+static int apple_smc_acpi_port_write(struct apple_smc_acpi *smc, smc_key key, const u8 *buffer,
+		size_t len)
+{
+	int ret;
+
+	ret = apple_smc_acpi_port_valid(smc);
+	if (ret)
+		return ret;
+
+	if (apple_smc_acpi_port_write_cmd(smc, SMC_MSG_WRITE_KEY) ||
+			apple_smc_acpi_port_write_key(smc, key)) {
+		dev_dbg(smc->dev, "port/write: write argument failed, key: 0x%X\n", key);
+		return -EIO;
+	}
+
+	if (apple_smc_acpi_port_write_byte(smc, len)) {
+		dev_dbg(smc->dev, "port/write: write len failed, key: 0x%X, len: 0x%zX\n",
+				key, len);
+		return -EIO;
+	}
+
+	for (ret = 0; ret < len; ret++) {
+		if (apple_smc_acpi_port_write_byte(smc, buffer[ret])) {
+			dev_dbg(smc->dev, "port/write: write failed, key: 0x%X\n", key);
+			return -EIO;
+		}
+	}
+	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
+}
+
+static int apple_smc_acpi_port_get_key_info(struct apple_smc_acpi *smc,
+			smc_key key, struct apple_smc_key_info *info)
+{
+	u8 buf[6];
+
+	if (apple_smc_acpi_port_read(smc, SMC_MSG_GET_KEY_INFO, key, buf, sizeof(buf)))
+		return -EIO;
+
+	if (!info)
+		return 0;
+
+	info->size = buf[0];
+	info->type_code = get_unaligned_be32(&buf[1]);
+	info->flags = buf[5];
+
+	return 0;
+}
+
+static void apple_smc_acpi_mmio_clear(struct apple_smc_acpi *smc)
+{
+	if (ioread8(smc->iomem_base + SMC_MMIO_KEY_STATUS))
+		return iowrite8(0, smc->iomem_base + SMC_MMIO_KEY_STATUS);
+}
+
+static int apple_smc_acpi_mmio_wait(struct apple_smc_acpi *smc)
+{
+	u8 status;
+	int ret;
+
+	if (smc->interrupt_enabled) {
+		if (wait_for_completion_timeout(&smc->cmd_done,
+					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
+			return 0;
+
+		smc->interrupt_enabled = 0;
+		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
+	}
+
+	ret = read_poll_timeout(ioread8, status, status & SMC_MMIO_STATUS_DONE,
+				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
+				false, smc->iomem_base + SMC_MMIO_KEY_STATUS);
+	if (ret)
+		dev_dbg(smc->dev, "mmio/wait: timeout");
+
+	return ret;
+}
+
+static int apple_smc_acpi_mmio_result(struct apple_smc_acpi *smc, smc_key key)
+{
+	u8 status;
+
+	if (apple_smc_acpi_mmio_wait(smc))
+		return -EIO;
+
+	status = ioread8(smc->iomem_base + SMC_MMIO_KEY_CMD);
+	if (status) {
+		dev_dbg(smc->dev, "mmio: command failed, status: 0x%X, key: 0x%X\n",
+			status, key);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int apple_smc_acpi_mmio_read(struct apple_smc_acpi *smc, u8 cmd, smc_key key,
+		void *buffer, size_t len)
+{
+	int ret;
+
+	reinit_completion(&smc->cmd_done);
+	apple_smc_acpi_mmio_clear(smc);
+	iowrite32be(key, smc->iomem_base + SMC_MMIO_KEY_NAME);
+	iowrite8(0, smc->iomem_base + SMC_MMIO_KEY_SMC_ID);
+	iowrite8(cmd, smc->iomem_base + SMC_MMIO_KEY_CMD);
+
+	ret = apple_smc_acpi_mmio_result(smc, key);
+	if (ret)
+		return ret;
+
+	memcpy_fromio(buffer, smc->iomem_base + SMC_MMIO_KEY_DATA, len);
+	return 0;
+}
+
+static int apple_smc_acpi_mmio_write(struct apple_smc_acpi *smc, smc_key key, const void *buffer,
+		size_t len)
+{
+	reinit_completion(&smc->cmd_done);
+	apple_smc_acpi_mmio_clear(smc);
+	iowrite32be(key, smc->iomem_base + SMC_MMIO_KEY_NAME);
+	memcpy_toio(smc->iomem_base + SMC_MMIO_KEY_DATA, buffer, len);
+	iowrite8(len, smc->iomem_base + SMC_MMIO_KEY_DATA_LEN);
+	iowrite8(0, smc->iomem_base + SMC_MMIO_KEY_SMC_ID);
+	iowrite8(SMC_MSG_WRITE_KEY, smc->iomem_base + SMC_MMIO_KEY_CMD);
+
+	return apple_smc_acpi_mmio_result(smc, key);
+}
+
+static int apple_smc_acpi_mmio_get_key_info(struct apple_smc_acpi *smc, smc_key key,
+					struct apple_smc_key_info *info)
+{
+	int ret;
+
+	reinit_completion(&smc->cmd_done);
+	apple_smc_acpi_mmio_clear(smc);
+	iowrite32be(key, smc->iomem_base + SMC_MMIO_KEY_NAME);
+	iowrite8(0, smc->iomem_base + SMC_MMIO_KEY_SMC_ID);
+	iowrite8(SMC_MSG_GET_KEY_INFO, smc->iomem_base + SMC_MMIO_KEY_CMD);
+	ret = apple_smc_acpi_mmio_result(smc, key);
+	if (ret)
+		return ret;
+
+	if (!info)
+		return 0;
+
+	info->type_code = cpu_to_be32(ioread32(smc->iomem_base + SMC_MMIO_KEY_DATA));
+	info->size = ioread8(smc->iomem_base + SMC_MMIO_KEY_INFO_SIZE);
+	info->flags = ioread8(smc->iomem_base + SMC_MMIO_KEY_INFO_FLAGS);
+
+	return 0;
+}
+
+static void apple_smc_acpi_shutdown_work(struct work_struct *work)
+{
+	orderly_poweroff(true);
+}
+
+static void apple_smc_acpi_notifier_work(struct work_struct *work)
+{
+	struct apple_smc_acpi *smc =
+		container_of(work, struct apple_smc_acpi, notifier_work);
+
+	u8 event;
+
+	for (;;) {
+		scoped_guard(spinlock_irqsave, &smc->event_lock) {
+			if (!kfifo_get(&smc->event_fifo, &event))
+				return;
+		}
+
+		blocking_notifier_call_chain(&smc->event_handlers, event, NULL);
+	}
+}
+
+static irqreturn_t apple_smc_acpi_irq(int irq, void *data)
+{
+	struct apple_smc_acpi *smc = data;
+	u8 status, int_id;
+
+	if (smc->is_mmio) {
+		status = ioread8(smc->iomem_base + SMC_MMIO_KEY_INTERRUPT_STATUS);
+		if (!(status & SMC_MMIO_IRQ_PENDING) && status)
+			return IRQ_NONE;
+	} else {
+		status = inb(smc->port_base + SMC_IO_CMD_PORT);
+		if (!(status & SMC_IO_STATUS_IRQ_PENDING) && status)
+			return IRQ_NONE;
+	}
+
+	int_id = inb(smc->port_base + SMC_IO_INT_ID_PORT);
+	switch (int_id) {
+	case SMC_INT_CMD_DONE:
+		complete(&smc->cmd_done);
+		break;
+	case SMC_INT_SHUTDOWN:
+		schedule_work(&smc->shutdown_work);
+		break;
+	case SMC_INT_BRIDGEOS_CRASH:
+		dev_crit(smc->dev, "BridgeOS Crashed!!!\n");
+		break;
+	case SMC_INT_ALS_CHANGE:
+	case SMC_INT_THERMAL_LEVEL:
+	case SMC_INT_PLATFORM_FUNCTION:
+	case SMC_INT_SMS_DROP:
+	case SMC_INT_SMS_ORIENTATION:
+	case SMC_INT_SMS_SHOCK:
+	case SMC_INT_PLIMIT_CHANGED:
+		scoped_guard(spinlock_irqsave, &smc->event_lock) {
+			if (!kfifo_put(&smc->event_fifo, int_id))
+				dev_warn_ratelimited(smc->dev, "Notification lost: %u\n",
+						     int_id);
+		}
+
+		schedule_work(&smc->notifier_work);
+		break;
+	}
+
+	return IRQ_HANDLED;
+}
+
+static acpi_status apple_smc_acpi_walk_resources(struct acpi_resource *res, void *data)
+{
+	struct apple_smc_acpi *smc = data;
+
+	switch (res->type) {
+	case ACPI_RESOURCE_TYPE_IO:
+		if (!smc->has_port) {
+			if (res->data.io.address_length < SMC_IO_NR_PORTS)
+				return AE_ERROR;
+			smc->port_base = res->data.io.minimum;
+			smc->has_port = true;
+		}
+		return AE_OK;
+
+	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+		if (!smc->is_mmio) {
+			if (res->data.fixed_memory32.address_length < SMC_MMIO_MIN_SIZE) {
+				dev_dbg(smc->dev, "found mmio support but its too small: %u\n",
+					res->data.fixed_memory32.address_length);
+				return AE_OK;
+			}
+			smc->iomem_base_addr = res->data.fixed_memory32.address;
+			smc->iomem_base_size = res->data.fixed_memory32.address_length;
+			smc->is_mmio = true;
+		}
+		return AE_OK;
+
+	case ACPI_RESOURCE_TYPE_IRQ:
+		smc->irq = res->data.irq.interrupts[0];
+		return AE_OK;
+
+	case ACPI_RESOURCE_TYPE_END_TAG:
+		if (!smc->has_port)
+			return AE_NOT_FOUND;
+
+		return AE_OK;
+
+	default:
+		return AE_OK;
+	}
+}
+
+static void apple_smc_acpi_try_enable_mmio(struct apple_smc_acpi *smc)
+{
+	u8 ldkn;
+
+	if (!smc->is_mmio)
+		return;
+
+	smc->iomem_base = devm_ioremap(smc->dev, smc->iomem_base_addr,
+					smc->iomem_base_size);
+	if (!smc->iomem_base)
+		goto out;
+
+	if (ioread8(smc->iomem_base + SMC_MMIO_KEY_STATUS) == 0xFF) {
+		dev_dbg(smc->dev, "mmio enable failed: init status is 0xff\n");
+		goto out_iomem;
+	}
+
+	if (apple_smc_acpi_mmio_read(smc, SMC_MSG_READ_KEY, SMC_KEY(LDKN), &ldkn,
+				     sizeof(ldkn))) {
+		dev_dbg(smc->dev, "mmio enable failed: ldkn read failed\n");
+		goto out_iomem;
+	}
+
+	if (ldkn < 2) {
+		dev_dbg(smc->dev, "mmio enable failed: ldkn version less than 2\n");
+		goto out_iomem;
+	}
+	return;
+
+out_iomem:
+	devm_iounmap(smc->dev, smc->iomem_base);
+	smc->iomem_base = NULL;
+out:
+	smc->is_mmio = false;
+}
+
+static void apple_smc_acpi_try_enable_interrupts(struct apple_smc_acpi *smc)
+{
+	const u8 enable = 1;
+	int ret;
+
+	if (!smc->has_interrupt)
+		return;
+
+	if (smc->is_mmio)
+		ret = apple_smc_acpi_mmio_write(smc, SMC_KEY(NTOK), &enable, sizeof(enable));
+	else
+		ret = apple_smc_acpi_port_write(smc, SMC_KEY(NTOK), &enable, sizeof(enable));
+
+	if (ret < 0) {
+		dev_dbg(smc->dev, "Unable to enable interrupts\n");
+		smc->interrupt_enabled = 0;
+		return;
+	}
+
+	smc->interrupt_enabled = 1;
+}
+
+static int apple_smc_acpi_read(void *cookie, smc_key key, void *buf, size_t size)
+{
+	struct apple_smc_acpi *smc = cookie;
+	int ret;
+
+	if (smc->is_mmio)
+		ret = apple_smc_acpi_mmio_read(smc, SMC_MSG_READ_KEY,
+			key, buf, size);
+	else
+		ret = apple_smc_acpi_port_read(smc, SMC_MSG_READ_KEY,
+			key, buf, size);
+
+	if (ret < 0)
+		return ret;
+
+	return size;
+
+}
+
+static int apple_smc_acpi_write(void *cookie, smc_key key, const void *buf, size_t size)
+{
+	struct apple_smc_acpi *smc = cookie;
+	int ret;
+
+	if (smc->is_mmio)
+		ret = apple_smc_acpi_mmio_write(smc, key, buf, size);
+	else
+		ret = apple_smc_acpi_port_write(smc, key, buf, size);
+
+	if (ret < 0)
+		return ret;
+
+	return size;
+}
+
+static int apple_smc_acpi_get_key_by_index(void *cookie, int index, smc_key *key)
+{
+	struct apple_smc_acpi *smc = cookie;
+
+	if (smc->is_mmio)
+		return apple_smc_acpi_mmio_read(smc, SMC_MSG_GET_KEY_BY_INDEX, (smc_key) index,
+				key, 4);
+	else
+		return apple_smc_acpi_port_read(smc, SMC_MSG_GET_KEY_BY_INDEX, (smc_key) index,
+				(u8 *)key, 4);
+
+}
+
+static int apple_smc_acpi_get_key_info(void *cookie, smc_key key,
+		struct apple_smc_key_info *info)
+{
+	struct apple_smc_acpi *smc = cookie;
+
+	if (smc->is_mmio)
+		return apple_smc_acpi_mmio_get_key_info(smc, key, info);
+	else
+		return apple_smc_acpi_port_get_key_info(smc, key, info);
+
+}
+
+static void apple_smc_acpi_notifications(void *cookie)
+{
+	const u8 buf = 0;
+
+	apple_smc_acpi_write(cookie, SMC_KEY(NTOK), &buf, sizeof(buf));
+}
+
+static const struct apple_smc_backend_ops apple_smc_acpi_be_ops = {
+	.read = apple_smc_acpi_read,
+	.write = apple_smc_acpi_write,
+	.get_key_by_index = apple_smc_acpi_get_key_by_index,
+	.get_key_info = apple_smc_acpi_get_key_info,
+	.disable_notifications = apple_smc_acpi_notifications,
+};
+
+static ssize_t plimit_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct apple_smc *smc = dev_get_drvdata(dev);
+	struct apple_smc_acpi *smc_acpi = smc->be_cookie;
+
+	return sysfs_emit(buf, "%08x %02x\n",
+			inl(smc_acpi->port_base + SMC_IO_INT_PLIMIT),
+			inb(smc_acpi->port_base + SMC_IO_INT_PLIMIT_GPU));
+}
+static DEVICE_ATTR_RO(plimit);
+
+static struct attribute *apple_smc_acpi_attrs[] = {
+	&dev_attr_plimit.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(apple_smc_acpi);
+
+static int apple_smc_acpi_probe(struct platform_device *pdev)
+{
+	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
+	struct apple_smc_acpi *smc;
+	acpi_status status;
+	int ret;
+
+	smc = devm_kzalloc(&pdev->dev, sizeof(*smc), GFP_KERNEL);
+	if (!smc)
+		return -ENOMEM;
+
+	smc->dev = &pdev->dev;
+	init_completion(&smc->cmd_done);
+	status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
+				apple_smc_acpi_walk_resources, smc);
+
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	if (!devm_request_region(smc->dev, smc->port_base, SMC_IO_NR_PORTS, "macsmc-acpi"))
+		return -EBUSY;
+
+	apple_smc_acpi_try_enable_mmio(smc);
+	BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
+	spin_lock_init(&smc->event_lock);
+	INIT_KFIFO(smc->event_fifo);
+
+	ret = devm_work_autocancel(smc->dev, &smc->shutdown_work,
+				   apple_smc_acpi_shutdown_work);
+	if (ret)
+		return ret;
+
+	ret = devm_work_autocancel(smc->dev, &smc->notifier_work,
+				   apple_smc_acpi_notifier_work);
+	if (ret)
+		return ret;
+
+	if (smc->irq) {
+		ret = devm_request_irq(smc->dev, smc->irq, apple_smc_acpi_irq,
+				       0, "macsmc-acpi", smc);
+		if (ret < 0)
+			dev_dbg(smc->dev, "Unable to register interrupts\n");
+		smc->has_interrupt = !ret;
+	}
+	apple_smc_acpi_try_enable_interrupts(smc);
+
+	return apple_smc_probe(smc->dev, &apple_smc_acpi_be_ops, smc, &smc->event_handlers, true);
+}
+
+static int apple_smc_acpi_resume(struct device *dev)
+{
+	struct apple_smc *smc = dev_get_drvdata(dev);
+	struct apple_smc_acpi *smc_acpi = smc->be_cookie;
+
+	/* NTOK may be set to 0 on resume */
+	if (smc_acpi->interrupt_enabled) {
+		mutex_lock(&smc->mutex);
+		smc_acpi->interrupt_enabled = 0;
+		apple_smc_acpi_try_enable_interrupts(smc_acpi);
+		mutex_unlock(&smc->mutex);
+	}
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(apple_smc_acpi_ops, NULL, apple_smc_acpi_resume);
+
+static const struct acpi_device_id apple_smc_acpi_ids[] = {
+	{"APP0001", 0},
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, apple_smc_acpi_ids);
+
+static struct platform_driver apple_smc_acpi_driver = {
+	.probe = apple_smc_acpi_probe,
+	.driver = {
+		.name = "macsmc-acpi",
+		.acpi_match_table = apple_smc_acpi_ids,
+		.pm = pm_sleep_ptr(&apple_smc_acpi_ops),
+		.dev_groups = apple_smc_acpi_groups,
+	},
+};
+module_platform_driver(apple_smc_acpi_driver);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC ACPI backend");
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 03/14] watchdog: add driver for apple smc
  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 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 13:48   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Add a watchdog driver for the SMC on Intel Macs. It can
reset the machine if the system stops responding. It works
on both newer and older SMC versions.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/mfd/macsmc-core.c     |  11 +++
 drivers/watchdog/Kconfig      |  11 +++
 drivers/watchdog/Makefile     |   1 +
 drivers/watchdog/macsmc_wdt.c | 158 ++++++++++++++++++++++++++++++++++
 4 files changed, 181 insertions(+)
 create mode 100644 drivers/watchdog/macsmc_wdt.c

diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
index b8905c834..1c1469828 100644
--- a/drivers/mfd/macsmc-core.c
+++ b/drivers/mfd/macsmc-core.c
@@ -33,6 +33,10 @@ static const struct mfd_cell apple_smc_acpi_rtc[] = {
 	MFD_CELL_NAME("macsmc-rtc"),
 };
 
+static const struct mfd_cell apple_smc_acpi_wdt[] = {
+	MFD_CELL_NAME("macsmc-wdt"),
+};
+
 int apple_smc_read(struct apple_smc *smc, smc_key key, void *buf, size_t size)
 {
 	guard(mutex)(&smc->mutex);
@@ -147,6 +151,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 				return ret;
 		}
 
+		if (apple_smc_key_exists(smc, SMC_KEY(NATJ))) {
+			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_wdt,
+				ARRAY_SIZE(apple_smc_acpi_wdt), NULL, 0, NULL);
+			if (ret < 0)
+				return ret;
+		}
+
 	} else
 		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
 			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index f7d0a0c2c..d80949bff 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1517,6 +1517,17 @@ config KEMPLD_WDT
 	  This driver can also be built as a module. If so, the module will be
 	  called kempld_wdt.
 
+config MACSMC_WDT
+	tristate "Apple SMC Watchdog"
+	depends on X86 && MACSMC_ACPI
+	select WATCHDOG_CORE
+	help
+	  This driver adds support for the watchdog in Intel Macs using
+	  the Apple SMC.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called macsmc_wdt.
+
 config SC1200_WDT
 	tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog"
 	depends on (X86 || COMPILE_TEST) && HAS_IOPORT
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 9ac406677..275e6aad8 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -134,6 +134,7 @@ obj-$(CONFIG_IT8712F_WDT) += it8712f_wdt.o
 obj-$(CONFIG_IT87_WDT) += it87_wdt.o
 obj-$(CONFIG_HP_WATCHDOG) += hpwdt.o
 obj-$(CONFIG_KEMPLD_WDT) += kempld_wdt.o
+obj-$(CONFIG_MACSMC_WDT) += macsmc_wdt.o
 obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
 obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
 obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o
diff --git a/drivers/watchdog/macsmc_wdt.c b/drivers/watchdog/macsmc_wdt.c
new file mode 100644
index 000000000..e2fc7f4e3
--- /dev/null
+++ b/drivers/watchdog/macsmc_wdt.c
@@ -0,0 +1,158 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * Apple SMC Watchdog Driver
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ */
+
+#include <linux/mfd/macsmc.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int timeout = WATCHDOG_TIMEOUT; /* in secounds */
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout,
+		 "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
+		 __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
+
+struct macsmc_wdt {
+	struct watchdog_device wdd;
+	struct apple_smc *smc;
+	bool has_oswd; /* Newer version of watchdogs in macsmc */
+};
+
+static int macsmc_wdt_write_timeout(struct macsmc_wdt *drv, unsigned int timeout)
+{
+	int ret;
+
+	if (drv->has_oswd) {
+		ret = apple_smc_write_u16(drv->smc, SMC_KEY(OSWD), (u16)(timeout << 8));
+		if (ret < 0)
+			return ret;
+	} else {
+		/*
+		 * NATJ = 2, makes the watchdog do force restart if NATi == 0
+		 * NATJ = 0, makes the watchdog do nothing if NATi == 0
+		 */
+		if (timeout == 0) {
+			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 0);
+			if (ret < 0)
+				return ret;
+		}
+		ret = apple_smc_write_u16(drv->smc, SMC_KEY(NATi), (u16)(timeout << 8));
+		if (ret < 0)
+			return ret;
+
+		if (timeout != 0) {
+			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 2);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int macsmc_wdt_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
+{
+	struct macsmc_wdt *drv = watchdog_get_drvdata(wdd);
+	int ret;
+
+	if (watchdog_active(wdd)) {
+		ret = macsmc_wdt_write_timeout(drv, timeout);
+		if (ret)
+			return ret;
+	}
+
+	wdd->timeout = timeout;
+
+	return 0;
+}
+
+static int macsmc_wdt_start(struct watchdog_device *wdd)
+{
+	return macsmc_wdt_write_timeout(watchdog_get_drvdata(wdd), wdd->timeout);
+}
+
+static int macsmc_wdt_stop(struct watchdog_device *wdd)
+{
+	return macsmc_wdt_write_timeout(watchdog_get_drvdata(wdd), 0);
+}
+
+static int macsmc_wdt_ping(struct watchdog_device *wdd)
+{
+	struct macsmc_wdt *drv = watchdog_get_drvdata(wdd);
+	int ret;
+
+	if (drv->has_oswd)
+		ret = apple_smc_write_u16(drv->smc, SMC_KEY(OSWD), (u16)(wdd->timeout << 8));
+	else
+		ret = apple_smc_write_u16(drv->smc, SMC_KEY(NATi), (u16)(wdd->timeout << 8));
+
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static const struct watchdog_ops macsmc_wdt_ops = {
+	.owner =	THIS_MODULE,
+	.start =	macsmc_wdt_start,
+	.stop  =	macsmc_wdt_stop,
+	.set_timeout =	macsmc_wdt_set_timeout,
+	.ping =	macsmc_wdt_ping,
+};
+
+static const struct watchdog_info macsmc_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "Macsmc Watchdog timer",
+};
+
+static int macsmc_wdt_probe(struct platform_device *pdev)
+{
+	struct macsmc_wdt *drv;
+
+	drv = devm_kzalloc(&pdev->dev, sizeof(struct macsmc_wdt), GFP_KERNEL);
+	if (!drv)
+		return -ENOMEM;
+
+	drv->smc = dev_get_drvdata(pdev->dev.parent);
+	if (apple_smc_key_exists(drv->smc, SMC_KEY(OSWD)))
+		drv->has_oswd = true;
+	else
+		drv->has_oswd = false;
+
+	drv->wdd.parent = &pdev->dev;
+	drv->wdd.ops = &macsmc_wdt_ops;
+	drv->wdd.info = &macsmc_wdt_info;
+	drv->wdd.min_timeout = 1;
+	drv->wdd.max_timeout = 255;
+	drv->wdd.timeout = WATCHDOG_TIMEOUT;
+	watchdog_init_timeout(&drv->wdd, timeout, &pdev->dev);
+	watchdog_set_nowayout(&drv->wdd, nowayout);
+	watchdog_stop_on_reboot(&drv->wdd);
+	watchdog_stop_on_unregister(&drv->wdd);
+	watchdog_set_drvdata(&drv->wdd, drv);
+
+	return devm_watchdog_register_device(&pdev->dev, &drv->wdd);
+}
+
+static struct platform_driver macsmc_wdt_driver = {
+	.probe = macsmc_wdt_probe,
+	.driver = {
+		.name = "macsmc-wdt",
+	},
+};
+module_platform_driver(macsmc_wdt_driver);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC Watchdog Driver");
+MODULE_ALIAS("platform:macsmc-wdt");
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 04/14] iio/light: add new driver for macsmc
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (2 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 13:47   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

Add a driver for the ambient light sensors, exposed through
the standard IIO interface with left and right channels.

This replaces the light sensor support in applesmc.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/iio/light/Kconfig        |  11 ++
 drivers/iio/light/Makefile       |   1 +
 drivers/iio/light/macsmc-light.c | 209 +++++++++++++++++++++++++++++++
 drivers/mfd/macsmc-core.c        |  11 ++
 4 files changed, 232 insertions(+)
 create mode 100644 drivers/iio/light/macsmc-light.c

diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 462fff1dd..f84707edc 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -457,6 +457,17 @@ config LV0104CS
 	  To compile this driver as a module, choose M here:
 	  the module will be called lv0104cs.
 
+config MACSMC_LIGHT
+	tristate "Apple SMC Light Sensor"
+	depends on MACSMC_ACPI
+	help
+	  Say Y here if you have a Intel-based Mac. and you
+	  want support for light sensors.
+
+	  To compile this driver as a module, choose M here:
+	  the module will be called macsmc_light
+
+
 config MAX44000
 	tristate "MAX44000 Ambient and Infrared Proximity Sensor"
 	depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 6672ed01a..2ef4c054d 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_LTR390)		+= ltr390.o
 obj-$(CONFIG_LTR501)		+= ltr501.o
 obj-$(CONFIG_LTRF216A)		+= ltrf216a.o
 obj-$(CONFIG_LV0104CS)		+= lv0104cs.o
+obj-$(CONFIG_MACSMC_LIGHT)	+= macsmc-light.o
 obj-$(CONFIG_MAX44000)		+= max44000.o
 obj-$(CONFIG_MAX44009)		+= max44009.o
 obj-$(CONFIG_NOA1305)		+= noa1305.o
diff --git a/drivers/iio/light/macsmc-light.c b/drivers/iio/light/macsmc-light.c
new file mode 100644
index 000000000..12d88035a
--- /dev/null
+++ b/drivers/iio/light/macsmc-light.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * Apple SMC Light Sensor Driver
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ *
+ * Based on drivers/hwmom/applesmc.c:
+ * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ */
+
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+enum {
+	LEFT_LIGHT = 0,
+	RIGHT_LIGHT,
+};
+
+struct macsmc_light {
+	struct apple_smc *smc;
+	struct notifier_block nb;
+	struct iio_dev *indio_dev;
+	u8 size;		/* length of the ALV0 key, ALV1 has the same */
+	bool single_sensor;	/* one combined 10-bit value instead of ALV0 + ALV1 */
+};
+
+static int macsmc_light_read_raw(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan,
+		int *val, int *val2, long mask)
+
+{
+	struct macsmc_light *drv = iio_priv(indio_dev);
+	u8 buffer[10];
+	int ret;
+
+	if (mask != IIO_CHAN_INFO_RAW)
+		return -EINVAL;
+
+	switch (chan->channel) {
+	case LEFT_LIGHT:
+		ret = apple_smc_read(drv->smc, SMC_KEY(ALV0), buffer, drv->size);
+		if (ret < 0)
+			return ret;
+
+		if (drv->single_sensor)
+			*val = get_unaligned_be16(buffer + 6) >> 2;
+		else
+			*val = buffer[2];
+
+		break;
+	case RIGHT_LIGHT:
+		if (drv->single_sensor) {
+			*val = 0;
+			break;
+		}
+		ret = apple_smc_read(drv->smc, SMC_KEY(ALV1), buffer, drv->size);
+		if (ret < 0)
+			return ret;
+
+		*val = buffer[2];
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return IIO_VAL_INT;
+}
+
+static int macsmc_light_event(struct notifier_block *nb, unsigned long event, void *data)
+{
+	struct macsmc_light *drv = container_of(nb, struct macsmc_light, nb);
+	struct iio_dev *indio_dev = drv->indio_dev;
+	s64 timestamp = iio_get_time_ns(indio_dev);
+
+	/* check if event is for us */
+	if (event != SMC_INT_ALS_CHANGE)
+		return NOTIFY_DONE;
+
+	iio_push_event(indio_dev,
+		       IIO_UNMOD_EVENT_CODE(IIO_LIGHT, LEFT_LIGHT,
+					    IIO_EV_TYPE_CHANGE,
+					    IIO_EV_DIR_EITHER),
+		       timestamp);
+
+	if (!drv->single_sensor) {
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_LIGHT, RIGHT_LIGHT,
+						    IIO_EV_TYPE_CHANGE,
+						    IIO_EV_DIR_EITHER),
+			       timestamp);
+	}
+
+	return NOTIFY_OK;
+}
+
+static void macsmc_light_unregister_notifier(void *data)
+{
+	struct macsmc_light *drv = data;
+
+	blocking_notifier_chain_unregister(drv->smc->event_handlers,
+					   &drv->nb);
+}
+
+static const struct iio_event_spec macsmc_light_events[] = {
+	{
+		.type = IIO_EV_TYPE_CHANGE,
+		.dir = IIO_EV_DIR_EITHER,
+	},
+};
+
+static const struct iio_chan_spec macsmc_light_channels[] = {
+	{
+		.type = IIO_LIGHT,
+		.channel = LEFT_LIGHT,
+		.indexed = 1,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.event_spec = macsmc_light_events,
+		.num_event_specs = ARRAY_SIZE(macsmc_light_events),
+	},
+	{
+		.type = IIO_LIGHT,
+		.channel = RIGHT_LIGHT,
+		.indexed = 1,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.event_spec = macsmc_light_events,
+		.num_event_specs = ARRAY_SIZE(macsmc_light_events),
+	},
+};
+
+static int macsmc_light_read_label(struct iio_dev *indio_dev,
+				   const struct iio_chan_spec *chan, char *label)
+{
+	return sysfs_emit(label, "%s\n", chan->channel == LEFT_LIGHT ? "left" : "right");
+}
+
+static const struct iio_info macsmc_light_info = {
+	.read_raw = macsmc_light_read_raw,
+	.read_label = macsmc_light_read_label,
+};
+
+static int macsmc_light_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct iio_dev *indio_dev;
+	struct macsmc_light *drv;
+	struct apple_smc_key_info info;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*drv));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	drv = iio_priv(indio_dev);
+	drv->smc = dev_get_drvdata(dev->parent);
+
+	ret = apple_smc_get_key_info(drv->smc, SMC_KEY(ALV0), &info);
+	if (ret < 0)
+		return -ENODEV;
+
+	if (info.size < 3 || info.size > 10)
+		return -ENODEV;
+
+	drv->size = info.size;
+	drv->single_sensor = info.size == 10;
+	drv->indio_dev = indio_dev;
+	drv->nb.notifier_call = macsmc_light_event;
+	ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, macsmc_light_unregister_notifier, drv);
+	if (ret)
+		return ret;
+
+	indio_dev->name = "macsmc-light";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &macsmc_light_info;
+	indio_dev->channels = macsmc_light_channels;
+	indio_dev->num_channels = ARRAY_SIZE(macsmc_light_channels);
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static struct platform_driver macsmc_light_driver = {
+	.probe = macsmc_light_probe,
+	.driver = {
+		.name = "macsmc-light",
+	},
+};
+module_platform_driver(macsmc_light_driver);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC Light Sensor Driver");
+MODULE_ALIAS("platform:macsmc-light");
diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
index 1c1469828..6014df4fe 100644
--- a/drivers/mfd/macsmc-core.c
+++ b/drivers/mfd/macsmc-core.c
@@ -29,6 +29,10 @@ static const struct mfd_cell apple_smc_acpi_common[] = {
 	MFD_CELL_NAME("macsmc-power"),
 };
 
+static const struct mfd_cell apple_smc_acpi_light[] = {
+	MFD_CELL_NAME("macsmc-light"),
+};
+
 static const struct mfd_cell apple_smc_acpi_rtc[] = {
 	MFD_CELL_NAME("macsmc-rtc"),
 };
@@ -158,6 +162,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 				return ret;
 		}
 
+		if (apple_smc_key_exists(smc, SMC_KEY(ALV0))) {
+			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_light,
+				ARRAY_SIZE(apple_smc_acpi_light), NULL, 0, NULL);
+			if (ret < 0)
+				return ret;
+		}
+
 	} else
 		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
 			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 05/14] iio/accel: add driver for apple SMS
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (3 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:11   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Add a driver for the Sudden Motion Sensor accelerometer,
exposed through IIO. It reports the three axes and also
drop, orientation and shock events.

This replaces the motion sensor support in applesmc.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/iio/accel/Kconfig        |  10 ++
 drivers/iio/accel/Makefile       |   1 +
 drivers/iio/accel/macsmc-accel.c | 260 +++++++++++++++++++++++++++++++
 drivers/mfd/macsmc-core.c        |  10 ++
 4 files changed, 281 insertions(+)
 create mode 100644 drivers/iio/accel/macsmc-accel.c

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 141ac9842..50bc127a4 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -532,6 +532,16 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MACSMC_ACCEL
+	tristate "Apple SMC Motion Sensor Driver"
+	depends on MACSMC_ACPI
+	help
+	  Say yes here if you want support for Apple Motion Sensors, that uses
+	  the System Management Controller.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called macsmc-accel.
+
 config MC3230
 	tristate "mCube MC3230 Digital Accelerometer Driver"
 	depends on I2C
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index fa440a859..52fe661de 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -54,6 +54,7 @@ obj-$(CONFIG_KXSD9)	+= kxsd9.o
 obj-$(CONFIG_KXSD9_SPI)	+= kxsd9-spi.o
 obj-$(CONFIG_KXSD9_I2C)	+= kxsd9-i2c.o
 obj-$(CONFIG_MC3230)	+= mc3230.o
+obj-$(CONFIG_MACSMC_ACCEL)	+= macsmc-accel.o
 
 obj-$(CONFIG_MMA7455)		+= mma7455_core.o
 obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
diff --git a/drivers/iio/accel/macsmc-accel.c b/drivers/iio/accel/macsmc-accel.c
new file mode 100644
index 000000000..79891fd13
--- /dev/null
+++ b/drivers/iio/accel/macsmc-accel.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC sudden motion sensor (SMS) driver
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ *
+ * Based on drivers/hwmon/applesmc.c:
+ * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ */
+
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/container_of.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/types.h>
+#include <linux/byteorder/generic.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+struct macsmc_accel {
+	struct apple_smc *smc;
+	struct iio_dev *indio_dev;
+	struct notifier_block nb;
+};
+
+static int macsmc_accel_read(struct macsmc_accel *drv, smc_key key, s16 *p)
+{
+	int ret;
+
+	ret = apple_smc_read_s16(drv->smc, key, p);
+	if (ret < 0)
+		return ret;
+
+	*p = (s16)be16_to_cpu(*p);
+	return 0;
+}
+
+static int macsmc_accel_dev_init(struct macsmc_accel *drv)
+{
+	int ret, total;
+	u16 buf, write_value;
+
+	ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
+	if (ret < 0)
+		return ret;
+
+	/* 0xE0 enables the interrupts and the actual motion sensors */
+	write_value = buf | 0xE0;
+
+	for (total = 0; total < 100; total++) {
+		ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
+		if (!ret && (buf & 0xE0) == 0xE0)
+			return 0;
+
+		apple_smc_write_u16(drv->smc, SMC_KEY(MOCN), write_value);
+		msleep(50);
+	}
+
+	return -ENODEV;
+}
+
+static int macsmc_accel_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+		int *val, int *val2, long mask)
+{
+	struct macsmc_accel *drv = iio_priv(indio_dev);
+	smc_key key;
+	int ret;
+	s16 buf;
+
+	if (mask != IIO_CHAN_INFO_RAW)
+		return -EINVAL;
+
+	switch (chan->channel2) {
+	case IIO_MOD_X:
+		key = SMC_KEY(MO_X);
+		break;
+	case IIO_MOD_Y:
+		key = SMC_KEY(MO_Y);
+		break;
+	case IIO_MOD_Z:
+		key = SMC_KEY(MO_Z);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = macsmc_accel_read(drv, key, &buf);
+	if (ret < 0)
+		return ret;
+
+	*val = buf;
+
+	return IIO_VAL_INT;
+}
+
+static int macsmc_accel_event(struct notifier_block *nb, unsigned long event, void *data)
+{
+	struct macsmc_accel *drv = container_of(nb, struct macsmc_accel, nb);
+	u64 code;
+
+	switch (event) {
+	case SMC_INT_SMS_DROP:
+		code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_AND_Y_AND_Z,
+					  IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING);
+		break;
+	case SMC_INT_SMS_ORIENTATION:
+		code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z,
+					  IIO_EV_TYPE_CHANGE, IIO_EV_DIR_NONE);
+		break;
+	case SMC_INT_SMS_SHOCK:
+		code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z,
+					  IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING);
+		break;
+	default:
+		return NOTIFY_DONE;
+	}
+
+	iio_push_event(drv->indio_dev, code, iio_get_time_ns(drv->indio_dev));
+	return NOTIFY_OK;
+}
+
+static void macsmc_accel_unregister_notifier(void *data)
+{
+	struct macsmc_accel *drv = data;
+
+	blocking_notifier_chain_unregister(drv->smc->event_handlers,
+					&drv->nb);
+}
+
+static const struct iio_event_spec macsmc_accel_drop_events[] = {
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_FALLING,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+};
+
+static const struct iio_event_spec macsmc_accel_any_axis_events[] = {
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_RISING,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+	{
+		.type = IIO_EV_TYPE_CHANGE,
+		.dir = IIO_EV_DIR_NONE,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+};
+
+static const struct iio_chan_spec macsmc_accel_channels[] = {
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_X,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_Y,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_Z,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_X_AND_Y_AND_Z,
+		.event_spec = macsmc_accel_drop_events,
+		.num_event_specs = ARRAY_SIZE(macsmc_accel_drop_events),
+	},
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_X_OR_Y_OR_Z,
+		.event_spec = macsmc_accel_any_axis_events,
+		.num_event_specs = ARRAY_SIZE(macsmc_accel_any_axis_events),
+	},
+};
+
+static const struct iio_info macsmc_accel_info = {
+	.read_raw = macsmc_accel_read_raw
+};
+
+static int macsmc_accel_restore(struct device *dev)
+{
+	struct macsmc_accel *drv = dev_get_drvdata(dev);
+
+	return macsmc_accel_dev_init(drv);
+}
+
+static const struct dev_pm_ops macsmc_accel_pm_ops = {
+	.restore = macsmc_accel_restore,
+};
+
+static int macsmc_accel_probe(struct platform_device *pdev)
+{
+	struct macsmc_accel *drv;
+	struct iio_dev *indio_dev;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*drv));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	drv = iio_priv(indio_dev);
+	drv->smc = dev_get_drvdata(pdev->dev.parent);
+
+	ret = macsmc_accel_dev_init(drv);
+	if (ret)
+		return ret;
+
+	drv->indio_dev = indio_dev;
+	drv->nb.notifier_call = macsmc_accel_event;
+	ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&pdev->dev, macsmc_accel_unregister_notifier, drv);
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(pdev, drv);
+
+	indio_dev->name = "macsmc-accel";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &macsmc_accel_info;
+	indio_dev->channels = macsmc_accel_channels;
+	indio_dev->num_channels = ARRAY_SIZE(macsmc_accel_channels);
+
+	return devm_iio_device_register(&pdev->dev, indio_dev);
+}
+
+static struct platform_driver macsmc_accel_driver = {
+	.probe = macsmc_accel_probe,
+	.driver = {
+		.name = "macsmc-accel",
+		.pm = pm_sleep_ptr(&macsmc_accel_pm_ops),
+	},
+};
+module_platform_driver(macsmc_accel_driver);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_DESCRIPTION("Apple SMC Motion Sensor Driver");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_ALIAS("platform:macsmc-accel");
diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
index 6014df4fe..6567d2f1f 100644
--- a/drivers/mfd/macsmc-core.c
+++ b/drivers/mfd/macsmc-core.c
@@ -24,6 +24,10 @@ static const struct mfd_cell apple_smc_rtkit_devs[] = {
  * There isn't device tree on acpi backend, so we need to use
  * apple_smc_key_exists to register mfd devs
  */
+static const struct mfd_cell apple_smc_acpi_accel[] = {
+	MFD_CELL_NAME("macsmc-accel"),
+};
+
 static const struct mfd_cell apple_smc_acpi_common[] = {
 	MFD_CELL_NAME("macsmc-hwmon"),
 	MFD_CELL_NAME("macsmc-power"),
@@ -169,6 +173,12 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 				return ret;
 		}
 
+		if (apple_smc_key_exists(smc, SMC_KEY(MOCN))) {
+			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_accel,
+				ARRAY_SIZE(apple_smc_acpi_accel), NULL, 0, NULL);
+			if (ret < 0)
+				return ret;
+		}
 	} else
 		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
 			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 06/14] leds: add support for macsmc kbl
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (4 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:07   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

Add a LED class driver to control the keyboard backlight.

This replaces the keyboard backlight support in applesmc.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/leds/Kconfig       | 11 +++++
 drivers/leds/Makefile      |  1 +
 drivers/leds/leds-macsmc.c | 91 ++++++++++++++++++++++++++++++++++++++
 drivers/mfd/macsmc-core.c  | 11 +++++
 4 files changed, 114 insertions(+)
 create mode 100644 drivers/leds/leds-macsmc.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 7ec2c8d78..30cd64d41 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -729,6 +729,17 @@ config LEDS_ADP5520
 	  To compile this driver as a module, choose M here: the module will
 	  be called leds-adp5520.
 
+config LEDS_MACSMC
+	tristate "Keyboard Backlight support for Intel-Macs"
+	depends on LEDS_CLASS
+	depends on MACSMC_ACPI
+	help
+	  This option enables support for the Keyboard backlight in
+	  Intel-Macs using macsmc.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called leds-macsmc.
+
 config LEDS_MAX5970
 	tristate "LED Support for Maxim 5970"
 	depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 4d4b08915..1ef8b970d 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_LEDS_LP8864)		+= leds-lp8864.o
 obj-$(CONFIG_LEDS_LT3593)		+= leds-lt3593.o
 obj-$(CONFIG_LEDS_LTC3208)		+= leds-ltc3208.o
 obj-$(CONFIG_LEDS_LTC3220)		+= leds-ltc3220.o
+obj-$(CONFIG_LEDS_MACSMC)		+= leds-macsmc.o
 obj-$(CONFIG_LEDS_MAX5970)		+= leds-max5970.o
 obj-$(CONFIG_LEDS_MAX77650)		+= leds-max77650.o
 obj-$(CONFIG_LEDS_MAX77705)		+= leds-max77705.o
diff --git a/drivers/leds/leds-macsmc.c b/drivers/leds/leds-macsmc.c
new file mode 100644
index 000000000..095653765
--- /dev/null
+++ b/drivers/leds/leds-macsmc.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * Apple SMC Keyboard backlight driver
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ *
+ * Based on drivers/hwmon/applesmc.c
+ * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ *
+ */
+
+#include <linux/leds.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/platform_device.h>
+
+struct macsmc_led {
+	struct led_classdev cdev;
+	struct apple_smc *smc;
+	u8 brightness;
+};
+
+static enum led_brightness macsmc_led_get_brightness(struct led_classdev *cdev)
+{
+	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
+
+	return drv->brightness;
+}
+
+static int macsmc_led_set_brightness(struct led_classdev *cdev, enum led_brightness value)
+{
+	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
+	int ret;
+
+	ret = apple_smc_write_u16(drv->smc, SMC_KEY(LKSB), (u16) (value & 0xFF));
+	if (ret < 0)
+		return ret;
+
+	drv->brightness = value & 0xFF;
+
+	return 0;
+}
+
+static int macsmc_led_probe(struct platform_device *pdev)
+{
+	struct macsmc_led *drv;
+
+	drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
+	if (!drv)
+		return -ENOMEM;
+
+	drv->smc = dev_get_drvdata(pdev->dev.parent);
+
+	drv->cdev.name = "smc::kbd_backlight";
+	drv->cdev.max_brightness = 255;
+	drv->cdev.brightness_get = macsmc_led_get_brightness;
+	drv->cdev.brightness_set_blocking = macsmc_led_set_brightness;
+	drv->cdev.dev = &pdev->dev;
+
+	platform_set_drvdata(pdev, drv);
+
+	return devm_led_classdev_register(&pdev->dev, &drv->cdev);
+}
+
+static int macsmc_led_resume(struct device *dev)
+{
+	struct macsmc_led *drv = dev_get_drvdata(dev);
+	int ret;
+
+	ret = apple_smc_write_u16(drv->smc, SMC_KEY(LKSB), (u16) (drv->brightness));
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(macsmc_led_pm, NULL, macsmc_led_resume);
+
+static struct platform_driver macsmc_led_driver = {
+	.probe = macsmc_led_probe,
+	.driver = {
+		.name = "macsmc-led",
+		.pm = pm_sleep_ptr(&macsmc_led_pm),
+	},
+};
+module_platform_driver(macsmc_led_driver);
+
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
+MODULE_DESCRIPTION("LED keyboard backlight driver for Intel-macs using macsmc");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_ALIAS("platform:macsmc-led");
diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
index 6567d2f1f..bc4200f57 100644
--- a/drivers/mfd/macsmc-core.c
+++ b/drivers/mfd/macsmc-core.c
@@ -33,6 +33,10 @@ static const struct mfd_cell apple_smc_acpi_common[] = {
 	MFD_CELL_NAME("macsmc-power"),
 };
 
+static const struct mfd_cell apple_smc_acpi_led[] = {
+	MFD_CELL_NAME("macsmc-led"),
+};
+
 static const struct mfd_cell apple_smc_acpi_light[] = {
 	MFD_CELL_NAME("macsmc-light"),
 };
@@ -179,6 +183,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 			if (ret < 0)
 				return ret;
 		}
+
+		if (apple_smc_key_exists(smc, SMC_KEY(LKSB))) {
+			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_led,
+				ARRAY_SIZE(apple_smc_acpi_led), NULL, 0, NULL);
+			if (ret < 0)
+				return ret;
+		}
 	} else
 		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
 			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (5 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:12   ` Andy Shevchenko
  2026-12-04 14:16   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
                   ` (7 subsequent siblings)
  14 siblings, 2 replies; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Aditya Garg, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
work correctly on T2 Macs, so the clock from the SMC is
used instead.

On these machines the time offset is kept in the SMC instead
of NVMEM, and the clock rate is read from the SMC too.

Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/rtc/rtc-macsmc.c | 132 +++++++++++++++++++++++++++++++++------
 1 file changed, 112 insertions(+), 20 deletions(-)

diff --git a/drivers/rtc/rtc-macsmc.c b/drivers/rtc/rtc-macsmc.c
index 8fe883066..900a46339 100644
--- a/drivers/rtc/rtc-macsmc.c
+++ b/drivers/rtc/rtc-macsmc.c
@@ -2,9 +2,12 @@
 /*
  * Apple SMC RTC driver
  * Copyright The Asahi Linux Contributors
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
  */
 
 #include <linux/bitops.h>
+#include <linux/delay.h>
 #include <linux/mfd/macsmc.h>
 #include <linux/module.h>
 #include <linux/nvmem-consumer.h>
@@ -20,13 +23,54 @@
 /* 32768 Hz clock */
 #define RTC_SEC_SHIFT 15
 
+static bool force_clkm;
+module_param(force_clkm, bool, 0644);
+MODULE_PARM_DESC(force_clkm, "Force CLKM Key, instead of trying to use CLKL");
+
 struct macsmc_rtc {
 	struct device *dev;
 	struct apple_smc *smc;
 	struct rtc_device *rtc_dev;
 	struct nvmem_cell *rtc_offset;
+	uint8_t shift;
+	bool async_rtc;
 };
 
+static int macsmc_rtc_read_clkl(struct macsmc_rtc *rtc, u64 *ctr)
+{
+	u64 request = 0xffffffffffffULL;
+	u64 response = 0;
+	int i, j, ret;
+
+	for (i = 0; i < 4; i++) {
+		for (j = 0; j < 40; j++) {
+			ret = apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES);
+			if (ret == RTC_BYTES)
+				break;
+		}
+		if (ret != RTC_BYTES)
+			continue;
+
+		msleep(20);
+
+		for (j = 0; j < 20; j++) {
+			ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &response, RTC_BYTES);
+			if (ret == RTC_BYTES) {
+				if ((response & 0x7fff) == 5 || (response & 0x7fff) == 6)
+					return -EAGAIN;
+
+				if (response != 0xffffffffffffULL) {
+					*ctr = response;
+					return RTC_BYTES;
+				}
+			}
+			fsleep(1000);
+		}
+	}
+
+	return -EIO;
+}
+
 static int macsmc_rtc_get_time(struct device *dev, struct rtc_time *tm)
 {
 	struct macsmc_rtc *rtc = dev_get_drvdata(dev);
@@ -36,25 +80,36 @@ static int macsmc_rtc_get_time(struct device *dev, struct rtc_time *tm)
 	size_t len;
 	int ret;
 
-	ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
+	if (rtc->async_rtc && !force_clkm)
+		ret = macsmc_rtc_read_clkl(rtc, &ctr);
+	else
+		ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
+
 	if (ret < 0)
 		return ret;
 	if (ret != RTC_BYTES)
 		return -EIO;
 
-	p_off = nvmem_cell_read(rtc->rtc_offset, &len);
-	if (IS_ERR(p_off))
-		return PTR_ERR(p_off);
-	if (len < RTC_BYTES) {
+	if (rtc->smc->is_acpi) {
+		ret = apple_smc_read(rtc->smc, SMC_KEY(CLKO), &off, RTC_BYTES);
+		if (ret < 0)
+			return ret;
+		if (ret != RTC_BYTES)
+			return -EIO;
+	} else {
+		p_off = nvmem_cell_read(rtc->rtc_offset, &len);
+		if (IS_ERR(p_off))
+			return PTR_ERR(p_off);
+		if (len < RTC_BYTES) {
+			kfree(p_off);
+			return -EIO;
+		}
+
+		memcpy(&off, p_off, RTC_BYTES);
 		kfree(p_off);
-		return -EIO;
 	}
-
-	memcpy(&off, p_off, RTC_BYTES);
-	kfree(p_off);
-
 	/* Sign extend from 48 to 64 bits, then arithmetic shift right 15 bits to get seconds */
-	now = sign_extend64(ctr + off, RTC_BITS - 1) >> RTC_SEC_SHIFT;
+	now = sign_extend64(ctr + off, RTC_BITS - 1) >> rtc->shift;
 	rtc_time64_to_tm(now, tm);
 
 	return ret;
@@ -66,14 +121,26 @@ static int macsmc_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	u64 ctr = 0, off = 0;
 	int ret;
 
-	ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
+	if (rtc->async_rtc && !force_clkm)
+		ret = macsmc_rtc_read_clkl(rtc, &ctr);
+	else
+		ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
 	if (ret < 0)
 		return ret;
 	if (ret != RTC_BYTES)
 		return -EIO;
 
 	/* This sets the offset such that the set second begins now */
-	off = (rtc_tm_to_time64(tm) << RTC_SEC_SHIFT) - ctr;
+	off = (rtc_tm_to_time64(tm) << rtc->shift) - ctr;
+	if (rtc->smc->is_acpi) {
+		ret = apple_smc_write(rtc->smc, SMC_KEY(CLKO), &off, RTC_BYTES);
+		if (ret < 0)
+			return ret;
+		if (ret != RTC_BYTES)
+			return -EIO;
+
+		return 0;
+	}
 	return nvmem_cell_write(rtc->rtc_offset, &off, RTC_BYTES);
 }
 
@@ -86,13 +153,15 @@ static int macsmc_rtc_probe(struct platform_device *pdev)
 {
 	struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
 	struct macsmc_rtc *rtc;
+	int ret;
+	u32 clkr = 0xFFFFFFFF;
 
 	/*
 	 * MFD will probe this device even without a node in the device tree,
 	 * thus bail out early if the SMC on the current machines does not
 	 * support RTC and has no node in the device tree.
 	 */
-	if (!pdev->dev.of_node)
+	if (!pdev->dev.of_node && !smc->is_acpi)
 		return -ENODEV;
 
 	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
@@ -102,18 +171,40 @@ static int macsmc_rtc_probe(struct platform_device *pdev)
 	rtc->dev = &pdev->dev;
 	rtc->smc = smc;
 
-	rtc->rtc_offset = devm_nvmem_cell_get(&pdev->dev, "rtc_offset");
-	if (IS_ERR(rtc->rtc_offset))
-		return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_offset),
-				     "Failed to get rtc_offset NVMEM cell\n");
+	if (!rtc->smc->is_acpi) {
+		rtc->rtc_offset = devm_nvmem_cell_get(&pdev->dev, "rtc_offset");
+		if (IS_ERR(rtc->rtc_offset))
+			return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_offset),
+					     "Failed to get rtc_offset NVMEM cell\n");
+	}
+
+	if (rtc->smc->is_acpi) {
+		ret = apple_smc_read_u32(rtc->smc, SMC_KEY(CLKR), &clkr);
+		if (ret < 0 || clkr == 0xFFFFFFFF)
+			rtc->shift = RTC_SEC_SHIFT;
+		else
+			rtc->shift = ffs(clkr) - 1;
+
+		if (apple_smc_key_exists(rtc->smc, SMC_KEY(CLKL))) {
+			u64 clkl = 0xffffffffffffULL;
+
+			ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &clkl, RTC_BYTES);
+			if (ret == RTC_BYTES && clkl != 0xffffffffffffULL)
+				rtc->async_rtc = true;
+		}
+	} else
+		rtc->shift = RTC_SEC_SHIFT;
+
+	dev_info(&pdev->dev, "%u clock, using %s key\n", (clkr != 0xFFFFFFFF) ? clkr : 32768,
+				rtc->async_rtc ? "CLKL" : "CLKM");
 
 	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	rtc->rtc_dev->ops = &macsmc_rtc_ops;
-	rtc->rtc_dev->range_min = S64_MIN >> (RTC_SEC_SHIFT + (64 - RTC_BITS));
-	rtc->rtc_dev->range_max = S64_MAX >> (RTC_SEC_SHIFT + (64 - RTC_BITS));
+	rtc->rtc_dev->range_min = S64_MIN >> (rtc->shift + (64 - RTC_BITS));
+	rtc->rtc_dev->range_max = S64_MAX >> (rtc->shift + (64 - RTC_BITS));
 
 	platform_set_drvdata(pdev, rtc);
 
@@ -138,3 +229,4 @@ module_platform_driver(macsmc_rtc_driver);
 MODULE_LICENSE("Dual MIT/GPL");
 MODULE_DESCRIPTION("Apple SMC RTC driver");
 MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
+MODULE_ALIAS("platform:macsmc-rtc");
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (6 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:11   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Aditya Garg, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Add a flag to detect Apple T2 chips on Intel Macs.
Cache the result to avoid repeated checks. That will
be used in upcoming patches.

Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 arch/x86/kernel/quirks.c                      | 37 ++++++++++++++++++
 include/linux/platform_data/x86/apple.h       |  5 +++
 .../platform_certs/keyring_handler.h          |  8 ----
 security/integrity/platform_certs/load_uefi.c | 38 ++++---------------
 4 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c
index a92f18db9..6651e5d4d 100644
--- a/arch/x86/kernel/quirks.c
+++ b/arch/x86/kernel/quirks.c
@@ -664,8 +664,45 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras
 bool x86_apple_machine;
 EXPORT_SYMBOL(x86_apple_machine);
 
+bool has_apple_t2_chip;
+EXPORT_SYMBOL(has_apple_t2_chip);
+
+static const char * const __initconst apple_t2_models[] = {
+	"MacBookPro15,1",
+	"MacBookPro15,2",
+	"MacBookPro15,3",
+	"MacBookPro15,4",
+	"MacBookPro16,1",
+	"MacBookPro16,2",
+	"MacBookPro16,3",
+	"MacBookPro16,4",
+	"MacBookAir8,1",
+	"MacBookAir8,2",
+	"MacBookAir9,1",
+	"Macmini8,1",
+	"MacPro7,1",
+	"iMac20,1",
+	"iMac20,2",
+	"iMacPro1,1",
+};
+
 void __init early_platform_quirks(void)
 {
 	x86_apple_machine = dmi_match(DMI_SYS_VENDOR, "Apple Inc.") ||
 			    dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc.");
+
+	if (x86_apple_machine) {
+		const char *product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
+		int i;
+
+		if (!product_name)
+			return;
+
+		for (i = 0; i < ARRAY_SIZE(apple_t2_models); i++) {
+			if (!strcmp(product_name, apple_t2_models[i])) {
+				has_apple_t2_chip = true;
+				break;
+			}
+		}
+	}
 }
diff --git a/include/linux/platform_data/x86/apple.h b/include/linux/platform_data/x86/apple.h
index 079e816c3..47b27dcea 100644
--- a/include/linux/platform_data/x86/apple.h
+++ b/include/linux/platform_data/x86/apple.h
@@ -6,8 +6,13 @@
  * x86_apple_machine - whether the machine is an x86 Apple Macintosh
  */
 extern bool x86_apple_machine;
+/**
+ * has_apple_t2_chip - whether the machine has the Apple T2 chip
+ */
+extern bool has_apple_t2_chip;
 #else
 #define x86_apple_machine false
+#define has_apple_t2_chip false
 #endif
 
 #endif
diff --git a/security/integrity/platform_certs/keyring_handler.h b/security/integrity/platform_certs/keyring_handler.h
index f92895cc5..a355f4400 100644
--- a/security/integrity/platform_certs/keyring_handler.h
+++ b/security/integrity/platform_certs/keyring_handler.h
@@ -45,11 +45,3 @@ efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_ty
 efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_type);
 
 #endif
-
-#ifndef UEFI_QUIRK_SKIP_CERT
-#define UEFI_QUIRK_SKIP_CERT(vendor, product) \
-		 .matches = { \
-			DMI_MATCH(DMI_BOARD_VENDOR, vendor), \
-			DMI_MATCH(DMI_PRODUCT_NAME, product), \
-		},
-#endif
diff --git a/security/integrity/platform_certs/load_uefi.c b/security/integrity/platform_certs/load_uefi.c
index c0d694844..b4096d4c8 100644
--- a/security/integrity/platform_certs/load_uefi.c
+++ b/security/integrity/platform_certs/load_uefi.c
@@ -3,42 +3,16 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/cred.h>
-#include <linux/dmi.h>
 #include <linux/err.h>
 #include <linux/efi.h>
 #include <linux/slab.h>
 #include <linux/ima.h>
+#include <linux/platform_data/x86/apple.h>
 #include <keys/asymmetric-type.h>
 #include <keys/system_keyring.h>
 #include "../integrity.h"
 #include "keyring_handler.h"
 
-/*
- * On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot
- * certificates causes occurrence of a page fault in Apple's firmware and
- * a crash disabling EFI runtime services. The following quirk skips reading
- * these variables.
- */
-static const struct dmi_system_id uefi_skip_cert[] = {
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,2") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,3") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro15,4") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,2") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,3") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookPro16,4") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir8,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir8,2") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacBookAir9,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "Macmini8,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacPro7,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,1") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,2") },
-	{ UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMacPro1,1") },
-	{ }
-};
-
 /*
  * Look to see if a UEFI variable called MokIgnoreDB exists and return true if
  * it does.
@@ -165,10 +139,14 @@ static int __init load_uefi_certs(void)
 	unsigned long dbsize = 0, dbxsize = 0, mokxsize = 0;
 	efi_status_t status;
 	int rc = 0;
-	const struct dmi_system_id *dmi_id;
 
-	dmi_id = dmi_first_match(uefi_skip_cert);
-	if (dmi_id) {
+	/*
+	 * On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot
+	 * certificates causes occurrence of a page fault in Apple's firmware and
+	 * a crash disabling EFI runtime services. The following quirk skips reading
+	 * these variables.
+	 */
+	if (has_apple_t2_chip) {
 		pr_err("Reading UEFI Secure Boot Certs is not supported on T2 Macs.\n");
 		return false;
 	}
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 09/14] treewide: disable other rtc's in t2 macs
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (7 preceding siblings ...)
  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 ` Atharva Tiwari
  2026-12-04 14:27   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Aditya Garg, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

The CMOS RTC and the ACPI TAD clock don't work correctly on
T2 Macs. When macsmc-rtc is enabled, turn them off on these
machines so macsmc-rtc is the only clock.

Apple also uses RTC to update NTP instead of wallclock so we
do that also.

Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 arch/x86/kernel/rtc.c   | 5 +++++
 drivers/acpi/acpi_tad.c | 5 +++++
 drivers/rtc/rtc-cmos.c  | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 314b062a1..90f24e6ce 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -3,6 +3,7 @@
  * RTC related functions
  */
 #include <linux/acpi.h>
+#include <linux/platform_data/x86/apple.h>
 #include <linux/platform_device.h>
 #include <linux/mc146818rtc.h>
 #include <linux/export.h>
@@ -101,6 +102,10 @@ EXPORT_SYMBOL(rtc_cmos_write);
 
 int update_persistent_clock64(struct timespec64 now)
 {
+	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
+			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
+		return -ENODEV;
+
 	return x86_platform.set_wallclock(&now);
 }
 
diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
index 45459a4ca..a13716451 100644
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -28,6 +28,7 @@
 #include <linux/ktime.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/platform_data/x86/apple.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/rtc.h>
@@ -845,6 +846,10 @@ static int acpi_tad_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
+			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
+		caps &= ~ACPI_TAD_RT;
+
 	if (!acpi_has_method(handle, "_PRW")) {
 		dev_info(dev, "Missing _PRW\n");
 		caps &= ~(ACPI_TAD_AC_WAKE | ACPI_TAD_DC_WAKE);
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index fa04ece15..f930a36d0 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -33,6 +33,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
+#include <linux/platform_data/x86/apple.h>
 #include <linux/platform_device.h>
 #include <linux/log2.h>
 #include <linux/pm.h>
@@ -944,6 +945,10 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 		.priv = &cmos_rtc,
 	};
 
+	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
+			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
+		return -ENODEV;
+
 	/* there can be only one ... */
 	if (cmos_rtc.dev)
 		return -EBUSY;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (8 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:39   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Andre Eikmeyer, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

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.

It also adds a charge limit, which acpi-sbs doesn't offer.

And now we have power stats on non-mobile macs as well (iMacs,
MacPros,etc), using macsmc-ac.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Co-developed-by: Andre Eikmeyer <dev@deq.rocks>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/power/supply/macsmc-power.c | 803 ++++++++++++++++++++++------
 1 file changed, 654 insertions(+), 149 deletions(-)

diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c
index ced37a701..2ebf620a2 100644
--- a/drivers/power/supply/macsmc-power.c
+++ b/drivers/power/supply/macsmc-power.c
@@ -7,8 +7,11 @@
  * on Apple Silicon systems.
  *
  * Copyright The Asahi Linux Contributors
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
  */
 
+#include <linux/acpi.h>
 #include <linux/ctype.h>
 #include <linux/delay.h>
 #include <linux/devm-helpers.h>
@@ -80,12 +83,17 @@ struct macsmc_power {
 	char serial_number[MAX_STRING_LENGTH];
 	char mfg_date[MAX_STRING_LENGTH];
 
+	bool has_battery;
+
 	/* Supported feature flags based on SMC key presence */
+	bool has_b0ap; /* Power Now (New intel macs and Apple silicon) */
 	bool has_chwa; /* Charge limit (Modern firmware) */
-	bool has_chls; /* Charge limit (Older firmware) */
+	bool has_chls; /* Charge limit (Older firmware And New firmware on Intel macs) */
 	bool has_ch0i; /* Force discharge (Older firmware) */
 	bool has_ch0c; /* Inhibit charge (Older firmware) */
 	bool has_chte; /* Inhibit charge (Modern firmware) */
+	bool has_pd0r; /* AC Adapter current power in watts (Old Intel macs) */
+
 	/*
 	 * Battery critical key is 1 byte and charge key is little endian
 	 * (Modern firmware)
@@ -95,6 +103,7 @@ struct macsmc_power {
 	u8 num_cells;
 	int nominal_voltage_mv;
 
+	struct acpi_device *adapter;
 	struct notifier_block nb;
 	struct work_struct critical_work;
 	bool emergency_shutdown_triggered;
@@ -195,6 +204,41 @@ static int macsmc_battery_get_status(struct macsmc_power *power)
 	return POWER_SUPPLY_STATUS_CHARGING;
 }
 
+static int macsmc_battery_acpi_get_status(struct macsmc_power *power)
+{
+	acpi_status status;
+	int ret;
+	s16 vs16;
+	u16 vu16;
+	unsigned long long adapter_status;
+
+	ret = apple_smc_read_s16(power->smc, SMC_KEY(B0AC), &vs16);
+	if (ret < 0)
+		return ret;
+
+	ret = apple_smc_read_u16(power->smc, SMC_KEY(BRSC), &vu16);
+	if (ret < 0)
+		return ret;
+
+	vu16 = swab16(vu16);
+	vs16 = (s16)swab16(vs16);
+
+	status = acpi_evaluate_integer(power->adapter->handle, "_PSR", NULL, &adapter_status);
+
+	if (ACPI_SUCCESS(status) && !!adapter_status) {
+		if (vu16 == 100 && vs16 <= 0)
+			return POWER_SUPPLY_STATUS_FULL;
+
+		if (vs16 > 0)
+			return POWER_SUPPLY_STATUS_CHARGING;
+
+		return POWER_SUPPLY_STATUS_NOT_CHARGING;
+	}
+
+	return POWER_SUPPLY_STATUS_DISCHARGING;
+}
+
+
 static int macsmc_battery_get_charge_behaviour(struct macsmc_power *power)
 {
 	int ret;
@@ -322,6 +366,210 @@ static int macsmc_battery_get_capacity_level(struct macsmc_power *power)
 		return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
 }
 
+static int macsmc_battery_acpi_get_capacity_level(struct macsmc_power *power)
+{
+	int ret;
+	u16 vu16;
+
+	ret = apple_smc_read_u16(power->smc, SMC_KEY(BRSC), &vu16);
+	if (ret < 0)
+		return ret;
+
+	vu16 = swab16(vu16);
+
+	if (vu16 <= 5)
+		return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
+	if (vu16 <= 20)
+		return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
+	if (vu16 <= 80)
+		return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
+	if (vu16 < 100)
+		return POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
+
+	return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
+}
+
+static int macsmc_battery_acpi_read_f32_scaled(struct apple_smc *smc, smc_key key,
+	int *p, int scale)
+{
+	u32 fval;
+	u64 val;
+	int ret, exp;
+
+	ret = apple_smc_read_u32(smc, key, &fval);
+	if (ret < 0)
+		return ret;
+
+	val = (u64)((fval & GENMASK(22, 0)) | BIT(23));
+	exp = ((fval >> 23) & 0xff) - 127 - 23;
+
+	val *= (u64)scale;
+
+	if (exp > 63)
+		val = U64_MAX;
+	else if (exp < -63)
+		val = 0;
+	else if (exp < 0)
+		val >>= -exp;
+	else if (exp != 0 &&
+		 (val & ~((1ULL << (64 - exp)) - 1)))
+		val = U64_MAX;
+	else
+		val <<= exp;
+
+	if (fval & BIT(31)) {
+		if (val > (u64)INT_MAX + 1)
+			*p = INT_MIN;
+		else
+			*p = -(int)val;
+	} else {
+		if (val > INT_MAX)
+			*p = INT_MAX;
+		else
+			*p = (int)val;
+	}
+
+	return 0;
+}
+
+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 */
+	case __SMC_KEY('f', 'p', '3', 'd'): {
+		u16 fp3d;
+
+		ret = apple_smc_read_u16(smc, key, &fp3d);
+		if (ret)
+			return ret;
+
+		*val = mult_frac((s64)be16_to_cpu(fp3d), scale, BIT(13));
+		break;
+	}
+
+	/* 5.11 fixed point decimal */
+	case __SMC_KEY('f', 'p', '5', 'b'): {
+		u16 fp5b;
+
+		ret = apple_smc_read_u16(smc, key, &fp5b);
+		if (ret)
+			return ret;
+
+		*val = mult_frac(be16_to_cpu(fp5b), scale, BIT(11));
+		break;
+	}
+
+	/* 8.8 fixed point decimal */
+	case __SMC_KEY('f', 'p', '8', '8'): {
+		u16 fp88;
+
+		ret = apple_smc_read_u16(smc, key, &fp88);
+		if (ret)
+			return ret;
+
+		*val = mult_frac(be16_to_cpu(fp88), scale, BIT(8));
+		break;
+	}
+
+	/* 3.12 signed fixed point decimal */
+	case __SMC_KEY('s', 'p', '3', 'c'): {
+		s16 sp3c;
+
+		ret = apple_smc_read_s16(smc, key, &sp3c);
+		if (ret)
+			return ret;
+
+		*val = mult_frac((s64)(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, 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, 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, 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, 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, key, &sp87);
+		if (ret)
+			return ret;
+
+		*val = mult_frac((s16)be16_to_cpu(sp87), scale, BIT(7));
+		break;
+	}
+
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
 static s16 macsmc_swap_b0rm(struct macsmc_power *power, s16 b0rm)
 {
 	/* B0RM was Big Endian, likely pass through from TI gas gauge */
@@ -343,7 +591,10 @@ static int macsmc_battery_get_property(struct power_supply *psy,
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS:
-		val->intval = macsmc_battery_get_status(power);
+		if (power->smc->is_acpi)
+			val->intval = macsmc_battery_acpi_get_status(power);
+		else
+			val->intval = macsmc_battery_get_status(power);
 		ret = val->intval < 0 ? val->intval : 0;
 		break;
 	case POWER_SUPPLY_PROP_PRESENT:
@@ -359,36 +610,82 @@ static int macsmc_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0TF), &vu16);
-		val->intval = vu16 == 0xffff ? 0 : vu16 * 60;
+		if (power->smc->is_acpi)
+			val->intval = vu16 == 0xffff ? 0 : swab16(vu16) * 60;
+		else
+			val->intval = vu16 == 0xffff ? 0 : vu16 * 60;
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
-		ret = apple_smc_read_u8(power->smc, SMC_KEY(BUIC), &vu8);
-		val->intval = vu8;
+		if (power->smc->is_acpi) {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(BRSC), &vu16);
+			val->intval = swab16(vu16);
+		} else {
+			ret = apple_smc_read_u8(power->smc, SMC_KEY(BUIC), &vu8);
+			val->intval = vu8;
+		}
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
-		val->intval = macsmc_battery_get_capacity_level(power);
+		if (power->smc->is_acpi)
+			val->intval = macsmc_battery_acpi_get_capacity_level(power);
+		else
+			val->intval = macsmc_battery_get_capacity_level(power);
 		ret = val->intval < 0 ? val->intval : 0;
 		break;
 	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;
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		ret = apple_smc_read_s16(power->smc, SMC_KEY(B0AC), &vs16);
-		val->intval = vs16 * 1000;
+		if (power->smc->is_acpi)
+			val->intval = (s16)swab16(vs16) * 1000;
+		else
+			val->intval = vs16 * 1000;
 		break;
 	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;
 	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(BITV), &vu16);
-		val->intval = vu16 * 1000;
+		if (power->smc->is_acpi)
+			val->intval = swab16(vu16) * 1000;
+		else
+			val->intval = vu16 * 1000;
 		break;
 	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
 		/* Calculate total max design voltage from per-cell maximum voltage */
-		ret = apple_smc_read_u16(power->smc, SMC_KEY(BVVN), &vu16);
-		val->intval = vu16 * 1000 * power->num_cells;
+		if (power->smc->is_acpi) {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(BCMV), &vu16);
+			val->intval = swab16(vu16) * 1000 * power->num_cells;
+		} else {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(BVVN), &vu16);
+			val->intval = vu16 * 1000 * power->num_cells;
+		}
 		break;
 	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
 		/* Lifetime min */
@@ -400,17 +697,36 @@ static int macsmc_battery_get_property(struct power_supply *psy,
 		ret = apple_smc_read_s16(power->smc, SMC_KEY(BLPX), &vs16);
 		val->intval = vs16 * 1000;
 		break;
+	case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
+		if (power->has_chls) {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(CHLS), &vu16);
+			val->intval = vu16 & 0xFF;
+		} else {
+			ret = apple_smc_read_u8(power->smc, SMC_KEY(BCLM), &vu8);
+			val->intval = vu8;
+		}
+		break;
 	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RC), &vu16);
 		val->intval = vu16 * 1000;
 		break;
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
-		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RI), &vu16);
-		val->intval = vu16 * 1000;
+		if (power->smc->is_acpi) {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(CHBI), &vu16);
+			val->intval = swab16(vu16) * 1000;
+		} else {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RI), &vu16);
+			val->intval = vu16 * 1000;
+		}
 		break;
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
-		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RV), &vu16);
-		val->intval = vu16 * 1000;
+		if (power->smc->is_acpi) {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(CHBV), &vu16);
+			val->intval = swab16(vu16) * 1000;
+		} else {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RV), &vu16);
+			val->intval = vu16 * 1000;
+		}
 		break;
 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0DC), &vu16);
@@ -418,27 +734,64 @@ static int macsmc_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_CHARGE_FULL:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0FC), &vu16);
-		val->intval = vu16 * 1000;
+		if (power->smc->is_acpi)
+			val->intval = swab16(vu16) * 1000;
+		else
+			val->intval = vu16 * 1000;
 		break;
 	case POWER_SUPPLY_PROP_CHARGE_NOW:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RM), &vu16);
-		val->intval = macsmc_swap_b0rm(power, vu16) * 1000;
+		if (power->smc->is_acpi)
+			val->intval = swab16(vu16) * 1000;
+		else
+			val->intval = macsmc_swap_b0rm(power, vu16) * 1000;
 		break;
 	case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0DC), &vu16);
-		val->intval = vu16 * power->nominal_voltage_mv;
+		if (power->smc->is_acpi) {
+			if (ret < 0)
+				return ret;
+
+			u16 voltage;
+
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
+			val->intval = vu16 * swab16(voltage);
+		} else
+			val->intval = vu16 * power->nominal_voltage_mv;
 		break;
 	case POWER_SUPPLY_PROP_ENERGY_FULL:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0FC), &vu16);
-		val->intval = vu16 * power->nominal_voltage_mv;
+		if (power->smc->is_acpi) {
+			if (ret < 0)
+				return ret;
+
+			u16 voltage;
+
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
+			val->intval = swab16(vu16) * swab16(voltage);
+		} else
+			val->intval = vu16 * power->nominal_voltage_mv;
 		break;
 	case POWER_SUPPLY_PROP_ENERGY_NOW:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RM), &vu16);
-		val->intval = macsmc_swap_b0rm(power, vu16) * power->nominal_voltage_mv;
+		if (power->smc->is_acpi) {
+			if (ret < 0)
+				return ret;
+
+			u16 voltage;
+
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
+			val->intval = swab16(vu16) * swab16(voltage);
+		} else
+			val->intval = macsmc_swap_b0rm(power, vu16) * power->nominal_voltage_mv;
 		break;
 	case POWER_SUPPLY_PROP_TEMP:
-		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AT), &vu16);
-		val->intval = vu16 - 2732; /* Kelvin x10 to Celsius x10 */
+		if (power->smc->is_acpi)
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(TB0T), &val->intval, 10);
+		else {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AT), &vu16);
+			val->intval = vu16 - 2732; /* Kelvin x10 to Celsius x10 */
+		}
 		break;
 	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
 		ret = apple_smc_read_s64(power->smc, SMC_KEY(BAAC), &vs64);
@@ -446,7 +799,10 @@ static int macsmc_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_CYCLE_COUNT:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0CT), &vu16);
-		val->intval = vu16;
+		if (power->smc->is_acpi)
+			val->intval = swab16(vu16);
+		else
+			val->intval = vu16;
 		break;
 	case POWER_SUPPLY_PROP_SCOPE:
 		val->intval = POWER_SUPPLY_SCOPE_SYSTEM;
@@ -489,6 +845,15 @@ static int macsmc_battery_set_property(struct power_supply *psy,
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
 		return macsmc_battery_set_charge_behaviour(power, val->intval);
+	case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
+		if (val->intval > 100 || val->intval < 1)
+			return -EINVAL;
+		if (power->has_chls) {
+			u16 vu16 = val->intval & 0xFF;
+
+			return apple_smc_write_u16(power->smc, SMC_KEY(CHLS), vu16);
+		}
+		return apple_smc_write_u8(power->smc, SMC_KEY(BCLM), (u8) val->intval);
 	default:
 		return -EINVAL;
 	}
@@ -500,6 +865,8 @@ static int macsmc_battery_property_is_writeable(struct power_supply *psy,
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
 		return true;
+	case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
+		return true;
 	default:
 		return false;
 	}
@@ -524,12 +891,55 @@ static int macsmc_ac_get_property(struct power_supply *psy,
 
 	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;
+	case POWER_SUPPLY_PROP_CURRENT_NOW:
+		if (power->has_battery)
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(ID0R),
+					&val->intval, 1000000);
+		else
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(ID2R),
+					&val->intval, 1000000);
+		break;
+	case POWER_SUPPLY_PROP_POWER_NOW:
+		if (power->has_pd0r)
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(PD0R),
+					&val->intval, 1000000);
+		else if (power->has_battery)
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(PDTR),
+					&val->intval, 1000000);
+		else
+			ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(PD2R),
+					&val->intval, 1000000);
 		break;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = apple_smc_read_u16(power->smc, SMC_KEY(AC-n), &vu16);
-		val->intval = vu16 * 1000;
+		if (power->smc->is_acpi) {
+			if (power->has_battery)
+				ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(VD0R),
+						&val->intval, 1000000);
+			else
+				ret = macsmc_battery_acpi_read(power->smc, SMC_KEY(VD2R),
+						&val->intval, 1000000);
+		} else {
+			ret = apple_smc_read_u16(power->smc, SMC_KEY(AC-n), &vu16);
+			val->intval = vu16 * 1000;
+		}
 		break;
 	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
 		ret = apple_smc_read_u16(power->smc, SMC_KEY(AC-i), &vu16);
@@ -537,7 +947,10 @@ static int macsmc_ac_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT:
 		ret = apple_smc_read_u32(power->smc, SMC_KEY(ACPW), &vu32);
-		val->intval = vu32 * 1000;
+		if (power->smc->is_acpi)
+			val->intval = swab32(vu32) * 1000;
+		else
+			val->intval = vu32 * 1000;
 		break;
 	default:
 		return -EINVAL;
@@ -634,6 +1047,19 @@ static int macsmc_power_event(struct notifier_block *nb, unsigned long event, vo
 	return NOTIFY_DONE;
 }
 
+static void macsmc_power_acpi_notify(acpi_handle handle, u32 event, void *context)
+{
+	struct macsmc_power *power = context;
+
+	if (event == 0x80) {
+		if (power->batt)
+			power_supply_changed(power->batt);
+		if (power->ac)
+			power_supply_changed(power->ac);
+	}
+}
+
+
 static int macsmc_power_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -667,18 +1093,23 @@ static int macsmc_power_probe(struct platform_device *pdev)
 		return ret;
 
 	/*
-	 * Check for battery presence.
-	 * B0AV is a fundamental key.
+	 * On Intel Mac's we have a key that indicates if the device has a battery,
+	 * but on Apple silicon Mac's we dont, so we check for B0AV
 	 */
-	if (apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16) == 0 &&
+	if (smc->is_acpi && apple_smc_read_flag(power->smc, SMC_KEY(BBIN), &flag) == 0 && flag)
+		has_battery = true;
+
+	else if (!smc->is_acpi &&
+	    apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &vu16) == 0 &&
 	    macsmc_battery_get_status(power) > POWER_SUPPLY_STATUS_UNKNOWN)
 		has_battery = true;
 
+	power->has_battery = has_battery;
 	/*
 	 * Check for AC adapter presence.
 	 * CHIS is a fundamental key.
 	 */
-	if (apple_smc_key_exists(smc, SMC_KEY(CHIS)))
+	if (apple_smc_key_exists(smc, SMC_KEY(CHIS)) || smc->is_acpi)
 		has_ac_adapter = true;
 
 	if (!has_battery && !has_ac_adapter)
@@ -694,118 +1125,161 @@ static int macsmc_power_probe(struct platform_device *pdev)
 
 		nprops = 0;
 
-		/* Fundamental properties */
-		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_MODEL_NAME;
-		props[nprops++] = POWER_SUPPLY_PROP_SERIAL_NUMBER;
-		props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_YEAR;
-		props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_MONTH;
-		props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_DAY;
-
-		/* Extended properties usually present */
-		props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW;
-		props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_FULL_NOW;
-		props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
-		props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
-		props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MIN;
-		props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MAX;
-		props[nprops++] = POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT;
-		props[nprops++] = POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
-		props[nprops++] = POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE;
-		props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
-		props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL;
-		props[nprops++] = POWER_SUPPLY_PROP_CHARGE_NOW;
-		props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
-		props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL;
-		props[nprops++] = POWER_SUPPLY_PROP_ENERGY_NOW;
-		props[nprops++] = POWER_SUPPLY_PROP_CHARGE_COUNTER;
-
-		/* Detect features based on key availability */
-		if (apple_smc_key_exists(smc, SMC_KEY(CHTE)))
-			power->has_chte = true;
-		if (apple_smc_key_exists(smc, SMC_KEY(CH0C)))
-			power->has_ch0c = true;
-		if (apple_smc_key_exists(smc, SMC_KEY(CH0I)))
-			power->has_ch0i = true;
-
-		ret = apple_smc_get_key_info(power->smc, SMC_KEY(BCF0), &info);
-		if (ret) {
-			dev_err(&pdev->dev, "Failed to determine BCF0 key size\n");
-			return ret;
-		}
-		if (info.size == 1)
-			power->fw_ge_27 = true;
-		else if (info.size == 4)
-			power->fw_ge_27 = false;
-		else {
-			dev_err(&pdev->dev, "Unexpected BCF0 key size %d\n", info.size);
-			return -EIO;
-		}
-
-		/* Reset "Optimised Battery Charging" flags to default state */
-		if (power->has_chte)
-			apple_smc_write_u32(smc, SMC_KEY(CHTE), 0);
-		else if (power->has_ch0c)
-			apple_smc_write_u8(smc, SMC_KEY(CH0C), 0);
-
-		if (power->has_ch0i)
-			apple_smc_write_u8(smc, SMC_KEY(CH0I), 0);
-
-		apple_smc_write_u8(smc, SMC_KEY(CH0K), 0);
-		apple_smc_write_u8(smc, SMC_KEY(CH0B), 0);
-
-		/* Configure charge behaviour if supported */
-		if (power->has_ch0i || power->has_ch0c || power->has_chte) {
-			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR;
-
-			power->batt_desc.charge_behaviours =
-				BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO);
+		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_CONSTANT_CHARGE_CURRENT_MAX;
+			props[nprops++] = POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE;
+			props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_FULL_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL;
+			props[nprops++] = POWER_SUPPLY_PROP_ENERGY_NOW;
+
+			if (apple_smc_key_exists(smc, SMC_KEY(B0DC))) {
+				props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
+				props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
+			}
+			if (apple_smc_key_exists(smc, SMC_KEY(CHLS)))
+				power->has_chls = true;
+			if (power->has_chls || apple_smc_key_exists(smc, SMC_KEY(BCLM)))
+				props[nprops++] = POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD;
+			if (apple_smc_key_exists(smc, SMC_KEY(B0AP)))
+				power->has_b0ap = true;
+			if (apple_smc_key_exists(smc, SMC_KEY(B0TE)))
+				props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW;
+			if (apple_smc_key_exists(smc, SMC_KEY(BITV)))
+				props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
+			if (apple_smc_key_exists(smc, SMC_KEY(BCMV)))
+				props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
+
+			if (apple_smc_key_exists(smc, SMC_KEY(BC3V)))
+				power->num_cells = 3;
+			else
+				power->num_cells = 2;
+		} else {
+			/* Fundamental properties */
+			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_MODEL_NAME;
+			props[nprops++] = POWER_SUPPLY_PROP_SERIAL_NUMBER;
+			props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_YEAR;
+			props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_MONTH;
+			props[nprops++] = POWER_SUPPLY_PROP_MANUFACTURE_DAY;
+
+			/* Extended properties usually present */
+			props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_FULL_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
+			props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
+			props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MIN;
+			props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_MAX;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT;
+			props[nprops++] = POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
+			props[nprops++] = POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_FULL;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
+			props[nprops++] = POWER_SUPPLY_PROP_ENERGY_FULL;
+			props[nprops++] = POWER_SUPPLY_PROP_ENERGY_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_CHARGE_COUNTER;
+
+			/* Detect features based on key availability */
+			if (apple_smc_key_exists(smc, SMC_KEY(CHTE)))
+				power->has_chte = true;
+			if (apple_smc_key_exists(smc, SMC_KEY(CH0C)))
+				power->has_ch0c = true;
+			if (apple_smc_key_exists(smc, SMC_KEY(CH0I)))
+				power->has_ch0i = true;
+
+			ret = apple_smc_get_key_info(power->smc, SMC_KEY(BCF0), &info);
+			if (ret) {
+				dev_err(&pdev->dev, "Failed to determine BCF0 key size\n");
+				return ret;
+			}
+			if (info.size == 1)
+				power->fw_ge_27 = true;
+			else if (info.size == 4)
+				power->fw_ge_27 = false;
+			else {
+				dev_err(&pdev->dev, "Unexpected BCF0 key size %d\n", info.size);
+				return -EIO;
+			}
+
+			/* Reset "Optimised Battery Charging" flags to default state */
+			if (power->has_chte)
+				apple_smc_write_u32(smc, SMC_KEY(CHTE), 0);
+			else if (power->has_ch0c)
+				apple_smc_write_u8(smc, SMC_KEY(CH0C), 0);
 
 			if (power->has_ch0i)
-				power->batt_desc.charge_behaviours |=
-					BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE);
-
-			if (power->has_chte || power->has_ch0c)
-				power->batt_desc.charge_behaviours |=
-					BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE);
+				apple_smc_write_u8(smc, SMC_KEY(CH0I), 0);
+
+			apple_smc_write_u8(smc, SMC_KEY(CH0K), 0);
+			apple_smc_write_u8(smc, SMC_KEY(CH0B), 0);
+
+			/* Configure charge behaviour if supported */
+			if (power->has_ch0i || power->has_ch0c || power->has_chte) {
+				props[nprops++] = POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR;
+
+				power->batt_desc.charge_behaviours =
+					BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO);
+
+				if (power->has_ch0i)
+					power->batt_desc.charge_behaviours |=
+						BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE);
+
+				if (power->has_chte || power->has_ch0c)
+					power->batt_desc.charge_behaviours |=
+						BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE);
+			}
+
+			/* Detect charge limit method (CHWA vs CHLS) */
+			if (apple_smc_read_flag(power->smc, SMC_KEY(CHWA), &flag) == 0)
+				power->has_chwa = true;
+			else if (apple_smc_read_u16(power->smc, SMC_KEY(CHLS), &vu16) >= 0)
+				power->has_chls = true;
+
+			/* Fetch identity strings */
+			apple_smc_read(smc, SMC_KEY(BMDN), power->model_name,
+				       sizeof(power->model_name) - 1);
+			apple_smc_read(smc, SMC_KEY(BMSN), power->serial_number,
+				       sizeof(power->serial_number) - 1);
+			apple_smc_read(smc, SMC_KEY(BMDT), power->mfg_date,
+				       sizeof(power->mfg_date) - 1);
+
+			apple_smc_read_u8(power->smc, SMC_KEY(BNCB), &power->num_cells);
+			power->nominal_voltage_mv = MACSMC_NOMINAL_CELL_VOLTAGE_MV *
+							power->num_cells;
+
+			/* Enable critical shutdown notifications by reading status once */
+			macsmc_battery_read_bcf0(power, &val32);
 		}
-
-		/* Detect charge limit method (CHWA vs CHLS) */
-		if (apple_smc_read_flag(power->smc, SMC_KEY(CHWA), &flag) == 0)
-			power->has_chwa = true;
-		else if (apple_smc_read_u16(power->smc, SMC_KEY(CHLS), &vu16) >= 0)
-			power->has_chls = true;
-
 		if (nprops > MACSMC_MAX_BATT_PROPS)
 			return -ENOMEM;
 
 		power->batt_desc.properties = props;
 		power->batt_desc.num_properties = nprops;
 
-		/* Fetch identity strings */
-		apple_smc_read(smc, SMC_KEY(BMDN), power->model_name,
-			       sizeof(power->model_name) - 1);
-		apple_smc_read(smc, SMC_KEY(BMSN), power->serial_number,
-			       sizeof(power->serial_number) - 1);
-		apple_smc_read(smc, SMC_KEY(BMDT), power->mfg_date,
-			       sizeof(power->mfg_date) - 1);
-
-		apple_smc_read_u8(power->smc, SMC_KEY(BNCB), &power->num_cells);
-		power->nominal_voltage_mv = MACSMC_NOMINAL_CELL_VOLTAGE_MV * power->num_cells;
-
-		/* Enable critical shutdown notifications by reading status once */
-		macsmc_battery_read_bcf0(power, &val32);
-
 		psy_cfg.drv_data = power;
 		power->batt = devm_power_supply_register(dev, &power->batt_desc, &psy_cfg);
 		if (IS_ERR(power->batt)) {
@@ -829,16 +1303,27 @@ static int macsmc_power_probe(struct platform_device *pdev)
 		/* Online status is fundamental */
 		props[nprops++] = POWER_SUPPLY_PROP_ONLINE;
 
-		/* Input power limits are usually available */
-		if (apple_smc_key_exists(power->smc, SMC_KEY(ACPW)))
-			props[nprops++] = POWER_SUPPLY_PROP_INPUT_POWER_LIMIT;
-
-		/* macOS 15.4+ firmware dropped legacy AC keys (AC-n, AC-i) */
-		if (apple_smc_read_u16(power->smc, SMC_KEY(AC-n), &vu16) >= 0) {
-			props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
-			props[nprops++] = POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT;
+		if (smc->is_acpi) {
+			props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
+			props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
+			if (apple_smc_key_exists(power->smc, SMC_KEY(PD0R)))
+				power->has_pd0r = true;
+			/* MacBookPro5,x and 7,x dosent have VD0R key or any equivalent */
+			if (!power->has_battery || apple_smc_key_exists(power->smc, SMC_KEY(VD0R)))
+				props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
+			if (apple_smc_key_exists(power->smc, SMC_KEY(ACPW)))
+				props[nprops++] = POWER_SUPPLY_PROP_INPUT_POWER_LIMIT;
+		} else {
+			/* Input power limits are usually available */
+			if (apple_smc_key_exists(power->smc, SMC_KEY(ACPW)))
+				props[nprops++] = POWER_SUPPLY_PROP_INPUT_POWER_LIMIT;
+
+			/* macOS 15.4+ firmware dropped legacy AC keys (AC-n, AC-i) */
+			if (apple_smc_read_u16(power->smc, SMC_KEY(AC-n), &vu16) >= 0) {
+				props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;
+				props[nprops++] = POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT;
+			}
 		}
-
 		if (nprops > MACSMC_MAX_AC_PROPS)
 			return -ENOMEM;
 
@@ -858,9 +1343,22 @@ static int macsmc_power_probe(struct platform_device *pdev)
 	if (!power->batt && !power->ac)
 		return -ENODEV;
 
-	power->nb.notifier_call = macsmc_power_event;
-	blocking_notifier_chain_register(smc->event_handlers, &power->nb);
+	if (!smc->is_acpi) {
+		power->nb.notifier_call = macsmc_power_event;
+		blocking_notifier_chain_register(smc->event_handlers, &power->nb);
+	} else if (power->has_battery) {
+		power->adapter = acpi_dev_get_first_match_dev("ACPI0003", NULL, -1);
+		if (!power->adapter)
+			return -ENODEV;
 
+		ret = acpi_dev_install_notify_handler(power->adapter, ACPI_DEVICE_NOTIFY,
+					macsmc_power_acpi_notify, power);
+		if (ret) {
+			acpi_dev_put(power->adapter);
+			power->adapter = NULL;
+			return ret;
+		}
+	}
 	return 0;
 }
 
@@ -868,7 +1366,13 @@ static void macsmc_power_remove(struct platform_device *pdev)
 {
 	struct macsmc_power *power = dev_get_drvdata(&pdev->dev);
 
-	blocking_notifier_chain_unregister(power->smc->event_handlers, &power->nb);
+	if (!power->smc->is_acpi)
+		blocking_notifier_chain_unregister(power->smc->event_handlers, &power->nb);
+	else if (power->has_battery) {
+		acpi_dev_remove_notify_handler(power->adapter, ACPI_DEVICE_NOTIFY,
+				macsmc_power_acpi_notify);
+		acpi_dev_put(power->adapter);
+	}
 }
 
 static const struct platform_device_id macsmc_power_id[] = {
@@ -891,3 +1395,4 @@ MODULE_LICENSE("Dual MIT/GPL");
 MODULE_DESCRIPTION("Apple SMC battery and power management driver");
 MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
 MODULE_AUTHOR("Michael Reeves <michael.reeves077@gmail.com>");
+MODULE_ALIAS("platform:macsmc-power");
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (9 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:08   ` Andy Shevchenko
  2026-12-04 14:25   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
                   ` (3 subsequent siblings)
  14 siblings, 2 replies; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

When macsmc-power is enabled on an Intel Mac, skip acpi-sbs
and the ACPI battery and adapter drivers, since macsmc-power
now provides them. This avoids duplicate devices.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/acpi/sbs.c       | 5 ++++-
 drivers/acpi/x86/utils.c | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index f10bbf13c..368bcae72 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -634,6 +634,10 @@ static int acpi_sbs_probe(struct platform_device *pdev)
 	int result = 0;
 	int id;
 
+	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
+			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
+		return -ENODEV;
+
 	device = ACPI_COMPANION(&pdev->dev);
 	if (!device)
 		return -ENODEV;
@@ -664,7 +668,6 @@ static int acpi_sbs_probe(struct platform_device *pdev)
 					acpi_battery_add(sbs, id);
 		}
 	}
-
 	if (!sbs->manager_present)
 		acpi_battery_add(sbs, 0);
 
diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c
index 418951639..2c54c0f67 100644
--- a/drivers/acpi/x86/utils.c
+++ b/drivers/acpi/x86/utils.c
@@ -14,6 +14,7 @@
 #include <linux/dmi.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/platform_data/x86/apple.h>
 #include <asm/cpu_device_id.h>
 #include <asm/intel-family.h>
 #include "../internal.h"
@@ -608,6 +609,10 @@ bool acpi_quirk_skip_acpi_ac_and_battery(void)
 	long quirks = 0;
 	int i;
 
+	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
+			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
+		return true;
+
 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
 	if (dmi_id)
 		quirks = (unsigned long)dmi_id->driver_data;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 12/14] hwmon/macsmc: add more types
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (10 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:37   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

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.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
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..14b68cf8c 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 = (s64)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 = (s64)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 = (s64)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 = (s64)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((s64)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((s64)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((s64)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((s64)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((s64)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((s64)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((s64)(s16)be16_to_cpu(sp1e), scale, 1 << 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((s64)(s16)be16_to_cpu(sp2d), scale, 1 << 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((s64)(s16)be16_to_cpu(sp3c), scale, 1 << 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((s64)(s16)be16_to_cpu(sp4b), scale, 1 << 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((s64)(s16)be16_to_cpu(sp5a), scale, 1 << 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((s64)(s16)be16_to_cpu(sp69), scale, 1 << 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((s64)(s16)be16_to_cpu(sp78), scale, 1 << 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((s64)(s16)be16_to_cpu(sp87), scale, 1 << 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((s64)(s16)be16_to_cpu(sp96), scale, 1 << 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((s64)(s16)be16_to_cpu(spa5), scale, 1 << 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((s64)(s16)be16_to_cpu(spc3), scale, 1 << 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((s64)(s16)be16_to_cpu(spd2), scale, 1 << 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 = (s64)(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


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (11 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:48   ` sashiko-bot
  2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
  2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Andre Eikmeyer, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Make macsmc-hwmon work on Intel Macs, as a replacement for
the hwmon part of applesmc.

Sensors now have readable names instead of raw keys like
TA0P. It also adds power, current and voltage sensors that
applesmc doesn't provide, and supports fan control on newer
machines aswell.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Co-developed-by: Andre Eikmeyer <dev@deq.rocks>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/hwmon/Kconfig        |   5 +-
 drivers/hwmon/macsmc-hwmon.c | 842 ++++++++++++++++++++++++++++++++++-
 2 files changed, 827 insertions(+), 20 deletions(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 91ca7031c..4d0bb87ff 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1244,13 +1244,12 @@ config SENSORS_LTQ_CPUTEMP
 	  sensor inside your CPU.
 
 config SENSORS_MACSMC_HWMON
-	tristate "Apple SMC (Apple Silicon)"
+	tristate "Apple SMC Hardware monitoring"
 	depends on MFD_MACSMC_CORE
 	help
 	  This driver enables hwmon support for current, power, temperature,
 	  and voltage sensors, as well as fan speed reporting and control
-	  on Apple Silicon devices. Say Y here if you have an Apple Silicon
-	  device.
+	  on Apple devices. Say Y here if you have an Apple device.
 
 	  This driver can also be built as a module. If so, the module will
 	  be called macsmc-hwmon.
diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c
index 14b68cf8c..d531eb412 100644
--- a/drivers/hwmon/macsmc-hwmon.c
+++ b/drivers/hwmon/macsmc-hwmon.c
@@ -2,7 +2,7 @@
 /*
  * Apple SMC hwmon driver for Apple Silicon platforms
  *
- * The System Management Controller on Apple Silicon devices is responsible for
+ * The System Management Controller on Apple Silicon And Intel Macs is responsible for
  * measuring data from sensors across the SoC and machine. These include power,
  * temperature, voltage and current sensors. Some "sensors" actually expose
  * derived values. An example of this is the key PHPC, which is an estimate
@@ -18,6 +18,11 @@
  * Originally based on a concept by Jean-Francois Bortolotti <jeff@borto.fr>
  *
  * Copyright The Asahi Linux Contributors
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ *
+ * Old macs fan control based on smcFanControl:
+ * Copyright (C) 2006 Hendrik Holtmann <holtmann@mac.com>
  */
 
 #include <linux/bitfield.h>
@@ -47,7 +52,7 @@ MODULE_PARM_DESC(fan_control,
 struct macsmc_hwmon_sensor {
 	struct apple_smc_key_info info;
 	smc_key macsmc_key;
-	char label[MAX_LABEL_LENGTH];
+	char *label;
 	u32 attrs;
 };
 
@@ -71,7 +76,8 @@ struct macsmc_hwmon_sensors {
 struct macsmc_hwmon_fans {
 	struct hwmon_channel_info channel_info;
 	struct macsmc_hwmon_fan *fans;
-	u32 count;
+	u8 count;
+	bool has_old_manual;
 };
 
 struct macsmc_hwmon {
@@ -553,8 +559,8 @@ static int macsmc_hwmon_write_f32(struct apple_smc *smc, smc_key key, long value
 			val <<= 23 - exp;
 
 		fval = FIELD_PREP(FLT_SIGN_MASK, neg) |
-		       FIELD_PREP(FLT_EXP_MASK, exp + FLT_EXP_BIAS) |
-		       FIELD_PREP(FLT_MANT_MASK, val & FLT_MANT_MASK);
+			FIELD_PREP(FLT_EXP_MASK, exp + FLT_EXP_BIAS) |
+			FIELD_PREP(FLT_MANT_MASK, val & FLT_MANT_MASK);
 	}
 
 	return apple_smc_write_u32(smc, key, fval);
@@ -599,6 +605,25 @@ static int macsmc_hwmon_read_fan(struct macsmc_hwmon *hwmon, u32 attr, int chan,
 	}
 }
 
+static int macsmc_hwmon_write_old_fan_manual(struct macsmc_hwmon *hwmon, u8 val, int channel)
+{
+	int ret;
+	u16 buf;
+
+	ret = apple_smc_read_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), &buf);
+	if (ret)
+		return ret;
+
+	buf = be16_to_cpu(buf);
+
+	if (val)
+		buf |= BIT(channel);
+	else
+		buf &= ~BIT(channel);
+
+	return apple_smc_write_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), cpu_to_be16(buf));
+}
+
 static int macsmc_hwmon_write_fan(struct device *dev, u32 attr, int channel,
 				  long val)
 {
@@ -606,7 +631,8 @@ static int macsmc_hwmon_write_fan(struct device *dev, u32 attr, int channel,
 	long min, max;
 	int ret;
 
-	if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key == 0)
+	if (!fan_control || (hwmon->fan.fans[channel].mode.macsmc_key == 0 &&
+				!hwmon->fan.has_old_manual))
 		return -EOPNOTSUPP;
 
 	/*
@@ -625,7 +651,10 @@ static int macsmc_hwmon_write_fan(struct device *dev, u32 attr, int channel,
 	if (val >= min && val <= max) {
 		if (!hwmon->fan.fans[channel].manual) {
 			/* Write 1 to mode key for manual control */
-			ret = macsmc_hwmon_write_key(hwmon->smc,
+			if (hwmon->fan.has_old_manual)
+				ret = macsmc_hwmon_write_old_fan_manual(hwmon, 1, channel);
+			else
+				ret = macsmc_hwmon_write_key(hwmon->smc,
 						     &hwmon->fan.fans[channel].mode, 1);
 			if (ret < 0)
 				return ret;
@@ -636,7 +665,10 @@ static int macsmc_hwmon_write_fan(struct device *dev, u32 attr, int channel,
 					      &hwmon->fan.fans[channel].set, val);
 	} else if (!val) {
 		if (hwmon->fan.fans[channel].manual) {
-			ret = macsmc_hwmon_write_key(hwmon->smc,
+			if (hwmon->fan.has_old_manual)
+				ret = macsmc_hwmon_write_old_fan_manual(hwmon, 0, channel);
+			else
+				ret = macsmc_hwmon_write_key(hwmon->smc,
 						     &hwmon->fan.fans[channel].mode, 0);
 			if (ret < 0)
 				return ret;
@@ -697,10 +729,11 @@ static int macsmc_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
 }
 
 static umode_t macsmc_hwmon_fan_is_visible(const struct macsmc_hwmon_fan *fan,
-					   u32 attr)
+					   u32 attr, bool has_old_manual)
 {
 	if (fan->attrs & BIT(attr)) {
-		if (attr == hwmon_fan_target && fan_control && fan->mode.macsmc_key)
+		if (attr == hwmon_fan_target && fan_control &&
+				(fan->mode.macsmc_key || has_old_manual))
 			return 0644;
 
 		return 0444;
@@ -710,8 +743,8 @@ static umode_t macsmc_hwmon_fan_is_visible(const struct macsmc_hwmon_fan *fan,
 }
 
 static umode_t macsmc_hwmon_is_visible(const void *data,
-				       enum hwmon_sensor_types type, u32 attr,
-				       int channel)
+					enum hwmon_sensor_types type, u32 attr,
+					int channel)
 {
 	const struct macsmc_hwmon *hwmon = data;
 	struct macsmc_hwmon_sensor *sensor;
@@ -730,7 +763,8 @@ static umode_t macsmc_hwmon_is_visible(const void *data,
 		sensor = &hwmon->temp.sensors[channel];
 		break;
 	case hwmon_fan:
-		return macsmc_hwmon_fan_is_visible(&hwmon->fan.fans[channel], attr);
+		return macsmc_hwmon_fan_is_visible(&hwmon->fan.fans[channel],
+				attr, hwmon->fan.has_old_manual);
 	default:
 		return 0;
 	}
@@ -800,6 +834,602 @@ static int macsmc_hwmon_create_sensor(struct device *dev, struct apple_smc *smc,
 	return 0;
 }
 
+struct macsmc_sensor_desc {
+	char *name;
+	smc_key key;
+};
+
+/*
+ * Key's name taken from:
+ * https://github.com/kaiT2en/KaiT2en-Fedora/blob/main/apps/t2-smc-control/src/main.rs
+ * https://github.com/acidanthera/VirtualSMC/tree/master/Docs/
+ */
+
+static const struct macsmc_sensor_desc temp_sensors[] = {
+	{ "Ambient 2 Raw Temperature (TA1p)", SMC_KEY(TA1p) },
+	{ "Ambient 3 Raw Temperature (TA2p)", SMC_KEY(TA2p) },
+	{ "Ambient Cooked Temperature (TA0P)", SMC_KEY(TA0P) },
+	{ "Ambient Cooked Temperature 1 (TA1P)", SMC_KEY(TA1P) },
+	{ "Ambient Cooked Temperature 2 (TA2P)", SMC_KEY(TA2P) },
+	{ "Ambient Raw Temperature (TA0p)", SMC_KEY(TA0p) },
+	{ "Ambient Virtual Temperature (TA0V)", SMC_KEY(TA0V) },
+	{ "Audio L Temperature (TaLC)", SMC_KEY(TaLC) },
+	{ "Audio R Temperature (TaRC)", SMC_KEY(TaRC) },
+	{ "Backlight Controller Proximity Cooked Temperature (Tb0P)", SMC_KEY(Tb0P) },
+	{ "Backlight Controller Proximity Raw Temperature (Tb0p)", SMC_KEY(Tb0p) },
+	{ "Battery Ambient Temperature (TB3T)", SMC_KEY(TB3T) },
+	{ "Battery Temperature (TB0T)", SMC_KEY(TB0T) },
+	{ "Battery Temperature, Same As TB0T (TBXT)", SMC_KEY(TBXT) },
+	{ "Battery TS1 Temperature (TB1T)", SMC_KEY(TB1T) },
+	{ "Battery TS2 Temperature (TB2T)", SMC_KEY(TB2T) },
+	{ "Charger Proximity Temperature (TCHP)", SMC_KEY(TCHP) },
+	{ "CPU 1 Heatsink Alt. Temperature (TCAH)", SMC_KEY(TCAH) },
+	{ "CPU 1 Heatsink Temperature (TC0H)", SMC_KEY(TC0H) },
+	{ "CPU 1 Package Temperature (TCAD)", SMC_KEY(TCAD) },
+	{ "CPU 2 Diode Filtered Temperature (TC1F)", SMC_KEY(TC1F) },
+	{ "CPU 2 Diode Virtual Temperature (TC1E)", SMC_KEY(TC1E) },
+	{ "CPU 2 Heatsink Alt. Temperature (TCBH)", SMC_KEY(TCBH) },
+	{ "CPU 2 Heatsink Temperature (TC1H)", SMC_KEY(TC1H) },
+	{ "CPU 2 Package Alt. Temperature (TCBD)", SMC_KEY(TCBD) },
+	{ "CPU 2 Package Temperature (TC1D)", SMC_KEY(TC1D) },
+	{ "CPU 2 Proximity Raw Temperature (TC1p)", SMC_KEY(TC1p) },
+	{ "CPU Core 0 Absolute Raw Temperature PECI (TC0c)", SMC_KEY(TC0c) },
+	{ "CPU Core 1 Absolute Cooked Temperature PECI (TC1C)", SMC_KEY(TC1C) },
+	{ "CPU Core 1 Absolute Raw Temperature PECI (TC1c)", SMC_KEY(TC1c) },
+	{ "CPU Core 2 Absolute Cooked Temperature PECI (TC2C)", SMC_KEY(TC2C) },
+	{ "CPU Core 2 Absolute Raw Temperature PECI (TC2c)", SMC_KEY(TC2c) },
+	{ "CPU Core 3 Absolute Cooked Temperature PECI (TC3C)", SMC_KEY(TC3C) },
+	{ "CPU Core 3 Absolute Raw Temperature PECI (TC3c)", SMC_KEY(TC3c) },
+	{ "CPU Core 3 Temperature PECI (TC4C)", SMC_KEY(TC4C) },
+	{ "CPU Core 4 Absolute Raw Temperature PECI (TC4c)", SMC_KEY(TC4c) },
+	{ "CPU Core 5 Absolute Raw Temperature PECI (TC5c)", SMC_KEY(TC5c) },
+	{ "CPU Core 6 Absolute Raw Temperature PECI (TC6c)", SMC_KEY(TC6c) },
+	{ "CPU Core 7 Absolute Raw Temperature PECI (TC7c)", SMC_KEY(TC7c) },
+	{ "CPU Core 8 Absolute Raw Temperature PECI (TC8c)", SMC_KEY(TC8c) },
+	{ "CPU Core 9 Absolute Raw Temperature PECI (TC9c)", SMC_KEY(TC9c) },
+	{ "CPU Core PECI Temperature (TC0C)", SMC_KEY(TC0C) },
+	{ "CPU Die Raw Temperature (TC0d)", SMC_KEY(TC0d) },
+	{ "CPU Die Temperature (TC0D)", SMC_KEY(TC0D) },
+	{ "CPU eDRAM Hot Indicator PECI (TCMc)", SMC_KEY(TCMc) },
+	{ "CPU Gfx Core Absolute Cooked Temperature PECI (TCGC)", SMC_KEY(TCGC) },
+	{ "CPU Gfx Core Absolute Raw Temperature PECI (TCGc)", SMC_KEY(TCGc) },
+	{ "CPU Heatpipe Temperature (Th0H)", SMC_KEY(Th0H) },
+	{ "CPU Max Package Core Absolute Cooked Temperature PECI (TCXC)", SMC_KEY(TCXC) },
+	{ "CPU Max Package Core Absolute Raw Temperature PECI (TCXc)", SMC_KEY(TCXc) },
+	{ "CPU Max Package Core Relative Cooked Temperature PECI (TCXR)", SMC_KEY(TCXR) },
+	{ "CPU Max Package Core Relative Raw Temperature PECI (TCXr)", SMC_KEY(TCXr) },
+	{ "CPU PECI Die Filtered And Adjusted Temperature (TC0F)", SMC_KEY(TC0F) },
+	{ "CPU PECI Die Filtered Temperature (TC0E)", SMC_KEY(TC0E) },
+	{ "CPU PECI Die Temperature Adjustment (TC0G)", SMC_KEY(TC0G) },
+	{ "CPU PECI Die Temperature Filter Coeff (TCFC)", SMC_KEY(TCFC) },
+	{ "CPU PECI Die Temperature Max Error (TC0J)", SMC_KEY(TC0J) },
+	{ "CPU PECI Die Temperature Trend (TC0T)", SMC_KEY(TC0T) },
+	{ "CPU PECI Die Temperature Trend (TCTD)", SMC_KEY(TCTD) },
+	{ "CPU Proximity Raw Temperature (TC0p)", SMC_KEY(TC0p) },
+	{ "CPU Proximity Temperature (TC0P)", SMC_KEY(TC0P) },
+	{ "CPU Relative To ProcHot 1 (TCAC)", SMC_KEY(TCAC) },
+	{ "CPU Relative To ProcHot 2 (TCBC)", SMC_KEY(TCBC) },
+	{ "CPU System Agent Core Absolute Cooked Temperature PECI (TCSC)", SMC_KEY(TCSC) },
+	{ "CPU System Agent Core Absolute Raw Temperature PECI (TCSc)", SMC_KEY(TCSc) },
+	{ "CPU System Agent Core Temperature PECI (TCSA)", SMC_KEY(TCSA) },
+	{ "CPU VR Proximity Cooked Temperature (TC1P)", SMC_KEY(TC1P) },
+	{ "DCIn Air Flow Adjusted Temperature (TaSP)", SMC_KEY(TaSP) },
+	{ "DCIn Air Flow Temperature (Ta0P)", SMC_KEY(Ta0P) },
+	{ "DIMM 0 PECI Cooked Temperature (TM0D)", SMC_KEY(TM0D) },
+	{ "DIMM 0 Proximity Raw Temperature (TM0p)", SMC_KEY(TM0p) },
+	{ "DIMM 1 PECI Cooked Temperature (TM1D)", SMC_KEY(TM1D) },
+	{ "DIMM 1 Proximity Cooked Temperature (TM1P)", SMC_KEY(TM1P) },
+	{ "DIMM 1 Proximity Raw Temperature (TM1p)", SMC_KEY(TM1p) },
+	{ "DIMM 2 PECI Cooked Temperature (TM2D)", SMC_KEY(TM2D) },
+	{ "DIMM 2 Proximity Cooked Temperature (TM2P)", SMC_KEY(TM2P) },
+	{ "DIMM 2 Proximity Raw Temperature (TM2p)", SMC_KEY(TM2p) },
+	{ "DIMM 3 PECI Cooked Temperature (TM3D)", SMC_KEY(TM3D) },
+	{ "DIMM 3 Proximity Cooked Temperature (TM3P)", SMC_KEY(TM3P) },
+	{ "DIMM 3 Proximity Raw Temperature (TM3p)", SMC_KEY(TM3p) },
+	{ "DIMM Bandwidth Estimate (TMBS)", SMC_KEY(TMBS) },
+	{ "DIMM Max Cooked Temperature (TMXD)", SMC_KEY(TMXD) },
+	{ "DIMM Proximity Max Cooked Temperature (TMXP)", SMC_KEY(TMXP) },
+	{ "DIMM Virtual Temperature (TM0V)", SMC_KEY(TM0V) },
+	{ "DIMM Virtual Temperature For 2x DIMM Slot 1+2 Or 2+3 Config (TM2b)", SMC_KEY(TM2b) },
+	{ "DIMM Virtual Temperature For 2x DIMM Slot 1+2+3+4 Config (TM1a)", SMC_KEY(TM1a) },
+	{ "DIMM Virtual Temperature For 2x DIMM Slot 1+3 Config (TM2a)", SMC_KEY(TM2a) },
+	{ "DIMM Virtual Temperature For 2x DIMM Slot 1+4 Or 2+4 Config (TM2c)", SMC_KEY(TM2c) },
+	{ "DIMM Virtual Temperature For 2x DIMM Slot 3+4 Config (TM2d)", SMC_KEY(TM2d) },
+	{ "DIMM Virtual Temperature For 3x DIMM Slot 1+2+3 Config (TM3d)", SMC_KEY(TM3d) },
+	{ "DIMM Virtual Temperature For 3x DIMM Slot 1+2+4 Config (TM3c)", SMC_KEY(TM3c) },
+	{ "DIMM Virtual Temperature For 3x DIMM Slot 1+3+4 Config (TM3b)", SMC_KEY(TM3b) },
+	{ "DIMM Virtual Temperature For 3x DIMM Slot 2+3+4 Config (TM3a)", SMC_KEY(TM3a) },
+	{ "DIMM Virtual Temperature For 4x DIMM Slot 1+2+3+4 Config (TM4a)", SMC_KEY(TM4a) },
+	{ "Drive 0 Backup Virtual DRAM Temperature (TH0V)", SMC_KEY(TH0V) },
+	{ "Drive 0 OOBv1 Mapped Temperature (TH0O)", SMC_KEY(TH0O) },
+	{ "Drive 0 OOBv1 Raw Bit-Mapped Temperature (TH0o)", SMC_KEY(TH0o) },
+	{ "Drive 0 OOBv3 Absolute Cooked Temperature A (TH0A)", SMC_KEY(TH0A) },
+	{ "Drive 0 OOBv3 Absolute Cooked Temperature B (TH0B)", SMC_KEY(TH0B) },
+	{ "Drive 0 OOBv3 Absolute Cooked Temperature C (TH0C)", SMC_KEY(TH0C) },
+	{ "Drive 0 OOBv3 Absolute Raw Temperature A (TH0a)", SMC_KEY(TH0a) },
+	{ "Drive 0 OOBv3 Absolute Raw Temperature B (TH0b)", SMC_KEY(TH0b) },
+	{ "Drive 0 OOBv3 Absolute Raw Temperature C (TH0c)", SMC_KEY(TH0c) },
+	{ "Drive 0 OOBv3 Raw Temperature Max (TH0x)", SMC_KEY(TH0x) },
+	{ "Drive 0 OOBv3 Relative Cooked Temperature Max (TH0R)", SMC_KEY(TH0R) },
+	{ "Drive 0 OOBv3 Relative Filtered Temperature Max (TH0F)", SMC_KEY(TH0F) },
+	{ "Drive 0 Temperature Sensor Existence Used For TM0V (TH0e)", SMC_KEY(TH0e) },
+	{ "Drive 1 OOBv1 Filtered Temperature (TH1P)", SMC_KEY(TH1P) },
+	{ "Drive 1 OOBv1 Mapped Temperature (TH1O)", SMC_KEY(TH1O) },
+	{ "Drive 1 OOBv1 Raw Bit-Mapped Temperature (TH1o)", SMC_KEY(TH1o) },
+	{ "Drive 1 OOBv3 Absolute Cooked Temperature A (TH1A)", SMC_KEY(TH1A) },
+	{ "Drive 1 OOBv3 Absolute Cooked Temperature B (TH1B)", SMC_KEY(TH1B) },
+	{ "Drive 1 OOBv3 Absolute Cooked Temperature C (TH1C)", SMC_KEY(TH1C) },
+	{ "Drive 1 OOBv3 Absolute Raw Temperature A (TH1a)", SMC_KEY(TH1a) },
+	{ "Drive 1 OOBv3 Absolute Raw Temperature B (TH1b)", SMC_KEY(TH1b) },
+	{ "Drive 1 OOBv3 Absolute Raw Temperature C (TH1c)", SMC_KEY(TH1c) },
+	{ "Drive 1 OOBv3 Relative Cooked Temperature Max (TH1R)", SMC_KEY(TH1R) },
+	{ "Drive 1 OOBv3 Relative Filtered Temperature Max (TH1F)", SMC_KEY(TH1F) },
+	{ "EMC1428 Internal Diode Raw Temperature (Tm0p)", SMC_KEY(Tm0p) },
+	{ "Expansion Slots Temperature (TS0C)", SMC_KEY(TS0C) },
+	{ "Fan 0 Synthetic Temperature (TF0S)", SMC_KEY(TF0S) },
+	{ "Fan Target Temperature (TTF0)", SMC_KEY(TTF0) },
+	{ "Filtered Power Supply 1 Proximity Temperature (TpFP)", SMC_KEY(TpFP) },
+	{ "Filtered Vent Proximity Temperature (TVFP)", SMC_KEY(TVFP) },
+	{ "Fin Stack Temperature (THFH)", SMC_KEY(THFH) },
+	{ "GFX 0 Memory Temperature (TG0M)", SMC_KEY(TG0M) },
+	{ "GPU 0 Die Cooked Temperature (TG0D)", SMC_KEY(TG0D) },
+	{ "GPU 0 Die Filtered And Adjusted Temperature (TG0F)", SMC_KEY(TG0F) },
+	{ "GPU 0 Die Filtered Temperature (TG0E)", SMC_KEY(TG0E) },
+	{ "GPU 0 Die Raw Temperature (TG0d)", SMC_KEY(TG0d) },
+	{ "GPU 0 Die Temperature Max Error (TG0J)", SMC_KEY(TG0J) },
+	{ "GPU 0 Die Temperature Trend (TG0T)", SMC_KEY(TG0T) },
+	{ "GPU 0 Proximity Cooked Temperature (TG0P)", SMC_KEY(TG0P) },
+	{ "GPU 0 Proximity Raw Temperature (TG0p)", SMC_KEY(TG0p) },
+	{ "GPU AMD Die Digital Temperature (TGDD)", SMC_KEY(TGDD) },
+	{ "GPU B VR Proximity Cooked Temperature (TG5P)", SMC_KEY(TG5P) },
+	{ "GPU B VRAM Proximity Cooked Temperature (TG4P)", SMC_KEY(TG4P) },
+	{ "GPU Die Analog Temperature (TGDF)", SMC_KEY(TGDF) },
+	{ "GPU Digital Die Filtered Temperature (TG1F)", SMC_KEY(TG1F) },
+	{ "GPU Digital Die Raw Temperature Without Offset (TG1d)", SMC_KEY(TG1d) },
+	{ "GPU Digital Die Temperature (TG1D)", SMC_KEY(TG1D) },
+	{ "GPU FB VR Proximity 3 Cooked Temperature (TG3P)", SMC_KEY(TG3P) },
+	{ "GPU FB VR Proximity 3 Raw Temperature (TG3p)", SMC_KEY(TG3p) },
+	{ "GPU GDDR5 Proximity 1 Cooked Temperature (TG1P)", SMC_KEY(TG1P) },
+	{ "GPU GDDR5 Proximity 1 Raw Temperature (TG1p)", SMC_KEY(TG1p) },
+	{ "GPU VR Proximity 2 Cooked Temperature (TG2P)", SMC_KEY(TG2P) },
+	{ "GPU VR Proximity 2 Raw Temperature (TG2p)", SMC_KEY(TG2p) },
+	{ "GPU VR Temperature (TGVP)", SMC_KEY(TGVP) },
+	{ "GFX 1 Memory Temperature (TJ0M)", SMC_KEY(TJ0M) },
+	{ "GPU 1 Die Cooked Temperature (TJ0D)", SMC_KEY(TJ0D) },
+	{ "GPU 1 Die Filtered And Adjusted Temperature (TJ0F)", SMC_KEY(TJ0F) },
+	{ "GPU 1 Die Filtered Temperature (TJ0E)", SMC_KEY(TJ0E) },
+	{ "GPU 1 Die Raw Temperature (TJ0d)", SMC_KEY(TJ0d) },
+	{ "GPU 1 Die Temperature Max Error (TJ0J)", SMC_KEY(TJ0J) },
+	{ "GPU 1 Die Temperature Trend (TJ0T)", SMC_KEY(TJ0T) },
+	{ "GPU 1 Proximity Cooked Temperature (TJ0P)", SMC_KEY(TJ0P) },
+	{ "GPU 1 Proximity Raw Temperature (TJ0p)", SMC_KEY(TJ0p) },
+	{ "GPU 1 AMD Die Digital Temperature (TJDD)", SMC_KEY(TJDD) },
+	{ "GPU 1 VR Proximity Cooked Temperature (TJ5P)", SMC_KEY(TJ5P) },
+	{ "GPU 1 VRAM Proximity Cooked Temperature (TJ4P)", SMC_KEY(TJ4P) },
+	{ "GPU 1 Die Analog Temperature (TJDF)", SMC_KEY(TJDF) },
+	{ "GPU 1 Digital Die Filtered Temperature (TJ1F)", SMC_KEY(TJ1F) },
+	{ "GPU 1 Digital Die Raw Temperature Without Offset (TJ1d)", SMC_KEY(TJ1d) },
+	{ "GPU 1 Digital Die Temperature (TJ1D)", SMC_KEY(TJ1D) },
+	{ "GPU 1 FB VR Proximity 3 Cooked Temperature (TJ3P)", SMC_KEY(TJ3P) },
+	{ "GPU 1 FB VR Proximity 3 Raw Temperature (TJ3p)", SMC_KEY(TJ3p) },
+	{ "GPU 1 GDDR5 Proximity 1 Cooked Temperature (TJ1P)", SMC_KEY(TJ1P) },
+	{ "GPU 1 GDDR5 Proximity 1 Raw Temperature (TJ1p)", SMC_KEY(TJ1p) },
+	{ "GPU 1 VR Proximity 2 Cooked Temperature (TJ2P)", SMC_KEY(TJ2P) },
+	{ "GPU 1 VR Proximity 2 Raw Temperature (TJ2p)", SMC_KEY(TJ2p) },
+	{ "GPU 1 VR Temperature (TJVP)", SMC_KEY(TJVP) },
+	{ "HDD Bay 3 Temperature (TH2P)", SMC_KEY(TH2P) },
+	{ "HDD Bay 4 Temperature (TH3P)", SMC_KEY(TH3P) },
+	{ "HDD Proximity Temperature (TH0P)", SMC_KEY(TH0P) },
+	{ "Heat Pipe Temperature (TG0H)", SMC_KEY(TG0H) },
+	{ "Heat Pipe Temperature 2 (TG1H)", SMC_KEY(TG1H) },
+	{ "Heat Spreader Proximity Temperature (Th0P)", SMC_KEY(Th0P) },
+	{ "High Speed I/O Proximity 0 Temperature (TI0P)", SMC_KEY(TI0P) },
+	{ "High Speed I/O Proximity 1 Temperature (TI1P)", SMC_KEY(TI1P) },
+	{ "LCD Filtered Center Front-Of-Screen Temperature Feeding TL1V (TL1v)", SMC_KEY(TL1v) },
+	{ "LCD Filtered Center Front-Of-Screen Temperature For Color Compensation (TL1V)", SMC_KEY(TL1V) },
+	{ "LCD Filtered Front-Of-Screen Hotspot Virtual Temperature (TL0V)", SMC_KEY(TL0V) },
+	{ "LCD IR Target Hotspot Calculated Temperature (TL2p)", SMC_KEY(TL2p) },
+	{ "LCD IR Temperature Sensor Die Raw Temperature (TL3p)", SMC_KEY(TL3p) },
+	{ "LCD TCON Proximity Cooked Temperature (TL1P)", SMC_KEY(TL1P) },
+	{ "LCD TCON Proximity Raw Temperature (TL1p)", SMC_KEY(TL1p) },
+	{ "LCD Unfiltered Front-Of-Screen Cooked Temperature (TL0P)", SMC_KEY(TL0P) },
+	{ "LCD Unfiltered Front-Of-Screen Raw Temperature (TL0p)", SMC_KEY(TL0p) },
+	{ "Left Fin Stack Temperature (Th2H)", SMC_KEY(Th2H) },
+	{ "Max PECI Reported Temperature (TCMX)", SMC_KEY(TCMX) },
+	{ "MCH Diode Temperature (TN0C)", SMC_KEY(TN0C) },
+	{ "MCH Heatsink Temperature (TN0H)", SMC_KEY(TN0H) },
+	{ "MCP Die 2 Temperature (TN1D)", SMC_KEY(TN1D) },
+	{ "MCP Die Temperature (TN0D)", SMC_KEY(TN0D) },
+	{ "MCP Proximity Temperature (TN0P)", SMC_KEY(TN0P) },
+	{ "Mem Bank B1 Temperature (TM8P)", SMC_KEY(TM8P) },
+	{ "Mem Bank B2 Temperature (TM9P)", SMC_KEY(TM9P) },
+	{ "Mem Module A2 Temperature (TM1S)", SMC_KEY(TM1S) },
+	{ "Mem Module A3 Temperature (TM2S)", SMC_KEY(TM2S) },
+	{ "Mem Module A4 Temperature (TM3S)", SMC_KEY(TM3S) },
+	{ "Mem Module B1 Temperature (TM8S)", SMC_KEY(TM8S) },
+	{ "Mem Module B2 Temperature (TM9S)", SMC_KEY(TM9S) },
+	{ "Memory Controller/Integrated Graphics PECI Temperature (TMCD)", SMC_KEY(TMCD) },
+	{ "Memory Proximity Temperature (TM0P)", SMC_KEY(TM0P) },
+	{ "MLB Bottom Side Temperature (Tm1P)", SMC_KEY(Tm1P) },
+	{ "MLB Proximity 0 Cooked Temperature (Tm0P)", SMC_KEY(Tm0P) },
+	{ "MLB Proximity 1 Raw Temperature (Tm1p)", SMC_KEY(Tm1p) },
+	{ "MLB Proximity 2 Cooked Temperature (Tm2P)", SMC_KEY(Tm2P) },
+	{ "MLB Proximity 2 Raw Temperature (Tm2p)", SMC_KEY(Tm2p) },
+	{ "MLB Proximity Temperature (TMLB)", SMC_KEY(TMLB) },
+	{ "MLB Temperature (Tp0P)", SMC_KEY(Tp0P) },
+	{ "NAND Temperature (Th0N)", SMC_KEY(Th0N) },
+	{ "Northbridge 2 Temperature (TN1P)", SMC_KEY(TN1P) },
+	{ "Optical Drive Temperature (TO0P)", SMC_KEY(TO0P) },
+	{ "Palm Rest Temperature (Ts0P)", SMC_KEY(Ts0P) },
+	{ "Palm Rest Temperature 2 (Ts1P)", SMC_KEY(Ts1P) },
+	{ "PCH Die Cooked Temperature (TPCD)", SMC_KEY(TPCD) },
+	{ "PCH Digital Die Raw Temperature (TPCd)", SMC_KEY(TPCd) },
+	{ "PCH Diode Temperature (TP0D)", SMC_KEY(TP0D) },
+	{ "PCH Proximity Temperature (TP0P)", SMC_KEY(TP0P) },
+	{ "PCI Slot 1 Pos 1 Temperature (TA0S)", SMC_KEY(TA0S) },
+	{ "PCI Slot 1 Pos 2 Temperature (TA1S)", SMC_KEY(TA1S) },
+	{ "PCI Slot 2 Pos 1 Temperature (TA2S)", SMC_KEY(TA2S) },
+	{ "PCI Slot 2 Pos 2 Temperature (TA3S)", SMC_KEY(TA3S) },
+	{ "Power Supply 1 Alt. Temperature (Tp0C)", SMC_KEY(Tp0C) },
+	{ "Power Supply 2 Alt. Temperature (Tp1C)", SMC_KEY(Tp1C) },
+	{ "Power Supply 3 Temperature (Tp2P)", SMC_KEY(Tp2P) },
+	{ "Power Supply 4 Temperature (Tp3P)", SMC_KEY(Tp3P) },
+	{ "Power Supply 5 Temperature (Tp4P)", SMC_KEY(Tp4P) },
+	{ "Power Supply 6 Temperature (Tp5P)", SMC_KEY(Tp5P) },
+	{ "Power Supply T2 Secondary Heatsink Cooked Temperature (Tp2H)", SMC_KEY(Tp2H) },
+	{ "Power Supply T2 Secondary Heatsink Filtered Temperature (Tp2F)", SMC_KEY(Tp2F) },
+	{ "Power Supply T2 Secondary Heatsink Raw Temperature (Tp2h)", SMC_KEY(Tp2h) },
+	{ "PSU Secondary Heatsink Diode Cooked Temperature (Tp0T)", SMC_KEY(Tp0T) },
+	{ "Right Fin Stack Temperature (Th1H)", SMC_KEY(Th1H) },
+	{ "RIO Temperature (Th0R)", SMC_KEY(Th0R) },
+	{ "S2 Camera Proximity Temperature (TS2P)", SMC_KEY(TS2P) },
+	{ "Secondary Power Supply Proximity Temperature (Tp1P)", SMC_KEY(Tp1P) },
+	{ "Skin 0 Raw Temperature (TS0p)", SMC_KEY(TS0p) },
+	{ "Skin 0 Virtual Temperature (TS0V)", SMC_KEY(TS0V) },
+	{ "Speaker Proximity 2 Temperature (TS1P)", SMC_KEY(TS1P) },
+	{ "Speaker Proximity Temperature (TS0P)", SMC_KEY(TS0P) },
+	{ "Speaker Remote 2 Temperature (TS1D)", SMC_KEY(TS1D) },
+	{ "Speaker Remote Temperature (TS0D)", SMC_KEY(TS0D) },
+	{ "SSD 0 OOBv3 Cooked Temperature Max (TH0X)", SMC_KEY(TH0X) },
+	{ "SSD 1 OOBv3 Cooked Temperature Max (TH1X)", SMC_KEY(TH1X) },
+	{ "Synthetic Bottom Skin Temperature (Ts0S)", SMC_KEY(Ts0S) },
+	{ "Synthetic DIMM Estimate (TM0S)", SMC_KEY(TM0S) },
+	{ "Synthetic Top Skin Temperature (Ts1S)", SMC_KEY(Ts1S) },
+	{ "TBT Proximity Raw Temperature (TI0p)", SMC_KEY(TI0p) },
+	{ "TBT Thermal Diode Raw Temperature (Te0t)", SMC_KEY(Te0t) },
+	{ "TBT Thermal Diode Temperature (Te0T)", SMC_KEY(Te0T) },
+	{ "Thermal Trap Hysteresis (TsTH)", SMC_KEY(TsTH) },
+	{ "Thermal Trap Threshold (TsTP)", SMC_KEY(TsTP) },
+	{ "Thermal Warning Hysteresis (TsHS)", SMC_KEY(TsHS) },
+	{ "Thermal Warning Threshold (TsWS)", SMC_KEY(TsWS) },
+	{ "Thunderbolt Die Temperature (THSP)", SMC_KEY(THSP) },
+	{ "Thunderbolt L Temperature (TTLD)", SMC_KEY(TTLD) },
+	{ "Thunderbolt Proximity Cooked Temperature (TI0T)", SMC_KEY(TI0T) },
+	{ "Thunderbolt R Temperature (TTRD)", SMC_KEY(TTRD) },
+	{ "Touchpad Temperature (Ts2S)", SMC_KEY(Ts2S) },
+	{ "Vent Proximity Temperature (TV0P)", SMC_KEY(TV0P) },
+	{ "WiFi Proximity Raw Temperature (TW0p)", SMC_KEY(TW0p) },
+	{ "Wireless Proximity Temperature (TW0P)", SMC_KEY(TW0P) },
+};
+
+static const struct macsmc_sensor_desc power_sensors[] = {
+	{ "12 V Rail (Pp0R)", SMC_KEY(Pp0R) },
+	{ "2nd GPU Plimit (MSTi)", SMC_KEY(MSTi) },
+	{ "3.3V In S0 Power (PR3C)", SMC_KEY(PR3C) },
+	{ "3.3V S0 Power (PR0C)", SMC_KEY(PR0C) },
+	{ "3.3V S3 Power (PR1C)", SMC_KEY(PR1C) },
+	{ "3.3V S5 Power (PR5C)", SMC_KEY(PR5C) },
+	{ "5V Lowside Power (P50R)", SMC_KEY(P50R) },
+	{ "A8 Load-Side Rail (PA8C)", SMC_KEY(PA8C) },
+	{ "Audio ScratchPad Register (MST1)", SMC_KEY(MST1) },
+	{ "Audio ScratchPad2 Register (MST2)", SMC_KEY(MST2) },
+	{ "Average Main Chipset Power (Pc0R)", SMC_KEY(Pc0R) },
+	{ "Battery Rail (PB0R)", SMC_KEY(PB0R) },
+	{ "Battery Rail (PBLC)", SMC_KEY(PBLC) },
+	{ "BL Rail 12 V (PBLR)", SMC_KEY(PBLR) },
+	{ "Chipset IMon Power (PCS1)", SMC_KEY(PCS1) },
+	{ "Chipset Lowside Power (PCS0)", SMC_KEY(PCS0) },
+	{ "CPU 1V5 Power (PD1R)", SMC_KEY(PD1R) },
+	{ "CPU Core (PCAC)", SMC_KEY(PCAC) },
+	{ "CPU Core 1 (PC0C)", SMC_KEY(PC0C) },
+	{ "CPU Core 2 (PC1C)", SMC_KEY(PC1C) },
+	{ "CPU Core 3 (PC2C)", SMC_KEY(PC2C) },
+	{ "CPU Core 4 (PC3C)", SMC_KEY(PC3C) },
+	{ "CPU Core 5 (PC4C)", SMC_KEY(PC4C) },
+	{ "CPU Core 6 (PC5C)", SMC_KEY(PC5C) },
+	{ "CPU Core 7 (PC6C)", SMC_KEY(PC6C) },
+	{ "CPU Core 8 (PC7C)", SMC_KEY(PC7C) },
+	{ "CPU Core IMON (PCAM)", SMC_KEY(PCAM) },
+	{ "CPU Cores (PCPC)", SMC_KEY(PCPC) },
+	{ "CPU DRAM (PCPD)", SMC_KEY(PCPD) },
+	{ "CPU GFX (PCPG)", SMC_KEY(PCPG) },
+	{ "CPU High-Side Average (PC0R)", SMC_KEY(PC0R) },
+	{ "CPU I/O High-Side (PC0I)", SMC_KEY(PC0I) },
+	{ "CPU I/O High-Side 2 (PC0M)", SMC_KEY(PC0M) },
+	{ "CPU I/O Load-Side Rail (PCIC)", SMC_KEY(PCIC) },
+	{ "CPU Integrated GPU (PC0G)", SMC_KEY(PC0G) },
+	{ "CPU Package Total PECI (PCPT)", SMC_KEY(PCPT) },
+	{ "CPU Package Total Power SMC (PCPR)", SMC_KEY(PCPR) },
+	{ "CPU Package Total Power SMC Load Sensors (PCLT)", SMC_KEY(PCLT) },
+	{ "CPU Plimit (MSTc)", SMC_KEY(MSTc) },
+	{ "CPU Rail (PC1R)", SMC_KEY(PC1R) },
+	{ "CPU Raw Package (PC0c)", SMC_KEY(PC0c) },
+	{ "CPU S0 Rail (PC5R)", SMC_KEY(PC5R) },
+	{ "CPU System Agent (PC0S)", SMC_KEY(PC0S) },
+	{ "CPU Total (PCPL)", SMC_KEY(PCPL) },
+	{ "CPU Total (PCTR)", SMC_KEY(PCTR) },
+	{ "CPU VccEDRAM (PCEC)", SMC_KEY(PCEC) },
+	{ "CPU VCCSA (PCSC)", SMC_KEY(PCSC) },
+	{ "CT Load-Side Rail (PCTC)", SMC_KEY(PCTC) },
+	{ "DC-In MLB S5 Rail (PD5R)", SMC_KEY(PD5R) },
+	{ "DC-In MLB Total (PDMR)", SMC_KEY(PDMR) },
+	{ "DDR (PM1C)", SMC_KEY(PM1C) },
+	{ "DDR Power 1.8V CPU (PM2C)", SMC_KEY(PM2C) },
+	{ "DDR S3 Power (PM3C)", SMC_KEY(PM3C) },
+	{ "DIMM Load-Side Power Per Fan RPM Squared (PM0f)", SMC_KEY(PM0f) },
+	{ "Discrete BMON On Battery Power (PB1R)", SMC_KEY(PB1R) },
+	{ "Drive 0 (PH0R)", SMC_KEY(PH0R) },
+	{ "Drive 0 Filtered Total Power (PH0F)", SMC_KEY(PH0F) },
+	{ "Drive 1 (PH1R)", SMC_KEY(PH1R) },
+	{ "Drive 1 Filtered Power (PH1F)", SMC_KEY(PH1F) },
+	{ "Drive 2 Power (PH2R)", SMC_KEY(PH2R) },
+	{ "External GPU 1.05 V (PG2C)", SMC_KEY(PG2C) },
+	{ "External GPU 1.35 V (PG3C)", SMC_KEY(PG3C) },
+	{ "External GPU 1.8 V (PG1C)", SMC_KEY(PG1C) },
+	{ "External GPU Rail 4 (PG4C)", SMC_KEY(PG4C) },
+	{ "F3 Load-Side Rail (PF3C)", SMC_KEY(PF3C) },
+	{ "Forced Idle Limit (MSTf)", SMC_KEY(MSTf) },
+	{ "GFX B Total Power (PG1R)", SMC_KEY(PG1R) },
+	{ "GPU (PG0C)", SMC_KEY(PG0C) },
+	{ "GPU 0 Rail (PG0R)", SMC_KEY(PG0R) },
+	{ "GPU 2 Rail (PG2R)", SMC_KEY(PG2R) },
+	{ "GPU A VDDCI Low Side Power (PG0S)", SMC_KEY(PG0S) },
+	{ "GPU Aux Input-Side Power (PG1A)", SMC_KEY(PG1A) },
+	{ "GPU Aux Load-Side Power (PG0A)", SMC_KEY(PG0A) },
+	{ "GPU B VDDCI Low Side Power (PG1S)", SMC_KEY(PG1S) },
+	{ "GPU Frame Buffer Input-Side Power (PG0F)", SMC_KEY(PG0F) },
+	{ "GPU Frame Buffer Input-Side Power (PG1F)", SMC_KEY(PG1F) },
+	{ "GPU Mem Ctl Load-Side Power (PG0M)", SMC_KEY(PG0M) },
+	{ "GPU Package Total Power SMC (PGPR)", SMC_KEY(PGPR) },
+	{ "GPU Plimit (MSTg)", SMC_KEY(MSTg) },
+	{ "GPU Total (PGTR)", SMC_KEY(PGTR) },
+	{ "GPU Uncore High-Side Power (PG0U)", SMC_KEY(PG0U) },
+	{ "GPU VDDCI Load-Side Power (PG0I)", SMC_KEY(PG0I) },
+	{ "GPU VRAM Load-Side Power (PG0V)", SMC_KEY(PG0V) },
+	{ "Heatpipe (PHPC)", SMC_KEY(PHPC) },
+	{ "HP Power Target (PTHC)", SMC_KEY(PTHC) },
+	{ "HP Power Throttle (MSLT)", SMC_KEY(MSLT) },
+	{ "I/O Board Total Power (PI0R)", SMC_KEY(PI0R) },
+	{ "Intel GPU IMON (PCGC)", SMC_KEY(PCGC) },
+	{ "Intel GPU IMON 2 (PCGM)", SMC_KEY(PCGM) },
+	{ "LCD Panel (PLDC)", SMC_KEY(PLDC) },
+	{ "Left Thunderbolt/I/O Rail (POLR)", SMC_KEY(POLR) },
+	{ "Left USB-C Load-Side Rail (PULC)", SMC_KEY(PULC) },
+	{ "Main 3.3 V Rail (PH02)", SMC_KEY(PH02) },
+	{ "Main 5 V Rail (PH05)", SMC_KEY(PH05) },
+	{ "MC Load-Side Rail (PMCC)", SMC_KEY(PMCC) },
+	{ "MCH (PN0C)", SMC_KEY(PN0C) },
+	{ "MCP Memory Power (PN1C)", SMC_KEY(PN1C) },
+	{ "MCP VCore Power (PN0R)", SMC_KEY(PN0R) },
+	{ "MEM Plimit (MSTm)", SMC_KEY(MSTm) },
+	{ "Memory Average (PM0C)", SMC_KEY(PM0C) },
+	{ "Memory Power (PZDM)", SMC_KEY(PZDM) },
+	{ "Memory Rail (PM0R)", SMC_KEY(PM0R) },
+	{ "Memory Total Power (PMTR)", SMC_KEY(PMTR) },
+	{ "Misc. Rail (PO0R)", SMC_KEY(PO0R) },
+	{ "ODD Power (PZOD)", SMC_KEY(PZOD) },
+	{ "Other 3.3V High Side Power (PO3R)", SMC_KEY(PO3R) },
+	{ "Other 5 V High-Side (PO5R)", SMC_KEY(PO5R) },
+	{ "PBus (PP0R)", SMC_KEY(PP0R) },
+	{ "PBus Battery Discharge (PPBR)", SMC_KEY(PPBR) },
+	{ "PCH Core Power (PSBC)", SMC_KEY(PSBC) },
+	{ "PCH Rail (PN1R)", SMC_KEY(PN1R) },
+	{ "Power Supply Filter Coefficient (PD0K)", SMC_KEY(PD0K) },
+	{ "Power Supply Filtered Power (PD0E)", SMC_KEY(PD0E) },
+	{ "Power Supply Max Error Filtered Output (PD0J)", SMC_KEY(PD0J) },
+	{ "Power Supply Power Filtered Then Adjusted (PD0F)", SMC_KEY(PD0F) },
+	{ "Power Supply Power Trend (PD0D)", SMC_KEY(PD0D) },
+	{ "Power Zone AP (PZAP)", SMC_KEY(PZAP) },
+	{ "Power Zone Backlight (PZBL)", SMC_KEY(PZBL) },
+	{ "Power Zone Storage (PZHD)", SMC_KEY(PZHD) },
+	{ "Right Thunderbolt/I/O Rail (PORR)", SMC_KEY(PORR) },
+	{ "Right USB-C Load-Side Rail (PURC)", SMC_KEY(PURC) },
+	{ "S0 5.0V Power (PR0R)", SMC_KEY(PR0R) },
+	{ "S1 Load-Side Rail (PS1C)", SMC_KEY(PS1C) },
+	{ "S2 Camera Power (PCMC)", SMC_KEY(PCMC) },
+	{ "S2 Camera Power (PS2C)", SMC_KEY(PS2C) },
+	{ "S3 3.30V Power (PR1R)", SMC_KEY(PR1R) },
+	{ "S3 5.0V Power (PR2R)", SMC_KEY(PR2R) },
+	{ "S5 3.30V Power (PR3R)", SMC_KEY(PR3R) },
+	{ "SL Rail 3.3 V (PSLC)", SMC_KEY(PSLC) },
+	{ "SSD 3.3 V Load-Side Rail 0 (PH0C)", SMC_KEY(PH0C) },
+	{ "SSD 3.3 V Load-Side Rail 1 (PH1C)", SMC_KEY(PH1C) },
+	{ "SSD Power (PHDC)", SMC_KEY(PHDC) },
+	{ "SSD Power (PSDC)", SMC_KEY(PSDC) },
+	{ "System Total, 1 s Delayed (PSTR)", SMC_KEY(PSTR) },
+	{ "T101 Accuator Power (PTPC)", SMC_KEY(PTPC) },
+	{ "T25 Track Pad Power (PTPR)", SMC_KEY(PTPR) },
+	{ "Thunderbolt Power (PHSC)", SMC_KEY(PHSC) },
+	{ "Thunderbolt Power (PHSP)", SMC_KEY(PHSP) },
+	{ "WiFi (PAPC)", SMC_KEY(PAPC) },
+	{ "Wifi Load-Side Power (PW0R)", SMC_KEY(PW0R) },
+	{ "Heatpipe Average (PZ0G)", SMC_KEY(PZ0G) },
+	{ "Heatpipe Average Target (PZ0E)", SMC_KEY(PZ0E) },
+	{ "Heatpipe Filtered (PZ0F)", SMC_KEY(PZ0F) },
+	{ "Heatpipe Throttle (PZ0T)", SMC_KEY(PZ0T) },
+	{ "CPU Average (PZ1G)", SMC_KEY(PZ1G) },
+	{ "CPU Filtered (PZ1F)", SMC_KEY(PZ1F) },
+	{ "CPU Target (PZ1E)", SMC_KEY(PZ1E) },
+	{ "CPU Throttle (PZ1T)", SMC_KEY(PZ1T) },
+	{ "dGPU Average (PZ2G)", SMC_KEY(PZ2G) },
+	{ "dGPU Filtered (PZ2F)", SMC_KEY(PZ2F) },
+	{ "dGPU Target (PZ2E)", SMC_KEY(PZ2E) },
+	{ "dGPU Throttle (PZ2T)", SMC_KEY(PZ2T) },
+	{ "Batt aux Average (PZ3G)", SMC_KEY(PZ3G) },
+	{ "Batt aux Filtered (PZ3F)", SMC_KEY(PZ3F) },
+	{ "Batt aux Target (PZ3E)", SMC_KEY(PZ3E) },
+	{ "Batt aux Throttle (PZ3T)", SMC_KEY(PZ3T) },
+	{ "Battery Average (PZ4G)", SMC_KEY(PZ4G) },
+	{ "Battery Filtered (PZ4F)", SMC_KEY(PZ4F) },
+	{ "Battery Target (PZ4E)", SMC_KEY(PZ4E) },
+	{ "Battery Throttle (PZ4T)", SMC_KEY(PZ4T) },
+	{ "Zone 5 Abstract Throttle (PZ5T)", SMC_KEY(PZ5T) },
+	{ "Zone 5 Average Power (PZ5G)", SMC_KEY(PZ5G) },
+	{ "Zone 5 Filtered Power (PZ5F)", SMC_KEY(PZ5F) },
+	{ "Zone 5 Target Power (PZ5E)", SMC_KEY(PZ5E) },
+};
+
+static const struct macsmc_sensor_desc current_sensors[] = {
+	{ "3.3V S0 Current (IR0C)", SMC_KEY(IR0C) },
+	{ "3.3V S0 Current (IR3C)", SMC_KEY(IR3C) },
+	{ "5.0V S0 Current (IR5C)", SMC_KEY(IR5C) },
+	{ "5V Lowside Current (I50R)", SMC_KEY(I50R) },
+	{ "Airport Current (IZOP)", SMC_KEY(IZOP) },
+	{ "Backlight Current (IBLC)", SMC_KEY(IBLC) },
+	{ "Battery Current (IBAC)", SMC_KEY(IBAC) },
+	{ "Battery Current Discrete (IP0R)", SMC_KEY(IP0R) },
+	{ "Battery Discharge Current MLB (IB0R)", SMC_KEY(IB0R) },
+	{ "Camera S2 Current (ICMC)", SMC_KEY(ICMC) },
+	{ "CPU 1V5 Current (ID1R)", SMC_KEY(ID1R) },
+	{ "CPU And MEM Current (IM0C)", SMC_KEY(IM0C) },
+	{ "CPU AXG Low-Side Current (IC0G)", SMC_KEY(IC0G) },
+	{ "CPU Core Current (IC0C)", SMC_KEY(IC0C) },
+	{ "CPU Core Current (ICS0)", SMC_KEY(ICS0) },
+	{ "CPU Current From CPU IMON (ICS1)", SMC_KEY(ICS1) },
+	{ "CPU DDR Current (IC3C)", SMC_KEY(IC3C) },
+	{ "CPU DDR Current (IM1C)", SMC_KEY(IM1C) },
+	{ "CPU High Side Current (IC0R)", SMC_KEY(IC0R) },
+	{ "CPU High Side Current From EMC1704 (IC1R)", SMC_KEY(IC1R) },
+	{ "CPU I/O High-Side Current (IC0I)", SMC_KEY(IC0I) },
+	{ "CPU Mem Low-Side Current (IC0M)", SMC_KEY(IC0M) },
+	{ "CPU Riser 12V High Side Current (ICTR)", SMC_KEY(ICTR) },
+	{ "CPU VCCIO Current (IC1C)", SMC_KEY(IC1C) },
+	{ "CPU VCCSA Current (IC2C)", SMC_KEY(IC2C) },
+	{ "CPU VSA Low Side Current (IC0S)", SMC_KEY(IC0S) },
+	{ "CSreg Current (Ic0R)", SMC_KEY(Ic0R) },
+	{ "DDR S3 Current (IM3C)", SMC_KEY(IM3C) },
+	{ "DIMM Current (IZDM)", SMC_KEY(IZDM) },
+	{ "DIMM Load-Side Current (IM0R)", SMC_KEY(IM0R) },
+	{ "Discrete Battery Current (IPB1)", SMC_KEY(IPB1) },
+	{ "Drive 0 12V Load-Side Current (IH02)", SMC_KEY(IH02) },
+	{ "Drive 0 5V Load-Side Current (IH05)", SMC_KEY(IH05) },
+	{ "Drive 1 3.3V Load-Side Current (IH1R)", SMC_KEY(IH1R) },
+	{ "Ext GPU 1.05V Current (IG2C)", SMC_KEY(IG2C) },
+	{ "Ext GPU 1.35V Current (IG3C)", SMC_KEY(IG3C) },
+	{ "Ext GPU High Side Current (IG0R)", SMC_KEY(IG0R) },
+	{ "GFX B Riser 12V High Side Current (IG1R)", SMC_KEY(IG1R) },
+	{ "GFX Vcore Current (IN0R)", SMC_KEY(IN0R) },
+	{ "GPU A VDDCI Low Side Current (IG0S)", SMC_KEY(IG0S) },
+	{ "GPU Aux Input-Side Current (IG1A)", SMC_KEY(IG1A) },
+	{ "GPU B VDDCI Low Side Current (IG1S)", SMC_KEY(IG1S) },
+	{ "GPU Core Current (IG0C)", SMC_KEY(IG0C) },
+	{ "GPU Core Input-Side Current (IG1C)", SMC_KEY(IG1C) },
+	{ "GPU FB High-Side Current (IG0F)", SMC_KEY(IG0F) },
+	{ "GPU FB Input-Side Current (IG1F)", SMC_KEY(IG1F) },
+	{ "GPU Uncore High-Side Current (IG0U)", SMC_KEY(IG0U) },
+	{ "GPU VDDCI Load-Side Current (IG0I)", SMC_KEY(IG0I) },
+	{ "HDD Current (IZHD)", SMC_KEY(IZHD) },
+	{ "I/O Board 12V High Side Current (II0R)", SMC_KEY(II0R) },
+	{ "Internal GFX Core Current (IN0C)", SMC_KEY(IN0C) },
+	{ "LCD Backlight Current (IZBL)", SMC_KEY(IZBL) },
+	{ "LCD Panel Current (ILDC)", SMC_KEY(ILDC) },
+	{ "LPDDR Current 1.8V (IM2C)", SMC_KEY(IM2C) },
+	{ "MCP DDR Current (IN1C)", SMC_KEY(IN1C) },
+	{ "Memory 1V5 High Side Current (IMTR)", SMC_KEY(IMTR) },
+	{ "ODD Current (IODC)", SMC_KEY(IODC) },
+	{ "ODD Current (IZOD)", SMC_KEY(IZOD) },
+	{ "Other 3.3V High Side Current (IO3R)", SMC_KEY(IO3R) },
+	{ "Other 5V High Side Current (IO5R)", SMC_KEY(IO5R) },
+	{ "Other High Side Current (IO0R)", SMC_KEY(IO0R) },
+	{ "Other High Side Current (IR1C)", SMC_KEY(IR1C) },
+	{ "PBus On Battery Current (IPBR)", SMC_KEY(IPBR) },
+	{ "PCH 1V05 Current (IN1R)", SMC_KEY(IN1R) },
+	{ "PCH Core Current (ISBC)", SMC_KEY(ISBC) },
+	{ "PCH/GPU/TBT 1.05V High-Side Current (IR1R)", SMC_KEY(IR1R) },
+	{ "Power Supply 12V Current Dynamic Filter Coeff (ID2L)", SMC_KEY(ID2L) },
+	{ "Power Supply 12V Current Filter Input (ID2I)", SMC_KEY(ID2I) },
+	{ "Power Supply 12V Current Filtered (ID2E)", SMC_KEY(ID2E) },
+	{ "Power Supply 12V Current Filtered And Adjusted (ID2F)", SMC_KEY(ID2F) },
+	{ "Power Supply 12V Current Max Error (ID2J)", SMC_KEY(ID2J) },
+	{ "Power Supply 12V Current Trend (ID2T)", SMC_KEY(ID2T) },
+	{ "S2 Camera Current (IS2C)", SMC_KEY(IS2C) },
+	{ "S3 5.0V Current (IR2C)", SMC_KEY(IR2C) },
+	{ "SSD 3V3 Low Side Current (IH0R)", SMC_KEY(IH0R) },
+	{ "SSD Current (IHDC)", SMC_KEY(IHDC) },
+	{ "SSD Current (ISDC)", SMC_KEY(ISDC) },
+	{ "Thunderbolt Current (IHSC)", SMC_KEY(IHSC) },
+	{ "Thunderbolt Current (IHSP)", SMC_KEY(IHSP) },
+	{ "Trackpad Actuator Current (ITPC)", SMC_KEY(ITPC) },
+	{ "Wifi Load-Side Current (IW0R)", SMC_KEY(IW0R) },
+	{ "WLAN Current (IZAP)", SMC_KEY(IZAP) },
+	{ "WLAN Lowside Current (IAPC)", SMC_KEY(IAPC) },
+};
+
+static const struct macsmc_sensor_desc voltage_sensors[] = {
+	{ "1.05V To CPU/PCH Lowside Voltage (VC1C)", SMC_KEY(VC1C) },
+	{ "1.2V To CPU/MEM Lowside Voltage (VM0C)", SMC_KEY(VM0C) },
+	{ "1.8V S3 Lowside Voltage (VM1C)", SMC_KEY(VM1C) },
+	{ "3.3V Load-Side Voltage (VR3R)", SMC_KEY(VR3R) },
+	{ "5V Lowside Voltage (V50R)", SMC_KEY(V50R) },
+	{ "ACC Voltage (VACC)", SMC_KEY(VACC) },
+	{ "ACDC Cooked Voltage (Vp0C)", SMC_KEY(Vp0C) },
+	{ "Backlight Output Voltage (VBLC)", SMC_KEY(VBLC) },
+	{ "Backlight Voltage (VZBL)", SMC_KEY(VZBL) },
+	{ "CPU AXG Low-Side Voltage (VC0G)", SMC_KEY(VC0G) },
+	{ "CPU Core Voltage (VC0C)", SMC_KEY(VC0C) },
+	{ "CPU Core Voltage (VCS0)", SMC_KEY(VCS0) },
+	{ "CPU High Side Voltage From EMC1704 (VC1R)", SMC_KEY(VC1R) },
+	{ "CPU Mem Load-Side Voltage (VC0M)", SMC_KEY(VC0M) },
+	{ "CPU Ripple Voltage (VCRC)", SMC_KEY(VCRC) },
+	{ "CPU Ripple Voltage (VCRP)", SMC_KEY(VCRP) },
+	{ "CPU VCCSA Voltage (VC2C)", SMC_KEY(VC2C) },
+	{ "CPU VSA Low Side Voltage (VC0S)", SMC_KEY(VC0S) },
+	{ "DIMM Load-Side Voltage (VM0R)", SMC_KEY(VM0R) },
+	{ "Drive 0 5V Load-Side Voltage (VH05)", SMC_KEY(VH05) },
+	{ "FIVR CPU Supply Voltage (VCFR)", SMC_KEY(VCFR) },
+	{ "GFX Vcore Voltage (VN0R)", SMC_KEY(VN0R) },
+	{ "GPU A VDDCI Low Side Voltage (VG0S)", SMC_KEY(VG0S) },
+	{ "GPU B VDDCI Low Side Voltage (VG1S)", SMC_KEY(VG1S) },
+	{ "GPU Core Input-Side Voltage (VG1C)", SMC_KEY(VG1C) },
+	{ "GPU Core Voltage (VG0C)", SMC_KEY(VG0C) },
+	{ "GPU Frame Buffer Input-Side Voltage (VG0F)", SMC_KEY(VG0F) },
+	{ "GPU Frame Buffer Input-Side Voltage (VG1F)", SMC_KEY(VG1F) },
+	{ "GPU Uncore High-Side Voltage (VG0U)", SMC_KEY(VG0U) },
+	{ "GPU VDDCI Load-Side Voltage (VG0I)", SMC_KEY(VG0I) },
+	{ "LCD IR Temp Sensor Voltage Raw Register (VL3t)", SMC_KEY(VL3t) },
+	{ "MCP Core Voltage (VN0C)", SMC_KEY(VN0C) },
+	{ "MCP Memory Voltage (VN1C)", SMC_KEY(VN1C) },
+	{ "Memory Voltage (VZDM)", SMC_KEY(VZDM) },
+	{ "ODD Voltage (VODC)", SMC_KEY(VODC) },
+	{ "ODD Voltage (VZOD)", SMC_KEY(VZOD) },
+	{ "PBus Rail Voltage (VP0R)", SMC_KEY(VP0R) },
+	{ "PCH Low-Side Voltage (VN1R)", SMC_KEY(VN1R) },
+	{ "PCH/GPU/TBT Load-Side Voltage (VR1R)", SMC_KEY(VR1R) },
+	{ "PSU Cooked Temperature As Voltage (VP0T)", SMC_KEY(VP0T) },
+	{ "SD Card Voltage (VSDC)", SMC_KEY(VSDC) },
+	{ "SSD 3.3V Low-Side Voltage (VH1R)", SMC_KEY(VH1R) },
+	{ "SSD 3V3 Low Side Voltage (VH0R)", SMC_KEY(VH0R) },
+	{ "SSD Voltage (VZHD)", SMC_KEY(VZHD) },
+	{ "T101 Accuator Voltage (VTPC)", SMC_KEY(VTPC) },
+	{ "WIFI Voltage (VZAP)", SMC_KEY(VZAP) },
+	{ "Wireless Voltage (VAPC)", SMC_KEY(VAPC) },
+};
+
+static int macsmc_hwmon_create_sensor_acpi(struct apple_smc *smc,
+		struct macsmc_hwmon_sensor *sensor, smc_key key, char *name, u32 attrs)
+{
+	int ret;
+
+	ret = apple_smc_get_key_info(smc, key, &sensor->info);
+	if (ret)
+		return ret;
+
+	sensor->macsmc_key = key;
+	sensor->label = name;
+	sensor->attrs = attrs;
+
+	return 0;
+}
 /*
  * Fan data is exposed by the SMC as multiple sensors.
  *
@@ -871,6 +1501,57 @@ static int macsmc_hwmon_create_fan(struct device *dev, struct apple_smc *smc,
 	return 0;
 }
 
+static int macsmc_hwmon_create_fan_acpi(struct apple_smc *smc,
+					struct macsmc_hwmon_fan *fan, int num)
+{
+	const char num_char = num + '0';
+	int ret;
+
+	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->now,
+			__SMC_KEY('F', num_char, 'A', 'c'), NULL, 0);
+	if (ret)
+		return ret;
+
+	if (apple_smc_key_exists(smc, __SMC_KEY('F', num_char, 'I', 'D'))) {
+		char buf[17];
+
+		ret = apple_smc_read(smc, __SMC_KEY('F', num_char, 'I', 'D'), buf, 16);
+		if (ret < 0)
+			return ret;
+
+		buf[16] = '\0';
+		snprintf(fan->label, sizeof(fan->label), "%s", buf + 4);
+	} else
+		snprintf(fan->label, sizeof(fan->label), "Fan %d", num);
+
+	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->min,
+			__SMC_KEY('F', num_char, 'M', 'n'), NULL, 0);
+	if (ret)
+		return ret;
+
+	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->max,
+			__SMC_KEY('F', num_char, 'M', 'x'), NULL, 0);
+	if (ret)
+		return ret;
+
+	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->set,
+			__SMC_KEY('F', num_char, 'T', 'g'), NULL, 0);
+	if (ret)
+		return ret;
+
+	if (apple_smc_key_exists(smc, __SMC_KEY('F', num_char, 'M', 'd'))) {
+		ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->mode,
+				__SMC_KEY('F', num_char, 'M', 'd'), NULL, 0);
+		if (ret)
+			return ret;
+	}
+
+	fan->attrs = HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX | HWMON_F_TARGET;
+	fan->manual = false;
+
+	return 0;
+}
+
 static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon,
 					 struct device_node *hwmon_node)
 {
@@ -907,7 +1588,7 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon,
 
 	if (n_fan) {
 		hwmon->fan.fans = devm_kcalloc(hwmon->dev, n_fan,
-					       sizeof(struct macsmc_hwmon_fan), GFP_KERNEL);
+						sizeof(struct macsmc_hwmon_fan), GFP_KERNEL);
 		if (!hwmon->fan.fans)
 			return -ENOMEM;
 
@@ -990,6 +1671,103 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon,
 	return 0;
 }
 
+static int macsmc_hwmon_register_sensors_acpi(
+	struct macsmc_hwmon *hwmon,
+	struct macsmc_hwmon_sensors *sensors,
+	const struct macsmc_sensor_desc *descs,
+	size_t num_descs,
+	u32 attrs)
+{
+	size_t count = 0;
+	size_t i;
+	int ret;
+
+	for (i = 0; i < num_descs; i++) {
+		if (apple_smc_key_exists(hwmon->smc, descs[i].key))
+			count++;
+	}
+
+	if (!count)
+		return 0;
+
+	sensors->sensors = devm_kcalloc(hwmon->dev, count,
+					sizeof(*sensors->sensors),
+					GFP_KERNEL);
+	if (!sensors->sensors)
+		return -ENOMEM;
+
+	sensors->count = 0;
+
+	for (i = 0; i < num_descs; i++) {
+		if (!apple_smc_key_exists(hwmon->smc, descs[i].key))
+			continue;
+
+		ret = macsmc_hwmon_create_sensor_acpi(hwmon->smc,
+						&sensors->sensors[sensors->count],
+						descs[i].key,
+						descs[i].name,
+						attrs);
+		if (ret)
+			return ret;
+
+		sensors->count++;
+	}
+
+	return 0;
+}
+
+static int macsmc_hwmon_populate_sensors_acpi(struct macsmc_hwmon *hwmon)
+{
+	int ret, i;
+	u8 count;
+
+	ret = apple_smc_read_u8(hwmon->smc, SMC_KEY(FNum), &count);
+	if (count && !ret) {
+		hwmon->fan.fans = devm_kcalloc(hwmon->dev, count,
+				sizeof(struct macsmc_hwmon_fan), GFP_KERNEL);
+		if (!hwmon->fan.fans)
+			return -ENOMEM;
+
+		hwmon->fan.count = count;
+		hwmon->fan.has_old_manual = apple_smc_key_exists(hwmon->smc,
+				__SMC_KEY('F', 'S', '!', ' '));
+
+		for (i = 0; i < hwmon->fan.count; i++) {
+			ret = macsmc_hwmon_create_fan_acpi(hwmon->smc, &hwmon->fan.fans[i], i);
+			if (ret)
+				return ret;
+		}
+	}
+	ret = macsmc_hwmon_register_sensors_acpi(hwmon, &hwmon->temp,
+						temp_sensors,
+						ARRAY_SIZE(temp_sensors),
+						HWMON_T_INPUT | HWMON_T_LABEL);
+	if (ret)
+		return ret;
+
+	ret = macsmc_hwmon_register_sensors_acpi(hwmon, &hwmon->power,
+						power_sensors,
+						ARRAY_SIZE(power_sensors),
+						HWMON_P_INPUT | HWMON_P_LABEL);
+	if (ret)
+		return ret;
+
+	ret = macsmc_hwmon_register_sensors_acpi(hwmon, &hwmon->curr,
+						current_sensors,
+						ARRAY_SIZE(current_sensors),
+						HWMON_C_INPUT | HWMON_C_LABEL);
+	if (ret)
+		return ret;
+
+	ret = macsmc_hwmon_register_sensors_acpi(hwmon, &hwmon->volt,
+						voltage_sensors,
+						ARRAY_SIZE(voltage_sensors),
+						HWMON_I_INPUT | HWMON_I_LABEL);
+	if (ret)
+		return ret;
+
+	return 0;
+}
 /* Create NULL-terminated config arrays */
 static void macsmc_hwmon_populate_configs(u32 *configs, const struct macsmc_hwmon_sensors *sensors)
 {
@@ -1090,9 +1868,9 @@ static int macsmc_hwmon_probe(struct platform_device *pdev)
 	/*
 	 * The MFD driver will try to probe us unconditionally. Some devices
 	 * with the SMC do not have hwmon capabilities. Only probe if we have
-	 * a hwmon node.
+	 * a hwmon node or the machine is a intel mac.
 	 */
-	if (!pdev->dev.of_node)
+	if (!pdev->dev.of_node && !smc->is_acpi)
 		return -ENODEV;
 
 	hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon),
@@ -1102,8 +1880,12 @@ static int macsmc_hwmon_probe(struct platform_device *pdev)
 
 	hwmon->dev = &pdev->dev;
 	hwmon->smc = smc;
+	platform_set_drvdata(pdev, hwmon);
 
-	ret = macsmc_hwmon_populate_sensors(hwmon, hwmon->dev->of_node);
+	if (hwmon->smc->is_acpi)
+		ret = macsmc_hwmon_populate_sensors_acpi(hwmon);
+	else
+		ret = macsmc_hwmon_populate_sensors(hwmon, hwmon->dev->of_node);
 	if (ret) {
 		dev_err(hwmon->dev, "Could not parse sensors\n");
 		return ret;
@@ -1142,6 +1924,30 @@ static int macsmc_hwmon_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int macsmc_hwmon_resume(struct platform_device *pdev)
+{
+	struct macsmc_hwmon *hwmon = dev_get_drvdata(&pdev->dev);
+
+	if (hwmon->smc->is_acpi && !hwmon->fan.has_old_manual) {
+		int idx;
+		int ret;
+
+		for (idx = 0; idx < hwmon->fan.count; idx++)
+			if (hwmon->fan.fans[idx].manual) {
+				ret = macsmc_hwmon_write_key(hwmon->smc,
+						&hwmon->fan.fans[idx].mode, 1);
+				if (ret < 0) {
+					dev_warn(&pdev->dev,
+						"Unable to reenable fan manual, disabling\n");
+					hwmon->fan.fans[idx].manual = false;
+				}
+			}
+
+	}
+
+	return 0;
+}
+
 static const struct of_device_id macsmc_hwmon_of_table[] = {
 	{ .compatible = "apple,smc-hwmon" },
 	{}
@@ -1150,6 +1956,7 @@ MODULE_DEVICE_TABLE(of, macsmc_hwmon_of_table);
 
 static struct platform_driver macsmc_hwmon_driver = {
 	.probe = macsmc_hwmon_probe,
+	.resume = macsmc_hwmon_resume,
 	.driver = {
 		.name = "macsmc-hwmon",
 		.of_match_table = macsmc_hwmon_of_table,
@@ -1160,3 +1967,4 @@ module_platform_driver(macsmc_hwmon_driver);
 MODULE_DESCRIPTION("Apple Silicon SMC hwmon driver");
 MODULE_AUTHOR("James Calligeros <jcalligeros99@gmail.com>");
 MODULE_LICENSE("Dual MIT/GPL");
+MODULE_ALIAS("platform:macsmc-hwmon");
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (12 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
@ 2026-12-04 13:12 ` Atharva Tiwari
  2026-12-04 14:48   ` sashiko-bot
  2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko
  14 siblings, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 13:12 UTC (permalink / raw)
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Aditya Garg,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

Add a /dev/smc device so userspace can talk to the SMC
directly. Some keys that need to be written aren't handled by
any driver, or affect several drivers at once, so they
can't be exposed cleanly through the kernel interfaces.

Keys already managed by kernel drivers can't be written this
way, to avoid conflicts.

Tested-by: Ihor Odainyi <pv4k@odayny.com>
Tested-by: Antoine Sidem <sidemantoine@gmail.com>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
---
 drivers/mfd/macsmc-core.c   | 140 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/macsmc.h  |  61 ++--------------
 include/uapi/linux/macsmc.h | 119 ++++++++++++++++++++++++++++++
 3 files changed, 264 insertions(+), 56 deletions(-)
 create mode 100644 include/uapi/linux/macsmc.h

diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
index bc4200f57..a53df6f6c 100644
--- a/drivers/mfd/macsmc-core.c
+++ b/drivers/mfd/macsmc-core.c
@@ -6,10 +6,13 @@
 
 #include <linux/bitfield.h>
 #include <linux/device.h>
+#include <linux/fs.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/macsmc.h>
+#include <linux/miscdevice.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
+#include <linux/uaccess.h>
 
 static const struct mfd_cell apple_smc_rtkit_devs[] = {
 	MFD_CELL_NAME("macsmc-input"),
@@ -112,6 +115,129 @@ static void apple_smc_disable_notifications(void *data)
 	smc->be->disable_notifications(smc->be_cookie);
 }
 
+static long apple_smc_fops_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	struct apple_smc *smc = file->private_data;
+	void __user *argp = (void __user *)arg;
+	int ret;
+
+	switch (cmd) {
+	case IOCTL_SMC_READ: {
+		struct ioctl_smc_rw_payload payload;
+		struct apple_smc_key_info info;
+
+		if (copy_from_user(&payload, argp, sizeof(payload)))
+			return -EFAULT;
+
+		ret = apple_smc_get_key_info(smc, payload.key, &info);
+		if (ret < 0)
+			return ret;
+
+		if (payload.size != info.size)
+			return -EINVAL;
+
+		if (payload.size > 32 || !(info.flags & APPLE_SMC_READABLE))
+			return -EINVAL;
+
+		ret = apple_smc_read(smc, payload.key, payload.buf, payload.size);
+		if (ret < 0)
+			return ret;
+
+		if (copy_to_user(argp, &payload, sizeof(payload)))
+			return -EFAULT;
+		return 0;
+	}
+	case IOCTL_SMC_WRITE: {
+		struct ioctl_smc_rw_payload payload;
+		struct apple_smc_key_info info;
+
+		if (copy_from_user(&payload, argp, sizeof(payload)))
+			return -EFAULT;
+
+		ret = apple_smc_get_key_info(smc, payload.key, &info);
+		if (ret < 0)
+			return ret;
+
+		if (payload.size != info.size)
+			return -EINVAL;
+
+		if (payload.size > 32)
+			return -EINVAL;
+
+		switch (payload.key) {
+		case __SMC_KEY('H', 'E', '0', 'N'):
+		case __SMC_KEY('H', 'E', '2', 'N'):
+		case __SMC_KEY('H', 'I', '0', 'N'):
+		case __SMC_KEY('M', 'S', 'T', 'S'):
+		case __SMC_KEY('M', 'S', 'P', 'C'):
+		case __SMC_KEY('Q', 'E', 'N', 'A'):
+			break;
+		default:
+			return -EPERM;
+		}
+
+		ret = apple_smc_write(smc, payload.key, payload.buf, payload.size);
+		if (ret < 0)
+			return ret;
+
+		return 0;
+	}
+	case IOCTL_SMC_GET_KEY_INDEX: {
+		struct ioctl_smc_index_payload payload;
+
+		if (copy_from_user(&payload, argp, sizeof(payload)))
+			return -EFAULT;
+
+		ret = apple_smc_get_key_by_index(smc, payload.index, &payload.key);
+		if (ret < 0)
+			return ret;
+
+		if (copy_to_user(argp, &payload, sizeof(payload)))
+			return -EFAULT;
+
+		return 0;
+	}
+	case IOCTL_SMC_GET_KEY_INFO: {
+		struct ioctl_smc_info_payload payload;
+
+		if (copy_from_user(&payload, argp, sizeof(payload)))
+			return -EFAULT;
+
+		ret = apple_smc_get_key_info(smc, payload.key, &payload.info);
+		if (ret < 0)
+			return ret;
+
+		if (copy_to_user(argp, &payload, sizeof(payload)))
+			return -EFAULT;
+
+		return 0;
+	}
+	default:
+		return -EINVAL;
+	}
+}
+
+static int apple_smc_fops_open(struct inode *inode, struct file *file)
+{
+	struct miscdevice *misc = file->private_data;
+
+	file->private_data = container_of(misc, struct apple_smc, miscdev);
+	return 0;
+}
+
+static const struct file_operations apple_smc_fops = {
+	.owner		= THIS_MODULE,
+	.open		= apple_smc_fops_open,
+	.unlocked_ioctl	= apple_smc_fops_ioctl,
+	.compat_ioctl	= compat_ptr_ioctl,
+	.llseek		= noop_llseek,
+};
+
+static void apple_smc_misc_unregister(void *data)
+{
+	misc_deregister(data);
+}
+
 int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 		void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi)
 {
@@ -150,6 +276,20 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
 	if (ret)
 		return ret;
 
+	smc->miscdev.minor = MISC_DYNAMIC_MINOR;
+	smc->miscdev.name = "smc";
+	smc->miscdev.fops = &apple_smc_fops;
+	smc->miscdev.parent = dev;
+	smc->miscdev.mode = 0600;
+
+	ret = misc_register(&smc->miscdev);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, apple_smc_misc_unregister, &smc->miscdev);
+	if (ret)
+		return ret;
+
 	if (smc->is_acpi) {
 		ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common,
 			ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL);
diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h
index cdd040f0c..a09dc6396 100644
--- a/include/linux/mfd/macsmc.h
+++ b/include/linux/mfd/macsmc.h
@@ -8,44 +8,9 @@
 #ifndef _LINUX_MFD_MACSMC_H
 #define _LINUX_MFD_MACSMC_H
 
+#include <linux/miscdevice.h>
 #include <linux/soc/apple/rtkit.h>
-
-/**
- * typedef smc_key - Alias for u32 to be used for SMC keys
- *
- * SMC keys are 32bit integers containing packed ASCII characters in natural
- * integer order, i.e. 0xAABBCCDD, which represent the FourCC ABCD.
- * The SMC driver is designed with this assumption and ensures the right
- * endianness is used when these are stored to memory and sent to or received
- * from the actual SMC firmware (which can be done in either shared memory or
- * as 64bit mailbox message on Apple Silicon).
- * Internally, SMC stores these keys in a table sorted lexicographically and
- * allows resolving an index into this table to the corresponding SMC key.
- * Thus, storing keys as u32 is very convenient as it allows to e.g. use
- * normal comparison operators which directly map to the natural order used
- * by SMC firmware.
- *
- * This simple type alias is introduced to allow easy recognition of SMC key
- * variables and arguments.
- */
-typedef u32 smc_key;
-
-/**
- * SMC_KEY - Convert FourCC SMC keys in source code to smc_key
- *
- * This macro can be used to easily define FourCC SMC keys in source code
- * and convert these to u32 / smc_key, e.g. SMC_KEY(NTAP) will expand to
- * 0x4e544150.
- *
- * @s: FourCC SMC key to be converted
- */
-#define SMC_KEY(s) (smc_key)(_SMC_KEY(#s))
-#define _SMC_KEY(s) (((s)[0] << 24) | ((s)[1] << 16) | ((s)[2] << 8) | (s)[3])
-#define __SMC_KEY(a, b, c, d) (((u32)(a) << 24) | ((u32)(b) << 16) | ((u32)(c) << 8) | ((u32)(d)))
-
-#define APPLE_SMC_READABLE BIT(7)
-#define APPLE_SMC_WRITABLE BIT(6)
-#define APPLE_SMC_FUNCTION BIT(4)
+#include <uapi/linux/macsmc.h>
 
 #define SMC_MSG_READ_KEY                0x10
 #define SMC_MSG_WRITE_KEY               0x11
@@ -66,25 +31,6 @@ typedef u32 smc_key;
 #define SMC_INT_SMS_SHOCK               0x6F
 #define SMC_INT_PLIMIT_CHANGED          0x80
 
-/**
- * struct apple_smc_key_info - Information for a SMC key as returned by SMC
- * @type_code: FourCC code indicating the type for this key.
- *             Known types:
- *              ch8*: ASCII string
- *              flag: Boolean, 1 or 0
- *              flt: 32-bit single-precision IEEE 754 float
- *              hex: Binary data
- *              ioft: 64bit Unsigned fixed-point intger (48.16)
- *              {si,ui}{8,16,32,64}: Signed/Unsigned 8-/16-/32-/64-bit integer
- * @size: Size of the buffer associated with this key
- * @flags: Bitfield encoding flags (APPLE_SMC_{READABLE,WRITABLE,FUNCTION})
- */
-struct apple_smc_key_info {
-	u32 type_code;
-	u8 size;
-	u8 flags;
-};
-
 /**
  * enum apple_smc_boot_stage - SMC boot stage
  * @APPLE_SMC_BOOTING: SMC is booting
@@ -136,6 +82,7 @@ struct apple_smc_backend_ops {
  * @is_acpi: Is the backend ACPI based
  * @mutex: Mutex for non-atomic mode
  * @lock: Spinlock for atomic mode
+ * @miscdev: Misc Device struct for ioctl ops
  */
 struct apple_smc {
 	struct device *dev;
@@ -152,6 +99,8 @@ struct apple_smc {
 
 	struct mutex mutex;
 	spinlock_t lock;
+
+	struct miscdevice miscdev;
 };
 
 /**
diff --git a/include/uapi/linux/macsmc.h b/include/uapi/linux/macsmc.h
new file mode 100644
index 000000000..ef784539d
--- /dev/null
+++ b/include/uapi/linux/macsmc.h
@@ -0,0 +1,119 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT WITH Linux-syscall-note */
+/*
+ * Apple SMC Public Interface
+ *
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
+ */
+
+#ifndef _UAPI_MACSMC_H
+#define _UAPI_MACSMC_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+/**
+ * typedef smc_key - Alias for u32 to be used for SMC keys
+ *
+ * SMC keys are 32bit integers containing packed ASCII characters in natural
+ * integer order, i.e. 0xAABBCCDD, which represent the FourCC ABCD.
+ * The SMC driver is designed with this assumption and ensures the right
+ * endianness is used when these are stored to memory and sent to or received
+ * from the actual SMC firmware (which can be done in either shared memory or
+ * as 64bit mailbox message on Apple Silicon).
+ * Internally, SMC stores these keys in a table sorted lexicographically and
+ * allows resolving an index into this table to the corresponding SMC key.
+ * Thus, storing keys as u32 is very convenient as it allows to e.g. use
+ * normal comparison operators which directly map to the natural order used
+ * by SMC firmware.
+ *
+ * This simple type alias is introduced to allow easy recognition of SMC key
+ * variables and arguments.
+ */
+typedef __u32 smc_key;
+
+/**
+ * SMC_KEY - Convert FourCC SMC keys in source code to smc_key
+ *
+ * This macro can be used to easily define FourCC SMC keys in source code
+ * and convert these to u32 / smc_key, e.g. SMC_KEY(NTAP) will expand to
+ * 0x4e544150.
+ *
+ * @s: FourCC SMC key to be converted
+ */
+#define SMC_KEY(s) ((smc_key)(_SMC_KEY(#s)))
+#define _SMC_KEY(s) (((s)[0] << 24) | ((s)[1] << 16) | ((s)[2] << 8) | (s)[3])
+#define __SMC_KEY(a, b, c, d) (((__u32)(a) << 24) | ((__u32)(b) << 16) | ((__u32)(c) << 8) | ((__u32)(d)))
+
+#define APPLE_SMC_READABLE		BIT(7)
+#define APPLE_SMC_WRITABLE		BIT(6)
+#define APPLE_SMC_FUNCTION		BIT(4)
+#define APPLE_SMC_CONST		BIT(3)
+#define APPLE_SMC_ATOMIC		BIT(2)
+#define APPLE_SMC_PRIVATE_READ		BIT(1)
+#define APPLE_SMC_PRIVATE_WRITE		BIT(0)
+
+/**
+ * struct apple_smc_key_info - Information for a SMC key as returned by SMC
+ * @type_code: FourCC code indicating the type for this key.
+ *      Known types:
+ *       ch8*: ASCII string
+ *       flag: Boolean, 1 or 0
+ *       flt: 32-bit single-precision IEEE 754 float
+ *       hex: Binary data
+ *       ioft: 64bit Unsigned fixed-point intger (48.16)
+ *       {si,ui}{8,16,32,64}: Signed/Unsigned 8-/16-/32-/64-bit integer
+ * @size: Size of the buffer associated with this key
+ * @flags: Bitfield encoding flags (APPLE_SMC_{READABLE,WRITABLE,FUNCTION,
+ *       CONST,ATOMIC,PRIVATE_READ,PRIVATE_WRITE})
+ */
+struct apple_smc_key_info {
+	__u32 type_code;
+	__u8 size;
+	__u8 flags;
+};
+
+/**
+ * struct ioctl_smc_rw_payload - argument for IOCTL_SMC_READ and IOCTL_SMC_WRITE
+ * @key: SMC key to access. Input.
+ * @size: Size of the key's data in bytes. Input. It must match the size the
+ *	SMC reports for @key (see IOCTL_SMC_GET_KEY_INFO) and cannot exceed
+ *	the size of @buf.
+ * @buf: Key data. For IOCTL_SMC_READ this is filled in by the kernel with the
+ *	value read from @key. For IOCTL_SMC_WRITE it holds the value to write to
+ *	@key.
+ */
+struct ioctl_smc_rw_payload {
+	smc_key key;
+	__u32 size;
+	__u8 buf[32];
+};
+
+/**
+ * struct ioctl_smc_index_payload - argument for IOCTL_SMC_GET_KEY_INDEX
+ * @index: Position in the SMC's key table. Input.
+ * @key: Key stored at @index. Filled in by the kernel.
+ *
+ * Calling this with increasing @index values lists every key the SMC exposes.
+ */
+struct ioctl_smc_index_payload {
+	__u16 index;
+	smc_key key;
+};
+
+/**
+ * struct ioctl_smc_info_payload - argument for IOCTL_SMC_GET_KEY_INFO
+ * @key: SMC key to look up. Input.
+ * @info: Size, type code and flags of @key. Filled in by the kernel.
+ */
+struct ioctl_smc_info_payload {
+	smc_key key;
+	struct apple_smc_key_info info;
+};
+
+#define APPLE_SMC_MAGIC 'S'
+#define IOCTL_SMC_READ    _IOWR(APPLE_SMC_MAGIC, 1, struct ioctl_smc_rw_payload)
+#define IOCTL_SMC_WRITE   _IOW(APPLE_SMC_MAGIC, 2, struct ioctl_smc_rw_payload)
+#define IOCTL_SMC_GET_KEY_INDEX  _IOWR(APPLE_SMC_MAGIC, 3, struct ioctl_smc_index_payload)
+#define IOCTL_SMC_GET_KEY_INFO   _IOWR(APPLE_SMC_MAGIC, 4, struct ioctl_smc_info_payload)
+
+#endif /* _UAPI_MACSMC_H */
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: [PATCH 04/14] iio/light: add new driver for macsmc
  2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
@ 2026-12-04 13:47   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 13:47 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] iio: light: notifier registered before
  devm_iio_device_register() causes UAF
- [Medium] iio: light: unconditional RIGHT_LIGHT channel and missing
  ALV1 validation
- [Medium] iio: light: macsmc-light exposes unitless raw SMC counts as
  IIO_LIGHT
- [Low] iio: light: Kconfig module name mismatch and MACSMC_ACPI
  dependency
- [Low] mfd: macsmc: literal -1 passed to devm_mfd_add_devices() for
  light cell
--

commit e9ed4cb9e8bdd5a53203bb98eb77007e4876b53e
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

iio/light: add new driver for macsmc

This commit adds an IIO ambient light sensor driver for Apple SMC
(macsmc-light) exposing left and right channels, and registers its MFD
cell from macsmc-core when the ALV0 key is present.

> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 462fff1ddef20..f84707edc6772 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -457,6 +457,17 @@ config LV0104CS
>  	  To compile this driver as a module, choose M here:
>  	  the module will be called lv0104cs.
>  
> +config MACSMC_LIGHT
> +	tristate "Apple SMC Light Sensor"
> +	depends on MACSMC_ACPI
> +	help
> +	  Say Y here if you have a Intel-based Mac. and you
> +	  want support for light sensors.
> +
> +	  To compile this driver as a module, choose M here:
> +	  the module will be called macsmc_light

[Severity: Low]
The Makefile builds macsmc-light.o, so the help text should say
macsmc-light (with a hyphen and trailing period) rather than
macsmc_light.

Also, macsmc-light only uses architecture-independent interfaces from
MFD_MACSMC_CORE.  Should this depend on MFD_MACSMC_CORE (or MACSMC_ACPI
|| (MFD_MACSMC_CORE && COMPILE_TEST)) like the sibling macsmc drivers so
it can be compile-tested on non-x86 builds?

> diff --git a/drivers/iio/light/macsmc-light.c b/drivers/iio/light/macsmc-light.c
> new file mode 100644
> index 0000000000000..12d88035ad746
> --- /dev/null
> +++ b/drivers/iio/light/macsmc-light.c

[ ... ]

> +static const struct iio_chan_spec macsmc_light_channels[] = {
> +	{
> +		.type = IIO_LIGHT,
> +		.channel = LEFT_LIGHT,
> +		.indexed = 1,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +		.event_spec = macsmc_light_events,
> +		.num_event_specs = ARRAY_SIZE(macsmc_light_events),
> +	},
> +	{
> +		.type = IIO_LIGHT,
> +		.channel = RIGHT_LIGHT,
> +		.indexed = 1,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +		.event_spec = macsmc_light_events,
> +		.num_event_specs = ARRAY_SIZE(macsmc_light_events),
> +	},
> +};

[Severity: Medium]
Should these channels use IIO_INTENSITY instead of IIO_LIGHT?

Per Documentation/ABI/testing/sysfs-bus-iio, IIO_LIGHT
(in_illuminanceY_raw) must report illuminance in lux after scale and
offset.  macsmc_light_read_raw() instead returns uncalibrated, unit-less
raw SMC counts with no scale attribute.

Exposing unit-less counts under in_illuminanceY_raw locks in wrong units
for userspace.  Without a lux conversion or scale factor, IIO_INTENSITY
(in_intensityY_raw) is the documented type for unit-less light readings.

[ ... ]

> +	ret = apple_smc_get_key_info(drv->smc, SMC_KEY(ALV0), &info);
> +	if (ret < 0)
> +		return -ENODEV;
> +
> +	if (info.size < 3 || info.size > 10)
> +		return -ENODEV;
> +
> +	drv->size = info.size;
> +	drv->single_sensor = info.size == 10;

[Severity: Medium]
Does macsmc_light_probe() need to check ALV1 separately and register
only one channel when a single sensor is present?

On single-sensor Macs (10-byte ALV0), registering both channels exposes
a nonexistent right channel that always returns 0 and never emits
events.

When ALV0 is 3 to 9 bytes on hardware without a matching-length ALV1,
reading RIGHT_LIGHT with drv->size fails or reads past ALV1 while
macsmc_light_event() still pushes RIGHT_LIGHT events.  Querying ALV1 in
probe and sizing indio_dev->num_channels accordingly would avoid both.

> +	drv->indio_dev = indio_dev;
> +	drv->nb.notifier_call = macsmc_light_event;
> +	ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(dev, macsmc_light_unregister_notifier, drv);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->name = "macsmc-light";
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->info = &macsmc_light_info;
> +	indio_dev->channels = macsmc_light_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(macsmc_light_channels);
> +
> +	return devm_iio_device_register(dev, indio_dev);

[Severity: Medium]
Can registering the SMC notifier before devm_iio_device_register() cause
a use-after-free on probe failure and inverted teardown on unbind?

apple_smc_acpi_probe() enables SMC interrupts before adding MFD
children, so SMC_INT_ALS_CHANGE can invoke macsmc_light_event() while
devm_iio_device_register() is still running or unwinding:

CPU0                                CPU1
macsmc_light_probe()
  blocking_notifier_chain_register()
  devm_iio_device_register()
    iio_device_register_eventset()
      event_interface = ev_int
    ... (cdev_device_add() fails)
    iio_device_unregister_eventset()
                                    apple_smc_acpi_notifier_work()
                                      macsmc_light_event()
                                        iio_push_event()
                                          ev_int = ...->event_interface
      kfree(ev_int)
      event_interface = NULL
                                          iio_event_enabled(ev_int)
                                            <-- use-after-free

On normal unbind, devres LIFO order also runs iio_device_unregister()
before macsmc_light_unregister_notifier(), leaving the notifier pushing
events after the IIO device is torn down.  Registering the notifier
after devm_iio_device_register() succeeds fixes both.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index 1c14698285456..6014df4fe1c0a 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -158,6 +162,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  				return ret;
>  		}
>  
> +		if (apple_smc_key_exists(smc, SMC_KEY(ALV0))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_light,
> +				ARRAY_SIZE(apple_smc_acpi_light), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}

[Severity: Low]
This isn't a bug, but devm_mfd_add_devices() here passes a literal -1
instead of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE if a fixed
single-instance name is required).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=4

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 03/14] watchdog: add driver for apple smc
  2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
@ 2026-12-04 13:48   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 13:48 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] watchdog: macsmc_wdt: missing suspend/resume PM callbacks
- [Medium] mfd: macsmc: apple_smc_probe() checks only NATJ for
  macsmc-wdt
- [Medium] watchdog: macsmc_wdt: unsynchronized NATJ/NATi writes can
  force reset
- [Medium] watchdog: macsmc_wdt: apple_smc_key_exists() causes 1s PIO
  timeout stalls
- [Low] watchdog: macsmc_wdt uses obsolete __MODULE_STRING() and omits
  direct headers
--

commit dd87f5854d512b3a6e66e9d3cd77fe418fb3e73a
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

watchdog: add driver for apple smc

This commit adds a watchdog driver for the Apple SMC on Intel Macs,
supporting both newer OSWD and legacy NATJ/NATi SMC keys, and registers
the platform device from macsmc-core.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index b8905c834c448..1c14698285456 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -147,6 +151,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  				return ret;
>  		}
>  
> +		if (apple_smc_key_exists(smc, SMC_KEY(NATJ))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_wdt,
> +				ARRAY_SIZE(apple_smc_acpi_wdt), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}
> +
>  	} else

[Severity: Medium]
Should this check also accept SMC_KEY(OSWD) and require SMC_KEY(NATi)
alongside SMC_KEY(NATJ)?

On newer Intel Macs that expose OSWD without the legacy NATJ key,
apple_smc_probe() never registers macsmc-wdt.  Conversely, on an SMC with
NATJ but without OSWD or NATi, macsmc_wdt_probe() falls back to
has_oswd = false and registers a watchdog whose operations fail with -EIO.

Checking for OSWD or both NATJ and NATi in apple_smc_probe() and
macsmc_wdt_probe() avoids both cases.

[ ... ]

> diff --git a/drivers/watchdog/macsmc_wdt.c b/drivers/watchdog/macsmc_wdt.c
> new file mode 100644
> index 0000000000000..e2fc7f4e3e4b7
> --- /dev/null
> +++ b/drivers/watchdog/macsmc_wdt.c
> @@ -0,0 +1,158 @@

[ ... ]

> +#include <linux/mfd/macsmc.h>
> +#include <linux/platform_device.h>
> +#include <linux/watchdog.h>
> +
> +#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
> +
> +static bool nowayout = WATCHDOG_NOWAYOUT;
> +module_param(nowayout, bool, 0);
> +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started default="
> +		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
> +
> +static int timeout = WATCHDOG_TIMEOUT; /* in secounds */
> +module_param(timeout, int, 0);
> +MODULE_PARM_DESC(timeout,
> +		 "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
> +		 __MODULE_STRING(WATCHDOG_TIMEOUT) ".");

[Severity: Low]
Can __MODULE_STRING() be replaced with __stringify() here?  It is marked
obsolete and scheduled for removal in include/linux/module.h, and no other
callers remain in the tree.

The file also omits direct includes of linux/module.h and linux/stringify.h
despite using module macros, and the nowayout MODULE_PARM_DESC() has an
unmatched closing parenthesis before the end of the string.

[ ... ]

> +		if (timeout == 0) {
> +			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 0);
> +			if (ret < 0)
> +				return ret;
> +		}
> +		ret = apple_smc_write_u16(drv->smc, SMC_KEY(NATi), (u16)(timeout << 8));
> +		if (ret < 0)
> +			return ret;
> +
> +		if (timeout != 0) {
> +			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 2);
> +			if (ret < 0)
> +				return ret;
> +		}

[Severity: Medium]
Can concurrent stop and start/set_timeout calls interleave these NATJ and
NATi writes into a forced reset?

macsmc_wdt_probe() enables watchdog_stop_on_reboot(), which calls
macsmc_wdt_stop() without wd_data->lock while userspace can still issue
watchdog ioctls.  Because apple_smc_write() only holds smc->mutex per
key write, the two-key sequence can interleave:

CPU0 (ioctl)                      CPU1 (reboot notifier)
macsmc_wdt_set_timeout()          watchdog_reboot_notifier()
  macsmc_wdt_write_timeout(t)       macsmc_wdt_stop()
    write(NATi, t << 8)               macsmc_wdt_write_timeout(0)
                                        write(NATJ, 0)
                                        write(NATi, 0)
    write(NATJ, 2)  <-- NATi == 0, NATJ == 2: forced reset

Leaving NATi == 0 with NATJ == 2 triggers an immediate forced restart on
legacy !has_oswd Macs.  Serializing macsmc_wdt_write_timeout() and
macsmc_wdt_ping() with a mutex in struct macsmc_wdt prevents this race.

[ ... ]

> +	drv->smc = dev_get_drvdata(pdev->dev.parent);
> +	if (apple_smc_key_exists(drv->smc, SMC_KEY(OSWD)))
> +		drv->has_oswd = true;
> +	else
> +		drv->has_oswd = false;

[Severity: Medium]
Does probing a missing key via apple_smc_key_exists() stall for 1 second
on PIO-based Intel Macs?

On PIO Macs (!smc->is_mmio), apple_smc_get_key_info() dispatches to
apple_smc_acpi_port_read(), which has no error-status check and only fails
when apple_smc_acpi_port_wait() times out after SMC_TIMEOUT_MS (1000 ms).

This deterministically stalls probe for 1 second while holding smc->mutex
on every older PIO Mac without OSWD (and likewise for the NATJ check in
apple_smc_probe() on PIO Macs without NATJ), blocking concurrent SMC
accesses from sibling MFD drivers.

[ ... ]

> +static struct platform_driver macsmc_wdt_driver = {
> +	.probe = macsmc_wdt_probe,
> +	.driver = {
> +		.name = "macsmc-wdt",
> +	},
> +};

[Severity: High]
Does macsmc_wdt_driver need suspend and resume PM callbacks to stop an
active watchdog across system sleep?

The watchdog core does not stop hardware watchdogs in
watchdog_dev_suspend(), so an armed SMC watchdog (at most 255 seconds)
will expire while the host CPU is suspended and force a hard reset.

Conversely, if the SMC clears its watchdog keys across sleep, the lack of
a resume callback leaves the hardware watchdog silently disabled after
resume while WDOG_ACTIVE remains set.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=3

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 01/14] treewide: Add backend for macsmc
  2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
@ 2026-12-04 13:56   ` sashiko-bot
  2026-12-04 14:07   ` Andy Shevchenko
  2026-12-04 16:45   ` Sven Peter
  2 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 13:56 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] mfd: macsmc: Kconfig split disables Apple SMC drivers in arm64
  defconfig
- [Medium] mfd: macsmc: notifications left enabled if apple_smc_probe()
  fails early
- [Low] mfd: macsmc: endianness type mismatch in apple_smc_probe()
- [Low] mfd: macsmc: signed %d format specifier used for u32 key_count
- [Low] mfd: macsmc: non-standard subject prefix and incomplete commit
  message
- [Low] mfd: macsmc-core: apple_smc_probe() passes raw -1 to
  devm_mfd_add_devices()
- [Low] mfd: macsmc: undocumented swab32() in core
  apple_smc_get_key_by_index()
- [Low] mfd: macsmc: missing NULL checks on optional ops and backend
  locking docs
- [Low] mfd: macsmc.h retains unused RTKit header include and RTKit-only
  definitions
--

commit 97275525c07f52eb987554687e4771a43c630a9d
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

> treewide: Add backend for macsmc
>
> Split the Apple SMC driver into a common core and a backend
> that handles the actual communication. The existing RTKit
> code moves to its own backend, and nothing changes for
> Apple Silicon.
>
> This lets the same SMC drivers run on other kinds of
> hardware, starting with Intel Macs, as a replacement for
> applesmc.
>
> Tested-by: Ihor Odainyi <pv4k@odayny.com>
> Tested-by: Antoine Sidem <sidemantoine@gmail.com>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
The MFD convention for commit subjects is "mfd: macsmc: <Capitalized
description>" rather than "treewide:".  The changelog also states that
nothing changes for Apple Silicon, omitting the Kconfig rename, dropping
the OF dependency from SENSORS_MACSMC_HWMON, renaming the RTKit platform
driver from macsmc to macsmc-rtkit, caching first_key and last_key in
apple_smc_probe(), and adding the ACPI MFD cells and SMC_INT_* macros.

[ ... ]

> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 87ed55c155f03..c58cc3315f22a 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -339,24 +339,15 @@ config MFD_LOCHNAGAR
>  	help
>  	  Support for Cirrus Logic Lochnagar audio development board.
>  
> -config MFD_MACSMC
> -	tristate "Apple Silicon System Management Controller (SMC)"
> -	depends on ARCH_APPLE || COMPILE_TEST
> -	depends on OF
> -	depends on APPLE_RTKIT
> +config MFD_MACSMC_CORE
> +	tristate "Apple System Management Controller (SMC) Core"
>  	select MFD_CORE

[Severity: High]
Does deleting CONFIG_MFD_MACSMC silently disable the Apple Silicon SMC
driver stack in arm64 defconfig and existing configs?

arch/arm64/configs/defconfig still sets CONFIG_MFD_MACSMC=m and is not
updated in this series, so make defconfig and olddefconfig drop the SMC
core, RTKit backend, GPIO, reboot/power-off, hwmon, and RTC drivers on
Apple Silicon.

Making MFD_MACSMC_CORE a hidden symbol selected by MACSMC_RTKIT and
updating arm64 defconfig would avoid breaking existing builds.  Renaming
the RTKit platform driver from macsmc to macsmc-rtkit also changes the
sysfs driver path and module name on Apple Silicon.

[ ... ]

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> new file mode 100644
> index 0000000000000..b8905c834c448
> --- /dev/null
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> +int apple_smc_enter_atomic(struct apple_smc *smc)
> +{
> +	guard(mutex)(&smc->mutex);
> +	return smc->be->enter_atomic(smc->be_cookie);
> +}
> +EXPORT_SYMBOL(apple_smc_enter_atomic);
> +
> +int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
> +{
> +	guard(spinlock_irqsave)(&smc->lock);
> +	return smc->be->write_atomic(smc->be_cookie, key, buf, size);
> +}
> +EXPORT_SYMBOL(apple_smc_write_atomic);
> +
> +int apple_smc_rw(struct apple_smc *smc, smc_key key, const void *wbuf, size_t wsize,
> +		void *rbuf, size_t rsize)
> +{
> +	guard(mutex)(&smc->mutex);
> +	return smc->be->rw(smc->be_cookie, key, wbuf, wsize, rbuf, rsize);
> +}
> +EXPORT_SYMBOL(apple_smc_rw);

[Severity: Low]
Should these wrappers check for NULL before invoking enter_atomic,
write_atomic, and rw, and return -EOPNOTSUPP when unimplemented?

Commit "platform/x86: add backend for macsmc in intel macs" leaves those
three callbacks NULL in apple_smc_acpi_be_ops, so calling them on an
ACPI backend would cause a NULL pointer dereference.

The kernel-doc for struct apple_smc_backend_ops in
include/linux/mfd/macsmc.h could also document which callbacks are
optional and their locking context (smc->mutex for sleeping ops vs
smc->lock with spin_lock_irqsave for write_atomic).

> +
> +int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key)
> +{
> +	guard(mutex)(&smc->mutex);
> +	int ret;
> +
> +	ret = smc->be->get_key_by_index(smc->be_cookie, index, key);
> +	*key = swab32(*key);
> +
> +	return ret;
> +}

[Severity: Low]
Should the byte swap in apple_smc_get_key_by_index() live in the
backends rather than the generic core?

Every other callback in struct apple_smc_backend_ops uses host-order
smc_key values, and get_key_by_index does not document that it must
return a byte-swapped key.  Moving the conversion into each backend
would keep the interface consistent with typedef smc_key.

[ ... ]

> +int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
> +		void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi)
> +{
> +	struct apple_smc *smc;
> +	__be32 count;
> +	int ret;

[ ... ]

> +	ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
> +	if (ret < 0)
> +		return ret;
> +	smc->key_count = be32_to_cpu(count);

[Severity: Low]
Does passing __be32 *count to apple_smc_read_u32() reintroduce a Sparse
-Wbitwise warning?

apple_smc_read_u32() takes a host-endian u32 *, which regresses
0a29aa605286 ("mfd: macsmc: Fix key count endianness annotation").
Reading into count with apple_smc_read() and checking the returned byte
count avoids the type mismatch.

[ ... ]

> +	if (smc->is_acpi) {
> +		ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common,
> +			ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (apple_smc_key_exists(smc, SMC_KEY(CLKO))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_rtc,
> +				ARRAY_SIZE(apple_smc_acpi_rtc), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}
> +
> +	} else
> +		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
> +			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);
> +	if (ret < 0)
> +		return ret;

[Severity: Low]
These devm_mfd_add_devices() calls pass a raw -1 instead of
PLATFORM_DEVID_AUTO (preferred for new MFD code) or PLATFORM_DEVID_NONE,
which the driver used before this split.

> +
> +	dev_info(dev, "Successfully Initialized (%d keys First key: %p4ch Last key: %p4ch)\n",
> +			smc->key_count, &smc->first_key, &smc->last_key);

[Severity: Low]
smc->key_count is a u32, so %u would match its type better than %d.

[ ... ]

> diff --git a/drivers/mfd/macsmc.c b/drivers/soc/apple/macsmc-rtkit.c
> similarity index 70%
> rename from drivers/mfd/macsmc.c
> rename to drivers/soc/apple/macsmc-rtkit.c
> index 514cba7dc897a..eaebeb1be3734 100644
> --- a/drivers/mfd/macsmc.c
> +++ b/drivers/soc/apple/macsmc-rtkit.c

[ ... ]

> @@ -458,49 +450,32 @@ static int apple_smc_probe(struct platform_device *pdev)
>  		return -EIO;
>  	}
>  
> -	dev_set_drvdata(&pdev->dev, smc);
>  	BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
>  
> -	ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
> -	if (ret >= 0 && ret != sizeof(count))
> -		ret = -EINVAL;
> -	if (ret < 0)
> -		return dev_err_probe(smc->dev, ret, "Failed to get key count");
> -	smc->key_count = be32_to_cpu(count);
> -
>  	/* Enable notifications */
> -	apple_smc_write_flag(smc, SMC_KEY(NTAP), true);
> -	ret = devm_add_action_or_reset(dev, apple_smc_disable_notifications, smc);
> -	if (ret)
> -		return ret;
> +	apple_smc_rtkit_rw_locked(smc, SMC_KEY(NTAP), &flag, sizeof(flag), NULL, 0);
>  
> -	ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE,
> -				   apple_smc_devs, ARRAY_SIZE(apple_smc_devs),
> -				   NULL, 0, NULL);
> -	if (ret)
> -		return dev_err_probe(smc->dev, ret, "Failed to register sub-devices");
> -
> -
> -	return 0;
> +	return apple_smc_probe(dev, &apple_smc_rtkit_backend_ops, smc,
> +			&smc->event_handlers, false);
>  }

[Severity: Medium]
Does enabling NTAP notifications here leave them enabled if
apple_smc_probe() fails early?

In apple_smc_probe(), devm_kzalloc() and the initial #KEY, first_key,
and last_key queries all run before devm_add_action_or_reset() registers
apple_smc_disable_notifications().  If any of those fail, probe unwinds
without disabling notifications in firmware.

Enabling notifications through a backend callback right before
devm_add_action_or_reset() in apple_smc_probe() (or registering the
cleanup action immediately here) would keep enable and disable balanced.

[ ... ]

> diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h
> index cc09ecce0df74..cdd040f0c010f 100644
> --- a/include/linux/mfd/macsmc.h
> +++ b/include/linux/mfd/macsmc.h
> @@ -47,6 +47,25 @@ typedef u32 smc_key;
>  #define APPLE_SMC_WRITABLE BIT(6)
>  #define APPLE_SMC_FUNCTION BIT(4)
>  
> +#define SMC_MSG_READ_KEY                0x10
> +#define SMC_MSG_WRITE_KEY               0x11
> +#define SMC_MSG_GET_KEY_BY_INDEX        0x12
> +#define SMC_MSG_GET_KEY_INFO            0x13
> +#define SMC_MSG_INITIALIZE              0x17
> +#define SMC_MSG_NOTIFICATION            0x18
> +#define SMC_MSG_RW_KEY                  0x20

[Severity: Low]
Can SMC_MSG_INITIALIZE, SMC_MSG_NOTIFICATION, SMC_MSG_RW_KEY, and
enum apple_smc_boot_stage stay private to drivers/soc/apple/macsmc-rtkit.c?

They are only used by the RTKit backend across the series.  This header
also still includes <linux/soc/apple/rtkit.h> even though all RTKit
fields were removed from struct apple_smc, pulling RTKit, mailbox, and
OF headers into generic and x86 consumers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=1

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
@ 2026-12-04 13:58   ` sashiko-bot
  2026-12-04 14:19   ` Andy Shevchenko
  1 sibling, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 13:58 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 20 potential
issues to consider:
- [High] platform/x86: macsmc-acpi: I/O port conflict with applesmc
  lacks Kconfig exclusion
- [High] platform/x86: macsmc-acpi: broken cmd_done completion wait in
  apple_smc_acpi_port_wait()
- [Medium] platform/x86: macsmc-acpi: completion race and missing status
  check in MMIO wait
- [Medium] platform/x86: macsmc-acpi: 1 ms poll interval inflates
  PIO/MMIO wait latency
- [Medium] platform/x86: macsmc-acpi: broken status check in
  apple_smc_acpi_irq()
- [Medium] platform/x86: macsmc-acpi: NTOK left enabled on early
  apple_smc_probe() fail
- [Medium] platform/x86: macsmc-acpi: unlocked flag read in
  apple_smc_acpi_resume()
- [Medium] platform/x86: macsmc-acpi: unchecked ACPI_COMPANION() in
  apple_smc_acpi_probe()
- [Medium] platform/x86: macsmc-acpi: omit PIO data flush in
  apple_smc_acpi_port_read()
- [Medium] platform/x86: apple_smc_acpi_resume() can skip restoring NTOK
  after resume
- [Medium] platform/x86: raw ACPI IRQ and missing flags in
  apple_smc_acpi_probe()
- [Medium] platform/x86: unchecked ACPI_COMPANION() in
  apple_smc_acpi_probe()
- [Medium] platform/x86: macsmc-acpi races with applesmc on SMC I/O
  ports
- [Low] platform/x86: macsmc-acpi: undocumented multi-value plimit sysfs
  attribute
- [Low] platform/x86: __be32 to u32 in
  apple_smc_acpi_mmio_get_key_info()
- [Low] platform/x86: void return expression in
  apple_smc_acpi_mmio_clear()
- [Low] platform/x86: macsmc-acpi: apple_smc_acpi_write() returns size
  instead of 0
- [Low] platform/x86: macsmc-acpi: devm_ioremap() without
  devm_request_mem_region()
- [Low] platform/x86: macsmc-acpi exposes undocumented plimit sysfs
  attribute
- [Low] platform/x86: raw byte array kept in
  apple_smc_acpi_port_get_key_info()
--

commit eb95b0b0da7b2552eb2f4941cef2db07a98b0710
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

platform/x86: add backend for macsmc in intel macs

This commit adds an ACPI backend driver for the Apple SMC on Intel Macs,
supporting I/O port and MMIO transfers as well as interrupt-driven
completion with polling fallback.

> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 9ce384e0475ea..7a061e48465b4 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -202,6 +202,16 @@ config ADV_SWBUTTON
>  	  To compile this driver as a module, choose M here. The module will
>  	  be called adv_swbutton.
>  
> +config MACSMC_ACPI
> +	tristate "Apple SMC (System Management Controller) ACPI Backend"
> +	depends on MFD_MACSMC_CORE && ACPI

[Severity: High]
Can CONFIG_MACSMC_ACPI and CONFIG_SENSORS_APPLESMC be enabled at the same
time without mutual exclusion?

Both drivers auto-load on Intel Macs and claim the same 32-byte I/O port
region (0x300-0x31f).  When both are built-in, drivers/Makefile links
hwmon/ before platform/, so applesmc_init() always reserves the ports
first and apple_smc_acpi_probe() fails with -EBUSY; when built as modules,
they race at boot.  Because later patches in this series disable acpi-sbs,
ACPI battery/AC, rtc-cmos, and acpi-tad whenever CONFIG_MACSMC_ACPI is
enabled, applesmc winning the port claim leaves those devices without any
driver.

[ ... ]

> diff --git a/drivers/platform/x86/macsmc-acpi.c b/drivers/platform/x86/macsmc-acpi.c
> new file mode 100644
> index 0000000000000..8a93245c9d293
> --- /dev/null
> +++ b/drivers/platform/x86/macsmc-acpi.c

[ ... ]

> +static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
> +{
> +	u8 status;
> +	int ret;
> +
> +	if (smc->interrupt_enabled) {
> +		reinit_completion(&smc->cmd_done);
> +		if (wait_for_completion_timeout(&smc->cmd_done,
> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> +			return 0;
> +
> +		smc->interrupt_enabled = 0;
> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> +	}

[Severity: High]
Does apple_smc_acpi_port_wait() unconditionally block on cmd_done without
checking the port status register first?

Every PIO read and write begins with apple_smc_acpi_port_valid() ->
apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY) while the SMC is idle
and no command is in flight, so the first PIO transaction on an
interrupt-capable PIO Mac always stalls for 1000 ms under smc->mutex and
permanently clears smc->interrupt_enabled.

In addition, calling reinit_completion(&smc->cmd_done) after outb() races
with complete(&smc->cmd_done) in apple_smc_acpi_irq() and can lose the
wakeup.  Returning 0 on wakeup also skips verifying (status & mask) == val,
and the fallback debug message says "mmio/wait" in the PIO path.

> +	ret = read_poll_timeout(inb, status, (status & mask) == val,
> +				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
> +				false, smc->port_base + SMC_IO_CMD_PORT);

[Severity: Medium]
Does polling with a 1 ms sleep interval inflate PIO and MMIO wait latency?

read_poll_timeout() with USEC_PER_MSEC sleeps 251-1000 us on the first
failed status check, both here and in apple_smc_acpi_mmio_wait().  Because
each PIO key access performs ~10-13 byte-level status handshakes while
holding smc->mutex, per-key latency grows from ~0.1-0.5 ms in applesmc
(which starts at 8 us with backoff in wait_status()) to several
milliseconds per key, stalling multi-key hwmon and power_supply queries.

[ ... ]

> +	for (ret = 0; ret < len; ret++) {
> +		if (apple_smc_acpi_port_wait(smc,
> +				SMC_IO_STATUS_AWAITING_DATA | SMC_IO_STATUS_BUSY,
> +				SMC_IO_STATUS_AWAITING_DATA | SMC_IO_STATUS_BUSY)) {
> +			dev_dbg(smc->dev, "port/read: read failed, key: 0x%X\n", key);
> +			return -EIO;
> +		}
> +		buffer[ret] = inb(smc->port_base + SMC_IO_DATA_PORT);
> +	}
> +
> +	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);

[Severity: Medium]
Should apple_smc_acpi_port_read() drain unread bytes while
SMC_IO_STATUS_AWAITING_DATA is set before waiting for SMC_IO_STATUS_BUSY
to clear?

As described in commit 25f2bd7f5add ("hwmon: (applesmc) Always read until
end of data"), 2012+ Intel SMCs can leave trailing bytes in the output
FIFO, keeping SMC_IO_STATUS_BUSY asserted until drained.  Without the
flush loop from applesmc.c read_smc(), waiting directly for BUSY to clear
times out after 1000 ms and leaves the SMC PIO state machine
desynchronized, especially since apple_smc_read() does not validate the
caller's length against key info.size.

[ ... ]

> +static int apple_smc_acpi_port_get_key_info(struct apple_smc_acpi *smc,
> +			smc_key key, struct apple_smc_key_info *info)
> +{
> +	u8 buf[6];
> +
> +	if (apple_smc_acpi_port_read(smc, SMC_MSG_GET_KEY_INFO, key, buf, sizeof(buf)))
> +		return -EIO;
> +
> +	if (!info)
> +		return 0;
> +
> +	info->size = buf[0];
> +	info->type_code = get_unaligned_be32(&buf[1]);
> +	info->flags = buf[5];
> +
> +	return 0;
> +}

[Severity: Low]
As reported by Ilpo Järvinen on RFC [1], this still reads into a raw
u8 buf[6] array with magic offsets instead of a __packed struct with named
members and a __be32 type_code field.

The #include <linux/compiler.h> at the top of the file is also unused
(__packed comes from linux/compiler_attributes.h), and the commit message
still wraps lines early at 51-60 columns instead of 72-75 columns.

> +static void apple_smc_acpi_mmio_clear(struct apple_smc_acpi *smc)
> +{
> +	if (ioread8(smc->iomem_base + SMC_MMIO_KEY_STATUS))
> +		return iowrite8(0, smc->iomem_base + SMC_MMIO_KEY_STATUS);
> +}

[Severity: Low]
Returning the void result of iowrite8() from a void function violates ISO
C and triggers sparse/pedantic warnings; dropping the return keyword fixes
it.

Also, dev_dbg(smc->dev, "mmio/wait: timeout"); in
apple_smc_acpi_mmio_wait() is missing a trailing newline.

> +static int apple_smc_acpi_mmio_wait(struct apple_smc_acpi *smc)
> +{
> +	u8 status;
> +	int ret;
> +
> +	if (smc->interrupt_enabled) {
> +		if (wait_for_completion_timeout(&smc->cmd_done,
> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> +			return 0;
> +
> +		smc->interrupt_enabled = 0;
> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> +	}

[Severity: Medium]
Can a delayed or spurious SMC_INT_CMD_DONE wake apple_smc_acpi_mmio_wait()
before the in-flight MMIO command finishes?

apple_smc_acpi_try_enable_interrupts() polls the NTOK=1 write while the
IRQ handler is already active and sets smc->interrupt_enabled = 1 without
draining any resulting SMC_INT_CMD_DONE.  Because
apple_smc_acpi_mmio_wait() returns 0 immediately on wakeup without
checking SMC_MMIO_STATUS_DONE, an early wakeup causes
apple_smc_acpi_mmio_result() to read an unfinished command opcode (-EIO)
or stale SMC_MMIO_KEY_DATA.

In addition, once a timeout clears smc->interrupt_enabled = 0, NTOK stays
enabled in hardware, so the IRQ handler still calls complete() while the
polled MMIO paths unconditionally call unlocked reinit_completion():

CPU0 (polled MMIO)                CPU1 (<hardirq>)
apple_smc_acpi_mmio_read()
  reinit_completion(&smc->cmd_done)
    cmd_done.done = 0;            apple_smc_acpi_irq()
                                    complete(&smc->cmd_done)
                                      cmd_done.done++;  <-- data race

Disabling NTOK (or gating complete() and reinit_completion() on
interrupt_enabled) and verifying SMC_MMIO_STATUS_DONE after wakeup would
avoid both issues.

[ ... ]

> +	info->type_code = cpu_to_be32(ioread32(smc->iomem_base + SMC_MMIO_KEY_DATA));

[Severity: Low]
Does assigning cpu_to_be32() to host-order u32 info->type_code trigger a
sparse endianness warning?  Using ioread32be() reads the big-endian MMIO
register directly into u32 and matches iowrite32be() above.

[ ... ]

> +	if (smc->is_mmio) {
> +		status = ioread8(smc->iomem_base + SMC_MMIO_KEY_INTERRUPT_STATUS);
> +		if (!(status & SMC_MMIO_IRQ_PENDING) && status)
> +			return IRQ_NONE;
> +	} else {
> +		status = inb(smc->port_base + SMC_IO_CMD_PORT);
> +		if (!(status & SMC_IO_STATUS_IRQ_PENDING) && status)
> +			return IRQ_NONE;
> +	}

[Severity: Medium]
Why do both status checks include "&& status"?

When no SMC interrupt is pending and the status register reads 0, the
condition evaluates to false and apple_smc_acpi_irq() does not return
IRQ_NONE.  On a spurious or shared interrupt, it falls through to read
SMC_IO_INT_ID_PORT (risking re-dispatching a stale ID such as
SMC_INT_SHUTDOWN or SMC_INT_CMD_DONE) and unconditionally returns
IRQ_HANDLED even for unknown or zero int_id values.  Conversely, if an
event arrives without IRQ_PENDING while another status bit such as
SMC_IO_STATUS_BUSY is set, this check drops it with IRQ_NONE.

[ ... ]

> +	case ACPI_RESOURCE_TYPE_IRQ:
> +		smc->irq = res->data.irq.interrupts[0];
> +		return AE_OK;

[Severity: Medium]
Does storing the raw ACPI IRQ number from _CRS bypass Linux IRQ
translation and ignore ExtendedIrq descriptors and IRQ flags?

acpi_create_platform_device() already translates both
ACPI_RESOURCE_TYPE_IRQ and ACPI_RESOURCE_TYPE_EXTENDED_IRQ into
IORESOURCE_IRQ resources with trigger and shareability flags.  Passing the
raw GSI to devm_request_irq() with hardcoded flags 0 in
apple_smc_acpi_probe() can register on the wrong Linux IRQ when the GSI
does not map 1:1, fail with -EBUSY on shared lines, or miss ExtendedIrq
descriptors and disable SMC notifications.  Using
platform_get_irq_optional() handles translation and trigger setup.

[ ... ]

> +	smc->iomem_base = devm_ioremap(smc->dev, smc->iomem_base_addr,
> +					smc->iomem_base_size);

[Severity: Low]
Should this claim the MMIO window with devm_request_mem_region() (or
devm_ioremap_resource()) before mapping it, as apple_smc_acpi_probe() does
for the PIO ports with devm_request_region()?  Without an IORESOURCE_BUSY
reservation, conflicting drivers will not get -EBUSY,
CONFIG_IO_STRICT_DEVMEM protection is bypassed, and /proc/iomem does not
show macsmc-acpi owning the window.

[ ... ]

> +	if (ret < 0)
> +		return ret;
> +
> +	return size;
> +}

[Severity: Low]
Should apple_smc_acpi_write() return 0 on success instead of size?

include/linux/mfd/macsmc.h documents apple_smc_write() as returning 0 on
success (matching macsmc-rtkit), and APPLE_SMC_TYPE_OPS passes its return
value directly through.  Returning size leaks positive byte counts out of
callbacks documented to return 0 or negative errno, such as
macsmc_hwmon_write_fan() (hwmon_ops.write) and
macsmc_battery_set_property().

[ ... ]

> +static ssize_t plimit_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> +	struct apple_smc *smc = dev_get_drvdata(dev);
> +	struct apple_smc_acpi *smc_acpi = smc->be_cookie;
> +
> +	return sysfs_emit(buf, "%08x %02x\n",
> +			inl(smc_acpi->port_base + SMC_IO_INT_PLIMIT),
> +			inb(smc_acpi->port_base + SMC_IO_INT_PLIMIT_GPU));
> +}
> +static DEVICE_ATTR_RO(plimit);

[Severity: Low]
This adds a new userspace sysfs attribute that formats two values in one
file (violating the sysfs one-value-per-file convention), has no
Documentation/ABI/ entry, and is not mentioned in the commit message.

plimit_show() and apple_smc_acpi_resume() also reach directly into core
struct apple_smc internals (smc->be_cookie and smc->mutex) instead of
using core helpers.

[ ... ]

> +static int apple_smc_acpi_probe(struct platform_device *pdev)
> +{
> +	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);

[Severity: Medium]
Can ACPI_COMPANION(&pdev->dev) return NULL here?

Because platform_bus_type allows driver_override, binding a non-ACPI
platform device to macsmc-acpi via sysfs enters apple_smc_acpi_probe()
with a NULL adev, causing a NULL pointer dereference oops when
adev->handle is evaluated below.

[ ... ]

> +	status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
> +				apple_smc_acpi_walk_resources, smc);

[Severity: Medium]
Is adev->handle dereferenced without checking if adev is non-NULL?
Checking if (!adev) return -ENODEV; or passing ACPI_HANDLE(&pdev->dev)
avoids a NULL pointer dereference if a non-ACPI platform device is bound
to this driver.

[ ... ]

> +	if (!devm_request_region(smc->dev, smc->port_base, SMC_IO_NR_PORTS, "macsmc-acpi"))
> +		return -EBUSY;

[Severity: Medium]
Can macsmc-acpi and applesmc race for this 32-byte I/O port region at
boot?

Both drivers auto-load on Intel Macs (APP0001 ACPI modalias vs applesmc
DMI whitelist) and request 0x300-0x31f.  When both are built as modules,
udev loads them concurrently, non-deterministically switching userspace
between the legacy applesmc ABI and the macsmc MFD ABIs across boots; when
both are built-in, applesmc always claims the region first.

[ ... ]

> +	apple_smc_acpi_try_enable_interrupts(smc);
> +
> +	return apple_smc_probe(smc->dev, &apple_smc_acpi_be_ops, smc, &smc->event_handlers, true);

[Severity: Medium]
Does enabling NTOK=1 before apple_smc_probe() leave hardware notifications
armed if apple_smc_probe() fails early?

apple_smc_probe() does not register devm_add_action_or_reset(...,
apple_smc_disable_notifications, ...) until after devm_kzalloc() and the
initial #KEY, first_key, and last_key reads.  If any of those fail, devres
unregisters apple_smc_acpi_irq() while NTOK remains 1 in SMC hardware.

Also, during normal teardown, apple_smc_acpi_notifications() writes NTOK=0
while smc->interrupt_enabled is still 1, which risks a 1000 ms timeout if
clearing NTOK suppresses its own CMD_DONE interrupt.

> +static int apple_smc_acpi_resume(struct device *dev)
> +{
> +	struct apple_smc *smc = dev_get_drvdata(dev);
> +	struct apple_smc_acpi *smc_acpi = smc->be_cookie;
> +
> +	/* NTOK may be set to 0 on resume */
> +	if (smc_acpi->interrupt_enabled) {
> +		mutex_lock(&smc->mutex);
> +		smc_acpi->interrupt_enabled = 0;
> +		apple_smc_acpi_try_enable_interrupts(smc_acpi);
> +		mutex_unlock(&smc->mutex);
> +	}
> +	return 0;
> +}

[Severity: Medium]
Is checking smc_acpi->interrupt_enabled before acquiring smc->mutex a data
race and TOCTOU?

There is no .suspend callback and IRQs are re-enabled before dpm_resume()
runs, so a concurrent SMC transaction on a non-freezable workqueue can
clear interrupt_enabled under smc->mutex while apple_smc_acpi_resume()
reads it unlocked:

CPU0 (dpm_resume)                 CPU1 (kworker)
apple_smc_acpi_resume()
  if (smc_acpi->interrupt_enabled)
                                  apple_smc_read()
                                    mutex_lock(&smc->mutex)
                                    apple_smc_acpi_mmio_wait()
                                      smc->interrupt_enabled = 0;
                                    mutex_unlock(&smc->mutex)
  mutex_lock(&smc->mutex)
  smc_acpi->interrupt_enabled = 0;
  apple_smc_acpi_try_enable_interrupts()  <-- TOCTOU / data race

Acquiring smc->mutex before checking smc_acpi->interrupt_enabled closes
the race.

[Severity: Medium]
Can apple_smc_acpi_resume() permanently skip restoring NTOK=1 after
suspend/resume?

ACPI runtime GPEs are re-enabled in platform_resume_early() or
platform_resume_finish() before dpm_resume() runs apple_smc_acpi_resume().
If a non-freezable ACPI notification (such as ACPI0003 triggering
power_supply_changed() -> apple_smc_read*()) accesses the SMC while
firmware has reset NTOK to 0, apple_smc_acpi_mmio_wait() stalls for
1000 ms and clears smc->interrupt_enabled = 0.  When
apple_smc_acpi_resume() then runs, it sees interrupt_enabled == 0 and
skips apple_smc_acpi_try_enable_interrupts(), leaving SMC accesses stuck
in polling mode and all asynchronous SMC notifications disabled across
subsequent resumes.  The same occurs after any single transient missed IRQ
followed by suspend/resume.

[ ... ]

> +		.dev_groups = apple_smc_acpi_groups,

[Severity: Low]
Registering apple_smc_acpi_groups exposes the undocumented plimit sysfs
attribute to userspace without a Documentation/ABI/ entry or commit
message description; once merged, it becomes permanent kernel ABI.

[1] https://lore.kernel.org/r/0cba7eea-ed39-d4d8-8587-f1c07cb5b03f@linux.intel.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=2

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 01/14] treewide: Add backend for macsmc
  2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
  2026-12-04 13:56   ` sashiko-bot
@ 2026-12-04 14:07   ` Andy Shevchenko
  2026-12-04 16:45   ` Sven Peter
  2 siblings, 0 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 14:07 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Fri, Dec 04, 2026 at 08:12:41AM -0500, Atharva Tiwari wrote:
> Split the Apple SMC driver into a common core and a backend
> that handles the actual communication. The existing RTKit
> code moves to its own backend, and nothing changes for
> Apple Silicon.
> 
> This lets the same SMC drivers run on other kinds of
> hardware, starting with Intel Macs, as a replacement for
> applesmc.

There are plenty of style related issues in this code, besides the fact
that it begs for a split. Read mailing list archives to understand what
the problems are.

...

> +#include <linux/bitfield.h>
> +#include <linux/device.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/mutex.h>
> +#include <linux/spinlock.h>

Does it follow IWYU?

...

> +EXPORT_SYMBOL(apple_smc_enter_atomic);

Why no namespace is used?

...

> +int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, const void *buf, size_t size)
> +{
> +	guard(spinlock_irqsave)(&smc->lock);

Delimit guard()() with blank line(s) so it will be easier to catch when reading
the code.

> +	return smc->be->write_atomic(smc->be_cookie, key, buf, size);
> +}

...

> +int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key)
> +{
> +	guard(mutex)(&smc->mutex);
> +	int ret;

No, we define variables at the top (yes, still).

> +	ret = smc->be->get_key_by_index(smc->be_cookie, index, key);
> +	*key = swab32(*key);
> +
> +	return ret;
> +}

...

The above just something that I see briefly. But you need to revisit the whole
code base.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 06/14] leds: add support for macsmc kbl
  2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
@ 2026-12-04 14:07   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:07 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] leds: macsmc: stale brightness cache races with async
  brightness_set_blocking
- [Medium] leds: macsmc: missing suspend handling races with resume and
  parent SMC PM
- [Medium] mfd: macsmc: apple_smc_key_exists() for LKSB stalls PIO probe
  for 1000 ms
- [Low] leds: macsmc: commit subject, changelog, and ddata naming
  convention issues
- [Low] leds: macsmc: macsmc_led_probe() sets internal led_classdev.dev
  field
--

commit 37d499b0477cc7b3e4f2a80df75efcdc8c547b85
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

> leds: add support for macsmc kbl
>
> Add a LED class driver to control the keyboard backlight.
>
> This replaces the keyboard backlight support in applesmc.
>
> Tested-by: Ihor Odainyi <pv4k@odayny.com>
> Tested-by: Antoine Sidem <sidemantoine@gmail.com>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
This isn't a bug, but the commit subject does not follow the LEDs
subsystem convention ("leds: <driver>: <Capitalized description>", for
example "leds: macsmc: Add keyboard backlight driver") and uses the
unexplained abbreviation "kbl".

The commit message also omits the change in drivers/mfd/macsmc-core.c
that registers the macsmc-led MFD cell when SMC_KEY(LKSB) exists.

A few minor subsystem conventions: LED drivers typically name their
private data pointer ddata instead of drv and report probe errors with
dev_err_probe(), and MFD drivers prefer PLATFORM_DEVID_AUTO over literal
-1 in devm_mfd_add_devices().

> diff --git a/drivers/leds/leds-macsmc.c b/drivers/leds/leds-macsmc.c
> new file mode 100644
> index 0000000000000..095653765cc80
> --- /dev/null
> +++ b/drivers/leds/leds-macsmc.c

[ ... ]

> +static enum led_brightness macsmc_led_get_brightness(struct led_classdev *cdev)
> +{
> +	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
> +
> +	return drv->brightness;
> +}
> +
> +static int macsmc_led_set_brightness(struct led_classdev *cdev, enum led_brightness value)
> +{
> +	struct macsmc_led *drv = container_of(cdev, struct macsmc_led, cdev);
> +	int ret;
> +
> +	ret = apple_smc_write_u16(drv->smc, SMC_KEY(LKSB), (u16) (value & 0xFF));
> +	if (ret < 0)
> +		return ret;
> +
> +	drv->brightness = value & 0xFF;
> +
> +	return 0;
> +}

[Severity: Medium]
Can macsmc_led_get_brightness() race with the asynchronous
brightness_set_blocking work and overwrite led_cdev->brightness with a
stale value?

When userspace writes a new brightness, brightness_store() updates
led_cdev->brightness synchronously, queues set_brightness_work on leds_wq,
and drops led_cdev->led_access.  A subsequent read of brightness then
calls led_update_brightness() -> macsmc_led_get_brightness() without any
lock shared with macsmc_led_set_brightness():

CPU0                              kworker (leds_wq)
brightness_store(new)
  led_cdev->brightness = new
  queue_work(set_brightness_work)
                                  set_brightness_delayed()
                                    macsmc_led_set_brightness(new)
                                      apple_smc_write_u16(LKSB, new)
brightness_show()
  led_update_brightness()
    macsmc_led_get_brightness()
      return drv->brightness  <-- stale read / data race
    led_cdev->brightness = old
                                      drv->brightness = new

Because set_brightness_delayed() does not update led_cdev->brightness
afterwards, led_cdev->brightness stays stuck at the stale value until
another read or write occurs, and the unlocked access to drv->brightness
is a data race.  Since SMC key LKSB is write-only (as in
drivers/hwmon/applesmc.c), leaving brightness_get NULL lets the LED core
report its synchronously maintained led_cdev->brightness.

[ ... ]

> +	drv->cdev.name = "smc::kbd_backlight";
> +	drv->cdev.max_brightness = 255;
> +	drv->cdev.brightness_get = macsmc_led_get_brightness;
> +	drv->cdev.brightness_set_blocking = macsmc_led_set_brightness;
> +	drv->cdev.dev = &pdev->dev;

[Severity: Low]
Should drv->cdev.dev = &pdev->dev be dropped?

led_classdev.dev is an internal field populated by
led_classdev_register_ext() with the newly created leds_class child
device and checked by led_classdev_unregister(); the parent device is
already passed to devm_led_classdev_register().

[ ... ]

> +static int macsmc_led_resume(struct device *dev)
> +{
> +	struct macsmc_led *drv = dev_get_drvdata(dev);
> +	int ret;
> +
> +	ret = apple_smc_write_u16(drv->smc, SMC_KEY(LKSB), (u16) (drv->brightness));
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(macsmc_led_pm, NULL, macsmc_led_resume);

[Severity: Medium]
Does omitting suspend handling allow set_brightness_work to race with
parent SMC resume and with macsmc_led_resume()?

Because LED_CORE_SUSPENDRESUME is unset and macsmc_led_pm has no suspend
callback, set_brightness_work on the non-freezable leds_wq is never
quiesced across sleep.  An active trigger or pending brightness update
can issue an SMC write during suspend or early resume before
apple_smc_acpi_resume() re-enables NTOK; if that write times out,
macsmc-acpi clears interrupt_enabled to 0, preventing
apple_smc_acpi_resume() from re-enabling SMC interrupts until reboot.

In addition, macsmc_led_resume() reads drv->brightness without a lock
shared with macsmc_led_set_brightness():

CPU0 (resume)                     kworker (leds_wq)
macsmc_led_resume()
  reads old drv->brightness
                                  macsmc_led_set_brightness(new)
                                    apple_smc_write_u16(LKSB, new)
                                    drv->brightness = new
  apple_smc_write_u16(LKSB, old)  <-- overwrites newer brightness

Setting LED_CORE_SUSPENDRESUME in drv->cdev.flags and dropping
macsmc_led_resume(), macsmc_led_pm, and drv->brightness lets the LED
core set LED_SUSPENDED and flush set_brightness_work on suspend, then
restore brightness on resume.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index 6567d2f1f8f53..bc4200f574bd5 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -179,6 +183,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  			if (ret < 0)
>  				return ret;
>  		}
> +
> +		if (apple_smc_key_exists(smc, SMC_KEY(LKSB))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_led,
> +				ARRAY_SIZE(apple_smc_acpi_led), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}

[Severity: Medium]
Does probing SMC_KEY(LKSB) via apple_smc_key_exists() stall boot for a
full second on PIO-based Intel Macs without a keyboard backlight?

On PIO Macs (such as desktop iMac, Mac Mini, or Mac Pro models),
apple_smc_key_exists() calls apple_smc_get_key_info() ->
apple_smc_acpi_port_read(), which has no error-status check and only
returns an error when apple_smc_acpi_port_wait() hits the 1000 ms
SMC_TIMEOUT_MS timeout.  Legacy drivers/hwmon/applesmc.c avoids this
stall in applesmc_has_key() by binary-searching valid key indices
instead.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=6

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  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 14:25   ` sashiko-bot
  1 sibling, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 14:08 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:
> When macsmc-power is enabled on an Intel Mac, skip acpi-sbs
> and the ACPI battery and adapter drivers, since macsmc-power
> now provides them. This avoids duplicate devices.

...

> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> +		return -ENODEV;


This is a hack. And it's even indented wrongly.

...

> @@ -664,7 +668,6 @@ static int acpi_sbs_probe(struct platform_device *pdev)
>  					acpi_battery_add(sbs, id);
>  		}
>  	}
> -
>  	if (!sbs->manager_present)
>  		acpi_battery_add(sbs, 0);

What the heck is this?

...

Please, read what you is about to send,

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 05/14] iio/accel: add driver for apple SMS
  2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
@ 2026-12-04 14:11   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:11 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] iio: accel: macsmc-accel: missing event config callbacks in
  macsmc_accel_info
- [Medium] iio: accel: macsmc_accel_probe() enables notifier before IIO
  registration
- [Medium] iio: accel: macsmc_accel_dev_init() ignores SMC errors and
  misorders poll
- [Medium] iio: accel: macsmc-accel: undocumented orientation change
  event ABI
- [Medium] mfd: macsmc: probing absent MOCN via apple_smc_key_exists()
  stalls PIO boot
- [Low] iio: accel: macsmc-accel: s16 passed to be16_to_cpu() in
  macsmc_accel_read()
- [Low] iio: accel: macsmc-accel: Makefile order, MFD cell ID, and
  subject conventions
--

commit 72edf11305348abc7eba7049f44352095cfc9e6d
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

iio/accel: add driver for apple SMS

This commit adds an IIO accelerometer driver for the Apple SMC Sudden
Motion Sensor (reporting X/Y/Z axes and drop, orientation, and shock
events) and registers it from the ACPI SMC MFD core when the MOCN key
exists.

> diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
> index fa440a8592839..52fe661dec666 100644
> --- a/drivers/iio/accel/Makefile
> +++ b/drivers/iio/accel/Makefile
> @@ -54,6 +54,7 @@ obj-$(CONFIG_KXSD9)	+= kxsd9.o
>  obj-$(CONFIG_KXSD9_SPI)	+= kxsd9-spi.o
>  obj-$(CONFIG_KXSD9_I2C)	+= kxsd9-i2c.o
>  obj-$(CONFIG_MC3230)	+= mc3230.o
> +obj-$(CONFIG_MACSMC_ACCEL)	+= macsmc-accel.o

[Severity: Low]
This isn't a bug, but CONFIG_MACSMC_ACCEL is placed after CONFIG_MC3230,
breaking the alphabetical ordering in this Makefile.  Similarly, the new
devm_mfd_add_devices() call in drivers/mfd/macsmc-core.c passes -1 instead
of PLATFORM_DEVID_AUTO (or PLATFORM_DEVID_NONE), and the commit subject
uses "iio/accel:" instead of the standard "iio: accel:" prefix.

> diff --git a/drivers/iio/accel/macsmc-accel.c b/drivers/iio/accel/macsmc-accel.c
> new file mode 100644
> index 0000000000000..79891fd13c56a
> --- /dev/null
> +++ b/drivers/iio/accel/macsmc-accel.c

[ ... ]

> +static int macsmc_accel_read(struct macsmc_accel *drv, smc_key key, s16 *p)
> +{
> +	int ret;
> +
> +	ret = apple_smc_read_s16(drv->smc, key, p);
> +	if (ret < 0)
> +		return ret;
> +
> +	*p = (s16)be16_to_cpu(*p);
> +	return 0;
> +}

[Severity: Low]
Does passing host-endian s16 *p directly to be16_to_cpu() trigger a sparse
endianness warning?  __be16_to_cpu() expects a restricted __be16 value, so
reading into a local __be16 (e.g., via apple_smc_read()) and converting
with be16_to_cpu() into *p keeps the endianness types sparse-clean.

> +static int macsmc_accel_dev_init(struct macsmc_accel *drv)
> +{
> +	int ret, total;
> +	u16 buf, write_value;
> +
> +	ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* 0xE0 enables the interrupts and the actual motion sensors */
> +	write_value = buf | 0xE0;
> +
> +	for (total = 0; total < 100; total++) {
> +		ret = apple_smc_read_u16(drv->smc, SMC_KEY(MOCN), &buf);
> +		if (!ret && (buf & 0xE0) == 0xE0)
> +			return 0;
> +
> +		apple_smc_write_u16(drv->smc, SMC_KEY(MOCN), write_value);
> +		msleep(50);
> +	}
> +
> +	return -ENODEV;
> +}

[Severity: Medium]
Can this retry loop stall probe or hibernation restore for minutes while
holding smc->mutex?

Both read errors from apple_smc_read_u16() and the return value of
apple_smc_write_u16() are ignored across 100 iterations.  Each SMC
transaction holds smc->mutex and can wait up to SMC_TIMEOUT_MS (1000 ms),
turning persistent timeouts into a multi-minute stall for sibling drivers.

The loop also re-reads MOCN on iteration 0 without checking the initial
read for (buf & 0xE0) == 0xE0, and returns -ENODEV after the 100th write
and sleep without checking whether that final write took effect.  Checking
the initial read, propagating I/O errors (or bounding wall-clock time),
and doing write, sleep, then read in the loop avoids these issues.

[ ... ]

> +	case SMC_INT_SMS_ORIENTATION:
> +		code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z,
> +					  IIO_EV_TYPE_CHANGE, IIO_EV_DIR_NONE);
> +		break;

[Severity: Medium]
As reported by Jonathan Cameron on RFC [1], what acceleration condition
triggers SMC_INT_SMS_ORIENTATION?  No other IIO_ACCEL driver uses
IIO_EV_TYPE_CHANGE, and in_accel_x|y|z_change_en is undocumented in
Documentation/ABI/testing/sysfs-bus-iio, so userspace cannot interpret it.

[ ... ]

> +static const struct iio_event_spec macsmc_accel_drop_events[] = {
> +	{
> +		.type = IIO_EV_TYPE_THRESH,
> +		.dir = IIO_EV_DIR_FALLING,
> +		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
> +	},
> +};
> +
> +static const struct iio_event_spec macsmc_accel_any_axis_events[] = {
> +	{
> +		.type = IIO_EV_TYPE_THRESH,
> +		.dir = IIO_EV_DIR_RISING,
> +		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
> +	},
> +	{
> +		.type = IIO_EV_TYPE_CHANGE,
> +		.dir = IIO_EV_DIR_NONE,
> +		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
> +	},
> +};

[ ... ]

> +static const struct iio_info macsmc_accel_info = {
> +	.read_raw = macsmc_accel_read_raw
> +};

[Severity: Medium]
Will all three exported *_en event sysfs attributes unconditionally fail
with -EINVAL?

Setting BIT(IIO_EV_INFO_ENABLE) registers the *_en attributes via
iio_ev_state_show() and iio_ev_state_store(), which both return -EINVAL
when read_event_config and write_event_config are NULL in
macsmc_accel_info.  This either needs those callbacks implemented or
BIT(IIO_EV_INFO_ENABLE) omitted if the events are always enabled.

[ ... ]

> +	ret = macsmc_accel_dev_init(drv);
> +	if (ret)
> +		return ret;
> +
> +	drv->indio_dev = indio_dev;
> +	drv->nb.notifier_call = macsmc_accel_event;
> +	ret = blocking_notifier_chain_register(drv->smc->event_handlers, &drv->nb);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(&pdev->dev, macsmc_accel_unregister_notifier, drv);
> +	if (ret)
> +		return ret;
> +
> +	platform_set_drvdata(pdev, drv);
> +
> +	indio_dev->name = "macsmc-accel";
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->info = &macsmc_accel_info;
> +	indio_dev->channels = macsmc_accel_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(macsmc_accel_channels);
> +
> +	return devm_iio_device_register(&pdev->dev, indio_dev);
> +}

[Severity: Medium]
Can macsmc_accel_event() hit a use-after-free on ev_int if
devm_iio_device_register() fails?

The parent SMC IRQ and notifier work are already active before
macsmc_accel_probe() runs, and macsmc_accel_dev_init() enables motion
sensor interrupts before the IIO device is registered.  If a late step in
__iio_device_register() fails, it frees ev_int before devres unregisters
the notifier:

CPU0                              CPU1 (kworker)
macsmc_accel_probe()
  macsmc_accel_dev_init()
  blocking_notifier_chain_register()
  devm_iio_device_register()
    iio_device_register_eventset()
      iio_dev_opaque->event_interface = ev_int
                                  apple_smc_acpi_notifier_work()
                                    macsmc_accel_event()
                                      iio_push_event()
                                        ev_int = ...->event_interface
    ... (error unwind)
    kfree(ev_int)
    iio_dev_opaque->event_interface = NULL
                                        iio_event_enabled(ev_int)
                                          <-- use-after-free

If the freed slab object is reused with its enabled bit set, kfifo_put()
and wake_up_poll() can also corrupt memory.  Registering the IIO device
before registering the SMC notifier closes this window and ensures the
notifier is torn down before iio_device_unregister() on remove.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index 6014df4fe1c0a..6567d2f1f8f53 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -169,6 +173,12 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  				return ret;
>  		}
>  
> +		if (apple_smc_key_exists(smc, SMC_KEY(MOCN))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_accel,
> +				ARRAY_SIZE(apple_smc_acpi_accel), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}
>  	} else
>  		ret = devm_mfd_add_devices(dev, -1, apple_smc_rtkit_devs,
>  			ARRAY_SIZE(apple_smc_rtkit_devs), NULL, 0, NULL);

[Severity: Medium]
Does probing SMC_KEY(MOCN) via apple_smc_key_exists() add a 1-second
synchronous boot stall on PIO-based Intel Macs without a motion sensor?

On PIO Macs, apple_smc_acpi_port_get_key_info() has no non-timeout error
check, so an absent key only fails after apple_smc_acpi_port_wait() polls
SMC_IO_CMD_PORT for the full SMC_TIMEOUT_MS (1000 ms).  Binary searching
via GET_KEY_BY_INDEX (like applesmc_has_key()) avoids this timeout.

[1] https://lore.kernel.org/r/20261101013540.3af16ea0@jic23-hlaptop

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip
  2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
@ 2026-12-04 14:11   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:11 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Aditya Garg, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] x86: inconsistent naming and missing __ro_after_init on
  has_apple_t2_chip
- [Low] x86: open-coded match_string(), early return, and __initconst
  style
- [Low] x86/apple: missing var keyword in has_apple_t2_chip kernel-doc
  comment
- [Low] treewide: commit message omits load_uefi.c refactoring and
  export context
--

commit a2285f7954298eb43ab5023f81b0b6900c8dde80
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

> treewide: Add a flag to detect the Apple T2 chip
>
> Add a flag to detect Apple T2 chips on Intel Macs.
> Cache the result to avoid repeated checks. That will
> be used in upcoming patches.
>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
Should the commit message mention that this patch also converts
load_uefi_certs() in security/integrity/platform_certs/load_uefi.c to use
has_apple_t2_chip and removes uefi_skip_cert and UEFI_QUIRK_SKIP_CERT?
It would also help reviewers to note which upcoming drivers or runtime
paths need has_apple_t2_chip exported globally.

> diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c
> index a92f18db96100..6651e5d4d106f 100644
> --- a/arch/x86/kernel/quirks.c
> +++ b/arch/x86/kernel/quirks.c
> @@ -664,8 +664,45 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras
>  bool x86_apple_machine;
>  EXPORT_SYMBOL(x86_apple_machine);
>  
> +bool has_apple_t2_chip;
> +EXPORT_SYMBOL(has_apple_t2_chip);

[Severity: Low]
Should this flag keep the x86_apple_ prefix from x86_apple_machine (such
as x86_apple_t2 or x86_apple_t2_machine)?  Because x86/apple.h defines it
to false when CONFIG_X86 is disabled, an unprefixed name is misleading on
arm64 kernels running on Apple T2 SoC hardware.

Since has_apple_t2_chip is only written during early_platform_quirks(),
it can also be marked __ro_after_init.

> +
> +static const char * const __initconst apple_t2_models[] = {
> +	"MacBookPro15,1",

[ ... ]

> +	"iMacPro1,1",
> +};
> +
>  void __init early_platform_quirks(void)
>  {
>  	x86_apple_machine = dmi_match(DMI_SYS_VENDOR, "Apple Inc.") ||
>  			    dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc.");
> +
> +	if (x86_apple_machine) {
> +		const char *product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
> +		int i;
> +
> +		if (!product_name)
> +			return;
> +
> +		for (i = 0; i < ARRAY_SIZE(apple_t2_models); i++) {
> +			if (!strcmp(product_name, apple_t2_models[i])) {
> +				has_apple_t2_chip = true;
> +				break;
> +			}
> +		}
> +	}
>  }

[Severity: Low]
Could this loop reuse match_string(apple_t2_models,
ARRAY_SIZE(apple_t2_models), product_name) >= 0?  Returning early when
product_name is NULL also exits early_platform_quirks() entirely, which
would skip any future quirks added after this block.

Also, per include/linux/init.h, __initconst belongs between the variable
name and "=" (apple_t2_models[] __initconst =).  Note that an array of
pointers only puts the pointer table in .init.rodata while leaving the
model strings in permanent .rodata.

> diff --git a/include/linux/platform_data/x86/apple.h b/include/linux/platform_data/x86/apple.h
> index 079e816c3c219..47b27dceab18c 100644
> --- a/include/linux/platform_data/x86/apple.h
> +++ b/include/linux/platform_data/x86/apple.h
> @@ -6,8 +6,13 @@
>   * x86_apple_machine - whether the machine is an x86 Apple Macintosh
>   */
>  extern bool x86_apple_machine;
> +/**
> + * has_apple_t2_chip - whether the machine has the Apple T2 chip
> + */
> +extern bool has_apple_t2_chip;

[Severity: Low]
Does this kernel-doc comment need the "var" keyword ("* var
has_apple_t2_chip - ...")?  Without it, scripts/kernel-doc parses the
declaration as a function and emits a "cannot understand function
prototype" warning.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=8

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  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 14:16   ` sashiko-bot
  1 sibling, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 14:12 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Aditya Garg, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:
> Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
> work correctly on T2 Macs, so the clock from the SMC is
> used instead.
> 
> On these machines the time offset is kept in the SMC instead
> of NVMEM, and the clock rate is read from the SMC too.

...

> +static bool force_clkm;
> +module_param(force_clkm, bool, 0644);
> +MODULE_PARM_DESC(force_clkm, "Force CLKM Key, instead of trying to use CLKL");

No, why?!

...

>  struct macsmc_rtc {
>  	struct device *dev;
>  	struct apple_smc *smc;
>  	struct rtc_device *rtc_dev;
>  	struct nvmem_cell *rtc_offset;
> +	uint8_t shift;

No, use kernel types.

> +	bool async_rtc;
>  };

...

> +static int macsmc_rtc_read_clkl(struct macsmc_rtc *rtc, u64 *ctr)
> +{
> +	u64 request = 0xffffffffffffULL;
> +	u64 response = 0;
> +	int i, j, ret;
> +
> +	for (i = 0; i < 4; i++) {
> +		for (j = 0; j < 40; j++) {
> +			ret = apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES);
> +			if (ret == RTC_BYTES)
> +				break;
> +		}
> +		if (ret != RTC_BYTES)
> +			continue;
> +
> +		msleep(20);
> +
> +		for (j = 0; j < 20; j++) {
> +			ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &response, RTC_BYTES);
> +			if (ret == RTC_BYTES) {
> +				if ((response & 0x7fff) == 5 || (response & 0x7fff) == 6)
> +					return -EAGAIN;
> +
> +				if (response != 0xffffffffffffULL) {
> +					*ctr = response;
> +					return RTC_BYTES;
> +				}
> +			}
> +			fsleep(1000);
> +		}
> +	}
> +
> +	return -EIO;
> +}

Really, folks, read the last a year code or so to understand why the above is
no go (style-wise). It's your homework, you can find all of the typical issues
in the mailing list archives.

...

> +MODULE_ALIAS("platform:macsmc-rtc");

Are you sure it's a best approach?

...

Overall impression that you copied'n'pasted AI slop without much effort made on
editing and understanding. Also looks like each patch requires a logical split
to a mini-series.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  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:16   ` sashiko-bot
  1 sibling, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:16 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Aditya Garg, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] rtc: macsmc: shift underflow and UB on invalid CLKR in
  macsmc_rtc_probe()
- [Medium] rtc: macsmc: valid timestamps rejected with -EAGAIN in
  macsmc_rtc_read_clkl()
- [Medium] rtc: macsmc: unthrottled CLKL retries amplify SMC timeouts to
  160+ seconds
- [Low] rtc: macsmc: inconsistent CLKR and key logging in
  macsmc_rtc_probe()
- [Low] rtc: macsmc: undocumented CLKL protocol, magic values, and
  force_clkm param
--

commit 6ab7cff8bec4fb4d17c73d18ad219c5e9e888129
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

> rtc: add support for x86 macs in macsmc-rtc
>
> Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
> work correctly on T2 Macs, so the clock from the SMC is
> used instead.
>
> On these machines the time offset is kept in the SMC instead
> of NVMEM, and the clock rate is read from the SMC too.
>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

[Severity: Low]
This isn't a bug, but the commit message does not explain the new CLKL
latch/poll protocol or the force_clkm module parameter.  Documenting why CLKL
is needed over CLKM and what its magic values (0xffffffffffffULL, 0x7fff, 5,
6) mean in the changelog and comments would help maintainability.

Also, the CLKL/CLKM read logic is duplicated in macsmc_rtc_get_time() and
macsmc_rtc_set_time(), and macsmc_rtc_probe() splits the rtc->smc->is_acpi
check across two adjacent if blocks.

> diff --git a/drivers/rtc/rtc-macsmc.c b/drivers/rtc/rtc-macsmc.c
> index 8fe8830669569..900a46339f72f 100644
> --- a/drivers/rtc/rtc-macsmc.c
> +++ b/drivers/rtc/rtc-macsmc.c

[ ... ]

> +static int macsmc_rtc_read_clkl(struct macsmc_rtc *rtc, u64 *ctr)
> +{
> +	u64 request = 0xffffffffffffULL;
> +	u64 response = 0;
> +	int i, j, ret;
> +
> +	for (i = 0; i < 4; i++) {
> +		for (j = 0; j < 40; j++) {
> +			ret = apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES);
> +			if (ret == RTC_BYTES)
> +				break;
> +		}
> +		if (ret != RTC_BYTES)
> +			continue;
> +
> +		msleep(20);
> +
> +		for (j = 0; j < 20; j++) {
> +			ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &response, RTC_BYTES);

[Severity: Medium]
Can these retry loops block for 160+ seconds when the SMC is unresponsive?

The outer and inner loops perform up to 160 apple_smc_write() attempts with
no delay, backoff, timeout bailout, or signal check, followed by msleep(20)
and up to 80 apple_smc_read() attempts.  In macsmc-acpi.c, SMC_TIMEOUT_MS is
1000 ms, so timed-out CLKL transactions amplify into multi-minute stalls.

Because RTC callers hold rtc->ops_lock and every SMC transaction takes the
shared smc->mutex, a stall exceeds the hung-task timeout and blocks sibling
SMC subdevices as well as boot, suspend/resume, and sysfs RTC readers.  Even
on healthy hardware, msleep(20) adds at least 20 ms to every CLKL access.

> +			if (ret == RTC_BYTES) {
> +				if ((response & 0x7fff) == 5 || (response & 0x7fff) == 6)
> +					return -EAGAIN;
> +
> +				if (response != 0xffffffffffffULL) {
> +					*ctr = response;
> +					return RTC_BYTES;
> +				}
> +			}

[Severity: Medium]
Will masking response with 0x7fff reject valid timestamps with -EAGAIN?

The lower 15 bits of the 48-bit counter are the sub-second ticks at 32768 Hz,
so any valid counter value whose low 15 bits equal 5 or 6 (twice every second)
aborts immediately.  Neither macsmc_rtc_read_clkl() nor RTC core callers such
as rtc_hctosys() retry on -EAGAIN, causing sporadic RTC read/write failures.

[ ... ]

> @@ -102,18 +171,40 @@ static int macsmc_rtc_probe(struct platform_device *pdev)

[ ... ]

> +	if (rtc->smc->is_acpi) {
> +		ret = apple_smc_read_u32(rtc->smc, SMC_KEY(CLKR), &clkr);
> +		if (ret < 0 || clkr == 0xFFFFFFFF)
> +			rtc->shift = RTC_SEC_SHIFT;
> +		else
> +			rtc->shift = ffs(clkr) - 1;

[Severity: Medium]
Can an invalid CLKR value underflow rtc->shift and cause shift-out-of-bounds
undefined behavior?

If firmware returns clkr == 0, ffs(0) - 1 wraps uint8_t rtc->shift to 255.
That makes the 64-bit shifts for range_min/range_max in macsmc_rtc_probe()
(by 271 bits) and the shifts in macsmc_rtc_get_time() and
macsmc_rtc_set_time() (by 255 bits) undefined behavior.

Any non-power-of-two clkr also silently computes the wrong shift.  Checking
ret < 0 || !is_power_of_2(clkr) rejects 0, 0xFFFFFFFF, and non-powers of two
while keeping rtc->shift in 0..31.

[ ... ]

> +	dev_info(&pdev->dev, "%u clock, using %s key\n", (clkr != 0xFFFFFFFF) ? clkr : 32768,
> +				rtc->async_rtc ? "CLKL" : "CLKM");

[Severity: Low]
Can this dev_info() log a bogus clock rate or the wrong key?

If apple_smc_acpi_port_read() fails partway through reading CLKR, it has
already written partial bytes into clkr before returning -EIO, so clkr is no
longer 0xFFFFFFFF even though rtc->shift fell back to RTC_SEC_SHIFT.  Using
1U << rtc->shift avoids printing that corrupted value.

Also, rtc->async_rtc ? "CLKL" : "CLKM" ignores force_clkm, so with
force_clkm=1 on a CLKL system probe logs "using CLKL key" while get/set_time
actually use CLKM.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=7

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
  2026-12-04 13:58   ` sashiko-bot
@ 2026-12-04 14:19   ` Andy Shevchenko
  2026-12-04 14:52     ` Aditya Garg
  2026-12-04 19:57     ` Atharva Tiwari
  1 sibling, 2 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 14:19 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:
> Add a backend that talks to the SMC on Intel Macs over ACPI.
> It supports the old I/O port interface, and also MMIO and
> interrupt-driven completion, which applesmc doesn't have.
> If an interrupt is missed it falls back to polling.
> 
> This is the base that lets the macsmc drivers replace
> applesmc.

...

> +#include <linux/acpi.h>
> +#include <linux/bits.h>

> +#include <linux/byteorder/generic.h>

Wrong, the asm/byteorder.h has to be used.

> +#include <linux/cleanup.h>
> +#include <linux/compiler.h>
> +#include <linux/completion.h>
> +#include <linux/device.h>
> +#include <linux/devm-helpers.h>
> +#include <linux/interrupt.h>
> +#include <linux/io.h>

> +#include <linux/ioport.h>

> +#include <linux/iopoll.h>

With this, io.h is not required.

> +#include <linux/kfifo.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm.h>
> +#include <linux/reboot.h>
> +#include <linux/spinlock.h>
> +#include <linux/time.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
> +#include <linux/workqueue.h>

...

> +#define SMC_TIMEOUT_MS			1000

Why not (1 * MSEC_PER_SEC) here ?

...

> +struct apple_smc_acpi {
> +	struct device *dev;
> +
> +	u8 __iomem *iomem_base;
> +	u32 iomem_base_addr, iomem_base_size;
> +	bool is_mmio;
> +
> +	u16 port_base;
> +	bool has_port;
> +
> +	int irq;

> +	bool has_interrupt;

Why? Isn't non-positive value means no interrupt?

> +	bool interrupt_enabled;

Why? Isn't IRQ core provides something for this?

> +	struct completion cmd_done;
> +
> +	struct blocking_notifier_head event_handlers;
> +	struct work_struct shutdown_work;
> +	struct work_struct notifier_work;
> +
> +	DECLARE_KFIFO(event_fifo, u8, 64);
> +	/* Protects event_fifo, shared between the IRQ handler and notifier_work */
> +	spinlock_t event_lock;
> +};
> +
> +

Why double blank line?

> +static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
> +{
> +	u8 status;
> +	int ret;
> +
> +	if (smc->interrupt_enabled) {
> +		reinit_completion(&smc->cmd_done);
> +		if (wait_for_completion_timeout(&smc->cmd_done,
> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> +			return 0;
> +
> +		smc->interrupt_enabled = 0;
> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> +	}
> +
> +	ret = read_poll_timeout(inb, status, (status & mask) == val,
> +				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
> +				false, smc->port_base + SMC_IO_CMD_PORT);
> +	if (ret)
> +		dev_dbg(smc->dev, "port/wait: timeout value:%u, mask:%u\n", val, mask);
> +
> +	return ret;
> +}

...

> +static int apple_smc_acpi_port_write_key(struct apple_smc_acpi *smc, smc_key key)
> +{
> +	int i;
> +
> +	for (i = 3; i >= 0; i--) {
> +		if (apple_smc_acpi_port_write_byte(smc, (key >> (i * 8)) & 0xff))
> +			return -EIO;
> +	}

Missing blank line.

> +	return 0;

This should use proper __be32 type instead.

> +}
> +
> +static int apple_smc_acpi_port_valid(struct apple_smc_acpi *smc)
> +{
> +	int ret;

> +	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> +	if (!ret)

Huh?! This is way non-standard. Don't do that.
This is a semantic mistake.

> +		return ret;
> +
> +	ret = apple_smc_acpi_port_write_cmd(smc, SMC_MSG_READ_KEY);
> +	if (ret)
> +		return ret;
> +
> +	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> +}

...

> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
> +	{"APP0001", 0},
> +	{}
> +};

Where have you been last half a year?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc
  2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
                   ` (13 preceding siblings ...)
  2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
@ 2026-12-04 14:20 ` Andy Shevchenko
  14 siblings, 0 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 14:20 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

On Fri, Dec 04, 2026 at 08:12:40AM -0500, Atharva Tiwari wrote:
> applesmc is very old, and all of its code is lumped into one
> driver. Fan control, sensors, the light sensor, the motion
> sensor and the keyboard backlight in a single file
> with its own way of talking to the SMC. It is hard to extend
> and to support new machines.
> 
> This series adds Intel Mac support to the macsmc drivers that
> were written for Apple Silicon (the Asahi implementation).
> The SMC works the same way on both platforms, so we share a
> lot of code with Asahi. Only the way of talking to the SMC
> differs.
> 
> To make that work, patch 1 splits the macsmc driver into a
> common core and a backend. The existing RTKit code moves into
> its own backend. Patch 2 adds an ACPI backend for Intel Macs
> with I/O port, MMIO and interrupt support. After that, each
> function gets its own small driver using the standard kernel
> interfaces (hwmon, IIO, LEDs, power supply, RTC, watchdog),
> instead of one large driver doing everything.
> 
> On Intel Macs these drivers replace applesmc (hwmon, light
> sensor, motion sensor and keyboard backlight) and acpi-sbs
> (battery and adapter). They are mutually exclusive with the
> drivers they replace, so only one is used at a time.
> 
> The series is organised as follows:
> 
>   1      Split macsmc into a core and backends
>   2      ACPI backend for Intel Macs
>   3-6    New drivers: watchdog, IIO light and accelerometer,
>          keyboard backlight LED
>   7-9    RTC support for T2 Macs, a T2 detection flag, and
>          disabling the broken ACPI RTCs
>   10-11  Power supply support, replacing acpi-sbs
>   12-13  hwmon support for Intel Macs
>   14     ioctl for userspace access to SMC keys

This AI slop needs a lot more *human* work. Take your time, polish
the output. This series anyways missed v7.5.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  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:25   ` sashiko-bot
  1 sibling, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:25 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] acpi: unconditional skip leaves Intel Macs without battery or
  AC drivers
- [High] power: supply: NULL power->adapter deref in
  macsmc_power_probe()
- [Low] acpi: Apple skip check bypasses DMI overrides and is duplicated
  in sbs.c
--

commit 1f23bca9ef468a05d91753f57047443718511acf
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

acpi: disable battery and adapter for x86 apple machines

This commit skips probing acpi-sbs and disables the ACPI AC and battery
drivers on x86 Apple machines when CONFIG_MACSMC_ACPI and
CONFIG_MACSMC_POWER are enabled.

> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index f10bbf13c242f..368bcae7223f3 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -634,6 +634,10 @@ static int acpi_sbs_probe(struct platform_device *pdev)
>  	int result = 0;
>  	int id;
>  
> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> +		return -ENODEV;
> +
>  	device = ACPI_COMPANION(&pdev->dev);
>  	if (!device)
>  		return -ENODEV;

[Severity: High]
Can this leave Intel Macs without any battery or AC adapter drivers?

Both acpi_sbs_probe() here and acpi_quirk_skip_acpi_ac_and_battery() in
drivers/acpi/x86/utils.c disable the ACPI drivers using compile-time
IS_ENABLED() checks and x86_apple_machine, without verifying that
macsmc-acpi and macsmc-power actually bind or that APP0001 and ACPI0003
are present.

Because CONFIG_MACSMC_ACPI, CONFIG_MACSMC_POWER, and
CONFIG_SENSORS_APPLESMC are tristate options with no Kconfig exclusion, a
distribution or allmodconfig kernel can load applesmc first.
applesmc_init() then claims the SMC I/O ports with request_region(),
causing apple_smc_acpi_probe() to fail with -EBUSY so macsmc-power is
never instantiated.

Similarly, macsmc_power_probe() fails with -ENODEV on battery-equipped
Intel Macs that lack ACPI0003. Since acpi_ac_init() and acpi_battery_init()
only check acpi_quirk_skip_acpi_ac_and_battery() once at init and return
-ENODEV, the system ends up with no battery or AC power_supply devices.

> diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c
> index 418951639f511..2c54c0f679bfd 100644
> --- a/drivers/acpi/x86/utils.c
> +++ b/drivers/acpi/x86/utils.c

[ ... ]

> @@ -608,6 +609,10 @@ bool acpi_quirk_skip_acpi_ac_and_battery(void)
>  	long quirks = 0;
>  	int i;
>  
> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> +		return true;
> +
>  	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
>  	if (dmi_id)
>  		quirks = (unsigned long)dmi_id->driver_data;

[Severity: Low]
Does returning before dmi_first_match(acpi_quirk_skip_dmi_ids) bypass the
ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY override mechanism?

Unlike the existing PMIC checks further down in this function, this early
return would prevent any future Apple DMI entry from opting back into the
ACPI AC and battery drivers.

Also, acpi_sbs_probe() duplicates this check instead of reusing
acpi_quirk_skip_acpi_ac_and_battery(), and the drivers/acpi/sbs.c diff
drops an unrelated blank line.

[Severity: High]
With this commit relying on macsmc-power to replace the ACPI drivers, can
macsmc_power_probe() from commit "power/supply: add support for x86 macs
in macsmc-power" dereference a NULL power->adapter during probe?

macsmc_power_probe() registers power->batt and power->ac with
devm_power_supply_register() before assigning power->adapter via
acpi_dev_get_first_match_dev("ACPI0003", NULL, -1):

CPU0                               CPU1
macsmc_power_probe()
  devm_power_supply_register()
                                   sysfs read (status)
                                     macsmc_battery_acpi_get_status()
                                       power->adapter->handle <-- NULL deref
  power->adapter = ...

Any read of POWER_SUPPLY_PROP_STATUS in macsmc_battery_acpi_get_status()
or POWER_SUPPLY_PROP_ONLINE in macsmc_ac_get_property() during this window,
or during devm teardown if the ACPI0003 lookup or notify installation
fails, hits a NULL pointer dereference and kernel oops. Looking up
power->adapter before registering the power_supply devices would avoid
this window.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=11

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 09/14] treewide: disable other rtc's in t2 macs
  2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
@ 2026-12-04 14:27   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:27 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Aditya Garg, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] x86/rtc: read_persistent_clock64() still reads broken CMOS RTC
  on T2 Macs
- [Medium] rtc: compile-time IS_ENABLED() disables T2 Mac RTCs if
  macsmc-rtc fails
- [Low] ACPI: TAD: acpi_tad_probe() clears ACPI_TAD_RT without
  ACPI_TAD_RT_IN_MS
- [Low] treewide: duplicated leaf-driver Kconfig guard across x86, ACPI,
  and RTC
- [Low] treewide: commit message reverses NTP-to-RTC synchronization
  direction
--

commit 4cff46337e95a353ab01666127ac4401097aabbb
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

treewide: disable other rtc's in t2 macs

This commit disables the CMOS RTC, the ACPI TAD real-time clock capability,
and legacy x86 persistent clock updates on Apple T2 Macs when
CONFIG_MACSMC_ACPI and CONFIG_RTC_DRV_MACSMC are enabled.

> Apple also uses RTC to update NTP instead of wallclock so we
> do that also.

[Severity: Low]
Does this sentence have the synchronization direction reversed?  Returning
-ENODEV from update_persistent_clock64() causes sync_hw_clock() in
kernel/time/ntp.c to fall back to update_rtc(), so NTP updates the RTC
class device instead of the legacy x86 wallclock, rather than the RTC
updating NTP.

> diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
> index 314b062a15de9..90f24e6cebfda 100644
> --- a/arch/x86/kernel/rtc.c
> +++ b/arch/x86/kernel/rtc.c

[ ... ]

> @@ -101,6 +102,10 @@ EXPORT_SYMBOL(rtc_cmos_write);
>  
>  int update_persistent_clock64(struct timespec64 now)
>  {
> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
> +		return -ENODEV;
> +
>  	return x86_platform.set_wallclock(&now);
>  }

[Severity: High]
Should read_persistent_clock64() also bypass the CMOS RTC on T2 Macs?
Right now it still calls x86_platform.get_wallclock(ts), which invokes
mach_get_cmos_time() on the broken CMOS clock that NTP will no longer
update.

On boot, if that read returns any valid non-zero timestamp,
timekeeping_init() initializes wall time from it and sets
persistent_clock_exists = true.  That makes timekeeping_rtc_skipsuspend()
return true, so rtc_suspend() skips snapshotting macsmc-rtc.

On S3 resume, timekeeping_resume() then either injects a bogus CMOS delta
and skips rtc_resume(), or leaves rtc_resume() to compute sleep time
against zeroed old_rtc and old_system snapshots.  If CMOS UIP is stuck,
mc146818_get_time() also busy-waits for 1000 ms on boot, suspend, and
resume.

Returning early from read_persistent_clock64() with ts->tv_sec and
ts->tv_nsec zeroed under the same T2 guard keeps persistent_clock_exists
false so boot and suspend/resume use macsmc-rtc.

> diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
> index 45459a4cafae3..a137164511f7b 100644
> --- a/drivers/acpi/acpi_tad.c
> +++ b/drivers/acpi/acpi_tad.c

[ ... ]

> @@ -845,6 +846,10 @@ static int acpi_tad_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
> +		caps &= ~ACPI_TAD_RT;
> +
>  	if (!acpi_has_method(handle, "_PRW")) {
>  		dev_info(dev, "Missing _PRW\n");
>  		caps &= ~(ACPI_TAD_AC_WAKE | ACPI_TAD_DC_WAKE);

[Severity: Low]
Should this also clear ACPI_TAD_RT_IN_MS?  Leaving it set in
dd->capabilities lets caps_show() report millisecond real-time accuracy in
sysfs even though ACPI_TAD_RT has been disabled, unlike the
ACPI_TAD_AC_WAKE / ACPI_TAD_DC_WAKE handling just below.

> diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
> index 209aa4ec732c8..9a6cecc192955 100644
> --- a/drivers/rtc/rtc-cmos.c
> +++ b/drivers/rtc/rtc-cmos.c

[ ... ]

> @@ -968,6 +969,10 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
>  		.priv = &cmos_rtc,
>  	};
>  
> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> +			IS_ENABLED(CONFIG_RTC_DRV_MACSMC) && has_apple_t2_chip)
> +		return -ENODEV;
> +
>  	/* there can be only one ... */
>  	if (cmos_rtc.dev)
>  		return -EBUSY;

[Severity: Medium]
Can gating these checks on compile-time IS_ENABLED() leave a T2 Mac with
no working RTC when CONFIG_MACSMC_ACPI=m and CONFIG_RTC_DRV_MACSMC=m?

drivers/hwmon/applesmc.c still matches all T2 Macs via
applesmc_whitelist[] with no exclusion against macsmc-acpi, and reserves
the same SMC I/O ports (0x300..0x31f).  If applesmc loads first,
apple_smc_acpi_probe() fails with -EBUSY in devm_request_region(), so
macsmc-rtc is never instantiated.

Because cmos_do_probe(), acpi_tad_probe(), and update_persistent_clock64()
already returned early, the system ends up with no /dev/rtc* device (and
no cmos_nvram or acpi_cmos_wake_setup()), and sync_hw_clock() fails with
-ENODEV.

Either the broken T2 RTCs should be quirked directly while resolving the
applesmc port conflict, or the fallback should not be disabled based
solely on tristate Kconfig symbols.

[Severity: Low]
This isn't a bug, but repeating the leaf-driver Kconfig check across
arch/x86, ACPI, and RTC couples generic drivers to downstream symbol
names.  Moving it to a static inline helper in
include/linux/platform_data/x86/apple.h (and splitting the changes per
subsystem) would keep the checks consistent and easier to review.

The commit message would also benefit from explaining how the CMOS RTC
and ACPI TAD fail on T2 Macs, and why disabling all of rtc-cmos
(including cmos_nvram and acpi_cmos_wake_setup()) is safe there.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=9

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 12/14] hwmon/macsmc: add more types
  2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
@ 2026-12-04 14:37   ` sashiko-bot
  2026-12-04 18:44     ` Guenter Roeck
  0 siblings, 1 reply; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:37 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] hwmon: (macsmc) missing endian conversion in
  macsmc_hwmon_read_key()
- [Medium] hwmon: (macsmc) unclamped s64 to long truncation in
  macsmc_hwmon_read_key()
- [Low] hwmon: macsmc: sparse __be16 type mismatches on SMC fixed-point
  I/O
- [Low] hwmon: macsmc: duplicate fixed-point decoding in
  macsmc_hwmon_read_key()
- [Low] hwmon: missing range check for fpe2 write in
  macsmc_hwmon_write_key()
--

commit fa0827d4a4896bab5a321d44d03d23f333c92b8e
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

hwmon/macsmc: add more types

This commit adds read support for common integer and fixed-point SMC key
types in macsmc_hwmon_read_key() and write support for fpe2 fan speed keys
in macsmc_hwmon_write_key().

> diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c
> index 1500ec2cc9f83..14b68cf8c283e 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,

[ ... ]

> +	/* 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 = (s64)ui16 * scale;
> +		break;
> +	}

[Severity: High]
Do the ui16, si16, ui32, and si32 cases need endianness conversion?

The ACPI SMC backend copies raw big-endian firmware bytes without
swapping, as macsmc_battery_get_property() accounts for when smc->is_acpi
is true.  Using the raw values directly returns byte-swapped readings and
corrupted signs on Intel ACPI Macs.

Converting from big-endian when smc->is_acpi is true and from
little-endian otherwise (sign-extending si16 and si32 afterward) would
handle both Intel and Apple Silicon backends.

[ ... ]

> +	/* 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 = (s64)ui32 * scale;
> +		break;
> +	}

[Severity: Medium]
Can assigning the scaled s64 product directly to long *val truncate on
32-bit kernels?

SENSORS_MACSMC_HWMON does not depend on 64BIT, and macsmc_hwmon_read()
passes scale = 1000000 for power sensors.  On 32-bit builds where long is
32 bits, scaled values for ui16, si16, ui32, si32, spc3, spd2, and spf0
can exceed [LONG_MIN, LONG_MAX] and silently wrap or invert sign.

Clamping with clamp_t(s64, ..., LONG_MIN, LONG_MAX) before assigning to
*val would match the saturation done for flt and ioft above.

[ ... ]

> +	/* 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((s64)be16_to_cpu(fp2e), scale, BIT(14));
> +		break;
> +	}

[Severity: Low]
Will sparse warn about __be16 type mismatches across the fixed-point
cases?

All 20 new fp* and sp* cases pass host-endian u16 or s16 variables to
be16_to_cpu(), and the fpe2 case in macsmc_hwmon_write_key() passes
cpu_to_be16() to apple_smc_write_u16().

Using __be16 buffers with apple_smc_read()/apple_smc_write() or dedicated
__be16 helpers would eliminate these sparse warnings.

> +
> +	/* 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((s64)be16_to_cpu(fp3d), scale, BIT(13));
> +		break;
> +	}

[Severity: Low]
Can the 20 fp* and sp* cases be collapsed into a parameterized helper
instead of repeating the read and scaling boilerplate?

Aside from the repetition (and minor inconsistencies between BIT(n) and
1 << n divisors and variable initialization), similar fixed-point
decoding also exists in macsmc_battery_acpi_read() in
drivers/power/supply/macsmc-power.c and could potentially be shared.

[ ... ]

> @@ -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));

[Severity: Low]
Should this check that val is within [0, 0x3fff] before shifting and
narrowing to 16 bits?

macsmc_hwmon_write_fan() only bounds val against fan->min and fan->max,
which macsmc_hwmon_create_fan() parses independently without requiring
them to be fpe2.  If a negative value reaches this path, val << 2 is
signed left-shift undefined behavior, and val >= 0x4000 silently wraps.

Returning -EINVAL when val < 0 || val >= 0x4000, matching
applesmc_hwmon_write() in drivers/hwmon/applesmc.c, would prevent both.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=12

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power
  2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
@ 2026-12-04 14:39   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:39 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Andre Eikmeyer,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-pci, linux-gpio, linux-hwmon, linux-leds, mfd, linux-rtc,
	linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 12 potential
issues to consider:
- [High] power: supply: macsmc: NULL deref of power->adapter in
  macsmc_power_probe()
- [Medium] power: supply: macsmc: build failure when CONFIG_ACPI is
  disabled
- [Medium] power: supply: macsmc: premature acpi_dev_put() in
  macsmc_power_remove()
- [Medium] power: supply: macsmc: signed 64-bit overflow via BIT() in
  mult_frac()
- [Medium] power: supply: macsmc: ENERGY_FULL* uses live B0AV instead of
  nominal voltage
- [Medium] power: supply: macsmc: missing swab16() for B0TE on ACPI Macs
- [Medium] power: supply: macsmc: AC properties registered without SMC
  key checks
- [Medium] power: supply: macsmc: reversed OR probes non-existent CHIS
  on Intel Macs
- [Low] power: supply: macsmc: duplicate float decoder in macsmc-power
- [Low] power: supply: macsmc: sparse __be16 mismatch in
  macsmc_battery_acpi_read()
- [Low] power: supply: macsmc: uninitialized voltage read on B0AV
  failure
- [Low] power: supply: macsmc: repeated apple_smc_get_key_info() on
  runtime reads
--

commit 82e1fded22961a0b758f2413ade4066e910b5ff5
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

power/supply: add support for x86 macs in macsmc-power

This commit adds Intel x86 Mac support to the macsmc-power driver using
ACPI adapter status and notifications along with big-endian and
fixed-point SMC keys, exposing battery charge thresholds and AC power
telemetry.

> diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c
> index ced37a7019981..2ebf620a22c9c 100644
> --- a/drivers/power/supply/macsmc-power.c
> +++ b/drivers/power/supply/macsmc-power.c

[ ... ]

> @@ -195,6 +204,41 @@ static int macsmc_battery_get_status(struct macsmc_power *power)
>  	return POWER_SUPPLY_STATUS_CHARGING;
>  }
>  
> +static int macsmc_battery_acpi_get_status(struct macsmc_power *power)
> +{

[ ... ]

> +	status = acpi_evaluate_integer(power->adapter->handle, "_PSR", NULL, &adapter_status);

[Severity: Medium]
Does this build when CONFIG_ACPI is disabled?

CONFIG_MACSMC_POWER only depends on MFD_MACSMC_CORE, which does not depend
on ACPI (for example on DeviceTree-only Apple Silicon ARM64 kernels).  When
CONFIG_ACPI is disabled, struct acpi_device is only forward-declared and
acpi_evaluate_integer(), acpi_dev_install_notify_handler(), and
acpi_dev_remove_notify_handler() have no stubs in include/acpi/acpi_bus.h.
The same unguarded ACPI calls also appear in macsmc_ac_get_property(),
macsmc_power_probe(), and macsmc_power_remove().

[ ... ]

> @@ -322,6 +366,210 @@ static int macsmc_battery_get_capacity_level(struct macsmc_power *power)

[ ... ]

> +static int macsmc_battery_acpi_read_f32_scaled(struct apple_smc *smc, smc_key key,
> +	int *p, int scale)

[Severity: Low]
Can macsmc_battery_acpi_read_f32_scaled() and the fixed-point decoders in
macsmc_battery_acpi_read() be shared in macsmc-core instead of duplicating
macsmc_hwmon_read_f32_scaled() and the fixed-point decoding from
drivers/hwmon/macsmc-hwmon.c?

Keeping separate copies has already led to drift between the two drivers,
such as the unsigned BIT() divisor issue below.

[ ... ]

> +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;

[Severity: Low]
Can the key info for these SMC keys be cached at probe time instead of
calling apple_smc_get_key_info() on every property read?

apple_smc_get_key_info() is uncached and performs a full synchronous SMC
transaction under smc->mutex, doubling the hardware IPC round-trips for
each runtime read of B0AP, TB0T, and the AC telemetry keys.

[ ... ]

> +	/* 3.13 fixed point decimal */
> +	case __SMC_KEY('f', 'p', '3', 'd'): {
> +		u16 fp3d;
> +
> +		ret = apple_smc_read_u16(smc, key, &fp3d);
> +		if (ret)
> +			return ret;
> +
> +		*val = mult_frac((s64)be16_to_cpu(fp3d), scale, BIT(13));
> +		break;
> +	}

[Severity: Low]
Will sparse warn about passing host-endian u16 and s16 values to
be16_to_cpu() across all nine fixed-point cases in
macsmc_battery_acpi_read()?

be16_to_cpu() expects __be16, whereas fp3d through sp87 are declared as
plain u16 or s16.

[ ... ]

> +	/* 3.12 signed fixed point decimal */
> +	case __SMC_KEY('s', 'p', '3', 'c'): {
> +		s16 sp3c;
> +
> +		ret = apple_smc_read_s16(smc, key, &sp3c);
> +		if (ret)
> +			return ret;
> +
> +		*val = mult_frac((s64)(s16)be16_to_cpu(sp3c), scale, BIT(12));
> +		break;
> +	}

[Severity: Medium]
Can BIT(12) as the divisor in mult_frac() trigger signed 64-bit overflow
when sp3c is negative?

BIT(12) has type unsigned long (64-bit on x86_64), so inside mult_frac()
the division x_ / d_ converts negative s64 x_ to unsigned 64-bit and
produces a quotient around 4.5e15.  Multiplying that by scale = 1000000 in
s64 overflows S64_MAX (triggering UBSAN under CONFIG_UBSAN_SIGNED_WRAP).
The remaining signed fixed-point cases (sp4b through sp87) similarly pass
unsigned BIT() divisors to mult_frac(), forcing unsigned division on
negative s16 values.  Using a signed divisor such as (1 << 12) avoids the
unsigned promotion.

[ ... ]

> @@ -418,27 +734,64 @@ static int macsmc_battery_get_property(struct power_supply *psy,

[ ... ]

>  	case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
>  		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0DC), &vu16);
> -		val->intval = vu16 * power->nominal_voltage_mv;
> +		if (power->smc->is_acpi) {
> +			if (ret < 0)
> +				return ret;
> +
> +			u16 voltage;
> +
> +			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
> +			val->intval = vu16 * swab16(voltage);
> +		} else
> +			val->intval = vu16 * power->nominal_voltage_mv;
>  		break;
>  	case POWER_SUPPLY_PROP_ENERGY_FULL:
>  		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0FC), &vu16);
> -		val->intval = vu16 * power->nominal_voltage_mv;
> +		if (power->smc->is_acpi) {
> +			if (ret < 0)
> +				return ret;
> +
> +			u16 voltage;
> +
> +			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
> +			val->intval = swab16(vu16) * swab16(voltage);
> +		} else
> +			val->intval = vu16 * power->nominal_voltage_mv;
>  		break;

[Severity: Medium]
Should ENERGY_FULL_DESIGN and ENERGY_FULL on ACPI Macs use
power->nominal_voltage_mv instead of the live battery voltage B0AV?

Multiplying B0DC and B0FC by live B0AV makes the reported design and full
energy fluctuate with state of charge and load sag, distorting userspace
battery wear calculations.  macsmc_power_probe() already sets
power->num_cells on ACPI Macs, so power->nominal_voltage_mv can be
computed the same way as on Apple Silicon.

>  	case POWER_SUPPLY_PROP_ENERGY_NOW:
>  		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RM), &vu16);
> -		val->intval = macsmc_swap_b0rm(power, vu16) * power->nominal_voltage_mv;
> +		if (power->smc->is_acpi) {
> +			if (ret < 0)
> +				return ret;
> +
> +			u16 voltage;
> +
> +			ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage);
> +			val->intval = swab16(vu16) * swab16(voltage);
> +		} else
> +			val->intval = macsmc_swap_b0rm(power, vu16) * power->nominal_voltage_mv;
>  		break;

[Severity: Low]
Does this read an uninitialized stack variable voltage if reading B0AV
fails?

In all three ENERGY_* cases, ret is not checked after
apple_smc_read_u16(power->smc, SMC_KEY(B0AV), &voltage), so an SMC I/O
error leaves voltage uninitialized when passed to swab16().

[ ... ]

> @@ -667,18 +1093,23 @@ static int macsmc_power_probe(struct platform_device *pdev)

[ ... ]

> -	if (apple_smc_key_exists(smc, SMC_KEY(CHIS)))
> +	if (apple_smc_key_exists(smc, SMC_KEY(CHIS)) || smc->is_acpi)
>  		has_ac_adapter = true;

[Severity: Medium]
Should smc->is_acpi be checked before apple_smc_key_exists(smc, SMC_KEY(CHIS))?

With CHIS on the left side of ||, every PIO-mode Intel Mac probes the
Apple-Silicon-only CHIS key and discards the result.  When CHIS is
missing, apple_smc_acpi_port_wait() stalls for 1-2 seconds while holding
smc->mutex and clears smc->interrupt_enabled, forcing all subsequent SMC
commands to fall back to 1 ms polling.

[ ... ]

> @@ -694,118 +1125,161 @@ static int macsmc_power_probe(struct platform_device *pdev)

[ ... ]

> +			if (apple_smc_key_exists(smc, SMC_KEY(B0TE)))
> +				props[nprops++] = POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW;

[Severity: Medium]
Is POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW missing a swab16() conversion for
ACPI Macs?

macsmc_battery_get_property() was updated to byte-swap B0TF for
TIME_TO_FULL_NOW, but B0TE was left unchanged:

drivers/power/supply/macsmc-power.c:macsmc_battery_get_property() {
	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
		ret = apple_smc_read_u16(power->smc, SMC_KEY(B0TE), &vu16);
		val->intval = vu16 == 0xffff ? 0 : vu16 * 60;
		break;
}

On Intel ACPI Macs where B0TE is big-endian, reading time_to_empty_now
returns corrupted byte-swapped values whenever B0TE is not 0xffff.

[ ... ]

> @@ -829,16 +1303,27 @@ static int macsmc_power_probe(struct platform_device *pdev)

[ ... ]

> +		if (smc->is_acpi) {
> +			props[nprops++] = POWER_SUPPLY_PROP_CURRENT_NOW;
> +			props[nprops++] = POWER_SUPPLY_PROP_POWER_NOW;
> +			if (apple_smc_key_exists(power->smc, SMC_KEY(PD0R)))
> +				power->has_pd0r = true;
> +			/* MacBookPro5,x and 7,x dosent have VD0R key or any equivalent */
> +			if (!power->has_battery || apple_smc_key_exists(power->smc, SMC_KEY(VD0R)))
> +				props[nprops++] = POWER_SUPPLY_PROP_VOLTAGE_NOW;

[Severity: Medium]
Can registering CURRENT_NOW, POWER_NOW, and desktop VOLTAGE_NOW without
checking for their backing SMC keys break macsmc-ac uevents?

If ID0R/ID2R, PDTR/PD2R, or VD2R is absent (for example on a laptop with
its battery disconnected where power->has_battery is false and
macsmc_ac_get_property() queries desktop keys ID2R, PD2R, and VD2R),
apple_smc_get_key_info() returns -EIO.  Because add_prop_uevent() in
drivers/power/supply/power_supply_sysfs.c only ignores -ENODEV, -ENODATA,
and -EINVAL, returning -EIO fails power_supply_uevent() for the entire
macsmc-ac device.

[ ... ]

> @@ -858,9 +1343,22 @@ static int macsmc_power_probe(struct platform_device *pdev)
>  	if (!power->batt && !power->ac)
>  		return -ENODEV;
>  
> -	power->nb.notifier_call = macsmc_power_event;
> -	blocking_notifier_chain_register(smc->event_handlers, &power->nb);
> +	if (!smc->is_acpi) {
> +		power->nb.notifier_call = macsmc_power_event;
> +		blocking_notifier_chain_register(smc->event_handlers, &power->nb);
> +	} else if (power->has_battery) {
> +		power->adapter = acpi_dev_get_first_match_dev("ACPI0003", NULL, -1);
> +		if (!power->adapter)
> +			return -ENODEV;
>  
> +		ret = acpi_dev_install_notify_handler(power->adapter, ACPI_DEVICE_NOTIFY,
> +					macsmc_power_acpi_notify, power);
> +		if (ret) {
> +			acpi_dev_put(power->adapter);
> +			power->adapter = NULL;
> +			return ret;
> +		}
> +	}
>  	return 0;
>  }

[Severity: High]
Can power->adapter be dereferenced while NULL during macsmc_power_probe()?

Both power->batt and power->ac are registered with
devm_power_supply_register() before power->adapter is acquired.  As soon
as device_add() emits KOBJ_ADD, userspace (such as udevd or upowerd) or
deferred_register_work can read status or online before power->adapter is
assigned:

CPU0                              CPU1
macsmc_power_probe()
  devm_power_supply_register(batt)
                                  sysfs read: macsmc-battery/status
                                    macsmc_battery_acpi_get_status()
                                      power->adapter->handle <-- NULL deref
  power->adapter = acpi_dev_get_first_match_dev(...)

The same NULL pointer dereference happens if acpi_dev_get_first_match_dev()
or acpi_dev_install_notify_handler() fails and leaves power->adapter NULL
until devres unregisters the power supplies.  Acquiring power->adapter
with a devm cleanup action before calling devm_power_supply_register()
avoids both windows.

> @@ -868,7 +1366,13 @@ static void macsmc_power_remove(struct platform_device *pdev)
>  {
>  	struct macsmc_power *power = dev_get_drvdata(&pdev->dev);
>  
> -	blocking_notifier_chain_unregister(power->smc->event_handlers, &power->nb);
> +	if (!power->smc->is_acpi)
> +		blocking_notifier_chain_unregister(power->smc->event_handlers, &power->nb);
> +	else if (power->has_battery) {
> +		acpi_dev_remove_notify_handler(power->adapter, ACPI_DEVICE_NOTIFY,
> +				macsmc_power_acpi_notify);
> +		acpi_dev_put(power->adapter);
> +	}
>  }

[Severity: Medium]
Does calling acpi_dev_put(power->adapter) in macsmc_power_remove() drop
the reference before power->batt and power->ac are unregistered?

__device_release_driver() runs macsmc_power_remove() before
devres_release_all() unregisters devm-managed power supplies, leaving a
window where sysfs reads still dereference power->adapter->handle without
a reference:

CPU0                            CPU1
__device_release_driver()
  macsmc_power_remove()
    acpi_dev_put(power->adapter)
                                sysfs read: macsmc-battery/status
                                  macsmc_battery_acpi_get_status()
                                    power->adapter->handle <-- use-after-put
  devres_release_all()
    power_supply_unregister(...)

Releasing power->adapter via a devm_add_action_or_reset() callback
registered before devm_power_supply_register() guarantees both power
supplies are unregistered before acpi_dev_put().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=10

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys
  2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
@ 2026-12-04 14:48   ` sashiko-bot
  0 siblings, 0 replies; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:48 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

Thank you for your contribution! Sashiko AI review found 17 potential
issues to consider:
- [High] mfd: macsmc: use-after-free in apple_smc_fops_ioctl() after
  device unbind
- [Medium] mfd: macsmc: IOCTL_SMC_WRITE ignores FMODE_WRITE on /dev/smc
  fd
- [Medium] mfd: macsmc: missing APPLE_SMC_WRITABLE check and late
  allowlist validation
- [Medium] mfd: macsmc: raw /dev/smc ioctl UAPI in MFD core with
  undocumented allowlist
- [Medium] mfd: macsmc: commit message mischaracterizes 6-key write
  allowlist
- [Medium] mfd: macsmc: Missing index bounds check in
  IOCTL_SMC_GET_KEY_INDEX
- [Medium] mfd: macsmc: apple_smc_probe() omits OSWD and NATi for
  macsmc-wdt
- [Medium] mfd: macsmc: kernel-only BIT() macro used in UAPI header
- [Medium] mfd: macsmc: UAPI ioctl structs have implicit padding and
  32-byte key cap
- [Medium] mfd: macsmc: unconditional /dev/smc registration and
  unfiltered key reads
- [Low] mfd: macsmc: return -ENOTTY for unknown cmd in
  apple_smc_fops_ioctl()
- [Low] mfd: macsmc: implicit padding holes in new UAPI ioctl structs
- [Low] mfd: macsmc: commit subject violates MFD prefix and
  capitalization rules
- [Low] mfd: macsmc: invalid SPDX license expression in UAPI header
- [Low] mfd: macsmc: apple_smc_fops_ioctl() returns -EINVAL for unknown
  commands
- [Low] mfd: macsmc: ioctl magic 'S' conflicts and lacks
  ioctl-number.rst entry
- [Low] mfd: macsmc: commit message misdescribes IOCTL_SMC_WRITE key
  allowlist
--

commit 4104c5546b08cdfee61eacef164c47b7d69ce901
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

mfd/macsmc: add ioctl to access smc keys

This commit registers a /dev/smc miscdevice in macsmc-core and adds a
UAPI header exposing ioctls to read keys, write a fixed set of keys,
enumerate keys by index, and query key metadata.

> mfd/macsmc: add ioctl to access smc keys

[Severity: Low]
This isn't a bug, but MFD commit subjects use the format
"mfd: <driver>: <Capitalized description>", e.g.
"mfd: macsmc: Add ioctl to access SMC keys".

> Keys already managed by kernel drivers can't be written this
> way, to avoid conflicts.

[Severity: Medium]
Does this accurately describe the write restriction?  The changelog
describes a denylist of driver-managed keys, whereas
apple_smc_fops_ioctl() enforces a strict hardcoded allowlist of six
keys (HE0N, HE2N, HI0N, MSTS, MSPC, QENA) and rejects every other key
with -EPERM.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index bc4200f574bd5..a53df6f6cd3f2 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -112,6 +115,129 @@ static void apple_smc_disable_notifications(void *data)
>  	smc->be->disable_notifications(smc->be_cookie);
>  }
>  
> +static long apple_smc_fops_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> +{

[ ... ]

> +	case IOCTL_SMC_WRITE: {
> +		struct ioctl_smc_rw_payload payload;
> +		struct apple_smc_key_info info;
> +
> +		if (copy_from_user(&payload, argp, sizeof(payload)))
> +			return -EFAULT;

[Severity: Medium]
Can an O_RDONLY file descriptor write SMC keys here?  vfs_ioctl() does
not enforce FMODE_WRITE on behalf of drivers, so IOCTL_SMC_WRITE should
reject callers whose file->f_mode lacks FMODE_WRITE.

> +		ret = apple_smc_get_key_info(smc, payload.key, &info);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (payload.size != info.size)
> +			return -EINVAL;
> +
> +		if (payload.size > 32)
> +			return -EINVAL;
> +
> +		switch (payload.key) {
> +		case __SMC_KEY('H', 'E', '0', 'N'):
> +		case __SMC_KEY('H', 'E', '2', 'N'):
> +		case __SMC_KEY('H', 'I', '0', 'N'):
> +		case __SMC_KEY('M', 'S', 'T', 'S'):
> +		case __SMC_KEY('M', 'S', 'P', 'C'):
> +		case __SMC_KEY('Q', 'E', 'N', 'A'):
> +			break;
> +		default:
> +			return -EPERM;
> +		}

[Severity: Medium]
Should IOCTL_SMC_WRITE check (info.flags & APPLE_SMC_WRITABLE) before
writing, and validate payload.size and the key allowlist before calling
apple_smc_get_key_info()?

Unlike IOCTL_SMC_READ, IOCTL_SMC_WRITE omits the writability flag check;
on the ACPI PIO backend, apple_smc_acpi_port_write() does not read back
a firmware error status, so a write to a read-only key can silently
succeed.  Running apple_smc_get_key_info() before the static size and
allowlist checks also acquires smc->mutex and performs hardware IPC for
disallowed or oversized requests (and on ACPI PIO, a nonexistent key
stalls for 1000 ms and clears smc->interrupt_enabled).

[Severity: Low]
Neither the commit message nor comments here explain what these six
allowlisted keys control or why userspace needs write access to them;
the changelog only mentions excluding driver-managed keys.

[ ... ]

> +	case IOCTL_SMC_GET_KEY_INDEX: {
> +		struct ioctl_smc_index_payload payload;
> +
> +		if (copy_from_user(&payload, argp, sizeof(payload)))
> +			return -EFAULT;
> +
> +		ret = apple_smc_get_key_by_index(smc, payload.index, &payload.key);

[Severity: Medium]
Does IOCTL_SMC_GET_KEY_INDEX need to check payload.index >= smc->key_count
before calling apple_smc_get_key_by_index()?

Because the UAPI documents sequential enumeration with increasing index
values, normal callers will pass payload.index == smc->key_count to find
the end of the table.  On ACPI PIO Intel Macs, an out-of-range query
stalls apple_smc_acpi_port_wait() for up to 2 seconds while holding
smc->mutex and permanently clears smc->interrupt_enabled = 0, reverting
subsequent SMC PIO transactions to polling.

[ ... ]

> +	default:
> +		return -EINVAL;
> +	}
> +}

[Severity: Low]
Should unrecognized ioctl commands return -ENOTTY instead of -EINVAL?
Returning -EINVAL breaks standard userspace ioctl probing such as
isatty() / TCGETS on /dev/smc.

[Severity: Low]
Per Documentation/driver-api/ioctl.rst, unlocked_ioctl handlers should
return -ENOTTY (or -ENOIOCTLCMD) for unknown command numbers so
userspace can distinguish unsupported ioctls from invalid payload
arguments (-EINVAL).

[ ... ]

> @@ -150,6 +276,20 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  	if (ret)
>  		return ret;
>  
> +	smc->miscdev.minor = MISC_DYNAMIC_MINOR;
> +	smc->miscdev.name = "smc";
> +	smc->miscdev.fops = &apple_smc_fops;
> +	smc->miscdev.parent = dev;
> +	smc->miscdev.mode = 0600;
> +
> +	ret = misc_register(&smc->miscdev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(dev, apple_smc_misc_unregister, &smc->miscdev);
> +	if (ret)
> +		return ret;
> +
>  	if (smc->is_acpi) {
>  		ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common,
>  			ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL);

[Severity: High]
Can apple_smc_fops_ioctl() hit a use-after-free when the SMC device is
unbound or a backend module is unloaded while /dev/smc is open?

struct apple_smc and its backend context are devm-allocated,
apple_smc_fops_open() caches a raw pointer to smc in file->private_data
with no reference counting or revocation lock, and apple_smc_fops.owner
pins only macsmc-core rather than the loadable macsmc-acpi or
macsmc-rtkit backend modules.  misc_deregister() does not revoke open
file descriptors or wait for in-flight ioctls:

CPU0                              CPU1
sysfs unbind / rmmod macsmc-acpi  open("/dev/smc")
  devres_release_all()              file->private_data = smc
    misc_deregister()
    kfree(smc) & backend teardown
                                  ioctl(fd, IOCTL_SMC_READ, ...)
                                    apple_smc_fops_ioctl()
                                      mutex_lock(&smc->mutex) <-- UAF
                                      smc->be->read(...)

The same race also exists if devm_mfd_add_devices() fails after
misc_register() exposes /dev/smc.  Registering the miscdevice after MFD
child registration, refcounting the open-file context independently of
devm, and synchronizing deregistration with a lock (such as an
rw_semaphore) before tearing down backend resources would prevent this.

[Severity: Medium]
As reported by Jonathan Cameron on RFC [1], should a raw firmware
pass-through miscdevice and custom ioctl UAPI live in drivers/mfd/?

Core MFD drivers normally handle only shared resources and child
registration, and exposing a permanent opaque ioctl interface for six
undocumented keys bypasses standard kernel subsystems (or fwctl) without
explaining what those keys do or why standard interfaces cannot be used.

[Severity: Medium]
As reported by Sasha Finkelstein on RFC [2], why is /dev/smc registered
unconditionally here instead of being restricted to T2 Macs, and why
does IOCTL_SMC_READ allow reading arbitrary readable keys?

Because misc_register() runs before checking smc->is_acpi or
has_apple_t2_chip (added in commit "treewide: Add a flag to detect the
Apple T2 chip"), /dev/smc is exposed on Apple Silicon RTKit and non-T2
Intel Macs as well.  On the read path, IOCTL_SMC_READ only checks
APPLE_SMC_READABLE and size <= 32, without a read allowlist or
filtering read-sensitive keys such as APPLE_SMC_FUNCTION or
APPLE_SMC_PRIVATE_READ.

[Severity: Medium]
In the smc->is_acpi branch right below, apple_smc_probe() gates
apple_smc_acpi_wdt registration solely on SMC_KEY(NATJ).

macsmc_wdt_probe() in drivers/watchdog/macsmc_wdt.c supports newer SMCs
via SMC_KEY(OSWD) and otherwise requires both SMC_KEY(NATJ) and
SMC_KEY(NATi).  Checking only NATJ leaves the watchdog unregistered on
OSWD-only Macs and registers it even when NATi is absent.

> diff --git a/include/uapi/linux/macsmc.h b/include/uapi/linux/macsmc.h
> new file mode 100644
> index 0000000000000..ef784539d3252
> --- /dev/null
> +++ b/include/uapi/linux/macsmc.h
> @@ -0,0 +1,119 @@
> +/* SPDX-License-Identifier: GPL-2.0-only OR MIT WITH Linux-syscall-note */

[Severity: Low]
Is this SPDX expression valid?  WITH binds more tightly than OR, so this
attaches Linux-syscall-note to MIT (which scripts/spdxcheck.py rejects)
and leaves GPL-2.0-only without the syscall note.  It should be
"(GPL-2.0-only WITH Linux-syscall-note) OR MIT".

[ ... ]

> +#define APPLE_SMC_READABLE		BIT(7)
> +#define APPLE_SMC_WRITABLE		BIT(6)
> +#define APPLE_SMC_FUNCTION		BIT(4)
> +#define APPLE_SMC_CONST		BIT(3)
> +#define APPLE_SMC_ATOMIC		BIT(2)
> +#define APPLE_SMC_PRIVATE_READ		BIT(1)
> +#define APPLE_SMC_PRIVATE_WRITE		BIT(0)

[Severity: Medium]
Does this break userspace compilation when any APPLE_SMC_* flag is
referenced?  BIT() is a kernel-internal macro not provided by UAPI
headers; UAPI constants should use _BITUL() (with <linux/const.h>) or
plain unsigned shifts such as (1U << 7).

[ ... ]

> +struct ioctl_smc_rw_payload {
> +	smc_key key;
> +	__u32 size;
> +	__u8 buf[32];
> +};

[Severity: Medium]
Does hardcoding __u8 buf[32] permanently prevent accessing SMC keys
larger than 32 bytes?  struct apple_smc_key_info.size is __u8 and the
RTKit backend defines SMC_MAX_SIZE as 255, so baking sizeof(struct
ioctl_smc_rw_payload) into the ioctl ABI makes larger keys inaccessible
without new ioctls.

In addition, struct ioctl_smc_index_payload narrows index to __u16
despite u32 smc->key_count (with a 2-byte internal padding hole), and
struct apple_smc_key_info leaves 2 bytes of implicit tail padding when
embedded in struct ioctl_smc_info_payload.

[ ... ]

> +struct ioctl_smc_index_payload {
> +	__u16 index;
> +	smc_key key;
> +};

[Severity: Low]
Both struct ioctl_smc_index_payload (between __u16 index and smc_key
key) and struct apple_smc_key_info (trailing 2 bytes) contain implicit
compiler padding holes.  Widening index to __u32 and adding explicit
reserved padding fields avoids unnamed holes in the UAPI structs.

[ ... ]

> +#define APPLE_SMC_MAGIC 'S'
> +#define IOCTL_SMC_READ    _IOWR(APPLE_SMC_MAGIC, 1, struct ioctl_smc_rw_payload)
> +#define IOCTL_SMC_WRITE   _IOW(APPLE_SMC_MAGIC, 2, struct ioctl_smc_rw_payload)
> +#define IOCTL_SMC_GET_KEY_INDEX  _IOWR(APPLE_SMC_MAGIC, 3, struct ioctl_smc_index_payload)
> +#define IOCTL_SMC_GET_KEY_INFO   _IOWR(APPLE_SMC_MAGIC, 4, struct ioctl_smc_info_payload)

[Severity: Low]
Does APPLE_SMC_MAGIC 'S' conflict with existing ioctl numbers?
Documentation/userspace-api/ioctl/ioctl-number.rst already lists 'S' as
conflicted across cdrom.h, asequencer.h, scsi_ioctl.h, and scsi.h, and
this new range is not registered there.

[1] https://lore.kernel.org/r/20261101013817.22d67ea7@jic23-hlaptop
[2] https://lore.kernel.org/r/525E5B4D-A947-4567-9FCD-5FFF2CA8B161@chaosmail.tech

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=14

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon
  2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
@ 2026-12-04 14:48   ` sashiko-bot
  2026-12-04 18:45     ` Guenter Roeck
  0 siblings, 1 reply; 53+ messages in thread
From: sashiko-bot @ 2026-12-04 14:48 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Andre Eikmeyer,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-pci, linux-gpio, linux-hwmon, linux-leds, mfd, linux-rtc,
	linux-watchdog, keyrings, linux-security-module

Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] hwmon: macsmc: NULL pointer dereference in DT sensor label
  handling
- [High] hwmon: macsmc: redundant SMC probes cause multi-minute PIO
  probe stalls
- [Medium] hwmon: macsmc: uninitialized count read in
  macsmc_hwmon_populate_sensors_acpi()
- [Medium] hwmon: macsmc: heap OOB write in
  macsmc_hwmon_register_sensors_acpi()
- [Medium] hwmon: macsmc: invalid sensor keys and missing key validation
  on ACPI
- [Medium] hwmon: macsmc: unvalidated F%dID read and fatal optional fan
  key errors
- [Medium] hwmon: macsmc: missing big-endian conversion for integer keys
  on ACPI
- [Medium] hwmon: macsmc_hwmon_resume() skips FS! and target restore,
  uses legacy PM
- [Low] hwmon: macsmc: outdated docs, MODULE_DESCRIPTION, and whitespace
  changes
- [Low] hwmon: macsmc: u16/__be16 mismatch in
  macsmc_hwmon_write_old_fan_manual()
- [Low] hwmon: macsmc-hwmon uses deprecated legacy
  platform_driver.resume callback
--

commit cda7f94f03b9c07639e3fb001f94e54d739b4e68
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

hwmon: add support for x86 macs in macsmc-hwmon

This commit extends macsmc-hwmon to support Intel Macs over ACPI by
adding static sensor descriptor tables, ACPI sensor and fan discovery,
legacy FS! manual fan control, and a resume callback.

> diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c
> index 14b68cf8c283e..d531eb4122f89 100644
> --- a/drivers/hwmon/macsmc-hwmon.c
> +++ b/drivers/hwmon/macsmc-hwmon.c

[ ... ]

> @@ -47,7 +52,7 @@ MODULE_PARM_DESC(fan_control,
>  struct macsmc_hwmon_sensor {
>  	struct apple_smc_key_info info;
>  	smc_key macsmc_key;
> -	char label[MAX_LABEL_LENGTH];
> +	char *label;
>  	u32 attrs;
>  };

[Severity: High]
Does changing label to a char * pointer cause a NULL pointer dereference on
Apple Silicon Device Tree systems?

macsmc_hwmon_populate_sensors() zero-allocates each sensor array with
devm_kcalloc(), leaving sensor->label NULL.  When a Device Tree sensor node
has a label property, macsmc_hwmon_create_sensor() calls
strscpy_pad(sensor->label, label, sizeof(sensor->label)), writing to NULL
with a pointer size; when a node omits label, macsmc_hwmon_populate_sensors()
dereferences NULL via if (*sensor->label).

Making label (and macsmc_sensor_desc.name) const char *, assigning the DT
label pointer directly (or via devm_kstrdup_const()), and checking
sensor->label && *sensor->label would avoid this.

[ ... ]

> @@ -599,6 +605,25 @@ static int macsmc_hwmon_read_fan(struct macsmc_hwmon *hwmon, u32 attr, int chan,
>  	}
>  }
>  
> +static int macsmc_hwmon_write_old_fan_manual(struct macsmc_hwmon *hwmon, u8 val, int channel)
> +{
> +	int ret;
> +	u16 buf;
> +
> +	ret = apple_smc_read_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), &buf);
> +	if (ret)
> +		return ret;
> +
> +	buf = be16_to_cpu(buf);
> +
> +	if (val)
> +		buf |= BIT(channel);
> +	else
> +		buf &= ~BIT(channel);
> +
> +	return apple_smc_write_u16(hwmon->smc, __SMC_KEY('F', 'S', '!', ' '), cpu_to_be16(buf));
> +}

[Severity: Low]
Will buf trigger sparse endianness warnings here?  buf is declared as
host-endian u16, passed directly to be16_to_cpu(), and then cpu_to_be16(buf)
is passed to apple_smc_write_u16(), which takes a plain u16.  Reading and
writing a __be16 variable via apple_smc_read() and apple_smc_write() would
keep endianness annotations consistent.

[ ... ]

> +static int macsmc_hwmon_create_sensor_acpi(struct apple_smc *smc,
> +		struct macsmc_hwmon_sensor *sensor, smc_key key, char *name, u32 attrs)
> +{
> +	int ret;
> +
> +	ret = apple_smc_get_key_info(smc, key, &sensor->info);
> +	if (ret)
> +		return ret;
> +
> +	sensor->macsmc_key = key;
> +	sensor->label = name;
> +	sensor->attrs = attrs;
> +
> +	return 0;
> +}

[Severity: Medium]
Can this register unreadable keys, unsupported SMC types, or non-sensor keys
as hwmon attributes and thermal zones?

macsmc_hwmon_create_sensor_acpi() never checks APPLE_SMC_READABLE or whether
sensor->info.type_code is handled by macsmc_hwmon_read_key(), so keys with
types such as flag, hex_, or ch8* fail every read with -EOPNOTSUPP or -EIO.

The static tables also include non-sensor entries such as audio scratchpads
(MST1, MST2), power limits and throttles (MSTc, MSTg, PZ0T..PZ5T), and
non-temperature keys (TCFC, TMBS, TH0e) in temp_sensors[], which are exposed
as kernel thermal zones because HWMON_C_REGISTER_TZ is set.

[ ... ]

> +static int macsmc_hwmon_create_fan_acpi(struct apple_smc *smc,
> +					struct macsmc_hwmon_fan *fan, int num)
> +{
> +	const char num_char = num + '0';
> +	int ret;
> +
> +	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->now,
> +			__SMC_KEY('F', num_char, 'A', 'c'), NULL, 0);
> +	if (ret)
> +		return ret;
> +
> +	if (apple_smc_key_exists(smc, __SMC_KEY('F', num_char, 'I', 'D'))) {
> +		char buf[17];
> +
> +		ret = apple_smc_read(smc, __SMC_KEY('F', num_char, 'I', 'D'), buf, 16);
> +		if (ret < 0)
> +			return ret;
> +
> +		buf[16] = '\0';
> +		snprintf(fan->label, sizeof(fan->label), "%s", buf + 4);
> +	} else
> +		snprintf(fan->label, sizeof(fan->label), "Fan %d", num);
> +
> +	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->min,
> +			__SMC_KEY('F', num_char, 'M', 'n'), NULL, 0);
> +	if (ret)
> +		return ret;
> +
> +	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->max,
> +			__SMC_KEY('F', num_char, 'M', 'x'), NULL, 0);
> +	if (ret)
> +		return ret;
> +
> +	ret = macsmc_hwmon_create_sensor_acpi(smc, &fan->set,
> +			__SMC_KEY('F', num_char, 'T', 'g'), NULL, 0);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Can a short or unreadable F%dID key copy stale MMIO bytes or abort the entire
hwmon probe?

apple_smc_key_exists() discards info.size, so apple_smc_read() requests 16
bytes without checking that F%dID is 16 bytes long; apple_smc_acpi_mmio_read()
copies len bytes unconditionally from SRAM, and PIO mode times out with -EIO.
On read failure, or if any of F%dMn, F%dMx, or F%dTg is absent, returning ret
aborts macsmc_hwmon_probe() completely instead of falling back to "Fan %d" or
treating those keys as optional like macsmc_hwmon_create_fan() does.

[ ... ]

> +static int macsmc_hwmon_register_sensors_acpi(
> +	struct macsmc_hwmon *hwmon,
> +	struct macsmc_hwmon_sensors *sensors,
> +	const struct macsmc_sensor_desc *descs,
> +	size_t num_descs,
> +	u32 attrs)
> +{
> +	size_t count = 0;
> +	size_t i;
> +	int ret;
> +
> +	for (i = 0; i < num_descs; i++) {
> +		if (apple_smc_key_exists(hwmon->smc, descs[i].key))
> +			count++;
> +	}
> +
> +	if (!count)
> +		return 0;
> +
> +	sensors->sensors = devm_kcalloc(hwmon->dev, count,
> +					sizeof(*sensors->sensors),
> +					GFP_KERNEL);
> +	if (!sensors->sensors)
> +		return -ENOMEM;
> +
> +	sensors->count = 0;
> +
> +	for (i = 0; i < num_descs; i++) {
> +		if (!apple_smc_key_exists(hwmon->smc, descs[i].key))
> +			continue;
> +
> +		ret = macsmc_hwmon_create_sensor_acpi(hwmon->smc,
> +						&sensors->sensors[sensors->count],
> +						descs[i].key,
> +						descs[i].name,
> +						attrs);
> +		if (ret)
> +			return ret;
> +
> +		sensors->count++;
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Can a transient SMC timeout cause a heap out-of-bounds write past
sensors->sensors?

apple_smc_key_exists() treats transient -EIO timeouts the same as missing
keys.  If a key query fails during the counting pass and succeeds during the
second pass, sensors->count exceeds the allocated count without any bounds
check, overflowing sensors->sensors.

[Severity: High]
Will probing all 558 static keys twice over live SMC hardware stall boot for
minutes on PIO Intel Macs?

This function queries every key twice via apple_smc_key_exists() and a third
time in macsmc_hwmon_create_sensor_acpi() for present keys
(macsmc_hwmon_create_fan_acpi() similarly double-queries F%dMd).  On PIO
Macs, apple_smc_acpi_port_read() detects nonexistent keys only by timing out
for 1,000 ms in apple_smc_acpi_port_wait() and disabling SMC interrupts on
the first miss, so probing hundreds of absent keys twice stalls probe for
over 15 minutes.

Enumerating or binary-searching the sorted SMC key table via
apple_smc_get_key_by_index() (like applesmc.c does) would avoid probing
missing keys.

> +static int macsmc_hwmon_populate_sensors_acpi(struct macsmc_hwmon *hwmon)
> +{
> +	int ret, i;
> +	u8 count;
> +
> +	ret = apple_smc_read_u8(hwmon->smc, SMC_KEY(FNum), &count);
> +	if (count && !ret) {

[Severity: Medium]
Does if (count && !ret) read uninitialized stack variable count when reading
FNum fails?

On error, both apple_smc_acpi_mmio_read() and apple_smc_acpi_port_read()
return without writing to the output buffer, leaving count uninitialized on
fanless Macs without FNum and triggering KMSAN uninit-value reports.
Checking if (!ret && count) avoids this.

[ ... ]

> +	if (hwmon->smc->is_acpi)
> +		ret = macsmc_hwmon_populate_sensors_acpi(hwmon);
> +	else
> +		ret = macsmc_hwmon_populate_sensors(hwmon, hwmon->dev->of_node);

[Severity: Medium]
Will Intel Mac sensors backed by ui16, si16, ui32, or si32 SMC keys return
byte-swapped values?

Multi-byte integer keys on Intel ACPI SMCs are big-endian (as handled for FS!
in macsmc_hwmon_write_old_fan_manual() and in macsmc-power.c), but
macsmc_hwmon_read_key() reads them in host byte order without converting when
smc->is_acpi is true:

drivers/hwmon/macsmc-hwmon.c:macsmc_hwmon_read_key() {
	...
	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 = (s64)ui16 * scale;
		break;
	}
	...
}

The same applies to si16, ui32, and si32, so any ACPI sensor using those
types reports garbage on little-endian x86 hosts.

[ ... ]

> +static int macsmc_hwmon_resume(struct platform_device *pdev)
> +{
> +	struct macsmc_hwmon *hwmon = dev_get_drvdata(&pdev->dev);
> +
> +	if (hwmon->smc->is_acpi && !hwmon->fan.has_old_manual) {
> +		int idx;
> +		int ret;
> +
> +		for (idx = 0; idx < hwmon->fan.count; idx++)
> +			if (hwmon->fan.fans[idx].manual) {
> +				ret = macsmc_hwmon_write_key(hwmon->smc,
> +						&hwmon->fan.fans[idx].mode, 1);
> +				if (ret < 0) {
> +					dev_warn(&pdev->dev,
> +						"Unable to reenable fan manual, disabling\n");
> +					hwmon->fan.fans[idx].manual = false;
> +				}
> +			}
> +
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Does macsmc_hwmon_resume() leave fan control state desynchronized with the
SMC after suspend or hibernation?

Checking !hwmon->fan.has_old_manual skips older Intel Macs that use FS!, so
fans[idx].manual stays true in memory after the SMC resets to automatic mode
and later fanX_target writes will not re-set FS! until userspace writes 0
first.  On newer Intel Macs, re-enabling manual mode (F%dMd = 1) without
restoring the saved F%dTg target speed locks fans in manual mode at the SMC's
post-sleep or post-boot default target.

[ ... ]

>  static struct platform_driver macsmc_hwmon_driver = {
>  	.probe = macsmc_hwmon_probe,
> +	.resume = macsmc_hwmon_resume,
>  	.driver = {
>  		.name = "macsmc-hwmon",
>  		.of_match_table = macsmc_hwmon_of_table,

[Severity: Low]
Should this use DEFINE_SIMPLE_DEV_PM_OPS() with .driver.pm = pm_sleep_ptr()
instead of the deprecated legacy platform_driver.resume callback?  Using
dev_pm_ops matches the other macsmc drivers in this series and allows the
compiler to drop macsmc_hwmon_resume() when CONFIG_PM_SLEEP is disabled.

[ ... ]

>  MODULE_DESCRIPTION("Apple Silicon SMC hwmon driver");
>  MODULE_AUTHOR("James Calligeros <jcalligeros99@gmail.com>");
>  MODULE_LICENSE("Dual MIT/GPL");
> +MODULE_ALIAS("platform:macsmc-hwmon");

[Severity: Low]
This isn't a bug, but Documentation/hwmon/macsmc-hwmon.rst,
MODULE_DESCRIPTION, and the file header comment still describe the driver as
Apple Silicon only.  The patch also includes unrelated whitespace changes in
macsmc_hwmon_write_f32(), macsmc_hwmon_is_visible(), and
macsmc_hwmon_populate_sensors() that misalign continuation lines away from
the opening parenthesis.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=13

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  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:26       ` Sven Peter
  0 siblings, 2 replies; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 14:48 UTC (permalink / raw)
  To: Andy Shevchenko, Atharva Tiwari
  Cc: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Guenter Roeck, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Lee Jones, Pavel Machek,
	Griffin Kroah-Hartman, Hans de Goede, Ilpo Järvinen,
	Sebastian Reichel, Alexandre Belloni, Wim Van Sebroeck,
	Jarkko Sakkinen, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-kernel, linux-pci, linux-acpi, linux-gpio, asahi,
	linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module



On 04-Dec-26 07:42 PM, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:
>> Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
>> work correctly on T2 Macs, so the clock from the SMC is
>> used instead.
>>
>> On these machines the time offset is kept in the SMC instead
>> of NVMEM, and the clock rate is read from the SMC too.
> 
> ...
> 
>> +static bool force_clkm;
>> +module_param(force_clkm, bool, 0644);
>> +MODULE_PARM_DESC(force_clkm, "Force CLKM Key, instead of trying to use CLKL");
> 
> No, why?!
> 
> ...
> 
>>  struct macsmc_rtc {
>>  	struct device *dev;
>>  	struct apple_smc *smc;
>>  	struct rtc_device *rtc_dev;
>>  	struct nvmem_cell *rtc_offset;
>> +	uint8_t shift;
> 
> No, use kernel types.
> 
>> +	bool async_rtc;
>>  };
> 
> ...
> 
>> +static int macsmc_rtc_read_clkl(struct macsmc_rtc *rtc, u64 *ctr)
>> +{
>> +	u64 request = 0xffffffffffffULL;
>> +	u64 response = 0;
>> +	int i, j, ret;
>> +
>> +	for (i = 0; i < 4; i++) {
>> +		for (j = 0; j < 40; j++) {
>> +			ret = apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES);
>> +			if (ret == RTC_BYTES)
>> +				break;
>> +		}
>> +		if (ret != RTC_BYTES)
>> +			continue;
>> +
>> +		msleep(20);
>> +
>> +		for (j = 0; j < 20; j++) {
>> +			ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &response, RTC_BYTES);
>> +			if (ret == RTC_BYTES) {
>> +				if ((response & 0x7fff) == 5 || (response & 0x7fff) == 6)
>> +					return -EAGAIN;
>> +
>> +				if (response != 0xffffffffffffULL) {
>> +					*ctr = response;
>> +					return RTC_BYTES;
>> +				}
>> +			}
>> +			fsleep(1000);
>> +		}
>> +	}
>> +
>> +	return -EIO;
>> +}
> 
> Really, folks, read the last a year code or so to understand why the above is
> no go (style-wise). It's your homework, you can find all of the typical issues
> in the mailing list archives.
> 
> ...
> 
>> +MODULE_ALIAS("platform:macsmc-rtc");
> 
> Are you sure it's a best approach?
> 
> ...
> 
> Overall impression that you copied'n'pasted AI slop without much effort made on
> editing and understanding. Also looks like each patch requires a logical split
> to a mini-series.
> 

The whole code is being developed before AI was compatible enough to generate all this. Thanks for the AI insight. The logical split is good enough IMO. Pretty much same as what Asahi Linux did. I would be nicer if you could elaborate the split by a few examples rather than just making a statement.


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 14:19   ` Andy Shevchenko
@ 2026-12-04 14:52     ` Aditya Garg
  2026-12-04 17:23       ` Andy Shevchenko
  2026-12-04 19:57     ` Atharva Tiwari
  1 sibling, 1 reply; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 14:52 UTC (permalink / raw)
  To: Andy Shevchenko, Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module, Linus Torvalds



On 04-Dec-26 07:49 PM, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:
>> Add a backend that talks to the SMC on Intel Macs over ACPI.
>> It supports the old I/O port interface, and also MMIO and
>> interrupt-driven completion, which applesmc doesn't have.
>> If an interrupt is missed it falls back to polling.
>>
>> This is the base that lets the macsmc drivers replace
>> applesmc.
> 
> ...
> 
>> +#include <linux/acpi.h>
>> +#include <linux/bits.h>
> 
>> +#include <linux/byteorder/generic.h>
> 
> Wrong, the asm/byteorder.h has to be used.
> 
>> +#include <linux/cleanup.h>
>> +#include <linux/compiler.h>
>> +#include <linux/completion.h>
>> +#include <linux/device.h>
>> +#include <linux/devm-helpers.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/io.h>
> 
>> +#include <linux/ioport.h>
> 
>> +#include <linux/iopoll.h>
> 
> With this, io.h is not required.
> 
>> +#include <linux/kfifo.h>
>> +#include <linux/mfd/macsmc.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pm.h>
>> +#include <linux/reboot.h>
>> +#include <linux/spinlock.h>
>> +#include <linux/time.h>
>> +#include <linux/types.h>
>> +#include <linux/unaligned.h>
>> +#include <linux/workqueue.h>
> 
> ...
> 
>> +#define SMC_TIMEOUT_MS			1000
> 
> Why not (1 * MSEC_PER_SEC) here ?
> 
> ...
> 
>> +struct apple_smc_acpi {
>> +	struct device *dev;
>> +
>> +	u8 __iomem *iomem_base;
>> +	u32 iomem_base_addr, iomem_base_size;
>> +	bool is_mmio;
>> +
>> +	u16 port_base;
>> +	bool has_port;
>> +
>> +	int irq;
> 
>> +	bool has_interrupt;
> 
> Why? Isn't non-positive value means no interrupt?
> 
>> +	bool interrupt_enabled;
> 
> Why? Isn't IRQ core provides something for this?
> 
>> +	struct completion cmd_done;
>> +
>> +	struct blocking_notifier_head event_handlers;
>> +	struct work_struct shutdown_work;
>> +	struct work_struct notifier_work;
>> +
>> +	DECLARE_KFIFO(event_fifo, u8, 64);
>> +	/* Protects event_fifo, shared between the IRQ handler and notifier_work */
>> +	spinlock_t event_lock;
>> +};
>> +
>> +
> 
> Why double blank line?
> 
>> +static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
>> +{
>> +	u8 status;
>> +	int ret;
>> +
>> +	if (smc->interrupt_enabled) {
>> +		reinit_completion(&smc->cmd_done);
>> +		if (wait_for_completion_timeout(&smc->cmd_done,
>> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
>> +			return 0;
>> +
>> +		smc->interrupt_enabled = 0;
>> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
>> +	}
>> +
>> +	ret = read_poll_timeout(inb, status, (status & mask) == val,
>> +				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
>> +				false, smc->port_base + SMC_IO_CMD_PORT);
>> +	if (ret)
>> +		dev_dbg(smc->dev, "port/wait: timeout value:%u, mask:%u\n", val, mask);
>> +
>> +	return ret;
>> +}
> 
> ...
> 
>> +static int apple_smc_acpi_port_write_key(struct apple_smc_acpi *smc, smc_key key)
>> +{
>> +	int i;
>> +
>> +	for (i = 3; i >= 0; i--) {
>> +		if (apple_smc_acpi_port_write_byte(smc, (key >> (i * 8)) & 0xff))
>> +			return -EIO;
>> +	}
> 
> Missing blank line.
> 
>> +	return 0;
> 
> This should use proper __be32 type instead.
> 
>> +}
>> +
>> +static int apple_smc_acpi_port_valid(struct apple_smc_acpi *smc)
>> +{
>> +	int ret;
> 
>> +	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
>> +	if (!ret)
> 
> Huh?! This is way non-standard. Don't do that.
> This is a semantic mistake.
> 
>> +		return ret;
>> +
>> +	ret = apple_smc_acpi_port_write_cmd(smc, SMC_MSG_READ_KEY);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
>> +}
> 
> ...
> 
>> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
>> +	{"APP0001", 0},
>> +	{}
>> +};
> 
> Where have you been last half a year?

He is a new kernel dev. Not your fault for assuming he is a seasoned one. Can the maintainers be friendly and point out code errors rather than the RTFM thing for LKML as well? Or atleast point out some examples rather than just ranting.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 14:08   ` Andy Shevchenko
@ 2026-12-04 14:56     ` Aditya Garg
  2026-12-04 17:14       ` Andy Shevchenko
  0 siblings, 1 reply; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 14:56 UTC (permalink / raw)
  To: Andy Shevchenko, Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module



On 04-Dec-26 07:38 PM, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:
>> When macsmc-power is enabled on an Intel Mac, skip acpi-sbs
>> and the ACPI battery and adapter drivers, since macsmc-power
>> now provides them. This avoids duplicate devices.
> 
> ...
> 
>> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
>> +			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
>> +		return -ENODEV;
> 
> 
> This is a hack. And it's even indented wrongly.

Do you have a better idea to avoid using duplicate devices?
> 
> ...
> 
>> @@ -664,7 +668,6 @@ static int acpi_sbs_probe(struct platform_device *pdev)
>>  					acpi_battery_add(sbs, id);
>>  		}
>>  	}
>> -
>>  	if (!sbs->manager_present)
>>  		acpi_battery_add(sbs, 0);
> 
> What the heck is this?
> 
> ...
> 
> Please, read what you is about to send,
> 


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 01/14] treewide: Add backend for macsmc
  2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
  2026-12-04 13:56   ` sashiko-bot
  2026-12-04 14:07   ` Andy Shevchenko
@ 2026-12-04 16:45   ` Sven Peter
  2 siblings, 0 replies; 53+ messages in thread
From: Sven Peter @ 2026-12-04 16:45 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module



On 04.12.26 14:12, Atharva Tiwari wrote:
> Split the Apple SMC driver into a common core and a backend
> that handles the actual communication. The existing RTKit
> code moves to its own backend, and nothing changes for
> Apple Silicon.
> 
> This lets the same SMC drivers run on other kinds of
> hardware, starting with Intel Macs, as a replacement for
> applesmc.
> 
> Tested-by: Ihor Odainyi <pv4k@odayny.com>
> Tested-by: Antoine Sidem <sidemantoine@gmail.com>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
> ---

Why is this is a single patch? That makes review very hard and I'm 
pretty sure there's no need for "treewide: " here. You probably want at 
least few mfd patches that prepare the split, then one that moves the 
rtkit stuff to soc/apple and then probably another patch to add the ACPI 
specific stuff that's in this commit. And the gpio changes here probably 
should be separate as well.


Sven


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  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:26       ` Sven Peter
  1 sibling, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:06 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

On Fri, Dec 04, 2026 at 08:18:54PM +0530, Aditya Garg wrote:
> On 04-Dec-26 07:42 PM, Andy Shevchenko wrote:
> > On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:

...

> > Overall impression that you copied'n'pasted AI slop without much effort made on
> > editing and understanding. Also looks like each patch requires a logical split
> > to a mini-series.
> 
> The whole code is being developed before AI was compatible enough to generate
> all this. Thanks for the AI insight. The logical split is good enough IMO.

Not only me thinks otherwise.

> Pretty much same as what Asahi Linux did.

Is Asahi Linux now the Golden Standard for the Linux kernel patches?

> I would be nicer if you could elaborate the split by a few examples rather
> than just making a statement.

Examples? Hmm... I'm puzzled a bit by the request, but if you really want
something, take any of my 8+ patch series in the past from Git history.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  2026-12-04 17:06       ` Andy Shevchenko
@ 2026-12-04 17:10         ` Aditya Garg
  2026-12-04 17:18           ` Andy Shevchenko
  0 siblings, 1 reply; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 17:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Atharva Tiwari, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno S�, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module



> On 4 Dec 2026, at 10:37 PM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> 
> On Fri, Dec 04, 2026 at 08:18:54PM +0530, Aditya Garg wrote:
>>> On 04-Dec-26 07:42 PM, Andy Shevchenko wrote:
>>> On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:
> 
> ...
> 
>>> Overall impression that you copied'n'pasted AI slop without much effort made on
>>> editing and understanding. Also looks like each patch requires a logical split
>>> to a mini-series.
>> 
>> The whole code is being developed before AI was compatible enough to generate
>> all this. Thanks for the AI insight. The logical split is good enough IMO.
> 
> Not only me thinks otherwise.

No worries. It's probably not worth discussing AI here anyways.
> 
>> Pretty much same as what Asahi Linux did.
> 
> Is Asahi Linux now the Golden Standard for the Linux kernel patches?

What I am quoting are patches that are upstreamed into the kernel. I believe they had similar vigorous review like these. Nevertheless, Sven has pointed out the errors here.
> 
>> I would be nicer if you could elaborate the split by a few examples rather
>> than just making a statement.
> 
> Examples? Hmm... I'm puzzled a bit by the request, but if you really want
> something, take any of my 8+ patch series in the past from Git history.

Well this was a reply to a comment where you were asking where the author was for the past half year. My bad, I replied to the wrong email here.
> 
> --
> With Best Regards,
> Andy Shevchenko
> 
> 

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 14:56     ` Aditya Garg
@ 2026-12-04 17:14       ` Andy Shevchenko
  2026-12-04 18:51         ` Aditya Garg
  0 siblings, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:14 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Fri, Dec 04, 2026 at 08:26:48PM +0530, Aditya Garg wrote:
> On 04-Dec-26 07:38 PM, Andy Shevchenko wrote:
> > On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:

...

> >> +	if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> >> +			IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> >> +		return -ENODEV;
> > 
> > This is a hack. And it's even indented wrongly.
> 
> Do you have a better idea to avoid using duplicate devices?

The commit message is poorly written to advice anything.
It's unclear why we have duplicate drivers for the same ACPI HID to begin with.
Can MAC case be enumerated differently? When the SMS driver is not compiled
this one is still in use, why is it not a problem? So, there are many unaswered
questions...

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  2026-12-04 17:10         ` Aditya Garg
@ 2026-12-04 17:18           ` Andy Shevchenko
  0 siblings, 0 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:18 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Guenter Roeck,
	Jonathan Cameron, David Lechner, Nuno S�, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-kernel, linux-pci, linux-acpi, linux-gpio,
	asahi, linux-arm-kernel, linux-hwmon, linux-iio, linux-leds, mfd,
	platform-driver-x86, linux-pm, linux-rtc, linux-watchdog,
	linux-integrity, keyrings, linux-security-module

On Fri, Dec 04, 2026 at 10:40:34PM +0530, Aditya Garg wrote:
> > On 4 Dec 2026, at 10:37 PM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Fri, Dec 04, 2026 at 08:18:54PM +0530, Aditya Garg wrote:
> >>> On 04-Dec-26 07:42 PM, Andy Shevchenko wrote:
> >>> On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:

...

> >> Pretty much same as what Asahi Linux did.
> > 
> > Is Asahi Linux now the Golden Standard for the Linux kernel patches?
> 
> What I am quoting are patches that are upstreamed into the kernel. I believe
> they had similar vigorous review like these. Nevertheless, Sven has pointed
> out the errors here.

I understand, but sometimes bad code appears in the kernel because of "business
needs", I saw so many times that even authored by Intel.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 14:52     ` Aditya Garg
@ 2026-12-04 17:23       ` Andy Shevchenko
  2026-12-04 18:34         ` Aditya Garg
  0 siblings, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 17:23 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module, Linus Torvalds

On Fri, Dec 04, 2026 at 08:22:52PM +0530, Aditya Garg wrote:
> On 04-Dec-26 07:49 PM, Andy Shevchenko wrote:
> > On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:

...

> >> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
> >> +	{"APP0001", 0},
> >> +	{}
> >> +};
> > 
> > Where have you been last half a year?
> 
> He is a new kernel dev. Not your fault for assuming he is a seasoned one.

Oh, sorry for that. Do you have any internal mailing list to discuss patches
before sending, or is it just this mailing list for the fully open discussion?

> Can the maintainers be friendly and point out code errors rather than the
> RTFM thing for LKML as well? Or atleast point out some examples rather than
> just ranting.

Sure. The C99 initialisers is a requirement nowadays for the ID tables.
As well as common style. I highly recommend to check with Git history
for each of the subsystem and check the last contributions. AI actually
may be helpful with collecting and summarising such an info.

The above should be

static const struct acpi_device_id apple_smc_acpi_ids[] = {
	{ .id = "APP0001" },
	{ }
};

P.S. Sorry for my tone, I'm so grumpy on the later AI slop here and there,
especially when people do not read anything.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc
  2026-12-04 14:48     ` Aditya Garg
  2026-12-04 17:06       ` Andy Shevchenko
@ 2026-12-04 17:26       ` Sven Peter
  1 sibling, 0 replies; 53+ messages in thread
From: Sven Peter @ 2026-12-04 17:26 UTC (permalink / raw)
  To: Aditya Garg, Andy Shevchenko, Atharva Tiwari
  Cc: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module



On 04.12.26 15:48, Aditya Garg wrote:
> 
> 
> On 04-Dec-26 07:42 PM, Andy Shevchenko wrote:
>> On Fri, Dec 04, 2026 at 08:12:47AM -0500, Atharva Tiwari wrote:
>>> Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
>>> work correctly on T2 Macs, so the clock from the SMC is
>>> used instead.
>>>
>>> On these machines the time offset is kept in the SMC instead

[...]

> 
>  The logical split is good enough IMO. Pretty much same as what Asahi Linux did. 

Nope, this series here is *very* different. Please take a look at those 
series again if you truly believe that they are similar. There was no 
treewide and similar weird things in there. There were at least three 
separate series for SMC support because a single series would've been 
much too large.

I've only looked at the first commit which could probably be its own 
mini series that could land first here but I wouldn't be surprised if 
the other commits have similar issues and should also be split into 
smaller logical chunks.


Sven

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 17:23       ` Andy Shevchenko
@ 2026-12-04 18:34         ` Aditya Garg
  0 siblings, 0 replies; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 18:34 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module, Linus Torvalds



On 04-Dec-26 10:53 PM, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 08:22:52PM +0530, Aditya Garg wrote:
>> On 04-Dec-26 07:49 PM, Andy Shevchenko wrote:
>>> On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:
> 
> ...
> 
>>>> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
>>>> +	{"APP0001", 0},
>>>> +	{}
>>>> +};
>>>
>>> Where have you been last half a year?
>>
>> He is a new kernel dev. Not your fault for assuming he is a seasoned one.
> 
> Oh, sorry for that. Do you have any internal mailing list to discuss patches
> before sending, or is it just this mailing list for the fully open discussion?

There has been an internal discussion. Infact an RFC was also sent for this series.
> 
>> Can the maintainers be friendly and point out code errors rather than the
>> RTFM thing for LKML as well? Or atleast point out some examples rather than
>> just ranting.
> 
> Sure. The C99 initialisers is a requirement nowadays for the ID tables.
> As well as common style. I highly recommend to check with Git history
> for each of the subsystem and check the last contributions. AI actually
> may be helpful with collecting and summarising such an info.
> 
> The above should be
> 
> static const struct acpi_device_id apple_smc_acpi_ids[] = {
> 	{ .id = "APP0001" },
> 	{ }
> };

Thank you very much for this. I appreciate it.
> 
> P.S. Sorry for my tone, I'm so grumpy on the later AI slop here and there,
> especially when people do not read anything.

I understand your feeling here. I myself am frustrated because of a pile load of slop PRs on my projects xD.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 12/14] hwmon/macsmc: add more types
  2026-12-04 14:37   ` sashiko-bot
@ 2026-12-04 18:44     ` Guenter Roeck
  0 siblings, 0 replies; 53+ messages in thread
From: Guenter Roeck @ 2026-12-04 18:44 UTC (permalink / raw)
  To: sashiko-reviews, Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar, Roberto Sassu,
	Dmitry Kasatkin, Eric Snowberg, Paul Moore, James Morris,
	Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon, linux-leds,
	mfd, linux-rtc, linux-watchdog, keyrings, linux-security-module

On 12/4/26 06:37, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 5 potential
> issues to consider:
> - [High] hwmon: (macsmc) missing endian conversion in
>    macsmc_hwmon_read_key()
> - [Medium] hwmon: (macsmc) unclamped s64 to long truncation in
>    macsmc_hwmon_read_key()
> - [Low] hwmon: macsmc: sparse __be16 type mismatches on SMC fixed-point
>    I/O
> - [Low] hwmon: macsmc: duplicate fixed-point decoding in
>    macsmc_hwmon_read_key()
> - [Low] hwmon: missing range check for fpe2 write in
>    macsmc_hwmon_write_key()
> --
> 

Too much for me to even look at. Please fix.

Guenter


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon
  2026-12-04 14:48   ` sashiko-bot
@ 2026-12-04 18:45     ` Guenter Roeck
  2026-12-04 20:13       ` Jarkko Sakkinen
  0 siblings, 1 reply; 53+ messages in thread
From: Guenter Roeck @ 2026-12-04 18:45 UTC (permalink / raw)
  To: sashiko-reviews, Atharva Tiwari
  Cc: Ihor Odainyi, Antoine Sidem, Aditya Garg, Andre Eikmeyer,
	Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Rafael J. Wysocki, Len Brown,
	Linus Walleij, Bartosz Golaszewski, Sven Peter, Janne Grunau,
	Neal Gompa, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-pci, linux-gpio, linux-hwmon,
	linux-leds, mfd, linux-rtc, linux-watchdog, keyrings,
	linux-security-module

On 12/4/26 06:48, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 11 potential
> issues to consider:
> - [High] hwmon: macsmc: NULL pointer dereference in DT sensor label
>    handling
> - [High] hwmon: macsmc: redundant SMC probes cause multi-minute PIO
>    probe stalls
> - [Medium] hwmon: macsmc: uninitialized count read in
>    macsmc_hwmon_populate_sensors_acpi()
> - [Medium] hwmon: macsmc: heap OOB write in
>    macsmc_hwmon_register_sensors_acpi()
> - [Medium] hwmon: macsmc: invalid sensor keys and missing key validation
>    on ACPI
> - [Medium] hwmon: macsmc: unvalidated F%dID read and fatal optional fan
>    key errors
> - [Medium] hwmon: macsmc: missing big-endian conversion for integer keys
>    on ACPI
> - [Medium] hwmon: macsmc_hwmon_resume() skips FS! and target restore,
>    uses legacy PM
> - [Low] hwmon: macsmc: outdated docs, MODULE_DESCRIPTION, and whitespace
>    changes
> - [Low] hwmon: macsmc: u16/__be16 mismatch in
>    macsmc_hwmon_write_old_fan_manual()
> - [Low] hwmon: macsmc-hwmon uses deprecated legacy
>    platform_driver.resume callback
> --

Too much for me to even look at. Please fix.

Guenter


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 17:14       ` Andy Shevchenko
@ 2026-12-04 18:51         ` Aditya Garg
  2026-12-04 20:02           ` Andy Shevchenko
  0 siblings, 1 reply; 53+ messages in thread
From: Aditya Garg @ 2026-12-04 18:51 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno S�,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module



> On 4 Dec 2026, at 10:45 PM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> 
> On Fri, Dec 04, 2026 at 08:26:48PM +0530, Aditya Garg wrote:
>>> On 04-Dec-26 07:38 PM, Andy Shevchenko wrote:
>>> On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:
> 
> ...
> 
>>>> +    if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
>>>> +            IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
>>>> +        return -ENODEV;
>>> 
>>> This is a hack. And it's even indented wrongly.
>> 
>> Do you have a better idea to avoid using duplicate devices?
> 
> The commit message is poorly written to advice anything.
> It's unclear why we have duplicate drivers for the same ACPI HID to begin with.
> Can MAC case be enumerated differently? When the SMS driver is not compiled
> this one is still in use, why is it not a problem? So, there are many unaswered
> questions...

On Macs you can get battery and adapter stats using both ACPI and SMC. The SMC reported values are more reliable so we developed a driver for that. But if we use that driver, Linux thinks there are 2 batteries, one from ACPI and other from SMC. So we need to disable it from ACPI.

One way is to simply check is the device is a Mac and disable ACPI permanently. Other way is check if SMC is compiled or not. If not, fall back to ACPI so that we don't loose battery.

I understand the issue with commit messages. The author's native language isn't English so he is unable to communicate properly and thus is using AI to write the messages. I'll try and help him here.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 14:19   ` Andy Shevchenko
  2026-12-04 14:52     ` Aditya Garg
@ 2026-12-04 19:57     ` Atharva Tiwari
  2026-12-04 20:23       ` Andy Shevchenko
  1 sibling, 1 reply; 53+ messages in thread
From: Atharva Tiwari @ 2026-12-04 19:57 UTC (permalink / raw)
  To: andriy.shevchenko
  Cc: aditya.garg, alexandre.belloni, andy, asahi,
	atharvatiwarilinuxdev, bhelgaas, bp, brgl, dave.hansen, dlechner,
	dmitry.kasatkin, eric.snowberg, griffin, hansg, hpa,
	ilpo.jarvinen, j, jarkko, jic23, jmorris, keyrings, lee, lenb,
	linusw, linux-acpi, linux-arm-kernel, linux-gpio, linux-hwmon,
	linux-iio, linux-integrity, linux-kernel, linux-leds, linux-pci,
	linux-pm, linux-rtc, linux-security-module, linux-watchdog, linux,
	mfd, mingo, neal, nuno.sa, paul, pavel, platform-driver-x86, pv4k,
	rafael, roberto.sassu, serge, sidemantoine, sre, sven, tglx, wim,
	x86, zohar

> > +	bool has_interrupt;
> 
> Why? Isn't non-positive value means no interrupt?
> 
> > +	bool interrupt_enabled;
> 
> Why? Isn't IRQ core provides something for this?

Sorry if i was not clear, but basically

has_interrupt means that there is a interrupt line present in ACPI and
the driver should write to NTOK key.

interrupt_enabled means that interrupts are enabled (NTOK written successfully)
and interrupts can be used for reading and writing, thats why when a interrupt
is missed, the driver sets interrupt_enabled to 0:

+	if (smc->interrupt_enabled) {
+		if (wait_for_completion_timeout(&smc->cmd_done,
+					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
+			return 0;
+
+		smc->interrupt_enabled = 0;
+		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
+	}

interrupt_enabled is not used anywhere else except in the resume code.

I will remove the has_interrupt variable, because you said non-positive irq means no interrupt.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 18:51         ` Aditya Garg
@ 2026-12-04 20:02           ` Andy Shevchenko
  2026-12-04 20:13             ` Andy Shevchenko
  0 siblings, 1 reply; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 20:02 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno S�,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Sat, Dec 05, 2026 at 12:21:14AM +0530, Aditya Garg wrote:
> 
> 
> > On 4 Dec 2026, at 10:45 PM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > 
> > On Fri, Dec 04, 2026 at 08:26:48PM +0530, Aditya Garg wrote:
> >>> On 04-Dec-26 07:38 PM, Andy Shevchenko wrote:
> >>> On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:
> > 
> > ...
> > 
> >>>> +    if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> >>>> +            IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> >>>> +        return -ENODEV;
> >>> 
> >>> This is a hack. And it's even indented wrongly.
> >> 
> >> Do you have a better idea to avoid using duplicate devices?
> > 
> > The commit message is poorly written to advice anything.
> > It's unclear why we have duplicate drivers for the same ACPI HID to begin with.
> > Can MAC case be enumerated differently? When the SMS driver is not compiled
> > this one is still in use, why is it not a problem? So, there are many unaswered
> > questions...
> 
> On Macs you can get battery and adapter stats using both ACPI and SMC. The
> SMC reported values are more reliable so we developed a driver for that. But
> if we use that driver, Linux thinks there are 2 batteries, one from ACPI and
> other from SMC. So we need to disable it from ACPI.
> 
> One way is to simply check is the device is a Mac and disable ACPI
> permanently. Other way is check if SMC is compiled or not. If not, fall back
> to ACPI so that we don't loose battery.

Should we just disable ACPI0002 enumeration via a quirk in somewhere drivers/acpi/ ?
Like acpi_create_platform_device() blocks the devices in the forbidden_id_list.

> I understand the issue with commit messages. The author's native language
> isn't English so he is unable to communicate properly and thus is using AI to
> write the messages. I'll try and help him here.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon
  2026-12-04 18:45     ` Guenter Roeck
@ 2026-12-04 20:13       ` Jarkko Sakkinen
  0 siblings, 0 replies; 53+ messages in thread
From: Jarkko Sakkinen @ 2026-12-04 20:13 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: sashiko-reviews, Atharva Tiwari, Ihor Odainyi, Antoine Sidem,
	Aditya Garg, Andre Eikmeyer, Bjorn Helgaas, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Rafael J. Wysocki, Len Brown, Linus Walleij, Bartosz Golaszewski,
	Sven Peter, Janne Grunau, Neal Gompa, Jonathan Cameron,
	David Lechner, Nuno Sá, Andy Shevchenko, Lee Jones,
	Pavel Machek, Griffin Kroah-Hartman, Hans de Goede,
	Ilpo Järvinen, Sebastian Reichel, Alexandre Belloni,
	Wim Van Sebroeck, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn,
	linux-pci, linux-gpio, linux-hwmon, linux-leds, mfd, linux-rtc,
	linux-watchdog, keyrings, linux-security-module

On Fri, Dec 04, 2026 at 10:45:03AM -0800, Guenter Roeck wrote:
> On 12/4/26 06:48, sashiko-bot@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 11 potential
> > issues to consider:
> > - [High] hwmon: macsmc: NULL pointer dereference in DT sensor label
> >    handling
> > - [High] hwmon: macsmc: redundant SMC probes cause multi-minute PIO
> >    probe stalls
> > - [Medium] hwmon: macsmc: uninitialized count read in
> >    macsmc_hwmon_populate_sensors_acpi()
> > - [Medium] hwmon: macsmc: heap OOB write in
> >    macsmc_hwmon_register_sensors_acpi()
> > - [Medium] hwmon: macsmc: invalid sensor keys and missing key validation
> >    on ACPI
> > - [Medium] hwmon: macsmc: unvalidated F%dID read and fatal optional fan
> >    key errors
> > - [Medium] hwmon: macsmc: missing big-endian conversion for integer keys
> >    on ACPI
> > - [Medium] hwmon: macsmc_hwmon_resume() skips FS! and target restore,
> >    uses legacy PM
> > - [Low] hwmon: macsmc: outdated docs, MODULE_DESCRIPTION, and whitespace
> >    changes
> > - [Low] hwmon: macsmc: u16/__be16 mismatch in
> >    macsmc_hwmon_write_old_fan_manual()
> > - [Low] hwmon: macsmc-hwmon uses deprecated legacy
> >    platform_driver.resume callback
> > --
> 
> Too much for me to even look at. Please fix.

It's the longest dump from Sashiko I've seen so far so totally
understandable...

Br, Jarkko

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines
  2026-12-04 20:02           ` Andy Shevchenko
@ 2026-12-04 20:13             ` Andy Shevchenko
  0 siblings, 0 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 20:13 UTC (permalink / raw)
  To: Aditya Garg
  Cc: Atharva Tiwari, Ihor Odainyi, Antoine Sidem, Bjorn Helgaas,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Rafael J. Wysocki, Len Brown, Linus Walleij,
	Bartosz Golaszewski, Sven Peter, Janne Grunau, Neal Gompa,
	Guenter Roeck, Jonathan Cameron, David Lechner, Nuno S�,
	Andy Shevchenko, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Hans de Goede, Ilpo Järvinen, Sebastian Reichel,
	Alexandre Belloni, Wim Van Sebroeck, Jarkko Sakkinen, Mimi Zohar,
	Roberto Sassu, Dmitry Kasatkin, Eric Snowberg, Paul Moore,
	James Morris, Serge E. Hallyn, linux-kernel, linux-pci,
	linux-acpi, linux-gpio, asahi, linux-arm-kernel, linux-hwmon,
	linux-iio, linux-leds, mfd, platform-driver-x86, linux-pm,
	linux-rtc, linux-watchdog, linux-integrity, keyrings,
	linux-security-module

On Fri, Dec 04, 2026 at 10:02:46PM +0200, Andy Shevchenko wrote:
> On Sat, Dec 05, 2026 at 12:21:14AM +0530, Aditya Garg wrote:
> > > On 4 Dec 2026, at 10:45 PM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > On Fri, Dec 04, 2026 at 08:26:48PM +0530, Aditya Garg wrote:
> > >>> On 04-Dec-26 07:38 PM, Andy Shevchenko wrote:
> > >>> On Fri, Dec 04, 2026 at 08:12:51AM -0500, Atharva Tiwari wrote:

...

> > >>>> +    if (IS_ENABLED(CONFIG_MACSMC_ACPI) &&
> > >>>> +            IS_ENABLED(CONFIG_MACSMC_POWER) && x86_apple_machine)
> > >>>> +        return -ENODEV;
> > >>> 
> > >>> This is a hack. And it's even indented wrongly.
> > >> 
> > >> Do you have a better idea to avoid using duplicate devices?
> > > 
> > > The commit message is poorly written to advice anything.
> > > It's unclear why we have duplicate drivers for the same ACPI HID to begin with.
> > > Can MAC case be enumerated differently? When the SMS driver is not compiled
> > > this one is still in use, why is it not a problem? So, there are many unaswered
> > > questions...
> > 
> > On Macs you can get battery and adapter stats using both ACPI and SMC. The
> > SMC reported values are more reliable so we developed a driver for that. But
> > if we use that driver, Linux thinks there are 2 batteries, one from ACPI and
> > other from SMC. So we need to disable it from ACPI.
> > 
> > One way is to simply check is the device is a Mac and disable ACPI
> > permanently. Other way is check if SMC is compiled or not. If not, fall back
> > to ACPI so that we don't loose battery.
> 
> Should we just disable ACPI0002 enumeration via a quirk in somewhere drivers/acpi/ ?
> Like acpi_create_platform_device() blocks the devices in the forbidden_id_list.

Since we have already acpi_quirk_skip_acpi_ac_and_battery() quirk, perhaps the
proper place is to have it only in utils.c and apply in sbs.c via a call to
acpi_quirk_skip_acpi_ac_and_battery(). Would that work?

> > I understand the issue with commit messages. The author's native language
> > isn't English so he is unable to communicate properly and thus is using AI to
> > write the messages. I'll try and help him here.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
  2026-12-04 19:57     ` Atharva Tiwari
@ 2026-12-04 20:23       ` Andy Shevchenko
  0 siblings, 0 replies; 53+ messages in thread
From: Andy Shevchenko @ 2026-12-04 20:23 UTC (permalink / raw)
  To: Atharva Tiwari
  Cc: aditya.garg, alexandre.belloni, andy, asahi, bhelgaas, bp, brgl,
	dave.hansen, dlechner, dmitry.kasatkin, eric.snowberg, griffin,
	hansg, hpa, ilpo.jarvinen, j, jarkko, jic23, jmorris, keyrings,
	lee, lenb, linusw, linux-acpi, linux-arm-kernel, linux-gpio,
	linux-hwmon, linux-iio, linux-integrity, linux-kernel, linux-leds,
	linux-pci, linux-pm, linux-rtc, linux-security-module,
	linux-watchdog, linux, mfd, mingo, neal, nuno.sa, paul, pavel,
	platform-driver-x86, pv4k, rafael, roberto.sassu, serge,
	sidemantoine, sre, sven, tglx, wim, x86, zohar

On Fri, Dec 04, 2026 at 02:57:44PM -0500, Atharva Tiwari wrote:

...

> > > +	bool has_interrupt;
> > 
> > Why? Isn't non-positive value means no interrupt?

> > > +	bool interrupt_enabled;
> > 
> > Why? Isn't IRQ core provides something for this?
> 
> Sorry if i was not clear, but basically
> 
> has_interrupt means that there is a interrupt line present in ACPI and
> the driver should write to NTOK key.
> 
> interrupt_enabled means that interrupts are enabled (NTOK written successfully)
> and interrupts can be used for reading and writing, thats why when a interrupt
> is missed, the driver sets interrupt_enabled to 0:

Okay, so this is the state of the communication with the remote side.

> +	if (smc->interrupt_enabled) {
> +		if (wait_for_completion_timeout(&smc->cmd_done,
> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> +			return 0;
> +
> +		smc->interrupt_enabled = 0;
> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> +	}
> 
> interrupt_enabled is not used anywhere else except in the resume code.
> 
> I will remove the has_interrupt variable, because you said non-positive irq
> means no interrupt.

This is usual interpretation of a value in IRQ (that's why in many places in
the code it's signed; where it's unsigned 0 means NOIRQ).

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2026-12-04 20:24 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 13:56   ` sashiko-bot
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 13:58   ` sashiko-bot
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:48   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-12-04 13:47   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-12-04 14:07   ` sashiko-bot
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 14:16   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-12-04 14:27   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-12-04 14:39   ` sashiko-bot
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 14:25   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-12-04 14:37   ` sashiko-bot
2026-12-04 18:44     ` Guenter Roeck
2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 18:45     ` Guenter Roeck
2026-12-04 20:13       ` Jarkko Sakkinen
2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox