* [PATCH v5 00/10] Apple Mac System Management Controller
@ 2025-05-11 8:18 Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block Sven Peter via B4 Relay
` (10 more replies)
0 siblings, 11 replies; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm, Krzysztof Kozlowski
Hi,
This series adds support for the System Management Controller found in
Apple Silicon devices which we model as a mfd. It also includes support
for the GPIO block and the power/reset block as sub-devices.
Changes between v4 and v5:
- Alyssa's comments:
- Made the WARN_ON in the reboot driver more obvious
- Added missing brackets around a for loop in the reboot driver
- Used min instead of open-coded variant inside the gpio driver
- Reoder struct memebers to prevent padding inside the mfd driver
- Lee's comments:
- All comments now start with an uppercase letter
- Removed apple_smc_read_ioft_scaled and apple_smc_read_f32_scaled
since these are not yet used and likely don't belong into
drivers/mfd
- Relaced if (ret != 0) with if (ret) when possible
- Used devm_platform_get_and_ioremap_resource to get and map the
SRAM resource
- Used reverse Christmas-tree formating when declaring variables
- Dropped _platform left-overs from probe and remove functions
- Removed dev_dbg prints which are no long required after
development
- Reworked is_alive/is_initialized so that it's obvious how errors
during boot are propagated from the callback to the probe function
- Used dev_warn instead of dev_err in a few places
- Removed no-op apple_smc_rtkit_shmem_destroy; this required an
additional change in rtkit.c because we had a check there that's a
bit too strict
- Removed struct resource in apple_smc_rtkit_shmem_setup and
open-coded resource_contains instead
- Unwrapped lines with less than 100 chars
- Made sure to compile with W=1 and ran scripts/kernel-doc -v
on macsmc.h once and fixed any fallout
- Removed first_key/last_key from struct smc and moved
apple_smc_find_first_key_index to the gpio driver since it's only
used there anyway to find the index of the first GPIO key (gP00)
- Return -EIO when a command fails instead of whatever SMC returns
which does not map to Linux errnos on errors
Changes between v3 and v4:
- Added documentation for all functions and structs
- Fixed dt-bindings and re-ordered commits so that the mfd one comes
last and can include the gpio subdevice
- Added the reset driver and corresponding bindings
- Reworked the atomic mode inside SMC since the previous implementation
called mutex_lock from atomic context
- Removed the backend split for now which lead to a quite intense discussion
for the previous versions which hadn't been solved as far as I could tell
from the old threads.
It's also been 2+ years and I haven't heard of any backend implementation
for T2 or even older macs. It's also unclear to me which sub-devices
are actually useful there because at least GPIO and shutdown/reboot
from this series will not work as-is there.
I'd rather have this initial version which only supports M1+ macs upstream
and then iterate there if any other backend is developed.
I'll gladly help to re-introduce backend support if it's ever required.
Dependencies:
The code and dt-bindings themselves apply cleanly to 6.15-rc1 but
the device tree changes require the already merged SPMI controller
and SPMI NVMEM series which will be part of 6.16.
The series is also using the printf format specifiers which will
land in 6.16 via the drm-misc tree.
A tree with all dependencies for testing is available at
https://github.com/AsahiLinux/linux/commits/sven/smc-v5/.
Merging:
The dt-binding patches all depend on each other such that they all
should probably go together with the mfd device itself.
The following commits also depend on mfd due to the new header file and
will either have to go through the mfd tree as well or we'll need an
immutable branch there or we just wait one kernel release and I'll
re-submit the rest then.
I'll take the device tree updates through our tree which also has the
previous device tree updates these depend on.
v4: https://lore.kernel.org/asahi/20250503-smc-6-15-v4-0-500b9b6546fc@svenpeter.dev/
v3: https://lore.kernel.org/asahi/Y2qEpgIdpRTzTQbN@shell.armlinux.org.uk/
v2: https://lore.kernel.org/asahi/YxdInl2qzQWM+3bs@shell.armlinux.org.uk/
v1: https://lore.kernel.org/asahi/YxC5eZjGgd8xguDr@shell.armlinux.org.uk/
Best,
Sven
---
Hector Martin (5):
gpio: Add new gpio-macsmc driver for Apple Macs
power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
arm64: dts: apple: t8103: Add SMC node
arm64: dts: apple: t8112: Add SMC node
arm64: dts: apple: t600x: Add SMC node
Russell King (Oracle) (2):
dt-bindings: gpio: Add Apple Mac SMC GPIO block
dt-bindings: mfd: Add Apple Mac System Management Controller
Sven Peter (3):
dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller
soc: apple: rtkit: Make shmem_destroy optional
mfd: Add Apple Silicon System Management Controller
.../devicetree/bindings/gpio/apple,smc-gpio.yaml | 37 ++
.../devicetree/bindings/mfd/apple,smc.yaml | 71 +++
.../bindings/power/reset/apple,smc-reboot.yaml | 52 +++
MAINTAINERS | 7 +
arch/arm64/boot/dts/apple/t600x-die0.dtsi | 35 ++
arch/arm64/boot/dts/apple/t8103.dtsi | 35 ++
arch/arm64/boot/dts/apple/t8112.dtsi | 35 ++
drivers/gpio/Kconfig | 10 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-macsmc.c | 293 ++++++++++++
drivers/mfd/Kconfig | 15 +
drivers/mfd/Makefile | 1 +
drivers/mfd/macsmc.c | 506 +++++++++++++++++++++
drivers/power/reset/Kconfig | 11 +
drivers/power/reset/Makefile | 1 +
drivers/power/reset/macsmc-reboot.c | 363 +++++++++++++++
drivers/soc/apple/rtkit.c | 3 +-
include/linux/mfd/macsmc.h | 277 +++++++++++
18 files changed, 1751 insertions(+), 2 deletions(-)
---
base-commit: 5abab6ab4ebacfff5857b63bd349902a6568d2e8
change-id: 20250304-smc-6-15-f0ed619e31d4
Best regards,
--
Sven Peter <sven@svenpeter.dev>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-14 20:55 ` Rob Herring (Arm)
2025-05-11 8:18 ` [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller Sven Peter via B4 Relay
` (9 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Add the DT binding for the Apple Mac System Management Controller GPIOs.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
.../devicetree/bindings/gpio/apple,smc-gpio.yaml | 37 ++++++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 38 insertions(+)
diff --git a/Documentation/devicetree/bindings/gpio/apple,smc-gpio.yaml b/Documentation/devicetree/bindings/gpio/apple,smc-gpio.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..07305eeb2595f59d5c28f6e507295b828dafd4a1
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/apple,smc-gpio.yaml
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/apple,smc-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple Mac System Management Controller GPIO
+
+maintainers:
+ - Sven Peter <sven@svenpeter.dev>
+
+description:
+ Apple Mac System Management Controller GPIO block.
+
+properties:
+ compatible:
+ const: apple,smc-gpio
+
+ gpio-controller: true
+
+ '#gpio-cells':
+ const: 2
+
+required:
+ - compatible
+ - gpio-controller
+ - '#gpio-cells'
+
+additionalProperties: false
+
+examples:
+ - |
+ gpio {
+ compatible = "apple,smc-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index 96b82704950184bd71623ff41fc4df31e4c7fe87..b53f3929b06006f9f38f5cda048516891c18c7ab 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2267,6 +2267,7 @@ F: Documentation/devicetree/bindings/arm/apple/*
F: Documentation/devicetree/bindings/clock/apple,nco.yaml
F: Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml
F: Documentation/devicetree/bindings/dma/apple,admac.yaml
+F: Documentation/devicetree/bindings/gpio/apple,smc-gpio.yaml
F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml
F: Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml
F: Documentation/devicetree/bindings/interrupt-controller/apple,*
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-14 20:56 ` Rob Herring
2025-05-11 8:18 ` [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller Sven Peter via B4 Relay
` (8 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Sven Peter <sven@svenpeter.dev>
On Apple Silicon machines a clean shutdown or reboot requires
talking to SMC and writing to NVMEM cells. Add a binding for
this MFD sub-device.
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
.../bindings/power/reset/apple,smc-reboot.yaml | 52 ++++++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 53 insertions(+)
diff --git a/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml b/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..e55e524914c2f57f7acf239fdefcbdc7a993b69f
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/reset/apple,smc-reboot.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple SMC Reboot Controller
+
+description: |
+ The Apple System Management Controller (SMC) provides reboot functionality
+ on Apple Silicon SoCs. It uses NVMEM cells to store and track various
+ system state information related to boot, shutdown, and panic events.
+
+maintainers:
+ - Sven Peter <sven@svenpeter.dev>
+
+properties:
+ compatible:
+ const: apple,smc-reboot
+
+ nvmem-cells:
+ items:
+ - description: Flag indicating shutdown (as opposed to reboot)
+ - description: Stage at which the boot process stopped (0x30 for normal boot)
+ - description: Counter for boot errors
+ - description: Counter for system panics
+ - description: Power management settings
+
+ nvmem-cell-names:
+ items:
+ - const: shutdown_flag
+ - const: boot_stage
+ - const: boot_error_count
+ - const: panic_count
+ - const: pm_setting
+
+required:
+ - compatible
+ - nvmem-cells
+ - nvmem-cell-names
+
+additionalProperties: false
+
+examples:
+ - |
+ reboot {
+ compatible = "apple,smc-reboot";
+ nvmem-cells = <&shutdown_flag>, <&boot_stage>,
+ <&boot_error_count>, <&panic_count>, <&pm_setting>;
+ nvmem-cell-names = "shutdown_flag", "boot_stage",
+ "boot_error_count", "panic_count", "pm_setting";
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index b53f3929b06006f9f38f5cda048516891c18c7ab..3f32d028ab49994a0da9f3882f37b9c3b183f5b4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2281,6 +2281,7 @@ F: Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
F: Documentation/devicetree/bindings/pci/apple,pcie.yaml
F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
F: Documentation/devicetree/bindings/power/apple*
+F: Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
F: Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml
F: Documentation/devicetree/bindings/spi/apple,spi.yaml
F: Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-14 20:55 ` Rob Herring
2025-05-11 8:18 ` [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional Sven Peter via B4 Relay
` (7 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm, Krzysztof Kozlowski
From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Add a DT binding for the Apple Mac System Management Controller.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
.../devicetree/bindings/mfd/apple,smc.yaml | 71 ++++++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 72 insertions(+)
diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..9f1058c15bbf62d84f8a72fdaa354909b02e2801
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/apple,smc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple Mac System Management Controller
+
+maintainers:
+ - Sven Peter <sven@svenpeter.dev>
+
+description:
+ Apple Mac System Management Controller implements various functions
+ such as GPIO, RTC, power, reboot.
+
+properties:
+ compatible:
+ items:
+ - enum:
+ - apple,t6000-smc
+ - apple,t8103-smc
+ - apple,t8112-smc
+ - const: apple,smc
+
+ reg:
+ items:
+ - description: SMC area
+ - description: SRAM area
+
+ reg-names:
+ items:
+ - const: smc
+ - const: sram
+
+ mboxes:
+ maxItems: 1
+
+ gpio:
+ $ref: /schemas/gpio/apple,smc-gpio.yaml
+
+ reboot:
+ $ref: /schemas/power/reset/apple,smc-reboot.yaml
+
+additionalProperties: false
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - mboxes
+
+examples:
+ - |
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ smc@23e400000 {
+ compatible = "apple,t8103-smc", "apple,smc";
+ reg = <0x2 0x3e400000 0x0 0x4000>,
+ <0x2 0x3fe00000 0x0 0x100000>;
+ reg-names = "smc", "sram";
+ mboxes = <&smc_mbox>;
+
+ smc_gpio: gpio {
+ compatible = "apple,smc-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+ };
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3f32d028ab49994a0da9f3882f37b9c3b183f5b4..27caedc40262ee9b9fdb6478f7624422517375a7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2275,6 +2275,7 @@ F: Documentation/devicetree/bindings/iommu/apple,dart.yaml
F: Documentation/devicetree/bindings/iommu/apple,sart.yaml
F: Documentation/devicetree/bindings/leds/backlight/apple,dwi-bl.yaml
F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
+F: Documentation/devicetree/bindings/mfd/apple,smc.yaml
F: Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml
F: Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
F: Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (2 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 16:42 ` Alyssa Rosenzweig
2025-05-11 8:18 ` [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller Sven Peter via B4 Relay
` (6 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Sven Peter <sven@svenpeter.dev>
shmem_destroy isn't always required for coprocessor-managed buffers but we
still enforce that it exists. Just relax the check.
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
drivers/soc/apple/rtkit.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
index 5fffd0f003dc2f4f377faf96cce0c1ce4ff0b788..b8d4da147d23f7e99e76eea314e4d976cddbd1c6 100644
--- a/drivers/soc/apple/rtkit.c
+++ b/drivers/soc/apple/rtkit.c
@@ -279,8 +279,7 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
dev_dbg(rtk->dev, "RTKit: buffer request for 0x%zx bytes at %pad\n",
buffer->size, &buffer->iova);
- if (buffer->iova &&
- (!rtk->ops->shmem_setup || !rtk->ops->shmem_destroy)) {
+ if (buffer->iova && !rtk->ops->shmem_setup) {
err = -EINVAL;
goto error;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (3 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 16:51 ` Alyssa Rosenzweig
2025-05-11 8:18 ` [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs Sven Peter via B4 Relay
` (5 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Sven Peter <sven@svenpeter.dev>
The System Management Controller (SMC) on Apple Silicon 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.
Some of the sub-devices are potentially also useful on pre-M1 Apple
machines and support for SMCs on these machines can be added at a later
time.
Co-developed-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
MAINTAINERS | 2 +
drivers/mfd/Kconfig | 15 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/macsmc.c | 506 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/macsmc.h | 277 +++++++++++++++++++++++++
5 files changed, 801 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 27caedc40262ee9b9fdb6478f7624422517375a7..dfaca531600c22d487fb17a25294686611dd4513 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2298,6 +2298,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/nvme/host/apple.c
F: drivers/nvmem/apple-efuses.c
F: drivers/pinctrl/pinctrl-apple-gpio.c
@@ -2308,6 +2309,7 @@ F: drivers/video/backlight/apple_dwi_bl.c
F: drivers/watchdog/apple_wdt.c
F: include/dt-bindings/interrupt-controller/apple-aic.h
F: include/dt-bindings/pinctrl/apple.h
+F: include/linux/mfd/macsmc.h
F: include/linux/soc/apple/*
ARM/ARTPEC MACHINE SUPPORT
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 22b93631003943c393d9fe704748bc23f1905397..da56fc4f05b7b7e0a521fcd97bee087424ec4d5b 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -285,6 +285,21 @@ config MFD_CS42L43_SDW
Select this to support the Cirrus Logic CS42L43 PC CODEC with
headphone and class D speaker drivers over SoundWire.
+config MFD_MACSMC
+ tristate "Apple Silicon System Management Controller (SMC)"
+ select MFD_CORE
+ help
+ The System Management Controller (SMC) on Apple Silicon 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 948cbdf42a18b22a826f0b17fb8d5796a7ec8ba6..e9e2403d961a631d9d63a274e0e4f6457ae9e0f2 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -21,6 +21,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_TI_LP873X) += lp873x.o
obj-$(CONFIG_MFD_TI_LP87565) += lp87565.o
diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
new file mode 100644
index 0000000000000000000000000000000000000000..908c0cc3d0b19a170d558f6c662998d5e3d7374c
--- /dev/null
+++ b/drivers/mfd/macsmc.c
@@ -0,0 +1,506 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC (System Management Controller) MFD driver
+ *
+ * Copyright The Asahi Linux Contributors
+ */
+
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#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>
+#include <linux/of_platform.h>
+#include <linux/overflow.h>
+#include <linux/platform_device.h>
+#include <linux/soc/apple/rtkit.h>
+#include <linux/unaligned.h>
+
+#define SMC_ENDPOINT 0x20
+
+/* We don't actually know the true size here but this seem reasonable */
+#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)
+#define SMC_ID GENMASK_ULL(15, 12)
+#define SMC_MSG GENMASK_ULL(7, 0)
+#define SMC_RESULT SMC_MSG
+
+#define SMC_TIMEOUT_MS 500
+
+static const struct mfd_cell apple_smc_devs[] = {
+ MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-gpio"),
+ MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),
+};
+
+static int apple_smc_cmd_locked(struct apple_smc *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)
+ return -EIO;
+
+ reinit_completion(&smc->cmd_done);
+
+ smc->msg_id = (smc->msg_id + 1) & 0xf;
+ msg = (FIELD_PREP(SMC_MSG, cmd) |
+ FIELD_PREP(SMC_SIZE, size) |
+ FIELD_PREP(SMC_WSIZE, wsize) |
+ FIELD_PREP(SMC_ID, smc->msg_id) |
+ FIELD_PREP(SMC_DATA, arg));
+
+ ret = apple_rtkit_send_message(smc->rtk, SMC_ENDPOINT, msg, NULL, false);
+ if (ret) {
+ dev_err(smc->dev, "Failed to send command\n");
+ return ret;
+ }
+
+ if (wait_for_completion_timeout(&smc->cmd_done, msecs_to_jiffies(SMC_TIMEOUT_MS)) <= 0) {
+ dev_err(smc->dev, "Command timed out (%llx)", msg);
+ return -ETIMEDOUT;
+ }
+
+ if (FIELD_GET(SMC_ID, smc->cmd_ret) != smc->msg_id) {
+ dev_err(smc->dev, "Command sequence mismatch (expected %d, got %d)\n",
+ smc->msg_id, (unsigned int)FIELD_GET(SMC_ID, smc->cmd_ret));
+ return -EIO;
+ }
+
+ result = FIELD_GET(SMC_RESULT, smc->cmd_ret);
+ if (result)
+ return -EIO;
+
+ if (ret_data)
+ *ret_data = FIELD_GET(SMC_DATA, smc->cmd_ret);
+
+ 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,
+ const void *wbuf, size_t wsize,
+ void *rbuf, size_t rsize)
+{
+ u64 smc_size, smc_wsize;
+ u32 rdata;
+ int ret;
+ u64 cmd;
+
+ lockdep_assert_held(&smc->mutex);
+
+ if (rsize > SMC_MAX_SIZE)
+ return -EINVAL;
+ if (wsize > SMC_MAX_SIZE)
+ return -EINVAL;
+
+ if (rsize && wsize) {
+ cmd = SMC_MSG_RW_KEY;
+ memcpy_toio(smc->shmem.iomem, wbuf, wsize);
+ smc_size = rsize;
+ smc_wsize = wsize;
+ } else if (wsize && !rsize) {
+ cmd = SMC_MSG_WRITE_KEY;
+ memcpy_toio(smc->shmem.iomem, wbuf, wsize);
+ /*
+ * Setting size to the length we want to write and wsize to 0
+ * looks silly but that's how the SMC protocol works ¯\_(ツ)_/¯
+ */
+ smc_size = wsize;
+ smc_wsize = 0;
+ } else if (!wsize && rsize) {
+ cmd = SMC_MSG_READ_KEY;
+ smc_size = rsize;
+ smc_wsize = 0;
+ } else {
+ return -EINVAL;
+ }
+
+ ret = apple_smc_cmd_locked(smc, cmd, key, smc_size, smc_wsize, &rdata);
+ if (ret < 0)
+ return ret;
+
+ if (rsize) {
+ /*
+ * Small data <= 4 bytes is returned as part of the reply
+ * message which is sent over the mailbox FIFO. Everything
+ * bigger has to be copied from SRAM which is mapped as
+ * Device memory.
+ */
+ if (rsize <= 4)
+ memcpy(rbuf, &rdata, rsize);
+ else
+ memcpy_fromio(rbuf, smc->shmem.iomem, rsize);
+ }
+
+ return ret;
+}
+
+int apple_smc_read(struct apple_smc *smc, smc_key key, void *buf, size_t size)
+{
+ guard(mutex)(&smc->mutex);
+
+ return apple_smc_rw_locked(smc, key, NULL, 0, buf, size);
+}
+EXPORT_SYMBOL(apple_smc_read);
+
+int apple_smc_write(struct apple_smc *smc, smc_key key, void *buf, size_t size)
+{
+ guard(mutex)(&smc->mutex);
+
+ return apple_smc_rw_locked(smc, key, buf, size, NULL, 0);
+}
+EXPORT_SYMBOL(apple_smc_write);
+
+int apple_smc_rw(struct apple_smc *smc, smc_key key, void *wbuf, size_t wsize,
+ void *rbuf, size_t rsize)
+{
+ guard(mutex)(&smc->mutex);
+
+ return apple_smc_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)
+{
+ int ret;
+
+ ret = apple_smc_cmd(smc, SMC_MSG_GET_KEY_BY_INDEX, index, 0, 0, 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)
+{
+ u8 key_info[6];
+ int ret;
+
+ ret = apple_smc_cmd(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];
+ info->type_code = get_unaligned_be32(&key_info[1]);
+ info->flags = key_info[5];
+ }
+ return ret;
+}
+EXPORT_SYMBOL(apple_smc_get_key_info);
+
+int apple_smc_enter_atomic(struct apple_smc *smc)
+{
+ guard(mutex)(&smc->mutex);
+
+ /*
+ * Disable notifications since this is called before shutdown and no
+ * notification handler will be able to handle the notification
+ * using atomic operations only. Also ignore any failure here
+ * because we're about to shut down or reboot anyway.
+ * We can't use apple_smc_write_flag here since that would try to lock
+ * smc->mutex again.
+ */
+ const u8 flag = 0;
+
+ apple_smc_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, void *buf, size_t size)
+{
+ guard(spinlock_irqsave)(&smc->lock);
+ u8 result;
+ int ret;
+ u64 msg;
+
+ if (size > SMC_MAX_SIZE || size == 0)
+ return -EINVAL;
+
+ if (smc->boot_stage != APPLE_SMC_INITIALIZED)
+ return -EIO;
+ if (!smc->atomic_mode)
+ return -EIO;
+
+ memcpy_toio(smc->shmem.iomem, buf, size);
+ smc->msg_id = (smc->msg_id + 1) & 0xf;
+ msg = (FIELD_PREP(SMC_MSG, SMC_MSG_WRITE_KEY) |
+ FIELD_PREP(SMC_SIZE, size) |
+ FIELD_PREP(SMC_ID, smc->msg_id) |
+ FIELD_PREP(SMC_DATA, key));
+ smc->atomic_pending = true;
+
+ ret = apple_rtkit_send_message(smc->rtk, SMC_ENDPOINT, msg, NULL, true);
+ if (ret < 0) {
+ dev_err(smc->dev, "Failed to send command (%d)\n", ret);
+ return ret;
+ }
+
+ while (smc->atomic_pending) {
+ ret = apple_rtkit_poll(smc->rtk);
+ if (ret < 0) {
+ dev_err(smc->dev, "RTKit poll failed (%llx)", msg);
+ return ret;
+ }
+ udelay(100);
+ }
+
+ if (FIELD_GET(SMC_ID, smc->cmd_ret) != smc->msg_id) {
+ dev_err(smc->dev, "Command sequence mismatch (expected %d, got %d)\n",
+ smc->msg_id, (unsigned int)FIELD_GET(SMC_ID, smc->cmd_ret));
+ return -EIO;
+ }
+
+ result = FIELD_GET(SMC_RESULT, smc->cmd_ret);
+ if (result)
+ return -EIO;
+
+ return FIELD_GET(SMC_SIZE, smc->cmd_ret);
+}
+EXPORT_SYMBOL(apple_smc_write_atomic);
+
+static void apple_smc_rtkit_crashed(void *cookie, const void *bfr, size_t bfr_len)
+{
+ struct apple_smc *smc = cookie;
+
+ smc->boot_stage = APPLE_SMC_ERROR_CRASHED;
+ dev_err(smc->dev, "SMC crashed! Your system will reboot in a few seconds...\n");
+}
+
+static int apple_smc_rtkit_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
+{
+ struct apple_smc *smc = cookie;
+ size_t bfr_end;
+
+ if (!bfr->iova) {
+ dev_err(smc->dev, "RTKit wants a RAM buffer\n");
+ return -EIO;
+ }
+
+ if (check_add_overflow(bfr->iova, bfr->size - 1, &bfr_end))
+ return -EFAULT;
+
+ if (bfr->iova < smc->sram->start || bfr->iova > smc->sram->end ||
+ bfr_end > smc->sram->end) {
+ dev_err(smc->dev, "RTKit buffer request outside SRAM region: [0x%llx, 0x%llx]\n",
+ (unsigned long long)bfr->iova,
+ (unsigned long long)bfr_end);
+ return -EFAULT;
+ }
+
+ bfr->iomem = smc->sram_base + (bfr->iova - smc->sram->start);
+ bfr->is_mapped = true;
+
+ return 0;
+}
+
+static bool apple_smc_rtkit_recv_early(void *cookie, u8 endpoint, u64 message)
+{
+ struct apple_smc *smc = cookie;
+
+ if (endpoint != SMC_ENDPOINT) {
+ dev_warn(smc->dev, "Received message for unknown endpoint 0x%x\n", endpoint);
+ return false;
+ }
+
+ if (smc->boot_stage == APPLE_SMC_BOOTING) {
+ int ret;
+
+ smc->shmem.iova = message;
+ smc->shmem.size = SMC_SHMEM_SIZE;
+ ret = apple_smc_rtkit_shmem_setup(smc, &smc->shmem);
+ if (ret < 0) {
+ smc->boot_stage = APPLE_SMC_ERROR_NO_SHMEM;
+ dev_err(smc->dev, "Failed to initialize shared memory (%d)\n", ret);
+ } else {
+ smc->boot_stage = APPLE_SMC_INITIALIZED;
+ }
+ complete(&smc->init_done);
+ } else if (FIELD_GET(SMC_MSG, message) == SMC_MSG_NOTIFICATION) {
+ /* Handle these in the RTKit worker thread */
+ return false;
+ } else {
+ smc->cmd_ret = message;
+ if (smc->atomic_pending)
+ smc->atomic_pending = false;
+ else
+ complete(&smc->cmd_done);
+ }
+
+ return true;
+}
+
+static void apple_smc_rtkit_recv(void *cookie, u8 endpoint, u64 message)
+{
+ struct apple_smc *smc = cookie;
+
+ if (endpoint != SMC_ENDPOINT) {
+ dev_warn(smc->dev, "Received message for unknown endpoint 0x%x\n", endpoint);
+ return;
+ }
+
+ if (FIELD_GET(SMC_MSG, message) != SMC_MSG_NOTIFICATION) {
+ dev_warn(smc->dev, "Received unknown message from worker: 0x%llx\n", message);
+ return;
+ }
+
+ blocking_notifier_call_chain(&smc->event_handlers, FIELD_GET(SMC_DATA, message), NULL);
+}
+
+static const struct apple_rtkit_ops apple_smc_rtkit_ops = {
+ .crashed = apple_smc_rtkit_crashed,
+ .recv_message = apple_smc_rtkit_recv,
+ .recv_message_early = apple_smc_rtkit_recv_early,
+ .shmem_setup = apple_smc_rtkit_shmem_setup,
+};
+
+static int apple_smc_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct apple_smc *smc;
+ u32 count;
+ int ret;
+
+ smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
+ if (!smc)
+ return -ENOMEM;
+
+ smc->dev = &pdev->dev;
+ smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram);
+ if (IS_ERR(smc->sram_base))
+ return dev_err_probe(dev, PTR_ERR(smc->sram_base), "Failed to map SRAM region");
+
+ smc->rtk = devm_apple_rtkit_init(dev, smc, NULL, 0, &apple_smc_rtkit_ops);
+ if (IS_ERR(smc->rtk))
+ return dev_err_probe(dev, PTR_ERR(smc->rtk), "Failed to initialize RTKit");
+
+ smc->boot_stage = APPLE_SMC_BOOTING;
+ ret = apple_rtkit_wake(smc->rtk);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to wake up SMC");
+
+ ret = apple_rtkit_start_ep(smc->rtk, SMC_ENDPOINT);
+ if (ret) {
+ ret = dev_err_probe(dev, ret, "Failed to start SMC endpoint");
+ goto cleanup;
+ }
+
+ init_completion(&smc->init_done);
+ init_completion(&smc->cmd_done);
+
+ ret = apple_rtkit_send_message(smc->rtk, SMC_ENDPOINT,
+ FIELD_PREP(SMC_MSG, SMC_MSG_INITIALIZE), NULL, false);
+ if (ret) {
+ ret = dev_err_probe(dev, ret, "Failed to send init message");
+ goto cleanup;
+ }
+
+ if (wait_for_completion_timeout(&smc->init_done, msecs_to_jiffies(SMC_TIMEOUT_MS)) == 0) {
+ ret = -ETIMEDOUT;
+ dev_err(dev, "Timed out initializing SMC");
+ goto cleanup;
+ }
+
+ if (smc->boot_stage != APPLE_SMC_INITIALIZED) {
+ ret = -EIO;
+ dev_err(dev, "SMC failed to boot successfully, boot stage=%d\n", smc->boot_stage);
+ goto cleanup;
+ }
+
+ dev_set_drvdata(&pdev->dev, smc);
+ BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
+
+ ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
+ if (ret) {
+ ret = dev_err_probe(smc->dev, ret, "Failed to get key count");
+ goto cleanup;
+ }
+ smc->key_count = be32_to_cpu(count);
+
+ /* Enable notifications */
+ apple_smc_write_flag(smc, SMC_KEY(NTAP), true);
+
+ ret = mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE,
+ apple_smc_devs, ARRAY_SIZE(apple_smc_devs),
+ NULL, 0, NULL);
+ if (ret) {
+ ret = dev_err_probe(smc->dev, ret, "Failed to register sub-devices");
+ goto cleanup;
+ }
+
+ return 0;
+
+cleanup:
+ /* Try to shut down RTKit, if it's not completely wedged */
+ if (apple_rtkit_is_running(smc->rtk))
+ apple_rtkit_quiesce(smc->rtk);
+
+ return ret;
+}
+
+static void apple_smc_remove(struct platform_device *pdev)
+{
+ struct apple_smc *smc = platform_get_drvdata(pdev);
+
+ mfd_remove_devices(smc->dev);
+
+ /* Disable notifications */
+ apple_smc_write_flag(smc, SMC_KEY(NTAP), false);
+
+ /* Shut down SMC firmware */
+ if (apple_rtkit_is_running(smc->rtk))
+ apple_rtkit_quiesce(smc->rtk);
+}
+
+static const struct of_device_id apple_smc_of_match[] = {
+ { .compatible = "apple,smc" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, apple_smc_of_match);
+
+static struct platform_driver apple_smc_driver = {
+ .driver = {
+ .name = "mfd-macsmc",
+ .of_match_table = apple_smc_of_match,
+ },
+ .probe = apple_smc_probe,
+ .remove = apple_smc_remove,
+};
+module_platform_driver(apple_smc_driver);
+
+MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
+MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC driver");
diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h
new file mode 100644
index 0000000000000000000000000000000000000000..19b6f14eb2f5dab0f1e03f679dad769716f7a0ff
--- /dev/null
+++ b/include/linux/mfd/macsmc.h
@@ -0,0 +1,277 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * Apple SMC (System Management Controller) core definitions
+ *
+ * Copyright (C) The Asahi Linux Contributors
+ */
+
+#ifndef _LINUX_MFD_MACSMC_H
+#define _LINUX_MFD_MACSMC_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 APPLE_SMC_READABLE BIT(7)
+#define APPLE_SMC_WRITABLE BIT(6)
+#define APPLE_SMC_FUNCTION BIT(4)
+
+/**
+ * struct apple_smc_key_info - information for a SMC key as returned by SMC
+ * @size: size of the buffer associated with this key
+ * @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
+ * @flags: bitfield encoding flags (APPLE_SMC_{READABLE,WRITABLE,FUNCTION})
+ */
+struct apple_smc_key_info {
+ u8 size;
+ u32 type_code;
+ u8 flags;
+};
+
+/**
+ * enum apple_smc_boot_stage - SMC boot stage
+ * @APPLE_SMC_BOOTING: SMC is booting
+ * @APPLE_SMC_INITIALIZED: SMC is initialized and ready to use
+ * @APPLE_SMC_ERROR_NO_SHMEM: shared memory could not be initialized during boot
+ * @APPLE_SMC_ERROR_CRASHED: SMC has crashed
+ */
+enum apple_smc_boot_stage {
+ APPLE_SMC_BOOTING,
+ APPLE_SMC_INITIALIZED,
+ APPLE_SMC_ERROR_NO_SHMEM,
+ APPLE_SMC_ERROR_CRASHED
+};
+
+/**
+ * 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
+ * @mutex: mutex for non-atomic mode
+ * @lock: spinlock for atomic mode
+ */
+struct apple_smc {
+ struct device *dev;
+
+ u32 key_count;
+ smc_key first_key;
+ smc_key last_key;
+
+ 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;
+
+ struct mutex mutex;
+ spinlock_t lock;
+};
+
+/**
+ * apple_smc_read - read size bytes from given SMC key into buf
+ * @smc: pointer to apple_smc struct
+ * @key: smc_key to be read
+ * @buf: buffer into which size bytes of data will be read from SMC
+ * @size: number of bytes to be read into buf
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_read(struct apple_smc *smc, smc_key key, void *buf, size_t size);
+
+/**
+ * apple_smc_write - write size bytes into given SMC key from buf
+ * @smc: pointer to apple_smc struct
+ * @key: smc_key data will be written to
+ * @buf: buffer from which size bytes of data will be written to SMC
+ * @size: number of bytes to be written
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_write(struct apple_smc *smc, smc_key key, void *buf, size_t size);
+
+/**
+ * apple_smc_enter_atomic - enter atomic mode to be able to use apple_smc_write_atomic
+ * @smc: pointer to apple_smc struct
+ *
+ * This function switches the SMC backend to atomic mode which allows the
+ * use of apple_smc_write_atomic while disabling *all* other functions.
+ * This is only used for shutdown/reboot which requires writing to a SMC
+ * key from atomic context.
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_enter_atomic(struct apple_smc *smc);
+
+/**
+ * apple_smc_write_atomic - write size bytes into given SMC key from buf without sleeping
+ * @smc: pointer to apple_smc struct
+ * @key: smc_key data will be written to
+ * @buf: buffer from which size bytes of data will be written to SMC
+ * @size: number of bytes to be written
+ *
+ * Note that this function will fail if apple_smc_enter_atomic hasn't been
+ * called before.
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_write_atomic(struct apple_smc *smc, smc_key key, void *buf, size_t size);
+
+/**
+ * apple_smc_rw - write and then read using the given SMC key
+ * @smc: pointer to apple_smc struct
+ * @key: smc_key data will be written to
+ * @wbuf: buffer from which size bytes of data will be written to SMC
+ * @wsize: number of bytes to be written
+ * @rbuf: buffer to which size bytes of data will be read from SMC
+ * @rsize: number of bytes to be read
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_rw(struct apple_smc *smc, smc_key key, void *wbuf, size_t wsize,
+ void *rbuf, size_t rsize);
+
+/**
+ * apple_smc_get_key_by_index - given an index return the corresponding SMC key
+ * @smc: pointer to apple_smc struct
+ * @index: index to be resolved
+ * @key: buffer for SMC key to be returned
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_get_key_by_index(struct apple_smc *smc, int index, smc_key *key);
+
+/**
+ * apple_smc_get_key_info - get key information from SMC
+ * @smc: pointer to apple_smc struct
+ * @key: key to acquire information for
+ * @info: pointer to struct apple_smc_key_info which will be filled
+ *
+ * Return: Zero on success, negative errno on error
+ */
+int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_key_info *info);
+
+/**
+ * apple_smc_key_exists - check if the given SMC key exists
+ * @smc: pointer to apple_smc struct
+ * @key: smc_key to be checked
+ */
+static inline bool apple_smc_key_exists(struct apple_smc *smc, smc_key key)
+{
+ return apple_smc_get_key_info(smc, key, NULL) >= 0;
+}
+
+#define APPLE_SMC_TYPE_OPS(type) \
+ static inline int apple_smc_read_##type(struct apple_smc *smc, smc_key key, type *p) \
+ { \
+ int ret = apple_smc_read(smc, key, p, sizeof(*p)); \
+ return (ret < 0) ? ret : ((ret != sizeof(*p)) ? -EINVAL : 0); \
+ } \
+ static inline int apple_smc_write_##type(struct apple_smc *smc, smc_key key, type p) \
+ { \
+ return apple_smc_write(smc, key, &p, sizeof(p)); \
+ } \
+ static inline int apple_smc_write_##type##_atomic(struct apple_smc *smc, smc_key key, type p) \
+ { \
+ return apple_smc_write_atomic(smc, key, &p, sizeof(p)); \
+ } \
+ static inline int apple_smc_rw_##type(struct apple_smc *smc, smc_key key, \
+ type w, type *r) \
+ { \
+ int ret = apple_smc_rw(smc, key, &w, sizeof(w), r, sizeof(*r)); \
+ return (ret < 0) ? ret : ((ret != sizeof(*r)) ? -EINVAL : 0); \
+ }
+
+APPLE_SMC_TYPE_OPS(u64)
+APPLE_SMC_TYPE_OPS(u32)
+APPLE_SMC_TYPE_OPS(u16)
+APPLE_SMC_TYPE_OPS(u8)
+APPLE_SMC_TYPE_OPS(s64)
+APPLE_SMC_TYPE_OPS(s32)
+APPLE_SMC_TYPE_OPS(s16)
+APPLE_SMC_TYPE_OPS(s8)
+
+static inline int apple_smc_read_flag(struct apple_smc *smc, smc_key key, bool *flag)
+{
+ u8 val;
+ int ret = apple_smc_read_u8(smc, key, &val);
+
+ if (ret < 0)
+ return ret;
+
+ *flag = val ? true : false;
+ return ret;
+}
+
+static inline int apple_smc_write_flag(struct apple_smc *smc, smc_key key, bool state)
+{
+ return apple_smc_write_u8(smc, key, state ? 1 : 0);
+}
+
+static inline int apple_smc_write_flag_atomic(struct apple_smc *smc, smc_key key, bool state)
+{
+ return apple_smc_write_u8_atomic(smc, key, state ? 1 : 0);
+}
+
+#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (4 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 16:45 ` Alyssa Rosenzweig
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
` (4 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Hector Martin <marcan@marcan.st>
This driver implements the GPIO service on top of the SMC framework
on Apple Mac machines. In particular, these are the GPIOs present in the
PMU IC which are used to control power to certain on-board devices.
Although the underlying hardware supports various pin config settings
(input/output, open drain, etc.), this driver does not implement that
functionality and leaves it up to the firmware to configure things
properly. We also don't yet support interrupts/events. This is
sufficient for device power control, which is the only thing we need to
support at this point. More features will be implemented when needed.
To our knowledge, only Apple Silicon Macs implement this SMC feature.
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
MAINTAINERS | 1 +
drivers/gpio/Kconfig | 10 ++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-macsmc.c | 293 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 305 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index dfaca531600c22d487fb17a25294686611dd4513..fa3a5f9ee40446bcc725c9eac2a36651e6bc7553 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2291,6 +2291,7 @@ F: drivers/bluetooth/hci_bcm4377.c
F: drivers/clk/clk-apple-nco.c
F: drivers/cpufreq/apple-soc-cpufreq.c
F: drivers/dma/apple-admac.c
+F: drivers/gpio/gpio-macsmc.c
F: drivers/pmdomain/apple/
F: drivers/i2c/busses/i2c-pasemi-core.c
F: drivers/i2c/busses/i2c-pasemi-platform.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index f2c39bbff83a33dcb12b2d32aa3ebc358a0dd949..f0e25105f8ebe7356344722987333a9fc244ea1f 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1440,6 +1440,16 @@ config GPIO_LP87565
This driver can also be built as a module. If so, the module will be
called gpio-lp87565.
+config GPIO_MACSMC
+ tristate "Apple Mac SMC GPIO"
+ depends on MFD_MACSMC
+ help
+ Support for GPIOs controlled by the SMC microcontroller on Apple Mac
+ systems.
+
+ This driver can also be built as a module. If so, the module will be
+ called gpio-macsmc.
+
config GPIO_MADERA
tristate "Cirrus Logic Madera class codecs"
depends on PINCTRL_MADERA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index af130882ffeeef8b1d518867bfe1493ec4f21b5f..c2e47f356bfae73384ace8103074f246e49fb9d6 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -97,6 +97,7 @@ obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o
obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o
obj-$(CONFIG_GPIO_LPC18XX) += gpio-lpc18xx.o
obj-$(CONFIG_GPIO_LPC32XX) += gpio-lpc32xx.o
+obj-$(CONFIG_GPIO_MACSMC) += gpio-macsmc.o
obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o
obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o
obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o
diff --git a/drivers/gpio/gpio-macsmc.c b/drivers/gpio/gpio-macsmc.c
new file mode 100644
index 0000000000000000000000000000000000000000..bb179c71a05e294c9ec68db332ad4c0dff118d1a
--- /dev/null
+++ b/drivers/gpio/gpio-macsmc.c
@@ -0,0 +1,293 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC GPIO driver
+ * Copyright The Asahi Linux Contributors
+ *
+ * This driver implements basic SMC PMU GPIO support that can read inputs
+ * and write outputs. Mode changes and IRQ config are not yet implemented.
+ */
+
+#include <linux/bitmap.h>
+#include <linux/device.h>
+#include <linux/gpio/driver.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/macsmc.h>
+
+#define MAX_GPIO 64
+
+/*
+ * Commands 0-6 are, presumably, the intended API.
+ * Command 0xff lets you get/set the pin configuration in detail directly,
+ * but the bit meanings seem not to be stable between devices/PMU hardware
+ * versions.
+ *
+ * We're going to try to make do with the low commands for now.
+ * We don't implement pin mode changes at this time.
+ */
+
+#define CMD_ACTION (0 << 24)
+#define CMD_OUTPUT (1 << 24)
+#define CMD_INPUT (2 << 24)
+#define CMD_PINMODE (3 << 24)
+#define CMD_IRQ_ENABLE (4 << 24)
+#define CMD_IRQ_ACK (5 << 24)
+#define CMD_IRQ_MODE (6 << 24)
+#define CMD_CONFIG (0xff << 24)
+
+#define MODE_INPUT 0
+#define MODE_OUTPUT 1
+#define MODE_VALUE_0 0
+#define MODE_VALUE_1 2
+
+#define IRQ_MODE_HIGH 0
+#define IRQ_MODE_LOW 1
+#define IRQ_MODE_RISING 2
+#define IRQ_MODE_FALLING 3
+#define IRQ_MODE_BOTH 4
+
+#define CONFIG_MASK GENMASK(23, 16)
+#define CONFIG_VAL GENMASK(7, 0)
+
+#define CONFIG_OUTMODE GENMASK(7, 6)
+#define CONFIG_IRQMODE GENMASK(5, 3)
+#define CONFIG_PULLDOWN BIT(2)
+#define CONFIG_PULLUP BIT(1)
+#define CONFIG_OUTVAL BIT(0)
+
+/*
+ * Output modes seem to differ depending on the PMU in use... ?
+ * j274 / M1 (Sera PMU):
+ * 0 = input
+ * 1 = output
+ * 2 = open drain
+ * 3 = disable
+ * j314 / M1Pro (Maverick PMU):
+ * 0 = input
+ * 1 = open drain
+ * 2 = output
+ * 3 = ?
+ */
+
+struct macsmc_gpio {
+ struct device *dev;
+ struct apple_smc *smc;
+ struct gpio_chip gc;
+
+ int first_index;
+};
+
+static int macsmc_gpio_nr(smc_key key)
+{
+ int low = hex_to_bin(key & 0xff);
+ int high = hex_to_bin((key >> 8) & 0xff);
+
+ if (low < 0 || high < 0)
+ return -1;
+
+ return low | (high << 4);
+}
+
+static int macsmc_gpio_key(unsigned int offset)
+{
+ return _SMC_KEY("gP\0\0") | hex_asc_hi(offset) << 8 | hex_asc_lo(offset);
+}
+
+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)
+ return -ENODEV;
+
+ /* Binary search to find index of first SMC key bigger or equal to key */
+ start = 0;
+ count = smc->key_count;
+ while (count > 1) {
+ smc_key pkey;
+ int pivot = start + ((count - 1) >> 1);
+
+ ret = apple_smc_get_key_by_index(smc, pivot, &pkey);
+ if (ret < 0)
+ return ret;
+
+ if (pkey == key)
+ return pivot;
+
+ pivot++;
+
+ if (pkey < key) {
+ count -= pivot - start;
+ start = pivot;
+ } else {
+ count = pivot - start;
+ }
+ }
+
+ return start;
+}
+
+static int macsmc_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+ struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
+ smc_key key = macsmc_gpio_key(offset);
+ u32 val;
+ int ret;
+
+ /* First try reading the explicit pin mode register */
+ ret = apple_smc_rw_u32(smcgp->smc, key, CMD_PINMODE, &val);
+ if (!ret)
+ return (val & MODE_OUTPUT) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+
+ /*
+ * Less common IRQ configs cause CMD_PINMODE to fail, and so does open drain mode.
+ * Fall back to reading IRQ mode, which will only succeed for inputs.
+ */
+ ret = apple_smc_rw_u32(smcgp->smc, key, CMD_IRQ_MODE, &val);
+ return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
+static int macsmc_gpio_get(struct gpio_chip *gc, unsigned int offset)
+{
+ struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
+ smc_key key = macsmc_gpio_key(offset);
+ u32 cmd, val;
+ int ret;
+
+ ret = macsmc_gpio_get_direction(gc, offset);
+ if (ret < 0)
+ return ret;
+
+ if (ret == GPIO_LINE_DIRECTION_OUT)
+ cmd = CMD_OUTPUT;
+ else
+ cmd = CMD_INPUT;
+
+ ret = apple_smc_rw_u32(smcgp->smc, key, cmd, &val);
+ if (ret < 0)
+ return ret;
+
+ return val ? 1 : 0;
+}
+
+static int macsmc_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
+{
+ struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
+ smc_key key = macsmc_gpio_key(offset);
+ int ret;
+
+ value |= CMD_OUTPUT;
+ ret = apple_smc_write_u32(smcgp->smc, key, CMD_OUTPUT | value);
+ if (ret < 0)
+ dev_err(smcgp->dev, "GPIO set failed %p4ch = 0x%x\n",
+ &key, value);
+
+ return ret;
+}
+
+static int macsmc_gpio_init_valid_mask(struct gpio_chip *gc,
+ unsigned long *valid_mask, unsigned int ngpios)
+{
+ struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
+ int count;
+ int i;
+
+ count = min(smcgp->smc->key_count, MAX_GPIO);
+
+ bitmap_zero(valid_mask, ngpios);
+
+ for (i = 0; i < count; i++) {
+ int ret, gpio_nr;
+ smc_key key;
+
+ ret = apple_smc_get_key_by_index(smcgp->smc, smcgp->first_index + i, &key);
+ if (ret < 0)
+ return ret;
+
+ if (key > SMC_KEY(gPff))
+ break;
+
+ gpio_nr = macsmc_gpio_nr(key);
+ if (gpio_nr < 0 || gpio_nr > MAX_GPIO) {
+ dev_err(smcgp->dev, "Bad GPIO key %p4ch\n", &key);
+ continue;
+ }
+
+ set_bit(gpio_nr, valid_mask);
+ }
+
+ return 0;
+}
+
+static int macsmc_gpio_probe(struct platform_device *pdev)
+{
+ struct macsmc_gpio *smcgp;
+ struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
+ smc_key key;
+ int ret;
+
+ smcgp = devm_kzalloc(&pdev->dev, sizeof(*smcgp), GFP_KERNEL);
+ if (!smcgp)
+ return -ENOMEM;
+
+ smcgp->dev = &pdev->dev;
+ smcgp->smc = smc;
+
+ smcgp->first_index = macsmc_gpio_find_first_gpio_index(smcgp);
+ if (smcgp->first_index < 0)
+ return smcgp->first_index;
+
+ ret = apple_smc_get_key_by_index(smc, smcgp->first_index, &key);
+ if (ret < 0)
+ return ret;
+
+ if (key > macsmc_gpio_key(MAX_GPIO - 1))
+ return -ENODEV;
+
+ dev_info(smcgp->dev, "First GPIO key: %p4ch\n", &key);
+
+ smcgp->gc.label = "macsmc-pmu-gpio";
+ smcgp->gc.owner = THIS_MODULE;
+ smcgp->gc.get = macsmc_gpio_get;
+ smcgp->gc.set_rv = macsmc_gpio_set;
+ smcgp->gc.get_direction = macsmc_gpio_get_direction;
+ smcgp->gc.init_valid_mask = macsmc_gpio_init_valid_mask;
+ smcgp->gc.can_sleep = true;
+ smcgp->gc.ngpio = MAX_GPIO;
+ smcgp->gc.base = -1;
+ smcgp->gc.parent = &pdev->dev;
+
+ return devm_gpiochip_add_data(&pdev->dev, &smcgp->gc, smcgp);
+}
+
+static const struct of_device_id macsmc_gpio_of_table[] = {
+ { .compatible = "apple,smc-gpio", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, macsmc_gpio_of_table);
+
+static struct platform_driver macsmc_gpio_driver = {
+ .driver = {
+ .name = "macsmc-gpio",
+ .of_match_table = macsmc_gpio_of_table,
+ },
+ .probe = macsmc_gpio_probe,
+};
+module_platform_driver(macsmc_gpio_driver);
+
+MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC GPIO driver");
+MODULE_ALIAS("platform:macsmc-gpio");
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (5 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 10:07 ` Stefan Wahren
` (2 more replies)
2025-05-11 8:18 ` [PATCH v5 08/10] arm64: dts: apple: t8103: Add SMC node Sven Peter via B4 Relay
` (3 subsequent siblings)
10 siblings, 3 replies; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Hector Martin <marcan@marcan.st>
This driver implements the reboot/shutdown support exposed by the SMC
on Apple Silicon machines, such as Apple M1 Macs.
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
MAINTAINERS | 1 +
drivers/power/reset/Kconfig | 11 ++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/macsmc-reboot.c | 363 ++++++++++++++++++++++++++++++++++++
4 files changed, 376 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index fa3a5f9ee40446bcc725c9eac2a36651e6bc7553..84f7a730eb2260b7c1e0487d18c8eb3de82f5206 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2303,6 +2303,7 @@ F: drivers/mfd/macsmc.c
F: drivers/nvme/host/apple.c
F: drivers/nvmem/apple-efuses.c
F: drivers/pinctrl/pinctrl-apple-gpio.c
+F: drivers/power/reset/macsmc-reboot.c
F: drivers/pwm/pwm-apple.c
F: drivers/soc/apple/*
F: drivers/spi/spi-apple.c
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 60bf0ca64cf395cd18238fc626611c74d29844ee..6e8dfff64fdc001d09b6c00630cd8b7e2fafdd8e 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -128,6 +128,17 @@ config POWER_RESET_LINKSTATION
Say Y here if you have a Buffalo LinkStation LS421D/E.
+config POWER_RESET_MACSMC
+ tristate "Apple SMC reset/power-off driver"
+ depends on ARCH_APPLE || COMPILE_TEST
+ depends on MFD_MACSMC
+ depends on OF
+ help
+ This driver supports reset and power-off on Apple Mac machines
+ that implement this functionality via the SMC.
+
+ Say Y here if you have an Apple Silicon Mac.
+
config POWER_RESET_MSM
bool "Qualcomm MSM power-off driver"
depends on ARCH_QCOM
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 10782d32e1da39f4b8b4566e8a885f2e13f65130..887dd9e49b7293b69b9429ddc0c1571194a153cf 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
obj-$(CONFIG_POWER_RESET_LINKSTATION) += linkstation-poweroff.o
+obj-$(CONFIG_POWER_RESET_MACSMC) += macsmc-reboot.o
obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c
new file mode 100644
index 0000000000000000000000000000000000000000..d82339e427886667be4ad2de0d1d5c04d2383059
--- /dev/null
+++ b/drivers/power/reset/macsmc-reboot.c
@@ -0,0 +1,363 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC Reboot/Poweroff Handler
+ * Copyright The Asahi Linux Contributors
+ */
+
+#include <linux/delay.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/slab.h>
+
+struct macsmc_reboot_nvmem {
+ struct nvmem_cell *shutdown_flag;
+ struct nvmem_cell *pm_setting;
+ struct nvmem_cell *boot_stage;
+ struct nvmem_cell *boot_error_count;
+ struct nvmem_cell *panic_count;
+};
+
+static const char * const nvmem_names[] = {
+ "shutdown_flag",
+ "pm_setting",
+ "boot_stage",
+ "boot_error_count",
+ "panic_count",
+};
+
+enum boot_stage {
+ BOOT_STAGE_SHUTDOWN = 0x00, /* Clean shutdown */
+ BOOT_STAGE_IBOOT_DONE = 0x2f, /* Last stage of bootloader */
+ BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */
+};
+
+enum pm_setting {
+ PM_SETTING_AC_POWER_RESTORE = 0x02,
+ PM_SETTING_AC_POWER_OFF = 0x03,
+};
+
+static const char * const ac_power_modes[] = { "off", "restore" };
+
+static int ac_power_mode_map[] = {
+ PM_SETTING_AC_POWER_OFF,
+ PM_SETTING_AC_POWER_RESTORE,
+};
+
+struct macsmc_reboot {
+ struct device *dev;
+ struct apple_smc *smc;
+ struct notifier_block reboot_notify;
+
+ union {
+ struct macsmc_reboot_nvmem nvm;
+ struct nvmem_cell *nvm_cells[ARRAY_SIZE(nvmem_names)];
+ };
+};
+
+/* Helpers to read/write a u8 given a struct nvmem_cell */
+static int nvmem_cell_get_u8(struct nvmem_cell *cell)
+{
+ size_t len;
+ u8 val;
+ void *ret = nvmem_cell_read(cell, &len);
+
+ if (IS_ERR(ret))
+ return PTR_ERR(ret);
+
+ if (len < 1) {
+ kfree(ret);
+ return -EINVAL;
+ }
+
+ val = *(u8 *)ret;
+ kfree(ret);
+ return val;
+}
+
+static int nvmem_cell_set_u8(struct nvmem_cell *cell, u8 val)
+{
+ return nvmem_cell_write(cell, &val, sizeof(val));
+}
+
+static ssize_t macsmc_ac_power_mode_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t n)
+{
+ struct macsmc_reboot *reboot = dev_get_drvdata(dev);
+ int mode;
+ int ret;
+
+ mode = sysfs_match_string(ac_power_modes, buf);
+ if (mode < 0)
+ return mode;
+
+ ret = nvmem_cell_set_u8(reboot->nvm.pm_setting, ac_power_mode_map[mode]);
+ if (ret < 0)
+ return ret;
+
+ return n;
+}
+
+static ssize_t macsmc_ac_power_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct macsmc_reboot *reboot = dev_get_drvdata(dev);
+ int len = 0;
+ int i;
+ int mode = nvmem_cell_get_u8(reboot->nvm.pm_setting);
+
+ if (mode < 0)
+ return mode;
+
+ for (i = 0; i < ARRAY_SIZE(ac_power_mode_map); i++) {
+ if (mode == ac_power_mode_map[i])
+ len += scnprintf(buf+len, PAGE_SIZE-len,
+ "[%s] ", ac_power_modes[i]);
+ else
+ len += scnprintf(buf+len, PAGE_SIZE-len,
+ "%s ", ac_power_modes[i]);
+ }
+
+ buf[len-1] = '\n';
+ return len;
+}
+static DEVICE_ATTR(ac_power_mode, 0644, macsmc_ac_power_mode_show,
+ macsmc_ac_power_mode_store);
+
+/*
+ * SMC 'MBSE' key actions:
+ *
+ * 'offw' - shutdown warning
+ * 'slpw' - sleep warning
+ * 'rest' - restart warning
+ * 'off1' - shutdown (needs PMU bit set to stay on)
+ * 'susp' - suspend
+ * 'phra' - restart ("PE Halt Restart Action"?)
+ * 'panb' - panic beginning
+ * 'pane' - panic end
+ */
+
+static int macsmc_prepare_atomic(struct sys_off_data *data)
+{
+ struct macsmc_reboot *reboot = data->cb_data;
+
+ dev_info(reboot->dev, "Preparing SMC for atomic mode\n");
+
+ apple_smc_enter_atomic(reboot->smc);
+ return NOTIFY_OK;
+}
+
+static int macsmc_power_off(struct sys_off_data *data)
+{
+ struct macsmc_reboot *reboot = data->cb_data;
+
+ dev_info(reboot->dev, "Issuing power off (off1)\n");
+
+ if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(off1)) < 0) {
+ dev_err(reboot->dev, "Failed to issue MBSE = off1 (power_off)\n");
+ } else {
+ mdelay(100);
+ WARN_ONCE(1, "Unable to power off system\n");
+ }
+
+ return NOTIFY_OK;
+}
+
+static int macsmc_restart(struct sys_off_data *data)
+{
+ struct macsmc_reboot *reboot = data->cb_data;
+
+ dev_info(reboot->dev, "Issuing restart (phra)\n");
+
+ if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(phra)) < 0) {
+ dev_err(reboot->dev, "Failed to issue MBSE = phra (restart)\n");
+ } else {
+ mdelay(100);
+ WARN_ONCE(1, "Unable to restart system\n");
+ }
+
+ return NOTIFY_OK;
+}
+
+static int macsmc_reboot_notify(struct notifier_block *this, unsigned long action, void *data)
+{
+ struct macsmc_reboot *reboot = container_of(this, struct macsmc_reboot, reboot_notify);
+ u32 val;
+ u8 shutdown_flag;
+
+ switch (action) {
+ case SYS_RESTART:
+ val = SMC_KEY(rest);
+ shutdown_flag = 0;
+ break;
+ case SYS_POWER_OFF:
+ val = SMC_KEY(offw);
+ shutdown_flag = 1;
+ break;
+ default:
+ return NOTIFY_DONE;
+ }
+
+ dev_info(reboot->dev, "Preparing for reboot (%p4ch)\n", &val);
+
+ /* On the Mac Mini, this will turn off the LED for power off */
+ if (apple_smc_write_u32(reboot->smc, SMC_KEY(MBSE), val) < 0)
+ dev_err(reboot->dev, "Failed to issue MBSE = %p4ch (reboot_prepare)\n", &val);
+
+ /* Set the boot_stage to 0, which means we're doing a clean shutdown/reboot. */
+ if (reboot->nvm.boot_stage &&
+ nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_SHUTDOWN) < 0)
+ dev_err(reboot->dev, "Failed to write boot_stage\n");
+
+ /*
+ * Set the PMU flag to actually reboot into the off state.
+ * Without this, the device will just reboot. We make it optional in case it is no longer
+ * necessary on newer hardware.
+ */
+ if (reboot->nvm.shutdown_flag &&
+ nvmem_cell_set_u8(reboot->nvm.shutdown_flag, shutdown_flag) < 0)
+ dev_err(reboot->dev, "Failed to write shutdown_flag\n");
+
+ return NOTIFY_OK;
+}
+
+static void macsmc_power_init_error_counts(struct macsmc_reboot *reboot)
+{
+ int boot_error_count, panic_count;
+
+ if (!reboot->nvm.boot_error_count || !reboot->nvm.panic_count)
+ return;
+
+ boot_error_count = nvmem_cell_get_u8(reboot->nvm.boot_error_count);
+ if (boot_error_count < 0) {
+ dev_err(reboot->dev, "Failed to read boot_error_count (%d)\n", boot_error_count);
+ return;
+ }
+
+ panic_count = nvmem_cell_get_u8(reboot->nvm.panic_count);
+ if (panic_count < 0) {
+ dev_err(reboot->dev, "Failed to read panic_count (%d)\n", panic_count);
+ return;
+ }
+
+ if (!boot_error_count && !panic_count)
+ return;
+
+ dev_warn(reboot->dev, "PMU logged %d boot error(s) and %d panic(s)\n",
+ boot_error_count, panic_count);
+
+ if (nvmem_cell_set_u8(reboot->nvm.panic_count, 0) < 0)
+ dev_err(reboot->dev, "Failed to reset panic_count\n");
+ if (nvmem_cell_set_u8(reboot->nvm.boot_error_count, 0) < 0)
+ dev_err(reboot->dev, "Failed to reset boot_error_count\n");
+}
+
+static int macsmc_reboot_probe(struct platform_device *pdev)
+{
+ struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
+ struct macsmc_reboot *reboot;
+ int ret, i;
+
+ /* Ignore devices without this functionality */
+ if (!apple_smc_key_exists(smc, SMC_KEY(MBSE)))
+ return -ENODEV;
+
+ reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
+ if (!reboot)
+ return -ENOMEM;
+
+ reboot->dev = &pdev->dev;
+ reboot->smc = smc;
+
+ platform_set_drvdata(pdev, reboot);
+
+ pdev->dev.of_node = of_get_child_by_name(pdev->dev.parent->of_node, "reboot");
+
+ for (i = 0; i < ARRAY_SIZE(nvmem_names); i++) {
+ struct nvmem_cell *cell;
+
+ cell = devm_nvmem_cell_get(&pdev->dev,
+ nvmem_names[i]);
+ if (IS_ERR(cell)) {
+ if (PTR_ERR(cell) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ dev_warn(&pdev->dev, "Missing NVMEM cell %s (%ld)\n",
+ nvmem_names[i], PTR_ERR(cell));
+ /* Non fatal, we'll deal with it */
+ cell = NULL;
+ }
+ reboot->nvm_cells[i] = cell;
+ }
+
+ /* Set the boot_stage to indicate we're running the OS kernel */
+ if (reboot->nvm.boot_stage &&
+ nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_KERNEL_STARTED) < 0)
+ dev_err(reboot->dev, "Failed to write boot_stage\n");
+
+ /* Display and clear the error counts */
+ macsmc_power_init_error_counts(reboot);
+
+ reboot->reboot_notify.notifier_call = macsmc_reboot_notify;
+
+ ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF_PREPARE,
+ SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to register power-off prepare handler\n");
+ ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
+ macsmc_power_off, reboot);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to register power-off handler\n");
+
+ ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART_PREPARE,
+ SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to register restart prepare handler\n");
+ ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH,
+ macsmc_restart, reboot);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to register restart handler\n");
+
+ ret = devm_register_reboot_notifier(&pdev->dev, &reboot->reboot_notify);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to register reboot notifier\n");
+
+ dev_info(&pdev->dev, "Handling reboot and poweroff requests via SMC\n");
+
+ if (device_create_file(&pdev->dev, &dev_attr_ac_power_mode))
+ dev_warn(&pdev->dev, "could not create sysfs file\n");
+
+ return 0;
+}
+
+static void macsmc_reboot_remove(struct platform_device *pdev)
+{
+ device_remove_file(&pdev->dev, &dev_attr_ac_power_mode);
+}
+
+static const struct of_device_id macsmc_reboot_of_table[] = {
+ { .compatible = "apple,smc-reboot", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, macsmc_reboot_of_table);
+
+static struct platform_driver macsmc_reboot_driver = {
+ .driver = {
+ .name = "macsmc-reboot",
+ .of_match_table = macsmc_reboot_of_table,
+ },
+ .probe = macsmc_reboot_probe,
+ .remove = macsmc_reboot_remove,
+};
+module_platform_driver(macsmc_reboot_driver);
+
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC reboot/poweroff driver");
+MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
+MODULE_ALIAS("platform:macsmc-reboot");
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 08/10] arm64: dts: apple: t8103: Add SMC node
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (6 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 09/10] arm64: dts: apple: t8112: " Sven Peter via B4 Relay
` (2 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
arch/arm64/boot/dts/apple/t8103.dtsi | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index 20faf0c0d80927b2e18dd966a61b5507b322c72f..58270e7d79b07ee98340f140972a6f0d14c86dcb 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -836,6 +836,41 @@ wdt: watchdog@23d2b0000 {
interrupts = <AIC_IRQ 338 IRQ_TYPE_LEVEL_HIGH>;
};
+ smc: smc@23e400000 {
+ compatible = "apple,t8103-smc", "apple,smc";
+ reg = <0x2 0x3e400000 0x0 0x4000>,
+ <0x2 0x3fe00000 0x0 0x100000>;
+ reg-names = "smc", "sram";
+ mboxes = <&smc_mbox>;
+
+ smc_gpio: gpio {
+ compatible = "apple,smc-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ smc_reboot: reboot {
+ compatible = "apple,smc-reboot";
+ nvmem-cells = <&shutdown_flag>, <&boot_stage>,
+ <&boot_error_count>, <&panic_count>, <&pm_setting>;
+ nvmem-cell-names = "shutdown_flag", "boot_stage",
+ "boot_error_count", "panic_count", "pm_setting";
+ };
+ };
+
+ smc_mbox: mbox@23e408000 {
+ compatible = "apple,t8103-asc-mailbox", "apple,asc-mailbox-v4";
+ reg = <0x2 0x3e408000 0x0 0x4000>;
+ interrupt-parent = <&aic>;
+ interrupts = <AIC_IRQ 400 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 401 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 402 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 403 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "send-empty", "send-not-empty",
+ "recv-empty", "recv-not-empty";
+ #mbox-cells = <0>;
+ };
+
pinctrl_smc: pinctrl@23e820000 {
compatible = "apple,t8103-pinctrl", "apple,pinctrl";
reg = <0x2 0x3e820000 0x0 0x4000>;
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 09/10] arm64: dts: apple: t8112: Add SMC node
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (7 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 08/10] arm64: dts: apple: t8103: Add SMC node Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 10/10] arm64: dts: apple: t600x: " Sven Peter via B4 Relay
2025-05-12 12:25 ` [PATCH v5 00/10] Apple Mac System Management Controller Neal Gompa
10 siblings, 0 replies; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
arch/arm64/boot/dts/apple/t8112.dtsi | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi
index e95711d8337f6cea898e88a3d564caf2c4f94404..861cf2f684a067d73f79d8f01447bc375136793d 100644
--- a/arch/arm64/boot/dts/apple/t8112.dtsi
+++ b/arch/arm64/boot/dts/apple/t8112.dtsi
@@ -839,6 +839,41 @@ rtc_offset: rtc-offset@f900 {
};
};
+ smc: smc@23e400000 {
+ compatible = "apple,t8112-smc", "apple,smc";
+ reg = <0x2 0x3e400000 0x0 0x4000>,
+ <0x2 0x3fe00000 0x0 0x100000>;
+ reg-names = "smc", "sram";
+ mboxes = <&smc_mbox>;
+
+ smc_gpio: gpio {
+ compatible = "apple,smc-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ smc_reboot: reboot {
+ compatible = "apple,smc-reboot";
+ nvmem-cells = <&shutdown_flag>, <&boot_stage>,
+ <&boot_error_count>, <&panic_count>, <&pm_setting>;
+ nvmem-cell-names = "shutdown_flag", "boot_stage",
+ "boot_error_count", "panic_count", "pm_setting";
+ };
+ };
+
+ smc_mbox: mbox@23e408000 {
+ compatible = "apple,t8112-asc-mailbox", "apple,asc-mailbox-v4";
+ reg = <0x2 0x3e408000 0x0 0x4000>;
+ interrupt-parent = <&aic>;
+ interrupts = <AIC_IRQ 499 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 500 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 501 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 502 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "send-empty", "send-not-empty",
+ "recv-empty", "recv-not-empty";
+ #mbox-cells = <0>;
+ };
+
pinctrl_smc: pinctrl@23e820000 {
compatible = "apple,t8112-pinctrl", "apple,pinctrl";
reg = <0x2 0x3e820000 0x0 0x4000>;
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v5 10/10] arm64: dts: apple: t600x: Add SMC node
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (8 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 09/10] arm64: dts: apple: t8112: " Sven Peter via B4 Relay
@ 2025-05-11 8:18 ` Sven Peter via B4 Relay
2025-05-12 12:25 ` [PATCH v5 00/10] Apple Mac System Management Controller Neal Gompa
10 siblings, 0 replies; 24+ messages in thread
From: Sven Peter via B4 Relay @ 2025-05-11 8:18 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
Hector Martin, Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
From: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
arch/arm64/boot/dts/apple/t600x-die0.dtsi | 35 +++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi
index 110bc6719512e334e04b496fb157cb4368679957..4993a8ace87b2fc7e645b08c19fcd9b0c21896aa 100644
--- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi
+++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi
@@ -24,6 +24,41 @@ aic: interrupt-controller@28e100000 {
power-domains = <&ps_aic>;
};
+ smc: smc@290400000 {
+ compatible = "apple,t6000-smc", "apple,smc";
+ reg = <0x2 0x90400000 0x0 0x4000>,
+ <0x2 0x91e00000 0x0 0x100000>;
+ reg-names = "smc", "sram";
+ mboxes = <&smc_mbox>;
+
+ smc_gpio: gpio {
+ compatible = "apple,smc-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ smc_reboot: reboot {
+ compatible = "apple,smc-reboot";
+ nvmem-cells = <&shutdown_flag>, <&boot_stage>,
+ <&boot_error_count>, <&panic_count>, <&pm_setting>;
+ nvmem-cell-names = "shutdown_flag", "boot_stage",
+ "boot_error_count", "panic_count", "pm_setting";
+ };
+ };
+
+ smc_mbox: mbox@290408000 {
+ compatible = "apple,t6000-asc-mailbox", "apple,asc-mailbox-v4";
+ reg = <0x2 0x90408000 0x0 0x4000>;
+ interrupt-parent = <&aic>;
+ interrupts = <AIC_IRQ 0 754 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 0 755 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 0 756 IRQ_TYPE_LEVEL_HIGH>,
+ <AIC_IRQ 0 757 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "send-empty", "send-not-empty",
+ "recv-empty", "recv-not-empty";
+ #mbox-cells = <0>;
+ };
+
pinctrl_smc: pinctrl@290820000 {
compatible = "apple,t6000-pinctrl", "apple,pinctrl";
reg = <0x2 0x90820000 0x0 0x4000>;
--
2.34.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
@ 2025-05-11 10:07 ` Stefan Wahren
2025-05-11 10:14 ` Sven Peter
2025-05-11 16:44 ` Alyssa Rosenzweig
2025-05-11 22:16 ` Sebastian Reichel
2 siblings, 1 reply; 24+ messages in thread
From: Stefan Wahren @ 2025-05-11 10:07 UTC (permalink / raw)
To: sven, Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King (Oracle)
Cc: asahi, linux-arm-kernel, linux-gpio, devicetree, linux-kernel,
linux-pm
Hi Sven,
Am 11.05.25 um 10:18 schrieb Sven Peter via B4 Relay:
> From: Hector Martin <marcan@marcan.st>
>
> This driver implements the reboot/shutdown support exposed by the SMC
> on Apple Silicon machines, such as Apple M1 Macs.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> MAINTAINERS | 1 +
> drivers/power/reset/Kconfig | 11 ++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/macsmc-reboot.c | 363 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 376 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fa3a5f9ee40446bcc725c9eac2a36651e6bc7553..84f7a730eb2260b7c1e0487d18c8eb3de82f5206 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2303,6 +2303,7 @@ F: drivers/mfd/macsmc.c
> F: drivers/nvme/host/apple.c
> F: drivers/nvmem/apple-efuses.c
> F: drivers/pinctrl/pinctrl-apple-gpio.c
> +F: drivers/power/reset/macsmc-reboot.c
> F: drivers/pwm/pwm-apple.c
> F: drivers/soc/apple/*
> F: drivers/spi/spi-apple.c
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 60bf0ca64cf395cd18238fc626611c74d29844ee..6e8dfff64fdc001d09b6c00630cd8b7e2fafdd8e 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -128,6 +128,17 @@ config POWER_RESET_LINKSTATION
>
> Say Y here if you have a Buffalo LinkStation LS421D/E.
>
> +config POWER_RESET_MACSMC
> + tristate "Apple SMC reset/power-off driver"
> + depends on ARCH_APPLE || COMPILE_TEST
> + depends on MFD_MACSMC
> + depends on OF
> + help
> + This driver supports reset and power-off on Apple Mac machines
> + that implement this functionality via the SMC.
> +
> + Say Y here if you have an Apple Silicon Mac.
> +
> config POWER_RESET_MSM
> bool "Qualcomm MSM power-off driver"
> depends on ARCH_QCOM
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index 10782d32e1da39f4b8b4566e8a885f2e13f65130..887dd9e49b7293b69b9429ddc0c1571194a153cf 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
> obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
> obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
> obj-$(CONFIG_POWER_RESET_LINKSTATION) += linkstation-poweroff.o
> +obj-$(CONFIG_POWER_RESET_MACSMC) += macsmc-reboot.o
> obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
> obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
> obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
> diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..d82339e427886667be4ad2de0d1d5c04d2383059
> --- /dev/null
> +++ b/drivers/power/reset/macsmc-reboot.c
> @@ -0,0 +1,363 @@
> +// SPDX-License-Identifier: GPL-2.0-only OR MIT
> +/*
> + * Apple SMC Reboot/Poweroff Handler
> + * Copyright The Asahi Linux Contributors
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>
> +#include <linux/slab.h>
> +
> +struct macsmc_reboot_nvmem {
> + struct nvmem_cell *shutdown_flag;
> + struct nvmem_cell *pm_setting;
> + struct nvmem_cell *boot_stage;
> + struct nvmem_cell *boot_error_count;
> + struct nvmem_cell *panic_count;
> +};
> +
> +static const char * const nvmem_names[] = {
> + "shutdown_flag",
> + "pm_setting",
> + "boot_stage",
> + "boot_error_count",
> + "panic_count",
> +};
> +
> +enum boot_stage {
> + BOOT_STAGE_SHUTDOWN = 0x00, /* Clean shutdown */
> + BOOT_STAGE_IBOOT_DONE = 0x2f, /* Last stage of bootloader */
> + BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */
> +};
> +
> +enum pm_setting {
> + PM_SETTING_AC_POWER_RESTORE = 0x02,
> + PM_SETTING_AC_POWER_OFF = 0x03,
> +};
> +
> +static const char * const ac_power_modes[] = { "off", "restore" };
> +
> +static int ac_power_mode_map[] = {
> + PM_SETTING_AC_POWER_OFF,
> + PM_SETTING_AC_POWER_RESTORE,
> +};
> +
> +struct macsmc_reboot {
> + struct device *dev;
> + struct apple_smc *smc;
> + struct notifier_block reboot_notify;
> +
> + union {
> + struct macsmc_reboot_nvmem nvm;
> + struct nvmem_cell *nvm_cells[ARRAY_SIZE(nvmem_names)];
> + };
> +};
> +
> +/* Helpers to read/write a u8 given a struct nvmem_cell */
> +static int nvmem_cell_get_u8(struct nvmem_cell *cell)
> +{
> + size_t len;
> + u8 val;
> + void *ret = nvmem_cell_read(cell, &len);
in case this series needs a respin, please rename the pointer (e.g.
buf). This is very unusual, because ret is usually of type int.
Regards
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 10:07 ` Stefan Wahren
@ 2025-05-11 10:14 ` Sven Peter
0 siblings, 0 replies; 24+ messages in thread
From: Sven Peter @ 2025-05-11 10:14 UTC (permalink / raw)
To: Stefan Wahren
Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sebastian Reichel, Lee Jones,
Marc Zyngier, Russell King, asahi, linux-arm-kernel,
open list:GPIO SUBSYSTEM, devicetree, linux-kernel, linux-pm
Hi Stefan,
On Sun, May 11, 2025, at 12:07, Stefan Wahren wrote:
> Hi Sven,
>
> Am 11.05.25 um 10:18 schrieb Sven Peter via B4 Relay:
[...]
>> +/* Helpers to read/write a u8 given a struct nvmem_cell */
>> +static int nvmem_cell_get_u8(struct nvmem_cell *cell)
>> +{
>> + size_t len;
>> + u8 val;
>> + void *ret = nvmem_cell_read(cell, &len);
> in case this series needs a respin, please rename the pointer (e.g.
> buf). This is very unusual, because ret is usually of type int.
That's indeed odd, I'll rename it.
Thanks,
Sven
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional
2025-05-11 8:18 ` [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional Sven Peter via B4 Relay
@ 2025-05-11 16:42 ` Alyssa Rosenzweig
0 siblings, 0 replies; 24+ messages in thread
From: Alyssa Rosenzweig @ 2025-05-11 16:42 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Neal Gompa, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Le Sun , May 11, 2025 at 08:18:39AM +0000, Sven Peter via B4 Relay a écrit :
> From: Sven Peter <sven@svenpeter.dev>
>
> shmem_destroy isn't always required for coprocessor-managed buffers but we
> still enforce that it exists. Just relax the check.
>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> drivers/soc/apple/rtkit.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
> index 5fffd0f003dc2f4f377faf96cce0c1ce4ff0b788..b8d4da147d23f7e99e76eea314e4d976cddbd1c6 100644
> --- a/drivers/soc/apple/rtkit.c
> +++ b/drivers/soc/apple/rtkit.c
> @@ -279,8 +279,7 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
> dev_dbg(rtk->dev, "RTKit: buffer request for 0x%zx bytes at %pad\n",
> buffer->size, &buffer->iova);
>
> - if (buffer->iova &&
> - (!rtk->ops->shmem_setup || !rtk->ops->shmem_destroy)) {
> + if (buffer->iova && !rtk->ops->shmem_setup) {
> err = -EINVAL;
> goto error;
> }
>
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
2025-05-11 10:07 ` Stefan Wahren
@ 2025-05-11 16:44 ` Alyssa Rosenzweig
2025-05-11 22:16 ` Sebastian Reichel
2 siblings, 0 replies; 24+ messages in thread
From: Alyssa Rosenzweig @ 2025-05-11 16:44 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Neal Gompa, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
with Stefan's comment addressed
Le Sun , May 11, 2025 at 08:18:42AM +0000, Sven Peter via B4 Relay a écrit :
> From: Hector Martin <marcan@marcan.st>
>
> This driver implements the reboot/shutdown support exposed by the SMC
> on Apple Silicon machines, such as Apple M1 Macs.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> MAINTAINERS | 1 +
> drivers/power/reset/Kconfig | 11 ++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/macsmc-reboot.c | 363 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 376 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fa3a5f9ee40446bcc725c9eac2a36651e6bc7553..84f7a730eb2260b7c1e0487d18c8eb3de82f5206 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2303,6 +2303,7 @@ F: drivers/mfd/macsmc.c
> F: drivers/nvme/host/apple.c
> F: drivers/nvmem/apple-efuses.c
> F: drivers/pinctrl/pinctrl-apple-gpio.c
> +F: drivers/power/reset/macsmc-reboot.c
> F: drivers/pwm/pwm-apple.c
> F: drivers/soc/apple/*
> F: drivers/spi/spi-apple.c
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 60bf0ca64cf395cd18238fc626611c74d29844ee..6e8dfff64fdc001d09b6c00630cd8b7e2fafdd8e 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -128,6 +128,17 @@ config POWER_RESET_LINKSTATION
>
> Say Y here if you have a Buffalo LinkStation LS421D/E.
>
> +config POWER_RESET_MACSMC
> + tristate "Apple SMC reset/power-off driver"
> + depends on ARCH_APPLE || COMPILE_TEST
> + depends on MFD_MACSMC
> + depends on OF
> + help
> + This driver supports reset and power-off on Apple Mac machines
> + that implement this functionality via the SMC.
> +
> + Say Y here if you have an Apple Silicon Mac.
> +
> config POWER_RESET_MSM
> bool "Qualcomm MSM power-off driver"
> depends on ARCH_QCOM
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index 10782d32e1da39f4b8b4566e8a885f2e13f65130..887dd9e49b7293b69b9429ddc0c1571194a153cf 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
> obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
> obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
> obj-$(CONFIG_POWER_RESET_LINKSTATION) += linkstation-poweroff.o
> +obj-$(CONFIG_POWER_RESET_MACSMC) += macsmc-reboot.o
> obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
> obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
> obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
> diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..d82339e427886667be4ad2de0d1d5c04d2383059
> --- /dev/null
> +++ b/drivers/power/reset/macsmc-reboot.c
> @@ -0,0 +1,363 @@
> +// SPDX-License-Identifier: GPL-2.0-only OR MIT
> +/*
> + * Apple SMC Reboot/Poweroff Handler
> + * Copyright The Asahi Linux Contributors
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>
> +#include <linux/slab.h>
> +
> +struct macsmc_reboot_nvmem {
> + struct nvmem_cell *shutdown_flag;
> + struct nvmem_cell *pm_setting;
> + struct nvmem_cell *boot_stage;
> + struct nvmem_cell *boot_error_count;
> + struct nvmem_cell *panic_count;
> +};
> +
> +static const char * const nvmem_names[] = {
> + "shutdown_flag",
> + "pm_setting",
> + "boot_stage",
> + "boot_error_count",
> + "panic_count",
> +};
> +
> +enum boot_stage {
> + BOOT_STAGE_SHUTDOWN = 0x00, /* Clean shutdown */
> + BOOT_STAGE_IBOOT_DONE = 0x2f, /* Last stage of bootloader */
> + BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */
> +};
> +
> +enum pm_setting {
> + PM_SETTING_AC_POWER_RESTORE = 0x02,
> + PM_SETTING_AC_POWER_OFF = 0x03,
> +};
> +
> +static const char * const ac_power_modes[] = { "off", "restore" };
> +
> +static int ac_power_mode_map[] = {
> + PM_SETTING_AC_POWER_OFF,
> + PM_SETTING_AC_POWER_RESTORE,
> +};
> +
> +struct macsmc_reboot {
> + struct device *dev;
> + struct apple_smc *smc;
> + struct notifier_block reboot_notify;
> +
> + union {
> + struct macsmc_reboot_nvmem nvm;
> + struct nvmem_cell *nvm_cells[ARRAY_SIZE(nvmem_names)];
> + };
> +};
> +
> +/* Helpers to read/write a u8 given a struct nvmem_cell */
> +static int nvmem_cell_get_u8(struct nvmem_cell *cell)
> +{
> + size_t len;
> + u8 val;
> + void *ret = nvmem_cell_read(cell, &len);
> +
> + if (IS_ERR(ret))
> + return PTR_ERR(ret);
> +
> + if (len < 1) {
> + kfree(ret);
> + return -EINVAL;
> + }
> +
> + val = *(u8 *)ret;
> + kfree(ret);
> + return val;
> +}
> +
> +static int nvmem_cell_set_u8(struct nvmem_cell *cell, u8 val)
> +{
> + return nvmem_cell_write(cell, &val, sizeof(val));
> +}
> +
> +static ssize_t macsmc_ac_power_mode_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t n)
> +{
> + struct macsmc_reboot *reboot = dev_get_drvdata(dev);
> + int mode;
> + int ret;
> +
> + mode = sysfs_match_string(ac_power_modes, buf);
> + if (mode < 0)
> + return mode;
> +
> + ret = nvmem_cell_set_u8(reboot->nvm.pm_setting, ac_power_mode_map[mode]);
> + if (ret < 0)
> + return ret;
> +
> + return n;
> +}
> +
> +static ssize_t macsmc_ac_power_mode_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct macsmc_reboot *reboot = dev_get_drvdata(dev);
> + int len = 0;
> + int i;
> + int mode = nvmem_cell_get_u8(reboot->nvm.pm_setting);
> +
> + if (mode < 0)
> + return mode;
> +
> + for (i = 0; i < ARRAY_SIZE(ac_power_mode_map); i++) {
> + if (mode == ac_power_mode_map[i])
> + len += scnprintf(buf+len, PAGE_SIZE-len,
> + "[%s] ", ac_power_modes[i]);
> + else
> + len += scnprintf(buf+len, PAGE_SIZE-len,
> + "%s ", ac_power_modes[i]);
> + }
> +
> + buf[len-1] = '\n';
> + return len;
> +}
> +static DEVICE_ATTR(ac_power_mode, 0644, macsmc_ac_power_mode_show,
> + macsmc_ac_power_mode_store);
> +
> +/*
> + * SMC 'MBSE' key actions:
> + *
> + * 'offw' - shutdown warning
> + * 'slpw' - sleep warning
> + * 'rest' - restart warning
> + * 'off1' - shutdown (needs PMU bit set to stay on)
> + * 'susp' - suspend
> + * 'phra' - restart ("PE Halt Restart Action"?)
> + * 'panb' - panic beginning
> + * 'pane' - panic end
> + */
> +
> +static int macsmc_prepare_atomic(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Preparing SMC for atomic mode\n");
> +
> + apple_smc_enter_atomic(reboot->smc);
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_power_off(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Issuing power off (off1)\n");
> +
> + if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(off1)) < 0) {
> + dev_err(reboot->dev, "Failed to issue MBSE = off1 (power_off)\n");
> + } else {
> + mdelay(100);
> + WARN_ONCE(1, "Unable to power off system\n");
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_restart(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Issuing restart (phra)\n");
> +
> + if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(phra)) < 0) {
> + dev_err(reboot->dev, "Failed to issue MBSE = phra (restart)\n");
> + } else {
> + mdelay(100);
> + WARN_ONCE(1, "Unable to restart system\n");
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_reboot_notify(struct notifier_block *this, unsigned long action, void *data)
> +{
> + struct macsmc_reboot *reboot = container_of(this, struct macsmc_reboot, reboot_notify);
> + u32 val;
> + u8 shutdown_flag;
> +
> + switch (action) {
> + case SYS_RESTART:
> + val = SMC_KEY(rest);
> + shutdown_flag = 0;
> + break;
> + case SYS_POWER_OFF:
> + val = SMC_KEY(offw);
> + shutdown_flag = 1;
> + break;
> + default:
> + return NOTIFY_DONE;
> + }
> +
> + dev_info(reboot->dev, "Preparing for reboot (%p4ch)\n", &val);
> +
> + /* On the Mac Mini, this will turn off the LED for power off */
> + if (apple_smc_write_u32(reboot->smc, SMC_KEY(MBSE), val) < 0)
> + dev_err(reboot->dev, "Failed to issue MBSE = %p4ch (reboot_prepare)\n", &val);
> +
> + /* Set the boot_stage to 0, which means we're doing a clean shutdown/reboot. */
> + if (reboot->nvm.boot_stage &&
> + nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_SHUTDOWN) < 0)
> + dev_err(reboot->dev, "Failed to write boot_stage\n");
> +
> + /*
> + * Set the PMU flag to actually reboot into the off state.
> + * Without this, the device will just reboot. We make it optional in case it is no longer
> + * necessary on newer hardware.
> + */
> + if (reboot->nvm.shutdown_flag &&
> + nvmem_cell_set_u8(reboot->nvm.shutdown_flag, shutdown_flag) < 0)
> + dev_err(reboot->dev, "Failed to write shutdown_flag\n");
> +
> + return NOTIFY_OK;
> +}
> +
> +static void macsmc_power_init_error_counts(struct macsmc_reboot *reboot)
> +{
> + int boot_error_count, panic_count;
> +
> + if (!reboot->nvm.boot_error_count || !reboot->nvm.panic_count)
> + return;
> +
> + boot_error_count = nvmem_cell_get_u8(reboot->nvm.boot_error_count);
> + if (boot_error_count < 0) {
> + dev_err(reboot->dev, "Failed to read boot_error_count (%d)\n", boot_error_count);
> + return;
> + }
> +
> + panic_count = nvmem_cell_get_u8(reboot->nvm.panic_count);
> + if (panic_count < 0) {
> + dev_err(reboot->dev, "Failed to read panic_count (%d)\n", panic_count);
> + return;
> + }
> +
> + if (!boot_error_count && !panic_count)
> + return;
> +
> + dev_warn(reboot->dev, "PMU logged %d boot error(s) and %d panic(s)\n",
> + boot_error_count, panic_count);
> +
> + if (nvmem_cell_set_u8(reboot->nvm.panic_count, 0) < 0)
> + dev_err(reboot->dev, "Failed to reset panic_count\n");
> + if (nvmem_cell_set_u8(reboot->nvm.boot_error_count, 0) < 0)
> + dev_err(reboot->dev, "Failed to reset boot_error_count\n");
> +}
> +
> +static int macsmc_reboot_probe(struct platform_device *pdev)
> +{
> + struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
> + struct macsmc_reboot *reboot;
> + int ret, i;
> +
> + /* Ignore devices without this functionality */
> + if (!apple_smc_key_exists(smc, SMC_KEY(MBSE)))
> + return -ENODEV;
> +
> + reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
> + if (!reboot)
> + return -ENOMEM;
> +
> + reboot->dev = &pdev->dev;
> + reboot->smc = smc;
> +
> + platform_set_drvdata(pdev, reboot);
> +
> + pdev->dev.of_node = of_get_child_by_name(pdev->dev.parent->of_node, "reboot");
> +
> + for (i = 0; i < ARRAY_SIZE(nvmem_names); i++) {
> + struct nvmem_cell *cell;
> +
> + cell = devm_nvmem_cell_get(&pdev->dev,
> + nvmem_names[i]);
> + if (IS_ERR(cell)) {
> + if (PTR_ERR(cell) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + dev_warn(&pdev->dev, "Missing NVMEM cell %s (%ld)\n",
> + nvmem_names[i], PTR_ERR(cell));
> + /* Non fatal, we'll deal with it */
> + cell = NULL;
> + }
> + reboot->nvm_cells[i] = cell;
> + }
> +
> + /* Set the boot_stage to indicate we're running the OS kernel */
> + if (reboot->nvm.boot_stage &&
> + nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_KERNEL_STARTED) < 0)
> + dev_err(reboot->dev, "Failed to write boot_stage\n");
> +
> + /* Display and clear the error counts */
> + macsmc_power_init_error_counts(reboot);
> +
> + reboot->reboot_notify.notifier_call = macsmc_reboot_notify;
> +
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF_PREPARE,
> + SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register power-off prepare handler\n");
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
> + macsmc_power_off, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register power-off handler\n");
> +
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART_PREPARE,
> + SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register restart prepare handler\n");
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH,
> + macsmc_restart, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to register restart handler\n");
> +
> + ret = devm_register_reboot_notifier(&pdev->dev, &reboot->reboot_notify);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to register reboot notifier\n");
> +
> + dev_info(&pdev->dev, "Handling reboot and poweroff requests via SMC\n");
> +
> + if (device_create_file(&pdev->dev, &dev_attr_ac_power_mode))
> + dev_warn(&pdev->dev, "could not create sysfs file\n");
> +
> + return 0;
> +}
> +
> +static void macsmc_reboot_remove(struct platform_device *pdev)
> +{
> + device_remove_file(&pdev->dev, &dev_attr_ac_power_mode);
> +}
> +
> +static const struct of_device_id macsmc_reboot_of_table[] = {
> + { .compatible = "apple,smc-reboot", },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, macsmc_reboot_of_table);
> +
> +static struct platform_driver macsmc_reboot_driver = {
> + .driver = {
> + .name = "macsmc-reboot",
> + .of_match_table = macsmc_reboot_of_table,
> + },
> + .probe = macsmc_reboot_probe,
> + .remove = macsmc_reboot_remove,
> +};
> +module_platform_driver(macsmc_reboot_driver);
> +
> +MODULE_LICENSE("Dual MIT/GPL");
> +MODULE_DESCRIPTION("Apple SMC reboot/poweroff driver");
> +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
> +MODULE_ALIAS("platform:macsmc-reboot");
>
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs
2025-05-11 8:18 ` [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs Sven Peter via B4 Relay
@ 2025-05-11 16:45 ` Alyssa Rosenzweig
0 siblings, 0 replies; 24+ messages in thread
From: Alyssa Rosenzweig @ 2025-05-11 16:45 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Neal Gompa, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Le Sun , May 11, 2025 at 08:18:41AM +0000, Sven Peter via B4 Relay a écrit :
> From: Hector Martin <marcan@marcan.st>
>
> This driver implements the GPIO service on top of the SMC framework
> on Apple Mac machines. In particular, these are the GPIOs present in the
> PMU IC which are used to control power to certain on-board devices.
>
> Although the underlying hardware supports various pin config settings
> (input/output, open drain, etc.), this driver does not implement that
> functionality and leaves it up to the firmware to configure things
> properly. We also don't yet support interrupts/events. This is
> sufficient for device power control, which is the only thing we need to
> support at this point. More features will be implemented when needed.
>
> To our knowledge, only Apple Silicon Macs implement this SMC feature.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Reviewed-by: Bartosz Golaszewski <brgl@bgdev.pl>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Reviewed-by: Sven Peter <sven@svenpeter.dev>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> MAINTAINERS | 1 +
> drivers/gpio/Kconfig | 10 ++
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-macsmc.c | 293 +++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 305 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index dfaca531600c22d487fb17a25294686611dd4513..fa3a5f9ee40446bcc725c9eac2a36651e6bc7553 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2291,6 +2291,7 @@ F: drivers/bluetooth/hci_bcm4377.c
> F: drivers/clk/clk-apple-nco.c
> F: drivers/cpufreq/apple-soc-cpufreq.c
> F: drivers/dma/apple-admac.c
> +F: drivers/gpio/gpio-macsmc.c
> F: drivers/pmdomain/apple/
> F: drivers/i2c/busses/i2c-pasemi-core.c
> F: drivers/i2c/busses/i2c-pasemi-platform.c
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index f2c39bbff83a33dcb12b2d32aa3ebc358a0dd949..f0e25105f8ebe7356344722987333a9fc244ea1f 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1440,6 +1440,16 @@ config GPIO_LP87565
> This driver can also be built as a module. If so, the module will be
> called gpio-lp87565.
>
> +config GPIO_MACSMC
> + tristate "Apple Mac SMC GPIO"
> + depends on MFD_MACSMC
> + help
> + Support for GPIOs controlled by the SMC microcontroller on Apple Mac
> + systems.
> +
> + This driver can also be built as a module. If so, the module will be
> + called gpio-macsmc.
> +
> config GPIO_MADERA
> tristate "Cirrus Logic Madera class codecs"
> depends on PINCTRL_MADERA
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index af130882ffeeef8b1d518867bfe1493ec4f21b5f..c2e47f356bfae73384ace8103074f246e49fb9d6 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -97,6 +97,7 @@ obj-$(CONFIG_GPIO_LP873X) += gpio-lp873x.o
> obj-$(CONFIG_GPIO_LP87565) += gpio-lp87565.o
> obj-$(CONFIG_GPIO_LPC18XX) += gpio-lpc18xx.o
> obj-$(CONFIG_GPIO_LPC32XX) += gpio-lpc32xx.o
> +obj-$(CONFIG_GPIO_MACSMC) += gpio-macsmc.o
> obj-$(CONFIG_GPIO_MADERA) += gpio-madera.o
> obj-$(CONFIG_GPIO_MAX3191X) += gpio-max3191x.o
> obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o
> diff --git a/drivers/gpio/gpio-macsmc.c b/drivers/gpio/gpio-macsmc.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..bb179c71a05e294c9ec68db332ad4c0dff118d1a
> --- /dev/null
> +++ b/drivers/gpio/gpio-macsmc.c
> @@ -0,0 +1,293 @@
> +// SPDX-License-Identifier: GPL-2.0-only OR MIT
> +/*
> + * Apple SMC GPIO driver
> + * Copyright The Asahi Linux Contributors
> + *
> + * This driver implements basic SMC PMU GPIO support that can read inputs
> + * and write outputs. Mode changes and IRQ config are not yet implemented.
> + */
> +
> +#include <linux/bitmap.h>
> +#include <linux/device.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/macsmc.h>
> +
> +#define MAX_GPIO 64
> +
> +/*
> + * Commands 0-6 are, presumably, the intended API.
> + * Command 0xff lets you get/set the pin configuration in detail directly,
> + * but the bit meanings seem not to be stable between devices/PMU hardware
> + * versions.
> + *
> + * We're going to try to make do with the low commands for now.
> + * We don't implement pin mode changes at this time.
> + */
> +
> +#define CMD_ACTION (0 << 24)
> +#define CMD_OUTPUT (1 << 24)
> +#define CMD_INPUT (2 << 24)
> +#define CMD_PINMODE (3 << 24)
> +#define CMD_IRQ_ENABLE (4 << 24)
> +#define CMD_IRQ_ACK (5 << 24)
> +#define CMD_IRQ_MODE (6 << 24)
> +#define CMD_CONFIG (0xff << 24)
> +
> +#define MODE_INPUT 0
> +#define MODE_OUTPUT 1
> +#define MODE_VALUE_0 0
> +#define MODE_VALUE_1 2
> +
> +#define IRQ_MODE_HIGH 0
> +#define IRQ_MODE_LOW 1
> +#define IRQ_MODE_RISING 2
> +#define IRQ_MODE_FALLING 3
> +#define IRQ_MODE_BOTH 4
> +
> +#define CONFIG_MASK GENMASK(23, 16)
> +#define CONFIG_VAL GENMASK(7, 0)
> +
> +#define CONFIG_OUTMODE GENMASK(7, 6)
> +#define CONFIG_IRQMODE GENMASK(5, 3)
> +#define CONFIG_PULLDOWN BIT(2)
> +#define CONFIG_PULLUP BIT(1)
> +#define CONFIG_OUTVAL BIT(0)
> +
> +/*
> + * Output modes seem to differ depending on the PMU in use... ?
> + * j274 / M1 (Sera PMU):
> + * 0 = input
> + * 1 = output
> + * 2 = open drain
> + * 3 = disable
> + * j314 / M1Pro (Maverick PMU):
> + * 0 = input
> + * 1 = open drain
> + * 2 = output
> + * 3 = ?
> + */
> +
> +struct macsmc_gpio {
> + struct device *dev;
> + struct apple_smc *smc;
> + struct gpio_chip gc;
> +
> + int first_index;
> +};
> +
> +static int macsmc_gpio_nr(smc_key key)
> +{
> + int low = hex_to_bin(key & 0xff);
> + int high = hex_to_bin((key >> 8) & 0xff);
> +
> + if (low < 0 || high < 0)
> + return -1;
> +
> + return low | (high << 4);
> +}
> +
> +static int macsmc_gpio_key(unsigned int offset)
> +{
> + return _SMC_KEY("gP\0\0") | hex_asc_hi(offset) << 8 | hex_asc_lo(offset);
> +}
> +
> +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)
> + return -ENODEV;
> +
> + /* Binary search to find index of first SMC key bigger or equal to key */
> + start = 0;
> + count = smc->key_count;
> + while (count > 1) {
> + smc_key pkey;
> + int pivot = start + ((count - 1) >> 1);
> +
> + ret = apple_smc_get_key_by_index(smc, pivot, &pkey);
> + if (ret < 0)
> + return ret;
> +
> + if (pkey == key)
> + return pivot;
> +
> + pivot++;
> +
> + if (pkey < key) {
> + count -= pivot - start;
> + start = pivot;
> + } else {
> + count = pivot - start;
> + }
> + }
> +
> + return start;
> +}
> +
> +static int macsmc_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
> +{
> + struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
> + smc_key key = macsmc_gpio_key(offset);
> + u32 val;
> + int ret;
> +
> + /* First try reading the explicit pin mode register */
> + ret = apple_smc_rw_u32(smcgp->smc, key, CMD_PINMODE, &val);
> + if (!ret)
> + return (val & MODE_OUTPUT) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
> +
> + /*
> + * Less common IRQ configs cause CMD_PINMODE to fail, and so does open drain mode.
> + * Fall back to reading IRQ mode, which will only succeed for inputs.
> + */
> + ret = apple_smc_rw_u32(smcgp->smc, key, CMD_IRQ_MODE, &val);
> + return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
> +}
> +
> +static int macsmc_gpio_get(struct gpio_chip *gc, unsigned int offset)
> +{
> + struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
> + smc_key key = macsmc_gpio_key(offset);
> + u32 cmd, val;
> + int ret;
> +
> + ret = macsmc_gpio_get_direction(gc, offset);
> + if (ret < 0)
> + return ret;
> +
> + if (ret == GPIO_LINE_DIRECTION_OUT)
> + cmd = CMD_OUTPUT;
> + else
> + cmd = CMD_INPUT;
> +
> + ret = apple_smc_rw_u32(smcgp->smc, key, cmd, &val);
> + if (ret < 0)
> + return ret;
> +
> + return val ? 1 : 0;
> +}
> +
> +static int macsmc_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
> +{
> + struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
> + smc_key key = macsmc_gpio_key(offset);
> + int ret;
> +
> + value |= CMD_OUTPUT;
> + ret = apple_smc_write_u32(smcgp->smc, key, CMD_OUTPUT | value);
> + if (ret < 0)
> + dev_err(smcgp->dev, "GPIO set failed %p4ch = 0x%x\n",
> + &key, value);
> +
> + return ret;
> +}
> +
> +static int macsmc_gpio_init_valid_mask(struct gpio_chip *gc,
> + unsigned long *valid_mask, unsigned int ngpios)
> +{
> + struct macsmc_gpio *smcgp = gpiochip_get_data(gc);
> + int count;
> + int i;
> +
> + count = min(smcgp->smc->key_count, MAX_GPIO);
> +
> + bitmap_zero(valid_mask, ngpios);
> +
> + for (i = 0; i < count; i++) {
> + int ret, gpio_nr;
> + smc_key key;
> +
> + ret = apple_smc_get_key_by_index(smcgp->smc, smcgp->first_index + i, &key);
> + if (ret < 0)
> + return ret;
> +
> + if (key > SMC_KEY(gPff))
> + break;
> +
> + gpio_nr = macsmc_gpio_nr(key);
> + if (gpio_nr < 0 || gpio_nr > MAX_GPIO) {
> + dev_err(smcgp->dev, "Bad GPIO key %p4ch\n", &key);
> + continue;
> + }
> +
> + set_bit(gpio_nr, valid_mask);
> + }
> +
> + return 0;
> +}
> +
> +static int macsmc_gpio_probe(struct platform_device *pdev)
> +{
> + struct macsmc_gpio *smcgp;
> + struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
> + smc_key key;
> + int ret;
> +
> + smcgp = devm_kzalloc(&pdev->dev, sizeof(*smcgp), GFP_KERNEL);
> + if (!smcgp)
> + return -ENOMEM;
> +
> + smcgp->dev = &pdev->dev;
> + smcgp->smc = smc;
> +
> + smcgp->first_index = macsmc_gpio_find_first_gpio_index(smcgp);
> + if (smcgp->first_index < 0)
> + return smcgp->first_index;
> +
> + ret = apple_smc_get_key_by_index(smc, smcgp->first_index, &key);
> + if (ret < 0)
> + return ret;
> +
> + if (key > macsmc_gpio_key(MAX_GPIO - 1))
> + return -ENODEV;
> +
> + dev_info(smcgp->dev, "First GPIO key: %p4ch\n", &key);
> +
> + smcgp->gc.label = "macsmc-pmu-gpio";
> + smcgp->gc.owner = THIS_MODULE;
> + smcgp->gc.get = macsmc_gpio_get;
> + smcgp->gc.set_rv = macsmc_gpio_set;
> + smcgp->gc.get_direction = macsmc_gpio_get_direction;
> + smcgp->gc.init_valid_mask = macsmc_gpio_init_valid_mask;
> + smcgp->gc.can_sleep = true;
> + smcgp->gc.ngpio = MAX_GPIO;
> + smcgp->gc.base = -1;
> + smcgp->gc.parent = &pdev->dev;
> +
> + return devm_gpiochip_add_data(&pdev->dev, &smcgp->gc, smcgp);
> +}
> +
> +static const struct of_device_id macsmc_gpio_of_table[] = {
> + { .compatible = "apple,smc-gpio", },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, macsmc_gpio_of_table);
> +
> +static struct platform_driver macsmc_gpio_driver = {
> + .driver = {
> + .name = "macsmc-gpio",
> + .of_match_table = macsmc_gpio_of_table,
> + },
> + .probe = macsmc_gpio_probe,
> +};
> +module_platform_driver(macsmc_gpio_driver);
> +
> +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
> +MODULE_LICENSE("Dual MIT/GPL");
> +MODULE_DESCRIPTION("Apple SMC GPIO driver");
> +MODULE_ALIAS("platform:macsmc-gpio");
>
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller
2025-05-11 8:18 ` [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller Sven Peter via B4 Relay
@ 2025-05-11 16:51 ` Alyssa Rosenzweig
2025-05-12 11:18 ` Sven Peter
0 siblings, 1 reply; 24+ messages in thread
From: Alyssa Rosenzweig @ 2025-05-11 16:51 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Neal Gompa, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
> +struct apple_smc_key_info {
> + u8 size;
> + u32 type_code;
> + u8 flags;
> +};
This still has the padding problem from v4. With that fixed,
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
2025-05-11 10:07 ` Stefan Wahren
2025-05-11 16:44 ` Alyssa Rosenzweig
@ 2025-05-11 22:16 ` Sebastian Reichel
2025-05-12 15:41 ` Sven Peter
2 siblings, 1 reply; 24+ messages in thread
From: Sebastian Reichel @ 2025-05-11 22:16 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
Hi,
On Sun, May 11, 2025 at 08:18:42AM +0000, Sven Peter via B4 Relay wrote:
> From: Hector Martin <marcan@marcan.st>
>
> This driver implements the reboot/shutdown support exposed by the SMC
> on Apple Silicon machines, such as Apple M1 Macs.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> MAINTAINERS | 1 +
> drivers/power/reset/Kconfig | 11 ++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/macsmc-reboot.c | 363 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 376 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fa3a5f9ee40446bcc725c9eac2a36651e6bc7553..84f7a730eb2260b7c1e0487d18c8eb3de82f5206 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2303,6 +2303,7 @@ F: drivers/mfd/macsmc.c
> F: drivers/nvme/host/apple.c
> F: drivers/nvmem/apple-efuses.c
> F: drivers/pinctrl/pinctrl-apple-gpio.c
> +F: drivers/power/reset/macsmc-reboot.c
> F: drivers/pwm/pwm-apple.c
> F: drivers/soc/apple/*
> F: drivers/spi/spi-apple.c
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 60bf0ca64cf395cd18238fc626611c74d29844ee..6e8dfff64fdc001d09b6c00630cd8b7e2fafdd8e 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -128,6 +128,17 @@ config POWER_RESET_LINKSTATION
>
> Say Y here if you have a Buffalo LinkStation LS421D/E.
>
> +config POWER_RESET_MACSMC
> + tristate "Apple SMC reset/power-off driver"
> + depends on ARCH_APPLE || COMPILE_TEST
> + depends on MFD_MACSMC
> + depends on OF
This can also be 'OF || COMPILE_TEST'. But I would expect this
driver to just have 'depends on MFD_MACSMC' and then manage the
checks for ARCH_APPLE and OF in the MFD Kconfig.
> + help
> + This driver supports reset and power-off on Apple Mac machines
> + that implement this functionality via the SMC.
> +
> + Say Y here if you have an Apple Silicon Mac.
> +
> config POWER_RESET_MSM
> bool "Qualcomm MSM power-off driver"
> depends on ARCH_QCOM
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index 10782d32e1da39f4b8b4566e8a885f2e13f65130..887dd9e49b7293b69b9429ddc0c1571194a153cf 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
> obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
> obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
> obj-$(CONFIG_POWER_RESET_LINKSTATION) += linkstation-poweroff.o
> +obj-$(CONFIG_POWER_RESET_MACSMC) += macsmc-reboot.o
> obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
> obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
> obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
> diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..d82339e427886667be4ad2de0d1d5c04d2383059
> --- /dev/null
> +++ b/drivers/power/reset/macsmc-reboot.c
> @@ -0,0 +1,363 @@
> +// SPDX-License-Identifier: GPL-2.0-only OR MIT
> +/*
> + * Apple SMC Reboot/Poweroff Handler
> + * Copyright The Asahi Linux Contributors
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
> +#include <linux/of.h>
Once of_get_child_by_name() is no lnger used the correct include for
the remaining 'struct of_device_id' is <linux/mod_devicetable.h>
instead of <linux/of.h>.
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>
> +#include <linux/slab.h>
> +
> +struct macsmc_reboot_nvmem {
> + struct nvmem_cell *shutdown_flag;
> + struct nvmem_cell *pm_setting;
> + struct nvmem_cell *boot_stage;
> + struct nvmem_cell *boot_error_count;
> + struct nvmem_cell *panic_count;
> +};
> +
> +static const char * const nvmem_names[] = {
> + "shutdown_flag",
> + "pm_setting",
> + "boot_stage",
> + "boot_error_count",
> + "panic_count",
> +};
> +
> +enum boot_stage {
> + BOOT_STAGE_SHUTDOWN = 0x00, /* Clean shutdown */
> + BOOT_STAGE_IBOOT_DONE = 0x2f, /* Last stage of bootloader */
> + BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */
> +};
> +
> +enum pm_setting {
> + PM_SETTING_AC_POWER_RESTORE = 0x02,
> + PM_SETTING_AC_POWER_OFF = 0x03,
> +};
> +
> +static const char * const ac_power_modes[] = { "off", "restore" };
> +
> +static int ac_power_mode_map[] = {
> + PM_SETTING_AC_POWER_OFF,
> + PM_SETTING_AC_POWER_RESTORE,
> +};
> +
> +struct macsmc_reboot {
> + struct device *dev;
> + struct apple_smc *smc;
> + struct notifier_block reboot_notify;
> +
> + union {
> + struct macsmc_reboot_nvmem nvm;
> + struct nvmem_cell *nvm_cells[ARRAY_SIZE(nvmem_names)];
> + };
> +};
> +
> +/* Helpers to read/write a u8 given a struct nvmem_cell */
> +static int nvmem_cell_get_u8(struct nvmem_cell *cell)
> +{
> + size_t len;
> + u8 val;
> + void *ret = nvmem_cell_read(cell, &len);
> +
> + if (IS_ERR(ret))
> + return PTR_ERR(ret);
> +
> + if (len < 1) {
> + kfree(ret);
> + return -EINVAL;
> + }
> +
> + val = *(u8 *)ret;
> + kfree(ret);
> + return val;
> +}
> +
> +static int nvmem_cell_set_u8(struct nvmem_cell *cell, u8 val)
> +{
> + return nvmem_cell_write(cell, &val, sizeof(val));
> +}
> +
> +static ssize_t macsmc_ac_power_mode_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t n)
> +{
> + struct macsmc_reboot *reboot = dev_get_drvdata(dev);
> + int mode;
> + int ret;
> +
> + mode = sysfs_match_string(ac_power_modes, buf);
> + if (mode < 0)
> + return mode;
> +
> + ret = nvmem_cell_set_u8(reboot->nvm.pm_setting, ac_power_mode_map[mode]);
> + if (ret < 0)
> + return ret;
> +
> + return n;
> +}
> +
> +static ssize_t macsmc_ac_power_mode_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct macsmc_reboot *reboot = dev_get_drvdata(dev);
> + int len = 0;
> + int i;
> + int mode = nvmem_cell_get_u8(reboot->nvm.pm_setting);
> +
> + if (mode < 0)
> + return mode;
> +
> + for (i = 0; i < ARRAY_SIZE(ac_power_mode_map); i++) {
> + if (mode == ac_power_mode_map[i])
> + len += scnprintf(buf+len, PAGE_SIZE-len,
> + "[%s] ", ac_power_modes[i]);
> + else
> + len += scnprintf(buf+len, PAGE_SIZE-len,
> + "%s ", ac_power_modes[i]);
> + }
> +
> + buf[len-1] = '\n';
> + return len;
> +}
> +static DEVICE_ATTR(ac_power_mode, 0644, macsmc_ac_power_mode_show,
> + macsmc_ac_power_mode_store);
> +
> +/*
> + * SMC 'MBSE' key actions:
> + *
> + * 'offw' - shutdown warning
> + * 'slpw' - sleep warning
> + * 'rest' - restart warning
> + * 'off1' - shutdown (needs PMU bit set to stay on)
> + * 'susp' - suspend
> + * 'phra' - restart ("PE Halt Restart Action"?)
> + * 'panb' - panic beginning
> + * 'pane' - panic end
> + */
> +
> +static int macsmc_prepare_atomic(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Preparing SMC for atomic mode\n");
> +
> + apple_smc_enter_atomic(reboot->smc);
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_power_off(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Issuing power off (off1)\n");
> +
> + if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(off1)) < 0) {
> + dev_err(reboot->dev, "Failed to issue MBSE = off1 (power_off)\n");
> + } else {
> + mdelay(100);
> + WARN_ONCE(1, "Unable to power off system\n");
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_restart(struct sys_off_data *data)
> +{
> + struct macsmc_reboot *reboot = data->cb_data;
> +
> + dev_info(reboot->dev, "Issuing restart (phra)\n");
> +
> + if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(phra)) < 0) {
> + dev_err(reboot->dev, "Failed to issue MBSE = phra (restart)\n");
> + } else {
> + mdelay(100);
> + WARN_ONCE(1, "Unable to restart system\n");
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> +static int macsmc_reboot_notify(struct notifier_block *this, unsigned long action, void *data)
> +{
> + struct macsmc_reboot *reboot = container_of(this, struct macsmc_reboot, reboot_notify);
> + u32 val;
> + u8 shutdown_flag;
> +
> + switch (action) {
> + case SYS_RESTART:
> + val = SMC_KEY(rest);
> + shutdown_flag = 0;
> + break;
> + case SYS_POWER_OFF:
> + val = SMC_KEY(offw);
> + shutdown_flag = 1;
> + break;
> + default:
> + return NOTIFY_DONE;
> + }
> +
> + dev_info(reboot->dev, "Preparing for reboot (%p4ch)\n", &val);
> +
> + /* On the Mac Mini, this will turn off the LED for power off */
> + if (apple_smc_write_u32(reboot->smc, SMC_KEY(MBSE), val) < 0)
> + dev_err(reboot->dev, "Failed to issue MBSE = %p4ch (reboot_prepare)\n", &val);
> +
> + /* Set the boot_stage to 0, which means we're doing a clean shutdown/reboot. */
> + if (reboot->nvm.boot_stage &&
> + nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_SHUTDOWN) < 0)
> + dev_err(reboot->dev, "Failed to write boot_stage\n");
> +
> + /*
> + * Set the PMU flag to actually reboot into the off state.
> + * Without this, the device will just reboot. We make it optional in case it is no longer
> + * necessary on newer hardware.
> + */
> + if (reboot->nvm.shutdown_flag &&
> + nvmem_cell_set_u8(reboot->nvm.shutdown_flag, shutdown_flag) < 0)
> + dev_err(reboot->dev, "Failed to write shutdown_flag\n");
> +
> + return NOTIFY_OK;
> +}
> +
> +static void macsmc_power_init_error_counts(struct macsmc_reboot *reboot)
> +{
> + int boot_error_count, panic_count;
> +
> + if (!reboot->nvm.boot_error_count || !reboot->nvm.panic_count)
> + return;
> +
> + boot_error_count = nvmem_cell_get_u8(reboot->nvm.boot_error_count);
> + if (boot_error_count < 0) {
> + dev_err(reboot->dev, "Failed to read boot_error_count (%d)\n", boot_error_count);
> + return;
> + }
> +
> + panic_count = nvmem_cell_get_u8(reboot->nvm.panic_count);
> + if (panic_count < 0) {
> + dev_err(reboot->dev, "Failed to read panic_count (%d)\n", panic_count);
> + return;
> + }
> +
> + if (!boot_error_count && !panic_count)
> + return;
> +
> + dev_warn(reboot->dev, "PMU logged %d boot error(s) and %d panic(s)\n",
> + boot_error_count, panic_count);
> +
> + if (nvmem_cell_set_u8(reboot->nvm.panic_count, 0) < 0)
> + dev_err(reboot->dev, "Failed to reset panic_count\n");
> + if (nvmem_cell_set_u8(reboot->nvm.boot_error_count, 0) < 0)
> + dev_err(reboot->dev, "Failed to reset boot_error_count\n");
> +}
> +
> +static int macsmc_reboot_probe(struct platform_device *pdev)
> +{
> + struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
> + struct macsmc_reboot *reboot;
> + int ret, i;
> +
> + /* Ignore devices without this functionality */
> + if (!apple_smc_key_exists(smc, SMC_KEY(MBSE)))
> + return -ENODEV;
> +
> + reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
> + if (!reboot)
> + return -ENOMEM;
> +
> + reboot->dev = &pdev->dev;
> + reboot->smc = smc;
> +
> + platform_set_drvdata(pdev, reboot);
> +
> + pdev->dev.of_node = of_get_child_by_name(pdev->dev.parent->of_node, "reboot");
Why is this needed? The of_node should already be set correctly when
probed via the of_match_table.
> + for (i = 0; i < ARRAY_SIZE(nvmem_names); i++) {
> + struct nvmem_cell *cell;
> +
> + cell = devm_nvmem_cell_get(&pdev->dev,
> + nvmem_names[i]);
> + if (IS_ERR(cell)) {
> + if (PTR_ERR(cell) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + dev_warn(&pdev->dev, "Missing NVMEM cell %s (%ld)\n",
> + nvmem_names[i], PTR_ERR(cell));
> + /* Non fatal, we'll deal with it */
> + cell = NULL;
> + }
> + reboot->nvm_cells[i] = cell;
> + }
> +
> + /* Set the boot_stage to indicate we're running the OS kernel */
> + if (reboot->nvm.boot_stage &&
> + nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_KERNEL_STARTED) < 0)
> + dev_err(reboot->dev, "Failed to write boot_stage\n");
> +
> + /* Display and clear the error counts */
> + macsmc_power_init_error_counts(reboot);
> +
> + reboot->reboot_notify.notifier_call = macsmc_reboot_notify;
> +
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF_PREPARE,
> + SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register power-off prepare handler\n");
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_HIGH,
> + macsmc_power_off, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register power-off handler\n");
> +
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART_PREPARE,
> + SYS_OFF_PRIO_HIGH, macsmc_prepare_atomic, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to register restart prepare handler\n");
> + ret = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH,
> + macsmc_restart, reboot);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to register restart handler\n");
> +
> + ret = devm_register_reboot_notifier(&pdev->dev, &reboot->reboot_notify);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to register reboot notifier\n");
> +
> + dev_info(&pdev->dev, "Handling reboot and poweroff requests via SMC\n");
> +
> + if (device_create_file(&pdev->dev, &dev_attr_ac_power_mode))
> + dev_warn(&pdev->dev, "could not create sysfs file\n");
custom sysfs files must be documented in Documentation/ABI.
> +
> + return 0;
> +}
> +
> +static void macsmc_reboot_remove(struct platform_device *pdev)
> +{
> + device_remove_file(&pdev->dev, &dev_attr_ac_power_mode);
> +}
> +
> +static const struct of_device_id macsmc_reboot_of_table[] = {
> + { .compatible = "apple,smc-reboot", },Documentation/ABI
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, macsmc_reboot_of_table);
> +
> +static struct platform_driver macsmc_reboot_driver = {
> + .driver = {
> + .name = "macsmc-reboot",
> + .of_match_table = macsmc_reboot_of_table,
> + },
> + .probe = macsmc_reboot_probe,
> + .remove = macsmc_reboot_remove,
> +};
> +module_platform_driver(macsmc_reboot_driver);
> +
> +MODULE_LICENSE("Dual MIT/GPL");
> +MODULE_DESCRIPTION("Apple SMC reboot/poweroff driver");
> +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
> +MODULE_ALIAS("platform:macsmc-reboot");
Why is the MODULE_ALIAS needed?
Greetings,
-- Sebastian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller
2025-05-11 16:51 ` Alyssa Rosenzweig
@ 2025-05-12 11:18 ` Sven Peter
0 siblings, 0 replies; 24+ messages in thread
From: Sven Peter @ 2025-05-12 11:18 UTC (permalink / raw)
To: Alyssa Rosenzweig
Cc: Janne Grunau, Neal Gompa, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King, asahi, linux-arm-kernel, open list:GPIO SUBSYSTEM,
devicetree, linux-kernel, linux-pm
Hi,
On Sun, May 11, 2025, at 18:51, Alyssa Rosenzweig wrote:
>> +struct apple_smc_key_info {
>> + u8 size;
>> + u32 type_code;
>> + u8 flags;
>> +};
>
> This still has the padding problem from v4. With that fixed,
I somehow managed to drop two !fixup commits before sending this out :-(
One of them was moving type_code to the beginning and the other some cosmetic
changes (mainly starting descriptions with uppercase letters) to macsmc.h.
Will be fixed for the next version for real this time.
>
> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Thanks,
Sven
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 00/10] Apple Mac System Management Controller
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
` (9 preceding siblings ...)
2025-05-11 8:18 ` [PATCH v5 10/10] arm64: dts: apple: t600x: " Sven Peter via B4 Relay
@ 2025-05-12 12:25 ` Neal Gompa
10 siblings, 0 replies; 24+ messages in thread
From: Neal Gompa @ 2025-05-12 12:25 UTC (permalink / raw)
To: sven
Cc: Janne Grunau, Alyssa Rosenzweig, Hector Martin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm, Krzysztof Kozlowski
On Sun, May 11, 2025 at 4:19 AM Sven Peter via B4 Relay
<devnull+sven.svenpeter.dev@kernel.org> wrote:
>
> Hi,
>
> This series adds support for the System Management Controller found in
> Apple Silicon devices which we model as a mfd. It also includes support
> for the GPIO block and the power/reset block as sub-devices.
>
> Changes between v4 and v5:
> - Alyssa's comments:
> - Made the WARN_ON in the reboot driver more obvious
> - Added missing brackets around a for loop in the reboot driver
> - Used min instead of open-coded variant inside the gpio driver
> - Reoder struct memebers to prevent padding inside the mfd driver
> - Lee's comments:
> - All comments now start with an uppercase letter
> - Removed apple_smc_read_ioft_scaled and apple_smc_read_f32_scaled
> since these are not yet used and likely don't belong into
> drivers/mfd
> - Relaced if (ret != 0) with if (ret) when possible
> - Used devm_platform_get_and_ioremap_resource to get and map the
> SRAM resource
> - Used reverse Christmas-tree formating when declaring variables
> - Dropped _platform left-overs from probe and remove functions
> - Removed dev_dbg prints which are no long required after
> development
> - Reworked is_alive/is_initialized so that it's obvious how errors
> during boot are propagated from the callback to the probe function
> - Used dev_warn instead of dev_err in a few places
> - Removed no-op apple_smc_rtkit_shmem_destroy; this required an
> additional change in rtkit.c because we had a check there that's a
> bit too strict
> - Removed struct resource in apple_smc_rtkit_shmem_setup and
> open-coded resource_contains instead
> - Unwrapped lines with less than 100 chars
> - Made sure to compile with W=1 and ran scripts/kernel-doc -v
> on macsmc.h once and fixed any fallout
> - Removed first_key/last_key from struct smc and moved
> apple_smc_find_first_key_index to the gpio driver since it's only
> used there anyway to find the index of the first GPIO key (gP00)
> - Return -EIO when a command fails instead of whatever SMC returns
> which does not map to Linux errnos on errors
>
> Changes between v3 and v4:
> - Added documentation for all functions and structs
> - Fixed dt-bindings and re-ordered commits so that the mfd one comes
> last and can include the gpio subdevice
> - Added the reset driver and corresponding bindings
> - Reworked the atomic mode inside SMC since the previous implementation
> called mutex_lock from atomic context
> - Removed the backend split for now which lead to a quite intense discussion
> for the previous versions which hadn't been solved as far as I could tell
> from the old threads.
> It's also been 2+ years and I haven't heard of any backend implementation
> for T2 or even older macs. It's also unclear to me which sub-devices
> are actually useful there because at least GPIO and shutdown/reboot
> from this series will not work as-is there.
> I'd rather have this initial version which only supports M1+ macs upstream
> and then iterate there if any other backend is developed.
> I'll gladly help to re-introduce backend support if it's ever required.
>
> Dependencies:
> The code and dt-bindings themselves apply cleanly to 6.15-rc1 but
> the device tree changes require the already merged SPMI controller
> and SPMI NVMEM series which will be part of 6.16.
> The series is also using the printf format specifiers which will
> land in 6.16 via the drm-misc tree.
> A tree with all dependencies for testing is available at
> https://github.com/AsahiLinux/linux/commits/sven/smc-v5/.
>
> Merging:
> The dt-binding patches all depend on each other such that they all
> should probably go together with the mfd device itself.
> The following commits also depend on mfd due to the new header file and
> will either have to go through the mfd tree as well or we'll need an
> immutable branch there or we just wait one kernel release and I'll
> re-submit the rest then.
> I'll take the device tree updates through our tree which also has the
> previous device tree updates these depend on.
>
> v4: https://lore.kernel.org/asahi/20250503-smc-6-15-v4-0-500b9b6546fc@svenpeter.dev/
> v3: https://lore.kernel.org/asahi/Y2qEpgIdpRTzTQbN@shell.armlinux.org.uk/
> v2: https://lore.kernel.org/asahi/YxdInl2qzQWM+3bs@shell.armlinux.org.uk/
> v1: https://lore.kernel.org/asahi/YxC5eZjGgd8xguDr@shell.armlinux.org.uk/
>
> Best,
>
> Sven
>
> ---
> Hector Martin (5):
> gpio: Add new gpio-macsmc driver for Apple Macs
> power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
> arm64: dts: apple: t8103: Add SMC node
> arm64: dts: apple: t8112: Add SMC node
> arm64: dts: apple: t600x: Add SMC node
>
> Russell King (Oracle) (2):
> dt-bindings: gpio: Add Apple Mac SMC GPIO block
> dt-bindings: mfd: Add Apple Mac System Management Controller
>
> Sven Peter (3):
> dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller
> soc: apple: rtkit: Make shmem_destroy optional
> mfd: Add Apple Silicon System Management Controller
>
> .../devicetree/bindings/gpio/apple,smc-gpio.yaml | 37 ++
> .../devicetree/bindings/mfd/apple,smc.yaml | 71 +++
> .../bindings/power/reset/apple,smc-reboot.yaml | 52 +++
> MAINTAINERS | 7 +
> arch/arm64/boot/dts/apple/t600x-die0.dtsi | 35 ++
> arch/arm64/boot/dts/apple/t8103.dtsi | 35 ++
> arch/arm64/boot/dts/apple/t8112.dtsi | 35 ++
> drivers/gpio/Kconfig | 10 +
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-macsmc.c | 293 ++++++++++++
> drivers/mfd/Kconfig | 15 +
> drivers/mfd/Makefile | 1 +
> drivers/mfd/macsmc.c | 506 +++++++++++++++++++++
> drivers/power/reset/Kconfig | 11 +
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/macsmc-reboot.c | 363 +++++++++++++++
> drivers/soc/apple/rtkit.c | 3 +-
> include/linux/mfd/macsmc.h | 277 +++++++++++
> 18 files changed, 1751 insertions(+), 2 deletions(-)
> ---
> base-commit: 5abab6ab4ebacfff5857b63bd349902a6568d2e8
> change-id: 20250304-smc-6-15-f0ed619e31d4
>
Series overall looks good to me.
Reviewed-by: Neal Gompa <neal@gompa.dev>
--
真実はいつも一つ!/ Always, there's only one truth!
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC
2025-05-11 22:16 ` Sebastian Reichel
@ 2025-05-12 15:41 ` Sven Peter
0 siblings, 0 replies; 24+ messages in thread
From: Sven Peter @ 2025-05-12 15:41 UTC (permalink / raw)
To: Sebastian Reichel
Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Lee Jones, Marc Zyngier,
Russell King, asahi, linux-arm-kernel, open list:GPIO SUBSYSTEM,
devicetree, linux-kernel, linux-pm
Hi Sebastian,
thanks for the review!
On Mon, May 12, 2025, at 00:16, Sebastian Reichel wrote:
> Hi,
>
> On Sun, May 11, 2025 at 08:18:42AM +0000, Sven Peter via B4 Relay wrote:
>> From: Hector Martin <marcan@marcan.st>
>>
>> This driver implements the reboot/shutdown support exposed by the SMC
>> on Apple Silicon machines, such as Apple M1 Macs.
>>
>> Signed-off-by: Hector Martin <marcan@marcan.st>
>> Signed-off-by: Sven Peter <sven@svenpeter.dev>
>> ---
>> MAINTAINERS | 1 +
>> drivers/power/reset/Kconfig | 11 ++
>> drivers/power/reset/Makefile | 1 +
>> drivers/power/reset/macsmc-reboot.c | 363 ++++++++++++++++++++++++++++++++++++
>> 4 files changed, 376 insertions(+)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index fa3a5f9ee40446bcc725c9eac2a36651e6bc7553..84f7a730eb2260b7c1e0487d18c8eb3de82f5206 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -2303,6 +2303,7 @@ F: drivers/mfd/macsmc.c
>> F: drivers/nvme/host/apple.c
>> F: drivers/nvmem/apple-efuses.c
>> F: drivers/pinctrl/pinctrl-apple-gpio.c
>> +F: drivers/power/reset/macsmc-reboot.c
>> F: drivers/pwm/pwm-apple.c
>> F: drivers/soc/apple/*
>> F: drivers/spi/spi-apple.c
>> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
>> index 60bf0ca64cf395cd18238fc626611c74d29844ee..6e8dfff64fdc001d09b6c00630cd8b7e2fafdd8e 100644
>> --- a/drivers/power/reset/Kconfig
>> +++ b/drivers/power/reset/Kconfig
>> @@ -128,6 +128,17 @@ config POWER_RESET_LINKSTATION
>>
>> Say Y here if you have a Buffalo LinkStation LS421D/E.
>>
>> +config POWER_RESET_MACSMC
>> + tristate "Apple SMC reset/power-off driver"
>> + depends on ARCH_APPLE || COMPILE_TEST
>> + depends on MFD_MACSMC
>> + depends on OF
>
> This can also be 'OF || COMPILE_TEST'. But I would expect this
> driver to just have 'depends on MFD_MACSMC' and then manage the
> checks for ARCH_APPLE and OF in the MFD Kconfig.
Makes sense, it'll just depend on MFD_MACSMC then and I'll move the ARCH_APPLE,
OF, etc. depends to the MFD Kconfig.
>
[...]
>> +#include <linux/delay.h>
>> +#include <linux/mfd/core.h>
>> +#include <linux/mfd/macsmc.h>
>> +#include <linux/module.h>
>> +#include <linux/nvmem-consumer.h>
>> +#include <linux/of.h>
>
> Once of_get_child_by_name() is no lnger used the correct include for
> the remaining 'struct of_device_id' is <linux/mod_devicetable.h>
> instead of <linux/of.h>.
Fixed.
>
[...]
>> +
>> + pdev->dev.of_node = of_get_child_by_name(pdev->dev.parent->of_node, "reboot");
>
> Why is this needed? The of_node should already be set correctly when
> probed via the of_match_table.
Leftovers from a previous version that didn't use of_match_table.
I'll remove it.
>
[...]
>> +
>> + if (device_create_file(&pdev->dev, &dev_attr_ac_power_mode))
>> + dev_warn(&pdev->dev, "could not create sysfs file\n");
>
> custom sysfs files must be documented in Documentation/ABI.
This sysfs file allows to configure if the system reboots automatically after
power loss. But now that I'm looking at this again I'm not sure this driver
is even the proper place for this (the nvmem cell is kinda unrelated to SMC)
or if we need this at all in the kernel since the nvmem cell is already
exposed to sysfs just with a less convenient interface at
/sys/bus/nvmem/devices/spmi_nvmem0/cells/pm-setting@d001,0.
I'm going to drop it for now and revisit this later.
>
>> +
[...]
>> +MODULE_LICENSE("Dual MIT/GPL");
>> +MODULE_DESCRIPTION("Apple SMC reboot/poweroff driver");
>> +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
>> +MODULE_ALIAS("platform:macsmc-reboot");
>
> Why is the MODULE_ALIAS needed?
No idea, my best guess is it was copy/pasted without a good reason.
I'll drop it.
Thanks,
Sven
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller
2025-05-11 8:18 ` [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller Sven Peter via B4 Relay
@ 2025-05-14 20:55 ` Rob Herring
0 siblings, 0 replies; 24+ messages in thread
From: Rob Herring @ 2025-05-14 20:55 UTC (permalink / raw)
To: Sven Peter
Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm, Krzysztof Kozlowski
On Sun, May 11, 2025 at 08:18:38AM +0000, Sven Peter wrote:
> From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
>
> Add a DT binding for the Apple Mac System Management Controller.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> .../devicetree/bindings/mfd/apple,smc.yaml | 71 ++++++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 72 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
> new file mode 100644
> index 0000000000000000000000000000000000000000..9f1058c15bbf62d84f8a72fdaa354909b02e2801
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
> @@ -0,0 +1,71 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/apple,smc.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Apple Mac System Management Controller
> +
> +maintainers:
> + - Sven Peter <sven@svenpeter.dev>
> +
> +description:
> + Apple Mac System Management Controller implements various functions
> + such as GPIO, RTC, power, reboot.
> +
> +properties:
> + compatible:
> + items:
> + - enum:
> + - apple,t6000-smc
> + - apple,t8103-smc
> + - apple,t8112-smc
> + - const: apple,smc
> +
> + reg:
> + items:
> + - description: SMC area
> + - description: SRAM area
> +
> + reg-names:
> + items:
> + - const: smc
> + - const: sram
> +
> + mboxes:
> + maxItems: 1
> +
> + gpio:
> + $ref: /schemas/gpio/apple,smc-gpio.yaml
> +
> + reboot:
> + $ref: /schemas/power/reset/apple,smc-reboot.yaml
> +
> +additionalProperties: false
> +
> +required:
> + - compatible
> + - reg
> + - reg-names
> + - mboxes
> +
> +examples:
> + - |
> + soc {
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + smc@23e400000 {
> + compatible = "apple,t8103-smc", "apple,smc";
> + reg = <0x2 0x3e400000 0x0 0x4000>,
> + <0x2 0x3fe00000 0x0 0x100000>;
> + reg-names = "smc", "sram";
> + mboxes = <&smc_mbox>;
> +
> + smc_gpio: gpio {
> + compatible = "apple,smc-gpio";
> + gpio-controller;
> + #gpio-cells = <2>;
> + };
> + };
If there's another version, please make the example here complete and
drop the other incomplete examples in the child bindings.
Rob
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block
2025-05-11 8:18 ` [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block Sven Peter via B4 Relay
@ 2025-05-14 20:55 ` Rob Herring (Arm)
0 siblings, 0 replies; 24+ messages in thread
From: Rob Herring (Arm) @ 2025-05-14 20:55 UTC (permalink / raw)
To: Sven Peter
Cc: Russell King (Oracle), asahi, linux-pm, Hector Martin,
Marc Zyngier, Krzysztof Kozlowski, Conor Dooley, linux-arm-kernel,
Bartosz Golaszewski, devicetree, Janne Grunau, Lee Jones,
Alyssa Rosenzweig, linux-kernel, Sebastian Reichel, Linus Walleij,
Neal Gompa, linux-gpio
On Sun, 11 May 2025 08:18:36 +0000, Sven Peter wrote:
> From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
>
> Add the DT binding for the Apple Mac System Management Controller GPIOs.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> .../devicetree/bindings/gpio/apple,smc-gpio.yaml | 37 ++++++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 38 insertions(+)
>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller
2025-05-11 8:18 ` [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller Sven Peter via B4 Relay
@ 2025-05-14 20:56 ` Rob Herring
0 siblings, 0 replies; 24+ messages in thread
From: Rob Herring @ 2025-05-14 20:56 UTC (permalink / raw)
To: Sven Peter
Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Hector Martin,
Linus Walleij, Bartosz Golaszewski, Krzysztof Kozlowski,
Conor Dooley, Sebastian Reichel, Lee Jones, Marc Zyngier,
Russell King (Oracle), asahi, linux-arm-kernel, linux-gpio,
devicetree, linux-kernel, linux-pm
On Sun, May 11, 2025 at 08:18:37AM +0000, Sven Peter wrote:
> On Apple Silicon machines a clean shutdown or reboot requires
> talking to SMC and writing to NVMEM cells. Add a binding for
> this MFD sub-device.
>
> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> .../bindings/power/reset/apple,smc-reboot.yaml | 52 ++++++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 53 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml b/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
> new file mode 100644
> index 0000000000000000000000000000000000000000..e55e524914c2f57f7acf239fdefcbdc7a993b69f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
> @@ -0,0 +1,52 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/power/reset/apple,smc-reboot.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Apple SMC Reboot Controller
> +
> +description: |
Don't need '|' here.
> + The Apple System Management Controller (SMC) provides reboot functionality
> + on Apple Silicon SoCs. It uses NVMEM cells to store and track various
> + system state information related to boot, shutdown, and panic events.
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2025-05-14 20:56 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-11 8:18 [PATCH v5 00/10] Apple Mac System Management Controller Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 01/10] dt-bindings: gpio: Add Apple Mac SMC GPIO block Sven Peter via B4 Relay
2025-05-14 20:55 ` Rob Herring (Arm)
2025-05-11 8:18 ` [PATCH v5 02/10] dt-bindings: power: reboot: Add Apple Mac SMC Reboot Controller Sven Peter via B4 Relay
2025-05-14 20:56 ` Rob Herring
2025-05-11 8:18 ` [PATCH v5 03/10] dt-bindings: mfd: Add Apple Mac System Management Controller Sven Peter via B4 Relay
2025-05-14 20:55 ` Rob Herring
2025-05-11 8:18 ` [PATCH v5 04/10] soc: apple: rtkit: Make shmem_destroy optional Sven Peter via B4 Relay
2025-05-11 16:42 ` Alyssa Rosenzweig
2025-05-11 8:18 ` [PATCH v5 05/10] mfd: Add Apple Silicon System Management Controller Sven Peter via B4 Relay
2025-05-11 16:51 ` Alyssa Rosenzweig
2025-05-12 11:18 ` Sven Peter
2025-05-11 8:18 ` [PATCH v5 06/10] gpio: Add new gpio-macsmc driver for Apple Macs Sven Peter via B4 Relay
2025-05-11 16:45 ` Alyssa Rosenzweig
2025-05-11 8:18 ` [PATCH v5 07/10] power: reset: macsmc-reboot: Add driver for rebooting via Apple SMC Sven Peter via B4 Relay
2025-05-11 10:07 ` Stefan Wahren
2025-05-11 10:14 ` Sven Peter
2025-05-11 16:44 ` Alyssa Rosenzweig
2025-05-11 22:16 ` Sebastian Reichel
2025-05-12 15:41 ` Sven Peter
2025-05-11 8:18 ` [PATCH v5 08/10] arm64: dts: apple: t8103: Add SMC node Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 09/10] arm64: dts: apple: t8112: " Sven Peter via B4 Relay
2025-05-11 8:18 ` [PATCH v5 10/10] arm64: dts: apple: t600x: " Sven Peter via B4 Relay
2025-05-12 12:25 ` [PATCH v5 00/10] Apple Mac System Management Controller Neal Gompa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).