Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 1 | /* dvb-usb-dvb.c is part of the DVB USB library. |
| 2 | * |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 3 | * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 4 | * 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" |
| 10 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 11 | /* does the complete input transfer handling */ |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 12 | static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) |
| 13 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 14 | struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 15 | int newfeedcount, ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 16 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 17 | if (adap == NULL) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 18 | return -ENODEV; |
| 19 | |
Michael Krufky | 2d04c13 | 2011-09-08 01:17:39 -0300 | [diff] [blame] | 20 | if ((adap->active_fe < 0) || |
| 21 | (adap->active_fe >= adap->num_frontends_initialized)) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 22 | return -EINVAL; |
| 23 | } |
| 24 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 25 | newfeedcount = adap->feedcount + (onoff ? 1 : -1); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 26 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 27 | /* stop feed before setting a new pid if there will be no pid anymore */ |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 28 | if (newfeedcount == 0) { |
| 29 | deb_ts("stop feeding\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 30 | usb_urb_kill(&adap->fe_adap[adap->active_fe].stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 31 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 32 | if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) { |
| 33 | ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 0); |
Malcolm Priestley | dca6b74 | 2011-04-17 16:55:14 -0300 | [diff] [blame] | 34 | if (ret < 0) { |
| 35 | err("error while stopping stream."); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 36 | return ret; |
Malcolm Priestley | dca6b74 | 2011-04-17 16:55:14 -0300 | [diff] [blame] | 37 | } |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 38 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 41 | adap->feedcount = newfeedcount; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 42 | |
| 43 | /* activate the pid on the device specific pid_filter */ |
Michael Krufky | 2b7a7c3 | 2011-09-16 09:40:32 -0300 | [diff] [blame] | 44 | deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n", |
| 45 | adap->fe_adap[adap->active_fe].pid_filtering ? |
| 46 | "yes" : "no", dvbdmxfeed->pid, dvbdmxfeed->pid, |
| 47 | dvbdmxfeed->index, onoff ? "on" : "off"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 48 | if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER && |
| 49 | adap->fe_adap[adap->active_fe].pid_filtering && |
| 50 | adap->props.fe[adap->active_fe].pid_filter != NULL) |
| 51 | adap->props.fe[adap->active_fe].pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid, onoff); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 52 | |
| 53 | /* start the feed if this was the first feed and there is still a feed |
| 54 | * for reception. |
| 55 | */ |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 56 | if (adap->feedcount == onoff && adap->feedcount > 0) { |
Patrick Boettcher | 8126fdb | 2005-08-27 19:30:30 +0200 | [diff] [blame] | 57 | deb_ts("submitting all URBs\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 58 | usb_urb_submit(&adap->fe_adap[adap->active_fe].stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 59 | |
| 60 | deb_ts("controlling pid parser\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 61 | if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER && |
| 62 | adap->props.fe[adap->active_fe].caps & |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 63 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 64 | adap->props.fe[adap->active_fe].pid_filter_ctrl != NULL) { |
| 65 | ret = adap->props.fe[adap->active_fe].pid_filter_ctrl(adap, |
| 66 | adap->fe_adap[adap->active_fe].pid_filtering); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 67 | if (ret < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 68 | err("could not handle pid_parser"); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 69 | return ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 70 | } |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 71 | } |
| 72 | deb_ts("start feeding\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 73 | if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) { |
| 74 | ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 1); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 75 | if (ret < 0) { |
| 76 | err("error while enabling fifo."); |
| 77 | return ret; |
| 78 | } |
| 79 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 80 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed) |
| 86 | { |
| 87 | deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid,dvbdmxfeed->type); |
| 88 | return dvb_usb_ctrl_feed(dvbdmxfeed,1); |
| 89 | } |
| 90 | |
| 91 | static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) |
| 92 | { |
| 93 | deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, dvbdmxfeed->type); |
| 94 | return dvb_usb_ctrl_feed(dvbdmxfeed,0); |
| 95 | } |
| 96 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 97 | int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 98 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 99 | int i; |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 100 | int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name, |
| 101 | adap->dev->owner, &adap->dev->udev->dev, |
| 102 | adapter_nums); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 103 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 104 | if (ret < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 105 | deb_info("dvb_register_adapter failed: error %d", ret); |
| 106 | goto err; |
| 107 | } |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 108 | adap->dvb_adap.priv = adap; |
Michael Krufky | 94d9831 | 2009-09-07 13:32:29 -0300 | [diff] [blame] | 109 | adap->dvb_adap.fe_ioctl_override = adap->props.fe_ioctl_override; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 110 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 111 | if (adap->dev->props.read_mac_address) { |
| 112 | if (adap->dev->props.read_mac_address(adap->dev,adap->dvb_adap.proposed_mac) == 0) |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 113 | info("MAC address: %pM",adap->dvb_adap.proposed_mac); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 114 | else |
| 115 | err("MAC address reading failed."); |
| 116 | } |
| 117 | |
| 118 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 119 | adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING; |
| 120 | adap->demux.priv = adap; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 121 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 122 | adap->demux.filternum = 0; |
| 123 | for (i = 0; i < adap->props.num_frontends; i++) { |
| 124 | if (adap->demux.filternum < adap->fe_adap[i].max_feed_count) |
| 125 | adap->demux.filternum = adap->fe_adap[i].max_feed_count; |
| 126 | } |
| 127 | adap->demux.feednum = adap->demux.filternum; |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 128 | adap->demux.start_feed = dvb_usb_start_feed; |
| 129 | adap->demux.stop_feed = dvb_usb_stop_feed; |
| 130 | adap->demux.write_to_decoder = NULL; |
| 131 | if ((ret = dvb_dmx_init(&adap->demux)) < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 132 | err("dvb_dmx_init failed: error %d",ret); |
| 133 | goto err_dmx; |
| 134 | } |
| 135 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 136 | adap->dmxdev.filternum = adap->demux.filternum; |
| 137 | adap->dmxdev.demux = &adap->demux.dmx; |
| 138 | adap->dmxdev.capabilities = 0; |
| 139 | if ((ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap)) < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 140 | err("dvb_dmxdev_init failed: error %d",ret); |
| 141 | goto err_dmx_dev; |
| 142 | } |
| 143 | |
Jonathan Nieder | 60826f0 | 2011-12-31 08:10:57 -0300 | [diff] [blame^] | 144 | if ((ret = dvb_net_init(&adap->dvb_adap, &adap->dvb_net, |
| 145 | &adap->demux.dmx)) < 0) { |
| 146 | err("dvb_net_init failed: error %d",ret); |
| 147 | goto err_net_init; |
| 148 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 149 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 150 | adap->state |= DVB_USB_ADAP_STATE_DVB; |
Trent Piepho | 8397703 | 2006-05-12 20:36:24 -0300 | [diff] [blame] | 151 | return 0; |
| 152 | |
Jonathan Nieder | 60826f0 | 2011-12-31 08:10:57 -0300 | [diff] [blame^] | 153 | err_net_init: |
| 154 | dvb_dmxdev_release(&adap->dmxdev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 155 | err_dmx_dev: |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 156 | dvb_dmx_release(&adap->demux); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 157 | err_dmx: |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 158 | dvb_unregister_adapter(&adap->dvb_adap); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 159 | err: |
| 160 | return ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 163 | int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 164 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 165 | if (adap->state & DVB_USB_ADAP_STATE_DVB) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 166 | deb_info("unregistering DVB part\n"); |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 167 | dvb_net_release(&adap->dvb_net); |
| 168 | adap->demux.dmx.close(&adap->demux.dmx); |
| 169 | dvb_dmxdev_release(&adap->dmxdev); |
| 170 | dvb_dmx_release(&adap->demux); |
| 171 | dvb_unregister_adapter(&adap->dvb_adap); |
| 172 | adap->state &= ~DVB_USB_ADAP_STATE_DVB; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 173 | } |
| 174 | return 0; |
| 175 | } |
| 176 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 177 | static int dvb_usb_set_active_fe(struct dvb_frontend *fe, int onoff) |
| 178 | { |
| 179 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 180 | |
| 181 | int ret = (adap->props.frontend_ctrl) ? |
| 182 | adap->props.frontend_ctrl(fe, onoff) : 0; |
| 183 | |
| 184 | if (ret < 0) { |
| 185 | err("frontend_ctrl request failed"); |
| 186 | return ret; |
| 187 | } |
| 188 | if (onoff) |
| 189 | adap->active_fe = fe->id; |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 194 | static int dvb_usb_fe_wakeup(struct dvb_frontend *fe) |
| 195 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 196 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 197 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 198 | dvb_usb_device_power_ctrl(adap->dev, 1); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 199 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 200 | dvb_usb_set_active_fe(fe, 1); |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 201 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 202 | if (adap->fe_adap[fe->id].fe_init) |
| 203 | adap->fe_adap[fe->id].fe_init(fe); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static int dvb_usb_fe_sleep(struct dvb_frontend *fe) |
| 209 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 210 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 211 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 212 | if (adap->fe_adap[fe->id].fe_sleep) |
| 213 | adap->fe_adap[fe->id].fe_sleep(fe); |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 214 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 215 | dvb_usb_set_active_fe(fe, 0); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 216 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 217 | return dvb_usb_device_power_ctrl(adap->dev, 0); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 220 | int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 221 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 222 | int ret, i; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 223 | |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 224 | /* register all given adapter frontends */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 225 | for (i = 0; i < adap->props.num_frontends; i++) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 226 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 227 | if (adap->props.fe[i].frontend_attach == NULL) { |
| 228 | err("strange: '%s' #%d,%d " |
| 229 | "doesn't want to attach a frontend.", |
| 230 | adap->dev->desc->name, adap->id, i); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | ret = adap->props.fe[i].frontend_attach(adap); |
| 236 | if (ret || adap->fe_adap[i].fe == NULL) { |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 237 | /* only print error when there is no FE at all */ |
| 238 | if (i == 0) |
| 239 | err("no frontend was attached by '%s'", |
| 240 | adap->dev->desc->name); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 245 | adap->fe_adap[i].fe->id = i; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 246 | |
| 247 | /* re-assign sleep and wakeup functions */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 248 | adap->fe_adap[i].fe_init = adap->fe_adap[i].fe->ops.init; |
| 249 | adap->fe_adap[i].fe->ops.init = dvb_usb_fe_wakeup; |
| 250 | adap->fe_adap[i].fe_sleep = adap->fe_adap[i].fe->ops.sleep; |
| 251 | adap->fe_adap[i].fe->ops.sleep = dvb_usb_fe_sleep; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 252 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 253 | if (dvb_register_frontend(&adap->dvb_adap, adap->fe_adap[i].fe)) { |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 254 | err("Frontend %d registration failed.", i); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 255 | dvb_frontend_detach(adap->fe_adap[i].fe); |
| 256 | adap->fe_adap[i].fe = NULL; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 257 | /* In error case, do not try register more FEs, |
| 258 | * still leaving already registered FEs alive. */ |
| 259 | if (i == 0) |
| 260 | return -ENODEV; |
| 261 | else |
| 262 | return 0; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 263 | } |
Patrick Boettcher | 5a19f31 | 2006-08-02 08:44:31 -0300 | [diff] [blame] | 264 | |
| 265 | /* only attach the tuner if the demod is there */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 266 | if (adap->props.fe[i].tuner_attach != NULL) |
| 267 | adap->props.fe[i].tuner_attach(adap); |
| 268 | |
| 269 | adap->num_frontends_initialized++; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 270 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 271 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 275 | int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 276 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 277 | int i = adap->num_frontends_initialized - 1; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 278 | |
| 279 | /* unregister all given adapter frontends */ |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 280 | for (; i >= 0; i--) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 281 | if (adap->fe_adap[i].fe != NULL) { |
| 282 | dvb_unregister_frontend(adap->fe_adap[i].fe); |
| 283 | dvb_frontend_detach(adap->fe_adap[i].fe); |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 284 | } |
Patrick Boettcher | 4e66c97 | 2006-08-08 15:48:11 -0300 | [diff] [blame] | 285 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 286 | adap->num_frontends_initialized = 0; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 287 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 288 | return 0; |
| 289 | } |