Re: [PATCH v2 25/46] drm/mediatek: mtk_dpi: Fully separate HW setup from common code

From: CK Hu (胡俊光)

Date: Sun Nov 15 2026 - 19:42:10 EST


On Tue, 2026-07-14 at 13:43 +0200, AngeloGioacchino Del Regno wrote:
> As a preparation step for adding support for DVO and creating a
> mtk_dpi_common library, fully separate all of the register writing
> mechanisms from commonizable hardware setup functions.
>
> While at it, also perform some spare code style cleanups and also
> remove the mtk_dpi_config_vsync_{l,r}{odd,even}() functions and
> open-code the single line found in each of those, as now all of
> the parameters are clearly labeled and won't have any meaningful
> impact on human readability.
>
> This change brings no functional differences.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
> ---

[snip]

> @@ -516,7 +474,6 @@ static void mtk_dpi_power_off(struct mtk_dpi *dpi)
> if (--dpi->refcount != 0)
> return;
>
> - mtk_dpi_disable(dpi);

Commit message says no function difference, but function changes here because of reference count.
This is not related to the title "Fully separate HW setup from common code",
so separate this to an independent patch.

> clk_disable_unprepare(dpi->pixel_clk);
> clk_disable_unprepare(dpi->tvd_clk);
> clk_disable_unprepare(dpi->engine_clk);
> @@ -607,40 +564,40 @@ static void mtk_dpi_set_pixel_clk(struct mtk_dpi *dpi, struct videomode *vm, int
> pll_rate, vm->pixelclock);
> }
>
> -static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
> +static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi, struct videomode *vm,
> struct mtk_dpi_sync *sync,
> - struct drm_display_mode *mode)
> + struct mtk_dpi_polarities *dpi_pol,
> + struct mtk_dpi_yc_limit *limit)
> {
> - struct mtk_dpi_polarities dpi_pol;
> - struct videomode vm = { 0 };
> + struct drm_display_mode *mode = &dpi->mode;
>
> - drm_display_mode_to_videomode(mode, &vm);
> + drm_display_mode_to_videomode(mode, vm);
>
> if (!dpi->conf->clocked_by_hdmi)
> - mtk_dpi_set_pixel_clk(dpi, &vm, mode->clock);
> + mtk_dpi_set_pixel_clk(dpi, vm, mode->clock);
>
> - dpi_pol.ck_pol = MTK_DPI_POLARITY_FALLING;
> - dpi_pol.de_pol = MTK_DPI_POLARITY_RISING;
> - dpi_pol.hsync_pol = vm.flags & DISPLAY_FLAGS_HSYNC_HIGH ?
> + dpi_pol->ck_pol = MTK_DPI_POLARITY_FALLING;
> + dpi_pol->de_pol = MTK_DPI_POLARITY_RISING;
> + dpi_pol->hsync_pol = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
> MTK_DPI_POLARITY_FALLING : MTK_DPI_POLARITY_RISING;
> - dpi_pol.vsync_pol = vm.flags & DISPLAY_FLAGS_VSYNC_HIGH ?
> + dpi_pol->vsync_pol = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
> MTK_DPI_POLARITY_FALLING : MTK_DPI_POLARITY_RISING;
>
> /*
> * Depending on the IP version, we may output a different amount of
> * pixels for each iteration: adjust the display porches accordingly.
> */
> - sync->hsync.sync_width = vm.hsync_len / dpi->conf->pixels_per_iter;
> - sync->hsync.back_porch = vm.hback_porch / dpi->conf->pixels_per_iter;
> - sync->hsync.front_porch = vm.hfront_porch / dpi->conf->pixels_per_iter;
> + sync->hsync.sync_width = vm->hsync_len / dpi->conf->pixels_per_iter;
> + sync->hsync.back_porch = vm->hback_porch / dpi->conf->pixels_per_iter;
> + sync->hsync.front_porch = vm->hfront_porch / dpi->conf->pixels_per_iter;
> sync->hsync.shift_half_line = false;
>
> - sync->vsync_l_odd.sync_width = vm.vsync_len;
> - sync->vsync_l_odd.back_porch = vm.vback_porch;
> - sync->vsync_l_odd.front_porch = vm.vfront_porch;
> + sync->vsync_l_odd.sync_width = vm->vsync_len;
> + sync->vsync_l_odd.back_porch = vm->vback_porch;
> + sync->vsync_l_odd.front_porch = vm->vfront_porch;
> sync->vsync_l_odd.shift_half_line = false;
>
> - if (vm.flags & DISPLAY_FLAGS_INTERLACED) {
> + if (vm->flags & DISPLAY_FLAGS_INTERLACED) {
> sync->vsync_l_even = sync->vsync_l_odd;
> sync->vsync_l_even.shift_half_line = true;
>
> @@ -653,27 +610,55 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
> sync->vsync_r_odd = sync->vsync_l_odd;
> }
>
> + if (drm_default_rgb_quant_range(&dpi->mode) == HDMI_QUANTIZATION_RANGE_LIMITED) {

drm_default_rgb_quant_range(mode)

Regards,
CK

> + limit->y_bottom = 0x10;
> + limit->y_top = 0xfe0;
> + limit->c_bottom = 0x10;
> + limit->c_top = 0xfe0;
> + } else {
> + limit->y_bottom = 0;
> + limit->y_top = 0xfff;
> + limit->c_bottom = 0;
> + limit->c_top = 0xfff;
> + }
> +
> + return 0;
> +}
> +