Skip to content

Commit 71f2354

Browse files
johnstultz-workairlied
authored andcommitted
drm: kirin: Add mode_valid logic to avoid mode clocks we can't generate
Currently the hikey dsi logic cannot generate accurate byte clocks values for all pixel clock values. Thus if a mode clock is selected that cannot match the calculated byte clock, the device will boot with a blank screen. This patch uses the new mode_valid callback (many thanks to Jose Abreu for upstreaming it!) to ensure we don't select modes we cannot generate. Also, since the ade crtc code will adjust the mode in mode_set, this patch also adds a mode_fixup callback which we use to make sure we are validating the mode clock that will eventually be used. Cc: Daniel Vetter <daniel.vetter@intel.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Sean Paul <seanpaul@chromium.org> Cc: David Airlie <airlied@linux.ie> Cc: Rob Clark <robdclark@gmail.com> Cc: Xinliang Liu <xinliang.liu@linaro.org> Cc: Xinliang Liu <z.liuxinliang@hisilicon.com> Cc: Rongrong Zou <zourongrong@gmail.com> Cc: Xinwei Kong <kong.kongxinwei@hisilicon.com> Cc: Chen Feng <puck.chen@hisilicon.com> Cc: Jose Abreu <Jose.Abreu@synopsys.com> Cc: Archit Taneja <architt@codeaurora.org> Cc: dri-devel@lists.freedesktop.org Reviewed-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: John Stultz <john.stultz@linaro.org> Reviewed-by: Xinliang Liu <xinliang.liu@linaro.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent e47ef30 commit 71f2354

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,72 @@ static void dsi_encoder_enable(struct drm_encoder *encoder)
603603
dsi->enable = true;
604604
}
605605

606+
static enum drm_mode_status dsi_encoder_phy_mode_valid(
607+
struct drm_encoder *encoder,
608+
const struct drm_display_mode *mode)
609+
{
610+
struct dw_dsi *dsi = encoder_to_dsi(encoder);
611+
struct mipi_phy_params phy;
612+
u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format);
613+
u32 req_kHz, act_kHz, lane_byte_clk_kHz;
614+
615+
/* Calculate the lane byte clk using the adjusted mode clk */
616+
memset(&phy, 0, sizeof(phy));
617+
req_kHz = mode->clock * bpp / dsi->lanes;
618+
act_kHz = dsi_calc_phy_rate(req_kHz, &phy);
619+
lane_byte_clk_kHz = act_kHz / 8;
620+
621+
DRM_DEBUG_DRIVER("Checking mode %ix%i-%i@%i clock: %i...",
622+
mode->hdisplay, mode->vdisplay, bpp,
623+
drm_mode_vrefresh(mode), mode->clock);
624+
625+
/*
626+
* Make sure the adjusted mode clock and the lane byte clk
627+
* have a common denominator base frequency
628+
*/
629+
if (mode->clock/dsi->lanes == lane_byte_clk_kHz/3) {
630+
DRM_DEBUG_DRIVER("OK!\n");
631+
return MODE_OK;
632+
}
633+
634+
DRM_DEBUG_DRIVER("BAD!\n");
635+
return MODE_BAD;
636+
}
637+
638+
static enum drm_mode_status dsi_encoder_mode_valid(struct drm_encoder *encoder,
639+
const struct drm_display_mode *mode)
640+
641+
{
642+
const struct drm_crtc_helper_funcs *crtc_funcs = NULL;
643+
struct drm_crtc *crtc = NULL;
644+
struct drm_display_mode adj_mode;
645+
enum drm_mode_status ret;
646+
647+
/*
648+
* The crtc might adjust the mode, so go through the
649+
* possible crtcs (technically just one) and call
650+
* mode_fixup to figure out the adjusted mode before we
651+
* validate it.
652+
*/
653+
drm_for_each_crtc(crtc, encoder->dev) {
654+
/*
655+
* reset adj_mode to the mode value each time,
656+
* so we don't adjust the mode twice
657+
*/
658+
drm_mode_copy(&adj_mode, mode);
659+
660+
crtc_funcs = crtc->helper_private;
661+
if (crtc_funcs && crtc_funcs->mode_fixup)
662+
if (!crtc_funcs->mode_fixup(crtc, mode, &adj_mode))
663+
return MODE_BAD;
664+
665+
ret = dsi_encoder_phy_mode_valid(encoder, &adj_mode);
666+
if (ret != MODE_OK)
667+
return ret;
668+
}
669+
return MODE_OK;
670+
}
671+
606672
static void dsi_encoder_mode_set(struct drm_encoder *encoder,
607673
struct drm_display_mode *mode,
608674
struct drm_display_mode *adj_mode)
@@ -622,6 +688,7 @@ static int dsi_encoder_atomic_check(struct drm_encoder *encoder,
622688

623689
static const struct drm_encoder_helper_funcs dw_encoder_helper_funcs = {
624690
.atomic_check = dsi_encoder_atomic_check,
691+
.mode_valid = dsi_encoder_mode_valid,
625692
.mode_set = dsi_encoder_mode_set,
626693
.enable = dsi_encoder_enable,
627694
.disable = dsi_encoder_disable

‎drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ static void ade_init(struct ade_hw_ctx *ctx)
178178
FRM_END_START_MASK, REG_EFFECTIVE_IN_ADEEN_FRMEND);
179179
}
180180

181+
static bool ade_crtc_mode_fixup(struct drm_crtc *crtc,
182+
const struct drm_display_mode *mode,
183+
struct drm_display_mode *adjusted_mode)
184+
{
185+
struct ade_crtc *acrtc = to_ade_crtc(crtc);
186+
struct ade_hw_ctx *ctx = acrtc->ctx;
187+
188+
adjusted_mode->clock =
189+
clk_round_rate(ctx->ade_pix_clk, mode->clock * 1000) / 1000;
190+
return true;
191+
}
192+
193+
181194
static void ade_set_pix_clk(struct ade_hw_ctx *ctx,
182195
struct drm_display_mode *mode,
183196
struct drm_display_mode *adj_mode)
@@ -555,6 +568,7 @@ static void ade_crtc_atomic_flush(struct drm_crtc *crtc,
555568
}
556569

557570
static const struct drm_crtc_helper_funcs ade_crtc_helper_funcs = {
571+
.mode_fixup = ade_crtc_mode_fixup,
558572
.mode_set_nofb = ade_crtc_mode_set_nofb,
559573
.atomic_begin = ade_crtc_atomic_begin,
560574
.atomic_flush = ade_crtc_atomic_flush,

0 commit comments

Comments
 (0)