Skip to content

Commit 118c000

Browse files
Danielmachonclaudiubeznea
authored andcommitted
clk: lan966x: prepare driver for lan969x support
In preparation for lan969x support, add private match data for lan966x and add variables for: peripheral clock names, clock gate names, number of total clocks and number of generic clocks. Use the variables throughout. Signed-off-by: Daniel Machon <daniel.machon@microchip.com> Link: https://lore.kernel.org/r/20240916-lan969x-clock-v1-3-0e150336074d@microchip.com [claudiu.beznea: in lan966x_clk_probe(): keep struct_size() arguments on a single line] Signed-off-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>
1 parent 6049fa1 commit 118c000

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

drivers/clk/clk-lan966x.c

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#define DIV_MAX 255
2626

27-
static const char * const clk_names[N_CLOCKS] = {
27+
static const char * const lan966x_clk_names[] = {
2828
"qspi0", "qspi1", "qspi2", "sdmmc0",
2929
"pi", "mcan0", "mcan1", "flexcom0",
3030
"flexcom1", "flexcom2", "flexcom3",
@@ -53,14 +53,30 @@ struct clk_gate_soc_desc {
5353
int bit_idx;
5454
};
5555

56-
static const struct clk_gate_soc_desc clk_gate_desc[] = {
56+
static const struct clk_gate_soc_desc lan966x_clk_gate_desc[] = {
5757
{ "uhphs", 11 },
5858
{ "udphs", 10 },
5959
{ "mcramc", 9 },
6060
{ "hmatrix", 8 },
6161
{ }
6262
};
6363

64+
struct lan966x_match_data {
65+
char *name;
66+
const char * const *clk_name;
67+
const struct clk_gate_soc_desc *clk_gate_desc;
68+
u8 num_generic_clks;
69+
u8 num_total_clks;
70+
};
71+
72+
static struct lan966x_match_data lan966x_desc = {
73+
.name = "lan966x",
74+
.clk_name = lan966x_clk_names,
75+
.clk_gate_desc = lan966x_clk_gate_desc,
76+
.num_total_clks = 18,
77+
.num_generic_clks = 14,
78+
};
79+
6480
static DEFINE_SPINLOCK(clk_gate_lock);
6581
static void __iomem *base;
6682

@@ -186,38 +202,45 @@ static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i)
186202
};
187203

188204
static int lan966x_gate_clk_register(struct device *dev,
205+
const struct lan966x_match_data *data,
189206
struct clk_hw_onecell_data *hw_data,
190207
void __iomem *gate_base)
191208
{
192-
int i;
209+
for (int i = data->num_generic_clks; i < data->num_total_clks; ++i) {
210+
int idx = i - data->num_generic_clks;
211+
const struct clk_gate_soc_desc *desc;
193212

194-
for (i = GCK_GATE_UHPHS; i < N_CLOCKS; ++i) {
195-
int idx = i - GCK_GATE_UHPHS;
213+
desc = &data->clk_gate_desc[idx];
196214

197215
hw_data->hws[i] =
198-
devm_clk_hw_register_gate(dev, clk_gate_desc[idx].name,
199-
"lan966x", 0, gate_base,
200-
clk_gate_desc[idx].bit_idx,
216+
devm_clk_hw_register_gate(dev, desc->name,
217+
data->name, 0, gate_base,
218+
desc->bit_idx,
201219
0, &clk_gate_lock);
202220

203221
if (IS_ERR(hw_data->hws[i]))
204222
return dev_err_probe(dev, PTR_ERR(hw_data->hws[i]),
205223
"failed to register %s clock\n",
206-
clk_gate_desc[idx].name);
224+
desc->name);
207225
}
208226

209227
return 0;
210228
}
211229

212230
static int lan966x_clk_probe(struct platform_device *pdev)
213231
{
232+
const struct lan966x_match_data *data;
214233
struct clk_hw_onecell_data *hw_data;
215234
struct device *dev = &pdev->dev;
216235
void __iomem *gate_base;
217236
struct resource *res;
218237
int i, ret;
219238

220-
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, N_CLOCKS),
239+
data = device_get_match_data(dev);
240+
if (!data)
241+
return -EINVAL;
242+
243+
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, data->num_total_clks),
221244
GFP_KERNEL);
222245
if (!hw_data)
223246
return -ENOMEM;
@@ -228,10 +251,10 @@ static int lan966x_clk_probe(struct platform_device *pdev)
228251

229252
init.ops = &lan966x_gck_ops;
230253

231-
hw_data->num = GCK_GATE_UHPHS;
254+
hw_data->num = data->num_generic_clks;
232255

233-
for (i = 0; i < GCK_GATE_UHPHS; i++) {
234-
init.name = clk_names[i];
256+
for (i = 0; i < data->num_generic_clks; i++) {
257+
init.name = data->clk_name[i];
235258
hw_data->hws[i] = lan966x_gck_clk_register(dev, i);
236259
if (IS_ERR(hw_data->hws[i])) {
237260
dev_err(dev, "failed to register %s clock\n",
@@ -246,9 +269,9 @@ static int lan966x_clk_probe(struct platform_device *pdev)
246269
if (IS_ERR(gate_base))
247270
return PTR_ERR(gate_base);
248271

249-
hw_data->num = N_CLOCKS;
272+
hw_data->num = data->num_total_clks;
250273

251-
ret = lan966x_gate_clk_register(dev, hw_data, gate_base);
274+
ret = lan966x_gate_clk_register(dev, data, hw_data, gate_base);
252275
if (ret)
253276
return ret;
254277
}
@@ -257,7 +280,7 @@ static int lan966x_clk_probe(struct platform_device *pdev)
257280
}
258281

259282
static const struct of_device_id lan966x_clk_dt_ids[] = {
260-
{ .compatible = "microchip,lan966x-gck", },
283+
{ .compatible = "microchip,lan966x-gck", .data = &lan966x_desc },
261284
{ }
262285
};
263286
MODULE_DEVICE_TABLE(of, lan966x_clk_dt_ids);

0 commit comments

Comments
 (0)