diff --git a/drivers/gpu/drm/apple/iomfb_iboot.c b/drivers/gpu/drm/apple/iomfb_iboot.c index 757b122dc8e42..da23461b32f1e 100644 --- a/drivers/gpu/drm/apple/iomfb_iboot.c +++ b/drivers/gpu/drm/apple/iomfb_iboot.c @@ -135,6 +135,27 @@ static const struct apple_rtkit_ops dcp_iboot_rtkit_ops = { .syslog_is_debug = dcp_iboot_rtk_syslog_debug, }; +/* + * Nothing scans out the bootloader's framebuffers while the main DCP stays + * off: drop the simpledrm devices on them, outputs that would show nothing. + * This detaches a simpledrm that is bound already, as the built-in one is + * long before this probe; one loaded later would bind again. + */ +static void dcp_iboot_drop_boot_fbs(void) +{ + struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); + + for_each_child_of_node_scoped(chosen, np) { + struct resource res; + + if (!of_device_is_compatible(np, "simple-framebuffer") || + of_address_to_resource(np, 0, &res)) + continue; + aperture_remove_conflicting_devices(res.start, resource_size(&res), + dcp_iboot_driver_name()); + } +} + static bool dcp_iboot_handoff_quiesced(struct dcp_iboot *ib) { struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); @@ -708,17 +729,23 @@ static int dcp_iboot_start(struct dcp_iboot *ib) } /* - * Without a USB-C display the bootloader drives HDMI from the main DCP - * (source 0) and never starts DCPEXT0. hdmi_np: DCPEXT0's node, which - * describes the HDMI PHY. + * hdmi_np: DCPEXT0's node, which describes the HDMI PHY; its source select + * names the DCP driving HDMI (0 the main DCP, 1 DCPEXT0). On the J873g, + * iBoot lights only a monitor on the back-right port, through the main DCP, + * and leaves HDMI to the kernel even when HDMI is the only display. A + * source a bootloader did set is still adopted. */ int dcp_iboot_probe(struct apple_dcp *dcp) { struct device *dev = dcp->dev; + /* Read by whichever DCP probes first, before any DCP drives a port. */ + int boot_link = t8152_atc_boot_link(dev); struct device_node *hdmi_np __free(device_node) = t8152_hdmi_node(); int source = hdmi_np ? t8152_hdmi_source(hdmi_np) : -ENODEV; struct t8152_display *disp; struct dcp_iboot *ib; + u32 dp_source = 0; + bool main_dcp; u32 live; int ret; @@ -729,6 +756,22 @@ int dcp_iboot_probe(struct apple_dcp *dcp) return -ENODEV; } + /* + * A main DCP that the bootloader left without a display cannot power + * one: its SET_POWER never completes, on HDMI or USB-C. It has one + * when it drives HDMI or the bootloader's link on a USB-C port; none + * when iBoot found no monitor on back-right, with HDMI alone too. Then + * leave its outputs to the DCPEXTs, which start cold, and the shared + * HDMI port with them. If the ports could not be read, bind as before. + */ + of_property_read_u32(dev->of_node, "apple,dp-source", &dp_source); + main_dcp = dev->of_node != hdmi_np && !dp_source; + if (main_dcp && source != 0 && boot_link == 0) { + dcp_iboot_drop_boot_fbs(); + dev_info(dev, "no display from the bootloader: main DCP off, the DCPEXTs drive the outputs\n"); + return -ENODEV; + } + /* * The bootloader's AFK endpoint hand-off: without it there is no * telling whether an endpoint is live, and an INIT on a live one diff --git a/drivers/gpu/drm/apple/t8152_atc.c b/drivers/gpu/drm/apple/t8152_atc.c index ce4b6a84602de..633bfd9d02d0c 100644 --- a/drivers/gpu/drm/apple/t8152_atc.c +++ b/drivers/gpu/drm/apple/t8152_atc.c @@ -84,6 +84,9 @@ struct t8152_atc { /* J873 has one display crossbar. Claims outlive firmware PHY power cycles. */ static DEFINE_MUTEX(atc_owner_lock); static struct device *atc_owner[4]; +/* The bootloader's link from the main DCP, read once: t8152_atc_boot_link(). */ +static bool atc_boot_read; +static int atc_boot_link; /* All three DCPs borrow the same AP AUX controller for EDID reads. */ static DEFINE_MUTEX(atc_aux_lock); @@ -785,6 +788,27 @@ static void __iomem *atc_map(struct t8152_display *disp, struct device_node *np, return devm_ioremap(disp->dev, res.start, resource_size(&res)); } +/* + * The PHY block hangs the bus while it is power-gated: look at it only with + * its DP dependencies and the common PSD up. + */ +static bool atc_powered(void __iomem *ps, void __iomem *psd) +{ + return (readl(ps) & 0xf0) == 0xf0 && !(readl(psd + ATC_PSD_STATE) & 7); +} + +/* The crossbar routes the port from the DCP with this dp-source. */ +static bool atc_routed(void __iomem *base, u32 dp_source) +{ + return ((readl(base + ATC_XBAR + 0x44) >> 20) & 0xf) == dp_source * 2; +} + +/* Common block out of reset and AUX up, as the bootloader leaves a link. */ +static bool atc_link_up(u32 cfg) +{ + return (cfg & 0x1f) == 0x1b; +} + static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, struct device_node *np, void __iomem *dp_clock) { @@ -817,23 +841,15 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, port->tunable_len[1] /= sizeof(__be32); atc->nports++; - /* - * The PHY block hangs the bus while it is power-gated: look at it only - * with its DP dependencies and the common PSD up. - */ - if ((readl(port->ps) & 0xf0) != 0xf0 || - (readl(port->psd + ATC_PSD_STATE) & 7)) { + if (!atc_powered(port->ps, port->psd)) { dev_info(disp->dev, "ATC%u: powered down\n", port->index); return 0; } /* A different DCP may already be driving this port. */ - if (atc_owner[port->index] || - ((readl(port->base + ATC_XBAR + 0x44) >> 20) & 0xf) != - disp->dp_source * 2) + if (atc_owner[port->index] || !atc_routed(port->base, disp->dp_source)) return 0; - /* Common block out of reset and AUX up, as the bootloader leaves it. */ cfg = readl(port->base + ATC_CFG); - port->active = (cfg & 0x1f) == 0x1b; + port->active = atc_link_up(cfg); if ((readl(port->base + 0x4c) & 0x1f) == 0x10 || (readl(port->base + 0x4c) & 0x1f) == 0x11) { port->lanes = 2; @@ -857,6 +873,67 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, return 0; } +static void __iomem *atc_iomap(struct device_node *np, const char *name) +{ + int i = of_property_match_string(np, "reg-names", name); + + return i < 0 ? NULL : of_iomap(np, i); +} + +/* 1 with a bootloader link from this dp-source, 0 without, or an error. */ +static int atc_port_boot_link(struct device_node *np, u32 dp_source) +{ + void __iomem *base = atc_iomap(np, "atc"); + void __iomem *ps = atc_iomap(np, "atc-ps"); + void __iomem *psd = atc_iomap(np, "atc-psd"); + int ret = -ENODEV; + + /* What atc_port_init() adopts. A port in USB4 routes from no DCP. */ + if (base && ps && psd) + ret = atc_powered(ps, psd) && atc_routed(base, dp_source) && + atc_link_up(readl(base + ATC_CFG)); + if (psd) + iounmap(psd); + if (ps) + iounmap(ps); + if (base) + iounmap(base); + return ret; +} + +/* + * 1 when the bootloader left a DisplayPort link from the main DCP + * (dp-source 0) on one of the USB-C ports, 0 when every port was read and + * none has one, an error when a port could not be read. The DCPs share the + * ports (the DCPEXTs' apple,usb-c-ports name the main DCP), so the first DCP + * to probe reads them, before any DCP claims or powers one, and the others + * get its answer. + */ +int t8152_atc_boot_link(struct device *dev) +{ + struct device_node *ports __free(device_node) = + of_parse_phandle(dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: dev->of_node; + bool children = false; + + guard(mutex)(&atc_owner_lock); + if (atc_boot_read) + return atc_boot_link; + atc_boot_read = true; + atc_boot_link = 0; + for_each_child_of_node_scoped(np, child) { + if (!of_property_present(child, "apple,dfp-endpoint")) + continue; + children = true; + atc_boot_link = atc_port_boot_link(child, 0); + if (atc_boot_link) + break; + } + if (!children) + atc_boot_link = atc_port_boot_link(np, 0); + return atc_boot_link; +} + int t8152_atc_init(struct t8152_display *disp) { struct device_node *ports __free(device_node) = diff --git a/drivers/gpu/drm/apple/t8152_display.h b/drivers/gpu/drm/apple/t8152_display.h index b26baf6b04924..3e1cc9d7008b9 100644 --- a/drivers/gpu/drm/apple/t8152_display.h +++ b/drivers/gpu/drm/apple/t8152_display.h @@ -109,6 +109,7 @@ struct t8152_display { }; /* t8152_atc.c */ +int t8152_atc_boot_link(struct device *dev); int t8152_atc_init(struct t8152_display *disp); bool t8152_atc_release(struct t8152_display *disp);