1 From b896355fc4988216d4f38582d07add9252a795ae Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 3 Apr 2023 02:17:30 +0100
4 Subject: [PATCH 02/13] net: dsa: mt7530: refactor SGMII PCS creation
6 Instead of macro templates use a dedidated function and allocated
7 regmap_config when creating the regmaps for the pcs-mtk-lynxi
9 This is in preparation to switching to use unlocked regmap accessors
10 and have regmap's locking API handle locking for us.
12 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
13 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/dsa/mt7530.c | 74 +++++++++++++++++++++++++++-------------
17 1 file changed, 50 insertions(+), 24 deletions(-)
19 --- a/drivers/net/dsa/mt7530.c
20 +++ b/drivers/net/dsa/mt7530.c
21 @@ -2950,26 +2950,56 @@ static const struct regmap_bus mt7531_re
22 .reg_update_bits = mt7530_regmap_update_bits,
25 -#define MT7531_PCS_REGMAP_CONFIG(_name, _reg_base) \
31 - .reg_base = _reg_base, \
32 - .max_register = 0x17c, \
34 +mt7531_create_sgmii(struct mt7530_priv *priv)
36 + struct regmap_config *mt7531_pcs_config[2];
37 + struct phylink_pcs *pcs;
38 + struct regmap *regmap;
41 + for (i = 0; i < 2; i++) {
42 + mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
43 + sizeof(struct regmap_config),
45 + if (!mt7531_pcs_config[i]) {
50 + mt7531_pcs_config[i]->name = i ? "port6" : "port5";
51 + mt7531_pcs_config[i]->reg_bits = 16;
52 + mt7531_pcs_config[i]->val_bits = 32;
53 + mt7531_pcs_config[i]->reg_stride = 4;
54 + mt7531_pcs_config[i]->reg_base = MT7531_SGMII_REG_BASE(5 + i);
55 + mt7531_pcs_config[i]->max_register = 0x17c;
57 + regmap = devm_regmap_init(priv->dev,
58 + &mt7531_regmap_bus, priv,
59 + mt7531_pcs_config[i]);
60 + if (IS_ERR(regmap)) {
61 + ret = PTR_ERR(regmap);
64 + pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
65 + MT7531_PHYA_CTRL_SIGNAL3, 0);
70 + priv->ports[5 + i].sgmii_pcs = pcs;
73 -static const struct regmap_config mt7531_pcs_config[] = {
74 - MT7531_PCS_REGMAP_CONFIG("port5", MT7531_SGMII_REG_BASE(5)),
75 - MT7531_PCS_REGMAP_CONFIG("port6", MT7531_SGMII_REG_BASE(6)),
78 + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
84 mt753x_setup(struct dsa_switch *ds)
86 struct mt7530_priv *priv = ds->priv;
87 - struct regmap *regmap;
90 /* Initialise the PCS devices */
91 @@ -2991,15 +3021,11 @@ mt753x_setup(struct dsa_switch *ds)
93 mt7530_free_irq_common(priv);
95 - if (priv->id == ID_MT7531)
96 - for (i = 0; i < 2; i++) {
97 - regmap = devm_regmap_init(ds->dev,
98 - &mt7531_regmap_bus, priv,
99 - &mt7531_pcs_config[i]);
100 - priv->ports[5 + i].sgmii_pcs =
101 - mtk_pcs_lynxi_create(ds->dev, regmap,
102 - MT7531_PHYA_CTRL_SIGNAL3, 0);
104 + if (priv->id == ID_MT7531) {
105 + ret = mt7531_create_sgmii(priv);
106 + if (ret && priv->irq)
107 + mt7530_free_irq_common(priv);