Skip to content

Commit 7b5d694

Browse files
committed
Merge branch 'bits/110-smc' into asahi-wip
2 parents 21d842f + 01c686d commit 7b5d694

20 files changed

Lines changed: 2556 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/hwmon/apple,smc-hwmon.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Apple SMC Hardware Monitoring
8+
9+
description:
10+
Apple's System Management Controller (SMC) exposes a vast array of
11+
hardware monitoring sensors, including temperature probes, current and
12+
voltage sense, power meters, and fan speeds. It also provides endpoints
13+
to manually control the speed of each fan individually. Each Apple
14+
Silicon device exposes a different set of endpoints via SMC keys. This
15+
is true even when two machines share an SoC. The CPU core temperature
16+
sensor keys on an M1 Mac mini are different to those on an M1 MacBook
17+
Pro, for example.
18+
19+
maintainers:
20+
- James Calligeros <jcalligeros99@gmail.com>
21+
22+
$defs:
23+
sensor:
24+
type: object
25+
26+
properties:
27+
apple,key-id:
28+
$ref: /schemas/types.yaml#/definitions/string
29+
pattern: "^[A-Za-z0-9]{4}$"
30+
description: The SMC FourCC key of the desired sensor.
31+
Must match the node's suffix.
32+
33+
label:
34+
description: Human-readable name for the sensor
35+
36+
required:
37+
- apple,key-id
38+
39+
properties:
40+
compatible:
41+
const: apple,smc-hwmon
42+
43+
patternProperties:
44+
"^current-[A-Za-z0-9]{4}$":
45+
$ref: "#/$defs/sensor"
46+
unevaluatedProperties: false
47+
48+
"^fan-[A-Za-z0-9]{4}$":
49+
$ref: "#/$defs/sensor"
50+
unevaluatedProperties: false
51+
52+
properties:
53+
apple,fan-minimum:
54+
$ref: /schemas/types.yaml#/definitions/string
55+
pattern: "^[A-Za-z0-9]{4}$"
56+
description: SMC key containing the fan's minimum speed
57+
58+
apple,fan-maximum:
59+
$ref: /schemas/types.yaml#/definitions/string
60+
pattern: "^[A-Za-z0-9]{4}$"
61+
description: SMC key containing the fan's maximum speed
62+
63+
apple,fan-target:
64+
$ref: /schemas/types.yaml#/definitions/string
65+
pattern: "^[A-Za-z0-9]{4}$"
66+
description: Writeable endpoint for setting desired fan speed
67+
68+
apple,fan-mode:
69+
$ref: /schemas/types.yaml#/definitions/string
70+
pattern: "^[A-Za-z0-9]{4}$"
71+
description: Writeable key to enable/disable manual fan control
72+
73+
74+
"^power-[A-Za-z0-9]{4}$":
75+
$ref: "#/$defs/sensor"
76+
unevaluatedProperties: false
77+
78+
"^temperature-[A-Za-z0-9]{4}$":
79+
$ref: "#/$defs/sensor"
80+
unevaluatedProperties: false
81+
82+
"^voltage-[A-Za-z0-9]{4}$":
83+
$ref: "#/$defs/sensor"
84+
unevaluatedProperties: false
85+
86+
additionalProperties: false

Documentation/devicetree/bindings/mfd/apple,smc.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ properties:
4646
reboot:
4747
$ref: /schemas/power/reset/apple,smc-reboot.yaml
4848

49+
rtc:
50+
$ref: /schemas/rtc/apple,smc-rtc.yaml
51+
52+
hwmon:
53+
$ref: /schemas/hwmon/apple,smc-hwmon.yaml
54+
4955
additionalProperties: false
5056

