ngene-dvb.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * ngene-dvb.c: nGene PCIe bridge driver - DVB functions
  3. *
  4. * Copyright (C) 2005-2007 Micronas
  5. *
  6. * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
  7. * Modifications for new nGene firmware,
  8. * support for EEPROM-copying,
  9. * support for new dual DVB-S2 card prototype
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * version 2 only, as published by the Free Software Foundation.
  15. *
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  26. * 02110-1301, USA
  27. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  28. */
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/delay.h>
  32. #include <linux/slab.h>
  33. #include <linux/poll.h>
  34. #include <linux/io.h>
  35. #include <asm/div64.h>
  36. #include <linux/pci.h>
  37. #include <linux/smp_lock.h>
  38. #include <linux/timer.h>
  39. #include <linux/version.h>
  40. #include <linux/byteorder/generic.h>
  41. #include <linux/firmware.h>
  42. #include <linux/vmalloc.h>
  43. #include "ngene.h"
  44. #define COMMAND_TIMEOUT_WORKAROUND
  45. /****************************************************************************/
  46. /* COMMAND API interface ****************************************************/
  47. /****************************************************************************/
  48. /****************************************************************************/
  49. /* DVB functions and API interface ******************************************/
  50. /****************************************************************************/
  51. static void swap_buffer(u32 *p, u32 len)
  52. {
  53. while (len) {
  54. *p = swab32(*p);
  55. p++;
  56. len -= 4;
  57. }
  58. }
  59. void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
  60. {
  61. struct ngene_channel *chan = priv;
  62. #ifdef COMMAND_TIMEOUT_WORKAROUND
  63. if (chan->users > 0)
  64. #endif
  65. dvb_dmx_swfilter(&chan->demux, buf, len);
  66. return NULL;
  67. }
  68. u8 fill_ts[188] = { 0x47, 0x1f, 0xff, 0x10 };
  69. void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
  70. {
  71. struct ngene_channel *chan = priv;
  72. struct ngene *dev = chan->dev;
  73. u32 alen;
  74. alen = dvb_ringbuffer_avail(&dev->tsout_rbuf);
  75. alen -= alen % 188;
  76. if (alen < len)
  77. FillTSBuffer(buf + alen, len - alen, flags);
  78. else
  79. alen = len;
  80. dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen);
  81. if (flags & DF_SWAP32)
  82. swap_buffer((u32 *)buf, alen);
  83. wake_up_interruptible(&dev->tsout_rbuf.queue);
  84. return buf;
  85. }
  86. int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed)
  87. {
  88. struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
  89. struct ngene_channel *chan = dvbdmx->priv;
  90. if (chan->users == 0) {
  91. #ifdef COMMAND_TIMEOUT_WORKAROUND
  92. if (!chan->running)
  93. #endif
  94. set_transfer(chan, 1);
  95. /* msleep(10); */
  96. }
  97. return ++chan->users;
  98. }
  99. int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
  100. {
  101. struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
  102. struct ngene_channel *chan = dvbdmx->priv;
  103. if (--chan->users)
  104. return chan->users;
  105. #ifndef COMMAND_TIMEOUT_WORKAROUND
  106. set_transfer(chan, 0);
  107. #endif
  108. return 0;
  109. }
  110. int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
  111. int (*start_feed)(struct dvb_demux_feed *),
  112. int (*stop_feed)(struct dvb_demux_feed *),
  113. void *priv)
  114. {
  115. dvbdemux->priv = priv;
  116. dvbdemux->filternum = 256;
  117. dvbdemux->feednum = 256;
  118. dvbdemux->start_feed = start_feed;
  119. dvbdemux->stop_feed = stop_feed;
  120. dvbdemux->write_to_decoder = NULL;
  121. dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
  122. DMX_SECTION_FILTERING |
  123. DMX_MEMORY_BASED_FILTERING);
  124. return dvb_dmx_init(dvbdemux);
  125. }
  126. int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
  127. struct dvb_demux *dvbdemux,
  128. struct dmx_frontend *hw_frontend,
  129. struct dmx_frontend *mem_frontend,
  130. struct dvb_adapter *dvb_adapter)
  131. {
  132. int ret;
  133. dmxdev->filternum = 256;
  134. dmxdev->demux = &dvbdemux->dmx;
  135. dmxdev->capabilities = 0;
  136. ret = dvb_dmxdev_init(dmxdev, dvb_adapter);
  137. if (ret < 0)
  138. return ret;
  139. hw_frontend->source = DMX_FRONTEND_0;
  140. dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend);
  141. mem_frontend->source = DMX_MEMORY_FE;
  142. dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend);
  143. return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend);
  144. }