From: Andrea della Porta <andrea.porta@suse.com>
To: Stephen Boyd <sboyd@kernel.org>
Cc: "Andrea della Porta" <andrea.porta@suse.com>,
"Andrew Lunn" <andrew@lunn.ch>, "Arnd Bergmann" <arnd@arndb.de>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Conor Dooley" <conor+dt@kernel.org>,
"Derek Kiernan" <derek.kiernan@amd.com>,
"Dragan Cvetic" <dragan.cvetic@amd.com>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Herve Codina" <herve.codina@bootlin.com>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Michael Turquette" <mturquette@baylibre.com>,
"Rob Herring" <robh@kernel.org>,
"Saravana Kannan" <saravanak@google.com>,
"St efan Wahren" <wahrenst@gmx.net>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Will Deacon" <will@kernel.org>,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org, phil@raspberrypi.com,
jonathan@raspberrypi.com
Subject: Re: [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1
Date: Sun, 27 Oct 2024 12:28:23 +0100 [thread overview]
Message-ID: <Zx4j1-y26si9Ojp8@apocalypse> (raw)
In-Reply-To: <21fe104262989f04fadf9ec57dcac6df.sboyd@kernel.org>
Hi Stephen,
On 14:52 Wed 23 Oct , Stephen Boyd wrote:
> Quoting Andrea della Porta (2024-10-23 08:36:06)
> > Hi Stephen,
> >
> > On 15:08 Wed 09 Oct , Stephen Boyd wrote:
> > > Quoting Andrea della Porta (2024-10-07 05:39:51)
> > > > diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> > > > index 299bc678ed1b..537019987f0c 100644
> > > > --- a/drivers/clk/Kconfig
> > > > +++ b/drivers/clk/Kconfig
> > > > @@ -88,6 +88,15 @@ config COMMON_CLK_RK808
> > > > These multi-function devices have two fixed-rate oscillators, clocked at 32KHz each.
> > > > Clkout1 is always on, Clkout2 can off by control register.
> > > >
> > > > +config COMMON_CLK_RP1
> > > > + tristate "Raspberry Pi RP1-based clock support"
> > > > + depends on PCI || COMPILE_TEST
> > >
> > > A better limit would be some ARCH_* config.
> >
> > I've avoided ARCH_BCM2835 since the original intention is for this driver
> > to work (in the future) also for custom PCI cards with RP1 on-board, and not
> > only for Rpi5.
>
> How will that custom PCI card work? It will need this driver to probe?
AFAICT there's no commercially available PCI card slot sporting an RP1 on-board,
but this driver should be used to probe and use that card too.
> Is the iomem going to be exposed through some PCI config space?
Yes, just as leverage in this driver through BAR1.
>
> It's not great to depend on CONFIG_PCI because then the driver is forced
> to be =m if PCI ever becomes tristate (unlikely, but still makes for bad
> copy/pasta). I understand this line is trying to limit the availability
> of the config symbol. Maybe it should simply depend on ARM or ARM64? Or
> on nothing at all.
I see, Herve proposed CONFIG_MISC_RP1 that is enabled whenever this driver is
selected, and it makes a lot of sense to me.
>
> >
> > > > diff --git a/drivers/clk/clk-rp1.c b/drivers/clk/clk-rp1.c
> > > > new file mode 100644
> > > > index 000000000000..9016666fb27d
> > > > --- /dev/null
> > > > +++ b/drivers/clk/clk-rp1.c
> > >
> > > > +#include <linux/clk.h>
> > >
> > > Preferably this include isn't included.
> >
> > This include is currently needed by devm_clk_get_enabled() to retrieve
> > the xosc. Since that clock is based on a crystal (so it's fixed and
> > always enabled), I'm planning to hardcode it in the driver. This will
> > not only get rid of the devm_clk_get_enabled() call (and hence of the
> > clk.h include), but it'll also simplify the top devicetree. No promise
> > though, I need to check a couple of things first.
>
> A clk provider (clk-provider.h) should ideally not be a clk consumer
> (clk.h).
Ack.
>
> >
> >
> > > > +
> > > > +static int rp1_pll_ph_set_rate(struct clk_hw *hw,
> > > > + unsigned long rate, unsigned long parent_rate)
> > > > +{
> > > > + struct rp1_pll_ph *pll_ph = container_of(hw, struct rp1_pll_ph, hw);
> > > > + const struct rp1_pll_ph_data *data = pll_ph->data;
> > > > +
> > > > + /* Nothing really to do here! */
> > >
> > > Is it read-only? Don't define a set_rate function then and make the rate
> > > determination function return the same value all the time.
> >
> > Not 100% sure about it, maybe Raspberry Pi colleagues can explain.
> > By 'rate determination function' you're referring (in this case) to
> > rp1_pll_ph_recalc_rate(), right?
>
> Yes.
>
> > If so, that clock type seems to have
> > a fixed divider but teh resulting clock depends on the parent rate, so
> > it has to be calculated.
>
> Sure, it has to be calculated, but it will return the rate that causes
> no change to the hardware. When that happens, the set_rate() op should
> be skipped, and you can see that with clk_divider_ro_ops not having a
> set_rate() function pointer.
Ack.
>
> >
> > > > +static int rp1_clock_determine_rate(struct clk_hw *hw,
> > > > + struct clk_rate_request *req)
> > > > +{
> > > > + struct clk_hw *parent, *best_parent = NULL;
> > > > + unsigned long best_rate = 0;
> > > > + unsigned long best_prate = 0;
> > > > + unsigned long best_rate_diff = ULONG_MAX;
> > > > + unsigned long prate, calc_rate;
> > > > + size_t i;
> > > > +
> > > > + /*
> > > > + * If the NO_REPARENT flag is set, try to use existing parent.
> > > > + */
> > > > + if ((clk_hw_get_flags(hw) & CLK_SET_RATE_NO_REPARENT)) {
> > >
> > > Is this flag ever set?
> >
> > Not right now, but it will be used as soon as I'll add the video clocks,
> > so I thought to leave it be to avoid adding it back in the future.
> > For this minimal support is not needed though, so let me know if you
> > want it removed.
> >
>
> Ok sure.
>
> >
> > > > +
> > > > + [RP1_CLK_ETH_TSU] = REGISTER_CLK(.name = "clk_eth_tsu",
> > > > + .parents = {"rp1-xosc"},
> > > > + .num_std_parents = 0,
> > > > + .num_aux_parents = 1,
> > > > + .ctrl_reg = CLK_ETH_TSU_CTRL,
> > > > + .div_int_reg = CLK_ETH_TSU_DIV_INT,
> > > > + .sel_reg = CLK_ETH_TSU_SEL,
> > > > + .div_int_max = DIV_INT_8BIT_MAX,
> > > > + .max_freq = 50 * MHz,
> > > > + .fc0_src = FC_NUM(5, 7),
> > > > + ),
> > > > +
> > > > + [RP1_CLK_SYS] = REGISTER_CLK(.name = "clk_sys",
> > > > + .parents = {"rp1-xosc", "-", "pll_sys"},
> > >
> > > Please use struct clk_parent_data or clk_hw directly. Don't use strings
> > > to describe parents.
> >
> > Describing parents as as strings allows to directly assign it to struct
> > clk_init_data, as in rp1_register_clock():
> >
> > const struct rp1_clock_data *clock_data = data;
> > struct clk_init_data init = { };
> > ...
> > init.parent_names = clock_data->parents;
> >
> > otherwise we should create an array and populate from clk_parent_data::name,
> > which is of course feasible but a bit less compact. Are you sure you want
> > to change it?
> >
>
> Do not use strings to describe parents. That's the guiding principle
> here. I agree using strings certainly makes it easy to describe things
> but that doesn't mean it is acceptable.
Ack.
>
> > > > + struct clk *clk_xosc;
> > > > + struct clk_hw **hws;
> > > > + unsigned int i;
> > > > +
> > > > + clockman = devm_kzalloc(dev, struct_size(clockman, onecell.hws, asize),
> > > > + GFP_KERNEL);
> > > > + if (!clockman)
> > > > + return -ENOMEM;
> > > > +
> > > > + spin_lock_init(&clockman->regs_lock);
> > > > + clockman->dev = dev;
> > > > +
> > > > + clockman->regs = devm_platform_ioremap_resource(pdev, 0);
> > > > + if (IS_ERR(clockman->regs))
> > > > + return PTR_ERR(clockman->regs);
> > > > +
> > > > + clk_xosc = devm_clk_get_enabled(dev, NULL);
> > > > + if (IS_ERR(clk_xosc))
> > > > + return PTR_ERR(clk_xosc);
> > > > +
> > > > + clockman->hw_xosc = __clk_get_hw(clk_xosc);
> > >
> > > Please use struct clk_parent_data::index instead.
> >
> > Sorry, I didn't catch what you mean here. Can you please elaborate?
> >
>
> Don't use __clk_get_hw() at all. Also, don't use clk_get() and friends
> in clk provider drivers. Use struct clk_parent_data so that the
> framework can do the work for you at the right time.
Ack.
Many thanks,
Andrea
next prev parent reply other threads:[~2024-10-27 11:28 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 12:39 [PATCH v2 00/14] Add support for RaspberryPi RP1 PCI device using a DT overlay Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 01/14] dt-bindings: clock: Add RaspberryPi RP1 clock bindings Andrea della Porta
2024-10-08 6:31 ` Krzysztof Kozlowski
2024-10-21 17:07 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 02/14] dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings Andrea della Porta
2024-10-08 6:29 ` Krzysztof Kozlowski
2024-10-21 17:41 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 03/14] dt-bindings: pci: Add common schema for devices accessible through PCI BARs Andrea della Porta
2024-10-07 14:16 ` Rob Herring (Arm)
2024-10-08 6:24 ` Krzysztof Kozlowski
2024-10-22 9:16 ` Andrea della Porta
2024-10-10 2:47 ` Rob Herring
2024-10-22 9:16 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 04/14] dt-bindings: misc: Add device specific bindings for RaspberryPi RP1 Andrea della Porta
2024-10-08 6:26 ` Krzysztof Kozlowski
2024-10-22 10:00 ` Andrea della Porta
2024-10-10 2:52 ` Rob Herring
2024-10-22 9:30 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 05/14] PCI: of_property: Sanitize 32 bit PCI address parsed from DT Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 06/14] of: address: Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 07/14] gpiolib: Export symbol gpiochip_set_names() Andrea della Porta
2024-10-07 12:51 ` Bartosz Golaszewski
2024-10-07 12:39 ` [PATCH v2 08/14] clk: rp1: Add support for clocks provided by RP1 Andrea della Porta
2024-10-09 22:08 ` Stephen Boyd
2024-10-23 15:36 ` Andrea della Porta
2024-10-23 16:32 ` Herve Codina
2024-10-27 11:15 ` Andrea della Porta
2024-10-23 21:52 ` Stephen Boyd
2024-10-27 11:28 ` Andrea della Porta [this message]
2024-11-14 15:41 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 09/14] pinctrl: rp1: Implement RaspberryPi RP1 gpio support Andrea della Porta
2024-10-11 9:03 ` Linus Walleij
2024-10-11 10:08 ` Stefan Wahren
2024-10-27 11:32 ` Andrea della Porta
2024-10-27 11:32 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 10/14] arm64: dts: rp1: Add support for RaspberryPi's RP1 device Andrea della Porta
2024-10-07 14:57 ` Herve Codina
2024-10-27 13:26 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 11/14] misc: rp1: RaspberryPi RP1 misc driver Andrea della Porta
2024-10-07 15:41 ` Herve Codina
2024-10-28 9:57 ` Andrea della Porta
2024-10-10 19:03 ` kernel test robot
2024-10-11 5:15 ` kernel test robot
2024-10-24 15:21 ` Dave Stevenson
2024-10-25 8:29 ` Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 12/14] arm64: dts: bcm2712: Add external clock for RP1 chipset on Rpi5 Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 13/14] arm64: dts: Add DTS overlay for RP1 gpio line names Andrea della Porta
2024-10-07 12:39 ` [PATCH v2 14/14] arm64: defconfig: Enable RP1 misc/clock/gpio drivers Andrea della Porta
2024-10-08 6:32 ` Krzysztof Kozlowski
2024-10-28 10:36 ` Andrea della Porta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zx4j1-y26si9Ojp8@apocalypse \
--to=andrea.porta@suse.com \
--cc=andrew@lunn.ch \
--cc=arnd@arndb.de \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhelgaas@google.com \
--cc=brgl@bgdev.pl \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=derek.kiernan@amd.com \
--cc=devicetree@vger.kernel.org \
--cc=dragan.cvetic@amd.com \
--cc=florian.fainelli@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=herve.codina@bootlin.com \
--cc=jonathan@raspberrypi.com \
--cc=krzk+dt@kernel.org \
--cc=kw@linux.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=lpieralisi@kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=manivannan.sadhasivam@linaro.org \
--cc=masahiroy@kernel.org \
--cc=mturquette@baylibre.com \
--cc=phil@raspberrypi.com \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=sboyd@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=wahrenst@gmx.net \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).