Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp882420pxb; Wed, 27 Oct 2021 14:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeQqdfTFSQ70mvyL33dojw5VUFYddlSt7oJsGVsKba54PFgWKdYNOqW/2h77Q/3v70Zry1 X-Received: by 2002:a50:da48:: with SMTP id a8mr427383edk.155.1635369861469; Wed, 27 Oct 2021 14:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369861; cv=none; d=google.com; s=arc-20160816; b=A029rUVXV45/3+eGO9AjLXvmmEPkJMxsqk9AuxKVGcEMkAZEYoU2+uZ7KFPlh89ml8 wZeUuzdzrgG0IDDUo60OQ5LXrQsbsyvbfnGiCtRE+oqJW91HNEo0Hm2yslYbR+9q1Mbt LQca+9fLKF26xAnZBlcJgJa0vsaTmV+E5uFq6qiqtsKKRdDKzPUuwsv1/BmUzLWEIOMT XiwUxl6B3pxpV+3XOUEa5e+uIbq6t1mXny9gEWpZLy5041YJbPD1PioV26WhBwVc0y6V bwHWbqLwqv1IzDH4g2oWIBg+zIvSI0Ui/FmcFMXXAaTBV1zxksz8VBMfTlVUv3uNCEBj RwoQ== 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; bh=BiML64M/ZDvyFY9rZ7QddrucYVgq/xM1VLXouL/jQco=; b=gHDC+5l4889cT7MU/49czJDTuxbfwAqYCwS5fbpqUXnhT0Ytx+7yIonfefHr/JFaNR 1Gae4ssMIDbU3AFQVUCiKnn8n+ANh3SpcLzDrtRBzYND0S0QqEuNucQlaqUN4a7IyRbY tcBLLTf+qMl1ZTDkgMGUeqNwrqyVVL/EEK4kV3FRffpF37bSNLz65pDGdJ3xqoSKiBqu 9y4f60GhlYzlWMUKEJHXCHhZdF/Mn1j7Rdm/sMRfQ+LRPDoaVN9gGkBPEhuZL2O088Wh 5o3Qqa1fGO62a2d7yF9fYs132BbE7yHI6q/4Po6DXCLWUZn2Y9PFmv4qR3fx4LfZ14q3 7v8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l16si1748532edb.108.2021.10.27.14.23.54; Wed, 27 Oct 2021 14:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237319AbhJ0LZI (ORCPT + 97 others); Wed, 27 Oct 2021 07:25:08 -0400 Received: from gloria.sntech.de ([185.11.138.130]:45532 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234141AbhJ0LZG (ORCPT ); Wed, 27 Oct 2021 07:25:06 -0400 Received: from ip5f5a6e92.dynamic.kabel-deutschland.de ([95.90.110.146] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfh0c-0002rs-6H; Wed, 27 Oct 2021 13:22:18 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Stephen Boyd , linux-riscv@lists.infradead.org Cc: "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , linux-clk , "open list:GPIO SUBSYSTEM" , linux-riscv , "open list:SERIAL DRIVERS" , Geert Uytterhoeven , Palmer Dabbelt , Paul Walmsley , Rob Herring , Michael Turquette , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , Daniel Lezcano , Andy Shevchenko , Jiri Slaby , Maximilian Luz , Sagar Kadam , Drew Fustini , Michael Zhu , Fu Wei , Anup Patel , Atish Patra , Linux Kernel Mailing List , Emil Renner Berthing Subject: Re: [PATCH v2 06/16] clk: starfive: Add JH7100 clock generator driver Date: Wed, 27 Oct 2021 13:22:16 +0200 Message-ID: <8431982.yxsUHB6BNW@diego> In-Reply-To: References: <20211021174223.43310-1-kernel@esmil.dk> <163529604399.15791.378104318036812951@swboyd.mtv.corp.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Mittwoch, 27. Oktober 2021, 12:24:07 CEST schrieb Emil Renner Berthing: > On Wed, 27 Oct 2021 at 02:54, Stephen Boyd wrote: > > Quoting Emil Renner Berthing (2021-10-26 15:35:36) > > > On Tue, 26 Oct 2021 at 22:20, Stephen Boyd wrote: > > > > Quoting Emil Renner Berthing (2021-10-21 10:42:13) > > > > > +}; > > > > > + > > > > > +struct clk_starfive_jh7100_priv { > > > > > + /* protect registers against overlapping read-modify-write */ > > > > > + spinlock_t rmw_lock; > > > > > > > > Does overlapping mean concurrent? > > > > > > Yes, sorry. > > > > > > > Do different clks share the same registers? > > > > > > No, each clock has their own register, but they use that register both > > > to gate the clock and other configuration. The Locking chapter of > > > Documentation/driver-api/clk.rst talks about the prepare lock and the > > > enable lock and then says: > > > "However, access to resources that are shared between operations of > > > the two groups needs to be protected by the drivers. An example of > > > such a resource would be a register that controls both the clock rate > > > and the clock enable/disable state." > > > > Alright got it. Maybe say "protect clk enable and set rate from > > happening at the same time". > > > > > > > > > > + return ERR_PTR(-EINVAL); > > > > > + } > > > > > + > > > > > + if (idx >= JH7100_CLK_PLL0_OUT) > > > > > + return priv->pll[idx - JH7100_CLK_PLL0_OUT]; > > > > > + > > > > > + return &priv->reg[idx].hw; > > > > > +} > > > > > + > > > > > +static int __init clk_starfive_jh7100_probe(struct platform_device *pdev) > > > > > > > > Drop __init as this can be called after kernel init is over. > > > > > > Oh interesting, I'd like to know when that can happen. The comment for > > > the builtin_platform_driver macro says it's just a wrapper for > > > > I thought this was using module_platform_driver() macro? > > > > > device_initcall. > > > > > > Won't we then need to remove all the __initconst tags too since the > > > probe function walks through jh7100_clk_data which eventually > > > references all __initconst data? > > > > Yes. If it's builtin_platform_driver() it can't be a module/tristate > > Kconfig, in which case all the init markings can stay. > > Yes, it's already bool in the Kconfig file. After looking into this I > think it's better to do like the rockchip drivers and use > builtin_platform_driver_probe to make sure the probe function only > called at kernel init time: > > static struct platform_driver clk_starfive_jh7100_driver = { > .driver = { > .name = "clk-starfive-jh7100", > .of_match_table = clk_starfive_jh7100_match, > .suppress_bind_attrs = true, > }, > }; > builtin_platform_driver_probe(clk_starfive_jh7100_driver, > clk_starfive_jh7100_probe); > > @Andy: is the supress_bind_attrs what you were asking about? > > > > > > + > > > > > + clk->hw.init = &init; > > > > > + clk->idx = idx; > > > > > + clk->max = jh7100_clk_data[idx].max; > > > > > + > > > > > + ret = clk_hw_register(priv->dev, &clk->hw); > > > > > > > > Why not use devm_clk_hw_register()? > > > > > > I probably could. Just for my understanding that's just to avoid the > > > loop on error below, because as a builtin driver the device won't > > > otherwise go away, right? > > > > Yes > > > > > > > > > > + if (ret) > > > > > + goto err; > > > > > + } > > > > > + > > > > > + ret = devm_of_clk_add_hw_provider(priv->dev, clk_starfive_jh7100_get, priv); > > > > > + if (ret) > > > > > + goto err; > > > > > + > > > > > + return 0; > > > > > +err: > > > > > + while (idx) > > > > > + clk_hw_unregister(&priv->reg[--idx].hw); > > > > > + return ret; > > > > > +} > > > > > + > > > > > +static const struct of_device_id clk_starfive_jh7100_match[] = { > > > > > + { .compatible = "starfive,jh7100-clkgen" }, > > > > > + { /* sentinel */ } > > > > > +}; > > > > > > > > Please add MODULE_DEVICE_TABLE() > > > > > > Will do! > > > > If it's never going to be a module then don't add any module_* things. > > So does that just mean no MODULE_DEVICE_TABLE or should I also remove > MODULE_DESCRIPTION, MODULE_AUTHOR and MODULE_LICENSE? I'm just double > checking because the rockchip drivers seem to have MODULE_DESCRIPTION > and MODULE_LICENSE lines. reading this I realized that the current implementation on the Rockchip side is faulty :-) . For one, there recently was a change for 5.16 that moved this to use module_platform_driver, while keeping the initdata, which suggest that the change was actually not tested at all in that context. And secondly the kconfig is wrong to actually use tristate and should instead use bool. Of course this is also influenced by the recent GKI discussion [0] ;-) I'm going to revert the one change and also adapt the kconfig to use bool again. Heiko [0] https://lwn.net/Articles/872209/