s3c-dma-ops.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. {
  34. struct cb_data *data;
  35. if (s3c2410_dma_request(dma_ch, param->client, NULL) < 0) {
  36. s3c2410_dma_free(dma_ch, param->client);
  37. return 0;
  38. }
  39. if (param->cap == DMA_CYCLIC)
  40. s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
  41. data = kzalloc(sizeof(struct cb_data), GFP_KERNEL);
  42. data->ch = dma_ch;
  43. list_add_tail(&data->node, &dma_list);
  44. return (unsigned)dma_ch;
  45. }
  46. static int s3c_dma_release(unsigned ch, void *param)
  47. {
  48. struct cb_data *data;
  49. list_for_each_entry(data, &dma_list, node)
  50. if (data->ch == ch)
  51. break;
  52. list_del(&data->node);
  53. s3c2410_dma_free(ch, param);
  54. kfree(data);
  55. return 0;
  56. }
  57. static int s3c_dma_config(unsigned ch, struct samsung_dma_config *param)
  58. {
  59. s3c2410_dma_devconfig(ch, param->direction, param->fifo);
  60. s3c2410_dma_config(ch, param->width);
  61. return 0;
  62. }
  63. static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep *param)
  64. {
  65. struct cb_data *data;
  66. int len = (param->cap == DMA_CYCLIC) ? param->period : param->len;
  67. list_for_each_entry(data, &dma_list, node)
  68. if (data->ch == ch)
  69. break;
  70. if (!data->fp) {
  71. s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
  72. data->fp = param->fp;
  73. data->fp_param = param->fp_param;
  74. }
  75. s3c2410_dma_enqueue(ch, (void *)data, param->buf, len);
  76. return 0;
  77. }
  78. static inline int s3c_dma_trigger(unsigned ch)
  79. {
  80. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
  81. }
  82. static inline int s3c_dma_started(unsigned ch)
  83. {
  84. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
  85. }
  86. static inline int s3c_dma_flush(unsigned ch)
  87. {
  88. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
  89. }
  90. static inline int s3c_dma_stop(unsigned ch)
  91. {
  92. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
  93. }
  94. static struct samsung_dma_ops s3c_dma_ops = {
  95. .request = s3c_dma_request,
  96. .release = s3c_dma_release,
  97. .config = s3c_dma_config,
  98. .prepare = s3c_dma_prepare,
  99. .trigger = s3c_dma_trigger,
  100. .started = s3c_dma_started,
  101. .flush = s3c_dma_flush,
  102. .stop = s3c_dma_stop,
  103. };
  104. void *s3c_dma_get_ops(void)
  105. {
  106. return &s3c_dma_ops;
  107. }
  108. EXPORT_SYMBOL(s3c_dma_get_ops);