2 Mantis PCI bridge driver
3 Copyright (C) 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>
23 #include <linux/signal.h>
24 #include <linux/sched.h>
25 #include <linux/interrupt.h>
26 #include <linux/pci.h>
27 #include <linux/i2c.h>
31 #include "dvb_demux.h"
32 #include "dvb_frontend.h"
35 #include "mantis_common.h"
36 #include "mantis_dma.h"
37 #include "mantis_ca.h"
38 #include "mantis_ioc.h"
39 #include "mantis_dvb.h"
41 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43 int mantis_frontend_power(struct mantis_pci *mantis, enum mantis_power power)
45 struct mantis_hwconfig *config = mantis->hwconfig;
49 dprintk(MANTIS_DEBUG, 1, "Power ON");
50 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
52 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
57 dprintk(MANTIS_DEBUG, 1, "Power OFF");
58 mantis_gpio_set_bits(mantis, config->power, POWER_OFF);
63 dprintk(MANTIS_DEBUG, 1, "Unknown state <%02x>", power);
69 EXPORT_SYMBOL_GPL(mantis_frontend_power);
71 void mantis_frontend_soft_reset(struct mantis_pci *mantis)
73 struct mantis_hwconfig *config = mantis->hwconfig;
75 dprintk(MANTIS_DEBUG, 1, "Frontend RESET");
76 mantis_gpio_set_bits(mantis, config->reset, 0);
78 mantis_gpio_set_bits(mantis, config->reset, 0);
80 mantis_gpio_set_bits(mantis, config->reset, 1);
82 mantis_gpio_set_bits(mantis, config->reset, 1);
87 EXPORT_SYMBOL_GPL(mantis_frontend_soft_reset);
89 static int mantis_frontend_shutdown(struct mantis_pci *mantis)
93 mantis_frontend_soft_reset(mantis);
94 err = mantis_frontend_power(mantis, POWER_OFF);
96 dprintk(MANTIS_ERROR, 1, "Frontend POWER OFF failed! <%d>", err);
103 static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
105 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
106 struct mantis_pci *mantis = dvbdmx->priv;
108 dprintk(MANTIS_DEBUG, 1, "Mantis DVB Start feed");
109 if (!dvbdmx->dmx.frontend) {
110 dprintk(MANTIS_DEBUG, 1, "no frontend ?");
115 dprintk(MANTIS_DEBUG, 1, "mantis start feed, feeds=%d", mantis->feeds);
117 if (mantis->feeds == 1) {
118 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma");
119 mantis_dma_start(mantis);
120 tasklet_enable(&mantis->tasklet);
123 return mantis->feeds;
126 static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
128 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
129 struct mantis_pci *mantis = dvbdmx->priv;
131 dprintk(MANTIS_DEBUG, 1, "Mantis DVB Stop feed");
132 if (!dvbdmx->dmx.frontend) {
133 dprintk(MANTIS_DEBUG, 1, "no frontend ?");
138 if (mantis->feeds == 0) {
139 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma");
140 tasklet_disable(&mantis->tasklet);
141 mantis_dma_stop(mantis);
147 int mantis_dvb_init(struct mantis_pci *mantis)
149 struct mantis_hwconfig *config = mantis->hwconfig;
152 dprintk(MANTIS_DEBUG, 1, "dvb_register_adapter");
154 result = dvb_register_adapter(&mantis->dvb_adapter,
155 "Mantis DVB adapter",
162 dprintk(MANTIS_ERROR, 1, "Error registering adapter");
166 mantis->dvb_adapter.priv = mantis;
167 mantis->demux.dmx.capabilities = DMX_TS_FILTERING |
168 DMX_SECTION_FILTERING |
169 DMX_MEMORY_BASED_FILTERING;
171 mantis->demux.priv = mantis;
172 mantis->demux.filternum = 256;
173 mantis->demux.feednum = 256;
174 mantis->demux.start_feed = mantis_dvb_start_feed;
175 mantis->demux.stop_feed = mantis_dvb_stop_feed;
176 mantis->demux.write_to_decoder = NULL;
178 dprintk(MANTIS_DEBUG, 1, "dvb_dmx_init");
179 result = dvb_dmx_init(&mantis->demux);
181 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
186 mantis->dmxdev.filternum = 256;
187 mantis->dmxdev.demux = &mantis->demux.dmx;
188 mantis->dmxdev.capabilities = 0;
189 dprintk(MANTIS_DEBUG, 1, "dvb_dmxdev_init");
191 result = dvb_dmxdev_init(&mantis->dmxdev, &mantis->dvb_adapter);
194 dprintk(MANTIS_ERROR, 1, "dvb_dmxdev_init failed, ERROR=%d", result);
198 mantis->fe_hw.source = DMX_FRONTEND_0;
199 result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx, &mantis->fe_hw);
202 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
206 mantis->fe_mem.source = DMX_MEMORY_FE;
207 result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx, &mantis->fe_mem);
209 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
213 result = mantis->demux.dmx.connect_frontend(&mantis->demux.dmx, &mantis->fe_hw);
215 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
219 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
220 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
221 tasklet_disable(&mantis->tasklet);
222 if (mantis->hwconfig) {
223 result = config->frontend_init(mantis, mantis->fe);
225 dprintk(MANTIS_ERROR, 1, "!!! NO Frontends found !!!");
228 if (mantis->fe == NULL) {
230 dprintk(MANTIS_ERROR, 1, "FE <NULL>");
233 result = dvb_register_frontend(&mantis->dvb_adapter, mantis->fe);
235 dprintk(MANTIS_ERROR, 1, "ERROR: Frontend registration failed");
237 if (mantis->fe->ops.release)
238 mantis->fe->ops.release(mantis->fe);
248 /* Error conditions .. */
250 tasklet_kill(&mantis->tasklet);
251 dvb_net_release(&mantis->dvbnet);
253 dvb_unregister_frontend(mantis->fe);
254 dvb_frontend_detach(mantis->fe);
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 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);
284 dvb_unregister_frontend(mantis->fe);
285 dvb_frontend_detach(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);