clk: add support for Airoha AN7583 clock
Subsystems (3)
v13 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 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 (5):
dt-bindings: clock: airoha: Document support for AN7583 clock
clk: en7523: use devm variant for clk_hw_register and fixed clock
clk: en7523: protect concurrent access to reset and PCI register
clk: en7523: generalize register clocks function
clk: en7523: add support for Airoha AN7583 clock
.../bindings/clock/airoha,en7523-scu.yaml | 25 ++ drivers/clk/clk-en7523.c | 340 +++++++++++++++++- include/dt-bindings/clock/en7523-clk.h | 3 + .../dt-bindings/reset/airoha,an7583-reset.h | 65 ++++ 4 files changed, 422 insertions(+), 11 deletions(-) create mode 100644 include/dt-bindings/reset/airoha,an7583-reset.h
Signature · 1 line
2.55.0
PATCH v13 1/5 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 | 25 +++++++ include/dt-bindings/clock/en7523-clk.h | 3 + .../dt-bindings/reset/airoha,an7583-reset.h | 65 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 include/dt-bindings/reset/airoha,an7583-reset.h
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +25 -0
@@ -31,6 +31,7 @@ properties: compatible: items: - enum: + - airoha,an7583-scu - airoha,en7523-scu - airoha,en7581-scu - econet,en751221-scu
@@ -57,12 +58,36 @@ 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 the PCIe related clocks and resets. + 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
[email protected]
AI reviewRe: [PATCH v13 1/5] dt-bindings: clock: airoha: Document support for AN7583 clock
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] dt-bindings: clock: airoha: unwieldy per-compatible conditionals in schema - [Low] dt-bindings…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] dt-bindings: clock: airoha: unwieldy per-compatible conditionals in schema
- [Low] dt-bindings: clock: airoha: inaccurate description of airoha,chip-scu
--
commit f0ae95ef10113af9be9b8cf6b0ed7bcb3dcee33f
Author: Christian Marangi <[email protected]>
dt-bindings: clock: airoha: Document support for AN7583 clock
This commit documents the Airoha AN7583 clock and reset controller binding in the EN7523 SCU schema, adding the airoha,chip-scu phandle property along with clock and reset binding header constants for AN7583.
Quoted 13 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-0@@ -31,6 +31,7 @@ properties: compatible: items: - enum: + - airoha,an7583-scu - airoha,en7523-scu - airoha,en7581-scu - econet,en751221-scu
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml properties: · line 64
Quoted 7 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +4
-0@@ -57,12 +58,36 @@ 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 the PCIe related clocks and resets.
[Severity: Low]
As reported by Brian Masney on v9 [1], is the description of airoha,chip-scu accurate? As noted in the commit message and implemented in drivers/clk/clk-en7523.c, the Chip SCU provides the registers used to read base clock sources, dividers, and clock gates, whereas the main SCU register block provides the registers for PCIe clocks, resets, and PHY SERDES.
Quoted 14 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +8
-0required: - compatible - reg - '#clock-cells' allOf: + - if: + properties: + compatible: + const: airoha,an7583-scu + + then: + properties: + reg:
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml properties: · line 89
Quoted 10 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +10
-0+ maxItems: 1 + + required: + - airoha,chip-scu + - '#reset-cells' + - '#phy-cells' + + else: + properties: + airoha,chip-scu: false
[Severity: Low]
This isn't a bug, but with airoha,an7583-scu added, all four compatibles in this schema now have separate per-compatible if-then blocks in allOf with diverging constraints across reg, #phy-cells, #reset-cells, and airoha,chip-scu. Would it be cleaner to split the variants into separate binding schemas (or consolidate shared constraints such as reg maxItems: 1) rather than adding another per-compatible conditional block?
[1] https://lore.kernel.org/r/179383990045.753844.10400171550739497565.b4-review@b4
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v13 1/5] dt-bindings: clock: airoha: Document support for AN7583 clock
In reply to Christian MarangiHi Christian,
Quoted 45 lines
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_compatiblewhile 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.
Acked-by Conor Dooley <[email protected]>Signed-off-by Christian Marangi <[email protected]>--- .../bindings/clock/airoha,en7523-scu.yaml | 25 +++++++ include/dt-bindings/clock/en7523-clk.h | 3 + .../dt-bindings/reset/airoha,an7583-reset.h | 65 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 include/dt-bindings/reset/airoha,an7583-reset.hDocumentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-0@@ -31,6 +31,7 @@ properties: compatible: items: - enum: + - airoha,an7583-scu - airoha,en7523-scu - airoha,en7581-scu - econet,en751221-scu
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml properties: · line 64
Quoted 7 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +4
-0@@ -57,12 +58,36 @@ 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 the PCIe related clocks and resets.
My question from an earlier version appears to be unanswered, and Sashiko flagged it.
Brian
Signature · 1 line
Brian Masney <[email protected]>
PATCH v13 2/5 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.
--- drivers/clk/clk-en7523.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/clk/clk-en7523.c +4 -4
@@ -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,7 +707,7 @@ 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));
@@ -769,7 +769,7 @@ static void en7581_register_clocks(struct device *dev, struct clk_hw_onecell_dat } 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));
@@ -1103,7 +1103,7 @@ 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);else
Signature · 1 line
2.55.0
PATCH v13 3/5 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 PCI unprepare case to permit calling it before clk_hw_register and reference the global spinlock.
--- drivers/clk/clk-en7523.c | 74 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-)
drivers/clk/clk-en7523.c +69 -5
@@ -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 device *dev,struct en_clk_gate *cg); };static const u32 gsw_base[] = {400000000 ,500000000 };
@@ -584,51 +585,95 @@ 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; +unsigned long flags;u32 val, mask; + priv =dev_get_drvdata (dev); +/* Need to pull device low before reset */ +spin_lock_irqsave (&priv->lock, flags); val =readl (np_base +REG_PCI_CONTROL ); val &= ~(REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT );writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 );/* Enable PCIe port 1 */ +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_PCI_CONTROL ); val |=REG_PCI_CONTROL_REFCLK_EN1 ;writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 );/* Reset to default */ +spin_lock_irqsave (&priv->lock, flags); 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 ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_RESET_CONTROL1 );writel (val | mask, np_base +REG_RESET_CONTROL1 ); +spin_unlock_irqrestore (&priv->lock, flags); +msleep (100 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_RESET_CONTROL1 );writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (5000 ,10000 );/* Release device */ - mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ; +spin_lock_irqsave (&priv->lock, flags); val =readl (np_base +REG_PCI_CONTROL ); + mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ;writel (val & ~mask, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_PCI_CONTROL );writel (val | mask, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +msleep (250 );return 0 ; } -static void en7523_pci_unprepare (struct clk_hw *hw) +static void __en7523_pci_unprepare (struct device *dev,struct en_clk_gate *cg) { - struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct en_clk_priv *priv =dev_get_drvdata (dev);void __iomem *np_base = cg->base; +unsigned long flags;u32 val; +spin_lock_irqsave (&priv->lock, flags); val =readl (np_base +REG_PCI_CONTROL ); val &= ~REG_PCI_CONTROL_REFCLK_EN1 ;writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +} + +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 (dev, cg); } static struct clk_hw *en7523_register_pcie_clk(struct device *dev,
@@ -648,8 +693,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 (dev, cg);if (devm_clk_hw_register (dev, &cg->hw))return NULL ;
@@ -663,6 +708,7 @@ static int en7581_pci_is_enabled(struct clk_hw *hw)u32 val, mask; mask =REG_PCI_CONTROL_REFCLK_EN0 |REG_PCI_CONTROL_REFCLK_EN1 ; + val =readl (cg->base +REG_PCI_CONTROL );return (val & mask) == mask; }
@@ -670,10 +716,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 );
@@ -683,10 +735,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 ); }
@@ -787,11 +845,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;
@@ -832,6 +893,7 @@ static int en7523_reset_status(struct reset_controller_dev *rcdev, inverted = true; val =readl (addr) &BIT (id %RST_NR_PER_BANK ); +return inverted ? !val : !!val; }
@@ -1220,6 +1282,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 +1304,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
Re: [PATCH v13 3/5] clk: en7523: protect concurrent access to reset and PCI register
Hi Christian,
Quoted 8 lines
Use 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 PCI unprepare case to permit calling it before
clk_hw_registerand reference the global spinlock.
This should be split out into it's own patch.
Quoted 22 lines
Signed-off-by Christian Marangi <[email protected]>--- drivers/clk/clk-en7523.c | 74 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-)drivers/clk/clk-en7523.c +1
-0@@ -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 device *dev,struct en_clk_gate *cg); };static const u32 gsw_base[] = {400000000 ,500000000 };@@ -584,51 +585,95 @@ 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);
drivers/clk/clk-en7523.c static int en7523_pci_is_enabled(struct clk_hw *hw) · line 597
Quoted 10 lines
drivers/clk/clk-en7523.c +6
-0+struct device *dev =clk_hw_get_dev (hw);void __iomem *np_base = cg->base; +struct en_clk_priv *priv; +unsigned long flags;u32 val, mask; + priv =dev_get_drvdata (dev); +/* Need to pull device low before reset */ +spin_lock_irqsave (&priv->lock, flags);
You can use:
scoped_guard(spinlock_irqsave, &priv->lock) {
...
}Quoted 97 lines
drivers/clk/clk-en7523.c +43
-5val =readl (np_base +REG_PCI_CONTROL ); val &= ~(REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT );writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 );/* Enable PCIe port 1 */ +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_PCI_CONTROL ); val |=REG_PCI_CONTROL_REFCLK_EN1 ;writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 );/* Reset to default */ +spin_lock_irqsave (&priv->lock, flags); 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 ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_RESET_CONTROL1 );writel (val | mask, np_base +REG_RESET_CONTROL1 ); +spin_unlock_irqrestore (&priv->lock, flags); +msleep (100 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_RESET_CONTROL1 );writel (val & ~mask, np_base +REG_RESET_CONTROL1 ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (5000 ,10000 );/* Release device */ - mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ; +spin_lock_irqsave (&priv->lock, flags); val =readl (np_base +REG_PCI_CONTROL ); + mask =REG_PCI_CONTROL_PERSTOUT1 |REG_PCI_CONTROL_PERSTOUT ;writel (val & ~mask, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +usleep_range (1000 ,2000 ); + +spin_lock_irqsave (&priv->lock, flags); + val =readl (np_base +REG_PCI_CONTROL );writel (val | mask, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +msleep (250 );return 0 ; } -static void en7523_pci_unprepare (struct clk_hw *hw) +static void __en7523_pci_unprepare (struct device *dev,struct en_clk_gate *cg) { - struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw); +struct en_clk_priv *priv =dev_get_drvdata (dev);void __iomem *np_base = cg->base; +unsigned long flags;u32 val; +spin_lock_irqsave (&priv->lock, flags); val =readl (np_base +REG_PCI_CONTROL ); val &= ~REG_PCI_CONTROL_REFCLK_EN1 ;writel (val, np_base +REG_PCI_CONTROL ); +spin_unlock_irqrestore (&priv->lock, flags); +} + +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 (dev, cg); } static struct clk_hw *en7523_register_pcie_clk(struct device *dev,@@ -648,8 +693,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 (dev, cg);if (devm_clk_hw_register (dev, &cg->hw))return NULL ;
drivers/clk/clk-en7523.c static int en7581_pci_is_enabled(struct clk_hw *hw) · line 711
Quoted 4 lines
drivers/clk/clk-en7523.c +1
-0@@ -663,6 +708,7 @@ static int en7581_pci_is_enabled(struct clk_hw *hw)u32 val, mask; mask =REG_PCI_CONTROL_REFCLK_EN0 |REG_PCI_CONTROL_REFCLK_EN1 ; +
Extra newline can be dropped.
Brian
Signature · 1 line
Brian Masney <[email protected]>
PATCH v13 4/5 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.
--- drivers/clk/clk-en7523.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clk/clk-en7523.c +7 -2
@@ -147,6 +147,7 @@ struct en_clk_priv {struct en_clk_soc_data {u32 num_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);
@@ -802,12 +803,15 @@ static int en7523_clk_hw_init(struct platform_device *pdev,static void 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;u32 rate;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_clocks -1 ; i++) { +const struct en_clk_desc *desc = &soc_data->base_clks[i];u32 val, reg = desc->div_reg ? desc->div_reg : desc->base_reg;int err;
@@ -1286,6 +1290,7 @@ static const struct en_clk_soc_data en7523_data = { };static const struct en_clk_soc_data en7581_data = { + .base_clks = en7581_base_clks,/* We increment num_clocks by 1 to account for additional PCIe clock */ .num_clocks =ARRAY_SIZE (en7581_base_clks) +1 , .pcie_ops = {
Signature · 1 line
2.55.0
Re: [PATCH v13 4/5] clk: en7523: generalize register clocks function
Hi Christian,
Quoted 26 lines · Christian Marangi
Airoha 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.
Signed-off-by Christian Marangi <[email protected]>--- drivers/clk/clk-en7523.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/clk/clk-en7523.c +1
-0@@ -147,6 +147,7 @@ struct en_clk_priv {struct en_clk_soc_data {u32 num_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);@@ -802,12 +803,15 @@ static int en7523_clk_hw_init(struct platform_device *pdev,static void en7581_register_clocks (struct device *dev,struct clk_hw_onecell_data *clk_data,struct regmap *map,void __iomem *base) {
drivers/clk/clk-en7523.c static int en7523_clk_hw_init(struct platform_device *pdev, · line 813
Quoted 10 lines
drivers/clk/clk-en7523.c +4
-2+const struct en_clk_soc_data *soc_data;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]; + soc_data =device_get_match_data (dev); + +for (i =0 ; i < soc_data->num_clocks -1 ; i++) {
Can there be a proper count stored so that you don't have to do the - 1 here. If I recall, that's done in some other places in this driver.
Brian
PATCH v13 5/5 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 | 249 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+)
drivers/clk/clk-en7523.c +249 -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>
@@ -167,6 +168,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[] = { {
@@ -369,6 +378,138 @@ 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 , + .div_step =1 , + .div_offset =1 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .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_step =1 , + .div_offset =1 , + }, { + .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_val0 =20 , + .div_step =2 , + }, { + .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_val0 =40 , + .div_step =2 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .id =AN7583_CLK_MDIO1 , + .name ="mdio1" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + + .base_value =25000000 , + + .div_bits =4 , + .div_shift =19 , + .div_step =1 , + .div_offset =1 , + } +}; +static const u16 en7581_rst_ofs[] = {REG_RST_CTRL2 ,REG_RST_CTRL1 ,
@@ -544,6 +685,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);
@@ -1148,6 +1347,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 ));
@@ -1301,6 +1537,18 @@ static const struct en_clk_soc_data en7581_data = { .hw_init = en7581_clk_hw_init, }; +static const struct en_clk_soc_data an7583_data = { + .base_clks = an7583_base_clks, +/* We increment num_clocks by 1 to account for additional PCIe clock */ + .num_clocks =ARRAY_SIZE (an7583_base_clks) +1 , + .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 = {
@@ -1315,6 +1563,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 v13 5/5] 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: AN7583 MDIO clocks lack rate ops in en7581_register_clocks() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] clk: en7523: AN7583 MDIO clocks lack rate ops in en7581_register_clocks()
--
commit 1cdcca32a0679ec11e0c737e0957ebcf9e9e90ec
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 1 line
drivers/clk/clk-en7523.c +0
-0@@ -369,6 +378,138 @@ static const struct en_clk_desc en7581_base_clks[] = {
[ ... ]
Quoted 26 lines
drivers/clk/clk-en7523.c +26
-0+ }, { + .id = AN7583_CLK_MDIO0, + .name = "mdio0", + + .base_reg = REG_CRYPTO_CLKSRC2, + + .base_value = 25000000, + + .div_bits = 4, + .div_shift = 15, + .div_step = 1, + .div_offset = 1, + }, { + .id = AN7583_CLK_MDIO1, + .name = "mdio1", + + .base_reg = REG_CRYPTO_CLKSRC2, + + .base_value = 25000000, + + .div_bits = 4, + .div_shift = 19, + .div_step = 1, + .div_offset = 1, + } +};
[ ... ]
Quoted 15 lines
drivers/clk/clk-en7523.c +11
-0@@ -1148,6 +1347,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 1370
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]
Does registering AN7583_CLK_MDIO0 and AN7583_CLK_MDIO1 via en7581_register_clocks() prevent clk_set_rate() from updating their hardware dividers?
en7581_register_clocks() registers every entry in soc_data->base_clks with devm_clk_hw_register_fixed_rate(), which uses clk_fixed_rate_ops and provides no .set_rate, .round_rate, or .determine_rate callbacks. When the MDIO controller driver probes, its clk_set_rate() call is a no-op that returns 0 without programming the 4-bit divider in REG_CRYPTO_CLKSRC2, leaving the MDIO bus at its 25 MHz boot default instead of 2.5 MHz:
drivers/net/mdio/mdio-airoha.c:airoha_mdio_probe() {
...
/* Check if a custom frequency is defined in DT or default to 2.5 MHz */
if (of_property_read_u32(dev->of_node, "clock-frequency", &freq))
freq = 2500000;
ret = clk_set_rate(priv->clk, freq);
if (ret)
return ret;
...
}Although adjustable clock rate support was noted on v10 as planned for a separate series, the in-tree airoha-mdio consumer already relies on clk_set_rate() at this commit.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v13 5/5] clk: en7523: add support for Airoha AN7583 clock
In reply to Christian MarangiQuoted 257 lines
Add 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.
Signed-off-by Christian Marangi <[email protected]>--- drivers/clk/clk-en7523.c | 249 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+)drivers/clk/clk-en7523.c +210
-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> @@ -167,6 +168,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[] = { {@@ -369,6 +378,138 @@ 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 , + .div_step =1 , + .div_offset =1 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .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_step =1 , + .div_offset =1 , + }, { + .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_val0 =20 , + .div_step =2 , + }, { + .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_val0 =40 , + .div_step =2 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .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 , + .div_step =1 , + .div_offset =1 , + }, { + .id =AN7583_CLK_MDIO1 , + .name ="mdio1" , + + .base_reg =REG_CRYPTO_CLKSRC2 , + + .base_value =25000000 , + + .div_bits =4 , + .div_shift =19 , + .div_step =1 , + .div_offset =1 , + } +}; +static const u16 en7581_rst_ofs[] = {REG_RST_CTRL2 ,REG_RST_CTRL1 ,@@ -544,6 +685,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);@@ -1149,6 +1348,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 1371
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);
The Sashiko output looks legit here about the missing .set_rate, .round_rate, or .determine_rate callbacks.
Brian
Signature · 1 line
Brian Masney <[email protected]>