2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
25 #include <linux/kref.h>
26 #include <asm/uaccess.h>
27 #include <linux/usb.h>
29 /* header file for Usb device driver*/
30 #include "as102_drv.h"
33 #if defined(CONFIG_DVB_CORE) || defined(CONFIG_DVB_CORE_MODULE)
36 #warning >>> DVB_CORE not defined !!! <<<
40 module_param_named(debug, debug, int, 0644);
41 MODULE_PARM_DESC(debug, "Turn on/off debugging (default: off)");
44 module_param_named(dual_tuner, dual_tuner, int, 0644);
45 MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner configuration (default: off)");
47 static int fw_upload = 1;
48 module_param_named(fw_upload, fw_upload, int, 0644);
49 MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
51 static int pid_filtering = 0;
52 module_param_named(pid_filtering, pid_filtering, int, 0644);
53 MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
55 static int ts_auto_disable = 0;
56 module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
57 MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
60 module_param_named(elna_enable, elna_enable, int, 0644);
61 MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
63 #ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
64 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
67 #if defined(CONFIG_DVB_CORE) || defined(CONFIG_DVB_CORE_MODULE)
68 static void as102_stop_stream(struct as102_dev_t *dev) {
69 struct as102_bus_adapter_t *bus_adap;
72 bus_adap = &dev->bus_adap;
76 if (bus_adap->ops->stop_stream != NULL)
77 bus_adap->ops->stop_stream(dev);
79 if (ts_auto_disable) {
80 if (mutex_lock_interruptible(&dev->bus_adap.lock))
83 if (as10x_cmd_stop_streaming(bus_adap) < 0) {
84 dprintk(debug, "as10x_cmd_stop_streaming failed\n");
87 mutex_unlock(&dev->bus_adap.lock);
91 static int as102_start_stream(struct as102_dev_t *dev) {
93 struct as102_bus_adapter_t *bus_adap;
97 bus_adap = &dev->bus_adap;
101 if (bus_adap->ops->start_stream != NULL) {
102 ret = bus_adap->ops->start_stream(dev);
105 if (ts_auto_disable) {
106 if (mutex_lock_interruptible(&dev->bus_adap.lock))
109 ret = as10x_cmd_start_streaming(bus_adap);
111 mutex_unlock(&dev->bus_adap.lock);
117 static int as10x_pid_filter(struct as102_dev_t *dev,
118 int index, u16 pid, int onoff) {
120 struct as102_bus_adapter_t *bus_adap = &dev->bus_adap;
125 if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
126 dprintk(debug, "mutex_lock_interruptible(lock) failed !\n");
132 ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
133 dprintk(debug, "DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
138 struct as10x_ts_filter filter;
140 filter.type = TS_PID_TYPE_TS;
144 ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
145 dprintk(debug, "ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
146 index, filter.idx, filter.pid, ret);
151 mutex_unlock(&dev->bus_adap.lock);
157 static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed) {
159 struct dvb_demux *demux = dvbdmxfeed->demux;
160 struct as102_dev_t *as102_dev = demux->priv;
164 if (mutex_lock_interruptible(&as102_dev->sem))
168 as10x_pid_filter(as102_dev,
169 dvbdmxfeed->index, dvbdmxfeed->pid, 1);
172 if (as102_dev->streaming++ == 0) {
173 ret = as102_start_stream(as102_dev);
176 mutex_unlock(&as102_dev->sem);
181 static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed) {
182 struct dvb_demux *demux = dvbdmxfeed->demux;
183 struct as102_dev_t *as102_dev = demux->priv;
187 if (mutex_lock_interruptible(&as102_dev->sem))
190 if (--as102_dev->streaming == 0) {
191 as102_stop_stream(as102_dev);
195 as10x_pid_filter(as102_dev,
196 dvbdmxfeed->index, dvbdmxfeed->pid, 0);
199 mutex_unlock(&as102_dev->sem);
205 int as102_dvb_register(struct as102_dev_t *as102_dev) {
209 #if defined(CONFIG_DVB_CORE) || defined(CONFIG_DVB_CORE_MODULE)
210 ret = dvb_register_adapter(&as102_dev->dvb_adap,
213 #if defined(CONFIG_AS102_USB)
214 &as102_dev->bus_adap.usb_dev->dev
215 #elif defined(CONFIG_AS102_SPI)
216 &as102_dev->bus_adap.spi_dev->dev
218 #error >>> dvb_register_adapter <<<
220 #ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
225 err("%s: dvb_register_adapter() failed (errno = %d)",
230 as102_dev->dvb_dmx.priv = as102_dev;
231 as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
232 as102_dev->dvb_dmx.feednum = 256;
233 as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
234 as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
236 as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
237 DMX_SECTION_FILTERING;
239 as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
240 as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
241 as102_dev->dvb_dmxdev.capabilities = 0;
243 if ((ret = dvb_dmx_init(&as102_dev->dvb_dmx)) < 0) {
244 err("%s: dvb_dmx_init() failed (errno = %d)",
249 ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
251 err("%s: dvb_dmxdev_init() failed (errno = %d)",
256 ret = as102_dvb_register_fe(as102_dev, &as102_dev->dvb_fe);
258 err("%s: as102_dvb_register_frontend() failed (errno = %d)",
264 /* init bus mutex for token locking */
265 mutex_init(&as102_dev->bus_adap.lock);
267 /* init start / stop stream mutex */
268 mutex_init(&as102_dev->sem);
270 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
272 * try to load as102 firmware. If firmware upload failed, we'll be
273 * able to upload it later.
276 try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
282 /* FIXME: free dvb_XXX */
286 void as102_dvb_unregister(struct as102_dev_t *as102_dev) {
289 #if defined(CONFIG_DVB_CORE) || defined(CONFIG_DVB_CORE_MODULE)
290 /* unregister as102 frontend */
291 as102_dvb_unregister_fe(&as102_dev->dvb_fe);
293 /* unregister demux device */
294 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
295 dvb_dmx_release(&as102_dev->dvb_dmx);
297 /* unregister dvb adapter */
298 dvb_unregister_adapter(&as102_dev->dvb_adap);
303 static int __init as102_driver_init(void) {
308 /* register this driver with the low level subsystem */
309 #if defined(CONFIG_AS102_USB)
310 ret = usb_register(&as102_usb_driver);
312 err("usb_register failed (ret = %d)", ret);
314 #if defined(CONFIG_AS102_SPI)
315 ret = spi_register_driver(&as102_spi_driver);
317 printk(KERN_ERR "spi_register failed (ret = %d)", ret);
325 * Mandatory function : Adds a special section to the module indicating
326 * where initialisation function is defined
328 module_init(as102_driver_init);
331 * \brief as102 driver exit point. This function is called when device has
334 static void __exit as102_driver_exit(void) {
336 /* deregister this driver with the low level bus subsystem */
337 #if defined(CONFIG_AS102_USB)
338 usb_deregister(&as102_usb_driver);
340 #if defined(CONFIG_AS102_SPI)
341 spi_unregister_driver(&as102_spi_driver);
347 * required function for unload: Adds a special section to the module
348 * indicating where unload function is defined
350 module_exit(as102_driver_exit);
351 /* modinfo details */
352 MODULE_DESCRIPTION(DRIVER_FULL_NAME);
353 MODULE_LICENSE("GPL");
354 MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");
356 /* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */