flexcop-dma.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. * flexcop-dma.c - configuring and controlling the DMA of the FlexCop
  4. * see flexcop.c for copyright information
  5. */
  6. #include "flexcop.h"
  7. int flexcop_dma_allocate(struct pci_dev *pdev,
  8. struct flexcop_dma *dma, u32 size)
  9. {
  10. u8 *tcpu;
  11. dma_addr_t tdma = 0;
  12. if (size % 2) {
  13. err("dma buffersize has to be even.");
  14. return -EINVAL;
  15. }
  16. if ((tcpu = pci_alloc_consistent(pdev, size, &tdma)) != NULL) {
  17. dma->pdev = pdev;
  18. dma->cpu_addr0 = tcpu;
  19. dma->dma_addr0 = tdma;
  20. dma->cpu_addr1 = tcpu + size/2;
  21. dma->dma_addr1 = tdma + size/2;
  22. dma->size = size/2;
  23. return 0;
  24. }
  25. return -ENOMEM;
  26. }
  27. EXPORT_SYMBOL(flexcop_dma_allocate);
  28. void flexcop_dma_free(struct flexcop_dma *dma)
  29. {
  30. pci_free_consistent(dma->pdev, dma->size*2,
  31. 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 within one "
  54. "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 "
  76. "flexcop_dma_xfer_control call.");
  77. return -EINVAL;
  78. }
  79. v0x0 = fc->read_ibi_reg(fc,r0x0);
  80. v0xc = fc->read_ibi_reg(fc,r0xc);
  81. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  82. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  83. if (index & FC_DMA_SUBADDR_0)
  84. v0x0.dma_0x0.dma_0start = onoff;
  85. if (index & FC_DMA_SUBADDR_1)
  86. v0xc.dma_0xc.dma_1start = onoff;
  87. fc->write_ibi_reg(fc,r0x0,v0x0);
  88. fc->write_ibi_reg(fc,r0xc,v0xc);
  89. deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
  90. deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
  91. return 0;
  92. }
  93. EXPORT_SYMBOL(flexcop_dma_xfer_control);
  94. static int flexcop_dma_remap(struct flexcop_device *fc,
  95. flexcop_dma_index_t dma_idx,
  96. int onoff)
  97. {
  98. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
  99. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  100. deb_info("%s\n",__func__);
  101. v.dma_0xc.remap_enable = onoff;
  102. fc->write_ibi_reg(fc,r,v);
  103. return 0;
  104. }
  105. int flexcop_dma_control_size_irq(struct flexcop_device *fc,
  106. flexcop_dma_index_t no,
  107. int onoff)
  108. {
  109. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  110. if (no & FC_DMA_1)
  111. v.ctrl_208.DMA1_IRQ_Enable_sig = onoff;
  112. if (no & FC_DMA_2)
  113. v.ctrl_208.DMA2_IRQ_Enable_sig = onoff;
  114. fc->write_ibi_reg(fc,ctrl_208,v);
  115. return 0;
  116. }
  117. EXPORT_SYMBOL(flexcop_dma_control_size_irq);
  118. int flexcop_dma_control_timer_irq(struct flexcop_device *fc,
  119. flexcop_dma_index_t no,
  120. int onoff)
  121. {
  122. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  123. if (no & FC_DMA_1)
  124. v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
  125. if (no & FC_DMA_2)
  126. v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
  127. fc->write_ibi_reg(fc,ctrl_208,v);
  128. return 0;
  129. }
  130. EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
  131. /* 1 cycles = 1.97 msec */
  132. int flexcop_dma_config_timer(struct flexcop_device *fc,
  133. flexcop_dma_index_t dma_idx, u8 cycles)
  134. {
  135. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
  136. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  137. flexcop_dma_remap(fc,dma_idx,0);
  138. deb_info("%s\n",__func__);
  139. v.dma_0x4_write.dmatimer = cycles;
  140. fc->write_ibi_reg(fc,r,v);
  141. return 0;
  142. }
  143. EXPORT_SYMBOL(flexcop_dma_config_timer);