aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2010-01-17 21:37:09 +0000
committerGabor Juhos <juhosg@openwrt.org>2010-01-17 21:37:09 +0000
commitd2229cb1cc7f0d58b976bf6bac2eedcc9eb6ed97 (patch)
treee52535e59a634024eee80669062eae02060ad315
parent088ba7e1db664ce40cd753746fc66f427ccc8977 (diff)
downloadupstream-d2229cb1cc7f0d58b976bf6bac2eedcc9eb6ed97.tar.gz
upstream-d2229cb1cc7f0d58b976bf6bac2eedcc9eb6ed97.tar.bz2
upstream-d2229cb1cc7f0d58b976bf6bac2eedcc9eb6ed97.zip
rtl8366_smi: register the switch directly from the probe routine
SVN-Revision: 19202
-rw-r--r--target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c b/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
index 0d54126cce..3b4795ba4b 100644
--- a/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
+++ b/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
@@ -1718,6 +1718,27 @@ static struct switch_dev rtldev = {
.reset_switch = rtl8366_reset_switch,
};
+static int rtl8366_smi_switch_init(struct rtl8366_smi *smi)
+{
+ struct switch_dev *dev = &smi->dev;
+ int err;
+
+ memcpy(dev, &rtldev, sizeof(struct switch_dev));
+ dev->priv = smi;
+ dev->devname = dev_name(&smi->pdev->dev);
+
+ err = register_switch(dev, NULL);
+ if (err)
+ dev_err(&smi->pdev->dev, "switch registration failed\n");
+
+ return;
+}
+
+static void rtl8366_smi_switch_cleanup(struct rtl8366_smi *smi)
+{
+ unregister_switch(&smi->dev);
+}
+
static int rtl8366_smi_mii_read(struct mii_bus *bus, int addr, int reg)
{
struct rtl8366_smi *smi = bus->priv;
@@ -1787,6 +1808,12 @@ static void rtl8366_smi_mii_cleanup(struct rtl8366_smi *smi)
mdiobus_free(smi->mii_bus);
}
+static int rtl8366_smi_mii_bus_match(struct mii_bus *bus)
+{
+ return (bus->read == rtl8366_smi_mii_read &&
+ bus->write == rtl8366_smi_mii_write);
+}
+
static int rtl8366_smi_setup(struct rtl8366_smi *smi)
{
u32 chip_id = 0;
@@ -1878,8 +1905,14 @@ static int __init rtl8366_smi_probe(struct platform_device *pdev)
if (err)
goto err_clear_drvdata;
+ err = rtl8366_smi_switch_init(smi);
+ if (err)
+ goto err_mii_cleanup;
+
return 0;
+ err_mii_cleanup:
+ rtl8366_smi_mii_cleanup(smi);
err_clear_drvdata:
platform_set_drvdata(pdev, NULL);
gpio_free(pdata->gpio_sck);
@@ -1893,26 +1926,8 @@ static int __init rtl8366_smi_probe(struct platform_device *pdev)
int rtl8366_phy_config_init(struct phy_device *phydev)
{
- int err;
- struct net_device *netdev = phydev->attached_dev;
- struct rtl8366_smi *smi = phydev->bus->priv;
- struct switch_dev *dev = &smi->dev;
-
- /* Only init the switch for the primary PHY */
- if (phydev->addr != 4) {
- printk(KERN_INFO "Discarding address: %d\n", phydev->addr);
- return 0;
- }
-
- memcpy(&smi->dev, &rtldev, sizeof(struct switch_dev));
- dev->priv = smi;
- dev->netdev = netdev;
-
- err = register_switch(dev, netdev);
- if (err < 0) {
- printk(KERN_INFO "Switch registration failed\n");
- return err;
- }
+ if (!rtl8366_smi_mii_bus_match(phydev->bus))
+ return -EINVAL;
return 0;
}
@@ -1944,8 +1959,8 @@ static int __devexit rtl8366_smi_remove(struct platform_device *pdev)
pdata = pdev->dev.platform_data;
+ rtl8366_smi_switch_cleanup(smi);
rtl8366_debugfs_remove(smi);
- phy_driver_unregister(&rtl8366_smi_phy_driver);
rtl8366_smi_mii_cleanup(smi);
platform_set_drvdata(pdev, NULL);
gpio_free(pdata->gpio_sck);