2 * cx18 functions for DVB support
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
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"
24 #include "cx18-streams.h"
25 #include "cx18-cards.h"
29 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
31 #define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a000
33 static struct mxl5005s_config hauppauge_hvr1600_tuner = {
34 .i2c_address = 0xC6 >> 1,
35 .if_freq = IF_FREQ_5380000HZ,
36 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
37 .agc_mode = MXL_SINGLE_AGC,
38 .tracking_filter = MXL_TF_C_H,
39 .rssi_enable = MXL_RSSI_ENABLE,
40 .cap_select = MXL_CAP_SEL_ENABLE,
41 .div_out = MXL_DIV_OUT_4,
42 .clock_out = MXL_CLOCK_OUT_DISABLE,
43 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
44 .top = MXL5005S_TOP_25P2,
45 .mod_mode = MXL_DIGITAL_MODE,
46 .if_mode = MXL_ZERO_IF,
47 .AgcMasterByte = 0x00,
50 static struct s5h1409_config hauppauge_hvr1600_config = {
51 .demod_address = 0x32 >> 1,
52 .output_mode = S5H1409_SERIAL_OUTPUT,
53 .gpio = S5H1409_GPIO_ON,
55 .inversion = S5H1409_INVERSION_OFF,
56 .status_mode = S5H1409_DEMODLOCKING,
57 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
61 static int dvb_register(struct cx18_stream *stream);
63 /* Kernel DVB framework calls this when the feed needs to start.
64 * The CX18 framework should enable the transport DMA handling
65 * and queue processing.
67 static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
69 struct dvb_demux *demux = feed->demux;
70 struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
71 struct cx18 *cx = stream->cx;
75 CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
76 feed->pid, feed->index);
78 mutex_lock(&cx->serialize_lock);
79 ret = cx18_init_on_first_open(cx);
80 mutex_unlock(&cx->serialize_lock);
82 CX18_ERR("Failed to initialize firmware starting DVB feed\n");
87 switch (cx->card->type) {
88 case CX18_CARD_HVR_1600_ESMT:
89 case CX18_CARD_HVR_1600_SAMSUNG:
90 v = read_reg(CX18_REG_DMUX_NUM_PORT_0_CONTROL);
91 v |= 0x00400000; /* Serial Mode */
92 v |= 0x00002000; /* Data Length - Byte */
93 v |= 0x00010000; /* Error - Polarity */
94 v |= 0x00020000; /* Error - Passthru */
95 v |= 0x000c0000; /* Error - Ignore */
96 write_reg(v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
100 /* Assumption - Parallel transport - Signalling
101 * undefined or default.
106 if (!demux->dmx.frontend)
110 mutex_lock(&stream->dvb.feedlock);
111 if (stream->dvb.feeding++ == 0) {
112 CX18_DEBUG_INFO("Starting Transport DMA\n");
113 ret = cx18_start_v4l2_encode_stream(stream);
116 "Failed to start Transport DMA\n");
117 stream->dvb.feeding--;
121 mutex_unlock(&stream->dvb.feedlock);
127 /* Kernel DVB framework calls this when the feed needs to stop. */
128 static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
130 struct dvb_demux *demux = feed->demux;
131 struct cx18_stream *stream = (struct cx18_stream *)demux->priv;
132 struct cx18 *cx = stream->cx;
135 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
136 feed->pid, feed->index);
139 mutex_lock(&stream->dvb.feedlock);
140 if (--stream->dvb.feeding == 0) {
141 CX18_DEBUG_INFO("Stopping Transport DMA\n");
142 ret = cx18_stop_v4l2_encode_stream(stream, 0);
145 mutex_unlock(&stream->dvb.feedlock);
151 int cx18_dvb_register(struct cx18_stream *stream)
153 struct cx18 *cx = stream->cx;
154 struct cx18_dvb *dvb = &stream->dvb;
155 struct dvb_adapter *dvb_adapter;
156 struct dvb_demux *dvbdemux;
157 struct dmx_demux *dmx;
163 ret = dvb_register_adapter(&dvb->dvb_adapter,
165 THIS_MODULE, &cx->dev->dev, adapter_nr);
169 dvb_adapter = &dvb->dvb_adapter;
171 dvbdemux = &dvb->demux;
173 dvbdemux->priv = (void *)stream;
175 dvbdemux->filternum = 256;
176 dvbdemux->feednum = 256;
177 dvbdemux->start_feed = cx18_dvb_start_feed;
178 dvbdemux->stop_feed = cx18_dvb_stop_feed;
179 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
180 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
181 ret = dvb_dmx_init(dvbdemux);
183 goto err_dvb_unregister_adapter;
185 dmx = &dvbdemux->dmx;
187 dvb->hw_frontend.source = DMX_FRONTEND_0;
188 dvb->mem_frontend.source = DMX_MEMORY_FE;
189 dvb->dmxdev.filternum = 256;
190 dvb->dmxdev.demux = dmx;
192 ret = dvb_dmxdev_init(&dvb->dmxdev, dvb_adapter);
194 goto err_dvb_dmx_release;
196 ret = dmx->add_frontend(dmx, &dvb->hw_frontend);
198 goto err_dvb_dmxdev_release;
200 ret = dmx->add_frontend(dmx, &dvb->mem_frontend);
202 goto err_remove_hw_frontend;
204 ret = dmx->connect_frontend(dmx, &dvb->hw_frontend);
206 goto err_remove_mem_frontend;
208 ret = dvb_register(stream);
210 goto err_disconnect_frontend;
212 dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
214 CX18_INFO("DVB Frontend registered\n");
215 mutex_init(&dvb->feedlock);
219 err_disconnect_frontend:
220 dmx->disconnect_frontend(dmx);
221 err_remove_mem_frontend:
222 dmx->remove_frontend(dmx, &dvb->mem_frontend);
223 err_remove_hw_frontend:
224 dmx->remove_frontend(dmx, &dvb->hw_frontend);
225 err_dvb_dmxdev_release:
226 dvb_dmxdev_release(&dvb->dmxdev);
228 dvb_dmx_release(dvbdemux);
229 err_dvb_unregister_adapter:
230 dvb_unregister_adapter(dvb_adapter);
235 void cx18_dvb_unregister(struct cx18_stream *stream)
237 struct cx18 *cx = stream->cx;
238 struct cx18_dvb *dvb = &stream->dvb;
239 struct dvb_adapter *dvb_adapter;
240 struct dvb_demux *dvbdemux;
241 struct dmx_demux *dmx;
243 CX18_INFO("unregister DVB\n");
245 dvb_adapter = &dvb->dvb_adapter;
246 dvbdemux = &dvb->demux;
247 dmx = &dvbdemux->dmx;
250 dvb_net_release(&dvb->dvbnet);
251 dmx->remove_frontend(dmx, &dvb->mem_frontend);
252 dmx->remove_frontend(dmx, &dvb->hw_frontend);
253 dvb_dmxdev_release(&dvb->dmxdev);
254 dvb_dmx_release(dvbdemux);
255 dvb_unregister_frontend(dvb->fe);
256 dvb_frontend_detach(dvb->fe);
257 dvb_unregister_adapter(dvb_adapter);
260 /* All the DVB attach calls go here, this function get's modified
261 * for each new card. No other function in this file needs
264 static int dvb_register(struct cx18_stream *stream)
266 struct cx18_dvb *dvb = &stream->dvb;
267 struct cx18 *cx = stream->cx;
270 switch (cx->card->type) {
271 case CX18_CARD_HVR_1600_ESMT:
272 case CX18_CARD_HVR_1600_SAMSUNG:
273 dvb->fe = dvb_attach(s5h1409_attach,
274 &hauppauge_hvr1600_config,
276 if (dvb->fe != NULL) {
277 dvb_attach(mxl5005s_attach, dvb->fe,
279 &hauppauge_hvr1600_tuner);
284 /* No Digital Tv Support */
288 if (dvb->fe == NULL) {
289 CX18_ERR("frontend initialization failed\n");
293 ret = dvb_register_frontend(&dvb->dvb_adapter, dvb->fe);
295 if (dvb->fe->ops.release)
296 dvb->fe->ops.release(dvb->fe);