Skip to content

Commit e92bdf4

Browse files
Srinivas-Kandagatladavem330
authored andcommitted
of/mdio-gpio: Simplify the way device tree support is implemented.
This patch cleans up the way device tree support is added in mdio-gpio driver. I found lot of code duplication which is not necessary. Also strangely a new platform driver was also introduced for device tree support. All this forced me to do this cleanup patch. After this patch, the driver probe checks the of_node pointer to get the data from device tree. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f9dc9ac commit e92bdf4

1 file changed

Lines changed: 40 additions & 92 deletions

File tree

‎drivers/net/phy/mdio-gpio.c‎

Lines changed: 40 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,38 @@
2828
#include <linux/gpio.h>
2929
#include <linux/mdio-gpio.h>
3030

31-
#ifdef CONFIG_OF_GPIO
3231
#include <linux/of_gpio.h>
3332
#include <linux/of_mdio.h>
34-
#include <linux/of_platform.h>
35-
#endif
3633

3734
struct mdio_gpio_info {
3835
struct mdiobb_ctrl ctrl;
3936
int mdc, mdio;
4037
};
4138

39+
static void *mdio_gpio_of_get_data(struct platform_device *pdev)
40+
{
41+
struct device_node *np = pdev->dev.of_node;
42+
struct mdio_gpio_platform_data *pdata;
43+
int ret;
44+
45+
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
46+
if (!pdata)
47+
return NULL;
48+
49+
ret = of_get_gpio(np, 0);
50+
if (ret < 0)
51+
return NULL;
52+
53+
pdata->mdc = ret;
54+
55+
ret = of_get_gpio(np, 1);
56+
if (ret < 0)
57+
return NULL;
58+
pdata->mdio = ret;
59+
60+
return pdata;
61+
}
62+
4263
static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
4364
{
4465
struct mdio_gpio_info *bitbang =
@@ -162,18 +183,27 @@ static void __devexit mdio_gpio_bus_destroy(struct device *dev)
162183

163184
static int __devinit mdio_gpio_probe(struct platform_device *pdev)
164185
{
165-
struct mdio_gpio_platform_data *pdata = pdev->dev.platform_data;
186+
struct mdio_gpio_platform_data *pdata;
166187
struct mii_bus *new_bus;
167188
int ret;
168189

190+
if (pdev->dev.of_node)
191+
pdata = mdio_gpio_of_get_data(pdev);
192+
else
193+
pdata = pdev->dev.platform_data;
194+
169195
if (!pdata)
170196
return -ENODEV;
171197

172198
new_bus = mdio_gpio_bus_init(&pdev->dev, pdata, pdev->id);
173199
if (!new_bus)
174200
return -ENODEV;
175201

176-
ret = mdiobus_register(new_bus);
202+
if (pdev->dev.of_node)
203+
ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
204+
else
205+
ret = mdiobus_register(new_bus);
206+
177207
if (ret)
178208
mdio_gpio_bus_deinit(&pdev->dev);
179209

@@ -187,112 +217,30 @@ static int __devexit mdio_gpio_remove(struct platform_device *pdev)
187217
return 0;
188218
}
189219

190-
#ifdef CONFIG_OF_GPIO
191-
192-
static int __devinit mdio_ofgpio_probe(struct platform_device *ofdev)
193-
{
194-
struct mdio_gpio_platform_data *pdata;
195-
struct mii_bus *new_bus;
196-
int ret;
197-
198-
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
199-
if (!pdata)
200-
return -ENOMEM;
201-
202-
ret = of_get_gpio(ofdev->dev.of_node, 0);
203-
if (ret < 0)
204-
goto out_free;
205-
pdata->mdc = ret;
206-
207-
ret = of_get_gpio(ofdev->dev.of_node, 1);
208-
if (ret < 0)
209-
goto out_free;
210-
pdata->mdio = ret;
211-
212-
new_bus = mdio_gpio_bus_init(&ofdev->dev, pdata, pdata->mdc);
213-
if (!new_bus)
214-
goto out_free;
215-
216-
ret = of_mdiobus_register(new_bus, ofdev->dev.of_node);
217-
if (ret)
218-
mdio_gpio_bus_deinit(&ofdev->dev);
219-
220-
return ret;
221-
222-
out_free:
223-
kfree(pdata);
224-
return -ENODEV;
225-
}
226-
227-
static int __devexit mdio_ofgpio_remove(struct platform_device *ofdev)
228-
{
229-
mdio_gpio_bus_destroy(&ofdev->dev);
230-
kfree(ofdev->dev.platform_data);
231-
232-
return 0;
233-
}
234-
235-
static struct of_device_id mdio_ofgpio_match[] = {
236-
{
237-
.compatible = "virtual,mdio-gpio",
238-
},
239-
{},
240-
};
241-
MODULE_DEVICE_TABLE(of, mdio_ofgpio_match);
242-
243-
static struct platform_driver mdio_ofgpio_driver = {
244-
.driver = {
245-
.name = "mdio-ofgpio",
246-
.owner = THIS_MODULE,
247-
.of_match_table = mdio_ofgpio_match,
248-
},
249-
.probe = mdio_ofgpio_probe,
250-
.remove = __devexit_p(mdio_ofgpio_remove),
220+
static struct of_device_id mdio_gpio_of_match[] = {
221+
{ .compatible = "virtual,mdio-gpio", },
222+
{ /* sentinel */ }
251223
};
252224

253-
static inline int __init mdio_ofgpio_init(void)
254-
{
255-
return platform_driver_register(&mdio_ofgpio_driver);
256-
}
257-
258-
static inline void mdio_ofgpio_exit(void)
259-
{
260-
platform_driver_unregister(&mdio_ofgpio_driver);
261-
}
262-
#else
263-
static inline int __init mdio_ofgpio_init(void) { return 0; }
264-
static inline void mdio_ofgpio_exit(void) { }
265-
#endif /* CONFIG_OF_GPIO */
266-
267225
static struct platform_driver mdio_gpio_driver = {
268226
.probe = mdio_gpio_probe,
269227
.remove = __devexit_p(mdio_gpio_remove),
270228
.driver = {
271229
.name = "mdio-gpio",
272230
.owner = THIS_MODULE,
231+
.of_match_table = mdio_gpio_of_match,
273232
},
274233
};
275234

276235
static int __init mdio_gpio_init(void)
277236
{
278-
int ret;
279-
280-
ret = mdio_ofgpio_init();
281-
if (ret)
282-
return ret;
283-
284-
ret = platform_driver_register(&mdio_gpio_driver);
285-
if (ret)
286-
mdio_ofgpio_exit();
287-
288-
return ret;
237+
return platform_driver_register(&mdio_gpio_driver);
289238
}
290239
module_init(mdio_gpio_init);
291240

292241
static void __exit mdio_gpio_exit(void)
293242
{
294243
platform_driver_unregister(&mdio_gpio_driver);
295-
mdio_ofgpio_exit();
296244
}
297245
module_exit(mdio_gpio_exit);
298246

0 commit comments

Comments
 (0)