mfd: macsmc: add rtc, hwmon and hid subdevices
Subsystems (7)
v2 cover mfd: macsmc: add rtc, hwmon and hid subdevices
Hi all,
This series adds support for the remaining SMC subdevices. These are the RTC, hwmon, and HID devices. They are being submitted together as the RTC and hwmon drivers both require changes to the SMC DT schema.
The RTC driver is responsible for getting and setting the system clock, and requires an NVMEM cell. This series replaces Sven's original RTC driver submission [1].
The hwmon function is an interesting one. While each Apple Silicon device exposes pretty similar sets of sensors, these all seem to be paired to different SMC keys in the firmware interface. This is true even when the sensors are on the SoC. For example, an M1 MacBook Pro will use different keys to access the LITTLE core temperature sensors to an M1 Mac mini. This necessitates describing which keys correspond to which sensors for each device individually, and populating the hwmon structs at runtime. We do this with a node in the device tree. This series includes only the keys for sensors which we know to be common to all devices. The SMC is also responsible for monitoring and controlling fan speeds on systems with fans, which we expose via the hwmon driver.
The SMC also handles the hardware power button and lid switch. Power button presses and lid opening/closing are emitted as HID events, so we add a HID subdevice to handle them.
Note that this series is based on a branch with three additional commits applied to add the parent SMC nodes to the relevant Devicetrees. This was done to silence build errors. The series applies cleanly to 6.17-rc1.
Regards,
James
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Addressed Guenter's initial feedback on the hwmon driver
- Modified hwmon driver to reflect DT schema changes
- Added compatible property to hwmon node
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Hector Martin (2):
rtc: Add new rtc-macsmc driver for Apple Silicon Macs
input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lid
James Calligeros (7):
dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
mfd: macsmc: Wire up Apple SMC RTC subdevice
hwmon: Add Apple Silicon SMC hwmon driver
mfd: macsmc: Wire up Apple SMC hwmon subdevice
mfd: macsmc: Wire up Apple SMC HID subdevice
arm64: dts: apple: Add common hwmon sensors and fans
arm64: dts: apple: t8103, t600x, t8112: Add common hwmon nodes to devices
Sven Peter (2):
dt-bindings: rtc: Add Apple SMC RTC
arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node
.../bindings/hwmon/apple,smc-hwmon.yaml | 132 ++++ .../bindings/mfd/apple,smc.yaml | 45 ++ .../bindings/rtc/apple,smc-rtc.yaml | 35 + MAINTAINERS | 5 + .../boot/dts/apple/hwmon-common.dtsi | 37 ++ .../boot/dts/apple/hwmon-fan-dual.dtsi | 24 + arch/arm64/boot/dts/apple/hwmon-fan.dtsi | 19 + .../boot/dts/apple/hwmon-laptop.dtsi | 35 + .../boot/dts/apple/hwmon-mac-mini.dtsi | 17 + .../arm64/boot/dts/apple/t6001-j375c.dts | 2 + .../arm64/boot/dts/apple/t6002-j375d.dts | 2 + .../arm64/boot/dts/apple/t600x-die0.dtsi | 6 + .../boot/dts/apple/t600x-j314-j316.dtsi | 4 + .../arm64/boot/dts/apple/t600x-j375.dtsi | 2 + arch/arm64/boot/dts/apple/t8103-j274.dts | 2 + arch/arm64/boot/dts/apple/t8103-j293.dts | 3 + arch/arm64/boot/dts/apple/t8103-j313.dts | 2 + arch/arm64/boot/dts/apple/t8103-j456.dts | 2 + arch/arm64/boot/dts/apple/t8103-j457.dts | 2 + .../arm64/boot/dts/apple/t8103-jxxx.dtsi | 2 + arch/arm64/boot/dts/apple/t8103.dtsi | 6 + arch/arm64/boot/dts/apple/t8112-j413.dts | 2 + arch/arm64/boot/dts/apple/t8112-j473.dts | 2 + arch/arm64/boot/dts/apple/t8112-j493.dts | 3 + .../arm64/boot/dts/apple/t8112-jxxx.dtsi | 2 + arch/arm64/boot/dts/apple/t8112.dtsi | 6 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/macsmc_hwmon.c | 848 +++++++++++++++++++++++++ drivers/input/misc/Kconfig | 11 + drivers/input/misc/Makefile | 1 + drivers/input/misc/macsmc-hid.c | 209 ++++++ drivers/mfd/macsmc.c | 3 + drivers/rtc/Kconfig | 11 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-macsmc.c | 141 ++++ 36 files changed, 1637 insertions(+)
---
base-commit: 876d6a70b24869f96ebc8672caf86cb4bae72927
change-id: 20250816-macsmc-subdevs-87032c017d0c
Best regards,
Signature · 1 line
James Calligeros <[email protected]>
PATCH v2 1/11 dt-bindings: rtc: Add Apple SMC RTC
From: Sven Peter <[email protected]>
Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC, but most of the PMU functionality is abstracted out by the SMC. An additional RTC offset stored inside NVMEM is required to compute the current date/time.
--- .../bindings/mfd/apple,smc.yaml | 9 +++++++ .../bindings/rtc/apple,smc-rtc.yaml | 35 +++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 45 insertions(+)
Documentation/devicetree/bindings/mfd/apple,smc.yaml +9 -0
@@ -41,6 +41,9 @@ properties: reboot: $ref: /schemas/power/reset/apple,smc-reboot.yaml + rtc: + $ref: /schemas/rtc/apple,smc-rtc.yaml + additionalProperties: false required:
@@ -75,5 +78,11 @@ examples: nvmem-cell-names = "shutdown_flag", "boot_stage", "boot_error_count", "panic_count"; }; + + rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; }; };
Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/rtc/apple,smc-rtc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple SMC RTC + +description: + Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC, + but most of the PMU functionality is abstracted out by the SMC. + An additional RTC offset stored inside NVMEM is required to compute + the current date/time. + +maintainers: + - Sven Peter <[email protected]> + +properties: + compatible: + const: apple,smc-rtc + + nvmem-cells: + items: + - description: 48bit RTC offset, specified in 32768 (2^15) Hz clock ticks + + nvmem-cell-names: + items: + - const: rtc_offset + +required: + - compatible + - nvmem-cells + - nvmem-cell-names + +additionalProperties: false
MAINTAINERS +1 -0
@@ -2397,6 +2397,7 @@ 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/rtc/apple,smc-rtc.yaml F: Documentation/devicetree/bindings/spi/apple,spi.yaml F: Documentation/devicetree/bindings/spmi/apple,spmi.yaml F: Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
Signature · 1 line
2.51.0
PATCH v2 2/11 dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
In reply to James CalligerosApple Silicon devices integrate a vast array of sensors, monitoring current, power, temperature, and voltage across almost every part of the system. The sensors themselves are all connected to the System Management Controller (SMC). The SMC firmware exposes the data reported by these sensors via its standard FourCC-based key-value API. The SMC is also responsible for monitoring and controlling any fans connected to the system, exposing them in the same way.
For reasons known only to Apple, each device exposes its sensors with an almost totally unique set of keys. This is true even for devices which share an SoC. An M1 Mac mini, for example, will report its core temperatures on different keys to an M1 MacBook Pro. Worse still, the SMC does not provide a way to enumerate the available keys at runtime, nor do the keys follow any sort of reasonable or consistent naming rules that could be used to deduce their purpose. We must therefore know which keys are present on any given device, and which function they serve, ahead of time.
Add a schema so that we can describe the available sensors for a given Apple Silicon device in the Devicetree.
--- .../bindings/hwmon/apple,smc-hwmon.yaml | 132 +++++++++++++++++++++++++ .../bindings/mfd/apple,smc.yaml | 36 +++++++ MAINTAINERS | 1 + 3 files changed, 169 insertions(+)
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +132 -0
@@ -0,0 +1,132 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/apple,smc-hwmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple SMC Hardware Monitoring + +description: + Apple's System Management Controller (SMC) exposes a vast array of + hardware monitoring sensors, including temperature probes, current and + voltage sense, power meters, and fan speeds. It also provides endpoints + to manually control the speed of each fan individually. Each Apple + Silicon device exposes a different set of endpoints via SMC keys. This + is true even when two machines share an SoC. The CPU core temperature + sensor keys on an M1 Mac mini are different to those on an M1 MacBook + Pro, for example. + +maintainers: + - James Calligeros <[email protected]> + +definitions: + apple,key-id: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: The SMC FourCC key of the desired sensor. + Must match the node's suffix. + + label: + description: Human-readable name for the sensor + +properties: + compatible: + const: apple,smc-hwmon + +patternProperties: + "^current-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^fan-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + apple,fan-minimum: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: SMC key containing the fan's minimum speed + + apple,fan-maximum: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: SMC key containing the fan's maximum speed + + apple,fan-target: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: Writeable endpoint for setting desired fan speed + + apple,fan-mode: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: Writeable key to enable/disable manual fan control + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^power-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^temperature-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^voltage-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + +additionalProperties: false
Documentation/devicetree/bindings/mfd/apple,smc.yaml +36 -0
@@ -44,6 +44,9 @@ properties: rtc: $ref: /schemas/rtc/apple,smc-rtc.yaml + hwmon: + $ref: /schemas/hwmon/apple,smc-hwmon.yaml + additionalProperties: false required:
@@ -84,5 +87,38 @@ examples: nvmem-cells = <&rtc_offset>; nvmem-cell-names = "rtc_offset"; }; + + hwmon { + compatible = "apple,smc-hwmon"; + + current-ID0R { + apple,key-id = "ID0R"; + label = "AC Input Current"; + }; + + fan-F0Ac { + apple,key-id = "F0Ac"; + apple,fan-minimum = "F0Mn"; + apple,fan-maximum = "F0Mx"; + apple,fan-target = "F0Tg"; + apple,fan-mode = "F0Md"; + label = "Fan 1"; + }; + + power-PSTR { + apple,key-id = "PSTR"; + label = "Total System Power"; + }; + + temperature-TW0P { + apple,key-id = "TW0P"; + label = "WiFi/BT Module Temperature"; + }; + + voltage-VD0R { + apple,key-id = "VD0R"; + label = "AC Input Voltage"; + }; + }; }; };
MAINTAINERS +1 -0
@@ -2380,6 +2380,7 @@ 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/gpu/apple,agx.yaml +F: Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.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,*
Signature · 1 line
2.51.0
Rob Herring
maintainerRe: [PATCH v2 02/11] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
Quoted 46 lines · James Calligeros
Apple Silicon devices integrate a vast array of sensors, monitoring current, power, temperature, and voltage across almost every part of the system. The sensors themselves are all connected to the System Management Controller (SMC). The SMC firmware exposes the data reported by these sensors via its standard FourCC-based key-value API. The SMC is also responsible for monitoring and controlling any fans connected to the system, exposing them in the same way.
For reasons known only to Apple, each device exposes its sensors with an almost totally unique set of keys. This is true even for devices which share an SoC. An M1 Mac mini, for example, will report its core temperatures on different keys to an M1 MacBook Pro. Worse still, the SMC does not provide a way to enumerate the available keys at runtime, nor do the keys follow any sort of reasonable or consistent naming rules that could be used to deduce their purpose. We must therefore know which keys are present on any given device, and which function they serve, ahead of time.
Add a schema so that we can describe the available sensors for a given Apple Silicon device in the Devicetree.
Signed-off-by James Calligeros <[email protected]>--- .../bindings/hwmon/apple,smc-hwmon.yaml | 132 +++++++++++++++++++++++++ .../bindings/mfd/apple,smc.yaml | 36 +++++++ MAINTAINERS | 1 + 3 files changed, 169 insertions(+)Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +12
-0@@ -0,0 +1,132 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/apple,smc-hwmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple SMC Hardware Monitoring + +description: + Apple's System Management Controller (SMC) exposes a vast array of + hardware monitoring sensors, including temperature probes, current and + voltage sense, power meters, and fan speeds. It also provides endpoints
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml line 22
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +10
-0+ to manually control the speed of each fan individually. Each Apple + Silicon device exposes a different set of endpoints via SMC keys. This + is true even when two machines share an SoC. The CPU core temperature + sensor keys on an M1 Mac mini are different to those on an M1 MacBook + Pro, for example. + +maintainers: + - James Calligeros <[email protected]> + +definitions:
$defs
definitions was convention. $defs is in json-schema spec now.
Quoted 18 lines
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +18
-0+ apple,key-id: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: The SMC FourCC key of the desired sensor. + Must match the node's suffix. + + label: + description: Human-readable name for the sensor + +properties: + compatible: + const: apple,smc-hwmon + +patternProperties: + "^current-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false +
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +10
-0+ properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label
This should be something like this:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor"
unevaluatedProperties: false
With the $defs/sensor being:
$defs:
sensor:
type: object
properties:
apple,key-id:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[A-Za-z0-9]{4}$"
description:
The SMC FourCC key of the desired sensor. Must match the node's suffix.
label:
description: Human-readable name for the sensor
required:
- apple,key-id
- label
Though in general, 'label' should never be required being just for human convenience.
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml line 54
Quoted 4 lines
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +4
-0+ + "^fan-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false
And this one the same as above, but with the additional fan properties listed here.
Quoted 78 lines
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +78
-0+ + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + apple,fan-minimum: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: SMC key containing the fan's minimum speed + + apple,fan-maximum: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: SMC key containing the fan's maximum speed + + apple,fan-target: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: Writeable endpoint for setting desired fan speed + + apple,fan-mode: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[A-Za-z0-9]{4}$" + description: Writeable key to enable/disable manual fan control + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^power-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^temperature-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + + "^voltage-[A-Za-z0-9]{4}$": + type: object + additionalProperties: false + + properties: + apple,key-id: + $ref: "#/definitions/apple,key-id" + + label: + $ref: "#/definitions/label" + + required: + - apple,key-id + - label + +additionalProperties: false
Janne Grunau
maintainerRe: [PATCH v2 02/11] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
Quoted 59 lines · Rob Herring
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml
Quoted 34 lines · James Calligeros
Apple Silicon devices integrate a vast array of sensors, monitoring current, power, temperature, and voltage across almost every part of the system. The sensors themselves are all connected to the System Management Controller (SMC). The SMC firmware exposes the data reported by these sensors via its standard FourCC-based key-value API. The SMC is also responsible for monitoring and controlling any fans connected to the system, exposing them in the same way.
For reasons known only to Apple, each device exposes its sensors with an almost totally unique set of keys. This is true even for devices which share an SoC. An M1 Mac mini, for example, will report its core temperatures on different keys to an M1 MacBook Pro. Worse still, the SMC does not provide a way to enumerate the available keys at runtime, nor do the keys follow any sort of reasonable or consistent naming rules that could be used to deduce their purpose. We must therefore know which keys are present on any given device, and which function they serve, ahead of time.
Add a schema so that we can describe the available sensors for a given Apple Silicon device in the Devicetree.
Signed-off-by James Calligeros <[email protected]>--- .../bindings/hwmon/apple,smc-hwmon.yaml | 132 +++++++++++++++++++++++++ .../bindings/mfd/apple,smc.yaml | 36 +++++++ MAINTAINERS | 1 + 3 files changed, 169 insertions(+)Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +0
-0@@ -0,0 +1,132 @@This should be something like this:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor"
unevaluatedProperties: falseWith the $defs/sensor being:
$defs:
sensor:
type: objectproperties:
apple,key-id:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[A-Za-z0-9]{4}$"
description:
The SMC FourCC key of the desired sensor. Must match the node's suffix.label:
description: Human-readable name for the sensor
Quoted 6 lines
required:
- apple,key-id
- labelThough in general, 'label' should never be required being just for human convenience.
That does not sound as it would be compatible with skipping nodes in the driver if the node misses label. The driver could of course fall back to create a hwmon sensors without labels. I looks to me it would be a stretch to call the presence of the labels human convenience.
Janne
Rob Herring
maintainerRe: [PATCH v2 02/11] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
Quoted 65 lines · Janne Grunau
Quoted 63 lines · Rob Herring
Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml
Quoted 34 lines · James Calligeros
Apple Silicon devices integrate a vast array of sensors, monitoring current, power, temperature, and voltage across almost every part of the system. The sensors themselves are all connected to the System Management Controller (SMC). The SMC firmware exposes the data reported by these sensors via its standard FourCC-based key-value API. The SMC is also responsible for monitoring and controlling any fans connected to the system, exposing them in the same way.
For reasons known only to Apple, each device exposes its sensors with an almost totally unique set of keys. This is true even for devices which share an SoC. An M1 Mac mini, for example, will report its core temperatures on different keys to an M1 MacBook Pro. Worse still, the SMC does not provide a way to enumerate the available keys at runtime, nor do the keys follow any sort of reasonable or consistent naming rules that could be used to deduce their purpose. We must therefore know which keys are present on any given device, and which function they serve, ahead of time.
Add a schema so that we can describe the available sensors for a given Apple Silicon device in the Devicetree.
Signed-off-by James Calligeros <[email protected]>--- .../bindings/hwmon/apple,smc-hwmon.yaml | 132 +++++++++++++++++++++++++ .../bindings/mfd/apple,smc.yaml | 36 +++++++ MAINTAINERS | 1 + 3 files changed, 169 insertions(+)Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml new file +0
-0@@ -0,0 +1,132 @@This should be something like this:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor"
unevaluatedProperties: falseWith the $defs/sensor being:
$defs:
sensor:
type: objectproperties:
apple,key-id:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[A-Za-z0-9]{4}$"
description:
The SMC FourCC key of the desired sensor. Must match the node's suffix.label:
description: Human-readable name for the sensorrequired:
- apple,key-id
- label
Quoted 6 lines
Quoted 2 lines
Though in general, 'label' should never be required being just for human convenience.
That does not sound as it would be compatible with skipping nodes in the driver if the node misses label. The driver could of course fall back to create a hwmon sensors without labels.
The driver absolutely should.
Quoted 2 lines
I looks to me it would be a
stretch to call the presence of the labels human convenience.
Then it is an abuse of 'label". "label" is supposed to be literally that. Matching a sticker on a port of a device.
If you need to associate a sensor with some other piece of h/w, then that should be via a phandle or something.
Rob
Re: [PATCH v2 02/11] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
Hi Rob,
Quoted 31 lines · Australian Eastern Standard Time Rob Herring
Quoted 30 lines · Janne Grunau
Quoted 29 lines · Rob Herring
This should be something like this:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor"
unevaluatedProperties: falseWith the $defs/sensor being:
$defs:
sensor:
type: objectproperties:
apple,key-id:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[A-Za-z0-9]{4}$"description:
The SMC FourCC key of the desired sensor. Must match the node's suffix.label:
description: Human-readable name for the sensorrequired:
- apple,key-id
- label
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Though in general, 'label' should never be required being just for human convenience.
That does not sound as it would be compatible with skipping nodes in the driver if the node misses label. The driver could of course fall back to create a hwmon sensors without labels.
The driver absolutely should.
The original submission (and our downstream version) do this, but I changed it for v2 per Sven's feedback [1]. Outside of development/experimentation, we will (should) never have a sensor in the Devicetree of uknown utility. If we know what a sensor is for, then we should have a label for it.
Quoted 8 lines
Quoted 2 lines
I looks to me it would be a
stretch to call the presence of the labels human convenience.Then it is an abuse of 'label". "label" is supposed to be literally that. Matching a sticker on a port of a device.
If you need to associate a sensor with some other piece of h/w, then that should be via a phandle or something.
I don't think doing so is particularly useful for this platform. Few of the sensors that we know about are directly related to any one piece of hardware.
It's pretty much just the CPU cores and Broadcom module. The rest are things like fans, palm rest area temperature sensors, ammeters and voltmeters for entire
rails, etc.
Even where we can reliably associate a sensor to a piece of hardware, (e.g. the WiFi/BT board), doing so does not by itself do anything useful. We still need to write a human-readable label for the sensor.
I was trying to avoid yet another vendor property, but would something like 'apple,sensor-label' work here?
Quoted 1 line
Rob
James
Guenter Roeck
maintainerRe: [PATCH v2 02/11] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
Quoted 42 lines · James Calligeros
Hi Rob,
Quoted 38 lines · Australian Eastern Standard Time Rob Herring
Quoted 36 lines · Janne Grunau
Quoted 25 lines · Rob Herring
This should be something like this:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor" unevaluatedProperties: falseWith the $defs/sensor being:
$defs:
sensor:
type: objectproperties:
apple,key-id:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[A-Za-z0-9]{4}$"description:
The SMC FourCC key of the desired sensor. Must match the node's suffix.label:
description: Human-readable name for the sensorQuoted 6 lines
required:
- apple,key-id
- labelThough in general, 'label' should never be required being just for human convenience.
That does not sound as it would be compatible with skipping nodes in the driver if the node misses label. The driver could of course fall back to create a hwmon sensors without labels.
Quoted 7 lines
Quoted 1 line
The driver absolutely should.
The original submission (and our downstream version) do this, but I changed it for v2 per Sven's feedback [1]. Outside of development/experimentation, we will (should) never have a sensor in the Devicetree of uknown utility. If we know what a sensor is for, then we should have a label for it.
Label attributes are optional in hwmon drivers. Period.
Guenter
PATCH v2 3/11 rtc: Add new rtc-macsmc driver for Apple Silicon Macs
In reply to James CalligerosFrom: Hector Martin <[email protected]>
Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC, but most of the PMU functionality is abstracted out by the SMC. On T600x machines, the RTC counter must be accessed via the SMC to get full functionality, and it seems likely that future machines will move towards making SMC handle all RTC functionality.
The SMC RTC counter access is implemented on all current machines as of the time of this writing, on firmware 12.x. However, the RTC offset (needed to set the time) is still only accessible via direct PMU access. To handle this, we expose the RTC offset as an NVMEM cell from the SPMI PMU device node, and this driver consumes that cell and uses it to compute/set the current time.
--- MAINTAINERS | 1 + drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-macsmc.c | 141 +++++++++++++++++++++++++ 4 files changed, 154 insertions(+)
MAINTAINERS +1 -0
@@ -2422,6 +2422,7 @@ F: drivers/nvmem/apple-spmi-nvmem.c F: drivers/pinctrl/pinctrl-apple-gpio.c F: drivers/power/reset/macsmc-reboot.c F: drivers/pwm/pwm-apple.c +F: drivers/rtc/rtc-macsmc.c F: drivers/soc/apple/* F: drivers/spi/spi-apple.c F: drivers/spmi/spmi-apple-controller.c
drivers/rtc/Kconfig +11 -0
@@ -2068,6 +2068,17 @@ config RTC_DRV_WILCO_EC This can also be built as a module. If so, the module will be named "rtc_wilco_ec". +config RTC_DRV_MACSMC + tristate "Apple Mac System Management Controller RTC" + depends on MFD_MACSMC + help + If you say yes here you get support for RTC functions + inside Apple SPMI PMUs accessed through the SoC's + System Management Controller + + To compile this driver as a module, choose M here: the + module will be called rtc-macsmc. + config RTC_DRV_MSC313 tristate "MStar MSC313 RTC" depends on ARCH_MSTARV7 || COMPILE_TEST
drivers/rtc/Makefile +1 -0
@@ -93,6 +93,7 @@ obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o obj-$(CONFIG_RTC_DRV_MA35D1) += rtc-ma35d1.o +obj-$(CONFIG_RTC_DRV_MACSMC) += rtc-macsmc.o obj-$(CONFIG_RTC_DRV_MAX31335) += rtc-max31335.o obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
drivers/rtc/rtc-macsmc.c new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v2 4/11 mfd: macsmc: Wire up Apple SMC RTC subdevice
In reply to James CalligerosAdd the new SMC RTC function to the mfd device
--- drivers/mfd/macsmc.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/macsmc.c +1 -0
@@ -47,6 +47,7 @@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" ), +MFD_CELL_OF ("macsmc-rtc" ,NULL ,NULL ,0 ,0 ,"apple,smc-rtc" ), }; static int apple_smc_cmd_locked(struct apple_smc *smc, u64 cmd, u64 arg,
Signature · 1 line
2.51.0
PATCH v2 5/11 hwmon: Add Apple Silicon SMC hwmon driver
In reply to James CalligerosThe System Management Controller on Apple Silicon devices is responsible for integrating and exposing the data reported by the vast array of hardware monitoring sensors present on these devices. It is also responsible for fan control, and allows users to manually set fan speeds if they so desire. Add a hwmon driver to expose current, power, temperature, and voltage monitoring sensors, as well as fan speed monitoring and control via the SMC on Apple Silicon devices.
The SMC firmware has no consistency between devices, even when they share an SoC. The FourCC keys used to access sensors are almost random. An M1 Mac mini will have different FourCCs for its CPU core temperature sensors to an M1 MacBook Pro, for example. For this reason, the valid sensors for a given device are specified in a child of the SMC Devicetree node. The driver uses this information to determine which sensors to make available at runtime.
--- MAINTAINERS | 1 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/macsmc_hwmon.c | 848 +++++++++++++++++++++++++ 4 files changed, 862 insertions(+)
MAINTAINERS +1 -0
@@ -2408,6 +2408,7 @@ 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/hwmon/macsmc_hwmon.c F: drivers/pmdomain/apple/ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.c
drivers/hwmon/Kconfig +12 -0
@@ -1164,6 +1164,18 @@ config SENSORS_LTQ_CPUTEMP If you say yes here you get support for the temperature sensor inside your CPU. +config SENSORS_MACSMC_HWMON + tristate "Apple SMC (Apple Silicon)" + depends on MFD_MACSMC && OF + help + This driver enables hwmon support for current, power, temperature, + and voltage sensors, as well as fan speed reporting and control + on Apple Silicon devices. Say Y here if you have an Apple Silicon + device. + + This driver can also be built as a module. If so, the module will + be called macsmc_hwmon. + config SENSORS_MAX1111 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" depends on SPI_MASTER
drivers/hwmon/Makefile +1 -0
@@ -147,6 +147,7 @@ obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o obj-$(CONFIG_SENSORS_LTC4282) += ltc4282.o obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o +obj-$(CONFIG_SENSORS_MACSMC_HWMON) += macsmc_hwmon.o obj-$(CONFIG_SENSORS_MAX1111) += max1111.o obj-$(CONFIG_SENSORS_MAX127) += max127.o obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
drivers/hwmon/macsmc_hwmon.c new file +848 -0
848 lines not on this page · raw message
Signature · 1 line
2.51.0
Guenter Roeck
maintainerRe: [PATCH v2 05/11] hwmon: Add Apple Silicon SMC hwmon driver
Quoted 16 lines · James Calligeros
The System Management Controller on Apple Silicon devices is responsible for integrating and exposing the data reported by the vast array of hardware monitoring sensors present on these devices. It is also responsible for fan control, and allows users to manually set fan speeds if they so desire. Add a hwmon driver to expose current, power, temperature, and voltage monitoring sensors, as well as fan speed monitoring and control via the SMC on Apple Silicon devices.
The SMC firmware has no consistency between devices, even when they share an SoC. The FourCC keys used to access sensors are almost random. An M1 Mac mini will have different FourCCs for its CPU core temperature sensors to an M1 MacBook Pro, for example. For this reason, the valid sensors for a given device are specified in a child of the SMC Devicetree node. The driver uses this information to determine which sensors to make available at runtime.
Quoted 8 lines
Co-developed-by Janne Grunau <[email protected]>Signed-off-by Janne Grunau <[email protected]>Signed-off-by James Calligeros <[email protected]>--- MAINTAINERS | 1 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/macsmc_hwmon.c | 848 +++++++++++++++++++++++++
Documentation/hwmon/macsmc_hwmon missing
Quoted 69 lines
4 files changed, 862 insertions(+)MAINTAINERS +1
-0@@ -2408,6 +2408,7 @@ 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/hwmon/macsmc_hwmon.c F: drivers/pmdomain/apple/ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.cdrivers/hwmon/Kconfig +12
-0@@ -1164,6 +1164,18 @@ config SENSORS_LTQ_CPUTEMP If you say yes here you get support for the temperature sensor inside your CPU. +config SENSORS_MACSMC_HWMON + tristate "Apple SMC (Apple Silicon)" + depends on MFD_MACSMC && OF + help + This driver enables hwmon support for current, power, temperature, + and voltage sensors, as well as fan speed reporting and control + on Apple Silicon devices. Say Y here if you have an Apple Silicon + device. + + This driver can also be built as a module. If so, the module will + be called macsmc_hwmon. + config SENSORS_MAX1111 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" depends on SPI_MASTERdrivers/hwmon/Makefile +1
-0@@ -147,6 +147,7 @@ obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o obj-$(CONFIG_SENSORS_LTC4282) += ltc4282.o obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o +obj-$(CONFIG_SENSORS_MACSMC_HWMON) += macsmc_hwmon.o obj-$(CONFIG_SENSORS_MAX1111) += max1111.o obj-$(CONFIG_SENSORS_MAX127) += max127.o obj-$(CONFIG_SENSORS_MAX16065) += max16065.odrivers/hwmon/macsmc_hwmon.c new file +14
-0@@ -0,0 +1,848 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* +* Apple SMC hwmon driver for Apple Silicon platforms +* +* The System Management Controller on Apple Silicon devices is responsible for +* measuring data from sensors across the SoC and machine. These include power, +* temperature, voltage and current sensors. Some "sensors" actually expose +* derived values. An example of this is the key PHPC, which is an estimate +* of the heat energy being dissipated by the SoC. +* +* While each SoC only has one SMC variant, each platform exposes a different +* set of sensors. For example, M1 MacBooks expose battery telemetry sensors +* which are not present on the M1 Mac mini. For this reason, the available +* sensors for a given platform are described in the device tree in a child
drivers/hwmon/macsmc_hwmon.c line 24
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+* node of the SMC device. We must walk this list of available sensors and +* populate the required hwmon data structures at runtime. +* +* Originally based on a concept by Jean-Francois Bortolotti <[email protected]> +* +* Copyright The Asahi Linux Contributors +*/ + +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h>
Unnecessary include file
Quoted 62 lines
drivers/hwmon/macsmc_hwmon.c new file +62
-0+#include <linux/mfd/macsmc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +#define MAX_LABEL_LENGTH 32 +#define NUM_SENSOR_TYPES 5/* temp, volt, current, power, fan */ + +#define FLT_EXP_BIAS 127 +#define FLT_EXP_MASK GENMASK(30, 23) +#define FLT_MANT_BIAS 23 +#define FLT_MANT_MASK GENMASK(22, 0) +#define FLT_SIGN_MASK BIT(31) + +static bool fan_control; +module_param_unsafe (fan_control, bool,0644 ); +MODULE_PARM_DESC (fan_control, +"Override the SMC to set your own fan speeds on supported machines" ); + +struct macsmc_hwmon_sensor { +struct apple_smc_key_info info; +smc_key macsmc_key; +char label[MAX_LABEL_LENGTH ]; +}; + +struct macsmc_hwmon_fan { +struct macsmc_hwmon_sensor now; +struct macsmc_hwmon_sensor min; +struct macsmc_hwmon_sensor max; +struct macsmc_hwmon_sensor set; +struct macsmc_hwmon_sensor mode; +char label[MAX_LABEL_LENGTH ]; +u32 attrs; +bool manual; +}; + +struct macsmc_hwmon_sensors { +struct hwmon_channel_info channel_info; +struct macsmc_hwmon_sensor *sensors; +u32 count; +}; + +struct macsmc_hwmon_fans { +struct hwmon_channel_info channel_info; +struct macsmc_hwmon_fan *fans; +u32 count; +}; + +struct macsmc_hwmon { +struct device *dev; +struct apple_smc *smc; +struct device *hwmon_dev; +struct hwmon_chip_info chip_info; +/* Chip + sensor types + NULL */ +const struct hwmon_channel_info *channel_infos[1 +NUM_SENSOR_TYPES +1 ]; +struct macsmc_hwmon_sensors temp; +struct macsmc_hwmon_sensors volt; +struct macsmc_hwmon_sensors curr; +struct macsmc_hwmon_sensors power; +struct macsmc_hwmon_fans fan; +}; +
drivers/hwmon/macsmc_hwmon.c line 96
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+static int macsmc_hwmon_read_label (struct device *dev, +enum hwmon_sensor_types type,u32 attr, +int channel,const char **str) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev); + +switch (type) { +case hwmon_temp: +if (channel >= hwmon->temp.count) +return -EINVAL ;
Wrong. Such channels should not be instantiated. It is completely unacceptable for the "sensors" command to report such errors. Also more below on the use of -EINVAL when readin values.
Quoted 106 lines
drivers/hwmon/macsmc_hwmon.c new file +106
-0+ *str = hwmon->temp.sensors[channel].label; +break ; +case hwmon_in: +if (channel >= hwmon->volt.count) +return -EINVAL ; + *str = hwmon->volt.sensors[channel].label; +break ; +case hwmon_curr: +if (channel >= hwmon->curr.count) +return -EINVAL ; + *str = hwmon->curr.sensors[channel].label; +break ; +case hwmon_power: +if (channel >= hwmon->power.count) +return -EINVAL ; + *str = hwmon->power.sensors[channel].label; +break ; +case hwmon_fan: +if (channel >= hwmon->fan.count) +return -EINVAL ; + *str = hwmon->fan.fans[channel].label; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; +} + +/* +* A number of sensors report data in a 48.16 fixed-point decimal format that is +* not used by any other function of the SMC. +*/ +static int macsmc_hwmon_read_ioft_scaled (struct apple_smc *smc,smc_key key, +u64 *p,int scale) +{ +u64 val; +int ret; + + ret =apple_smc_read_u64 (smc, key, &val); +if (ret <0 ) +return ret; + + *p =mult_frac (val, scale,65536 ); + +return 0 ; +} + +/* +* Many sensors report their data as IEEE-754 floats. No other SMC function uses +* them. +*/ +static int macsmc_hwmon_read_f32_scaled (struct apple_smc *smc,smc_key key, +int *p,int scale) +{ +u32 fval; +u64 val; +int ret, exp; + + ret =apple_smc_read_u32 (smc, key, &fval); +if (ret <0 ) +return ret; + + val = ((u64)((fval &FLT_MANT_MASK ) |BIT (23 ))); + exp = ((fval >>23 ) &0xff ) -FLT_EXP_BIAS -FLT_MANT_BIAS ; +if (scale <0 ) { + val <<=32 ; + exp -=32 ; + val /= -scale; + }else { + val *= scale; + } + +if (exp >63 ) + val =U64_MAX ; +else if (exp <-63 ) + val =0 ; +else if (exp <0 ) + val >>= -exp; +else if (exp !=0 && (val & ~((1UL << (64 - exp)) -1 )))/* overflow */ + val =U64_MAX ; +else + val <<= exp; + +if (fval &FLT_SIGN_MASK ) { +if (val > (-(s64 )INT_MIN )) + *p =INT_MIN ; +else + *p = -val; + }else { +if (val >INT_MAX ) + *p =INT_MAX ; +else + *p = val; + } + +return 0 ; +} + +/* +* The SMC has keys of multiple types, denoted by a FourCC of the same format +* as the key ID. We don't know what data type a key encodes until we poke at it. +*/ +static int macsmc_hwmon_read_key (struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor,int scale, +long *val)
drivers/hwmon/macsmc_hwmon.c line 212
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+{ +int ret; + +switch (sensor->info.type_code) { +/* 32-bit IEEE 754 float */ +case _SMC_KEY ("flt " ): { +u32 flt_ =0 ; + + ret =macsmc_hwmon_read_f32_scaled (smc, sensor->macsmc_key, + &flt_, scale);
if (ret) return ret;
drivers/hwmon/macsmc_hwmon.c line 221
Quoted 9 lines
drivers/hwmon/macsmc_hwmon.c new file +9
-0+ *val = flt_; +break ; + } +/* 48.16 fixed point decimal */ +case _SMC_KEY ("ioft" ): { +u64 ioft =0 ; + + ret =macsmc_hwmon_read_ioft_scaled (smc, sensor->macsmc_key, + &ioft, scale);
if (ret) return ret;
drivers/hwmon/macsmc_hwmon.c line 230
Quoted 9 lines
drivers/hwmon/macsmc_hwmon.c new file +9
-0+ *val = (long )ioft; +break ; + } +default : +return -EOPNOTSUPP ; + } + +if (ret) +return -EINVAL ;
Drop
Quoted 53 lines
drivers/hwmon/macsmc_hwmon.c new file +53
-0+ +return 0 ; +} + +static int macsmc_hwmon_write_f32_scaled (struct apple_smc *smc,smc_key key, +int value,int scale) +{ +u64 val; +u32 fval =0 ; +int exp, neg; + + val =abs (value); + neg = val != value; + +if (scale >1 ) { + val <<=32 ; + exp =32 ; + val /= scale; + }else if (scale <1 ) { + val *= -scale; + } + +if (val) { +int msb =__fls (val) - exp; + +if (msb >23 ) { + val >>= msb -23 ; + exp -= msb -23 ; + }else if (msb <23 ) { + val <<=23 - msb; + exp += msb; + } + + fval =FIELD_PREP (FLT_SIGN_MASK , neg) | +FIELD_PREP (FLT_EXP_MASK , exp +FLT_EXP_BIAS ) | +FIELD_PREP (FLT_MANT_MASK , val); + } + +return apple_smc_write_u32 (smc, key, fval); +} + +static int macsmc_hwmon_write_key (struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor,long val, +int scale) +{ +switch (sensor->info.type_code) { +/* 32-bit IEEE 754 float */ +case _SMC_KEY ("flt " ): +return macsmc_hwmon_write_f32_scaled (smc, sensor->macsmc_key, + val, scale); +/* unsigned 8-bit integer */ +case _SMC_KEY ("ui8 " ): +return apple_smc_write_u8 (smc, sensor->macsmc_key, val);
drivers/hwmon/macsmc_hwmon.c line 293
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+default : +return -EOPNOTSUPP ; + } +} + +static int macsmc_hwmon_read_fan (struct macsmc_hwmon *hwmon,u32 attr,int chan, +long *val) +{ +if (!(hwmon->fan.fans[chan].attrs &BIT (attr))) +return -EINVAL ;
This is wrong. If the fan does not exist, the is_visible function should have dropped the attribute. Also, EINVAL is "invalid argument" which is just impossible when _reading_ a value from the kernel.
Quoted 6 lines
drivers/hwmon/macsmc_hwmon.c new file +6
-0+ +switch (attr) { +case hwmon_fan_input: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].now,1 , val); +case hwmon_fan_min:
drivers/hwmon/macsmc_hwmon.c line 309
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].min,1 , val); +case hwmon_fan_max: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].max,1 , val); +case hwmon_fan_target: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].set,1 , val); +default : +return -EINVAL ;
As above.
Quoted 7 lines
drivers/hwmon/macsmc_hwmon.c new file +7
-0+ } +} + +static int macsmc_hwmon_write_fan (struct device *dev,u32 attr,int channel, +long val) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev);
drivers/hwmon/macsmc_hwmon.c line 326
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+long min, max; +int ret; + +if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key ==0 ) +return -EOPNOTSUPP ; + +if (channel >= hwmon->fan.count || + !(hwmon->fan.fans[channel].attrs &BIT (attr)) || + attr != hwmon_fan_target) +return -EINVAL ;
And again.
Quoted 89 lines
drivers/hwmon/macsmc_hwmon.c new file +89
-0+ +/* +* The SMC does no sanity checks on requested fan speeds, so we need to. +*/ + ret =macsmc_hwmon_read_key (hwmon->smc, &hwmon->fan.fans[channel].min, +1 , &min); +if (ret) +return ret; + + ret =macsmc_hwmon_read_key (hwmon->smc, &hwmon->fan.fans[channel].max, +1 , &max); +if (ret) +return ret; + +if (val >= min && val <= max) { +if (!hwmon->fan.fans[channel].manual) { +/* Write 1 to mode key for manual control */ + ret =macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].mode,1 , +1 ); +if (ret <0 ) +return ret; + + hwmon->fan.fans[channel].manual = true; + } +return macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].set, val,1 ); + }else if (!val) { +if (hwmon->fan.fans[channel].manual) { + ret =macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].mode,0 ,1 ); +if (ret <0 ) +return ret; + + hwmon->fan.fans[channel].manual = false; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int macsmc_hwmon_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev); +int ret =0 ; + +switch (type) { +case hwmon_temp: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->temp.sensors[channel],1000 , val); +break ; +case hwmon_in: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->volt.sensors[channel],1000 , val); +break ; +case hwmon_curr: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->curr.sensors[channel],1000 , val); +break ; +case hwmon_power: +/* SMC returns power in Watts with acceptable precision to scale to uW */ + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->power.sensors[channel], +1000000 , val); +break ; +case hwmon_fan: + ret =macsmc_hwmon_read_fan (hwmon, attr, channel, val); +break ; +default : +return -EOPNOTSUPP ; + } + +return ret; +} + +static int macsmc_hwmon_write (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long val) +{ +switch (type) { +case hwmon_fan: +return macsmc_hwmon_write_fan (dev, attr, channel, val); +default : +return -EOPNOTSUPP ; + } +} +
drivers/hwmon/macsmc_hwmon.c line 425
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+static umode_t macsmc_hwmon_fan_is_visible (const void *data,u32 attr, +int channel) +{ +const struct macsmc_hwmon *hwmon = data; + +if (fan_control && attr == hwmon_fan_target && + hwmon->fan.fans[channel].mode.macsmc_key !=0 ) +return 0644 ; + +return 0444 ;
This should return 0 for non-existing fans.
Quoted 4 lines
drivers/hwmon/macsmc_hwmon.c new file +4
-0+} + +static umode_t macsmc_hwmon_is_visible(const void *data, + enum hwmon_sensor_types type, u32 attr,
drivers/hwmon/macsmc_hwmon.c line 439
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+ int channel) +{ +switch (type) { +case hwmon_fan: +return macsmc_hwmon_fan_is_visible (data, attr, channel); +default : +break ; + } + +return 0444 ;
If those attributes exist they must be supported. Otherwise return 0.
Quoted 70 lines
drivers/hwmon/macsmc_hwmon.c new file +70
-0+} + +static const struct hwmon_ops macsmc_hwmon_ops = { + .is_visible = macsmc_hwmon_is_visible, + .read = macsmc_hwmon_read, + .read_string = macsmc_hwmon_read_label, + .write = macsmc_hwmon_write, +}; + +/* +* Get the key metadata, including key data type, from the SMC. +*/ +static int macsmc_hwmon_parse_key (struct device *dev,struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor, +const char *key) +{ +int ret; + + ret =apple_smc_get_key_info (smc,_SMC_KEY (key), &sensor->info); +if (ret) { +dev_err (dev,"Failed to retrieve key info for %s\n" , key); +return ret; + } + + sensor->macsmc_key =_SMC_KEY (key); + +return 0 ; +} + +/* +* A sensor is a single key-value pair as made available by the SMC. +* The devicetree gives us the SMC key ID and a friendly name where the +* purpose of the sensor is known. +*/ +static int macsmc_hwmon_create_sensor (struct device *dev,struct apple_smc *smc, +struct device_node *sensor_node, +struct macsmc_hwmon_sensor *sensor) +{ +const char *key, *label; +int ret; + + ret =of_property_read_string (sensor_node,"apple,key-id" , &key); +if (ret) { +dev_err (dev,"Could not find apple,key-id in sensor node\n" ); +return ret; + } + + ret =macsmc_hwmon_parse_key (dev, smc, sensor, key); +if (ret) +return ret; + + ret =of_property_read_string (sensor_node,"label" , &label); +if (ret) { +dev_err (dev,"No label found for sensor %s\n" , key); +return ret; + } + +strscpy_pad (sensor->label, label,sizeof (sensor->label)); + +return 0 ; +} + +/* +* Fan data is exposed by the SMC as multiple sensors. +* +* The devicetree schema reuses apple,key-id for the actual fan speed sensor. +* Min, max and target keys do not need labels, so we can reuse label +* for naming the entire fan. +*/ +static int macsmc_hwmon_create_fan(struct device *dev, struct apple_smc *smc,
drivers/hwmon/macsmc_hwmon.c line 519
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+struct device_node *fan_node, + struct macsmc_hwmon_fan *fan) +{ + const char *label, *now, *min, *max, *set, *mode; +int ret; + + ret =of_property_read_string (fan_node,"apple,key-id" , &now); +if (ret) { +dev_err (dev,"apple,key-id not found in fan node!\n" ); +return -EINVAL ;
return ret;
Never overwrite error numbers.
Quoted 177 lines
drivers/hwmon/macsmc_hwmon.c new file +177
-0+ } + + ret =macsmc_hwmon_parse_key (dev, smc, &fan->now, now); +if (ret) +return ret; + + ret =of_property_read_string (fan_node,"label" , &label); +if (ret) { +dev_err (dev,"No label found for fan %s\n" , now); +return ret; + } + +strscpy_pad (fan->label, label,sizeof (fan->label)); + + fan->attrs =HWMON_F_LABEL |HWMON_F_INPUT ; + +/* The following keys are not required to simply monitor fan speed */ +if (!of_property_read_string (fan_node,"apple,fan-minimum" , &min)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->min, min); +if (ret) +return ret; + + fan->attrs |=HWMON_F_MIN ; + } + +if (!of_property_read_string (fan_node,"apple,fan-maximum" , &max)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->max, max); +if (ret) +return ret; + + fan->attrs |=HWMON_F_MAX ; + } + +if (!of_property_read_string (fan_node,"apple,fan-target" , &set)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->set, set); +if (ret) +return ret; + + fan->attrs |=HWMON_F_TARGET ; + } + +if (!of_property_read_string (fan_node,"apple,fan-mode" , &mode)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->mode, mode); +if (ret) +return ret; + } + +/* Initialise fan control mode to automatic */ + fan->manual = false; + +return 0 ; +} + +static int macsmc_hwmon_populate_sensors (struct macsmc_hwmon *hwmon, +struct device_node *hwmon_node) +{ +struct device_node *key_node__maybe_unused ; +u32 n_current =0 , n_fan =0 , n_power =0 , n_temperature =0 , n_voltage =0 ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"current-" ) { + n_current++; + } + +if (n_current) { + hwmon->curr.sensors =devm_kcalloc (hwmon->dev, n_current, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->curr.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"current-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->curr.sensors[hwmon->curr.count])) + hwmon->curr.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"fan-" ) { + n_fan++; + } + +if (n_fan) { + hwmon->fan.fans =devm_kcalloc (hwmon->dev, n_fan, +sizeof (struct macsmc_hwmon_fan ),GFP_KERNEL ); +if (!hwmon->fan.fans) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"fan-" ) { +if (!macsmc_hwmon_create_fan (hwmon->dev, hwmon->smc, key_node, + &hwmon->fan.fans[hwmon->fan.count])) + hwmon->fan.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"power-" ) { + n_power++; + } + +if (n_power) { + hwmon->power.sensors =devm_kcalloc (hwmon->dev, n_power, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->power.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"power-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->power.sensors[hwmon->power.count])) + hwmon->power.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"temperature-" ) { + n_temperature++; + } + +if (n_temperature) { + hwmon->temp.sensors =devm_kcalloc (hwmon->dev, n_temperature, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->temp.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"temperature-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->temp.sensors[hwmon->temp.count])) + hwmon->temp.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"voltage-" ) { + n_voltage++; + } + +if (n_voltage) { + hwmon->volt.sensors =devm_kcalloc (hwmon->dev, n_voltage, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->volt.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"volt-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->volt.sensors[hwmon->volt.count])) + hwmon->volt.count++; + } + } + +return 0 ; +} + +/* Create NULL-terminated config arrays */ +static void macsmc_hwmon_populate_configs (u32 *configs,u32 num_keys,u32 flags) +{ +int idx; + +for (idx =0 ; idx < num_keys; idx++) + configs[idx] = flags; +} + +static void macsmc_hwmon_populate_fan_configs (u32 *configs,u32 num_keys, +struct macsmc_hwmon_fans *fans) +{ +int idx; + +for (idx =0 ; idx < num_keys; idx++) + configs[idx] = fans->fans[idx].attrs; +} + +static const struct hwmon_channel_info *const macsmc_chip_channel_info = +HWMON_CHANNEL_INFO (chip,HWMON_C_REGISTER_TZ ); + +static int macsmc_hwmon_create_infos (struct macsmc_hwmon *hwmon) +{ +struct hwmon_channel_info *channel_info; +int i =0 ; + +/* chip */ + hwmon->channel_infos[i++] = macsmc_chip_channel_info; + +if (hwmon->curr.count) {
drivers/hwmon/macsmc_hwmon.c line 706
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+ channel_info = &hwmon->curr.channel_info; + channel_info->type = hwmon_curr; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->curr.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->curr.count, + (HWMON_C_INPUT |HWMON_C_LABEL ));
Unnecessary ()
Quoted 18 lines
drivers/hwmon/macsmc_hwmon.c new file +18
-0+ hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->fan.count) { + channel_info = &hwmon->fan.channel_info; + channel_info->type = hwmon_fan; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->fan.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_fan_configs ((u32 *)channel_info->config, + hwmon->fan.count, + &hwmon->fan); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->power.count) {
drivers/hwmon/macsmc_hwmon.c line 734
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+ channel_info = &hwmon->power.channel_info; + channel_info->type = hwmon_power; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->power.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->power.count, + (HWMON_P_INPUT |HWMON_P_LABEL ));
Unnecessary (). Drop everywhere.
Quoted 114 lines
drivers/hwmon/macsmc_hwmon.c new file +114
-0+ hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->temp.count) { + channel_info = &hwmon->temp.channel_info; + channel_info->type = hwmon_temp; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->temp.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->temp.count, + (HWMON_T_INPUT |HWMON_T_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->volt.count) { + channel_info = &hwmon->volt.channel_info; + channel_info->type = hwmon_in; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->volt.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->volt.count, + (HWMON_I_INPUT |HWMON_I_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +return 0 ; +} + +static int macsmc_hwmon_probe (struct platform_device *pdev) +{ +struct apple_smc *smc =dev_get_drvdata (pdev->dev.parent); +struct macsmc_hwmon *hwmon; +int ret; + +/* +* The MFD driver will try to probe us unconditionally. Some devices +* with the SMC do not have hwmon capabilities. Only probe if we have +* a hwmon node. +*/ +if (!pdev->dev.of_node) +return -ENODEV ; + + hwmon =devm_kzalloc (&pdev->dev,sizeof (*hwmon), +GFP_KERNEL ); +if (!hwmon) +return -ENOMEM ; + + hwmon->dev = &pdev->dev; + hwmon->smc = smc; + + ret =macsmc_hwmon_populate_sensors (hwmon, hwmon->dev->of_node); +if (ret) { +dev_err (hwmon->dev,"Could not populate keys!\n" ); +return ret; + } + +if (!hwmon->curr.count && !hwmon->fan.count && + !hwmon->power.count && !hwmon->temp.count && + !hwmon->volt.count) { +dev_err (hwmon->dev, +"No valid keys found of any supported type" ); +return -ENODEV ; + } + + ret =macsmc_hwmon_create_infos (hwmon); +if (ret) +return ret; + + hwmon->chip_info.ops = &macsmc_hwmon_ops; + hwmon->chip_info.info = + (const struct hwmon_channel_info *const *)&hwmon->channel_infos; + + hwmon->hwmon_dev =devm_hwmon_device_register_with_info (&pdev->dev, +"macsmc_hwmon" , hwmon, + &hwmon->chip_info,NULL ); +if (IS_ERR (hwmon->hwmon_dev)) +return dev_err_probe (hwmon->dev,PTR_ERR (hwmon->hwmon_dev), +"Probing SMC hwmon device failed\n" ); + +dev_info (hwmon->dev,"Registered SMC hwmon device. Sensors:" ); +dev_info (hwmon->dev, +"Current: %d, Fans: %d, Power: %d, Temperature: %d, Voltage: %d" , + hwmon->curr.count, hwmon->fan.count, + hwmon->power.count, hwmon->temp.count, + hwmon->volt.count); + +return 0 ; +} + +static const struct of_device_id macsmc_hwmon_of_table[] = { + { .compatible ="apple,smc-hwmon" }, + {} +}; +MODULE_DEVICE_TABLE (of, macsmc_hwmon_of_table); + +static struct platform_driver macsmc_hwmon_driver = { + .probe = macsmc_hwmon_probe, + .driver = { + .name ="macsmc_hwmon" , + .of_match_table = macsmc_hwmon_of_table, + }, +}; +module_platform_driver (macsmc_hwmon_driver); + +MODULE_DESCRIPTION ("Apple Silicon SMC hwmon driver" ); +MODULE_AUTHOR ("James Calligeros <[email protected]>" ); +MODULE_LICENSE ("Dual MIT/GPL" ); +MODULE_ALIAS ("platform:macsmc_hwmon" );
Janne Grunau
maintainerRe: [PATCH v2 05/11] hwmon: Add Apple Silicon SMC hwmon driver
In reply to James CalligerosQuoted 16 lines · James Calligeros
The System Management Controller on Apple Silicon devices is responsible for integrating and exposing the data reported by the vast array of hardware monitoring sensors present on these devices. It is also responsible for fan control, and allows users to manually set fan speeds if they so desire. Add a hwmon driver to expose current, power, temperature, and voltage monitoring sensors, as well as fan speed monitoring and control via the SMC on Apple Silicon devices.
The SMC firmware has no consistency between devices, even when they share an SoC. The FourCC keys used to access sensors are almost random. An M1 Mac mini will have different FourCCs for its CPU core temperature sensors to an M1 MacBook Pro, for example. For this reason, the valid sensors for a given device are specified in a child of the SMC Devicetree node. The driver uses this information to determine which sensors to make available at runtime.
Quoted 8 lines
Co-developed-by Janne Grunau <[email protected]>Signed-off-by Janne Grunau <[email protected]>Signed-off-by James Calligeros <[email protected]>--- MAINTAINERS | 1 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/macsmc_hwmon.c | 848 +++++++++++++++++++++++++
Please use macsmc-hwmon.c as name. All other macsmc sub device drivers use '-' and it's more common in 'drivers/hwmon/*.c'
Quoted 23 lines
4 files changed, 862 insertions(+)MAINTAINERS +1
-0@@ -2408,6 +2408,7 @@ 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/hwmon/macsmc_hwmon.c F: drivers/pmdomain/apple/ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.cdrivers/hwmon/Kconfig +1
-0@@ -1164,6 +1164,18 @@ config SENSORS_LTQ_CPUTEMP If you say yes here you get support for the temperature sensor inside your CPU. +config SENSORS_MACSMC_HWMON
drivers/hwmon/Kconfig config SENSORS_LTQ_CPUTEMP · line 1177
Quoted 10 lines
drivers/hwmon/Kconfig +10
-0+ tristate "Apple SMC (Apple Silicon)" + depends on MFD_MACSMC && OF + help + This driver enables hwmon support for current, power, temperature, + and voltage sensors, as well as fan speed reporting and control + on Apple Silicon devices. Say Y here if you have an Apple Silicon + device. + + This driver can also be built as a module. If so, the module will + be called macsmc_hwmon.
macsmc-hwmon
Quoted 43 lines
drivers/hwmon/Kconfig +1
-0+ config SENSORS_MAX1111 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" depends on SPI_MASTERdrivers/hwmon/Makefile +1
-0@@ -147,6 +147,7 @@ obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o obj-$(CONFIG_SENSORS_LTC4282) += ltc4282.o obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o +obj-$(CONFIG_SENSORS_MACSMC_HWMON) += macsmc_hwmon.o obj-$(CONFIG_SENSORS_MAX1111) += max1111.o obj-$(CONFIG_SENSORS_MAX127) += max127.o obj-$(CONFIG_SENSORS_MAX16065) += max16065.odrivers/hwmon/macsmc_hwmon.c new file +21
-0@@ -0,0 +1,848 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* +* Apple SMC hwmon driver for Apple Silicon platforms +* +* The System Management Controller on Apple Silicon devices is responsible for +* measuring data from sensors across the SoC and machine. These include power, +* temperature, voltage and current sensors. Some "sensors" actually expose +* derived values. An example of this is the key PHPC, which is an estimate +* of the heat energy being dissipated by the SoC. +* +* While each SoC only has one SMC variant, each platform exposes a different +* set of sensors. For example, M1 MacBooks expose battery telemetry sensors +* which are not present on the M1 Mac mini. For this reason, the available +* sensors for a given platform are described in the device tree in a child +* node of the SMC device. We must walk this list of available sensors and +* populate the required hwmon data structures at runtime. +* +* Originally based on a concept by Jean-Francois Bortolotti <[email protected]> +* +* Copyright The Asahi Linux Contributors +*/
drivers/hwmon/macsmc_hwmon.c line 31
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+ +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/mfd/macsmc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +#define MAX_LABEL_LENGTH 32 +#define NUM_SENSOR_TYPES 5/* temp, volt, current, power, fan */
I would write voltage and temperature out. At least in comments. Shortening "voltage" to volt seems strange when "current" and "power" are used otherwise.
Quoted 41 lines
drivers/hwmon/macsmc_hwmon.c new file +41
-0+ +#define FLT_EXP_BIAS 127 +#define FLT_EXP_MASK GENMASK(30, 23) +#define FLT_MANT_BIAS 23 +#define FLT_MANT_MASK GENMASK(22, 0) +#define FLT_SIGN_MASK BIT(31) + +static bool fan_control; +module_param_unsafe (fan_control, bool,0644 ); +MODULE_PARM_DESC (fan_control, +"Override the SMC to set your own fan speeds on supported machines" ); + +struct macsmc_hwmon_sensor { +struct apple_smc_key_info info; +smc_key macsmc_key; +char label[MAX_LABEL_LENGTH ]; +}; + +struct macsmc_hwmon_fan { +struct macsmc_hwmon_sensor now; +struct macsmc_hwmon_sensor min; +struct macsmc_hwmon_sensor max; +struct macsmc_hwmon_sensor set; +struct macsmc_hwmon_sensor mode; +char label[MAX_LABEL_LENGTH ]; +u32 attrs; +bool manual; +}; + +struct macsmc_hwmon_sensors { +struct hwmon_channel_info channel_info; +struct macsmc_hwmon_sensor *sensors; +u32 count; +}; + +struct macsmc_hwmon_fans { +struct hwmon_channel_info channel_info; +struct macsmc_hwmon_fan *fans; +u32 count; +}; +
drivers/hwmon/macsmc_hwmon.c line 82
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+struct macsmc_hwmon { +struct device *dev; +struct apple_smc *smc; +struct device *hwmon_dev; +struct hwmon_chip_info chip_info; +/* Chip + sensor types + NULL */ +const struct hwmon_channel_info *channel_infos[1 +NUM_SENSOR_TYPES +1 ]; +struct macsmc_hwmon_sensors temp; +struct macsmc_hwmon_sensors volt; +struct macsmc_hwmon_sensors curr;
matching the "hwmon_*" names is a convincing argument not sure what to do about the voltage sensors though
Quoted 73 lines
drivers/hwmon/macsmc_hwmon.c new file +73
-0+struct macsmc_hwmon_sensors power; +struct macsmc_hwmon_fans fan; +}; + +static int macsmc_hwmon_read_label (struct device *dev, +enum hwmon_sensor_types type,u32 attr, +int channel,const char **str) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev); + +switch (type) { +case hwmon_temp: +if (channel >= hwmon->temp.count) +return -EINVAL ; + *str = hwmon->temp.sensors[channel].label; +break ; +case hwmon_in: +if (channel >= hwmon->volt.count) +return -EINVAL ; + *str = hwmon->volt.sensors[channel].label; +break ; +case hwmon_curr: +if (channel >= hwmon->curr.count) +return -EINVAL ; + *str = hwmon->curr.sensors[channel].label; +break ; +case hwmon_power: +if (channel >= hwmon->power.count) +return -EINVAL ; + *str = hwmon->power.sensors[channel].label; +break ; +case hwmon_fan: +if (channel >= hwmon->fan.count) +return -EINVAL ; + *str = hwmon->fan.fans[channel].label; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; +} + +/* +* A number of sensors report data in a 48.16 fixed-point decimal format that is +* not used by any other function of the SMC. +*/ +static int macsmc_hwmon_read_ioft_scaled (struct apple_smc *smc,smc_key key, +u64 *p,int scale) +{ +u64 val; +int ret; + + ret =apple_smc_read_u64 (smc, key, &val); +if (ret <0 ) +return ret; + + *p =mult_frac (val, scale,65536 ); + +return 0 ; +} + +/* +* Many sensors report their data as IEEE-754 floats. No other SMC function uses +* them. +*/ +static int macsmc_hwmon_read_f32_scaled (struct apple_smc *smc,smc_key key, +int *p,int scale) +{ +u32 fval; +u64 val; +int ret, exp; +
drivers/hwmon/macsmc_hwmon.c line 165
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+ ret =apple_smc_read_u32 (smc, key, &fval); +if (ret <0 ) +return ret; + + val = ((u64)((fval &FLT_MANT_MASK ) |BIT (23 ))); + exp = ((fval >>23 ) &0xff ) -FLT_EXP_BIAS -FLT_MANT_BIAS ; +if (scale <0 ) { + val <<=32 ; + exp -=32 ; + val /= -scale;
64-bit division is not universally available. The easiest solution for Apple silicon would be to depend on CONFIG_64BIT. However so far macsmc_hwmon_read_key() is only called with positive scale values so it would make sense to just not support negative scale values.
Quoted 33 lines
drivers/hwmon/macsmc_hwmon.c new file +33
-0+ }else { + val *= scale; + } + +if (exp >63 ) + val =U64_MAX ; +else if (exp <-63 ) + val =0 ; +else if (exp <0 ) + val >>= -exp; +else if (exp !=0 && (val & ~((1UL << (64 - exp)) -1 )))/* overflow */ + val =U64_MAX ; +else + val <<= exp; + +if (fval &FLT_SIGN_MASK ) { +if (val > (-(s64 )INT_MIN )) + *p =INT_MIN ; +else + *p = -val; + }else { +if (val >INT_MAX ) + *p =INT_MAX ; +else + *p = val; + } + +return 0 ; +} + +/* +* The SMC has keys of multiple types, denoted by a FourCC of the same format +* as the key ID. We don't know what data type a key encodes until we poke at it.
drivers/hwmon/macsmc_hwmon.c line 208
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+*/ +static int macsmc_hwmon_read_key (struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor,int scale, +long *val) +{ +int ret; + +switch (sensor->info.type_code) { +/* 32-bit IEEE 754 float */ +case _SMC_KEY ("flt " ): {
This fails here with gcc (GCC) 15.2.1 20250808 (Red Hat 15.2.1-1)" "error: case label does not reduce to an integer constant" The same for the other "case _SMC_KEY()" statements
Quoted 30 lines
drivers/hwmon/macsmc_hwmon.c new file +30
-0+u32 flt_ =0 ; + + ret =macsmc_hwmon_read_f32_scaled (smc, sensor->macsmc_key, + &flt_, scale); + *val = flt_; +break ; + } +/* 48.16 fixed point decimal */ +case _SMC_KEY ("ioft" ): { +u64 ioft =0 ; + + ret =macsmc_hwmon_read_ioft_scaled (smc, sensor->macsmc_key, + &ioft, scale); + *val = (long )ioft; +break ; + } +default : +return -EOPNOTSUPP ; + } + +if (ret) +return -EINVAL ; + +return 0 ; +} + +static int macsmc_hwmon_write_f32_scaled (struct apple_smc *smc,smc_key key, +int value,int scale) +{ +u64 val;
drivers/hwmon/macsmc_hwmon.c line 248
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+u32 fval =0 ; +int exp, neg; + + val =abs (value); + neg = val != value; + +if (scale >1 ) { + val <<=32 ; + exp =32 ; + val /= scale;
Similar here. macsmc_hwmon_write_key() is only called with scale == 1
Quoted 235 lines
drivers/hwmon/macsmc_hwmon.c new file +235
-0+ }else if (scale <1 ) { + val *= -scale; + } + +if (val) { +int msb =__fls (val) - exp; + +if (msb >23 ) { + val >>= msb -23 ; + exp -= msb -23 ; + }else if (msb <23 ) { + val <<=23 - msb; + exp += msb; + } + + fval =FIELD_PREP (FLT_SIGN_MASK , neg) | +FIELD_PREP (FLT_EXP_MASK , exp +FLT_EXP_BIAS ) | +FIELD_PREP (FLT_MANT_MASK , val); + } + +return apple_smc_write_u32 (smc, key, fval); +} + +static int macsmc_hwmon_write_key (struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor,long val, +int scale) +{ +switch (sensor->info.type_code) { +/* 32-bit IEEE 754 float */ +case _SMC_KEY ("flt " ): +return macsmc_hwmon_write_f32_scaled (smc, sensor->macsmc_key, + val, scale); +/* unsigned 8-bit integer */ +case _SMC_KEY ("ui8 " ): +return apple_smc_write_u8 (smc, sensor->macsmc_key, val); +default : +return -EOPNOTSUPP ; + } +} + +static int macsmc_hwmon_read_fan (struct macsmc_hwmon *hwmon,u32 attr,int chan, +long *val) +{ +if (!(hwmon->fan.fans[chan].attrs &BIT (attr))) +return -EINVAL ; + +switch (attr) { +case hwmon_fan_input: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].now,1 , val); +case hwmon_fan_min: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].min,1 , val); +case hwmon_fan_max: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].max,1 , val); +case hwmon_fan_target: +return macsmc_hwmon_read_key (hwmon->smc, + &hwmon->fan.fans[chan].set,1 , val); +default : +return -EINVAL ; + } +} + +static int macsmc_hwmon_write_fan (struct device *dev,u32 attr,int channel, +long val) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev); +long min, max; +int ret; + +if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key ==0 ) +return -EOPNOTSUPP ; + +if (channel >= hwmon->fan.count || + !(hwmon->fan.fans[channel].attrs &BIT (attr)) || + attr != hwmon_fan_target) +return -EINVAL ; + +/* +* The SMC does no sanity checks on requested fan speeds, so we need to. +*/ + ret =macsmc_hwmon_read_key (hwmon->smc, &hwmon->fan.fans[channel].min, +1 , &min); +if (ret) +return ret; + + ret =macsmc_hwmon_read_key (hwmon->smc, &hwmon->fan.fans[channel].max, +1 , &max); +if (ret) +return ret; + +if (val >= min && val <= max) { +if (!hwmon->fan.fans[channel].manual) { +/* Write 1 to mode key for manual control */ + ret =macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].mode,1 , +1 ); +if (ret <0 ) +return ret; + + hwmon->fan.fans[channel].manual = true; + } +return macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].set, val,1 ); + }else if (!val) { +if (hwmon->fan.fans[channel].manual) { + ret =macsmc_hwmon_write_key (hwmon->smc, + &hwmon->fan.fans[channel].mode,0 ,1 ); +if (ret <0 ) +return ret; + + hwmon->fan.fans[channel].manual = false; + } + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int macsmc_hwmon_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct macsmc_hwmon *hwmon =dev_get_drvdata (dev); +int ret =0 ; + +switch (type) { +case hwmon_temp: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->temp.sensors[channel],1000 , val); +break ; +case hwmon_in: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->volt.sensors[channel],1000 , val); +break ; +case hwmon_curr: + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->curr.sensors[channel],1000 , val); +break ; +case hwmon_power: +/* SMC returns power in Watts with acceptable precision to scale to uW */ + ret =macsmc_hwmon_read_key (hwmon->smc, + &hwmon->power.sensors[channel], +1000000 , val); +break ; +case hwmon_fan: + ret =macsmc_hwmon_read_fan (hwmon, attr, channel, val); +break ; +default : +return -EOPNOTSUPP ; + } + +return ret; +} + +static int macsmc_hwmon_write (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long val) +{ +switch (type) { +case hwmon_fan: +return macsmc_hwmon_write_fan (dev, attr, channel, val); +default : +return -EOPNOTSUPP ; + } +} + +static umode_t macsmc_hwmon_fan_is_visible (const void *data,u32 attr, +int channel) +{ +const struct macsmc_hwmon *hwmon = data; + +if (fan_control && attr == hwmon_fan_target && + hwmon->fan.fans[channel].mode.macsmc_key !=0 ) +return 0644 ; + +return 0444 ; +} + +static umode_t macsmc_hwmon_is_visible (const void *data, +enum hwmon_sensor_types type,u32 attr, +int channel) +{ +switch (type) { +case hwmon_fan: +return macsmc_hwmon_fan_is_visible (data, attr, channel); +default : +break ; + } + +return 0444 ; +} + +static const struct hwmon_ops macsmc_hwmon_ops = { + .is_visible = macsmc_hwmon_is_visible, + .read = macsmc_hwmon_read, + .read_string = macsmc_hwmon_read_label, + .write = macsmc_hwmon_write, +}; + +/* +* Get the key metadata, including key data type, from the SMC. +*/ +static int macsmc_hwmon_parse_key (struct device *dev,struct apple_smc *smc, +struct macsmc_hwmon_sensor *sensor, +const char *key) +{ +int ret; + + ret =apple_smc_get_key_info (smc,_SMC_KEY (key), &sensor->info); +if (ret) { +dev_err (dev,"Failed to retrieve key info for %s\n" , key); +return ret; + } + + sensor->macsmc_key =_SMC_KEY (key); + +return 0 ; +} + +/* +* A sensor is a single key-value pair as made available by the SMC. +* The devicetree gives us the SMC key ID and a friendly name where the +* purpose of the sensor is known. +*/ +static int macsmc_hwmon_create_sensor (struct device *dev,struct apple_smc *smc, +struct device_node *sensor_node, +struct macsmc_hwmon_sensor *sensor) +{ +const char *key, *label; +int ret; + + ret =of_property_read_string (sensor_node,"apple,key-id" , &key); +if (ret) { +dev_err (dev,"Could not find apple,key-id in sensor node\n" );
drivers/hwmon/macsmc_hwmon.c line 493
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+return ret; + } + + ret =macsmc_hwmon_parse_key (dev, smc, sensor, key); +if (ret) +return ret; + + ret =of_property_read_string (sensor_node,"label" , &label); +if (ret) { +dev_err (dev,"No label found for sensor %s\n" , key);
see discussion in the dt-bindings patch, if the label is just for human convenience this should not fail but use the key-id as fallback.
Quoted 336 lines
drivers/hwmon/macsmc_hwmon.c new file +336
-0+return ret; + } + +strscpy_pad (sensor->label, label,sizeof (sensor->label)); + +return 0 ; +} + +/* +* Fan data is exposed by the SMC as multiple sensors. +* +* The devicetree schema reuses apple,key-id for the actual fan speed sensor. +* Min, max and target keys do not need labels, so we can reuse label +* for naming the entire fan. +*/ +static int macsmc_hwmon_create_fan (struct device *dev,struct apple_smc *smc, +struct device_node *fan_node, +struct macsmc_hwmon_fan *fan) +{ +const char *label, *now, *min, *max, *set, *mode; +int ret; + + ret =of_property_read_string (fan_node,"apple,key-id" , &now); +if (ret) { +dev_err (dev,"apple,key-id not found in fan node!\n" ); +return -EINVAL ; + } + + ret =macsmc_hwmon_parse_key (dev, smc, &fan->now, now); +if (ret) +return ret; + + ret =of_property_read_string (fan_node,"label" , &label); +if (ret) { +dev_err (dev,"No label found for fan %s\n" , now); +return ret; + } + +strscpy_pad (fan->label, label,sizeof (fan->label)); + + fan->attrs =HWMON_F_LABEL |HWMON_F_INPUT ; + +/* The following keys are not required to simply monitor fan speed */ +if (!of_property_read_string (fan_node,"apple,fan-minimum" , &min)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->min, min); +if (ret) +return ret; + + fan->attrs |=HWMON_F_MIN ; + } + +if (!of_property_read_string (fan_node,"apple,fan-maximum" , &max)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->max, max); +if (ret) +return ret; + + fan->attrs |=HWMON_F_MAX ; + } + +if (!of_property_read_string (fan_node,"apple,fan-target" , &set)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->set, set); +if (ret) +return ret; + + fan->attrs |=HWMON_F_TARGET ; + } + +if (!of_property_read_string (fan_node,"apple,fan-mode" , &mode)) { + ret =macsmc_hwmon_parse_key (dev, smc, &fan->mode, mode); +if (ret) +return ret; + } + +/* Initialise fan control mode to automatic */ + fan->manual = false; + +return 0 ; +} + +static int macsmc_hwmon_populate_sensors (struct macsmc_hwmon *hwmon, +struct device_node *hwmon_node) +{ +struct device_node *key_node__maybe_unused ; +u32 n_current =0 , n_fan =0 , n_power =0 , n_temperature =0 , n_voltage =0 ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"current-" ) { + n_current++; + } + +if (n_current) { + hwmon->curr.sensors =devm_kcalloc (hwmon->dev, n_current, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->curr.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"current-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->curr.sensors[hwmon->curr.count])) + hwmon->curr.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"fan-" ) { + n_fan++; + } + +if (n_fan) { + hwmon->fan.fans =devm_kcalloc (hwmon->dev, n_fan, +sizeof (struct macsmc_hwmon_fan ),GFP_KERNEL ); +if (!hwmon->fan.fans) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"fan-" ) { +if (!macsmc_hwmon_create_fan (hwmon->dev, hwmon->smc, key_node, + &hwmon->fan.fans[hwmon->fan.count])) + hwmon->fan.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"power-" ) { + n_power++; + } + +if (n_power) { + hwmon->power.sensors =devm_kcalloc (hwmon->dev, n_power, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->power.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"power-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->power.sensors[hwmon->power.count])) + hwmon->power.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"temperature-" ) { + n_temperature++; + } + +if (n_temperature) { + hwmon->temp.sensors =devm_kcalloc (hwmon->dev, n_temperature, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->temp.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"temperature-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->temp.sensors[hwmon->temp.count])) + hwmon->temp.count++; + } + } + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"voltage-" ) { + n_voltage++; + } + +if (n_voltage) { + hwmon->volt.sensors =devm_kcalloc (hwmon->dev, n_voltage, +sizeof (struct macsmc_hwmon_sensor ),GFP_KERNEL ); +if (!hwmon->volt.sensors) +return -ENOMEM ; + +for_each_child_of_node_with_prefix (hwmon_node, key_node,"volt-" ) { +if (!macsmc_hwmon_create_sensor (hwmon->dev, hwmon->smc, key_node, + &hwmon->volt.sensors[hwmon->volt.count])) + hwmon->volt.count++; + } + } + +return 0 ; +} + +/* Create NULL-terminated config arrays */ +static void macsmc_hwmon_populate_configs (u32 *configs,u32 num_keys,u32 flags) +{ +int idx; + +for (idx =0 ; idx < num_keys; idx++) + configs[idx] = flags; +} + +static void macsmc_hwmon_populate_fan_configs (u32 *configs,u32 num_keys, +struct macsmc_hwmon_fans *fans) +{ +int idx; + +for (idx =0 ; idx < num_keys; idx++) + configs[idx] = fans->fans[idx].attrs; +} + +static const struct hwmon_channel_info *const macsmc_chip_channel_info = +HWMON_CHANNEL_INFO (chip,HWMON_C_REGISTER_TZ ); + +static int macsmc_hwmon_create_infos (struct macsmc_hwmon *hwmon) +{ +struct hwmon_channel_info *channel_info; +int i =0 ; + +/* chip */ + hwmon->channel_infos[i++] = macsmc_chip_channel_info; + +if (hwmon->curr.count) { + channel_info = &hwmon->curr.channel_info; + channel_info->type = hwmon_curr; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->curr.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->curr.count, + (HWMON_C_INPUT |HWMON_C_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->fan.count) { + channel_info = &hwmon->fan.channel_info; + channel_info->type = hwmon_fan; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->fan.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_fan_configs ((u32 *)channel_info->config, + hwmon->fan.count, + &hwmon->fan); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->power.count) { + channel_info = &hwmon->power.channel_info; + channel_info->type = hwmon_power; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->power.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->power.count, + (HWMON_P_INPUT |HWMON_P_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->temp.count) { + channel_info = &hwmon->temp.channel_info; + channel_info->type = hwmon_temp; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->temp.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->temp.count, + (HWMON_T_INPUT |HWMON_T_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +if (hwmon->volt.count) { + channel_info = &hwmon->volt.channel_info; + channel_info->type = hwmon_in; + channel_info->config =devm_kcalloc (hwmon->dev, hwmon->volt.count +1 , +sizeof (u32),GFP_KERNEL ); +if (!channel_info->config) +return -ENOMEM ; + +macsmc_hwmon_populate_configs ((u32 *)channel_info->config, + hwmon->volt.count, + (HWMON_I_INPUT |HWMON_I_LABEL )); + hwmon->channel_infos[i++] = channel_info; + } + +return 0 ; +} + +static int macsmc_hwmon_probe (struct platform_device *pdev) +{ +struct apple_smc *smc =dev_get_drvdata (pdev->dev.parent); +struct macsmc_hwmon *hwmon; +int ret; + +/* +* The MFD driver will try to probe us unconditionally. Some devices +* with the SMC do not have hwmon capabilities. Only probe if we have +* a hwmon node. +*/ +if (!pdev->dev.of_node) +return -ENODEV ; + + hwmon =devm_kzalloc (&pdev->dev,sizeof (*hwmon), +GFP_KERNEL ); +if (!hwmon) +return -ENOMEM ; + + hwmon->dev = &pdev->dev; + hwmon->smc = smc; + + ret =macsmc_hwmon_populate_sensors (hwmon, hwmon->dev->of_node); +if (ret) { +dev_err (hwmon->dev,"Could not populate keys!\n" ); +return ret; + } + +if (!hwmon->curr.count && !hwmon->fan.count && + !hwmon->power.count && !hwmon->temp.count && + !hwmon->volt.count) { +dev_err (hwmon->dev, +"No valid keys found of any supported type" ); +return -ENODEV ; + } + + ret =macsmc_hwmon_create_infos (hwmon); +if (ret) +return ret; + + hwmon->chip_info.ops = &macsmc_hwmon_ops; + hwmon->chip_info.info = + (const struct hwmon_channel_info *const *)&hwmon->channel_infos; + + hwmon->hwmon_dev =devm_hwmon_device_register_with_info (&pdev->dev, +"macsmc_hwmon" , hwmon, + &hwmon->chip_info,NULL ); +if (IS_ERR (hwmon->hwmon_dev)) +return dev_err_probe (hwmon->dev,PTR_ERR (hwmon->hwmon_dev), +"Probing SMC hwmon device failed\n" ); + +dev_info (hwmon->dev,"Registered SMC hwmon device. Sensors:" ); +dev_info (hwmon->dev, +"Current: %d, Fans: %d, Power: %d, Temperature: %d, Voltage: %d" , + hwmon->curr.count, hwmon->fan.count, + hwmon->power.count, hwmon->temp.count, + hwmon->volt.count); + +return 0 ; +} +
drivers/hwmon/macsmc_hwmon.c line 839
Quoted 10 lines
drivers/hwmon/macsmc_hwmon.c new file +10
-0+static const struct of_device_id macsmc_hwmon_of_table[] = { + { .compatible ="apple,smc-hwmon" }, + {} +}; +MODULE_DEVICE_TABLE (of, macsmc_hwmon_of_table); + +static struct platform_driver macsmc_hwmon_driver = { + .probe = macsmc_hwmon_probe, + .driver = { + .name ="macsmc_hwmon" ,
macsmc-hwmon
drivers/hwmon/macsmc_hwmon.c line 848
Quoted 9 lines
drivers/hwmon/macsmc_hwmon.c new file +9
-0+ .of_match_table = macsmc_hwmon_of_table, + }, +}; +module_platform_driver (macsmc_hwmon_driver); + +MODULE_DESCRIPTION ("Apple Silicon SMC hwmon driver" ); +MODULE_AUTHOR ("James Calligeros <[email protected]>" ); +MODULE_LICENSE ("Dual MIT/GPL" ); +MODULE_ALIAS ("platform:macsmc_hwmon" );
The module alias should be removed when using MFD_CELL_OF in macsmc.c
Janne
PATCH v2 6/11 mfd: macsmc: Wire up Apple SMC hwmon subdevice
In reply to James CalligerosAdd the SMC hwmon functionality to the mfd device
--- drivers/mfd/macsmc.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/macsmc.c +1 -0
@@ -46,6 +46,7 @@static const struct mfd_cell apple_smc_devs[] = {MFD_CELL_OF ("macsmc-gpio" ,NULL ,NULL ,0 ,0 ,"apple,smc-gpio" ), +MFD_CELL_OF ("macsmc_hwmon" ,NULL ,NULL ,0 ,0 ,"apple,smc-hwmon" ),MFD_CELL_OF ("macsmc-reboot" ,NULL ,NULL ,0 ,0 ,"apple,smc-reboot" ),MFD_CELL_OF ("macsmc-rtc" ,NULL ,NULL ,0 ,0 ,"apple,smc-rtc" ), };
Signature · 1 line
2.51.0
PATCH v2 7/11 input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lid
In reply to James CalligerosFrom: Hector Martin <[email protected]>
This driver implements power button and lid switch support for Apple Mac devices using SMC controllers driven by the macsmc driver.
In addition to basic input support, this also responds to the final shutdown warning (when the power button is held down long enough) by doing an emergency kernel poweroff. This allows the NVMe controller to be cleanly shut down, which prevents data loss for in-cache data.
--- MAINTAINERS | 1 + drivers/input/misc/Kconfig | 11 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/macsmc-hid.c | 209 +++++++++++++++++++++++++ 4 files changed, 222 insertions(+)
MAINTAINERS +1 -0
@@ -2412,6 +2412,7 @@ F: drivers/hwmon/macsmc_hwmon.c F: drivers/pmdomain/apple/ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.c +F: drivers/input/misc/macsmc-hid.c F: drivers/input/touchscreen/apple_z2.c F: drivers/iommu/apple-dart.c F: drivers/iommu/io-pgtable-dart.c
drivers/input/misc/Kconfig +11 -0
@@ -961,4 +961,15 @@ config INPUT_STPMIC1_ONKEY To compile this driver as a module, choose M here: the module will be called stpmic1_onkey. +config INPUT_MACSMC_HID + tristate "Apple Mac SMC lid/buttons" + depends on MFD_MACSMC + help + Say Y here if you want to use the input events delivered via the + SMC controller on Apple Mac machines using the macsmc driver. + This includes lid open/close and the power button. + + To compile this driver as a module, choose M here: the + module will be called macsmc-hid. + endif
drivers/input/misc/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_INPUT_IQS7222) += iqs7222.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o +obj-$(CONFIG_INPUT_MACSMC_HID) += macsmc-hid.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o
drivers/input/misc/macsmc-hid.c new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.51.0
Dmitry Torokhov
maintainerRe: [PATCH v2 07/11] input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lid
Hi James,
Quoted 5 lines · James Calligeros
drivers/input/misc/macsmc-hid.c new file +5
-0+static void macsmc_hid_event_button (struct macsmc_hid *smchid,unsigned long event) +{ +u8 button = (event >>8 ) &0xff ; +u8 state = !!(event &0xff ); +
drivers/input/misc/macsmc-hid.c line 55
Quoted 10 lines
drivers/input/misc/macsmc-hid.c new file +10
-0+switch (button) { +case BTN_POWER : +case BTN_TOUCHID : +if (smchid->wakeup_mode) { +if (state) +pm_wakeup_hard_event (smchid->dev); + }else { +input_report_key (smchid->input,KEY_POWER , state); +input_sync (smchid->input); + }
I believe you should be using pm_wakeup_event() in all cases so that pressing power would interrupt suspend even if resume() handler has not been run yet. Also I do not think suppressing KEY_POWER is needed. Userspace should be smart and decide whether to shutdown the system or not when receiving KEY_POWER depending on the overall system state.
...
drivers/input/misc/macsmc-hid.c line 113
Quoted 7 lines
drivers/input/misc/macsmc-hid.c new file +7
-0+ +static int macsmc_hid_probe (struct platform_device *pdev) +{ +struct apple_smc *smc =dev_get_drvdata (pdev->dev.parent); +struct macsmc_hid *smchid; +bool have_lid, have_power; +int ret;
int error;
Quoted 42 lines
drivers/input/misc/macsmc-hid.c new file +42
-0+ +/* Bail early if this SMC neither supports power button nor lid events */ + have_lid =apple_smc_key_exists (smc,SMC_KEY (MSLD )); + have_power =apple_smc_key_exists (smc,SMC_KEY (bHLD)); +if (!have_lid && !have_power) +return -ENODEV ; + + smchid =devm_kzalloc (&pdev->dev,sizeof (*smchid),GFP_KERNEL ); +if (!smchid) +return -ENOMEM ; + + smchid->dev = &pdev->dev; + smchid->smc = smc; +platform_set_drvdata (pdev, smchid); + + smchid->input =devm_input_allocate_device (&pdev->dev); +if (!smchid->input) +return -ENOMEM ; + + smchid->input->phys ="macsmc-hid (0)" ; + smchid->input->name ="Apple SMC power/lid events" ; + +if (have_lid) +input_set_capability (smchid->input,EV_SW ,SW_LID ); +if (have_power) +input_set_capability (smchid->input,EV_KEY ,KEY_POWER ); + + ret =input_register_device (smchid->input); +if (ret) { +dev_err (&pdev->dev,"Failed to register input device: %d\n" , ret); +return ret; + } + +if (have_lid) { +u8 val; + + ret =apple_smc_read_u8 (smc,SMC_KEY (MSLD ), &val); +if (ret <0 ) +dev_warn (&pdev->dev,"Failed to read initial lid state\n" ); +else +input_report_switch (smchid->input,SW_LID , val); + }
drivers/input/misc/macsmc-hid.c line 165
Quoted 10 lines
drivers/input/misc/macsmc-hid.c new file +10
-0+ +if (have_power) { +u32 val; + + ret =apple_smc_read_u32 (smc,SMC_KEY (bHLD), &val); +if (ret <0 ) +dev_warn (&pdev->dev,"Failed to read initial power button state\n" ); +else +input_report_key (smchid->input,KEY_POWER , val &1 ); + }
Since you are doing this to seed initial switch/button state I would do this before registering input device (this is safe to do so).
Thanks.
Signature · 1 line
Dmitry
Janne Grunau
maintainerRe: [PATCH v2 07/11] input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lid
Quoted 14 lines · Dmitry Torokhov
Hi James,
Quoted 11 lines · James Calligeros
drivers/input/misc/macsmc-hid.c new file +11
-0+static void macsmc_hid_event_button (struct macsmc_hid *smchid,unsigned long event) +{ +u8 button = (event >>8 ) &0xff ; +u8 state = !!(event &0xff ); + +switch (button) { +case BTN_POWER : +case BTN_TOUCHID : +if (smchid->wakeup_mode) { +if (state) +pm_wakeup_hard_event (smchid->dev);
Quoted 8 lines
drivers/input/misc/macsmc-hid.c line 55
Quoted 4 lines
drivers/input/misc/macsmc-hid.c new file +4
-0+ }else { +input_report_key (smchid->input,KEY_POWER , state); +input_sync (smchid->input); + }I believe you should be using
pm_wakeup_event()in all cases so that pressing power would interrupt suspend even ifresume()handler has not been run yet.
pm_wakeup_event() does not wake from s2idle. pm_wakeup_dev_event()'s hard parameter is explicitily documented to wake from s2idle. So using pm_wakeup_dev_event and use smchid->wakeup_mode && state as hard parameter seems the correct thing to do.
Quoted 3 lines
Also I do not think suppressing
KEY_POWERis needed. Userspace should be smart and decide whether to shutdown the system or not when receivingKEY_POWERdepending on the overall system state.
Not all user space. Using the power button to wake from s2idle while showing agetty's login prompt on a tty results in an immediate shutdown.
Janne
Janne Grunau
maintainerRe: [PATCH v2 07/11] input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lid
In reply to James CalligerosQuoted 14 lines · James Calligeros
From: Hector Martin <[email protected]>
This driver implements power button and lid switch support for Apple Mac devices using SMC controllers driven by the macsmc driver.
In addition to basic input support, this also responds to the final shutdown warning (when the power button is held down long enough) by doing an emergency kernel poweroff. This allows the NVMe controller to be cleanly shut down, which prevents data loss for in-cache data.
Signed-off-by Hector Martin <[email protected]>Co-developed-by Sven Peter <[email protected]>Signed-off-by Sven Peter <[email protected]>Signed-off-by James Calligeros <[email protected]>
Quoted 5 lines
--- MAINTAINERS | 1 + drivers/input/misc/Kconfig | 11 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/macsmc-hid.c | 209 +++++++++++++++++++++++++
I would rename this driver to macsmc-input. I would expect hid driver to live in drivers/hid/ and use HID report descriptors
Quoted 251 lines
4 files changed, 222 insertions(+)MAINTAINERS +1
-0@@ -2412,6 +2412,7 @@ F: drivers/hwmon/macsmc_hwmon.c F: drivers/pmdomain/apple/ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.c +F: drivers/input/misc/macsmc-hid.c F: drivers/input/touchscreen/apple_z2.c F: drivers/iommu/apple-dart.c F: drivers/iommu/io-pgtable-dart.cdrivers/input/misc/Kconfig +11
-0@@ -961,4 +961,15 @@ config INPUT_STPMIC1_ONKEY To compile this driver as a module, choose M here: the module will be called stpmic1_onkey. +config INPUT_MACSMC_HID + tristate "Apple Mac SMC lid/buttons" + depends on MFD_MACSMC + help + Say Y here if you want to use the input events delivered via the + SMC controller on Apple Mac machines using the macsmc driver. + This includes lid open/close and the power button. + + To compile this driver as a module, choose M here: the + module will be called macsmc-hid. + endifdrivers/input/misc/Makefile +1
-0@@ -51,6 +51,7 @@ obj-$(CONFIG_INPUT_IQS7222) += iqs7222.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o +obj-$(CONFIG_INPUT_MACSMC_HID) += macsmc-hid.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.odrivers/input/misc/macsmc-hid.c new file +199
-0@@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* +* Apple SMC input event driver +* Copyright The Asahi Linux Contributors +* +* This driver exposes HID events from the SMC as an input device. +* This includes the lid open/close and power button notifications. +*/ + +#include <linux/device.h> +#include <linux/input.h> +#include <linux/mfd/core.h> +#include <linux/mfd/macsmc.h> +#include <linux/module.h> +#include <linux/reboot.h> + +/** +* struct macsmc_hid +* @dev: Underlying struct device for the HID sub-device +* @smc: Pointer to apple_smc struct of the mfd parent +* @input: Allocated input_dev; devres managed +* @nb: Notifier block used for incoming events from SMC (e.g. button pressed down) +* @wakeup_mode: Set to true when system is suspended and power button events should wake it +*/ +struct macsmc_hid { +struct device *dev; +struct apple_smc *smc; +struct input_dev *input; +struct notifier_block nb; +bool wakeup_mode; +}; + +#define SMC_EV_BTN 0x7201 +#define SMC_EV_LID 0x7203 + +#define BTN_POWER 0x01/* power button on e.g. Mac Mini chasis pressed */ +#define BTN_TOUCHID 0x06/* combined TouchID / power button on MacBooks pressed */ +#define BTN_POWER_HELD_SHORT 0xfe/* power button briefly held down */ +#define BTN_POWER_HELD_LONG 0x00/* power button held down; sent just before forced poweroff */ + +static void macsmc_hid_event_button (struct macsmc_hid *smchid,unsigned long event) +{ +u8 button = (event >>8 ) &0xff ; +u8 state = !!(event &0xff ); + +switch (button) { +case BTN_POWER : +case BTN_TOUCHID : +if (smchid->wakeup_mode) { +if (state) +pm_wakeup_hard_event (smchid->dev); + }else { +input_report_key (smchid->input,KEY_POWER , state); +input_sync (smchid->input); + } +break ; +case BTN_POWER_HELD_SHORT :/* power button held down; ignore */ +break ; +case BTN_POWER_HELD_LONG : +/* +* If we get here the power button has been held down for a while and +* we have about 4 seconds before forced power-off is triggered by SMC. +* Try to do an emergency shutdown to make sure the NVMe cache is +* flushed. macOS actually does this by panicing (!)... +*/ +if (state) { +dev_crit (smchid->dev,"Triggering forced shutdown!\n" ); +if (kernel_can_power_off ()) +kernel_power_off (); +else /* Missing macsmc-reboot driver? */ +kernel_restart ("SMC power button triggered restart" ); + } +break ; +default : +dev_warn (smchid->dev,"Unknown SMC button event: %04lx\n" , event &0xffff ); + } +} + +static void macsmc_hid_event_lid (struct macsmc_hid *smchid,unsigned long event) +{ +u8 lid_state = !!((event >>8 ) &0xff ); + +if (smchid->wakeup_mode && !lid_state) +pm_wakeup_hard_event (smchid->dev); + +input_report_switch (smchid->input,SW_LID , lid_state); +input_sync (smchid->input); +} + +static int macsmc_hid_event (struct notifier_block *nb,unsigned long event,void *data) +{ + struct macsmc_hid *smchid = container_of(nb, struct macsmc_hid, nb); +u16 type = event >>16 ; + +switch (type) { +case SMC_EV_BTN : +macsmc_hid_event_button (smchid, event); +return NOTIFY_OK ; +case SMC_EV_LID : +macsmc_hid_event_lid (smchid, event); +return NOTIFY_OK ; +default : +/* SMC event meant for another driver */ +return NOTIFY_DONE ; + } +} + +static int macsmc_hid_probe (struct platform_device *pdev) +{ +struct apple_smc *smc =dev_get_drvdata (pdev->dev.parent); +struct macsmc_hid *smchid; +bool have_lid, have_power; +int ret; + +/* Bail early if this SMC neither supports power button nor lid events */ + have_lid =apple_smc_key_exists (smc,SMC_KEY (MSLD )); + have_power =apple_smc_key_exists (smc,SMC_KEY (bHLD)); +if (!have_lid && !have_power) +return -ENODEV ; + + smchid =devm_kzalloc (&pdev->dev,sizeof (*smchid),GFP_KERNEL ); +if (!smchid) +return -ENOMEM ; + + smchid->dev = &pdev->dev; + smchid->smc = smc; +platform_set_drvdata (pdev, smchid); + + smchid->input =devm_input_allocate_device (&pdev->dev); +if (!smchid->input) +return -ENOMEM ; + + smchid->input->phys ="macsmc-hid (0)" ; + smchid->input->name ="Apple SMC power/lid events" ; + +if (have_lid) +input_set_capability (smchid->input,EV_SW ,SW_LID ); +if (have_power) +input_set_capability (smchid->input,EV_KEY ,KEY_POWER ); + + ret =input_register_device (smchid->input); +if (ret) { +dev_err (&pdev->dev,"Failed to register input device: %d\n" , ret); +return ret; + } + +if (have_lid) { +u8 val; + + ret =apple_smc_read_u8 (smc,SMC_KEY (MSLD ), &val); +if (ret <0 ) +dev_warn (&pdev->dev,"Failed to read initial lid state\n" ); +else +input_report_switch (smchid->input,SW_LID , val); + } + +if (have_power) { +u32 val; + + ret =apple_smc_read_u32 (smc,SMC_KEY (bHLD), &val); +if (ret <0 ) +dev_warn (&pdev->dev,"Failed to read initial power button state\n" ); +else +input_report_key (smchid->input,KEY_POWER , val &1 ); + } + +input_sync (smchid->input); + + smchid->nb.notifier_call = macsmc_hid_event; +blocking_notifier_chain_register (&smc->event_handlers, &smchid->nb); + +device_init_wakeup (&pdev->dev,1 ); + +return 0 ; +} + +static int macsmc_hid_pm_prepare (struct device *dev) +{ +struct macsmc_hid *smchid =dev_get_drvdata (dev); + + smchid->wakeup_mode = true; +return 0 ; +} + +static void macsmc_hid_pm_complete (struct device *dev) +{ +struct macsmc_hid *smchid =dev_get_drvdata (dev); + + smchid->wakeup_mode = false; +} + +static const struct dev_pm_ops macsmc_hid_pm_ops = { + .prepare = macsmc_hid_pm_prepare, + .complete = macsmc_hid_pm_complete, +}; + +static struct platform_driver macsmc_hid_driver = { + .driver = { + .name ="macsmc-hid" ,
drivers/input/misc/macsmc-hid.c line 209
Quoted 10 lines
drivers/input/misc/macsmc-hid.c new file +10
-0+ .pm = &macsmc_hid_pm_ops, + }, + .probe = macsmc_hid_probe, +}; +module_platform_driver (macsmc_hid_driver); + +MODULE_AUTHOR ("Hector Martin <[email protected]>" ); +MODULE_LICENSE ("Dual MIT/GPL" ); +MODULE_DESCRIPTION ("Apple SMC HID driver" ); +MODULE_ALIAS ("platform:macsmc-hid" );
The module alias should be removed.
Janne
PATCH v2 8/11 mfd: macsmc: Wire up Apple SMC HID subdevice
In reply to James CalligerosAdd the new SMC HID function to the mfd device
--- drivers/mfd/macsmc.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/macsmc.c +1 -0
@@ -45,6 +45,7 @@#define SMC_TIMEOUT_MS 500static const struct mfd_cell apple_smc_devs[] = { +MFD_CELL_NAME ("macsmc-hid" ),MFD_CELL_OF ("macsmc-gpio" ,NULL ,NULL ,0 ,0 ,"apple,smc-gpio" ),MFD_CELL_OF ("macsmc_hwmon" ,NULL ,NULL ,0 ,0 ,"apple,smc-hwmon" ),MFD_CELL_OF ("macsmc-reboot" ,NULL ,NULL ,0 ,0 ,"apple,smc-reboot" ),
Signature · 1 line
2.51.0
Janne Grunau
maintainerRe: [PATCH v2 08/11] mfd: macsmc: Wire up Apple SMC HID subdevice
Quoted 12 lines · James Calligeros
Add the new SMC HID function to the mfd device
Signed-off-by James Calligeros <[email protected]>--- drivers/mfd/macsmc.c | 1 + 1 file changed, 1 insertion(+)drivers/mfd/macsmc.c +0
-0
drivers/mfd/macsmc.c line 48
Quoted 4 lines
drivers/mfd/macsmc.c +1
-0@@ -45,6 +45,7 @@#define SMC_TIMEOUT_MS 500static const struct mfd_cell apple_smc_devs[] = { +MFD_CELL_NAME ("macsmc-hid" ),
I think it would make sense to use MFD_CELL_OF and device nodes for all macsmc even though it's in the case of macsmc-input (or -hid) not strictly necessary
drivers/mfd/macsmc.c line 51
Quoted 3 lines
drivers/mfd/macsmc.c +0
-0MFD_CELL_OF ("macsmc-gpio" ,NULL ,NULL ,0 ,0 ,"apple,smc-gpio" ),MFD_CELL_OF ("macsmc_hwmon" ,NULL ,NULL ,0 ,0 ,"apple,smc-hwmon" ), MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),
Janne
PATCH v2 9/11 arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node
In reply to James CalligerosFrom: Sven Peter <[email protected]>
The System Manager Controller of all M1/M2 SoCs supports the RTC sub-device.
--- .../arm64/boot/dts/apple/t600x-die0.dtsi | 6 ++++++ arch/arm64/boot/dts/apple/t8103.dtsi | 6 ++++++ arch/arm64/boot/dts/apple/t8112.dtsi | 6 ++++++ 3 files changed, 18 insertions(+)
arch/arm64/boot/dts/apple/t600x-die0.dtsi +6 -0
@@ -44,6 +44,12 @@ smc_reboot: reboot { nvmem-cell-names = "shutdown_flag", "boot_stage", "boot_error_count", "panic_count"; }; + + rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; }; smc_mbox: mbox@290408000 {
arch/arm64/boot/dts/apple/t8103.dtsi +6 -0
@@ -916,6 +916,12 @@ smc_reboot: reboot { nvmem-cell-names = "shutdown_flag", "boot_stage", "boot_error_count", "panic_count"; }; + + rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; }; smc_mbox: mbox@23e408000 {
arch/arm64/boot/dts/apple/t8112.dtsi +6 -0
@@ -919,6 +919,12 @@ smc_reboot: reboot { nvmem-cell-names = "shutdown_flag", "boot_stage", "boot_error_count", "panic_count"; }; + + rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; }; smc_mbox: mbox@23e408000 {
Signature · 1 line
2.51.0
PATCH v2 10/11 arm64: dts: apple: Add common hwmon sensors and fans
In reply to James CalligerosEach Apple Silicon device exposes a unique set of sensors and fans, however some have been found to be reliably common across devices.
Add these as .dtsi files so that they can be combined with any device-specific sensors without excessive repetition.
--- .../boot/dts/apple/hwmon-common.dtsi | 37 +++++++++++++++++++++++++ .../boot/dts/apple/hwmon-fan-dual.dtsi | 24 ++++++++++++++++ arch/arm64/boot/dts/apple/hwmon-fan.dtsi | 19 +++++++++++++ .../boot/dts/apple/hwmon-laptop.dtsi | 35 +++++++++++++++++++++++ .../boot/dts/apple/hwmon-mac-mini.dtsi | 17 ++++++++++++ 5 files changed, 132 insertions(+)
arch/arm64/boot/dts/apple/hwmon-common.dtsi new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * Hardawre monitoring sensors expected to be found on all Apple Silicon devices + * + * Copyright The Asahi Linux Contributors + */ + +&smc { + hwmon { + compatible = "apple,smc-hwmon"; + + current-ID0R { + apple,key-id = "ID0R"; + label = "AC Input Current"; + }; + power-PSTR { + apple,key-id = "PSTR"; + label = "Total System Power"; + }; + power-PDTR { + apple,key-id = "PDTR"; + label = "AC Input Power"; + }; + power-PMVR { + apple,key-id = "PMVR"; + label = "3.8 V Rail Power"; + }; + temperature-TH0x { + apple,key-id = "TH0x"; + label = "NAND Flash Temperature"; + }; + voltage-VD0R { + apple,key-id = "VD0R"; + label = "AC Input Voltage"; + }; + }; +};
arch/arm64/boot/dts/apple/hwmon-fan-dual.dtsi new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * SMC hwmon fan keys for Apple Silicon desktops/laptops with two fans + * + * Copyright The Asahi Linux Contributors + */ + +#include "hwmon-fan.dtsi" + +&smc { + hwmon { + fan-F0Ac { + label = "Fan 1"; + }; + fan-F1Ac { + apple,key-id = "F1Ac"; + label = "Fan 2"; + apple,fan-minimum = "F1Mn"; + apple,fan-maximum = "F1Mx"; + apple,fan-target = "F1Tg"; + apple,fan-mode = "F1Md"; + }; + }; +};
arch/arm64/boot/dts/apple/hwmon-fan.dtsi new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * hwmon fan keys for Apple Silicon desktops/laptops with a single fan. + * + * Copyright The Asahi Linux Contributors + */ + +&smc { + hwmon { + fan-F0Ac { + apple,key-id = "F0Ac"; + label = "Fan"; + apple,fan-minimum = "F0Mn"; + apple,fan-maximum = "F0Mx"; + apple,fan-target = "F0Tg"; + apple,fan-mode = "F0Md"; + }; + }; +};
arch/arm64/boot/dts/apple/hwmon-laptop.dtsi new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * Hardware monitoring sensors expected on all Apple Silicon laptops + * + * Copyright The Asahi Linux Contributors + */ + +&smc { + hwmon { + power-PHPC { + apple,key-id = "PHPC"; + label = "Heatpipe Power"; + }; + temperature-TB0T { + apple,key-id = "TB0T"; + label = "Battery Hotspot Temperature"; + }; + temperature-TCHP { + apple,key-id = "TCHP"; + label = "Charge Regulator Temperature"; + }; + temperature-TW0P { + apple,key-id = "TW0P"; + label = "WiFi/BT Module Temperature"; + }; + voltage-SBAV { + apple,key-id = "SBAV"; + label = "Battery Voltage"; + }; + voltage-VD0R { + apple,key-id = "VD0R"; + label = "Charger Input Voltage"; + }; + }; +};
arch/arm64/boot/dts/apple/hwmon-mac-mini.dtsi new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * hwmon sensors expected on all Mac mini models + * + * Copyright The Asahi Linux Contributors + */ + +#include "hwmon-fan.dtsi" + +&smc { + hwmon { + temperature-TW0P { + apple,key-id = "TW0P"; + label = "WiFi/BT Module Temperature"; + }; + }; +};
Signature · 1 line
2.51.0
Janne Grunau
maintainerRe: [PATCH v2 10/11] arm64: dts: apple: Add common hwmon sensors and fans
Quoted 21 lines · James Calligeros
Each Apple Silicon device exposes a unique set of sensors and fans, however some have been found to be reliably common across devices.
Add these as .dtsi files so that they can be combined with any device-specific sensors without excessive repetition.
Signed-off-by James Calligeros <[email protected]>--- .../boot/dts/apple/hwmon-common.dtsi | 37 +++++++++++++++++++++++++ .../boot/dts/apple/hwmon-fan-dual.dtsi | 24 ++++++++++++++++ arch/arm64/boot/dts/apple/hwmon-fan.dtsi | 19 +++++++++++++ .../boot/dts/apple/hwmon-laptop.dtsi | 35 +++++++++++++++++++++++ .../boot/dts/apple/hwmon-mac-mini.dtsi | 17 ++++++++++++ 5 files changed, 132 insertions(+)arch/arm64/boot/dts/apple/hwmon-common.dtsi new file +0
-0
arch/arm64/boot/dts/apple/hwmon-common.dtsi line 3
Quoted 3 lines
arch/arm64/boot/dts/apple/hwmon-common.dtsi new file +3
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * Hardawre monitoring sensors expected to be found on all Apple Silicon devices
typo: "Hardawre"
arch/arm64/boot/dts/apple/hwmon-common.dtsi line 10
Quoted 7 lines
arch/arm64/boot/dts/apple/hwmon-common.dtsi new file +7
-0+ * + * Copyright The Asahi Linux Contributors + */ + +&smc { + hwmon { + compatible = "apple,smc-hwmon";
I think it woiuld make more sense to add the hwmon child node with the compatible in the SoC *.dtsi and then only add the sensor nodes to "&smc_hwmon" in these hwmon-*.dtsi files
Janne
PATCH v2 11/11 arm64: dts: apple: t8103, t600x, t8112: Add common hwmon nodes to devices
In reply to James CalligerosAdd the known, common hwmon-related SMC keys to the DTs for the devices they pertain to.
--- .../arm64/boot/dts/apple/t6001-j375c.dts | 2 ++ .../arm64/boot/dts/apple/t6002-j375d.dts | 2 ++ .../boot/dts/apple/t600x-j314-j316.dtsi | 4 ++++ .../arm64/boot/dts/apple/t600x-j375.dtsi | 2 ++ arch/arm64/boot/dts/apple/t8103-j274.dts | 2 ++ arch/arm64/boot/dts/apple/t8103-j293.dts | 3 +++ arch/arm64/boot/dts/apple/t8103-j313.dts | 2 ++ arch/arm64/boot/dts/apple/t8103-j456.dts | 2 ++ arch/arm64/boot/dts/apple/t8103-j457.dts | 2 ++ .../arm64/boot/dts/apple/t8103-jxxx.dtsi | 2 ++ arch/arm64/boot/dts/apple/t8112-j413.dts | 2 ++ arch/arm64/boot/dts/apple/t8112-j473.dts | 2 ++ arch/arm64/boot/dts/apple/t8112-j493.dts | 3 +++ .../arm64/boot/dts/apple/t8112-jxxx.dtsi | 2 ++ 14 files changed, 32 insertions(+)
arch/arm64/boot/dts/apple/t6001-j375c.dts +2 -0
@@ -16,3 +16,5 @@ / { compatible = "apple,j375c", "apple,t6001", "apple,arm-platform"; model = "Apple Mac Studio (M1 Max, 2022)"; }; + +#include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6002-j375d.dts +2 -0
@@ -48,3 +48,5 @@ hpm5: usb-pd@3a { /delete-node/ &ps_disp0_cpu0_die1; /delete-node/ &ps_disp0_fe_die1; + +#include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +4 -0
@@ -121,3 +121,7 @@ &fpwm0 { }; #include "spi1-nvram.dtsi" + +#include "hwmon-common.dtsi" +#include "hwmon-laptop.dtsi" +#include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t600x-j375.dtsi +2 -0
@@ -128,3 +128,5 @@ &pcie0_dart_3 { }; #include "spi1-nvram.dtsi" + +#include "hwmon-common.dtsi"
arch/arm64/boot/dts/apple/t8103-j274.dts +2 -0
@@ -61,3 +61,5 @@ &pcie0_dart_2 { &i2c2 { status = "okay"; }; + +#include "hwmon-mac-mini.dtsi"
arch/arm64/boot/dts/apple/t8103-j293.dts +3 -0
@@ -119,3 +119,6 @@ dfr_panel_in: endpoint { &displaydfr_dart { status = "okay"; }; + +#include "hwmon-laptop.dtsi" +#include "hwmon-fan.dtsi"
arch/arm64/boot/dts/apple/t8103-j313.dts +2 -0
@@ -41,3 +41,5 @@ &wifi0 { &fpwm1 { status = "okay"; }; + +#include "hwmon-laptop.dtsi"
arch/arm64/boot/dts/apple/t8103-j456.dts +2 -0
@@ -75,3 +75,5 @@ &pcie0_dart_1 { &pcie0_dart_2 { status = "okay"; }; + +#include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t8103-j457.dts +2 -0
@@ -48,3 +48,5 @@ ethernet0: ethernet@0,0 { &pcie0_dart_2 { status = "okay"; }; + +#include "hwmon-fan.dtsi"
arch/arm64/boot/dts/apple/t8103-jxxx.dtsi +2 -0
@@ -92,3 +92,5 @@ &nco_clkref { }; #include "spi1-nvram.dtsi" + +#include "hwmon-common.dtsi"
arch/arm64/boot/dts/apple/t8112-j413.dts +2 -0
@@ -78,3 +78,5 @@ &i2c4 { &fpwm1 { status = "okay"; }; + +#include "hwmon-laptop.dtsi"
arch/arm64/boot/dts/apple/t8112-j473.dts +2 -0
@@ -52,3 +52,5 @@ &pcie1_dart { &pcie2_dart { status = "okay"; }; + +#include "hwmon-mac-mini.dtsi"
arch/arm64/boot/dts/apple/t8112-j493.dts +3 -0
@@ -133,3 +133,6 @@ touchbar0: touchbar@0 { touchscreen-inverted-y; }; }; + +#include "hwmon-laptop.dtsi" +#include "hwmon-fan.dtsi"
arch/arm64/boot/dts/apple/t8112-jxxx.dtsi +2 -0
@@ -81,3 +81,5 @@ &nco_clkref { }; #include "spi1-nvram.dtsi" + +#include "hwmon-common.dtsi"
Signature · 1 line
2.51.0
Guenter Roeck
maintainerQuoted 37 lines · James Calligeros
Hi all,
This series adds support for the remaining SMC subdevices. These are the RTC, hwmon, and HID devices. They are being submitted together as the RTC and hwmon drivers both require changes to the SMC DT schema.
The RTC driver is responsible for getting and setting the system clock, and requires an NVMEM cell. This series replaces Sven's original RTC driver submission [1].
The hwmon function is an interesting one. While each Apple Silicon device exposes pretty similar sets of sensors, these all seem to be paired to different SMC keys in the firmware interface. This is true even when the sensors are on the SoC. For example, an M1 MacBook Pro will use different keys to access the LITTLE core temperature sensors to an M1 Mac mini. This necessitates describing which keys correspond to which sensors for each device individually, and populating the hwmon structs at runtime. We do this with a node in the device tree. This series includes only the keys for sensors which we know to be common to all devices. The SMC is also responsible for monitoring and controlling fan speeds on systems with fans, which we expose via the hwmon driver.
The SMC also handles the hardware power button and lid switch. Power button presses and lid opening/closing are emitted as HID events, so we add a HID subdevice to handle them.
Note that this series is based on a branch with three additional commits applied to add the parent SMC nodes to the relevant Devicetrees. This was done to silence build errors. The series applies cleanly to 6.17-rc1.
Regards,
James
Signed-off-by James Calligeros <[email protected]>
Quoted 10 lines
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Addressed Guenter's initial feedback on the hwmon driver
Don't you think that is a bit useless ? You might as well say "Addressed feedback comments" and be done with the change log.
Guenter
Quoted 11 lines · Guenter Roeck
Quoted 10 lines
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Addressed Guenter's initial feedback on the hwmon driver
Quoted 4 lines
Don't you think that is a bit useless ? You might as well say "Addressed feedback comments" and be done with the change log.
Guenter
I don't think this warrants a v3, so hopefully the amended changelog below will suffice.
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Removed log messages sysfs read/write functions in hwmon driver
- Removed ignored errors from hwmon driver
- Removed uses of dev_err for non-errors in hwmon driver
- Made it more obvious that a number of hwmon fan properties are optional
- Modified hwmon driver to reflect DT schema changes
- Added compatible property to hwmon node
- Link to v1: https://lore.kernel.org/r/[email protected]
James
Quoted 21 lines · James Calligeros
Quoted 11 lines · Guenter Roeck
Quoted 10 lines
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Addressed Guenter's initial feedback on the hwmon driverQuoted 4 lines
Don't you think that is a bit useless ? You might as well say "Addressed feedback comments" and be done with the change log.
Guenter
I don't think this warrants a v3, so hopefully the amended changelog below will suffice.
Quoted 17 lines
---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Removed log messages sysfs read/write functions in hwmon driver
- Removed ignored errors from hwmon driver
- Removed uses ofdev_errfor non-errors in hwmon driver
- Made it more obvious that a number of hwmon fan properties are optional
- Modified hwmon driver to reflect DT schema changes
- Added compatible property to hwmon node
- Link to v1: https://lore.kernel.org/r/[email protected]
Series LGTM.
Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
Alexandre Belloni
maintainerHello,
Quoted 6 lines · James Calligeros
Hi all,
This series adds support for the remaining SMC subdevices. These are the RTC, hwmon, and HID devices. They are being submitted together as the RTC and hwmon drivers both require changes to the SMC DT schema.
How do you expect this to be merged? From what I get, I could just take 1 and 3 as there doesn't seem to be any actual dependencies on any of the other patches and the MFD change doesn't depend on the RTC changes.
Quoted 108 lines
The RTC driver is responsible for getting and setting the system clock, and requires an NVMEM cell. This series replaces Sven's original RTC driver submission [1].
The hwmon function is an interesting one. While each Apple Silicon device exposes pretty similar sets of sensors, these all seem to be paired to different SMC keys in the firmware interface. This is true even when the sensors are on the SoC. For example, an M1 MacBook Pro will use different keys to access the LITTLE core temperature sensors to an M1 Mac mini. This necessitates describing which keys correspond to which sensors for each device individually, and populating the hwmon structs at runtime. We do this with a node in the device tree. This series includes only the keys for sensors which we know to be common to all devices. The SMC is also responsible for monitoring and controlling fan speeds on systems with fans, which we expose via the hwmon driver.
The SMC also handles the hardware power button and lid switch. Power button presses and lid opening/closing are emitted as HID events, so we add a HID subdevice to handle them.
Note that this series is based on a branch with three additional commits applied to add the parent SMC nodes to the relevant Devicetrees. This was done to silence build errors. The series applies cleanly to 6.17-rc1.
Regards,
James
Signed-off-by James Calligeros <[email protected]>---
Changes in v2:
- Added Rob's R-b tag to RTC DT binding
- Removed redundant nesting from hwmon DT binding
- Dedpulicated property definitions in hwmon DT schema
- Made label a required property for hwmon DT nodes
- Clarified semantics in hwmon DT schema definitions
- Split mfd tree changes into separate commits
- Fixed numerous style errors in hwmon driver
- Addressed Guenter's initial feedback on the hwmon driver
- Modified hwmon driver to reflect DT schema changes
- Added compatible property to hwmon node
- Link to v1: https://lore.kernel.org/r/[email protected]---
Hector Martin (2):
rtc: Add new rtc-macsmc driver for Apple Silicon Macs
input: macsmc-hid: New driver to handle the Apple Mac SMC buttons/lidJames Calligeros (7):
dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
mfd: macsmc: Wire up Apple SMC RTC subdevice
hwmon: Add Apple Silicon SMC hwmon driver
mfd: macsmc: Wire up Apple SMC hwmon subdevice
mfd: macsmc: Wire up Apple SMC HID subdevice
arm64: dts: apple: Add common hwmon sensors and fans
arm64: dts: apple: t8103, t600x, t8112: Add common hwmon nodes to devicesSven Peter (2):
dt-bindings: rtc: Add Apple SMC RTC
arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node.../bindings/hwmon/apple,smc-hwmon.yaml | 132 ++++ .../bindings/mfd/apple,smc.yaml | 45 ++ .../bindings/rtc/apple,smc-rtc.yaml | 35 + MAINTAINERS | 5 + .../boot/dts/apple/hwmon-common.dtsi | 37 ++ .../boot/dts/apple/hwmon-fan-dual.dtsi | 24 + arch/arm64/boot/dts/apple/hwmon-fan.dtsi | 19 + .../boot/dts/apple/hwmon-laptop.dtsi | 35 + .../boot/dts/apple/hwmon-mac-mini.dtsi | 17 + .../arm64/boot/dts/apple/t6001-j375c.dts | 2 + .../arm64/boot/dts/apple/t6002-j375d.dts | 2 + .../arm64/boot/dts/apple/t600x-die0.dtsi | 6 + .../boot/dts/apple/t600x-j314-j316.dtsi | 4 + .../arm64/boot/dts/apple/t600x-j375.dtsi | 2 + arch/arm64/boot/dts/apple/t8103-j274.dts | 2 + arch/arm64/boot/dts/apple/t8103-j293.dts | 3 + arch/arm64/boot/dts/apple/t8103-j313.dts | 2 + arch/arm64/boot/dts/apple/t8103-j456.dts | 2 + arch/arm64/boot/dts/apple/t8103-j457.dts | 2 + .../arm64/boot/dts/apple/t8103-jxxx.dtsi | 2 + arch/arm64/boot/dts/apple/t8103.dtsi | 6 + arch/arm64/boot/dts/apple/t8112-j413.dts | 2 + arch/arm64/boot/dts/apple/t8112-j473.dts | 2 + arch/arm64/boot/dts/apple/t8112-j493.dts | 3 + .../arm64/boot/dts/apple/t8112-jxxx.dtsi | 2 + arch/arm64/boot/dts/apple/t8112.dtsi | 6 + drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/macsmc_hwmon.c | 848 +++++++++++++++++++++++++ drivers/input/misc/Kconfig | 11 + drivers/input/misc/Makefile | 1 + drivers/input/misc/macsmc-hid.c | 209 ++++++ drivers/mfd/macsmc.c | 3 + drivers/rtc/Kconfig | 11 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-macsmc.c | 141 ++++ 36 files changed, 1637 insertions(+)---
base-commit:876d6a70b24869f96ebc8672caf86cb4bae72927
change-id: 20250816-macsmc-subdevs-87032c017d0cBest regards,
Signature · 1 line
James Calligeros <[email protected]>
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Janne Grunau
maintainerQuoted 5 lines · James Calligeros
Hi all,
This series adds support for the remaining SMC subdevices. These are the RTC, hwmon, and HID devices. They are being submitted together as the RTC and hwmon drivers both require changes to the SMC DT schema.
I we would instantiate all sub devices via MFD_CELL_OF macsmc-hid (or -input) and the omitted macsmc-power would require SMC dt-binding changes as well. I'm conflicted on that since both use SMC to determine if they are present.
Janne