[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250116233542.1610163-1-mattwmajewski@gmail.com>
Date: Thu, 16 Jan 2025 18:35:42 -0500
From: Matthew Majewski <mattwmajewski@...il.com>
To: mturquette@...libre.com,
sboyd@...nel.org
Cc: linux-clk@...r.kernel.org,
linux-kernel@...r.kernel.org,
Matthew Majewski <mattwmajewski@...il.com>
Subject: [PATCH] clk: si5351: allow more than one driver instance
The si5351 clock driver creates several clk_hw instances to represent
the internal clock structure of the device. The names of these
internal clocks are not unique across driver instances, however,
meaning that attempting to create more than one instance of the si5351
driver will fail due to name conflicts.
This patch corrects this issue by issuing a unique name to each
internal clk_hw instance. The unique name is generated by prepending
the i2c_client device name. This naming convention was borrowed from
mmc/host/meson-mx-sdhc-clkc.c.
Signed-off-by: Matthew Majewski <mattwmajewski@...il.com>
---
drivers/clk/clk-si5351.c | 69 ++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 20 deletions(-)
diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index a4c92c5ef3ff..dfdf58ca5260 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1440,6 +1440,8 @@ static int si5351_i2c_probe(struct i2c_client *client)
struct si5351_driver_data *drvdata;
struct clk_init_data init;
const char *parent_names[4];
+ char parent_clk_names[4][64];
+ char clk_name[64];
u8 num_parents, num_clocks;
int ret, n;
@@ -1540,7 +1542,9 @@ static int si5351_i2c_probe(struct i2c_client *client)
/* register xtal input clock gate */
memset(&init, 0, sizeof(init));
- init.name = si5351_input_names[0];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[0]);
+ init.name = clk_name;
init.ops = &si5351_xtal_ops;
init.flags = 0;
if (!IS_ERR(drvdata->pxtal)) {
@@ -1558,7 +1562,9 @@ static int si5351_i2c_probe(struct i2c_client *client)
/* register clkin input clock gate */
if (drvdata->variant == SI5351_VARIANT_C) {
memset(&init, 0, sizeof(init));
- init.name = si5351_input_names[1];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[1]);
+ init.name = clk_name;
init.ops = &si5351_clkin_ops;
if (!IS_ERR(drvdata->pclkin)) {
drvdata->pclkin_name = __clk_get_name(drvdata->pclkin);
@@ -1574,17 +1580,25 @@ static int si5351_i2c_probe(struct i2c_client *client)
}
}
+ parent_names[0] = parent_clk_names[0];
+ parent_names[1] = parent_clk_names[1];
+ parent_names[2] = parent_clk_names[2];
+ parent_names[3] = parent_clk_names[3];
+
/* Si5351C allows to mux either xtal or clkin to PLL input */
num_parents = (drvdata->variant == SI5351_VARIANT_C) ? 2 : 1;
- parent_names[0] = si5351_input_names[0];
- parent_names[1] = si5351_input_names[1];
+ snprintf(parent_clk_names[0], sizeof(parent_clk_names[0]), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[0]);
+ snprintf(parent_clk_names[1], sizeof(parent_clk_names[1]), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[1]);
/* register PLLA */
drvdata->pll[0].num = 0;
drvdata->pll[0].drvdata = drvdata;
drvdata->pll[0].hw.init = &init;
memset(&init, 0, sizeof(init));
- init.name = si5351_pll_names[0];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev), si5351_pll_names[0]);
+ init.name = clk_name;
init.ops = &si5351_pll_ops;
init.flags = 0;
init.parent_names = parent_names;
@@ -1601,13 +1615,17 @@ static int si5351_i2c_probe(struct i2c_client *client)
drvdata->pll[1].hw.init = &init;
memset(&init, 0, sizeof(init));
if (drvdata->variant == SI5351_VARIANT_B) {
- init.name = si5351_pll_names[2];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_pll_names[2]);
+ init.name = clk_name;
init.ops = &si5351_vxco_ops;
init.flags = 0;
init.parent_names = NULL;
init.num_parents = 0;
} else {
- init.name = si5351_pll_names[1];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_pll_names[1]);
+ init.name = clk_name;
init.ops = &si5351_pll_ops;
init.flags = 0;
init.parent_names = parent_names;
@@ -1621,11 +1639,15 @@ static int si5351_i2c_probe(struct i2c_client *client)
/* register clk multisync and clk out divider */
num_clocks = (drvdata->variant == SI5351_VARIANT_A3) ? 3 : 8;
- parent_names[0] = si5351_pll_names[0];
- if (drvdata->variant == SI5351_VARIANT_B)
- parent_names[1] = si5351_pll_names[2];
- else
- parent_names[1] = si5351_pll_names[1];
+ snprintf(parent_clk_names[0], sizeof(parent_clk_names[0]), "%s#%s",
+ dev_name(&client->dev), si5351_pll_names[0]);
+ if (drvdata->variant == SI5351_VARIANT_B) {
+ snprintf(parent_clk_names[1], sizeof(parent_clk_names[1]), "%s#%s",
+ dev_name(&client->dev), si5351_pll_names[2]);
+ } else {
+ snprintf(parent_clk_names[1], sizeof(parent_clk_names[1]), "%s#%s",
+ dev_name(&client->dev), si5351_pll_names[1]);
+ }
drvdata->msynth = devm_kcalloc(&client->dev, num_clocks,
sizeof(*drvdata->msynth), GFP_KERNEL);
@@ -1643,7 +1665,9 @@ static int si5351_i2c_probe(struct i2c_client *client)
drvdata->msynth[n].drvdata = drvdata;
drvdata->msynth[n].hw.init = &init;
memset(&init, 0, sizeof(init));
- init.name = si5351_msynth_names[n];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_msynth_names[n]);
+ init.name = clk_name;
init.ops = &si5351_msynth_ops;
init.flags = 0;
if (pdata->clkout[n].pll_master)
@@ -1660,18 +1684,23 @@ static int si5351_i2c_probe(struct i2c_client *client)
}
num_parents = (drvdata->variant == SI5351_VARIANT_C) ? 4 : 3;
- parent_names[2] = si5351_input_names[0];
- parent_names[3] = si5351_input_names[1];
+ snprintf(parent_clk_names[2], sizeof(parent_clk_names[2]), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[0]);
+ snprintf(parent_clk_names[3], sizeof(parent_clk_names[3]), "%s#%s", dev_name(&client->dev),
+ si5351_input_names[1]);
for (n = 0; n < num_clocks; n++) {
- parent_names[0] = si5351_msynth_names[n];
- parent_names[1] = (n < 4) ? si5351_msynth_names[0] :
- si5351_msynth_names[4];
-
+ snprintf(parent_clk_names[0], sizeof(parent_clk_names[0]), "%s#%s",
+ dev_name(&client->dev), si5351_msynth_names[n]);
+ snprintf(parent_clk_names[1], sizeof(parent_clk_names[1]), "%s#%s",
+ dev_name(&client->dev),
+ (n < 4) ? si5351_msynth_names[0] : si5351_msynth_names[4]);
drvdata->clkout[n].num = n;
drvdata->clkout[n].drvdata = drvdata;
drvdata->clkout[n].hw.init = &init;
memset(&init, 0, sizeof(init));
- init.name = si5351_clkout_names[n];
+ snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(&client->dev),
+ si5351_clkout_names[n]);
+ init.name = clk_name;
init.ops = &si5351_clkout_ops;
init.flags = 0;
if (pdata->clkout[n].clkout_src == SI5351_CLKOUT_SRC_MSYNTH_N)
--
2.25.1
Powered by blists - more mailing lists