2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
21 #include <linux/kref.h>
22 #include <linux/uaccess.h>
23 #include <linux/usb.h>
25 /* header file for usb device driver*/
26 #include "as102_drv.h"
31 module_param_named(dual_tuner, dual_tuner, int, 0644);
32 MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner config (default: off)");
34 static int fw_upload = 1;
35 module_param_named(fw_upload, fw_upload, int, 0644);
36 MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
38 static int pid_filtering;
39 module_param_named(pid_filtering, pid_filtering, int, 0644);
40 MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
42 static int ts_auto_disable;
43 module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
44 MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
47 module_param_named(elna_enable, elna_enable, int, 0644);
48 MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
50 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
52 static void as102_stop_stream(struct as102_dev_t *dev)
54 struct as10x_bus_adapter_t *bus_adap;
57 bus_adap = &dev->bus_adap;
61 if (bus_adap->ops->stop_stream != NULL)
62 bus_adap->ops->stop_stream(dev);
64 if (ts_auto_disable) {
65 if (mutex_lock_interruptible(&dev->bus_adap.lock))
68 if (as10x_cmd_stop_streaming(bus_adap) < 0)
69 dev_dbg(&dev->bus_adap.usb_dev->dev,
70 "as10x_cmd_stop_streaming failed\n");
72 mutex_unlock(&dev->bus_adap.lock);
76 static int as102_start_stream(struct as102_dev_t *dev)
78 struct as10x_bus_adapter_t *bus_adap;
82 bus_adap = &dev->bus_adap;
86 if (bus_adap->ops->start_stream != NULL)
87 ret = bus_adap->ops->start_stream(dev);
89 if (ts_auto_disable) {
90 if (mutex_lock_interruptible(&dev->bus_adap.lock))
93 ret = as10x_cmd_start_streaming(bus_adap);
95 mutex_unlock(&dev->bus_adap.lock);
101 static int as10x_pid_filter(struct as102_dev_t *dev,
102 int index, u16 pid, int onoff) {
104 struct as10x_bus_adapter_t *bus_adap = &dev->bus_adap;
107 if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
108 dev_dbg(&dev->bus_adap.usb_dev->dev,
109 "amutex_lock_interruptible(lock) failed !\n");
115 ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
116 dev_dbg(&dev->bus_adap.usb_dev->dev,
117 "DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
122 struct as10x_ts_filter filter;
124 filter.type = TS_PID_TYPE_TS;
128 ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
129 dev_dbg(&dev->bus_adap.usb_dev->dev,
130 "ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
131 index, filter.idx, filter.pid, ret);
136 mutex_unlock(&dev->bus_adap.lock);
140 static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
143 struct dvb_demux *demux = dvbdmxfeed->demux;
144 struct as102_dev_t *as102_dev = demux->priv;
146 if (mutex_lock_interruptible(&as102_dev->sem))
150 as10x_pid_filter(as102_dev, dvbdmxfeed->index,
153 if (as102_dev->streaming++ == 0)
154 ret = as102_start_stream(as102_dev);
156 mutex_unlock(&as102_dev->sem);
160 static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
162 struct dvb_demux *demux = dvbdmxfeed->demux;
163 struct as102_dev_t *as102_dev = demux->priv;
165 if (mutex_lock_interruptible(&as102_dev->sem))
168 if (--as102_dev->streaming == 0)
169 as102_stop_stream(as102_dev);
172 as10x_pid_filter(as102_dev, dvbdmxfeed->index,
175 mutex_unlock(&as102_dev->sem);
179 int as102_dvb_register(struct as102_dev_t *as102_dev)
181 struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
184 ret = dvb_register_adapter(&as102_dev->dvb_adap,
185 as102_dev->name, THIS_MODULE,
188 dev_err(dev, "%s: dvb_register_adapter() failed: %d\n",
193 as102_dev->dvb_dmx.priv = as102_dev;
194 as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
195 as102_dev->dvb_dmx.feednum = 256;
196 as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
197 as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
199 as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
200 DMX_SECTION_FILTERING;
202 as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
203 as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
204 as102_dev->dvb_dmxdev.capabilities = 0;
206 ret = dvb_dmx_init(&as102_dev->dvb_dmx);
208 dev_err(dev, "%s: dvb_dmx_init() failed: %d\n", __func__, ret);
212 ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
214 dev_err(dev, "%s: dvb_dmxdev_init() failed: %d\n",
219 /* Attach the frontend */
220 as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name,
221 &as102_dev->bus_adap,
222 as102_dev->elna_cfg);
223 if (!as102_dev->dvb_fe) {
224 dev_err(dev, "%s: as102_attach() failed: %d",
229 ret = dvb_register_frontend(&as102_dev->dvb_adap, as102_dev->dvb_fe);
231 dev_err(dev, "%s: as102_dvb_register_frontend() failed: %d",
236 /* init bus mutex for token locking */
237 mutex_init(&as102_dev->bus_adap.lock);
239 /* init start / stop stream mutex */
240 mutex_init(&as102_dev->sem);
243 * try to load as102 firmware. If firmware upload failed, we'll be
244 * able to upload it later.
247 try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
250 pr_info("Registered device %s", as102_dev->name);
254 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
256 dvb_dmx_release(&as102_dev->dvb_dmx);
258 dvb_unregister_adapter(&as102_dev->dvb_adap);
262 void as102_dvb_unregister(struct as102_dev_t *as102_dev)
264 /* unregister as102 frontend */
265 dvb_unregister_frontend(as102_dev->dvb_fe);
267 /* detach frontend */
268 dvb_frontend_detach(as102_dev->dvb_fe);
270 /* unregister demux device */
271 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
272 dvb_dmx_release(&as102_dev->dvb_dmx);
274 /* unregister dvb adapter */
275 dvb_unregister_adapter(&as102_dev->dvb_adap);
277 pr_info("Unregistered device %s", as102_dev->name);
280 module_usb_driver(as102_usb_driver);
282 /* modinfo details */
283 MODULE_DESCRIPTION(DRIVER_FULL_NAME);
284 MODULE_LICENSE("GPL");
285 MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");