dma.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * linux/arch/arm/mach-pxa/dma.c
  3. *
  4. * PXA DMA registration and IRQ dispatching
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Nov 15, 2001
  8. * Copyright: MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/errno.h>
  19. #include <asm/system.h>
  20. #include <asm/irq.h>
  21. #include <asm/hardware.h>
  22. #include <asm/dma.h>
  23. #include <asm/arch/pxa-regs.h>
  24. static struct dma_channel {
  25. char *name;
  26. void (*irq_handler)(int, void *);
  27. void *data;
  28. } dma_channels[PXA_DMA_CHANNELS];
  29. int pxa_request_dma (char *name, pxa_dma_prio prio,
  30. void (*irq_handler)(int, void *),
  31. void *data)
  32. {
  33. unsigned long flags;
  34. int i, found = 0;
  35. /* basic sanity checks */
  36. if (!name || !irq_handler)
  37. return -EINVAL;
  38. local_irq_save(flags);
  39. do {
  40. /* try grabbing a DMA channel with the requested priority */
  41. pxa_for_each_dma_prio (i, prio) {
  42. if (!dma_channels[i].name) {
  43. found = 1;
  44. break;
  45. }
  46. }
  47. /* if requested prio group is full, try a hier priority */
  48. } while (!found && prio--);
  49. if (found) {
  50. DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
  51. dma_channels[i].name = name;
  52. dma_channels[i].irq_handler = irq_handler;
  53. dma_channels[i].data = data;
  54. } else {
  55. printk (KERN_WARNING "No more available DMA channels for %s\n", name);
  56. i = -ENODEV;
  57. }
  58. local_irq_restore(flags);
  59. return i;
  60. }
  61. void pxa_free_dma (int dma_ch)
  62. {
  63. unsigned long flags;
  64. if (!dma_channels[dma_ch].name) {
  65. printk (KERN_CRIT
  66. "%s: trying to free channel %d which is already freed\n",
  67. __FUNCTION__, dma_ch);
  68. return;
  69. }
  70. local_irq_save(flags);
  71. DCSR(dma_ch) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
  72. dma_channels[dma_ch].name = NULL;
  73. local_irq_restore(flags);
  74. }
  75. static irqreturn_t dma_irq_handler(int irq, void *dev_id)
  76. {
  77. int i, dint = DINT;
  78. for (i = 0; i < PXA_DMA_CHANNELS; i++) {
  79. if (dint & (1 << i)) {
  80. struct dma_channel *channel = &dma_channels[i];
  81. if (channel->name && channel->irq_handler) {
  82. channel->irq_handler(i, channel->data);
  83. } else {
  84. /*
  85. * IRQ for an unregistered DMA channel:
  86. * let's clear the interrupts and disable it.
  87. */
  88. printk (KERN_WARNING "spurious IRQ for DMA channel %d\n", i);
  89. DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
  90. }
  91. }
  92. }
  93. return IRQ_HANDLED;
  94. }
  95. static int __init pxa_dma_init (void)
  96. {
  97. int ret;
  98. ret = request_irq (IRQ_DMA, dma_irq_handler, 0, "DMA", NULL);
  99. if (ret)
  100. printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
  101. return ret;
  102. }
  103. arch_initcall(pxa_dma_init);
  104. EXPORT_SYMBOL(pxa_request_dma);
  105. EXPORT_SYMBOL(pxa_free_dma);