w1: masters: tegra_w1: Clear device ready flag when suspended
authorRebecca Schultz Zavin <rebecca@android.com>
Wed, 1 Sep 2010 23:14:24 +0000 (16:14 -0700)
committerColin Cross <ccross@android.com>
Wed, 6 Oct 2010 23:50:42 +0000 (16:50 -0700)
This will prevent any device from trying to read/write via w1
before the w1 master has resumed.

Change-Id: Ic3a27f07db6fcefb76937adf471d2fd44033b178
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
drivers/w1/masters/tegra_w1.c

index 9443c4b1dbc65ad46e3625524f01dcba5a290f56..3d1e1dc82180656d004c1eaf62fc1fe36bc2423d 100644 (file)
@@ -282,7 +282,7 @@ static u8 tegra_w1_touch_bit(void *data, u8 bit)
                w1_writel(dev, control | OC_WR0_BIT, OWR_CONTROL);
                rc = w1_wait(dev, OI_BIT_XFER_DONE);
                if (rc) {
-                       W1_ERR("write-0 failed\n");
+                       W1_ERR("write-0 failed %d\n", rc);
                        goto done;
                }
        }
@@ -308,7 +308,7 @@ static u8 tegra_w1_reset_bus(void *data)
        presence = 1;
        mutex_lock(&dev->mutex);
        if (!dev->ready)
-               goto done;
+               goto not_ready;
 
        clk_enable(dev->clk);
        w1_imask(dev, OI_PRESENCE_DONE);
@@ -336,6 +336,7 @@ done:
        w1_imask(dev, 0);
        dev->transfer_completion = NULL;
        clk_disable(dev->clk);
+not_ready:
        mutex_unlock(&dev->mutex);
        return presence;
 }
@@ -450,6 +451,10 @@ static int tegra_w1_remove(struct platform_device *pdev)
 
 static int tegra_w1_suspend(struct platform_device *pdev, pm_message_t state)
 {
+       struct tegra_device *dev = platform_get_drvdata(pdev);
+       mutex_lock(&dev->mutex);
+       dev->ready = false;
+       mutex_unlock(&dev->mutex);
        return 0;
 }
 
@@ -459,6 +464,9 @@ static int tegra_w1_resume(struct platform_device *pdev)
 
        /* TODO: Is this necessary? I would assume yes. */
        w1_setup(dev);
+       mutex_lock(&dev->mutex);
+       dev->ready = true;
+       mutex_unlock(&dev->mutex);
        return 0;
 }