standardDeviationMemoryDefinition.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * bfin_dma.c - Blackfin DMA implementation
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/param.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/sched.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/spinlock.h>
  17. #include <asm/blackfin.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/dma.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/early_printk.h>
  22. /*
  23. * To make sure we work around 05000119 - we always check DMA_DONE bit,
  24. * never the DMA_RUN bit
  25. */
  26. struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  27. EXPORT_SYMBOL(dma_ch);
  28. static int __init blackfin_dma_init(void)
  29. {
  30. int i;
  31. printk(KERN_INFO "Blackfin DMA Controller\n");
  32. #if ANOMALY_05000480
  33. bfin_write_DMAC_TC_PER(0x0111);
  34. #endif
  35. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  36. atomic_set(&dma_ch[i].chan_status, 0);
  37. dma_ch[i].regs = dma_io_base_addr[i];
  38. }
  39. #if defined(CH_MEM_STREAM3_SRC) && defined(CONFIG_BF60x)
  40. /* Mark MEMDMA Channel 3 as requested since we're using it internally */
  41. request_dma(CH_MEM_STREAM3_DEST, "Blackfin dma_memcpy");
  42. request_dma(CH_MEM_STREAM3_SRC, "Blackfin dma_memcpy");
  43. #else
  44. /* Mark MEMDMA Channel 0 as requested since we're using it internally */
  45. request_dma(CH_MEM_STREAM0_DEST, "Blackfin dma_memcpy");
  46. request_dma(CH_MEM_STREAM0_SRC, "Blackfin dma_memcpy");
  47. #endif
  48. #if defined(CONFIG_DEB_DMA_URGENT)
  49. bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
  50. | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
  51. #endif
  52. return 0;
  53. }
  54. arch_initcall(blackfin_dma_init);
  55. #ifdef CONFIG_PROC_FS
  56. static int proc_dma_show(struct seq_file *m, void *v)
  57. {
  58. int i;
  59. for (i = 0; i < MAX_DMA_CHANNELS; ++i)
  60. if (dma_channel_active(i))
  61. seq_printf(m, "%2d: %s\n", i, dma_ch[i].device_id);
  62. return 0;
  63. }
  64. static int proc_dma_open(struct inode *inode, struct file *file)
  65. {
  66. return single_open(file, proc_dma_show, NULL);
  67. }
  68. static const struct file_operations proc_dma_operations = {
  69. .open = proc_dma_open,
  70. .read = seq_read,
  71. .llseek = seq_lseek,
  72. .release = single_release,
  73. };
  74. static int __init proc_dma_init(void)
  75. {
  76. proc_create("dma", 0, NULL, &proc_dma_operations);
  77. return 0;
  78. }
  79. late_initcall(proc_dma_init);
  80. #endif
  81. static void set_dma_peripheral_map(unsigned int channel, const char *device_id)
  82. {
  83. #ifdef CONFIG_BF54x
  84. unsigned int per_map;
  85. switch (channel) {
  86. case CH_UART2_RX: per_map = 0xC << 12; break;
  87. case CH_UART2_TX: per_map = 0xD << 12; break;
  88. case CH_UART3_RX: per_map = 0xE << 12; break;
  89. case CH_UART3_TX: per_map = 0xF << 12; break;
  90. default: return;
  91. }
  92. if (strncmp(device_id, "BFIN_UART", 9) == 0)
  93. dma_ch[channel].regs->peripheral_map = per_map;
  94. #endif
  95. }
  96. /**
  97. * request_dma - request a DMA channel
  98. *
  99. * Request the specific DMA channel from the system if it's available.
  100. */
  101. int request_dma(unsigned int channel, const char *device_id)
  102. {
  103. pr_debug("request_dma() : BEGIN\n");
  104. if (device_id == NULL)
  105. printk(KERN_WARNING "request_dma(%u): no device_id given\n", channel);
  106. #if defined(CONFIG_BF561) && ANOMALY_05000182
  107. if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
  108. if (get_cclk() > 500000000) {
  109. printk(KERN_WARNING
  110. "Request IMDMA failed due to ANOMALY 05000182\n");
  111. return -EFAULT;
  112. }
  113. }
  114. #endif
  115. if (atomic_cmpxchg(&dma_ch[channel].chan_status, 0, 1)) {
  116. pr_debug("DMA CHANNEL IN USE\n");
  117. return -EBUSY;
  118. }
  119. set_dma_peripheral_map(channel, device_id);
  120. dma_ch[channel].device_id = device_id;
  121. dma_ch[channel].irq = 0;
  122. /* This is to be enabled by putting a restriction -
  123. * you have to request DMA, before doing any operations on
  124. * descriptor/channel
  125. */
  126. pr_debug("request_dma() : END\n");
  127. return 0;
  128. }
  129. EXPORT_SYMBOL(request_dma);