ar71xx: build ALFA AP96 images with default profile as well
[oweals/openwrt.git] / target / linux / ar71xx / files / drivers / net / ag71xx / ag71xx_phy.c
index 9c76544aff6734fe5e011492f6e17557ca4b8d8f..b10dd4917df22b79b76c520c3cacd18c30d141df 100644 (file)
@@ -44,8 +44,12 @@ static void ag71xx_phy_link_adjust(struct net_device *dev)
 
 void ag71xx_phy_start(struct ag71xx *ag)
 {
+       struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
+
        if (ag->phy_dev) {
                phy_start(ag->phy_dev);
+       } else if (pdata->switch_data) {
+               ag71xx_ar7240_start(ag);
        } else {
                ag->link = 1;
                ag71xx_link_adjust(ag);
@@ -54,12 +58,20 @@ void ag71xx_phy_start(struct ag71xx *ag)
 
 void ag71xx_phy_stop(struct ag71xx *ag)
 {
-       if (ag->phy_dev) {
+       struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
+       unsigned long flags;
+
+       if (ag->phy_dev)
                phy_stop(ag->phy_dev);
-       } else {
+       else if (pdata->switch_data)
+               ag71xx_ar7240_stop(ag);
+
+       spin_lock_irqsave(&ag->lock, flags);
+       if (ag->link) {
                ag->link = 0;
                ag71xx_link_adjust(ag);
        }
+       spin_unlock_irqrestore(&ag->lock, flags);
 }
 
 static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
@@ -182,10 +194,14 @@ static struct mii_bus *dev_to_mii_bus(struct device *dev)
        return NULL;
 }
 
-int ag71xx_phy_connect(struct ag71xx *ag)
+int __devinit ag71xx_phy_connect(struct ag71xx *ag)
 {
        struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
 
+       if (pdata->mii_bus_dev == NULL ||
+           pdata->mii_bus_dev->bus == NULL )
+               return ag71xx_phy_connect_fixed(ag);
+
        ag->mii_bus = dev_to_mii_bus(pdata->mii_bus_dev);
        if (ag->mii_bus == NULL) {
                printk(KERN_ERR "%s: unable to find MII bus on device '%s'\n",
@@ -200,6 +216,9 @@ int ag71xx_phy_connect(struct ag71xx *ag)
                mutex_unlock(&ag->mii_bus->mdio_lock);
        }
 
+       if (pdata->switch_data)
+               return ag71xx_ar7240_init(ag);
+
        if (pdata->phy_mask)
                return ag71xx_phy_connect_multi(ag);
 
@@ -208,6 +227,10 @@ int ag71xx_phy_connect(struct ag71xx *ag)
 
 void ag71xx_phy_disconnect(struct ag71xx *ag)
 {
-       if (ag->phy_dev)
+       struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
+
+       if (pdata->switch_data)
+               ag71xx_ar7240_cleanup(ag);
+       else if (ag->phy_dev)
                phy_disconnect(ag->phy_dev);
 }