2 * ngene-dvb.c: nGene PCIe bridge driver - DVB functions
4 * Copyright (C) 2005-2007 Micronas
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
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.
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.
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
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
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>
36 #include <asm/div64.h>
37 #include <linux/pci.h>
38 #include <linux/timer.h>
39 #include <linux/byteorder/generic.h>
40 #include <linux/firmware.h>
41 #include <linux/vmalloc.h>
46 /****************************************************************************/
47 /* COMMAND API interface ****************************************************/
48 /****************************************************************************/
50 static ssize_t
ts_write(struct file
*file
, const char *buf
,
51 size_t count
, loff_t
*ppos
)
53 struct dvb_device
*dvbdev
= file
->private_data
;
54 struct ngene_channel
*chan
= dvbdev
->priv
;
55 struct ngene
*dev
= chan
->dev
;
57 if (wait_event_interruptible(dev
->tsout_rbuf
.queue
,
59 (&dev
->tsout_rbuf
) >= count
) < 0)
62 dvb_ringbuffer_write(&dev
->tsout_rbuf
, buf
, count
);
67 static ssize_t
ts_read(struct file
*file
, char *buf
,
68 size_t count
, loff_t
*ppos
)
70 struct dvb_device
*dvbdev
= file
->private_data
;
71 struct ngene_channel
*chan
= dvbdev
->priv
;
72 struct ngene
*dev
= chan
->dev
;
77 if (wait_event_interruptible(
79 dvb_ringbuffer_avail(&dev
->tsin_rbuf
) > 0) < 0)
81 avail
= dvb_ringbuffer_avail(&dev
->tsin_rbuf
);
84 dvb_ringbuffer_read_user(&dev
->tsin_rbuf
, buf
, avail
);
91 static const struct file_operations ci_fops
= {
95 .open
= dvb_generic_open
,
96 .release
= dvb_generic_release
,
99 struct dvb_device ngene_dvbdev_ci
= {
108 /****************************************************************************/
109 /* DVB functions and API interface ******************************************/
110 /****************************************************************************/
112 static void swap_buffer(u32
*p
, u32 len
)
121 void *tsin_exchange(void *priv
, void *buf
, u32 len
, u32 clock
, u32 flags
)
123 struct ngene_channel
*chan
= priv
;
124 struct ngene
*dev
= chan
->dev
;
127 if (flags
& DF_SWAP32
)
128 swap_buffer(buf
, len
);
129 if (dev
->ci
.en
&& chan
->number
== 2) {
130 if (dvb_ringbuffer_free(&dev
->tsin_rbuf
) > len
) {
131 dvb_ringbuffer_write(&dev
->tsin_rbuf
, buf
, len
);
132 wake_up_interruptible(&dev
->tsin_rbuf
.queue
);
136 if (chan
->users
> 0) {
137 dvb_dmx_swfilter(&chan
->demux
, buf
, len
);
142 u8 fill_ts
[188] = { 0x47, 0x1f, 0xff, 0x10 };
144 void *tsout_exchange(void *priv
, void *buf
, u32 len
, u32 clock
, u32 flags
)
146 struct ngene_channel
*chan
= priv
;
147 struct ngene
*dev
= chan
->dev
;
150 alen
= dvb_ringbuffer_avail(&dev
->tsout_rbuf
);
154 FillTSBuffer(buf
+ alen
, len
- alen
, flags
);
157 dvb_ringbuffer_read(&dev
->tsout_rbuf
, buf
, alen
);
158 if (flags
& DF_SWAP32
)
159 swap_buffer((u32
*)buf
, alen
);
160 wake_up_interruptible(&dev
->tsout_rbuf
.queue
);
166 int ngene_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
168 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
169 struct ngene_channel
*chan
= dvbdmx
->priv
;
171 if (chan
->users
== 0) {
172 if (!chan
->dev
->cmd_timeout_workaround
|| !chan
->running
)
173 set_transfer(chan
, 1);
176 return ++chan
->users
;
179 int ngene_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
181 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
182 struct ngene_channel
*chan
= dvbdmx
->priv
;
187 if (!chan
->dev
->cmd_timeout_workaround
)
188 set_transfer(chan
, 0);
193 int my_dvb_dmx_ts_card_init(struct dvb_demux
*dvbdemux
, char *id
,
194 int (*start_feed
)(struct dvb_demux_feed
*),
195 int (*stop_feed
)(struct dvb_demux_feed
*),
198 dvbdemux
->priv
= priv
;
200 dvbdemux
->filternum
= 256;
201 dvbdemux
->feednum
= 256;
202 dvbdemux
->start_feed
= start_feed
;
203 dvbdemux
->stop_feed
= stop_feed
;
204 dvbdemux
->write_to_decoder
= NULL
;
205 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
206 DMX_SECTION_FILTERING
|
207 DMX_MEMORY_BASED_FILTERING
);
208 return dvb_dmx_init(dvbdemux
);
211 int my_dvb_dmxdev_ts_card_init(struct dmxdev
*dmxdev
,
212 struct dvb_demux
*dvbdemux
,
213 struct dmx_frontend
*hw_frontend
,
214 struct dmx_frontend
*mem_frontend
,
215 struct dvb_adapter
*dvb_adapter
)
219 dmxdev
->filternum
= 256;
220 dmxdev
->demux
= &dvbdemux
->dmx
;
221 dmxdev
->capabilities
= 0;
222 ret
= dvb_dmxdev_init(dmxdev
, dvb_adapter
);
226 hw_frontend
->source
= DMX_FRONTEND_0
;
227 dvbdemux
->dmx
.add_frontend(&dvbdemux
->dmx
, hw_frontend
);
228 mem_frontend
->source
= DMX_MEMORY_FE
;
229 dvbdemux
->dmx
.add_frontend(&dvbdemux
->dmx
, mem_frontend
);
230 return dvbdemux
->dmx
.connect_frontend(&dvbdemux
->dmx
, hw_frontend
);