* [PATCH net-next v3 1/3] net: mdio: aspeed: move reg accessing part into separate functions
2022-04-07 1:17 [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO Potin Lai
@ 2022-04-07 1:17 ` Potin Lai
2022-04-07 1:17 ` [PATCH net-next v3 2/3] net: mdio: aspeed: Introduce read write function for c22 and c45 Potin Lai
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Potin Lai @ 2022-04-07 1:17 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, davem,
Jakub Kicinski, Joel Stanley, Andrew Jeffery
Cc: netdev, linux-arm-kernel, linux-aspeed, linux-kernel,
Patrick Williams, Potin Lai
Add aspeed_mdio_op() and aseed_mdio_get_data() for register accessing.
aspeed_mdio_op() handles operations, write command to control register,
then check and wait operations is finished (bit 31 is cleared).
aseed_mdio_get_data() fetchs the result value of operation from data
register.
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/mdio/mdio-aspeed.c | 70 ++++++++++++++++++----------------
1 file changed, 38 insertions(+), 32 deletions(-)
diff --git a/drivers/net/mdio/mdio-aspeed.c b/drivers/net/mdio/mdio-aspeed.c
index e2273588c75b..f22be2f069e9 100644
--- a/drivers/net/mdio/mdio-aspeed.c
+++ b/drivers/net/mdio/mdio-aspeed.c
@@ -39,34 +39,35 @@ struct aspeed_mdio {
void __iomem *base;
};
-static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
+static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
+ u16 data)
{
struct aspeed_mdio *ctx = bus->priv;
u32 ctrl;
- u32 data;
- int rc;
- dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d\n", __func__, addr,
- regnum);
-
- /* Just clause 22 for the moment */
- if (regnum & MII_ADDR_C45)
- return -EOPNOTSUPP;
+ dev_dbg(&bus->dev, "%s: st: %u op: %u, phyad: %u, regad: %u, data: %u\n",
+ __func__, st, op, phyad, regad, data);
ctrl = ASPEED_MDIO_CTRL_FIRE
- | FIELD_PREP(ASPEED_MDIO_CTRL_ST, ASPEED_MDIO_CTRL_ST_C22)
- | FIELD_PREP(ASPEED_MDIO_CTRL_OP, MDIO_C22_OP_READ)
- | FIELD_PREP(ASPEED_MDIO_CTRL_PHYAD, addr)
- | FIELD_PREP(ASPEED_MDIO_CTRL_REGAD, regnum);
+ | FIELD_PREP(ASPEED_MDIO_CTRL_ST, st)
+ | FIELD_PREP(ASPEED_MDIO_CTRL_OP, op)
+ | FIELD_PREP(ASPEED_MDIO_CTRL_PHYAD, phyad)
+ | FIELD_PREP(ASPEED_MDIO_CTRL_REGAD, regad)
+ | FIELD_PREP(ASPEED_MDIO_DATA_MIIRDATA, data);
iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
- rc = readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl,
+ return readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl,
!(ctrl & ASPEED_MDIO_CTRL_FIRE),
ASPEED_MDIO_INTERVAL_US,
ASPEED_MDIO_TIMEOUT_US);
- if (rc < 0)
- return rc;
+}
+
+static int aspeed_mdio_get_data(struct mii_bus *bus)
+{
+ struct aspeed_mdio *ctx = bus->priv;
+ int rc;
+ u32 data;
rc = readl_poll_timeout(ctx->base + ASPEED_MDIO_DATA, data,
data & ASPEED_MDIO_DATA_IDLE,
@@ -78,31 +79,36 @@ static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
return FIELD_GET(ASPEED_MDIO_DATA_MIIRDATA, data);
}
-static int aspeed_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
+static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
{
- struct aspeed_mdio *ctx = bus->priv;
- u32 ctrl;
+ int rc;
- dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d, val: 0x%x\n",
- __func__, addr, regnum, val);
+ dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d\n", __func__, addr,
+ regnum);
/* Just clause 22 for the moment */
if (regnum & MII_ADDR_C45)
return -EOPNOTSUPP;
- ctrl = ASPEED_MDIO_CTRL_FIRE
- | FIELD_PREP(ASPEED_MDIO_CTRL_ST, ASPEED_MDIO_CTRL_ST_C22)
- | FIELD_PREP(ASPEED_MDIO_CTRL_OP, MDIO_C22_OP_WRITE)
- | FIELD_PREP(ASPEED_MDIO_CTRL_PHYAD, addr)
- | FIELD_PREP(ASPEED_MDIO_CTRL_REGAD, regnum)
- | FIELD_PREP(ASPEED_MDIO_CTRL_MIIWDATA, val);
+ rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_READ,
+ addr, regnum, 0);
+ if (rc < 0)
+ return rc;
- iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL);
+ return aspeed_mdio_get_data(bus);
+}
- return readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl,
- !(ctrl & ASPEED_MDIO_CTRL_FIRE),
- ASPEED_MDIO_INTERVAL_US,
- ASPEED_MDIO_TIMEOUT_US);
+static int aspeed_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
+{
+ dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d, val: 0x%x\n",
+ __func__, addr, regnum, val);
+
+ /* Just clause 22 for the moment */
+ if (regnum & MII_ADDR_C45)
+ return -EOPNOTSUPP;
+
+ return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_WRITE,
+ addr, regnum, val);
}
static int aspeed_mdio_probe(struct platform_device *pdev)
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next v3 2/3] net: mdio: aspeed: Introduce read write function for c22 and c45
2022-04-07 1:17 [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO Potin Lai
2022-04-07 1:17 ` [PATCH net-next v3 1/3] net: mdio: aspeed: move reg accessing part into separate functions Potin Lai
@ 2022-04-07 1:17 ` Potin Lai
2022-04-07 1:17 ` [PATCH net-next v3 3/3] net: mdio: aspeed: Add c45 support Potin Lai
2022-04-08 11:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 8+ messages in thread
From: Potin Lai @ 2022-04-07 1:17 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, davem,
Jakub Kicinski, Joel Stanley, Andrew Jeffery
Cc: netdev, linux-arm-kernel, linux-aspeed, linux-kernel,
Patrick Williams, Potin Lai
Add following additional functions to move out the implementation from
aspeed_mdio_read() and aspeed_mdio_write().
c22:
- aspeed_mdio_read_c22()
- aspeed_mdio_write_c22()
c45:
- aspeed_mdio_read_c45()
- aspeed_mdio_write_c45()
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/mdio/mdio-aspeed.c | 46 +++++++++++++++++++++++++---------
1 file changed, 34 insertions(+), 12 deletions(-)
diff --git a/drivers/net/mdio/mdio-aspeed.c b/drivers/net/mdio/mdio-aspeed.c
index f22be2f069e9..5becddb56117 100644
--- a/drivers/net/mdio/mdio-aspeed.c
+++ b/drivers/net/mdio/mdio-aspeed.c
@@ -79,17 +79,10 @@ static int aspeed_mdio_get_data(struct mii_bus *bus)
return FIELD_GET(ASPEED_MDIO_DATA_MIIRDATA, data);
}
-static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
+static int aspeed_mdio_read_c22(struct mii_bus *bus, int addr, int regnum)
{
int rc;
- dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d\n", __func__, addr,
- regnum);
-
- /* Just clause 22 for the moment */
- if (regnum & MII_ADDR_C45)
- return -EOPNOTSUPP;
-
rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_READ,
addr, regnum, 0);
if (rc < 0)
@@ -98,17 +91,46 @@ static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
return aspeed_mdio_get_data(bus);
}
+static int aspeed_mdio_write_c22(struct mii_bus *bus, int addr, int regnum,
+ u16 val)
+{
+ return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_WRITE,
+ addr, regnum, val);
+}
+
+static int aspeed_mdio_read_c45(struct mii_bus *bus, int addr, int regnum)
+{
+ /* TODO: add c45 support */
+ return -EOPNOTSUPP;
+}
+
+static int aspeed_mdio_write_c45(struct mii_bus *bus, int addr, int regnum,
+ u16 val)
+{
+ /* TODO: add c45 support */
+ return -EOPNOTSUPP;
+}
+
+static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
+{
+ dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d\n", __func__, addr,
+ regnum);
+
+ if (regnum & MII_ADDR_C45)
+ return aspeed_mdio_read_c45(bus, addr, regnum);
+
+ return aspeed_mdio_read_c22(bus, addr, regnum);
+}
+
static int aspeed_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
{
dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d, val: 0x%x\n",
__func__, addr, regnum, val);
- /* Just clause 22 for the moment */
if (regnum & MII_ADDR_C45)
- return -EOPNOTSUPP;
+ return aspeed_mdio_write_c45(bus, addr, regnum, val);
- return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_WRITE,
- addr, regnum, val);
+ return aspeed_mdio_write_c22(bus, addr, regnum, val);
}
static int aspeed_mdio_probe(struct platform_device *pdev)
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next v3 3/3] net: mdio: aspeed: Add c45 support
2022-04-07 1:17 [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO Potin Lai
2022-04-07 1:17 ` [PATCH net-next v3 1/3] net: mdio: aspeed: move reg accessing part into separate functions Potin Lai
2022-04-07 1:17 ` [PATCH net-next v3 2/3] net: mdio: aspeed: Introduce read write function for c22 and c45 Potin Lai
@ 2022-04-07 1:17 ` Potin Lai
2022-04-07 1:21 ` Andrew Lunn
2022-04-08 11:30 ` patchwork-bot+netdevbpf
3 siblings, 1 reply; 8+ messages in thread
From: Potin Lai @ 2022-04-07 1:17 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, davem,
Jakub Kicinski, Joel Stanley, Andrew Jeffery
Cc: netdev, linux-arm-kernel, linux-aspeed, linux-kernel,
Patrick Williams, Potin Lai
Add Clause 45 support for Aspeed mdio driver.
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
---
drivers/net/mdio/mdio-aspeed.c | 37 +++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/drivers/net/mdio/mdio-aspeed.c b/drivers/net/mdio/mdio-aspeed.c
index 5becddb56117..7aa49827196f 100644
--- a/drivers/net/mdio/mdio-aspeed.c
+++ b/drivers/net/mdio/mdio-aspeed.c
@@ -21,6 +21,10 @@
#define ASPEED_MDIO_CTRL_OP GENMASK(27, 26)
#define MDIO_C22_OP_WRITE 0b01
#define MDIO_C22_OP_READ 0b10
+#define MDIO_C45_OP_ADDR 0b00
+#define MDIO_C45_OP_WRITE 0b01
+#define MDIO_C45_OP_PREAD 0b10
+#define MDIO_C45_OP_READ 0b11
#define ASPEED_MDIO_CTRL_PHYAD GENMASK(25, 21)
#define ASPEED_MDIO_CTRL_REGAD GENMASK(20, 16)
#define ASPEED_MDIO_CTRL_MIIWDATA GENMASK(15, 0)
@@ -66,8 +70,8 @@ static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad,
static int aspeed_mdio_get_data(struct mii_bus *bus)
{
struct aspeed_mdio *ctx = bus->priv;
- int rc;
u32 data;
+ int rc;
rc = readl_poll_timeout(ctx->base + ASPEED_MDIO_DATA, data,
data & ASPEED_MDIO_DATA_IDLE,
@@ -100,15 +104,37 @@ static int aspeed_mdio_write_c22(struct mii_bus *bus, int addr, int regnum,
static int aspeed_mdio_read_c45(struct mii_bus *bus, int addr, int regnum)
{
- /* TODO: add c45 support */
- return -EOPNOTSUPP;
+ u8 c45_dev = (regnum >> 16) & 0x1F;
+ u16 c45_addr = regnum & 0xFFFF;
+ int rc;
+
+ rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_ADDR,
+ addr, c45_dev, c45_addr);
+ if (rc < 0)
+ return rc;
+
+ rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_READ,
+ addr, c45_dev, 0);
+ if (rc < 0)
+ return rc;
+
+ return aspeed_mdio_get_data(bus);
}
static int aspeed_mdio_write_c45(struct mii_bus *bus, int addr, int regnum,
u16 val)
{
- /* TODO: add c45 support */
- return -EOPNOTSUPP;
+ u8 c45_dev = (regnum >> 16) & 0x1F;
+ u16 c45_addr = regnum & 0xFFFF;
+ int rc;
+
+ rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_ADDR,
+ addr, c45_dev, c45_addr);
+ if (rc < 0)
+ return rc;
+
+ return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_WRITE,
+ addr, c45_dev, val);
}
static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum)
@@ -153,6 +179,7 @@ static int aspeed_mdio_probe(struct platform_device *pdev)
bus->parent = &pdev->dev;
bus->read = aspeed_mdio_read;
bus->write = aspeed_mdio_write;
+ bus->probe_capabilities = MDIOBUS_C22_C45;
rc = of_mdiobus_register(bus, pdev->dev.of_node);
if (rc) {
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v3 3/3] net: mdio: aspeed: Add c45 support
2022-04-07 1:17 ` [PATCH net-next v3 3/3] net: mdio: aspeed: Add c45 support Potin Lai
@ 2022-04-07 1:21 ` Andrew Lunn
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2022-04-07 1:21 UTC (permalink / raw)
To: Potin Lai
Cc: Heiner Kallweit, Russell King, davem, Jakub Kicinski,
Joel Stanley, Andrew Jeffery, netdev, linux-arm-kernel,
linux-aspeed, linux-kernel, Patrick Williams
On Thu, Apr 07, 2022 at 09:17:38AM +0800, Potin Lai wrote:
> Add Clause 45 support for Aspeed mdio driver.
>
> Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v3 3/3] net: mdio: aspeed: Add c45 support
@ 2022-04-07 1:21 ` Andrew Lunn
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2022-04-07 1:21 UTC (permalink / raw)
To: Potin Lai
Cc: Heiner Kallweit, Russell King, davem, Jakub Kicinski,
Joel Stanley, Andrew Jeffery, netdev, linux-arm-kernel,
linux-aspeed, linux-kernel, Patrick Williams
On Thu, Apr 07, 2022 at 09:17:38AM +0800, Potin Lai wrote:
> Add Clause 45 support for Aspeed mdio driver.
>
> Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO
2022-04-07 1:17 [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO Potin Lai
@ 2022-04-08 11:30 ` patchwork-bot+netdevbpf
2022-04-07 1:17 ` [PATCH net-next v3 2/3] net: mdio: aspeed: Introduce read write function for c22 and c45 Potin Lai
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-08 11:30 UTC (permalink / raw)
To: Potin Lai
Cc: andrew, hkallweit1, linux, davem, kuba, joel, andrew, netdev,
linux-arm-kernel, linux-aspeed, linux-kernel, patrick
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 7 Apr 2022 09:17:35 +0800 you wrote:
> This patch series add Clause 45 support for Aspeed MDIO driver, and
> separate c22 and c45 implementation into different functions.
>
>
> LINK: [v1] https://lore.kernel.org/all/20220329161949.19762-1-potin.lai@quantatw.com/
> LINK: [v2] https://lore.kernel.org/all/20220406170055.28516-1-potin.lai@quantatw.com/
>
> [...]
Here is the summary with links:
- [net-next,v3,1/3] net: mdio: aspeed: move reg accessing part into separate functions
https://git.kernel.org/netdev/net-next/c/737ca352569e
- [net-next,v3,2/3] net: mdio: aspeed: Introduce read write function for c22 and c45
https://git.kernel.org/netdev/net-next/c/eb0571932314
- [net-next,v3,3/3] net: mdio: aspeed: Add c45 support
https://git.kernel.org/netdev/net-next/c/e6df1b4a2759
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v3 0/3] Add Clause 45 support for Aspeed MDIO
@ 2022-04-08 11:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-08 11:30 UTC (permalink / raw)
To: Potin Lai
Cc: andrew, hkallweit1, linux, davem, kuba, joel, andrew, netdev,
linux-arm-kernel, linux-aspeed, linux-kernel, patrick
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 7 Apr 2022 09:17:35 +0800 you wrote:
> This patch series add Clause 45 support for Aspeed MDIO driver, and
> separate c22 and c45 implementation into different functions.
>
>
> LINK: [v1] https://lore.kernel.org/all/20220329161949.19762-1-potin.lai@quantatw.com/
> LINK: [v2] https://lore.kernel.org/all/20220406170055.28516-1-potin.lai@quantatw.com/
>
> [...]
Here is the summary with links:
- [net-next,v3,1/3] net: mdio: aspeed: move reg accessing part into separate functions
https://git.kernel.org/netdev/net-next/c/737ca352569e
- [net-next,v3,2/3] net: mdio: aspeed: Introduce read write function for c22 and c45
https://git.kernel.org/netdev/net-next/c/eb0571932314
- [net-next,v3,3/3] net: mdio: aspeed: Add c45 support
https://git.kernel.org/netdev/net-next/c/e6df1b4a2759
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread