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