From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch, b.zolnierkie@samsung.com
Cc: linux-fbdev@vger.kernel.org,
Thomas Zimmermann <tzimmermann@suse.de>,
dri-devel@lists.freedesktop.org
Subject: [PATCH 08/11] drm/fbdevdrm: Add mode conversion DRM <-> fbdev
Date: Tue, 26 Mar 2019 10:17:41 +0100 [thread overview]
Message-ID: <20190326091744.11542-9-tzimmermann@suse.de> (raw)
In-Reply-To: <20190326091744.11542-1-tzimmermann@suse.de>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/fbdevdrm/Makefile | 1 +
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 153 ++++++++++++++++++++++
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 46 +++++++
3 files changed, 200 insertions(+)
create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c
create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h
diff --git a/drivers/gpu/drm/fbdevdrm/Makefile b/drivers/gpu/drm/fbdevdrm/Makefile
index aef60d0f4888..2ca906a3258b 100644
--- a/drivers/gpu/drm/fbdevdrm/Makefile
+++ b/drivers/gpu/drm/fbdevdrm/Makefile
@@ -3,6 +3,7 @@ fbdevdrm-y := fbdevdrm_bo.o \
fbdevdrm_device.o \
fbdevdrm_drv.o \
fbdevdrm_format.o \
+ fbdevdrm_modes.o \
fbdevdrm_modeset.o \
fbdevdrm_ttm.o
diff --git a/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c
new file mode 100644
index 000000000000..bd3ad691e7ce
--- /dev/null
+++ b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * One purpose of this driver is to allow for easy conversion of framebuffer
+ * drivers to DRM. As a special exception to the GNU GPL, you are allowed to
+ * relicense this file under the terms of a license of your choice if you're
+ * porting a framebuffer driver. In order to do so, update the SPDX license
+ * identifier to the new license and remove this exception.
+ *
+ * If you add code to this file, please ensure that it's compatible with the
+ * stated exception.
+ */
+
+#include "fbdevdrm_modes.h"
+#include <drm/drm_modes.h>
+#include <linux/fb.h>
+
+void drm_mode_update_from_fb_videomode(struct drm_display_mode *mode,
+ const struct fb_videomode *fb_mode)
+{
+ mode->type = DRM_MODE_TYPE_DRIVER;
+
+ mode->clock = PICOS2KHZ(fb_mode->pixclock);
+
+ mode->hdisplay = fb_mode->xres;
+ mode->hsync_start = mode->hdisplay + fb_mode->right_margin;
+ mode->hsync_end = mode->hsync_start + fb_mode->hsync_len;
+ mode->htotal = mode->hsync_end + fb_mode->left_margin;
+ mode->hskew = 0;
+
+ mode->vdisplay = fb_mode->yres;
+ mode->vsync_start = mode->vdisplay + fb_mode->lower_margin;
+ mode->vsync_end = mode->vsync_start + fb_mode->vsync_len;
+ mode->vtotal = mode->vsync_end + fb_mode->upper_margin;
+ mode->vscan = 0;
+
+ mode->flags = 0;
+
+ if (fb_mode->sync & FB_SYNC_HOR_HIGH_ACT)
+ mode->flags |= DRM_MODE_FLAG_PHSYNC;
+ else
+ mode->flags |= DRM_MODE_FLAG_NHSYNC;
+
+ if (fb_mode->sync & FB_SYNC_VERT_HIGH_ACT)
+ mode->flags |= DRM_MODE_FLAG_PVSYNC;
+ else
+ mode->flags |= DRM_MODE_FLAG_NVSYNC;
+
+ if (fb_mode->sync & FB_SYNC_COMP_HIGH_ACT)
+ mode->flags |= DRM_MODE_FLAG_CSYNC | DRM_MODE_FLAG_PCSYNC;
+
+ if (fb_mode->vmode & FB_VMODE_INTERLACED)
+ mode->flags |= DRM_MODE_FLAG_INTERLACE;
+
+ if (fb_mode->vmode & FB_VMODE_DOUBLE)
+ mode->flags |= DRM_MODE_FLAG_DBLSCAN;
+
+ mode->width_mm = 0;
+ mode->height_mm = 0;
+
+ mode->vrefresh = fb_mode->refresh;
+ mode->hsync = mode->clock / mode->vtotal;
+
+ /* final step; depends on previous setup */
+ if (fb_mode->name) {
+ strncpy(mode->name, fb_mode->name, sizeof(mode->name) - 1);
+ mode->name[sizeof(mode->name) - 1] = '\0';
+ } else {
+ drm_mode_set_name(mode);
+ }
+}
+
+void drm_mode_update_from_fb_var_screeninfo(
+ struct drm_display_mode *mode, const struct fb_var_screeninfo *fb_var)
+{
+ struct fb_videomode fb_mode;
+
+ fb_var_to_videomode(&fb_mode, fb_var);
+ drm_mode_update_from_fb_videomode(mode, &fb_mode);
+}
+
+struct drm_display_mode* drm_mode_create_from_fb_videomode(
+ struct drm_device *dev, const struct fb_videomode *fb_mode)
+{
+ /* cleared to '0' */
+ struct drm_display_mode *mode = drm_mode_create(dev);
+ if (!mode)
+ return NULL;
+
+ drm_mode_update_from_fb_videomode(mode, fb_mode);
+
+ return mode;
+}
+
+void
+fbdevdrm_update_fb_videomode_from_mode(struct fb_videomode *fb_mode,
+ const struct drm_display_mode *mode)
+{
+ fb_mode->name = NULL;
+ fb_mode->refresh = mode->vrefresh;
+ fb_mode->xres = mode->hdisplay;
+ fb_mode->yres = mode->vdisplay;
+ fb_mode->pixclock = KHZ2PICOS(mode->clock);
+ fb_mode->left_margin = mode->htotal - mode->hsync_end;
+ fb_mode->right_margin = mode->hsync_start - mode->hdisplay;
+ fb_mode->upper_margin = mode->vtotal - mode->vsync_end;
+ fb_mode->lower_margin = mode->vsync_start - mode->vdisplay;
+ fb_mode->hsync_len = mode->hsync_end - mode->hsync_start;
+ fb_mode->vsync_len = mode->vsync_end - mode->vsync_start;
+
+ fb_mode->sync = 0;
+ if (mode->flags & DRM_MODE_FLAG_PHSYNC)
+ fb_mode->sync |= FB_SYNC_HOR_HIGH_ACT;
+ if (mode->flags & DRM_MODE_FLAG_PVSYNC)
+ fb_mode->sync |= FB_SYNC_VERT_HIGH_ACT;
+ if (mode->flags & (DRM_MODE_FLAG_CSYNC | DRM_MODE_FLAG_PCSYNC))
+ fb_mode->sync |= FB_SYNC_COMP_HIGH_ACT;
+
+ fb_mode->vmode = 0;
+ if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+ fb_mode->vmode |= FB_VMODE_INTERLACED;
+ if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
+ fb_mode->vmode |= FB_VMODE_DOUBLE;
+
+ fb_mode->flag = 0;
+}
+
+void
+fbdevdrm_init_fb_videomode_from_mode(struct fb_videomode *fb_mode,
+ const struct drm_display_mode *mode)
+{
+ memset(fb_mode, 0, sizeof(*fb_mode));
+ fbdevdrm_update_fb_videomode_from_mode(fb_mode, mode);
+}
+
+void
+fbdevdrm_update_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *fb_var,
+ const struct drm_display_mode *mode)
+{
+ struct fb_videomode fb_mode;
+ fbdevdrm_init_fb_videomode_from_mode(&fb_mode, mode);
+ fb_videomode_to_var(fb_var, &fb_mode);
+
+ fb_var->height = mode->height_mm;
+ fb_var->width = mode->width_mm;
+}
+
+void
+fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *fb_var,
+ const struct drm_display_mode *mode)
+{
+ memset(fb_var, 0, sizeof(*fb_var));
+ fbdevdrm_update_fb_var_screeninfo_from_mode(fb_var, mode);
+}
diff --git a/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h
new file mode 100644
index 000000000000..f88a86a83858
--- /dev/null
+++ b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * One purpose of this driver is to allow for easy conversion of framebuffer
+ * drivers to DRM. As a special exception to the GNU GPL, you are allowed to
+ * relicense this file under the terms of a license of your choice if you're
+ * porting a framebuffer driver. In order to do so, update the SPDX license
+ * identifier to the new license and remove this exception.
+ *
+ * If you add code to this file, please ensure that it's compatible with the
+ * stated exception.
+ */
+
+#ifndef FBDEVDRM_MODES_H
+#define FBDEVDRM_MODES_H
+
+struct drm_device;
+struct drm_display_mode;
+struct fb_videomode;
+struct fb_var_screeninfo;
+
+void drm_mode_update_from_fb_videomode(struct drm_display_mode *mode,
+ const struct fb_videomode *fb_mode);
+
+void drm_mode_update_from_fb_var_screeninfo(
+ struct drm_display_mode *mode, const struct fb_var_screeninfo *fb_var);
+
+struct drm_display_mode* drm_mode_create_from_fb_videomode(
+ struct drm_device *dev, const struct fb_videomode *fb_mode);
+
+void
+fbdevdrm_update_fb_videomode_from_mode(struct fb_videomode *fb_mode,
+ const struct drm_display_mode *mode);
+
+void
+fbdevdrm_init_fb_videomode_from_mode(struct fb_videomode *fb_mode,
+ const struct drm_display_mode *mode);
+
+void
+fbdevdrm_update_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var,
+ const struct drm_display_mode *mode);
+
+void
+fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var,
+ const struct drm_display_mode *mode);
+
+#endif
--
2.21.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-03-26 9:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 9:17 [RFC][PATCH 00/11] DRM driver for fbdev devices Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 01/11] drm/fbdevdrm: Add driver skeleton Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 02/11] drm/fbdevdrm: Add fbdevdrm device Thomas Zimmermann
2019-03-26 16:03 ` Adam Jackson
2019-03-27 7:55 ` Thomas Zimmermann
2019-03-27 8:03 ` Daniel Vetter
2019-03-26 9:17 ` [PATCH 03/11] drm/fbdevdrm: Add memory management Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 04/11] drm/fbdevdrm: Add file operations Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 05/11] drm/fbdevdrm: Add GEM and dumb interfaces Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 06/11] drm/fbdevdrm: Add modesetting infrastructure Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 07/11] drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion Thomas Zimmermann
2019-03-26 16:29 ` Ville Syrjälä
2019-03-27 8:28 ` Thomas Zimmermann
2019-03-27 10:00 ` Ville Syrjälä
2019-03-26 9:17 ` Thomas Zimmermann [this message]
2019-03-26 9:17 ` [PATCH 09/11] drm/fbdevdrm: Add primary plane Thomas Zimmermann
2019-03-26 13:33 ` Mathieu Malaterre
2019-03-26 13:57 ` Thomas Zimmermann
2019-03-27 9:37 ` Thomas Zimmermann
2019-04-02 7:08 ` Mathieu Malaterre
2019-03-26 9:17 ` [PATCH 10/11] drm/fbdevdrm: Add CRTC Thomas Zimmermann
2019-03-26 9:17 ` [PATCH 11/11] drm/fbdevdrm: Detect and validate display modes Thomas Zimmermann
2019-03-26 16:47 ` Ville Syrjälä
2019-03-26 18:20 ` Daniel Vetter
2019-03-27 8:31 ` Thomas Zimmermann
2019-03-26 14:53 ` [RFC][PATCH 00/11] DRM driver for fbdev devices Daniel Vetter
2019-03-27 9:10 ` Thomas Zimmermann
2019-03-27 9:41 ` Daniel Vetter
2019-03-27 9:55 ` Michel Dänzer
2019-03-27 10:58 ` Daniel Vetter
2019-03-27 14:46 ` Thomas Zimmermann
2019-03-27 17:05 ` Daniel Vetter
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=20190326091744.11542-9-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@linux.ie \
--cc=b.zolnierkie@samsung.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fbdev@vger.kernel.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