2 Mantis PCI bridge driver
3 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.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 of the License, or
8 (at your option) any later version.
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.
20 #include <linux/kernel.h>
21 #include <linux/bitops.h>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/interrupt.h>
27 #include <linux/pci.h>
28 #include <linux/i2c.h>
32 #include "dvb_demux.h"
33 #include "dvb_frontend.h"
36 #include "mantis_common.h"
37 #include "mantis_dma.h"
38 #include "mantis_ca.h"
39 #include "mantis_ioc.h"
40 #include "mantis_dvb.h"
42 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
44 int mantis_frontend_power(struct mantis_pci
*mantis
, enum mantis_power power
)
46 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
50 dprintk(MANTIS_DEBUG
, 1, "Power ON");
51 gpio_set_bits(mantis
, config
->power
, POWER_ON
);
53 gpio_set_bits(mantis
, config
->power
, POWER_ON
);
58 dprintk(MANTIS_DEBUG
, 1, "Power OFF");
59 gpio_set_bits(mantis
, config
->power
, POWER_OFF
);
64 dprintk(MANTIS_DEBUG
, 1, "Unknown state <%02x>", power
);
70 EXPORT_SYMBOL_GPL(mantis_frontend_power
);
72 void mantis_frontend_soft_reset(struct mantis_pci
*mantis
)
74 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
76 dprintk(MANTIS_DEBUG
, 1, "Frontend RESET");
77 gpio_set_bits(mantis
, config
->reset
, 0);
79 gpio_set_bits(mantis
, config
->reset
, 0);
81 gpio_set_bits(mantis
, config
->reset
, 1);
83 gpio_set_bits(mantis
, config
->reset
, 1);
88 EXPORT_SYMBOL_GPL(mantis_frontend_soft_reset
);
90 static int mantis_frontend_shutdown(struct mantis_pci
*mantis
)
94 mantis_frontend_soft_reset(mantis
);
95 err
= mantis_frontend_power(mantis
, POWER_OFF
);
97 dprintk(MANTIS_ERROR
, 1, "Frontend POWER OFF failed! <%d>", err
);
104 static int mantis_dvb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
106 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
107 struct mantis_pci
*mantis
= dvbdmx
->priv
;
109 dprintk(MANTIS_DEBUG
, 1, "Mantis DVB Start feed");
110 if (!dvbdmx
->dmx
.frontend
) {
111 dprintk(MANTIS_DEBUG
, 1, "no frontend ?");
116 dprintk(MANTIS_DEBUG
, 1, "mantis start feed, feeds=%d", mantis
->feeds
);
118 if (mantis
->feeds
== 1) {
119 dprintk(MANTIS_DEBUG
, 1, "mantis start feed & dma");
120 printk("mantis start feed & dma\n");
121 mantis_dma_start(mantis
);
124 return mantis
->feeds
;
127 static int mantis_dvb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
129 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
130 struct mantis_pci
*mantis
= dvbdmx
->priv
;
132 dprintk(MANTIS_DEBUG
, 1, "Mantis DVB Stop feed");
133 if (!dvbdmx
->dmx
.frontend
) {
134 dprintk(MANTIS_DEBUG
, 1, "no frontend ?");
139 if (mantis
->feeds
== 0) {
140 dprintk(MANTIS_DEBUG
, 1, "mantis stop feed and dma");
141 printk("mantis stop feed and dma\n");
142 mantis_dma_stop(mantis
);
148 int __devinit
mantis_dvb_init(struct mantis_pci
*mantis
)
150 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
153 dprintk(MANTIS_DEBUG
, 1, "dvb_register_adapter");
155 result
= dvb_register_adapter(&mantis
->dvb_adapter
,
156 "Mantis DVB adapter",
163 dprintk(MANTIS_ERROR
, 1, "Error registering adapter");
167 mantis
->dvb_adapter
.priv
= mantis
;
168 mantis
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
|
169 DMX_SECTION_FILTERING
|
170 DMX_MEMORY_BASED_FILTERING
;
172 mantis
->demux
.priv
= mantis
;
173 mantis
->demux
.filternum
= 256;
174 mantis
->demux
.feednum
= 256;
175 mantis
->demux
.start_feed
= mantis_dvb_start_feed
;
176 mantis
->demux
.stop_feed
= mantis_dvb_stop_feed
;
177 mantis
->demux
.write_to_decoder
= NULL
;
179 dprintk(MANTIS_DEBUG
, 1, "dvb_dmx_init");
180 result
= dvb_dmx_init(&mantis
->demux
);
182 dprintk(MANTIS_ERROR
, 1, "dvb_dmx_init failed, ERROR=%d", result
);
187 mantis
->dmxdev
.filternum
= 256;
188 mantis
->dmxdev
.demux
= &mantis
->demux
.dmx
;
189 mantis
->dmxdev
.capabilities
= 0;
190 dprintk(MANTIS_DEBUG
, 1, "dvb_dmxdev_init");
192 result
= dvb_dmxdev_init(&mantis
->dmxdev
, &mantis
->dvb_adapter
);
195 dprintk(MANTIS_ERROR
, 1, "dvb_dmxdev_init failed, ERROR=%d", result
);
199 mantis
->fe_hw
.source
= DMX_FRONTEND_0
;
200 result
= mantis
->demux
.dmx
.add_frontend(&mantis
->demux
.dmx
, &mantis
->fe_hw
);
203 dprintk(MANTIS_ERROR
, 1, "dvb_dmx_init failed, ERROR=%d", result
);
207 mantis
->fe_mem
.source
= DMX_MEMORY_FE
;
208 result
= mantis
->demux
.dmx
.add_frontend(&mantis
->demux
.dmx
,&mantis
->fe_mem
);
210 dprintk(MANTIS_ERROR
, 1,"dvb_dmx_init failed, ERROR=%d", result
);
214 result
= mantis
->demux
.dmx
.connect_frontend(&mantis
->demux
.dmx
, &mantis
->fe_hw
);
216 dprintk(MANTIS_ERROR
, 1, "dvb_dmx_init failed, ERROR=%d", result
);
220 dvb_net_init(&mantis
->dvb_adapter
, &mantis
->dvbnet
, &mantis
->demux
.dmx
);
221 tasklet_init(&mantis
->tasklet
, mantis_dma_xfer
, (unsigned long) mantis
);
222 if (mantis
->hwconfig
) {
223 result
= config
->frontend_init(mantis
, mantis
->fe
);
225 dprintk(MANTIS_ERROR
, 1, "!!! NO Frontends found !!!");
228 // if (mantis->dvb_adapter == NULL) {
229 // dprintk(MANTIS_ERROR, 1, "DVB adapter <NULL>");
232 if (mantis
->fe
== NULL
) {
233 dprintk(MANTIS_ERROR
, 1, "FE <NULL>");
237 if (dvb_register_frontend(&mantis
->dvb_adapter
, mantis
->fe
)) {
238 dprintk(MANTIS_ERROR
, 1, "ERROR: Frontend registration failed");
240 if (mantis
->fe
->ops
.release
)
241 mantis
->fe
->ops
.release(mantis
->fe
);
251 /* Error conditions .. */
253 tasklet_kill(&mantis
->tasklet
);
254 dvb_net_release(&mantis
->dvbnet
);
257 mantis
->demux
.dmx
.remove_frontend(&mantis
->demux
.dmx
, &mantis
->fe_mem
);
260 mantis
->demux
.dmx
.remove_frontend(&mantis
->demux
.dmx
, &mantis
->fe_hw
);
263 dvb_dmxdev_release(&mantis
->dmxdev
);
266 dvb_dmx_release(&mantis
->demux
);
269 dvb_unregister_adapter(&mantis
->dvb_adapter
);
273 EXPORT_SYMBOL_GPL(mantis_dvb_init
);
275 int __devexit
mantis_dvb_exit(struct mantis_pci
*mantis
)
280 // mantis_ca_exit(mantis);
281 err
= mantis_frontend_shutdown(mantis
);
283 dprintk(MANTIS_ERROR
, 1, "Frontend exit while POWER ON! <%d>", err
);
285 dvb_unregister_frontend(mantis
->fe
);
288 tasklet_kill(&mantis
->tasklet
);
289 dvb_net_release(&mantis
->dvbnet
);
291 mantis
->demux
.dmx
.remove_frontend(&mantis
->demux
.dmx
, &mantis
->fe_mem
);
292 mantis
->demux
.dmx
.remove_frontend(&mantis
->demux
.dmx
, &mantis
->fe_hw
);
294 dvb_dmxdev_release(&mantis
->dmxdev
);
295 dvb_dmx_release(&mantis
->demux
);
297 dprintk(MANTIS_DEBUG
, 1, "dvb_unregister_adapter");
298 dvb_unregister_adapter(&mantis
->dvb_adapter
);
302 EXPORT_SYMBOL_GPL(mantis_dvb_exit
);