mg_disk: fix reading invalid status when use polling driver
[firefly-linux-kernel-4.4.55.git] / drivers / block / mg_disk.c
index 5b120eab2baa16c09b26ccc3f276ab638e9c60d9..6440d59454140bbd5e5b04d09e9a5c13c76dfb8a 100644 (file)
@@ -219,6 +219,16 @@ static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
        host->error = MG_ERR_NONE;
        expire = jiffies + msecs_to_jiffies(msec);
 
+       /* These 2 times dummy status read prevents reading invalid
+        * status. A very little time (3 times of mflash operating clk)
+        * is required for busy bit is set. Use dummy read instead of
+        * busy wait, because mflash's PLL is machine dependent.
+        */
+       if (prv_data->use_polling) {
+               status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
+               status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
+       }
+
        status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
 
        do {