10e2c6a184f54cea51d65bfbd9e9f0f90cf84884
[librecmc/librecmc.git] /
1 From 37c9c0d8d0b2e24f8c9af72ecd4edd31537284d3 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 3 Apr 2023 02:18:39 +0100
4 Subject: [PATCH 11/16] net: dsa: mt7530: introduce mt7530_probe_common helper
5  function
6
7 Move commonly used parts from mt7530_probe into new mt7530_probe_common
8 helper function which will be used by both, mt7530_probe and the
9 to-be-introduced mt7988_probe.
10
11 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
12 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15  drivers/net/dsa/mt7530.c | 98 ++++++++++++++++++++++------------------
16  1 file changed, 54 insertions(+), 44 deletions(-)
17
18 --- a/drivers/net/dsa/mt7530.c
19 +++ b/drivers/net/dsa/mt7530.c
20 @@ -3366,44 +3366,21 @@ static const struct of_device_id mt7530_
21  MODULE_DEVICE_TABLE(of, mt7530_of_match);
22  
23  static int
24 -mt7530_probe(struct mdio_device *mdiodev)
25 +mt7530_probe_common(struct mt7530_priv *priv)
26  {
27 -       static struct regmap_config *regmap_config;
28 -       struct mt7530_priv *priv;
29 -       struct device_node *dn;
30 -       int ret;
31 +       struct device *dev = priv->dev;
32  
33 -       dn = mdiodev->dev.of_node;
34 -
35 -       priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
36 -       if (!priv)
37 -               return -ENOMEM;
38 -
39 -       priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
40 +       priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
41         if (!priv->ds)
42                 return -ENOMEM;
43  
44 -       priv->ds->dev = &mdiodev->dev;
45 +       priv->ds->dev = dev;
46         priv->ds->num_ports = MT7530_NUM_PORTS;
47  
48 -       /* Use medatek,mcm property to distinguish hardware type that would
49 -        * casues a little bit differences on power-on sequence.
50 -        */
51 -       priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
52 -       if (priv->mcm) {
53 -               dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
54 -
55 -               priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm");
56 -               if (IS_ERR(priv->rstc)) {
57 -                       dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
58 -                       return PTR_ERR(priv->rstc);
59 -               }
60 -       }
61 -
62         /* Get the hardware identifier from the devicetree node.
63          * We will need it for some of the clock and regulator setup.
64          */
65 -       priv->info = of_device_get_match_data(&mdiodev->dev);
66 +       priv->info = of_device_get_match_data(dev);
67         if (!priv->info)
68                 return -EINVAL;
69  
70 @@ -3417,23 +3394,53 @@ mt7530_probe(struct mdio_device *mdiodev
71                 return -EINVAL;
72  
73         priv->id = priv->info->id;
74 +       priv->dev = dev;
75 +       priv->ds->priv = priv;
76 +       priv->ds->ops = &mt7530_switch_ops;
77 +       mutex_init(&priv->reg_mutex);
78 +       dev_set_drvdata(dev, priv);
79  
80 -       if (priv->id == ID_MT7530) {
81 -               priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
82 -               if (IS_ERR(priv->core_pwr))
83 -                       return PTR_ERR(priv->core_pwr);
84 +       return 0;
85 +}
86  
87 -               priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
88 -               if (IS_ERR(priv->io_pwr))
89 -                       return PTR_ERR(priv->io_pwr);
90 -       }
91 +static int
92 +mt7530_probe(struct mdio_device *mdiodev)
93 +{
94 +       static struct regmap_config *regmap_config;
95 +       struct mt7530_priv *priv;
96 +       struct device_node *dn;
97 +       int ret;
98 +
99 +       dn = mdiodev->dev.of_node;
100 +
101 +       priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
102 +       if (!priv)
103 +               return -ENOMEM;
104  
105 -       /* Not MCM that indicates switch works as the remote standalone
106 +       priv->bus = mdiodev->bus;
107 +       priv->dev = &mdiodev->dev;
108 +
109 +       ret = mt7530_probe_common(priv);
110 +       if (ret)
111 +               return ret;
112 +
113 +       /* Use medatek,mcm property to distinguish hardware type that would
114 +        * cause a little bit differences on power-on sequence.
115 +        * Not MCM that indicates switch works as the remote standalone
116          * integrated circuit so the GPIO pin would be used to complete
117          * the reset, otherwise memory-mapped register accessing used
118          * through syscon provides in the case of MCM.
119          */
120 -       if (!priv->mcm) {
121 +       priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
122 +       if (priv->mcm) {
123 +               dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
124 +
125 +               priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm");
126 +               if (IS_ERR(priv->rstc)) {
127 +                       dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
128 +                       return PTR_ERR(priv->rstc);
129 +               }
130 +       } else {
131                 priv->reset = devm_gpiod_get_optional(&mdiodev->dev, "reset",
132                                                       GPIOD_OUT_LOW);
133                 if (IS_ERR(priv->reset)) {
134 @@ -3442,12 +3449,15 @@ mt7530_probe(struct mdio_device *mdiodev
135                 }
136         }
137  
138 -       priv->bus = mdiodev->bus;
139 -       priv->dev = &mdiodev->dev;
140 -       priv->ds->priv = priv;
141 -       priv->ds->ops = &mt7530_switch_ops;
142 -       mutex_init(&priv->reg_mutex);
143 -       dev_set_drvdata(&mdiodev->dev, priv);
144 +       if (priv->id == ID_MT7530) {
145 +               priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
146 +               if (IS_ERR(priv->core_pwr))
147 +                       return PTR_ERR(priv->core_pwr);
148 +
149 +               priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
150 +               if (IS_ERR(priv->io_pwr))
151 +                       return PTR_ERR(priv->io_pwr);
152 +       }
153  
154         regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config),
155                                      GFP_KERNEL);