mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2025-12-10 06:24:40 +01:00
Add a new microchipsw target aimed add supporting Microchip switch SoC-s. Start by supporting LAN969x SoC-s as the first subtarget. Signed-off-by: Robert Marko <robert.marko@sartura.hr>
151 lines
4.6 KiB
Diff
151 lines
4.6 KiB
Diff
From 471d54facf2a1ee5740839e7870873a3f5965911 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Machon <daniel.machon@microchip.com>
|
|
Date: Mon, 16 Sep 2024 11:49:21 +0200
|
|
Subject: [PATCH 05/25] 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>
|
|
---
|
|
drivers/clk/clk-lan966x.c | 55 +++++++++++++++++++++++++++------------
|
|
1 file changed, 39 insertions(+), 16 deletions(-)
|
|
|
|
--- a/drivers/clk/clk-lan966x.c
|
|
+++ b/drivers/clk/clk-lan966x.c
|
|
@@ -24,7 +24,7 @@
|
|
|
|
#define DIV_MAX 255
|
|
|
|
-static const char * const clk_names[N_CLOCKS] = {
|
|
+static const char * const lan966x_clk_names[] = {
|
|
"qspi0", "qspi1", "qspi2", "sdmmc0",
|
|
"pi", "mcan0", "mcan1", "flexcom0",
|
|
"flexcom1", "flexcom2", "flexcom3",
|
|
@@ -53,7 +53,7 @@ struct clk_gate_soc_desc {
|
|
int bit_idx;
|
|
};
|
|
|
|
-static const struct clk_gate_soc_desc clk_gate_desc[] = {
|
|
+static const struct clk_gate_soc_desc lan966x_clk_gate_desc[] = {
|
|
{ "uhphs", 11 },
|
|
{ "udphs", 10 },
|
|
{ "mcramc", 9 },
|
|
@@ -61,6 +61,22 @@ static const struct clk_gate_soc_desc cl
|
|
{ }
|
|
};
|
|
|
|
+struct lan966x_match_data {
|
|
+ char *name;
|
|
+ const char * const *clk_name;
|
|
+ const struct clk_gate_soc_desc *clk_gate_desc;
|
|
+ u8 num_generic_clks;
|
|
+ u8 num_total_clks;
|
|
+};
|
|
+
|
|
+static struct lan966x_match_data lan966x_desc = {
|
|
+ .name = "lan966x",
|
|
+ .clk_name = lan966x_clk_names,
|
|
+ .clk_gate_desc = lan966x_clk_gate_desc,
|
|
+ .num_total_clks = 18,
|
|
+ .num_generic_clks = 14,
|
|
+};
|
|
+
|
|
static DEFINE_SPINLOCK(clk_gate_lock);
|
|
static void __iomem *base;
|
|
|
|
@@ -186,24 +202,26 @@ static struct clk_hw *lan966x_gck_clk_re
|
|
};
|
|
|
|
static int lan966x_gate_clk_register(struct device *dev,
|
|
+ const struct lan966x_match_data *data,
|
|
struct clk_hw_onecell_data *hw_data,
|
|
void __iomem *gate_base)
|
|
{
|
|
- int i;
|
|
+ for (int i = data->num_generic_clks; i < data->num_total_clks; ++i) {
|
|
+ int idx = i - data->num_generic_clks;
|
|
+ const struct clk_gate_soc_desc *desc;
|
|
|
|
- for (i = GCK_GATE_UHPHS; i < N_CLOCKS; ++i) {
|
|
- int idx = i - GCK_GATE_UHPHS;
|
|
+ desc = &data->clk_gate_desc[idx];
|
|
|
|
hw_data->hws[i] =
|
|
- devm_clk_hw_register_gate(dev, clk_gate_desc[idx].name,
|
|
- "lan966x", 0, gate_base,
|
|
- clk_gate_desc[idx].bit_idx,
|
|
+ devm_clk_hw_register_gate(dev, desc->name,
|
|
+ data->name, 0, gate_base,
|
|
+ desc->bit_idx,
|
|
0, &clk_gate_lock);
|
|
|
|
if (IS_ERR(hw_data->hws[i]))
|
|
return dev_err_probe(dev, PTR_ERR(hw_data->hws[i]),
|
|
"failed to register %s clock\n",
|
|
- clk_gate_desc[idx].name);
|
|
+ desc->name);
|
|
}
|
|
|
|
return 0;
|
|
@@ -211,13 +229,18 @@ static int lan966x_gate_clk_register(str
|
|
|
|
static int lan966x_clk_probe(struct platform_device *pdev)
|
|
{
|
|
+ const struct lan966x_match_data *data;
|
|
struct clk_hw_onecell_data *hw_data;
|
|
struct device *dev = &pdev->dev;
|
|
void __iomem *gate_base;
|
|
struct resource *res;
|
|
int i, ret;
|
|
|
|
- hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, N_CLOCKS),
|
|
+ data = device_get_match_data(dev);
|
|
+ if (!data)
|
|
+ return -EINVAL;
|
|
+
|
|
+ hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, data->num_total_clks),
|
|
GFP_KERNEL);
|
|
if (!hw_data)
|
|
return -ENOMEM;
|
|
@@ -228,10 +251,10 @@ static int lan966x_clk_probe(struct plat
|
|
|
|
init.ops = &lan966x_gck_ops;
|
|
|
|
- hw_data->num = GCK_GATE_UHPHS;
|
|
+ hw_data->num = data->num_generic_clks;
|
|
|
|
- for (i = 0; i < GCK_GATE_UHPHS; i++) {
|
|
- init.name = clk_names[i];
|
|
+ for (i = 0; i < data->num_generic_clks; i++) {
|
|
+ init.name = data->clk_name[i];
|
|
hw_data->hws[i] = lan966x_gck_clk_register(dev, i);
|
|
if (IS_ERR(hw_data->hws[i])) {
|
|
dev_err(dev, "failed to register %s clock\n",
|
|
@@ -246,9 +269,9 @@ static int lan966x_clk_probe(struct plat
|
|
if (IS_ERR(gate_base))
|
|
return PTR_ERR(gate_base);
|
|
|
|
- hw_data->num = N_CLOCKS;
|
|
+ hw_data->num = data->num_total_clks;
|
|
|
|
- ret = lan966x_gate_clk_register(dev, hw_data, gate_base);
|
|
+ ret = lan966x_gate_clk_register(dev, data, hw_data, gate_base);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
@@ -257,7 +280,7 @@ static int lan966x_clk_probe(struct plat
|
|
}
|
|
|
|
static const struct of_device_id lan966x_clk_dt_ids[] = {
|
|
- { .compatible = "microchip,lan966x-gck", },
|
|
+ { .compatible = "microchip,lan966x-gck", .data = &lan966x_desc },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, lan966x_clk_dt_ids);
|