Merge remote-tracking branch 'lsk/v3.10/topic/gator' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / drivers / misc / mei / hw-me.c
index 1bf3f8b5ce3a13d35e67a9772cc812ae5a3b7e1f..297cc10a26da88544a08f961a4835c7f49ce65dc 100644 (file)
@@ -164,6 +164,9 @@ static void mei_me_hw_reset_release(struct mei_device *dev)
        hcsr |= H_IG;
        hcsr &= ~H_RST;
        mei_hcsr_set(hw, hcsr);
+
+       /* complete this write before we set host ready on another CPU */
+       mmiowb();
 }
 /**
  * mei_me_hw_reset - resets fw via mei csr register.
@@ -183,9 +186,22 @@ static void mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
        else
                hcsr &= ~H_IE;
 
+       dev->recvd_hw_ready = false;
        mei_me_reg_write(hw, H_CSR, hcsr);
 
-       if (dev->dev_state == MEI_DEV_POWER_DOWN)
+       /*
+        * Host reads the H_CSR once to ensure that the
+        * posted write to H_CSR completes.
+        */
+       hcsr = mei_hcsr_read(hw);
+
+       if ((hcsr & H_RST) == 0)
+               dev_warn(&dev->pdev->dev, "H_RST is not set = 0x%08X", hcsr);
+
+       if ((hcsr & H_RDY) == H_RDY)
+               dev_warn(&dev->pdev->dev, "H_RDY is not cleared 0x%08X", hcsr);
+
+       if (intr_enable == false)
                mei_me_hw_reset_release(dev);
 
        dev_dbg(&dev->pdev->dev, "current HCSR = 0x%08x.\n", mei_hcsr_read(hw));
@@ -201,6 +217,7 @@ static void mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
 static void mei_me_host_set_ready(struct mei_device *dev)
 {
        struct mei_me_hw *hw = to_me_hw(dev);
+       hw->host_hw_state = mei_hcsr_read(hw);
        hw->host_hw_state |= H_IE | H_IG | H_RDY;
        mei_hcsr_set(hw, hw->host_hw_state);
 }
@@ -233,10 +250,7 @@ static bool mei_me_hw_is_ready(struct mei_device *dev)
 static int mei_me_hw_ready_wait(struct mei_device *dev)
 {
        int err;
-       if (mei_me_hw_is_ready(dev))
-               return 0;
 
-       dev->recvd_hw_ready = false;
        mutex_unlock(&dev->device_lock);
        err = wait_event_interruptible_timeout(dev->wait_hw_ready,
                        dev->recvd_hw_ready,
@@ -496,19 +510,15 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
        /*  check if we need to start the dev */
        if (!mei_host_is_ready(dev)) {
                if (mei_hw_is_ready(dev)) {
+                       mei_me_hw_reset_release(dev);
                        dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
 
                        dev->recvd_hw_ready = true;
                        wake_up_interruptible(&dev->wait_hw_ready);
-
-                       mutex_unlock(&dev->device_lock);
-                       return IRQ_HANDLED;
                } else {
-                       dev_dbg(&dev->pdev->dev, "Reset Completed.\n");
-                       mei_me_hw_reset_release(dev);
-                       mutex_unlock(&dev->device_lock);
-                       return IRQ_HANDLED;
+                       dev_dbg(&dev->pdev->dev, "Spurious Interrupt\n");
                }
+               goto end;
        }
        /* check slots available for reading */
        slots = mei_count_full_read_slots(dev);