dma-ops.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <linux/export.h>
  17. #include <mach/dma.h>
  18. static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
  19. struct samsung_dma_info *info)
  20. {
  21. struct dma_chan *chan;
  22. dma_cap_mask_t mask;
  23. struct dma_slave_config slave_config;
  24. void *filter_param;
  25. dma_cap_zero(mask);
  26. dma_cap_set(info->cap, mask);
  27. /*
  28. * If a dma channel property of a device node from device tree is
  29. * specified, use that as the fliter parameter.
  30. */
  31. filter_param = (dma_ch == DMACH_DT_PROP) ? (void *)info->dt_dmach_prop :
  32. (void *)dma_ch;
  33. chan = dma_request_channel(mask, pl330_filter, filter_param);
  34. if (info->direction == DMA_DEV_TO_MEM) {
  35. memset(&slave_config, 0, sizeof(struct dma_slave_config));
  36. slave_config.direction = info->direction;
  37. slave_config.src_addr = info->fifo;
  38. slave_config.src_addr_width = info->width;
  39. slave_config.src_maxburst = 1;
  40. dmaengine_slave_config(chan, &slave_config);
  41. } else if (info->direction == DMA_MEM_TO_DEV) {
  42. memset(&slave_config, 0, sizeof(struct dma_slave_config));
  43. slave_config.direction = info->direction;
  44. slave_config.dst_addr = info->fifo;
  45. slave_config.dst_addr_width = info->width;
  46. slave_config.dst_maxburst = 1;
  47. dmaengine_slave_config(chan, &slave_config);
  48. }
  49. return (unsigned)chan;
  50. }
  51. static int samsung_dmadev_release(unsigned ch,
  52. struct s3c2410_dma_client *client)
  53. {
  54. dma_release_channel((struct dma_chan *)ch);
  55. return 0;
  56. }
  57. static int samsung_dmadev_prepare(unsigned ch,
  58. struct samsung_dma_prep_info *info)
  59. {
  60. struct scatterlist sg;
  61. struct dma_chan *chan = (struct dma_chan *)ch;
  62. struct dma_async_tx_descriptor *desc;
  63. switch (info->cap) {
  64. case DMA_SLAVE:
  65. sg_init_table(&sg, 1);
  66. sg_dma_len(&sg) = info->len;
  67. sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
  68. info->len, offset_in_page(info->buf));
  69. sg_dma_address(&sg) = info->buf;
  70. desc = dmaengine_prep_slave_sg(chan,
  71. &sg, 1, info->direction, DMA_PREP_INTERRUPT);
  72. break;
  73. case DMA_CYCLIC:
  74. desc = dmaengine_prep_dma_cyclic(chan,
  75. info->buf, info->len, info->period, info->direction);
  76. break;
  77. default:
  78. dev_err(&chan->dev->device, "unsupported format\n");
  79. return -EFAULT;
  80. }
  81. if (!desc) {
  82. dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
  83. return -EFAULT;
  84. }
  85. desc->callback = info->fp;
  86. desc->callback_param = info->fp_param;
  87. dmaengine_submit((struct dma_async_tx_descriptor *)desc);
  88. return 0;
  89. }
  90. static inline int samsung_dmadev_trigger(unsigned ch)
  91. {
  92. dma_async_issue_pending((struct dma_chan *)ch);
  93. return 0;
  94. }
  95. static inline int samsung_dmadev_flush(unsigned ch)
  96. {
  97. return dmaengine_terminate_all((struct dma_chan *)ch);
  98. }
  99. static struct samsung_dma_ops dmadev_ops = {
  100. .request = samsung_dmadev_request,
  101. .release = samsung_dmadev_release,
  102. .prepare = samsung_dmadev_prepare,
  103. .trigger = samsung_dmadev_trigger,
  104. .started = NULL,
  105. .flush = samsung_dmadev_flush,
  106. .stop = samsung_dmadev_flush,
  107. };
  108. void *samsung_dmadev_get_ops(void)
  109. {
  110. return &dmadev_ops;
  111. }
  112. EXPORT_SYMBOL(samsung_dmadev_get_ops);