From patchwork Tue Mar 26 09:17:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 10870717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95EBF15AC for ; Tue, 26 Mar 2019 09:18:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FB132873C for ; Tue, 26 Mar 2019 09:18:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73FC229035; Tue, 26 Mar 2019 09:18:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F28872873C for ; Tue, 26 Mar 2019 09:18:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9809A6E7B8; Tue, 26 Mar 2019 09:18:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 204E26E7B5 for ; Tue, 26 Mar 2019 09:17:58 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AEFF7AE27; Tue, 26 Mar 2019 09:17:56 +0000 (UTC) From: Thomas Zimmermann To: airlied@linux.ie, daniel@ffwll.ch, b.zolnierkie@samsung.com Subject: [PATCH 10/11] drm/fbdevdrm: Add CRTC Date: Tue, 26 Mar 2019 10:17:43 +0100 Message-Id: <20190326091744.11542-11-tzimmermann@suse.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326091744.11542-1-tzimmermann@suse.de> References: <20190326091744.11542-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 150 +++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c index 3473b85acbf1..87f56ec76edf 100644 --- a/drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +++ b/drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c @@ -18,10 +18,18 @@ #include #include #include +#include #include #include +#include "fbdevdrm_modes.h" #include "fbdevdrm_primary.h" +static struct fbdevdrm_modeset* fbdevdrm_modeset_of_crtc( + struct drm_crtc *crtc) +{ + return container_of(crtc, struct fbdevdrm_modeset, crtc); +} + /* * CRTC */ @@ -29,18 +37,124 @@ static enum drm_mode_status crtc_helper_mode_valid( struct drm_crtc *crtc, const struct drm_display_mode *mode) { + static const unsigned char bits_per_pixel[] = { + 32, 16, 8, 24, 15 + }; + + struct fbdevdrm_modeset *modeset; + struct fb_var_screeninfo fb_var; + size_t i; + int ret; + + modeset = fbdevdrm_modeset_of_crtc(crtc); + + if (!modeset->fb_info->fbops->fb_check_var) + return MODE_OK; + + for (i = 0; i < ARRAY_SIZE(bits_per_pixel); ++i) { + + memcpy(&fb_var, &modeset->fb_info->var, sizeof(fb_var)); + fbdevdrm_update_fb_var_screeninfo_from_mode(&fb_var, mode); + fb_var.bits_per_pixel = bits_per_pixel[i]; + + ret = modeset->fb_info->fbops->fb_check_var(&fb_var, modeset->fb_info); + if (ret) + continue; /* generally not supported */ + if ((mode->hdisplay != fb_var.xres) || + (mode->vdisplay != fb_var.yres)) + continue; /* unsupported resolution */ + if (KHZ2PICOS(mode->clock) != fb_var.pixclock) + continue; /* unsupported pixel clock */ + + break; /* mode successfully tested */ + } + if (i == ARRAY_SIZE(bits_per_pixel)) + return MODE_BAD; /* mode is not support */ + return MODE_OK; } +static int fbdevdrm_update_fb_var_screeninfo_from_crtc( + struct fb_var_screeninfo *fb_var, struct drm_crtc* crtc) +{ + struct drm_plane *primary = crtc->primary; + struct fbdevdrm_modeset *modeset = fbdevdrm_modeset_of_crtc(crtc); + + if (primary && primary->state && primary->state->fb) + return fbdevdrm_update_fb_var_screeninfo_from_framebuffer( + fb_var, primary->state->fb, + modeset->fb_info->fix.smem_len); + + fb_var->xres_virtual = fb_var->xres; + fb_var->yres_virtual = fb_var->yres; + fb_var->bits_per_pixel = modeset->dev->mode_config.preferred_depth; + + return 0; +} + static bool crtc_helper_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { + struct fbdevdrm_modeset *modeset; + struct fb_var_screeninfo fb_var; + int ret; + + modeset = fbdevdrm_modeset_of_crtc(crtc); + + if (!modeset->fb_info->fbops->fb_check_var) + return true; + + fbdevdrm_init_fb_var_screeninfo_from_mode(&fb_var, mode); + + ret = fbdevdrm_update_fb_var_screeninfo_from_crtc(&fb_var, crtc); + if (ret) + return true; + + ret = modeset->fb_info->fbops->fb_check_var(&fb_var, modeset->fb_info); + if (ret < 0) + return false; + + drm_mode_update_from_fb_var_screeninfo(adjusted_mode, &fb_var); + return true; } static void crtc_helper_mode_set_nofb(struct drm_crtc *crtc) -{ } +{ + struct fbdevdrm_modeset *modeset; + struct fb_var_screeninfo fb_var; + int ret; + + /* As this is atomic mode setting, any function call is not + * allowed to fail. If it does, an additional test should be + * added to crtc_helper_atomic_check(). + */ + + modeset = fbdevdrm_modeset_of_crtc(crtc); + + memset(&fb_var, 0, sizeof(fb_var)); + fbdevdrm_update_fb_var_screeninfo_from_mode(&fb_var, &crtc->state->adjusted_mode); + + if (crtc->primary && crtc->primary->state && crtc->primary->state->fb) { + ret = fbdevdrm_update_fb_var_screeninfo_from_framebuffer( + &fb_var, crtc->primary->state->fb, + modeset->fb_info->fix.smem_len); + if (ret) + return; + } else { + fb_var.xres_virtual = fb_var.xres; + fb_var.yres_virtual = fb_var.yres; + } + + fb_var.activate = FB_ACTIVATE_NOW; + + ret = fb_set_var(modeset->fb_info, &fb_var); + if (ret) { + DRM_ERROR("fbdevdrm: fb_set_var() failed: %d\n", ret); + return; + } +} static int crtc_helper_mode_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, @@ -53,6 +167,40 @@ static int crtc_helper_mode_set_base_atomic(struct drm_crtc *crtc, static int crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state) { + struct fbdevdrm_modeset *modeset; + struct fb_videomode fb_mode, fb_var_mode; + + modeset = fbdevdrm_modeset_of_crtc(crtc); + + /* DRM porting notes: when fbcon takes over the console, it regularly + * changes the display mode. Where's apparently no way to detect this + * directly from fbcon itself. DRM's mode information might therefore + * be out of data, after it takes over the display at a later time. + * Here, we test the CRTC's current mode with the fbdev state. If they + * do not match, we request a mode change from DRM. If you port an + * fbdev driver to DRM, you can remove this code section, DRM will + * be in full control of the display device and doesn't have to react + * to changes from external sources. + */ + + if (!state->mode_changed && state->adjusted_mode.clock) { + fbdevdrm_init_fb_videomode_from_mode(&fb_mode, &state->adjusted_mode); + fb_var_to_videomode(&fb_var_mode, &modeset->fb_info->var); + if (!fb_mode_is_equal(&fb_mode, &fb_var_mode)) + state->mode_changed = true; + } + + /* TODO: The vblank interupt is currently not supported. We set + * the corresponding flag as a workaround. Some fbdev drivers + * support FBIO_WAITFORVSYNC, which we might use for querying + * vblanks. + * + * DRM porting notes: if you're porting an fbdev driver to DRM, + * remove this line and instead signal a vblank event from the + * interupt handler. + */ + state->no_vblank = true; + return 0; }