1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/mm.h>
26#include <linux/kref.h>
27#include <linux/uaccess.h>
28#include <linux/usb.h>
29
30
31#include "as102_drv.h"
32#include "as102_fw.h"
33#include "dvbdev.h"
34
35int as102_debug;
36module_param_named(debug, as102_debug, int, 0644);
37MODULE_PARM_DESC(debug, "Turn on/off debugging (default: off)");
38
39int dual_tuner;
40module_param_named(dual_tuner, dual_tuner, int, 0644);
41MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner config (default: off)");
42
43static int fw_upload = 1;
44module_param_named(fw_upload, fw_upload, int, 0644);
45MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
46
47static int pid_filtering;
48module_param_named(pid_filtering, pid_filtering, int, 0644);
49MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
50
51static int ts_auto_disable;
52module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
53MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
54
55int elna_enable = 1;
56module_param_named(elna_enable, elna_enable, int, 0644);
57MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
58
59DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
60
61static void as102_stop_stream(struct as102_dev_t *dev)
62{
63 struct as10x_bus_adapter_t *bus_adap;
64
65 if (dev != NULL)
66 bus_adap = &dev->bus_adap;
67 else
68 return;
69
70 if (bus_adap->ops->stop_stream != NULL)
71 bus_adap->ops->stop_stream(dev);
72
73 if (ts_auto_disable) {
74 if (mutex_lock_interruptible(&dev->bus_adap.lock))
75 return;
76
77 if (as10x_cmd_stop_streaming(bus_adap) < 0)
78 dprintk(debug, "as10x_cmd_stop_streaming failed\n");
79
80 mutex_unlock(&dev->bus_adap.lock);
81 }
82}
83
84static int as102_start_stream(struct as102_dev_t *dev)
85{
86 struct as10x_bus_adapter_t *bus_adap;
87 int ret = -EFAULT;
88
89 if (dev != NULL)
90 bus_adap = &dev->bus_adap;
91 else
92 return ret;
93
94 if (bus_adap->ops->start_stream != NULL)
95 ret = bus_adap->ops->start_stream(dev);
96
97 if (ts_auto_disable) {
98 if (mutex_lock_interruptible(&dev->bus_adap.lock))
99 return -EFAULT;
100
101 ret = as10x_cmd_start_streaming(bus_adap);
102
103 mutex_unlock(&dev->bus_adap.lock);
104 }
105
106 return ret;
107}
108
109static int as10x_pid_filter(struct as102_dev_t *dev,
110 int index, u16 pid, int onoff) {
111
112 struct as10x_bus_adapter_t *bus_adap = &dev->bus_adap;
113 int ret = -EFAULT;
114
115 ENTER();
116
117 if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
118 dprintk(debug, "mutex_lock_interruptible(lock) failed !\n");
119 return -EBUSY;
120 }
121
122 switch (onoff) {
123 case 0:
124 ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
125 dprintk(debug, "DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
126 index, pid, ret);
127 break;
128 case 1:
129 {
130 struct as10x_ts_filter filter;
131
132 filter.type = TS_PID_TYPE_TS;
133 filter.idx = 0xFF;
134 filter.pid = pid;
135
136 ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
137 dprintk(debug, "ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
138 index, filter.idx, filter.pid, ret);
139 break;
140 }
141 }
142
143 mutex_unlock(&dev->bus_adap.lock);
144
145 LEAVE();
146 return ret;
147}
148
149static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
150{
151 int ret = 0;
152 struct dvb_demux *demux = dvbdmxfeed->demux;
153 struct as102_dev_t *as102_dev = demux->priv;
154
155 ENTER();
156
157 if (mutex_lock_interruptible(&as102_dev->sem))
158 return -ERESTARTSYS;
159
160 if (pid_filtering)
161 as10x_pid_filter(as102_dev, dvbdmxfeed->index,
162 dvbdmxfeed->pid, 1);
163
164 if (as102_dev->streaming++ == 0)
165 ret = as102_start_stream(as102_dev);
166
167 mutex_unlock(&as102_dev->sem);
168 LEAVE();
169 return ret;
170}
171
172static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
173{
174 struct dvb_demux *demux = dvbdmxfeed->demux;
175 struct as102_dev_t *as102_dev = demux->priv;
176
177 ENTER();
178
179 if (mutex_lock_interruptible(&as102_dev->sem))
180 return -ERESTARTSYS;
181
182 if (--as102_dev->streaming == 0)
183 as102_stop_stream(as102_dev);
184
185 if (pid_filtering)
186 as10x_pid_filter(as102_dev, dvbdmxfeed->index,
187 dvbdmxfeed->pid, 0);
188
189 mutex_unlock(&as102_dev->sem);
190 LEAVE();
191 return 0;
192}
193
194int as102_dvb_register(struct as102_dev_t *as102_dev)
195{
196 struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
197 int ret;
198
199 ret = dvb_register_adapter(&as102_dev->dvb_adap,
200 as102_dev->name, THIS_MODULE,
201 dev, adapter_nr);
202 if (ret < 0) {
203 dev_err(dev, "%s: dvb_register_adapter() failed: %d\n",
204 __func__, ret);
205 return ret;
206 }
207
208 as102_dev->dvb_dmx.priv = as102_dev;
209 as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
210 as102_dev->dvb_dmx.feednum = 256;
211 as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
212 as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
213
214 as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
215 DMX_SECTION_FILTERING;
216
217 as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
218 as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
219 as102_dev->dvb_dmxdev.capabilities = 0;
220
221 ret = dvb_dmx_init(&as102_dev->dvb_dmx);
222 if (ret < 0) {
223 dev_err(dev, "%s: dvb_dmx_init() failed: %d\n", __func__, ret);
224 goto edmxinit;
225 }
226
227 ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
228 if (ret < 0) {
229 dev_err(dev, "%s: dvb_dmxdev_init() failed: %d\n",
230 __func__, ret);
231 goto edmxdinit;
232 }
233
234 ret = as102_dvb_register_fe(as102_dev, &as102_dev->dvb_fe);
235 if (ret < 0) {
236 dev_err(dev, "%s: as102_dvb_register_frontend() failed: %d",
237 __func__, ret);
238 goto efereg;
239 }
240
241
242 mutex_init(&as102_dev->bus_adap.lock);
243
244
245 mutex_init(&as102_dev->sem);
246
247
248
249
250
251 if (fw_upload)
252 try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
253 "firmware_class");
254
255 pr_info("Registered device %s", as102_dev->name);
256 return 0;
257
258efereg:
259 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
260edmxdinit:
261 dvb_dmx_release(&as102_dev->dvb_dmx);
262edmxinit:
263 dvb_unregister_adapter(&as102_dev->dvb_adap);
264 return ret;
265}
266
267void as102_dvb_unregister(struct as102_dev_t *as102_dev)
268{
269
270 as102_dvb_unregister_fe(&as102_dev->dvb_fe);
271
272
273 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
274 dvb_dmx_release(&as102_dev->dvb_dmx);
275
276
277 dvb_unregister_adapter(&as102_dev->dvb_adap);
278
279 pr_info("Unregistered device %s", as102_dev->name);
280}
281
282module_usb_driver(as102_usb_driver);
283
284
285MODULE_DESCRIPTION(DRIVER_FULL_NAME);
286MODULE_LICENSE("GPL");
287MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");
288