2008-02-04 02:46:16 +00:00
|
|
|
/*
|
|
|
|
* pvrusb2-dvb.c - linux-dvb api interface to the pvrusb2 driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-02-04 02:55:07 +00:00
|
|
|
#include <linux/kthread.h>
|
2008-02-04 03:00:19 +00:00
|
|
|
#include <linux/freezer.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-07-24 04:28:13 +00:00
|
|
|
#include <linux/mm.h>
|
2008-02-04 02:46:16 +00:00
|
|
|
#include "dvbdev.h"
|
2008-04-26 22:44:59 +00:00
|
|
|
#include "pvrusb2-debug.h"
|
2008-02-04 02:46:16 +00:00
|
|
|
#include "pvrusb2-hdw-internal.h"
|
|
|
|
#include "pvrusb2-hdw.h"
|
2008-02-04 03:00:19 +00:00
|
|
|
#include "pvrusb2-io.h"
|
2008-02-04 02:46:16 +00:00
|
|
|
#include "pvrusb2-dvb.h"
|
|
|
|
|
|
|
|
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
|
|
|
|
|
2008-02-06 07:24:51 +00:00
|
|
|
static int pvr2_dvb_feed_func(struct pvr2_dvb_adapter *adap)
|
2008-02-04 03:00:19 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned int count;
|
|
|
|
struct pvr2_buffer *bp;
|
2008-02-06 09:59:48 +00:00
|
|
|
struct pvr2_stream *stream;
|
2008-02-04 03:00:19 +00:00
|
|
|
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED, "dvb feed thread started");
|
2008-02-04 03:00:19 +00:00
|
|
|
set_freezable();
|
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
stream = adap->channel.stream->stream;
|
2008-02-04 03:00:19 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2008-02-06 09:59:48 +00:00
|
|
|
if (kthread_should_stop()) break;
|
2008-02-04 03:00:19 +00:00
|
|
|
|
|
|
|
/* Not sure about this... */
|
|
|
|
try_to_freeze();
|
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
bp = pvr2_stream_get_ready_buffer(stream);
|
2008-02-04 03:00:19 +00:00
|
|
|
if (bp != NULL) {
|
|
|
|
count = pvr2_buffer_get_count(bp);
|
|
|
|
if (count) {
|
|
|
|
dvb_dmx_swfilter(
|
|
|
|
&adap->demux,
|
2008-02-06 09:59:48 +00:00
|
|
|
adap->buffer_storage[
|
|
|
|
pvr2_buffer_get_id(bp)],
|
2008-02-04 03:00:19 +00:00
|
|
|
count);
|
|
|
|
} else {
|
|
|
|
ret = pvr2_buffer_get_status(bp);
|
2008-02-06 09:59:48 +00:00
|
|
|
if (ret < 0) break;
|
2008-02-04 03:00:19 +00:00
|
|
|
}
|
|
|
|
ret = pvr2_buffer_queue(bp);
|
2008-02-06 09:59:48 +00:00
|
|
|
if (ret < 0) break;
|
2008-02-04 03:00:19 +00:00
|
|
|
|
|
|
|
/* Since we know we did something to a buffer,
|
|
|
|
just go back and try again. No point in
|
|
|
|
blocking unless we really ran out of
|
|
|
|
buffers to process. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-30 23:36:31 +00:00
|
|
|
/* Wait until more buffers become available or we're
|
|
|
|
told not to wait any longer. */
|
2008-02-04 03:00:19 +00:00
|
|
|
ret = wait_event_interruptible(
|
2008-02-06 09:59:48 +00:00
|
|
|
adap->buffer_wait_data,
|
2008-03-30 23:36:31 +00:00
|
|
|
(pvr2_stream_get_ready_count(stream) > 0) ||
|
2008-04-07 05:57:13 +00:00
|
|
|
kthread_should_stop());
|
2008-02-06 09:59:48 +00:00
|
|
|
if (ret < 0) break;
|
2008-02-04 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here and ret is < 0, then an error has occurred.
|
|
|
|
Probably would be a good idea to communicate that to DVB core... */
|
|
|
|
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED, "dvb feed thread stopped");
|
2008-02-04 03:00:19 +00:00
|
|
|
|
2008-02-06 07:24:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_feed_thread(void *data)
|
|
|
|
{
|
|
|
|
int stat = pvr2_dvb_feed_func(data);
|
2008-02-04 03:00:19 +00:00
|
|
|
/* from videobuf-dvb.c: */
|
|
|
|
while (!kthread_should_stop()) {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
schedule();
|
|
|
|
}
|
2008-02-06 07:24:51 +00:00
|
|
|
return stat;
|
2008-02-04 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
static void pvr2_dvb_notify(struct pvr2_dvb_adapter *adap)
|
2008-02-04 02:55:07 +00:00
|
|
|
{
|
2008-02-06 09:59:48 +00:00
|
|
|
wake_up(&adap->buffer_wait_data);
|
|
|
|
}
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
static void pvr2_dvb_stream_end(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
unsigned int idx;
|
|
|
|
struct pvr2_stream *stream;
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
if (adap->thread) {
|
|
|
|
kthread_stop(adap->thread);
|
|
|
|
adap->thread = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adap->channel.stream) {
|
|
|
|
stream = adap->channel.stream->stream;
|
|
|
|
} else {
|
|
|
|
stream = NULL;
|
|
|
|
}
|
|
|
|
if (stream) {
|
|
|
|
pvr2_hdw_set_streaming(adap->channel.hdw, 0);
|
|
|
|
pvr2_stream_set_callback(stream, NULL, NULL);
|
|
|
|
pvr2_stream_kill(stream);
|
|
|
|
pvr2_stream_set_buffer_count(stream, 0);
|
|
|
|
pvr2_channel_claim_stream(&adap->channel, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adap->stream_run) {
|
|
|
|
for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
|
|
|
|
if (!(adap->buffer_storage[idx])) continue;
|
|
|
|
kfree(adap->buffer_storage[idx]);
|
2008-04-28 23:50:03 +00:00
|
|
|
adap->buffer_storage[idx] = NULL;
|
2008-02-06 09:59:48 +00:00
|
|
|
}
|
|
|
|
adap->stream_run = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_stream_do_start(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
struct pvr2_context *pvr = adap->channel.mc_head;
|
|
|
|
unsigned int idx;
|
|
|
|
int ret;
|
|
|
|
struct pvr2_buffer *bp;
|
2008-04-28 23:50:03 +00:00
|
|
|
struct pvr2_stream *stream = NULL;
|
2008-02-06 09:59:48 +00:00
|
|
|
|
|
|
|
if (adap->stream_run) return -EIO;
|
|
|
|
|
|
|
|
ret = pvr2_channel_claim_stream(&adap->channel, &pvr->video_stream);
|
|
|
|
/* somebody else already has the stream */
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
|
|
|
|
stream = adap->channel.stream->stream;
|
|
|
|
|
|
|
|
for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
|
|
|
|
adap->buffer_storage[idx] = kmalloc(PVR2_DVB_BUFFER_SIZE,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!(adap->buffer_storage[idx])) return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
pvr2_stream_set_callback(pvr->video_stream.stream,
|
|
|
|
(pvr2_stream_callback) pvr2_dvb_notify, adap);
|
|
|
|
|
|
|
|
ret = pvr2_stream_set_buffer_count(stream, PVR2_DVB_BUFFER_COUNT);
|
|
|
|
if (ret < 0) return ret;
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
|
|
|
|
bp = pvr2_stream_get_buffer(stream, idx);
|
|
|
|
pvr2_buffer_set_buffer(bp,
|
|
|
|
adap->buffer_storage[idx],
|
|
|
|
PVR2_DVB_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pvr2_hdw_set_streaming(adap->channel.hdw, 1);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
|
2008-04-28 23:50:03 +00:00
|
|
|
while ((bp = pvr2_stream_get_idle_buffer(stream)) != NULL) {
|
2008-02-06 09:59:48 +00:00
|
|
|
ret = pvr2_buffer_queue(bp);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
}
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
adap->thread = kthread_run(pvr2_dvb_feed_thread, adap, "pvrusb2-dvb");
|
|
|
|
|
|
|
|
if (IS_ERR(adap->thread)) {
|
|
|
|
ret = PTR_ERR(adap->thread);
|
2008-02-04 02:55:07 +00:00
|
|
|
adap->thread = NULL;
|
2008-02-06 09:59:48 +00:00
|
|
|
return ret;
|
2008-02-04 02:55:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
adap->stream_run = !0;
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
static int pvr2_dvb_stream_start(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
int ret = pvr2_dvb_stream_do_start(adap);
|
|
|
|
if (ret < 0) pvr2_dvb_stream_end(adap);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-04 02:55:07 +00:00
|
|
|
|
2008-02-06 09:59:48 +00:00
|
|
|
static int pvr2_dvb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
|
|
|
|
{
|
|
|
|
struct pvr2_dvb_adapter *adap = dvbdmxfeed->demux->priv;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (adap == NULL) return -ENODEV;
|
|
|
|
|
|
|
|
mutex_lock(&adap->lock);
|
|
|
|
do {
|
|
|
|
if (onoff) {
|
|
|
|
if (!adap->feedcount) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED,
|
|
|
|
"start feeding demux");
|
2008-02-06 09:59:48 +00:00
|
|
|
ret = pvr2_dvb_stream_start(adap);
|
|
|
|
if (ret < 0) break;
|
|
|
|
}
|
|
|
|
(adap->feedcount)++;
|
|
|
|
} else if (adap->feedcount > 0) {
|
|
|
|
(adap->feedcount)--;
|
|
|
|
if (!adap->feedcount) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED,
|
|
|
|
"stop feeding demux");
|
2008-02-06 09:59:48 +00:00
|
|
|
pvr2_dvb_stream_end(adap);
|
|
|
|
}
|
2008-02-04 02:55:07 +00:00
|
|
|
}
|
2008-02-06 09:59:48 +00:00
|
|
|
} while (0);
|
2008-02-04 02:55:07 +00:00
|
|
|
mutex_unlock(&adap->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-04 02:46:16 +00:00
|
|
|
static int pvr2_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
|
|
|
|
{
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED, "start pid: 0x%04x", dvbdmxfeed->pid);
|
2008-02-04 02:55:07 +00:00
|
|
|
return pvr2_dvb_ctrl_feed(dvbdmxfeed, 1);
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
|
|
|
|
{
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_DVB_FEED, "stop pid: 0x%04x", dvbdmxfeed->pid);
|
2008-02-04 02:55:07 +00:00
|
|
|
return pvr2_dvb_ctrl_feed(dvbdmxfeed, 0);
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-04 02:48:09 +00:00
|
|
|
static int pvr2_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
|
|
|
|
{
|
2008-04-21 06:47:43 +00:00
|
|
|
struct pvr2_dvb_adapter *adap = fe->dvb->priv;
|
|
|
|
return pvr2_channel_limit_inputs(
|
|
|
|
&adap->channel,
|
|
|
|
(acquire ? (1 << PVR2_CVAL_INPUT_DTV) : 0));
|
2008-02-04 02:48:09 +00:00
|
|
|
}
|
|
|
|
|
2008-02-04 02:46:16 +00:00
|
|
|
static int pvr2_dvb_adapter_init(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dvb_register_adapter(&adap->dvb_adap, "pvrusb2-dvb",
|
|
|
|
THIS_MODULE/*&hdw->usb_dev->owner*/,
|
2008-02-06 09:59:48 +00:00
|
|
|
&adap->channel.hdw->usb_dev->dev,
|
2008-02-04 02:46:16 +00:00
|
|
|
adapter_nr);
|
|
|
|
if (ret < 0) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"dvb_register_adapter failed: error %d", ret);
|
2008-02-04 02:46:16 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
adap->dvb_adap.priv = adap;
|
|
|
|
|
|
|
|
adap->demux.dmx.capabilities = DMX_TS_FILTERING |
|
|
|
|
DMX_SECTION_FILTERING |
|
|
|
|
DMX_MEMORY_BASED_FILTERING;
|
|
|
|
adap->demux.priv = adap;
|
|
|
|
adap->demux.filternum = 256;
|
|
|
|
adap->demux.feednum = 256;
|
|
|
|
adap->demux.start_feed = pvr2_dvb_start_feed;
|
|
|
|
adap->demux.stop_feed = pvr2_dvb_stop_feed;
|
|
|
|
adap->demux.write_to_decoder = NULL;
|
|
|
|
|
|
|
|
ret = dvb_dmx_init(&adap->demux);
|
|
|
|
if (ret < 0) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"dvb_dmx_init failed: error %d", ret);
|
2008-02-04 02:46:16 +00:00
|
|
|
goto err_dmx;
|
|
|
|
}
|
|
|
|
|
|
|
|
adap->dmxdev.filternum = adap->demux.filternum;
|
|
|
|
adap->dmxdev.demux = &adap->demux.dmx;
|
|
|
|
adap->dmxdev.capabilities = 0;
|
|
|
|
|
|
|
|
ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap);
|
|
|
|
if (ret < 0) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"dvb_dmxdev_init failed: error %d", ret);
|
2008-02-04 02:46:16 +00:00
|
|
|
goto err_dmx_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
dvb_net_init(&adap->dvb_adap, &adap->dvb_net, &adap->demux.dmx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_dmx_dev:
|
|
|
|
dvb_dmx_release(&adap->demux);
|
|
|
|
err_dmx:
|
|
|
|
dvb_unregister_adapter(&adap->dvb_adap);
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_adapter_exit(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_INFO, "unregistering DVB devices");
|
2008-02-09 18:55:54 +00:00
|
|
|
dvb_net_release(&adap->dvb_net);
|
|
|
|
adap->demux.dmx.close(&adap->demux.dmx);
|
|
|
|
dvb_dmxdev_release(&adap->dmxdev);
|
|
|
|
dvb_dmx_release(&adap->demux);
|
|
|
|
dvb_unregister_adapter(&adap->dvb_adap);
|
2008-02-04 02:46:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
2008-02-06 09:59:48 +00:00
|
|
|
struct pvr2_hdw *hdw = adap->channel.hdw;
|
2009-03-07 05:08:58 +00:00
|
|
|
const struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props;
|
2008-04-21 06:47:43 +00:00
|
|
|
int ret = 0;
|
2008-02-04 02:46:16 +00:00
|
|
|
|
|
|
|
if (dvb_props == NULL) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS, "fe_props not defined!");
|
2008-02-04 02:46:16 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-04-21 06:47:43 +00:00
|
|
|
ret = pvr2_channel_limit_inputs(
|
|
|
|
&adap->channel,
|
|
|
|
(1 << PVR2_CVAL_INPUT_DTV));
|
|
|
|
if (ret) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"failed to grab control of dtv input (code=%d)",
|
2008-04-21 06:47:43 +00:00
|
|
|
ret);
|
2008-02-10 08:33:37 +00:00
|
|
|
return ret;
|
2008-04-21 06:47:43 +00:00
|
|
|
}
|
2008-02-10 08:33:37 +00:00
|
|
|
|
2008-02-04 02:46:16 +00:00
|
|
|
if (dvb_props->frontend_attach == NULL) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"frontend_attach not defined!");
|
2008-04-21 06:47:43 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((dvb_props->frontend_attach(adap) == 0) && (adap->fe)) {
|
|
|
|
|
|
|
|
if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"frontend registration failed!");
|
2008-02-04 02:46:16 +00:00
|
|
|
dvb_frontend_detach(adap->fe);
|
|
|
|
adap->fe = NULL;
|
2008-04-21 06:47:43 +00:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dvb_props->tuner_attach)
|
|
|
|
dvb_props->tuner_attach(adap);
|
|
|
|
|
|
|
|
if (adap->fe->ops.analog_ops.standby)
|
|
|
|
adap->fe->ops.analog_ops.standby(adap->fe);
|
|
|
|
|
2008-02-04 02:48:09 +00:00
|
|
|
/* Ensure all frontends negotiate bus access */
|
|
|
|
adap->fe->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
|
|
|
|
|
2008-02-04 02:46:16 +00:00
|
|
|
} else {
|
2008-04-26 22:44:59 +00:00
|
|
|
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
|
|
|
|
"no frontend was attached!");
|
2008-04-21 06:47:43 +00:00
|
|
|
ret = -ENODEV;
|
|
|
|
return ret;
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
2008-04-21 06:47:43 +00:00
|
|
|
done:
|
|
|
|
pvr2_channel_limit_inputs(&adap->channel, 0);
|
|
|
|
return ret;
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pvr2_dvb_frontend_exit(struct pvr2_dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
if (adap->fe != NULL) {
|
|
|
|
dvb_unregister_frontend(adap->fe);
|
|
|
|
dvb_frontend_detach(adap->fe);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-09 22:47:07 +00:00
|
|
|
static void pvr2_dvb_destroy(struct pvr2_dvb_adapter *adap)
|
2008-02-09 18:44:30 +00:00
|
|
|
{
|
|
|
|
pvr2_dvb_stream_end(adap);
|
|
|
|
pvr2_dvb_frontend_exit(adap);
|
|
|
|
pvr2_dvb_adapter_exit(adap);
|
|
|
|
pvr2_channel_done(&adap->channel);
|
2008-02-09 22:47:07 +00:00
|
|
|
kfree(adap);
|
2008-02-09 18:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pvr2_dvb_internal_check(struct pvr2_channel *chp)
|
|
|
|
{
|
|
|
|
struct pvr2_dvb_adapter *adap;
|
|
|
|
adap = container_of(chp, struct pvr2_dvb_adapter, channel);
|
|
|
|
if (!adap->channel.mc_head->disconnect_flag) return;
|
2008-02-09 22:47:07 +00:00
|
|
|
pvr2_dvb_destroy(adap);
|
2008-02-09 18:44:30 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 22:47:07 +00:00
|
|
|
struct pvr2_dvb_adapter *pvr2_dvb_create(struct pvr2_context *pvr)
|
2008-02-04 02:46:16 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-02-06 09:59:48 +00:00
|
|
|
struct pvr2_dvb_adapter *adap;
|
2008-02-09 19:29:52 +00:00
|
|
|
if (!pvr->hdw->hdw_desc->dvb_props) {
|
|
|
|
/* Device lacks a digital interface so don't set up
|
|
|
|
the DVB side of the driver either. For now. */
|
2008-02-09 22:47:52 +00:00
|
|
|
return NULL;
|
2008-02-09 19:29:52 +00:00
|
|
|
}
|
2008-02-09 22:47:07 +00:00
|
|
|
adap = kzalloc(sizeof(*adap), GFP_KERNEL);
|
|
|
|
if (!adap) return adap;
|
2008-02-06 09:59:48 +00:00
|
|
|
pvr2_channel_init(&adap->channel, pvr);
|
2008-02-09 18:44:30 +00:00
|
|
|
adap->channel.check_func = pvr2_dvb_internal_check;
|
2008-02-06 09:59:48 +00:00
|
|
|
init_waitqueue_head(&adap->buffer_wait_data);
|
2008-02-09 22:47:07 +00:00
|
|
|
mutex_init(&adap->lock);
|
|
|
|
ret = pvr2_dvb_adapter_init(adap);
|
2008-02-09 19:29:52 +00:00
|
|
|
if (ret < 0) goto fail1;
|
2008-02-09 22:47:07 +00:00
|
|
|
ret = pvr2_dvb_frontend_init(adap);
|
2008-02-09 19:29:52 +00:00
|
|
|
if (ret < 0) goto fail2;
|
2008-02-09 22:47:07 +00:00
|
|
|
return adap;
|
2008-02-09 19:29:52 +00:00
|
|
|
|
|
|
|
fail2:
|
|
|
|
pvr2_dvb_adapter_exit(adap);
|
|
|
|
fail1:
|
2008-02-09 18:44:30 +00:00
|
|
|
pvr2_channel_done(&adap->channel);
|
2008-02-09 22:47:07 +00:00
|
|
|
return NULL;
|
2008-02-04 02:46:16 +00:00
|
|
|
}
|
|
|
|
|