diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 68df9410d3363..426689d2ae038 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -77,9 +77,84 @@ phy-names = "dp-phy"; hdmi-pwren-gpios = <&smc_gpio 15 GPIO_ACTIVE_HIGH>; dp2hdmi-pwren-gpios = <&smc_gpio 26 GPIO_ACTIVE_HIGH>; + /* + * The main pipe's realtime bandwidth request slot (D003), as macOS + * provides it on this Mac; without it the firmware runs with realtime + * bandwidth disabled. + */ + apple,bw-scratch = <&pmgr_dcp_bw 0 4 0>; + /* D408 clock-frequency request (index 0): /arm-io/disp0 clock-id 364's ADT rate. */ + clocks = <&dcp_fw_clk364>; + status = "okay"; +}; + +/* + * The HDMI port as macOS drives it, from dispext0 (4K60, and 4K120 with DSC, + * on that pipe alone; the main DCP booted and idle), through the same PHY + * (source select = its dcp-index 1) and converter rails as the main DCP. It is + * used when the boot loader hands dispext0 over (aura: boot.bin line + * chosen.asahi,j713-dcpext=1); otherwise the main DCP above drives the port. + * iBoot leaves DISPEXT0 running: Linux must not switch its domains, as for the + * main DCP. + */ +&dcpext0_mbox { + /delete-property/ power-domains; + status = "okay"; +}; + +&dcpext0_dart { + /delete-property/ power-domains; + status = "okay"; +}; + +&dispext0_dart { + /delete-property/ power-domains; + status = "okay"; +}; + +&dcpext0 { + /delete-property/ power-domains; + apple,connector-type = "HDMI-A"; + apple,dptx-phy = <4>; + phys = <&dptx_phy>; + phy-names = "dp-phy"; + hdmi-pwren-gpios = <&smc_gpio 15 GPIO_ACTIVE_HIGH>; + dp2hdmi-pwren-gpios = <&smc_gpio 26 GPIO_ACTIVE_HIGH>; + clocks = <&dcp_fw_clk369>; status = "okay"; }; +/ { + /* + * The display pipes' firmware clocks, from the ADT's /arm-io + * clock-frequencies at their first clock-id (disp0 364, dispext0 369), + * the same in the 26.6.2 and 27.2 trees. Their second clock-ids (431, + * 432) have no rate. + */ + dcp_fw_clk364: clock-dcp-firmware-364 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <300000000>; + clock-output-names = "dcp_firmware_364"; + }; + + dcp_fw_clk369: clock-dcp-firmware-369 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <533333328>; + clock-output-names = "dcp_firmware_369"; + }; +}; + +&soc { + /* 0x20000 into the window the main DCP has as disp-4. */ + pmgr_dcp_bw: power-management@382820000 { + reg = <0x3 0x82820000 0x0 0x8>; + reg-names = "dcp-bw-scratch"; + #apple,bw-scratch-cells = <3>; + }; +}; + &disp0_piodma { status = "okay"; }; diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 945a9c6df7692..e70e7cbab14c9 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1456,13 +1456,20 @@ static const struct of_device_id apple_dcp_id_tbl[] = { {}, }; +/* + * Whether this DRM device has no DCP components, only T8132 external outputs: + * the fixed HDMI port, driven by the main DCP or by a handed-over dcpext (the + * Mac mini). + */ 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); + struct device_node *np; + bool present = false; - of_node_put(np); + for_each_compatible_node(np, NULL, "apple,t8132-dcp") + present = present || (dcp_t8132_main_external(np) && of_device_is_available(np)); + for_each_compatible_node(np, NULL, "apple,t8132-dcpext") + present = present || dcp_t8132_fixed_hdmi(np); return present; } @@ -1475,6 +1482,7 @@ static bool apple_t8132_main_external_present(void) static bool apple_dcp_usable(struct device_node *np) { return of_device_is_available(np) && !dcp_t8132_main_external(np) && + !dcp_t8132_main_hdmi_idle(np) && (!of_device_is_compatible(np, "apple,t6030-dcpext") || dcp_t6030_ext_native(np)) && (!of_device_is_compatible(np, "apple,t8140-dcpext") || diff --git a/drivers/gpu/drm/apple/dcp-m4-callback.h b/drivers/gpu/drm/apple/dcp-m4-callback.h index 7a6fb73856e1a..81fb52af62cad 100644 --- a/drivers/gpu/drm/apple/dcp-m4-callback.h +++ b/drivers/gpu/drm/apple/dcp-m4-callback.h @@ -26,6 +26,12 @@ struct dcp_m4_callback_ops { * Absent: the optional service is declined (status 1). */ int (*bandwidth)(void *cookie, void *output); + /* + * D408 clock-frequency request (@index): the DCP's own firmware clock rate, 0 + * if the device tree gives it. Absent or failing: the answers the J713 + * handoff was qualified with. + */ + int (*clock_rate)(void *cookie, u32 index, u64 *rate); }; struct dcp_m4_callback_shape { @@ -120,6 +126,7 @@ static inline int dcp_m4_callback_dispatch(const struct dcp_m4_callback_ops *ops u8 *out = output; int method, ret; u32 value; + u64 rate; method = dcp_m4_callback_shape(tag, input_size, output_size); if (method < 0) @@ -186,7 +193,10 @@ static inline int dcp_m4_callback_dispatch(const struct dcp_m4_callback_ops *ops value = get_unaligned_le32(in + 4); if (memcmp(in, "VORP", 4) || value > 1) return -EINVAL; - put_unaligned_le64(value ? 24000000 : 48000000, out); + if (ops->clock_rate && !ops->clock_rate(cookie, value, &rate)) + put_unaligned_le64(rate, out); + else + put_unaligned_le64(value ? 24000000 : 48000000, out); return 0; case 590: value = get_unaligned_le32(in); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 8f1b7bef35bf7..c43e27178f6b7 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5968,11 +5968,62 @@ 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. */ +/* + * A T8132 external DCP the board routes to the fixed HDMI port (the Mac + * mini's dispext0, the pipe macOS drives its HDMI port from), through the + * same DPTX PHY and HDMI converter rails as the main DCP, the PHY's source + * select being the DCP's index, and that the boot loader handed over. + */ +static bool dcp_t8132_hdmi_dcpext_ready(struct device_node *np) +{ + u32 ready = 0; + + return np && of_device_is_compatible(np, "apple,t8132-dcpext") && + of_device_is_available(np) && + dcp_connector_type_from_dt(np) == DRM_MODE_CONNECTOR_HDMIA && + !of_property_read_u32(np, "apple,t8132-dcpext-firmware-ready", &ready) && + ready == 1; +} + +/* Whether a handed-over dcpext drives the fixed HDMI port. */ +static bool dcp_t8132_hdmi_on_dcpext(void) +{ + struct device_node *np; + bool on = false; + + for_each_compatible_node(np, NULL, "apple,t8132-dcpext") + on = on || dcp_t8132_hdmi_dcpext_ready(np); + return on; +} + +/* + * A T8132 main DCP can serve a fixed external output instead of a panel, + * unless a handed-over dcpext serves that port instead. + */ 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; + dcp_connector_type_from_dt(np) == DRM_MODE_CONNECTOR_HDMIA && + !dcp_t8132_hdmi_on_dcpext(); +} + +/* + * A main DCP whose HDMI port a handed-over dcpext drives: it is left as the + * boot loader left it, booted and idle, as macOS leaves it on the Mac mini. + * Without that handoff (a boot loader that keeps dispext0), the main DCP + * drives the port as before. + */ +bool dcp_t8132_main_hdmi_idle(struct device_node *np) +{ + return np && of_device_is_compatible(np, "apple,t8132-dcp") && + dcp_connector_type_from_dt(np) == DRM_MODE_CONNECTOR_HDMIA && + dcp_t8132_hdmi_on_dcpext(); +} + +/* The T8132 DCP that drives the fixed HDMI port: the main DCP or a dcpext. */ +bool dcp_t8132_fixed_hdmi(struct device_node *np) +{ + return dcp_t8132_main_external(np) || dcp_t8132_hdmi_dcpext_ready(np); } /* @@ -7238,8 +7289,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (iomfb_is_m4(dcp)) { bool main_external = dcp_t8132_main_external(dev->of_node); + bool fixed_hdmi = dcp_t8132_fixed_hdmi(dev->of_node); - if (main_external) { + if (fixed_hdmi) { dcp->fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA; dcp->connector_type = DRM_MODE_CONNECTOR_HDMIA; ret = dcp_m4_hdmi_prepare(dcp); @@ -7263,7 +7315,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) ret = dcp_pin_live_session(dcp); if (!ret) ret = iomfb_m4_adopt_external(dcp); - if (!ret && main_external) { + if (!ret && fixed_hdmi) { ret = dcp_desktop_dptx_connect(dcp, 0); if (ret) { dev_warn(dev, "initial HDMI DPTX connect failed: %d\n", @@ -7271,7 +7323,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) ret = 0; } } - if (!ret && !main_external) + if (!ret && !fixed_hdmi) dcp_t8132_ext_routes(dcp); return ret; } @@ -7685,6 +7737,10 @@ static int dcp_platform_probe(struct platform_device *pdev) return -ENODEV; } + if (dcp_t8132_main_hdmi_idle(dev->of_node)) { + dev_info(dev, "HDMI port on a handed-over external DCP: main DCP left booted and idle\n"); + return -ENODEV; + } if (of_device_is_compatible(dev->of_node, "apple,t8132-dcpext")) return dcp_platform_probe_t8132_ext(pdev); if (!dcp_ext_is_failsafe(dev->of_node)) diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 5f04178061351..dc3f8af72d78a 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -16,6 +16,8 @@ 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); +bool dcp_t8132_fixed_hdmi(struct device_node *np); +bool dcp_t8132_main_hdmi_idle(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 e2ddcfae78139..d52b3a10554ed 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -8,6 +8,7 @@ * completion; an uncertain transaction stays pinned until reboot. */ #include +#include #include #include #include @@ -163,6 +164,9 @@ struct iomfb_m4 { size_t coproc_size; /* The realtime bandwidth mailbox from the DT (0: none), see dcp_m4_bw_mailbox() */ u64 bw_mailbox; + /* D408: the firmware clock rate from the DT, see dcp_m4_fw_clock() */ + bool fw_clock; + u64 fw_clock_hz; struct work_struct backlight_work; void __iomem *coproc; struct apple_rtkit *rtkit; @@ -1424,8 +1428,19 @@ static int dcp_m4_runtime_bandwidth(void *cookie, void *output) return 0; } +static int dcp_m4_runtime_clock_rate(void *cookie, u32 index, u64 *rate) +{ + struct dcp_m4_runtime *r = cookie; + + if (!r->dcp->fw_clock) + return -ENOENT; + *rate = index ? 0 : r->dcp->fw_clock_hz; + return 0; +} + static const struct dcp_m4_callback_ops dcp_m4_runtime_ops = { .call = dcp_m4_runtime_call, + .clock_rate = dcp_m4_runtime_clock_rate, .property = dcp_m4_runtime_property, .memory = dcp_m4_runtime_memory, .event = dcp_m4_runtime_event, @@ -2567,6 +2582,27 @@ static bool iomfb_m4_firmware_property(struct device_node *np, const char *name) version[0] == 26 && version[1] == 6 && version[2] == 2; } +/* + * The rate the firmware asks for with D408 clock-frequency request (index 0): the DCP's + * own clock in the device tree (a fixed clock at the rate of the display's + * first ADT clock-id, as macOS answers), index 1 then returns 0, the + * rate of its second. Without one, the qualified J713 answers stand. + */ +static void dcp_m4_fw_clock(struct iomfb_m4 *dcp) +{ + struct clk *clk = of_clk_get(dcp->dev->of_node, 0); + + if (IS_ERR(clk)) { + if (PTR_ERR(clk) != -ENOENT) + dev_warn(dcp->dev, "firmware clock: %pe: the default rates stand\n", clk); + return; + } + dcp->fw_clock_hz = clk_get_rate(clk); + dcp->fw_clock = true; + clk_put(clk); + dev_dbg(dcp->dev, "firmware clock %llu Hz\n", dcp->fw_clock_hz); +} + /* * The realtime bandwidth mailbox the DT gives @dev, or 0: apple,bw-scratch * names the provider's reg range, the firmware's display register index and @@ -2677,6 +2713,7 @@ int iomfb_m4_init(struct apple_dcp *owner) dcp->owner = owner; dcp->dev = dev; dcp->bw_mailbox = dcp_m4_bw_mailbox(dev); + dcp_m4_fw_clock(dcp); mutex_init(&dcp->lock); mutex_init(&dcp->ext_modes_lock); spin_lock_init(&dcp->state_lock); diff --git a/drivers/gpu/drm/apple/t8132_ext_drm.c b/drivers/gpu/drm/apple/t8132_ext_drm.c index 0c219f775ef81..d8e8c2c13f65e 100644 --- a/drivers/gpu/drm/apple/t8132_ext_drm.c +++ b/drivers/gpu/drm/apple/t8132_ext_drm.c @@ -1045,7 +1045,7 @@ 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, - dcp_t8132_main_external(pdev->dev.of_node) ? + dcp_t8132_fixed_hdmi(pdev->dev.of_node) ? DRM_MODE_CONNECTOR_HDMIA : DRM_MODE_CONNECTOR_DisplayPort); if (ret) goto err_encoder; diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index a7366b7f1efe7..99e38e7ff5565 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -910,6 +910,22 @@ static bool apple_dart_t8132_main_external(void) !of_property_read_string(dcp, "apple,connector-type", &connector) && !strcmp(connector, "HDMI-A"); of_node_put(dcp); + /* + * The fixed HDMI port on dispext0 instead (as macOS drives it): the main + * DCP stays booted and idle, its tables as the boot loader handed them + * over for the port, and its display DART still serves the display + * device's imports, as when the main DCP drives the port. + */ + for_each_compatible_node(dcp, NULL, "apple,t8132-dcpext") { + u32 ready = 0; + + if (!qualified && of_device_is_available(dcp) && + !of_property_read_string(dcp, "apple,connector-type", &connector) && + !strcmp(connector, "HDMI-A") && + !of_property_read_u32(dcp, "apple,t8132-dcpext-firmware-ready", &ready) && + ready == 1) + qualified = true; + } return qualified; }