Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1695333rwd; Thu, 18 May 2023 16:12:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7l47bpoKmM18P2382sBlj+RRxPPTBKqnD3OAUIwQ5zPzqpMOEf1tqVregYrL1BMJlUqNeU X-Received: by 2002:a05:6a20:94ce:b0:101:1f8:735e with SMTP id ht14-20020a056a2094ce00b0010101f8735emr181808pzb.0.1684451533904; Thu, 18 May 2023 16:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684451533; cv=none; d=google.com; s=arc-20160816; b=JWmiOtgcnARkoolwRZRetqkqjRvyz1+gEih1dJrfTo5Z6VVxdBbzWS+hvrTu6fyHzp j3t02lT77LQYGq11uYGE2LWitVXt/PJp8ZhqW1LZ2DJjBGiI5EUoQdPa3IGSu1JEHAuf teT85b+zoT5VZkrmnnve/4X3YcA5A2/FJFXs5Eg1gkttOgjnuMtAJzhsAH+J11mMwJw2 5ledV89UuJHaXW895Of5Nj1DyP7ZYNwDjQxXSZ59BHYSBGXw9jPTUie4pHgmvFTtDeRg 0hq1S5gRrM9N8FLVO8tGTQhun61CveVZbKL0deiPCyhq7O+wU6loUz0J3YnekHZSB8v/ 3PVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yt5KFw+xtdIb6VItu3DPNGmoCpleoJEIyPuwXXhva2M=; b=VH7z10hrN0CnVQaEE3QhloBi/ZBgrtjFafKyvStwhAtpwZERiKUOqvrq8p3TjUl426 NKmDten7WMsvhIwTbjEaYJayNhweqFBjvaSAe4LrDg49vkOJXvDx2bjyOH6pI4hNF6ji On4Pm91+6FHAzJsIdAXOJelCHmN5k62VDsBFAgt5sz/6UCkoYUeWYcrvbUBdDAASowYE QxnBYw0L46OCwzEKzsjw6hwD2DLXGLuhLTpUi02DLzxyCPCsUWPqlVsDG8LRrxWRdAIe AHy9hVQlSynCykp9B3e+uDUpiDT9iiFv5k3VKsGL1YEZJhz1carIFLAHdFZ2Wx1nYHvl MGDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZcATbFkp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020a656aad000000b0051f00f55bd8si2432362pgu.224.2023.05.18.16.11.57; Thu, 18 May 2023 16:12:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZcATbFkp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231207AbjERXHE (ORCPT + 99 others); Thu, 18 May 2023 19:07:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjERXGv (ORCPT ); Thu, 18 May 2023 19:06:51 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8891AB for ; Thu, 18 May 2023 16:06:47 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-331ad4cd4fdso6081775ab.1 for ; Thu, 18 May 2023 16:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684451206; x=1687043206; 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=yt5KFw+xtdIb6VItu3DPNGmoCpleoJEIyPuwXXhva2M=; b=ZcATbFkprZeFTNuSJqhxSUZTj8gzDbNC/xotilvBhiqsd7QSqMSDRlsOucCBzqXZyI XYouvbGfy4ahQndKyeE3b4McfpFsCkVne6kX591hEGmbntrkFhdAVjCmhbokhuWzV6Qb anxwWcjMkXR4e51VGHvVXIHkOzVOyAtFr3pGDTBEmEQR/MtlznidBh0F+I34vf4J1Qm6 Nncs08OSkIf5QPK2hFekbTNfMI+9kaRRcjiztdhB7bKKdRB2YhxblcBs7dq+9Z/N13f2 Caxw69r1Z4ec5gN6TN+eFIxmzt01LxDa4B25itUC9/dOkGKbIpAkmpscavvVIq29yNiO ksuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684451206; x=1687043206; 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=yt5KFw+xtdIb6VItu3DPNGmoCpleoJEIyPuwXXhva2M=; b=Eul/Lo9BRIZZd4YQ7KxTJpTa/cFtwqGPwDhEuF15/hrdWZ27KGaHHniSr9O131r2fa ev9vTWaDmnodmEjrZ5EHc3inWzJoGXWwFo57YjTa7XPy02ej53WvkwGB4pNZJLHyVN3S qCM2Mr12xq/91T+RPTw26yq5h2C6OQuFK9Kj42e0dGprqXudjYhQrL4Ri7oGWZ2P02bq R1iMwukNbsqbEfUYvYb+oQu0lUPRfQk9ZCYGh30Jr8Ec9PMdiLvvSsTHYaX6XH+fWOTN Kk8KD6PygZfoAtPi0oNSx9alTQBjTQi/3NoP+9SuIhn8SToukME6FssUvaKSkCSMGOzX hDLA== X-Gm-Message-State: AC+VfDy38vwrUK4ZoZMOhEPkpqPmx4iJM6fFF7upfbJa55Q8LxjXYjZc VK+Ef8WDbNLZswltIKMUc5s= X-Received: by 2002:a92:d90c:0:b0:338:98a9:3898 with SMTP id s12-20020a92d90c000000b0033898a93898mr91909iln.21.1684451206258; Thu, 18 May 2023 16:06:46 -0700 (PDT) Received: from aford-B741.lan ([2601:447:d001:897f:56b8:635c:4c7a:15b1]) by smtp.gmail.com with ESMTPSA id z12-20020a92cd0c000000b003317ebbc426sm635897iln.47.2023.05.18.16.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 16:06:45 -0700 (PDT) From: Adam Ford To: dri-devel@lists.freedesktop.org Cc: aford@beaconembedded.com, Adam Ford , Lucas Stach , Chen-Yu Tsai , Frieder Schrempf , Michael Walle , Marek Szyprowski , Jagan Teki , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Inki Dae , Marek Vasut , linux-kernel@vger.kernel.org Subject: [PATCH V7 5/6] drm: bridge: samsung-dsim: Dynamically configure DPHY timing Date: Thu, 18 May 2023 18:06:25 -0500 Message-Id: <20230518230626.404068-6-aford173@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230518230626.404068-1-aford173@gmail.com> References: <20230518230626.404068-1-aford173@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DPHY timings are currently hard coded. Since the input clock can be variable, the phy timings need to be variable too. To facilitate this, we need to cache the hs_clock based on what is generated from the PLL. The phy_mipi_dphy_get_default_config_for_hsclk function configures the DPHY timings in pico-seconds, and a small macro converts those timings into clock cycles based on the hs_clk. Signed-off-by: Adam Ford Signed-off-by: Lucas Stach Tested-by: Chen-Yu Tsai Tested-by: Frieder Schrempf Reviewed-by: Frieder Schrempf Tested-by: Michael Walle Tested-by: Marek Szyprowski Reviewed-by: Jagan Teki Tested-by: Jagan Teki # imx8mm-icore --- drivers/gpu/drm/bridge/samsung-dsim.c | 58 +++++++++++++++++++++++---- include/drm/bridge/samsung-dsim.h | 1 + 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c index 6f012016068a..e67e501c9d49 100644 --- a/drivers/gpu/drm/bridge/samsung-dsim.c +++ b/drivers/gpu/drm/bridge/samsung-dsim.c @@ -218,6 +218,8 @@ #define OLD_SCLK_MIPI_CLK_NAME "pll_clk" +#define PS_TO_CYCLE(ps, hz) DIV64_U64_ROUND_CLOSEST(((ps) * (hz)), 1000000000000ULL) + static const char *const clk_names[5] = { "bus_clk", "sclk_mipi", @@ -651,6 +653,8 @@ static unsigned long samsung_dsim_set_pll(struct samsung_dsim *dsi, reg = samsung_dsim_read(dsi, DSIM_STATUS_REG); } while ((reg & DSIM_PLL_STABLE) == 0); + dsi->hs_clock = fout; + return fout; } @@ -698,13 +702,47 @@ static void samsung_dsim_set_phy_ctrl(struct samsung_dsim *dsi) const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; const unsigned int *reg_values = driver_data->reg_values; u32 reg; + struct phy_configure_opts_mipi_dphy cfg; + int clk_prepare, lpx, clk_zero, clk_post, clk_trail; + int hs_exit, hs_prepare, hs_zero, hs_trail; + unsigned long long byte_clock = dsi->hs_clock / 8; if (driver_data->has_freqband) return; + phy_mipi_dphy_get_default_config_for_hsclk(dsi->hs_clock, + dsi->lanes, &cfg); + + /* + * TODO: + * The tech Applications Processor manuals for i.MX8M Mini, Nano, + * and Plus don't state what the definition of the PHYTIMING + * bits are beyond their address and bit position. + * After reviewing NXP's downstream code, it appears + * that the various PHYTIMING registers take the number + * of cycles and use various dividers on them. This + * calculation does not result in an exact match to the + * downstream code, but it is very close to the values + * generated by their lookup table, and it appears + * to sync at a variety of resolutions. If someone + * can get a more accurate mathematical equation needed + * for these registers, this should be updated. + */ + + lpx = PS_TO_CYCLE(cfg.lpx, byte_clock); + hs_exit = PS_TO_CYCLE(cfg.hs_exit, byte_clock); + clk_prepare = PS_TO_CYCLE(cfg.clk_prepare, byte_clock); + clk_zero = PS_TO_CYCLE(cfg.clk_zero, byte_clock); + clk_post = PS_TO_CYCLE(cfg.clk_post, byte_clock); + clk_trail = PS_TO_CYCLE(cfg.clk_trail, byte_clock); + hs_prepare = PS_TO_CYCLE(cfg.hs_prepare, byte_clock); + hs_zero = PS_TO_CYCLE(cfg.hs_zero, byte_clock); + hs_trail = PS_TO_CYCLE(cfg.hs_trail, byte_clock); + /* B D-PHY: D-PHY Master & Slave Analog Block control */ reg = reg_values[PHYCTRL_ULPS_EXIT] | reg_values[PHYCTRL_VREG_LP] | reg_values[PHYCTRL_SLEW_UP]; + samsung_dsim_write(dsi, DSIM_PHYCTRL_REG, reg); /* @@ -712,7 +750,9 @@ static void samsung_dsim_set_phy_ctrl(struct samsung_dsim *dsi) * T HS-EXIT: Time that the transmitter drives LP-11 following a HS * burst */ - reg = reg_values[PHYTIMING_LPX] | reg_values[PHYTIMING_HS_EXIT]; + + reg = DSIM_PHYTIMING_LPX(lpx) | DSIM_PHYTIMING_HS_EXIT(hs_exit); + samsung_dsim_write(dsi, DSIM_PHYTIMING_REG, reg); /* @@ -728,10 +768,11 @@ static void samsung_dsim_set_phy_ctrl(struct samsung_dsim *dsi) * T CLK-TRAIL: Time that the transmitter drives the HS-0 state after * the last payload clock bit of a HS transmission burst */ - reg = reg_values[PHYTIMING_CLK_PREPARE] | - reg_values[PHYTIMING_CLK_ZERO] | - reg_values[PHYTIMING_CLK_POST] | - reg_values[PHYTIMING_CLK_TRAIL]; + + reg = DSIM_PHYTIMING1_CLK_PREPARE(clk_prepare) | + DSIM_PHYTIMING1_CLK_ZERO(clk_zero) | + DSIM_PHYTIMING1_CLK_POST(clk_post) | + DSIM_PHYTIMING1_CLK_TRAIL(clk_trail); samsung_dsim_write(dsi, DSIM_PHYTIMING1_REG, reg); @@ -744,8 +785,11 @@ static void samsung_dsim_set_phy_ctrl(struct samsung_dsim *dsi) * T HS-TRAIL: Time that the transmitter drives the flipped differential * state after last payload data bit of a HS transmission burst */ - reg = reg_values[PHYTIMING_HS_PREPARE] | reg_values[PHYTIMING_HS_ZERO] | - reg_values[PHYTIMING_HS_TRAIL]; + + reg = DSIM_PHYTIMING2_HS_PREPARE(hs_prepare) | + DSIM_PHYTIMING2_HS_ZERO(hs_zero) | + DSIM_PHYTIMING2_HS_TRAIL(hs_trail); + samsung_dsim_write(dsi, DSIM_PHYTIMING2_REG, reg); } diff --git a/include/drm/bridge/samsung-dsim.h b/include/drm/bridge/samsung-dsim.h index a1a5b2b89a7a..d9d431e3b65a 100644 --- a/include/drm/bridge/samsung-dsim.h +++ b/include/drm/bridge/samsung-dsim.h @@ -93,6 +93,7 @@ struct samsung_dsim { u32 pll_clk_rate; u32 burst_clk_rate; + u32 hs_clock; u32 esc_clk_rate; u32 lanes; u32 mode_flags; -- 2.39.2