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

net: mvmdio: allow platform device style registration

This patch changes the mvmdio driver not to use device tree
helper functions such as of_mdiobus_register() and of_iomap() so we can
instantiate this driver using a classic platform_device approach. Use
the device manager helper to ioremap() the base register cookie so we
get automatic freeing upon error and removal. This change is harmless
for Device Tree platforms because they will get the driver be registered
the same way as it was before.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Florian Fainelli and committed by
David S. Miller
7111b717 43d68690

+15 -7
+15 -7
drivers/net/ethernet/marvell/mvmdio.c
··· 24 24 #include <linux/module.h> 25 25 #include <linux/mutex.h> 26 26 #include <linux/phy.h> 27 - #include <linux/of_address.h> 28 - #include <linux/of_mdio.h> 29 27 #include <linux/platform_device.h> 30 28 #include <linux/delay.h> 29 + #include <linux/io.h> 30 + #include <linux/of_mdio.h> 31 31 32 32 #define MVMDIO_SMI_DATA_SHIFT 0 33 33 #define MVMDIO_SMI_PHY_ADDR_SHIFT 16 ··· 143 143 144 144 static int orion_mdio_probe(struct platform_device *pdev) 145 145 { 146 - struct device_node *np = pdev->dev.of_node; 146 + struct resource *r; 147 147 struct mii_bus *bus; 148 148 struct orion_mdio_dev *dev; 149 149 int i, ret; 150 + 151 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 152 + if (!r) { 153 + dev_err(&pdev->dev, "No SMI register address given\n"); 154 + return -ENODEV; 155 + } 150 156 151 157 bus = mdiobus_alloc_size(sizeof(struct orion_mdio_dev)); 152 158 if (!bus) { ··· 178 172 bus->irq[i] = PHY_POLL; 179 173 180 174 dev = bus->priv; 181 - dev->smireg = of_iomap(pdev->dev.of_node, 0); 175 + dev->smireg = devm_ioremap(&pdev->dev, r->start, resource_size(r)); 182 176 if (!dev->smireg) { 183 - dev_err(&pdev->dev, "No SMI register address given in DT\n"); 177 + dev_err(&pdev->dev, "Unable to remap SMI register\n"); 184 178 kfree(bus->irq); 185 179 mdiobus_free(bus); 186 180 return -ENODEV; ··· 188 182 189 183 mutex_init(&dev->lock); 190 184 191 - ret = of_mdiobus_register(bus, np); 185 + if (pdev->dev.of_node) 186 + ret = of_mdiobus_register(bus, pdev->dev.of_node); 187 + else 188 + ret = mdiobus_register(bus); 192 189 if (ret < 0) { 193 190 dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret); 194 - iounmap(dev->smireg); 195 191 kfree(bus->irq); 196 192 mdiobus_free(bus); 197 193 return ret;