Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2417347rwb; Mon, 7 Nov 2022 13:04:08 -0800 (PST) X-Google-Smtp-Source: AMsMyM4uHoc+K36X4L/S9XEy3n8sy1yA69DjvUd3KnsiRoa5TsNo0oEr2S+eIC9gDoDhkLPcjpOz X-Received: by 2002:a63:5553:0:b0:43c:5c1e:424f with SMTP id f19-20020a635553000000b0043c5c1e424fmr45022505pgm.353.1667855048229; Mon, 07 Nov 2022 13:04:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667855048; cv=none; d=google.com; s=arc-20160816; b=RYoJor/KSv+qkWXyonKt+idoLgkUXBxiv1Kgs/AD7gRQHCslXVpLeMljcXwkl1kAw2 7M3ThLHSSkavDdgXaT6IOxP5WJ9KD0qtMdpFVkjV9blOjxZ61ohCX2yRNcPskgQn6CxK bsV93G/gCmTExjyg4uPNgNLpPzrF6WG4mb/P1YxLjgPzpKMQ1/OS3K83qxsVf6tQpo2Q qv3WiXukdBTORf+/0NXE2EwN8N2RcU8YlFyw8OA+2nI12u0DZdl8N2sLTM4BH3V9RTh9 Pv6djp975AlsMACEWk4v281cTYig6SBdSQGapuAj24WCzT4BVAbprenOO8KBoG48X6W+ 9AGw== 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 :message-id:date:in-reply-to:subject:cc:to:from:references :dkim-signature; bh=xNuIDh9+z0CfhmCPEaKB/O13kWB7hEyf2+U7jlAoSUM=; b=fr17dCjGHxTR1mRKuSY3DDIg6qy6/ug+iKXUVCe5WLIqulyl9TSGNeHNA5AdBNpMfK 4zou/6aBKxbnb1BiPSomy05JNdd1pEfIbY+NXu8k4oTnl+DFHpQpZlqSzyZe0/5EoyFf l/VB8JJQG3gL7CFBp1qy2F4pH79EgO8pM6/Qdj9SWIYHLBvftEgx2HlE628Y4uUmqcGK +ZQdEEGTwplmCI3vsfZkKtBqRijZpT3BI2VKfZQ9hH6k5yu2YQO5MAurs2+oFCNM2PHj YXVUhmntoqFFnmrHiUSIBUGncZ/Xv5aTULnGIhXvBck+2x5i9gOv8D+1oy0xTff00KMV weow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PMUoELhE; 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 v202-20020a6361d3000000b00460b3aecba3si9864138pgb.542.2022.11.07.13.03.55; Mon, 07 Nov 2022 13:04:08 -0800 (PST) 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=20210112 header.b=PMUoELhE; 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 S232854AbiKGU5a (ORCPT + 93 others); Mon, 7 Nov 2022 15:57:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233103AbiKGU5X (ORCPT ); Mon, 7 Nov 2022 15:57:23 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179992B632; Mon, 7 Nov 2022 12:57:22 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id cl5so18010443wrb.9; Mon, 07 Nov 2022 12:57:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:references:from:to:cc:subject:date:message-id :reply-to; bh=xNuIDh9+z0CfhmCPEaKB/O13kWB7hEyf2+U7jlAoSUM=; b=PMUoELhE6AnXK+iNbgb6rPTOJPEKsFgBujXqxbWpgwA5fYf4gBdL2QEZ7s38On6Pdv tEvNrpWkJH7345NtNVL6P6neZYoOwCet4Y628+aQE5juJnavU3qBi7KlO1rk5DAUAUOq 438HwMs8JiemVJnEaCYxBD3fJBcnKF+Ec4ElTT2rACGgYIzmW6zjKAQjhVEt1OoUDQVI vKeu2GP4yAVneediojKblkMb81j+Ywo5HajTIEQtgDumphUC4m8/Zrw4Q3MU5M1r0ziT 8aiG4DnxTEwp4bvltkVyz/XtyJfkf0wefxRxSHxi02sFECEhyFppC6IqlBS76u0z4eLR 9SRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:references:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=xNuIDh9+z0CfhmCPEaKB/O13kWB7hEyf2+U7jlAoSUM=; b=JsLXa4biJokzvgDsx+WOLHELdsIAyAbr1+6cee+6wTnxzoPbYO3BjrlijspssfmSsN LLKLAQtUd11MPSOft6/+qp0XLIUFdAucPc6sSg0QqoC2Wr1e+vyXaw7nD2f8njvVc7js YVv6k057OaofuB4C/P03K/1WVJmMUwPqp21RGCRgGzjqOVluY3UhGcMP5Oq7zbAJIR4L rupNKoKRlDmlhmgaya5NZeC3fOcZfty3co0Zfu6EtzAYN072AxK8HYIAfbqUn7on/7aK vzs8Ivp2AZ066VMASy1c03lMmbFvQHzOjxs6hbDjwP5wF9xjOrWitpeqmorPMk1uWQ7Q TGeA== X-Gm-Message-State: ACrzQf3kfBuprYTJPLuhCSQIBntTUEWaV5wtsTUrU+HdBAeT/xqoPqsW aOk8Oae3zleHQh8DR1wjKrs= X-Received: by 2002:a5d:4ec1:0:b0:22e:435c:1e0f with SMTP id s1-20020a5d4ec1000000b0022e435c1e0fmr633954wrv.200.1667854640408; Mon, 07 Nov 2022 12:57:20 -0800 (PST) Received: from localhost (188.28.3.103.threembb.co.uk. [188.28.3.103]) by smtp.gmail.com with ESMTPSA id m1-20020a7bca41000000b003c6c3fb3cf6sm9173176wml.18.2022.11.07.12.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 12:57:19 -0800 (PST) References: <20221018-clk-range-checks-fixes-v2-0-f6736dec138e@cerno.tech> <20221018-clk-range-checks-fixes-v2-56-f6736dec138e@cerno.tech> <80VTKR.CE8RVN8M3ZYK3@crapouillou.net> <20221104145946.orsyrhiqvypisl5j@houat> <20221107085417.xrsh6xy3ouwdkp4z@houat> From: Aidan MacDonald To: Maxime Ripard Cc: Paul Cercueil , Stephen Boyd , Maxime Coquelin , Chen-Yu Tsai , Daniel Vetter , Nicolas Ferre , Thierry Reding , Jaroslav Kysela , Shawn Guo , Fabio Estevam , Ulf Hansson , Claudiu Beznea , Michael Turquette , Dinh Nguyen , Chunyan Zhang , Manivannan Sadhasivam , Andreas =?utf-8?Q?F=C3=A4rber?= , Jonathan Hunter , Abel Vesa , Charles Keepax , Alessandro Zummo , Peter De Schrijver , Orson Zhai , Alexandre Torgue , Prashant Gaikwad , Liam Girdwood , Alexandre Belloni , Samuel Holland , Matthias Brugger , Richard Fitzgerald , Vinod Koul , NXP Linux Team , Sekhar Nori , Kishon Vijay Abraham I , Linus Walleij , Takashi Iwai , David Airlie , Luca Ceresoli , Jernej Skrabec , Pengutronix Kernel Team , Baolin Wang , David Lechner , Sascha Hauer , Mark Brown , Max Filippov , Geert Uytterhoeven , linux-stm32@st-md-mailman.stormreply.com, alsa-devel@alsa-project.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, linux-mips@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-actions@lists.infradead.org, linux-clk@vger.kernel.org, AngeloGioacchino Del Regno , patches@opensource.cirrus.com, linux-tegra@vger.kernel.org, linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH v2 56/65] clk: ingenic: cgu: Switch to determine_rate In-reply-to: <20221107085417.xrsh6xy3ouwdkp4z@houat> Date: Mon, 07 Nov 2022 20:57:22 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 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 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 Maxime Ripard writes: > Hi, > > On Fri, Nov 04, 2022 at 05:35:29PM +0000, Aidan MacDonald wrote: >> >> Maxime Ripard writes: >> >> > Hi Paul, >> > >> > On Fri, Nov 04, 2022 at 02:31:20PM +0000, Paul Cercueil wrote: >> >> Le ven. 4 nov. 2022 =C3=A0 14:18:13 +0100, Maxime Ripard a >> >> =C3=A9crit : >> >> > The Ingenic CGU clocks implements a mux with a set_parent hook, but >> >> > doesn't provide a determine_rate implementation. >> >> > >> >> > This is a bit odd, since set_parent() is there to, as its name impl= ies, >> >> > change the parent of a clock. However, the most likely candidate to >> >> > trigger that parent change is a call to clk_set_rate(), with >> >> > determine_rate() figuring out which parent is the best suited for a >> >> > given rate. >> >> > >> >> > The other trigger would be a call to clk_set_parent(), but it's far= less >> >> > used, and it doesn't look like there's any obvious user for that cl= ock. >> >> > >> >> > So, the set_parent hook is effectively unused, possibly because of = an >> >> > oversight. However, it could also be an explicit decision by the >> >> > original author to avoid any reparenting but through an explicit ca= ll to >> >> > clk_set_parent(). >> >> > >> >> > The driver does implement round_rate() though, which means that we = can >> >> > change the rate of the clock, but we will never get to change the >> >> > parent. >> >> > >> >> > However, It's hard to tell whether it's been done on purpose or not. >> >> > >> >> > Since we'll start mandating a determine_rate() implementation, let's >> >> > convert the round_rate() implementation to a determine_rate(), which >> >> > will also make the current behavior explicit. And if it was an >> >> > oversight, the clock behaviour can be adjusted later on. >> >> >> >> So it's partly on purpose, partly because I didn't know about >> >> .determine_rate. >> >> >> >> There's nothing odd about having a lonely .set_parent callback; in my= case >> >> the clocks are parented from the device tree. >> >> >> >> Having the clocks driver trigger a parent change when requesting a ra= te >> >> change sounds very dangerous, IMHO. My MMC controller can be parented= to the >> >> external 48 MHz oscillator, and if the card requests 50 MHz, it could= switch >> >> to one of the PLLs. That works as long as the PLLs don't change rate,= but if >> >> one is configured as driving the CPU clock, it becomes messy. >> >> The thing is, the clocks driver has no way to know whether or not it = is >> >> "safe" to use a designated parent. >> >> >> >> For that reason, in practice, I never actually want to have a clock >> >> re-parented - it's almost always a bad idea vs. sticking to the paren= t clock >> >> configured in the DTS. >> > >> > Yeah, and this is totally fine. But we need to be explicit about it. T= he >> > determine_rate implementation I did in all the patches is an exact >> > equivalent to the round_rate one if there was one. We will never ask to >> > change the parent. >> > >> > Given what you just said, I would suggest to set the >> > CLK_SET_RATE_NO_REPARENT flag as well. >> >> Ideally there should be a way for drivers and the device tree to >> say, "clock X must be driven by clock Y", but the clock framework >> would be allowed to re-parent clocks freely as long as it doesn't >> violate any DT or driver constraints. > > I'm not really sure what you mean there, sorry. Isn't it what > assigned-clock-parents/clk_set_parent() at probe, plus a determine_rate > implementation that would affect best_parent_hw would already provide? Assigning the parent clock in the DT works once, at boot, but going off what you wrote in the commit message, if the clock driver has a .determine_rate() implementation that *can* reparent clocks then it probably *will* reparent them, and the DT assignment will be lost. What I'm suggesting is a runtime constraint that the clock subsystem would enforce, and actively prevent drivers from changing the parent. Either explicitly with clk_set_parent() or due to .determine_rate(). That way you could write a .determine_rate() implementation that *can* select a better parent, but if the DT applies a constraint to fix the clock to a particular parent, the clock subsystem will force that parent to be used so you can be sure the clock is never reparented by accident. >> That way allowing reparenting doesn't need to be an all-or-nothing >> thing, and it doesn't need to be decided at the clock driver level >> with special flags. > > Like I said, the default implementation is already working to what you > suggested if I understood properly. However, this has never been tested > for any of the drivers in that series so I don't want to introduce (and > debug ;)) regressions in all those drivers that were not setting any > constraint but never actually tested their reparenting code. > > So that series is strictly equivalent to what you had before, it's just > explicit now. > > If you find that some other decision make sense for your driver in > particular cases, feel free to change it. I barely know most of these > platforms, so I won't be able to make that decision (and test it) > unfortunately. > > Maxime That's OK, I didn't review the patch, I'm just making a general suggestion. :)