Skip to content

Commit 4029ea3

Browse files
lunndavem330
authored andcommitted
net: phy: mdio-gpio: Parse properties directly into bitbang structure
The same parsing code can be used for both OF and platform devices, if the platform device uses a gpiod_lookup_table. Parse these properties directly into the bitbang structure, rather than use an intermediate platform data structure. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fb76642 commit 4029ea3

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

drivers/net/phy/mdio-gpio.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,20 @@ struct mdio_gpio_info {
3535
struct gpio_desc *mdc, *mdio, *mdo;
3636
};
3737

38-
static void *mdio_gpio_of_get_data(struct device *dev)
38+
static int mdio_gpio_get_data(struct device *dev,
39+
struct mdio_gpio_info *bitbang)
3940
{
40-
struct mdio_gpio_platform_data *pdata;
41+
bitbang->mdc = devm_gpiod_get_index(dev, NULL, 0, GPIOD_OUT_LOW);
42+
if (IS_ERR(bitbang->mdc))
43+
return PTR_ERR(bitbang->mdc);
4144

42-
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
43-
if (!pdata)
44-
return NULL;
45-
46-
pdata->mdc = devm_gpiod_get_index(dev, NULL, 0, GPIOD_OUT_LOW);
47-
if (IS_ERR(pdata->mdc))
48-
return ERR_CAST(pdata->mdc);
49-
50-
pdata->mdio = devm_gpiod_get_index(dev, NULL, 1, GPIOD_IN);
51-
if (IS_ERR(pdata->mdio))
52-
return ERR_CAST(pdata->mdio);
53-
54-
pdata->mdo = devm_gpiod_get_index_optional(dev, NULL, 2, GPIOD_OUT_LOW);
55-
if (IS_ERR(pdata->mdo))
56-
return ERR_CAST(pdata->mdo);
45+
bitbang->mdio = devm_gpiod_get_index(dev, NULL, 1, GPIOD_IN);
46+
if (IS_ERR(bitbang->mdio))
47+
return PTR_ERR(bitbang->mdio);
5748

58-
return pdata;
49+
bitbang->mdo = devm_gpiod_get_index_optional(dev, NULL, 2,
50+
GPIOD_OUT_LOW);
51+
return PTR_ERR_OR_ZERO(bitbang->mdo);
5952
}
6053

6154
static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
@@ -116,15 +109,11 @@ static const struct mdiobb_ops mdio_gpio_ops = {
116109

117110
static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
118111
struct mdio_gpio_info *bitbang,
119-
struct mdio_gpio_platform_data *pdata,
120112
int bus_id)
121113
{
122114
struct mii_bus *new_bus;
123115

124116
bitbang->ctrl.ops = &mdio_gpio_ops;
125-
bitbang->mdc = pdata->mdc;
126-
bitbang->mdio = pdata->mdio;
127-
bitbang->mdo = pdata->mdo;
128117

129118
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
130119
if (!new_bus)
@@ -160,7 +149,6 @@ static void mdio_gpio_bus_destroy(struct device *dev)
160149

161150
static int mdio_gpio_probe(struct platform_device *pdev)
162151
{
163-
struct mdio_gpio_platform_data *pdata;
164152
struct mdio_gpio_info *bitbang;
165153
struct mii_bus *new_bus;
166154
int ret, bus_id;
@@ -169,22 +157,21 @@ static int mdio_gpio_probe(struct platform_device *pdev)
169157
if (!bitbang)
170158
return -ENOMEM;
171159

160+
ret = mdio_gpio_get_data(&pdev->dev, bitbang);
161+
if (ret)
162+
return ret;
163+
172164
if (pdev->dev.of_node) {
173-
pdata = mdio_gpio_of_get_data(&pdev->dev);
174165
bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio");
175166
if (bus_id < 0) {
176167
dev_warn(&pdev->dev, "failed to get alias id\n");
177168
bus_id = 0;
178169
}
179170
} else {
180-
pdata = dev_get_platdata(&pdev->dev);
181171
bus_id = pdev->id;
182172
}
183173

184-
if (!pdata)
185-
return -ENODEV;
186-
187-
new_bus = mdio_gpio_bus_init(&pdev->dev, bitbang, pdata, bus_id);
174+
new_bus = mdio_gpio_bus_init(&pdev->dev, bitbang, bus_id);
188175
if (!new_bus)
189176
return -ENODEV;
190177

0 commit comments

Comments
 (0)