5157
required:
@@ -80,5 +86,44 @@ examples:
8086
nvmem-cell-names = "shutdown_flag", "boot_stage",
8187
"boot_error_count", "panic_count";
8288
};
89+
90+
rtc {
91+
compatible = "apple,smc-rtc";
92+
nvmem-cells = <&rtc_offset>;
93+
nvmem-cell-names = "rtc_offset";
94+
};
95+
96+
hwmon {
97+
compatible = "apple,smc-hwmon";
98+
99+
current-ID0R {
100+
apple,key-id = "ID0R";
101+
label = "AC Input Current";
102+
};
103+
104+
fan-F0Ac {
105+
apple,key-id = "F0Ac";
106+
apple,fan-minimum = "F0Mn";
107+
apple,fan-maximum = "F0Mx";
108+
apple,fan-target = "F0Tg";
109+
apple,fan-mode = "F0Md";
110+
label = "Fan 1";
111+
};
112+
113+
power-PSTR {
114+
apple,key-id = "PSTR";
115+
label = "Total System Power";
116+
};
117+
118+
temperature-TW0P {
119+
apple,key-id = "TW0P";
120+
label = "WiFi/BT Module Temperature";
121+
};
122+
123+
voltage-VD0R {
124+
apple,key-id = "VD0R";
125+
label = "AC Input Voltage";
126+
};
127+
};
83128
};
84129
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/rtc/apple,smc-rtc.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Apple SMC RTC
8+
9+
description:
10+
Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
11+
but most of the PMU functionality is abstracted out by the SMC.
12+
An additional RTC offset stored inside NVMEM is required to compute
13+
the current date/time.
14+
15+
maintainers:
16+
- Sven Peter <sven@kernel.org>
17+
18+
properties:
19+
compatible:
20+
const: apple,smc-rtc
21+
22+
nvmem-cells:
23+
items:
24+
- description: 48bit RTC offset, specified in 32768 (2^15) Hz clock ticks
25+
26+
nvmem-cell-names:
27+
items:
28+
- const: rtc_offset
29+
30+
required:
31+
- compatible
32+
- nvmem-cells
33+
- nvmem-cell-names
34+
35+
additionalProperties: false
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
3+
Kernel driver macsmc-hwmon
4+
==========================
5+
6+
Supported hardware
7+
8+
* Apple Silicon Macs (M1 and up)
9+
10+
Author: James Calligeros <jcalligeros99@gmail.com>
11+
12+
Description
13+
-----------
14+
15+
macsmc-hwmon exposes the Apple System Management controller's
16+
temperature, voltage, current and power sensors, as well as
17+
fan speed and control capabilities, via hwmon.
18+
19+
Because each Apple Silicon Mac exposes a different set of sensors
20+
(e.g. the MacBooks expose battery telemetry that is not present on
21+
the desktop Macs), sensors present on any given machine are described
22+
via Devicetree. The driver picks these up and registers them with
23+
hwmon when probed.
24+
25+
Manual fan speed is supported via the fan_control module parameter. This
26+
is disabled by default and marked as unsafe, as it cannot be proven that
27+
the system will fail safe if overheating due to manual fan control being
28+
used.
29+
30+
sysfs interface
31+
---------------
32+
33+
currX_input
34+
Ammeter value
35+
36+
currX_label
37+
Ammeter label
38+
39+
fanX_input
40+
Current fan speed
41+
42+
fanX_label
43+
Fan label
44+
45+
fanX_min
46+
Minimum possible fan speed
47+
48+
fanX_max
49+
Maximum possible fan speed
50+
51+
fanX_target
52+
Current fan setpoint
53+
54+
inX_input
55+
Voltmeter value
56+
57+
inX_label
58+
Voltmeter label
59+
60+
powerX_input
61+
Power meter value
62+
63+
powerX_label
64+
Power meter label
65+
66+
tempX_input
67+
Temperature sensor value
68+
69+
tempX_label
70+
Temperature sensor label
71+

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ F: Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml
24232423
F: Documentation/devicetree/bindings/dma/apple,admac.yaml
24242424
F: Documentation/devicetree/bindings/gpio/apple,smc-gpio.yaml
24252425
F: Documentation/devicetree/bindings/gpu/apple,agx.yaml
2426+
F: Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml
24262427
F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml
24272428
F: Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml
24282429
F: Documentation/devicetree/bindings/interrupt-controller/apple,*
@@ -2440,19 +2441,23 @@ F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
24402441
F: Documentation/devicetree/bindings/power/apple*
24412442
F: Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
24422443
F: Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml
2444+
F: Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
24432445
F: Documentation/devicetree/bindings/spi/apple,spi.yaml
24442446
F: Documentation/devicetree/bindings/spmi/apple,spmi.yaml
24452447
F: Documentation/devicetree/bindings/usb/apple,dwc3.yaml
24462448
F: Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
2449+
F: Documentation/hwmon/macsmc-hwmon.rst
24472450
F: arch/arm64/boot/dts/apple/
24482451
F: drivers/bluetooth/hci_bcm4377.c
24492452
F: drivers/clk/clk-apple-nco.c
24502453
F: drivers/cpufreq/apple-soc-cpufreq.c
24512454
F: drivers/dma/apple-admac.c
24522455
F: drivers/gpio/gpio-macsmc.c
2456+
F: drivers/hwmon/macsmc-hwmon.c
24532457
F: drivers/pmdomain/apple/
24542458
F: drivers/i2c/busses/i2c-pasemi-core.c
24552459
F: drivers/i2c/busses/i2c-pasemi-platform.c
2460+
F: drivers/input/misc/macsmc-input.c
24562461
F: drivers/input/touchscreen/apple_z2.c
24572462
F: drivers/iommu/apple-dart.c
24582463
F: drivers/iommu/io-pgtable-dart.c
@@ -2464,6 +2469,7 @@ F: drivers/nvmem/apple-spmi-nvmem.c
24642469
F: drivers/pinctrl/pinctrl-apple-gpio.c
24652470
F: drivers/power/reset/macsmc-reboot.c
24662471
F: drivers/pwm/pwm-apple.c
2472+
F: drivers/rtc/rtc-macsmc.c
24672473
F: drivers/soc/apple/*
24682474
F: drivers/spi/spi-apple.c
24692475
F: drivers/spmi/spmi-apple-controller.c

drivers/hwmon/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,18 @@ config SENSORS_LTQ_CPUTEMP
11741174
If you say yes here you get support for the temperature
11751175
sensor inside your CPU.
11761176

1177+
config SENSORS_MACSMC_HWMON
1178+
tristate "Apple SMC (Apple Silicon)"
1179+
depends on MFD_MACSMC && OF
1180+
help
1181+
This driver enables hwmon support for current, power, temperature,
1182+
and voltage sensors, as well as fan speed reporting and control
1183+
on Apple Silicon devices. Say Y here if you have an Apple Silicon
1184+
device.
1185+
1186+
This driver can also be built as a module. If so, the module will
1187+
be called macsmc-hwmon.
1188+
11771189
config SENSORS_MAX1111
11781190
tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
11791191
depends on SPI_MASTER

drivers/hwmon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o
148148
obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o
149149
obj-$(CONFIG_SENSORS_LTC4282) += ltc4282.o
150150
obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
151+
obj-$(CONFIG_SENSORS_MACSMC_HWMON) += macsmc-hwmon.o
151152
obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
152153
obj-$(CONFIG_SENSORS_MAX127) += max127.o
153154
obj-$(CONFIG_SENSORS_MAX16065) += max16065.o

0 commit comments

Comments
 (0)