1 From cfbd6de588ef659c198083205dc954a6d3ed2aec Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 29 Dec 2022 17:33:35 +0100
4 Subject: [PATCH 4/5] net: dsa: qca8k: introduce single mii read/write lo/hi
6 It may be useful to read/write just the lo or hi half of a reg.
8 This is especially useful for phy poll with the use of mdio master.
9 The mdio master reg is composed by the first 16 bit related to setup and
10 the other half with the returned data or data to write.
12 Refactor the mii function to permit single mii read/write of lo or hi
15 Tested-by: Ronald Wahl <ronald.wahl@raritan.com>
16 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
19 drivers/net/dsa/qca/qca8k-8xxx.c | 106 ++++++++++++++++++++++++-------
20 1 file changed, 84 insertions(+), 22 deletions(-)
22 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
23 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
24 @@ -37,42 +37,104 @@ qca8k_split_addr(u32 regaddr, u16 *r1, u
28 -qca8k_mii_read32(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val)
29 +qca8k_mii_write_lo(struct mii_bus *bus, int phy_id, u32 regnum, u32 val)
34 - ret = bus->read(bus, phy_id, regnum);
37 - ret = bus->read(bus, phy_id, regnum + 1);
41 + ret = bus->write(bus, phy_id, regnum, lo);
43 + dev_err_ratelimited(&bus->dev,
44 + "failed to write qca8k 32bit lo register\n");
51 +qca8k_mii_write_hi(struct mii_bus *bus, int phy_id, u32 regnum, u32 val)
56 + hi = (u16)(val >> 16);
57 + ret = bus->write(bus, phy_id, regnum, hi);
59 dev_err_ratelimited(&bus->dev,
60 - "failed to read qca8k 32bit register\n");
64 + "failed to write qca8k 32bit hi register\n");
70 +qca8k_mii_read_lo(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val)
74 + ret = bus->read(bus, phy_id, regnum);
78 + *val = ret & 0xffff;
82 + dev_err_ratelimited(&bus->dev,
83 + "failed to read qca8k 32bit lo register\n");
90 -qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val)
92 +qca8k_mii_read_hi(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val)
98 - hi = (u16)(val >> 16);
99 + ret = bus->read(bus, phy_id, regnum);
103 - ret = bus->write(bus, phy_id, regnum, lo);
105 - ret = bus->write(bus, phy_id, regnum + 1, hi);
110 + dev_err_ratelimited(&bus->dev,
111 + "failed to read qca8k 32bit hi register\n");
118 +qca8k_mii_read32(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val)
125 + ret = qca8k_mii_read_lo(bus, phy_id, regnum, &lo);
127 - dev_err_ratelimited(&bus->dev,
128 - "failed to write qca8k 32bit register\n");
131 + ret = qca8k_mii_read_hi(bus, phy_id, regnum + 1, &hi);
142 +qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val)
144 + if (qca8k_mii_write_lo(bus, phy_id, regnum, val) < 0)
147 + qca8k_mii_write_hi(bus, phy_id, regnum + 1, val);