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 | 99e44da | 2016-01-24 12:56:58 -0200 | [diff] [blame] | 3 | * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.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" |
Mauro Carvalho Chehab | 41b44e3 | 2016-02-22 11:42:04 -0300 | [diff] [blame] | 10 | #include <media/media-device.h> |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 11 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 12 | /* does the complete input transfer handling */ |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 13 | static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) |
| 14 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 15 | struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 16 | int newfeedcount, ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 17 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 18 | if (adap == NULL) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 19 | return -ENODEV; |
| 20 | |
Michael Krufky | 2d04c13 | 2011-09-08 01:17:39 -0300 | [diff] [blame] | 21 | if ((adap->active_fe < 0) || |
| 22 | (adap->active_fe >= adap->num_frontends_initialized)) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 23 | return -EINVAL; |
| 24 | } |
| 25 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 26 | newfeedcount = adap->feedcount + (onoff ? 1 : -1); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 27 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 28 | /* 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] | 29 | if (newfeedcount == 0) { |
| 30 | deb_ts("stop feeding\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 31 | usb_urb_kill(&adap->fe_adap[adap->active_fe].stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 32 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 33 | if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) { |
| 34 | ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 0); |
Malcolm Priestley | dca6b74 | 2011-04-17 16:55:14 -0300 | [diff] [blame] | 35 | if (ret < 0) { |
| 36 | err("error while stopping stream."); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 37 | return ret; |
Malcolm Priestley | dca6b74 | 2011-04-17 16:55:14 -0300 | [diff] [blame] | 38 | } |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 39 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 42 | adap->feedcount = newfeedcount; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 43 | |
| 44 | /* activate the pid on the device specific pid_filter */ |
Michael Krufky | 2b7a7c3 | 2011-09-16 09:40:32 -0300 | [diff] [blame] | 45 | 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 Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 49 | 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 Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 53 | |
| 54 | /* start the feed if this was the first feed and there is still a feed |
| 55 | * for reception. |
| 56 | */ |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 57 | if (adap->feedcount == onoff && adap->feedcount > 0) { |
Patrick Boettcher | 8126fdb | 2005-08-27 19:30:30 +0200 | [diff] [blame] | 58 | deb_ts("submitting all URBs\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 59 | usb_urb_submit(&adap->fe_adap[adap->active_fe].stream); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 60 | |
| 61 | deb_ts("controlling pid parser\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 62 | if (adap->props.fe[adap->active_fe].caps & DVB_USB_ADAP_HAS_PID_FILTER && |
| 63 | adap->props.fe[adap->active_fe].caps & |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 64 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 65 | 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 Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 68 | if (ret < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 69 | err("could not handle pid_parser"); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 70 | return ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 71 | } |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 72 | } |
| 73 | deb_ts("start feeding\n"); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 74 | if (adap->props.fe[adap->active_fe].streaming_ctrl != NULL) { |
| 75 | ret = adap->props.fe[adap->active_fe].streaming_ctrl(adap, 1); |
Malcolm Priestley | c8b7ced | 2011-04-16 13:30:32 -0300 | [diff] [blame] | 76 | if (ret < 0) { |
| 77 | err("error while enabling fifo."); |
| 78 | return ret; |
| 79 | } |
| 80 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 81 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed) |
| 87 | { |
Luis de Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 88 | deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, |
| 89 | dvbdmxfeed->type); |
| 90 | return dvb_usb_ctrl_feed(dvbdmxfeed, 1); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static 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 Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 96 | return dvb_usb_ctrl_feed(dvbdmxfeed, 0); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 99 | static int dvb_usb_media_device_init(struct dvb_usb_adapter *adap) |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 100 | { |
| 101 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 102 | struct media_device *mdev; |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 103 | struct dvb_usb_device *d = adap->dev; |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 104 | struct usb_device *udev = d->udev; |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 105 | |
Mauro Carvalho Chehab | 6cf5dad | 2016-02-22 12:10:49 -0300 | [diff] [blame] | 106 | 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 Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 111 | |
Mauro Carvalho Chehab | 89a2c1d | 2015-03-02 11:26:14 -0300 | [diff] [blame] | 112 | dvb_register_media_controller(&adap->dvb_adap, mdev); |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 113 | |
| 114 | dev_info(&d->udev->dev, "media controller created\n"); |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 115 | #endif |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 116 | return 0; |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 117 | } |
| 118 | |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 119 | static int dvb_usb_media_device_register(struct dvb_usb_adapter *adap) |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 120 | { |
| 121 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 122 | return media_device_register(adap->dvb_adap.mdev); |
| 123 | #else |
| 124 | return 0; |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 125 | #endif |
| 126 | } |
| 127 | |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 128 | static void dvb_usb_media_device_unregister(struct dvb_usb_adapter *adap) |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 129 | { |
| 130 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 131 | if (!adap->dvb_adap.mdev) |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 132 | return; |
| 133 | |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 134 | media_device_unregister(adap->dvb_adap.mdev); |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 135 | media_device_cleanup(adap->dvb_adap.mdev); |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 136 | kfree(adap->dvb_adap.mdev); |
| 137 | adap->dvb_adap.mdev = NULL; |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 138 | #endif |
| 139 | } |
| 140 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 141 | 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] | 142 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 143 | int i; |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 144 | int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name, |
| 145 | adap->dev->owner, &adap->dev->udev->dev, |
| 146 | adapter_nums); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 147 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 148 | if (ret < 0) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 149 | deb_info("dvb_register_adapter failed: error %d", ret); |
| 150 | goto err; |
| 151 | } |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 152 | adap->dvb_adap.priv = adap; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 153 | |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 154 | 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 Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 159 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 160 | if (adap->dev->props.read_mac_address) { |
Luis de Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 161 | 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 Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 163 | else |
| 164 | err("MAC address reading failed."); |
| 165 | } |
| 166 | |
| 167 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 168 | adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING; |
| 169 | adap->demux.priv = adap; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 170 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 171 | 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 Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 177 | 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 Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 181 | err("dvb_dmx_init failed: error %d", ret); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 182 | goto err_dmx; |
| 183 | } |
| 184 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 185 | 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 Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 189 | err("dvb_dmxdev_init failed: error %d", ret); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 190 | goto err_dmx_dev; |
| 191 | } |
| 192 | |
Jonathan Nieder | 60826f0 | 2011-12-31 08:10:57 -0300 | [diff] [blame] | 193 | if ((ret = dvb_net_init(&adap->dvb_adap, &adap->dvb_net, |
| 194 | &adap->demux.dmx)) < 0) { |
Luis de Bethencourt | e68c2fe | 2015-02-04 10:42:12 -0300 | [diff] [blame] | 195 | err("dvb_net_init failed: error %d", ret); |
Jonathan Nieder | 60826f0 | 2011-12-31 08:10:57 -0300 | [diff] [blame] | 196 | goto err_net_init; |
| 197 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 198 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 199 | adap->state |= DVB_USB_ADAP_STATE_DVB; |
Trent Piepho | 8397703 | 2006-05-12 20:36:24 -0300 | [diff] [blame] | 200 | return 0; |
| 201 | |
Jonathan Nieder | 60826f0 | 2011-12-31 08:10:57 -0300 | [diff] [blame] | 202 | err_net_init: |
| 203 | dvb_dmxdev_release(&adap->dmxdev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 204 | err_dmx_dev: |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 205 | dvb_dmx_release(&adap->demux); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 206 | err_dmx: |
Mauro Carvalho Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 207 | dvb_usb_media_device_unregister(adap); |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 208 | err_mc: |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 209 | dvb_unregister_adapter(&adap->dvb_adap); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 210 | err: |
| 211 | return ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 214 | int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 215 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 216 | if (adap->state & DVB_USB_ADAP_STATE_DVB) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 217 | deb_info("unregistering DVB part\n"); |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 218 | 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 Chehab | a3dfc6d | 2015-02-13 10:08:17 -0300 | [diff] [blame] | 222 | dvb_usb_media_device_unregister(adap); |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 223 | dvb_unregister_adapter(&adap->dvb_adap); |
| 224 | adap->state &= ~DVB_USB_ADAP_STATE_DVB; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 229 | static 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 Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 246 | static int dvb_usb_fe_wakeup(struct dvb_frontend *fe) |
| 247 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 248 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 249 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 250 | dvb_usb_device_power_ctrl(adap->dev, 1); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 251 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 252 | dvb_usb_set_active_fe(fe, 1); |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 253 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 254 | if (adap->fe_adap[fe->id].fe_init) |
| 255 | adap->fe_adap[fe->id].fe_init(fe); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int dvb_usb_fe_sleep(struct dvb_frontend *fe) |
| 261 | { |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 262 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 263 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 264 | if (adap->fe_adap[fe->id].fe_sleep) |
| 265 | adap->fe_adap[fe->id].fe_sleep(fe); |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 266 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 267 | dvb_usb_set_active_fe(fe, 0); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 268 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 269 | return dvb_usb_device_power_ctrl(adap->dev, 0); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 272 | int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 273 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 274 | int ret, i; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 275 | |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 276 | /* register all given adapter frontends */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 277 | for (i = 0; i < adap->props.num_frontends; i++) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 278 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 279 | 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 Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 289 | /* 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 Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 297 | adap->fe_adap[i].fe->id = i; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 298 | |
| 299 | /* re-assign sleep and wakeup functions */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 300 | 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 Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 304 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 305 | if (dvb_register_frontend(&adap->dvb_adap, adap->fe_adap[i].fe)) { |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 306 | err("Frontend %d registration failed.", i); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 307 | dvb_frontend_detach(adap->fe_adap[i].fe); |
| 308 | adap->fe_adap[i].fe = NULL; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 309 | /* 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 Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 315 | } |
Patrick Boettcher | 5a19f31 | 2006-08-02 08:44:31 -0300 | [diff] [blame] | 316 | |
| 317 | /* only attach the tuner if the demod is there */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 318 | if (adap->props.fe[i].tuner_attach != NULL) |
| 319 | adap->props.fe[i].tuner_attach(adap); |
| 320 | |
| 321 | adap->num_frontends_initialized++; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 322 | } |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 323 | |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 324 | ret = dvb_create_media_graph(&adap->dvb_adap, true); |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 325 | if (ret) |
| 326 | return ret; |
Rafael Lourenço de Lima Chehab | 496ccf9 | 2015-02-13 18:29:14 -0300 | [diff] [blame] | 327 | |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 328 | ret = dvb_usb_media_device_register(adap); |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 329 | |
Mauro Carvalho Chehab | 0d3ab84 | 2015-09-04 15:33:46 -0300 | [diff] [blame] | 330 | return ret; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 333 | int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 334 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 335 | int i = adap->num_frontends_initialized - 1; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 336 | |
| 337 | /* unregister all given adapter frontends */ |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 338 | for (; i >= 0; i--) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 339 | 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 Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 342 | } |
Patrick Boettcher | 4e66c97 | 2006-08-08 15:48:11 -0300 | [diff] [blame] | 343 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 344 | adap->num_frontends_initialized = 0; |
Antti Palosaari | 9bd9e3b | 2011-07-25 20:16:13 -0300 | [diff] [blame] | 345 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 346 | return 0; |
| 347 | } |