GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / media / dvb / dvb-usb / dvb-usb-dvb.c
blobdf1ec3e69f4ac4d64156106f50607cba9ace282b
1 /* dvb-usb-dvb.c is part of the DVB USB library.
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for initializing and handling the
7 * linux-dvb API.
8 */
9 #include "dvb-usb-common.h"
11 /* does the complete input transfer handling */
12 static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
14 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
15 int newfeedcount,ret;
17 if (adap == NULL)
18 return -ENODEV;
20 newfeedcount = adap->feedcount + (onoff ? 1 : -1);
22 /* stop feed before setting a new pid if there will be no pid anymore */
23 if (newfeedcount == 0) {
24 deb_ts("stop feeding\n");
25 usb_urb_kill(&adap->stream);
27 if (adap->props.streaming_ctrl != NULL)
28 if ((ret = adap->props.streaming_ctrl(adap,0)))
29 err("error while stopping stream.");
32 adap->feedcount = newfeedcount;
34 /* activate the pid on the device specific pid_filter */
35 deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n",adap->pid_filtering ?
36 "yes" : "no", dvbdmxfeed->pid,dvbdmxfeed->pid,dvbdmxfeed->index,onoff ?
37 "on" : "off");
38 if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER &&
39 adap->pid_filtering &&
40 adap->props.pid_filter != NULL)
41 adap->props.pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid,onoff);
43 /* start the feed if this was the first feed and there is still a feed
44 * for reception.
46 if (adap->feedcount == onoff && adap->feedcount > 0) {
47 deb_ts("submitting all URBs\n");
48 usb_urb_submit(&adap->stream);
50 deb_ts("controlling pid parser\n");
51 if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER &&
52 adap->props.caps & DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF &&
53 adap->props.pid_filter_ctrl != NULL)
54 if (adap->props.pid_filter_ctrl(adap,adap->pid_filtering) < 0)
55 err("could not handle pid_parser");
57 deb_ts("start feeding\n");
58 if (adap->props.streaming_ctrl != NULL)
59 if (adap->props.streaming_ctrl(adap,1)) {
60 err("error while enabling fifo.");
61 return -ENODEV;
65 return 0;
68 static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
70 deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid,dvbdmxfeed->type);
71 return dvb_usb_ctrl_feed(dvbdmxfeed,1);
74 static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
76 deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, dvbdmxfeed->type);
77 return dvb_usb_ctrl_feed(dvbdmxfeed,0);
80 int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums)
82 int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name,
83 adap->dev->owner, &adap->dev->udev->dev,
84 adapter_nums);
86 if (ret < 0) {
87 deb_info("dvb_register_adapter failed: error %d", ret);
88 goto err;
90 adap->dvb_adap.priv = adap;
91 adap->dvb_adap.fe_ioctl_override = adap->props.fe_ioctl_override;
93 if (adap->dev->props.read_mac_address) {
94 if (adap->dev->props.read_mac_address(adap->dev,adap->dvb_adap.proposed_mac) == 0)
95 info("MAC address: %pM",adap->dvb_adap.proposed_mac);
96 else
97 err("MAC address reading failed.");
101 adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
102 adap->demux.priv = adap;
104 adap->demux.feednum = adap->demux.filternum = adap->max_feed_count;
105 adap->demux.start_feed = dvb_usb_start_feed;
106 adap->demux.stop_feed = dvb_usb_stop_feed;
107 adap->demux.write_to_decoder = NULL;
108 if ((ret = dvb_dmx_init(&adap->demux)) < 0) {
109 err("dvb_dmx_init failed: error %d",ret);
110 goto err_dmx;
113 adap->dmxdev.filternum = adap->demux.filternum;
114 adap->dmxdev.demux = &adap->demux.dmx;
115 adap->dmxdev.capabilities = 0;
116 if ((ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap)) < 0) {
117 err("dvb_dmxdev_init failed: error %d",ret);
118 goto err_dmx_dev;
121 dvb_net_init(&adap->dvb_adap, &adap->dvb_net, &adap->demux.dmx);
123 adap->state |= DVB_USB_ADAP_STATE_DVB;
124 return 0;
126 err_dmx_dev:
127 dvb_dmx_release(&adap->demux);
128 err_dmx:
129 dvb_unregister_adapter(&adap->dvb_adap);
130 err:
131 return ret;
134 int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap)
136 if (adap->state & DVB_USB_ADAP_STATE_DVB) {
137 deb_info("unregistering DVB part\n");
138 dvb_net_release(&adap->dvb_net);
139 adap->demux.dmx.close(&adap->demux.dmx);
140 dvb_dmxdev_release(&adap->dmxdev);
141 dvb_dmx_release(&adap->demux);
142 dvb_unregister_adapter(&adap->dvb_adap);
143 adap->state &= ~DVB_USB_ADAP_STATE_DVB;
145 return 0;
148 static int dvb_usb_fe_wakeup(struct dvb_frontend *fe)
150 struct dvb_usb_adapter *adap = fe->dvb->priv;
152 dvb_usb_device_power_ctrl(adap->dev, 1);
154 if (adap->fe_init)
155 adap->fe_init(fe);
157 return 0;
160 static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
162 struct dvb_usb_adapter *adap = fe->dvb->priv;
164 if (adap->fe_sleep)
165 adap->fe_sleep(fe);
167 return dvb_usb_device_power_ctrl(adap->dev, 0);
170 int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
172 if (adap->props.frontend_attach == NULL) {
173 err("strange: '%s' #%d doesn't want to attach a frontend.",adap->dev->desc->name, adap->id);
174 return 0;
177 /* re-assign sleep and wakeup functions */
178 if (adap->props.frontend_attach(adap) == 0 && adap->fe != NULL) {
179 adap->fe_init = adap->fe->ops.init; adap->fe->ops.init = dvb_usb_fe_wakeup;
180 adap->fe_sleep = adap->fe->ops.sleep; adap->fe->ops.sleep = dvb_usb_fe_sleep;
182 if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
183 err("Frontend registration failed.");
184 dvb_frontend_detach(adap->fe);
185 adap->fe = NULL;
186 return -ENODEV;
189 /* only attach the tuner if the demod is there */
190 if (adap->props.tuner_attach != NULL)
191 adap->props.tuner_attach(adap);
192 } else
193 err("no frontend was attached by '%s'",adap->dev->desc->name);
195 return 0;
198 int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap)
200 if (adap->fe != NULL) {
201 dvb_unregister_frontend(adap->fe);
202 dvb_frontend_detach(adap->fe);
204 return 0;