1 From 4d632005c90e253c000d0db73b7cdb9d8dc2e2dd 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 08/13] net: dsa: mt7530: introduce mt7530_probe_common helper
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.
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>
15 drivers/net/dsa/mt7530.c | 98 ++++++++++++++++++++++------------------
16 1 file changed, 54 insertions(+), 44 deletions(-)
18 --- a/drivers/net/dsa/mt7530.c
19 +++ b/drivers/net/dsa/mt7530.c
20 @@ -3177,44 +3177,21 @@ static const struct of_device_id mt7530_
21 MODULE_DEVICE_TABLE(of, mt7530_of_match);
24 -mt7530_probe(struct mdio_device *mdiodev)
25 +mt7530_probe_common(struct mt7530_priv *priv)
27 - static struct regmap_config *regmap_config;
28 - struct mt7530_priv *priv;
29 - struct device_node *dn;
31 + struct device *dev = priv->dev;
33 - dn = mdiodev->dev.of_node;
35 - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
39 - priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
40 + priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
44 - priv->ds->dev = &mdiodev->dev;
45 + priv->ds->dev = dev;
46 priv->ds->num_ports = MT7530_NUM_PORTS;
48 - /* Use medatek,mcm property to distinguish hardware type that would
49 - * casues a little bit differences on power-on sequence.
51 - priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
53 - dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
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);
62 /* Get the hardware identifier from the devicetree node.
63 * We will need it for some of the clock and regulator setup.
65 - priv->info = of_device_get_match_data(&mdiodev->dev);
66 + priv->info = of_device_get_match_data(dev);
70 @@ -3228,23 +3205,53 @@ mt7530_probe(struct mdio_device *mdiodev
73 priv->id = priv->info->id;
75 + priv->ds->priv = priv;
76 + priv->ds->ops = &mt7530_switch_ops;
77 + mutex_init(&priv->reg_mutex);
78 + dev_set_drvdata(dev, priv);
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);
87 - priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
88 - if (IS_ERR(priv->io_pwr))
89 - return PTR_ERR(priv->io_pwr);
92 +mt7530_probe(struct mdio_device *mdiodev)
94 + static struct regmap_config *regmap_config;
95 + struct mt7530_priv *priv;
96 + struct device_node *dn;
99 + dn = mdiodev->dev.of_node;
101 + priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
105 - /* Not MCM that indicates switch works as the remote standalone
106 + priv->bus = mdiodev->bus;
107 + priv->dev = &mdiodev->dev;
109 + ret = mt7530_probe_common(priv);
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.
121 + priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
123 + dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
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);
131 priv->reset = devm_gpiod_get_optional(&mdiodev->dev, "reset",
133 if (IS_ERR(priv->reset)) {
134 @@ -3253,12 +3260,15 @@ mt7530_probe(struct mdio_device *mdiodev
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);
149 + priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
150 + if (IS_ERR(priv->io_pwr))
151 + return PTR_ERR(priv->io_pwr);
154 regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config),