dma-ops.c 3.3 KB

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