From: Krzysztof Kozlowski <krzk@kernel.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org,
Thomas Fossati <thomas.fossati@linaro.org>,
Larisa Grigore <Larisa.Grigore@nxp.com>,
Ghennadi Procopciuc <ghennadi.procopciuc@nxp.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
"moderated list:ARM/STM32 ARCHITECTURE"
<linux-stm32@st-md-mailman.stormreply.com>,
"moderated list:ARM/STM32 ARCHITECTURE"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 2/2] clocksource/drivers/nxp-timer: Add the System Timer Module for the s32g platform
Date: Tue, 25 Mar 2025 08:30:08 +0100 [thread overview]
Message-ID: <bb7e4740-9608-4534-9c19-3ac066e2aa8f@kernel.org> (raw)
In-Reply-To: <20250324100008.346009-2-daniel.lezcano@linaro.org>
On 24/03/2025 11:00, Daniel Lezcano wrote:
> +
> +static int __init nxp_stm_clocksource_init(struct device *dev, const char *name,
> + void __iomem *base, struct clk *clk)
> +{
> + struct stm_timer *stm_timer;
> + int ret;
> +
> + stm_timer = devm_kzalloc(dev, sizeof(*stm_timer), GFP_KERNEL);
> + if (!stm_timer)
> + return -ENOMEM;
> +
> + stm_timer->base = base;
> + stm_timer->rate = clk_get_rate(clk);
> +
> + stm_timer->scs.cs.name = name;
You are aware that all node names will have exactly the same name? All
of them will be called "timer"?
> + stm_timer->scs.cs.rating = 460;
> + stm_timer->scs.cs.read = nxp_stm_clocksource_read;
> + stm_timer->scs.cs.enable = nxp_stm_clocksource_enable;
> + stm_timer->scs.cs.disable = nxp_stm_clocksource_disable;
> + stm_timer->scs.cs.suspend = nxp_stm_clocksource_suspend;
> + stm_timer->scs.cs.resume = nxp_stm_clocksource_resume;
> + stm_timer->scs.cs.mask = CLOCKSOURCE_MASK(32);
> + stm_timer->scs.cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
> +
> + ret = clocksource_register_hz(&stm_timer->scs.cs, stm_timer->rate);
> + if (ret)
> + return ret;
> +
> + stm_sched_clock = stm_timer;
> +
> + sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate);
> +
> + dev_set_drvdata(dev, stm_timer);
> +
> + dev_dbg(dev, "Registered clocksource %s\n", name);
Since all names will be the same, this makes little sense in debugging.
I guess you wanted one of the OF printk-formats for full node name.
> +
> + return 0;
> +}
> +
> +static int nxp_stm_clockevent_read_counter(struct stm_timer *stm_timer)
> +{
> + return readl(stm_timer->base + STM_CNT);
> +}
> +
...
> +
> +static int __init nxp_stm_timer_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct device_node *np = dev->of_node;
> + struct stm_instances *stm_instances;
> + const char *name = of_node_full_name(np);
> + void __iomem *base;
> + int irq, ret;
> + struct clk *clk;
> +
> + stm_instances = (typeof(stm_instances))of_device_get_match_data(dev);
No, you *cannot* drop the const. It's there on purpose. Match data
should be const because it defines per variant differences. That's why
the prototype of of_device_get_match_data() has such return type.
You just want some global singleton, not match data.
> + if (!stm_instances) {
> + dev_err(dev, "No STM instances associated with a cpu");
> + return -EINVAL;
> + }
> +
> + base = devm_of_iomap(dev, np, 0, NULL);
> + if (IS_ERR(base)) {
> + dev_err(dev, "Failed to iomap %pOFn\n", np);
You need to clean up the downstream code to match upstream. All of these
should be return dev_err_probe().
> + return PTR_ERR(base);
> + }
> +
> + irq = irq_of_parse_and_map(np, 0);
> + if (irq <= 0) {
> + dev_err(dev, "Failed to parse and map IRQ: %d\n", irq);
> + return -EINVAL;
> + }
> +
> + clk = devm_clk_get(dev, NULL);
> + if (IS_ERR(clk)) {
> + dev_err(dev, "Clock not found\n");
And this is clearly incorrect - spamming logs. Syntax is:
return dev_err_probe
> + return PTR_ERR(clk);
> + }
> +
> + ret = clk_prepare_enable(clk);
Drop, devm_clk_get_enabled.
> + if (ret) {
> + dev_err(dev, "Failed to enable STM timer clock: %d\n", ret);
> + return ret;
> + }
> +
> + if (!stm_instances->clocksource && (stm_instances->features & STM_CLKSRC)) {
> +
> + /*
> + * First probed STM will be a clocksource
> + */
> + ret = nxp_stm_clocksource_init(dev, name, base, clk);
> + if (ret)
> + return ret;
> + stm_instances->clocksource++;
That's racy. Devices can be brought async, ideally. This should be
rather idr or probably entire structure protected with a mutex.
> +
> + } else if (!stm_instances->clockevent_broadcast &&
> + (stm_instances->features & STM_CLKEVT_BROADCAST)) {
> +
> + /*
> + * Second probed STM will be a broadcast clockevent
> + */
> + ret = nxp_stm_clockevent_broadcast_init(dev, name, base, irq, clk);
> + if (ret)
> + return ret;
> + stm_instances->clockevent_broadcast++;
> +
> + } else if (stm_instances->clockevent_per_cpu < num_possible_cpus() &&
> + (stm_instances->features & STM_CLKEVT_PER_CPU)) {
> +
> + /*
> + * Next probed STM will be a per CPU clockevent, until
> + * we probe as much as we have CPUs available on the
> + * system, we do a partial initialization
> + */
> + ret = nxp_stm_clockevent_per_cpu_init(dev, name, base, irq, clk,
> + stm_instances->clockevent_per_cpu);
> + if (ret)
> + return ret;
> +
> + stm_instances->clockevent_per_cpu++;
> +
> + /*
> + * The number of probed STM for per CPU clockevent is
> + * equal to the number of available CPUs on the
> + * system. We install the cpu hotplug to finish the
> + * initialization by registering the clockevents
> + */
> + if (stm_instances->clockevent_per_cpu == num_possible_cpus()) {
> + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "STM timer:starting",
> + nxp_stm_clockevent_starting_cpu, NULL);
> + if (ret < 0)
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static struct stm_instances s32g_stm_instances = { .features = STM_CLKSRC | STM_CLKEVT_PER_CPU };
Missing const. Or misplaced - all file-scope static variables are
declared at the top.
> +
> +static const struct of_device_id nxp_stm_of_match[] = {
> + { .compatible = "nxp,s32g2-stm", &s32g_stm_instances },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, nxp_stm_of_match);
> +
> +static struct platform_driver nxp_stm_probe = {
> + .probe = nxp_stm_timer_probe,
> + .driver = {
> + .name = "nxp-stm",
> + .of_match_table = of_match_ptr(nxp_stm_of_match),
Drop of_match_ptr, you have here warnings.
> + },
> +};
> +module_platform_driver(nxp_stm_probe);
> +
> +MODULE_DESCRIPTION("NXP System Timer Module driver");
> +MODULE_LICENSE("GPL");
Best regards,
Krzysztof
next prev parent reply other threads:[~2025-03-25 7:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 10:00 [PATCH 1/2] dt-bindings: NXP System Timer Module Daniel Lezcano
2025-03-24 10:00 ` [PATCH 2/2] clocksource/drivers/nxp-timer: Add the System Timer Module for the s32g platform Daniel Lezcano
2025-03-25 7:28 ` Ghennadi Procopciuc
2025-03-25 10:53 ` Daniel Lezcano
2025-03-25 11:40 ` Ghennadi Procopciuc
2025-03-25 12:09 ` Daniel Lezcano
2025-03-25 12:21 ` Ghennadi Procopciuc
2025-03-25 12:51 ` Daniel Lezcano
2025-03-25 13:21 ` Ghennadi Procopciuc
2025-03-25 13:54 ` Daniel Lezcano
2025-03-26 7:44 ` Ghennadi Procopciuc
2025-03-26 8:06 ` Daniel Lezcano
2025-03-26 9:19 ` Daniel Lezcano
2025-03-26 9:57 ` Ghennadi Procopciuc
2025-03-26 10:31 ` Daniel Lezcano
2025-03-26 13:31 ` Ghennadi Procopciuc
2025-03-25 7:30 ` Krzysztof Kozlowski [this message]
2025-03-25 12:23 ` Daniel Lezcano
2025-03-25 12:30 ` Krzysztof Kozlowski
2025-03-25 18:38 ` Daniel Lezcano
2025-03-25 18:42 ` Krzysztof Kozlowski
2025-03-24 14:21 ` [PATCH 1/2] dt-bindings: NXP System Timer Module Rob Herring (Arm)
2025-03-24 14:35 ` Krzysztof Kozlowski
2025-03-24 14:44 ` Rob Herring
2025-03-31 10:49 ` Ghennadi Procopciuc
2025-03-31 11:59 ` Ghennadi Procopciuc
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=bb7e4740-9608-4534-9c19-3ac066e2aa8f@kernel.org \
--to=krzk@kernel.org \
--cc=Larisa.Grigore@nxp.com \
--cc=alexandre.torgue@foss.st.com \
--cc=daniel.lezcano@linaro.org \
--cc=ghennadi.procopciuc@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=tglx@linutronix.de \
--cc=thomas.fossati@linaro.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).