developer | 382dc9c | 2022-10-13 09:34:36 +0800 | [diff] [blame] | 1 | Index: linux-5.4.215/drivers/net/dsa/mt7530.c |
| 2 | =================================================================== |
| 3 | --- linux-5.4.215.orig/drivers/net/dsa/mt7530.c |
| 4 | +++ linux-5.4.215/drivers/net/dsa/mt7530.c |
| 5 | @@ -847,6 +847,117 @@ mt7531_ind_phy_write(struct dsa_switch * |
| 6 | return ret; |
| 7 | } |
| 8 | |
| 9 | +static int mt753x_mdio_read(struct mii_bus *bus, int addr, int regnum) |
| 10 | +{ |
| 11 | + struct mt7530_priv *priv = bus->priv; |
| 12 | + struct mt7530_dummy_poll p; |
| 13 | + int ret; |
| 14 | + u32 val; |
| 15 | + |
| 16 | + INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); |
| 17 | + |
| 18 | + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); |
| 19 | + |
| 20 | + ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val, |
| 21 | + !(val & MT7531_PHY_ACS_ST), 20, 100000); |
| 22 | + if (ret < 0) { |
| 23 | + dev_err(priv->dev, "poll timeout\n"); |
| 24 | + goto out; |
| 25 | + } |
| 26 | + |
| 27 | + val = MT7531_MDIO_CL22_READ | MT7531_MDIO_PHY_ADDR(addr) | |
| 28 | + MT7531_MDIO_REG_ADDR(regnum); |
| 29 | + |
| 30 | + mt7530_mii_write(priv, MT7531_PHY_IAC, val | MT7531_PHY_ACS_ST); |
| 31 | + |
| 32 | + ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val, |
| 33 | + !(val & MT7531_PHY_ACS_ST), 20, 100000); |
| 34 | + if (ret < 0) { |
| 35 | + dev_err(priv->dev, "poll timeout\n"); |
| 36 | + goto out; |
| 37 | + } |
| 38 | + |
| 39 | + ret = val & MT7531_MDIO_RW_DATA_MASK; |
| 40 | +out: |
| 41 | + mutex_unlock(&priv->bus->mdio_lock); |
| 42 | + |
| 43 | + return ret; |
| 44 | +} |
| 45 | + |
| 46 | +static int mt753x_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val) |
| 47 | +{ |
| 48 | + struct mt7530_priv *priv = bus->priv; |
| 49 | + struct mt7530_dummy_poll p; |
| 50 | + int ret; |
| 51 | + u32 reg; |
| 52 | + |
| 53 | + INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); |
| 54 | + |
| 55 | + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); |
| 56 | + |
| 57 | + ret = readx_poll_timeout(_mt7530_unlocked_read, &p, reg, |
| 58 | + !(reg & MT7531_PHY_ACS_ST), 20, 100000); |
| 59 | + if (ret < 0) { |
| 60 | + dev_err(priv->dev, "poll timeout\n"); |
| 61 | + goto out; |
| 62 | + } |
| 63 | + |
| 64 | + reg = MT7531_MDIO_CL22_WRITE | MT7531_MDIO_PHY_ADDR(addr) | |
| 65 | + MT7531_MDIO_REG_ADDR(regnum) | val; |
| 66 | + |
| 67 | + mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST); |
| 68 | + |
| 69 | + ret = readx_poll_timeout(_mt7530_unlocked_read, &p, reg, |
| 70 | + !(reg & MT7531_PHY_ACS_ST), 20, 100000); |
| 71 | + if (ret < 0) { |
| 72 | + dev_err(priv->dev, "poll timeout\n"); |
| 73 | + goto out; |
| 74 | + } |
| 75 | + |
| 76 | +out: |
| 77 | + mutex_unlock(&priv->bus->mdio_lock); |
| 78 | + |
| 79 | + return ret; |
| 80 | +} |
| 81 | + |
| 82 | +static int mt753x_setup_mdio(struct dsa_switch *ds) |
| 83 | +{ |
| 84 | + struct mt7530_priv *priv = ds->priv; |
| 85 | + struct device_node *mdio_np; |
| 86 | + int ret; |
| 87 | + |
| 88 | + mdio_np = of_get_compatible_child(priv->dev->of_node, "mediatek,dsa-slave-mdio"); |
| 89 | + if (!mdio_np) { |
| 90 | + dev_err(priv->dev, "no MDIO bus node\n"); |
| 91 | + return -ENODEV; |
| 92 | + } |
| 93 | + |
| 94 | + priv->ds->slave_mii_bus = devm_mdiobus_alloc(priv->dev); |
| 95 | + if (!priv->ds->slave_mii_bus) { |
| 96 | + ret = -ENOMEM; |
| 97 | + goto err_put_node; |
| 98 | + } |
| 99 | + priv->ds->slave_mii_bus->name = "mediatek,dsa-slave-mdio"; |
| 100 | + priv->ds->slave_mii_bus->priv = priv; |
| 101 | + priv->ds->slave_mii_bus->parent = priv->dev; |
| 102 | + priv->ds->slave_mii_bus->phy_mask = ~priv->ds->phys_mii_mask; |
| 103 | + priv->ds->slave_mii_bus->read = mt753x_mdio_read; |
| 104 | + priv->ds->slave_mii_bus->write = mt753x_mdio_write; |
| 105 | + snprintf(priv->ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d", |
| 106 | + priv->ds->dst->index, priv->ds->index); |
| 107 | + priv->ds->slave_mii_bus->dev.of_node = mdio_np; |
| 108 | + |
| 109 | + ret = of_mdiobus_register(priv->ds->slave_mii_bus, mdio_np); |
| 110 | + if (ret) |
| 111 | + dev_err(priv->dev, "unable to register MDIO bus %s\n", |
| 112 | + priv->ds->slave_mii_bus->id); |
| 113 | + |
| 114 | +err_put_node: |
| 115 | + of_node_put(mdio_np); |
| 116 | + |
| 117 | + return ret; |
| 118 | +} |
| 119 | + |
| 120 | static void |
| 121 | mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset, |
| 122 | uint8_t *data) |
| 123 | @@ -2694,6 +2805,10 @@ mt7988_setup(struct dsa_switch *ds) |
| 124 | if (ret < 0) |
| 125 | return ret; |
| 126 | |
| 127 | + ret = mt753x_setup_mdio(ds); |
| 128 | + if (ret < 0) |
| 129 | + dev_err(priv->dev, "mt753x_setup_mdio failed\n"); |
| 130 | + |
| 131 | return 0; |
| 132 | } |
| 133 | |