blob: 61a932c1cfff9f4b7e4a6d5e785fa8c7de4ccb8d [file] [log] [blame]
Devin Heitmueller1899e972010-03-13 23:10:13 -03001/*
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
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/slab.h>
34#include <linux/poll.h>
35#include <linux/io.h>
36#include <asm/div64.h>
37#include <linux/pci.h>
38#include <linux/smp_lock.h>
39#include <linux/timer.h>
40#include <linux/version.h>
41#include <linux/byteorder/generic.h>
42#include <linux/firmware.h>
43#include <linux/vmalloc.h>
44
45#include "ngene.h"
46
Devin Heitmueller1899e972010-03-13 23:10:13 -030047
48/****************************************************************************/
49/* COMMAND API interface ****************************************************/
50/****************************************************************************/
51
52/****************************************************************************/
53/* DVB functions and API interface ******************************************/
54/****************************************************************************/
55
56static void swap_buffer(u32 *p, u32 len)
57{
58 while (len) {
59 *p = swab32(*p);
60 p++;
61 len -= 4;
62 }
63}
64
65void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
66{
67 struct ngene_channel *chan = priv;
68
69
Devin Heitmueller1899e972010-03-13 23:10:13 -030070 if (chan->users > 0)
Devin Heitmueller1899e972010-03-13 23:10:13 -030071 dvb_dmx_swfilter(&chan->demux, buf, len);
72 return NULL;
73}
74
75u8 fill_ts[188] = { 0x47, 0x1f, 0xff, 0x10 };
76
77void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
78{
79 struct ngene_channel *chan = priv;
80 struct ngene *dev = chan->dev;
81 u32 alen;
82
83 alen = dvb_ringbuffer_avail(&dev->tsout_rbuf);
84 alen -= alen % 188;
85
86 if (alen < len)
87 FillTSBuffer(buf + alen, len - alen, flags);
88 else
89 alen = len;
90 dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen);
91 if (flags & DF_SWAP32)
92 swap_buffer((u32 *)buf, alen);
93 wake_up_interruptible(&dev->tsout_rbuf.queue);
94 return buf;
95}
96
97
98
99int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed)
100{
101 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
102 struct ngene_channel *chan = dvbdmx->priv;
103
104 if (chan->users == 0) {
Oliver Endriss5a2a1842010-05-16 06:07:07 -0300105 if (!chan->dev->cmd_timeout_workaround || !chan->running)
Devin Heitmueller1899e972010-03-13 23:10:13 -0300106 set_transfer(chan, 1);
Devin Heitmueller1899e972010-03-13 23:10:13 -0300107 }
108
109 return ++chan->users;
110}
111
112int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
113{
114 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
115 struct ngene_channel *chan = dvbdmx->priv;
116
117 if (--chan->users)
118 return chan->users;
119
Oliver Endriss5a2a1842010-05-16 06:07:07 -0300120 if (!chan->dev->cmd_timeout_workaround)
121 set_transfer(chan, 0);
Devin Heitmueller1899e972010-03-13 23:10:13 -0300122
123 return 0;
124}
125
126int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
127 int (*start_feed)(struct dvb_demux_feed *),
128 int (*stop_feed)(struct dvb_demux_feed *),
129 void *priv)
130{
131 dvbdemux->priv = priv;
132
133 dvbdemux->filternum = 256;
134 dvbdemux->feednum = 256;
135 dvbdemux->start_feed = start_feed;
136 dvbdemux->stop_feed = stop_feed;
137 dvbdemux->write_to_decoder = NULL;
138 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
139 DMX_SECTION_FILTERING |
140 DMX_MEMORY_BASED_FILTERING);
141 return dvb_dmx_init(dvbdemux);
142}
143
144int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
145 struct dvb_demux *dvbdemux,
146 struct dmx_frontend *hw_frontend,
147 struct dmx_frontend *mem_frontend,
148 struct dvb_adapter *dvb_adapter)
149{
150 int ret;
151
152 dmxdev->filternum = 256;
153 dmxdev->demux = &dvbdemux->dmx;
154 dmxdev->capabilities = 0;
155 ret = dvb_dmxdev_init(dmxdev, dvb_adapter);
156 if (ret < 0)
157 return ret;
158
159 hw_frontend->source = DMX_FRONTEND_0;
160 dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend);
161 mem_frontend->source = DMX_MEMORY_FE;
162 dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend);
163 return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend);
164}