summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/mediatek/mtk_disp_merge.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/mediatek/mtk_disp_merge.c')
-rw-r--r--drivers/gpu/drm/mediatek/mtk_disp_merge.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_merge.c b/drivers/gpu/drm/mediatek/mtk_disp_merge.c
index 22f768d923d5..32a29924bd54 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_merge.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_merge.c
@@ -222,6 +222,71 @@ void mtk_merge_clk_disable(struct device *dev)
clk_disable_unprepare(priv->clk);
}
+enum drm_mode_status mtk_merge_mode_valid(struct device *dev,
+ const struct drm_display_mode *mode)
+{
+ struct mtk_disp_merge *priv = dev_get_drvdata(dev);
+ unsigned long rate;
+
+ rate = clk_get_rate(priv->clk);
+
+ /* Convert to KHz and round the number */
+ rate = (rate + 500) / 1000;
+
+ if (rate && mode->clock > rate) {
+ dev_dbg(dev, "invalid clock: %d (>%lu)\n", mode->clock, rate);
+ return MODE_CLOCK_HIGH;
+ }
+
+ /*
+ * Measure the bandwidth requirement of hardware prefetch (per frame)
+ *
+ * let N = prefetch buffer size in lines
+ * (ex. N=3, then prefetch buffer size = 3 lines)
+ *
+ * prefetch size = htotal * N (pixels)
+ * time per line = 1 / fps / vtotal (seconds)
+ * duration = vbp * time per line
+ * = vbp / fps / vtotal
+ *
+ * data rate = prefetch size / duration
+ * = htotal * N / (vbp / fps / vtotal)
+ * = htotal * vtotal * fps * N / vbp
+ * = clk * N / vbp (pixels per second)
+ *
+ * Say 4K60 (CEA-861) is the maximum mode supported by the SoC
+ * data rate = 594000K * N / 72 = 8250 (standard)
+ * (remove K * N due to the same unit)
+ *
+ * For 2560x1440@144 (clk=583600K, vbp=17):
+ * data rate = 583600 / 17 ~= 34329 > 8250 (NG)
+ *
+ * For 2560x1440@120 (clk=497760K, vbp=77):
+ * data rate = 497760 / 77 ~= 6464 < 8250 (OK)
+ *
+ * A non-standard 4K60 timing (clk=521280K, vbp=54)
+ * data rate = 521280 / 54 ~= 9653 > 8250 (NG)
+ *
+ * Bandwidth requirement of hardware prefetch increases significantly
+ * when the VBP decreases (more than 4x in this example).
+ *
+ * The proposed formula is only one way to estimate whether our SoC
+ * supports the mode setting. The basic idea behind it is just to check
+ * if the data rate requirement is too high (directly proportional to
+ * pixel clock, inversely proportional to vbp). Please adjust the
+ * function if it doesn't fit your situation in the future.
+ */
+ rate = mode->clock / (mode->vtotal - mode->vsync_end);
+
+ if (rate > 8250) {
+ dev_dbg(dev, "invalid rate: %lu (>8250): " DRM_MODE_FMT "\n",
+ rate, DRM_MODE_ARG(mode));
+ return MODE_BAD;
+ }
+
+ return MODE_OK;
+}
+
static int mtk_disp_merge_bind(struct device *dev, struct device *master,
void *data)
{