From patchwork Mon Sep 18 16:20:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9957111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30F3160385 for ; Mon, 18 Sep 2017 16:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 214441FEB1 for ; Mon, 18 Sep 2017 16:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15FB52873E; Mon, 18 Sep 2017 16:20:35 +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=-6.9 required=2.0 tests=BAYES_00,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 AFFCE1FEB1 for ; Mon, 18 Sep 2017 16:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756073AbdIRQUe (ORCPT ); Mon, 18 Sep 2017 12:20:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53626 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756040AbdIRQUd (ORCPT ); Mon, 18 Sep 2017 12:20:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE89B81F07; Mon, 18 Sep 2017 16:20:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AE89B81F07 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=hdegoede@redhat.com Received: from shalem.localdomain.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA0845D981; Mon, 18 Sep 2017 16:20:31 +0000 (UTC) From: Hans de Goede To: Daniel Vetter , Jani Nikula , Sean Paul , David Airlie , Bartlomiej Zolnierkiewicz Cc: Hans de Goede , Bastien Nocera , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: [PATCH v2 4/4] drm/fb-helper: Apply panel orientation connector prop to the primary plane Date: Mon, 18 Sep 2017 18:20:21 +0200 Message-Id: <20170918162021.12021-4-hdegoede@redhat.com> In-Reply-To: <20170918162021.12021-1-hdegoede@redhat.com> References: <20170918162021.12021-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 18 Sep 2017 16:20:33 +0000 (UTC) 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 Apply the "panel orientation" drm connector prop to the primary plane, so that fbcon and fbdev using userspace programs display the right way up. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=94894 Signed-off-by: Hans de Goede --- Changes in v2: -New patch in v2 of this patch-set --- drivers/gpu/drm/drm_fb_helper.c | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 1b8f013ffa65..75c409430a26 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -41,6 +41,7 @@ #include #include +#include "drm_crtc_internal.h" #include "drm_crtc_helper_internal.h" static bool drm_fbdev_emulation = true; @@ -347,6 +348,53 @@ int drm_fb_helper_debug_leave(struct fb_info *info) } EXPORT_SYMBOL(drm_fb_helper_debug_leave); +static int get_plane_rotation_from_panel_orientation( + struct drm_fb_helper *fb_helper, struct drm_plane *plane) +{ + int i, rotation = DRM_MODE_ROTATE_0; + struct drm_connector *conn; + uint64_t valid_mask = 0; + + drm_fb_helper_for_each_connector(fb_helper, i) { + conn = fb_helper->connector_info[i]->connector; + if (conn->state->crtc && conn->state->crtc->primary == plane) { + switch (conn->display_info.panel_orientation) { + case DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP: + rotation = DRM_MODE_ROTATE_180; + break; + case DRM_MODE_PANEL_ORIENTATION_LEFT_UP: + rotation = DRM_MODE_ROTATE_90; + break; + case DRM_MODE_PANEL_ORIENTATION_RIGHT_UP: + rotation = DRM_MODE_ROTATE_270; + break; + } + break; + } + } + + /* + * Check the necessary rotation to compensate for the panel orientation + * is supported. + * Note currently we simply leave things as is when not supported, maybe + * we shouls set a hint in fb_info to tell fbcon to rotate in this case + * so that atleast the console ends up the right way. Maybe, but this: + * a) Is not necessary for any known models with a non upright panel + * b) Is tricky because fbcon rotation applies to all outputs rather + * then a single one + */ + if (!plane->rotation_property) + return DRM_MODE_ROTATE_0; + + for (i = 0; i < plane->rotation_property->num_values; i++) + valid_mask |= (1ULL << plane->rotation_property->values[i]); + + if (rotation & ~valid_mask) + return DRM_MODE_ROTATE_0; + + return rotation; +} + static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool active) { struct drm_device *dev = fb_helper->dev; @@ -376,8 +424,9 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ goto out_state; } - plane_state->rotation = DRM_MODE_ROTATE_0; - + plane_state->rotation = + get_plane_rotation_from_panel_orientation(fb_helper, + plane); plane->old_fb = plane->fb; plane_mask |= 1 << drm_plane_index(plane);