Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5084666rwd; Tue, 23 May 2023 18:10:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MlxqklZ9SOwN9r7y1/QvR7RFk+XmrXJdbJH1nCs+5buUscZywr9S9zcvWQpfPXIH8EL7t X-Received: by 2002:a05:6a20:d80d:b0:103:ee82:dcb0 with SMTP id iv13-20020a056a20d80d00b00103ee82dcb0mr17452082pzb.13.1684890606912; Tue, 23 May 2023 18:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684890606; cv=none; d=google.com; s=arc-20160816; b=z+Eb6DLrDqlzPRliGRjgNL9km8Q6UcwLWeWOfkXNUoD3Oh9h+oXv2pJKWlgsPVsibA kIo2i6u071m3a+olQmWXH8MSiIKBK17dHML/2Ub1RUwtHK8eK6XFmgBD8kOBKhY+4jXj JFaMlMJ+rGOAk+51nxC5YPYGnLnYEUWLFqtTF57CXmjslZiABle2iYJKTEOIOOu5jY2s 6ofVvYra3U2x1TrjLByvTf7A/+YPSynvQNQZhW+im9mjyzfBI1vNCp2o7YFERz7GLAwR 2vxiAtEOY+bhRFZiMnxD7k2Ew7OKN99R1afJj5/C75vmgpOaWkGuUXmBcDwoumXcrXzP lr0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=6UJu4At4JTYJZJm3ufdH8BuFWlW2L/vFJ5Zl0oCFuaU=; b=Ut31lAZlCqxXctrWlRKlKamB8m+pFLXrBjTmnk9nR2MjmwqkXlRkRjXW5fOuxta2uY gWvZNvFTDSJYuElzE9pY1qnE+ko+TGfcFl3+YCGCe4GxqnIjOfFEPERQcnHUZq3vNdPY QUn40R2R0c9A8mNOj/nYhr3JgvswLSB8ggQrz06L4FzBfeobzr60keiFaEE+7/5otI0h /zagNYTMQM5kw4ZdeAyEtr32TDH3KvHkwKsW+jnm4w0z+pXXkXwtabJQNGu0/0Dfo8Ng ZW6HX03qwodG8T0b35eiRoBK92UaauPbbKyyHsBpmv3p7YxXeWuh9s0GpcwYODduWuF1 MnzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=DyrqPvLX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n127-20020a632785000000b0053b99f68ceasi1236064pgn.613.2023.05.23.18.09.53; Tue, 23 May 2023 18:10:06 -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=@sberdevices.ru header.s=mail header.b=DyrqPvLX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238769AbjEXA41 (ORCPT + 99 others); Tue, 23 May 2023 20:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjEXA4W (ORCPT ); Tue, 23 May 2023 20:56:22 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88A9BCD; Tue, 23 May 2023 17:56:19 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 7F1085FD1B; Wed, 24 May 2023 03:56:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684889777; bh=6UJu4At4JTYJZJm3ufdH8BuFWlW2L/vFJ5Zl0oCFuaU=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; b=DyrqPvLXGsYToa8iWySrhnm3P5Z/mM8+b7Ss+5iIy3ovu7u3BaO9/wkN1Etw9JcaC KM+5eMnqEmclo/iRjGd1wbCsLYLRtR1RoyTQCBIh8jGIpXL94EUUWsynGEoFzXu/zQ MGn2eFGDaedaH+FQ4a7EpO66CEP27dhPSjU8+Z0iLoBCzpX0d1gqziMwLIO49gjoal 0OhojjOEUcuE+5KLhe3++MIy7NihYhcUR7G4GPd2XMb7PqyGzrvDS8JLFlq4+Au+m5 J5CtV3pjcKpje3XRe36ZjodKBhW7PaL+TYPwu2E3dfg2//oRq4wxjJ2gLdqgAkQDLt KwzwYfM0U4DOw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 24 May 2023 03:56:16 +0300 (MSK) Message-ID: <3fb39050-9543-f4a4-c8f2-a996e24c8e16@sberdevices.ru> Date: Wed, 24 May 2023 03:52:06 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v14 6/6] clk: meson: a1: add Amlogic A1 Peripherals clock controller driver Content-Language: en-US To: Heiner Kallweit CC: Martin Blumenstingl , "neil.armstrong@linaro.org" , "jbrunet@baylibre.com" , "mturquette@baylibre.com" , "sboyd@kernel.org" , "robh+dt@kernel.org" , "krzysztof.kozlowski+dt@linaro.org" , "khilman@baylibre.com" , "jian.hu@amlogic.com" , kernel , "rockosov@gmail.com" , "linux-amlogic@lists.infradead.org" , "linux-clk@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , Dmitry Rokosov References: <20230426095805.15338-1-ddrokosov@sberdevices.ru> <20230426095805.15338-7-ddrokosov@sberdevices.ru> <20230512140630.qd33rwzaalmadpmk@CAB-WSD-L081021> <20230517103456.p3sjxzbepvg7cr2r@CAB-WSD-L081021> <573d96df-7b08-4fa2-668b-58ff674a314e@gmail.com> <20230522134425.pc5fhojf53v6q2jz@CAB-WSD-L081021> From: George Stark In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/05/23 21:43:00 #21378639 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 5/22/23 23:36, Heiner Kallweit wrote: > On 22.05.2023 15:44, Dmitry Rokosov wrote: >> Heiner, >> >> On Fri, May 19, 2023 at 06:10:50PM +0200, Heiner Kallweit wrote: >>> On 18.05.2023 22:04, Martin Blumenstingl wrote: >>>> Hi Dmitry, >>>> >>>> On Wed, May 17, 2023 at 12:34 PM Dmitry Rokosov >>>> wrote: >>>> [...] >>>>>>> Additionally, the CCF determines the best ancestor based on how close >>>>>>> its rate is to the given one, based on arithmetic calculations. However, >>>>>>> we have independent knowledge that a certain clock would be better, with >>>>>>> less jitter and fewer intermediaries, which will likely improve energy >>>>>>> efficiency. Sadly, the CCF cannot take this into account. >>>>>> I agree that the implementation in CCF is fairly simple. There's ways >>>>>> to trick it though: IIRC if there are multiple equally suitable clocks >>>>>> it picks the first one. For me all of this has worked so far which is >>>>>> what makes me curious in this case (not saying that anything is wrong >>>>>> with your approach). >>>>>> >>>>>> Do you have a (real world) example where the RTC clock should be >>>>>> preferred over another clock? >>>>>> >>>>> Yes, a real-life example is the need for a 32Khz clock for an external >>>>> wifi chip. There is one option to provide this clock with high >>>>> precision, which is RTC + GENCLK. >>>>> >>>>>> I'm thinking about the following scenario. >>>>>> PWM parents: >>>>>> - XTAL: 24MHz >>>>>> - sys: not sure - let's say 166.67MHz >>>>>> - RTC: 32kHz >>>>>> >>>>>> Then after that there's a divider and a gate. >>>>>> >>>>>> Let's say the PWM controller needs a 1MHz clock: it can take that from >>>>>> XTAL or sys. Since XTAL is evenly divisible to 1MHz CCF will pick that >>>>>> and use the divider. >>>>>> But let's say the PWM controller needs a 32kHz clock: CCF would >>>>>> automatically pick the RTC clock. >>>>>> So is your implementation there to cover let's say 1kHz where >>>>>> mathematically 24MHz can be divided evenly to 1kHz (and thus should >>>>>> not result in any jitter) but RTC gives better precision in the real >>>>>> world (even though it's off by 24Hz)? >>>>>> >>>>> I don't think so. The highest precision that RTC can provide is from a >>>>> 32KHz rate only. However, I believe that a 1kHz frequency can also be >>>>> achieved by using xtal 24MHz with a divider, which can provide high >>>>> precision as well. >>>> Thank you again for the great discussion on IRC today. >>>> Here's my short summary so I don't forget before you'll follow up on this. >>>> >>>> In general there's two known cases where the RTC clock needs to be used: >>>> a) When using the GENCLK output of the SoC to output the 32kHz RTC >>>> clock and connect that to an SDIO WiFi chip clock input (this seems >>>> useful in my understanding because the RTC clock provides high >>>> precision) >>>> b) When using the PWM controller to output a 32kHz clock signal. In >>>> this case my understanding is that using the RTC clock as input to the >>>> PWM controller results in the best possible signal >>>> >>>> The second case won't be supported with Heiner's patches [0] that use >>>> CCF (common clock framework) in the PWM controller driver. >>>> In this series the parent clock is calculated using: >>>> freq = div64_u64(NSEC_PER_SEC * (u64)0xffff, period); >>>> >>>> A 32kHz clock means a PWM period of 30518ns. So with the above >>> To be precise: 30517,578125ns >>> What means that the PWM framework can't say "I want 32768Hz", >>> but just "I want something being very close to 32768Hz". >>> So what you need is some simple heuristic to interpret the >>> PWM request -> "PWM requests 30518ns, but supposedly it wants >>> 32768Hz" >>> >>> NSEC_PER_SEC / 30518 = 32767 (rounded down from 32767,547) >>> clk_round_rate(channel->clk, 32767) would return 0 (I *think*), >>> because it tries to find the next lower clock. >>> >>> The SoC families I'm familiar with have fclkin2 as PWM parent. >>> That's 1 GHz in my case, what results in a frequency of 32.767,547Hz >>> for period = 30518n. >>> What you're saying is that newer generations don't have PWM parents >>>> 24MHz any longer? >> No, of course not. For example, a fixed PLL (with all fclk_divX >> settings) has rates higher than 24MHz. However, we need to consider the >> 'heavy' background of such PWM. >> >> However, we have a "lightweight" clkin (special rtc32k) with a rate of >> 32kHz that we could potentially use as an input to produce a 32kHz >> output on the PWM lines. I don't see any reason why we should not >> support such special cases. >> > Two more things to consider: > 1. When wanting a 32kHz (well, 32768Hz) output with a 50% duty cycle, > then we need hi=0 and lo=0 with a 64kHz input clock. > See point 2 for an explanation of why 0 and not 1. > Means we couldn't use the RTC input clock. Did you consider this? > Or do I miss something? > 2. Seems the PWM block internally increments hi and lo, except the > constant_en bit is set on newer PWM block versions. > For bigger cnt values the impact is negligible, but for very small > values it's something we have to consider. > This was one additional motivation for me to choose an input > frequency that creates big cnt values. > Hello Heiner As I mentioned earlier I have some changes to take into account lo and hi regs incrementing. But it's more convenient to base my patch on top on one of yours (https://lore.kernel.org/linux-amlogic/23fe625e-dc23-4db8-3dce-83167cd3b206@gmail.com/) Is that ok if I resend your patch along with mine in series? Best regards George >>> >>>> calculation the PWM driver is asking for a clock rate of >=2GHz. >>>> We concluded that letting the common clock framework choose the best >>>> possible parent (meaning: removing CLK_SET_RATE_NO_REPARENT here) can >>>> be a way forward. >>>> But this means that the PWM controller driver must try to find the >>>> best possible parent somehow. The easiest way we came up with >>>> (pseudo-code): >>>> freq = NSEC_PER_SEC / period; >>>> fin_freq = clk_round_rate(channel->clk, freq); >>>> if (fin_freq != freq) { >>>> freq = div64_u64(NSEC_PER_SEC * (u64)0xffff, period); >>>> fin_freq = clk_round_rate(channel->clk, freq); >>>> } >>>> >>>> The idea is: for a requested 32kHz signal the PWM period is 30518ns. >>>> The updated logic would find that there's a matching clock input and >>>> use that directly. If not: use the original logic as suggested by >>>> Heiner. >>>> >>>> >>>> Best regards, >>>> Martin >>>> >>>> >>>> [0] https://lore.kernel.org/linux-amlogic/9faca2e6-b7a1-4748-7eb0-48f8064e323e@gmail.com/ >