dma-pvr2.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * arch/sh/drivers/dma/dma-pvr2.c
  3. *
  4. * NEC PowerVR 2 (Dreamcast) DMA support
  5. *
  6. * Copyright (C) 2003, 2004 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <mach/sysasic.h>
  17. #include <mach/dma.h>
  18. #include <asm/dma.h>
  19. #include <asm/io.h>
  20. static unsigned int xfer_complete;
  21. static int count;
  22. static irqreturn_t pvr2_dma_interrupt(int irq, void *dev_id)
  23. {
  24. if (get_dma_residue(PVR2_CASCADE_CHAN)) {
  25. printk(KERN_WARNING "DMA: SH DMAC did not complete transfer "
  26. "on channel %d, waiting..\n", PVR2_CASCADE_CHAN);
  27. dma_wait_for_completion(PVR2_CASCADE_CHAN);
  28. }
  29. if (count++ < 10)
  30. pr_debug("Got a pvr2 dma interrupt for channel %d\n",
  31. irq - HW_EVENT_PVR2_DMA);
  32. xfer_complete = 1;
  33. return IRQ_HANDLED;
  34. }
  35. static int pvr2_request_dma(struct dma_channel *chan)
  36. {
  37. if (__raw_readl(PVR2_DMA_MODE) != 0)
  38. return -EBUSY;
  39. __raw_writel(0, PVR2_DMA_LMMODE0);
  40. return 0;
  41. }
  42. static int pvr2_get_dma_residue(struct dma_channel *chan)
  43. {
  44. return xfer_complete == 0;
  45. }
  46. static int pvr2_xfer_dma(struct dma_channel *chan)
  47. {
  48. if (chan->sar || !chan->dar)
  49. return -EINVAL;
  50. xfer_complete = 0;
  51. __raw_writel(chan->dar, PVR2_DMA_ADDR);
  52. __raw_writel(chan->count, PVR2_DMA_COUNT);
  53. __raw_writel(chan->mode & DMA_MODE_MASK, PVR2_DMA_MODE);
  54. return 0;
  55. }
  56. static struct irqaction pvr2_dma_irq = {
  57. .name = "pvr2 DMA handler",
  58. .handler = pvr2_dma_interrupt,
  59. };
  60. static struct dma_ops pvr2_dma_ops = {
  61. .request = pvr2_request_dma,
  62. .get_residue = pvr2_get_dma_residue,
  63. .xfer = pvr2_xfer_dma,
  64. };
  65. static struct dma_info pvr2_dma_info = {
  66. .name = "pvr2_dmac",
  67. .nr_channels = 1,
  68. .ops = &pvr2_dma_ops,
  69. .flags = DMAC_CHANNELS_TEI_CAPABLE,
  70. };
  71. static int __init pvr2_dma_init(void)
  72. {
  73. setup_irq(HW_EVENT_PVR2_DMA, &pvr2_dma_irq);
  74. request_dma(PVR2_CASCADE_CHAN, "pvr2 cascade");
  75. return register_dmac(&pvr2_dma_info);
  76. }
  77. static void __exit pvr2_dma_exit(void)
  78. {
  79. free_dma(PVR2_CASCADE_CHAN);
  80. free_irq(HW_EVENT_PVR2_DMA, 0);
  81. unregister_dmac(&pvr2_dma_info);
  82. }
  83. subsys_initcall(pvr2_dma_init);
  84. module_exit(pvr2_dma_exit);
  85. MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
  86. MODULE_DESCRIPTION("NEC PowerVR 2 DMA driver");
  87. MODULE_LICENSE("GPL");