s3c-dma-ops.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <mach/dma.h>
  17. struct cb_data {
  18. void (*fp) (void *);
  19. void *fp_param;
  20. unsigned ch;
  21. struct list_head node;
  22. };
  23. static LIST_HEAD(dma_list);
  24. static void s3c_dma_cb(struct s3c2410_dma_chan *channel, void *param,
  25. int size, enum s3c2410_dma_buffresult res)
  26. {
  27. struct cb_data *data = param;
  28. data->fp(data->fp_param);
  29. }
  30. static unsigned s3c_dma_request(enum dma_ch dma_ch,
  31. struct samsung_dma_info *info)
  32. {
  33. struct cb_data *data;
  34. if (s3c2410_dma_request(dma_ch, info->client, NULL) < 0) {
  35. s3c2410_dma_free(dma_ch, info->client);
  36. return 0;
  37. }
  38. data = kzalloc(sizeof(struct cb_data), GFP_KERNEL);
  39. data->ch = dma_ch;
  40. list_add_tail(&data->node, &dma_list);
  41. if (info->direction == DMA_FROM_DEVICE)
  42. s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_HW, info->fifo);
  43. else
  44. s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_MEM, info->fifo);
  45. if (info->cap == DMA_CYCLIC)
  46. s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
  47. s3c2410_dma_config(dma_ch, info->width);
  48. return (unsigned)dma_ch;
  49. }
  50. static int s3c_dma_release(unsigned ch, struct s3c2410_dma_client *client)
  51. {
  52. struct cb_data *data;
  53. list_for_each_entry(data, &dma_list, node)
  54. if (data->ch == ch)
  55. break;
  56. list_del(&data->node);
  57. s3c2410_dma_free(ch, client);
  58. kfree(data);
  59. return 0;
  60. }
  61. static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep_info *info)
  62. {
  63. struct cb_data *data;
  64. int len = (info->cap == DMA_CYCLIC) ? info->period : info->len;
  65. list_for_each_entry(data, &dma_list, node)
  66. if (data->ch == ch)
  67. break;
  68. if (!data->fp) {
  69. s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
  70. data->fp = info->fp;
  71. data->fp_param = info->fp_param;
  72. }
  73. s3c2410_dma_enqueue(ch, (void *)data, info->buf, len);
  74. return 0;
  75. }
  76. static inline int s3c_dma_trigger(unsigned ch)
  77. {
  78. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
  79. }
  80. static inline int s3c_dma_started(unsigned ch)
  81. {
  82. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
  83. }
  84. static inline int s3c_dma_flush(unsigned ch)
  85. {
  86. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
  87. }
  88. static inline int s3c_dma_stop(unsigned ch)
  89. {
  90. return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
  91. }
  92. static struct samsung_dma_ops s3c_dma_ops = {
  93. .request = s3c_dma_request,
  94. .release = s3c_dma_release,
  95. .prepare = s3c_dma_prepare,
  96. .trigger = s3c_dma_trigger,
  97. .started = s3c_dma_started,
  98. .flush = s3c_dma_flush,
  99. .stop = s3c_dma_stop,
  100. };
  101. void *s3c_dma_get_ops(void)
  102. {
  103. return &s3c_dma_ops;
  104. }
  105. EXPORT_SYMBOL(s3c_dma_get_ops);