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: 10870705 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 EAB17186E for ; Tue, 26 Mar 2019 09:18:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7DAC2873C for ; Tue, 26 Mar 2019 09:18:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBC5929036; Tue, 26 Mar 2019 09:18:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5211C2902D for ; Tue, 26 Mar 2019 09:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726270AbfCZJR7 (ORCPT ); Tue, 26 Mar 2019 05:17:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:39820 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729334AbfCZJR6 (ORCPT ); Tue, 26 Mar 2019 05:17:58 -0400 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 Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Thomas Zimmermann 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 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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; }