Signed-off-by: Rafał Miłecki <[email protected]>
---
 .../generic/files/drivers/net/phy/b53/b53_common.c | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c 
b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c
index 859d8d1..42a1679 100644
--- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c
+++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/switch.h>
 #include <linux/platform_data/b53.h>
+#include <uapi/linux/mii.h>
 
 #include "b53_regs.h"
 #include "b53_priv.h"
@@ -794,6 +795,42 @@ static int b53_port_get_link(struct switch_dev *dev, int 
port,
 
 }
 
+static int b53_port_set_link(struct switch_dev *dev, int port,
+                            struct switch_port_link *link)
+{
+       struct b53_device *priv = sw_to_b53(dev);
+
+       if (!priv->ops->phy_write16)
+               return -ENOTSUPP;
+
+       if (link->aneg) {
+               b53_phy_write16(priv, port, MII_BMCR, 0x0000);
+               b53_phy_write16(priv, 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;
+               }
+
+               b53_phy_write16(priv, port, MII_BMCR, bmcr);
+       }
+
+       return 0;
+}
+
 static int b53_global_reset_switch(struct switch_dev *dev)
 {
        struct b53_device *priv = sw_to_b53(dev);
@@ -1002,6 +1039,7 @@ static const struct switch_dev_ops b53_switch_ops_25 = {
        .apply_config = b53_global_apply_config,
        .reset_switch = b53_global_reset_switch,
        .get_port_link = b53_port_get_link,
+       .set_port_link = b53_port_set_link,
 };
 
 static const struct switch_dev_ops b53_switch_ops_65 = {
@@ -1025,6 +1063,7 @@ static const struct switch_dev_ops b53_switch_ops_65 = {
        .apply_config = b53_global_apply_config,
        .reset_switch = b53_global_reset_switch,
        .get_port_link = b53_port_get_link,
+       .set_port_link = b53_port_set_link,
 };
 
 static const struct switch_dev_ops b53_switch_ops = {
@@ -1048,6 +1087,7 @@ static const struct switch_dev_ops b53_switch_ops = {
        .apply_config = b53_global_apply_config,
        .reset_switch = b53_global_reset_switch,
        .get_port_link = b53_port_get_link,
+       .set_port_link = b53_port_set_link,
 };
 
 struct b53_chip_data {
-- 
1.8.4.5
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to