[PATCH v2 20/22] e1000: Add a "poll register" function

Andrey Smirnov andrew.smirnov at gmail.com
Wed Jun 1 21:58:49 PDT 2016


Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
 drivers/net/e1000/e1000.h |  4 ++++
 drivers/net/e1000/regio.c | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index c6d26d5..cb3e5ef 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -2144,5 +2144,9 @@ int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
 int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
 int32_t e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
 
+int e1000_poll_reg(struct e1000_hw *hw, uint32_t reg,
+		   uint32_t mask, uint32_t value,
+		   uint64_t timeout);
+
 
 #endif	/* _E1000_HW_H_ */
diff --git a/drivers/net/e1000/regio.c b/drivers/net/e1000/regio.c
index 4970084..b2e9d7b 100644
--- a/drivers/net/e1000/regio.c
+++ b/drivers/net/e1000/regio.c
@@ -52,3 +52,19 @@ void e1000_write_flush(struct e1000_hw *hw)
 {
 	e1000_read_reg(hw, E1000_STATUS);
 }
+
+int e1000_poll_reg(struct e1000_hw *hw, uint32_t reg, uint32_t mask,
+		   uint32_t value, uint64_t timeout)
+{
+	const uint64_t start = get_time_ns();
+
+	do {
+		const uint32_t v = e1000_read_reg(hw, reg);
+
+		if ((v & mask) == value)
+			return 0;
+
+	} while (!is_timeout(start, timeout));
+
+	return -ETIMEDOUT;
+}
-- 
2.5.5




More information about the barebox mailing list