diff --git a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml index 2bff1703d7c94..ada449e9eb429 100644 --- a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml +++ b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml @@ -37,6 +37,8 @@ properties: minItems: 1 maxItems: 8 + dma-noncoherent: true + memory-region: minItems: 1 maxItems: 64 diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 879b2676783aa..f065f47c51678 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -23,6 +23,13 @@ model = "Apple Mac mini (M4, 2024)"; chassis-type = "desktop"; + aliases { + /* The loader and the display DART find the PIODMA stream by it. */ + disp0-piodma = &disp0_piodma; + /* Select the main DCP front end for the 26.6.2 boot framebuffer. */ + disp0-fe = &ps_disp_fe; + }; + /* * The speaker amp's shutdown line (SDZ, AP GPIO 15, the ADT * function-reset; low = shutdown). @@ -35,6 +42,62 @@ }; }; +&dcp_mbox { + /* iBoot leaves DISP_CPU in auto mode; Linux must not switch it. */ + /delete-property/ power-domains; +}; + +&dcp_dart { + power-domains = <&ps_disp_cpu>; +}; + +&disp0_dart { + power-domains = <&ps_disp_cpu>; +}; + +&dcp { + /* iBoot leaves DISP_CPU in auto mode; Linux must not switch it. */ + /delete-property/ power-domains; + /* Its PIODMA child owns iommu-addresses entries in /reserved-memory. */ + #address-cells = <2>; + #size-cells = <2>; + apple,connector-type = "HDMI-A"; + apple,dptx-phy = <4>; + phys = <&lpdptx_phy>; + phy-names = "dp-phy"; + /* ADT dp2hdmi-gpio0: hdmi_hpd on AOP GPIO 41. */ + hdmi-hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; + hdmi-pwren-gpios = <&smc_gpio 15 GPIO_ACTIVE_HIGH>; + dp2hdmi-pwren-gpios = <&smc_gpio 26 GPIO_ACTIVE_HIGH>; +}; + +/* + * The scanout frontend has no registers. The shared tree keeps it, disabled, + * under /soc, where the loader enables it for the boards with a panel. This + * board describes it at the root because a simple-bus child needs reg. The + * disp0 alias follows the label. + */ +/delete-node/ &display; + +/ { + display: display-subsystem { + compatible = "apple,t8132-display-subsystem", "apple,t8132-display-diagnostics"; + iommus = <&disp0_dart 0>; + dma-noncoherent; + status = "disabled"; + }; +}; + +/* + * Both retained display DARTs sit in DISP_CPU. iBoot leaves this + * state under firmware control and Linux must not touch its register. + * Give the DARTs a logical, always-on domain without a consumer switch. + */ +&ps_disp_cpu { + apple,firmware-owned; + status = "okay"; +}; + /* * iBoot scans out through dispext0 to the HDMI port (dptx-phy and a * DP-to-HDMI converter at i2c0 0x08, hot-plug on AOP GPIO 41): keep the @@ -56,7 +119,8 @@ * idle, and enables the display subsystem on iBoot's framebuffer; the display * gate (drivers/soc/apple/display-gate.c) then enables the admitted external * chains and points the display subsystem at their scanout DARTs. On the M4 - * 26.6.2 firmware path none of it is enabled from here. + * 26.6.2 firmware path the gate can instead enable the shared physical PHY + * for the main DCP. */ / { reserved-memory { diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 08c173fc6e8e0..c83bab8d35b64 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -2197,6 +2197,8 @@ static int apple_probe_typec_ports(struct drm_device *drm, return 0; } +static bool apple_t8132_main_external_present(void); + static int apple_get_fb_resource(struct device *dev, const char *name, struct resource *fb_r) { @@ -2216,7 +2218,9 @@ static int apple_get_fb_resource(struct device *dev, const char *name, goto err; } - if (!of_device_is_compatible(node, "framebuffer")) { + if (!of_device_is_compatible(node, "framebuffer") && + !(apple_t8132_main_external_present() && + of_device_is_compatible(node, "apple,asc-mem"))) { dev_err(dev, "reserved-memory node '%s' is incompatible\n", node->full_name); goto err; @@ -2279,6 +2283,16 @@ static const struct of_device_id apple_dcp_id_tbl[] = { {}, }; +static bool apple_t8132_main_external_present(void) +{ + struct device_node *np = of_find_compatible_node(NULL, NULL, + "apple,t8132-dcp"); + bool present = dcp_t8132_main_external(np) && of_device_is_available(np); + + of_node_put(np); + return present; +} + /* * A supported firmware-described external provider participates in component * matching. A T6030 external display processor is a pipe of this DRM device @@ -2287,7 +2301,7 @@ static const struct of_device_id apple_dcp_id_tbl[] = { */ static bool apple_dcp_usable(struct device_node *np) { - return of_device_is_available(np) && + return of_device_is_available(np) && !dcp_t8132_main_external(np) && (!of_device_is_compatible(np, "apple,t6030-dcpext") || dcp_t6030_ext_native(np)) && (!of_device_is_compatible(np, "apple,t8140-dcpext") || @@ -2372,6 +2386,15 @@ static void apple_dcp_start_fn(struct work_struct *work) w->ret = dcp_start(w->dcp); } +static bool apple_drm_has_output(struct drm_device *drm) +{ + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, drm) + return true; + return false; +} + static int apple_drm_init_dcp(struct device *dev) { struct apple_drm_private *apple = dev_get_drvdata(dev); @@ -2442,8 +2465,17 @@ static int apple_drm_init_dcp(struct device *dev) } } - if (num_dcp < 1) - return -ENODEV; + if (num_dcp < 1) { + if (!apple_t8132_main_external_present()) + return -ENODEV; + ret = t8132_ext_drm_init(&apple->drm); + if (ret) + dev_warn(dev, "T8132 main external output was not registered: %d\n", + ret); + else if (!apple_drm_has_output(&apple->drm)) + ret = -ENODEV; + return ret; + } /* * Build the Type-C port connectors before starting any pipeline: a @@ -2596,9 +2628,11 @@ static int apple_drm_init(struct device *dev) */ apple->drm.mode_config.prefer_shadow = true; - ret = component_bind_all(dev, apple); - if (ret) - return ret; + if (!apple_t8132_main_external_present()) { + ret = component_bind_all(dev, apple); + if (ret) + return ret; + } ret = apple_drm_init_dcp(dev); if (ret) @@ -2726,7 +2760,8 @@ static int apple_drm_init(struct device *dev) disable_work_sync(&apple->notch_console); t8132_ext_drm_fini(&apple->drm); apple_drm_quiesce_connectors(&apple->drm); - component_unbind_all(dev, NULL); + if (!apple_t8132_main_external_present()) + component_unbind_all(dev, NULL); dcp_unlink(&apple->drm); return ret; } @@ -2758,7 +2793,8 @@ static void apple_drm_uninit(struct device *dev) disable_work_sync(&apple->notch_hotplug); disable_work_sync(&apple->notch_console); - component_unbind_all(dev, NULL); + if (!apple_t8132_main_external_present()) + component_unbind_all(dev, NULL); dcp_unlink(&apple->drm); dev_set_drvdata(dev, NULL); @@ -2834,10 +2870,14 @@ static int apple_platform_probe(struct platform_device *pdev) /* add DCP components, handle less than 1 as probe error */ num_dcp = add_dcp_components(mdev, &match); - if (num_dcp < 1) - return -ENODEV; - - ret = component_master_add_with_match(mdev, &apple_drm_ops, match); + if (num_dcp < 1) { + if (!apple_t8132_main_external_present()) + return -ENODEV; + ret = apple_drm_init(mdev); + } else { + ret = component_master_add_with_match(mdev, &apple_drm_ops, + match); + } if (ret) return ret; @@ -2853,7 +2893,10 @@ static int apple_platform_probe(struct platform_device *pdev) static void apple_platform_remove(struct platform_device *pdev) { pm_vt_switch_unregister(&pdev->dev); - component_master_del(&pdev->dev, &apple_drm_ops); + if (apple_t8132_main_external_present()) + apple_drm_uninit(&pdev->dev); + else + component_master_del(&pdev->dev, &apple_drm_ops); } static const struct of_device_id of_match[] = { diff --git a/drivers/gpu/drm/apple/dcp-m4-profile.h b/drivers/gpu/drm/apple/dcp-m4-profile.h index 438f734f87d06..54952950e1941 100644 --- a/drivers/gpu/drm/apple/dcp-m4-profile.h +++ b/drivers/gpu/drm/apple/dcp-m4-profile.h @@ -58,6 +58,20 @@ static const struct dcp_m4_profile dcp_m4_profile_j713 = { .timing = dcp_m4_timing_j713, .timing_elements = 1, }; +/* The J773g uses the shared firmware ABI for an external output, not a panel. */ +static const struct dcp_m4_profile dcp_m4_profile_j773g = { + .name = "J773g", .machine = "apple,j773g", + .panel_width = 2560, .panel_height = 1664, .notch_rows = 64, + .boot_stride = 10240, + .swap_size = 0x1bd8, .swap_surface = 0x588, .swap_dva = 0xe38, + .swap_nullable = 0x1bcb, .swap_tail = 0x1bd6, .swap_nits = 0x35e, + .swap_intent = 0x17c, + .disabled_color = 0xff000000, + .done_method = 590, .done_size = 0x730, .open_method = 457, + .brightness_max = 500, .brightness_default = 120, + .width_mm = 0, .height_mm = 0, +}; + /* The J715's panel timing, as macOS reports it (TimingElements, ID 2). */ static const u32 dcp_m4_timing_j715[2][8] = { { 2880, 2960, 8, 32, 40, 7710975, 1, 0 }, @@ -106,6 +120,7 @@ static const struct dcp_m4_profile dcp_m4_profile_j604 = { static const struct dcp_m4_profile *const dcp_m4_profiles[] = { &dcp_m4_profile_j713, + &dcp_m4_profile_j773g, &dcp_m4_profile_j715, &dcp_m4_profile_j604, }; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index a3437f7bd462b..5f2f927817902 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7253,6 +7253,13 @@ static int dcp_connector_type_from_dt(struct device_node *np) return DRM_MODE_CONNECTOR_Unknown; } +/* A T8132 main DCP can serve a fixed external output instead of a panel. */ +bool dcp_t8132_main_external(struct device_node *np) +{ + return np && of_device_is_compatible(np, "apple,t8132-dcp") && + dcp_connector_type_from_dt(np) == DRM_MODE_CONNECTOR_HDMIA; +} + /* * The fixed route's crossbar selection and Type-C mux are taken at probe and * must be released with the device: a crossbar left selected blocks the next @@ -8455,6 +8462,69 @@ static int dcp_desktop_probe_routes(struct apple_dcp *dcp) return 0; } +/* + * A fixed HDMI main DCP reaches its sink through a T8122-style DPTX PHY and + * two converter power GPIOs. Require every resource and leave it powered for + * the retained firmware session. + */ +static int dcp_m4_hdmi_prepare(struct apple_dcp *dcp) +{ + struct device *dev = dcp->dev; + struct gpio_desc *hpd; + int hpd_level, ret; + + hpd = devm_gpiod_get_optional(dev, "hdmi-hpd", GPIOD_IN); + if (IS_ERR(hpd)) + return dev_err_probe(dev, PTR_ERR(hpd), "HDMI HPD GPIO unavailable"); + + dcp->hw.num_dptx_ports = 1; + dcp->phy = devm_phy_get(dev, "dp-phy"); + if (IS_ERR(dcp->phy)) + return dev_err_probe(dev, PTR_ERR(dcp->phy), + "HDMI DP PHY unavailable\n"); + dcp->fixed_phy = dcp->phy; + ret = phy_init(dcp->phy); + if (ret) + return dev_err_probe(dev, ret, "HDMI DP PHY init failed\n"); + ret = phy_power_on(dcp->phy); + if (ret) { + phy_exit(dcp->phy); + return dev_err_probe(dev, ret, "HDMI DP PHY power failed\n"); + } + ret = devm_add_action_or_reset(dev, dcp_desktop_phy_off, dcp->phy); + if (ret) + return ret; + + dcp->hdmi_pwren = devm_gpiod_get(dev, "hdmi-pwren", GPIOD_OUT_HIGH); + if (IS_ERR(dcp->hdmi_pwren)) + return dev_err_probe(dev, PTR_ERR(dcp->hdmi_pwren), + "HDMI power GPIO unavailable\n"); + dcp->dp2hdmi_pwren = devm_gpiod_get(dev, "dp2hdmi-pwren", GPIOD_OUT_HIGH); + if (IS_ERR(dcp->dp2hdmi_pwren)) + return dev_err_probe(dev, PTR_ERR(dcp->dp2hdmi_pwren), + "DP2HDMI power GPIO unavailable\n"); + /* + * Give a connected sink time to assert HPD after the rails turn on. + * An unplugged output can stay low indefinitely, so a timeout does + * not prevent adoption of the retained DCP session. + */ + if (hpd) { + ret = read_poll_timeout(gpiod_get_value_cansleep, hpd_level, + hpd_level != 0, 1000, 100000, false, hpd); + if (hpd_level < 0) { + dev_warn(dev, "failed to sample HDMI HPD: %d\n", hpd_level); + msleep(100); + } else if (ret) { + dev_dbg(dev, "HDMI HPD stayed low during converter startup\n"); + } + } else { + /* Older device trees do not expose HPD. Keep their settle time. */ + msleep(100); + } + dev_info(dev, "fixed HDMI PHY and converter rails prepared\n"); + return 0; +} + /* * An adopted T8132 dcpext offers its Type-C routes. It is no component of * the DRM device (its outputs are added by t8132_ext_drm.c): the routes @@ -9264,8 +9334,18 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) return ret; if (iomfb_is_m4(dcp)) { - dcp->fixed_connector_type = DRM_MODE_CONNECTOR_eDP; - dcp->connector_type = DRM_MODE_CONNECTOR_eDP; + bool main_external = dcp_t8132_main_external(dev->of_node); + + if (main_external) { + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA; + dcp->connector_type = DRM_MODE_CONNECTOR_HDMIA; + ret = dcp_m4_hdmi_prepare(dcp); + if (ret) + return ret; + } else { + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_eDP; + dcp->connector_type = DRM_MODE_CONNECTOR_eDP; + } bitmap_zero(dcp->iomfb_surfaces, DCP_MAX_PLANES); set_bit(0, dcp->iomfb_surfaces); ret = iomfb_m4_init(dcp); @@ -9275,11 +9355,20 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) * An external DCP is no component of the DRM device. Once * adoption starts, its session outlives the device. */ - if (of_device_is_compatible(dev->of_node, "apple,t8132-dcpext")) { + if (of_device_is_compatible(dev->of_node, "apple,t8132-dcpext") || + main_external) { ret = dcp_pin_live_session(dcp); if (!ret) ret = iomfb_m4_adopt_external(dcp); - if (!ret) { + if (!ret && main_external) { + ret = dcp_desktop_dptx_connect(dcp, 0); + if (ret) { + dev_warn(dev, "initial HDMI DPTX connect failed: %d\n", + ret); + ret = 0; + } + } + if (!ret && !main_external) { dcp_t8132_ext_routes(dcp); iomfb_m4_ext_idle_kick(dcp); } @@ -9850,7 +9939,8 @@ static void dcp_platform_remove(struct platform_device *pdev) if (dcp) av_audiosrv_quiesce(dcp); /* An adopted external DCP never joined the DRM device. */ - if (dcp_t8132_ext_m4_node(pdev->dev.of_node)) { + if (dcp_t8132_ext_m4_node(pdev->dev.of_node) || + dcp_t8132_main_external(pdev->dev.of_node)) { /* Enabled with its Type-C routes, see dcp_t8132_ext_routes(). */ if (dcp) { disable_delayed_work_sync(&dcp->typec_reconnect_wq); diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 4b96c3f979a65..29c3718d48e80 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -15,6 +15,7 @@ bool dcp_h17p_external_supported(struct device_node *np); bool dcp_h17p_external_ready(struct device_node *np); +bool dcp_t8132_main_external(struct device_node *np); struct apple_atomic_state { struct drm_atomic_commit base; diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index 8aa08addb6bdc..e5027a08d1aeb 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -2743,9 +2743,11 @@ int iomfb_m4_init(struct apple_dcp *owner) u32 ready = 0; int ret; /* An external DCP the boot loader handed over: same firmware, no panel. */ - bool external = of_device_is_compatible(dev->of_node, "apple,t8132-dcpext"); + bool dcpext = of_device_is_compatible(dev->of_node, "apple,t8132-dcpext"); + bool main_external = dcp_t8132_main_external(dev->of_node); + bool external = dcpext || main_external; - if (external && + if (dcpext && (of_property_read_u32(dev->of_node, "apple,t8132-dcpext-firmware-ready", &ready) || ready != 1)) return dev_err_probe(dev, -ENODEV, "external DCP not handed over\n"); @@ -2765,10 +2767,14 @@ int iomfb_m4_init(struct apple_dcp *owner) if (ret) return ret; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "coproc"); - if (!res || resource_size(res) != SZ_16K || - (external ? res->start != 0x286e00000ULL && res->start != 0x48ae00000ULL : + if (!res) + return dev_err_probe(dev, -ENODEV, "missing coproc resource\n"); + if (resource_size(res) != SZ_16K || + (dcpext ? res->start != 0x286e00000ULL && res->start != 0x48ae00000ULL : res->start != 0x30ae00000ULL)) - return -ENODEV; + return dev_err_probe(dev, -ENODEV, + "unqualified %s DCP coproc resource %pa-%pa\n", + dcpext ? "external" : "main", &res->start, &res->end); /* Resolve the fallible supplier before creating a mailbox owner. */ ret = external ? 0 : apple_pmp_j713_display_prepare(dev); if (ret) diff --git a/drivers/gpu/drm/apple/t8132_ext_drm.c b/drivers/gpu/drm/apple/t8132_ext_drm.c index 508547909f287..4555c623f6972 100644 --- a/drivers/gpu/drm/apple/t8132_ext_drm.c +++ b/drivers/gpu/drm/apple/t8132_ext_drm.c @@ -49,6 +49,7 @@ #include #include +#include "dcp.h" #include "iomfb_m4.h" #include "t8132_ext_drm.h" @@ -1145,7 +1146,8 @@ static int t8132_ext_out_init(struct drm_device *drm, struct platform_device *pd goto err_crtc; out->encoder.possible_crtcs = drm_crtc_mask(&out->crtc); ret = drm_connector_init(drm, &out->connector, &t8132_ext_connector_funcs, - DRM_MODE_CONNECTOR_DisplayPort); + dcp_t8132_main_external(pdev->dev.of_node) ? + DRM_MODE_CONNECTOR_HDMIA : DRM_MODE_CONNECTOR_DisplayPort); if (ret) goto err_encoder; drm_connector_helper_add(&out->connector, &t8132_ext_connector_helpers); @@ -1222,6 +1224,31 @@ int t8132_ext_drm_init(struct drm_device *drm) put_device(&pdev->dev); ret = ret ?: err; } + /* A main DCP can describe a fixed external output instead of a panel. */ + if (count < T8132_EXT_MAX) { + struct platform_device *pdev; + + np = of_find_compatible_node(NULL, NULL, "apple,t8132-dcp"); + if (dcp_t8132_main_external(np) && of_device_is_available(np)) { + pdev = of_find_device_by_node(np); + if (pdev) { + if (!device_is_bound(&pdev->dev)) { + ret = ret ?: -EPROBE_DEFER; + } else { + err = t8132_ext_out_init(drm, pdev, mine); + if (err) + dev_err(&pdev->dev, + "no main external DRM output: %d\n", + err); + else + count++; + ret = ret ?: err; + } + put_device(&pdev->dev); + } + } + of_node_put(np); + } if (count || ret) drm_info(drm, "%u T8132 external output(s): %d\n", count, ret); return ret; diff --git a/drivers/iommu/apple-dart-dcp-format.h b/drivers/iommu/apple-dart-dcp-format.h index 52b853b59d973..a2344756b2111 100644 --- a/drivers/iommu/apple-dart-dcp-format.h +++ b/drivers/iommu/apple-dart-dcp-format.h @@ -54,6 +54,8 @@ struct dcp_adt_instance { static const u32 dcp_adt_kinds_internal[] = {1, 0, 10, 2, 2, 2, 2}; static const u32 dcp_adt_kinds_external[] = {1, 0, 10, 2}; +/* T8132 main external DCP (iop-dcp-nub lists six segments). */ +static const u32 dcp_adt_kinds_main_external[] = {1, 0, 10, 2, 2, 2}; static const struct dcp_adt_instance dcp_adt_internal = { .dart = "dart-dcp", @@ -65,6 +67,17 @@ static const struct dcp_adt_instance dcp_adt_internal = { .num_segments = ARRAY_SIZE(dcp_adt_kinds_internal), }; +/* Main external DCP: internal node names and six firmware segments. */ +static const struct dcp_adt_instance dcp_adt_main_external = { + .dart = "dart-dcp", + .dcp = "dcp", + .nub = "iop-dcp-nub", + .disp = "dart-disp0", + .segment_names = "__TEXT;__DATA;__OS_LOG;unknown;unknown;unknown", + .kinds = dcp_adt_kinds_main_external, + .num_segments = ARRAY_SIZE(dcp_adt_kinds_main_external), +}; + /* The external DCPs run the same firmware with a single extra segment. */ static const struct dcp_adt_instance dcp_adt_external[] = { { @@ -383,10 +396,12 @@ static inline int dcp_adt_parse_instance(const void *data, size_t size, /* Parse metadata only: live MMIO, RAM exclusion and page tables remain unproven. */ static inline int dcp_adt_parse_frontend(const void *data, size_t size, + const struct dcp_adt_instance *inst, struct dcp_adt_tables *firmware, struct dcp_adt_frontend *frontend) { - int ret = dcp_adt_parse_common(data, size, &dcp_adt_internal, firmware, frontend); + int ret = dcp_adt_parse_common(data, size, inst ? inst : &dcp_adt_internal, + firmware, frontend); if (ret) return ret; diff --git a/drivers/iommu/apple-dart-dcp-shared.h b/drivers/iommu/apple-dart-dcp-shared.h index b206785cb0737..a23e148253ec1 100644 --- a/drivers/iommu/apple-dart-dcp-shared.h +++ b/drivers/iommu/apple-dart-dcp-shared.h @@ -280,7 +280,8 @@ static int __apple_dart_dcp_dispext_map(struct device *piodma, unsigned int sid, if (ret) return ret; pio = to_dart_domain(iommu_get_domain_for_dev(piodma))->dcp; - if (pio->sid != 16 || !pio->dart->dispext) + if (pio->sid != 16 || + (!pio->dart->dispext && !pio->dart->t8132_main_external)) return -ENODEV; dcp = sid ? pio : pio->dart->frontend[0]; if (!dcp) @@ -369,7 +370,8 @@ int apple_dart_dcp_dispext_stream_ok(struct device *piodma, unsigned int sid) if (!domain || domain->owner != &apple_dart_iommu_ops || (sid != 0 && sid != 16)) return -ENODEV; pio = to_dart_domain(domain)->dcp; - if (!pio || pio->sid != 16 || !pio->dart->dispext) + if (!pio || pio->sid != 16 || + (!pio->dart->dispext && !pio->dart->t8132_main_external)) return -ENODEV; dcp = sid ? pio : pio->dart->frontend[0]; if (!dcp) @@ -445,7 +447,8 @@ static void *__apple_dart_dcp_dispext_scanout_alloc(struct device *piodma, size_ if (ret) return ERR_PTR(ret); pio = to_dart_domain(iommu_get_domain_for_dev(piodma))->dcp; - if (pio->sid != 16 || !pio->dart->dispext) + if (pio->sid != 16 || + (!pio->dart->dispext && !pio->dart->t8132_main_external)) return ERR_PTR(-ENODEV); dcp = pio->dart->frontend[0]; if (!dcp) @@ -568,7 +571,8 @@ static struct apple_dart_dcp *apple_dart_dcp_dispext_pio(struct device *piodma) if (!domain || domain->owner != &apple_dart_iommu_ops) return NULL; pio = to_dart_domain(domain)->dcp; - if (!pio || pio->sid != 16 || !pio->dart->dispext) + if (!pio || pio->sid != 16 || + (!pio->dart->dispext && !pio->dart->t8132_main_external)) return NULL; return pio; } diff --git a/drivers/iommu/apple-dart-dcp.h b/drivers/iommu/apple-dart-dcp.h index 358fed1bbedfb..5c5afe2de220a 100644 --- a/drivers/iommu/apple-dart-dcp.h +++ b/drivers/iommu/apple-dart-dcp.h @@ -309,7 +309,8 @@ static int apple_dart_dcp_read_adt(struct apple_dart *dart, struct dcp_adt_table ret = dcp_adt_parse_common(data, resource_size(&res), dart->dcp_instance, tables, frontend); else - ret = frontend ? dcp_adt_parse_frontend(data, resource_size(&res), tables, + ret = frontend ? dcp_adt_parse_frontend(data, resource_size(&res), + dart->dcp_instance, tables, frontend) : dcp_adt_parse_instance(data, resource_size(&res), dart->dcp_instance, tables); @@ -413,6 +414,18 @@ static int apple_dart_dcp_arena(struct apple_dart_dcp *dcp) return slots >= DCP_DART_SCANOUT_SLOTS ? 0 : -ENOSPC; } +/* Legacy firmware trees use an underscore in the SID16 alias. */ +static struct device_node *apple_dart_frontend_node(bool piodma) +{ + struct device_node *node; + + if (!piodma) + return of_find_node_by_path("disp0"); + + node = of_find_node_by_path("disp0-piodma"); + return node ? node : of_find_node_by_path("disp0_piodma"); +} + /* * The @i-th memory-region entry of @consumer in *@node, NULL for one whose * node is disabled. A tree may carry disabled placeholders for regions only @@ -438,12 +451,13 @@ static int apple_dart_dcp_region(struct device_node *consumer, int i, static int apple_dart_dcp_leaf_regions(struct apple_dart_dcp *dcp) { struct device_node *consumer, *node; - /* An external display DART's SID16 serves its dcpext's memory. */ - const char *alias = dcp->sid == 23 || dcp->dart->dispext ? - dcp->dart->dcp_instance->dcp : dcp->sid == 0 ? "disp0" : "disp0_piodma"; int count, ret = 0; - consumer = of_find_node_by_path(alias); + /* An external display DART's SID16 serves its dcpext's memory. */ + if (dcp->sid == 23 || dcp->dart->dispext) + consumer = of_find_node_by_path(dcp->dart->dcp_instance->dcp); + else + consumer = apple_dart_frontend_node(dcp->sid != 0); if (!consumer) return -ENODEV; count = of_property_count_u32_elems(consumer, "memory-region"); @@ -779,7 +793,9 @@ static int apple_dart_frontend_validate(struct apple_dart_dcp *dcp, { struct device_node *alias; struct of_phandle_args spec; - u32 wanted = dcp->sid == 0 ? BIT(4) | BIT(6) : BIT(5); + bool main_external = dcp->dart->dcp_instance == &dcp_adt_main_external; + u32 wanted = dcp->sid == 0 ? + (main_external ? BIT(4) : BIT(4) | BIT(6)) : BIT(5); u32 seen = 0; unsigned long flags; int nr, ret; @@ -811,9 +827,11 @@ static int apple_dart_frontend_validate(struct apple_dart_dcp *dcp, if (ret) return ret; - alias = of_find_node_by_path(dcp->sid == 0 ? "disp0" : "disp0_piodma"); + alias = apple_dart_frontend_node(dcp->sid != 0); ret = alias && consumer == alias && of_device_is_available(alias) && - of_property_read_bool(alias, "apple,j713-inherited-mappings") ? 0 : -ENODEV; + (main_external || + of_property_read_bool(alias, "apple,j713-inherited-mappings")) ? + 0 : -ENODEV; of_node_put(alias); if (ret) return ret; @@ -838,6 +856,9 @@ static int apple_dart_frontend_validate(struct apple_dart_dcp *dcp, struct resource res; const __be32 *maps; unsigned int matches = 0; + bool retained_framebuffer = main_external && dcp->sid == 0 && + of_property_match_string(consumer, "memory-region-names", + "framebuffer") == i; int bytes; if (!node) @@ -851,6 +872,15 @@ static int apple_dart_frontend_validate(struct apple_dart_dcp *dcp, rmem->base != res.start || rmem->size != resource_size(&res)) goto put_node; maps = of_get_property(node, "iommu-addresses", &bytes); + /* + * The retained scanout framebuffer is a physical handoff, not a + * frontend-DART segment. Keep requiring the reserved no-map region, + * but only region94 participates in SID0's inherited table contract. + */ + if (retained_framebuffer) { + ret = maps ? -EINVAL : 0; + goto put_node; + } if (!maps || bytes <= 0 || bytes % (5 * sizeof(*maps))) goto put_node; for (int j = 0; j < bytes / sizeof(*maps); j += 5) { @@ -1028,7 +1058,7 @@ static int apple_dart_frontend_prepare(struct apple_dart *dart) frontend.end[i], &borrowed[i]); if (ret) return ret; - node = of_find_node_by_path(i ? "disp0_piodma" : "disp0"); + node = apple_dart_frontend_node(i); ret = node ? apple_dart_frontend_validate(borrowed[i], node) : -ENODEV; of_node_put(node); if (ret) @@ -1054,7 +1084,7 @@ static ssize_t j713_display_state_show(struct device *dev, if (!dart->frontend[0] || !dart->frontend[1] || !READ_ONCE(dart->iommu.ready)) return -ENODEV; for (unsigned int i = 0; i < 2; i++) { - struct device_node *node = of_find_node_by_path(i ? "disp0_piodma" : "disp0"); + struct device_node *node = apple_dart_frontend_node(i); status[i] = node ? apple_dart_frontend_validate(dart->frontend[i], node) : -ENODEV; of_node_put(node); @@ -1107,7 +1137,8 @@ static int apple_dart_dcp_validate(struct apple_dart_dcp *dcp, struct device *de } if (!of_device_is_compatible(dev->of_node, - dcp->dart->dcp_instance == &dcp_adt_internal ? + (dcp->dart->dcp_instance == &dcp_adt_internal || + dcp->dart->dcp_instance == &dcp_adt_main_external) ? "apple,t8132-dcp" : "apple,t8132-dcpext") || !apple_dart_dcp_firmware(dev->of_node) || (dcp->owner && dcp->owner != dev)) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index cbaea92c45012..83c938d9f7945 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -514,6 +514,7 @@ struct apple_dart { /* The display coprocessor whose firmware DART (SID23) this is. */ const struct dcp_adt_instance *dcp_instance; bool preserve_display; + bool t8132_main_external; /* A J713 external display DART, borrowed from its external DCP */ bool dispext; /* @@ -948,6 +949,21 @@ static const char *apple_dart_board(void) return board ?: "unknown board"; } +/* A fixed HDMI connector makes the T8132 main DCP an external pipeline. */ +static bool apple_dart_t8132_main_external(void) +{ + struct device_node *dcp; + const char *connector; + bool qualified; + + dcp = of_find_compatible_node(NULL, NULL, "apple,t8132-dcp"); + qualified = dcp && of_device_is_available(dcp) && + !of_property_read_string(dcp, "apple,connector-type", &connector) && + !strcmp(connector, "HDMI-A"); + of_node_put(dcp); + return qualified; +} + static int apple_dart_dcp_invalidate_tlb(struct apple_dart_stream_map *stream_map); #include "apple-dart-dcp.h" @@ -6242,6 +6258,7 @@ static int apple_dart_probe(struct platform_device *pdev) bool cold_avd = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart"); bool cold_ane_gen3 = of_device_is_compatible(dev->of_node, "apple,t8152-ane-dart"); bool cold_isoc = of_device_is_compatible(dev->of_node, "apple,t8152-disp-isoc-dart"); + bool t8132_main_external; bool t8132_dcpext = false; /* @@ -6267,6 +6284,7 @@ static int apple_dart_probe(struct platform_device *pdev) apple_dart_serves_t8132_dcp(dev->of_node, "apple,t8132-dcp"); if (t8132_dcp) j713_display = false; + t8132_main_external = j713_display && apple_dart_t8132_main_external(); /* * An external display processor handed over the same way (the J773g's * HDMI dcpext0, an Air's USB-C dcpext0 and dcpext1) runs the same @@ -6425,6 +6443,7 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) return ret; dart->preserve_display = j713_display || j713_dcpext || j713_dispext; + dart->t8132_main_external = t8132_main_external; dart->dispext = j713_dispext; dart->power_gated = j713_dispext; if (j713_display && of_property_present(dev->of_node, "apple,clock-protection")) { @@ -6446,7 +6465,8 @@ static int apple_dart_probe(struct platform_device *pdev) else if (j713_dispext) dart->dcp_instance = &dcp_adt_external[res->start == 0x48a300000ULL]; else if (j713_display) - dart->dcp_instance = &dcp_adt_internal; + dart->dcp_instance = t8132_main_external ? + &dcp_adt_main_external : &dcp_adt_internal; if (tunneled) { pd_np = of_parse_phandle(dev->of_node, "power-domains", 0); if (pd_np) { @@ -8859,7 +8879,17 @@ int apple_dart_dcp_dispext_state(struct device_node *consumer) if (!device_is_bound(&pdev->dev) || pdev->dev.driver != &apple_dart_driver.driver) goto out; dart = platform_get_drvdata(pdev); - if (!dart || !dart->dispext || !dart->frontend[1]) + if (!dart || !dart->frontend[1]) + goto out; + if (!dart->dispext && dart->t8132_main_external) { + if (!dart->frontend[0] || !apple_dart_dcp_registers(dart->frontend[0]) || + !apple_dart_dcp_registers(dart->frontend[1]) || apple_dart_fault_pending(dart)) + ret = -EIO; + else + ret = 0; + goto out; + } + if (!dart->dispext) goto out; ret = apple_dart_dispext_verify(dart, "after power-up"); out: diff --git a/drivers/phy/apple/dptx.c b/drivers/phy/apple/dptx.c index 7405b7d1c7ad0..bf20a7a8da713 100644 --- a/drivers/phy/apple/dptx.c +++ b/drivers/phy/apple/dptx.c @@ -36,6 +36,7 @@ enum apple_dptx_type { DPTX_PHY_T8112, DPTX_PHY_T6020, DPTX_PHY_T6050, + DPTX_PHY_T8122, }; /* The PLL core calibration the board describes, in t6050_pll_core_cfg() order. */ @@ -153,6 +154,82 @@ static int dptx_phy_set_active_lane_count(struct apple_dptx_phy *phy, u32 num_la return 0; } +static int dptx_phy_activate_t8122(struct apple_dptx_phy *phy, u32 dcp_index) +{ + u32 done, code, val; + + dev_dbg(phy->dev, "T8122 PHY activation: begin (DCP %u)\n", + dcp_index); + + /* Firmware raises the private PHY gate immediately before this callback. */ + usleep_range(5000, 6000); + + readl(phy->regs.core + 0x10); + writel(dcp_index, phy->regs.core + 0x10); + + set32(phy->regs.core + 0x48, 0x010); + set32(phy->regs.core + 0x48, 0x020); + clear32(phy->regs.core + 0x48, 0x040); + set32(phy->regs.core + 0x48, 0x100); + set32(phy->regs.core + 0x48, 0x200); + clear32(phy->regs.core + 0x48, 0x400); + set32(phy->regs.core + 0x48, 0x001); + set32(phy->regs.core + 0x48, 0x002); + clear32(phy->regs.core + 0x48, 0x004); + + val = readl(phy->regs.dptx + 0x2014); + writel((val & ~0x3f0000) | (0x30 << 16), + phy->regs.dptx + 0x2014); + set32(phy->regs.dptx + 0x20b8, 0x010000); + clear32(phy->regs.dptx + 0x2220, 0x0000002); + set32(phy->regs.dptx + 0x222c, 0x000800); + set32(phy->regs.dptx + 0x222c, 0x000100); + set32(phy->regs.dptx + 0x2230, 0x0200000); + clear32(phy->regs.dptx + 0x2278, 0x08000000); + set32(phy->regs.dptx + 0x22a4, 0x0000001); + + for (u32 loff = DPTX_LANE0_OFFSET; loff < DPTX_LANE_END; + loff += DPTX_LANE_STRIDE) { + val = readl(phy->regs.dptx + loff + 0x40); + writel((val & ~0xe00000) | 0x200000, + phy->regs.dptx + loff + 0x40); + } + for (u32 loff = DPTX_LANE0_OFFSET; loff < DPTX_LANE_END; + loff += DPTX_LANE_STRIDE) + set32(phy->regs.dptx + loff + 0x40, 0x080000); + for (u32 loff = DPTX_LANE0_OFFSET; loff < DPTX_LANE_END; + loff += DPTX_LANE_STRIDE) + clear32(phy->regs.dptx + loff + 0x244, 0x10); + + set32(phy->regs.dptx + 0x2218, 0x001); + clear32(phy->regs.dptx + 0x2234, 0x00000001); + set32(phy->regs.dptx + 0x2200, 0x0002); + clear32(phy->regs.dptx + 0x1000, 0x00000002); + set32(phy->regs.dptx + 0x4004, 0x08); + + dptx_phy_set_active_lane_count(phy, 0); + + dev_dbg(phy->dev, "T8122 PHY activation: calibration start\n"); + set32(phy->regs.dptx + 0x4224, 1); + set32(phy->regs.dptx + 0x4200, 0x3c0); + set32(phy->regs.dptx + 0x4200, 1); + udelay(125); + done = readl(phy->regs.dptx + 0x4204) & 1; + clear32(phy->regs.dptx + 0x4200, 1); + code = (readl(phy->regs.dptx + 0x4210) >> 18) & 0x7f; + if (!done) { + dev_err(phy->dev, "impedance calibration did not complete (0x4204 %#x)\n", + readl(phy->regs.dptx + 0x4204)); + return -ETIMEDOUT; + } + mask32(phy->regs.dptx + 0x4228, 0x7f0000, code << 16); + set32(phy->regs.dptx + 0x4228, 0x8000); + dev_dbg(phy->dev, "T8122 PHY activation: complete, calibration code %#x\n", + code); + + return 0; +} + static int dptx_phy_activate(struct apple_dptx_phy *phy, u32 dcp_index) { u32 val_2014; @@ -160,6 +237,8 @@ static int dptx_phy_activate(struct apple_dptx_phy *phy, u32 dcp_index) u32 val_4408; dev_dbg(phy->dev, "activate(dcp:%u)\n", dcp_index); + if (phy->hw.type == DPTX_PHY_T8122) + return dptx_phy_activate_t8122(phy, dcp_index); // MMIO: R.4 0x23c500010 (dptx-phy[1], offset 0x10) = 0x0 // MMIO: W.4 0x23c500010 (dptx-phy[1], offset 0x10) = 0x0 @@ -409,13 +488,17 @@ static int dptx_phy_set_link_rate(struct apple_dptx_phy *phy, u32 link_rate) // MMIO: R.4 0x23c542220 (dptx-phy[0], offset 0x2220) = 0x11090a0 // MMIO: W.4 0x23c542220 (dptx-phy[0], offset 0x2220) = 0x1109020 - clear32(phy->regs.dptx + 0x2220, 0x0000080); + if (phy->hw.type == DPTX_PHY_T8122) + clear32(phy->regs.dptx + 0x222c, 0x0000002); + else + clear32(phy->regs.dptx + 0x2220, 0x0000080); // MMIO: R.4 0x23c5420b0 (dptx-phy[0], offset 0x20b0) = 0x1e0e01c2 // MMIO: W.4 0x23c5420b0 (dptx-phy[0], offset 0x20b0) = 0x1e0e01c2 val_20b0 = readl(phy->regs.dptx + 0x20b0); /* TODO: what happens on dptx-phy */ - if (phy->hw.type == DPTX_PHY_T6020) + if (phy->hw.type == DPTX_PHY_T6020 || + phy->hw.type == DPTX_PHY_T8122) val_20b0 = (val_20b0 & ~0x3ff) | 0x2a3; writel(val_20b0, phy->regs.dptx + 0x20b0); @@ -423,7 +506,8 @@ static int dptx_phy_set_link_rate(struct apple_dptx_phy *phy, u32 link_rate) // MMIO: W.4 0x23c5420b4 (dptx-phy[0], offset 0x20b4) = 0x7fffffe val_20b4 = readl(phy->regs.dptx + 0x20b4); /* TODO: what happens on dptx-phy */ - if (phy->hw.type == DPTX_PHY_T6020) + if (phy->hw.type == DPTX_PHY_T6020 || + phy->hw.type == DPTX_PHY_T8122) val_20b4 = (val_20b4 | 0x4000000) & ~0x0008000; writel(val_20b4, phy->regs.dptx + 0x20b4); @@ -431,7 +515,9 @@ static int dptx_phy_set_link_rate(struct apple_dptx_phy *phy, u32 link_rate) // MMIO: W.4 0x23c5420b4 (dptx-phy[0], offset 0x20b4) = 0x7fffffe val_20b4 = readl(phy->regs.dptx + 0x20b4); /* TODO: what happens on dptx-phy */ - if (phy->hw.type == DPTX_PHY_T6020) + if (phy->hw.type == DPTX_PHY_T8122) + val_20b4 &= ~0x0000002; + else if (phy->hw.type == DPTX_PHY_T6020) val_20b4 = (val_20b4 | 0x0000001) & ~0x0000004; writel(val_20b4, phy->regs.dptx + 0x20b4); @@ -446,13 +532,15 @@ static int dptx_phy_set_link_rate(struct apple_dptx_phy *phy, u32 link_rate) // MMIO: R.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x654800 // MMIO: W.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x654800 /* TODO: unclear */ - if (phy->hw.type == DPTX_PHY_T6020) + if (phy->hw.type == DPTX_PHY_T6020 || + phy->hw.type == DPTX_PHY_T8122) set32(phy->regs.dptx + 0x20b8, 0x010000); else set32(phy->regs.dptx + 0x20b8, 0); // MMIO: R.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x654800 // MMIO: W.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x454800 - clear32(phy->regs.dptx + 0x20b8, 0x200000); + if (phy->hw.type != DPTX_PHY_T8122) + clear32(phy->regs.dptx + 0x20b8, 0x200000); // MMIO: R.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x454800 // MMIO: W.4 0x23c5420b8 (dptx-phy[0], offset 0x20b8) = 0x454800 @@ -1120,6 +1208,17 @@ static int dptx_phy_probe(struct platform_device *pdev) mutex_init(&dptx_phy->lock); + /* + * The generic PHY core only propagates runtime-PM references to the + * provider when runtime PM was enabled before devm_phy_create(). + */ + if (dptx_phy->hw.type == DPTX_PHY_T8122) { + ret = devm_pm_runtime_enable(dev); + if (ret) + return dev_err_probe(dev, ret, + "failed to enable runtime PM\n"); + } + dptx_phy->regs.core = devm_platform_ioremap_resource_byname(pdev, "core"); if (IS_ERR(dptx_phy->regs.core)) @@ -1190,10 +1289,15 @@ static const struct apple_dptx_phy_hw apple_dptx_hw_t6050 = { .type = DPTX_PHY_T6050, }; +static const struct apple_dptx_phy_hw apple_dptx_hw_t8122 = { + .type = DPTX_PHY_T8122, +}; + static const struct of_device_id dptx_phy_match[] = { { .compatible = "apple,t6020-dptx-phy", .data = &apple_dptx_hw_t6020 }, { .compatible = "apple,t8112-dptx-phy", .data = &apple_dptx_hw_t8112 }, { .compatible = "apple,t6050-dptx-phy", .data = &apple_dptx_hw_t6050 }, + { .compatible = "apple,t8122-dptx-phy", .data = &apple_dptx_hw_t8122 }, {}, }; MODULE_DEVICE_TABLE(of, dptx_phy_match); diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 6bc8de49503f8..e6a9d41ee22bc 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -3880,6 +3880,227 @@ static int __init gate_t8132_prepare(struct of_changeset *cs, struct device_node return ret; } +enum { + T8132_HDMI_PHY, + T8132_HDMI_FW_DART, + T8132_HDMI_DISP_DART, + T8132_HDMI_MBOX, + T8132_HDMI_PIODMA, + T8132_HDMI_DCP, + T8132_HDMI_NR, +}; + +/* + * Check that every memory-region of @np is an available apple,asc-mem node, + * as staged_firmware_memory() does for path-addressed stages. + */ +static bool __init staged_node_firmware_memory(struct device_node *np) +{ + struct device_node *chosen, *region; + int i, n; + u32 record[2]; + + n = of_count_phandle_with_args(np, "memory-region", NULL); + for (i = 0; i < n; i++) { + region = of_parse_phandle(np, "memory-region", i); + if (region && of_device_is_available(region) && + of_device_is_compatible(region, "apple,asc-mem")) { + of_node_put(region); + continue; + } + of_node_put(region); + n = -ENODEV; + break; + } + if (n > 0) + return true; + chosen = of_find_node_by_path("/chosen"); + if (chosen && !of_property_read_u32_array(chosen, "m4,dcpext", record, 2)) + staged_err("%pOF: no firmware memory (loader record <%u %u>), nothing enabled\n", + np, record[0], record[1]); + else + staged_err("%pOF: no firmware memory, nothing enabled\n", np); + of_node_put(chosen); + return false; +} + +static void __init gate_t8132_put_nodes(struct device_node *nodes[T8132_HDMI_NR]) +{ + unsigned int i; + + for (i = 0; i < T8132_HDMI_NR; i++) { + of_node_put(nodes[i]); + nodes[i] = NULL; + } +} + +/* + * Derive a fixed-DP T8132 DCP's chain from its own DT phandles: the dp-phy + * PHY, firmware DART (iommus), display DART (piodma's iommus), mailbox + * (mboxes), piodma child, then the dcpext node itself. + */ +static int __init gate_t8132_resolve_fixed_dp(struct device_node *dcp, + int phy_idx, + struct device_node *nodes[T8132_HDMI_NR]) +{ + struct of_phandle_args args; + + memset(nodes, 0, T8132_HDMI_NR * sizeof(*nodes)); + + if (of_parse_phandle_with_args(dcp, "phys", "#phy-cells", phy_idx, &args)) + goto fail; + nodes[T8132_HDMI_PHY] = args.np; + + if (of_parse_phandle_with_args(dcp, "iommus", "#iommu-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_FW_DART] = args.np; + + if (of_parse_phandle_with_args(dcp, "mboxes", "#mbox-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_MBOX] = args.np; + + nodes[T8132_HDMI_PIODMA] = of_get_child_by_name(dcp, "piodma"); + if (!nodes[T8132_HDMI_PIODMA]) + goto fail; + + if (of_parse_phandle_with_args(nodes[T8132_HDMI_PIODMA], "iommus", + "#iommu-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_DISP_DART] = args.np; + + nodes[T8132_HDMI_DCP] = of_node_get(dcp); + return 0; + +fail: + gate_t8132_put_nodes(nodes); + return -EINVAL; +} + +static bool __init gate_t8132_fb_domain(const struct device_node *np, const char *expected) +{ + const char *label; + u32 cells; + + return of_device_is_available(np) && np->phandle && + of_device_is_compatible(np, "apple,t8132-pmgr-pwrstate") && + !of_property_read_string(np, "label", &label) && !strcmp(label, expected) && + !of_property_read_u32(np, "#power-domain-cells", &cells) && !cells; +} + +/* + * Keep the 26.6.2 iBoot framebuffer attached to the main DCP front end, + * including when the display driver is disabled or the handoff is refused. + * The loader can rename the node, so find it the same way as OF population. + */ +static void __init gate_t8132_legacy_fb(void) +{ + struct device_node *frontend __free(device_node) = NULL; + struct device_node *fb __free(device_node) = NULL; + struct device_node *previous __free(device_node) = NULL; + struct device_node *phy __free(device_node) = NULL; + struct property *prop; + const __be32 *old; + __be32 *domains; + int len; + + if (!apple_t8132_qualified_firmware()) + return; + + frontend = of_find_node_by_path("disp0-fe"); + if (!gate_t8132_fb_domain(frontend, "disp_fe")) + return; + + fb = of_get_compatible_child(of_chosen, "simple-framebuffer"); + if (!of_device_is_available(fb)) + return; + + old = of_get_property(fb, "power-domains", &len); + if (!old || len != 2 * sizeof(*old) || be32_to_cpu(old[0]) == frontend->phandle) + return; + + /* Each cell must resolve to the expected zero-cell provider. */ + previous = of_parse_phandle(fb, "power-domains", 0); + phy = of_parse_phandle(fb, "power-domains", 1); + if (!gate_t8132_fb_domain(previous, "dispext0_fe") || + !gate_t8132_fb_domain(phy, "dptx_phy")) + return; + + prop = kzalloc_obj(*prop); + if (!prop) + return; + prop->name = kstrdup("power-domains", GFP_KERNEL); + domains = kmemdup(old, len, GFP_KERNEL); + if (prop->name && domains) { + domains[0] = cpu_to_be32(frontend->phandle); + prop->value = domains; + prop->length = len; + of_property_set_flag(prop, OF_DYNAMIC); + if (!of_update_property(fb, prop)) + return; + } + kfree(domains); + kfree(prop->name); + kfree(prop); +} + +/* The M4 firmware uses the main DCP and the PHY's legacy operations. */ +static void __init gate_t8132_main_hdmi(void) +{ + struct device_node *dcp __free(device_node) = of_find_node_by_path("dcp"); + struct device_node *display __free(device_node) = NULL; + struct device_node *phy_domain __free(device_node) = NULL; + struct device_node *nodes[T8132_HDMI_NR]; + const char *connector; + struct of_changeset *cs; + int i, phy_idx, ret; + + if (!apple_t8132_qualified_firmware() || + !of_device_is_compatible(dcp, "apple,t8132-dcp") || + of_property_read_string(dcp, "apple,connector-type", &connector) || + strcmp(connector, "HDMI-A") || + (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only())) + return; + + phy_idx = of_property_match_string(dcp, "phy-names", "dp-phy"); + if (phy_idx < 0 || gate_t8132_resolve_fixed_dp(dcp, phy_idx, nodes)) + return; + + staged_prefix = gate_t8132.prefix; + display = of_find_node_by_path("disp0"); + phy_domain = of_parse_phandle(nodes[T8132_HDMI_PHY], "power-domains", 0); + if (!display || !of_device_is_compatible(display, gate_t8132.display_compat) || + !of_device_is_compatible(nodes[T8132_HDMI_PHY], "apple,t8132-dptx-phy") || + !of_device_is_available(phy_domain) || + !staged_node_firmware_memory(dcp) || + !staged_node_firmware_memory(display) || + !staged_node_firmware_memory(nodes[T8132_HDMI_PIODMA])) + goto put_nodes; + + cs = gate_cs_alloc(); + if (!cs) + goto put_nodes; + /* The legacy driver cannot restore the PHY state lost across power-off. */ + ret = 0; + if (!of_property_present(phy_domain, "apple,always-on")) + ret = of_changeset_add_prop_bool(cs, phy_domain, "apple,always-on"); + if (!ret) + ret = of_changeset_update_prop_string(cs, nodes[T8132_HDMI_PHY], + "compatible", "apple,t8122-dptx-phy"); + for (i = 0; !ret && i < T8132_HDMI_NR; i++) + ret = of_changeset_update_prop_string(cs, nodes[i], "status", "okay"); + if (!ret) + ret = of_changeset_update_prop_string(cs, display, "status", "okay"); + if (!ret) + ret = of_changeset_apply(cs); + if (ret) { + gate_cs_free(cs); + staged_err("%pOF: could not enable the inherited HDMI chain: %d\n", dcp, ret); + } + +put_nodes: + gate_t8132_put_nodes(nodes); +} + static void __init gate_t8132_run(void) { struct device_node *display __free(device_node) = @@ -3922,6 +4143,8 @@ static void __init apple_display_gate_soc(void) int i; if (apple_t8132_firmware_path()) { + gate_t8132_legacy_fb(); + gate_t8132_main_hdmi(); gate_j713_dcpext_routes(); gate_t8132_run(); return; diff --git a/tools/asahi/apple-dart-dcp-placeholder-tests.py b/tools/asahi/apple-dart-dcp-placeholder-tests.py index 5303997b15a5a..ecf559d1ae98b 100755 --- a/tools/asahi/apple-dart-dcp-placeholder-tests.py +++ b/tools/asahi/apple-dart-dcp-placeholder-tests.py @@ -34,6 +34,7 @@ def definition(source, name): args = parser.parse_args() source = (ROOT / 'drivers/iommu/apple-dart-dcp.h').read_text() +frontend = definition(source, 'static struct device_node *apple_dart_frontend_node(') region = definition(source, 'static int apple_dart_dcp_region(') leaf = definition(source, 'static int apple_dart_dcp_leaf_regions(') validate = definition(source, 'static int apple_dart_dcp_validate(') @@ -101,7 +102,7 @@ def definition(source, name): rmem.size = n->size; return &rmem; } -''' + region + '\n' + leaf + r''' +''' + frontend + '\n' + region + '\n' + leaf + r''' static const struct dcp_instance ext0 = { "dcpext0" }; static struct apple_dart dart = { false, &ext0 }; static int run(struct apple_dart_dcp *d, unsigned int sid, bool dispext) diff --git a/tools/asahi/apple-dart-dispext-window-tests.py b/tools/asahi/apple-dart-dispext-window-tests.py index 53749deec1413..7e6339c52d499 100755 --- a/tools/asahi/apple-dart-dispext-window-tests.py +++ b/tools/asahi/apple-dart-dispext-window-tests.py @@ -165,6 +165,7 @@ def apply_mutation(bodies, mutation): struct apple_dart { struct apple_dart_dcp *frontend[2]; bool dispext; + bool t8132_main_external; bool retired; bool regs_bad; bool fault_pending; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index e8eebff435dcd..782841c01fa08 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1549,6 +1549,7 @@ def function(source, marker): + function(drm, 'struct apple_dcp_start_work {') + ';\n' + function(drm, 'static void apple_dcp_start_fn(')) if 'static void apple_dcp_start_fn(' in drm else '', + function(drm, 'static bool apple_drm_has_output('), function(drm, 'static int apple_drm_init_dcp('), 'static int publish_provider(struct platform_device *pdev, struct apple_dcp *dcp)\n' '{\n\tstruct device *dev = &pdev->dev;\n\tint ret;\n' @@ -1592,6 +1593,11 @@ def function(source, marker): struct { int iomfb_method_profile; } hw; struct work_struct external_audio_work; }; +/* This J700 fixture has neither a T8132 main DCP nor its fixed HDMI path. */ +static bool __attribute__((unused)) dcp_t8132_main_external(struct device_node *n) +{ (void)n; return false; } +static bool __attribute__((unused)) apple_t8132_main_external_present(void) +{ return false; } /* This readiness fixture has no AV owner or native audio initializer. */ static void av_audiosrv_quiesce(struct apple_dcp *d) { assert(!d->external_native); } @@ -1621,6 +1627,8 @@ def function(source, marker): static void __attribute__((unused)) iomfb_v14_7_external_refuse(struct apple_dcp *d, const char *why) { (void)d; (void)why; assert(!"T6030 external processor in a J700 scenario"); } struct drm_device { int unused; }; +struct drm_crtc { int unused; }; +#define drm_for_each_crtc(crtc, drm) for ((void)(drm), (crtc) = NULL; (crtc); ) struct drm_encoder { int unused; }; /* Not a J713: production registers no T8132 external outputs and returns 0. */ static int __attribute__((unused)) t8132_ext_drm_init(struct drm_device *drm) { (void)drm; return 0; }