xref: /linux/drivers/media/usb/as102/as102_drv.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*3e0a4e85SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2d6317c68SMauro Carvalho Chehab /*
3d6317c68SMauro Carvalho Chehab  * Abilis Systems Single DVB-T Receiver
4d6317c68SMauro Carvalho Chehab  * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5d6317c68SMauro Carvalho Chehab  * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
6d6317c68SMauro Carvalho Chehab  */
7d6317c68SMauro Carvalho Chehab #include <linux/kernel.h>
8d6317c68SMauro Carvalho Chehab #include <linux/errno.h>
9d6317c68SMauro Carvalho Chehab #include <linux/slab.h>
10d6317c68SMauro Carvalho Chehab #include <linux/module.h>
11d6317c68SMauro Carvalho Chehab #include <linux/mm.h>
12d6317c68SMauro Carvalho Chehab #include <linux/kref.h>
13d6317c68SMauro Carvalho Chehab #include <linux/uaccess.h>
14d6317c68SMauro Carvalho Chehab #include <linux/usb.h>
15d6317c68SMauro Carvalho Chehab 
16d6317c68SMauro Carvalho Chehab /* header file for usb device driver*/
17d6317c68SMauro Carvalho Chehab #include "as102_drv.h"
1847f79129SMauro Carvalho Chehab #include "as10x_cmd.h"
1947f79129SMauro Carvalho Chehab #include "as102_fe.h"
20d6317c68SMauro Carvalho Chehab #include "as102_fw.h"
21fada1935SMauro Carvalho Chehab #include <media/dvbdev.h>
22d6317c68SMauro Carvalho Chehab 
23d6317c68SMauro Carvalho Chehab int dual_tuner;
24d6317c68SMauro Carvalho Chehab module_param_named(dual_tuner, dual_tuner, int, 0644);
25d6317c68SMauro Carvalho Chehab MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner config (default: off)");
26d6317c68SMauro Carvalho Chehab 
27d6317c68SMauro Carvalho Chehab static int fw_upload = 1;
28d6317c68SMauro Carvalho Chehab module_param_named(fw_upload, fw_upload, int, 0644);
29d6317c68SMauro Carvalho Chehab MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
30d6317c68SMauro Carvalho Chehab 
31d6317c68SMauro Carvalho Chehab static int pid_filtering;
32d6317c68SMauro Carvalho Chehab module_param_named(pid_filtering, pid_filtering, int, 0644);
33d6317c68SMauro Carvalho Chehab MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
34d6317c68SMauro Carvalho Chehab 
35d6317c68SMauro Carvalho Chehab static int ts_auto_disable;
36d6317c68SMauro Carvalho Chehab module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
37d6317c68SMauro Carvalho Chehab MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
38d6317c68SMauro Carvalho Chehab 
39d6317c68SMauro Carvalho Chehab int elna_enable = 1;
40d6317c68SMauro Carvalho Chehab module_param_named(elna_enable, elna_enable, int, 0644);
41d6317c68SMauro Carvalho Chehab MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
42d6317c68SMauro Carvalho Chehab 
43d6317c68SMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44d6317c68SMauro Carvalho Chehab 
as102_stop_stream(struct as102_dev_t * dev)45d6317c68SMauro Carvalho Chehab static void as102_stop_stream(struct as102_dev_t *dev)
46d6317c68SMauro Carvalho Chehab {
47d6317c68SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap;
48d6317c68SMauro Carvalho Chehab 
49d6317c68SMauro Carvalho Chehab 	if (dev != NULL)
50d6317c68SMauro Carvalho Chehab 		bus_adap = &dev->bus_adap;
51d6317c68SMauro Carvalho Chehab 	else
52d6317c68SMauro Carvalho Chehab 		return;
53d6317c68SMauro Carvalho Chehab 
54d6317c68SMauro Carvalho Chehab 	if (bus_adap->ops->stop_stream != NULL)
55d6317c68SMauro Carvalho Chehab 		bus_adap->ops->stop_stream(dev);
56d6317c68SMauro Carvalho Chehab 
57d6317c68SMauro Carvalho Chehab 	if (ts_auto_disable) {
58d6317c68SMauro Carvalho Chehab 		if (mutex_lock_interruptible(&dev->bus_adap.lock))
59d6317c68SMauro Carvalho Chehab 			return;
60d6317c68SMauro Carvalho Chehab 
61d6317c68SMauro Carvalho Chehab 		if (as10x_cmd_stop_streaming(bus_adap) < 0)
62d6317c68SMauro Carvalho Chehab 			dev_dbg(&dev->bus_adap.usb_dev->dev,
63d6317c68SMauro Carvalho Chehab 				"as10x_cmd_stop_streaming failed\n");
64d6317c68SMauro Carvalho Chehab 
65d6317c68SMauro Carvalho Chehab 		mutex_unlock(&dev->bus_adap.lock);
66d6317c68SMauro Carvalho Chehab 	}
67d6317c68SMauro Carvalho Chehab }
68d6317c68SMauro Carvalho Chehab 
as102_start_stream(struct as102_dev_t * dev)69d6317c68SMauro Carvalho Chehab static int as102_start_stream(struct as102_dev_t *dev)
70d6317c68SMauro Carvalho Chehab {
71d6317c68SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap;
72d6317c68SMauro Carvalho Chehab 	int ret = -EFAULT;
73d6317c68SMauro Carvalho Chehab 
74d6317c68SMauro Carvalho Chehab 	if (dev != NULL)
75d6317c68SMauro Carvalho Chehab 		bus_adap = &dev->bus_adap;
76d6317c68SMauro Carvalho Chehab 	else
77d6317c68SMauro Carvalho Chehab 		return ret;
78d6317c68SMauro Carvalho Chehab 
79d6317c68SMauro Carvalho Chehab 	if (bus_adap->ops->start_stream != NULL)
80d6317c68SMauro Carvalho Chehab 		ret = bus_adap->ops->start_stream(dev);
81d6317c68SMauro Carvalho Chehab 
82d6317c68SMauro Carvalho Chehab 	if (ts_auto_disable) {
83d6317c68SMauro Carvalho Chehab 		if (mutex_lock_interruptible(&dev->bus_adap.lock))
84d6317c68SMauro Carvalho Chehab 			return -EFAULT;
85d6317c68SMauro Carvalho Chehab 
86d6317c68SMauro Carvalho Chehab 		ret = as10x_cmd_start_streaming(bus_adap);
87d6317c68SMauro Carvalho Chehab 
88d6317c68SMauro Carvalho Chehab 		mutex_unlock(&dev->bus_adap.lock);
89d6317c68SMauro Carvalho Chehab 	}
90d6317c68SMauro Carvalho Chehab 
91d6317c68SMauro Carvalho Chehab 	return ret;
92d6317c68SMauro Carvalho Chehab }
93d6317c68SMauro Carvalho Chehab 
as10x_pid_filter(struct as102_dev_t * dev,int index,u16 pid,int onoff)94d6317c68SMauro Carvalho Chehab static int as10x_pid_filter(struct as102_dev_t *dev,
95d6317c68SMauro Carvalho Chehab 			    int index, u16 pid, int onoff) {
96d6317c68SMauro Carvalho Chehab 
97d6317c68SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = &dev->bus_adap;
98d6317c68SMauro Carvalho Chehab 	int ret = -EFAULT;
99d6317c68SMauro Carvalho Chehab 
100d6317c68SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
101d6317c68SMauro Carvalho Chehab 		dev_dbg(&dev->bus_adap.usb_dev->dev,
102d6317c68SMauro Carvalho Chehab 			"amutex_lock_interruptible(lock) failed !\n");
103d6317c68SMauro Carvalho Chehab 		return -EBUSY;
104d6317c68SMauro Carvalho Chehab 	}
105d6317c68SMauro Carvalho Chehab 
106d6317c68SMauro Carvalho Chehab 	switch (onoff) {
107d6317c68SMauro Carvalho Chehab 	case 0:
108d6317c68SMauro Carvalho Chehab 		ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
109d6317c68SMauro Carvalho Chehab 		dev_dbg(&dev->bus_adap.usb_dev->dev,
110d6317c68SMauro Carvalho Chehab 			"DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
111d6317c68SMauro Carvalho Chehab 			index, pid, ret);
112d6317c68SMauro Carvalho Chehab 		break;
113d6317c68SMauro Carvalho Chehab 	case 1:
114d6317c68SMauro Carvalho Chehab 	{
115d6317c68SMauro Carvalho Chehab 		struct as10x_ts_filter filter;
116d6317c68SMauro Carvalho Chehab 
117d6317c68SMauro Carvalho Chehab 		filter.type = TS_PID_TYPE_TS;
118d6317c68SMauro Carvalho Chehab 		filter.idx = 0xFF;
119d6317c68SMauro Carvalho Chehab 		filter.pid = pid;
120d6317c68SMauro Carvalho Chehab 
121d6317c68SMauro Carvalho Chehab 		ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
122d6317c68SMauro Carvalho Chehab 		dev_dbg(&dev->bus_adap.usb_dev->dev,
123d6317c68SMauro Carvalho Chehab 			"ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
124d6317c68SMauro Carvalho Chehab 			index, filter.idx, filter.pid, ret);
125d6317c68SMauro Carvalho Chehab 		break;
126d6317c68SMauro Carvalho Chehab 	}
127d6317c68SMauro Carvalho Chehab 	}
128d6317c68SMauro Carvalho Chehab 
129d6317c68SMauro Carvalho Chehab 	mutex_unlock(&dev->bus_adap.lock);
130d6317c68SMauro Carvalho Chehab 	return ret;
131d6317c68SMauro Carvalho Chehab }
132d6317c68SMauro Carvalho Chehab 
as102_dvb_dmx_start_feed(struct dvb_demux_feed * dvbdmxfeed)133d6317c68SMauro Carvalho Chehab static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
134d6317c68SMauro Carvalho Chehab {
135d6317c68SMauro Carvalho Chehab 	int ret = 0;
136d6317c68SMauro Carvalho Chehab 	struct dvb_demux *demux = dvbdmxfeed->demux;
137d6317c68SMauro Carvalho Chehab 	struct as102_dev_t *as102_dev = demux->priv;
138d6317c68SMauro Carvalho Chehab 
139d6317c68SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&as102_dev->sem))
140d6317c68SMauro Carvalho Chehab 		return -ERESTARTSYS;
141d6317c68SMauro Carvalho Chehab 
142d6317c68SMauro Carvalho Chehab 	if (pid_filtering)
143d6317c68SMauro Carvalho Chehab 		as10x_pid_filter(as102_dev, dvbdmxfeed->index,
144d6317c68SMauro Carvalho Chehab 				 dvbdmxfeed->pid, 1);
145d6317c68SMauro Carvalho Chehab 
146d6317c68SMauro Carvalho Chehab 	if (as102_dev->streaming++ == 0)
147d6317c68SMauro Carvalho Chehab 		ret = as102_start_stream(as102_dev);
148d6317c68SMauro Carvalho Chehab 
149d6317c68SMauro Carvalho Chehab 	mutex_unlock(&as102_dev->sem);
150d6317c68SMauro Carvalho Chehab 	return ret;
151d6317c68SMauro Carvalho Chehab }
152d6317c68SMauro Carvalho Chehab 
as102_dvb_dmx_stop_feed(struct dvb_demux_feed * dvbdmxfeed)153d6317c68SMauro Carvalho Chehab static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
154d6317c68SMauro Carvalho Chehab {
155d6317c68SMauro Carvalho Chehab 	struct dvb_demux *demux = dvbdmxfeed->demux;
156d6317c68SMauro Carvalho Chehab 	struct as102_dev_t *as102_dev = demux->priv;
157d6317c68SMauro Carvalho Chehab 
158d6317c68SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&as102_dev->sem))
159d6317c68SMauro Carvalho Chehab 		return -ERESTARTSYS;
160d6317c68SMauro Carvalho Chehab 
161d6317c68SMauro Carvalho Chehab 	if (--as102_dev->streaming == 0)
162d6317c68SMauro Carvalho Chehab 		as102_stop_stream(as102_dev);
163d6317c68SMauro Carvalho Chehab 
164d6317c68SMauro Carvalho Chehab 	if (pid_filtering)
165d6317c68SMauro Carvalho Chehab 		as10x_pid_filter(as102_dev, dvbdmxfeed->index,
166d6317c68SMauro Carvalho Chehab 				 dvbdmxfeed->pid, 0);
167d6317c68SMauro Carvalho Chehab 
168d6317c68SMauro Carvalho Chehab 	mutex_unlock(&as102_dev->sem);
169d6317c68SMauro Carvalho Chehab 	return 0;
170d6317c68SMauro Carvalho Chehab }
171d6317c68SMauro Carvalho Chehab 
as102_set_tune(void * priv,struct as10x_tune_args * tune_args)17247f79129SMauro Carvalho Chehab static int as102_set_tune(void *priv, struct as10x_tune_args *tune_args)
17347f79129SMauro Carvalho Chehab {
17447f79129SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = priv;
17547f79129SMauro Carvalho Chehab 	int ret;
17647f79129SMauro Carvalho Chehab 
17747f79129SMauro Carvalho Chehab 	/* Set frontend arguments */
17847f79129SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&bus_adap->lock))
17947f79129SMauro Carvalho Chehab 		return -EBUSY;
18047f79129SMauro Carvalho Chehab 
18147f79129SMauro Carvalho Chehab 	ret =  as10x_cmd_set_tune(bus_adap, tune_args);
18247f79129SMauro Carvalho Chehab 	if (ret != 0)
18347f79129SMauro Carvalho Chehab 		dev_dbg(&bus_adap->usb_dev->dev,
18447f79129SMauro Carvalho Chehab 			"as10x_cmd_set_tune failed. (err = %d)\n", ret);
18547f79129SMauro Carvalho Chehab 
18647f79129SMauro Carvalho Chehab 	mutex_unlock(&bus_adap->lock);
18747f79129SMauro Carvalho Chehab 
18847f79129SMauro Carvalho Chehab 	return ret;
18947f79129SMauro Carvalho Chehab }
19047f79129SMauro Carvalho Chehab 
as102_get_tps(void * priv,struct as10x_tps * tps)19147f79129SMauro Carvalho Chehab static int as102_get_tps(void *priv, struct as10x_tps *tps)
19247f79129SMauro Carvalho Chehab {
19347f79129SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = priv;
19447f79129SMauro Carvalho Chehab 	int ret;
19547f79129SMauro Carvalho Chehab 
19647f79129SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&bus_adap->lock))
19747f79129SMauro Carvalho Chehab 		return -EBUSY;
19847f79129SMauro Carvalho Chehab 
19947f79129SMauro Carvalho Chehab 	/* send abilis command: GET_TPS */
20047f79129SMauro Carvalho Chehab 	ret = as10x_cmd_get_tps(bus_adap, tps);
20147f79129SMauro Carvalho Chehab 
20247f79129SMauro Carvalho Chehab 	mutex_unlock(&bus_adap->lock);
20347f79129SMauro Carvalho Chehab 
20447f79129SMauro Carvalho Chehab 	return ret;
20547f79129SMauro Carvalho Chehab }
20647f79129SMauro Carvalho Chehab 
as102_get_status(void * priv,struct as10x_tune_status * tstate)20747f79129SMauro Carvalho Chehab static int as102_get_status(void *priv, struct as10x_tune_status *tstate)
20847f79129SMauro Carvalho Chehab {
20947f79129SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = priv;
21047f79129SMauro Carvalho Chehab 	int ret;
21147f79129SMauro Carvalho Chehab 
21247f79129SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&bus_adap->lock))
21347f79129SMauro Carvalho Chehab 		return -EBUSY;
21447f79129SMauro Carvalho Chehab 
21547f79129SMauro Carvalho Chehab 	/* send abilis command: GET_TUNE_STATUS */
21647f79129SMauro Carvalho Chehab 	ret = as10x_cmd_get_tune_status(bus_adap, tstate);
21747f79129SMauro Carvalho Chehab 	if (ret < 0) {
21847f79129SMauro Carvalho Chehab 		dev_dbg(&bus_adap->usb_dev->dev,
21947f79129SMauro Carvalho Chehab 			"as10x_cmd_get_tune_status failed (err = %d)\n",
22047f79129SMauro Carvalho Chehab 			ret);
22147f79129SMauro Carvalho Chehab 	}
22247f79129SMauro Carvalho Chehab 
22347f79129SMauro Carvalho Chehab 	mutex_unlock(&bus_adap->lock);
22447f79129SMauro Carvalho Chehab 
22547f79129SMauro Carvalho Chehab 	return ret;
22647f79129SMauro Carvalho Chehab }
22747f79129SMauro Carvalho Chehab 
as102_get_stats(void * priv,struct as10x_demod_stats * demod_stats)22847f79129SMauro Carvalho Chehab static int as102_get_stats(void *priv, struct as10x_demod_stats *demod_stats)
22947f79129SMauro Carvalho Chehab {
23047f79129SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = priv;
23147f79129SMauro Carvalho Chehab 	int ret;
23247f79129SMauro Carvalho Chehab 
23347f79129SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&bus_adap->lock))
23447f79129SMauro Carvalho Chehab 		return -EBUSY;
23547f79129SMauro Carvalho Chehab 
23647f79129SMauro Carvalho Chehab 	/* send abilis command: GET_TUNE_STATUS */
23747f79129SMauro Carvalho Chehab 	ret = as10x_cmd_get_demod_stats(bus_adap, demod_stats);
23847f79129SMauro Carvalho Chehab 	if (ret < 0) {
23947f79129SMauro Carvalho Chehab 		dev_dbg(&bus_adap->usb_dev->dev,
24047f79129SMauro Carvalho Chehab 			"as10x_cmd_get_demod_stats failed (probably not tuned)\n");
24147f79129SMauro Carvalho Chehab 	} else {
24247f79129SMauro Carvalho Chehab 		dev_dbg(&bus_adap->usb_dev->dev,
24347f79129SMauro Carvalho Chehab 			"demod status: fc: 0x%08x, bad fc: 0x%08x, bytes corrected: 0x%08x , MER: 0x%04x\n",
24447f79129SMauro Carvalho Chehab 			demod_stats->frame_count,
24547f79129SMauro Carvalho Chehab 			demod_stats->bad_frame_count,
24647f79129SMauro Carvalho Chehab 			demod_stats->bytes_fixed_by_rs,
24747f79129SMauro Carvalho Chehab 			demod_stats->mer);
24847f79129SMauro Carvalho Chehab 	}
24947f79129SMauro Carvalho Chehab 	mutex_unlock(&bus_adap->lock);
25047f79129SMauro Carvalho Chehab 
25147f79129SMauro Carvalho Chehab 	return ret;
25247f79129SMauro Carvalho Chehab }
25347f79129SMauro Carvalho Chehab 
as102_stream_ctrl(void * priv,int acquire,uint32_t elna_cfg)25447f79129SMauro Carvalho Chehab static int as102_stream_ctrl(void *priv, int acquire, uint32_t elna_cfg)
25547f79129SMauro Carvalho Chehab {
25647f79129SMauro Carvalho Chehab 	struct as10x_bus_adapter_t *bus_adap = priv;
25747f79129SMauro Carvalho Chehab 	int ret;
25847f79129SMauro Carvalho Chehab 
25947f79129SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&bus_adap->lock))
26047f79129SMauro Carvalho Chehab 		return -EBUSY;
26147f79129SMauro Carvalho Chehab 
26247f79129SMauro Carvalho Chehab 	if (acquire) {
26347f79129SMauro Carvalho Chehab 		if (elna_enable)
26447f79129SMauro Carvalho Chehab 			as10x_cmd_set_context(bus_adap,
26547f79129SMauro Carvalho Chehab 					      CONTEXT_LNA, elna_cfg);
26647f79129SMauro Carvalho Chehab 
26747f79129SMauro Carvalho Chehab 		ret = as10x_cmd_turn_on(bus_adap);
26847f79129SMauro Carvalho Chehab 	} else {
26947f79129SMauro Carvalho Chehab 		ret = as10x_cmd_turn_off(bus_adap);
27047f79129SMauro Carvalho Chehab 	}
27147f79129SMauro Carvalho Chehab 
27247f79129SMauro Carvalho Chehab 	mutex_unlock(&bus_adap->lock);
27347f79129SMauro Carvalho Chehab 
27447f79129SMauro Carvalho Chehab 	return ret;
27547f79129SMauro Carvalho Chehab }
27647f79129SMauro Carvalho Chehab 
27747f79129SMauro Carvalho Chehab static const struct as102_fe_ops as102_fe_ops = {
27847f79129SMauro Carvalho Chehab 	.set_tune = as102_set_tune,
27947f79129SMauro Carvalho Chehab 	.get_tps  = as102_get_tps,
28047f79129SMauro Carvalho Chehab 	.get_status = as102_get_status,
28147f79129SMauro Carvalho Chehab 	.get_stats = as102_get_stats,
28247f79129SMauro Carvalho Chehab 	.stream_ctrl = as102_stream_ctrl,
28347f79129SMauro Carvalho Chehab };
28447f79129SMauro Carvalho Chehab 
as102_dvb_register(struct as102_dev_t * as102_dev)285d6317c68SMauro Carvalho Chehab int as102_dvb_register(struct as102_dev_t *as102_dev)
286d6317c68SMauro Carvalho Chehab {
287d6317c68SMauro Carvalho Chehab 	struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
288d6317c68SMauro Carvalho Chehab 	int ret;
289d6317c68SMauro Carvalho Chehab 
290d6317c68SMauro Carvalho Chehab 	ret = dvb_register_adapter(&as102_dev->dvb_adap,
291d6317c68SMauro Carvalho Chehab 			   as102_dev->name, THIS_MODULE,
292d6317c68SMauro Carvalho Chehab 			   dev, adapter_nr);
293d6317c68SMauro Carvalho Chehab 	if (ret < 0) {
294d6317c68SMauro Carvalho Chehab 		dev_err(dev, "%s: dvb_register_adapter() failed: %d\n",
295d6317c68SMauro Carvalho Chehab 			__func__, ret);
296d6317c68SMauro Carvalho Chehab 		return ret;
297d6317c68SMauro Carvalho Chehab 	}
298d6317c68SMauro Carvalho Chehab 
299d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.priv = as102_dev;
300d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
301d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.feednum = 256;
302d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
303d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
304d6317c68SMauro Carvalho Chehab 
305d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
306d6317c68SMauro Carvalho Chehab 					      DMX_SECTION_FILTERING;
307d6317c68SMauro Carvalho Chehab 
308d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
309d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
310d6317c68SMauro Carvalho Chehab 	as102_dev->dvb_dmxdev.capabilities = 0;
311d6317c68SMauro Carvalho Chehab 
312d6317c68SMauro Carvalho Chehab 	ret = dvb_dmx_init(&as102_dev->dvb_dmx);
313d6317c68SMauro Carvalho Chehab 	if (ret < 0) {
314d6317c68SMauro Carvalho Chehab 		dev_err(dev, "%s: dvb_dmx_init() failed: %d\n", __func__, ret);
315d6317c68SMauro Carvalho Chehab 		goto edmxinit;
316d6317c68SMauro Carvalho Chehab 	}
317d6317c68SMauro Carvalho Chehab 
318d6317c68SMauro Carvalho Chehab 	ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
319d6317c68SMauro Carvalho Chehab 	if (ret < 0) {
320d6317c68SMauro Carvalho Chehab 		dev_err(dev, "%s: dvb_dmxdev_init() failed: %d\n",
321d6317c68SMauro Carvalho Chehab 			__func__, ret);
322d6317c68SMauro Carvalho Chehab 		goto edmxdinit;
323d6317c68SMauro Carvalho Chehab 	}
324d6317c68SMauro Carvalho Chehab 
325b601d9a5SMauro Carvalho Chehab 	/* Attach the frontend */
326b601d9a5SMauro Carvalho Chehab 	as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name,
32747f79129SMauro Carvalho Chehab 				       &as102_fe_ops,
328b601d9a5SMauro Carvalho Chehab 				       &as102_dev->bus_adap,
329b601d9a5SMauro Carvalho Chehab 				       as102_dev->elna_cfg);
330b601d9a5SMauro Carvalho Chehab 	if (!as102_dev->dvb_fe) {
331bfe40b79SJulia Lawall 		ret = -ENODEV;
332b601d9a5SMauro Carvalho Chehab 		dev_err(dev, "%s: as102_attach() failed: %d",
333b601d9a5SMauro Carvalho Chehab 		    __func__, ret);
334b601d9a5SMauro Carvalho Chehab 		goto efereg;
335b601d9a5SMauro Carvalho Chehab 	}
336b601d9a5SMauro Carvalho Chehab 
337b601d9a5SMauro Carvalho Chehab 	ret =  dvb_register_frontend(&as102_dev->dvb_adap, as102_dev->dvb_fe);
338d6317c68SMauro Carvalho Chehab 	if (ret < 0) {
339d6317c68SMauro Carvalho Chehab 		dev_err(dev, "%s: as102_dvb_register_frontend() failed: %d",
340d6317c68SMauro Carvalho Chehab 		    __func__, ret);
341d6317c68SMauro Carvalho Chehab 		goto efereg;
342d6317c68SMauro Carvalho Chehab 	}
343d6317c68SMauro Carvalho Chehab 
344d6317c68SMauro Carvalho Chehab 	/* init bus mutex for token locking */
345d6317c68SMauro Carvalho Chehab 	mutex_init(&as102_dev->bus_adap.lock);
346d6317c68SMauro Carvalho Chehab 
347d6317c68SMauro Carvalho Chehab 	/* init start / stop stream mutex */
348d6317c68SMauro Carvalho Chehab 	mutex_init(&as102_dev->sem);
349d6317c68SMauro Carvalho Chehab 
350d6317c68SMauro Carvalho Chehab 	/*
351d6317c68SMauro Carvalho Chehab 	 * try to load as102 firmware. If firmware upload failed, we'll be
352d6317c68SMauro Carvalho Chehab 	 * able to upload it later.
353d6317c68SMauro Carvalho Chehab 	 */
354d6317c68SMauro Carvalho Chehab 	if (fw_upload)
355d6317c68SMauro Carvalho Chehab 		try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
356d6317c68SMauro Carvalho Chehab 				"firmware_class");
357d6317c68SMauro Carvalho Chehab 
358d6317c68SMauro Carvalho Chehab 	pr_info("Registered device %s", as102_dev->name);
359d6317c68SMauro Carvalho Chehab 	return 0;
360d6317c68SMauro Carvalho Chehab 
361d6317c68SMauro Carvalho Chehab efereg:
362d6317c68SMauro Carvalho Chehab 	dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
363d6317c68SMauro Carvalho Chehab edmxdinit:
364d6317c68SMauro Carvalho Chehab 	dvb_dmx_release(&as102_dev->dvb_dmx);
365d6317c68SMauro Carvalho Chehab edmxinit:
366d6317c68SMauro Carvalho Chehab 	dvb_unregister_adapter(&as102_dev->dvb_adap);
367d6317c68SMauro Carvalho Chehab 	return ret;
368d6317c68SMauro Carvalho Chehab }
369d6317c68SMauro Carvalho Chehab 
as102_dvb_unregister(struct as102_dev_t * as102_dev)370d6317c68SMauro Carvalho Chehab void as102_dvb_unregister(struct as102_dev_t *as102_dev)
371d6317c68SMauro Carvalho Chehab {
372d6317c68SMauro Carvalho Chehab 	/* unregister as102 frontend */
373b601d9a5SMauro Carvalho Chehab 	dvb_unregister_frontend(as102_dev->dvb_fe);
374b601d9a5SMauro Carvalho Chehab 
375b601d9a5SMauro Carvalho Chehab 	/* detach frontend */
376b601d9a5SMauro Carvalho Chehab 	dvb_frontend_detach(as102_dev->dvb_fe);
377d6317c68SMauro Carvalho Chehab 
378d6317c68SMauro Carvalho Chehab 	/* unregister demux device */
379d6317c68SMauro Carvalho Chehab 	dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
380d6317c68SMauro Carvalho Chehab 	dvb_dmx_release(&as102_dev->dvb_dmx);
381d6317c68SMauro Carvalho Chehab 
382d6317c68SMauro Carvalho Chehab 	/* unregister dvb adapter */
383d6317c68SMauro Carvalho Chehab 	dvb_unregister_adapter(&as102_dev->dvb_adap);
384d6317c68SMauro Carvalho Chehab 
385d6317c68SMauro Carvalho Chehab 	pr_info("Unregistered device %s", as102_dev->name);
386d6317c68SMauro Carvalho Chehab }
387d6317c68SMauro Carvalho Chehab 
388d6317c68SMauro Carvalho Chehab module_usb_driver(as102_usb_driver);
389d6317c68SMauro Carvalho Chehab 
390d6317c68SMauro Carvalho Chehab /* modinfo details */
391d6317c68SMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_FULL_NAME);
392d6317c68SMauro Carvalho Chehab MODULE_LICENSE("GPL");
393d6317c68SMauro Carvalho Chehab MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");
394