if (bd->mode.status & BD_DONE)
                        break;
  
 -              if (bd->mode.status & BD_RROR)
 +              if (bd->mode.status & BD_RROR) {
 +                      bd->mode.status &= ~BD_RROR;
                        sdmac->status = DMA_ERROR;
 +                      error = -EIO;
 +              }
  
 +             /*
 +              * We use bd->mode.count to calculate the residue, since contains
 +              * the number of bytes present in the current buffer descriptor.
 +              */
 +
 +              sdmac->chn_real_count = bd->mode.count;
                bd->mode.status |= BD_DONE;
-               if (sdmac->desc.callback)
-                       sdmac->desc.callback(sdmac->desc.callback_param);
 +              bd->mode.count = sdmac->period_len;
 +
 +              /*
 +               * The callback is called from the interrupt context in order
 +               * to reduce latency and to avoid the risk of altering the
 +               * SDMA transaction status by the time the client tasklet is
 +               * executed.
 +               */
 +
++              dmaengine_desc_get_callback_invoke(&sdmac->desc, NULL);
 +
                sdmac->buf_tail++;
                sdmac->buf_tail %= sdmac->num_bd;
 +
 +              if (error)
 +                      sdmac->status = old_status;
        }
  }
  
                sdmac->status = DMA_COMPLETE;
  
        dma_cookie_complete(&sdmac->desc);
-       if (sdmac->desc.callback)
-               sdmac->desc.callback(sdmac->desc.callback_param);
+ 
+       dmaengine_desc_get_callback_invoke(&sdmac->desc, NULL);
  }
  
 -static void sdma_tasklet(unsigned long data)
 -{
 -      struct sdma_channel *sdmac = (struct sdma_channel *) data;
 -
 -      if (sdmac->flags & IMX_DMA_SG_LOOP)
 -              sdma_handle_channel_loop(sdmac);
 -      else
 -              mxc_sdma_handle_channel_normal(sdmac);
 -}
 -
  static irqreturn_t sdma_int_handler(int irq, void *dev_id)
  {
        struct sdma_engine *sdma = dev_id;