goto error_pipeline;
        }
 
+       ret = cal_ctx_prepare(ctx);
+       if (ret) {
+               ctx_err(ctx, "Failed to prepare context: %d\n", ret);
+               goto error_pipeline;
+       }
+
        spin_lock_irq(&ctx->dma.lock);
        buf = list_first_entry(&ctx->dma.queue, struct cal_buffer, list);
        ctx->dma.pending = buf;
 error_stop:
        cal_ctx_stop(ctx);
        pm_runtime_put_sync(ctx->cal->dev);
+       cal_ctx_unprepare(ctx);
 
 error_pipeline:
        media_pipeline_stop(&ctx->vdev.entity);
 
        pm_runtime_put_sync(ctx->cal->dev);
 
+       cal_ctx_unprepare(ctx);
+
        cal_release_buffers(ctx, VB2_BUF_STATE_ERROR);
 
        media_pipeline_stop(&ctx->vdev.entity);
 
                                         unsigned int instance);
 void cal_camerarx_destroy(struct cal_camerarx *phy);
 
+int cal_ctx_prepare(struct cal_ctx *ctx);
+void cal_ctx_unprepare(struct cal_ctx *ctx);
 void cal_ctx_set_dma_addr(struct cal_ctx *ctx, dma_addr_t addr);
 void cal_ctx_start(struct cal_ctx *ctx);
 void cal_ctx_stop(struct cal_ctx *ctx);