[PATCH 7/7] smm911x: check if the device is ready before using it

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Tue Aug 14 13:32:20 EDT 2012


poll the READY bit in PMT_CTRL. Any other access to the device is
forbidden while this bit isn't set. Try for 100ms

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/net/smc911x.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 021a194..f695dd2 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -413,6 +413,7 @@ static int smc911x_probe(struct device_d *dev)
 	struct smc911x_priv *priv;
 	uint32_t val;
 	struct smc911x_plat *pdata = dev->platform_data;
+	unsigned int to = 100;
 
 	priv = xzalloc(sizeof(*priv));
 	priv->width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
@@ -431,6 +432,17 @@ static int smc911x_probe(struct device_d *dev)
 		priv->reg_write = __smc911x_reg_write;
 	}
 
+	/*
+	 * poll the READY bit in PMT_CTRL. Any other access to the device is
+	 * forbidden while this bit isn't set. Try for 100ms
+	 */
+	while (!(smc911x_reg_read(priv, PMT_CTRL) & PMT_CTRL_READY) && --to)
+		udelay(1000);
+	if (to == 0) {
+		dev_err(dev, "Device not READY in 100ms aborting\n");
+		return -ENODEV;
+	}
+
 	val = smc911x_reg_read(priv, BYTE_TEST);
 	if (val == 0x43218765) {
 		dev_info(dev, "BYTE_TEST looks swapped, "
-- 
1.7.10.4




More information about the barebox mailing list