Logo Search packages:      
Sourcecode: linux-fsl-imx51 version File versions  Download package

int mxc_request_dma ( int *  channel,
const char *  devicename 
)

Allocates dma channel. If channel's value is 0, then the function allocates a free channel dynamically and sets its value to channel. Else allocates requested channel if it is free. If the channel is busy or no free channels (in dynamic allocation) -EBUSY returned.

Parameters:
channel pointer to channel number
devicename device name
Returns:
0 on success, error code on fail

Definition at line 715 of file sdma.c.

References sdma_struct::cd, iapi_interrupt_callback(), sdma_struct::in_use, and sdma_status_mutex.

{
      int i, res;

      res = 0;

      down(&sdma_status_mutex);

      /* Dynamic allocation */
      if (*channel == 0) {
            for (i = MAX_DMA_CHANNELS - 1; i > 0; i--) {
#ifdef CONFIG_SDMA_IRAM
                  /*TODO:It will be removed after DPTC used UDMA interface */
                  if (i >= MXC_DMA_CHANNEL_IRAM)
                        continue;
#endif                        /*CONFIG_SDMA_IRAM */
                  if (!sdma_data[i].in_use) {
                        *channel = i;
                        break;
                  }
            }
      }

      if (*channel > 0 && *channel < MAX_DMA_CHANNELS &&
          sdma_data[*channel].in_use == 0) {
            res = iapi_Open(sdma_data[0].cd, *channel);

            if (res < 0) {
                  printk(KERN_ERR "Failed iapi_Open channel %d, 0x%x\n",
                         *channel, res);
            } else {
                  sdma_data[*channel].in_use = 1;
                  strcpy(sdma_data[*channel].devicename, devicename);
                  sdma_data[*channel].cd = CHAD(*channel);

                  iapi_IoCtl(sdma_data[*channel].cd, IAPI_CHANGE_SYNCH,
                           CALLBACK_ISR);
                  iapi_IoCtl(sdma_data[*channel].cd,
                           IAPI_CHANGE_CALLBACKFUNC,
                           (unsigned long)iapi_interrupt_callback);
                  iapi_IoCtl(sdma_data[*channel].cd,
                           IAPI_CHANGE_USER_ARG,
                           (unsigned long)&(sdma_data[*channel]));
            }
      } else {
            res = -EBUSY;
      }

      up(&sdma_status_mutex);

      return res;
}


Generated by  Doxygen 1.6.0   Back to index