flexcop-dma.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
  4. * flexcop-dma.c - configuring and controlling the DMA of the FlexCop
  5. * see flexcop.c for copyright information
  6. */
  7. #include "flexcop.h"
  8. int flexcop_dma_allocate(struct pci_dev *pdev,
  9. struct flexcop_dma *dma, u32 size)
  10. {
  11. u8 *tcpu;
  12. dma_addr_t tdma = 0;
  13. if (size % 2) {
  14. err("dma buffersize has to be even.");
  15. return -EINVAL;
  16. }
  17. if ((tcpu = pci_alloc_consistent(pdev, size, &tdma)) != NULL) {
  18. dma->pdev = pdev;
  19. dma->cpu_addr0 = tcpu;
  20. dma->dma_addr0 = tdma;
  21. dma->cpu_addr1 = tcpu + size/2;
  22. dma->dma_addr1 = tdma + size/2;
  23. dma->size = size/2;
  24. return 0;
  25. }
  26. return -ENOMEM;
  27. }
  28. EXPORT_SYMBOL(flexcop_dma_allocate);
  29. void flexcop_dma_free(struct flexcop_dma *dma)
  30. {
  31. pci_free_consistent(dma->pdev, dma->size*2,
  32. dma->cpu_addr0, dma->dma_addr0);
  33. memset(dma,0,sizeof(struct flexcop_dma));
  34. }
  35. EXPORT_SYMBOL(flexcop_dma_free);
  36. int flexcop_dma_config(struct flexcop_device *fc,
  37. struct flexcop_dma *dma,
  38. flexcop_dma_index_t dma_idx)
  39. {
  40. flexcop_ibi_value v0x0,v0x4,v0xc;
  41. v0x0.raw = v0x4.raw = v0xc.raw = 0;
  42. v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
  43. v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
  44. v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
  45. if ((dma_idx & FC_DMA_1) == dma_idx) {
  46. fc->write_ibi_reg(fc,dma1_000,v0x0);
  47. fc->write_ibi_reg(fc,dma1_004,v0x4);
  48. fc->write_ibi_reg(fc,dma1_00c,v0xc);
  49. } else if ((dma_idx & FC_DMA_2) == dma_idx) {
  50. fc->write_ibi_reg(fc,dma2_010,v0x0);
  51. fc->write_ibi_reg(fc,dma2_014,v0x4);
  52. fc->write_ibi_reg(fc,dma2_01c,v0xc);
  53. } else {
  54. err("either DMA1 or DMA2 can be configured within one flexcop_dma_config call.");
  55. return -EINVAL;
  56. }
  57. return 0;
  58. }
  59. EXPORT_SYMBOL(flexcop_dma_config);
  60. /* start the DMA transfers, but not the DMA IRQs */
  61. int flexcop_dma_xfer_control(struct flexcop_device *fc,
  62. flexcop_dma_index_t dma_idx,
  63. flexcop_dma_addr_index_t index,
  64. int onoff)
  65. {
  66. flexcop_ibi_value v0x0,v0xc;
  67. flexcop_ibi_register r0x0,r0xc;
  68. if ((dma_idx & FC_DMA_1) == dma_idx) {
  69. r0x0 = dma1_000;
  70. r0xc = dma1_00c;
  71. } else if ((dma_idx & FC_DMA_2) == dma_idx) {
  72. r0x0 = dma2_010;
  73. r0xc = dma2_01c;
  74. } else {
  75. err("either transfer DMA1 or DMA2 can be started within one flexcop_dma_xfer_control call.");
  76. return -EINVAL;
  77. }
  78. v0x0 = fc->read_ibi_reg(fc,r0x0);
  79. v0xc = fc->read_ibi_reg(fc,r0xc);
  80. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  81. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  82. if (index & FC_DMA_SUBADDR_0)
  83. v0x0.dma_0x0.dma_0start = onoff;
  84. if (index & FC_DMA_SUBADDR_1)
  85. v0xc.dma_0xc.dma_1start = onoff;
  86. fc->write_ibi_reg(fc,r0x0,v0x0);
  87. fc->write_ibi_reg(fc,r0xc,v0xc);
  88. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  89. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  90. return 0;
  91. }
  92. EXPORT_SYMBOL(flexcop_dma_xfer_control);
  93. static int flexcop_dma_remap(struct flexcop_device *fc,
  94. flexcop_dma_index_t dma_idx,
  95. int onoff)
  96. {
  97. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
  98. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  99. deb_info("%s\n",__func__);
  100. v.dma_0xc.remap_enable = onoff;
  101. fc->write_ibi_reg(fc,r,v);
  102. return 0;
  103. }
  104. int flexcop_dma_control_size_irq(struct flexcop_device *fc,
  105. flexcop_dma_index_t no,
  106. int onoff)
  107. {
  108. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  109. if (no & FC_DMA_1)
  110. v.ctrl_208.DMA1_IRQ_Enable_sig = onoff;
  111. if (no & FC_DMA_2)
  112. v.ctrl_208.DMA2_IRQ_Enable_sig = onoff;
  113. fc->write_ibi_reg(fc,ctrl_208,v);
  114. return 0;
  115. }
  116. EXPORT_SYMBOL(flexcop_dma_control_size_irq);
  117. int flexcop_dma_control_timer_irq(struct flexcop_device *fc,
  118. flexcop_dma_index_t no,
  119. int onoff)
  120. {
  121. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  122. if (no & FC_DMA_1)
  123. v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
  124. if (no & FC_DMA_2)
  125. v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
  126. fc->write_ibi_reg(fc,ctrl_208,v);
  127. return 0;
  128. }
  129. EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
  130. /* 1 cycles = 1.97 msec */
  131. int flexcop_dma_config_timer(struct flexcop_device *fc,
  132. flexcop_dma_index_t dma_idx, u8 cycles)
  133. {
  134. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
  135. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  136. flexcop_dma_remap(fc,dma_idx,0);
  137. deb_info("%s\n",__func__);
  138. v.dma_0x4_write.dmatimer = cycles;
  139. fc->write_ibi_reg(fc,r,v);
  140. return 0;
  141. }
  142. EXPORT_SYMBOL(flexcop_dma_config_timer);