Skip to content

Commit 9527237

Browse files
Gabriel-Fernandzbebarino
authored andcommitted
clk: stm32mp1: convert to module driver
Adds support for probe deferral in way to prepare integration of the security in RCC clock and reset drivers. Some kernel clocks will be provided by the SCMI drivers. Since RCC clock driver create clocks which parents are SCMI clocks, RCC clock driver probe can be deferred. Signed-off-by: Etienne Carriere <[email protected]> Signed-off-by: Gabriel Fernandez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 9008fdd commit 9527237

File tree

1 file changed

+78
-43
lines changed

1 file changed

+78
-43
lines changed

drivers/clk/clk-stm32mp1.c

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <linux/delay.h>
1111
#include <linux/err.h>
1212
#include <linux/io.h>
13+
#include <linux/module.h>
1314
#include <linux/of.h>
1415
#include <linux/of_address.h>
16+
#include <linux/platform_device.h>
1517
#include <linux/slab.h>
1618
#include <linux/spinlock.h>
1719

@@ -469,7 +471,7 @@ static const struct clk_ops mp1_gate_clk_ops = {
469471
.is_enabled = clk_gate_is_enabled,
470472
};
471473

472-
static struct clk_hw *_get_stm32_mux(void __iomem *base,
474+
static struct clk_hw *_get_stm32_mux(struct device *dev, void __iomem *base,
473475
const struct stm32_mux_cfg *cfg,
474476
spinlock_t *lock)
475477
{
@@ -478,7 +480,7 @@ static struct clk_hw *_get_stm32_mux(void __iomem *base,
478480
struct clk_hw *mux_hw;
479481

480482
if (cfg->mmux) {
481-
mmux = kzalloc(sizeof(*mmux), GFP_KERNEL);
483+
mmux = devm_kzalloc(dev, sizeof(*mmux), GFP_KERNEL);
482484
if (!mmux)
483485
return ERR_PTR(-ENOMEM);
484486

@@ -493,7 +495,7 @@ static struct clk_hw *_get_stm32_mux(void __iomem *base,
493495
cfg->mmux->hws[cfg->mmux->nbr_clk++] = mux_hw;
494496

495497
} else {
496-
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
498+
mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
497499
if (!mux)
498500
return ERR_PTR(-ENOMEM);
499501

@@ -509,13 +511,13 @@ static struct clk_hw *_get_stm32_mux(void __iomem *base,
509511
return mux_hw;
510512
}
511513

512-
static struct clk_hw *_get_stm32_div(void __iomem *base,
514+
static struct clk_hw *_get_stm32_div(struct device *dev, void __iomem *base,
513515
const struct stm32_div_cfg *cfg,
514516
spinlock_t *lock)
515517
{
516518
struct clk_divider *div;
517519

518-
div = kzalloc(sizeof(*div), GFP_KERNEL);
520+
div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL);
519521

520522
if (!div)
521523
return ERR_PTR(-ENOMEM);
@@ -530,16 +532,16 @@ static struct clk_hw *_get_stm32_div(void __iomem *base,
530532
return &div->hw;
531533
}
532534

533-
static struct clk_hw *
534-
_get_stm32_gate(void __iomem *base,
535-
const struct stm32_gate_cfg *cfg, spinlock_t *lock)
535+
static struct clk_hw *_get_stm32_gate(struct device *dev, void __iomem *base,
536+
const struct stm32_gate_cfg *cfg,
537+
spinlock_t *lock)
536538
{
537539
struct stm32_clk_mgate *mgate;
538540
struct clk_gate *gate;
539541
struct clk_hw *gate_hw;
540542

541543
if (cfg->mgate) {
542-
mgate = kzalloc(sizeof(*mgate), GFP_KERNEL);
544+
mgate = devm_kzalloc(dev, sizeof(*mgate), GFP_KERNEL);
543545
if (!mgate)
544546
return ERR_PTR(-ENOMEM);
545547

@@ -554,7 +556,7 @@ _get_stm32_gate(void __iomem *base,
554556
gate_hw = &mgate->gate.hw;
555557

556558
} else {
557-
gate = kzalloc(sizeof(*gate), GFP_KERNEL);
559+
gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL);
558560
if (!gate)
559561
return ERR_PTR(-ENOMEM);
560562

@@ -592,7 +594,7 @@ clk_stm32_register_gate_ops(struct device *dev,
592594
if (cfg->ops)
593595
init.ops = cfg->ops;
594596

595-
hw = _get_stm32_gate(base, cfg, lock);
597+
hw = _get_stm32_gate(dev, base, cfg, lock);
596598
if (IS_ERR(hw))
597599
return ERR_PTR(-ENOMEM);
598600

@@ -623,7 +625,7 @@ clk_stm32_register_composite(struct device *dev,
623625
gate_ops = NULL;
624626

625627
if (cfg->mux) {
626-
mux_hw = _get_stm32_mux(base, cfg->mux, lock);
628+
mux_hw = _get_stm32_mux(dev, base, cfg->mux, lock);
627629

628630
if (!IS_ERR(mux_hw)) {
629631
mux_ops = &clk_mux_ops;
@@ -634,7 +636,7 @@ clk_stm32_register_composite(struct device *dev,
634636
}
635637

636638
if (cfg->div) {
637-
div_hw = _get_stm32_div(base, cfg->div, lock);
639+
div_hw = _get_stm32_div(dev, base, cfg->div, lock);
638640

639641
if (!IS_ERR(div_hw)) {
640642
div_ops = &clk_divider_ops;
@@ -645,7 +647,7 @@ clk_stm32_register_composite(struct device *dev,
645647
}
646648

647649
if (cfg->gate) {
648-
gate_hw = _get_stm32_gate(base, cfg->gate, lock);
650+
gate_hw = _get_stm32_gate(dev, base, cfg->gate, lock);
649651

650652
if (!IS_ERR(gate_hw)) {
651653
gate_ops = &clk_gate_ops;
@@ -890,7 +892,7 @@ static struct clk_hw *clk_register_pll(struct device *dev, const char *name,
890892
struct clk_hw *hw;
891893
int err;
892894

893-
element = kzalloc(sizeof(*element), GFP_KERNEL);
895+
element = devm_kzalloc(dev, sizeof(*element), GFP_KERNEL);
894896
if (!element)
895897
return ERR_PTR(-ENOMEM);
896898

@@ -914,10 +916,8 @@ static struct clk_hw *clk_register_pll(struct device *dev, const char *name,
914916
hw = &element->hw;
915917
err = clk_hw_register(dev, hw);
916918

917-
if (err) {
918-
kfree(element);
919+
if (err)
919920
return ERR_PTR(err);
920-
}
921921

922922
return hw;
923923
}
@@ -1028,7 +1028,7 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name,
10281028
struct clk_hw *hw;
10291029
int err;
10301030

1031-
tim_ker = kzalloc(sizeof(*tim_ker), GFP_KERNEL);
1031+
tim_ker = devm_kzalloc(dev, sizeof(*tim_ker), GFP_KERNEL);
10321032
if (!tim_ker)
10331033
return ERR_PTR(-ENOMEM);
10341034

@@ -1046,10 +1046,8 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name,
10461046
hw = &tim_ker->hw;
10471047
err = clk_hw_register(dev, hw);
10481048

1049-
if (err) {
1050-
kfree(tim_ker);
1049+
if (err)
10511050
return ERR_PTR(err);
1052-
}
10531051

10541052
return hw;
10551053
}
@@ -2076,6 +2074,7 @@ static const struct of_device_id stm32mp1_match_data[] = {
20762074
},
20772075
{ }
20782076
};
2077+
MODULE_DEVICE_TABLE(of, stm32mp1_match_data);
20792078

20802079
static int stm32_register_hw_clk(struct device *dev,
20812080
struct clk_hw_onecell_data *clk_data,
@@ -2101,8 +2100,7 @@ static int stm32_register_hw_clk(struct device *dev,
21012100
return 0;
21022101
}
21032102

2104-
static int stm32_rcc_init(struct device_node *np,
2105-
void __iomem *base,
2103+
static int stm32_rcc_init(struct device *dev, void __iomem *base,
21062104
const struct of_device_id *match_data)
21072105
{
21082106
struct clk_hw_onecell_data *clk_data;
@@ -2111,18 +2109,18 @@ static int stm32_rcc_init(struct device_node *np,
21112109
const struct stm32_clock_match_data *data;
21122110
int err, n, max_binding;
21132111

2114-
match = of_match_node(match_data, np);
2112+
match = of_match_node(match_data, dev_of_node(dev));
21152113
if (!match) {
2116-
pr_err("%s: match data not found\n", __func__);
2114+
dev_err(dev, "match data not found\n");
21172115
return -ENODEV;
21182116
}
21192117

21202118
data = match->data;
21212119

21222120
max_binding = data->maxbinding;
21232121

2124-
clk_data = kzalloc(struct_size(clk_data, hws, max_binding),
2125-
GFP_KERNEL);
2122+
clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, max_binding),
2123+
GFP_KERNEL);
21262124
if (!clk_data)
21272125
return -ENOMEM;
21282126

@@ -2134,36 +2132,73 @@ static int stm32_rcc_init(struct device_node *np,
21342132
hws[n] = ERR_PTR(-ENOENT);
21352133

21362134
for (n = 0; n < data->num; n++) {
2137-
err = stm32_register_hw_clk(NULL, clk_data, base, &rlock,
2135+
err = stm32_register_hw_clk(dev, clk_data, base, &rlock,
21382136
&data->cfg[n]);
21392137
if (err) {
2140-
pr_err("%s: can't register %s\n", __func__,
2141-
data->cfg[n].name);
2142-
2143-
kfree(clk_data);
2138+
dev_err(dev, "Can't register clk %s: %d\n",
2139+
data->cfg[n].name, err);
21442140

21452141
return err;
21462142
}
21472143
}
21482144

2149-
return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
2145+
return of_clk_add_hw_provider(dev_of_node(dev), of_clk_hw_onecell_get, clk_data);
21502146
}
21512147

2152-
static void stm32mp1_rcc_init(struct device_node *np)
2148+
static int stm32mp1_rcc_init(struct device *dev)
21532149
{
21542150
void __iomem *base;
2151+
int ret;
21552152

2156-
base = of_iomap(np, 0);
2153+
base = of_iomap(dev_of_node(dev), 0);
21572154
if (!base) {
2158-
pr_err("%pOFn: unable to map resource", np);
2159-
of_node_put(np);
2160-
return;
2155+
pr_err("%pOFn: unable to map resource", dev_of_node(dev));
2156+
ret = -ENOMEM;
2157+
goto out;
21612158
}
21622159

2163-
if (stm32_rcc_init(np, base, stm32mp1_match_data)) {
2164-
iounmap(base);
2165-
of_node_put(np);
2160+
ret = stm32_rcc_init(dev, base, stm32mp1_match_data);
2161+
2162+
out:
2163+
if (ret) {
2164+
if (base)
2165+
iounmap(base);
2166+
2167+
of_node_put(dev_of_node(dev));
21662168
}
2169+
2170+
return ret;
2171+
}
2172+
2173+
static int stm32mp1_rcc_clocks_probe(struct platform_device *pdev)
2174+
{
2175+
struct device *dev = &pdev->dev;
2176+
2177+
return stm32mp1_rcc_init(dev);
2178+
}
2179+
2180+
static int stm32mp1_rcc_clocks_remove(struct platform_device *pdev)
2181+
{
2182+
struct device *dev = &pdev->dev;
2183+
struct device_node *child, *np = dev_of_node(dev);
2184+
2185+
for_each_available_child_of_node(np, child)
2186+
of_clk_del_provider(child);
2187+
2188+
return 0;
21672189
}
21682190

2169-
CLK_OF_DECLARE_DRIVER(stm32mp1_rcc, "st,stm32mp1-rcc", stm32mp1_rcc_init);
2191+
static struct platform_driver stm32mp1_rcc_clocks_driver = {
2192+
.driver = {
2193+
.name = "stm32mp1_rcc",
2194+
.of_match_table = stm32mp1_match_data,
2195+
},
2196+
.probe = stm32mp1_rcc_clocks_probe,
2197+
.remove = stm32mp1_rcc_clocks_remove,
2198+
};
2199+
2200+
static int __init stm32mp1_clocks_init(void)
2201+
{
2202+
return platform_driver_register(&stm32mp1_rcc_clocks_driver);
2203+
}
2204+
core_initcall(stm32mp1_clocks_init);

0 commit comments

Comments
 (0)