^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * pvrusb2-dvb.c - linux-dvb api interface to the pvrusb2 driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <media/dvbdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "pvrusb2-debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "pvrusb2-hdw-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "pvrusb2-hdw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "pvrusb2-io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "pvrusb2-dvb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int pvr2_dvb_feed_func(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct pvr2_buffer *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct pvr2_stream *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) pvr2_trace(PVR2_TRACE_DVB_FEED, "dvb feed thread started");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) set_freezable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) stream = adap->channel.stream->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (kthread_should_stop()) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* Not sure about this... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) bp = pvr2_stream_get_ready_buffer(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (bp != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) count = pvr2_buffer_get_count(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) dvb_dmx_swfilter(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) &adap->demux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) adap->buffer_storage[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) pvr2_buffer_get_id(bp)],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ret = pvr2_buffer_get_status(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (ret < 0) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ret = pvr2_buffer_queue(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (ret < 0) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Since we know we did something to a buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) just go back and try again. No point in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) blocking unless we really ran out of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) buffers to process. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Wait until more buffers become available or we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) told not to wait any longer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ret = wait_event_interruptible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) adap->buffer_wait_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) (pvr2_stream_get_ready_count(stream) > 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) kthread_should_stop());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ret < 0) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* If we get here and ret is < 0, then an error has occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) Probably would be a good idea to communicate that to DVB core... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) pvr2_trace(PVR2_TRACE_DVB_FEED, "dvb feed thread stopped");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int pvr2_dvb_feed_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int stat = pvr2_dvb_feed_func(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* from videobuf-dvb.c: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void pvr2_dvb_notify(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) wake_up(&adap->buffer_wait_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void pvr2_dvb_stream_end(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct pvr2_stream *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (adap->thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) kthread_stop(adap->thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) adap->thread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (adap->channel.stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) stream = adap->channel.stream->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) stream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) pvr2_hdw_set_streaming(adap->channel.hdw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pvr2_stream_set_callback(stream, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) pvr2_stream_kill(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) pvr2_stream_set_buffer_count(stream, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) pvr2_channel_claim_stream(&adap->channel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (adap->stream_run) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!(adap->buffer_storage[idx])) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) kfree(adap->buffer_storage[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) adap->buffer_storage[idx] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) adap->stream_run = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int pvr2_dvb_stream_do_start(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct pvr2_context *pvr = adap->channel.mc_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct pvr2_buffer *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct pvr2_stream *stream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (adap->stream_run) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ret = pvr2_channel_claim_stream(&adap->channel, &pvr->video_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* somebody else already has the stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret < 0) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) stream = adap->channel.stream->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) adap->buffer_storage[idx] = kmalloc(PVR2_DVB_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!(adap->buffer_storage[idx])) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) pvr2_stream_set_callback(pvr->video_stream.stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) (pvr2_stream_callback) pvr2_dvb_notify, adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ret = pvr2_stream_set_buffer_count(stream, PVR2_DVB_BUFFER_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (ret < 0) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) bp = pvr2_stream_get_buffer(stream, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) pvr2_buffer_set_buffer(bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) adap->buffer_storage[idx],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) PVR2_DVB_BUFFER_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ret = pvr2_hdw_set_streaming(adap->channel.hdw, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (ret < 0) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) while ((bp = pvr2_stream_get_idle_buffer(stream)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ret = pvr2_buffer_queue(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (ret < 0) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) adap->thread = kthread_run(pvr2_dvb_feed_thread, adap, "pvrusb2-dvb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (IS_ERR(adap->thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = PTR_ERR(adap->thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) adap->thread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) adap->stream_run = !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int pvr2_dvb_stream_start(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int ret = pvr2_dvb_stream_do_start(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (ret < 0) pvr2_dvb_stream_end(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int pvr2_dvb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct pvr2_dvb_adapter *adap = dvbdmxfeed->demux->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (adap == NULL) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) mutex_lock(&adap->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!adap->feedcount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pvr2_trace(PVR2_TRACE_DVB_FEED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) "start feeding demux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ret = pvr2_dvb_stream_start(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (ret < 0) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) (adap->feedcount)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) } else if (adap->feedcount > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) (adap->feedcount)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!adap->feedcount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pvr2_trace(PVR2_TRACE_DVB_FEED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) "stop feeding demux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pvr2_dvb_stream_end(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mutex_unlock(&adap->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int pvr2_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) pvr2_trace(PVR2_TRACE_DVB_FEED, "start pid: 0x%04x", dvbdmxfeed->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return pvr2_dvb_ctrl_feed(dvbdmxfeed, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int pvr2_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) pvr2_trace(PVR2_TRACE_DVB_FEED, "stop pid: 0x%04x", dvbdmxfeed->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return pvr2_dvb_ctrl_feed(dvbdmxfeed, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int pvr2_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct pvr2_dvb_adapter *adap = fe->dvb->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return pvr2_channel_limit_inputs(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) &adap->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) (acquire ? (1 << PVR2_CVAL_INPUT_DTV) : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int pvr2_dvb_adapter_init(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ret = dvb_register_adapter(&adap->dvb_adap, "pvrusb2-dvb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) THIS_MODULE/*&hdw->usb_dev->owner*/,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) &adap->channel.hdw->usb_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) "dvb_register_adapter failed: error %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) adap->dvb_adap.priv = adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) adap->demux.dmx.capabilities = DMX_TS_FILTERING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) DMX_SECTION_FILTERING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) DMX_MEMORY_BASED_FILTERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) adap->demux.priv = adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) adap->demux.filternum = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) adap->demux.feednum = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) adap->demux.start_feed = pvr2_dvb_start_feed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) adap->demux.stop_feed = pvr2_dvb_stop_feed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) adap->demux.write_to_decoder = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ret = dvb_dmx_init(&adap->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) "dvb_dmx_init failed: error %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto err_dmx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) adap->dmxdev.filternum = adap->demux.filternum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) adap->dmxdev.demux = &adap->demux.dmx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) adap->dmxdev.capabilities = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) "dvb_dmxdev_init failed: error %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) goto err_dmx_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dvb_net_init(&adap->dvb_adap, &adap->dvb_net, &adap->demux.dmx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) err_dmx_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) dvb_dmx_release(&adap->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) err_dmx:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dvb_unregister_adapter(&adap->dvb_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int pvr2_dvb_adapter_exit(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) pvr2_trace(PVR2_TRACE_INFO, "unregistering DVB devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dvb_net_release(&adap->dvb_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) adap->demux.dmx.close(&adap->demux.dmx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) dvb_dmxdev_release(&adap->dmxdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dvb_dmx_release(&adap->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dvb_unregister_adapter(&adap->dvb_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct pvr2_hdw *hdw = adap->channel.hdw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) const struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (dvb_props == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pvr2_trace(PVR2_TRACE_ERROR_LEGS, "fe_props not defined!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ret = pvr2_channel_limit_inputs(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) &adap->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) (1 << PVR2_CVAL_INPUT_DTV));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) "failed to grab control of dtv input (code=%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (dvb_props->frontend_attach == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) "frontend_attach not defined!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (dvb_props->frontend_attach(adap) == 0 && adap->fe[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (dvb_register_frontend(&adap->dvb_adap, adap->fe[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) "frontend registration failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) goto fail_frontend0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (adap->fe[0]->ops.analog_ops.standby)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) adap->fe[0]->ops.analog_ops.standby(adap->fe[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) pvr2_trace(PVR2_TRACE_INFO, "transferring fe[%d] ts_bus_ctrl() to pvr2_dvb_bus_ctrl()",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) adap->fe[0]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) adap->fe[0]->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) "no frontend was attached!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (dvb_props->tuner_attach && dvb_props->tuner_attach(adap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) pvr2_trace(PVR2_TRACE_ERROR_LEGS, "tuner attach failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) goto fail_tuner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (adap->fe[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) adap->fe[1]->id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) adap->fe[1]->tuner_priv = adap->fe[0]->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) memcpy(&adap->fe[1]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) &adap->fe[0]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) sizeof(struct dvb_tuner_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (dvb_register_frontend(&adap->dvb_adap, adap->fe[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) pvr2_trace(PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) "frontend registration failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) goto fail_frontend1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* MFE lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) adap->dvb_adap.mfe_shared = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (adap->fe[1]->ops.analog_ops.standby)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) adap->fe[1]->ops.analog_ops.standby(adap->fe[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) pvr2_trace(PVR2_TRACE_INFO, "transferring fe[%d] ts_bus_ctrl() to pvr2_dvb_bus_ctrl()",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) adap->fe[1]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) adap->fe[1]->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) pvr2_channel_limit_inputs(&adap->channel, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) fail_frontend1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dvb_frontend_detach(adap->fe[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) adap->fe[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) fail_tuner:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dvb_unregister_frontend(adap->fe[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) fail_frontend0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) dvb_frontend_detach(adap->fe[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) adap->fe[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dvb_module_release(adap->i2c_client_tuner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) dvb_module_release(adap->i2c_client_demod[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dvb_module_release(adap->i2c_client_demod[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int pvr2_dvb_frontend_exit(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (adap->fe[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dvb_unregister_frontend(adap->fe[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dvb_frontend_detach(adap->fe[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) adap->fe[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (adap->fe[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) dvb_unregister_frontend(adap->fe[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) dvb_frontend_detach(adap->fe[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) adap->fe[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) dvb_module_release(adap->i2c_client_tuner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) adap->i2c_client_tuner = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dvb_module_release(adap->i2c_client_demod[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) adap->i2c_client_demod[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) dvb_module_release(adap->i2c_client_demod[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) adap->i2c_client_demod[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static void pvr2_dvb_destroy(struct pvr2_dvb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) pvr2_dvb_stream_end(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) pvr2_dvb_frontend_exit(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) pvr2_dvb_adapter_exit(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pvr2_channel_done(&adap->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) kfree(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static void pvr2_dvb_internal_check(struct pvr2_channel *chp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct pvr2_dvb_adapter *adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) adap = container_of(chp, struct pvr2_dvb_adapter, channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!adap->channel.mc_head->disconnect_flag) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) pvr2_dvb_destroy(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct pvr2_dvb_adapter *pvr2_dvb_create(struct pvr2_context *pvr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct pvr2_dvb_adapter *adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (!pvr->hdw->hdw_desc->dvb_props) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* Device lacks a digital interface so don't set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) the DVB side of the driver either. For now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) adap = kzalloc(sizeof(*adap), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (!adap) return adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) pvr2_channel_init(&adap->channel, pvr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) adap->channel.check_func = pvr2_dvb_internal_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) init_waitqueue_head(&adap->buffer_wait_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) mutex_init(&adap->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ret = pvr2_dvb_adapter_init(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (ret < 0) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ret = pvr2_dvb_frontend_init(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (ret < 0) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) pvr2_dvb_adapter_exit(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) pvr2_channel_done(&adap->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)