Author: rmilecki
Date: 2016-02-03 10:33:38 +0100 (Wed, 03 Feb 2016)
New Revision: 48621

Modified:
   trunk/target/linux/generic/files/drivers/net/phy/swconfig.c
   trunk/target/linux/generic/files/include/linux/switch.h
Log:
swconfig: add (PHY) generic helper setting port link

It's quite common for switches to have PHY per port so adding a generic
helper setting link state will help many drivers. It just needs an API
to access PHYs which this patch also adds.

Signed-off-by: Rafa?\197?\130 Mi?\197?\130ecki <[email protected]>

Modified: trunk/target/linux/generic/files/drivers/net/phy/swconfig.c
===================================================================
--- trunk/target/linux/generic/files/drivers/net/phy/swconfig.c 2016-02-03 
01:24:42 UTC (rev 48620)
+++ trunk/target/linux/generic/files/drivers/net/phy/swconfig.c 2016-02-03 
09:33:38 UTC (rev 48621)
@@ -25,6 +25,7 @@
 #include <linux/switch.h>
 #include <linux/of.h>
 #include <linux/version.h>
+#include <uapi/linux/mii.h>
 
 #define SWCONFIG_DEVNAME       "switch%d"
 
@@ -1168,7 +1169,42 @@
 }
 EXPORT_SYMBOL_GPL(unregister_switch);
 
+int
+switch_generic_set_link(struct switch_dev *dev, int port,
+                       struct switch_port_link *link)
+{
+       if (WARN_ON(!dev->ops->phy_write16))
+               return -ENOTSUPP;
 
+       /* Generic implementation */
+       if (link->aneg) {
+               dev->ops->phy_write16(dev, port, MII_BMCR, 0x0000);
+               dev->ops->phy_write16(dev, port, MII_BMCR, BMCR_ANENABLE | 
BMCR_ANRESTART);
+       } else {
+               u16 bmcr = 0;
+
+               if (link->duplex)
+                       bmcr |= BMCR_FULLDPLX;
+
+               switch (link->speed) {
+               case SWITCH_PORT_SPEED_10:
+                       break;
+               case SWITCH_PORT_SPEED_100:
+                       bmcr |= BMCR_SPEED100;
+                       break;
+               case SWITCH_PORT_SPEED_1000:
+                       bmcr |= BMCR_SPEED1000;
+                       break;
+               default:
+                       return -ENOTSUPP;
+               }
+
+               dev->ops->phy_write16(dev, port, MII_BMCR, bmcr);
+       }
+
+       return 0;
+}
+
 static int __init
 swconfig_init(void)
 {

Modified: trunk/target/linux/generic/files/include/linux/switch.h
===================================================================
--- trunk/target/linux/generic/files/include/linux/switch.h     2016-02-03 
01:24:42 UTC (rev 48620)
+++ trunk/target/linux/generic/files/include/linux/switch.h     2016-02-03 
09:33:38 UTC (rev 48621)
@@ -99,6 +99,9 @@
                             struct switch_port_link *link);
        int (*get_port_stats)(struct switch_dev *dev, int port,
                              struct switch_port_stats *stats);
+
+       int (*phy_read16)(struct switch_dev *dev, int addr, u8 reg, u16 *value);
+       int (*phy_write16)(struct switch_dev *dev, int addr, u8 reg, u16 value);
 };
 
 struct switch_dev {
@@ -170,4 +173,7 @@
        int max;
 };
 
+int switch_generic_set_link(struct switch_dev *dev, int port,
+                           struct switch_port_link *link);
+
 #endif /* _LINUX_SWITCH_H */
_______________________________________________
openwrt-commits mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-commits

Reply via email to