#include <linux/bitrev.h>
 #include <linux/clk.h>
+#include <linux/crc32.h>
 #include <linux/crc32poly.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
        struct stm32_crc_desc_ctx *ctx = shash_desc_ctx(desc);
        struct stm32_crc_ctx *mctx = crypto_shash_ctx(desc->tfm);
        struct stm32_crc *crc;
-       unsigned long flags;
 
        crc = stm32_crc_get_next_crc();
        if (!crc)
 
        pm_runtime_get_sync(crc->dev);
 
-       spin_lock_irqsave(&crc->lock, flags);
+       if (!spin_trylock(&crc->lock)) {
+               /* Hardware is busy, calculate crc32 by software */
+               if (mctx->poly == CRC32_POLY_LE)
+                       ctx->partial = crc32_le(ctx->partial, d8, length);
+               else
+                       ctx->partial = __crc32c_le(ctx->partial, d8, length);
+
+               goto pm_out;
+       }
 
        /*
         * Restore previously calculated CRC for this context as init value
        /* Store partial result */
        ctx->partial = readl_relaxed(crc->regs + CRC_DR);
 
-       spin_unlock_irqrestore(&crc->lock, flags);
+       spin_unlock(&crc->lock);
 
+pm_out:
        pm_runtime_mark_last_busy(crc->dev);
        pm_runtime_put_autosuspend(crc->dev);