armsr: armv8: enable serial console for Renesas platforms
[openwrt/staging/stintel.git] / target / linux / generic / backport-6.1 / 790-04-v6.4-net-dsa-mt7530-refactor-SGMII-PCS-creation.patch
1 From 8f83ad87e2df26ddf9b8afd4d2873644a872d929 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 04/48] net: dsa: mt7530: refactor SGMII PCS creation
5
6 Instead of macro templates use a dedidated function and allocated
7 regmap_config when creating the regmaps for the pcs-mtk-lynxi
8 instances.
9 This is in preparation to switching to use unlocked regmap accessors
10 and have regmap's locking API handle locking for us.
11
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>
15 ---
16 drivers/net/dsa/mt7530.c | 74 +++++++++++++++++++++++++++-------------
17 1 file changed, 50 insertions(+), 24 deletions(-)
18
19 --- a/drivers/net/dsa/mt7530.c
20 +++ b/drivers/net/dsa/mt7530.c
21 @@ -3189,26 +3189,56 @@ static const struct regmap_bus mt7531_re
22 .reg_update_bits = mt7530_regmap_update_bits,
23 };
24
25 -#define MT7531_PCS_REGMAP_CONFIG(_name, _reg_base) \
26 - { \
27 - .name = _name, \
28 - .reg_bits = 16, \
29 - .val_bits = 32, \
30 - .reg_stride = 4, \
31 - .reg_base = _reg_base, \
32 - .max_register = 0x17c, \
33 +static int
34 +mt7531_create_sgmii(struct mt7530_priv *priv)
35 +{
36 + struct regmap_config *mt7531_pcs_config[2];
37 + struct phylink_pcs *pcs;
38 + struct regmap *regmap;
39 + int i, ret = 0;
40 +
41 + for (i = 0; i < 2; i++) {
42 + mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
43 + sizeof(struct regmap_config),
44 + GFP_KERNEL);
45 + if (!mt7531_pcs_config[i]) {
46 + ret = -ENOMEM;
47 + break;
48 + }
49 +
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;
56 +
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);
62 + break;
63 + }
64 + pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
65 + MT7531_PHYA_CTRL_SIGNAL3, 0);
66 + if (!pcs) {
67 + ret = -ENXIO;
68 + break;
69 + }
70 + priv->ports[5 + i].sgmii_pcs = pcs;
71 }
72
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)),
76 -};
77 + if (ret && i)
78 + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
79 +
80 + return ret;
81 +}
82
83 static int
84 mt753x_setup(struct dsa_switch *ds)
85 {
86 struct mt7530_priv *priv = ds->priv;
87 - struct regmap *regmap;
88 int i, ret;
89
90 /* Initialise the PCS devices */
91 @@ -3230,15 +3260,11 @@ mt753x_setup(struct dsa_switch *ds)
92 if (ret && priv->irq)
93 mt7530_free_irq_common(priv);
94
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);
103 - }
104 + if (priv->id == ID_MT7531) {
105 + ret = mt7531_create_sgmii(priv);
106 + if (ret && priv->irq)
107 + mt7530_free_irq_common(priv);
108 + }
109
110 return ret;
111 }