Re: [PATCH v6 3/3] drm/rockchip: Add basic RK3588 HDMI output support

From: Cristian Ciocaltea
Date: Sat Sep 14 2024 - 14:29:16 EST


On 9/10/24 10:08 PM, Heiko Stübner wrote:
> Am Freitag, 6. September 2024, 03:17:42 CEST schrieb Cristian Ciocaltea:
>> The RK3588 SoC family integrates the newer Synopsys DesignWare HDMI 2.1
>> Quad-Pixel (QP) TX controller IP and a HDMI/eDP TX Combo PHY based on a
>> Samsung IP block.
>>
>> Add just the basic support for now, i.e. RGB output up to 4K@60Hz,
>> without audio, CEC or any of the HDMI 2.1 specific features.
>>
>> Co-developed-by: Algea Cao <algea.cao@xxxxxxxxxxxxxx>
>> Signed-off-by: Algea Cao <algea.cao@xxxxxxxxxxxxxx>
>> Tested-by: Heiko Stuebner <heiko@xxxxxxxxx>
>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@xxxxxxxxxxxxx>
>
> [...]
>
>> diff --git a/drivers/gpu/drm/rockchip/Makefile b/drivers/gpu/drm/rockchip/Makefile
>> index 3ff7b21c0414..3eab662a5a1d 100644
>> --- a/drivers/gpu/drm/rockchip/Makefile
>> +++ b/drivers/gpu/drm/rockchip/Makefile
>> @@ -11,6 +11,7 @@ rockchipdrm-$(CONFIG_ROCKCHIP_VOP) += rockchip_drm_vop.o rockchip_vop_reg.o
>
>> +static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
>> + void *data)
>> +{
>> + static const char * const clk_names[] = {
>> + "pclk", "earc", "aud", "hdp", "hclk_vo1",
>> + "ref" /* keep "ref" last */
>> + };
>
> [...]
>
>> + for (i = 0; i < ARRAY_SIZE(clk_names); i++) {
>> + clk = devm_clk_get_enabled(hdmi->dev, clk_names[i]);
>> +
>> + if (IS_ERR(clk)) {
>> + ret = PTR_ERR(clk);
>> + if (ret != -EPROBE_DEFER)
>> + drm_err(hdmi, "Failed to get %s clock: %d\n",
>> + clk_names[i], ret);
>> + return ret;
>> + }
>> + }
>> + hdmi->ref_clk = clk;
>
> How about using devm_clk_bulk_get_all_enable() for everything except the
> refclk and a separate call to devm_clk_get_enabled() for that refclk .

This helper seems to be partially broken as it doesn't return the number of
clocks stored in the clk_bulk_data table referenced by the clks argument,
meaning it's not possible to iterate these clocks. I provided a new helper
[1] as a possible fix.

If that gets accepted, we could rewrite this as:

ret = devm_clk_bulk_get_all_enabled(hdmi->dev, &clks);
if (ret < 0) {
drm_err(hdmi, "Failed to get clocks: %d\n", ret);
return ret;
}

for (i = 0; i < ret; i++) {
if (!strcmp(clks[i].id, "ref")) {
hdmi->ref_clk = clks[1].clk;
break;
}
}
if (!hdmi->ref_clk) {
drm_err(hdmi, "Missing ref clock\n");
return -EINVAL;
}

> That hdmi->ref_clk just accidentially falls out of that loop at the end
> looks somewhat strange, so getting and keeping that refclk
> separately would make this look cleaner.

I've added /* keep "ref" last */ comment above, but I agree it's not really
the best approach.

I'm going to submit v7 in the meantime, as this was the last remaining open
topic on my list. I guess we can figure this out afterwards.

Thanks,
Cristian

[1] https://lore.kernel.org/lkml/20240914-clk_bulk_ena_fix-v1-0-ce3537585c06@xxxxxxxxxxxxx/