|
17 | 17 | #include <linux/regmap.h>
|
18 | 18 | #include <linux/mutex.h>
|
19 | 19 | #include <linux/mii.h>
|
| 20 | +#include <linux/phy.h> |
20 | 21 |
|
21 | 22 | #include "lan9303.h"
|
22 | 23 |
|
|
57 | 58 | #define LAN9303_SWITCH_CSR_CMD_LANES (BIT(19) | BIT(18) | BIT(17) | BIT(16))
|
58 | 59 | #define LAN9303_VIRT_PHY_BASE 0x70
|
59 | 60 | #define LAN9303_VIRT_SPECIAL_CTRL 0x77
|
| 61 | +#define LAN9303_VIRT_SPECIAL_TURBO BIT(10) /*Turbo MII Enable*/ |
60 | 62 |
|
61 | 63 | /*13.4 Switch Fabric Control and Status Registers
|
62 | 64 | * 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,
|
760 | 762 | return chip->ops->phy_write(chip, phy, regnum, val);
|
761 | 763 | }
|
762 | 764 |
|
| 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 | + |
763 | 802 | static int lan9303_port_enable(struct dsa_switch *ds, int port,
|
764 | 803 | struct phy_device *phy)
|
765 | 804 | {
|
@@ -803,6 +842,7 @@ static const struct dsa_switch_ops lan9303_switch_ops = {
|
803 | 842 | .get_strings = lan9303_get_strings,
|
804 | 843 | .phy_read = lan9303_phy_read,
|
805 | 844 | .phy_write = lan9303_phy_write,
|
| 845 | + .adjust_link = lan9303_adjust_link, |
806 | 846 | .get_ethtool_stats = lan9303_get_ethtool_stats,
|
807 | 847 | .get_sset_count = lan9303_get_sset_count,
|
808 | 848 | .port_enable = lan9303_port_enable,
|
|
0 commit comments