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

Andrey Smirnov andrew.smirnov at gmail.com
Tue May 31 10:09:39 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 b47d538..73f2b98 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -2139,5 +2139,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 33012be..11b7d4b 100644
--- a/drivers/net/e1000/regio.c
+++ b/drivers/net/e1000/regio.c
@@ -53,3 +53,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