diff --git a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi index 26ab30e219f12..9ff4ed911d482 100644 --- a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi @@ -1132,10 +1132,7 @@ power-domains = <&ps_venc_pipe5>, <&ps_venc_pipe4>; }; - /* - * These states serve only the ANE. They stay disabled with the ane - * node in t8112.dtsi; enable them together with it. - */ + /* These states serve only the ANE. */ ps_ane_sys_cpu: power-controller@c008 { compatible = "apple,t8112-pmgr-pwrstate", "apple,pmgr-pwrstate"; reg = <0xc008 4>; @@ -1143,7 +1140,6 @@ #reset-cells = <0>; label = "ane_sys_cpu"; power-domains = <&ps_ane_sys>; - status = "disabled"; }; ps_ane_td: power-controller@c010 { @@ -1153,7 +1149,6 @@ #reset-cells = <0>; label = "ane_td"; power-domains = <&ps_ane_sys_cpu>; - status = "disabled"; }; ps_ane_base: power-controller@c018 { @@ -1163,7 +1158,6 @@ #reset-cells = <0>; label = "ane_base"; power-domains = <&ps_ane_td>; - status = "disabled"; }; ps_ane_set1: power-controller@c020 { @@ -1173,7 +1167,6 @@ #reset-cells = <0>; label = "ane_set1"; power-domains = <&ps_ane_base>; - status = "disabled"; }; ps_ane_set2: power-controller@c028 { @@ -1183,7 +1176,6 @@ #reset-cells = <0>; label = "ane_set2"; power-domains = <&ps_ane_set1>; - status = "disabled"; }; ps_ane_set3: power-controller@c030 { @@ -1193,7 +1185,6 @@ #reset-cells = <0>; label = "ane_set3"; power-domains = <&ps_ane_set2>; - status = "disabled"; }; ps_ane_set4: power-controller@c038 { @@ -1203,7 +1194,6 @@ #reset-cells = <0>; label = "ane_set4"; power-domains = <&ps_ane_set3>; - status = "disabled"; }; ps_disp0_cpu0: power-controller@10000 { diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index e19ef0b98292a..23369ae0246a2 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1788,7 +1788,6 @@ interrupts = ; interrupt-names = "recv-not-empty"; #mbox-cells = <0>; - status = "disabled"; }; ane_dart0: iommu@26b800000 { @@ -1798,7 +1797,6 @@ interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_ane_sys>; - status = "disabled"; }; ane_dart1: iommu@26b810000 { @@ -1808,7 +1806,6 @@ interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_ane_sys>; - status = "disabled"; }; ane_dart2: iommu@26b820000 { @@ -1818,7 +1815,6 @@ interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_ane_sys>; - status = "disabled"; }; ane: ane@26a000000 { @@ -1836,7 +1832,6 @@ <&ps_ane_base>, <&ps_ane_set1>, <&ps_ane_set2>, <&ps_ane_set3>, <&ps_ane_set4>; mboxes = <&ane_mbox>; - status = "disabled"; }; dispext0_dart: iommu@271304000 { diff --git a/drivers/accel/ane/ane_t6021.h b/drivers/accel/ane/ane_t6021.h index ce134209c5e06..bf6d0f3e44202 100644 --- a/drivers/accel/ane/ane_t6021.h +++ b/drivers/accel/ane/ane_t6021.h @@ -754,8 +754,9 @@ struct ane_asc_tunables; * for this SoC (T6021 only), so fw_alias_reserved=1 may map it; the * other SoCs always run the firmware from driver-owned memory. * ps_cpu_off: the ANE CPU ps word in the DT "pmgr" window (probe guard). - * pwgate_off: the PWGATE word in the DT "set" window, checked - * open before any engine read; 0 = not checked. + * pwgate_off: the power gate word in the DT "set" window. The driver + * opens it before ane_sys_cpu powers on, closes it after that state + * powers off, and checks it open before any engine read; 0 = no gate. * pmu_pa: the page of the seven ANE ps words; the firmware's power * service writes them through its DART at IOVA == PA. ps_off: the * first of the seven in that page. diff --git a/drivers/accel/ane/ane_t6021_fwload.c b/drivers/accel/ane/ane_t6021_fwload.c index 4dc4ce27b1674..f39e4b7e8b05c 100644 --- a/drivers/accel/ane/ane_t6021_fwload.c +++ b/drivers/accel/ane/ane_t6021_fwload.c @@ -533,11 +533,20 @@ int ane_t6021_fwload_check(struct device *dev) if (!fw_load) return 0; - ret = request_firmware(&fw, img->name, dev); + /* + * The image is installed on the machine itself from Apple's files, so + * a missing file is the normal state of a system that has not fetched + * it yet: say so once and leave the ANE off. Other errors are errors. + */ + ret = firmware_request_nowarn(&fw, img->name, dev); + if (ret == -ENOENT) { + dev_info(dev, + "firmware %s is not installed, so the ANE stays off; install it with omarchy-ane-firmware-fetch\n", + img->name); + return -ENODEV; + } if (ret) { - dev_err(dev, - "cannot load firmware %s: %d; install it with omarchy-ane-firmware-fetch (or equivalent for your distribution)\n", - img->name, ret); + dev_err(dev, "cannot load firmware %s: %d\n", img->name, ret); return ret; } diff --git a/drivers/accel/ane/ane_t6021_rtclient_main.c b/drivers/accel/ane/ane_t6021_rtclient_main.c index 5f1e5e66bd22d..77695f89c9808 100644 --- a/drivers/accel/ane/ane_t6021_rtclient_main.c +++ b/drivers/accel/ane/ane_t6021_rtclient_main.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -2063,6 +2064,13 @@ struct ane_rtclient_pd { struct device **pd_dev; struct device_link **pd_link; int count; + + /* T8112 power gate, kept in step with power-domains[0]. */ + struct notifier_block pwgate_nb; + void __iomem *pwgate_base; + void __iomem *pwgate; + bool pwgate_nb_added; + bool pwgate_opened; }; static LIST_HEAD(ane_rtclient_pd_list); @@ -2074,11 +2082,103 @@ static DEFINE_MUTEX(ane_rtclient_probe_guard_lock); static void ane_rtclient_pd_free(struct ane_rtclient_pd *pd) { list_del(&pd->list); + if (pd->pwgate_base) + iounmap(pd->pwgate_base); kfree(pd->pd_dev); kfree(pd->pd_link); kfree(pd); } +/* + * T8112 power gate. A word in the "set" window gates the ANE: bits 29:28 + * set (the word reads 0x30000000) is closed, both clear is open. It must be + * open before the ANE CPU power state (ane_sys_cpu) turns on and is closed + * again after that state turns off, with ane_sys, the parent, on both + * times. power-domains[0] is ane_sys_cpu, and genpd calls this notifier + * after ane_sys is on and before ane_sys_cpu is written (PRE_ON), and + * after ane_sys_cpu is off and before ane_sys goes off (OFF), which is that + * order. Only the two known values are written. Any other word fails the + * power-up without a write. + */ +#define ANE_PWGATE_CLOSED GENMASK(29, 28) +#define ANE_PWGATE_POLL_US 10 +#define ANE_PWGATE_TIMEOUT_US 100000 + +static int ane_rtclient_pwgate_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct ane_rtclient_pd *pd = + container_of(nb, struct ane_rtclient_pd, pwgate_nb); + u32 gate; + int ret; + + switch (action) { + case GENPD_NOTIFY_PRE_ON: + gate = readl(pd->pwgate); + if (!(gate & ANE_PWGATE_CLOSED)) + return NOTIFY_OK; + if (gate != ANE_PWGATE_CLOSED) { + dev_err(pd->dev, "power gate word %#x is not a known state\n", + gate); + return notifier_from_errno(-EIO); + } + writel(0, pd->pwgate); + ret = readl_poll_timeout_atomic(pd->pwgate, gate, + !(gate & ANE_PWGATE_CLOSED), + ANE_PWGATE_POLL_US, + ANE_PWGATE_TIMEOUT_US); + if (ret) { + writel(ANE_PWGATE_CLOSED, pd->pwgate); + dev_err(pd->dev, "power gate did not open (word %#x)\n", + gate); + return notifier_from_errno(ret); + } + pd->pwgate_opened = true; + return NOTIFY_OK; + case GENPD_NOTIFY_OFF: + if (!pd->pwgate_opened) + return NOTIFY_OK; + pd->pwgate_opened = false; + writel(ANE_PWGATE_CLOSED, pd->pwgate); + ret = readl_poll_timeout_atomic(pd->pwgate, gate, + (gate & ANE_PWGATE_CLOSED) == + ANE_PWGATE_CLOSED, + ANE_PWGATE_POLL_US, + ANE_PWGATE_TIMEOUT_US); + if (ret) + dev_warn(pd->dev, "power gate did not close (word %#x)\n", + gate); + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +/* + * Register the power gate notifier on power-domains[0] before its device + * link is created: the link resumes the domain at once. + */ +static int ane_rtclient_pwgate_add(struct ane_rtclient *ane, + struct ane_rtclient_pd *pd) +{ + int ret; + + if (!ane->soc->pwgate_off || pd->pwgate_nb_added) + return 0; + if (!pd->pwgate_base) { + pd->pwgate_base = of_iomap(ane->dev->of_node, 2); + if (!pd->pwgate_base) + return -ENOMEM; + pd->pwgate = pd->pwgate_base + ane->soc->pwgate_off; + } + pd->pwgate_nb.notifier_call = ane_rtclient_pwgate_notify; + ret = dev_pm_genpd_add_notifier(pd->pd_dev[0], &pd->pwgate_nb); + if (ret) + return ret; + pd->pwgate_nb_added = true; + return 0; +} + static int ane_rtclient_attach_genpd(struct ane_rtclient *ane) { struct device *dev = ane->dev; @@ -2127,6 +2227,11 @@ static int ane_rtclient_attach_genpd(struct ane_rtclient *ane) goto out; } } + if (i == 0) { + err = ane_rtclient_pwgate_add(ane, pd); + if (err) + goto out; + } if (!pd->pd_link[i]) { if (!ane_rtclient_pinned) { if (!try_module_get(THIS_MODULE)) { @@ -2171,6 +2276,15 @@ static void ane_rtclient_detach_genpd(struct device *dev) for (i = count - 1; i >= 0; i--) { if (pd->pd_link[i]) device_link_del(pd->pd_link[i]); + /* + * genpd keeps a notifier past detach, so drop it first. + * The domain may then go off with the gate open, the + * state between the two power-up steps. + */ + if (i == 0 && pd->pwgate_nb_added) { + dev_pm_genpd_remove_notifier(pd->pd_dev[0]); + pd->pwgate_nb_added = false; + } if (pd->pd_dev[i]) dev_pm_domain_detach(pd->pd_dev[i], true); } @@ -2282,9 +2396,10 @@ static int ane_rtclient_probe_inner(struct platform_device *pdev, pm_runtime_disable(dev); return -EPROBE_DEFER; } - /* T8112: macOS (type 0x70) opens PWGATE (bits 29:28 = 0) before - * the ps words. This driver only reads it: an engine read behind a - * closed gate is untested, so it refuses first. + /* T8112: the power gate notifier opened the gate before ane_sys_cpu + * turned on. A gate that still reads closed means the state was + * already on without it (no power-up ran), so refuse before any + * engine read. */ if (ane->soc->pwgate_off) { void __iomem *set = devm_of_iomap(dev, dev->of_node, 2, NULL);