flexcop-dma.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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;
  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_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
  36. {
  37. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  38. if (no & FC_DMA_1)
  39. v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
  40. if (no & FC_DMA_2)
  41. v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
  42. fc->write_ibi_reg(fc,ctrl_208,v);
  43. return 0;
  44. }
  45. EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
  46. int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
  47. {
  48. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  49. if (no & FC_DMA_1)
  50. v.ctrl_208.DMA1_IRQ_Enable_sig = onoff;
  51. if (no & FC_DMA_2)
  52. v.ctrl_208.DMA2_IRQ_Enable_sig = onoff;
  53. fc->write_ibi_reg(fc,ctrl_208,v);
  54. return 0;
  55. }
  56. EXPORT_SYMBOL(flexcop_dma_control_size_irq);
  57. int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
  58. {
  59. flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
  60. if (no & FC_DMA_1)
  61. v.ctrl_208.DMA1_Size_IRQ_Enable_sig = onoff;
  62. if (no & FC_DMA_2)
  63. v.ctrl_208.DMA2_Size_IRQ_Enable_sig = onoff;
  64. fc->write_ibi_reg(fc,ctrl_208,v);
  65. return 0;
  66. }
  67. EXPORT_SYMBOL(flexcop_dma_control_packet_irq);
  68. int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx,flexcop_dma_addr_index_t index)
  69. {
  70. flexcop_ibi_value v0x0,v0x4,v0xc;
  71. v0x0.raw = v0x4.raw = v0xc.raw = 0;
  72. v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
  73. v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
  74. v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
  75. if (index & FC_DMA_SUBADDR_0)
  76. v0x0.dma_0x0.dma_0start = 1;
  77. if (index & FC_DMA_SUBADDR_1)
  78. v0xc.dma_0xc.dma_1start = 1;
  79. if (dma_idx & FC_DMA_1) {
  80. fc->write_ibi_reg(fc,dma1_000,v0x0);
  81. fc->write_ibi_reg(fc,dma1_004,v0x4);
  82. fc->write_ibi_reg(fc,dma1_00c,v0xc);
  83. } else { /* (dma_idx & FC_DMA_2) */
  84. fc->write_ibi_reg(fc,dma2_010,v0x0);
  85. fc->write_ibi_reg(fc,dma2_014,v0x4);
  86. fc->write_ibi_reg(fc,dma2_01c,v0xc);
  87. }
  88. return 0;
  89. }
  90. EXPORT_SYMBOL(flexcop_dma_config);
  91. static int flexcop_dma_remap(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, int onoff)
  92. {
  93. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
  94. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  95. v.dma_0xc.remap_enable = onoff;
  96. fc->write_ibi_reg(fc,r,v);
  97. return 0;
  98. }
  99. /* 1 cycles = 1.97 msec */
  100. int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles)
  101. {
  102. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
  103. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  104. flexcop_dma_remap(fc,dma_idx,0);
  105. v.dma_0x4_write.dmatimer = cycles >> 1;
  106. fc->write_ibi_reg(fc,r,v);
  107. return 0;
  108. }
  109. EXPORT_SYMBOL(flexcop_dma_config_timer);
  110. int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets)
  111. {
  112. flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
  113. flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
  114. flexcop_dma_remap(fc,dma_idx,1);
  115. v.dma_0x4_remap.DMA_maxpackets = packets;
  116. fc->write_ibi_reg(fc,r,v);
  117. return 0;
  118. }
  119. EXPORT_SYMBOL(flexcop_dma_config_packet_count);