dma-ops.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* linux/arch/arm/plat-samsung/dma-ops.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Samsung DMA Operations
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/amba/pl330.h>
  15. #include <linux/scatterlist.h>
  16. #include <mach/dma.h>
  17. static inline bool pl330_filter(struct dma_chan *chan, void *param)
  18. {
  19. struct dma_pl330_peri *peri = chan->private;
  20. return peri->peri_id == (unsigned)param;
  21. }
  22. static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
  23. struct samsung_dma_info *info)
  24. {
  25. struct dma_chan *chan;
  26. dma_cap_mask_t mask;
  27. struct dma_slave_config slave_config;
  28. dma_cap_zero(mask);
  29. dma_cap_set(info->cap, mask);
  30. chan = dma_request_channel(mask, pl330_filter, (void *)dma_ch);
  31. if (info->direction == DMA_FROM_DEVICE) {
  32. memset(&slave_config, 0, sizeof(struct dma_slave_config));
  33. slave_config.direction = info->direction;
  34. slave_config.src_addr = info->fifo;
  35. slave_config.src_addr_width = info->width;
  36. slave_config.src_maxburst = 1;
  37. dmaengine_slave_config(chan, &slave_config);
  38. } else if (info->direction == DMA_TO_DEVICE) {
  39. memset(&slave_config, 0, sizeof(struct dma_slave_config));
  40. slave_config.direction = info->direction;
  41. slave_config.dst_addr = info->fifo;
  42. slave_config.dst_addr_width = info->width;
  43. slave_config.dst_maxburst = 1;
  44. dmaengine_slave_config(chan, &slave_config);
  45. }
  46. return (unsigned)chan;
  47. }
  48. static int samsung_dmadev_release(unsigned ch,
  49. struct s3c2410_dma_client *client)
  50. {
  51. dma_release_channel((struct dma_chan *)ch);
  52. return 0;
  53. }
  54. static int samsung_dmadev_prepare(unsigned ch,
  55. struct samsung_dma_prep_info *info)
  56. {
  57. struct scatterlist sg;
  58. struct dma_chan *chan = (struct dma_chan *)ch;
  59. struct dma_async_tx_descriptor *desc;
  60. switch (info->cap) {
  61. case DMA_SLAVE:
  62. sg_init_table(&sg, 1);
  63. sg_dma_len(&sg) = info->len;
  64. sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
  65. info->len, offset_in_page(info->buf));
  66. sg_dma_address(&sg) = info->buf;
  67. desc = chan->device->device_prep_slave_sg(chan,
  68. &sg, 1, info->direction, DMA_PREP_INTERRUPT);
  69. break;
  70. case DMA_CYCLIC:
  71. desc = chan->device->device_prep_dma_cyclic(chan,
  72. info->buf, info->len, info->period, info->direction);
  73. break;
  74. default:
  75. dev_err(&chan->dev->device, "unsupported format\n");
  76. return -EFAULT;
  77. }
  78. if (!desc) {
  79. dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
  80. return -EFAULT;
  81. }
  82. desc->callback = info->fp;
  83. desc->callback_param = info->fp_param;
  84. dmaengine_submit((struct dma_async_tx_descriptor *)desc);
  85. return 0;
  86. }
  87. static inline int samsung_dmadev_trigger(unsigned ch)
  88. {
  89. dma_async_issue_pending((struct dma_chan *)ch);
  90. return 0;
  91. }
  92. static inline int samsung_dmadev_flush(unsigned ch)
  93. {
  94. return dmaengine_terminate_all((struct dma_chan *)ch);
  95. }
  96. struct samsung_dma_ops dmadev_ops = {
  97. .request = samsung_dmadev_request,
  98. .release = samsung_dmadev_release,
  99. .prepare = samsung_dmadev_prepare,
  100. .trigger = samsung_dmadev_trigger,
  101. .started = NULL,
  102. .flush = samsung_dmadev_flush,
  103. .stop = samsung_dmadev_flush,
  104. };
  105. void *samsung_dmadev_get_ops(void)
  106. {
  107. return &dmadev_ops;
  108. }
  109. EXPORT_SYMBOL(samsung_dmadev_get_ops);