Skip to content

Commit 5ad5915

Browse files
HoratiuVulturnoglitch
authored andcommitted
clk: lan966x: Extend lan966x clock driver for clock gating support
Extend the clock driver to add support also for clock gating. The following peripherals can be gated: UHPHS, UDPHS, MCRAMC, HMATRIX. Signed-off-by: Horatiu Vultur <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: Nicolas Ferre <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 51d0a37 commit 5ad5915

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

drivers/clk/clk-lan966x.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ static struct clk_init_data init = {
4848
.num_parents = ARRAY_SIZE(lan966x_gck_pdata),
4949
};
5050

51+
struct clk_gate_soc_desc {
52+
const char *name;
53+
int bit_idx;
54+
};
55+
56+
static const struct clk_gate_soc_desc clk_gate_desc[] = {
57+
{ "uhphs", 11 },
58+
{ "udphs", 10 },
59+
{ "mcramc", 9 },
60+
{ "hmatrix", 8 },
61+
{ }
62+
};
63+
64+
static DEFINE_SPINLOCK(clk_gate_lock);
5165
static void __iomem *base;
5266

5367
static int lan966x_gck_enable(struct clk_hw *hw)
@@ -188,11 +202,37 @@ static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i)
188202
return &priv->hw;
189203
};
190204

205+
static int lan966x_gate_clk_register(struct device *dev,
206+
struct clk_hw_onecell_data *hw_data,
207+
void __iomem *gate_base)
208+
{
209+
int i;
210+
211+
for (i = GCK_GATE_UHPHS; i < N_CLOCKS; ++i) {
212+
int idx = i - GCK_GATE_UHPHS;
213+
214+
hw_data->hws[i] =
215+
devm_clk_hw_register_gate(dev, clk_gate_desc[idx].name,
216+
"lan966x", 0, base,
217+
clk_gate_desc[idx].bit_idx,
218+
0, &clk_gate_lock);
219+
220+
if (IS_ERR(hw_data->hws[i]))
221+
return dev_err_probe(dev, PTR_ERR(hw_data->hws[i]),
222+
"failed to register %s clock\n",
223+
clk_gate_desc[idx].name);
224+
}
225+
226+
return 0;
227+
}
228+
191229
static int lan966x_clk_probe(struct platform_device *pdev)
192230
{
193231
struct clk_hw_onecell_data *hw_data;
194232
struct device *dev = &pdev->dev;
195-
int i;
233+
void __iomem *gate_base;
234+
struct resource *res;
235+
int i, ret;
196236

197237
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, N_CLOCKS),
198238
GFP_KERNEL);
@@ -205,9 +245,9 @@ static int lan966x_clk_probe(struct platform_device *pdev)
205245

206246
init.ops = &lan966x_gck_ops;
207247

208-
hw_data->num = N_CLOCKS;
248+
hw_data->num = GCK_GATE_UHPHS;
209249

210-
for (i = 0; i < N_CLOCKS; i++) {
250+
for (i = 0; i < GCK_GATE_UHPHS; i++) {
211251
init.name = clk_names[i];
212252
hw_data->hws[i] = lan966x_gck_clk_register(dev, i);
213253
if (IS_ERR(hw_data->hws[i])) {
@@ -217,6 +257,19 @@ static int lan966x_clk_probe(struct platform_device *pdev)
217257
}
218258
}
219259

260+
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
261+
if (res) {
262+
gate_base = devm_ioremap_resource(&pdev->dev, res);
263+
if (IS_ERR(gate_base))
264+
return PTR_ERR(gate_base);
265+
266+
hw_data->num = N_CLOCKS;
267+
268+
ret = lan966x_gate_clk_register(dev, hw_data, gate_base);
269+
if (ret)
270+
return ret;
271+
}
272+
220273
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data);
221274
}
222275

0 commit comments

Comments
 (0)