dma-pvr2.c 2.2 KB

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