Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Srinivas Kandagatla and committed by
David S. Miller
e92bdf4b f9dc9ac5

+40 -92
+40 -92
drivers/net/phy/mdio-gpio.c
··· 28 28 #include <linux/gpio.h> 29 29 #include <linux/mdio-gpio.h> 30 30 31 - #ifdef CONFIG_OF_GPIO 32 31 #include <linux/of_gpio.h> 33 32 #include <linux/of_mdio.h> 34 - #include <linux/of_platform.h> 35 - #endif 36 33 37 34 struct mdio_gpio_info { 38 35 struct mdiobb_ctrl ctrl; 39 36 int mdc, mdio; 40 37 }; 38 + 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 + } 41 62 42 63 static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir) 43 64 { ··· 183 162 184 163 static int __devinit mdio_gpio_probe(struct platform_device *pdev) 185 164 { 186 - struct mdio_gpio_platform_data *pdata = pdev->dev.platform_data; 165 + struct mdio_gpio_platform_data *pdata; 187 166 struct mii_bus *new_bus; 188 167 int ret; 168 + 169 + if (pdev->dev.of_node) 170 + pdata = mdio_gpio_of_get_data(pdev); 171 + else 172 + pdata = pdev->dev.platform_data; 189 173 190 174 if (!pdata) 191 175 return -ENODEV; ··· 199 173 if (!new_bus) 200 174 return -ENODEV; 201 175 202 - ret = mdiobus_register(new_bus); 176 + if (pdev->dev.of_node) 177 + ret = of_mdiobus_register(new_bus, pdev->dev.of_node); 178 + else 179 + ret = mdiobus_register(new_bus); 180 + 203 181 if (ret) 204 182 mdio_gpio_bus_deinit(&pdev->dev); 205 183 ··· 217 187 return 0; 218 188 } 219 189 220 - #ifdef CONFIG_OF_GPIO 221 - 222 - static int __devinit mdio_ofgpio_probe(struct platform_device *ofdev) 223 - { 224 - struct mdio_gpio_platform_data *pdata; 225 - struct mii_bus *new_bus; 226 - int ret; 227 - 228 - pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 229 - if (!pdata) 230 - return -ENOMEM; 231 - 232 - ret = of_get_gpio(ofdev->dev.of_node, 0); 233 - if (ret < 0) 234 - goto out_free; 235 - pdata->mdc = ret; 236 - 237 - ret = of_get_gpio(ofdev->dev.of_node, 1); 238 - if (ret < 0) 239 - goto out_free; 240 - pdata->mdio = ret; 241 - 242 - new_bus = mdio_gpio_bus_init(&ofdev->dev, pdata, pdata->mdc); 243 - if (!new_bus) 244 - goto out_free; 245 - 246 - ret = of_mdiobus_register(new_bus, ofdev->dev.of_node); 247 - if (ret) 248 - mdio_gpio_bus_deinit(&ofdev->dev); 249 - 250 - return ret; 251 - 252 - out_free: 253 - kfree(pdata); 254 - return -ENODEV; 255 - } 256 - 257 - static int __devexit mdio_ofgpio_remove(struct platform_device *ofdev) 258 - { 259 - mdio_gpio_bus_destroy(&ofdev->dev); 260 - kfree(ofdev->dev.platform_data); 261 - 262 - return 0; 263 - } 264 - 265 - static struct of_device_id mdio_ofgpio_match[] = { 266 - { 267 - .compatible = "virtual,mdio-gpio", 268 - }, 269 - {}, 190 + static struct of_device_id mdio_gpio_of_match[] = { 191 + { .compatible = "virtual,mdio-gpio", }, 192 + { /* sentinel */ } 270 193 }; 271 - MODULE_DEVICE_TABLE(of, mdio_ofgpio_match); 272 - 273 - static struct platform_driver mdio_ofgpio_driver = { 274 - .driver = { 275 - .name = "mdio-ofgpio", 276 - .owner = THIS_MODULE, 277 - .of_match_table = mdio_ofgpio_match, 278 - }, 279 - .probe = mdio_ofgpio_probe, 280 - .remove = __devexit_p(mdio_ofgpio_remove), 281 - }; 282 - 283 - static inline int __init mdio_ofgpio_init(void) 284 - { 285 - return platform_driver_register(&mdio_ofgpio_driver); 286 - } 287 - 288 - static inline void mdio_ofgpio_exit(void) 289 - { 290 - platform_driver_unregister(&mdio_ofgpio_driver); 291 - } 292 - #else 293 - static inline int __init mdio_ofgpio_init(void) { return 0; } 294 - static inline void mdio_ofgpio_exit(void) { } 295 - #endif /* CONFIG_OF_GPIO */ 296 194 297 195 static struct platform_driver mdio_gpio_driver = { 298 196 .probe = mdio_gpio_probe, ··· 228 270 .driver = { 229 271 .name = "mdio-gpio", 230 272 .owner = THIS_MODULE, 273 + .of_match_table = mdio_gpio_of_match, 231 274 }, 232 275 }; 233 276 234 277 static int __init mdio_gpio_init(void) 235 278 { 236 - int ret; 237 - 238 - ret = mdio_ofgpio_init(); 239 - if (ret) 240 - return ret; 241 - 242 - ret = platform_driver_register(&mdio_gpio_driver); 243 - if (ret) 244 - mdio_ofgpio_exit(); 245 - 246 - return ret; 279 + return platform_driver_register(&mdio_gpio_driver); 247 280 } 248 281 module_init(mdio_gpio_init); 249 282 250 283 static void __exit mdio_gpio_exit(void) 251 284 { 252 285 platform_driver_unregister(&mdio_gpio_driver); 253 - mdio_ofgpio_exit(); 254 286 } 255 287 module_exit(mdio_gpio_exit); 256 288