diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 974dd84d1cbf7..5affc5c1c587d 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -98,6 +98,14 @@ patternProperties: Byte offsets of the pair of power-gate retention words (A, then B) within the selected pwrgate window. + apple,dcp: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Read on T6041 only, on an external display chain. The display coprocessor + this chain powers, which is then restarted after wake as on T6040. + Without it the coprocessor is shut down for suspend-to-RAM and stays + off after wake. + apple,fabric-domain: $ref: /schemas/types.yaml#/definitions/phandle description: diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 86c4059480aa5..ef2d4c2c524a0 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -277,6 +277,13 @@ patternProperties: pwren-gpios may be left untrained; the OS then trains it first and adopts it the same way. + apple,no-refclk-gating: + type: boolean + description: + Do not enable dynamic REFCLK gating on this root port. Set when the + endpoint requires a continuously running reference clock (matching + the ADT no-refclk-gating property). + apple,tunable: $ref: '#/$defs/tunable' description: Initialization tuples relative to this port's registers. diff --git a/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi b/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi index 1fe04fb9e6212..caf74c6cbb877 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi +++ b/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi @@ -115,6 +115,7 @@ <97 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index 9ce2d8d884d23..91a5e9f4ae5cd 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -970,6 +970,8 @@ }; &smc { + /* VDD_CIO mask: bit 8 + bit 0 keeps port 0 powered for atc0_common at commit. */ + apple,sleep-pmvc = <0x101>; status = "okay"; smc_gpio_low: gpio-low { @@ -1230,10 +1232,17 @@ <0x4 0x17020000 0x0 0x4000>, <0x4 0x17024000 0x0 0x4000>, <0x4 0x17028000 0x0 0x4000>, - <0x4 0x1702c000 0x0 0x4000>; + <0x4 0x1702c000 0x0 0x4000>, + <0x4 0x16000000 0x0 0x1000000>, + <0x4 0x15046200 0x0 0x4000>, + <0x4 0x15044000 0x0 0x4000>, + <0x4 0x17000000 0x0 0x40000>, + <0x4 0x17040000 0x0 0x28000>; reg-names = "config", "rc", "port0", "port1", "port2", "port3", - "phy0", "phy1", "phy2", "phy3"; + "phy0", "phy1", "phy2", "phy3", + "axi2af", "cio3pll", "clkgen", + "phy-block", "phy-ip"; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; pinctrl-names = "default"; @@ -1319,11 +1328,12 @@ }; }; - /* ADT pci-bridge2/lan-10gb: AQC113, PERST AP pin 6, no power */ + /* ADT pci-bridge2/lan-10gb: AQC113, PERST AP pin 6, no-refclk-gating, no power */ port02: pci@2,0 { device_type = "pci"; reg = <0x1000 0 0 0 0>; reset-gpios = <&pinctrl 6 GPIO_ACTIVE_LOW>; + apple,no-refclk-gating; bus-range = <3 3>; #address-cells = <3>; #size-cells = <2>; @@ -1465,6 +1475,7 @@ <19 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; typec0: connector { compatible = "usb-c-connector"; @@ -1495,6 +1506,7 @@ <45 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; @@ -1528,6 +1540,7 @@ <71 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; @@ -2068,6 +2081,105 @@ phandle = <&display>; }; +/* + * The internal DCP runs no panel here. The boot loader hands it over all the + * same, and the display driver keeps it as the sleep host, which stops every + * display processor before the display power chains go down (the J616c's). + */ +/ { + clk_disp0: clock-disp0 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <712000000>; + clock-output-names = "disp0"; + }; + + dcp_power: display-power@5048a9c14 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x048a9c14 0x0 0x8>, + <0x5 0x022a1000 0x0 0x100>, + <0x5 0x0282d000 0x0 0x1000>, + <0x5 0x00578000 0x0 0x1000>, + <0x4 0x03000100 0x0 0x10>; + reg-names = "pmc-dcp", "pwrgate", "pwrgate-aux", "gapf", "axi2af"; + #address-cells = <1>; + #size-cells = <0>; + + chain@0 { + reg = <0>; + label = "ext3"; + apple,dcp = <&dcpext3>; + apple,pwrgate-aux; + apple,gapf-offset = <0x740>; + apple,pwrgate-offsets = <0xfb4 0xfd8>; + power-domains = <&ps_dispext3_sys>, <&ps_dispext3_fe>, <&ps_dispext3_cpu>, + <&ps_dispext3_dbe>, <&ps_dpext3>, <&ps_dispext3_gp0>, + <&ps_dispext3_gp1>, <&ps_dispext3_gpl>, <&ps_dispext3_ppp>, + <&ps_dispext3_dsc>; + }; + + chain@1 { + reg = <1>; + label = "ext2"; + apple,dcp = <&dcpext2>; + apple,pwrgate-aux; + apple,gapf-offset = <0xd80>; + apple,pwrgate-offsets = <0xb34 0xb58>; + power-domains = <&ps_dispext2_sys>, <&ps_dispext2_fe>, <&ps_dispext2_cpu>, + <&ps_dispext2_dbe>, <&ps_dpext2>, <&ps_dispext2_gp0>, + <&ps_dispext2_gp1>, <&ps_dispext2_gpl>, <&ps_dispext2_ppp>, + <&ps_dispext2_dsc>; + }; + + chain@2 { + reg = <2>; + label = "ext1"; + apple,dcp = <&dcpext1>; + apple,pwrgate-aux; + apple,gapf-offset = <0xd00>; + apple,pwrgate-offsets = <0x6b4 0x6d8>; + power-domains = <&ps_dispext1_sys>, <&ps_dispext1_fe>, <&ps_dispext1_cpu>, + <&ps_dispext1_dbe>, <&ps_dpext1>, <&ps_dispext1_gp0>, + <&ps_dispext1_gp1>, <&ps_dispext1_gpl>, <&ps_dispext1_ppp>, + <&ps_dispext1_dsc>; + }; + + chain@3 { + reg = <3>; + label = "ext0"; + apple,dcp = <&dcpext0>; + apple,pwrgate-aux; + apple,gapf-offset = <0x840>; + apple,pwrgate-offsets = <0x234 0x258>; + power-domains = <&ps_dispext0_sys>, <&ps_dispext0_fe>, <&ps_dispext0_cpu>, + <&ps_dispext0_dbe>, <&ps_dpext0>, <&ps_dispext0_gp0>, + <&ps_dispext0_gp1>, <&ps_dispext0_gpl>, <&ps_dispext0_ppp>, + <&ps_dispext0_dsc>; + }; + + chain@4 { + reg = <4>; + label = "main"; + apple,main-chain; + apple,gapf-offset = <0x540>; + apple,pwrgate-offsets = <0x1c 0x60>; + apple,fabric-domain = <&ps_fab6_soc>; + power-domains = <&ps_disp_sys>, <&ps_disp_fe>, <&ps_disp_cpu>, + <&ps_disp_spi>, <&ps_disp_spmi>, <&ps_disp_dbe>, + <&ps_disp_dp>, <&ps_disp_gp0>, <&ps_disp_gp1>, + <&ps_disp_gpl>, <&ps_disp_cmb>, <&ps_disp_ppp>, + <&ps_disp_brc>, <&ps_disp_blc>; + }; + }; +}; + +&dcp { + apple,sleep-host-stop; + apple,display-power = <&dcp_power>; + clocks = <&clk_disp0>; + phandle = <&dcp>; +}; + &disp0_piodma { phandle = <&disp0_piodma>; }; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 4d92238a28558..1e3af2c1c0fb0 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -320,6 +320,11 @@ struct dcp_t6041_chain { unsigned int num_domains; /* T6040: an external chain's child_saved holds what its stop found */ bool child_valid; + /* + * T6041: the external DCP this chain powers (apple,dcp), restarted after the wake as + * T6040's are; 0 if none, and that DCP stays off after the wake. + */ + phandle dcp; }; /* @@ -1130,6 +1135,8 @@ struct apple_dcp { * started since: its D572(0) has come and gone, and a second set_power_state(0) gets none. */ bool pipe_off; + /* The firmware took the pipe down at start (no display) and nothing has powered it on. */ + bool pipe_off_since_start; /* Refused its idle with the display off: the firmware still runs, the display is dark. */ bool s2r_refused_off; /* The firmware's secure mailbox, where it has one. */ diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 983bf74ac69d6..bbaa92dcca204 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -4862,10 +4862,11 @@ static void dcp_dpavctrl_service_init(struct apple_epic_service *service, d->dpavctrl_late_service = service; /* - * The internal panel announces only the AV controller on interface 5 - * and the deferred DP controller on interface 7. + * The internal processor announces only the AV controller on + * interface 5 and the deferred DP controller on interface 7, with a + * panel or without one (the J575c). */ - if (dcp_has_panel(dcp)) { + if (!dcp_desktop_external(dcp)) { if (d->dpavctrl_av_controller[1] && d->dpavctrl_late_service) complete_all(&d->dpavctrl_ready); } else if (service->ep->num_channels >= 4) { @@ -8700,6 +8701,13 @@ static int dcp_t6041_parse_chain(struct device *dev, struct dcp_t6041_power *pwr chain->is_main = of_property_read_bool(child, "apple,main-chain"); pg_aux = of_property_read_bool(child, "apple,pwrgate-aux"); + if (!chain->is_main) { + struct device_node *dcp_np __free(device_node) = + of_parse_phandle(child, "apple,dcp", 0); + + if (dcp_np) + chain->dcp = dcp_np->phandle; + } if (of_property_read_u32(child, "apple,gapf-offset", &gapf_off) || (gapf_off & 3) || gapf_off > gapf_size || gapf_size - gapf_off < sizeof(u32)) { @@ -8762,7 +8770,7 @@ static int dcp_t6041_parse_chain(struct device *dev, struct dcp_t6041_power *pwr chain->domains[i] = reg; } - if ((chain->is_main || pwr->t6040) && count > 3) { + if ((chain->is_main || pwr->t6040 || chain->dcp) && count > 3) { chain->child_saved = devm_kcalloc(dev, count - 3, sizeof(*chain->child_saved), GFP_KERNEL); if (!chain->child_saved) @@ -10469,6 +10477,20 @@ void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) on, READ_ONCE(dcp->s2r_active)); guard(mutex)(&dcp->s2r_dart_lock); + + /* + * With no display at start (no HPD: the J575c's internal DCP drives no + * panel) the firmware takes its pipe down itself, before the start is + * done, and Linux never powers it on. A sleep then has no power-off to + * ask for: a second set_power_state(0) gets no D572. + */ + if (!dcp_desktop_external(dcp) && !dcp_has_panel(dcp) && !on && + !READ_ONCE(dcp->s2r_active) && !dcp->active) { + dev_dbg(dcp->dev, "display pipe off since start-up\n"); + WRITE_ONCE(dcp->pipe_off, true); + WRITE_ONCE(dcp->pipe_off_since_start, true); + } + if (!READ_ONCE(dcp->s2r_active)) return; @@ -13264,16 +13286,59 @@ static int dcp_t6041_recommit_planes(struct apple_dcp *dcp); */ #define DCP_S2R_PLUG_MS 10000 +/* + * The chain of an external DCP that is restarted after the wake. T6040: by its label, + * apple,dcp-endpoint 1 is ext0. T6041: the chain that names it (apple,dcp), if one does. + */ +static struct dcp_t6041_chain *dcp_t6040_ext_chain(struct apple_dcp *host, + struct apple_dcp *dcp) +{ + struct dcp_t6041_power *pwr = &host->t6041_power; + phandle ph = dcp->dev->of_node ? dcp->dev->of_node->phandle : 0; + char name[16]; + unsigned int i; + + if (!pwr->t6040) { + for (i = 0; i < pwr->num_chains && ph; i++) + if (!pwr->chains[i].is_main && pwr->chains[i].dcp == ph) + return &pwr->chains[i]; + return NULL; + } + if (!dcp->peer_endpoint) + return NULL; + snprintf(name, sizeof(name), "ext%u", dcp->peer_endpoint - 1); + for (i = 0; i < pwr->num_chains; i++) + if (!pwr->chains[i].is_main && !strcmp(pwr->chains[i].name, name)) + return &pwr->chains[i]; + return NULL; +} + /* * T6040 (apple,t6040-display-power): its sleep takes the external links down and back, its * external DCPs being restarted after the wake as the internal one (dcp_t6040_ext_start_one()). - * On T6041 they are shut down and stay off. + * On T6041 only those whose chain names them (apple,dcp) are; the others are shut down and + * stay off. + */ +bool dcp_t6040_relinks(struct apple_dcp *dcp) +{ + struct apple_dcp *host = READ_ONCE(dcp_t6041_host); + + if (!host || !dcp) + return false; + if (host->t6041_power.t6040) + return true; + return dcp != host && dcp_t6040_ext_chain(host, dcp); +} + +/* + * T6041's display DARTs are locked (apple_dart_display_keep()): an external DCP restarted after + * the wake keeps their words across the sleep, as the internal one does. */ -bool dcp_t6040_relinks(void) +static bool dcp_t6041_ext_keeps(struct apple_dcp *dcp) { struct apple_dcp *host = READ_ONCE(dcp_t6041_host); - return host && host->t6041_power.t6040; + return host && !host->t6041_power.t6040 && dcp_t6040_relinks(dcp); } /* The fixed HDMI output of a T6040 external DCP, not lent to a Type-C display. */ @@ -13351,7 +13416,8 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi /* The display DART's streams turned off here, not by a D572(0). */ bool streams_off = false; bool idle_attempted = false; - bool t6040 = dcp_t6040_relinks(); + /* T6040's sleep, or a T6041 external DCP restarted after the wake as T6040's are. */ + bool t6040 = dcp_t6040_relinks(dcp); bool relink; u32 ctrl, status; int ret; @@ -13426,6 +13492,16 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi if (dcp->s2r_dcp_dart && !external) apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true); keep_set = !external; + /* A T6041 external one's too: they are locked as well (dcp_t6041_ext_keeps()). */ + if (relink && dcp_t6041_ext_keeps(dcp)) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, true); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, + DCP_S2R_DCP_STREAMS, true); + keep_set = true; + } /* * As linux#1477 dcp_t6041_s2r_stop: the pipe off through the firmware, then wait for * its calls to settle. No av_service_disconnect: the firmware answered it with an @@ -13638,20 +13714,21 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi { int dart_ret = 0; - if (!external) { - if (keep_set) { - if (dcp->s2r_disp_dart) - apple_dart_display_keep(dcp->s2r_disp_dart, - DCP_S2R_DISP_STREAMS, false); - if (dcp->s2r_dcp_dart) - apple_dart_display_keep(dcp->s2r_dcp_dart, - DCP_S2R_DCP_STREAMS, false); - } - if ((powered_off || streams_off) && dcp->s2r_disp_dart) - dart_ret = apple_dart_display_streams(dcp->s2r_disp_dart, - DCP_S2R_DISP_STREAMS, - true, false); - } + if (keep_set) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, false); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, + DCP_S2R_DCP_STREAMS, false); + } + if (!external && (powered_off || streams_off) && dcp->s2r_disp_dart) + dart_ret = apple_dart_display_streams(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, + true, false); + if (relink && (powered_off || streams_off) && dcp->s2r_disp_dart) + apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, + true, false); dcp_s2r_put_darts(dcp); if (dart_ret) { dev_err(dev, "display DART restore after failed stop failed: %d\n", @@ -13660,9 +13737,6 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi return ret; } } - if (relink && powered_off && dcp->s2r_disp_dart) - apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true, false); - dcp_s2r_put_darts(dcp); iomfb_pause_presentation(dcp, false); if (idle_attempted) { int ap_ret = apple_rtkit_ap_power(dcp->rtk, true); @@ -13876,6 +13950,13 @@ static int dcp_t6041_display_poweron(struct apple_dcp *dcp) ktime_t start = ktime_get(); int ret; + /* + * A pipe the firmware took down at start, with no display, stays down: no power-on, so no + * D575 to wait for, and no mode to set (the J575c's internal DCP, the sleep host). + */ + if (READ_ONCE(dcp->pipe_off_since_start)) + return 0; + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) { WRITE_ONCE(dcp->pipe_off, false); WRITE_ONCE(dcp->afk_power_gen, dcp->afk_power_gen + 1); @@ -14365,23 +14446,6 @@ static bool dcp_t6040_word_up(void __iomem *w) 50, 10000); } -/* T6040: the chain of an external DCP, by its label: apple,dcp-endpoint 1 is ext0. */ -static struct dcp_t6041_chain *dcp_t6040_ext_chain(struct apple_dcp *host, - struct apple_dcp *dcp) -{ - struct dcp_t6041_power *pwr = &host->t6041_power; - char name[16]; - unsigned int i; - - if (!dcp->peer_endpoint) - return NULL; - snprintf(name, sizeof(name), "ext%u", dcp->peer_endpoint - 1); - for (i = 0; i < pwr->num_chains; i++) - if (!pwr->chains[i].is_main && !strcmp(pwr->chains[i].name, name)) - return &pwr->chains[i]; - return NULL; -} - /* * T6040: an external DCP after the wake, as the internal one (dcp_t6041_start_one()): its * chain's domains in the same order (SYS, the retention pair, FE, the GAPF protection off, CPU, @@ -14438,6 +14502,13 @@ static int dcp_t6040_ext_start_one(struct device *dev, void *data) of_node_put(piodma); dcp_t6041_dart_dark(dev->of_node, false); dcp_s2r_find_darts(dcp); + /* T6041: the words its locked DARTs had before the sleep (dcp_t6041_stop_one()). */ + if (!host->t6041_power.t6040) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, false); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, false); + } if (dcp->s2r_disp_dart) apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true, false); if (dcp->s2r_dcp_dart) @@ -14611,8 +14682,11 @@ static int dcp_t6041_s2r_step(enum dcp_t6041_step step) dcp_t6041_words = false; ret = driver_for_each_device(&apple_platform_driver.driver, NULL, NULL, dcp_t6041_start_one); - /* T6040: the external DCPs once the internal display runs again. */ - if (!ret && host->t6041_power.t6040) + /* + * The external DCPs once the internal display runs again: on T6040 all of them, + * on T6041 those whose chain names them (dcp_t6040_ext_chain()). + */ + if (!ret) ret = driver_for_each_device(&apple_platform_driver.driver, NULL, host, dcp_t6040_ext_start_one); return ret; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index c68f55fb41835..c945ba19a5397 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -181,7 +181,7 @@ bool dcp_hold_resume_event(struct platform_device *pdev); bool dcp_s2r_firmware_stopped(struct platform_device *pdev); int dcp_t6041_s2r_all(bool start); int dcp_t6041_s2idle(bool start); -bool dcp_t6040_relinks(void); +bool dcp_t6040_relinks(struct apple_dcp *dcp); int iomfb_start_rtkit(struct apple_dcp *dcp); void iomfb_ext26_start(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 46abe27ef302a..2ec1fdbccd781 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -1629,7 +1629,7 @@ static int dcp_retrain_active_crtc(struct apple_connector *connector, (READ_ONCE(dcp->mode_state.valid) || !dcp_has_mode(dcp, &crtc->state->mode))) { ret = 0; - } else if (dcp_t6040_relinks() && crtc && crtc->state && crtc->state->active && + } else if (dcp_t6040_relinks(dcp) && crtc && crtc->state && crtc->state->active && !dcp_mode_settable(dcp, &crtc->state->mode) && !dcp_typec_follows_crtc(dcp)) { /* @@ -2065,7 +2065,7 @@ void dcp_hotplug(struct work_struct *work) * mode list: the plug that follows reads that list, so a link recovery * pending for the old one would only take the new link down. */ - if (!READ_ONCE(connector->connected) && dcp_t6040_relinks()) + if (!READ_ONCE(connector->connected) && dcp_t6040_relinks(dcp)) cancel_delayed_work(&dcp->link_recovery_wq); scoped_guard(mutex, &connector->base.dev->mode_config.mutex) { diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 36dca5e1e1463..6adfbeae262ca 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -2691,6 +2691,7 @@ void DCP_FW_NAME(iomfb_poweron)(struct apple_dcp *dcp) #endif dev_info(dcp->dev, "dcp_poweron() starting\n"); WRITE_ONCE(dcp->pipe_off, false); + WRITE_ONCE(dcp->pipe_off_since_start, false); #if DCP_FW_H17(DCP_FW_VER) if (dcp_is_ext26(dcp)) return; /* Native26 publishes A473 only after a successful A413. */ diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index 01792f7abf962..a2cd29280201f 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c @@ -516,8 +516,10 @@ int aq_nic_start(struct aq_nic_s *self) aq_vec = self->aq_vec[i]; err = aq_vec_start(aq_vec); if (err < 0) - goto err_exit; + goto err_vec; } + /* All vectors have NAPI enabled; a failure past here is undone by aq_nic_stop(). */ + aq_utils_obj_set(&self->flags, AQ_NIC_FLAG_DPATH_UP); err = aq_reapply_rxnfc_all_rules(self); if (err < 0) @@ -599,6 +601,11 @@ int aq_nic_start(struct aq_nic_s *self) } netif_tx_start_all_queues(self->ndev); + return 0; + +err_vec: + while (i--) + aq_vec_stop(self->aq_vec[i]); err_exit: return err; } @@ -1428,6 +1435,15 @@ int aq_nic_stop(struct aq_nic_s *self) { unsigned int i = 0U; + /* + * Stopped already, with no start since: a resume whose aq_nic_init() failed leaves + * the interface running and its NAPI contexts disabled, and a second napi_disable() + * would wait for ever. + */ + if (!aq_utils_obj_test(&self->flags, AQ_NIC_FLAG_DPATH_UP)) + return 0; + aq_utils_obj_clear(&self->flags, AQ_NIC_FLAG_DPATH_UP); + netif_tx_disable(self->ndev); netif_carrier_off(self->ndev); @@ -1453,6 +1469,9 @@ int aq_nic_stop(struct aq_nic_s *self) void aq_nic_set_power(struct aq_nic_s *self) { + /* A controller that did not come back from a sleep answers no firmware request. */ + if (!pci_device_is_present(self->pdev)) + return; if (self->power_state != AQ_HW_POWER_STATE_D0 || self->aq_hw->aq_nic_cfg->wol) if (likely(self->aq_fw_ops->set_power)) { diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h index ad33f8586532b..d225f997699f6 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h @@ -83,6 +83,8 @@ struct aq_nic_cfg_s { #define AQ_NIC_FLAG_STOPPING 0x00000008U #define AQ_NIC_FLAG_RESETTING 0x00000010U #define AQ_NIC_FLAG_CLOSING 0x00000020U +/* From aq_vec_start() completion in aq_nic_start() to aq_nic_stop() */ +#define AQ_NIC_FLAG_DPATH_UP 0x00000040U #define AQ_NIC_PTP_DPATH_UP 0x02000000U #define AQ_NIC_LINK_DOWN 0x04000000U #define AQ_NIC_FLAG_ERR_UNPLUG 0x40000000U diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 442bbd6d12809..3e514e0e31ab8 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -775,6 +775,7 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; + bool no_refclk_gating; void __iomem *intr2axi; /* adopt_link: this port's */ u8 adopted_bus; /* adopt_link: the secondary bus */ unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ @@ -3314,6 +3315,33 @@ static int apple_pcie_t6030_link_port_dart(struct apple_pcie_port *port) return ret; } +static void apple_pcie_port_enable_cg(struct apple_pcie *pcie, + struct apple_pcie_port *port) +{ + if (pcie->hw->retain_clocks) + return; + + if (port->no_refclk_gating) { + if (pcie->hw->port_refclk) + rmw_set(PORT_REFCLK_CGDIS, + port->base + pcie->hw->port_refclk); + else if (port->phy) + rmw_clear(PHY_LANE_CFG_REFCLKCGEN, + port->phy + PHY_LANE_CFG); + } else { + if (pcie->hw->port_refclk) + rmw_clear(PORT_REFCLK_CGDIS, + port->base + pcie->hw->port_refclk); + else if (port->phy) + rmw_set(PHY_LANE_CFG_REFCLKCGEN, + port->phy + PHY_LANE_CFG); + } + + /* PCIe-C APPCLK state is part of the m1n1 handoff. */ + if (!pcie->hw->tunneled) + rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); +} + static int apple_pcie_setup_port(struct apple_pcie *pcie, struct device_node *np) { @@ -3344,6 +3372,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, port->idx = idx >> 11; port->pcie = pcie; port->np = of_node_get(np); + port->no_refclk_gating = of_property_read_bool(np, "apple,no-refclk-gating"); raw_spin_lock_init(&port->lock); raw_spin_lock_init(&port->irq_lock); @@ -3489,18 +3518,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, } } - if (!pcie->hw->retain_clocks) { - if (pcie->hw->port_refclk) - rmw_clear(PORT_REFCLK_CGDIS, - port->base + pcie->hw->port_refclk); - else if (port->phy) - rmw_set(PHY_LANE_CFG_REFCLKCGEN, - port->phy + PHY_LANE_CFG); - - /* PCIe-C APPCLK state is part of the m1n1 handoff. */ - if (!pcie->hw->tunneled) - rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); - } + apple_pcie_port_enable_cg(pcie, port); ret = apple_pcie_port_setup_irq(port); if (ret) @@ -9927,15 +9945,15 @@ static void apple_pcie_hib_rid2sid(struct apple_pcie *pcie, struct apple_pcie_po mutex_unlock(&pcie->lock); } -/* Once its PHY is ready: clock gating, interrupts and RID-to-SID map, then training. */ +/* Once its PHY is ready: keep clocks un-gated for training, restore IRQs and RID2SID, train. */ static int apple_pcie_hib_port_start(struct apple_pcie *pcie, struct apple_pcie_port *port) { if (!pcie->hw->retain_clocks) { if (pcie->hw->port_refclk) - rmw_clear(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk); + rmw_set(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk); else if (port->phy) - rmw_set(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG); - rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); + rmw_clear(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG); + rmw_set(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); } /* All port interrupts masked and cleared, MSI routing as at probe. */ apple_pcie_tunnel_restore_irq_hw(port); @@ -9964,6 +9982,7 @@ static int apple_pcie_hib_port_trained(struct apple_pcie *pcie, struct apple_pci apple_pcie_port_readl(port, PORT_STATUS), stat); return ret; } + apple_pcie_port_enable_cg(pcie, port); apple_pcie_port_writel(port, BIT(PORT_INT_LINK_UP), PORT_INTSTAT); apple_pcie_port_writel(port, port->saved_intmask, PORT_INTMSK); return 0; @@ -10076,6 +10095,7 @@ static void apple_pcie_hib_ports_phased(struct apple_pcie *pcie) apple_pcie_hib_port_failed(pcie, port, -ETIMEDOUT); continue; } + apple_pcie_port_enable_cg(pcie, port); port->hib_retrained = true; } /* 100 ms after the links before configuration requests (PCIe r5.0, 6.6.1). */ diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 71422a742f4ab..ea0124f884ec3 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -2288,8 +2288,9 @@ static void __init gate_t6041_internal(void) ret = -EINVAL; nodes[T6041_DISPLAY] = of_find_node_by_path("disp0"); nodes[T6041_PIODMA] = of_get_child_by_name(nodes[T6041_DCP], "piodma"); + /* A Mac with no panel (the J575c) describes none: the DCP then runs without one. */ nodes[T6041_PANEL] = of_get_child_by_name(nodes[T6041_DCP], "panel"); - if (!nodes[T6041_DISPLAY] || !nodes[T6041_PIODMA] || !nodes[T6041_PANEL] || + if (!nodes[T6041_DISPLAY] || !nodes[T6041_PIODMA] || !of_device_is_compatible(nodes[T6041_DISPLAY], gate_soc->display_compat) || !gate_marked(nodes[T6041_DCP]) || !gate_marked(nodes[T6041_DISPLAY]) || !gate_marked(nodes[T6041_PIODMA])) @@ -2319,7 +2320,7 @@ static void __init gate_t6041_internal(void) goto out; for (i = 0; i < ARRAY_SIZE(t6041_enable); i++) { - if (!gate_disabled(nodes[t6041_enable[i]])) { + if (nodes[t6041_enable[i]] && !gate_disabled(nodes[t6041_enable[i]])) { ret = -EBUSY; goto out; } @@ -2338,8 +2339,9 @@ static void __init gate_t6041_internal(void) of_changeset_init(&t6041_gate); for (i = 0; i < ARRAY_SIZE(t6041_enable) && !ret; i++) - ret = of_changeset_update_prop_string(&t6041_gate, nodes[t6041_enable[i]], - "status", "okay"); + if (nodes[t6041_enable[i]]) + ret = of_changeset_update_prop_string(&t6041_gate, nodes[t6041_enable[i]], + "status", "okay"); if (!ret && gate_disabled(nodes[T6041_PIODMA])) ret = of_changeset_update_prop_string(&t6041_gate, nodes[T6041_PIODMA], "status", "okay"); diff --git a/drivers/soc/apple/t6041-sleep.c b/drivers/soc/apple/t6041-sleep.c index a531e13d64698..eef193c53e984 100644 --- a/drivers/soc/apple/t6041-sleep.c +++ b/drivers/soc/apple/t6041-sleep.c @@ -100,6 +100,7 @@ #define APCIE_PORT_PERST_GUARD 0x13c #define APCIE_PORT_LINKSTS 0x208 #define APCIE_PORT_LINKSTS_UP BIT(0) +#define APCIE_PORT_LINKSTS_L2 BIT(6) #define APCIE_PORT_APPCLK 0x800 #define APCIE_PORT_APPCLK_EN BIT(0) #define APCIE_PORT_APPCLK_CGDIS BIT(8) @@ -113,8 +114,9 @@ #define APCIE_PHY_RESET BIT(4) #define APCIE_PHY_EN0 BIT(9) #define APCIE_PHY_EN1 BIT(10) -#define APCIE_PHY_LINK BIT(31) +#define APCIE_PHY_REFCLKCGEN (BIT(30) | BIT(31)) #define APCIE_PORT_STOP_US 5000 +#define APCIE_PORT_L2_WAIT_US 50000 #define APCIE_PERST_HOLD_US 1000 #define GPIO_PIN_DATA BIT(0) @@ -745,6 +747,10 @@ static void t6041_gp_ports_stop(struct t6041_sleep *s) !(v & APCIE_PORT_L2_BUSY), APCIE_PORT_STOP_US)) s->gp_stop_late |= BIT(i); + if (t6041_poll_until_us(port + APCIE_PORT_LINKSTS, v, + v & APCIE_PORT_LINKSTS_L2, + APCIE_PORT_L2_WAIT_US)) + s->gp_stop_late |= BIT(i); } if (s->gp_perst[i] >= 0) { void __iomem *reg = s->gpio + 4 * s->gp_perst[i]; @@ -756,7 +762,7 @@ static void t6041_gp_ports_stop(struct t6041_sleep *s) if (!test_bit(s->gp_perst[i], s->gpio_skip)) s->gpio_pre[s->gp_perst[i]] = v; } - writel(readl(phy) & ~APCIE_PHY_LINK, phy); + writel(readl(phy) & ~APCIE_PHY_REFCLKCGEN, phy); t6041_spin_us(APCIE_PERST_HOLD_US); writel(readl(port + APCIE_PORT_PERST_GUARD) | BIT(8), port + APCIE_PORT_PERST_GUARD); diff --git a/tools/asahi/afk-compact-start-tests.py b/tools/asahi/afk-compact-start-tests.py index 373cb1f095ed3..4022e01fb3812 100755 --- a/tools/asahi/afk-compact-start-tests.py +++ b/tools/asahi/afk-compact-start-tests.py @@ -255,6 +255,7 @@ def function(text, name): struct dptx_port dptxport[2]; struct dcp_desktop_state *desktop; bool has_panel; + bool desktop_external; }; struct apple_dcp_afkep { @@ -282,6 +283,11 @@ def function(text, name): return dcp->has_panel; } +static bool dcp_desktop_external(struct apple_dcp *dcp) +{ + return dcp->desktop_external; +} + static bool dcp_fw_is_14_7(const struct apple_dcp *dcp) { (void)dcp; diff --git a/tools/asahi/dcpext26-retrain-tests.py b/tools/asahi/dcpext26-retrain-tests.py index f4e8e784c2e81..d24c8940e684d 100644 --- a/tools/asahi/dcpext26-retrain-tests.py +++ b/tools/asahi/dcpext26-retrain-tests.py @@ -13,7 +13,7 @@ body = s[a:b] if '--negative-control' in sys.argv: a = body.index('\t} else if (dcp_is_ext26(dcp) && crtc && crtc->state &&') - b = body.index('\t} else if (dcp_t6040_relinks() && crtc && crtc->state &&', a) + b = body.index('\t} else if (dcp_t6040_relinks(dcp) && crtc && crtc->state &&', a) body = body[:a] + body[b:] pre = r''' @@ -46,7 +46,7 @@ #define DRM_MODESET_LOCK_ALL_END(dev, ctx, ret) } while (0) static bool dcp_is_ext26(struct apple_dcp *d) { return d->native; } static bool dcp_has_mode(struct apple_dcp *d, const struct mode *m) { return d->admitted && m->id == 1; } -static bool dcp_t6040_relinks(void) { return t604x; } +static bool dcp_t6040_relinks(struct apple_dcp *d) { return t604x; } static bool dcp_mode_settable(struct apple_dcp *d, const struct mode *m) { return !unlisted; } static bool dcp_typec_follows_crtc(struct apple_dcp *d) { return follows; } static bool dcp_crtc_lost_route(struct drm_crtc *c, struct apple_connector *p) { return lost; }