mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 11/16] video: factor out drm_mode_vrefresh
Date: Thu,  5 Jun 2025 23:07:21 +0200	[thread overview]
Message-ID: <20250605210726.1916656-12-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250605210726.1916656-1-a.fatoum@barebox.org>

This function is going to be used for the incoming MIPI-DSI support, so
let's make it reusable.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/Makefile                     |  1 +
 drivers/video/drm/Makefile                 |  2 +
 drivers/video/drm/drm_modes.c              | 67 ++++++++++++++++++++++
 drivers/video/rockchip/rockchip_drm_vop2.c | 13 -----
 include/video/drm/drm_modes.h              |  2 +
 5 files changed, 72 insertions(+), 13 deletions(-)
 create mode 100644 drivers/video/drm/Makefile
 create mode 100644 drivers/video/drm/drm_modes.c

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index f851837ebcdb..dde1da1bb98b 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_VIDEO) += fb.o mode-helpers.o
+obj-$(CONFIG_VIDEO) += drm/
 obj-$(CONFIG_DRIVER_VIDEO_EDID) += edid.o
 obj-$(CONFIG_OFDEVICE) += of_display_timing.o
 obj-$(CONFIG_DRIVER_VIDEO_BACKLIGHT) += backlight.o
diff --git a/drivers/video/drm/Makefile b/drivers/video/drm/Makefile
new file mode 100644
index 000000000000..06d586eb2184
--- /dev/null
+++ b/drivers/video/drm/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_VIDEO) += drm_modes.o
diff --git a/drivers/video/drm/drm_modes.c b/drivers/video/drm/drm_modes.c
new file mode 100644
index 000000000000..00fcfb9070ae
--- /dev/null
+++ b/drivers/video/drm/drm_modes.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 1997-2003 by The XFree86 Project, Inc.
+ * Copyright © 2007 Dave Airlie
+ * Copyright © 2007-2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ * Copyright 2005-2006 Luc Verhaegen
+ * Copyright (c) 2001, Andy Ritger  aritger@nvidia.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+#include <linux/ctype.h>
+#include <linux/export.h>
+#include <linux/list.h>
+#include <of.h>
+
+#include <video/drm/drm_modes.h>
+
+/**
+ * drm_mode_vrefresh - get the vrefresh of a mode
+ * @mode: mode
+ *
+ * Returns:
+ * @modes's vrefresh rate in Hz, rounded to the nearest integer. Calculates the
+ * value first if it is not yet set.
+ */
+int drm_mode_vrefresh(const struct drm_display_mode *mode)
+{
+	unsigned int num, den;
+
+	if (mode->htotal == 0 || mode->vtotal == 0)
+		return 0;
+
+	num = mode->clock;
+	den = mode->htotal * mode->vtotal;
+
+	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+		num *= 2;
+	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
+		den *= 2;
+	if (mode->vscan > 1)
+		den *= mode->vscan;
+
+	return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
+}
+EXPORT_SYMBOL(drm_mode_vrefresh);
diff --git a/drivers/video/rockchip/rockchip_drm_vop2.c b/drivers/video/rockchip/rockchip_drm_vop2.c
index b49053c6e915..d81e0357528b 100644
--- a/drivers/video/rockchip/rockchip_drm_vop2.c
+++ b/drivers/video/rockchip/rockchip_drm_vop2.c
@@ -975,19 +975,6 @@ static int us_to_vertical_line(struct drm_display_mode *mode, int us)
 	return us * mode->clock / mode->htotal / 1000;
 }
 
-static int drm_mode_vrefresh(const struct drm_display_mode *mode)
-{
-	unsigned int num, den;
-
-	if (mode->htotal == 0 || mode->vtotal == 0)
-		return 0;
-
-	num = mode->clock;
-	den = mode->htotal * mode->vtotal;
-
-	return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
-}
-
 static void vop2_crtc_atomic_enable(struct vop2_video_port *vp,
 				    struct drm_display_mode *mode,
 				    struct rockchip_crtc_state *vcstate)
diff --git a/include/video/drm/drm_modes.h b/include/video/drm/drm_modes.h
index afce8a25a9c4..003c76cab6e0 100644
--- a/include/video/drm/drm_modes.h
+++ b/include/video/drm/drm_modes.h
@@ -406,4 +406,6 @@ struct drm_display_mode {
 	enum drm_mode_status status;
 };
 
+int drm_mode_vrefresh(const struct drm_display_mode *mode);
+
 #endif /* __DRM_MODES_H__ */
-- 
2.39.5




  parent reply	other threads:[~2025-06-05 21:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 21:07 [PATCH 00/16] ARM: stm32mp: add MIPI DSI support Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 01/16] driver: bus: embed bus driver node into bus Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 02/16] driver: switch busses to device class Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 03/16] driver: factor out bus definitions into separate header Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 04/16] driver: bus: add helpers for finding devices in busses Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 05/16] drive: bus: make use of new bus_find_device helper Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 06/16] of: implement of_alias_from_compatible Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 07/16] video: vpl: fix potential read of uninitialized variable Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 08/16] video: vpl: factor out vpl_for_each Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 09/16] video: vpl: handle missing struct vpl::ioctl gracefully Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 10/16] video: vpl: add vpl_bridge abstraction Ahmad Fatoum
2025-06-05 21:07 ` Ahmad Fatoum [this message]
2025-06-05 21:07 ` [PATCH 12/16] video: add base MIPI DSI support Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 13/16] video: add Designware MIPI-DSI support Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 14/16] video: add STM32 MIPI DSI video driver Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 15/16] video: add support for Orise Technology otm8009a panel Ahmad Fatoum
2025-06-05 21:07 ` [PATCH 16/16] ARM: stm32mp: dk2: enable MIPI-DSI display by default Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250605210726.1916656-12-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox