da33aaa72f30c8569eeb87430f809e0ce47f4521
[openwrt/staging/ldir.git] /
1 From c6af53f038aa32cec12e8a305ba07c7ef168f1b0 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 4 Jan 2022 12:07:00 +0000
4 Subject: [PATCH 2/3] net: mdio: add helpers to extract clause 45 regad and
5 devad fields
6
7 Add a couple of helpers and definitions to extract the clause 45 regad
8 and devad fields from the regnum passed into MDIO drivers.
9
10 Tested-by: Daniel Golle <daniel@makrotopia.org>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16 include/linux/mdio.h | 12 ++++++++++++
17 1 file changed, 12 insertions(+)
18
19 --- a/include/linux/mdio.h
20 +++ b/include/linux/mdio.h
21 @@ -7,6 +7,7 @@
22 #define __LINUX_MDIO_H__
23
24 #include <uapi/linux/mdio.h>
25 +#include <linux/bitfield.h>
26 #include <linux/mod_devicetable.h>
27
28 /* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
29 @@ -14,6 +15,7 @@
30 */
31 #define MII_ADDR_C45 (1<<30)
32 #define MII_DEVADDR_C45_SHIFT 16
33 +#define MII_DEVADDR_C45_MASK GENMASK(20, 16)
34 #define MII_REGADDR_C45_MASK GENMASK(15, 0)
35
36 struct gpio_desc;
37 @@ -355,6 +357,16 @@ static inline u32 mdiobus_c45_addr(int d
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 {