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