clk: add support for Airoha AN7583 clock
Subsystems (3)
v16 cover clk: add support for Airoha AN7583 clock
This small series introduce some cleanup and support for clock and reset of Airoha AN7583.
The implementation is similar to EN7581 but AN7583 introduce new reset and more clock divisor support.
Changes v16:
- Add num_base_clk extra variable
- Add .set_rate patch
- Use dev_err instead of pr_err
- Use dev_dbg in hot path
- Better organize patch order
Changes v15:
- Fix num_clocks with new implementation for AN7583
Changes v14:
- Fix wrong definition for chip-scu
- Use scoped guard and guard API in reset
- Rework for better num_clocks handling
- Address some forma impovement suggested by Brian
Changes v13:
- Use guard API
- Drop spinlock on read operation
- Use enabled/disabled now that they don't sleep anymore
- Rebase on top of linux-next
Changes v12:
- Fix dereference on pcie early unprepare
Changes v11:
- Move to global spinlock
- Move pci ops to sleepable prepare/unprepare
Changes v10:
- Fix whitespace in include patch
- Add reset and phy cell as required
- Add additional patch for devm variant
- Add additional patch for lock for clock and reset access
Changes v9:
- Fix compilation error for priv (again) (this time fixed)
Changes v8:
- Add ACK tag by Connor
- Fix missing priv->base assign
Changes v7:
- Add further info for DT patch
- Add serdes selection support
- Rebase on top of linux-next
Changes v6:
- Address bot suggestion for DT patch
- Add further information on chip-scu phandle
- Add dedicated PERSTOUT reset and PCIE_HB reset
Changes v5:
- Rebase on top of linux-next
- Drop even more patch to reduce patch delta
- Make chip-scu specific to AN7583
Changes v4:
- Add review tag for DT patch
- Fix clock patch to use en7581-chip-scu compatible
- Drop PCIE SCU SSR write
Changes v3:
- Drop .set_rate patch (will be proposed later)
- Drop chip-scu binding and related patch
Changes v2:
- Add .set_rate support
- Rework DT to EN7581 implementation (clock driver is parent)
- Add additional cleanup patch
- Merge binding with schema patch
- Add chip_scu phandle
Christian Marangi (8):
dt-bindings: clock: airoha: Document support for AN7583 clock
clk: en7523: use devm variant for clk_hw_register and fixed clock
clk: en7523: don't call PCI clk OPs for early unprepare
clk: en7523: protect concurrent access to reset and PCI register
clk: en7523: convert to full clk_hw implementation for en7581
clk: en7523: add support for .set_rate for en7581
clk: en7523: generalize register clocks function
clk: en7523: add support for Airoha AN7583 clock
.../bindings/clock/airoha,en7523-scu.yaml | 26 + drivers/clk/clk-en7523.c | 806 ++++++++++++++++-- include/dt-bindings/clock/en7523-clk.h | 3 + .../dt-bindings/reset/airoha,an7583-reset.h | 65 ++ 4 files changed, 808 insertions(+), 92 deletions(-) create mode 100644 include/dt-bindings/reset/airoha,an7583-reset.h
Signature · 1 line
2.55.0
PATCH v16 1/8 dt-bindings: clock: airoha: Document support for AN7583 clock
Document support for Airoha AN7583 clock. This is based on the EN7523 clock schema with the new requirement of the "airoha,chip-scu".
The register for clock and reset for normal system and PCIe are scattered between the "SCU" and "chip SCU" registers (they are 2 different register block, the name is taken from the programming guide)
- Chip SCU provide register access to some clk gate and clk rate
- SCU provide register for reset, PCIe clock, other clock gate and PHY SERDES.
Upcoming and current airoha clock driver all follow this pattern of declaring one of the 2 register and use a sysconf for the other as the 2 register block are tighlty coupled.
EN7581 internally handle the syscon with a direct reference by the use of syscon_regmap_lookup_by_compatible while AN7583 wants to make this explicit in DT with the new "airoha,chip-scu" phandle.
Similar to EN7581, also AN7583 permit the selection of the serdes line.
Add additional binding for additional clock and reset lines.
--- .../bindings/clock/airoha,en7523-scu.yaml | 26 ++++++++ include/dt-bindings/clock/en7523-clk.h | 3 + .../dt-bindings/reset/airoha,an7583-reset.h | 65 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 include/dt-bindings/reset/airoha,an7583-reset.h
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +26 -0
@@ -31,6 +31,7 @@ properties: compatible: items: - enum: + - airoha,an7583-scu - airoha,en7523-scu - airoha,en7581-scu - econet,en751221-scu
@@ -57,12 +58,37 @@ properties: available serdes port. const: 1 + airoha,chip-scu: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the Chip SCU providing the registers required + for configuring and read the base clock sources, dividers and + clock gates. + required: - compatible - reg - '#clock-cells' allOf: + - if: + properties: + compatible: + const: airoha,an7583-scu + + then: + properties: + reg: + maxItems: 1 + + required: + - airoha,chip-scu + - '#reset-cells' + - '#phy-cells' + + else: + properties: + airoha,chip-scu: false + - if: properties: compatible:
include/dt-bindings/clock/en7523-clk.h +3 -0
@@ -14,4 +14,7 @@#define EN7581_CLK_EMMC 8 +#define AN7583_CLK_MDIO0 9 +#define AN7583_CLK_MDIO1 10 +#endif /* _DT_BINDINGS_CLOCK_AIROHA_EN7523_H_ */
include/dt-bindings/reset/airoha,an7583-reset.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v16 2/8 clk: en7523: use devm variant for clk_hw_register and fixed clock
In reply to Christian MarangiUse devm variant for clk_hw_register and clk_hw_register_fixed_rate to correctly unregister the clocks on probe fails.
This should never happen under normal condition but it's better to handle these cleanup.
While at it also switch to dev_err instead of pr_err for register clock functions.
--- drivers/clk/clk-en7523.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/clk/clk-en7523.c +13 -13
@@ -651,7 +651,7 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev,if (init.ops->unprepare) init.ops->unprepare (&cg->hw); -if (clk_hw_register (dev, &cg->hw)) +if (devm_clk_hw_register (dev, &cg->hw))return NULL ;return &cg->hw;
@@ -707,10 +707,10 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat val =readl (base + reg); rate /=en7523_get_div (desc, val); - hw =clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate); + hw =devm_clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate);if (IS_ERR (hw)) { -pr_err ("Failed to register clk %s: %ld\n" , - desc->name,PTR_ERR (hw)); +dev_err (dev,"Failed to register clk %s: %ld\n" , + desc->name,PTR_ERR (hw));continue ; }
@@ -755,24 +755,24 @@ static void en7581_register_clocks(struct device *dev, struct clk_hw_onecell_dat err =regmap_read (map, desc->base_reg, &val);if (err) { -pr_err ("Failed reading fixed clk rate %s: %d\n" , - desc->name, err); +dev_err (dev,"Failed reading fixed clk rate %s: %d\n" , + desc->name, err);continue ; } rate =en7523_get_base_rate (desc, val); err =regmap_read (map, reg, &val);if (err) { -pr_err ("Failed reading fixed clk div %s: %d\n" , - desc->name, err); +dev_err (dev,"Failed reading fixed clk div %s: %d\n" , + desc->name, err);continue ; } rate /=en7523_get_div (desc, val); - hw =clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate); + hw =devm_clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate);if (IS_ERR (hw)) { -pr_err ("Failed to register clk %s: %ld\n" , - desc->name,PTR_ERR (hw)); +dev_err (dev,"Failed to register clk %s: %ld\n" , + desc->name,PTR_ERR (hw));continue ; }
@@ -1103,9 +1103,9 @@ static void en751221_try_register_clk(struct device *dev, int key,if (WARN_ON_ONCE (key >=EN751221_MAX_CLKS ))return ; - hw =clk_hw_register_fixed_rate (dev, name,NULL ,0 , rate); + hw =devm_clk_hw_register_fixed_rate (dev, name,NULL ,0 , rate);if (IS_ERR (hw)) -pr_err ("Failed to register clk %s: %pe\n" , name, hw); +dev_err (dev,"Failed to register clk %s: %pe\n" , name, hw);else clk_data->hws[key] = hw; }
Signature · 1 line
2.55.0
PATCH v16 3/8 clk: en7523: don't call PCI clk OPs for early unprepare
In reply to Christian MarangiIt's wrong to call clk OPs before actually registering a clock. This was done for the PCI early unprepare.
Rework the function to a more internal helper also in preparation for global spinlock protection.
--- drivers/clk/clk-en7523.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/clk/clk-en7523.c +13 -4
@@ -150,6 +150,7 @@ struct en_clk_soc_data {const struct clk_ops pcie_ops;int (*hw_init)(struct platform_device *pdev,struct clk_hw_onecell_data *clk_data); +void (*pci_unprepare)(struct en_clk_gate *cg); };static const u32 gsw_base[] = {400000000 ,500000000 };
@@ -620,9 +621,8 @@ static int en7523_pci_prepare(struct clk_hw *hw)return 0 ; } -static void en7523_pci_unprepare (struct clk_hw *hw) +static void __en7523_pci_unprepare (struct en_clk_gate *cg) { - struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw);void __iomem *np_base = cg->base;u32 val;
@@ -631,6 +631,13 @@ static void en7523_pci_unprepare(struct clk_hw *hw)writel (val, np_base +REG_PCI_CONTROL ); } +static void en7523_pci_unprepare (struct clk_hw *hw) +{ + struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); + +__en7523_pci_unprepare (cg); +} +static struct clk_hw *en7523_register_pcie_clk (struct device *dev,void __iomem *np_base) {
@@ -648,8 +655,8 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev, cg->base = np_base; cg->hw.init = &init; -if (init.ops->unprepare) - init.ops->unprepare (&cg->hw); +if (soc_data->pci_unprepare) + soc_data->pci_unprepare (cg);if (devm_clk_hw_register (dev, &cg->hw))return NULL ;
@@ -1220,6 +1227,7 @@ static const struct en_clk_soc_data en7523_data = { .unprepare = en7523_pci_unprepare, }, .hw_init = en7523_clk_hw_init, + .pci_unprepare = __en7523_pci_unprepare, }; static const struct en_clk_soc_data en7581_data = {
@@ -1241,6 +1249,7 @@ static const struct en_clk_soc_data en751221_data = { .unprepare = en7523_pci_unprepare, }, .hw_init = en751221_clk_hw_init, + .pci_unprepare = __en7523_pci_unprepare, }; static const struct of_device_id of_match_clk_en7523[] = {
Signature · 1 line
2.55.0
PATCH v16 4/8 clk: en7523: protect concurrent access to reset and PCI register
In reply to Christian MarangiUse spinlock for concurrent access to reset and PCI register to catch case when clock is enabled/disabled while a reset is also operated at the same time. This is needed as register are shared for both clock and reset operation and rmw operation require protection against writing inconsistent data.
Some minor rework was needed for early PCI unprepare case to reference the global spinlock.
--- drivers/clk/clk-en7523.c | 94 ++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 22 deletions(-)
drivers/clk/clk-en7523.c +72 -22
@@ -150,7 +150,7 @@ struct en_clk_soc_data {const struct clk_ops pcie_ops;int (*hw_init)(struct platform_device *pdev,struct clk_hw_onecell_data *clk_data); -void (*pci_unprepare)(struct en_clk_gate *cg); +void (*pci_unprepare)(struct device *dev,struct en_clk_gate *cg); };static const u32 gsw_base[] = {400000000 ,500000000 };
@@ -585,47 +585,82 @@ static int en7523_pci_is_enabled(struct clk_hw *hw)static int en7523_pci_prepare (struct clk_hw *hw) { struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct device *dev =clk_hw_get_dev (hw);void __iomem *np_base = cg->base; +struct en_clk_priv *priv;u32 val, mask; + priv =dev_get_drvdata (dev); +/* Need to pull device low before reset */ - val =readl (np_base +REG_PCI_CONTROL ); - val &= ~(REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ); -writel (val, np_base +REG_PCI_CONTROL ); + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_PCI_CONTROL ); + val &= ~(REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ); +writel (val, np_base +REG_PCI_CONTROL ); + } +usleep_range (1000 ,2000 );/* Enable PCIe port 1 */ - val |=REG_PCI_CONTROL_REFCLK_EN1 ; -writel (val, np_base +REG_PCI_CONTROL ); + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_PCI_CONTROL ); + val |=REG_PCI_CONTROL_REFCLK_EN1 ; +writel (val, np_base +REG_PCI_CONTROL ); + } +usleep_range (1000 ,2000 );/* Reset to default */ - val =readl (np_base +REG_RESET_CONTROL1 ); - mask =REG_RESET_CONTROL_PCIE1 |REG_RESET_CONTROL_PCIE2 | -REG_RESET_CONTROL_PCIEHB ; -writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_RESET_CONTROL1 ); + mask =REG_RESET_CONTROL_PCIE1 |REG_RESET_CONTROL_PCIE2 | +REG_RESET_CONTROL_PCIEHB ; +writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); + } +usleep_range (1000 ,2000 ); -writel (val | mask, np_base +REG_RESET_CONTROL1 ); + + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_RESET_CONTROL1 ); +writel (val | mask, np_base +REG_RESET_CONTROL1 ); + } +msleep (100 ); -writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); + + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_RESET_CONTROL1 ); +writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); + } +usleep_range (5000 ,10000 );/* Release device */ - mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ; - val =readl (np_base +REG_PCI_CONTROL ); -writel (val & ~mask, np_base +REG_PCI_CONTROL ); + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_PCI_CONTROL ); + mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ; +writel (val & ~mask, np_base +REG_PCI_CONTROL ); + } +usleep_range (1000 ,2000 ); -writel (val | mask, np_base +REG_PCI_CONTROL ); + + scoped_guard(spinlock_irqsave, &priv->lock) { + val =readl (np_base +REG_PCI_CONTROL ); +writel (val | mask, np_base +REG_PCI_CONTROL ); + } +msleep (250 );return 0 ; } -static void __en7523_pci_unprepare (struct en_clk_gate *cg) +static void __en7523_pci_unprepare (struct device *dev,struct en_clk_gate *cg) { +struct en_clk_priv *priv =dev_get_drvdata (dev);void __iomem *np_base = cg->base;u32 val; +guard (spinlock_irqsave)(&priv->lock); + val =readl (np_base +REG_PCI_CONTROL ); val &= ~REG_PCI_CONTROL_REFCLK_EN1 ;writel (val, np_base +REG_PCI_CONTROL );
@@ -634,8 +669,9 @@ static void __en7523_pci_unprepare(struct en_clk_gate *cg)static void en7523_pci_unprepare (struct clk_hw *hw) { struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct device *dev =clk_hw_get_dev (hw); -__en7523_pci_unprepare (cg); +__en7523_pci_unprepare (dev, cg); } static struct clk_hw *en7523_register_pcie_clk(struct device *dev,
@@ -656,7 +692,7 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev, cg->hw.init = &init;if (soc_data->pci_unprepare) - soc_data->pci_unprepare (cg); + soc_data->pci_unprepare (dev, cg);if (devm_clk_hw_register (dev, &cg->hw))return NULL ;
@@ -677,10 +713,16 @@ static int en7581_pci_is_enabled(struct clk_hw *hw)static int en7581_pci_enable (struct clk_hw *hw) { struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct device *dev =clk_hw_get_dev (hw);void __iomem *np_base = cg->base; +struct en_clk_priv *priv;u32 val, mask; + priv =dev_get_drvdata (dev); mask =REG_PCI_CONTROL_REFCLK_EN0 |REG_PCI_CONTROL_REFCLK_EN1 ; + +guard (spinlock_irqsave)(&priv->lock); + val =readl (np_base +REG_PCI_CONTROL );writel (val | mask, np_base +REG_PCI_CONTROL );
@@ -690,10 +732,16 @@ static int en7581_pci_enable(struct clk_hw *hw)static void en7581_pci_disable (struct clk_hw *hw) { struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct device *dev =clk_hw_get_dev (hw);void __iomem *np_base = cg->base; +struct en_clk_priv *priv;u32 val, mask; + priv =dev_get_drvdata (dev); mask =REG_PCI_CONTROL_REFCLK_EN0 |REG_PCI_CONTROL_REFCLK_EN1 ; + +guard (spinlock_irqsave)(&priv->lock); + val =readl (np_base +REG_PCI_CONTROL );writel (val & ~mask, np_base +REG_PCI_CONTROL ); }
@@ -794,11 +842,14 @@ static int en7523_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert) { struct en_rst_data *rst_data = container_of(rcdev, struct en_rst_data, rcdev); +struct en_clk_priv *priv =dev_get_drvdata (rcdev->dev);u32 offset = rst_data->bank_ofs[id /RST_NR_PER_BANK ];void __iomem *addr = rst_data->base + offset;bool inverted = false;u32 val; +guard (spinlock_irqsave)(&priv->lock); +/* For PCIC reset logic is inverted, 0:assert 1:deassert */ if (offset ==REG_NP_SCU_PCIC ) inverted = true;
@@ -890,7 +941,6 @@ static int en7581_serdes_phy_set_mode(struct phy *phy, enum phy_mode mode,struct en_serdes_phy_instance *instance =phy_get_drvdata (phy);struct en_clk_priv *priv =dev_get_drvdata (phy->dev.parent);u32 reg, mask, sel, val; -unsigned long flags;switch (instance->serdes_port) {case AIROHA_SCU_SERDES_PCIE1 :
@@ -977,12 +1027,12 @@ static int en7581_serdes_phy_set_mode(struct phy *phy, enum phy_mode mode,return -EINVAL ; } -spin_lock_irqsave (&priv->lock, flags); +guard (spinlock_irqsave)(&priv->lock); + val =readl (priv->base + reg); val &= ~mask; val |= sel;writel (val, priv->base + reg); -spin_unlock_irqrestore (&priv->lock, flags);return 0 ; }
Signature · 1 line
2.55.0
PATCH v16 5/8 clk: en7523: convert to full clk_hw implementation for en7581
In reply to Christian MarangiIn preparation for support of .set_rate, convert the clock register logic from fixed clock implementation to full clk_hw implementation with dedicated OPs for Airoha EN7581 SoC.
While at it also rework the en7581_register_clocks() and en7523_register_pcie_clk() function to return error on clock register fail or on allocating dynamic memory.
--- drivers/clk/clk-en7523.c | 105 +++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 31 deletions(-)
drivers/clk/clk-en7523.c +74 -31
@@ -126,6 +126,12 @@ struct en_clk_gate {struct clk_hw hw; }; +struct en_clk { +struct regmap *map; +const struct en_clk_desc *desc; +struct clk_hw hw; +}; +struct en_rst_data {const u16 *bank_ofs;const u16 *idx_map;
@@ -683,10 +689,11 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev, .ops = &soc_data->pcie_ops, };struct en_clk_gate *cg; +int ret; cg =devm_kzalloc_obj (dev, *cg);if (!cg) -return NULL ; +return ERR_PTR (-ENOMEM ); cg->base = np_base; cg->hw.init = &init;
@@ -694,8 +701,9 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev,if (soc_data->pci_unprepare) soc_data->pci_unprepare (dev, cg); -if (devm_clk_hw_register (dev, &cg->hw)) -return NULL ; + ret =devm_clk_hw_register (dev, &cg->hw); +if (ret) +return ERR_PTR (ret);return &cg->hw; }
@@ -773,7 +781,8 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat } hw =en7523_register_pcie_clk (dev, np_base); - clk_data->hws[EN7523_CLK_PCIE ] = hw; +if (!IS_ERR (hw)) + clk_data->hws[EN7523_CLK_PCIE ] = hw; } static int en7523_clk_hw_init(struct platform_device *pdev,
@@ -796,46 +805,77 @@ static int en7523_clk_hw_init(struct platform_device *pdev, en7581_rst_ofs); } -static void en7581_register_clocks (struct device *dev,struct clk_hw_onecell_data *clk_data, -struct regmap *map,void __iomem *base) +static unsigned long en7581_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ + struct en_clk *c = container_of(hw, struct en_clk, hw); +const struct en_clk_desc *desc = c->desc; +struct device *dev =clk_hw_get_dev (hw); +struct regmap *map = c->map; +u32 val, reg, rate; +int err; + + err =regmap_read (map, desc->base_reg, &val); +if (err) { +dev_dbg (dev,"Failed reading fixed clk rate %s: %d\n" , + desc->name, err); +return 0 ; + } + rate =en7523_get_base_rate (desc, val); + + reg = desc->div_reg ? desc->div_reg : desc->base_reg; + err =regmap_read (map, reg, &val); +if (err) { +dev_dbg (dev,"Failed reading fixed clk div %s: %d\n" , + desc->name, err); +return 0 ; + } + +return rate /en7523_get_div (desc, val); +} + +static const struct clk_ops en7581_clk_ops = { + .recalc_rate = en7581_recalc_rate, +}; + +static int en7581_register_clocks (struct device *dev,struct clk_hw_onecell_data *clk_data, +struct regmap *map,void __iomem *base) {struct clk_hw *hw; -u32 rate;int i;for (i =0 ; i <ARRAY_SIZE (en7581_base_clks); i++) {const struct en_clk_desc *desc = &en7581_base_clks[i]; -u32 val, reg = desc->div_reg ? desc->div_reg : desc->base_reg; +struct clk_init_data init = { + .ops = &en7581_clk_ops, + }; +struct en_clk *en_clk;int err; - err =regmap_read (map, desc->base_reg, &val); -if (err) { -dev_err (dev,"Failed reading fixed clk rate %s: %d\n" , - desc->name, err); -continue ; - } - rate =en7523_get_base_rate (desc, val); + en_clk =devm_kzalloc_obj (dev, *en_clk); +if (!en_clk) +return -ENOMEM ; - err =regmap_read (map, reg, &val); -if (err) { -dev_err (dev,"Failed reading fixed clk div %s: %d\n" , - desc->name, err); -continue ; - } - rate /=en7523_get_div (desc, val); + init.name = desc->name; + en_clk->map = map; + en_clk->desc = desc; + en_clk->hw.init = &init; - hw =devm_clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate); -if (IS_ERR (hw)) { -dev_err (dev,"Failed to register clk %s: %ld\n" , - desc->name,PTR_ERR (hw)); -continue ; - } + err =devm_clk_hw_register (dev, &en_clk->hw); +if (err) +return dev_err_probe (dev, err,"Failed to register clk %s\n" , + desc->name); - clk_data->hws[desc->id] = hw; + clk_data->hws[desc->id] = &en_clk->hw; } hw =en7523_register_pcie_clk (dev, base); +if (IS_ERR (hw)) +return PTR_ERR (hw); + clk_data->hws[EN7523_CLK_PCIE ] = hw; + +return 0 ; } static int en7523_reset_update(struct reset_controller_dev *rcdev,
@@ -1117,7 +1157,9 @@ static int en7581_clk_hw_init(struct platform_device *pdev, priv->base = base; -en7581_register_clocks (&pdev->dev, clk_data, map, base); + ret =en7581_register_clocks (&pdev->dev, clk_data, map, base); +if (ret) +return ret; val =readl (base +REG_NP_SCU_SSTR ); val &= ~(REG_PCIE_XSI0_SEL_MASK |REG_PCIE_XSI1_SEL_MASK );
@@ -1179,7 +1221,8 @@ static void en751221_register_clocks(struct device *dev,/* PCI */ hw =en7523_register_pcie_clk (dev, np_base); - clk_data->hws[EN751221_CLK_PCIE ] = hw; +if (!IS_ERR (hw)) + clk_data->hws[EN751221_CLK_PCIE ] = hw;/* SPI */ rate =EN751221_SPI_BASE ;
Signature · 1 line
2.55.0
PATCH v16 6/8 clk: en7523: add support for .set_rate for en7581
In reply to Christian MarangiAdd support for EN7523 driver to configure rate for Airoha EN7581 SoC. The SoC expose both base clock selector and clock divisor hence it's possible to change the rate.
This will be especially needed for new SoC AN7583 that require changes for the MDIO and the eMMC.
The clock were assumed correctly configured by the bootloader but this goes against the rule of "kernel should not depend on external configuration".
To support the use of standard clock divider API, clock_div_table are added where needed (BUS, SPI and SLIC) in additionl to the previous info to derive and simulate the clock from the divisor registers.
Recalc rate for Airoha EN7581 is updated to use the divider_recalc_rate API for consistency with .set_rate and .determine_rate.
en7523_get_div() is updated to use the div table to drop redundant values.
--- drivers/clk/clk-en7523.c | 344 +++++++++++++++++++++++++++++++++++---- 1 file changed, 310 insertions(+), 34 deletions(-)
drivers/clk/clk-en7523.c +310 -34
@@ -116,9 +116,7 @@ struct en_clk_desc {u16 div_reg;u8 div_bits;u8 div_shift; -u16 div_val0; -u8 div_step; -u8 div_offset; +const struct clk_div_table *div_table; };struct en_clk_gate {
@@ -162,7 +160,88 @@ struct en_clk_soc_data {static const u32 gsw_base[] = {400000000 ,500000000 };static const u32 emi_base[] = {333000000 ,400000000 };static const u32 bus_base[] = {500000000 ,540000000 }; +/* From documentation divisor 1 is n/a */ +static const struct clk_div_table bus_div[] = { + { .val =1 , .div =2 }, + { .val =2 , .div =3 }, + { .val =3 , .div =4 }, + { .val =4 , .div =5 }, + { .val =5 , .div =6 }, + { .val =6 , .div =7 }, + { .val =7 , .div =8 }, + {/* sentinel */ } +};static const u32 slic_base[] = {100000000 ,3125000 }; +static const struct clk_div_table slic_div[] = { + { .val =0 , .div =20 }, + { .val =1 , .div =2 }, + { .val =2 , .div =4 }, + { .val =3 , .div =6 }, + { .val =4 , .div =8 }, + { .val =5 , .div =10 }, + { .val =6 , .div =12 }, + { .val =7 , .div =14 }, + { .val =8 , .div =16 }, + { .val =9 , .div =18 }, + { .val =10 , .div =20 }, + { .val =11 , .div =22 }, + { .val =12 , .div =24 }, + { .val =13 , .div =26 }, + { .val =14 , .div =28 }, + { .val =15 , .div =30 }, + { .val =16 , .div =32 }, + { .val =17 , .div =34 }, + { .val =18 , .div =36 }, + { .val =19 , .div =38 }, + { .val =20 , .div =40 }, + { .val =21 , .div =42 }, + { .val =22 , .div =44 }, + { .val =23 , .div =46 }, + { .val =24 , .div =48 }, + { .val =25 , .div =50 }, + { .val =26 , .div =52 }, + { .val =27 , .div =54 }, + { .val =28 , .div =56 }, + { .val =29 , .div =58 }, + { .val =30 , .div =60 }, + { .val =31 , .div =62 }, + {/* sentinel */ } +}; +static const struct clk_div_table spi_div[] = { + { .val =0 , .div =40 }, + { .val =1 , .div =2 }, + { .val =2 , .div =4 }, + { .val =3 , .div =6 }, + { .val =4 , .div =8 }, + { .val =5 , .div =10 }, + { .val =6 , .div =12 }, + { .val =7 , .div =14 }, + { .val =8 , .div =16 }, + { .val =9 , .div =18 }, + { .val =10 , .div =20 }, + { .val =11 , .div =22 }, + { .val =12 , .div =24 }, + { .val =13 , .div =26 }, + { .val =14 , .div =28 }, + { .val =15 , .div =30 }, + { .val =16 , .div =32 }, + { .val =17 , .div =34 }, + { .val =18 , .div =36 }, + { .val =19 , .div =38 }, + { .val =20 , .div =40 }, + { .val =21 , .div =42 }, + { .val =22 , .div =44 }, + { .val =23 , .div =46 }, + { .val =24 , .div =48 }, + { .val =25 , .div =50 }, + { .val =26 , .div =52 }, + { .val =27 , .div =54 }, + { .val =28 , .div =56 }, + { .val =29 , .div =58 }, + { .val =30 , .div =60 }, + { .val =31 , .div =62 }, + {/* sentinel */ } +};static const u32 npu_base[] = {333000000 ,400000000 ,500000000 };/* EN7581 */ static const u32 emi7581_base[] = {540000000 ,480000000 ,400000000 ,300000000 };
@@ -186,8 +265,6 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_EMI, .name = "emi",
@@ -200,8 +277,6 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_BUS, .name = "bus",
@@ -214,8 +289,7 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, + .div_table = bus_div, }, { .id = EN7523_CLK_SLIC, .name = "slic",
@@ -229,8 +303,7 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_reg = REG_SPI_CLK_DIV_SEL, .div_bits = 5, .div_shift = 24, - .div_val0 = 20, - .div_step = 2, + .div_table = slic_div, }, { .id = EN7523_CLK_SPI, .name = "spi",
@@ -241,8 +314,7 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_bits = 5, .div_shift = 8, - .div_val0 = 40, - .div_step = 2, + .div_table = spi_div, }, { .id = EN7523_CLK_NPU, .name = "npu",
@@ -255,8 +327,6 @@ static const struct en_clk_desc en7523_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_CRYPTO, .name = "crypto",
@@ -282,8 +352,6 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_EMI, .name = "emi",
@@ -296,8 +364,6 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_BUS, .name = "bus",
@@ -310,8 +376,7 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, + .div_table = bus_div, }, { .id = EN7523_CLK_SLIC, .name = "slic",
@@ -325,8 +390,7 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_reg = REG_SPI_CLK_DIV_SEL, .div_bits = 5, .div_shift = 24, - .div_val0 = 20, - .div_step = 2, + .div_table = slic_div, }, { .id = EN7523_CLK_SPI, .name = "spi",
@@ -337,8 +401,7 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_bits = 5, .div_shift = 8, - .div_val0 = 40, - .div_step = 2, + .div_table = spi_div, }, { .id = EN7523_CLK_NPU, .name = "npu",
@@ -351,8 +414,6 @@ static const struct en_clk_desc en7581_base_clks[] = { .div_bits = 3, .div_shift = 0, - .div_step = 1, - .div_offset = 1, }, { .id = EN7523_CLK_CRYPTO, .name = "crypto",
@@ -569,16 +630,20 @@ static u32 en7523_get_base_rate(const struct en_clk_desc *desc, u32 val)static u32 en7523_get_div (const struct en_clk_desc *desc,u32 val) { -if (!desc->div_bits) -return 1 ; +const struct clk_div_table *clkt; val >>= desc->div_shift; val &= (1 << desc->div_bits) -1 ; -if (!val && desc->div_val0) -return desc->div_val0; +if (desc->div_table) { +for (clkt = desc->div_table; clkt->div; clkt++) +if (clkt->val == val) +return clkt->div; -return (val + desc->div_offset) * desc->div_step; +return 0 ; + } + +return val +1 ; }static int en7523_pci_is_enabled (struct clk_hw *hw)
@@ -765,10 +830,21 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_datconst struct en_clk_desc *desc = &en7523_base_clks[i];u32 reg = desc->div_reg ? desc->div_reg : desc->base_reg;u32 val =readl (base + desc->base_reg); +u32 div; rate =en7523_get_base_rate (desc, val); + val =readl (base + reg); - rate /=en7523_get_div (desc, val); +if (desc->div_bits) { + div =en7523_get_div (desc, val); +if (!div) { +dev_err (dev,"Invalid div val for clk %s: %x\n" , + desc->name, val); +continue ; + } + + rate /= div; + } hw =devm_clk_hw_register_fixed_rate (dev, desc->name,NULL ,0 , rate);if (IS_ERR (hw)) {
@@ -831,11 +907,211 @@ static unsigned long en7581_recalc_rate(struct clk_hw *hw,return 0 ; } -return rate /en7523_get_div (desc, val); +if (desc->div_bits) { + val >>= desc->div_shift; + val &= (1 << desc->div_bits) -1 ; + + rate =divider_recalc_rate (hw, rate, val, desc->div_table, +0 , desc->div_bits); + } + +return rate; +} + +/* +* Simulate rate with every divisor supported +* 1. Search the divisor for the requested rate +* 2. Simulate the final rate with the new divisor +*/ +static unsigned long en7581_get_div_for_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate, +const struct en_clk_desc *desc, +int *div_val) +{ + *div_val =divider_get_val (rate, parent_rate, desc->div_table, + desc->div_bits,0 ); +if (*div_val <0 ) +return 0 ; + +return divider_recalc_rate (hw, parent_rate, *div_val, + desc->div_table,0 , + desc->div_bits); +} + +static int en7581_get_vals_for_rate (struct clk_hw *hw, +const struct en_clk_desc *desc, +unsigned long rate, +u32 *base_val,u32 *div_val) +{ +struct device *dev =clk_hw_get_dev (hw); +int tmp_base_val =0 , tmp_div_val =0 ; +unsigned long parent_rate, tmp_rate; + +if (!rate || (!desc->base_bits && !desc->div_bits)) +return -EINVAL ; + +if (!desc->base_bits) { + parent_rate = desc->base_value; + + tmp_rate =en7581_get_div_for_rate (hw, rate, parent_rate, + desc, &tmp_div_val); + +/* Matching clock found */ +if (tmp_rate == rate) + goto exit; + } + +/* Search requested rate with every matching base rate + divisor */ +for (; tmp_base_val < desc->n_base_values; tmp_base_val++) { + parent_rate = desc->base_values[tmp_base_val]; + tmp_rate = parent_rate; + +if (desc->div_bits) + tmp_rate =en7581_get_div_for_rate (hw, rate, parent_rate, + desc, &tmp_div_val); + +/* Matching clock found */ +if (tmp_rate == rate) +break ; + } + +/* Impossible, should be validated by determine rate */ +if (tmp_base_val >= desc->n_base_values) { +dev_dbg (dev,"Invalid rate for clock %s\n" , + desc->name); +return -EINVAL ; + } + +exit: + *base_val = tmp_base_val; + *div_val = tmp_div_val; + +return 0 ; +} + +static void en7581_update_best_rate (struct clk_rate_request *req, +unsigned long requested_rate, +unsigned long tmp_rate, +unsigned long *best_diff) +{ +unsigned long diff; + +if (!tmp_rate || tmp_rate < req->min_rate || + tmp_rate > req->max_rate) +return ; + + diff =abs_diff (requested_rate, tmp_rate); +if (diff < *best_diff) { + *best_diff = diff; + req->rate = tmp_rate; + } +} + +static void en7581_find_best_rate (struct clk_hw *hw, +struct clk_rate_request *req, +const struct en_clk_desc *desc, +unsigned long parent_rate, +unsigned long requested_rate, +unsigned long *best_diff) +{ +struct clk_rate_request div_req = *req; +int ret; + +if (!desc->div_bits) { +en7581_update_best_rate (req, requested_rate, parent_rate, + best_diff); +return ; + } + +/* Treat each internal base rate as a fixed parent for the divider. */ + div_req.rate =clamp (requested_rate, req->min_rate, req->max_rate); + div_req.rate =min (div_req.rate, parent_rate); + div_req.best_parent_rate = parent_rate; + ret =divider_determine_rate (hw, &div_req, desc->div_table, + desc->div_bits, +CLK_DIVIDER_ROUND_CLOSEST ); +if (ret) +return ; + +en7581_update_best_rate (req, requested_rate, div_req.rate, best_diff); +} + +static int en7581_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ + struct en_clk *en_clk = container_of(hw, struct en_clk, hw); +const struct en_clk_desc *desc = en_clk->desc; +unsigned long best_diff =ULONG_MAX ; +unsigned long rate = req->rate; +int tmp_base_val =0 ; + +if (!rate || (!desc->base_bits && !desc->div_bits)) +return -EINVAL ; + +if (!desc->base_bits) { +en7581_find_best_rate (hw, req, desc, desc->base_value, + rate, &best_diff); + goto exit; + } + +for (; tmp_base_val < desc->n_base_values; tmp_base_val++) +en7581_find_best_rate (hw, req, desc, + desc->base_values[tmp_base_val], + rate, &best_diff); + +exit: +return best_diff ==ULONG_MAX ? -EINVAL :0 ; +} + +static int en7581_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ + struct en_clk *en_clk = container_of(hw, struct en_clk, hw); +const struct en_clk_desc *desc = en_clk->desc; +struct device *dev =clk_hw_get_dev (hw); +u32 base_val, div_val, reg, val, mask; +struct regmap *map = en_clk->map; +int err; + + err =en7581_get_vals_for_rate (hw, en_clk->desc, rate, + &base_val, &div_val); +if (err) +return err; + +if (desc->div_bits) { + reg = desc->div_reg ? desc->div_reg : desc->base_reg; + + mask = (BIT (desc->div_bits) -1 ) << desc->div_shift; + val = div_val << desc->div_shift; + + err =regmap_update_bits (map, reg, mask, val); +if (err) { +dev_dbg (dev,"Failed to update div reg for clock %s\n" , + desc->name); +return err; + } + } + +if (desc->base_bits) { + mask = (BIT (desc->base_bits) -1 ) << desc->base_shift; + val = base_val << desc->base_shift; + + err =regmap_update_bits (map, desc->base_reg, mask, val); +if (err) { +dev_dbg (dev,"Failed to update reg for clock %s\n" , + desc->name); +return err; + } + } + +return 0 ; }static const struct clk_ops en7581_clk_ops = { .recalc_rate = en7581_recalc_rate, + .determine_rate = en7581_determine_rate, + .set_rate = en7581_set_rate, }; static int en7581_register_clocks(struct device *dev, struct clk_hw_onecell_data *clk_data,
Signature · 1 line
2.55.0
PATCH v16 7/8 clk: en7523: generalize register clocks function
In reply to Christian MarangiAiroha AN7583 SoC will use the same logic used by Airoha EN7581 SoC to register clocks. Generalize it to register clocks defined in soc_data.
Add the clocks definition in EN7581 SoC to support this new implementation.
Add the .num_base_clocks value to declare the number of base clocks.
--- drivers/clk/clk-en7523.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/clk/clk-en7523.c +9 -2
@@ -151,6 +151,8 @@ struct en_clk_priv {struct en_clk_soc_data {u32 num_clocks; +u32 num_base_clocks; +const struct en_clk_desc *base_clks;const struct clk_ops pcie_ops;int (*hw_init)(struct platform_device *pdev,struct clk_hw_onecell_data *clk_data);
@@ -1117,11 +1119,14 @@ static const struct clk_ops en7581_clk_ops = {static int en7581_register_clocks (struct device *dev,struct clk_hw_onecell_data *clk_data,struct regmap *map,void __iomem *base) { +const struct en_clk_soc_data *soc_data;struct clk_hw *hw;int i; -for (i =0 ; i <ARRAY_SIZE (en7581_base_clks); i++) { -const struct en_clk_desc *desc = &en7581_base_clks[i]; + soc_data =device_get_match_data (dev); + +for (i =0 ; i < soc_data->num_base_clocks; i++) { +const struct en_clk_desc *desc = &soc_data->base_clks[i];struct clk_init_data init = { .ops = &en7581_clk_ops, };
@@ -1602,6 +1607,8 @@ static const struct en_clk_soc_data en7523_data = {static const struct en_clk_soc_data en7581_data = {/* We increment num_clocks by 1 to account for additional PCIe clock */ .num_clocks =ARRAY_SIZE (en7581_base_clks) +1 , + .base_clks = en7581_base_clks, + .num_base_clocks =ARRAY_SIZE (en7581_base_clks), .pcie_ops = { .is_enabled = en7581_pci_is_enabled, .enable = en7581_pci_enable,
Signature · 1 line
2.55.0
PATCH v16 8/8 clk: en7523: add support for Airoha AN7583 clock
In reply to Christian MarangiAdd support for Airoha AN7583 clock and reset.
Airoha AN7583 SoC have the same register address of EN7581 but implement different bits and additional base clocks. Also reset are different with the introduction of 2 dedicated MDIO line and drop of some reset lines.
--- drivers/clk/clk-en7523.c | 237 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+)
drivers/clk/clk-en7523.c +237 -0
@@ -13,6 +13,7 @@#include <linux/reset-controller.h> #include <linux/spinlock.h> #include <dt-bindings/clock/en7523-clk.h> +#include <dt-bindings/reset/airoha,an7583-reset.h> #include <dt-bindings/reset/airoha,en7523-reset.h> #include <dt-bindings/reset/airoha,en7581-reset.h> #include <dt-bindings/clock/econet,en751221-scu.h>
@@ -253,6 +254,14 @@ static const u32 crypto_base[] = { 540000000, 480000000 };static const u32 emmc7581_base[] = {200000000 ,150000000 };/* EN751221 */ static const u32 gsw751221_base[] = {500000000 ,250000000 ,400000000 ,200000000 }; +/* AN7583 */ +static const u32 gsw7583_base[] = {540672000 ,270336000 ,400000000 ,200000000 }; +static const u32 emi7583_base[] = {540672000 ,480000000 ,400000000 ,300000000 }; +static const u32 bus7583_base[] = {600000000 ,540672000 ,480000000 ,400000000 }; +static const u32 spi7583_base[] = {400000000 ,12500000 }; +static const u32 npu7583_base[] = {666000000 ,800000000 ,720000000 ,600000000 }; +static const u32 crypto7583_base[] = {540672000 ,400000000 }; +static const u32 emmc7583_base[] = {150000000 ,200000000 };static const struct en_clk_desc en7523_base_clks[] = { {
@@ -437,6 +446,125 @@ static const struct en_clk_desc en7581_base_clks[] = { } }; +static const struct en_clk_desc an7583_base_clks[] = { + { + .id =EN7523_CLK_GSW , + .name ="gsw" , + + .base_reg =REG_GSW_CLK_DIV_SEL , + .base_bits =2 , + .base_shift =8 , + .base_values = gsw7583_base, + .n_base_values =ARRAY_SIZE (gsw7583_base), + + .div_bits =3 , + .div_shift =0 , + }, { + .id =EN7523_CLK_EMI , + .name ="emi" , + + .base_reg =REG_EMI_CLK_DIV_SEL , + .base_bits =2 , + .base_shift =8 , + .base_values = emi7583_base, + .n_base_values =ARRAY_SIZE (emi7583_base), + + .div_bits =3 , + .div_shift =0 , + }, { + .id =EN7523_CLK_BUS , + .name ="bus" , + + .base_reg =REG_BUS_CLK_DIV_SEL , + .base_bits =2 , + .base_shift =8 , + .base_values = bus7583_base, + .n_base_values =ARRAY_SIZE (bus7583_base), + + .div_bits =3 , + .div_shift =0 , + .div_table = bus_div, + }, { + .id =EN7523_CLK_SLIC , + .name ="slic" , + + .base_reg =REG_SPI_CLK_FREQ_SEL , + .base_bits =1 , + .base_shift =1 , + .base_values = slic_base, + .n_base_values =ARRAY_SIZE (slic_base), + + .div_reg =REG_SPI_CLK_DIV_SEL , + .div_bits =5 , + .div_shift =24 , + .div_table = slic_div, + }, { + .id =EN7523_CLK_SPI , + .name ="spi" , + + .base_reg =REG_SPI_CLK_FREQ_SEL , + .base_bits =1 , + .base_shift =0 , + .base_values = spi7583_base, + .n_base_values =ARRAY_SIZE (spi7583_base), + + .div_reg =REG_SPI_CLK_DIV_SEL , + .div_bits =5 , + .div_shift =8 , + .div_table = spi_div, + }, { + .id =EN7523_CLK_NPU , + .name ="npu" , + + .base_reg =REG_NPU_CLK_DIV_SEL , + .base_bits =2 , + .base_shift =9 , + .base_values = npu7583_base, + .n_base_values =ARRAY_SIZE (npu7583_base), + + .div_bits =3 , + .div_shift =0 , + }, { + .id =EN7523_CLK_CRYPTO , + .name ="crypto" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + .base_bits =1 , + .base_shift =0 , + .base_values = crypto7583_base, + .n_base_values =ARRAY_SIZE (crypto7583_base), + }, { + .id =EN7581_CLK_EMMC , + .name ="emmc" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + .base_bits =1 , + .base_shift =13 , + .base_values = emmc7583_base, + .n_base_values =ARRAY_SIZE (emmc7583_base), + }, { + .id =AN7583_CLK_MDIO0 , + .name ="mdio0" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + + .base_value =25000000 , + + .div_bits =4 , + .div_shift =15 , + }, { + .id =AN7583_CLK_MDIO1 , + .name ="mdio1" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + + .base_value =25000000 , + + .div_bits =4 , + .div_shift =19 , + } +}; +static const u16 en7581_rst_ofs[] = {REG_RST_CTRL2 ,REG_RST_CTRL1 ,
@@ -612,6 +740,64 @@ static const u16 en751221_rst_map[] = { [EN751221_USB_PHY_P1_RST] = 3 * RST_NR_PER_BANK + 7, }; +static const u16 an7583_rst_map[] = { +/* RST_CTRL2 */ + [AN7583_XPON_PHY_RST ] =0 , + [AN7583_GPON_OLT_RST ] =1 , + [AN7583_CPU_TIMER2_RST ] =2 , + [AN7583_HSUART_RST ] =3 , + [AN7583_UART4_RST ] =4 , + [AN7583_UART5_RST ] =5 , + [AN7583_I2C2_RST ] =6 , + [AN7583_XSI_MAC_RST ] =7 , + [AN7583_XSI_PHY_RST ] =8 , + [AN7583_NPU_RST ] =9 , + [AN7583_TRNG_MSTART_RST ] =12 , + [AN7583_DUAL_HSI0_RST ] =13 , + [AN7583_DUAL_HSI1_RST ] =14 , + [AN7583_DUAL_HSI0_MAC_RST ] =16 , + [AN7583_DUAL_HSI1_MAC_RST ] =17 , + [AN7583_XPON_XFI_RST ] =18 , + [AN7583_WDMA_RST ] =19 , + [AN7583_WOE0_RST ] =20 , + [AN7583_HSDMA_RST ] =22 , + [AN7583_TDMA_RST ] =24 , + [AN7583_EMMC_RST ] =25 , + [AN7583_SOE_RST ] =26 , + [AN7583_XFP_MAC_RST ] =28 , + [AN7583_MDIO0_RST ] =30 , + [AN7583_MDIO1_RST ] =31 , +/* RST_CTRL1 */ + [AN7583_PCM1_ZSI_ISI_RST ] =RST_NR_PER_BANK +0 , + [AN7583_FE_PDMA_RST ] =RST_NR_PER_BANK +1 , + [AN7583_FE_QDMA_RST ] =RST_NR_PER_BANK +2 , + [AN7583_PCM_SPIWP_RST ] =RST_NR_PER_BANK +4 , + [AN7583_CRYPTO_RST ] =RST_NR_PER_BANK +6 , + [AN7583_TIMER_RST ] =RST_NR_PER_BANK +8 , + [AN7583_PCM1_RST ] =RST_NR_PER_BANK +11 , + [AN7583_UART_RST ] =RST_NR_PER_BANK +12 , + [AN7583_GPIO_RST ] =RST_NR_PER_BANK +13 , + [AN7583_GDMA_RST ] =RST_NR_PER_BANK +14 , + [AN7583_I2C_MASTER_RST ] =RST_NR_PER_BANK +16 , + [AN7583_PCM2_ZSI_ISI_RST ] =RST_NR_PER_BANK +17 , + [AN7583_SFC_RST ] =RST_NR_PER_BANK +18 , + [AN7583_UART2_RST ] =RST_NR_PER_BANK +19 , + [AN7583_GDMP_RST ] =RST_NR_PER_BANK +20 , + [AN7583_FE_RST ] =RST_NR_PER_BANK +21 , + [AN7583_USB_HOST_P0_RST ] =RST_NR_PER_BANK +22 , + [AN7583_GSW_RST ] =RST_NR_PER_BANK +23 , + [AN7583_SFC2_PCM_RST ] =RST_NR_PER_BANK +25 , + [AN7583_PCIE0_RST ] =RST_NR_PER_BANK +26 , + [AN7583_PCIE1_RST ] =RST_NR_PER_BANK +27 , + [AN7583_CPU_TIMER_RST ] =RST_NR_PER_BANK +28 , + [AN7583_PCIE_HB_RST ] =RST_NR_PER_BANK +29 , + [AN7583_XPON_MAC_RST ] =RST_NR_PER_BANK +31 , + +/* RST_PCIC */ + [AN7583_PCIC_PERSTOUT0_RST ] =2 *RST_NR_PER_BANK +29 , + [AN7583_PCIC_PERSTOUT1_RST ] =2 *RST_NR_PER_BANK +26 , +}; +static int en7581_reset_register (struct device *dev,void __iomem *base,const u16 *rst_map,int nr_resets,const u16 *rst_reg_ofs);
@@ -1462,6 +1648,43 @@ static int en7581_clk_hw_init(struct platform_device *pdev,return en7581_serdes_phy_register (&pdev->dev); } +static int an7583_clk_hw_init (struct platform_device *pdev, +struct clk_hw_onecell_data *clk_data) +{ +struct en_clk_priv *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +struct regmap *map; +void __iomem *base; +u32 val; +int ret; + + map =syscon_regmap_lookup_by_phandle (dev->of_node,"airoha,chip-scu" ); +if (IS_ERR (map)) +return PTR_ERR (map); + + base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (base)) +return PTR_ERR (base); + + priv->base = base; + +en7581_register_clocks (dev, clk_data, map, base); + + val =readl (base +REG_RST_CTRL1 ); + val |=REG_PCIE_HB_RST ; +writel (val, base +REG_RST_CTRL1 ); + val &= ~REG_PCIE_HB_RST ; +writel (val, base +REG_RST_CTRL1 ); + + ret =en7581_reset_register (dev, base, an7583_rst_map, +ARRAY_SIZE (an7583_rst_map), + en7581_rst_ofs); +if (ret) +return ret; + +return en7581_serdes_phy_register (dev); +} +static enum en_hir get_hw_id (void __iomem *np_base) {u32 val =FIELD_GET (REG_HIR_MASK ,readl (np_base +REG_HIR ));
@@ -1617,6 +1840,19 @@ static const struct en_clk_soc_data en7581_data = { .hw_init = en7581_clk_hw_init, }; +static const struct en_clk_soc_data an7583_data = { +/* We increment num_clocks by 1 to account for additional PCIe clock */ + .num_clocks =ARRAY_SIZE (an7583_base_clks) +1 , + .base_clks = an7583_base_clks, + .num_base_clocks =ARRAY_SIZE (an7583_base_clks), + .pcie_ops = { + .is_enabled = en7581_pci_is_enabled, + .enable = en7581_pci_enable, + .disable = en7581_pci_disable, + }, + .hw_init = an7583_clk_hw_init, +}; +static const struct en_clk_soc_data en751221_data = { .num_clocks =EN751221_MAX_CLKS , .pcie_ops = {
@@ -1631,6 +1867,7 @@ static const struct en_clk_soc_data en751221_data = {static const struct of_device_id of_match_clk_en7523[] = { { .compatible ="airoha,en7523-scu" , .data = &en7523_data }, { .compatible ="airoha,en7581-scu" , .data = &en7581_data }, + { .compatible ="airoha,an7583-scu" , .data = &an7583_data }, { .compatible ="econet,en751221-scu" , .data = &en751221_data }, {/* sentinel */ } };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v16 8/8] clk: en7523: add support for Airoha AN7583 clock
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] clk: en7523: unchecked en7581_register_clocks() return in an7583_clk_hw_init() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] clk: en7523: unchecked en7581_register_clocks() return in an7583_clk_hw_init()
--
commit 9ef5aa8e833843fe127e6fd5746ea40e75110952
Author: Christian Marangi <[email protected]>
clk: en7523: add support for Airoha AN7583 clock
This commit adds clock and reset controller support for the Airoha AN7583 SoC to the en7523 clock driver.
Quoted 4 lines
drivers/clk/clk-en7523.c +0
-0
[ ... ]
Quoted 15 lines
drivers/clk/clk-en7523.c +11
-0@@ -1462,6 +1648,43 @@ static int en7581_clk_hw_init(struct platform_device *pdev,return en7581_serdes_phy_register (&pdev->dev); } +static int an7583_clk_hw_init (struct platform_device *pdev, +struct clk_hw_onecell_data *clk_data) +{ +struct en_clk_priv *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +struct regmap *map; +void __iomem *base; +u32 val; +int ret; + + map =syscon_regmap_lookup_by_phandle (dev->of_node,"airoha,chip-scu" );
drivers/clk/clk-en7523.c static int en7581_clk_hw_init(struct platform_device *pdev, · line 1671
Quoted 10 lines
drivers/clk/clk-en7523.c +10
-0+if (IS_ERR (map)) +return PTR_ERR (map); + + base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (base)) +return PTR_ERR (base); + + priv->base = base; + +en7581_register_clocks (dev, clk_data, map, base);
[Severity: Medium]
Should the return value of en7581_register_clocks() be checked here, as in en7581_clk_hw_init()? If an allocation or clock registration fails inside en7581_register_clocks(), probe still succeeds and registers clk_data with unpopulated NULL clk_data->hws[] entries.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8