developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From abf7f24a61f01977b657285d6425b1185354a29a Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:05:59 +0800 |
| 4 | Subject: [PATCH] [backport-networking-generic][999-1600-mdiobus-add-c45.patch] |
| 5 | |
| 6 | --- |
| 7 | include/linux/mdio.h | 49 ++++++++++++++++++++++++++++++++++++++++++++ |
| 8 | 1 file changed, 49 insertions(+) |
| 9 | |
developer | 599cda4 | 2022-05-24 15:13:31 +0800 | [diff] [blame] | 10 | diff --git a/include/linux/mdio.h b/include/linux/mdio.h |
| 11 | index 0f1f784de..006d1c1e9 100644 |
| 12 | --- a/include/linux/mdio.h |
| 13 | +++ b/include/linux/mdio.h |
| 14 | @@ -7,8 +7,17 @@ |
| 15 | #define __LINUX_MDIO_H__ |
| 16 | |
| 17 | #include <uapi/linux/mdio.h> |
| 18 | +#include <linux/bitfield.h> |
| 19 | #include <linux/mod_devicetable.h> |
| 20 | |
| 21 | +/* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit |
| 22 | + * IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips. |
| 23 | + */ |
| 24 | +#define MII_ADDR_C45 (1<<30) |
| 25 | +#define MII_DEVADDR_C45_SHIFT 16 |
| 26 | +#define MII_DEVADDR_C45_MASK GENMASK(20, 16) |
| 27 | +#define MII_REGADDR_C45_MASK GENMASK(15, 0) |
| 28 | + |
| 29 | struct gpio_desc; |
| 30 | struct mii_bus; |
| 31 | |
| 32 | @@ -325,6 +334,46 @@ int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum); |
| 33 | int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); |
| 34 | int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); |
| 35 | |
| 36 | +static inline u32 mdiobus_c45_addr(int devad, u16 regnum) |
| 37 | +{ |
| 38 | + return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum; |
| 39 | +} |
| 40 | + |
| 41 | +static inline u16 mdiobus_c45_regad(u32 regnum) |
| 42 | +{ |
| 43 | + return FIELD_GET(MII_REGADDR_C45_MASK, regnum); |
| 44 | +} |
| 45 | + |
| 46 | +static inline u16 mdiobus_c45_devad(u32 regnum) |
| 47 | +{ |
| 48 | + return FIELD_GET(MII_DEVADDR_C45_MASK, regnum); |
| 49 | +} |
| 50 | + |
| 51 | +static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad, |
| 52 | + u16 regnum) |
| 53 | +{ |
| 54 | + return __mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum)); |
| 55 | +} |
| 56 | + |
| 57 | +static inline int __mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad, |
| 58 | + u16 regnum, u16 val) |
| 59 | +{ |
| 60 | + return __mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), |
| 61 | + val); |
| 62 | +} |
| 63 | + |
| 64 | +static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad, |
| 65 | + u16 regnum) |
| 66 | +{ |
| 67 | + return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum)); |
| 68 | +} |
| 69 | + |
| 70 | +static inline int mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad, |
| 71 | + u16 regnum, u16 val) |
| 72 | +{ |
| 73 | + return mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), val); |
| 74 | +} |
| 75 | + |
| 76 | int mdiobus_register_device(struct mdio_device *mdiodev); |
| 77 | int mdiobus_unregister_device(struct mdio_device *mdiodev); |
| 78 | bool mdiobus_is_registered_device(struct mii_bus *bus, int addr); |
| 79 | -- |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 80 | 2.34.1 |
developer | 599cda4 | 2022-05-24 15:13:31 +0800 | [diff] [blame] | 81 | |