s3c-dma-ops.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* linux/arch/arm/plat-samsung/s3c-dma-ops.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Samsung S3C-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/slab.h>
  15. #include <linux/types.h>
  16. #include <linux/export.h>
  17. #include <mach/dma.h>
  18. struct cb_data {
  19. void (*fp) (void *);
  20. void *fp_param;
  21. unsigned ch;
  22. struct list_head node;
  23. };
  24. static LIST_HEAD(dma_list);
  25. static void s3c_dma_cb(struct s3c2410_dma_chan *channel, void *param,
  26. int size, enum s3c2410_dma_buffresult res)
  27. {
  28. struct cb_data *data = param;
  29. data->fp(data->fp_param);
  30. }
  31. static unsigned s3c_dma_request(enum dma_ch dma_ch,
  32. struct samsung_dma_req *param,
  33. struct device *dev, char *ch_name)
  34. {
  35. struct cb_data *data;
  36. if (s3c2410_dma_request(dma_ch, param->client, NULL) < 0) {
  37. s3c2410_dma_free(dma_ch, param->client);
  38. return 0;
  39. }
  40. if (param->cap == DMA_CYCLIC)
  41. s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
  42. data = kzalloc(sizeof(struct cb_data), GFP_KERNEL);
  43. data->ch = dma_ch;
  44. list_add_tail(&data->node, &dma_list);
  45. return (unsigned)dma_ch;
  46. }
  47. static int s3c_dma_release(unsigned ch, void *param)
  48. {
  49. struct cb_data *data;
  50. list_for_each_entry(data, &dma_list, node)
  51. if (data->ch == ch)
  52. break;
  53. list_del(&data->node);
  54. s3c2410_dma_free(ch, param);
  55. kfree(data);
  56. return 0;
  57. }
  58. static int s3c_dma_config(unsigned ch, struct samsung_dma_config *param)
  59. {
  60. s3c2410_dma_devconfig(ch, param->direction, param->fifo);
  61. s3c2410_dma_config(ch, param->width);
  62. return 0;
  63. }
  64. static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep *param)
  65. {
  66. struct cb_data *data;
  67. dma_addr_t pos = param->buf;
  68. dma_addr_t end = param->buf + param->len;
  69. list_for_each_entry(data, &dma_list, node)
  70. if (data->ch == ch)
  71. break;
  72. if (!data->fp) {
  73. s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
  74. data->fp = param->fp;
  75. data->fp_param = param->fp_param;
  76. }
  77. if (param->cap != DMA_CYCLIC) {
  78. s3c2410_dma_enqueue(ch, (void *)data, param->buf, param->len);
  79. return 0;
  80. }
  81. while (pos < end) {
  82. s3c2410_dma_enqueue(ch, (void *)data, pos, param->period);
  83. pos += param->period;
  84. }
  85. return 0;
  86. }
  87. static inline int s3c_dma_trigger(unsigned ch)
  88. {
  89. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
  90. }
  91. static inline int s3c_dma_started(unsigned ch)
  92. {
  93. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
  94. }
  95. static inline int s3c_dma_flush(unsigned ch)
  96. {
  97. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
  98. }
  99. static inline int s3c_dma_stop(unsigned ch)
  100. {
  101. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
  102. }
  103. static struct samsung_dma_ops s3c_dma_ops = {
  104. .request = s3c_dma_request,
  105. .release = s3c_dma_release,
  106. .config = s3c_dma_config,
  107. .prepare = s3c_dma_prepare,
  108. .trigger = s3c_dma_trigger,
  109. .started = s3c_dma_started,
  110. .flush = s3c_dma_flush,
  111. .stop = s3c_dma_stop,
  112. };
  113. void *s3c_dma_get_ops(void)
  114. {
  115. return &s3c_dma_ops;
  116. }
  117. EXPORT_SYMBOL(s3c_dma_get_ops);