From patchwork Wed Feb 28 17:53:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giulio Benetti X-Patchwork-Id: 10249175 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 422C060384 for ; Wed, 28 Feb 2018 18:01:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37908205AD for ; Wed, 28 Feb 2018 18:01:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C2F828D24; Wed, 28 Feb 2018 18:01:31 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E30EB28D3A for ; Wed, 28 Feb 2018 18:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=aHQ7CR1amOkp3eh7EfWHzQxL0u8xcAtWwz51PJwqqak=; b=OpGpD5NF4Zrj5K0/iAvcitEFKf ntojfCddu+dpDpxoIMpCw2dUzLUXlQtzAygnqc9Cwp4PWzs7XKIMnHOwDrYDvQxRVCbZhdoJ1i4Xb 1dWWANMipnhB/9uqxmPdLvUEpC3SPWB24u2+5elFxnbhG1iISsFpjf/sk+Mpra8URDxn5BQM0457L UdV8C2yml7OC8A/irkMPME51aYc0P9gK+vmaKYYm0W3LLzfMEynEQpZ3o4qR1/oAC11uphiu7cHeW /l7gig60n2KazfpfEHmNGGcqYZF8tcZFgURmIUKfWMQ9z4HYQ7Ug2SfTEVD2s/+yltplso9I3losY m3Pt+lfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1er62Z-0002UH-OG; Wed, 28 Feb 2018 18:01:19 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1er5wP-0005Ta-AV for linux-arm-kernel@bombadil.infradead.org; Wed, 28 Feb 2018 17:54:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/0lxaUU2kkJ9uzrJuGnvPPFfLHPbdXplayaOO6lpqbg=; b=le+3P2aAlouFVsJo3XOAISJ7d Ub13YFfyjubTFUSAULKLfIB9ql0HTQ+2hJPMd7HNoCLpwBb9hXiiUzZeMuzEjZXTAMWhFkPwKwB/m kNAVyea5fwrswKv42HExsBumf4hhHYXyzPhnCYF+wBelhUhUY+S3vcCgXBiz0FHuN1lAc36c2O10F dDhC2+1lGhM0vyM0v9ohs+D2p2vQ2XW/8aHrBm/9Sv/YJK2HOebVJaQ/RFgVoQ338Zxkv2mx4Ca5I bNX7mmSLDOIJGlsZZyLxvlhKnCs0E/DCW00ITqFIqu4U4ZEntWBKZQZ/He47AJQ6EoOZfFoKKvJSE vq7C3hOVw==; Received: from mail.micronovasrl.com ([212.103.203.10]) by merlin.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1er5wM-0001kG-9g for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2018 17:54:55 +0000 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id 73424B00183 for ; Wed, 28 Feb 2018 18:54:43 +0100 (CET) Authentication-Results: mail.micronovasrl.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=micronovasrl.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=micronovasrl.com; h=references:in-reply-to:x-mailer:message-id:date:date:subject :subject:to:from:from; s=dkim; t=1519840482; x=1520704483; bh=9G 5gUo9ed7aBQmpt4ygF1kJFaJeDLRhwRgLv13rMbh4=; b=npIx5SwM5nuYpQ9h5I qsWlz7flImpfh7nZzIAdmDTi7gbD/6ck6wEBV9cN0GZm4/04VO04a9BUGuwbOXkq LWqMAAzhfiDHq8SehrQO4c8khyLw8tsFmnFcBMyLHUVu2Zalle4oYBpbTGtmuplm GM1nZHyo6eejKr0v6pMfkSX+w= X-Virus-Scanned: Debian amavisd-new at mail.micronovasrl.com Received: from mail.micronovasrl.com ([127.0.0.1]) by mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 4bi48GWwgki4 for ; Wed, 28 Feb 2018 18:54:42 +0100 (CET) Received: from localhost.localdomain (62-11-51-166.dialup.tiscali.it [62.11.51.166]) by mail.micronovasrl.com (Postfix) with ESMTPSA id 07385B00A43; Wed, 28 Feb 2018 18:54:41 +0100 (CET) From: Giulio Benetti To: Maxime Ripard Subject: [PATCH 2/2] drm/sun4i: add lvds mode_valid function Date: Wed, 28 Feb 2018 18:53:52 +0100 Message-Id: <1519840432-61489-2-git-send-email-giulio.benetti@micronovasrl.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519840432-61489-1-git-send-email-giulio.benetti@micronovasrl.com> References: <1519840432-61489-1-git-send-email-giulio.benetti@micronovasrl.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180228_125454_511992_E908CFBF X-CRM114-Status: GOOD ( 10.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Chen-Yu Tsai , Giulio Benetti , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP mode_valid function is missing for lvds. Add it based on rgb model, also setting up dclk_min_div and dclk_max_div Signed-off-by: Giulio Benetti --- drivers/gpu/drm/sun4i/sun4i_lvds.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/gpu/drm/sun4i/sun4i_lvds.c b/drivers/gpu/drm/sun4i/sun4i_lvds.c index be3f14d..75223ee 100644 --- a/drivers/gpu/drm/sun4i/sun4i_lvds.c +++ b/drivers/gpu/drm/sun4i/sun4i_lvds.c @@ -46,8 +46,63 @@ static int sun4i_lvds_get_modes(struct drm_connector *connector) return drm_panel_get_modes(tcon->panel); } +static int sun4i_lvds_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) +{ + struct sun4i_lvds *lvds = drm_connector_to_sun4i_lvds(connector); + struct sun4i_tcon *tcon = lvds->tcon; + u32 hsync = mode->hsync_end - mode->hsync_start; + u32 vsync = mode->vsync_end - mode->vsync_start; + unsigned long rate = mode->clock * 1000; + long rounded_rate; + + DRM_DEBUG_DRIVER("Validating modes...\n"); + + if (hsync < 1) + return MODE_HSYNC_NARROW; + + if (hsync > 0x3ff) + return MODE_HSYNC_WIDE; + + if ((mode->hdisplay < 1) || (mode->htotal < 1)) + return MODE_H_ILLEGAL; + + if ((mode->hdisplay > 0x7ff) || (mode->htotal > 0xfff)) + return MODE_BAD_HVALUE; + + DRM_DEBUG_DRIVER("Horizontal parameters OK\n"); + + if (vsync < 1) + return MODE_VSYNC_NARROW; + + if (vsync > 0x3ff) + return MODE_VSYNC_WIDE; + + if ((mode->vdisplay < 1) || (mode->vtotal < 1)) + return MODE_V_ILLEGAL; + + if ((mode->vdisplay > 0x7ff) || (mode->vtotal > 0xfff)) + return MODE_BAD_VVALUE; + + DRM_DEBUG_DRIVER("Vertical parameters OK\n"); + + tcon->dclk_min_div = 7; + tcon->dclk_max_div = 18; + rounded_rate = clk_round_rate(tcon->dclk, rate); + if (rounded_rate < rate) + return MODE_CLOCK_LOW; + + if (rounded_rate > rate) + return MODE_CLOCK_HIGH; + + DRM_DEBUG_DRIVER("Clock rate OK\n"); + + return MODE_OK; +} + static struct drm_connector_helper_funcs sun4i_lvds_con_helper_funcs = { .get_modes = sun4i_lvds_get_modes, + .mode_valid = sun4i_lvds_mode_valid, }; static void