Skip to content

Commit 4d6a78b

Browse files
hjelmelanddavem330
authored andcommitted
net: dsa: lan9303: Add adjust_link() method
Make the driver react to device tree "fixed-link" declaration on CPU port. - turn off autonegotiation - force speed 10 or 100 mb/s - force duplex mode Signed-off-by: Egil Hjelmeland <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 00ba4cb commit 4d6a78b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

drivers/net/dsa/lan9303-core.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/regmap.h>
1818
#include <linux/mutex.h>
1919
#include <linux/mii.h>
20+
#include <linux/phy.h>
2021

2122
#include "lan9303.h"
2223

@@ -57,6 +58,7 @@
5758
#define LAN9303_SWITCH_CSR_CMD_LANES (BIT(19) | BIT(18) | BIT(17) | BIT(16))
5859
#define LAN9303_VIRT_PHY_BASE 0x70
5960
#define LAN9303_VIRT_SPECIAL_CTRL 0x77
61+
#define LAN9303_VIRT_SPECIAL_TURBO BIT(10) /*Turbo MII Enable*/
6062

6163
/*13.4 Switch Fabric Control and Status Registers
6264
* Accessed indirectly via SWITCH_CSR_CMD, SWITCH_CSR_DATA.
@@ -760,6 +762,43 @@ static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum,
760762
return chip->ops->phy_write(chip, phy, regnum, val);
761763
}
762764

765+
static void lan9303_adjust_link(struct dsa_switch *ds, int port,
766+
struct phy_device *phydev)
767+
{
768+
struct lan9303 *chip = ds->priv;
769+
int ctl, res;
770+
771+
if (!phy_is_pseudo_fixed_link(phydev))
772+
return;
773+
774+
ctl = lan9303_phy_read(ds, port, MII_BMCR);
775+
776+
ctl &= ~BMCR_ANENABLE;
777+
778+
if (phydev->speed == SPEED_100)
779+
ctl |= BMCR_SPEED100;
780+
else if (phydev->speed == SPEED_10)
781+
ctl &= ~BMCR_SPEED100;
782+
else
783+
dev_err(ds->dev, "unsupported speed: %d\n", phydev->speed);
784+
785+
if (phydev->duplex == DUPLEX_FULL)
786+
ctl |= BMCR_FULLDPLX;
787+
else
788+
ctl &= ~BMCR_FULLDPLX;
789+
790+
res = lan9303_phy_write(ds, port, MII_BMCR, ctl);
791+
792+
if (port == chip->phy_addr_sel_strap) {
793+
/* Virtual Phy: Remove Turbo 200Mbit mode */
794+
lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, &ctl);
795+
796+
ctl &= ~LAN9303_VIRT_SPECIAL_TURBO;
797+
res = regmap_write(chip->regmap,
798+
LAN9303_VIRT_SPECIAL_CTRL, ctl);
799+
}
800+
}
801+
763802
static int lan9303_port_enable(struct dsa_switch *ds, int port,
764803
struct phy_device *phy)
765804
{
@@ -803,6 +842,7 @@ static const struct dsa_switch_ops lan9303_switch_ops = {
803842
.get_strings = lan9303_get_strings,
804843
.phy_read = lan9303_phy_read,
805844
.phy_write = lan9303_phy_write,
845+
.adjust_link = lan9303_adjust_link,
806846
.get_ethtool_stats = lan9303_get_ethtool_stats,
807847
.get_sset_count = lan9303_get_sset_count,
808848
.port_enable = lan9303_port_enable,

0 commit comments

Comments
 (0)