* [PATCH v5] pinctrl: stm32: Add check for clk_enable()
@ 2024-12-15 20:40 Mingwei Zheng
2024-12-15 23:41 ` Marek Vasut
0 siblings, 1 reply; 4+ messages in thread
From: Mingwei Zheng @ 2024-12-15 20:40 UTC (permalink / raw)
To: antonio.borneo
Cc: marex, linus.walleij, mcoquelin.stm32, alexandre.torgue, make24,
peng.fan, fabien.dessenne, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel, Mingwei Zheng, Jiasheng Jiang
Convert the driver to clk_bulk*() API.
Add check for the return value of clk_bulk_enable() to catch
the potential error.
Fixes: 05d8af449d93 ("pinctrl: stm32: Keep pinctrl block clock enabled when LEVEL IRQ requested")
Signed-off-by: Mingwei Zheng <zmw12306@gmail.com>
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v4 -> v5:
1. Move the clock handling from stm32_gpiolib_register_bank()
and moving it to its caller.
2. Call clk_bulk_prepare_enable() in stm32_pctl_probe()
and clk_bulk_disable_unprepare() for error.
v3 -> v4:
1. Add initialization for pctl->clks.
2. Adjust alignment.
v2 -> v3:
1. Convert clk_disable_unprepare to clk_bulk_disable
and clk_bulk_unprepare.
v1 -> v2:
1. Move int ret declaration into if block.
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 70 ++++++++++++---------------
1 file changed, 32 insertions(+), 38 deletions(-)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 5b7fa77c1184..5874a054dc48 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -86,7 +86,6 @@ struct stm32_pinctrl_group {
struct stm32_gpio_bank {
void __iomem *base;
- struct clk *clk;
struct reset_control *rstc;
spinlock_t lock;
struct gpio_chip gpio_chip;
@@ -108,6 +107,7 @@ struct stm32_pinctrl {
unsigned ngroups;
const char **grp_names;
struct stm32_gpio_bank *banks;
+ struct clk_bulk_data *clks;
unsigned nbanks;
const struct stm32_pinctrl_match_data *match_data;
struct irq_domain *domain;
@@ -1308,12 +1308,6 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
if (IS_ERR(bank->base))
return PTR_ERR(bank->base);
- err = clk_prepare_enable(bank->clk);
- if (err) {
- dev_err(dev, "failed to prepare_enable clk (%d)\n", err);
- return err;
- }
-
bank->gpio_chip = stm32_gpio_template;
fwnode_property_read_string(fwnode, "st,bank-name", &bank->gpio_chip.label);
@@ -1360,26 +1354,21 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
bank->fwnode, &stm32_gpio_domain_ops,
bank);
- if (!bank->domain) {
- err = -ENODEV;
- goto err_clk;
- }
+ if (!bank->domain)
+ return -ENODEV;
}
names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
- if (!names) {
- err = -ENOMEM;
- goto err_clk;
- }
+ if (!names)
+ return -ENOMEM;
for (i = 0; i < npins; i++) {
stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
if (stm32_pin && stm32_pin->pin.name) {
names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
- if (!names[i]) {
- err = -ENOMEM;
- goto err_clk;
- }
+ if (!names[i])
+ return -ENOMEM;
+
} else {
names[i] = NULL;
}
@@ -1390,15 +1379,11 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
err = gpiochip_add_data(&bank->gpio_chip, bank);
if (err) {
dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_nr);
- goto err_clk;
+ return err;
}
dev_info(dev, "%s bank added\n", bank->gpio_chip.label);
return 0;
-
-err_clk:
- clk_disable_unprepare(bank->clk);
- return err;
}
static struct irq_domain *stm32_pctrl_get_irq_domain(struct platform_device *pdev)
@@ -1617,10 +1602,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
return -EINVAL;
}
pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks),
- GFP_KERNEL);
+ GFP_KERNEL);
if (!pctl->banks)
return -ENOMEM;
+ pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks),
+ GFP_KERNEL);
+ if (!pctl->clks)
+ return -ENOMEM;
+
+ for (i = 0; i < banks; ++i)
+ pctl->clks[i].id = "";
+
i = 0;
for_each_gpiochip_node(dev, child) {
struct stm32_gpio_bank *bank = &pctl->banks[i];
@@ -1631,11 +1624,10 @@ int stm32_pctl_probe(struct platform_device *pdev)
fwnode_handle_put(child);
return -EPROBE_DEFER;
}
-
- bank->clk = of_clk_get_by_name(np, NULL);
- if (IS_ERR(bank->clk)) {
+ pctl->clks[i].clk = of_clk_get_by_name(np, NULL);
+ if (IS_ERR(pctl->clks[i].clk)) {
fwnode_handle_put(child);
- return dev_err_probe(dev, PTR_ERR(bank->clk),
+ return dev_err_probe(dev, PTR_ERR(pctl->clks[i].clk),
"failed to get clk\n");
}
i++;
@@ -1646,15 +1638,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
if (ret) {
fwnode_handle_put(child);
- for (i = 0; i < pctl->nbanks; i++)
- clk_disable_unprepare(pctl->banks[i].clk);
-
return ret;
}
pctl->nbanks++;
}
+ ret = clk_bulk_prepare_enable(pctl->nbanks, pctl->clks);
+ if (ret) {
+ dev_err(dev, "failed to prepare_enable clk (%d)\n", ret);
+ return ret;
+ }
+
dev_info(dev, "Pinctrl STM32 initialized\n");
return 0;
@@ -1726,10 +1721,8 @@ static int __maybe_unused stm32_pinctrl_restore_gpio_regs(
int __maybe_unused stm32_pinctrl_suspend(struct device *dev)
{
struct stm32_pinctrl *pctl = dev_get_drvdata(dev);
- int i;
- for (i = 0; i < pctl->nbanks; i++)
- clk_disable(pctl->banks[i].clk);
+ clk_bulk_disable(pctl->nbanks, pctl->clks);
return 0;
}
@@ -1738,10 +1731,11 @@ int __maybe_unused stm32_pinctrl_resume(struct device *dev)
{
struct stm32_pinctrl *pctl = dev_get_drvdata(dev);
struct stm32_pinctrl_group *g = pctl->groups;
- int i;
+ int i, ret;
- for (i = 0; i < pctl->nbanks; i++)
- clk_enable(pctl->banks[i].clk);
+ ret = clk_bulk_enable(pctl->nbanks, pctl->clks);
+ if (ret)
+ return ret;
for (i = 0; i < pctl->ngroups; i++, g++)
stm32_pinctrl_restore_gpio_regs(pctl, g->pin);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v5] pinctrl: stm32: Add check for clk_enable()
2024-12-15 20:40 [PATCH v5] pinctrl: stm32: Add check for clk_enable() Mingwei Zheng
@ 2024-12-15 23:41 ` Marek Vasut
2024-12-23 2:23 ` Mingwei Zheng
2025-01-02 11:15 ` Antonio Borneo
0 siblings, 2 replies; 4+ messages in thread
From: Marek Vasut @ 2024-12-15 23:41 UTC (permalink / raw)
To: Mingwei Zheng, antonio.borneo
Cc: linus.walleij, mcoquelin.stm32, alexandre.torgue, make24,
peng.fan, fabien.dessenne, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel, Jiasheng Jiang
On 12/15/24 9:40 PM, Mingwei Zheng wrote:
[...]
> @@ -1617,10 +1602,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
> return -EINVAL;
> }
> pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks),
> - GFP_KERNEL);
> + GFP_KERNEL);
Please drop this one change.
> if (!pctl->banks)
> return -ENOMEM;
>
> + pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks),
> + GFP_KERNEL);
> + if (!pctl->clks)
> + return -ENOMEM;
> +
> + for (i = 0; i < banks; ++i)
> + pctl->clks[i].id = "";
Is this ^ assignment necessary ? If so, why ?
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5] pinctrl: stm32: Add check for clk_enable()
2024-12-15 23:41 ` Marek Vasut
@ 2024-12-23 2:23 ` Mingwei Zheng
2025-01-02 11:15 ` Antonio Borneo
1 sibling, 0 replies; 4+ messages in thread
From: Mingwei Zheng @ 2024-12-23 2:23 UTC (permalink / raw)
To: Marek Vasut
Cc: antonio.borneo, linus.walleij, mcoquelin.stm32, alexandre.torgue,
make24, peng.fan, fabien.dessenne, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel, Jiasheng Jiang
Hi Marek,
On Sun, Dec 15, 2024 at 6:54 PM Marek Vasut <marex@denx.de> wrote:
>
> On 12/15/24 9:40 PM, Mingwei Zheng wrote:
>
> [...]
>
> > @@ -1617,10 +1602,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> > pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks),
> > - GFP_KERNEL);
> > + GFP_KERNEL);
>
> Please drop this one change.
Fixed in PATCH v6.
>
> > if (!pctl->banks)
> > return -ENOMEM;
> >
> > + pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks),
> > + GFP_KERNEL);
> > + if (!pctl->clks)
> > + return -ENOMEM;
> > +
> > + for (i = 0; i < banks; ++i)
> > + pctl->clks[i].id = "";
>
> Is this ^ assignment necessary ? If so, why ?
>
> [...]
Thanks for pointing this out. We call devm_clk_bulk_get_all in
stm32_pctl_probe() to handle get clk in PATCH v6.
Best,
Mingwei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5] pinctrl: stm32: Add check for clk_enable()
2024-12-15 23:41 ` Marek Vasut
2024-12-23 2:23 ` Mingwei Zheng
@ 2025-01-02 11:15 ` Antonio Borneo
1 sibling, 0 replies; 4+ messages in thread
From: Antonio Borneo @ 2025-01-02 11:15 UTC (permalink / raw)
To: Marek Vasut, Mingwei Zheng
Cc: linus.walleij, mcoquelin.stm32, alexandre.torgue, make24,
peng.fan, fabien.dessenne, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel, Jiasheng Jiang
On Mon, 2024-12-16 at 00:41 +0100, Marek Vasut wrote:
> On 12/15/24 9:40 PM, Mingwei Zheng wrote:
>
> [...]
>
> > @@ -1617,10 +1602,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> > pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks),
> > - GFP_KERNEL);
> > + GFP_KERNEL);
>
> Please drop this one change.
>
> > if (!pctl->banks)
> > return -ENOMEM;
> >
> > + pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks),
> > + GFP_KERNEL);
> > + if (!pctl->clks)
> > + return -ENOMEM;
> > +
> > + for (i = 0; i < banks; ++i)
> > + pctl->clks[i].id = "";
>
> Is this ^ assignment necessary ? If so, why ?
The existing DTs don't have the 'clock-names' property, whose value is used to set this struct clk_bulk_data::id.
With this field kept at NULL, the error messages in clk_bulk_enable() and similar should print '(null)'.
This line sets it to empty string.
I would say it's not necessary, but I don't know if it's better to have:
"Failed to enable clk '': %d"
or
"Failed to enable clk '(null)': %d"
Antonio
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-02 11:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-15 20:40 [PATCH v5] pinctrl: stm32: Add check for clk_enable() Mingwei Zheng
2024-12-15 23:41 ` Marek Vasut
2024-12-23 2:23 ` Mingwei Zheng
2025-01-02 11:15 ` Antonio Borneo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox