aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/files/drivers/net/phy
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2016-02-03 09:33:38 +0000
committerRafał Miłecki <zajec5@gmail.com>2016-02-03 09:33:38 +0000
commit8fa705f8cca0da5c1c9051c5c013747603a3fa5e (patch)
tree42e8c98ea41e9279da12f1937941487a6153f235 /target/linux/generic/files/drivers/net/phy
parent68405d3034aaaf55e263d355ae2184f01380b4ed (diff)
downloadmaster-187ad058-8fa705f8cca0da5c1c9051c5c013747603a3fa5e.tar.gz
master-187ad058-8fa705f8cca0da5c1c9051c5c013747603a3fa5e.tar.bz2
master-187ad058-8fa705f8cca0da5c1c9051c5c013747603a3fa5e.zip
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ł Miłecki <zajec5@gmail.com> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@48621 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/generic/files/drivers/net/phy')
-rw-r--r--target/linux/generic/files/drivers/net/phy/swconfig.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c
index 4bfe64fbd0..68ddd246ad 100644
--- a/target/linux/generic/files/drivers/net/phy/swconfig.c
+++ b/target/linux/generic/files/drivers/net/phy/swconfig.c
@@ -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,6 +1169,41 @@ unregister_switch(struct switch_dev *dev)
}
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)