diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index d4d30bbe11ed9..e09b6a0848c93 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -92,6 +92,21 @@ properties: - const: mbox - const: secure + apple,secure-mbox: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The coprocessor's secure RTBuddy port, on a machine whose boot loader + hands the display over only to a node with a single mailbox in mboxes. + The driver takes it as the "secure" mailbox. Elsewhere the port is the + second entry of mboxes. + + apple,merged-mode-limit: + type: boolean + description: + The platform's limit on merged modes applies to this external display + coprocessor. A display takes a second coprocessor as its pair only + while one is left for every external display that is present. + iommus: maxItems: 1 diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8afd38261fe30..71c6458c15310 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -81,6 +81,7 @@ properties: iop,secure-rtbuddy-proxy. It is polled, with no interrupts described. items: - enum: + - apple,t6050-secure-rtbuddy-proxy - apple,t8140-secure-rtbuddy-proxy - const: apple,secure-rtbuddy-proxy diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml index c35e7d0e10faa..34416179acfa0 100644 --- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml @@ -68,6 +68,22 @@ properties: hwmon: $ref: /schemas/hwmon/apple,smc-hwmon.yaml + apple,wake-reasons: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 64 + items: + maximum: 63 + description: | + The bits of the SMC's wake record that have a name on this board, as the + ADT's smc-pmu node numbers them (event_name-bitN). + + apple,wake-reason-names: + $ref: /schemas/types.yaml#/definitions/string-array + minItems: 1 + maxItems: 64 + description: The names of the bits in apple,wake-reasons, in the same order. + additionalProperties: false required: diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6050-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6050-sleep.yaml index c32148802bd18..a8908c524d1ae 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6050-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6050-sleep.yaml @@ -117,10 +117,12 @@ properties: description: The AP pin controller, whose pins a deep sleep resets. apple,pinctrl-skip-pins: - $ref: /schemas/types.yaml#/definitions/uint32-array + oneOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - type: boolean description: | Pins neither saved nor restored. From the ADT, set by the bootloader; - without it no pin is saved. + without it no pin is saved. Empty where every pin is saved. apple,sleep-low-pins: $ref: /schemas/types.yaml#/definitions/uint32-array @@ -144,6 +146,14 @@ properties: The GFX die's wake sources left enabled for a sleep. From the ADT, set by the bootloader. + apple,display-method-sleep: + type: boolean + description: | + The display coprocessors take the sleep through their firmware 27 method + table: its sleep call and its swap, the panel's AV and DP services and the + external processors' handling around a sleep. Without it they keep the + method table they had and take the sleep's endpoint transport alone. + apple,clk-gating-boot: $ref: /schemas/types.yaml#/definitions/uint32-matrix items: diff --git a/arch/arm64/boot/dts/apple/t6050-j714s-sleep-soc.dtsi b/arch/arm64/boot/dts/apple/t6050-j714s-sleep-soc.dtsi index 9b0f2f0c3376e..5ef086dee5765 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s-sleep-soc.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-j714s-sleep-soc.dtsi @@ -4576,7 +4576,11 @@ * taking that DART down and back to the live value before using it again. The router's host * also needs the port's PHY, which it stops after the router and starts before it. The left * port's router was never up in a trace: it has none of this and is powered off for a sleep. + * + * A board that includes these SoC values without that router (no acio2) defines + * T6050_SLEEP_SOC_NO_CIO first. */ +#ifndef T6050_SLEEP_SOC_NO_CIO &die0 { ps_prot: syscon@2803f0000 { compatible = "apple,t6050-ps-prot", "syscon"; @@ -4595,3 +4599,4 @@ &apciec2_dart { apple,clock-protection = <&ps_prot 31>; }; +#endif /* T6050_SLEEP_SOC_NO_CIO */ diff --git a/arch/arm64/boot/dts/apple/t6050-j714s.dts b/arch/arm64/boot/dts/apple/t6050-j714s.dts index 383ec08bedbe2..ea1de8acef251 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714s.dts @@ -717,6 +717,36 @@ #include "t6050-j714s-sleep-soc.dtsi" #include "t6050-j714s-sleep-adt.dtsi" +/* A merged mode's pair is given only while every external display has an engine */ +&dcpext0 { + apple,merged-mode-limit; +}; + +&dcpext1 { + apple,merged-mode-limit; +}; + +&dcpext2 { + apple,merged-mode-limit; +}; + +&dcpext3 { + apple,merged-mode-limit; +}; + +/* The display coprocessors take the sleep through their firmware 27 method table */ +&sleep { + apple,display-method-sleep; +}; + +/* The SMC's wake reasons (ADT smc-pmu, event_name-bitN) */ +&smc { + apple,wake-reasons = <0 8 9 11 13 35 40 41 42 43 44 45 48>; + apple,wake-reason-names = "pwrbtn", "lid", "sdconn", "charger", "wifibt", + "trackpadkeyboard", "acattach", "acdetach", "USB-C_plug", + "USB2_plug", "USB2_wake", "aupo", "rtc"; +}; + /* * Sound through the AOP, as on J813: its audio service runs the serializers, the * CS42L84 headphone jack on admac-base-ns TX2/RX2 and the six SN012776 speaker amps diff --git a/arch/arm64/boot/dts/apple/t6050-k116s-sleep.dtsi b/arch/arm64/boot/dts/apple/t6050-k116s-sleep.dtsi new file mode 100644 index 0000000000000..058bed3fa682d --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-k116s-sleep.dtsi @@ -0,0 +1,279 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Deep sleep (suspend to RAM) on the K116s: the J714s description with this board's differences + * (the pins, the display coprocessor's secure mailbox, dcpext0). The sleep controller and what + * it needs from the rest of the tree. + */ + +/ { + aliases { + /* The boot loader finds the SIO by this alias */ + sio = &sio; + }; + + sleep: sleep-controller@280600000 { + compatible = "apple,t6050-sleep"; + reg = <0x2 0x80600000 0x0 0x4000>, + <0x2 0x80900000 0x0 0x4000>, + <0x2 0x88300000 0x0 0xc000>, + <0x23 0x00e80000 0x0 0x4000>, + <0x23 0x80600000 0x0 0xc000>, + <0x23 0x88300000 0x0 0x4000>, + <0x2 0x80760000 0x0 0x10000>, + <0x2 0x807d4000 0x0 0x4000>, + <0x2 0x80930000 0x0 0x4000>, + <0x23 0x00e90000 0x0 0x4000>, + <0x23 0x80760000 0x0 0x10000>, + <0x2 0x80700000 0x0 0x20000>, + <0x23 0x80700000 0x0 0x14000>, + <0x2 0x807ec000 0x0 0x4000>, + <0x2 0x80950000 0x0 0x4000>, + <0x23 0x807dc000 0x0 0x4000>, + <0x2 0x80620000 0x0 0x4000>, + <0x2 0x8062c000 0x0 0x4000>, + <0x2 0x80688000 0x0 0x4000>, + <0x2 0x88f04000 0x0 0x4000>, + <0x2 0x8836c000 0x0 0x4000>, + <0x2 0x88330000 0x0 0x4000>, + <0x2 0x80920000 0x0 0x4000>, + <0x2 0x8a014000 0x0 0x4000>, + <0x2 0x86700000 0x0 0x14000>, + <0x2 0x86806000 0x0 0x3000>, + <0x2 0x84240000 0x0 0x20000>, + <0x2 0x803f0000 0x0 0x4000>, + <0x2 0x88370000 0x0 0x4000>, + <0x23 0x88370000 0x0 0x4000>, + <0x2 0x10e40000 0x0 0x10000>, + <0x2 0x11e40000 0x0 0x10000>, + <0x2 0x12e40000 0x0 0x10000>, + <0x4 0x17020000 0x0 0x4000>, + <0x4 0x17980000 0x0 0x4000>, + <0x2 0x80000000 0x0 0x4000>, + <0x2 0x80078000 0x0 0x4000>, + <0x23 0x80078000 0x0 0x4000>, + <0x22 0x20200000 0x0 0x8000>, + <0x22 0x20400000 0x0 0x8000>, + <0x22 0x20600000 0x0 0x8000>, + <0x22 0x20800000 0x0 0x8000>, + <0x22 0x22200000 0x0 0x8000>, + <0x2 0x88004000 0x0 0x4000>, + <0x23 0x88004000 0x0 0x4000>, + <0x23 0x80400000 0x0 0x4000>; + reg-names = "ps0", "ps1", "ps-aon", "ps-gpx", "ps-media", "ps-gfx-aon", + "clk", "clk-soc", "clk1", "afr-clk", "media-clk", + "perf", "media-perf", "table0", "table1", "media-table", + "cluster", "pwrgate", "cpu-start", "commit", "wdt", "wdt-aux", + "disp-gate", "spmi", "pmc-voters", "pmc-rails", "ptd", "gapf", + "aon-clk", "media-aon-clk", "cpm0", "cpm1", "cpm2", + "storage-phy", "storage-phy-ip", + "clkgen", "clkgen-78", "media-clkgen-78", + "mcc22", "mcc23", "mcc24", "mcc25", "mcc26", + "wake", "wake-gfx", "aic-gfx"; + apple,display-coprocessors = <&dcp>, <&dcpext0>, <&dcpext1>, <&dcpext2>, <&dcpext3>; + apple,spmi-buses = <&nub_spmi_a0>, <&nub_spmi2>, <&nub_spmi_a1>, <&nub_spmi3>, + <&aop_spmi0>; + /* SEP's, PMP0's, SIO's and the DCP's DART, stopped in the sleep's last steps */ + apple,sleep-darts = <&sep_dart>, <&pmp0_dart>, <&sio_dart>, <&dcp_dart>; + /* The N1's host: its link is shut down for the sleep and brought back after it */ + apple,radio-pcie = <&pcie0>; + apple,pinctrl = <&pinctrl_ap>; + /* The display coprocessors take the sleep through their firmware 27 method table */ + apple,display-method-sleep; + }; +}; + +/* The SMC's wake reasons (ADT smc-pmu, event_name-bitN) */ +&smc { + apple,wake-reasons = <0 8 9 11 13 35 40 41 42 43 44 45 48>; + apple,wake-reason-names = "pwrbtn", "lid", "sdconn", "charger", "wifibt", + "trackpadkeyboard", "acattach", "acdetach", "USB-C_plug", + "USB2_plug", "USB2_wake", "aupo", "rtc"; +}; + +/* + * The N1's warm reset (ADT pci-bridge0 function-warm_reset: the SMC, key 'bpli'). The N1's + * firmware does not survive a sleep; the host resets the N1 after the wake, before its link + * trains. The writes that give the reset are the boot loader's to add (see the binding). + */ +&port00 { + apple,function-warm-reset = <&smc 0x62706c69 0x1000000>; +}; + +/* On through the commit: the sleep stops their users in its last steps. */ +&ps_pmp { + apple,always-on; +}; + +&ps_pms_sram { + apple,always-on; +}; + +&ps_gfx { + apple,always-on; +}; + +&ps_spi_p { + apple,always-on; +}; + +&ps_atc3_usb_aon { + apple,always-on; +}; + +&ps_sio { + apple,always-on; + status = "okay"; +}; + +&ps_sio_cpu { + apple,always-on; + status = "okay"; +}; + +/* The port controllers put in system power state S3 before the commit, then SLEEP */ +&hpm1 { + apple,sleep-ssps; +}; + +&hpm2 { + apple,sleep-ssps; +}; + +/* + * The MagSafe port's PD controller (ADT hpm5, nub-spmi-a0 0x08), described as + * on the J714s so that the sleep puts it in S3 with the others. + */ +&nub_spmi_a0 { + hpm5: usb-pd@8 { + compatible = "apple,sn201202x"; + reg = <0x8 SPMI_USID>; + apple,no-liquid-detection; + apple,sleep-ssps; + }; +}; + +&{/soc@200000000} { + /* + * The cores' power-gate enables, /arm-io/pmgr reg[0] + 0x2c000, one word per core: the + * boot loader leaves core 0's (the boot core's) and core 12's clear. Without them the + * boot cluster never powers down, and the sleep never gets past its first sequence. + */ + cluster_pwrgate: power-gate@28062c000 { + compatible = "apple,t6050-cluster-pwrgate", "apple,cluster-pwrgate"; + reg = <0x2 0x8062c000 0x0 0x4>, + <0x2 0x8062c0c0 0x0 0x4>; + }; +}; + +/* AOP2, running until the commit: its ASC mailbox at the AOP2 ASC + 0x8000 */ +&{/soc@200000000} { + aop2_mbox: mailbox@291608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x2 0x91608000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; +}; + +&aop2 { + reg = <0x2 0x91600000 0x0 0x4000>; + reg-names = "asc"; + /delete-property/ interrupts; + mboxes = <&aop2_mbox>; + mbox-names = "mbox"; + apple,dma-range = <0x110 0x0 0x10 0x0>; + status = "okay"; +}; + +/* + * The SIO, running until the sleep's own stop: its ASC bank split around its mailbox. The boot + * loader enables it with its firmware and tables. + */ +/delete-node/ &sio; + +&{/soc@200000000} { + sio_mbox: mailbox@505e08000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x5 0x5e08000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + power-domains = <&ps_sio_cpu>; + #mbox-cells = <0>; + }; + + sio: dma-controller@505e00000 { + compatible = "apple,t6050-sio", "apple,sio"; + reg = <0x5 0x5e00000 0x0 0x8000>, + <0x5 0x5850000 0x0 0x4000>, + <0x5 0x5e0c000 0x0 0x7c000>; + reg-names = "asc", "auxiliary", "asc-tail"; + #dma-cells = <1>; + dma-channels = <128>; + mboxes = <&sio_mbox>; + iommus = <&sio_dart 0>; + power-domains = <&ps_sio_cpu>; + clocks = <&peripheral_clocks 359>, <&peripheral_clocks 358>; + status = "disabled"; + }; +}; + +&sio_dart { + power-domains = <&ps_sio_cpu>; + status = "okay"; +}; + +/* + * The AP pins a deep sleep neither saves nor restores: none. The K116s ADT's gpio0 has no + * no-restore-gpio-pins (the J714s's has 5 6 7 112 141), and with those skipped the panel stayed + * dark after a deep sleep. Without the property no pin is saved at all. + */ +&sleep { + apple,pinctrl-skip-pins = <>; +}; + +/* + * The display coprocessor's secure mailbox (ADT /arm-io/dcp-exclave-mailbox, + * iop,secure-rtbuddy-proxy, reg 0x4cae7c000). Firmware 27.2 acknowledges no IOP power state + * while nothing answers it, as on T8140. + */ +&{/soc@200000000} { + dcp_secure_mbox: mailbox@4cae7c000 { + compatible = "apple,t6050-secure-rtbuddy-proxy", "apple,secure-rtbuddy-proxy"; + reg = <0x4 0xcae7c000 0x0 0x4000>; + #mbox-cells = <0>; + }; +}; + +/* + * Not in mboxes: the boot loader hands the display over only to a node whose mboxes is the one + * ASC mailbox. The driver adds it to the live tree at probe. + */ +&dcp { + apple,secure-mbox = <&dcp_secure_mbox>; +}; + +/* + * dcpext0 without its Type-C route, as dcpext1 to 3 are here. Its PHY's DP side + * is not described on this board, and the engine's probe waits for it and gives the engine + * up; a deep sleep needs the engine bound, to stop its firmware. + */ +&dcpext0 { + /delete-property/ apple,connector-type; + /delete-property/ apple,dptx-die; + /delete-property/ apple,typec-dptx-phys; + /delete-property/ apple,typec-mux-indices; + /delete-property/ phys; + /delete-property/ phy-names; + /delete-property/ mux-controls; + /delete-property/ mux-control-names; + /delete-node/ typec-routes; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-k116s.dts b/arch/arm64/boot/dts/apple/t6050-k116s.dts index fe6468edc72c1..f049736e9489f 100644 --- a/arch/arm64/boot/dts/apple/t6050-k116s.dts +++ b/arch/arm64/boot/dts/apple/t6050-k116s.dts @@ -913,3 +913,107 @@ &avd { status = "okay"; }; + +/* + * The PMU's RTC and its alarm. ADT: the PMU's info-rtc (0x2002), + * info-rtc_alarm_offset (0x2008), info-rtc_irq_mask_offset (0x200e), + * info-rtc_alarm_ctrl (0x2000) and info-rtc_scrpad (0x2100), the registers of + * the T6041 PMU. It raises no interrupt on this SoC: an armed alarm can only + * wake the machine from a firmware sleep, not from s2idle. + */ +&pmu { + pmu_rtc: rtc { + compatible = "apple,t6050-pmu-rtc", "apple,t6041-pmu-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + wakeup-source; + }; +}; + +/* + * The video encoder's power states, as on the J714s. iBoot leaves VENC0_SYS on, and the SoC does + * not enter the firmware-driven sleep with it on. Enabled and unused, genpd turns it off at + * boot. No encoder is described yet. + */ +&ps_fab1_piogw { + apple,firmware-owned; + status = "okay"; +}; + +&ps_fab0_soc { + apple,always-on; + status = "okay"; +}; + +&ps_venc0_sys { + status = "okay"; +}; + +&ps_venc0_dma { + status = "okay"; +}; + +&ps_venc0_pipe4 { + status = "okay"; +}; + +&ps_venc0_pipe5 { + status = "okay"; +}; + +&ps_venc0_me0 { + status = "okay"; +}; + +&ps_venc0_me1 { + status = "okay"; +}; + +/* + * Deep sleep: the sleep controller's description and the J714s's SoC values, then what differs + * on this board (firmware 27.2). + */ +#include "t6050-k116s-sleep.dtsi" +/* No USB4 router is described on this board: without the J714s's CIO sleep part. */ +#define T6050_SLEEP_SOC_NO_CIO +#include "t6050-j714s-sleep-soc.dtsi" + +/* + * macOS on this board parks the four clock words with 0x80100000 in the last 0.5 ms before its + * commit (traced as an aura guest); the J714s's values have bit 10 set. + */ +&sleep { + apple,seq-commit-sio = + <0x0 17 0x290 0x400024f>, + <0x0 17 0x2a0 0x400024f>, + <0x1 51 0xa0 0x0>, + <0x0 51 0xa0 0x80100000>, + <0x1 51 0xa0 0x0>, + <0x1 51 0xa4 0x0>, + <0x0 51 0xa4 0x80100000>, + <0x1 51 0xa4 0x0>, + <0x1 51 0x94 0x0>, + <0x0 51 0x94 0x80100000>, + <0x1 51 0x94 0x0>, + <0x1 51 0x90 0x0>, + <0x0 51 0x90 0x80100000>, + <0x1 51 0x90 0x0>; +}; + +/* + * The PMP firmware's __DATA starts at 0x56000 on 27.2 (ADT pmp0 segment-ranges: __TEXT 0x56000 + * bytes, __DATA 0x9b000 bytes), not at the J714s's 0x58000. With the wrong range kept over the + * sleep the PMP does not come back (endpoint discovery -62). + */ +&pmp0 { + apple,sram-keep = <0x56000 0x9b000>; +}; + +/* + * The panel's plug takes about 2.9 ms here from the video interface's announcement to the + * firmware's "ioav i/f is now closed", and the next round of reports follows about 33 ms later. + * With the J714s's 2500 us the open landed 25 us before the close. + */ +&dcp { + apple,panel-video-open-delay-us = <10000>; +}; diff --git a/drivers/dma/apple-sio.c b/drivers/dma/apple-sio.c index d4d954708a8d2..da9c47ded7084 100644 --- a/drivers/dma/apple-sio.c +++ b/drivers/dma/apple-sio.c @@ -697,12 +697,13 @@ static const struct sio_hw_data sio_hw_t6050 = { }; /* - * The T6050 description is in force on the board it has run on. On another T6050 board the - * node is taken as before: by its generic compatible. + * The T6050 description, with its stop at the sleep's commit, is in force on the boards + * that describe the sleep. On another T6050 board the node is taken as before: by its + * generic compatible. */ static bool sio_t6050_board(void) { - return of_machine_is_compatible("apple,j714s"); + return apple_t6050_sleep_described(); } static const struct of_device_id sio_of_match[] = { diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index ea38c3fd64de7..ab0c3d21ae9b6 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -944,6 +944,10 @@ struct apple_dcp { /* V27 sleep: the panel's next mode set is the mode it already has */ bool v27_keep_mode; + /* Since the V27 wake: the panel's video interface opened, the firmware reported the panel */ + struct completion v27_wake_video, v27_wake_hotplug; +#define V27_WAKE_VIDEO_MS 1500 +#define V27_WAKE_HOTPLUG_MS 250 /* V27 sleep: the output area of the call being pushed holds this (an in/out word) */ const void *push_out_prefill; diff --git a/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc index a5aa449b446dd..3d73c5f47dbe0 100644 --- a/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc @@ -7,11 +7,12 @@ static int dcp_peer_probe_power(struct apple_dcp *dcp, struct apple_dcp *peer, bool on) { struct dcp_peer_video_wait *wait; - struct dcp_method_entry method = { .name = "peer_power_test", - .tag = {'A', '4', '8', '4'} }; + struct dcp_method_entry method = { .name = "peer_power_test" }; u8 power[16] = {}, response[8]; int ret; + iomfb_v27_tag(dcp->v27_methods, "A484", method.tag); + wait = kzalloc(sizeof(*wait), GFP_KERNEL); if (!wait) return -ENOMEM; @@ -134,13 +135,14 @@ static int dcp_peer_probe_modeset(struct apple_dcp *dcp, struct apple_dcp *peer, bool firmware_requires_merge) { struct dcp_peer_video_wait *wait; - struct dcp_method_entry method = { .name = "peer_modeset_test", - .tag = {'A', '4', '1', '3'} }; + struct dcp_method_entry method = { .name = "peer_modeset_test" }; __le32 mode[2] = {video->color_id, video->timing_id}; u32 primary_id, peer_id, phase, status; unsigned long deadline; int ret; + iomfb_v27_tag(dcp->v27_methods, "A413", method.tag); + { guard(mutex)(&dcp_peer_lock); if (dcp->peer_reserved != peer || peer->peer_owner != dcp || diff --git a/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc index ed73f355eda7e..5a87e1973b9f2 100644 --- a/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc @@ -26,10 +26,11 @@ static void dcp_peer_background_start(struct apple_dcp *dcp, { struct dcp_peer_background *background = container_of(transaction, struct dcp_peer_background, transaction); - struct dcp_method_entry method = { .name = "peer_background_test", - .tag = {'A', '4', '0', '8'} }; + struct dcp_method_entry method = { .name = "peer_background_test" }; struct dcp_swap_submit_resp_v27 failed = { .ret = ~0U }; + iomfb_v27_tag(dcp->v27_methods, "A408", method.tag); + background->sent = true; if (!dcp_present_begin_h17p(&dcp->present_state_h17p, background->wire.swap.swap_id)) { @@ -185,6 +186,7 @@ static void dcp_peer_a407_background_start(struct apple_dcp *dcp, { struct dcp_peer_a407_background *background = container_of(transaction, struct dcp_peer_a407_background, transaction); + /* The J714s's 27.0 swap form, whose table names A407 (iomfb_v27_methods_j714s()). */ struct dcp_method_entry method = { .name = "peer_background_test", .tag = {'A', '4', '0', '7'} }; struct dcp_swap_submit_resp_v27 failed = { .ret = ~0U }; @@ -345,6 +347,8 @@ static ssize_t peer_swap_test_store(struct device *dev, dcp->crtc->base.state->active || peer->crtc->base.state->active || dcp->fw_compat != DCP_FIRMWARE_V_27_0 || peer->fw_compat != DCP_FIRMWARE_V_27_0 || + /* Both engines must take the swap form the owner sends. */ + dcp->v27_a407 != peer->v27_a407 || !device_trylock(peer->dev)) { ret = -EBUSY; goto out; diff --git a/drivers/gpu/drm/apple/dcp-peer-v27.inc b/drivers/gpu/drm/apple/dcp-peer-v27.inc index a824ab7e99265..34ee3e472d3ef 100644 --- a/drivers/gpu/drm/apple/dcp-peer-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-v27.inc @@ -8,12 +8,14 @@ module_param(peer_allocation_probe, bool, 0444); MODULE_PARM_DESC(peer_allocation_probe, "Firmware27 logical peer allocation for merged modes (default: on)"); /* - * The platform limit on merged modes (dcp_fabric_merged_fits()) holds on the - * board it has run on, for the J714s's T6050 external display processors. + * The platform limit on merged modes (dcp_fabric_merged_fits()) holds for the + * external display processors whose node says so (apple,merged-mode-limit). */ static bool dcp_peer_limit_applies(struct apple_dcp *dcp) { - return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && dcp_j714s_ext(dcp->dev); + return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcpext") && + of_property_read_bool(dcp->dev->of_node, "apple,merged-mode-limit"); } /* @@ -68,8 +70,7 @@ void dcp_peer_limit_update_v27(struct drm_device *drm) unsigned int n = 0, i; struct drm_crtc *crtc; - /* Neither a board without the limit nor a device without CRTCs. */ - if (!of_machine_is_compatible("apple,j714s") || !drm->mode_config.num_crtc) + if (!drm->mode_config.num_crtc) return; scoped_guard(mutex, &dcp_peer_lock) { drm_for_each_crtc(crtc, drm) { diff --git a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc index 3560cfc447a99..e5c896ae44013 100644 --- a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc @@ -46,7 +46,8 @@ static int dcp_peer_video_call_stream(struct apple_dcp *dcp, bool independent, wait = kzalloc(sizeof(*wait), GFP_KERNEL); if (!wait) return -ENOMEM; - memcpy(method.tag, tag, sizeof(method.tag)); + /* The calls name 27.0 IDs: this engine's build may number them differently. */ + iomfb_v27_tag(dcp->v27_methods, tag, method.tag); wait->size = out_size; init_completion(&wait->done); kref_init(&wait->refs); diff --git a/drivers/gpu/drm/apple/dcp-v27-sleep.inc b/drivers/gpu/drm/apple/dcp-v27-sleep.inc index dc37f122bb8ef..5f19e3a556226 100644 --- a/drivers/gpu/drm/apple/dcp-v27-sleep.inc +++ b/drivers/gpu/drm/apple/dcp-v27-sleep.inc @@ -248,6 +248,41 @@ static int dcp_v27_ext_cycle_ready(struct apple_dcp *dcp) return dcp->s2r_dcp_dart ? 0 : -ENODEV; } +/* + * A restart with the secure port (firmware 27.2), as dcp_s2r_warm_restart() does it: the + * port restarted before RUN, mapped between the main mailbox's IOP report and its AP on, then on. + */ +static int dcp_v27_warm_restart(struct apple_dcp *dcp, bool strict) +{ + int ret; + + if (dcp->secure_rtk && dcp->secure_answered) { + dcp_secure_poll_stop(dcp); + ret = apple_rtkit_port_restart(dcp->secure_rtk); + if (ret) + dev_warn(dcp->dev, "V27 wake: secure port restart: %d\n", ret); + } + return strict ? apple_rtkit_warm_restart_strict(dcp->rtk) : + apple_rtkit_warm_restart_stopped(dcp->rtk); +} + +static int dcp_v27_boot(struct apple_dcp *dcp) +{ + bool secure = dcp->secure_rtk && dcp->secure_answered; + int ret; + + ret = apple_rtkit_boot_with(dcp->rtk, secure ? dcp_secure_port_map : NULL, dcp); + if (ret || !secure) + return ret; + ret = dcp->secure_map_ret ?: apple_rtkit_port_on(dcp->secure_rtk, DCP_SECURE_TIMEOUT_MS); + if (ret) + dev_warn(dcp->dev, "V27 wake: secure port map %d (%lld us), on %d\n", + dcp->secure_map_ret, dcp->secure_map_us, ret); + else + dcp_secure_poll_start(dcp); + return 0; +} + /* * macOS's DCP stop/restart between its wake steps: sessions closed, AP and IOP * idle, IDLE_DONE, receive off, CPU_CONTROL RUN off; dart-dcp stopped, the display's domain off and, @@ -271,7 +306,11 @@ static int dcp_v27_rtkit_cycle(struct apple_dcp *dcp, unsigned int pause_ms) if (s && s->cycle_failed) return -ECANCELED; dcp_v27_sessions(dcp, false); - ret = apple_rtkit_idle_strict(dcp->rtk); + /* With a secure port: the IOP idle is taken only after the port's AP idle */ + if (dcp->secure_rtk && dcp->secure_answered) + ret = apple_rtkit_idle_strict_with(dcp->rtk, dcp_secure_port_idle, dcp); + else + ret = apple_rtkit_idle_strict(dcp->rtk); if (ret) { dev_warn(dcp->dev, "V27 wake: RTKit cycle: idle %d\n", ret); dcp_v27_sessions(dcp, true); @@ -347,12 +386,12 @@ static int dcp_v27_rtkit_cycle(struct apple_dcp *dcp, unsigned int pause_ms) dev_warn(dcp->dev, "V27 wake: RTKit cycle: display DART rewrite %d\n", ret); } } - ret = apple_rtkit_warm_restart_strict(dcp->rtk); + ret = dcp_v27_warm_restart(dcp, true); if (!ret) { writel(readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) | APPLE_DCP_COPROC_CPU_CONTROL_RUN, dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); run_status = readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_STATUS); - ret = apple_rtkit_boot(dcp->rtk); + ret = dcp_v27_boot(dcp); } /* * An external processor that did not start is not left down: its DART, power words and @@ -371,13 +410,13 @@ static int dcp_v27_rtkit_cycle(struct apple_dcp *dcp, unsigned int pause_ms) ret = apple_dart_m5_display_cycle(dcp->s2r_dcp_dart, true); } if (!ret) - ret = apple_rtkit_warm_restart_stopped(dcp->rtk); + ret = dcp_v27_warm_restart(dcp, false); if (!ret) { writel(readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) | APPLE_DCP_COPROC_CPU_CONTROL_RUN, dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); run_status = readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_STATUS); - ret = apple_rtkit_boot(dcp->rtk); + ret = dcp_v27_boot(dcp); } } if (ret) { @@ -1165,6 +1204,8 @@ static int dcp_v27_reopen_live(struct apple_dcp *dcp) return ret; s->soft_off = false; } + reinit_completion(&dcp->v27_wake_video); + reinit_completion(&dcp->v27_wake_hotplug); WRITE_ONCE(dcp->v27_keep_mode, true); } else if (s->ext_wake) { ret = dcp_v27_ext_wake_calls(s); @@ -1210,6 +1251,8 @@ static int dcp_v27_reopen_live(struct apple_dcp *dcp) return 0; } +static int dcp_v27_secure_idle_atomic(void *data); + static int dcp_v27_late_arm(void *data) { struct dcp_v27_sleep *s = data; @@ -1239,6 +1282,8 @@ static int dcp_v27_late_arm(void *data) ret = apple_rtkit_v27_arm(dcp->rtk, &s->rx); if (ret) dev_info(dcp->dev, "V27 arm: RTKit %d\n", ret); + else + apple_rtkit_v27_set_after_ap(s->rx, dcp_v27_secure_idle_atomic, dcp); } if (ret) { if (s->display && !s->display_early) { @@ -1257,6 +1302,20 @@ static int dcp_v27_late_arm(void *data) return 0; } +/* + * With a secure port (firmware 27.2): its AP idle between the main mailbox's AP idle and + * its IOP idle, polled, as this runs with interrupts off. Not acknowledged, it fails the stop: + * the firmware would not take the IOP idle. + */ +static int dcp_v27_secure_idle_atomic(void *data) +{ + struct apple_dcp *dcp = data; + + if (!dcp->secure_rtk || !dcp->secure_answered) + return 0; + return apple_rtkit_v27_port_ap_idle_atomic(dcp->secure_rtk, 5000); +} + static int dcp_v27_late_check(void *data) { struct dcp_v27_sleep *s = data; @@ -1391,9 +1450,11 @@ static int dcp_v27_sleep_prepare(struct apple_dcp *dcp) dev_warn(dcp->dev, "V27 sleep: no sleep RPC arguments in the DT\n"); return -EOPNOTSUPP; } - if (!dcp->retain_dma || IS_ERR_OR_NULL(dcp->rtk) || !dcp->active || dcp->crashed || dcp->quiescing || - dcp->secure_rtk) - return dcp_v27_refuse(dcp, "coprocessor not live (dma, rtkit, active, crashed, quiescing, secure)"); + if (!dcp->retain_dma || IS_ERR_OR_NULL(dcp->rtk) || !dcp->active || dcp->crashed || dcp->quiescing) + return dcp_v27_refuse(dcp, "coprocessor not live (dma, rtkit, active, crashed, quiescing)"); + /* The secure port is idled from the late stop, with nothing else reading it. */ + if (dcp->secure_rtk && dcp->secure_answered) + dcp_secure_poll_stop(dcp); /* Mode-config suspend is the actual DRM scanout-owner boundary. No HPD * shortcut: external firmware still executes A484/A500/AFK and late IDLE. */ @@ -1558,7 +1619,18 @@ static int dcp_v27_sleep_prepare(struct apple_dcp *dcp) if (ret) goto uncertain; for (i = ARRAY_SIZE(v27_sleep_endpoints); i-- > 0;) { - ret = afk_v27_sleep_control(dcp->sleep_v27_ep[v27_sleep_endpoints[i] - 0x20], false); + struct apple_dcp_afkep *ep = dcp->sleep_v27_ep[v27_sleep_endpoints[i] - 0x20]; + int check; + + /* + * An endpoint still taking a message (a service announced late, seen on 0x31 of + * a K116s DCPEXT) answers -EBUSY for a moment: wait it out as the other steps do, + * rather than refuse the sleep. + */ + if (ep) + read_poll_timeout(afk_v27_sleep_check, check, check != -EBUSY, 1000, + 300 * USEC_PER_MSEC, false, ep); + ret = afk_v27_sleep_control(ep, false); if (ret) { char name[12]; @@ -1639,7 +1711,7 @@ static int dcp_v27_sleep_restart(struct apple_dcp *dcp) if (s->phase == V27_STOPPED) { ret = apple_sleep_display_v27_power_ready(dcp->dev); if (!ret) - ret = apple_rtkit_warm_restart_strict(dcp->rtk); + ret = dcp_v27_warm_restart(dcp, true); /* * The final step stopped this CPU and it is still stopped: the firmware boots * from its reset vector next, so the state tracked before the stop does not @@ -1648,12 +1720,12 @@ static int dcp_v27_sleep_restart(struct apple_dcp *dcp) if (ret == -EUCLEAN && READ_ONCE(dcp->s2r_fw_down) && !(readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) & APPLE_DCP_COPROC_CPU_CONTROL_RUN)) - ret = apple_rtkit_warm_restart_stopped(dcp->rtk); + ret = dcp_v27_warm_restart(dcp, false); if (ret) return dcp_v27_fail(s, ret); writel(readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) | APPLE_DCP_COPROC_CPU_CONTROL_RUN, dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); - ret = apple_rtkit_boot(dcp->rtk); + ret = dcp_v27_boot(dcp); if (ret) return dcp_v27_fail(s, ret); } diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7cde46e009096..42d0e9d41103a 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -270,6 +270,36 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) { struct device *dev = dcp->dev; + /* + * The secure mailbox named outside mboxes, which the boot loader wants to be the one ASC + * mailbox (it refuses the display handoff otherwise). Added to the live node here. + */ + if (of_property_match_string(dev->of_node, "mbox-names", "secure") < 0 && + of_property_present(dev->of_node, "apple,secure-mbox")) { + static const char names[] = "mbox\0secure"; + struct property *boxes, *nm; + const __be32 *main_box, *sec; + __be32 *v; + int len; + + main_box = of_get_property(dev->of_node, "mboxes", &len); + sec = of_get_property(dev->of_node, "apple,secure-mbox", NULL); + boxes = devm_kzalloc(dev, sizeof(*boxes), GFP_KERNEL); + nm = devm_kzalloc(dev, sizeof(*nm), GFP_KERNEL); + v = devm_kcalloc(dev, 2, sizeof(*v), GFP_KERNEL); + if (main_box && len == 4 && sec && boxes && nm && v) { + v[0] = main_box[0]; + v[1] = sec[0]; + boxes->name = "mboxes"; + boxes->value = v; + boxes->length = 8; + nm->name = "mbox-names"; + nm->value = (void *)names; + nm->length = sizeof(names); + if (!of_update_property(dev->of_node, boxes)) + of_update_property(dev->of_node, nm); + } + } if (of_property_match_string(dev->of_node, "mbox-names", "secure") < 0) return 0; @@ -465,12 +495,13 @@ MODULE_PARM_DESC(t6050_ext_sleep, /* * What a T6050 external display processor gained outside the firmware 27 sleep itself (the * Type-C reconnect skipped for a crashed one, a crashed one refusing a deep sleep before - * anything is stopped, the link line) is in force on the board it has run on, the J714s. - * Elsewhere, other boards with the same SoC included, these are as before. + * anything is stopped, the link line) is in force where the sleep's description has the + * display coprocessors sleep by their method table (apple,display-method-sleep). Elsewhere, + * other boards with the same SoC included, these are as before. */ static bool dcp_j714s_ext(struct device *dev) { - return of_machine_is_compatible("apple,j714s") && + return apple_t6050_sleep_property("apple,display-method-sleep") && of_device_is_compatible(dev->of_node, "apple,t6050-dcpext"); } @@ -5797,9 +5828,12 @@ static bool dcp_v27_sleep_transport_supported(struct apple_dcp *dcp) dcp->fw_compat != DCP_FIRMWARE_V_27_0) return false; - /* The enum also covers later 27.x method tables. */ + /* + * The enum also covers later 27.x method tables. 27.2 keeps the endpoint + * transport; its renumbered IOMFB calls go through iomfb_v27_tag(). + */ return dcp_read_fw_version(dev, "apple,firmware-compat", compat) >= 0 && - !strcmp(compat, "27.0.0"); + (!strcmp(compat, "27.0.0") || !strcmp(compat, "27.2.0")); } static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) @@ -6993,6 +7027,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) INIT_LIST_HEAD(&dcp->swapped_out_fbs); mutex_init(&dcp->swapped_out_fbs_lock); + init_completion(&dcp->v27_wake_video); + init_completion(&dcp->v27_wake_hotplug); ret = dcp_backlight_init(dcp, dev); if (ret) return ret; @@ -7000,7 +7036,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) dcp->fw_compat = fw_compat; dcp->v27_j714s = fw_compat == DCP_FIRMWARE_V_27_0 && - of_machine_is_compatible("apple,j714s"); + apple_t6050_sleep_property("apple,display-method-sleep"); /* * Probe-lifetime like the desktop state: component bind opens a devres * group on this device and releases it on failure or unbind. diff --git a/drivers/gpu/drm/apple/epic/panelavep.c b/drivers/gpu/drm/apple/epic/panelavep.c index cd4507b2bf78f..6e7a0cb682bcf 100644 --- a/drivers/gpu/drm/apple/epic/panelavep.c +++ b/drivers/gpu/drm/apple/epic/panelavep.c @@ -131,9 +131,11 @@ static void panelav_open_worker(struct work_struct *work) if (ret) dev_warn(service->ep->dcp->dev, "panel AV: video interface %u OPEN failed: %d\n", service->channel, ret); - else + else { + complete(&service->ep->dcp->v27_wake_video); dev_info(service->ep->dcp->dev, "panel AV: video interface %u opened\n", service->channel); + } afk_service_put(service); kfree(w); } diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 1f3e97e6c5e9f..d8038e0fbcb49 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -892,11 +892,11 @@ static void iomfb_v27_sleep_start(struct apple_dcp *dcp, rpc->data, iomfb_v27_sleep_done, rpc); dcp->push_out_prefill = NULL; if ((rpc->a442 || rpc->a442_key) && !rpc->oob) { - static const struct dcp_method_entry a442 = { - .name = "v27_a442", .tag = { 'A', '4', '4', '2' }, - }; + struct dcp_method_entry a442 = { .name = "v27_a442" }; u8 in[92]; + iomfb_v27_tag(dcp->v27_methods, "A442", a442.tag); + memset(in, 0xaa, sizeof(in)); memset(in, 0, 16); in[8] = rpc->a442_key ?: 0x41; @@ -904,6 +904,9 @@ static void iomfb_v27_sleep_start(struct apple_dcp *dcp, if (rpc->a442_key) { memset(in + 80, 0, 12); in[84] = 0x20; + } else if (iomfb_v27_methods_renumbered(dcp->v27_methods)) { + /* 27.2 reads the filler as an index count and a block size */ + memset(in + 16, 0, sizeof(in) - 16); } dcp_push(dcp, true, &a442, sizeof(in), 4100, in, iomfb_v27_a442_done, NULL); } @@ -1002,7 +1005,7 @@ static int iomfb_v27_rpc(struct apple_dcp *dcp, bool a500, bool on, bool flags) rpc->method = (struct dcp_method_entry) { .name = a500 ? "v27_sleep_500" : "v27_sleep_power", }; - memcpy(rpc->method.tag, a500 ? "A500" : "A484", 4); + iomfb_v27_tag(dcp->v27_methods, a500 ? "A500" : "A484", rpc->method.tag); /* * Off, before each DCP's and DCPEXT's sleep idle: A484 with the sleep's flags, then * A500's sleep form. On, after the wake: A500's wake form, then A484 with the flags. @@ -1091,7 +1094,7 @@ static int iomfb_v27_call(struct apple_dcp *dcp, const char *tag, const void *in rpc->transaction.start = iomfb_v27_sleep_start; rpc->transaction.release = iomfb_v27_sleep_release; rpc->method = (struct dcp_method_entry) { .name = "v27_display_stage" }; - memcpy(rpc->method.tag, tag, 4); + iomfb_v27_tag(dcp->v27_methods, tag, rpc->method.tag); rpc->input = in_len; rpc->output = out_len; rpc->inout = inout; diff --git a/drivers/gpu/drm/apple/iomfb.h b/drivers/gpu/drm/apple/iomfb.h index e230a9eac9c5c..1d52ca712b119 100644 --- a/drivers/gpu/drm/apple/iomfb.h +++ b/drivers/gpu/drm/apple/iomfb.h @@ -220,6 +220,8 @@ struct dcp_method_entry { /* The IOMFB method table of a firmware 27.x build, by its compat string; NULL if unknown. */ const struct dcp_method_entry *iomfb_v27_methods(const char *compat); +bool iomfb_v27_methods_renumbered(const struct dcp_method_entry *methods); +void iomfb_v27_tag(const struct dcp_method_entry *methods, const char *tag, char *out); const struct dcp_method_entry *iomfb_v27_methods_j714s(struct device *dev, const struct dcp_method_entry *methods); /* The first method of a firmware 27.x table that has no ID, NULL if none. */ diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 066c7a5f1cfdd..c8c5fcc8e677f 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -4249,6 +4249,21 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp, keep_mode = dcp->v27_j714s && xchg(&dcp->v27_keep_mode, false) && dcp->mode.color_mode_id == mode->color_mode_id && dcp->mode.timing_mode_id == mode->timing_mode_id; + /* + * Firmware 27.2: sent once the panel's video interface is open again and the firmware + * has reported the panel, which it does after the open. + */ + if (keep_mode && iomfb_v27_methods_renumbered(dcp->v27_methods)) { + if (!wait_for_completion_timeout(&dcp->v27_wake_video, + msecs_to_jiffies(V27_WAKE_VIDEO_MS))) + dev_warn(dcp->dev, "V27 wake: panel video interface not open after %u ms\n", + V27_WAKE_VIDEO_MS); + else if (!wait_for_completion_timeout(&dcp->v27_wake_hotplug, + msecs_to_jiffies(V27_WAKE_HOTPLUG_MS))) + dev_warn(dcp->dev, "V27 wake: no hotplug report %u ms after the panel's open\n", + V27_WAKE_HOTPLUG_MS); + keep_mode = false; + } #endif dcp->mode = (struct dcp_set_digital_out_mode_req){ .color_mode_id = mode->color_mode_id, diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index a1ccdb537d54f..6c8e26d45c2aa 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -2,6 +2,7 @@ /* Copyright The Asahi Linux Contributors */ /* Copyright 2026 Aurora Silicon */ +#include #include #include @@ -269,6 +270,47 @@ const struct dcp_method_entry *iomfb_v27_methods(const char *compat) return NULL; } +/* + * @tag, a 27.0 ID the paired-mode calls name directly, in the build of @methods + * (into @out, 4 bytes). A method the tables name takes this build's ID; on 27.2, + * which moved IOMobileFramebufferAP up by 50, another A4xx ID (and A500) does too. + * Anything else keeps its 27.0 ID. + */ +void iomfb_v27_tag(const struct dcp_method_entry *methods, const char *tag, char *out) +{ + unsigned int i, id; + char in[4]; + + memcpy(in, tag, 4); + tag = in; + memcpy(out, tag, 4); + if (!iomfb_v27_methods_renumbered(methods)) + return; + for (i = 0; i < dcpep_num_methods; i++) { + if (dcp_methods_27_0[i].tag[0] && !memcmp(dcp_methods_27_0[i].tag, tag, 4) && + methods[i].tag[0]) { + memcpy(out, methods[i].tag, 4); + return; + } + } + if (methods != dcp_methods_27_2 || tag[0] != 'A' || !isdigit(tag[1]) || + !isdigit(tag[2]) || !isdigit(tag[3])) + return; + id = (tag[1] - '0') * 100 + (tag[2] - '0') * 10 + (tag[3] - '0'); + if (id < 400 || id > 500) + return; + id += 50; + out[1] = '0' + id / 100; + out[2] = '0' + id / 10 % 10; + out[3] = '0' + id % 10; +} + +/* Whether @methods is a build's table whose AP method IDs differ from 27.0's. */ +bool iomfb_v27_methods_renumbered(const struct dcp_method_entry *methods) +{ + return methods && (methods == dcp_methods_27_2 || methods == dcp_methods_27_3); +} + /* * The 27.0 table for the J714s, the board the firmware 27 sleep has run on (dcp->v27_j714s): a * copy with the sleep's A500 added. The shared table keeps the methods it had, so every other @@ -406,6 +448,9 @@ static bool trampoline_hotplug_h17p(struct apple_dcp *dcp, int tag, if (!(request->tiled_display_null & 1)) memcpy(out, request->tiled_display, sizeof(request->tiled_display)); + /* The V27 wake's mode set waits for the firmware's report of the panel */ + if (request->connected && dcp->v27_j714s) + complete(&dcp->v27_wake_hotplug); return trampoline_hotplug(dcp, tag, out, in); } diff --git a/drivers/gpu/drm/asahi/g17/sleep.c b/drivers/gpu/drm/asahi/g17/sleep.c index 917965e360142..37a6642fe323f 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.c +++ b/drivers/gpu/drm/asahi/g17/sleep.c @@ -46,14 +46,13 @@ #define ASC_CPU_CONTROL 0x44 #define ASC_CPU_CONTROL_RUN BIT(4) -/* Only the M5 boards with a deep sleep need a wrapped provider translation here: the J714s - * and the J716c. Other G17 clients retain their established direct-domain methods below. +/* Only the M5 boards with a deep sleep need a wrapped provider translation here: those whose + * device tree describes it. Other G17 clients retain their established direct-domain methods + * below. */ static bool asahi_g17_m5_provider(struct device *dev) { - return (of_machine_is_compatible("apple,j714s") || - of_machine_is_compatible("apple,j716c")) && - of_machine_is_compatible("apple,t6050") && + return apple_t6050_sleep_described() && of_device_is_compatible(dev->of_node, "apple,agx-g17s"); } diff --git a/drivers/iommu/apple-dart-v27-admission.inc b/drivers/iommu/apple-dart-v27-admission.inc index 906be5ef222ef..7b6c2be51b903 100644 --- a/drivers/iommu/apple-dart-v27-admission.inc +++ b/drivers/iommu/apple-dart-v27-admission.inc @@ -10,9 +10,7 @@ static bool apple_dart_v27_provider(struct device *dev, resource_size_t base) unsigned int i; if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) || - !(of_machine_is_compatible("apple,j714s") || - (of_machine_is_compatible("apple,j716c") && - of_machine_is_compatible("apple,t6050"))) || + !apple_t6050_sleep_described() || !of_device_is_compatible(dev->of_node, "apple,t6050-dart")) return false; for (i = 0; i < ARRAY_SIZE(ids); i++) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4bb6491eedb8c..114dc4bb0f3cc 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -5458,7 +5458,7 @@ static int apple_dart_probe(struct platform_device *pdev) if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) return -EOPNOTSUPP; dart->isp_host = of_device_is_compatible(dev->of_node, "apple,t6050-isp-dart"); - dart->isp_sleep = dart->isp_host && of_machine_is_compatible("apple,j714s"); + dart->isp_sleep = dart->isp_host && apple_t6050_sleep_described(); dart->power_retained = dart->isp_host; dart->per_stream = dart->isp_host || of_device_is_compatible(dev->of_node, "apple,t8140-dart") || diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 0a9aeced27721..d1a3cd69dcd0f 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -286,8 +287,8 @@ struct aic_info { bool siq_cfg_routing; /* A firmware-driven suspend powers the controller down: aic_syscore_ops keep it. */ bool fw_suspend; - /* If set, fw_suspend holds on these boards only */ - const char *const *fw_suspend_boards; + /* If set, fw_suspend holds only where this says the sleep is described */ + bool (*fw_suspend_described)(void); }; static const struct aic_info aic1_info __initconst = { @@ -336,12 +337,9 @@ static const struct aic_info aic3_info __initconst = { /* * The M5 Pro's sleep: the last steps mask every interrupt and acknowledge events by hand. The - * save and restore are set up on the boards with a T6050 sleep, the J714s and the J716c; + * save and restore are set up on the boards whose device tree describes a T6050 sleep; * another T6050 board is as one without them. */ -static const char *const aic3_t6050_sleep_boards[] __initconst = { - "apple,j714s", "apple,j716c", NULL -}; static const struct aic_info aic3_t6050_info __initconst = { .version = 3, @@ -349,7 +347,7 @@ static const struct aic_info aic3_t6050_info __initconst = { .fast_ipi = true, .local_fast_ipi = true, .fw_suspend = true, - .fw_suspend_boards = aic3_t6050_sleep_boards, + .fw_suspend_described = apple_t6050_sleep_described, }; static const struct aic_info aic3_t8140_info __initconst = { @@ -1280,8 +1278,7 @@ static struct syscore aic_syscore = { static void __init aic_sleep_init(struct aic_irq_chip *irqc) { if (!irqc->info.fw_suspend || - (irqc->info.fw_suspend_boards && - !of_machine_compatible_match(irqc->info.fw_suspend_boards))) + (irqc->info.fw_suspend_described && !irqc->info.fw_suspend_described())) return; aic_sleep.irq_cfg = kcalloc(irqc->nr_die * irqc->nr_irq, sizeof(u32), GFP_KERNEL); diff --git a/drivers/mfd/macsmc-test.c b/drivers/mfd/macsmc-test.c index 95eff75a72da2..471d322f32615 100644 --- a/drivers/mfd/macsmc-test.c +++ b/drivers/mfd/macsmc-test.c @@ -352,6 +352,9 @@ static void macsmc_lid_wake_test(struct kunit *test) static void macsmc_wake_reason_test(struct kunit *test) { + static const struct apple_smc_wake_reason j714s[] = { + { 8, "lid" }, { 9, "sdconn" }, { 13, "wifibt" }, { } + }; struct macsmc_test_context *ctx = test->priv; char names[128]; @@ -371,8 +374,8 @@ static void macsmc_wake_reason_test(struct kunit *test) KUNIT_EXPECT_EQ(test, apple_smc_wake_reason_bit(&ctx->smc, "lid"), 8); KUNIT_EXPECT_EQ(test, apple_smc_wake_reason_bit(&ctx->smc, "ipd_touch"), -1); - /* The J714s's: T8132's lid and radio bits, its SD reader at bit 9. */ - ctx->smc.wake_reasons = apple_smc_j714s_wake_reasons; + /* A device tree's own, here the J714s's: its SD reader at bit 9. */ + ctx->smc.wake_reasons = j714s; apple_smc_wake_reason_names(&ctx->smc, BIT_ULL(8) | BIT_ULL(9) | BIT_ULL(10) | BIT_ULL(13), names, sizeof(names)); KUNIT_EXPECT_STREQ(test, names, "lid sdconn wifibt"); diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 5204c960ebe9d..f3421668a5b6c 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -622,12 +622,29 @@ static const struct apple_smc_wake_reason apple_smc_t8132_wake_reasons[] = { { 44, "USB2_wake" }, { 45, "aupo" }, { 48, "rtc" }, { } }; -/* The J714s's: T8132's numbering, with the SD reader's and the keyboard's own bits */ -static const struct apple_smc_wake_reason apple_smc_j714s_wake_reasons[] = { - { 0, "pwrbtn" }, { 8, "lid" }, { 9, "sdconn" }, { 11, "charger" }, { 13, "wifibt" }, - { 35, "trackpadkeyboard" }, { 40, "acattach" }, { 41, "acdetach" }, { 42, "USB-C_plug" }, - { 43, "USB2_plug" }, { 44, "USB2_wake" }, { 45, "aupo" }, { 48, "rtc" }, { } -}; +/* A board's own numbering, from its device tree (apple,wake-reasons and their names) */ +static const struct apple_smc_wake_reason *apple_smc_dt_wake_reasons(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct apple_smc_wake_reason *r; + int i, n; + + n = of_property_count_u32_elems(np, "apple,wake-reasons"); + if (n <= 0 || n != of_property_count_strings(np, "apple,wake-reason-names")) + return NULL; + r = devm_kcalloc(dev, n + 1, sizeof(*r), GFP_KERNEL); + if (!r) + return NULL; + for (i = 0; i < n; i++) { + u32 bit; + + if (of_property_read_u32_index(np, "apple,wake-reasons", i, &bit) || bit > 63 || + of_property_read_string_index(np, "apple,wake-reason-names", i, &r[i].name)) + return NULL; + r[i].bit = bit; + } + return r; +} static int apple_smc_probe(struct platform_device *pdev) { @@ -640,18 +657,16 @@ static int apple_smc_probe(struct platform_device *pdev) smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL); if (!smc) return -ENOMEM; - smc->wake_reasons = of_device_is_compatible(dev->of_node, "apple,t8132-smc") ? - apple_smc_t8132_wake_reasons : apple_smc_t8140_wake_reasons; + smc->wake_reasons = apple_smc_dt_wake_reasons(dev); + if (!smc->wake_reasons) + smc->wake_reasons = of_device_is_compatible(dev->of_node, "apple,t8132-smc") ? + apple_smc_t8132_wake_reasons : apple_smc_t8140_wake_reasons; mutex_init(&smc->mutex); spin_lock_init(&smc->lock); smc->dev = &pdev->dev; - smc->saved_enabled = of_machine_is_compatible("apple,t6050") && - (of_machine_is_compatible("apple,j714s") || - of_machine_is_compatible("apple,j716c")) && + smc->saved_enabled = apple_t6050_sleep_described() && of_device_is_compatible(dev->of_node, "apple,t6050-smc"); - if (smc->saved_enabled && of_machine_is_compatible("apple,j714s")) - smc->wake_reasons = apple_smc_j714s_wake_reasons; /* J813's late notice needs the bounded, IRQ-independent transport too. */ if (of_machine_is_compatible("apple,j813")) smc->saved_enabled = true; diff --git a/drivers/nvme/host/apple-m5-sleep.h b/drivers/nvme/host/apple-m5-sleep.h index f22d6902bf256..50bcaeabde604 100644 --- a/drivers/nvme/host/apple-m5-sleep.h +++ b/drivers/nvme/host/apple-m5-sleep.h @@ -167,10 +167,8 @@ static int apple_nvme_m5_attach(struct apple_nvme *anv) { int ret; - /* Both boards use T6050 ANS2's split NVMe/NVMMU layout and retained SART. */ - if (!of_machine_is_compatible("apple,t6050") || - (!of_machine_is_compatible("apple,j714s") && - !of_machine_is_compatible("apple,j716c"))) + /* T6050 ANS2's split NVMe/NVMMU layout and retained SART, where the sleep is described. */ + if (!apple_t6050_sleep_described()) return -EOPNOTSUPP; /* The wait before the restart after a sleep comes from the DT; without it, no sleep. */ if (of_property_read_u32(anv->dev->of_node, "apple,sleep-wake-delay-ms", diff --git a/drivers/of/base.c b/drivers/of/base.c index f63a9486b1305..1e7b2e90f2f9a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1916,6 +1916,7 @@ int of_update_property(struct device_node *np, struct property *newprop) return rc; } +EXPORT_SYMBOL_GPL(of_update_property); static void of_alias_add(struct alias_prop *ap, struct device_node *np, int id, const char *stem, int stem_len) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 8e20a36cc575e..9c7037389dfa7 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -5426,8 +5426,7 @@ static void apple_pcie_t6050_sleep_probe(struct platform_device *pdev, struct ap { struct apple_pcie_port *port; - if (pcie->managed_sids || !(of_machine_is_compatible("apple,j714s") || - of_machine_is_compatible("apple,j716c"))) + if (pcie->managed_sids || !apple_t6050_sleep_described()) return; /* The one port a boot loader trained; an endpoint Linux powers is parked instead. */ list_for_each_entry(port, &pcie->ports, entry) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 7dceb224d2556..d67abe3f04a41 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -122,13 +122,13 @@ static void combo_pipe_fault(struct t6050_dp *dp, const char *what, int ret) /* * What the combo PHY gained for a deep sleep outside its sleep callbacks (a wrapper domain * still held at a stop is released, a safe state with a domain still held is stopped again, - * the always-on domain's hold over the sleep) is in force on the boards with a T6050 sleep, - * the J714s and the J716c. On another T6050 board the stop, the safe state and the probe are + * the always-on domain's hold over the sleep) is in force on the boards whose device tree + * describes a T6050 sleep. On another T6050 board the stop, the safe state and the probe are * as before. */ static bool combo_sleep_board(void) { - return of_machine_is_compatible("apple,j714s") || of_machine_is_compatible("apple,j716c"); + return apple_t6050_sleep_described(); } static bool combo_domains_held(struct t6050_dp *dp) diff --git a/drivers/soc/apple/rtkit-v27-late.inc b/drivers/soc/apple/rtkit-v27-late.inc index 6f3bfd84ab0a5..44d3b92cb27b8 100644 --- a/drivers/soc/apple/rtkit-v27-late.inc +++ b/drivers/soc/apple/rtkit-v27-late.inc @@ -7,8 +7,23 @@ struct apple_rtkit_v27_scope { DECLARE_KFIFO(deferred, struct apple_mbox_msg, 64); bool held, stopped, failed; int error; + /* + * Run once between the AP state's acknowledgment and the IOP request, interrupts off. + * An error fails the idle. + */ + int (*after_ap)(void *data); + void *after_ap_data; }; +void apple_rtkit_v27_set_after_ap(struct apple_rtkit_v27_scope *s, int (*fn)(void *), void *data) +{ + if (s) { + s->after_ap = fn; + s->after_ap_data = data; + } +} +EXPORT_SYMBOL_GPL(apple_rtkit_v27_set_after_ap); + bool apple_rtkit_v27_live(struct apple_rtkit *rtk) { return !rtk->crashed && !rtk->shutting_down && @@ -118,6 +133,43 @@ int apple_rtkit_v27_check(struct apple_rtkit_v27_scope *s) } EXPORT_SYMBOL_GPL(apple_rtkit_v27_check); +/* + * A second port's AP idle with interrupts off: sent, and its acknowledgment awaited by polling + * the port's mailbox, for at most @us. The port's tracked state is not updated. + */ +int apple_rtkit_v27_port_ap_idle_atomic(struct apple_rtkit *rtk, unsigned int us) +{ + struct apple_mbox_msg msg = { + .msg0 = FIELD_PREP(APPLE_RTKIT_MGMT_TYPE, APPLE_RTKIT_MGMT_SET_AP_PWR_STATE) | + FIELD_PREP(APPLE_RTKIT_MGMT_PWR_STATE, APPLE_RTKIT_PWR_STATE_IDLE), + .msg1 = APPLE_RTKIT_EP_MGMT, + }; + unsigned int i, n = us / 10; + int ret = -ETIMEDOUT; + + for (i = 0; i < n; i++) { + ret = apple_mbox_send_nowait(rtk->mbox, msg); + if (ret != -EAGAIN && ret != -EBUSY) + break; + udelay(10); + } + if (ret) + return ret; + for (; i < n; i++) { + struct apple_mbox_msg in; + + ret = apple_mbox_recv_nowait(rtk->mbox, &in); + if (ret < 0 && ret != -EBUSY) + return ret; + if (ret > 0 && in.msg1 == APPLE_RTKIT_EP_MGMT && + FIELD_GET(APPLE_RTKIT_MGMT_TYPE, in.msg0) == APPLE_RTKIT_MGMT_SET_AP_PWR_STATE_ACK) + return 0; + udelay(10); + } + return -ETIMEDOUT; +} +EXPORT_SYMBOL_GPL(apple_rtkit_v27_port_ap_idle_atomic); + int apple_rtkit_v27_idle_atomic(struct apple_rtkit_v27_scope *s) { struct apple_rtkit *rtk; @@ -180,6 +232,11 @@ int apple_rtkit_v27_idle_atomic(struct apple_rtkit_v27_scope *s) type == APPLE_RTKIT_MGMT_SET_AP_PWR_STATE_ACK && arg == APPLE_RTKIT_PWR_STATE_IDLE) { ap_ack = true; + if (s->after_ap) { + ret = s->after_ap(s->after_ap_data); + if (ret) + goto poison; + } } else if (msg.msg1 == APPLE_RTKIT_EP_MGMT && iop_sent && !iop_ack && type == APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE_ACK && arg == APPLE_RTKIT_PWR_STATE_IDLE) { diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 22a7fad956426..d3a09760f8f9f 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -558,11 +558,9 @@ static void apple_rtkit_management_rx(struct apple_rtkit *rtk, u64 msg) } } -static int apple_rtkit_alloc_shmem(struct apple_rtkit *rtk, u8 ep, - struct apple_rtkit_shmem *buffer) +static int apple_rtkit_alloc_first_shmem(struct apple_rtkit *rtk, u8 ep, + struct apple_rtkit_shmem *buffer) { - if (READ_ONCE(rtk->ans_hold)) - return apple_rtkit_ans_fail(rtk, -EBUSY); /* The crash log's buffer is asked for only at a crash: serve it after a strict restart too. */ if (READ_ONCE(rtk->strict_retained_buffers) && ep != APPLE_RTKIT_EP_CRASHLOG) return -EPROTO; @@ -577,6 +575,14 @@ static int apple_rtkit_alloc_shmem(struct apple_rtkit *rtk, u8 ep, return buffer->buffer ? 0 : -ENOMEM; } +static int apple_rtkit_alloc_shmem(struct apple_rtkit *rtk, u8 ep, + struct apple_rtkit_shmem *buffer) +{ + if (READ_ONCE(rtk->ans_hold)) + return apple_rtkit_ans_fail(rtk, -EBUSY); + return apple_rtkit_alloc_first_shmem(rtk, ep, buffer); +} + static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk, struct apple_rtkit_shmem *buffer, u8 ep, u64 msg) @@ -650,7 +656,8 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk, goto error; } - err = apple_rtkit_alloc_shmem(rtk, ep, &request); + /* The endpoint has no buffer yet: a first one replaces nothing the ANS hold protects */ + err = apple_rtkit_alloc_first_shmem(rtk, ep, &request); if (err) goto error; *buffer = request; @@ -2273,8 +2280,7 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, goto free_rtk; rtk->pmp_registry_v2 = of_device_is_compatible(dev->of_node, "apple,t6050-pmp-v2"); - rtk->pmp_ca_event_ack = rtk->pmp_registry_v2 && - of_machine_is_compatible("apple,j714s"); + rtk->pmp_ca_event_ack = rtk->pmp_registry_v2; init_completion(&rtk->epmap_completion); init_completion(&rtk->coreanalytics_completion); @@ -2776,6 +2782,13 @@ static int apple_rtkit_strict_idle_state(struct apple_rtkit *rtk, bool ap) } int apple_rtkit_idle_strict(struct apple_rtkit *rtk) +{ + return apple_rtkit_idle_strict_with(rtk, NULL, NULL); +} +EXPORT_SYMBOL_GPL(apple_rtkit_idle_strict); + +/* As apple_rtkit_idle_strict(), with a step between the AP state's and the IOP state's. */ +int apple_rtkit_idle_strict_with(struct apple_rtkit *rtk, void (*after_ap)(void *data), void *data) { int ret; @@ -2786,6 +2799,8 @@ int apple_rtkit_idle_strict(struct apple_rtkit *rtk) reinit_completion(&rtk->strict_idle_done); WRITE_ONCE(rtk->strict_idle_waiting, true); ret = apple_rtkit_strict_idle_state(rtk, true); + if (!ret && after_ap) + after_ap(data); if (!ret) ret = apple_rtkit_strict_idle_state(rtk, false); if (!ret && !wait_for_completion_timeout(&rtk->strict_idle_done, @@ -2798,7 +2813,7 @@ int apple_rtkit_idle_strict(struct apple_rtkit *rtk) rtk->strict_idle_poisoned = true; return ret; } -EXPORT_SYMBOL_GPL(apple_rtkit_idle_strict); +EXPORT_SYMBOL_GPL(apple_rtkit_idle_strict_with); int apple_rtkit_warm_restart_strict(struct apple_rtkit *rtk) { diff --git a/drivers/soc/apple/sleep-t6050.h b/drivers/soc/apple/sleep-t6050.h index b9744f3a5e36c..b4b9dfce1f659 100644 --- a/drivers/soc/apple/sleep-t6050.h +++ b/drivers/soc/apple/sleep-t6050.h @@ -623,8 +623,9 @@ static int t6050_sleep_check_alarm(struct apple_sleep *s) ret = t6050_sleep_pmu_xfer(s, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &control, 1); if (!ret) ret = t6050_sleep_pmu_xfer(s, T6050_SPMI_EXT_READL, T6050_RTC_MASK, NULL, &mask, 1); + /* No armed alarm is no refusal: the SMC's wake sources (lid, keys) do not need it */ if (!ret && (!(control & T6050_RTC_CTL_ARMED) || (mask & BIT(0)))) - ret = -EBUSY; + return 0; if (!ret) ret = t6050_sleep_pmu_xfer(s, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, NULL, r->alarm_compare, 4); @@ -2750,6 +2751,9 @@ static int t6050_sleep_final_check(struct apple_sleep *s) ret = t6050_sleep_check_alarm(s); if (ret) return ret; + /* No alarm armed: nothing to hold against the sleep timer */ + if (!r->alarm_valid) + return 0; ret = t6050_sleep_pmu_xfer(s, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, NULL, ticks, 6); if (ret) return ret; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 465e30fef8236..c5420f6436373 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1893,10 +1893,10 @@ static int apple_sleep_validate_cpu_topology(struct apple_sleep *s) soc->cpu_cores_per_cluster > 32) return dev_err_probe(s->dev, -EINVAL, "invalid CPU-start geometry\n"); - if (soc->machine && (!of_machine_is_compatible(soc->machine) || - cpu_logical_map(0) != soc->boot_mpidr || - num_possible_cpus() != soc->cpu_count)) - return dev_err_probe(s->dev, -EINVAL, "unsupported board/CPU inventory\n"); + /* The node's compatible chose the profile: its machine is where it was measured */ + if (soc->machine && (cpu_logical_map(0) != soc->boot_mpidr || + num_possible_cpus() != soc->cpu_count)) + return dev_err_probe(s->dev, -EINVAL, "unsupported CPU inventory\n"); index = of_property_match_string(np, "reg-names", "cpu-start"); if (index < 0) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 4d9b4ac0d8346..10eeb79d7de04 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -1083,12 +1083,12 @@ static void dwc3_apple_check_hub_later(struct dwc3_apple *appledwc) /* * Waiting for a Type-C PHY that is not started after sleep is specific to the T6050 boards - * whose port controllers take the sleep's power states (J714s, J716c). The notifier work - * and its admission rules apply to every board. + * whose port controllers take the sleep's power states: those whose device tree describes + * the sleep. The notifier work and its admission rules apply to every board. */ static bool dwc3_apple_sleep_board(void) { - return of_machine_is_compatible("apple,j714s") || of_machine_is_compatible("apple,j716c"); + return apple_t6050_sleep_described(); } /* diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 6ad1d66a67fb9..5024c09bf6453 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -354,16 +354,13 @@ static int tps6598x_disconnect(struct tps6598x *tps, u32 status) /* * The sleep's rules for the port controllers' system power state command (the controller is * woken first, the command's end is read at intervals, a failed S3 refuses the sleep, the - * command's limit and its lines) apply on the J714s, J716c, J813 and J815. - * These boards send the command (apple,sleep-ssps) during firmware-driven - * sleep. Other boards retain the original command behavior. + * command's limit and its lines) apply to every controller that sends the command around a + * firmware-driven sleep (apple,sleep-ssps). Other controllers retain the original command + * behavior. */ -static bool tipd_sleep_ssps_rules(void) +static bool tipd_sleep_ssps_rules(const struct tps6598x *tps) { - return of_machine_is_compatible("apple,j714s") || - of_machine_is_compatible("apple,j716c") || - of_machine_is_compatible("apple,j813") || - of_machine_is_compatible("apple,j815"); + return device_property_read_bool(tps->dev, "apple,sleep-ssps"); } /* @@ -419,11 +416,11 @@ static int tps6598x_exec_cmd_gap(struct tps6598x *tps, const char *cmd, * its last read was made at. Elsewhere a read made past the limit is a timeout, * as before. */ - if ((val || !tipd_sleep_ssps_rules()) && time_is_before_jiffies(timeout)) + if ((val || !tipd_sleep_ssps_rules(tps)) && time_is_before_jiffies(timeout)) return -ETIMEDOUT; /* A command with a long limit is not waited for in silence: a line each second */ if (val && cmd_timeout_ms > 1000 && time_is_before_jiffies(note) && - tipd_sleep_ssps_rules()) { + tipd_sleep_ssps_rules(tps)) { dev_info(tps->dev, "command %.4s not done after %u ms (limit %u ms)\n", cmd, jiffies_to_msecs(jiffies - (timeout - msecs_to_jiffies(cmd_timeout_ms))), cmd_timeout_ms); @@ -1719,17 +1716,12 @@ static int cd321x_prepare(struct tps6598x *tps) cancel_delayed_work_sync(&cd321x->rearm_work); /* As macOS does a second or so before the commit, measured on the same controller. */ - if (pm_suspend_via_firmware() && device_property_read_bool(tps->dev, "apple,sleep-ssps")) { + if (pm_suspend_via_firmware() && tipd_sleep_ssps_rules(tps)) { ktime_t start = ktime_get(); guard(mutex)(&tps->lock); ret = tps->data->switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S3); - /* Without the rules: the lines and their levels as they were */ - if (!tipd_sleep_ssps_rules() && ret) - dev_warn(tps->dev, "didn't take system power state S3: %d\n", ret); - else if (!tipd_sleep_ssps_rules()) - dev_dbg(tps->dev, "system power state S3\n"); - else if (ret) + if (ret) dev_warn(tps->dev, "didn't take system power state S3: %d after %lld ms%s\n", ret, ktime_ms_delta(ktime_get(), start), sleep_s3_refuse ? ": sleep refused" : ""); @@ -1737,7 +1729,7 @@ static int cd321x_prepare(struct tps6598x *tps) dev_info(tps->dev, "system power state S3 in %lld ms\n", ktime_ms_delta(ktime_get(), start)); } - if (ret && sleep_s3_refuse && tipd_sleep_ssps_rules()) + if (ret && sleep_s3_refuse) return -EBUSY; return 0; } @@ -1916,14 +1908,12 @@ static void cd321x_complete(struct tps6598x *tps) cd321x->pm.setup_pending = true; cd321x->reset_by_cut = true; } - if (pm_suspend_via_firmware() && device_property_read_bool(tps->dev, "apple,sleep-ssps")) { + if (pm_suspend_via_firmware() && tipd_sleep_ssps_rules(tps)) { ktime_t start = ktime_get(); int ret = tps->data->switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); /* After a sleep or a refused one: never waited for in silence, and never longer */ - if (!tipd_sleep_ssps_rules()) - ret = 0; - else if (ret) + if (ret) dev_warn(tps->dev, "didn't take system power state S0: %d after %lld ms; set up again by its next event\n", ret, ktime_ms_delta(ktime_get(), start)); else @@ -2395,7 +2385,7 @@ static int cd321x_switch_power_state(struct tps6598x *tps, u8 target_state) * Under the sleep's rules the command goes to a controller that has just been sent its * bus's wake command and has answered it, whatever it was doing: woken, read, commanded. */ - if (tps->wake && tipd_sleep_ssps_rules()) { + if (tps->wake && tipd_sleep_ssps_rules(tps)) { ret = tps->wake(tps); if (ret) return ret; @@ -2413,13 +2403,13 @@ static int cd321x_switch_power_state(struct tps6598x *tps, u8 target_state) * the sleep's rules. Under them S0 and S3 have the sleep's own limit and are read with * gaps. */ - if ((target_state == TPS_SYSTEM_POWER_STATE_S0 || tipd_sleep_ssps_rules()) && + if ((target_state == TPS_SYSTEM_POWER_STATE_S0 || tipd_sleep_ssps_rules(tps)) && device_is_compatible(tps->dev, "apple,sn201202x")) ret = tps6598x_exec_cmd_gap(tps, "SSPS", sizeof(target_state), &target_state, 0, NULL, - tipd_sleep_ssps_rules() ? + tipd_sleep_ssps_rules(tps) ? clamp(sleep_ssps_ms, 1000U, 5000U) : 5000, 0, - tipd_sleep_ssps_rules() ? CD321X_SSPS_READ_GAP_US : 0); + tipd_sleep_ssps_rules(tps) ? CD321X_SSPS_READ_GAP_US : 0); else ret = tps6598x_exec_cmd(tps, "SSPS", sizeof(target_state), &target_state, 0, NULL); diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c index 4865a65d9792d..2a93d3b3b9a82 100644 --- a/drivers/usb/typec/tipd/spmi.c +++ b/drivers/usb/typec/tipd/spmi.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -734,7 +735,7 @@ static bool sn201202x_sleep_event(struct tps6598x *tps) } /* - * On the T6050 boards that sleep (J714s, J716c), the probe and the sleep's SLEEP command print a + * On the T6050 boards that describe a deep sleep, the probe and the sleep's SLEEP command print a * line; on every other machine they don't. A controller without a connector (the MagSafe one, * hpm5) is probed as any other: it registers its Type-C port and power supply, and with * apple,sleep-ssps it follows the system's sleep as the USB-C ports' controllers do (woken and @@ -743,12 +744,7 @@ static bool sn201202x_sleep_event(struct tps6598x *tps) */ static bool sn201202x_sleep_board(void) { - return of_machine_is_compatible("apple,j714s") || of_machine_is_compatible("apple,j716c"); -} - -static bool sn201202x_j714s(void) -{ - return of_machine_is_compatible("apple,j714s"); + return apple_t6050_sleep_described(); } /* @@ -760,7 +756,7 @@ static bool sn201202x_j714s(void) * -EINVAL. Both ports, and every USB, Thunderbolt and DisplayPort device on them, stayed gone * until the next boot. * - * On that board a failed probe is tried again after a growing wait. After the third failed try + * On these boards a failed probe is tried again after a growing wait. After the third failed try * the controller's firmware is cold-reset ("Gaid", as the debug link's recovery does), unless * it is in the debug mode of the boot loader's debug link, and it is tried twice more. Each try * runs in a devres group of its own, so what a failed try set up is released before the next. @@ -817,7 +813,7 @@ static int sn201202x_init(struct sn201202x *sn) void *group; int ret; - if (!sn201202x_j714s()) { + if (!sn201202x_sleep_board()) { ret = tipd_init(tps); if (ret) cancel_delayed_work_sync(&sn->ldcm_work); diff --git a/include/linux/soc/apple/dcp-v27-sleep.h b/include/linux/soc/apple/dcp-v27-sleep.h index 5e56c40141903..3484c04a98c2c 100644 --- a/include/linux/soc/apple/dcp-v27-sleep.h +++ b/include/linux/soc/apple/dcp-v27-sleep.h @@ -39,6 +39,8 @@ int apple_rtkit_v27_arm(struct apple_rtkit *, struct apple_rtkit_v27_scope **); bool apple_rtkit_v27_live(struct apple_rtkit *); int apple_rtkit_v27_check(struct apple_rtkit_v27_scope *); int apple_rtkit_v27_idle_atomic(struct apple_rtkit_v27_scope *); +int apple_rtkit_v27_port_ap_idle_atomic(struct apple_rtkit *rtk, unsigned int us); +void apple_rtkit_v27_set_after_ap(struct apple_rtkit_v27_scope *s, int (*fn)(void *), void *data); int apple_rtkit_v27_disarm(struct apple_rtkit_v27_scope *, bool stopped); int apple_dart_v27_claim(struct device *provider, struct device *firmware, diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 4db916bb89f09..01b6f604148de 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -285,6 +285,7 @@ int apple_rtkit_idle(struct apple_rtkit *rtk); /* The mailbox's receive-enable bit (I2A_CONTROL bit 0): off once a slept firmware has answered its idle. */ void apple_rtkit_set_recv_enabled(struct apple_rtkit *rtk, bool enabled); int apple_rtkit_idle_strict(struct apple_rtkit *rtk); +int apple_rtkit_idle_strict_with(struct apple_rtkit *rtk, void (*after_ap)(void *data), void *data); int apple_rtkit_warm_restart_strict(struct apple_rtkit *rtk); int apple_rtkit_warm_restart_stopped(struct apple_rtkit *rtk); diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index cec1e88452676..db45c2c5615d9 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -9,10 +9,33 @@ #include #include #include +#include #include struct device; -struct device_node; + +/* + * A T6050 machine whose device tree describes the firmware-driven sleep. What a + * driver does for that sleep follows the description, not a list of boards. + * With @prop: the description also has that property. + */ +static inline bool apple_t6050_sleep_property(const char *prop) +{ + struct device_node *np; + bool ret; + + if (!of_machine_is_compatible("apple,t6050")) + return false; + np = of_find_compatible_node(NULL, NULL, "apple,t6050-sleep"); + ret = np && of_device_is_available(np) && (!prop || of_property_read_bool(np, prop)); + of_node_put(np); + return ret; +} + +static inline bool apple_t6050_sleep_described(void) +{ + return apple_t6050_sleep_property(NULL); +} /* The SMC's sleep messages: the pmVC value and the spacings between them, used as floors */ struct apple_sleep_smc_policy {