1 From eb1dd407b4be7ca38166a38c56c8edf52c6a399f Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sun, 16 Apr 2023 13:08:14 +0100
4 Subject: [PATCH 13/13] net: dsa: mt7530: fix support for MT7531BE
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 There are two variants of the MT7531 switch IC which got different
10 features (and pins) regarding port 5:
11 * MT7531AE: SGMII/1000Base-X/2500Base-X SerDes PCS
14 Moving the creation of the SerDes PCS from mt753x_setup to mt7530_probe
15 with commit 6de285229773 ("net: dsa: mt7530: move SGMII PCS creation
16 to mt7530_probe function") works fine for MT7531AE which got two
17 instances of mtk-pcs-lynxi, however, MT7531BE requires mt7531_pll_setup
18 to setup clocks before the single PCS on port 6 (usually used as CPU
19 port) starts to work and hence the PCS creation failed on MT7531BE.
21 Fix this by introducing a pointer to mt7531_create_sgmii function in
22 struct mt7530_priv and call it again at the end of mt753x_setup like it
23 was before commit 6de285229773 ("net: dsa: mt7530: move SGMII PCS
24 creation to mt7530_probe function").
26 Fixes: 6de285229773 ("net: dsa: mt7530: move SGMII PCS creation to mt7530_probe function")
27 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
28 Acked-by: Arınç ÜNAL <arinc.unal@arinc9.com>
29 Link: https://lore.kernel.org/r/ZDvlLhhqheobUvOK@makrotopia.org
30 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
32 drivers/net/dsa/mt7530-mdio.c | 16 ++++++++--------
33 drivers/net/dsa/mt7530.c | 6 ++++++
34 drivers/net/dsa/mt7530.h | 4 ++--
35 3 files changed, 16 insertions(+), 10 deletions(-)
37 --- a/drivers/net/dsa/mt7530-mdio.c
38 +++ b/drivers/net/dsa/mt7530-mdio.c
39 @@ -81,14 +81,17 @@ static const struct regmap_bus mt7530_re
43 -mt7531_create_sgmii(struct mt7530_priv *priv)
44 +mt7531_create_sgmii(struct mt7530_priv *priv, bool dual_sgmii)
46 - struct regmap_config *mt7531_pcs_config[2];
47 + struct regmap_config *mt7531_pcs_config[2] = {};
48 struct phylink_pcs *pcs;
49 struct regmap *regmap;
52 - for (i = 0; i < 2; i++) {
53 + /* MT7531AE has two SGMII units for port 5 and port 6
54 + * MT7531BE has only one SGMII unit for port 6
56 + for (i = dual_sgmii ? 0 : 1; i < 2; i++) {
57 mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
58 sizeof(struct regmap_config),
60 @@ -208,11 +211,8 @@ mt7530_probe(struct mdio_device *mdiodev
61 if (IS_ERR(priv->regmap))
62 return PTR_ERR(priv->regmap);
64 - if (priv->id == ID_MT7531) {
65 - ret = mt7531_create_sgmii(priv);
69 + if (priv->id == ID_MT7531)
70 + priv->create_sgmii = mt7531_create_sgmii;
72 return dsa_register_switch(priv->ds);
74 --- a/drivers/net/dsa/mt7530.c
75 +++ b/drivers/net/dsa/mt7530.c
76 @@ -3048,6 +3048,12 @@ mt753x_setup(struct dsa_switch *ds)
78 mt7530_free_irq_common(priv);
80 + if (priv->create_sgmii) {
81 + ret = priv->create_sgmii(priv, mt7531_dual_sgmii_supported(priv));
82 + if (ret && priv->irq)
83 + mt7530_free_irq(priv);
89 --- a/drivers/net/dsa/mt7530.h
90 +++ b/drivers/net/dsa/mt7530.h
91 @@ -748,10 +748,10 @@ struct mt753x_info {
93 * @p6_interface Holding the current port 6 interface
94 * @p5_intf_sel: Holding the current port 5 interface select
96 * @irq: IRQ number of the switch
97 * @irq_domain: IRQ domain of the switch irq_chip
98 * @irq_enable: IRQ enable bits, synced to SYS_INT_EN
99 + * @create_sgmii: Pointer to function creating SGMII PCS instance(s)
103 @@ -770,7 +770,6 @@ struct mt7530_priv {
104 unsigned int p5_intf_sel;
108 struct mt7530_port ports[MT7530_NUM_PORTS];
109 struct mt753x_pcs pcs[MT7530_NUM_PORTS];
110 /* protect among processes for registers access*/
111 @@ -778,6 +777,7 @@ struct mt7530_priv {
113 struct irq_domain *irq_domain;
115 + int (*create_sgmii)(struct mt7530_priv *priv, bool dual_sgmii);
118 struct mt7530_hw_vlan_entry {