From patchwork Sun Jan 8 16:56:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13092612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9140AC54EBE for ; Sun, 8 Jan 2023 16:57:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233647AbjAHQ5I (ORCPT ); Sun, 8 Jan 2023 11:57:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233508AbjAHQ5F (ORCPT ); Sun, 8 Jan 2023 11:57:05 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C0D10BE for ; Sun, 8 Jan 2023 08:57:03 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id bu8so9541177lfb.4 for ; Sun, 08 Jan 2023 08:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MojOF/93S3oRnJzgKxf5e9Ahv/idd5WHTFRxpckdje4=; b=NVoMZ4UsQCrJrNJ7HOzJjuxjLBZIqv0YV6mjO8mPCnwLdIhMPLMGTK53xmunEV2Uzi 6Q4YontEyKBHramQL4VWbOCJDfdqtbE/1yr2XqSrk/W63H+f4OWFwEWlDwbY97+62CC7 Dk3a1TvVlwmYtiPQV6XU1msAMT7CvhAcxg1Xv38EY6iYvOlm7CjKx4lHyuVlwKtKBwnn 2cHn6MP9rmyTJDx4dhgsZdjAMIH+vX3Lzjz5IP35TJqiPcbcpobNPt5FWNpP85FYjCSS IdD1xXAJa5ZcAafeg9mjlXClHWDL7+CbKvWt9K49DkB8Z/YUD0KFOL8EHEtuKgSQW/ia C2cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MojOF/93S3oRnJzgKxf5e9Ahv/idd5WHTFRxpckdje4=; b=6tlpVc/TWx1JXq222qhuBfltnT+vUixwPrhEloWt8GTDI+BoIxF2TabafH3LoCf5oY xnpIuTVg7C1RAwqVYwmC3vhq5N3tTrpDWr+e8XImxqj1QBOru41PxyIxi22SCxZ3KED4 MVkMZug6eyhm8GodEgk9dYEH6YY0DiljKSkzgl8M0Zdq1VDecjQg958vfW6PtUmQGUx/ ZLjoWoDo9CWzfBi8Z2pyJuduo8Z+T61k1ER3tqvVb3i3oxuSBoeGuwB7sR+vj990ZBdU thawvt7ohFMVu84hFbYJHy635VemB8HD3itk8KosUm4OaL1A2C1RbeU79szG7fjvQ5TR YCfw== X-Gm-Message-State: AFqh2kozhoJXEM98MjE+VtE69BtHfbgLHJVQC69CfM7G5jw7wdfmjWaX cRt/lSxUcmyYPbbvB2yyRoFqRg== X-Google-Smtp-Source: AMrXdXunAi3Qs/UsltE/4C3BiyKCtj35mVl/rTsTQ1cm7lLeqYZjG3D7mOMqNozk8oB+vMDfwPSXFQ== X-Received: by 2002:a05:6512:2349:b0:4a4:68b9:66cd with SMTP id p9-20020a056512234900b004a468b966cdmr17233207lfu.24.1673197021375; Sun, 08 Jan 2023 08:57:01 -0800 (PST) Received: from eriador.lan (dzccz6yyyyyyyyyyybcwt-3.rev.dnainternet.fi. [2001:14ba:a085:4d00::8a5]) by smtp.gmail.com with ESMTPSA id s2-20020a056512202200b004b561b211adsm1138323lfs.254.2023.01.08.08.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 08:57:01 -0800 (PST) From: Dmitry Baryshkov To: Vinod Koul , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2 05/13] drm/bridge: lt9611: fix clock calculation Date: Sun, 8 Jan 2023 18:56:48 +0200 Message-Id: <20230108165656.136871-6-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230108165656.136871-1-dmitry.baryshkov@linaro.org> References: <20230108165656.136871-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Instead of having several fixed values for the pcr register, calculate it before programming. This allows the bridge to support most of the display modes. Fixes: 23278bf54afe ("drm/bridge: Introduce LT9611 DSI to HDMI bridge") Signed-off-by: Dmitry Baryshkov Reviewed-by: Neil Armstrong --- drivers/gpu/drm/bridge/lontium-lt9611.c | 32 +++++++++++-------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/bridge/lontium-lt9611.c index f377052a45a4..e2799a0df8f8 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611.c @@ -192,8 +192,9 @@ static void lt9611_mipi_video_setup(struct lt9611 *lt9611, regmap_write(lt9611->regmap, 0x831b, (u8)(hsync_porch % 256)); } -static void lt9611_pcr_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode) +static void lt9611_pcr_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode, unsigned int postdiv) { + unsigned int pcr_m = mode->clock * 5 * postdiv / 27000; const struct reg_sequence reg_cfg[] = { { 0x830b, 0x01 }, { 0x830c, 0x10 }, @@ -236,24 +237,14 @@ static void lt9611_pcr_setup(struct lt9611 *lt9611, const struct drm_display_mod else regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); - switch (mode->hdisplay) { - case 640: - regmap_write(lt9611->regmap, 0x8326, 0x14); - break; - case 1920: - regmap_write(lt9611->regmap, 0x8326, 0x37); - break; - case 3840: - regmap_write(lt9611->regmap, 0x8326, 0x37); - break; - } + regmap_write(lt9611->regmap, 0x8326, pcr_m); /* pcr rst */ regmap_write(lt9611->regmap, 0x8011, 0x5a); regmap_write(lt9611->regmap, 0x8011, 0xfa); } -static int lt9611_pll_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode) +static int lt9611_pll_setup(struct lt9611 *lt9611, const struct drm_display_mode *mode, unsigned int *postdiv) { unsigned int pclk = mode->clock; const struct reg_sequence reg_cfg[] = { @@ -271,12 +262,16 @@ static int lt9611_pll_setup(struct lt9611 *lt9611, const struct drm_display_mode regmap_multi_reg_write(lt9611->regmap, reg_cfg, ARRAY_SIZE(reg_cfg)); - if (pclk > 150000) + if (pclk > 150000) { regmap_write(lt9611->regmap, 0x812d, 0x88); - else if (pclk > 70000) + *postdiv = 1; + } else if (pclk > 70000) { regmap_write(lt9611->regmap, 0x812d, 0x99); - else + *postdiv = 2; + } else { regmap_write(lt9611->regmap, 0x812d, 0xaa); + *postdiv = 4; + } /* * first divide pclk by 2 first @@ -895,14 +890,15 @@ static void lt9611_bridge_mode_set(struct drm_bridge *bridge, { struct lt9611 *lt9611 = bridge_to_lt9611(bridge); struct hdmi_avi_infoframe avi_frame; + unsigned int postdiv; int ret; lt9611_bridge_pre_enable(bridge); lt9611_mipi_input_digital(lt9611, mode); - lt9611_pll_setup(lt9611, mode); + lt9611_pll_setup(lt9611, mode, &postdiv); lt9611_mipi_video_setup(lt9611, mode); - lt9611_pcr_setup(lt9611, mode); + lt9611_pcr_setup(lt9611, mode, postdiv); ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame, <9611->connector,