s3c-dma-ops.c 2.8 KB

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