flexcop-dma.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. *
  4. * flexcop-dma.c - methods for configuring and controlling the DMA of the FlexCop.
  5. *
  6. * see flexcop.c for copyright information.
  7. */
  8. #include "flexcop.h"
  9. int flexcop_dma_allocate(struct pci_dev *pdev, 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,dma->cpu_addr0, dma->dma_addr0);
  32. memset(dma,0,sizeof(struct flexcop_dma));
  33. }
  34. EXPORT_SYMBOL(flexcop_dma_free);
  35. int flexcop_dma_config(struct flexcop_device *fc,
  36. struct flexcop_dma *dma,
  37. flexcop_dma_index_t dma_idx)
  38. {
  39. flexcop_ibi_value v0x0,v0x4,v0xc;
  40. v0x0.raw = v0x4.raw = v0xc.raw = 0;
  41. v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
  42. v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
  43. v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
  44. if ((dma_idx & FC_DMA_1) == dma_idx) {
  45. fc->write_ibi_reg(fc,dma1_000,v0x0);
  46. fc->write_ibi_reg(fc,dma1_004,v0x4);
  47. fc->write_ibi_reg(fc,dma1_00c,v0xc);
  48. } else if ((dma_idx & FC_DMA_2) == dma_idx) {
  49. fc->write_ibi_reg(fc,dma2_010,v0x0);
  50. fc->write_ibi_reg(fc,dma2_014,v0x4);
  51. fc->write_ibi_reg(fc,dma2_01c,v0xc);
  52. } else {
  53. err("either DMA1 or DMA2 can be configured at the within one flexcop_dma_config call.");
  54. return -EINVAL;
  55. }
  56. return 0;
  57. }
  58. EXPORT_SYMBOL(flexcop_dma_config);
  59. /* start the DMA transfers, but not the DMA IRQs */
  60. int flexcop_dma_xfer_control(struct flexcop_device *fc,
  61. flexcop_dma_index_t dma_idx,
  62. flexcop_dma_addr_index_t index,
  63. int onoff)
  64. {
  65. flexcop_ibi_value v0x0,v0xc;
  66. flexcop_ibi_register r0x0,r0xc;
  67. if ((dma_idx & FC_DMA_1) == dma_idx) {
  68. r0x0 = dma1_000;
  69. r0xc = dma1_00c;
  70. } else if ((dma_idx & FC_DMA_2) == dma_idx) {
  71. r0x0 = dma2_010;
  72. r0xc = dma2_01c;
  73. } else {
  74. err("either transfer DMA1 or DMA2 can be started within one flexcop_dma_xfer_control call.");
  75. return -EINVAL;
  76. }
  77. v0x0 = fc->read_ibi_reg(fc,r0x0);
  78. v0xc = fc->read_ibi_reg(fc,r0xc);
  79. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  80. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  81. if (index & FC_DMA_SUBADDR_0)
  82. v0x0.dma_0x0.dma_0start = onoff;
  83. if (index & FC_DMA_SUBADDR_1)
  84. v0xc.dma_0xc.dma_1start = onoff;
  85. fc->write_ibi_reg(fc,r0x0,v0x0);
  86. fc->write_ibi_reg(fc,r0xc,v0xc);
  87. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  88. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  89. return 0;
  90. }
  91. EXPORT_SYMBOL(flexcop_dma_xfer_control);
  92. static int flexcop_dma_remap(struct flexcop_device *fc,
  93. flexcop_dma_index_t dma_idx,
  94. int onoff)
  95. {
  96. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
  97. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  98. deb_info("%s\n",__func__);
  99. v.dma_0xc.remap_enable = onoff;
  100. fc->write_ibi_reg(fc,r,v);
  101. return 0;
  102. }
  103. int flexcop_dma_control_size_irq(struct flexcop_device *fc,
  104. flexcop_dma_index_t no,
  105. int onoff)
  106. {
  107. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  108. if (no & FC_DMA_1)
  109. v.ctrl_208.DMA1_IRQ_Enable_sig = onoff;
  110. if (no & FC_DMA_2)
  111. v.ctrl_208.DMA2_IRQ_Enable_sig = onoff;
  112. fc->write_ibi_reg(fc,ctrl_208,v);
  113. return 0;
  114. }
  115. EXPORT_SYMBOL(flexcop_dma_control_size_irq);
  116. int flexcop_dma_control_timer_irq(struct flexcop_device *fc,
  117. flexcop_dma_index_t no,
  118. int onoff)
  119. {
  120. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  121. if (no & FC_DMA_1)
  122. v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
  123. if (no & FC_DMA_2)
  124. v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
  125. fc->write_ibi_reg(fc,ctrl_208,v);
  126. return 0;
  127. }
  128. EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
  129. /* 1 cycles = 1.97 msec */
  130. int flexcop_dma_config_timer(struct flexcop_device *fc,
  131. flexcop_dma_index_t dma_idx,
  132. 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);