s3c-dma-ops.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. int len = (param->cap == DMA_CYCLIC) ? param->period : param->len;
  68. list_for_each_entry(data, &dma_list, node)
  69. if (data->ch == ch)
  70. break;
  71. if (!data->fp) {
  72. s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
  73. data->fp = param->fp;
  74. data->fp_param = param->fp_param;
  75. }
  76. s3c2410_dma_enqueue(ch, (void *)data, param->buf, len);
  77. return 0;
  78. }
  79. static inline int s3c_dma_trigger(unsigned ch)
  80. {
  81. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
  82. }
  83. static inline int s3c_dma_started(unsigned ch)
  84. {
  85. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
  86. }
  87. static inline int s3c_dma_flush(unsigned ch)
  88. {
  89. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
  90. }
  91. static inline int s3c_dma_stop(unsigned ch)
  92. {
  93. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
  94. }
  95. static struct samsung_dma_ops s3c_dma_ops = {
  96. .request = s3c_dma_request,
  97. .release = s3c_dma_release,
  98. .config = s3c_dma_config,
  99. .prepare = s3c_dma_prepare,
  100. .trigger = s3c_dma_trigger,
  101. .started = s3c_dma_started,
  102. .flush = s3c_dma_flush,
  103. .stop = s3c_dma_stop,
  104. };
  105. void *s3c_dma_get_ops(void)
  106. {
  107. return &s3c_dma_ops;
  108. }
  109. EXPORT_SYMBOL(s3c_dma_get_ops);