blob: a04c0a25062579c310c837c0ba83ff3f60e9d94c [file] [log] [blame]
Johannes Stezenbach776338e2005-06-23 22:02:35 -07001/* dvb-usb-dvb.c is part of the DVB USB library.
2 *
Patrick Boettcher99e44da2016-01-24 12:56:58 -02003 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
Johannes Stezenbach776338e2005-06-23 22:02:35 -07004 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for initializing and handling the
7 * linux-dvb API.
8 */
9#include "dvb-usb-common.h"
Mauro Carvalho Chehab41b44e32016-02-22 11:42:04 -030010#include <media/media-device.h>
Johannes Stezenbach776338e2005-06-23 22:02:35 -070011
Patrick Boettcher4d43e132006-09-30 06:53:48 -030012/* does the complete input transfer handling */
Johannes Stezenbach776338e2005-06-23 22:02:35 -070013static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
14{
Patrick Boettcher4d43e132006-09-30 06:53:48 -030015 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030016 int newfeedcount, ret;
Johannes Stezenbach776338e2005-06-23 22:02:35 -070017
Patrick Boettcher4d43e132006-09-30 06:53:48 -030018 if (adap == NULL)
Johannes Stezenbach776338e2005-06-23 22:02:35 -070019 return -ENODEV;
20
Michael Krufky2d04c132011-09-08 01:17:39 -030021 if ((adap->active_fe < 0) ||
22 (adap->active_fe >= adap->num_frontends_initialized)) {
Michael Krufky77eed212011-09-06 09:31:57 -030023 return -EINVAL;
24 }
25
Patrick Boettcher4d43e132006-09-30 06:53:48 -030026 newfeedcount = adap->feedcount + (onoff ? 1 : -1);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070027
Patrick Boettcher4d43e132006-09-30 06:53:48 -030028 /* stop feed before setting a new pid if there will be no pid anymore */
Johannes Stezenbach776338e2005-06-23 22:02:35 -070029 if (newfeedcount == 0) {
30 deb_ts("stop feeding\n");
Michael Krufky77eed212011-09-06 09:31:57 -030031 usb_urb_kill(&adap->fe_adap[adap->active_fe].stream);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070032
Michael Krufky77eed212011-09-06 09:31:57 -030033 if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) {
34 ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 0);
Malcolm Priestleydca6b742011-04-17 16:55:14 -030035 if (ret < 0) {
36 err("error while stopping stream.");
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030037 return ret;
Malcolm Priestleydca6b742011-04-17 16:55:14 -030038 }
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030039 }
Johannes Stezenbach776338e2005-06-23 22:02:35 -070040 }
41
Patrick Boettcher4d43e132006-09-30 06:53:48 -030042 adap->feedcount = newfeedcount;
Johannes Stezenbach776338e2005-06-23 22:02:35 -070043
44 /* activate the pid on the device specific pid_filter */
Michael Krufky2b7a7c32011-09-16 09:40:32 -030045 deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n",
46 adap->fe_adap[adap->active_fe].pid_filtering ?
47 "yes" : "no", dvbdmxfeed->pid, dvbdmxfeed->pid,
48 dvbdmxfeed->index, onoff ? "on" : "off");
Michael Krufky77eed212011-09-06 09:31:57 -030049 if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER &&
50 adap->fe_adap[adap->active_fe].pid_filtering &&
51 adap->props.fe[adap->active_fe].pid_filter != NULL)
52 adap->props.fe[adap->active_fe].pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid, onoff);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070053
54 /* start the feed if this was the first feed and there is still a feed
55 * for reception.
56 */
Patrick Boettcher4d43e132006-09-30 06:53:48 -030057 if (adap->feedcount == onoff && adap->feedcount > 0) {
Patrick Boettcher8126fdb2005-08-27 19:30:30 +020058 deb_ts("submitting all URBs\n");
Michael Krufky77eed212011-09-06 09:31:57 -030059 usb_urb_submit(&adap->fe_adap[adap->active_fe].stream);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070060
61 deb_ts("controlling pid parser\n");
Michael Krufky77eed212011-09-06 09:31:57 -030062 if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER &&
63 adap->props.fe[adap->active_fe].caps &
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030064 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF &&
Michael Krufky77eed212011-09-06 09:31:57 -030065 adap->props.fe[adap->active_fe].pid_filter_ctrl != NULL) {
66 ret = adap->props.fe[adap->active_fe].pid_filter_ctrl(adap,
67 adap->fe_adap[adap->active_fe].pid_filtering);
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030068 if (ret < 0) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -070069 err("could not handle pid_parser");
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030070 return ret;
Johannes Stezenbach776338e2005-06-23 22:02:35 -070071 }
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030072 }
73 deb_ts("start feeding\n");
Michael Krufky77eed212011-09-06 09:31:57 -030074 if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) {
75 ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 1);
Malcolm Priestleyc8b7ced2011-04-16 13:30:32 -030076 if (ret < 0) {
77 err("error while enabling fifo.");
78 return ret;
79 }
80 }
Johannes Stezenbach776338e2005-06-23 22:02:35 -070081
Johannes Stezenbach776338e2005-06-23 22:02:35 -070082 }
83 return 0;
84}
85
86static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
87{
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -030088 deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid,
89 dvbdmxfeed->type);
90 return dvb_usb_ctrl_feed(dvbdmxfeed, 1);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070091}
92
93static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
94{
95 deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, dvbdmxfeed->type);
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -030096 return dvb_usb_ctrl_feed(dvbdmxfeed, 0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070097}
98
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -020099static int dvb_usb_media_device_init(struct dvb_usb_adapter *adap)
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300100{
101#ifdef CONFIG_MEDIA_CONTROLLER_DVB
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300102 struct media_device *mdev;
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300103 struct dvb_usb_device *d = adap->dev;
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300104 struct usb_device *udev = d->udev;
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300105
Mauro Carvalho Chehab6cf5dad2016-02-22 12:10:49 -0300106 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
107 if (!mdev)
108 return -ENOMEM;
109
110 media_device_usb_init(mdev, udev, d->desc->name);
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200111
Mauro Carvalho Chehab89a2c1d2015-03-02 11:26:14 -0300112 dvb_register_media_controller(&adap->dvb_adap, mdev);
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300113
114 dev_info(&d->udev->dev, "media controller created\n");
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300115#endif
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200116 return 0;
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300117}
118
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200119static int dvb_usb_media_device_register(struct dvb_usb_adapter *adap)
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200120{
121#ifdef CONFIG_MEDIA_CONTROLLER_DVB
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200122 return media_device_register(adap->dvb_adap.mdev);
123#else
124 return 0;
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200125#endif
126}
127
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300128static void dvb_usb_media_device_unregister(struct dvb_usb_adapter *adap)
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300129{
130#ifdef CONFIG_MEDIA_CONTROLLER_DVB
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300131 if (!adap->dvb_adap.mdev)
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300132 return;
133
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300134 media_device_unregister(adap->dvb_adap.mdev);
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200135 media_device_cleanup(adap->dvb_adap.mdev);
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300136 kfree(adap->dvb_adap.mdev);
137 adap->dvb_adap.mdev = NULL;
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300138#endif
139}
140
Janne Grunau78e92002008-04-09 19:13:13 -0300141int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700142{
Michael Krufky77eed212011-09-06 09:31:57 -0300143 int i;
Janne Grunau78e92002008-04-09 19:13:13 -0300144 int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name,
145 adap->dev->owner, &adap->dev->udev->dev,
146 adapter_nums);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700147
Janne Grunau78e92002008-04-09 19:13:13 -0300148 if (ret < 0) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700149 deb_info("dvb_register_adapter failed: error %d", ret);
150 goto err;
151 }
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300152 adap->dvb_adap.priv = adap;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700153
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200154 ret = dvb_usb_media_device_init(adap);
155 if (ret < 0) {
156 deb_info("dvb_usb_media_device_init failed: error %d", ret);
157 goto err_mc;
158 }
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300159
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300160 if (adap->dev->props.read_mac_address) {
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -0300161 if (adap->dev->props.read_mac_address(adap->dev, adap->dvb_adap.proposed_mac) == 0)
162 info("MAC address: %pM", adap->dvb_adap.proposed_mac);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700163 else
164 err("MAC address reading failed.");
165 }
166
167
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300168 adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
169 adap->demux.priv = adap;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700170
Michael Krufky77eed212011-09-06 09:31:57 -0300171 adap->demux.filternum = 0;
172 for (i = 0; i < adap->props.num_frontends; i++) {
173 if (adap->demux.filternum < adap->fe_adap[i].max_feed_count)
174 adap->demux.filternum = adap->fe_adap[i].max_feed_count;
175 }
176 adap->demux.feednum = adap->demux.filternum;
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300177 adap->demux.start_feed = dvb_usb_start_feed;
178 adap->demux.stop_feed = dvb_usb_stop_feed;
179 adap->demux.write_to_decoder = NULL;
180 if ((ret = dvb_dmx_init(&adap->demux)) < 0) {
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -0300181 err("dvb_dmx_init failed: error %d", ret);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700182 goto err_dmx;
183 }
184
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300185 adap->dmxdev.filternum = adap->demux.filternum;
186 adap->dmxdev.demux = &adap->demux.dmx;
187 adap->dmxdev.capabilities = 0;
188 if ((ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap)) < 0) {
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -0300189 err("dvb_dmxdev_init failed: error %d", ret);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700190 goto err_dmx_dev;
191 }
192
Jonathan Nieder60826f02011-12-31 08:10:57 -0300193 if ((ret = dvb_net_init(&adap->dvb_adap, &adap->dvb_net,
194 &adap->demux.dmx)) < 0) {
Luis de Bethencourte68c2fe2015-02-04 10:42:12 -0300195 err("dvb_net_init failed: error %d", ret);
Jonathan Nieder60826f02011-12-31 08:10:57 -0300196 goto err_net_init;
197 }
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700198
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300199 adap->state |= DVB_USB_ADAP_STATE_DVB;
Trent Piepho83977032006-05-12 20:36:24 -0300200 return 0;
201
Jonathan Nieder60826f02011-12-31 08:10:57 -0300202err_net_init:
203 dvb_dmxdev_release(&adap->dmxdev);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700204err_dmx_dev:
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300205 dvb_dmx_release(&adap->demux);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700206err_dmx:
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300207 dvb_usb_media_device_unregister(adap);
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200208err_mc:
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300209 dvb_unregister_adapter(&adap->dvb_adap);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700210err:
211 return ret;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700212}
213
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300214int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700215{
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300216 if (adap->state & DVB_USB_ADAP_STATE_DVB) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700217 deb_info("unregistering DVB part\n");
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300218 dvb_net_release(&adap->dvb_net);
219 adap->demux.dmx.close(&adap->demux.dmx);
220 dvb_dmxdev_release(&adap->dmxdev);
221 dvb_dmx_release(&adap->demux);
Mauro Carvalho Chehaba3dfc6d2015-02-13 10:08:17 -0300222 dvb_usb_media_device_unregister(adap);
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300223 dvb_unregister_adapter(&adap->dvb_adap);
224 adap->state &= ~DVB_USB_ADAP_STATE_DVB;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700225 }
226 return 0;
227}
228
Michael Krufky77eed212011-09-06 09:31:57 -0300229static int dvb_usb_set_active_fe(struct dvb_frontend *fe, int onoff)
230{
231 struct dvb_usb_adapter *adap = fe->dvb->priv;
232
233 int ret = (adap->props.frontend_ctrl) ?
234 adap->props.frontend_ctrl(fe, onoff) : 0;
235
236 if (ret < 0) {
237 err("frontend_ctrl request failed");
238 return ret;
239 }
240 if (onoff)
241 adap->active_fe = fe->id;
242
243 return 0;
244}
245
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700246static int dvb_usb_fe_wakeup(struct dvb_frontend *fe)
247{
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300248 struct dvb_usb_adapter *adap = fe->dvb->priv;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700249
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300250 dvb_usb_device_power_ctrl(adap->dev, 1);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700251
Michael Krufky77eed212011-09-06 09:31:57 -0300252 dvb_usb_set_active_fe(fe, 1);
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300253
Michael Krufky77eed212011-09-06 09:31:57 -0300254 if (adap->fe_adap[fe->id].fe_init)
255 adap->fe_adap[fe->id].fe_init(fe);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700256
257 return 0;
258}
259
260static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
261{
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300262 struct dvb_usb_adapter *adap = fe->dvb->priv;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700263
Michael Krufky77eed212011-09-06 09:31:57 -0300264 if (adap->fe_adap[fe->id].fe_sleep)
265 adap->fe_adap[fe->id].fe_sleep(fe);
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300266
Michael Krufky77eed212011-09-06 09:31:57 -0300267 dvb_usb_set_active_fe(fe, 0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700268
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300269 return dvb_usb_device_power_ctrl(adap->dev, 0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700270}
271
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300272int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700273{
Michael Krufky77eed212011-09-06 09:31:57 -0300274 int ret, i;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700275
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300276 /* register all given adapter frontends */
Michael Krufky77eed212011-09-06 09:31:57 -0300277 for (i = 0; i < adap->props.num_frontends; i++) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700278
Michael Krufky77eed212011-09-06 09:31:57 -0300279 if (adap->props.fe[i].frontend_attach == NULL) {
280 err("strange: '%s' #%d,%d "
281 "doesn't want to attach a frontend.",
282 adap->dev->desc->name, adap->id, i);
283
284 return 0;
285 }
286
287 ret = adap->props.fe[i].frontend_attach(adap);
288 if (ret || adap->fe_adap[i].fe == NULL) {
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300289 /* only print error when there is no FE at all */
290 if (i == 0)
291 err("no frontend was attached by '%s'",
292 adap->dev->desc->name);
293
294 return 0;
295 }
296
Michael Krufky77eed212011-09-06 09:31:57 -0300297 adap->fe_adap[i].fe->id = i;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300298
299 /* re-assign sleep and wakeup functions */
Michael Krufky77eed212011-09-06 09:31:57 -0300300 adap->fe_adap[i].fe_init = adap->fe_adap[i].fe->ops.init;
301 adap->fe_adap[i].fe->ops.init = dvb_usb_fe_wakeup;
302 adap->fe_adap[i].fe_sleep = adap->fe_adap[i].fe->ops.sleep;
303 adap->fe_adap[i].fe->ops.sleep = dvb_usb_fe_sleep;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300304
Michael Krufky77eed212011-09-06 09:31:57 -0300305 if (dvb_register_frontend(&adap->dvb_adap, adap->fe_adap[i].fe)) {
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300306 err("Frontend %d registration failed.", i);
Michael Krufky77eed212011-09-06 09:31:57 -0300307 dvb_frontend_detach(adap->fe_adap[i].fe);
308 adap->fe_adap[i].fe = NULL;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300309 /* In error case, do not try register more FEs,
310 * still leaving already registered FEs alive. */
311 if (i == 0)
312 return -ENODEV;
313 else
314 return 0;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700315 }
Patrick Boettcher5a19f312006-08-02 08:44:31 -0300316
317 /* only attach the tuner if the demod is there */
Michael Krufky77eed212011-09-06 09:31:57 -0300318 if (adap->props.fe[i].tuner_attach != NULL)
319 adap->props.fe[i].tuner_attach(adap);
320
321 adap->num_frontends_initialized++;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300322 }
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700323
Mauro Carvalho Chehab0230d602015-12-29 11:52:23 -0200324 ret = dvb_create_media_graph(&adap->dvb_adap, true);
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200325 if (ret)
326 return ret;
Rafael Lourenço de Lima Chehab496ccf92015-02-13 18:29:14 -0300327
Mauro Carvalho Chehab9f806792015-12-28 09:55:49 -0200328 ret = dvb_usb_media_device_register(adap);
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200329
Mauro Carvalho Chehab0d3ab842015-09-04 15:33:46 -0300330 return ret;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700331}
332
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300333int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700334{
Michael Krufky77eed212011-09-06 09:31:57 -0300335 int i = adap->num_frontends_initialized - 1;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300336
337 /* unregister all given adapter frontends */
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300338 for (; i >= 0; i--) {
Michael Krufky77eed212011-09-06 09:31:57 -0300339 if (adap->fe_adap[i].fe != NULL) {
340 dvb_unregister_frontend(adap->fe_adap[i].fe);
341 dvb_frontend_detach(adap->fe_adap[i].fe);
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300342 }
Patrick Boettcher4e66c972006-08-08 15:48:11 -0300343 }
Michael Krufky77eed212011-09-06 09:31:57 -0300344 adap->num_frontends_initialized = 0;
Antti Palosaari9bd9e3b2011-07-25 20:16:13 -0300345
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700346 return 0;
347}