Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp29304rwl; Wed, 9 Aug 2023 10:23:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNWv8pvp7vXsKYrZuZ5yRerst+w5t9ribuMiKB+gmxEISvHi4lIrZp5MLmRaApWsg5vi3/ X-Received: by 2002:a17:902:d355:b0:1b8:8dbd:e1a0 with SMTP id l21-20020a170902d35500b001b88dbde1a0mr3580338plk.13.1691601806125; Wed, 09 Aug 2023 10:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691601806; cv=none; d=google.com; s=arc-20160816; b=R2oves/+t6+SmH1lC9ILN+4MZ/5cxSnmATuoTMCuoqR/sHofkaUEXB8MHYgoW+58u8 MMNoAMYbnu/6RjeXYMez0DAIaiILx9OIsx1zvqsAIOygkSUt8Y3H6sRGZH7n85hRHzXO jHrDkf3wiEQA2k2wA6o0rtr2W/7zxA4A1NTfKHQnR6BtBxlNlLkn7COLZEj+AAjcuOMw QLPlpp5bktaYYWWobevWQtZqHuh1dsyuD5S3TRX8W5UVGCckH1CknUhcwV2U/AT7cZJy y3RM4aDuW5OQmvf1+rHBCaESUfS/ydxs/r+j9Jf4ujCprncIlSjpnIG9dFXF+R/gLk+t z5iQ== 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:reply-to:in-reply-to:references:mime-version; bh=yLTosLjQXK26pWHdvpb3jdxnVMfneAyNtSmApJ0HuKs=; fh=paHVBXb3oUuhNsjFsGM9hSg4ArViQu5ulY7H+b+RxUI=; b=E3v3eL7ytfIAvoJNf08yNvCxGynJ2RllFZnNZ7rQpsSsW3zlu/pswwn1VsNbP1+dmp dUKMPumuE5uvQ+IkgjQJb8ZT21O5Bw/Z/uraoq9C5oCEkLenGDEfdza87ZSmpyU57MRH E3MWL2fM38KF27lfyb1sq6VZ89zyzT5rt23zsdXdyZdA267V6nkJ3aVNu5rsA+Oghtal eHoqMN8d8ic8rD0tcx40fUkCHvEjobBR/F88uZQn8xwWKcGvZAdmOCvqH+d5mHXwbqjn Xm4z9rxPk35jH2rwwimCy9XI/OQC9XQ15eY7iL2t6gmeZ0pRxKJtXvApRAr5GgVgo2KH 2VoA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170902d2c400b001b8987f4004si10349996plc.541.2023.08.09.10.23.12; Wed, 09 Aug 2023 10:23:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231127AbjHIQpJ convert rfc822-to-8bit (ORCPT + 99 others); Wed, 9 Aug 2023 12:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjHIQpI (ORCPT ); Wed, 9 Aug 2023 12:45:08 -0400 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C58121BFE; Wed, 9 Aug 2023 09:45:07 -0700 (PDT) Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-565f2567422so19530eaf.2; Wed, 09 Aug 2023 09:45:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691599506; x=1692204306; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=C/ppIpNykOtbP/6R4ynNuZ5RP4Dl5BB7MG8fQ5sVPJQ=; b=dug6ehjpYFw/6LBU3X5wozNz4kGI1f1ZrDCceFL/DNDpnc0myiLAB81CgegcXRZDAK Le5Aosiw2otd1LSybeJiRNtbPnemCcsHXCh3HyYPTNeHfZ2qeexvk7Edsapdzpi10Uq/ GVKHlSmc4rbzRPWA9UtmVP+2MYR/UdZhI4h/hBBQlvJKt9zcjhUgWkWFQLCaYM804uRd h3UVHugeG/yoWqGV426LNR3UYsaJ8Pmf50AN0HtTrG7FTxhkHQa/Ytn/HN7rdJBWgQ9o Y7ECzQlPOLZuWB+RH/MVdxlWjfnaTMRx8zbmseI/Dw9xrf8N3wbw/6bsFCGvjJwqj3h7 M3eQ== X-Gm-Message-State: AOJu0Yz4hu50TnUaZXTkPupVMurc6erlhdwQJR7OxEgNGGTA+0znAiTn 9oI5P1ev26ii2+Q8wGF47fPR46WQ8IoJiA== X-Received: by 2002:a54:4018:0:b0:3a7:2f1d:ea4e with SMTP id x24-20020a544018000000b003a72f1dea4emr3224540oie.41.1691599506378; Wed, 09 Aug 2023 09:45:06 -0700 (PDT) Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com. [209.85.161.45]) by smtp.gmail.com with ESMTPSA id o8-20020a0568080f8800b003a1d29f0549sm7219108oiw.15.2023.08.09.09.45.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Aug 2023 09:45:05 -0700 (PDT) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-56d6dfa8b52so18411eaf.3; Wed, 09 Aug 2023 09:45:05 -0700 (PDT) X-Received: by 2002:a05:6808:211e:b0:3a3:ffb7:1dd4 with SMTP id r30-20020a056808211e00b003a3ffb71dd4mr3716240oiw.6.1691599505466; Wed, 09 Aug 2023 09:45:05 -0700 (PDT) MIME-Version: 1.0 References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> Reply-To: wens@csie.org From: Chen-Yu Tsai Date: Thu, 10 Aug 2023 00:44:53 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 00/11] clk: sunxi-ng: Consider alternative parent rates when determining NKM clock rate To: Frank Oltmanns Cc: Maxime Ripard , Michael Turquette , Stephen Boyd , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Mon, Aug 7, 2023 at 8:44 PM Frank Oltmanns wrote: > > This patchset enables NKM clocks to consider alternative parent rates > and utilize this new feature to adjust the pll-video0 clock on Allwinner > A64. > > Furthermore, with this patchset pll-video0 considers rates that are > higher than the requested rate when finding the closest rate. In > consequence, higher rates are also considered by pll-video0's > descandents. In total, after applying this patchset, finding the closest > rate is supported by: > - ccu_nm > - ccu_nkm > - ccu_mux > - ccu_div > > This allows us to achieve an optimal rate for driving the board's panel. > > To provide some context, the clock structure involved in this process is > as follows: > clock clock type > -------------------------------------- > pll-video0 ccu_nm > pll-mipi ccu_nkm > tcon0 ccu_mux > tcon-data-clock sun4i_dclk > > The divider between tcon0 and tcon-data-clock is fixed at 4. Therefore, > in order to achieve a rate that closely matches the desired rate of the > panel, pll-mipi needs to operate at a specific rate. > > Tests > ===== > So far, this has been successfully tested on the A64-based Pinephone > using three different panel rates: > > 1. A panel rate that can be matched exactly by pll-video0. > 2. A panel rate that requires pll-video0 to undershoot to get the > closest rate. > 3. A panel rate that requires pll-video0 to overshoot to get the > closest rate. > > Test records: > > Re 1: > ----- > Panel requests tcon-data-clock of 103500000 Hz, i.e., pll-mipi needs to > run at 414000000 Hz. This results in the following clock rates: > clock rate > ------------------------------------- > pll-video0 207000000 > hdmi-phy-clk 51750000 > hdmi 207000000 > tcon1 207000000 > pll-mipi 414000000 > tcon0 414000000 > tcon-data-clock 103500000 > > The results of the find_best calls: > ccu_nkm_find_best_with_parent_adj: rate=414000000, best_rate=414000000, best_parent_rate=207000000, n=1, k=2, m=1 > ccu_nkm_find_best_with_parent_adj: rate=414000000, best_rate=414000000, best_parent_rate=207000000, n=1, k=2, m=1 > ccu_nkm_find_best_with_parent_adj: rate=414000000, best_rate=414000000, best_parent_rate=207000000, n=1, k=2, m=1 > ccu_nkm_find_best_with_parent_adj: rate=414000000, best_rate=414000000, best_parent_rate=207000000, n=1, k=2, m=1 > ccu_nkm_find_best: rate=414000000, best_rate=414000000, parent_rate=207000000, n=1, k=2, m=1 > > Re 2: > ----- > Panel requests tcon-data-clock of 103650000 Hz, i.e., pll-mipi needs to > run at 414600000 Hz. This results in the following clock rates: > clock rate > ------------------------------------- > pll-video0 282666666 > hdmi-phy-clk 70666666 > hdmi 282666666 > tcon1 282666666 > pll-mipi 414577776 > tcon0 414577776 > tcon-data-clock 103644444 > > The results of the find_best calls: > ccu_nkm_find_best_with_parent_adj: rate=414600000, best_rate=414577776, best_parent_rate=282666666, n=11, k=2, m=15 > ccu_nkm_find_best_with_parent_adj: rate=414600000, best_rate=414577776, best_parent_rate=282666666, n=11, k=2, m=15 > ccu_nkm_find_best_with_parent_adj: rate=414577776, best_rate=414577776, best_parent_rate=282666666, n=11, k=2, m=15 > ccu_nkm_find_best_with_parent_adj: rate=414577776, best_rate=414577776, best_parent_rate=282666666, n=11, k=2, m=15 > ccu_nkm_find_best: rate=414577776, best_rate=414577776, parent_rate=282666666, n=11, k=2, m=15 > > Re 3: > ----- > Panel requests tcon-data-clock of 112266000 Hz, i.e., pll-mipi needs to > run at 449064000 Hz. This results in the following clock rates: > clock rate > ------------------------------------- > pll-video0 207272727 > hdmi-phy-clk 51818181 > hdmi 207272727 > tcon1 207272727 > pll-mipi 449090908 > tcon0 449090908 > tcon-data-clock 112272727 > > The results of the find_best calls: > ccu_nkm_find_best_with_parent_adj: rate=449064000, best_rate=449090908, best_parent_rate=207272727, n=13, k=2, m=12 > ccu_nkm_find_best_with_parent_adj: rate=449064000, best_rate=449090908, best_parent_rate=207272727, n=13, k=2, m=12 > ccu_nkm_find_best_with_parent_adj: rate=449090908, best_rate=449090908, best_parent_rate=207272727, n=13, k=2, m=12 > ccu_nkm_find_best_with_parent_adj: rate=449090908, best_rate=449090908, best_parent_rate=207272727, n=13, k=2, m=12 > ccu_nkm_find_best: rate=449090908, best_rate=449090908, parent_rate=207272727, n=13, k=2, m=12 > > Changelog: > ---------- > Changes in v6: > - Removed unnecessary #include from ccu_nkm.c > - Link to v5: https://lore.kernel.org/r/20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev > > Changes in v5: > - Remove the dedicated function for calculating the optimal parent rate > for nkm clocks that was introduced in v2 and again in v4. Instead use > a simple calculation and require the parent clock to select the > closest rate to achieve optimal results. > - Change the order of parameters of nkm_best_rate and > nkm_best_rate_with_parent_adj as requested my Maxime Ripard. > - Prefer to not reset the rate of the nkm clock's parent if the ideal > rate can be reached using the parent's current rate, copying the > behavior of ccu_mp. > - Link to v4: https://lore.kernel.org/r/20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev > > Changes in v4: > - Re-introduce a dedicated function for calculating the optimal parent > rate for nkm clocks that was introduced in v2 and removed in v3. It > turned out that not having this functionality introduces a bug when > the parent does not support finding the closest rate: > https://lore.kernel.org/all/87pm4xg2ub.fsf@oltmanns.dev/ > - Incorporate review remarks: > - Correcting the parameter name for ccu_nkm_round_rate()'s parent HW > is now in a separate patch. > - Use correct parameter order in ccu_nkm_find_best_with_parent_adj. > - Add ccu_is_better_rate() and use it for determining the best rate > for nm and nkm, as well as ccu_mux_helper_determine_rate. > - Consistently introduce new macros for clock variants that support > finding the closest rate instead of updating existing macros. > - Use wrapper function for determining a ccu_mux's rate in order to > support finding the closest rate. > - Link to v3: https://lore.kernel.org/r/20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev > > Changes in v3: > - Use dedicated function for finding the best rate in cases where an > nkm clock supports setting its parent's rate, streamlining it with > the structure that is used in other sunxi-ng ccus such as ccu_mp > (PATCH 1). > - Therefore, remove the now obsolete comments that were introduced in > v2 (PATCH 1). > - Remove the dedicated function for calculating the optimal parent rate > for nkm clocks that was introduced in v2. Instead use a simple > calculation and require the parent clock to select the closest rate to > achieve optimal results (PATCH 1). > - Therefore, add support to set the closest rate for nm clocks (because > pll-mipi's parent pll-video0 is an nm clock) and all clock types that > are descendants of a64's pll-video0, i.e., nkm, mux, and div (PATCH 3 > et. seq.). > - Link to v2: https://lore.kernel.org/all/20230611090143.132257-1-frank@oltmanns.dev/ > > Changes in V2: > - Move optimal parent rate calculation to dedicated function > - Choose a parent rate that does not to overshoot requested rate > - Add comments to ccu_nkm_find_best > - Make sure that best_parent_rate stays at original parent rate in the unlikely > case that all combinations overshoot. > > Link to V1: > https://lore.kernel.org/lkml/20230605190745.366882-1-frank@oltmanns.dev/ > > --- > Frank Oltmanns (11): > clk: sunxi-ng: nkm: Use correct parameter name for parent HW > clk: sunxi-ng: nkm: consider alternative parent rates when determining rate > clk: sunxi-ng: a64: allow pll-mipi to set parent's rate > clk: sunxi-ng: Add feature to find closest rate > clk: sunxi-ng: Add helper function to find closest rate > clk: sunxi-ng: nm: Support finding closest rate > clk: sunxi-ng: nkm: Support finding closest rate > clk: sunxi-ng: mux: Support finding closest rate > clk: sunxi-ng: div: Support finding closest rate > clk: sunxi-ng: a64: select closest rate for pll-video0 > clk: sunxi-ng: nkm: Prefer current parent rate Whole series applied. There were some conflicts on patch 10 I had to fix up. I also took the liberty of realigning some of the lines. Please check if things are correct: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git/commit/?h=sunxi/clk-for-6.6&id=bf8eb12f52c49e10ca1d86564bfa096e09c51c38 ChenYu > drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 36 ++++++++++------------- > drivers/clk/sunxi-ng/ccu_common.c | 12 ++++++++ > drivers/clk/sunxi-ng/ccu_common.h | 6 ++++ > drivers/clk/sunxi-ng/ccu_div.h | 30 +++++++++++++++++++ > drivers/clk/sunxi-ng/ccu_mux.c | 15 ++++++++-- > drivers/clk/sunxi-ng/ccu_mux.h | 38 +++++++++++++++++------- > drivers/clk/sunxi-ng/ccu_nkm.c | 55 ++++++++++++++++++++++++++++++----- > drivers/clk/sunxi-ng/ccu_nm.c | 13 ++++----- > drivers/clk/sunxi-ng/ccu_nm.h | 48 ++++++++++++++++++++++++++++-- > 9 files changed, 202 insertions(+), 51 deletions(-) > --- > base-commit: 6995e2de6891c724bfeb2db33d7b87775f913ad1 > change-id: 20230626-pll-mipi_set_rate_parent-3363fc0d6e6f > > Best regards, > -- > Frank Oltmanns >