2 * cx18 functions for DVB support
4 * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "cx18-version.h"
25 #include "cx18-streams.h"
26 #include "cx18-cards.h"
30 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
32 #define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a000
34 static struct mxl5005s_config hauppauge_hvr1600_tuner = {
35 .i2c_address = 0xC6 >> 1,
36 .if_freq = IF_FREQ_5380000HZ,
37 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
38 .agc_mode = MXL_SINGLE_AGC,
39 .tracking_filter = MXL_TF_C_H,
40 .rssi_enable = MXL_RSSI_ENABLE,
41 .cap_select = MXL_CAP_SEL_ENABLE,
42 .div_out = MXL_DIV_OUT_4,
43 .clock_out = MXL_CLOCK_OUT_DISABLE,
44 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
45 .top = MXL5005S_TOP_25P2,
46 .mod_mode = MXL_DIGITAL_MODE,
47 .if_mode = MXL_ZERO_IF,
48 .AgcMasterByte = 0x00,
51 static struct s5h1409_config hauppauge_hvr1600_config = {
52 .demod_address = 0x32 >> 1,
53 .output_mode = S5H1409_SERIAL_OUTPUT,
54 .gpio = S5H1409_GPIO_ON,
56 .inversion = S5H1409_INVERSION_OFF,
57 .status_mode = S5H1409_DEMODLOCKING,
58 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
62 static int dvb_register(struct cx18_stream *stream);
64 /* Kernel DVB framework calls this when the feed needs to start.
65 * The CX18 framework should enable the transport DMA handling
66 * and queue processing.
68 static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
70 struct dvb_demux *demux = feed->demux;
71 struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
72 struct cx18 *cx = stream->cx;
76 CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
77 feed->pid, feed->index);
79 mutex_lock(&cx->serialize_lock);
80 ret = cx18_init_on_first_open(cx);
81 mutex_unlock(&cx->serialize_lock);
83 CX18_ERR("Failed to initialize firmware starting DVB feed\n");
88 switch (cx->card->type) {
89 case CX18_CARD_HVR_1600_ESMT:
90 case CX18_CARD_HVR_1600_SAMSUNG:
91 v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
92 v |= 0x00400000; /* Serial Mode */
93 v |= 0x00002000; /* Data Length - Byte */
94 v |= 0x00010000; /* Error - Polarity */
95 v |= 0x00020000; /* Error - Passthru */
96 v |= 0x000c0000; /* Error - Ignore */
97 cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
101 /* Assumption - Parallel transport - Signalling
102 * undefined or default.
107 if (!demux->dmx.frontend)
111 mutex_lock(&stream->dvb.feedlock);
112 if (stream->dvb.feeding++ == 0) {
113 CX18_DEBUG_INFO("Starting Transport DMA\n");
114 ret = cx18_start_v4l2_encode_stream(stream);
117 "Failed to start Transport DMA\n");
118 stream->dvb.feeding--;
122 mutex_unlock(&stream->dvb.feedlock);
128 /* Kernel DVB framework calls this when the feed needs to stop. */
129 static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
131 struct dvb_demux *demux = feed->demux;
132 struct cx18_stream *stream = (struct cx18_stream *)demux->priv;
133 struct cx18 *cx = stream->cx;
136 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
137 feed->pid, feed->index);
140 mutex_lock(&stream->dvb.feedlock);
141 if (--stream->dvb.feeding == 0) {
142 CX18_DEBUG_INFO("Stopping Transport DMA\n");
143 ret = cx18_stop_v4l2_encode_stream(stream, 0);
146 mutex_unlock(&stream->dvb.feedlock);
152 int cx18_dvb_register(struct cx18_stream *stream)
154 struct cx18 *cx = stream->cx;
155 struct cx18_dvb *dvb = &stream->dvb;
156 struct dvb_adapter *dvb_adapter;
157 struct dvb_demux *dvbdemux;
158 struct dmx_demux *dmx;
164 ret = dvb_register_adapter(&dvb->dvb_adapter,
166 THIS_MODULE, &cx->dev->dev, adapter_nr);
170 dvb_adapter = &dvb->dvb_adapter;
172 dvbdemux = &dvb->demux;
174 dvbdemux->priv = (void *)stream;
176 dvbdemux->filternum = 256;
177 dvbdemux->feednum = 256;
178 dvbdemux->start_feed = cx18_dvb_start_feed;
179 dvbdemux->stop_feed = cx18_dvb_stop_feed;
180 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
181 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
182 ret = dvb_dmx_init(dvbdemux);
184 goto err_dvb_unregister_adapter;
186 dmx = &dvbdemux->dmx;
188 dvb->hw_frontend.source = DMX_FRONTEND_0;
189 dvb->mem_frontend.source = DMX_MEMORY_FE;
190 dvb->dmxdev.filternum = 256;
191 dvb->dmxdev.demux = dmx;
193 ret = dvb_dmxdev_init(&dvb->dmxdev, dvb_adapter);
195 goto err_dvb_dmx_release;
197 ret = dmx->add_frontend(dmx, &dvb->hw_frontend);
199 goto err_dvb_dmxdev_release;
201 ret = dmx->add_frontend(dmx, &dvb->mem_frontend);
203 goto err_remove_hw_frontend;
205 ret = dmx->connect_frontend(dmx, &dvb->hw_frontend);
207 goto err_remove_mem_frontend;
209 ret = dvb_register(stream);
211 goto err_disconnect_frontend;
213 dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
215 CX18_INFO("DVB Frontend registered\n");
216 mutex_init(&dvb->feedlock);
220 err_disconnect_frontend:
221 dmx->disconnect_frontend(dmx);
222 err_remove_mem_frontend:
223 dmx->remove_frontend(dmx, &dvb->mem_frontend);
224 err_remove_hw_frontend:
225 dmx->remove_frontend(dmx, &dvb->hw_frontend);
226 err_dvb_dmxdev_release:
227 dvb_dmxdev_release(&dvb->dmxdev);
229 dvb_dmx_release(dvbdemux);
230 err_dvb_unregister_adapter:
231 dvb_unregister_adapter(dvb_adapter);
236 void cx18_dvb_unregister(struct cx18_stream *stream)
238 struct cx18 *cx = stream->cx;
239 struct cx18_dvb *dvb = &stream->dvb;
240 struct dvb_adapter *dvb_adapter;
241 struct dvb_demux *dvbdemux;
242 struct dmx_demux *dmx;
244 CX18_INFO("unregister DVB\n");
246 dvb_adapter = &dvb->dvb_adapter;
247 dvbdemux = &dvb->demux;
248 dmx = &dvbdemux->dmx;
251 dvb_net_release(&dvb->dvbnet);
252 dmx->remove_frontend(dmx, &dvb->mem_frontend);
253 dmx->remove_frontend(dmx, &dvb->hw_frontend);
254 dvb_dmxdev_release(&dvb->dmxdev);
255 dvb_dmx_release(dvbdemux);
256 dvb_unregister_frontend(dvb->fe);
257 dvb_frontend_detach(dvb->fe);
258 dvb_unregister_adapter(dvb_adapter);
261 /* All the DVB attach calls go here, this function get's modified
262 * for each new card. No other function in this file needs
265 static int dvb_register(struct cx18_stream *stream)
267 struct cx18_dvb *dvb = &stream->dvb;
268 struct cx18 *cx = stream->cx;
271 switch (cx->card->type) {
272 case CX18_CARD_HVR_1600_ESMT:
273 case CX18_CARD_HVR_1600_SAMSUNG:
274 dvb->fe = dvb_attach(s5h1409_attach,
275 &hauppauge_hvr1600_config,
277 if (dvb->fe != NULL) {
278 dvb_attach(mxl5005s_attach, dvb->fe,
280 &hauppauge_hvr1600_tuner);
285 /* No Digital Tv Support */
289 if (dvb->fe == NULL) {
290 CX18_ERR("frontend initialization failed\n");
294 ret = dvb_register_frontend(&dvb->dvb_adapter, dvb->fe);
296 if (dvb->fe->ops.release)
297 dvb->fe->ops.release(dvb->fe);