[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V2 5/6] hw/mdio: Move bitbang clock state tracking i
From: |
Grant Likely |
Subject: |
[Qemu-devel] [PATCH V2 5/6] hw/mdio: Move bitbang clock state tracking into core |
Date: |
Wed, 23 Jan 2013 16:15:29 +0000 |
No need for drivers to open code the check for clock state change. This
patch moves it into the common code.
Cc: Peter Maydell <address@hidden>
Cc: Paul Brook <address@hidden>
Cc: Edgar E. Iglesias <address@hidden>
Cc: Anthony Liguori <address@hidden>
Cc: Andreas Färber <address@hidden>
Signed-off-by: Grant Likely <address@hidden>
---
hw/etraxfs_eth.c | 7 ++-----
hw/mdio.c | 20 ++++++++++++--------
hw/mdio.h | 2 +-
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index f26e338..1bcdd12 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -173,11 +173,8 @@ eth_write(void *opaque, hwaddr addr,
if (value & 2) {
eth->mdio_bus.mdio = value & 1;
}
- if (eth->mdio_bus.mdc != (value & 4)) {
- mdio_cycle(ð->mdio_bus);
- eth_validate_duplex(eth);
- }
- eth->mdio_bus.mdc = !!(value & 4);
+ mdio_cycle(ð->mdio_bus, value & 4);
+ eth_validate_duplex(eth);
eth->regs[addr] = value;
break;
diff --git a/hw/mdio.c b/hw/mdio.c
index ca55e21..5272656 100644
--- a/hw/mdio.c
+++ b/hw/mdio.c
@@ -173,15 +173,19 @@ void mdio_write_req(struct qemu_mdio *bus, uint8_t addr,
uint8_t req,
}
}
-void mdio_cycle(struct qemu_mdio *bus)
+void mdio_cycle(struct qemu_mdio *bus, bool mdc)
{
+ if (mdc == bus->mdc) {
+ return; /* Clock state hasn't changed; do nothing */
+ }
+ bus->mdc = mdc;
bus->cnt++;
D(printf("mdc=%d mdio=%d state=%d cnt=%d drv=%d\n",
bus->mdc, bus->mdio, bus->state, bus->cnt, bus->output_enable));
switch (bus->state) {
case PREAMBLE:
- if (bus->mdc) {
+ if (!mdc) {
if (bus->cnt >= (32 * 2) && !bus->mdio) {
bus->cnt = 0;
bus->state = SOF;
@@ -190,7 +194,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case SOF:
- if (bus->mdc) {
+ if (!mdc) {
if (bus->mdio != 1) {
printf("WARNING: no SOF\n");
}
@@ -202,7 +206,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case OPC:
- if (bus->mdc) {
+ if (!mdc) {
bus->opc <<= 1;
bus->opc |= bus->mdio & 1;
if (bus->cnt == 2*2) {
@@ -213,7 +217,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case ADDR:
- if (bus->mdc) {
+ if (!mdc) {
bus->addr <<= 1;
bus->addr |= bus->mdio & 1;
@@ -225,7 +229,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case REQ:
- if (bus->mdc) {
+ if (!mdc) {
bus->req <<= 1;
bus->req |= bus->mdio & 1;
if (bus->cnt == 5*2) {
@@ -235,7 +239,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case TURNAROUND:
- if (bus->mdc && bus->cnt == 2*2) {
+ if (!mdc && bus->cnt == 2*2) {
bus->mdio = 0;
bus->cnt = 0;
@@ -248,7 +252,7 @@ void mdio_cycle(struct qemu_mdio *bus)
}
break;
case DATA:
- if (!bus->mdc) {
+ if (mdc) {
if (bus->output_enable) {
bus->mdio = !!(bus->data & (1 << 15));
bus->data <<= 1;
diff --git a/hw/mdio.h b/hw/mdio.h
index 1cbb422..bd1d0a0 100644
--- a/hw/mdio.h
+++ b/hw/mdio.h
@@ -85,6 +85,6 @@ void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy,
unsigned int addr);
uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req);
void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, uint16_t
data);
-void mdio_cycle(struct qemu_mdio *bus);
+void mdio_cycle(struct qemu_mdio *bus, bool mdc);
#endif
--
1.7.10.4
- [Qemu-devel] [PATCH V2 3/6] hw/mdio: Never set PHY RST and ANEG_RST bits on register write, (continued)
- [Qemu-devel] [PATCH V2 3/6] hw/mdio: Never set PHY RST and ANEG_RST bits on register write, Grant Likely, 2013/01/23
- [Qemu-devel] [PATCH V2 2/6] hw/mdio: Generalize etraxfs MDIO bitbanging emulation, Grant Likely, 2013/01/23
- [Qemu-devel] [PATCH V2 1/6] trivial: etraxfs_eth: Eliminate checkpatch errors, Grant Likely, 2013/01/23
- [Qemu-devel] [PATCH V2 6/6] hw/mdio: Use bitbang core for smc91c111 network device, Grant Likely, 2013/01/23
- [Qemu-devel] [PATCH V2 5/6] hw/mdio: Move bitbang clock state tracking into core,
Grant Likely <=
- Re: [Qemu-devel] Generalize MDIO framework, Edgar E. Iglesias, 2013/01/24