void chip_allow_sleep(struct wilc *wilc)
 {
        u32 reg = 0;
+       const struct wilc_hif_func *hif_func = wilc->hif_func;
+       u32 wakeup_reg, wakeup_bit;
+       u32 to_host_from_fw_reg, to_host_from_fw_bit;
+       u32 from_host_to_fw_reg, from_host_to_fw_bit;
+       u32 trials = 100;
+       int ret;
+
+       if (wilc->io_type == WILC_HIF_SDIO) {
+               wakeup_reg = WILC_SDIO_WAKEUP_REG;
+               wakeup_bit = WILC_SDIO_WAKEUP_BIT;
+               from_host_to_fw_reg = WILC_SDIO_HOST_TO_FW_REG;
+               from_host_to_fw_bit = WILC_SDIO_HOST_TO_FW_BIT;
+               to_host_from_fw_reg = WILC_SDIO_FW_TO_HOST_REG;
+               to_host_from_fw_bit = WILC_SDIO_FW_TO_HOST_BIT;
+       } else {
+               wakeup_reg = WILC_SPI_WAKEUP_REG;
+               wakeup_bit = WILC_SPI_WAKEUP_BIT;
+               from_host_to_fw_reg = WILC_SPI_HOST_TO_FW_REG;
+               from_host_to_fw_bit = WILC_SPI_HOST_TO_FW_BIT;
+               to_host_from_fw_reg = WILC_SPI_FW_TO_HOST_REG;
+               to_host_from_fw_bit = WILC_SPI_FW_TO_HOST_BIT;
+       }
+
+       while (trials--) {
+               ret = hif_func->hif_read_reg(wilc, to_host_from_fw_reg, ®);
+               if (ret)
+                       return;
+               if ((reg & to_host_from_fw_bit) == 0)
+                       break;
+       }
+       if (!trials)
+               pr_warn("FW not responding\n");
 
-       wilc->hif_func->hif_read_reg(wilc, WILC_SDIO_WAKEUP_REG, ®);
+       /* Clear bit 1 */
+       ret = hif_func->hif_read_reg(wilc, wakeup_reg, ®);
+       if (ret)
+               return;
+       if (reg & wakeup_bit) {
+               reg &= ~wakeup_bit;
+               ret = hif_func->hif_write_reg(wilc, wakeup_reg, reg);
+               if (ret)
+                       return;
+       }
 
-       wilc->hif_func->hif_write_reg(wilc, WILC_SDIO_WAKEUP_REG,
-                                     reg & ~WILC_SDIO_WAKEUP_BIT);
-       wilc->hif_func->hif_write_reg(wilc, WILC_SDIO_HOST_TO_FW_REG, 0);
+       ret = hif_func->hif_read_reg(wilc, from_host_to_fw_reg, ®);
+       if (ret)
+               return;
+       if (reg & from_host_to_fw_bit) {
+               reg &= ~from_host_to_fw_bit;
+               ret = hif_func->hif_write_reg(wilc, from_host_to_fw_reg, reg);
+               if (ret)
+                       return;
+
+       }
 }
 EXPORT_SYMBOL_GPL(chip_allow_sleep);