Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2081297rwd; Wed, 17 May 2023 05:38:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73dZ34sBv2MoZfcO01dBi0E5f6ig8y1i9HFUBWNcS+wB+TToF+GDvU0V2hCb26Xe6/3qdW X-Received: by 2002:a17:902:ba88:b0:1ac:43ea:7882 with SMTP id k8-20020a170902ba8800b001ac43ea7882mr40907683pls.29.1684327098232; Wed, 17 May 2023 05:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684327098; cv=none; d=google.com; s=arc-20160816; b=0fAclXbrhsuxKwhK8LpXvdAWkTdLd6frD9Rei0qH6fZ/59Y1zM5hmyfXY5I/Wz+3/t eBcNuho2tw3luankTGKVYBBV7JUNchoN35eHYdaPT1LrZ1AT2HryRP1jblzlss8utq2G i5WOp6Kvk2PYO49nSPOGOtwnRewTtJ8tGTuaL47r20cwyDOcA8qSB0DUzna0THcvAk/M 2pIgTBkxa6iQRI5cmG+ganyJb7TFJ+bQSZuAO+b79PaDMk13Db3CcfZGICvzF6M+MU7+ 3lMbzYG0V/uI6DBD8FPm8dabyj8/5GBD4V1Y2rOfXYx3hhmOnh12KwKkFHZGg7/epLNG HTkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4wJlwiloE3+nuW0LYCKoJcJcNbRRwPyYMQz34VEuBFQ=; b=Q6JRRKFqDw6RZFUZLTRGmEoWeVBQ7od8yySORGSdu6rKwaPcwkk6+JxI0j3msDlwwl cM8gZZ2kDsp6CoCK5NEWhSpxFdWiKPN9mbqO5Z0S+RU4o3kRk7NCUIU0japs1yijamMm TidmH9Jm76wo0Bj+UwbGvbTpHseR87DLn1vuiehF7ar3oVSLf36EMEa8n1mJ2JJGlg/d ybVNhk1IntWGHT67Jh2fy+uyCtJhUzbEHm+4Baunj1Gj47nO/JuWDwwQKqQGiOsjvcR/ qI1MaecDqHJhcbL08NTLZXBGHxbF5b8cX34ZDs/wJs04hATsuQE3IYaWxkjS10uCXfD5 UamA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RmEZapjn; 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 l9-20020a170903120900b001aaf2ced278si22761499plh.430.2023.05.17.05.38.03; Wed, 17 May 2023 05:38:18 -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=RmEZapjn; 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 S231446AbjEQMFB (ORCPT + 99 others); Wed, 17 May 2023 08:05:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231495AbjEQMEe (ORCPT ); Wed, 17 May 2023 08:04:34 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756BC61AF for ; Wed, 17 May 2023 05:01:34 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ae4e49727eso8180185ad.1 for ; Wed, 17 May 2023 05:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684324894; x=1686916894; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4wJlwiloE3+nuW0LYCKoJcJcNbRRwPyYMQz34VEuBFQ=; b=RmEZapjncbG2NP8yCl8Qvuz02FmKf8muzRax7BZ92EpQKLC45BVjZZWGJE/cCf9fuO bbEau2jh0cLF6DsE9dBEUV73tt3lbSNQs+IeP6o5UY+psQybrQm4PkLpawDoQCQXKspj GSi258UPxWTQFIA7k4D/mV+OW/9dGGhBwpQirfb5ERW9EC520nlJelOHqQGe12chIibP BD4iIEARovjKkhSk03DTa6xk1si04gksv5DKNKIFX19e+PgT57PBaOej1xSY1uOrCTGe xhdGvHDAtBiuh16IHmOzRXKJUUqUPZU/aBUB3MJMtoJOdLiietQVlnPrQoX9L8avi+Ys gbzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684324894; x=1686916894; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4wJlwiloE3+nuW0LYCKoJcJcNbRRwPyYMQz34VEuBFQ=; b=W/khY5n4mvoc4iLdxs18HAtmYEfLgK7gTeT4e/4f9D/CFygO9trFNxLzNAmlO54Oie M2wgvCOHzW4yyH+BDk+bx8iQ6CXb0adgDYfX9BKNmnc+94ojkFAghL3nIGM0sDY5Gi1U M5C+QoYUyxhGwk/9UBDMBCbNA2l3Y17P+3hHSl824uwT9acbUDxWPYwFrncCCc6+0sSW q5HswqWeXTa/vTo7PUW9HtYhaZuw48WgHm+tUEHC79TzQpguJyu8ttO3ejBfPvfy9jsx 79wQB12brlUyiQUOTOQuT6HBqhR/D2Gwv6LKs1d8ir8S3PAhVTxiMj4ltOO0eITsJ8O6 584Q== X-Gm-Message-State: AC+VfDyKC40EnJEoThysWpRvbezkgc3SuWGyu6Q+k6i6eiXuCzKnp6sN 9DjIL9no9SEzNr+Ist2nUx5iELYCynCGxu3mhdo= X-Received: by 2002:a17:902:b08d:b0:1ad:e099:fc04 with SMTP id p13-20020a170902b08d00b001ade099fc04mr18083254plr.38.1684324893729; Wed, 17 May 2023 05:01:33 -0700 (PDT) MIME-Version: 1.0 References: <20230515235713.232939-1-aford173@gmail.com> <20230515235713.232939-6-aford173@gmail.com> In-Reply-To: From: Adam Ford Date: Wed, 17 May 2023 07:01:22 -0500 Message-ID: Subject: Re: [PATCH V6 5/6] drm: bridge: samsung-dsim: Dynamically configure DPHY timing To: Jagan Teki Cc: dri-devel@lists.freedesktop.org, aford@beaconembedded.com, Lucas Stach , Chen-Yu Tsai , Frieder Schrempf , Michael Walle , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Inki Dae , Marek Szyprowski , Marek Vasut , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Wed, May 17, 2023 at 6:28=E2=80=AFAM Jagan Teki wrote: > > On Tue, May 16, 2023 at 5:27=E2=80=AFAM Adam Ford wr= ote: > > > > 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 > > --- > > drivers/gpu/drm/bridge/samsung-dsim.c | 57 +++++++++++++++++++++++---- > > include/drm/bridge/samsung-dsim.h | 1 + > > 2 files changed, 51 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/br= idge/samsung-dsim.c > > index 08266303c261..3944b7cfbbdf 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)), 100= 0000000000ULL) > > + > > static const char *const clk_names[5] =3D { > > "bus_clk", > > "sclk_mipi", > > @@ -651,6 +653,8 @@ static unsigned long samsung_dsim_set_pll(struct sa= msung_dsim *dsi, > > reg =3D samsung_dsim_read(dsi, DSIM_STATUS_REG); > > } while ((reg & DSIM_PLL_STABLE) =3D=3D 0); > > > > + dsi->hs_clock =3D fout; > > + > > return fout; > > } > > > > @@ -698,13 +702,46 @@ static void samsung_dsim_set_phy_ctrl(struct sams= ung_dsim *dsi) > > const struct samsung_dsim_driver_data *driver_data =3D dsi->dri= ver_data; > > const unsigned int *reg_values =3D 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 =3D 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 reference manual for i.MX8M Mini/Nano/Plus > > Does it mean, Applications Processor Reference Manual? better add it > clear reference. I can do that. > > > + * doesn'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, 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 =3D PS_TO_CYCLE(cfg.lpx, byte_clock); > > + hs_exit =3D PS_TO_CYCLE(cfg.hs_exit, byte_clock); > > + clk_prepare =3D PS_TO_CYCLE(cfg.clk_prepare, byte_clock); > > + clk_zero =3D PS_TO_CYCLE(cfg.clk_zero, byte_clock); > > + clk_post =3D PS_TO_CYCLE(cfg.clk_post, byte_clock); > > + clk_trail =3D PS_TO_CYCLE(cfg.clk_trail, byte_clock); > > + hs_prepare =3D PS_TO_CYCLE(cfg.hs_prepare, byte_clock); > > + hs_zero =3D PS_TO_CYCLE(cfg.hs_zero, byte_clock); > > + hs_trail =3D PS_TO_CYCLE(cfg.hs_trail, byte_clock); > > I think we can do some kind of negotiation has done similar in bsp by > taking inputs from bit_clk and PLL_1432X table. Did you try this? we > thought this approach while writing dsim to support dynamic dphy. I originally attempted to implement the lookup table that was used in the downstream NXP kernel, but I was told to not use a lookup table but to calculate them directly instead. I reached out to my NXP rep and I was told that they could not divulge the contents of these registers since the DSI driver was under a license from Samsung and that information was not available outside of an NDA. When I did the testing for this, I tested a variety of resolutions and refresh rates and compared the values output from here to those generated by the NXP lookup table, and they are very close. From what I could tell, the variance didn't appear to manifest itself on the monitors that I tried. I tried to explain this in the TODO message, but maybe it wasn't clear. Marek S tested this on Exynos and he didn't report any regressions. adam > > Thanks, > Jagan.