aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorManu Abraham <abraham.manu@gmail.com>2009-12-04 03:41:11 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-01-17 08:55:42 -0500
commitb3b961448f702339444036f94252ff2ba7a99feb (patch)
treef31007bb892091072fa97f43f5666105b1ea8f33 /drivers/media
parentadd206368462434ba97e8fe4de98e5d47ffdb0a0 (diff)
V4L/DVB (13795): [Mantis/Hopper] Code overhaul, add Hopper devices into the PCI ID list
Signed-off-by: Manu Abraham <manu@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/dvb/mantis/Kconfig22
-rw-r--r--drivers/media/dvb/mantis/Makefile42
-rw-r--r--drivers/media/dvb/mantis/hopper_cards.c260
-rw-r--r--drivers/media/dvb/mantis/hopper_vp3028.c76
-rw-r--r--drivers/media/dvb/mantis/hopper_vp3028.h10
-rw-r--r--drivers/media/dvb/mantis/mantis_ca.c69
-rw-r--r--drivers/media/dvb/mantis/mantis_ca.h7
-rw-r--r--drivers/media/dvb/mantis/mantis_cards.c279
-rw-r--r--drivers/media/dvb/mantis/mantis_common.h68
-rw-r--r--drivers/media/dvb/mantis/mantis_dma.c55
-rw-r--r--drivers/media/dvb/mantis/mantis_dma.h10
-rw-r--r--drivers/media/dvb/mantis/mantis_dvb.c364
-rw-r--r--drivers/media/dvb/mantis/mantis_dvb.h15
-rw-r--r--drivers/media/dvb/mantis/mantis_evm.c38
-rw-r--r--drivers/media/dvb/mantis/mantis_hif.c60
-rw-r--r--drivers/media/dvb/mantis/mantis_hif.h2
-rw-r--r--drivers/media/dvb/mantis/mantis_i2c.c75
-rw-r--r--drivers/media/dvb/mantis/mantis_i2c.h7
-rw-r--r--drivers/media/dvb/mantis/mantis_ioc.c145
-rw-r--r--drivers/media/dvb/mantis/mantis_link.h3
-rw-r--r--drivers/media/dvb/mantis/mantis_pci.c310
-rw-r--r--drivers/media/dvb/mantis/mantis_pci.h7
-rw-r--r--drivers/media/dvb/mantis/mantis_pcmcia.c22
-rw-r--r--drivers/media/dvb/mantis/mantis_reg.h40
-rw-r--r--drivers/media/dvb/mantis/mantis_uart.c37
-rw-r--r--drivers/media/dvb/mantis/mantis_uart.h2
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.c98
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.h13
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.c66
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.h6
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1041.c79
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1041.h14
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.c95
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.h11
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2040.c141
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2040.h11
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.c49
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.h8
38 files changed, 1881 insertions, 735 deletions
diff --git a/drivers/media/dvb/mantis/Kconfig b/drivers/media/dvb/mantis/Kconfig
index 4ba16d0ad96b..aaf025097b44 100644
--- a/drivers/media/dvb/mantis/Kconfig
+++ b/drivers/media/dvb/mantis/Kconfig
@@ -1,6 +1,15 @@
1config MANTIS_CORE
2 tristate "Mantis/Hopper PCI bridge based devices"
3 depends on PCI && I2C
4
5 help
6 Support for PCI cards based on the Mantis and Hopper PCi bridge.
7
8 Say Y if you own such a device and want to use it.
9
1config DVB_MANTIS 10config DVB_MANTIS
2 tristate "MANTIS based cards" 11 tristate "MANTIS based cards"
3 depends on DVB_CORE && PCI && I2C 12 depends on MANTIS_CORE && DVB_CORE && PCI && I2C
4 select DVB_MB86A16 13 select DVB_MB86A16
5 select DVB_CU1216 14 select DVB_CU1216
6 select DVB_ZL10353 15 select DVB_ZL10353
@@ -11,3 +20,14 @@ config DVB_MANTIS
11 Say Y when you have a Mantis based DVB card and want to use it. 20 Say Y when you have a Mantis based DVB card and want to use it.
12 21
13 If unsure say N. 22 If unsure say N.
23
24config DVB_HOPPER
25 tristate "HOPPER based cards"
26 depends on MANTIS_CORE && DVB_CORE && PCI && I2C
27 select DVB_ZL10353
28 select DVB_PLL
29 help
30 Support for PCI cards based on the Hopper PCI bridge.
31 Say Y when you have a Hopper based DVB card and want to use it.
32
33 If unsure say N
diff --git a/drivers/media/dvb/mantis/Makefile b/drivers/media/dvb/mantis/Makefile
index bb88cdc98ce0..399c9018cdb0 100644
--- a/drivers/media/dvb/mantis/Makefile
+++ b/drivers/media/dvb/mantis/Makefile
@@ -1,21 +1,27 @@
1mantis-objs = mantis_core.o \ 1mantis_core-objs := mantis_ioc.o \
2 mantis_uart.o \ 2 mantis_uart.o \
3 mantis_dma.o \ 3 mantis_dma.o \
4 mantis_pci.o \ 4 mantis_pci.o \
5 mantis_i2c.o \ 5 mantis_i2c.o \
6 mantis_dvb.o \ 6 mantis_dvb.o \
7 mantis_evm.o \ 7 mantis_evm.o \
8 mantis_hif.o \ 8 mantis_hif.o \
9 mantis_ca.o \ 9 mantis_ca.o \
10 mantis_pcmcia.o \ 10 mantis_pcmcia.o
11 mantis_vp1033.o \
12 mantis_vp1034.o \
13 mantis_vp1041.o \
14 mantis_vp2033.o \
15 mantis_vp2040.o \
16 mantis_vp3028.o \
17 mantis_vp3030.o
18 11
19obj-$(CONFIG_DVB_MANTIS) += mantis.o 12mantis-objs := mantis_cards.o \
13 mantis_vp1033.o \
14 mantis_vp1034.o \
15 mantis_vp1041.o \
16 mantis_vp2033.o \
17 mantis_vp2040.o \
18 mantis_vp3030.o
19
20hopper-objs := hopper_cards.o \
21 hopper_vp3028.o
22
23obj-$(CONFIG_MANTIS_CORE) += mantis_core.o
24obj-$(CONFIG_DVB_MANTIS) += mantis.o
25obj-$(CONFIG_DVB_HOPPER) += hopper.o
20 26
21EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 27EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/mantis/hopper_cards.c b/drivers/media/dvb/mantis/hopper_cards.c
new file mode 100644
index 000000000000..749e3f3dd06b
--- /dev/null
+++ b/drivers/media/dvb/mantis/hopper_cards.c
@@ -0,0 +1,260 @@
1#include <linux/module.h>
2#include <linux/moduleparam.h>
3#include <linux/kernel.h>
4#include <linux/pci.h>
5#include <asm/irq.h>
6#include <linux/interrupt.h>
7
8#include "dmxdev.h"
9#include "dvbdev.h"
10#include "dvb_demux.h"
11#include "dvb_frontend.h"
12#include "dvb_net.h"
13
14#include "mantis_common.h"
15#include "hopper_vp3028.h"
16#include "mantis_dma.h"
17#include "mantis_dvb.h"
18#include "mantis_uart.h"
19#include "mantis_ioc.h"
20#include "mantis_pci.h"
21#include "mantis_i2c.h"
22#include "mantis_reg.h"
23
24static unsigned int verbose;
25module_param(verbose, int, 0644);
26MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
27
28#define DRIVER_NAME "Hopper"
29
30static char *label[10] = {
31 "DMA",
32 "IRQ-0",
33 "IRQ-1",
34 "OCERR",
35 "PABRT",
36 "RIPRR",
37 "PPERR",
38 "FTRGT",
39 "RISCI",
40 "RACK"
41};
42
43static int devs;
44
45static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
46{
47 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
48 u32 rst_stat = 0, rst_mask = 0;
49
50 struct mantis_pci *mantis;
51 struct mantis_ca *ca;
52
53 mantis = (struct mantis_pci *) dev_id;
54 if (unlikely(mantis == NULL)) {
55 dprintk(MANTIS_ERROR, 1, "Mantis == NULL");
56 return IRQ_NONE;
57 }
58 ca = mantis->mantis_ca;
59
60 stat = mmread(MANTIS_INT_STAT);
61 mask = mmread(MANTIS_INT_MASK);
62 mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
63 if (!(stat & mask))
64 return IRQ_NONE;
65
66 rst_mask = MANTIS_GPIF_WRACK |
67 MANTIS_GPIF_OTHERR |
68 MANTIS_SBUF_WSTO |
69 MANTIS_GPIF_EXTIRQ;
70
71 rst_stat = mmread(MANTIS_GPIF_STATUS);
72 rst_stat &= rst_mask;
73 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
74
75 mantis->mantis_int_stat = stat;
76 mantis->mantis_int_mask = mask;
77 dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
78 if (stat & MANTIS_INT_RISCEN) {
79 dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
80 }
81 if (stat & MANTIS_INT_IRQ0) {
82 dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
83 mantis->gpif_status = rst_stat;
84 wake_up(&ca->hif_write_wq);
85 schedule_work(&ca->hif_evm_work);
86 }
87 if (stat & MANTIS_INT_IRQ1) {
88 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
89 schedule_work(&mantis->uart_work);
90 }
91 if (stat & MANTIS_INT_OCERR) {
92 dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
93 }
94 if (stat & MANTIS_INT_PABORT) {
95 dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
96 }
97 if (stat & MANTIS_INT_RIPERR) {
98 dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
99 }
100 if (stat & MANTIS_INT_PPERR) {
101 dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
102 }
103 if (stat & MANTIS_INT_FTRGT) {
104 dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
105 }
106 if (stat & MANTIS_INT_RISCI) {
107 dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
108 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
109 tasklet_schedule(&mantis->tasklet);
110 }
111 if (stat & MANTIS_INT_I2CDONE) {
112 dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
113 wake_up(&mantis->i2c_wq);
114 }
115 mmwrite(stat, MANTIS_INT_STAT);
116 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
117 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
118 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
119 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
120 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
121 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
122 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
123 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
124 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
125 MANTIS_INT_RISCI);
126
127 if (stat)
128 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
129
130 dprintk(MANTIS_DEBUG, 0, "\n");
131 return IRQ_HANDLED;
132}
133
134static int __devinit hopper_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
135{
136 struct mantis_pci *mantis;
137 struct mantis_hwconfig *config;
138 int err = 0;
139
140 mantis = kzalloc(sizeof (struct mantis_pci), GFP_KERNEL);
141 if (mantis == NULL) {
142 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
143 err = -ENOMEM;
144 goto fail0;
145 }
146
147 mantis->num = devs;
148 mantis->verbose = verbose;
149 mantis->pdev = pdev;
150 config = (struct mantis_hwconfig *) pci_id->driver_data;
151 config->irq_handler = &hopper_irq_handler;
152 mantis->hwconfig = config;
153
154 err = mantis_pci_init(mantis);
155 if (err) {
156 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
157 goto fail1;
158 }
159
160 err = mantis_stream_control(mantis, STREAM_TO_HIF);
161 if (err < 0) {
162 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
163 goto fail1;
164 }
165
166 err = mantis_i2c_init(mantis);
167 if (err < 0) {
168 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
169 goto fail2;
170 }
171
172 err = mantis_get_mac(mantis);
173 if (err < 0) {
174 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
175 goto fail2;
176 }
177
178 err = mantis_dma_init(mantis);
179 if (err < 0) {
180 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
181 goto fail3;
182 }
183
184 err = mantis_dvb_init(mantis);
185 if (err < 0) {
186 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
187 goto fail4;
188 }
189 devs++;
190
191 return err;
192
193fail5:
194 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
195 mantis_dvb_exit(mantis);
196
197fail4:
198 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
199 mantis_dma_exit(mantis);
200
201fail3:
202 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
203 mantis_i2c_exit(mantis);
204
205fail2:
206 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
207 mantis_pci_exit(mantis);
208
209fail1:
210 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
211 kfree(mantis);
212
213fail0:
214 return err;
215}
216
217static void __devexit hopper_pci_remove(struct pci_dev *pdev)
218{
219 struct mantis_pci *mantis = pci_get_drvdata(pdev);
220
221 if (mantis) {
222// mantis_uart_exit(mantis);
223 mantis_dvb_exit(mantis);
224 mantis_dma_exit(mantis);
225 mantis_i2c_exit(mantis);
226 mantis_pci_exit(mantis);
227 kfree(mantis);
228 }
229 return;
230
231}
232
233static struct pci_device_id hopper_pci_table[] = {
234 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config),
235 { }
236};
237
238static struct pci_driver hopper_pci_driver = {
239 .name = DRIVER_NAME,
240 .id_table = hopper_pci_table,
241 .probe = hopper_pci_probe,
242 .remove = hopper_pci_remove,
243};
244
245static int __devinit hopper_init(void)
246{
247 return pci_register_driver(&hopper_pci_driver);
248}
249
250static void __devexit hopper_exit(void)
251{
252 return pci_unregister_driver(&hopper_pci_driver);
253}
254
255module_init(hopper_init);
256module_exit(hopper_exit);
257
258MODULE_DESCRIPTION("HOPPER driver");
259MODULE_AUTHOR("Manu Abraham");
260MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/mantis/hopper_vp3028.c b/drivers/media/dvb/mantis/hopper_vp3028.c
new file mode 100644
index 000000000000..ba0c7e58b7a6
--- /dev/null
+++ b/drivers/media/dvb/mantis/hopper_vp3028.c
@@ -0,0 +1,76 @@
1/*
2 Mantis VP-3028 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "zl10353.h"
33#include "mantis_common.h"
34#include "mantis_ioc.h"
35#include "mantis_dvb.h"
36#include "hopper_vp3028.h"
37
38struct zl10353_config hopper_vp3028_config = {
39 .demod_address = 0x0f,
40};
41
42#define MANTIS_MODEL_NAME "VP-3028"
43#define MANTIS_DEV_TYPE "DVB-T"
44
45static int vp3028_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
46{
47 struct i2c_adapter *adapter = &mantis->adapter;
48 int err = 0;
49
50 err = mantis_frontend_power(mantis, POWER_ON);
51 mantis_frontend_soft_reset(mantis);
52
53 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
54 fe = zl10353_attach(&hopper_vp3028_config, adapter);
55
56 if (!fe)
57 return -1;
58
59 dprintk(MANTIS_ERROR, 1, "Done!");
60
61 return 0;
62}
63
64struct mantis_hwconfig vp3028_config = {
65 .model_name = MANTIS_MODEL_NAME,
66 .dev_type = MANTIS_DEV_TYPE,
67 .ts_size = MANTIS_TS_188,
68
69 .baud_rate = MANTIS_BAUD_9600,
70 .parity = MANTIS_PARITY_NONE,
71 .bytes = 0,
72
73 .frontend_init = vp3028_frontend_init,
74 .power = GPIF_A00,
75 .reset = GPIF_A03,
76};
diff --git a/drivers/media/dvb/mantis/hopper_vp3028.h b/drivers/media/dvb/mantis/hopper_vp3028.h
new file mode 100644
index 000000000000..e8a3c2297bb1
--- /dev/null
+++ b/drivers/media/dvb/mantis/hopper_vp3028.h
@@ -0,0 +1,10 @@
1#ifndef __MANTIS_VP3028_H
2#define __MANTIS_VP3028_H
3
4#include "mantis_common.h"
5
6#define MANTIS_VP_3028_DVB_T 0x0028
7
8extern struct mantis_hwconfig vp3028_config;
9
10#endif /* __MANTIS_VP3028_H */
diff --git a/drivers/media/dvb/mantis/mantis_ca.c b/drivers/media/dvb/mantis/mantis_ca.c
index 7aa27e0703b8..4151cba35e72 100644
--- a/drivers/media/dvb/mantis/mantis_ca.c
+++ b/drivers/media/dvb/mantis/mantis_ca.c
@@ -18,16 +18,30 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
21#include "mantis_common.h" 32#include "mantis_common.h"
22#include "mantis_link.h" 33#include "mantis_link.h"
23#include "mantis_hif.h" 34#include "mantis_hif.h"
35#include "mantis_reg.h"
36
37#include "mantis_ca.h"
24 38
25static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr) 39static int mantis_ca_read_attr_mem(struct dvb_ca_en50221 *en50221, int slot, int addr)
26{ 40{
27 struct mantis_ca *ca = en50221->data; 41 struct mantis_ca *ca = en50221->data;
28 struct mantis_pci *mantis = ca->ca_priv; 42 struct mantis_pci *mantis = ca->ca_priv;
29 43
30 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot); 44 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Read", slot);
31 45
32 if (slot != 0) 46 if (slot != 0)
33 return -EINVAL; 47 return -EINVAL;
@@ -40,7 +54,7 @@ static int mantis_ca_write_attr_mem(struct dvb_ca_en50221 *en50221, int slot, in
40 struct mantis_ca *ca = en50221->data; 54 struct mantis_ca *ca = en50221->data;
41 struct mantis_pci *mantis = ca->ca_priv; 55 struct mantis_pci *mantis = ca->ca_priv;
42 56
43 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot); 57 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request Attribute Mem Write", slot);
44 58
45 if (slot != 0) 59 if (slot != 0)
46 return -EINVAL; 60 return -EINVAL;
@@ -53,7 +67,7 @@ static int mantis_ca_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 a
53 struct mantis_ca *ca = en50221->data; 67 struct mantis_ca *ca = en50221->data;
54 struct mantis_pci *mantis = ca->ca_priv; 68 struct mantis_pci *mantis = ca->ca_priv;
55 69
56 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot); 70 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Read", slot);
57 71
58 if (slot != 0) 72 if (slot != 0)
59 return -EINVAL; 73 return -EINVAL;
@@ -66,7 +80,7 @@ static int mantis_ca_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8
66 struct mantis_ca *ca = en50221->data; 80 struct mantis_ca *ca = en50221->data;
67 struct mantis_pci *mantis = ca->ca_priv; 81 struct mantis_pci *mantis = ca->ca_priv;
68 82
69 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot); 83 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Request CAM control Write", slot);
70 84
71 if (slot != 0) 85 if (slot != 0)
72 return -EINVAL; 86 return -EINVAL;
@@ -79,7 +93,7 @@ static int mantis_ca_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
79 struct mantis_ca *ca = en50221->data; 93 struct mantis_ca *ca = en50221->data;
80 struct mantis_pci *mantis = ca->ca_priv; 94 struct mantis_pci *mantis = ca->ca_priv;
81 95
82 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot); 96 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot RESET", slot);
83 udelay(500); /* Wait.. */ 97 udelay(500); /* Wait.. */
84 mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */ 98 mmwrite(0xda, MANTIS_PCMCIA_RESET); /* Leading edge assert */
85 udelay(500); 99 udelay(500);
@@ -95,7 +109,7 @@ static int mantis_ca_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
95 struct mantis_ca *ca = en50221->data; 109 struct mantis_ca *ca = en50221->data;
96 struct mantis_pci *mantis = ca->ca_priv; 110 struct mantis_pci *mantis = ca->ca_priv;
97 111
98 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot); 112 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Slot shutdown", slot);
99 113
100 return 0; 114 return 0;
101} 115}
@@ -105,8 +119,8 @@ static int mantis_ts_control(struct dvb_ca_en50221 *en50221, int slot)
105 struct mantis_ca *ca = en50221->data; 119 struct mantis_ca *ca = en50221->data;
106 struct mantis_pci *mantis = ca->ca_priv; 120 struct mantis_pci *mantis = ca->ca_priv;
107 121
108 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): TS control", slot); 122 dprintk(MANTIS_DEBUG, 1, "Slot(%d): TS control", slot);
109 mantis_set_direction(mantis, 1); /* Enable TS through CAM */ 123// mantis_set_direction(mantis, 1); /* Enable TS through CAM */
110 124
111 return 0; 125 return 0;
112} 126}
@@ -116,13 +130,13 @@ static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open
116 struct mantis_ca *ca = en50221->data; 130 struct mantis_ca *ca = en50221->data;
117 struct mantis_pci *mantis = ca->ca_priv; 131 struct mantis_pci *mantis = ca->ca_priv;
118 132
119 dprintk(verbose, MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot); 133 dprintk(MANTIS_DEBUG, 1, "Slot(%d): Poll Slot status", slot);
120 134
121 if (ca->slot_state == MODULE_INSERTED) { 135 if (ca->slot_state == MODULE_INSERTED) {
122 dprintk(verbose, MANTIS_DEBUG, 1, "CA Module present and ready"); 136 dprintk(MANTIS_DEBUG, 1, "CA Module present and ready");
123 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY; 137 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
124 } else { 138 } else {
125 dprintk(verbose, MANTIS_DEBUG, 1, "CA Module not present or not ready"); 139 dprintk(MANTIS_DEBUG, 1, "CA Module not present or not ready");
126 } 140 }
127 141
128 return 0; 142 return 0;
@@ -130,20 +144,21 @@ static int mantis_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open
130 144
131int mantis_ca_init(struct mantis_pci *mantis) 145int mantis_ca_init(struct mantis_pci *mantis)
132{ 146{
133 struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter; 147 struct dvb_adapter *dvb_adapter = &mantis->dvb_adapter;
134 struct mantis_ca *ca; 148 struct mantis_ca *ca;
135 int ca_flags = 0, result; 149 int ca_flags = 0, result;
136 150
137 dprintk(verbose, MANTIS_DEBUG, 1, "Initializing Mantis CA"); 151 dprintk(MANTIS_DEBUG, 1, "Initializing Mantis CA");
138 if (!(ca = kzalloc(sizeof (struct mantis_ca), GFP_KERNEL))) { 152 ca = kzalloc(sizeof (struct mantis_ca), GFP_KERNEL);
139 dprintk(verbose, MANTIS_ERROR, 1, "Out of memory!, exiting .."); 153 if (!ca) {
154 dprintk(MANTIS_ERROR, 1, "Out of memory!, exiting ..");
140 result = -ENOMEM; 155 result = -ENOMEM;
141 goto err; 156 goto err;
142 } 157 }
143 158
144 ca->ca_priv = mantis; 159 ca->ca_priv = mantis;
145 mantis->mantis_ca = ca; 160 mantis->mantis_ca = ca;
146 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE; 161 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE;
147 /* register CA interface */ 162 /* register CA interface */
148 ca->en50221.owner = THIS_MODULE; 163 ca->en50221.owner = THIS_MODULE;
149 ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem; 164 ca->en50221.read_attribute_mem = mantis_ca_read_attr_mem;
@@ -162,28 +177,32 @@ int mantis_ca_init(struct mantis_pci *mantis)
162 init_waitqueue_head(&ca->hif_opdone_wq); 177 init_waitqueue_head(&ca->hif_opdone_wq);
163 init_waitqueue_head(&ca->hif_write_wq); 178 init_waitqueue_head(&ca->hif_write_wq);
164 179
165 dprintk(verbose, MANTIS_ERROR, 1, "Registering EN50221 device"); 180 dprintk(MANTIS_ERROR, 1, "Registering EN50221 device");
166 if ((result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1)) != 0) { 181 result = dvb_ca_en50221_init(dvb_adapter, &ca->en50221, ca_flags, 1);
167 dprintk(verbose, MANTIS_ERROR, 1, "EN50221: Initialization failed"); 182 if (result != 0) {
183 dprintk(MANTIS_ERROR, 1, "EN50221: Initialization failed <%d>", result);
168 goto err; 184 goto err;
169 } 185 }
170 dprintk(verbose, MANTIS_ERROR, 1, "Registered EN50221 device"); 186 dprintk(MANTIS_ERROR, 1, "Registered EN50221 device");
171 mantis_evmgr_init(ca); 187 mantis_evmgr_init(ca);
172 return 0; 188 return 0;
173err: 189err:
174 kfree(ca); 190 kfree(ca);
175 return result; 191 return result;
176} 192}
193EXPORT_SYMBOL_GPL(mantis_ca_init);
177 194
178void mantis_ca_exit(struct mantis_pci *mantis) 195void mantis_ca_exit(struct mantis_pci *mantis)
179{ 196{
180 struct mantis_ca *ca = mantis->mantis_ca; 197 struct mantis_ca *ca = mantis->mantis_ca;
181 198
182 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis CA exit"); 199 dprintk(MANTIS_DEBUG, 1, "Mantis CA exit");
183 200
184 mantis_evmgr_exit(ca); 201 mantis_evmgr_exit(ca);
185 dprintk(verbose, MANTIS_ERROR, 1, "Unregistering EN50221 device"); 202 dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device");
186 dvb_ca_en50221_release(&ca->en50221); 203 if (ca)
204 dvb_ca_en50221_release(&ca->en50221);
187 205
188 kfree(ca); 206 kfree(ca);
189} 207}
208EXPORT_SYMBOL_GPL(mantis_ca_exit);
diff --git a/drivers/media/dvb/mantis/mantis_ca.h b/drivers/media/dvb/mantis/mantis_ca.h
new file mode 100644
index 000000000000..b7e48ee1fac8
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_ca.h
@@ -0,0 +1,7 @@
1#ifndef __MANTIS_CA_H
2#define __MANTIS_CA_H
3
4extern int mantis_ca_init(struct mantis_pci *mantis);
5extern void mantis_ca_exit(struct mantis_pci *mantis);
6
7#endif /* __MANTIS_CA_H */
diff --git a/drivers/media/dvb/mantis/mantis_cards.c b/drivers/media/dvb/mantis/mantis_cards.c
new file mode 100644
index 000000000000..d486c7fcb453
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_cards.c
@@ -0,0 +1,279 @@
1#include <linux/module.h>
2#include <linux/moduleparam.h>
3#include <linux/kernel.h>
4#include <linux/pci.h>
5#include <asm/irq.h>
6#include <linux/interrupt.h>
7
8#include "dmxdev.h"
9#include "dvbdev.h"
10#include "dvb_demux.h"
11#include "dvb_frontend.h"
12#include "dvb_net.h"
13
14#include "mantis_common.h"
15
16#include "mantis_vp1033.h"
17#include "mantis_vp1034.h"
18#include "mantis_vp1041.h"
19#include "mantis_vp2033.h"
20#include "mantis_vp2040.h"
21#include "mantis_vp3030.h"
22
23#include "mantis_dma.h"
24#include "mantis_ca.h"
25#include "mantis_dvb.h"
26#include "mantis_uart.h"
27#include "mantis_ioc.h"
28#include "mantis_pci.h"
29#include "mantis_i2c.h"
30#include "mantis_reg.h"
31
32static unsigned int verbose;
33module_param(verbose, int, 0644);
34MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
35
36static int devs;
37
38#define DRIVER_NAME "Mantis"
39
40static char *label[10] = {
41 "DMA",
42 "IRQ-0",
43 "IRQ-1",
44 "OCERR",
45 "PABRT",
46 "RIPRR",
47 "PPERR",
48 "FTRGT",
49 "RISCI",
50 "RACK"
51};
52
53
54static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
55{
56 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
57 u32 rst_stat = 0, rst_mask = 0;
58
59 struct mantis_pci *mantis;
60 struct mantis_ca *ca;
61
62 mantis = (struct mantis_pci *) dev_id;
63 if (unlikely(mantis == NULL)) {
64 dprintk(MANTIS_ERROR, 1, "Mantis == NULL");
65 return IRQ_NONE;
66 }
67 ca = mantis->mantis_ca;
68
69 stat = mmread(MANTIS_INT_STAT);
70 mask = mmread(MANTIS_INT_MASK);
71 mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
72 if (!(stat & mask))
73 return IRQ_NONE;
74
75 rst_mask = MANTIS_GPIF_WRACK |
76 MANTIS_GPIF_OTHERR |
77 MANTIS_SBUF_WSTO |
78 MANTIS_GPIF_EXTIRQ;
79
80 rst_stat = mmread(MANTIS_GPIF_STATUS);
81 rst_stat &= rst_mask;
82 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
83
84 mantis->mantis_int_stat = stat;
85 mantis->mantis_int_mask = mask;
86 dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
87 if (stat & MANTIS_INT_RISCEN) {
88 dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
89 }
90 if (stat & MANTIS_INT_IRQ0) {
91 dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
92 mantis->gpif_status = rst_stat;
93 wake_up(&ca->hif_write_wq);
94 schedule_work(&ca->hif_evm_work);
95 }
96 if (stat & MANTIS_INT_IRQ1) {
97 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
98 schedule_work(&mantis->uart_work);
99 }
100 if (stat & MANTIS_INT_OCERR) {
101 dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
102 }
103 if (stat & MANTIS_INT_PABORT) {
104 dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
105 }
106 if (stat & MANTIS_INT_RIPERR) {
107 dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
108 }
109 if (stat & MANTIS_INT_PPERR) {
110 dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
111 }
112 if (stat & MANTIS_INT_FTRGT) {
113 dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
114 }
115 if (stat & MANTIS_INT_RISCI) {
116 dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
117 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
118 tasklet_schedule(&mantis->tasklet);
119 }
120 if (stat & MANTIS_INT_I2CDONE) {
121 dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
122 wake_up(&mantis->i2c_wq);
123 }
124 mmwrite(stat, MANTIS_INT_STAT);
125 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
126 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
127 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
128 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
129 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
130 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
131 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
132 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
133 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
134 MANTIS_INT_RISCI);
135
136 if (stat)
137 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
138
139 dprintk(MANTIS_DEBUG, 0, "\n");
140 return IRQ_HANDLED;
141}
142
143static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
144{
145 struct mantis_pci *mantis;
146 struct mantis_hwconfig *config;
147 int err = 0;
148
149 mantis = kzalloc(sizeof (struct mantis_pci), GFP_KERNEL);
150 if (mantis == NULL) {
151 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
152 err = -ENOMEM;
153 goto fail0;
154 }
155
156 mantis->num = devs;
157 mantis->verbose = verbose;
158 mantis->pdev = pdev;
159 config = (struct mantis_hwconfig *) pci_id->driver_data;
160 config->irq_handler = &mantis_irq_handler;
161 mantis->hwconfig = config;
162
163 err = mantis_pci_init(mantis);
164 if (err) {
165 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
166 goto fail1;
167 }
168
169 err = mantis_stream_control(mantis, STREAM_TO_HIF);
170 if (err < 0) {
171 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
172 goto fail1;
173 }
174
175 err = mantis_i2c_init(mantis);
176 if (err < 0) {
177 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
178 goto fail2;
179 }
180
181 err = mantis_get_mac(mantis);
182 if (err < 0) {
183 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
184 goto fail2;
185 }
186
187 err = mantis_dma_init(mantis);
188 if (err < 0) {
189 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
190 goto fail3;
191 }
192
193 err = mantis_dvb_init(mantis);
194 if (err < 0) {
195 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
196 goto fail4;
197 }
198 devs++;
199
200 return err;
201
202fail5:
203 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
204 mantis_dvb_exit(mantis);
205
206fail4:
207 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
208 mantis_dma_exit(mantis);
209
210fail3:
211 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
212 mantis_i2c_exit(mantis);
213
214fail2:
215 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
216 mantis_pci_exit(mantis);
217
218fail1:
219 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
220 kfree(mantis);
221
222fail0:
223 return err;
224}
225
226static void __devexit mantis_pci_remove(struct pci_dev *pdev)
227{
228 struct mantis_pci *mantis = pci_get_drvdata(pdev);
229
230 if (mantis) {
231 mantis_uart_exit(mantis);
232// mantis_ca_exit(mantis);
233 mantis_dvb_exit(mantis);
234 mantis_dma_exit(mantis);
235 mantis_i2c_exit(mantis);
236 mantis_pci_exit(mantis);
237 kfree(mantis);
238 }
239 return;
240}
241
242static struct pci_device_id mantis_pci_table[] = {
243 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config),
244 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config),
245 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config),
246 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config),
247 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config),
248 MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config),
249 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config),
250 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config),
251 MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config),
252 MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config),
253 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config),
254 { }
255};
256
257static struct pci_driver mantis_pci_driver = {
258 .name = DRIVER_NAME,
259 .id_table = mantis_pci_table,
260 .probe = mantis_pci_probe,
261 .remove = mantis_pci_remove,
262};
263
264static int __devinit mantis_init(void)
265{
266 return pci_register_driver(&mantis_pci_driver);
267}
268
269static void __devexit mantis_exit(void)
270{
271 return pci_unregister_driver(&mantis_pci_driver);
272}
273
274module_init(mantis_init);
275module_exit(mantis_exit);
276
277MODULE_DESCRIPTION("MANTIS driver");
278MODULE_AUTHOR("Manu Abraham");
279MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/mantis/mantis_common.h b/drivers/media/dvb/mantis/mantis_common.h
index 6a02adf1ab4d..e912c5962e3a 100644
--- a/drivers/media/dvb/mantis/mantis_common.h
+++ b/drivers/media/dvb/mantis/mantis_common.h
@@ -21,20 +21,9 @@
21#ifndef __MANTIS_COMMON_H 21#ifndef __MANTIS_COMMON_H
22#define __MANTIS_COMMON_H 22#define __MANTIS_COMMON_H
23 23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/kernel.h>
27#include <linux/pci.h>
28#include <linux/mutex.h> 24#include <linux/mutex.h>
29#include <linux/workqueue.h> 25#include <linux/workqueue.h>
30 26
31#include "dvbdev.h"
32#include "dvb_demux.h"
33#include "dmxdev.h"
34#include "dvb_frontend.h"
35#include "dvb_net.h"
36#include <linux/i2c.h>
37#include "mantis_reg.h"
38#include "mantis_uart.h" 27#include "mantis_uart.h"
39 28
40#include "mantis_link.h" 29#include "mantis_link.h"
@@ -44,18 +33,18 @@
44#define MANTIS_INFO 2 33#define MANTIS_INFO 2
45#define MANTIS_DEBUG 3 34#define MANTIS_DEBUG 3
46 35
47#define dprintk(x, y, z, format, arg...) do { \ 36#define dprintk(y, z, format, arg...) do { \
48 if (z) { \ 37 if (z) { \
49 if ((x > MANTIS_ERROR) && (x > y)) \ 38 if ((mantis->verbose > MANTIS_ERROR) && (mantis->verbose > y)) \
50 printk(KERN_ERR "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \ 39 printk(KERN_ERR "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
51 else if ((x > MANTIS_NOTICE) && (x > y)) \ 40 else if ((mantis->verbose > MANTIS_NOTICE) && (mantis->verbose > y)) \
52 printk(KERN_NOTICE "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \ 41 printk(KERN_NOTICE "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
53 else if ((x > MANTIS_INFO) && (x > y)) \ 42 else if ((mantis->verbose > MANTIS_INFO) && (mantis->verbose > y)) \
54 printk(KERN_INFO "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \ 43 printk(KERN_INFO "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
55 else if ((x > MANTIS_DEBUG) && (x > y)) \ 44 else if ((mantis->verbose > MANTIS_DEBUG) && (mantis->verbose > y)) \
56 printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \ 45 printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
57 } else { \ 46 } else { \
58 if (x > y) \ 47 if (mantis->verbose > y) \
59 printk(format , ##arg); \ 48 printk(format , ##arg); \
60 } \ 49 } \
61} while(0) 50} while(0)
@@ -63,8 +52,8 @@
63#define mwrite(dat, addr) writel((dat), addr) 52#define mwrite(dat, addr) writel((dat), addr)
64#define mread(addr) readl(addr) 53#define mread(addr) readl(addr)
65 54
66#define mmwrite(dat, addr) mwrite((dat), (mantis->mantis_mmio + (addr))) 55#define mmwrite(dat, addr) mwrite((dat), (mantis->mmio + (addr)))
67#define mmread(addr) mread(mantis->mantis_mmio + (addr)) 56#define mmread(addr) mread(mantis->mmio + (addr))
68#define mmand(dat, addr) mmwrite((dat) & mmread(addr), addr) 57#define mmand(dat, addr) mmwrite((dat) & mmread(addr), addr)
69#define mmor(dat, addr) mmwrite((dat) | mmread(addr), addr) 58#define mmor(dat, addr) mmwrite((dat) | mmread(addr), addr)
70#define mmaor(dat, addr) mmwrite((dat) | ((mask) & mmread(addr)), addr) 59#define mmaor(dat, addr) mmwrite((dat) | ((mask) & mmread(addr)), addr)
@@ -72,6 +61,22 @@
72#define MANTIS_TS_188 0 61#define MANTIS_TS_188 0
73#define MANTIS_TS_204 1 62#define MANTIS_TS_204 1
74 63
64#define TWINHAN_TECHNOLOGIES 0x1822
65#define MANTIS 0x4e35
66
67#define TECHNISAT 0x1ae4
68#define TERRATEC 0x153b
69
70#define MAKE_ENTRY(__subven, __subdev, __configptr) { \
71 .vendor = TWINHAN_TECHNOLOGIES, \
72 .device = MANTIS, \
73 .subvendor = (__subven), \
74 .subdevice = (__subdev), \
75 .driver_data = (unsigned long) (__configptr) \
76}
77
78struct mantis_pci;
79
75struct mantis_hwconfig { 80struct mantis_hwconfig {
76 char *model_name; 81 char *model_name;
77 char *dev_type; 82 char *dev_type;
@@ -80,6 +85,12 @@ struct mantis_hwconfig {
80 enum mantis_baud baud_rate; 85 enum mantis_baud baud_rate;
81 enum mantis_parity parity; 86 enum mantis_parity parity;
82 u32 bytes; 87 u32 bytes;
88
89 irqreturn_t (*irq_handler)(int irq, void *dev_id);
90 int (*frontend_init)(struct mantis_pci *mantis, struct dvb_frontend *fe);
91
92 u8 power;
93 u8 reset;
83}; 94};
84 95
85struct mantis_pci { 96struct mantis_pci {
@@ -96,7 +107,7 @@ struct mantis_pci {
96 struct pci_dev *pdev; 107 struct pci_dev *pdev;
97 108
98 unsigned long mantis_addr; 109 unsigned long mantis_addr;
99 volatile void __iomem *mantis_mmio; 110 void __iomem *mmio;
100 111
101 u8 irq; 112 u8 irq;
102 u8 revision; 113 u8 revision;
@@ -156,19 +167,4 @@ struct mantis_pci {
156 167
157#define MANTIS_HIF_STATUS (mantis->gpio_status) 168#define MANTIS_HIF_STATUS (mantis->gpio_status)
158 169
159extern unsigned int verbose; 170#endif /* __MANTIS_COMMON_H */
160extern unsigned int devs;
161extern unsigned int i2c;
162extern int mantis_dvb_init(struct mantis_pci *mantis);
163extern int mantis_frontend_init(struct mantis_pci *mantis);
164extern int mantis_dvb_exit(struct mantis_pci *mantis);
165extern void mantis_dma_xfer(unsigned long data);
166extern void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value);
167
168extern void mantis_set_direction(struct mantis_pci *mantis, int direction);
169
170extern int mantis_ca_init(struct mantis_pci *mantis);
171extern void mantis_ca_exit(struct mantis_pci *mantis);
172
173
174#endif //__MANTIS_COMMON_H
diff --git a/drivers/media/dvb/mantis/mantis_dma.c b/drivers/media/dvb/mantis/mantis_dma.c
index d15a1eb980c8..8ebcd96b2b7d 100644
--- a/drivers/media/dvb/mantis/mantis_dma.c
+++ b/drivers/media/dvb/mantis/mantis_dma.c
@@ -18,9 +18,25 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/kernel.h>
21#include <asm/page.h> 22#include <asm/page.h>
22#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
24#include <linux/pci.h>
25
26#include <asm/irq.h>
27#include <linux/signal.h>
28#include <linux/sched.h>
29#include <linux/interrupt.h>
30
31#include "dmxdev.h"
32#include "dvbdev.h"
33#include "dvb_demux.h"
34#include "dvb_frontend.h"
35#include "dvb_net.h"
36
23#include "mantis_common.h" 37#include "mantis_common.h"
38#include "mantis_reg.h"
39#include "mantis_dma.h"
24 40
25#define RISC_WRITE (0x01 << 28) 41#define RISC_WRITE (0x01 << 28)
26#define RISC_JUMP (0x07 << 28) 42#define RISC_JUMP (0x07 << 28)
@@ -38,7 +54,7 @@
38int mantis_dma_exit(struct mantis_pci *mantis) 54int mantis_dma_exit(struct mantis_pci *mantis)
39{ 55{
40 if (mantis->buf_cpu) { 56 if (mantis->buf_cpu) {
41 dprintk(verbose, MANTIS_ERROR, 1, 57 dprintk(MANTIS_ERROR, 1,
42 "DMA=0x%lx cpu=0x%p size=%d", 58 "DMA=0x%lx cpu=0x%p size=%d",
43 (unsigned long) mantis->buf_dma, 59 (unsigned long) mantis->buf_dma,
44 mantis->buf_cpu, 60 mantis->buf_cpu,
@@ -50,7 +66,7 @@ int mantis_dma_exit(struct mantis_pci *mantis)
50 mantis->buf_cpu = NULL; 66 mantis->buf_cpu = NULL;
51 } 67 }
52 if (mantis->risc_cpu) { 68 if (mantis->risc_cpu) {
53 dprintk(verbose, MANTIS_ERROR, 1, 69 dprintk(MANTIS_ERROR, 1,
54 "RISC=0x%lx cpu=0x%p size=%lx", 70 "RISC=0x%lx cpu=0x%p size=%lx",
55 (unsigned long) mantis->risc_dma, 71 (unsigned long) mantis->risc_dma,
56 mantis->risc_cpu, 72 mantis->risc_cpu,
@@ -64,6 +80,7 @@ int mantis_dma_exit(struct mantis_pci *mantis)
64 80
65 return 0; 81 return 0;
66} 82}
83EXPORT_SYMBOL_GPL(mantis_dma_exit);
67 84
68static inline int mantis_alloc_buffers(struct mantis_pci *mantis) 85static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
69{ 86{
@@ -72,12 +89,12 @@ static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
72 MANTIS_BUF_SIZE, 89 MANTIS_BUF_SIZE,
73 &mantis->buf_dma); 90 &mantis->buf_dma);
74 if (!mantis->buf_cpu) { 91 if (!mantis->buf_cpu) {
75 dprintk(verbose, MANTIS_ERROR, 1, 92 dprintk(MANTIS_ERROR, 1,
76 "DMA buffer allocation failed"); 93 "DMA buffer allocation failed");
77 94
78 goto err; 95 goto err;
79 } 96 }
80 dprintk(verbose, MANTIS_ERROR, 1, 97 dprintk(MANTIS_ERROR, 1,
81 "DMA=0x%lx cpu=0x%p size=%d", 98 "DMA=0x%lx cpu=0x%p size=%d",
82 (unsigned long) mantis->buf_dma, 99 (unsigned long) mantis->buf_dma,
83 mantis->buf_cpu, MANTIS_BUF_SIZE); 100 mantis->buf_cpu, MANTIS_BUF_SIZE);
@@ -88,14 +105,14 @@ static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
88 &mantis->risc_dma); 105 &mantis->risc_dma);
89 106
90 if (!mantis->risc_cpu) { 107 if (!mantis->risc_cpu) {
91 dprintk(verbose, MANTIS_ERROR, 1, 108 dprintk(MANTIS_ERROR, 1,
92 "RISC program allocation failed"); 109 "RISC program allocation failed");
93 110
94 mantis_dma_exit(mantis); 111 mantis_dma_exit(mantis);
95 112
96 goto err; 113 goto err;
97 } 114 }
98 dprintk(verbose, MANTIS_ERROR, 1, 115 dprintk(MANTIS_ERROR, 1,
99 "RISC=0x%lx cpu=0x%p size=%lx", 116 "RISC=0x%lx cpu=0x%p size=%lx",
100 (unsigned long) mantis->risc_dma, 117 (unsigned long) mantis->risc_dma,
101 mantis->risc_cpu, MANTIS_RISC_SIZE); 118 mantis->risc_cpu, MANTIS_RISC_SIZE);
@@ -103,7 +120,7 @@ static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
103 120
104 return 0; 121 return 0;
105err: 122err:
106 dprintk(verbose, MANTIS_ERROR, 1, "Out of memory (?) ....."); 123 dprintk(MANTIS_ERROR, 1, "Out of memory (?) .....");
107 return -ENOMEM; 124 return -ENOMEM;
108} 125}
109 126
@@ -117,12 +134,11 @@ static inline int mantis_calc_lines(struct mantis_pci *mantis)
117 mantis->line_count <<= 1; 134 mantis->line_count <<= 1;
118 } 135 }
119 136
120 dprintk(verbose, MANTIS_DEBUG, 1, 137 dprintk(MANTIS_DEBUG, 1, "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]",
121 "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]",
122 MANTIS_BLOCK_BYTES, mantis->line_bytes, mantis->line_count); 138 MANTIS_BLOCK_BYTES, mantis->line_bytes, mantis->line_count);
123 139
124 if (mantis->line_count > 255) { 140 if (mantis->line_count > 255) {
125 dprintk(verbose, MANTIS_ERROR, 1, "Buffer size error"); 141 dprintk(MANTIS_ERROR, 1, "Buffer size error");
126 return -EINVAL; 142 return -EINVAL;
127 } 143 }
128 144
@@ -133,9 +149,9 @@ int mantis_dma_init(struct mantis_pci *mantis)
133{ 149{
134 int err = 0; 150 int err = 0;
135 151
136 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DMA init"); 152 dprintk(MANTIS_DEBUG, 1, "Mantis DMA init");
137 if (mantis_alloc_buffers(mantis) < 0) { 153 if (mantis_alloc_buffers(mantis) < 0) {
138 dprintk(verbose, MANTIS_ERROR, 1, "Error allocating DMA buffer"); 154 dprintk(MANTIS_ERROR, 1, "Error allocating DMA buffer");
139 155
140 // Stop RISC Engine 156 // Stop RISC Engine
141// mmwrite(mmread(MANTIS_DMA_CTL) & ~MANTIS_RISC_EN, MANTIS_DMA_CTL); 157// mmwrite(mmread(MANTIS_DMA_CTL) & ~MANTIS_RISC_EN, MANTIS_DMA_CTL);
@@ -144,7 +160,7 @@ int mantis_dma_init(struct mantis_pci *mantis)
144 goto err; 160 goto err;
145 } 161 }
146 if ((err = mantis_calc_lines(mantis)) < 0) { 162 if ((err = mantis_calc_lines(mantis)) < 0) {
147 dprintk(verbose, MANTIS_ERROR, 1, "Mantis calc lines failed"); 163 dprintk(MANTIS_ERROR, 1, "Mantis calc lines failed");
148 164
149 goto err; 165 goto err;
150 } 166 }
@@ -153,20 +169,21 @@ int mantis_dma_init(struct mantis_pci *mantis)
153err: 169err:
154 return err; 170 return err;
155} 171}
172EXPORT_SYMBOL_GPL(mantis_dma_init);
156 173
157static inline void mantis_risc_program(struct mantis_pci *mantis) 174static inline void mantis_risc_program(struct mantis_pci *mantis)
158{ 175{
159 u32 buf_pos = 0; 176 u32 buf_pos = 0;
160 u32 line; 177 u32 line;
161 178
162 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis create RISC program"); 179 dprintk(MANTIS_DEBUG, 1, "Mantis create RISC program");
163 RISC_FLUSH(); 180 RISC_FLUSH();
164 181
165 dprintk(verbose, MANTIS_DEBUG, 1, "risc len lines %u, bytes per line %u", 182 dprintk(MANTIS_DEBUG, 1, "risc len lines %u, bytes per line %u",
166 mantis->line_count, mantis->line_bytes); 183 mantis->line_count, mantis->line_bytes);
167 184
168 for (line = 0; line < mantis->line_count; line++) { 185 for (line = 0; line < mantis->line_count; line++) {
169 dprintk(verbose, MANTIS_DEBUG, 1, "RISC PROG line=[%d]", line); 186 dprintk(MANTIS_DEBUG, 1, "RISC PROG line=[%d]", line);
170 if (!(buf_pos % MANTIS_BLOCK_BYTES)) { 187 if (!(buf_pos % MANTIS_BLOCK_BYTES)) {
171 RISC_INSTR(RISC_WRITE | 188 RISC_INSTR(RISC_WRITE |
172 RISC_IRQ | 189 RISC_IRQ |
@@ -186,7 +203,7 @@ static inline void mantis_risc_program(struct mantis_pci *mantis)
186 203
187void mantis_dma_start(struct mantis_pci *mantis) 204void mantis_dma_start(struct mantis_pci *mantis)
188{ 205{
189 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Start DMA engine"); 206 dprintk(MANTIS_DEBUG, 1, "Mantis Start DMA engine");
190 207
191 mantis_risc_program(mantis); 208 mantis_risc_program(mantis);
192 mmwrite(mantis->risc_dma, MANTIS_RISC_START); 209 mmwrite(mantis->risc_dma, MANTIS_RISC_START);
@@ -208,7 +225,7 @@ void mantis_dma_stop(struct mantis_pci *mantis)
208 225
209 stat = mmread(MANTIS_INT_STAT); 226 stat = mmread(MANTIS_INT_STAT);
210 mask = mmread(MANTIS_INT_MASK); 227 mask = mmread(MANTIS_INT_MASK);
211 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Stop DMA engine"); 228 dprintk(MANTIS_DEBUG, 1, "Mantis Stop DMA engine");
212 229
213 mmwrite((mmread(MANTIS_GPIF_ADDR) & (~(MANTIS_GPIF_HIFRDWRN))), MANTIS_GPIF_ADDR); 230 mmwrite((mmread(MANTIS_GPIF_ADDR) & (~(MANTIS_GPIF_HIFRDWRN))), MANTIS_GPIF_ADDR);
214 231
@@ -229,7 +246,7 @@ void mantis_dma_xfer(unsigned long data)
229 struct mantis_hwconfig *config = mantis->hwconfig; 246 struct mantis_hwconfig *config = mantis->hwconfig;
230 247
231 while (mantis->last_block != mantis->finished_block) { 248 while (mantis->last_block != mantis->finished_block) {
232 dprintk(verbose, MANTIS_DEBUG, 1, "last block=[%d] finished block=[%d]", 249 dprintk(MANTIS_DEBUG, 1, "last block=[%d] finished block=[%d]",
233 mantis->last_block, mantis->finished_block); 250 mantis->last_block, mantis->finished_block);
234 251
235 (config->ts_size ? dvb_dmx_swfilter_204: dvb_dmx_swfilter) 252 (config->ts_size ? dvb_dmx_swfilter_204: dvb_dmx_swfilter)
diff --git a/drivers/media/dvb/mantis/mantis_dma.h b/drivers/media/dvb/mantis/mantis_dma.h
new file mode 100644
index 000000000000..4cba8763536f
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_dma.h
@@ -0,0 +1,10 @@
1#ifndef __MANTIS_DMA_H
2#define __MANTIS_DMA_H
3
4extern int mantis_dma_init(struct mantis_pci *mantis);
5extern int mantis_dma_exit(struct mantis_pci *mantis);
6extern void mantis_dma_start(struct mantis_pci *mantis);
7extern void mantis_dma_stop(struct mantis_pci *mantis);
8extern void mantis_dma_xfer(unsigned long data);
9
10#endif /* __MANTIS_DMA_H */
diff --git a/drivers/media/dvb/mantis/mantis_dvb.c b/drivers/media/dvb/mantis/mantis_dvb.c
index de18bb97d8e9..be911d76daa7 100644
--- a/drivers/media/dvb/mantis/mantis_dvb.c
+++ b/drivers/media/dvb/mantis/mantis_dvb.c
@@ -17,65 +17,86 @@
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include <linux/kernel.h>
20#include <linux/bitops.h> 21#include <linux/bitops.h>
21#include "mantis_common.h" 22
22#include "mantis_core.h" 23#include <asm/irq.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>
23 29
24#include "dmxdev.h" 30#include "dmxdev.h"
25#include "dvbdev.h" 31#include "dvbdev.h"
26#include "dvb_demux.h" 32#include "dvb_demux.h"
27#include "dvb_frontend.h" 33#include "dvb_frontend.h"
28#include "mantis_vp1033.h" 34#include "dvb_net.h"
29#include "mantis_vp1034.h"
30#include "mantis_vp1041.h"
31#include "mantis_vp2033.h"
32#include "mantis_vp2040.h"
33#include "mantis_vp3030.h"
34 35
35DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 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"
36 41
37/* Tuner power supply control */ 42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
38void mantis_fe_powerup(struct mantis_pci *mantis)
39{
40 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power ON");
41 gpio_set_bits(mantis, 0x0c, 1);
42 msleep_interruptible(100);
43 gpio_set_bits(mantis, 0x0c, 1);
44 msleep_interruptible(100);
45}
46 43
47void mantis_fe_powerdown(struct mantis_pci *mantis) 44int mantis_frontend_power(struct mantis_pci *mantis, enum mantis_power power)
48{ 45{
49 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power OFF"); 46 struct mantis_hwconfig *config = mantis->hwconfig;
50 gpio_set_bits(mantis, 0x0c, 0); 47
51} 48 switch (power) {
49 case POWER_ON:
50 dprintk(MANTIS_DEBUG, 1, "Power ON");
51 gpio_set_bits(mantis, config->power, POWER_ON);
52 msleep(100);
53 gpio_set_bits(mantis, config->power, POWER_ON);
54 msleep(100);
55 break;
52 56
53static int mantis_fe_reset(struct dvb_frontend *fe) 57 case POWER_OFF:
54{ 58 dprintk(MANTIS_DEBUG, 1, "Power OFF");
55 struct mantis_pci *mantis = fe->dvb->priv; 59 gpio_set_bits(mantis, config->power, POWER_OFF);
60 msleep(100);
61 break;
56 62
57 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset"); 63 default:
58 gpio_set_bits(mantis, 13, 0); 64 dprintk(MANTIS_DEBUG, 1, "Unknown state <%02x>", power);
59 msleep_interruptible(100); 65 return -1;
60 gpio_set_bits(mantis, 13, 0); 66 }
61 msleep_interruptible(100);
62 gpio_set_bits(mantis, 13, 1);
63 msleep_interruptible(100);
64 gpio_set_bits(mantis, 13, 1);
65 67
66 return 0; 68 return 0;
67} 69}
70EXPORT_SYMBOL_GPL(mantis_frontend_power);
68 71
69static int mantis_frontend_reset(struct mantis_pci *mantis) 72void mantis_frontend_soft_reset(struct mantis_pci *mantis)
70{ 73{
71 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset"); 74 struct mantis_hwconfig *config = mantis->hwconfig;
72 gpio_set_bits(mantis, 13, 0); 75
73 msleep_interruptible(100); 76 dprintk(MANTIS_DEBUG, 1, "Frontend RESET");
74 gpio_set_bits(mantis, 13, 0); 77 gpio_set_bits(mantis, config->reset, 0);
75 msleep_interruptible(100); 78 msleep(100);
76 gpio_set_bits(mantis, 13, 1); 79 gpio_set_bits(mantis, config->reset, 0);
77 msleep_interruptible(100); 80 msleep(100);
78 gpio_set_bits(mantis, 13, 1); 81 gpio_set_bits(mantis, config->reset, 1);
82 msleep(100);
83 gpio_set_bits(mantis, config->reset, 1);
84 msleep(100);
85
86 return;
87}
88EXPORT_SYMBOL_GPL(mantis_frontend_soft_reset);
89
90static int mantis_frontend_shutdown(struct mantis_pci *mantis)
91{
92 int err;
93
94 mantis_frontend_soft_reset(mantis);
95 err = mantis_frontend_power(mantis, POWER_OFF);
96 if (err != 0) {
97 dprintk(MANTIS_ERROR, 1, "Frontend POWER OFF failed! <%d>", err);
98 return 1;
99 }
79 100
80 return 0; 101 return 0;
81} 102}
@@ -85,18 +106,17 @@ static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
85 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 106 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
86 struct mantis_pci *mantis = dvbdmx->priv; 107 struct mantis_pci *mantis = dvbdmx->priv;
87 108
88 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Start feed"); 109 dprintk(MANTIS_DEBUG, 1, "Mantis DVB Start feed");
89 if (!dvbdmx->dmx.frontend) { 110 if (!dvbdmx->dmx.frontend) {
90 dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?"); 111 dprintk(MANTIS_DEBUG, 1, "no frontend ?");
91 return -EINVAL; 112 return -EINVAL;
92 } 113 }
114
93 mantis->feeds++; 115 mantis->feeds++;
94 dprintk(verbose, MANTIS_DEBUG, 1, 116 dprintk(MANTIS_DEBUG, 1, "mantis start feed, feeds=%d", mantis->feeds);
95 "mantis start feed, feeds=%d",
96 mantis->feeds);
97 117
98 if (mantis->feeds == 1) { 118 if (mantis->feeds == 1) {
99 dprintk(verbose, MANTIS_DEBUG, 1, "mantis start feed & dma"); 119 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma");
100 printk("mantis start feed & dma\n"); 120 printk("mantis start feed & dma\n");
101 mantis_dma_start(mantis); 121 mantis_dma_start(mantis);
102 } 122 }
@@ -109,95 +129,129 @@ static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
109 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 129 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
110 struct mantis_pci *mantis = dvbdmx->priv; 130 struct mantis_pci *mantis = dvbdmx->priv;
111 131
112 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Stop feed"); 132 dprintk(MANTIS_DEBUG, 1, "Mantis DVB Stop feed");
113 if (!dvbdmx->dmx.frontend) { 133 if (!dvbdmx->dmx.frontend) {
114 dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?"); 134 dprintk(MANTIS_DEBUG, 1, "no frontend ?");
115 return -EINVAL; 135 return -EINVAL;
116 } 136 }
137
117 mantis->feeds--; 138 mantis->feeds--;
118 if (mantis->feeds == 0) { 139 if (mantis->feeds == 0) {
119 dprintk(verbose, MANTIS_DEBUG, 1, "mantis stop feed and dma"); 140 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma");
120 printk("mantis stop feed and dma\n"); 141 printk("mantis stop feed and dma\n");
121 mantis_dma_stop(mantis); 142 mantis_dma_stop(mantis);
122 } 143 }
144
123 return 0; 145 return 0;
124} 146}
125 147
126int __devinit mantis_dvb_init(struct mantis_pci *mantis) 148int __devinit mantis_dvb_init(struct mantis_pci *mantis)
127{ 149{
128 int result; 150 struct mantis_hwconfig *config = mantis->hwconfig;
151 int result = -1;
152
153 dprintk(MANTIS_DEBUG, 1, "dvb_register_adapter");
154
155 result = dvb_register_adapter(&mantis->dvb_adapter,
156 "Mantis DVB adapter",
157 THIS_MODULE,
158 &mantis->pdev->dev,
159 adapter_nr);
129 160
130 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_register_adapter"); 161 if (result < 0) {
131 if (dvb_register_adapter(&mantis->dvb_adapter,
132 "Mantis dvb adapter", THIS_MODULE,
133 &mantis->pdev->dev,
134 adapter_nr) < 0) {
135 162
136 dprintk(verbose, MANTIS_ERROR, 1, "Error registering adapter"); 163 dprintk(MANTIS_ERROR, 1, "Error registering adapter");
137 return -ENODEV; 164 return -ENODEV;
138 } 165 }
139 mantis->dvb_adapter.priv = mantis; 166
140 mantis->demux.dmx.capabilities = DMX_TS_FILTERING | 167 mantis->dvb_adapter.priv = mantis;
168 mantis->demux.dmx.capabilities = DMX_TS_FILTERING |
141 DMX_SECTION_FILTERING | 169 DMX_SECTION_FILTERING |
142 DMX_MEMORY_BASED_FILTERING; 170 DMX_MEMORY_BASED_FILTERING;
143 171
144 mantis->demux.priv = mantis; 172 mantis->demux.priv = mantis;
145 mantis->demux.filternum = 256; 173 mantis->demux.filternum = 256;
146 mantis->demux.feednum = 256; 174 mantis->demux.feednum = 256;
147 mantis->demux.start_feed = mantis_dvb_start_feed; 175 mantis->demux.start_feed = mantis_dvb_start_feed;
148 mantis->demux.stop_feed = mantis_dvb_stop_feed; 176 mantis->demux.stop_feed = mantis_dvb_stop_feed;
149 mantis->demux.write_to_decoder = NULL; 177 mantis->demux.write_to_decoder = NULL;
150 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmx_init"); 178
151 if ((result = dvb_dmx_init(&mantis->demux)) < 0) { 179 dprintk(MANTIS_DEBUG, 1, "dvb_dmx_init");
152 dprintk(verbose, MANTIS_ERROR, 1, 180 result = dvb_dmx_init(&mantis->demux);
153 "dvb_dmx_init failed, ERROR=%d", result); 181 if (result < 0) {
182 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
154 183
155 goto err0; 184 goto err0;
156 } 185 }
157 mantis->dmxdev.filternum = 256; 186
158 mantis->dmxdev.demux = &mantis->demux.dmx; 187 mantis->dmxdev.filternum = 256;
159 mantis->dmxdev.capabilities = 0; 188 mantis->dmxdev.demux = &mantis->demux.dmx;
160 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmxdev_init"); 189 mantis->dmxdev.capabilities = 0;
161 if ((result = dvb_dmxdev_init(&mantis->dmxdev, 190 dprintk(MANTIS_DEBUG, 1, "dvb_dmxdev_init");
162 &mantis->dvb_adapter)) < 0) { 191
163 192 result = dvb_dmxdev_init(&mantis->dmxdev, &mantis->dvb_adapter);
164 dprintk(verbose, MANTIS_ERROR, 1, 193 if (result < 0) {
165 "dvb_dmxdev_init failed, ERROR=%d", result); 194
195 dprintk(MANTIS_ERROR, 1, "dvb_dmxdev_init failed, ERROR=%d", result);
166 goto err1; 196 goto err1;
167 } 197 }
168 mantis->fe_hw.source = DMX_FRONTEND_0;
169 if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
170 &mantis->fe_hw)) < 0) {
171 198
172 dprintk(verbose, MANTIS_ERROR, 1, 199 mantis->fe_hw.source = DMX_FRONTEND_0;
173 "dvb_dmx_init failed, ERROR=%d", result); 200 result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx, &mantis->fe_hw);
201 if (result < 0) {
174 202
203 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
175 goto err2; 204 goto err2;
176 } 205 }
177 mantis->fe_mem.source = DMX_MEMORY_FE;
178 if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
179 &mantis->fe_mem)) < 0) {
180 dprintk(verbose, MANTIS_ERROR, 1,
181 "dvb_dmx_init failed, ERROR=%d", result);
182 206
207 mantis->fe_mem.source = DMX_MEMORY_FE;
208 result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,&mantis->fe_mem);
209 if (result < 0) {
210 dprintk(MANTIS_ERROR, 1,"dvb_dmx_init failed, ERROR=%d", result);
183 goto err3; 211 goto err3;
184 } 212 }
185 if ((result = mantis->demux.dmx.connect_frontend(&mantis->demux.dmx,
186 &mantis->fe_hw)) < 0) {
187
188 dprintk(verbose, MANTIS_ERROR, 1,
189 "dvb_dmx_init failed, ERROR=%d", result);
190 213
214 result = mantis->demux.dmx.connect_frontend(&mantis->demux.dmx, &mantis->fe_hw);
215 if (result < 0) {
216 dprintk(MANTIS_ERROR, 1, "dvb_dmx_init failed, ERROR=%d", result);
191 goto err4; 217 goto err4;
192 } 218 }
219
193 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx); 220 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
194 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis); 221 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
195 mantis_frontend_init(mantis); 222 if (mantis->hwconfig) {
196 mantis_ca_init(mantis); 223 result = config->frontend_init(mantis, mantis->fe);
224 if (result < 0) {
225 dprintk(MANTIS_ERROR, 1, "!!! NO Frontends found !!!");
226 goto err5;
227 } else {
228// if (mantis->dvb_adapter == NULL) {
229// dprintk(MANTIS_ERROR, 1, "DVB adapter <NULL>");
230// goto err5;
231// }
232 if (mantis->fe == NULL) {
233 dprintk(MANTIS_ERROR, 1, "FE <NULL>");
234 goto err5;
235 }
236
237 if (dvb_register_frontend(&mantis->dvb_adapter, mantis->fe)) {
238 dprintk(MANTIS_ERROR, 1, "ERROR: Frontend registration failed");
239
240 if (mantis->fe->ops.release)
241 mantis->fe->ops.release(mantis->fe);
242
243 mantis->fe = NULL;
244 goto err5;
245 }
246 }
247 }
197 248
198 return 0; 249 return 0;
199 250
200 /* Error conditions .. */ 251 /* Error conditions .. */
252err5:
253 tasklet_kill(&mantis->tasklet);
254 dvb_net_release(&mantis->dvbnet);
201err4: 255err4:
202 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem); 256 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
203err3: 257err3:
@@ -211,115 +265,17 @@ err0:
211 265
212 return result; 266 return result;
213} 267}
268EXPORT_SYMBOL_GPL(mantis_dvb_init);
214 269
215int __devinit mantis_frontend_init(struct mantis_pci *mantis) 270int __devexit mantis_dvb_exit(struct mantis_pci *mantis)
216{ 271{
217 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis frontend Init"); 272 int err;
218 mantis_fe_powerup(mantis);
219 mantis_frontend_reset(mantis);
220 dprintk(verbose, MANTIS_DEBUG, 1, "Device ID=%02x", mantis->subsystem_device);
221 switch (mantis->subsystem_device) {
222 case MANTIS_VP_1033_DVB_S: // VP-1033
223 dprintk(verbose, MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
224 mantis->fe = stv0299_attach(&lgtdqcs001f_config,
225 &mantis->adapter);
226
227 if (mantis->fe) {
228 mantis->fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
229 dprintk(verbose, MANTIS_ERROR, 1,
230 "found STV0299 DVB-S frontend @ 0x%02x",
231 lgtdqcs001f_config.demod_address);
232
233 dprintk(verbose, MANTIS_ERROR, 1,
234 "Mantis DVB-S STV0299 frontend attach success");
235 }
236 break;
237 case MANTIS_VP_1034_DVB_S: // VP-1034
238 dprintk(verbose, MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
239 mantis->fe = mb86a16_attach(&vp1034_config, &mantis->adapter);
240 if (mantis->fe) {
241 dprintk(verbose, MANTIS_ERROR, 1,
242 "found MB86A16 DVB-S/DSS frontend @0x%02x",
243 vp1034_config.demod_address);
244 273
245 } 274 err = mantis_frontend_shutdown(mantis);
246 break; 275 if (err != 0)
247 case MANTIS_VP_1041_DVB_S2: 276 dprintk(MANTIS_ERROR, 1, "Frontend exit while POWER ON! <%d>", err);
248 case TECHNISAT_SKYSTAR_HD2:
249 mantis->fe = stb0899_attach(&vp1041_config, &mantis->adapter);
250 if (mantis->fe) {
251 dprintk(verbose, MANTIS_ERROR, 1,
252 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x",
253 vp1041_config.demod_address);
254
255 if (stb6100_attach(mantis->fe, &vp1041_stb6100_config, &mantis->adapter)) {
256 if (!lnbp21_attach(mantis->fe, &mantis->adapter, 0, 0)) {
257 printk("%s: No LNBP21 found!\n", __FUNCTION__);
258 mantis->fe = NULL;
259 }
260 } else {
261 mantis->fe = NULL;
262 }
263 }
264 break;
265 case MANTIS_VP_2033_DVB_C: // VP-2033
266 case MANTIS_VP_2040_DVB_C: // VP-2040
267 case TERRATEC_CINERGY_C_PCI:
268 case TECHNISAT_CABLESTAR_HD2:
269 dprintk(verbose, MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
270 mantis->fe = tda10021_attach(&philips_cu1216_config,
271 &mantis->adapter,
272 read_pwm(mantis));
273
274 if (mantis->fe) {
275 dprintk(verbose, MANTIS_ERROR, 1,
276 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
277 philips_cu1216_config.demod_address);
278 } else {
279 mantis->fe = tda10023_attach(&tda10023_cu1216_config,
280 &mantis->adapter,
281 read_pwm(mantis));
282
283 if (mantis->fe) {
284 dprintk(verbose, MANTIS_ERROR, 1,
285 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
286 philips_cu1216_config.demod_address);
287 }
288 }
289 if (mantis->fe) {
290 mantis->fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set;
291 dprintk(verbose, MANTIS_ERROR, 1,
292 "Mantis DVB-C Philips CU1216 frontend attach success");
293 }
294 break;
295 default:
296 dprintk(verbose, MANTIS_DEBUG, 1, "Unknown frontend:[0x%02x]",
297 mantis->sub_device_id);
298 277
299 return -ENODEV; 278// mantis_ca_exit(mantis);
300 }
301 if (mantis->fe == NULL) {
302 dprintk(verbose, MANTIS_ERROR, 1, "!!! NO Frontends found !!!");
303 return -ENODEV;
304 } else {
305 if (dvb_register_frontend(&mantis->dvb_adapter, mantis->fe)) {
306 dprintk(verbose, MANTIS_ERROR, 1,
307 "ERROR: Frontend registration failed");
308
309 if (mantis->fe->ops.release)
310 mantis->fe->ops.release(mantis->fe);
311
312 mantis->fe = NULL;
313 return -ENODEV;
314 }
315 }
316
317 return 0;
318}
319
320int __devexit mantis_dvb_exit(struct mantis_pci *mantis)
321{
322 mantis_ca_exit(mantis);
323 tasklet_kill(&mantis->tasklet); 279 tasklet_kill(&mantis->tasklet);
324 dvb_net_release(&mantis->dvbnet); 280 dvb_net_release(&mantis->dvbnet);
325 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem); 281 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
@@ -329,8 +285,10 @@ int __devexit mantis_dvb_exit(struct mantis_pci *mantis)
329 285
330 if (mantis->fe) 286 if (mantis->fe)
331 dvb_unregister_frontend(mantis->fe); 287 dvb_unregister_frontend(mantis->fe);
332 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_unregister_adapter"); 288
289 dprintk(MANTIS_DEBUG, 1, "dvb_unregister_adapter");
333 dvb_unregister_adapter(&mantis->dvb_adapter); 290 dvb_unregister_adapter(&mantis->dvb_adapter);
334 291
335 return 0; 292 return 0;
336} 293}
294EXPORT_SYMBOL_GPL(mantis_dvb_exit);
diff --git a/drivers/media/dvb/mantis/mantis_dvb.h b/drivers/media/dvb/mantis/mantis_dvb.h
new file mode 100644
index 000000000000..31ebbb47df3e
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_dvb.h
@@ -0,0 +1,15 @@
1#ifndef __MANTIS_DVB_H
2#define __MANTIS_DVB_H
3
4enum mantis_power {
5 POWER_OFF = 0,
6 POWER_ON = 1
7};
8
9extern int mantis_frontend_power(struct mantis_pci *mantis, enum mantis_power power);
10extern void mantis_frontend_soft_reset(struct mantis_pci *mantis);
11
12extern int mantis_dvb_init(struct mantis_pci *mantis);
13extern int mantis_dvb_exit(struct mantis_pci *mantis);
14
15#endif /* __MANTIS_DVB_H */
diff --git a/drivers/media/dvb/mantis/mantis_evm.c b/drivers/media/dvb/mantis/mantis_evm.c
index 9be55f7942d4..2005b2489b74 100644
--- a/drivers/media/dvb/mantis/mantis_evm.c
+++ b/drivers/media/dvb/mantis/mantis_evm.c
@@ -18,9 +18,23 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/kernel.h>
22
23#include <asm/irq.h>
24#include <linux/signal.h>
25#include <linux/sched.h>
26#include <linux/interrupt.h>
27
28#include "dmxdev.h"
29#include "dvbdev.h"
30#include "dvb_demux.h"
31#include "dvb_frontend.h"
32#include "dvb_net.h"
33
21#include "mantis_common.h" 34#include "mantis_common.h"
22#include "mantis_link.h" 35#include "mantis_link.h"
23#include "mantis_hif.h" 36#include "mantis_hif.h"
37#include "mantis_reg.h"
24 38
25static void mantis_hifevm_work(struct work_struct *work) 39static void mantis_hifevm_work(struct work_struct *work)
26{ 40{
@@ -34,7 +48,7 @@ static void mantis_hifevm_work(struct work_struct *work)
34 48
35 if (gpif_stat & MANTIS_GPIF_DETSTAT) { 49 if (gpif_stat & MANTIS_GPIF_DETSTAT) {
36 if (gpif_stat & MANTIS_CARD_PLUGIN) { 50 if (gpif_stat & MANTIS_CARD_PLUGIN) {
37 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Plugin", mantis->num); 51 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Plugin", mantis->num);
38 mmwrite(0xdada0000, MANTIS_CARD_RESET); 52 mmwrite(0xdada0000, MANTIS_CARD_RESET);
39 mantis_event_cam_plugin(ca); 53 mantis_event_cam_plugin(ca);
40 dvb_ca_en50221_camchange_irq(&ca->en50221, 54 dvb_ca_en50221_camchange_irq(&ca->en50221,
@@ -43,7 +57,7 @@ static void mantis_hifevm_work(struct work_struct *work)
43 } 57 }
44 } else { 58 } else {
45 if (gpif_stat & MANTIS_CARD_PLUGOUT) { 59 if (gpif_stat & MANTIS_CARD_PLUGOUT) {
46 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Unplug", mantis->num); 60 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Unplug", mantis->num);
47 mmwrite(0xdada0000, MANTIS_CARD_RESET); 61 mmwrite(0xdada0000, MANTIS_CARD_RESET);
48 mantis_event_cam_unplug(ca); 62 mantis_event_cam_unplug(ca);
49 dvb_ca_en50221_camchange_irq(&ca->en50221, 63 dvb_ca_en50221_camchange_irq(&ca->en50221,
@@ -53,28 +67,28 @@ static void mantis_hifevm_work(struct work_struct *work)
53 } 67 }
54 68
55 if (mantis->gpif_status & MANTIS_GPIF_EXTIRQ) 69 if (mantis->gpif_status & MANTIS_GPIF_EXTIRQ)
56 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Ext IRQ", mantis->num); 70 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Ext IRQ", mantis->num);
57 71
58 if (mantis->gpif_status & MANTIS_SBUF_WSTO) 72 if (mantis->gpif_status & MANTIS_SBUF_WSTO)
59 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout", mantis->num); 73 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout", mantis->num);
60 74
61 if (mantis->gpif_status & MANTIS_GPIF_OTHERR) 75 if (mantis->gpif_status & MANTIS_GPIF_OTHERR)
62 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Alignment Error", mantis->num); 76 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Alignment Error", mantis->num);
63 77
64 if (gpif_stat & MANTIS_SBUF_OVFLW) 78 if (gpif_stat & MANTIS_SBUF_OVFLW)
65 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Overflow", mantis->num); 79 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Overflow", mantis->num);
66 80
67 if (gpif_stat & MANTIS_GPIF_BRRDY) 81 if (gpif_stat & MANTIS_GPIF_BRRDY)
68 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Read Ready", mantis->num); 82 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Read Ready", mantis->num);
69 83
70 if (gpif_stat & MANTIS_GPIF_INTSTAT) 84 if (gpif_stat & MANTIS_GPIF_INTSTAT)
71 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): GPIF IRQ", mantis->num); 85 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): GPIF IRQ", mantis->num);
72 86
73 if (gpif_stat & MANTIS_SBUF_EMPTY) 87 if (gpif_stat & MANTIS_SBUF_EMPTY)
74 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty", mantis->num); 88 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty", mantis->num);
75 89
76 if (gpif_stat & MANTIS_SBUF_OPDONE) { 90 if (gpif_stat & MANTIS_SBUF_OPDONE) {
77 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete", mantis->num); 91 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete", mantis->num);
78 ca->sbuf_status = MANTIS_SBUF_DATA_AVAIL; 92 ca->sbuf_status = MANTIS_SBUF_DATA_AVAIL;
79 ca->hif_event = MANTIS_SBUF_OPDONE; 93 ca->hif_event = MANTIS_SBUF_OPDONE;
80 wake_up(&ca->hif_opdone_wq); 94 wake_up(&ca->hif_opdone_wq);
@@ -85,7 +99,7 @@ int mantis_evmgr_init(struct mantis_ca *ca)
85{ 99{
86 struct mantis_pci *mantis = ca->ca_priv; 100 struct mantis_pci *mantis = ca->ca_priv;
87 101
88 dprintk(verbose, MANTIS_DEBUG, 1, "Initializing Mantis Host I/F Event manager"); 102 dprintk(MANTIS_DEBUG, 1, "Initializing Mantis Host I/F Event manager");
89 INIT_WORK(&ca->hif_evm_work, mantis_hifevm_work); 103 INIT_WORK(&ca->hif_evm_work, mantis_hifevm_work);
90 mantis_pcmcia_init(ca); 104 mantis_pcmcia_init(ca);
91 schedule_work(&ca->hif_evm_work); 105 schedule_work(&ca->hif_evm_work);
@@ -97,7 +111,7 @@ void mantis_evmgr_exit(struct mantis_ca *ca)
97{ 111{
98 struct mantis_pci *mantis = ca->ca_priv; 112 struct mantis_pci *mantis = ca->ca_priv;
99 113
100 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting"); 114 dprintk(MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting");
101 flush_scheduled_work(); 115 flush_scheduled_work();
102 mantis_hif_exit(ca); 116 mantis_hif_exit(ca);
103 mantis_pcmcia_exit(ca); 117 mantis_pcmcia_exit(ca);
diff --git a/drivers/media/dvb/mantis/mantis_hif.c b/drivers/media/dvb/mantis/mantis_hif.c
index 99a9724cbaff..bb05427fdeb6 100644
--- a/drivers/media/dvb/mantis/mantis_hif.c
+++ b/drivers/media/dvb/mantis/mantis_hif.c
@@ -18,10 +18,28 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/kernel.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24
25#include <asm/irq.h>
26#include <linux/signal.h>
27#include <linux/sched.h>
28#include <linux/interrupt.h>
29
30#include "dmxdev.h"
31#include "dvbdev.h"
32#include "dvb_demux.h"
33#include "dvb_frontend.h"
34#include "dvb_net.h"
35
21#include "mantis_common.h" 36#include "mantis_common.h"
37
22#include "mantis_hif.h" 38#include "mantis_hif.h"
23#include "mantis_link.h" /* temporary due to physical layer stuff */ 39#include "mantis_link.h" /* temporary due to physical layer stuff */
24 40
41#include "mantis_reg.h"
42
25static int mantis_hif_data_available(struct mantis_ca *ca) 43static int mantis_hif_data_available(struct mantis_ca *ca)
26{ 44{
27 struct mantis_pci *mantis = ca->ca_priv; 45 struct mantis_pci *mantis = ca->ca_priv;
@@ -31,7 +49,7 @@ static int mantis_hif_data_available(struct mantis_ca *ca)
31 ca->sbuf_status & MANTIS_SBUF_DATA_AVAIL, 49 ca->sbuf_status & MANTIS_SBUF_DATA_AVAIL,
32 msecs_to_jiffies(500)) == -ERESTARTSYS) { 50 msecs_to_jiffies(500)) == -ERESTARTSYS) {
33 51
34 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Read wait event timeout !", mantis->num); 52 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Read wait event timeout !", mantis->num);
35 rc = -EREMOTEIO; 53 rc = -EREMOTEIO;
36 } 54 }
37 ca->sbuf_status &= ~MANTIS_SBUF_DATA_AVAIL; 55 ca->sbuf_status &= ~MANTIS_SBUF_DATA_AVAIL;
@@ -48,10 +66,10 @@ static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
48 ca->hif_event & MANTIS_SBUF_OPDONE, 66 ca->hif_event & MANTIS_SBUF_OPDONE,
49 msecs_to_jiffies(500)) == -ERESTARTSYS) { 67 msecs_to_jiffies(500)) == -ERESTARTSYS) {
50 68
51 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num); 69 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
52 rc = -EREMOTEIO; 70 rc = -EREMOTEIO;
53 } 71 }
54 dprintk(verbose, MANTIS_DEBUG, 1, "Smart Buffer Operation complete"); 72 dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
55 ca->hif_event &= ~MANTIS_SBUF_OPDONE; 73 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
56 return rc; 74 return rc;
57} 75}
@@ -66,22 +84,22 @@ static int mantis_hif_write_wait(struct mantis_ca *ca)
66 mantis->gpif_status & MANTIS_GPIF_WRACK, 84 mantis->gpif_status & MANTIS_GPIF_WRACK,
67 msecs_to_jiffies(500)) == -ERESTARTSYS) { 85 msecs_to_jiffies(500)) == -ERESTARTSYS) {
68 86
69 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num); 87 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);
70 rc = -EREMOTEIO; 88 rc = -EREMOTEIO;
71 } 89 }
72 dprintk(verbose, MANTIS_DEBUG, 1, "Write Acknowledged"); 90 dprintk(MANTIS_DEBUG, 1, "Write Acknowledged");
73 mantis->gpif_status &= ~MANTIS_GPIF_WRACK; 91 mantis->gpif_status &= ~MANTIS_GPIF_WRACK;
74 while (!opdone) { 92 while (!opdone) {
75 opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE); 93 opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE);
76 udelay(500); 94 udelay(500);
77 timeout++; 95 timeout++;
78 if (timeout > 100) { 96 if (timeout > 100) {
79 dprintk(verbose, MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num); 97 dprintk(MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num);
80 rc = -ETIMEDOUT; 98 rc = -ETIMEDOUT;
81 break; 99 break;
82 } 100 }
83 } 101 }
84 dprintk(verbose, MANTIS_DEBUG, 1, "HIF Write success"); 102 dprintk(MANTIS_DEBUG, 1, "HIF Write success");
85 return rc; 103 return rc;
86} 104}
87 105
@@ -91,7 +109,7 @@ int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
91 struct mantis_pci *mantis = ca->ca_priv; 109 struct mantis_pci *mantis = ca->ca_priv;
92 u32 hif_addr = 0, data, count = 4; 110 u32 hif_addr = 0, data, count = 4;
93 111
94 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num); 112 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
95 mutex_lock(&ca->ca_lock); 113 mutex_lock(&ca->ca_lock);
96 hif_addr &= ~MANTIS_GPIF_PCMCIAREG; 114 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
97 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM; 115 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
@@ -104,13 +122,13 @@ int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
104 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR); 122 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
105 123
106 if (mantis_hif_sbuf_opdone_wait(ca) != 0) { 124 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
107 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num); 125 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
108 mutex_unlock(&ca->ca_lock); 126 mutex_unlock(&ca->ca_lock);
109 return -EREMOTEIO; 127 return -EREMOTEIO;
110 } 128 }
111 data = mmread(MANTIS_GPIF_DIN); 129 data = mmread(MANTIS_GPIF_DIN);
112 mutex_unlock(&ca->ca_lock); 130 mutex_unlock(&ca->ca_lock);
113 dprintk(verbose, MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data); 131 dprintk(MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);
114 return (data >> 24) & 0xff; 132 return (data >> 24) & 0xff;
115} 133}
116 134
@@ -120,7 +138,7 @@ int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
120 struct mantis_pci *mantis = ca->ca_priv; 138 struct mantis_pci *mantis = ca->ca_priv;
121 u32 hif_addr = 0; 139 u32 hif_addr = 0;
122 140
123 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num); 141 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
124 mutex_lock(&ca->ca_lock); 142 mutex_lock(&ca->ca_lock);
125 hif_addr &= ~MANTIS_GPIF_HIFRDWRN; 143 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
126 hif_addr &= ~MANTIS_GPIF_PCMCIAREG; 144 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
@@ -133,11 +151,11 @@ int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
133 mmwrite(data, MANTIS_GPIF_DOUT); 151 mmwrite(data, MANTIS_GPIF_DOUT);
134 152
135 if (mantis_hif_write_wait(ca) != 0) { 153 if (mantis_hif_write_wait(ca) != 0) {
136 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); 154 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
137 mutex_unlock(&ca->ca_lock); 155 mutex_unlock(&ca->ca_lock);
138 return -EREMOTEIO; 156 return -EREMOTEIO;
139 } 157 }
140 dprintk(verbose, MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr); 158 dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
141 mutex_unlock(&ca->ca_lock); 159 mutex_unlock(&ca->ca_lock);
142 160
143 return 0; 161 return 0;
@@ -148,7 +166,7 @@ int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
148 struct mantis_pci *mantis = ca->ca_priv; 166 struct mantis_pci *mantis = ca->ca_priv;
149 u32 data, hif_addr = 0; 167 u32 data, hif_addr = 0;
150 168
151 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num); 169 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
152 mutex_lock(&ca->ca_lock); 170 mutex_lock(&ca->ca_lock);
153 hif_addr &= ~MANTIS_GPIF_PCMCIAREG; 171 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
154 hif_addr |= MANTIS_GPIF_PCMCIAIOM; 172 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
@@ -161,12 +179,12 @@ int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
161 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR); 179 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
162 180
163 if (mantis_hif_sbuf_opdone_wait(ca) != 0) { 181 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
164 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); 182 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
165 mutex_unlock(&ca->ca_lock); 183 mutex_unlock(&ca->ca_lock);
166 return -EREMOTEIO; 184 return -EREMOTEIO;
167 } 185 }
168 data = mmread(MANTIS_GPIF_DIN); 186 data = mmread(MANTIS_GPIF_DIN);
169 dprintk(verbose, MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data); 187 dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
170 udelay(50); 188 udelay(50);
171 mutex_unlock(&ca->ca_lock); 189 mutex_unlock(&ca->ca_lock);
172 190
@@ -178,7 +196,7 @@ int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
178 struct mantis_pci *mantis = ca->ca_priv; 196 struct mantis_pci *mantis = ca->ca_priv;
179 u32 hif_addr = 0; 197 u32 hif_addr = 0;
180 198
181 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num); 199 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
182 mutex_lock(&ca->ca_lock); 200 mutex_lock(&ca->ca_lock);
183 hif_addr &= ~MANTIS_GPIF_PCMCIAREG; 201 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
184 hif_addr &= ~MANTIS_GPIF_HIFRDWRN; 202 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
@@ -190,11 +208,11 @@ int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
190 mmwrite(data, MANTIS_GPIF_DOUT); 208 mmwrite(data, MANTIS_GPIF_DOUT);
191 209
192 if (mantis_hif_write_wait(ca) != 0) { 210 if (mantis_hif_write_wait(ca) != 0) {
193 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); 211 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
194 mutex_unlock(&ca->ca_lock); 212 mutex_unlock(&ca->ca_lock);
195 return -EREMOTEIO; 213 return -EREMOTEIO;
196 } 214 }
197 dprintk(verbose, MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr); 215 dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
198 mutex_unlock(&ca->ca_lock); 216 mutex_unlock(&ca->ca_lock);
199 udelay(50); 217 udelay(50);
200 218
@@ -208,7 +226,7 @@ int mantis_hif_init(struct mantis_ca *ca)
208 u32 irqcfg; 226 u32 irqcfg;
209 227
210 slot[0].slave_cfg = 0x70773028; 228 slot[0].slave_cfg = 0x70773028;
211 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num); 229 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
212 230
213 mutex_lock(&ca->ca_lock); 231 mutex_lock(&ca->ca_lock);
214 irqcfg = mmread(MANTIS_GPIF_IRQCFG); 232 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
@@ -230,7 +248,7 @@ void mantis_hif_exit(struct mantis_ca *ca)
230 struct mantis_pci *mantis = ca->ca_priv; 248 struct mantis_pci *mantis = ca->ca_priv;
231 u32 irqcfg; 249 u32 irqcfg;
232 250
233 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num); 251 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
234 mutex_lock(&ca->ca_lock); 252 mutex_lock(&ca->ca_lock);
235 irqcfg = mmread(MANTIS_GPIF_IRQCFG); 253 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
236 irqcfg &= ~MANTIS_MASK_BRRDY; 254 irqcfg &= ~MANTIS_MASK_BRRDY;
diff --git a/drivers/media/dvb/mantis/mantis_hif.h b/drivers/media/dvb/mantis/mantis_hif.h
index 7ef45cec19d6..f960c0aeacc4 100644
--- a/drivers/media/dvb/mantis/mantis_hif.h
+++ b/drivers/media/dvb/mantis/mantis_hif.h
@@ -26,4 +26,4 @@
26#define MANTIS_HIF_IOMRD 3 26#define MANTIS_HIF_IOMRD 3
27#define MANTIS_HIF_IOMWR 4 27#define MANTIS_HIF_IOMWR 4
28 28
29#endif // __MANTIS_HIF_H 29#endif /* __MANTIS_HIF_H */
diff --git a/drivers/media/dvb/mantis/mantis_i2c.c b/drivers/media/dvb/mantis/mantis_i2c.c
index 45d9e6bd9628..ba55f0a9a10f 100644
--- a/drivers/media/dvb/mantis/mantis_i2c.c
+++ b/drivers/media/dvb/mantis/mantis_i2c.c
@@ -18,15 +18,20 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <asm/io.h> 21#include <asm/io.h>
26#include <linux/ioport.h> 22#include <linux/ioport.h>
27#include <asm/pgtable.h> 23#include <linux/pci.h>
28#include <asm/page.h> 24#include <linux/i2c.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
29#include "mantis_common.h" 32#include "mantis_common.h"
33#include "mantis_reg.h"
34#include "mantis_i2c.h"
30 35
31#define I2C_HW_B_MANTIS 0x1c 36#define I2C_HW_B_MANTIS 0x1c
32 37
@@ -35,20 +40,21 @@ static int mantis_ack_wait(struct mantis_pci *mantis)
35 int rc = 0; 40 int rc = 0;
36 u32 timeout = 0; 41 u32 timeout = 0;
37 42
38 if (wait_event_interruptible_timeout(mantis->i2c_wq, 43 if (wait_event_timeout(mantis->i2c_wq,
39 mantis->mantis_int_stat & MANTIS_INT_I2CDONE, 44 mantis->mantis_int_stat & MANTIS_INT_I2CDONE,
40 msecs_to_jiffies(50)) == -ERESTARTSYS) { 45 msecs_to_jiffies(50)) == -ERESTARTSYS) {
41 46
42 dprintk(verbose, MANTIS_DEBUG, 1, "Master !I2CDONE"); 47 dprintk(MANTIS_DEBUG, 1, "Master !I2CDONE");
43 rc = -EREMOTEIO; 48 rc = -EREMOTEIO;
44 } 49 }
50
45 while (!(mantis->mantis_int_stat & MANTIS_INT_I2CRACK)) { 51 while (!(mantis->mantis_int_stat & MANTIS_INT_I2CRACK)) {
46 dprintk(verbose, MANTIS_DEBUG, 1, "Waiting for Slave RACK"); 52 dprintk(MANTIS_DEBUG, 1, "Waiting for Slave RACK");
47 mantis->mantis_int_stat = mmread(MANTIS_INT_STAT); 53 mantis->mantis_int_stat = mmread(MANTIS_INT_STAT);
48 msleep(5); 54 msleep(5);
49 timeout++; 55 timeout++;
50 if (timeout > 500) { 56 if (timeout > 500) {
51 dprintk(verbose, MANTIS_ERROR, 1, "Slave RACK Fail !"); 57 dprintk(MANTIS_ERROR, 1, "Slave RACK Fail !");
52 rc = -EREMOTEIO; 58 rc = -EREMOTEIO;
53 break; 59 break;
54 } 60 }
@@ -62,7 +68,7 @@ static int mantis_i2c_read(struct mantis_pci *mantis, const struct i2c_msg *msg)
62{ 68{
63 u32 rxd, i; 69 u32 rxd, i;
64 70
65 dprintk(verbose, MANTIS_INFO, 0, " %s: Address=[0x%02x] <R>[ ", 71 dprintk(MANTIS_INFO, 0, " %s: Address=[0x%02x] <R>[ ",
66 __func__, msg->addr); 72 __func__, msg->addr);
67 73
68 for (i = 0; i < msg->len; i++) { 74 for (i = 0; i < msg->len; i++) {
@@ -77,14 +83,14 @@ static int mantis_i2c_read(struct mantis_pci *mantis, const struct i2c_msg *msg)
77 mmwrite(MANTIS_INT_I2CDONE, MANTIS_INT_STAT); 83 mmwrite(MANTIS_INT_I2CDONE, MANTIS_INT_STAT);
78 mmwrite(rxd, MANTIS_I2CDATA_CTL); 84 mmwrite(rxd, MANTIS_I2CDATA_CTL);
79 if (mantis_ack_wait(mantis) != 0) { 85 if (mantis_ack_wait(mantis) != 0) {
80 dprintk(verbose, MANTIS_DEBUG, 1, "ACK failed<R>"); 86 dprintk(MANTIS_DEBUG, 1, "ACK failed<R>");
81 return -EREMOTEIO; 87 return -EREMOTEIO;
82 } 88 }
83 rxd = mmread(MANTIS_I2CDATA_CTL); 89 rxd = mmread(MANTIS_I2CDATA_CTL);
84 msg->buf[i] = (u8)((rxd >> 8) & 0xFF); 90 msg->buf[i] = (u8)((rxd >> 8) & 0xFF);
85 dprintk(verbose, MANTIS_INFO, 0, "%02x ", msg->buf[i]); 91 dprintk(MANTIS_INFO, 0, "%02x ", msg->buf[i]);
86 } 92 }
87 dprintk(verbose, MANTIS_INFO, 0, "]\n"); 93 dprintk(MANTIS_INFO, 0, "]\n");
88 94
89 return 0; 95 return 0;
90} 96}
@@ -94,11 +100,11 @@ static int mantis_i2c_write(struct mantis_pci *mantis, const struct i2c_msg *msg
94 int i; 100 int i;
95 u32 txd = 0; 101 u32 txd = 0;
96 102
97 dprintk(verbose, MANTIS_INFO, 0, " %s: Address=[0x%02x] <W>[ ", 103 dprintk(MANTIS_INFO, 0, " %s: Address=[0x%02x] <W>[ ",
98 __func__, msg->addr); 104 __func__, msg->addr);
99 105
100 for (i = 0; i < msg->len; i++) { 106 for (i = 0; i < msg->len; i++) {
101 dprintk(verbose, MANTIS_INFO, 0, "%02x ", msg->buf[i]); 107 dprintk(MANTIS_INFO, 0, "%02x ", msg->buf[i]);
102 txd = (msg->addr << 25) | (msg->buf[i] << 8) 108 txd = (msg->addr << 25) | (msg->buf[i] << 8)
103 | MANTIS_I2C_RATE_3 109 | MANTIS_I2C_RATE_3
104 | MANTIS_I2C_STOP 110 | MANTIS_I2C_STOP
@@ -110,11 +116,11 @@ static int mantis_i2c_write(struct mantis_pci *mantis, const struct i2c_msg *msg
110 mmwrite(MANTIS_INT_I2CDONE, MANTIS_INT_STAT); 116 mmwrite(MANTIS_INT_I2CDONE, MANTIS_INT_STAT);
111 mmwrite(txd, MANTIS_I2CDATA_CTL); 117 mmwrite(txd, MANTIS_I2CDATA_CTL);
112 if (mantis_ack_wait(mantis) != 0) { 118 if (mantis_ack_wait(mantis) != 0) {
113 dprintk(verbose, MANTIS_DEBUG, 1, "ACK failed<W>"); 119 dprintk(MANTIS_DEBUG, 1, "ACK failed<W>");
114 return -EREMOTEIO; 120 return -EREMOTEIO;
115 } 121 }
116 } 122 }
117 dprintk(verbose, MANTIS_INFO, 0, "]\n"); 123 dprintk(MANTIS_INFO, 0, "]\n");
118 124
119 return 0; 125 return 0;
120} 126}
@@ -154,43 +160,46 @@ static struct i2c_algorithm mantis_algo = {
154 .functionality = mantis_i2c_func, 160 .functionality = mantis_i2c_func,
155}; 161};
156 162
157static struct i2c_adapter mantis_i2c_adapter = {
158 .owner = THIS_MODULE,
159 .name = "Mantis I2C",
160 .id = I2C_HW_B_MANTIS,
161 .class = I2C_CLASS_TV_DIGITAL,
162 .algo = &mantis_algo,
163};
164
165int __devinit mantis_i2c_init(struct mantis_pci *mantis) 163int __devinit mantis_i2c_init(struct mantis_pci *mantis)
166{ 164{
167 u32 intstat, intmask; 165 u32 intstat, intmask;
168 struct i2c_adapter *i2c_adapter = &mantis->adapter; 166 struct i2c_adapter *i2c_adapter = &mantis->adapter;
169 struct pci_dev *pdev = mantis->pdev; 167 struct pci_dev *pdev = mantis->pdev;
170 168
169 init_waitqueue_head(&mantis->i2c_wq);
171 mutex_init(&mantis->i2c_lock); 170 mutex_init(&mantis->i2c_lock);
172 memcpy(i2c_adapter, &mantis_i2c_adapter, sizeof (mantis_i2c_adapter)); 171 strncpy(i2c_adapter->name, "Mantis I2C", sizeof (i2c_adapter->name));
173 i2c_set_adapdata(i2c_adapter, mantis); 172 i2c_set_adapdata(i2c_adapter, mantis);
174 173
175 i2c_adapter->dev.parent = &pdev->dev; 174 i2c_adapter->owner = THIS_MODULE;
175 i2c_adapter->class = I2C_CLASS_TV_DIGITAL;
176 i2c_adapter->algo = &mantis_algo;
177 i2c_adapter->algo_data = NULL;
178 i2c_adapter->id = I2C_HW_B_MANTIS;
179 i2c_adapter->timeout = 500;
180 i2c_adapter->retries = 3;
181 i2c_adapter->dev.parent = &pdev->dev;
182
176 mantis->i2c_rc = i2c_add_adapter(i2c_adapter); 183 mantis->i2c_rc = i2c_add_adapter(i2c_adapter);
177 if (mantis->i2c_rc < 0) 184 if (mantis->i2c_rc < 0)
178 return mantis->i2c_rc; 185 return mantis->i2c_rc;
179 186
180 dprintk(verbose, MANTIS_DEBUG, 1, "Initializing I2C .."); 187 dprintk(MANTIS_DEBUG, 1, "Initializing I2C ..");
181 188
182 intstat = mmread(MANTIS_INT_STAT); 189 intstat = mmread(MANTIS_INT_STAT);
183 intmask = mmread(MANTIS_INT_MASK); 190 intmask = mmread(MANTIS_INT_MASK);
184 mmwrite(intstat, MANTIS_INT_STAT); 191 mmwrite(intstat, MANTIS_INT_STAT);
185 mmwrite(intmask | MANTIS_INT_I2CDONE, MANTIS_INT_MASK); 192 mmwrite(intmask | MANTIS_INT_I2CDONE, MANTIS_INT_MASK);
186 193
187 dprintk(verbose, MANTIS_DEBUG, 1, "[0x%08x/%08x]", intstat, intmask); 194 dprintk(MANTIS_DEBUG, 1, "Status=<%02x> Mask=<%02x>", intstat, intmask);
188 195
189 return 0; 196 return 0;
190} 197}
198EXPORT_SYMBOL_GPL(mantis_i2c_init);
191 199
192int __devexit mantis_i2c_exit(struct mantis_pci *mantis) 200int __devexit mantis_i2c_exit(struct mantis_pci *mantis)
193{ 201{
194 dprintk(verbose, MANTIS_DEBUG, 1, "Removing I2C adapter"); 202 dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter");
195 return i2c_del_adapter(&mantis->adapter); 203 return i2c_del_adapter(&mantis->adapter);
196} 204}
205EXPORT_SYMBOL_GPL(mantis_i2c_exit);
diff --git a/drivers/media/dvb/mantis/mantis_i2c.h b/drivers/media/dvb/mantis/mantis_i2c.h
new file mode 100644
index 000000000000..1e49ecfeee3e
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_i2c.h
@@ -0,0 +1,7 @@
1#ifndef __MANTIS_I2C_H
2#define __MANTIS_I2C_H
3
4extern int mantis_i2c_init(struct mantis_pci *mantis);
5extern int mantis_i2c_exit(struct mantis_pci *mantis);
6
7#endif /* __MANTIS_I2C_H */
diff --git a/drivers/media/dvb/mantis/mantis_ioc.c b/drivers/media/dvb/mantis/mantis_ioc.c
new file mode 100644
index 000000000000..4700088f0388
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_ioc.c
@@ -0,0 +1,145 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/kernel.h>
22#include <linux/i2c.h>
23
24#include <asm/irq.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/interrupt.h>
28
29#include "dmxdev.h"
30#include "dvbdev.h"
31#include "dvb_demux.h"
32#include "dvb_frontend.h"
33#include "dvb_net.h"
34
35#include "mantis_common.h"
36#include "mantis_reg.h"
37#include "mantis_ioc.h"
38
39static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
40{
41 struct i2c_adapter *adapter = &mantis->adapter;
42
43 int err;
44 struct i2c_msg msg[] = {
45 { .addr = 0x50, .flags = 0, .buf = data, .len = 1 },
46 { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length },
47 };
48
49 err = i2c_transfer(adapter, msg, 2);
50 if (err < 0) {
51 dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
52 err, data[0], data[1]);
53
54 return err;
55 }
56
57 return 0;
58}
59
60static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
61{
62 struct i2c_adapter *adapter = &mantis->adapter;
63 int err;
64
65 struct i2c_msg msg = { .addr = 0x50, .flags = 0, .buf = data, .len = length };
66
67 err = i2c_transfer(adapter, &msg, 1);
68 if (err < 0) {
69 dprintk(MANTIS_ERROR, 1, "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
70 err, length, data[0], data[1]);
71
72 return err;
73 }
74
75 return 0;
76}
77
78int mantis_get_mac(struct mantis_pci *mantis)
79{
80 int err;
81
82 mantis->mac_address[0] = 0x08;
83
84 err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6);
85 if (err < 0) {
86 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err);
87
88 return err;
89 }
90
91 dprintk(MANTIS_ERROR, 0,
92 " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
93 mantis->mac_address[0], mantis->mac_address[1],
94 mantis->mac_address[2], mantis->mac_address[3],
95 mantis->mac_address[4], mantis->mac_address[5]);
96
97 return 0;
98}
99EXPORT_SYMBOL_GPL(mantis_get_mac);
100
101/* Turn the given bit on or off. */
102void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
103{
104 u32 cur;
105
106 cur = mmread(MANTIS_GPIF_ADDR);
107 if (value)
108 mantis->gpio_status = cur | (1 << bitpos);
109 else
110 mantis->gpio_status = cur & (~(1 << bitpos));
111
112 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
113 mmwrite(0x00, MANTIS_GPIF_DOUT);
114}
115EXPORT_SYMBOL_GPL(gpio_set_bits);
116
117int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)
118{
119 u32 reg;
120
121 reg = mmread(MANTIS_CONTROL);
122 switch (stream_ctl) {
123 case STREAM_TO_HIF:
124 dprintk(MANTIS_DEBUG, 1, "Set stream to HIF");
125 reg &= 0xff - MANTIS_BYPASS;
126 mmwrite(reg, MANTIS_CONTROL);
127 reg |= MANTIS_BYPASS;
128 mmwrite(reg, MANTIS_CONTROL);
129 break;
130
131 case STREAM_TO_CAM:
132 dprintk(MANTIS_DEBUG, 1, "Set stream to CAM");
133 reg |= MANTIS_BYPASS;
134 mmwrite(reg, MANTIS_CONTROL);
135 reg &= 0xff - MANTIS_BYPASS;
136 mmwrite(reg, MANTIS_CONTROL);
137 break;
138 default:
139 dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl);
140 return -1;
141 }
142
143 return 0;
144}
145EXPORT_SYMBOL_GPL(mantis_stream_control);
diff --git a/drivers/media/dvb/mantis/mantis_link.h b/drivers/media/dvb/mantis/mantis_link.h
index f9aaaa52f52c..f6030c9fba2d 100644
--- a/drivers/media/dvb/mantis/mantis_link.h
+++ b/drivers/media/dvb/mantis/mantis_link.h
@@ -58,7 +58,6 @@ struct mantis_ca {
58 58
59 enum mantis_slot_state slot_state; 59 enum mantis_slot_state slot_state;
60 60
61// struct dvb_device *ca_dev;
62 void *ca_priv; 61 void *ca_priv;
63 62
64 struct dvb_ca_en50221 en50221; 63 struct dvb_ca_en50221 en50221;
@@ -81,4 +80,4 @@ extern int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data);
81extern int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr); 80extern int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr);
82extern int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data); 81extern int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data);
83 82
84#endif // __MANTIS_LINK_H 83#endif /* __MANTIS_LINK_H */
diff --git a/drivers/media/dvb/mantis/mantis_pci.c b/drivers/media/dvb/mantis/mantis_pci.c
index d1eac4083fcc..5165a390e07a 100644
--- a/drivers/media/dvb/mantis/mantis_pci.c
+++ b/drivers/media/dvb/mantis/mantis_pci.c
@@ -18,6 +18,9 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/kernel.h>
21#include <asm/io.h> 24#include <asm/io.h>
22#include <asm/pgtable.h> 25#include <asm/pgtable.h>
23#include <asm/page.h> 26#include <asm/page.h>
@@ -25,264 +28,149 @@
25#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
26#include <linux/init.h> 29#include <linux/init.h>
27#include <linux/device.h> 30#include <linux/device.h>
28#include "mantis_common.h" 31#include <linux/pci.h>
29#include "mantis_core.h"
30#include "mantis_uart.h"
31 32
32#include <asm/irq.h> 33#include <asm/irq.h>
33#include <linux/signal.h> 34#include <linux/signal.h>
34#include <linux/sched.h> 35#include <linux/sched.h>
35#include <linux/interrupt.h> 36#include <linux/interrupt.h>
36 37
37unsigned int verbose = 1; 38#include "dmxdev.h"
38module_param(verbose, int, 0644); 39#include "dvbdev.h"
39MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 40#include "dvb_demux.h"
40 41#include "dvb_frontend.h"
41unsigned int devs; 42#include "dvb_net.h"
42
43#define PCI_VENDOR_ID_MANTIS 0x1822
44#define PCI_DEVICE_ID_MANTIS_R11 0x4e35
45#define DRIVER_NAME "Mantis"
46
47static struct pci_device_id mantis_pci_table[] = {
48 { PCI_DEVICE(PCI_VENDOR_ID_MANTIS, PCI_DEVICE_ID_MANTIS_R11) },
49 { 0 },
50};
51
52MODULE_DEVICE_TABLE(pci, mantis_pci_table);
53
54static irqreturn_t mantis_pci_irq(int irq, void *dev_id)
55{
56 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
57 u32 rst_stat = 0, rst_mask = 0;
58 43
59 struct mantis_pci *mantis; 44#include <asm/irq.h>
60 struct mantis_ca *ca; 45#include <linux/signal.h>
46#include <linux/sched.h>
47#include <linux/interrupt.h>
61 48
62 mantis = (struct mantis_pci *) dev_id; 49#include "mantis_common.h"
63 if (unlikely(mantis == NULL)) { 50#include "mantis_reg.h"
64 dprintk(verbose, MANTIS_ERROR, 1, "Mantis == NULL"); 51#include "mantis_pci.h"
65 return IRQ_NONE;
66 }
67 ca = mantis->mantis_ca;
68
69 stat = mmread(MANTIS_INT_STAT);
70 mask = mmread(MANTIS_INT_MASK);
71 mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
72 if (!(stat & mask))
73 return IRQ_NONE;
74
75 rst_mask = MANTIS_GPIF_WRACK |
76 MANTIS_GPIF_OTHERR |
77 MANTIS_SBUF_WSTO |
78 MANTIS_GPIF_EXTIRQ;
79
80 rst_stat = mmread(MANTIS_GPIF_STATUS);
81 rst_stat &= rst_mask;
82 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
83
84 mantis->mantis_int_stat = stat;
85 mantis->mantis_int_mask = mask;
86 dprintk(verbose, MANTIS_DEBUG, 0, "=== Interrupts[%04x/%04x]= [", stat, mask);
87 if (stat & MANTIS_INT_RISCEN) {
88 dprintk(verbose, MANTIS_DEBUG, 0, "* DMA enabl *");
89 }
90 if (stat & MANTIS_INT_IRQ0) {
91 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-0 *");
92 mantis->gpif_status = rst_stat;
93 wake_up(&ca->hif_write_wq);
94 schedule_work(&ca->hif_evm_work);
95 }
96 if (stat & MANTIS_INT_IRQ1) {
97 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-1 *");
98 schedule_work(&mantis->uart_work);
99 }
100 if (stat & MANTIS_INT_OCERR) {
101 dprintk(verbose, MANTIS_DEBUG, 0, "* INT OCERR *");
102 }
103 if (stat & MANTIS_INT_PABORT) {
104 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PABRT *");
105 }
106 if (stat & MANTIS_INT_RIPERR) {
107 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RIPRR *");
108 }
109 if (stat & MANTIS_INT_PPERR) {
110 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PPERR *");
111 }
112 if (stat & MANTIS_INT_FTRGT) {
113 dprintk(verbose, MANTIS_DEBUG, 0, "* INT FTRGT *");
114 }
115 if (stat & MANTIS_INT_RISCI) {
116 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RISCI *");
117 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
118 tasklet_schedule(&mantis->tasklet);
119 }
120 if (stat & MANTIS_INT_I2CDONE) {
121 dprintk(verbose, MANTIS_DEBUG, 0, "* I2C DONE *");
122 wake_up(&mantis->i2c_wq);
123 }
124 mmwrite(stat, MANTIS_INT_STAT);
125 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
126 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
127 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
128 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
129 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
130 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
131 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
132 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
133 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
134 MANTIS_INT_RISCI);
135
136 if (stat)
137 dprintk(verbose, MANTIS_DEBUG, 0, "* Unknown [%04x] *", stat);
138
139 dprintk(verbose, MANTIS_DEBUG, 0, "] ===\n");
140
141 return IRQ_HANDLED;
142}
143 52
53#define DRIVER_NAME "Mantis Core"
144 54
145static int __devinit mantis_pci_probe(struct pci_dev *pdev, 55int __devinit mantis_pci_init(struct mantis_pci *mantis)
146 const struct pci_device_id *mantis_pci_table)
147{ 56{
148 u8 revision, latency; 57 u8 revision, latency;
149 struct mantis_pci *mantis; 58 struct mantis_hwconfig *config = mantis->hwconfig;
150 int ret = 0; 59 struct pci_dev *pdev = mantis->pdev;
60 int err, ret = 0;
61
62 dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
63 config->model_name,
64 config->dev_type,
65 mantis->pdev->bus->number,
66 PCI_SLOT(mantis->pdev->devfn),
67 PCI_FUNC(mantis->pdev->devfn));
68
69 err = pci_enable_device(pdev);
70 if (err != 0) {
71 ret = -ENODEV;
72 dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err);
73 goto fail0;
74 }
151 75
152 mantis = kmalloc(sizeof (struct mantis_pci), GFP_KERNEL); 76 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
153 if (mantis == NULL) { 77 if (err != 0) {
154 printk("%s: Out of memory\n", __func__); 78 dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);
155 ret = -ENOMEM; 79 ret = -ENOMEM;
156 goto err; 80 goto fail1;
157 } 81 }
158 memset(mantis, 0, sizeof (struct mantis_pci));
159 mantis->num = devs;
160 devs++;
161 82
162 if (pci_enable_device(pdev)) { 83 pci_set_master(pdev);
163 dprintk(verbose, MANTIS_ERROR, 1, "Mantis PCI enable failed");
164 ret = -ENODEV;
165 goto err;
166 }
167 mantis->mantis_addr = pci_resource_start(pdev, 0);
168 if (!request_mem_region(pci_resource_start(pdev, 0),
169 pci_resource_len(pdev, 0), DRIVER_NAME)) {
170 ret = -ENODEV;
171 goto err0;
172 }
173 84
174 mantis->mantis_mmio = ioremap(pci_resource_start(pdev, 0), 85 if (!request_mem_region(pci_resource_start(pdev, 0),
175 pci_resource_len(pdev, 0)); 86 pci_resource_len(pdev, 0),
87 DRIVER_NAME)) {
176 88
177 if (!mantis->mantis_mmio) { 89 dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !");
178 dprintk(verbose, MANTIS_ERROR, 1, "IO remap failed");
179 ret = -ENODEV; 90 ret = -ENODEV;
180 goto err1; 91 goto fail1;
181 } 92 }
182 93
183 // Clear and disable all interrupts at startup 94 mantis->mmio = ioremap(pci_resource_start(pdev, 0),
184 // to avoid lockup situations 95 pci_resource_len(pdev, 0));
185 mmwrite(0x00, MANTIS_INT_MASK);
186 if (request_irq(pdev->irq,
187 mantis_pci_irq,
188 IRQF_SHARED,
189 DRIVER_NAME,
190 mantis) < 0) {
191 96
192 dprintk(verbose, MANTIS_ERROR, 1, "Mantis IRQ reg failed"); 97 if (!mantis->mmio) {
98 dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !");
193 ret = -ENODEV; 99 ret = -ENODEV;
194 goto err2; 100 goto fail2;
195 } 101 }
196 pci_set_master(pdev); 102
197 pci_set_drvdata(pdev, mantis);
198 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency); 103 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
199 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); 104 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
200 mantis->latency = latency; 105 mantis->latency = latency;
201 mantis->revision = revision; 106 mantis->revision = revision;
202 mantis->pdev = pdev;
203 mantis->subsystem_vendor = pdev->subsystem_vendor;
204 mantis->subsystem_device = pdev->subsystem_device;
205 init_waitqueue_head(&mantis->i2c_wq);
206 107
207 mantis_set_direction(mantis, 0); /* CAM bypass */ 108 dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
109 mantis->revision,
110 mantis->pdev->subsystem_vendor,
111 mantis->pdev->subsystem_device);
112
113 dprintk(MANTIS_ERROR, 0,
114 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
115 mantis->pdev->irq,
116 mantis->latency,
117 mantis->mantis_addr,
118 mantis->mmio);
208 119
209 if (!latency) 120 err = request_irq(pdev->irq,
210 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 32); 121 config->irq_handler,
122 IRQF_SHARED,
123 DRIVER_NAME,
124 mantis);
211 125
212 dprintk(verbose, MANTIS_ERROR, 0, 126 if (err != 0) {
213 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
214 pdev->irq, mantis->latency,
215 mantis->mantis_addr, mantis->mantis_mmio);
216 127
217 // No more PCI specific stuff ! 128 dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);
218 if (mantis_core_init(mantis) < 0) {
219 dprintk(verbose, MANTIS_ERROR, 1, "Mantis core init failed");
220 ret = -ENODEV; 129 ret = -ENODEV;
221 goto err2; 130 goto fail3;
222 } 131 }
223 132
224 return 0; 133 pci_set_drvdata(pdev, mantis);
134 return ret;
225 135
226 // Error conditions .. 136 /* Error conditions */
227err2: 137fail3:
228 dprintk(verbose, MANTIS_DEBUG, 1, "Err: IO Unmap"); 138 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);
229 if (mantis->mantis_mmio) 139 if (mantis->mmio)
230 iounmap(mantis->mantis_mmio); 140 iounmap(mantis->mmio);
231err1: 141
232 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Release regions"); 142fail2:
143 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);
233 release_mem_region(pci_resource_start(pdev, 0), 144 release_mem_region(pci_resource_start(pdev, 0),
234 pci_resource_len(pdev, 0)); 145 pci_resource_len(pdev, 0));
146
147fail1:
148 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);
235 pci_disable_device(pdev); 149 pci_disable_device(pdev);
236err0: 150
237 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Free"); 151fail0:
238 kfree(mantis); 152 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
239err: 153 pci_set_drvdata(pdev, NULL);
240 dprintk(verbose, MANTIS_DEBUG, 1, "Err:");
241 return ret; 154 return ret;
242} 155}
156EXPORT_SYMBOL_GPL(mantis_pci_init);
243 157
244static void __devexit mantis_pci_remove(struct pci_dev *pdev) 158void __devexit mantis_pci_exit(struct mantis_pci *mantis)
245{ 159{
246 struct mantis_pci *mantis = pci_get_drvdata(pdev); 160 struct pci_dev *pdev = mantis->pdev;
247
248 if (mantis == NULL) {
249 dprintk(verbose, MANTIS_ERROR, 1, "Aeio, Mantis NULL ptr");
250 return;
251 }
252 mantis_core_exit(mantis);
253 dprintk(verbose, MANTIS_ERROR, 1, "Removing -->Mantis irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p",
254 pdev->irq, mantis->latency, mantis->mantis_addr,
255 mantis->mantis_mmio);
256 161
162 dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);
257 free_irq(pdev->irq, mantis); 163 free_irq(pdev->irq, mantis);
258 pci_release_regions(pdev); 164 if (mantis->mmio) {
259 if (mantis_dma_exit(mantis) < 0) 165 iounmap(mantis->mmio);
260 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed"); 166 release_mem_region(pci_resource_start(pdev, 0),
167 pci_resource_len(pdev, 0));
168 }
261 169
262 pci_set_drvdata(pdev, NULL);
263 pci_disable_device(pdev); 170 pci_disable_device(pdev);
264 kfree(mantis); 171 pci_set_drvdata(pdev, NULL);
265}
266
267static struct pci_driver mantis_pci_driver = {
268 .name = DRIVER_NAME,
269 .id_table = mantis_pci_table,
270 .probe = mantis_pci_probe,
271 .remove = mantis_pci_remove,
272};
273
274static int __devinit mantis_pci_init(void)
275{
276 return pci_register_driver(&mantis_pci_driver);
277}
278
279static void __devexit mantis_pci_exit(void)
280{
281 pci_unregister_driver(&mantis_pci_driver);
282} 172}
283 173EXPORT_SYMBOL_GPL(mantis_pci_exit);
284module_init(mantis_pci_init);
285module_exit(mantis_pci_exit);
286 174
287MODULE_DESCRIPTION("Mantis PCI DTV bridge driver"); 175MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
288MODULE_AUTHOR("Manu Abraham"); 176MODULE_AUTHOR("Manu Abraham");
diff --git a/drivers/media/dvb/mantis/mantis_pci.h b/drivers/media/dvb/mantis/mantis_pci.h
new file mode 100644
index 000000000000..5ce776ffcb32
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_pci.h
@@ -0,0 +1,7 @@
1#ifndef __MANTIS_PCI_H
2#define __MANTIS_PCI_H
3
4extern int mantis_pci_init(struct mantis_pci *mantis);
5extern void mantis_pci_exit(struct mantis_pci *mantis);
6
7#endif /* __MANTIS_PCI_H */
diff --git a/drivers/media/dvb/mantis/mantis_pcmcia.c b/drivers/media/dvb/mantis/mantis_pcmcia.c
index 4156a0820886..90ca356985eb 100644
--- a/drivers/media/dvb/mantis/mantis_pcmcia.c
+++ b/drivers/media/dvb/mantis/mantis_pcmcia.c
@@ -18,8 +18,22 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/kernel.h>
22
23#include <asm/irq.h>
24#include <linux/signal.h>
25#include <linux/sched.h>
26#include <linux/interrupt.h>
27
28#include "dmxdev.h"
29#include "dvbdev.h"
30#include "dvb_demux.h"
31#include "dvb_frontend.h"
32#include "dvb_net.h"
33
21#include "mantis_common.h" 34#include "mantis_common.h"
22#include "mantis_link.h" /* temporary due to physical layer stuff */ 35#include "mantis_link.h" /* temporary due to physical layer stuff */
36#include "mantis_reg.h"
23 37
24/* 38/*
25 * If Slot state is already PLUG_IN event and we are called 39 * If Slot state is already PLUG_IN event and we are called
@@ -32,7 +46,7 @@ void mantis_event_cam_plugin(struct mantis_ca *ca)
32 u32 gpif_irqcfg; 46 u32 gpif_irqcfg;
33 47
34 if (ca->slot_state == MODULE_XTRACTED) { 48 if (ca->slot_state == MODULE_XTRACTED) {
35 dprintk(verbose, MANTIS_DEBUG, 1, "Event: CAM Plugged IN: Adapter(%d) Slot(0)", mantis->num); 49 dprintk(MANTIS_DEBUG, 1, "Event: CAM Plugged IN: Adapter(%d) Slot(0)", mantis->num);
36 udelay(50); 50 udelay(50);
37 mmwrite(0xda000000, MANTIS_CARD_RESET); 51 mmwrite(0xda000000, MANTIS_CARD_RESET);
38 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG); 52 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG);
@@ -56,7 +70,7 @@ void mantis_event_cam_unplug(struct mantis_ca *ca)
56 u32 gpif_irqcfg; 70 u32 gpif_irqcfg;
57 71
58 if (ca->slot_state == MODULE_INSERTED) { 72 if (ca->slot_state == MODULE_INSERTED) {
59 dprintk(verbose, MANTIS_DEBUG, 1, "Event: CAM Unplugged: Adapter(%d) Slot(0)", mantis->num); 73 dprintk(MANTIS_DEBUG, 1, "Event: CAM Unplugged: Adapter(%d) Slot(0)", mantis->num);
60 udelay(50); 74 udelay(50);
61 mmwrite(0x00da0000, MANTIS_CARD_RESET); 75 mmwrite(0x00da0000, MANTIS_CARD_RESET);
62 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG); 76 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG);
@@ -80,14 +94,14 @@ int mantis_pcmcia_init(struct mantis_ca *ca)
80 card_stat = mmread(MANTIS_GPIF_IRQCFG); 94 card_stat = mmread(MANTIS_GPIF_IRQCFG);
81 95
82 if (gpif_stat & MANTIS_GPIF_DETSTAT) { 96 if (gpif_stat & MANTIS_GPIF_DETSTAT) {
83 dprintk(verbose, MANTIS_DEBUG, 1, "CAM found on Adapter(%d) Slot(0)", mantis->num); 97 dprintk(MANTIS_DEBUG, 1, "CAM found on Adapter(%d) Slot(0)", mantis->num);
84 mmwrite(card_stat | MANTIS_MASK_PLUGOUT, MANTIS_GPIF_IRQCFG); 98 mmwrite(card_stat | MANTIS_MASK_PLUGOUT, MANTIS_GPIF_IRQCFG);
85 ca->slot_state = MODULE_INSERTED; 99 ca->slot_state = MODULE_INSERTED;
86 dvb_ca_en50221_camchange_irq(&ca->en50221, 100 dvb_ca_en50221_camchange_irq(&ca->en50221,
87 0, 101 0,
88 DVB_CA_EN50221_CAMCHANGE_INSERTED); 102 DVB_CA_EN50221_CAMCHANGE_INSERTED);
89 } else { 103 } else {
90 dprintk(verbose, MANTIS_DEBUG, 1, "Empty Slot on Adapter(%d) Slot(0)", mantis->num); 104 dprintk(MANTIS_DEBUG, 1, "Empty Slot on Adapter(%d) Slot(0)", mantis->num);
91 mmwrite(card_stat | MANTIS_MASK_PLUGIN, MANTIS_GPIF_IRQCFG); 105 mmwrite(card_stat | MANTIS_MASK_PLUGIN, MANTIS_GPIF_IRQCFG);
92 ca->slot_state = MODULE_XTRACTED; 106 ca->slot_state = MODULE_XTRACTED;
93 dvb_ca_en50221_camchange_irq(&ca->en50221, 107 dvb_ca_en50221_camchange_irq(&ca->en50221,
diff --git a/drivers/media/dvb/mantis/mantis_reg.h b/drivers/media/dvb/mantis/mantis_reg.h
index 6f5cd4936763..0072e149a561 100644
--- a/drivers/media/dvb/mantis/mantis_reg.h
+++ b/drivers/media/dvb/mantis/mantis_reg.h
@@ -21,7 +21,7 @@
21#ifndef __MANTIS_REG_H 21#ifndef __MANTIS_REG_H
22#define __MANTIS_REG_H 22#define __MANTIS_REG_H
23 23
24// Interrupts 24/* Interrupts */
25#define MANTIS_INT_STAT 0x00 25#define MANTIS_INT_STAT 0x00
26#define MANTIS_INT_MASK 0x04 26#define MANTIS_INT_MASK 0x04
27 27
@@ -49,8 +49,12 @@
49#define MANTIS_INT_RISCI (0x01 << 1) 49#define MANTIS_INT_RISCI (0x01 << 1)
50#define MANTIS_INT_I2CDONE (0x01 << 0) 50#define MANTIS_INT_I2CDONE (0x01 << 0)
51 51
52// DMA 52/* DMA */
53#define MANTIS_DMA_CTL 0x08 53#define MANTIS_DMA_CTL 0x08
54#define MANTIS_GPIF_RD (0xff << 24)
55#define MANTIS_GPIF_WR (0xff << 16)
56#define MANTIS_CPU_DO (0x01 << 10)
57#define MANTIS_DRV_DO (0x01 << 9)
54#define MANTIS_I2C_RD (0x01 << 7) 58#define MANTIS_I2C_RD (0x01 << 7)
55#define MANTIS_I2C_WR (0x01 << 6) 59#define MANTIS_I2C_WR (0x01 << 6)
56#define MANTIS_DCAP_MODE (0x01 << 5) 60#define MANTIS_DCAP_MODE (0x01 << 5)
@@ -61,10 +65,16 @@
61#define MANTIS_DCAP_EN (0x01 << 1) 65#define MANTIS_DCAP_EN (0x01 << 1)
62#define MANTIS_RISC_EN (0x01 << 0) 66#define MANTIS_RISC_EN (0x01 << 0)
63 67
68/* DEBUG */
69#define MANTIS_DEBUGREG 0x0c
70#define MANTIS_DATINV (0x0e << 7)
71#define MANTIS_TOP_DEBUGSEL (0x07 << 4)
72#define MANTIS_PCMCIA_DEBUGSEL (0x0f << 0)
73
64#define MANTIS_RISC_START 0x10 74#define MANTIS_RISC_START 0x10
65#define MANTIS_RISC_PC 0x14 75#define MANTIS_RISC_PC 0x14
66 76
67// I2C 77/* I2C */
68#define MANTIS_I2CDATA_CTL 0x18 78#define MANTIS_I2CDATA_CTL 0x18
69#define MANTIS_I2C_RATE_1 (0x00 << 6) 79#define MANTIS_I2C_RATE_1 (0x00 << 6)
70#define MANTIS_I2C_RATE_2 (0x01 << 6) 80#define MANTIS_I2C_RATE_2 (0x01 << 6)
@@ -73,6 +83,28 @@
73#define MANTIS_I2C_STOP (0x01 << 5) 83#define MANTIS_I2C_STOP (0x01 << 5)
74#define MANTIS_I2C_PGMODE (0x01 << 3) 84#define MANTIS_I2C_PGMODE (0x01 << 3)
75 85
86/* DATA */
87#define MANTIS_CMD_DATA_R1 0x20
88#define MANTIS_CMD_DATA_3 (0xff << 24)
89#define MANTIS_CMD_DATA_2 (0xff << 16)
90#define MANTIS_CMD_DATA_1 (0xff << 8)
91#define MANTIS_CMD_DATA_0 (0xff << 0)
92
93#define MANTIS_CMD_DATA_R2 0x24
94#define MANTIS_CMD_DATA_7 (0xff << 24)
95#define MANTIS_CMD_DATA_6 (0xff << 16)
96#define MANTIS_CMD_DATA_5 (0xff << 8)
97#define MANTIS_CMD_DATA_4 (0xff << 0)
98
99#define MANTIS_CONTROL 0x28
100#define MANTIS_DET (0x01 << 7)
101#define MANTIS_DAT_CF_EN (0x01 << 6)
102#define MANTIS_ACS (0x03 << 4)
103#define MANTIS_VCCEN (0x01 << 3)
104#define MANTIS_BYPASS (0x01 << 2)
105#define MANTIS_MRST (0x01 << 1)
106#define MANTIS_CRST_INT (0x01 << 0)
107
76#define MANTIS_GPIF_CFGSLA 0x84 108#define MANTIS_GPIF_CFGSLA 0x84
77#define MANTIS_GPIF_WAITSMPL (0x07 << 28) 109#define MANTIS_GPIF_WAITSMPL (0x07 << 28)
78#define MANTIS_GPIF_BYTEADDRSUB (0x01 << 25) 110#define MANTIS_GPIF_BYTEADDRSUB (0x01 << 25)
@@ -162,4 +194,4 @@
162#define MANTIS_GPIF_LOGICRD (0xffff << 16) 194#define MANTIS_GPIF_LOGICRD (0xffff << 16)
163#define MANTIS_GPIF_LOGICRW (0xffff << 0) 195#define MANTIS_GPIF_LOGICRW (0xffff << 0)
164 196
165#endif //__MANTIS_REG_H 197#endif /* __MANTIS_REG_H */
diff --git a/drivers/media/dvb/mantis/mantis_uart.c b/drivers/media/dvb/mantis/mantis_uart.c
index 786fcc339117..fb423b0a58fd 100644
--- a/drivers/media/dvb/mantis/mantis_uart.c
+++ b/drivers/media/dvb/mantis/mantis_uart.c
@@ -1,5 +1,20 @@
1#include <linux/kernel.h>
1#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3
4#include <asm/irq.h>
5#include <linux/signal.h>
6#include <linux/sched.h>
7#include <linux/interrupt.h>
8
9#include "dmxdev.h"
10#include "dvbdev.h"
11#include "dvb_demux.h"
12#include "dvb_frontend.h"
13#include "dvb_net.h"
14
2#include "mantis_common.h" 15#include "mantis_common.h"
16#include "mantis_reg.h"
17#include "mantis_uart.h"
3 18
4struct mantis_uart_params { 19struct mantis_uart_params {
5 enum mantis_baud baud_rate; 20 enum mantis_baud baud_rate;
@@ -18,20 +33,20 @@ int mantis_uart_read(struct mantis_pci *mantis, u8 *data)
18 for (i = 0; i < (config->bytes + 1); i++) { 33 for (i = 0; i < (config->bytes + 1); i++) {
19 34
20 if (stat & MANTIS_UART_RXFIFO_FULL) { 35 if (stat & MANTIS_UART_RXFIFO_FULL) {
21 dprintk(verbose, MANTIS_ERROR, 1, "RX Fifo FULL"); 36 dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
22 } 37 }
23 data[i] = mmread(MANTIS_UART_RXD) & 0x3f; 38 data[i] = mmread(MANTIS_UART_RXD) & 0x3f;
24 39
25 stat = mmread(MANTIS_UART_STAT); 40 stat = mmread(MANTIS_UART_STAT);
26 41
27 dprintk(verbose, MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f); 42 dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f);
28 43
29 if (data[i] & (1 << 7)) { 44 if (data[i] & (1 << 7)) {
30 dprintk(verbose, MANTIS_ERROR, 1, "UART framing error"); 45 dprintk(MANTIS_ERROR, 1, "UART framing error");
31 return -EINVAL; 46 return -EINVAL;
32 } 47 }
33 if (data[i] & (1 << 6)) { 48 if (data[i] & (1 << 6)) {
34 dprintk(verbose, MANTIS_ERROR, 1, "UART parity error"); 49 dprintk(MANTIS_ERROR, 1, "UART parity error");
35 return -EINVAL; 50 return -EINVAL;
36 } 51 }
37 } 52 }
@@ -46,14 +61,14 @@ static void mantis_uart_work(struct work_struct *work)
46 u8 buf[16]; 61 u8 buf[16];
47 int i; 62 int i;
48 63
49 dprintk(verbose, MANTIS_DEBUG, 1, "UART read"); 64 dprintk(MANTIS_DEBUG, 1, "UART read");
50 mantis_uart_read(mantis, buf); 65 mantis_uart_read(mantis, buf);
51 66
52 dprintk(verbose, MANTIS_DEBUG, 1, "UART: "); 67 dprintk(MANTIS_DEBUG, 1, "UART: ");
53 for (i = 0; i < (config->bytes + 1); i++) 68 for (i = 0; i < (config->bytes + 1); i++)
54 dprintk(verbose, MANTIS_DEBUG, 0, "<%02x> ", buf[i]); 69 dprintk(MANTIS_DEBUG, 0, "<%02x> ", buf[i]);
55 70
56 dprintk(verbose, MANTIS_DEBUG, 0, "\n"); 71 dprintk(MANTIS_DEBUG, 0, "\n");
57} 72}
58 73
59static int mantis_uart_setup(struct mantis_pci *mantis, 74static int mantis_uart_setup(struct mantis_pci *mantis,
@@ -64,7 +79,7 @@ static int mantis_uart_setup(struct mantis_pci *mantis,
64 79
65 u32 reg; 80 u32 reg;
66 81
67 dprintk(verbose, MANTIS_DEBUG, 1, "Set Parity <%s> Baud Rate <%s>", 82 dprintk(MANTIS_DEBUG, 1, "Set Parity <%s> Baud Rate <%s>",
68 parity[params->parity], 83 parity[params->parity],
69 rates[params->baud_rate]); 84 rates[params->baud_rate]);
70 85
@@ -102,7 +117,7 @@ int mantis_uart_init(struct mantis_pci *mantis)
102 struct mantis_hwconfig *config = mantis->hwconfig; 117 struct mantis_hwconfig *config = mantis->hwconfig;
103 struct mantis_uart_params params; 118 struct mantis_uart_params params;
104 119
105 dprintk(verbose, MANTIS_DEBUG, 1, "Initializing UART .."); 120 dprintk(MANTIS_DEBUG, 1, "Initializing UART ..");
106 /* default parity: */ 121 /* default parity: */
107 params.baud_rate = config->baud_rate; 122 params.baud_rate = config->baud_rate;
108 params.parity = config->parity; 123 params.parity = config->parity;
@@ -131,9 +146,11 @@ int mantis_uart_init(struct mantis_pci *mantis)
131 146
132 return 0; 147 return 0;
133} 148}
149EXPORT_SYMBOL_GPL(mantis_uart_init);
134 150
135void mantis_uart_exit(struct mantis_pci *mantis) 151void mantis_uart_exit(struct mantis_pci *mantis)
136{ 152{
137 /* disable interrupt */ 153 /* disable interrupt */
138 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL); 154 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
139} 155}
156EXPORT_SYMBOL_GPL(mantis_uart_exit);
diff --git a/drivers/media/dvb/mantis/mantis_uart.h b/drivers/media/dvb/mantis/mantis_uart.h
index e9f938d37c3a..0a42cd01ab22 100644
--- a/drivers/media/dvb/mantis/mantis_uart.h
+++ b/drivers/media/dvb/mantis/mantis_uart.h
@@ -56,4 +56,4 @@ struct mantis_pci;
56extern int mantis_uart_init(struct mantis_pci *mantis); 56extern int mantis_uart_init(struct mantis_pci *mantis);
57extern void mantis_uart_exit(struct mantis_pci *mantis); 57extern void mantis_uart_exit(struct mantis_pci *mantis);
58 58
59#endif // __MANTIS_UART_H 59#endif /* __MANTIS_UART_H */
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.c b/drivers/media/dvb/mantis/mantis_vp1033.c
index 64cdfb8b709b..f2092ce9c4be 100644
--- a/drivers/media/dvb/mantis/mantis_vp1033.c
+++ b/drivers/media/dvb/mantis/mantis_vp1033.c
@@ -18,6 +18,18 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "stv0299.h"
21#include "mantis_common.h" 33#include "mantis_common.h"
22#include "mantis_vp1033.h" 34#include "mantis_vp1033.h"
23 35
@@ -66,47 +78,21 @@ u8 lgtdqcs001f_inittab[] = {
66 0xff, 0xff, 78 0xff, 0xff,
67}; 79};
68 80
69struct stv0299_config lgtdqcs001f_config = {
70 .demod_address = 0x68,
71 .inittab = lgtdqcs001f_inittab,
72 .mclk = 88000000UL,
73// .invert = 0,
74 .invert = 1,
75// .enhanced_tuning = 0,
76 .skip_reinit = 0,
77// .lock_output = STV0229_LOCKOUTPUT_0,
78 .volt13_op0_op1 = STV0299_VOLT13_OP0,
79 .min_delay_ms = 100,
80 .set_symbol_rate = lgtdqcs001f_set_symbol_rate,
81// .pll_set = lgtdqcs001f_pll_set,
82};
83
84#define MANTIS_MODEL_NAME "VP-1033" 81#define MANTIS_MODEL_NAME "VP-1033"
85#define MANTIS_DEV_TYPE "DVB-S/DSS" 82#define MANTIS_DEV_TYPE "DVB-S/DSS"
86 83
87struct mantis_hwconfig vp1033_mantis_config = {
88 .model_name = MANTIS_MODEL_NAME,
89 .dev_type = MANTIS_DEV_TYPE,
90 .ts_size = MANTIS_TS_204,
91 .baud_rate = MANTIS_BAUD_9600,
92 .parity = MANTIS_PARITY_NONE,
93 .bytes = 0,
94};
95
96int lgtdqcs001f_tuner_set(struct dvb_frontend *fe, 84int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,
97 struct dvb_frontend_parameters *params) 85 struct dvb_frontend_parameters *params)
98{ 86{
87 struct mantis_pci *mantis = fe->dvb->priv;
88 struct i2c_adapter *adapter = &mantis->adapter;
89
99 u8 buf[4]; 90 u8 buf[4];
100 u32 div; 91 u32 div;
101 92
102 struct mantis_pci *mantis = fe->dvb->priv;
103 93
104 struct i2c_msg msg = { 94 struct i2c_msg msg = {.addr = 0x61, .flags = 0, .buf = buf, .len = sizeof (buf) };
105 .addr = 0x61, 95
106 .flags = 0,
107 .buf = buf,
108 .len = sizeof (buf)
109 };
110 div = params->frequency / 250; 96 div = params->frequency / 250;
111 97
112 buf[0] = (div >> 8) & 0x7f; 98 buf[0] = (div >> 8) & 0x7f;
@@ -118,8 +104,8 @@ int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,
118 buf[3] |= 0x04; 104 buf[3] |= 0x04;
119 else 105 else
120 buf[3] &= ~0x04; 106 buf[3] &= ~0x04;
121 if (i2c_transfer(&mantis->adapter, &msg, 1) < 0) { 107 if (i2c_transfer(adapter, &msg, 1) < 0) {
122 dprintk(verbose, MANTIS_ERROR, 1, "Write: I2C Transfer failed"); 108 dprintk(MANTIS_ERROR, 1, "Write: I2C Transfer failed");
123 return -EIO; 109 return -EIO;
124 } 110 }
125 msleep_interruptible(100); 111 msleep_interruptible(100);
@@ -161,3 +147,49 @@ int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe,
161 147
162 return 0; 148 return 0;
163} 149}
150
151struct stv0299_config lgtdqcs001f_config = {
152 .demod_address = 0x68,
153 .inittab = lgtdqcs001f_inittab,
154 .mclk = 88000000UL,
155 .invert = 0,
156 .skip_reinit = 0,
157 .volt13_op0_op1 = STV0299_VOLT13_OP0,
158 .min_delay_ms = 100,
159 .set_symbol_rate = lgtdqcs001f_set_symbol_rate,
160};
161
162static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
163{
164 struct i2c_adapter *adapter = &mantis->adapter;
165
166 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
167 fe = stv0299_attach(&lgtdqcs001f_config, adapter);
168
169 if (fe) {
170 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
171 dprintk(MANTIS_ERROR, 1, "found STV0299 DVB-S frontend @ 0x%02x",
172 lgtdqcs001f_config.demod_address);
173
174 dprintk(MANTIS_ERROR, 1, "Mantis DVB-S STV0299 frontend attach success");
175 } else {
176 return -1;
177 }
178
179 mantis->fe = fe;
180 dprintk(MANTIS_ERROR, 1, "Done!");
181
182 return 0;
183}
184
185struct mantis_hwconfig vp1033_config = {
186 .model_name = MANTIS_MODEL_NAME,
187 .dev_type = MANTIS_DEV_TYPE,
188 .ts_size = MANTIS_TS_204,
189
190 .baud_rate = MANTIS_BAUD_9600,
191 .parity = MANTIS_PARITY_NONE,
192 .bytes = 0,
193
194 .frontend_init = vp1033_frontend_init,
195};
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.h b/drivers/media/dvb/mantis/mantis_vp1033.h
index e24570659d55..2c18d2153242 100644
--- a/drivers/media/dvb/mantis/mantis_vp1033.h
+++ b/drivers/media/dvb/mantis/mantis_vp1033.h
@@ -21,19 +21,10 @@
21#ifndef __MANTIS_VP1033_H 21#ifndef __MANTIS_VP1033_H
22#define __MANTIS_VP1033_H 22#define __MANTIS_VP1033_H
23 23
24#include "dvb_frontend.h"
25#include "mantis_common.h" 24#include "mantis_common.h"
26#include "stv0299.h"
27 25
28#define MANTIS_VP_1033_DVB_S 0x0016 26#define MANTIS_VP_1033_DVB_S 0x0016
29 27
30extern struct stv0299_config lgtdqcs001f_config; 28extern struct mantis_hwconfig vp1033_config;
31extern struct mantis_hwconfig vp1033_mantis_config;
32 29
33extern int lgtdqcs001f_tuner_set(struct dvb_frontend *fe, 30#endif /* __MANTIS_VP1033_H */
34 struct dvb_frontend_parameters *params);
35
36extern int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio);
37
38
39#endif // __MANTIS_VP1033_H
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.c b/drivers/media/dvb/mantis/mantis_vp1034.c
index 28f3420b2312..40778ec8f460 100644
--- a/drivers/media/dvb/mantis/mantis_vp1034.c
+++ b/drivers/media/dvb/mantis/mantis_vp1034.c
@@ -18,10 +18,24 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "mb86a16.h"
21#include "mantis_common.h" 33#include "mantis_common.h"
34#include "mantis_ioc.h"
22#include "mantis_vp1034.h" 35#include "mantis_vp1034.h"
36#include "mantis_reg.h"
23 37
24struct mb86a16_config vp1034_config = { 38struct mb86a16_config vp1034_mb86a16_config = {
25 .demod_address = 0x08, 39 .demod_address = 0x08,
26 .set_voltage = vp1034_set_voltage, 40 .set_voltage = vp1034_set_voltage,
27}; 41};
@@ -29,38 +43,62 @@ struct mb86a16_config vp1034_config = {
29#define MANTIS_MODEL_NAME "VP-1034" 43#define MANTIS_MODEL_NAME "VP-1034"
30#define MANTIS_DEV_TYPE "DVB-S/DSS" 44#define MANTIS_DEV_TYPE "DVB-S/DSS"
31 45
32struct mantis_hwconfig vp1034_mantis_config = {
33 .model_name = MANTIS_MODEL_NAME,
34 .dev_type = MANTIS_DEV_TYPE,
35 .ts_size = MANTIS_TS_204,
36 .baud_rate = MANTIS_BAUD_9600,
37 .parity = MANTIS_PARITY_NONE,
38 .bytes = 0,
39};
40
41int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 46int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
42{ 47{
43 struct mantis_pci *mantis = fe->dvb->priv; 48 struct mantis_pci *mantis = fe->dvb->priv;
44 49
45 switch (voltage) { 50 switch (voltage) {
46 case SEC_VOLTAGE_13: 51 case SEC_VOLTAGE_13:
47 dprintk(verbose, MANTIS_ERROR, 1, "Polarization=[13V]"); 52 dprintk(MANTIS_ERROR, 1, "Polarization=[13V]");
48 gpio_set_bits(mantis, 13, 1); 53 gpio_set_bits(mantis, 13, 1);
49 gpio_set_bits(mantis, 14, 0); 54 gpio_set_bits(mantis, 14, 0);
50 break; 55 break;
51 case SEC_VOLTAGE_18: 56 case SEC_VOLTAGE_18:
52 dprintk(verbose, MANTIS_ERROR, 1, "Polarization=[18V]"); 57 dprintk(MANTIS_ERROR, 1, "Polarization=[18V]");
53 gpio_set_bits(mantis, 13, 1); 58 gpio_set_bits(mantis, 13, 1);
54 gpio_set_bits(mantis, 14, 1); 59 gpio_set_bits(mantis, 14, 1);
55 break; 60 break;
56 case SEC_VOLTAGE_OFF: 61 case SEC_VOLTAGE_OFF:
57 dprintk(verbose, MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN"); 62 dprintk(MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN");
58 break; 63 break;
59 default: 64 default:
60 dprintk(verbose, MANTIS_ERROR, 1, "Invalid = (%d)", (u32 ) voltage); 65 dprintk(MANTIS_ERROR, 1, "Invalid = (%d)", (u32 ) voltage);
61 return -EINVAL; 66 return -EINVAL;
62 } 67 }
63 mmwrite(0x00, MANTIS_GPIF_DOUT); 68 mmwrite(0x00, MANTIS_GPIF_DOUT);
64 69
65 return 0; 70 return 0;
66} 71}
72
73static int vp1034_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
74{
75 struct i2c_adapter *adapter = &mantis->adapter;
76
77 dprintk(MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
78 fe = mb86a16_attach(&vp1034_mb86a16_config, adapter);
79 if (fe) {
80 dprintk(MANTIS_ERROR, 1,
81 "found MB86A16 DVB-S/DSS frontend @0x%02x",
82 vp1034_mb86a16_config.demod_address);
83
84 } else {
85 return -1;
86 }
87
88 mantis->fe = fe;
89 dprintk(MANTIS_ERROR, 1, "Done!");
90
91 return 0;
92}
93
94struct mantis_hwconfig vp1034_config = {
95 .model_name = MANTIS_MODEL_NAME,
96 .dev_type = MANTIS_DEV_TYPE,
97 .ts_size = MANTIS_TS_204,
98
99 .baud_rate = MANTIS_BAUD_9600,
100 .parity = MANTIS_PARITY_NONE,
101 .bytes = 0,
102
103 .frontend_init = vp1034_frontend_init,
104};
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.h b/drivers/media/dvb/mantis/mantis_vp1034.h
index 21948573b087..30269129066a 100644
--- a/drivers/media/dvb/mantis/mantis_vp1034.h
+++ b/drivers/media/dvb/mantis/mantis_vp1034.h
@@ -23,13 +23,11 @@
23 23
24#include "dvb_frontend.h" 24#include "dvb_frontend.h"
25#include "mantis_common.h" 25#include "mantis_common.h"
26#include "mb86a16.h"
27 26
28 27
29#define MANTIS_VP_1034_DVB_S 0x0014 28#define MANTIS_VP_1034_DVB_S 0x0014
30 29
31extern struct mantis_hwconfig vp1034_mantis_config; 30extern struct mantis_hwconfig vp1034_config;
32extern struct mb86a16_config vp1034_config;
33extern int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 31extern int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
34 32
35#endif // __MANTIS_VP1034_H 33#endif /* __MANTIS_VP1034_H */
diff --git a/drivers/media/dvb/mantis/mantis_vp1041.c b/drivers/media/dvb/mantis/mantis_vp1041.c
index 90df80b80e11..1181fad3b27b 100644
--- a/drivers/media/dvb/mantis/mantis_vp1041.c
+++ b/drivers/media/dvb/mantis/mantis_vp1041.c
@@ -18,24 +18,31 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
21#include "mantis_common.h" 32#include "mantis_common.h"
33#include "mantis_ioc.h"
34#include "mantis_dvb.h"
22#include "mantis_vp1041.h" 35#include "mantis_vp1041.h"
23#include "stb0899_reg.h" 36#include "stb0899_reg.h"
37#include "stb0899_drv.h"
24#include "stb0899_cfg.h" 38#include "stb0899_cfg.h"
25#include "stb6100_cfg.h" 39#include "stb6100_cfg.h"
40#include "stb6100.h"
41#include "lnbp21.h"
26 42
27#define MANTIS_MODEL_NAME "VP-1041" 43#define MANTIS_MODEL_NAME "VP-1041"
28#define MANTIS_DEV_TYPE "DSS/DVB-S/DVB-S2" 44#define MANTIS_DEV_TYPE "DSS/DVB-S/DVB-S2"
29 45
30struct mantis_hwconfig vp1041_mantis_config = {
31 .model_name = MANTIS_MODEL_NAME,
32 .dev_type = MANTIS_DEV_TYPE,
33 .ts_size = MANTIS_TS_188,
34 .baud_rate = MANTIS_BAUD_9600,
35 .parity = MANTIS_PARITY_NONE,
36 .bytes = 0,
37};
38
39static const struct stb0899_s1_reg vp1041_stb0899_s1_init_1[] = { 46static const struct stb0899_s1_reg vp1041_stb0899_s1_init_1[] = {
40 47
41// 0x0000000b , /* SYSREG */ 48// 0x0000000b , /* SYSREG */
@@ -258,7 +265,7 @@ static const struct stb0899_s1_reg vp1041_stb0899_s1_init_3[] = {
258 { 0xffff , 0xff }, 265 { 0xffff , 0xff },
259}; 266};
260 267
261struct stb0899_config vp1041_config = { 268struct stb0899_config vp1041_stb0899_config = {
262 .init_dev = vp1041_stb0899_s1_init_1, 269 .init_dev = vp1041_stb0899_s1_init_1,
263 .init_s2_demod = stb0899_s2_init_2, 270 .init_s2_demod = stb0899_s2_init_2,
264 .init_s1_demod = vp1041_stb0899_s1_init_3, 271 .init_s1_demod = vp1041_stb0899_s1_init_3,
@@ -299,3 +306,55 @@ struct stb6100_config vp1041_stb6100_config = {
299 .tuner_address = 0x60, 306 .tuner_address = 0x60,
300 .refclock = 27000000, 307 .refclock = 27000000,
301}; 308};
309
310static int vp1041_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
311{
312 struct i2c_adapter *adapter = &mantis->adapter;
313
314 int err = 0;
315
316 err = mantis_frontend_power(mantis, POWER_ON);
317 if (err == 0) {
318 mantis_frontend_soft_reset(mantis);
319 msleep(250);
320 mantis->fe = stb0899_attach(&vp1041_stb0899_config, adapter);
321 if (mantis->fe) {
322 dprintk(MANTIS_ERROR, 1,
323 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x",
324 vp1041_stb0899_config.demod_address);
325
326 if (stb6100_attach(mantis->fe, &vp1041_stb6100_config, adapter)) {
327 if (!lnbp21_attach(mantis->fe, adapter, 0, 0)) {
328 printk("%s: No LNBP21 found!\n", __func__);
329 }
330 }
331 } else {
332 return -EREMOTEIO;
333 }
334 } else {
335 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
336 adapter->name,
337 err);
338
339 return -EIO;
340 }
341
342
343 dprintk(MANTIS_ERROR, 1, "Done!");
344
345 return 0;
346}
347
348struct mantis_hwconfig vp1041_config = {
349 .model_name = MANTIS_MODEL_NAME,
350 .dev_type = MANTIS_DEV_TYPE,
351 .ts_size = MANTIS_TS_188,
352
353 .baud_rate = MANTIS_BAUD_9600,
354 .parity = MANTIS_PARITY_NONE,
355 .bytes = 0,
356
357 .frontend_init = vp1041_frontend_init,
358 .power = GPIF_A12,
359 .reset = GPIF_A13,
360};
diff --git a/drivers/media/dvb/mantis/mantis_vp1041.h b/drivers/media/dvb/mantis/mantis_vp1041.h
index 2cc83a6e5996..1ae5b3de8081 100644
--- a/drivers/media/dvb/mantis/mantis_vp1041.h
+++ b/drivers/media/dvb/mantis/mantis_vp1041.h
@@ -21,17 +21,13 @@
21#ifndef __MANTIS_VP1041_H 21#ifndef __MANTIS_VP1041_H
22#define __MANTIS_VP1041_H 22#define __MANTIS_VP1041_H
23 23
24#include "dvb_frontend.h"
25#include "mantis_common.h" 24#include "mantis_common.h"
26#include "stb0899_drv.h"
27#include "stb6100.h"
28#include "lnbp21.h"
29 25
30#define MANTIS_VP_1041_DVB_S2 0x0031 26#define MANTIS_VP_1041_DVB_S2 0x0031
31#define TECHNISAT_SKYSTAR_HD2 0x0001 27#define SKYSTAR_HD2_10 0x0001
28#define SKYSTAR_HD2_20 0x0003
29#define CINERGY_S2_PCI_HD 0x1179
32 30
33extern struct mantis_hwconfig vp1041_mantis_config; 31extern struct mantis_hwconfig vp1041_config;
34extern struct stb0899_config vp1041_config;
35extern struct stb6100_config vp1041_stb6100_config;
36 32
37#endif // __MANTIS_VP1041_H 33#endif /* __MANTIS_VP1041_H */
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.c b/drivers/media/dvb/mantis/mantis_vp2033.c
index 1171e69b7e64..877329175d0f 100644
--- a/drivers/media/dvb/mantis/mantis_vp2033.c
+++ b/drivers/media/dvb/mantis/mantis_vp2033.c
@@ -18,48 +18,59 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "tda1002x.h"
21#include "mantis_common.h" 33#include "mantis_common.h"
22#include "mantis_vp2033.h" 34#include "mantis_vp2033.h"
23 35
24#define MANTIS_MODEL_NAME "VP-2033" 36#define MANTIS_MODEL_NAME "VP-2033"
25#define MANTIS_DEV_TYPE "DVB-C" 37#define MANTIS_DEV_TYPE "DVB-C"
26 38
27struct mantis_hwconfig vp2033_mantis_config = { 39struct tda1002x_config vp2033_tda1002x_cu1216_config = {
28 .model_name = MANTIS_MODEL_NAME, 40 .demod_address = 0x18 >> 1,
29 .dev_type = MANTIS_DEV_TYPE, 41 .invert = 1,
30 .ts_size = MANTIS_TS_204,
31 .baud_rate = MANTIS_BAUD_9600,
32 .parity = MANTIS_PARITY_NONE,
33 .bytes = 0,
34}; 42};
35 43
36struct tda1002x_config philips_cu1216_config = { 44struct tda10023_config vp2033_tda10023_cu1216_config = {
37 .demod_address = 0x18 >> 1, 45 .demod_address = 0x18 >> 1,
38 .invert = 1, 46 .invert = 1,
39}; 47};
40 48
41u8 read_pwm(struct mantis_pci *mantis) 49static u8 read_pwm(struct mantis_pci *mantis)
42{ 50{
51 struct i2c_adapter *adapter = &mantis->adapter;
52
43 u8 b = 0xff; 53 u8 b = 0xff;
44 u8 pwm; 54 u8 pwm;
45 struct i2c_msg msg[] = { 55 struct i2c_msg msg[] = {
46 {.addr = 0x50,.flags = 0,.buf = &b,.len = 1}, 56 {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
47 {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} 57 {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
48 }; 58 };
49 59
50 if ((i2c_transfer(&mantis->adapter, msg, 2) != 2) 60 if ((i2c_transfer(adapter, msg, 2) != 2)
51 || (pwm == 0xff)) 61 || (pwm == 0xff))
52 pwm = 0x48; 62 pwm = 0x48;
53 63
54 return pwm; 64 return pwm;
55} 65}
56 66
57int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 67static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
58{ 68{
59 struct mantis_pci *mantis = fe->dvb->priv; 69 struct mantis_pci *mantis = fe->dvb->priv;
70 struct i2c_adapter *adapter = &mantis->adapter;
60 71
61 u8 buf[6]; 72 u8 buf[6];
62 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; 73 struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof (buf) };
63 int i; 74 int i;
64 75
65#define CU1216_IF 36125000 76#define CU1216_IF 36125000
@@ -78,7 +89,7 @@ int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parame
78 if (fe->ops.i2c_gate_ctrl) 89 if (fe->ops.i2c_gate_ctrl)
79 fe->ops.i2c_gate_ctrl(fe, 1); 90 fe->ops.i2c_gate_ctrl(fe, 1);
80 91
81 if (i2c_transfer(&mantis->adapter, &msg, 1) != 1) 92 if (i2c_transfer(adapter, &msg, 1) != 1)
82 return -EIO; 93 return -EIO;
83 94
84 /* wait for the pll lock */ 95 /* wait for the pll lock */
@@ -88,7 +99,7 @@ int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parame
88 if (fe->ops.i2c_gate_ctrl) 99 if (fe->ops.i2c_gate_ctrl)
89 fe->ops.i2c_gate_ctrl(fe, 1); 100 fe->ops.i2c_gate_ctrl(fe, 1);
90 101
91 if (i2c_transfer(&mantis->adapter, &msg, 1) == 1 && (buf[0] & 0x40)) 102 if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
92 break; 103 break;
93 104
94 msleep(10); 105 msleep(10);
@@ -102,8 +113,58 @@ int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parame
102 if (fe->ops.i2c_gate_ctrl) 113 if (fe->ops.i2c_gate_ctrl)
103 fe->ops.i2c_gate_ctrl(fe, 1); 114 fe->ops.i2c_gate_ctrl(fe, 1);
104 115
105 if (i2c_transfer(&mantis->adapter, &msg, 1) != 1) 116 if (i2c_transfer(adapter, &msg, 1) != 1)
106 return -EIO; 117 return -EIO;
107 118
108 return 0; 119 return 0;
109} 120}
121
122static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
123{
124 struct i2c_adapter *adapter = &mantis->adapter;
125
126 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
127 fe = tda10021_attach(&vp2033_tda1002x_cu1216_config,
128 adapter,
129 read_pwm(mantis));
130
131 if (fe) {
132 dprintk(MANTIS_ERROR, 1,
133 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
134 vp2033_tda1002x_cu1216_config.demod_address);
135 } else {
136 fe = tda10023_attach(&vp2033_tda10023_cu1216_config,
137 adapter,
138 read_pwm(mantis));
139
140 if (fe) {
141 dprintk(MANTIS_ERROR, 1,
142 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
143 vp2033_tda1002x_cu1216_config.demod_address);
144 }
145 }
146
147 if (fe) {
148 fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
149 dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
150 } else {
151 return -1;
152 }
153
154 mantis->fe = fe;
155 dprintk(MANTIS_DEBUG, 1, "Done!");
156
157 return 0;
158}
159
160struct mantis_hwconfig vp2033_config = {
161 .model_name = MANTIS_MODEL_NAME,
162 .dev_type = MANTIS_DEV_TYPE,
163 .ts_size = MANTIS_TS_204,
164
165 .baud_rate = MANTIS_BAUD_9600,
166 .parity = MANTIS_PARITY_NONE,
167 .bytes = 0,
168
169 .frontend_init = vp2033_frontend_init,
170};
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.h b/drivers/media/dvb/mantis/mantis_vp2033.h
index fcf8b85be941..e6c5fe80f726 100644
--- a/drivers/media/dvb/mantis/mantis_vp2033.h
+++ b/drivers/media/dvb/mantis/mantis_vp2033.h
@@ -21,17 +21,10 @@
21#ifndef __MANTIS_VP2033_H 21#ifndef __MANTIS_VP2033_H
22#define __MANTIS_VP2033_H 22#define __MANTIS_VP2033_H
23 23
24#include "dvb_frontend.h"
25#include "mantis_common.h" 24#include "mantis_common.h"
26#include "tda1002x.h"
27 25
28#define MANTIS_VP_2033_DVB_C 0x0008 26#define MANTIS_VP_2033_DVB_C 0x0008
29 27
30extern struct tda1002x_config philips_cu1216_config; 28extern struct mantis_hwconfig vp2033_config;
31extern struct mantis_hwconfig vp2033_mantis_config;
32 29
33extern int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params); 30#endif /* __MANTIS_VP2033_H */
34
35extern u8 read_pwm(struct mantis_pci *mantis);
36
37#endif // __MANTIS_VP2033_H
diff --git a/drivers/media/dvb/mantis/mantis_vp2040.c b/drivers/media/dvb/mantis/mantis_vp2040.c
index ce73d6beb5c6..51b082f7f917 100644
--- a/drivers/media/dvb/mantis/mantis_vp2040.c
+++ b/drivers/media/dvb/mantis/mantis_vp2040.c
@@ -18,22 +18,153 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "tda1002x.h"
21#include "mantis_common.h" 33#include "mantis_common.h"
22#include "mantis_vp2040.h" 34#include "mantis_vp2040.h"
23 35
24#define MANTIS_MODEL_NAME "VP-2040" 36#define MANTIS_MODEL_NAME "VP-2040"
25#define MANTIS_DEV_TYPE "DVB-C" 37#define MANTIS_DEV_TYPE "DVB-C"
26 38
27struct mantis_hwconfig vp2040_mantis_config = { 39struct tda1002x_config vp2040_tda1002x_cu1216_config = {
40 .demod_address = 0x18 >> 1,
41 .invert = 1,
42};
43
44struct tda10023_config vp2040_tda10023_cu1216_config = {
45 .demod_address = 0x18 >> 1,
46 .invert = 1,
47};
48
49static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
50{
51 struct mantis_pci *mantis = fe->dvb->priv;
52 struct i2c_adapter *adapter = &mantis->adapter;
53
54 u8 buf[6];
55 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof (buf) };
56 int i;
57
58#define CU1216_IF 36125000
59#define TUNER_MUL 62500
60
61 u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
62
63 buf[0] = (div >> 8) & 0x7f;
64 buf[1] = div & 0xff;
65 buf[2] = 0xce;
66 buf[3] = (params->frequency < 150000000 ? 0x01 :
67 params->frequency < 445000000 ? 0x02 : 0x04);
68 buf[4] = 0xde;
69 buf[5] = 0x20;
70
71 if (fe->ops.i2c_gate_ctrl)
72 fe->ops.i2c_gate_ctrl(fe, 1);
73
74 if (i2c_transfer(adapter, &msg, 1) != 1)
75 return -EIO;
76
77 /* wait for the pll lock */
78 msg.flags = I2C_M_RD;
79 msg.len = 1;
80 for (i = 0; i < 20; i++) {
81 if (fe->ops.i2c_gate_ctrl)
82 fe->ops.i2c_gate_ctrl(fe, 1);
83
84 if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
85 break;
86
87 msleep(10);
88 }
89
90 /* switch the charge pump to the lower current */
91 msg.flags = 0;
92 msg.len = 2;
93 msg.buf = &buf[2];
94 buf[2] &= ~0x40;
95 if (fe->ops.i2c_gate_ctrl)
96 fe->ops.i2c_gate_ctrl(fe, 1);
97
98 if (i2c_transfer(adapter, &msg, 1) != 1)
99 return -EIO;
100
101 return 0;
102}
103
104static u8 read_pwm(struct mantis_pci *mantis)
105{
106 struct i2c_adapter *adapter = &mantis->adapter;
107
108 u8 b = 0xff;
109 u8 pwm;
110 struct i2c_msg msg[] = {
111 {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
112 {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
113 };
114
115 if ((i2c_transfer(adapter, msg, 2) != 2)
116 || (pwm == 0xff))
117 pwm = 0x48;
118
119 return pwm;
120}
121
122static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
123{
124 struct i2c_adapter *adapter = &mantis->adapter;
125
126 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
127 fe = tda10021_attach(&vp2040_tda1002x_cu1216_config,
128 adapter,
129 read_pwm(mantis));
130
131 if (fe) {
132 dprintk(MANTIS_ERROR, 1,
133 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
134 vp2040_tda1002x_cu1216_config.demod_address);
135 } else {
136 fe = tda10023_attach(&vp2040_tda10023_cu1216_config,
137 adapter,
138 read_pwm(mantis));
139
140 if (fe) {
141 dprintk(MANTIS_ERROR, 1,
142 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
143 vp2040_tda1002x_cu1216_config.demod_address);
144 }
145 }
146
147 if (fe) {
148 fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
149 dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
150 } else {
151 return -1;
152 }
153
154 mantis->fe = fe;
155 dprintk(MANTIS_DEBUG, 1, "Done!");
156
157 return 0;
158}
159
160struct mantis_hwconfig vp2040_config = {
28 .model_name = MANTIS_MODEL_NAME, 161 .model_name = MANTIS_MODEL_NAME,
29 .dev_type = MANTIS_DEV_TYPE, 162 .dev_type = MANTIS_DEV_TYPE,
30 .ts_size = MANTIS_TS_204, 163 .ts_size = MANTIS_TS_204,
164
31 .baud_rate = MANTIS_BAUD_9600, 165 .baud_rate = MANTIS_BAUD_9600,
32 .parity = MANTIS_PARITY_NONE, 166 .parity = MANTIS_PARITY_NONE,
33 .bytes = 0, 167 .bytes = 0,
34};
35 168
36struct tda10023_config tda10023_cu1216_config = { 169 .frontend_init = vp2040_frontend_init,
37 .demod_address = 0x18 >> 1,
38 .invert = 1,
39}; 170};
diff --git a/drivers/media/dvb/mantis/mantis_vp2040.h b/drivers/media/dvb/mantis/mantis_vp2040.h
index c7457543d8b0..d125e219b685 100644
--- a/drivers/media/dvb/mantis/mantis_vp2040.h
+++ b/drivers/media/dvb/mantis/mantis_vp2040.h
@@ -21,15 +21,12 @@
21#ifndef __MANTIS_VP2040_H 21#ifndef __MANTIS_VP2040_H
22#define __MANTIS_VP2040_H 22#define __MANTIS_VP2040_H
23 23
24#include "dvb_frontend.h"
25#include "mantis_common.h" 24#include "mantis_common.h"
26#include "tda1002x.h"
27 25
28#define MANTIS_VP_2040_DVB_C 0x0043 26#define MANTIS_VP_2040_DVB_C 0x0043
29#define TERRATEC_CINERGY_C_PCI 0x1178 27#define CINERGY_C 0x1178
30#define TECHNISAT_CABLESTAR_HD2 0x0002 28#define CABLESTAR_HD2 0x0002
31 29
32extern struct tda10023_config tda10023_cu1216_config; 30extern struct mantis_hwconfig vp2040_config;
33extern struct mantis_hwconfig vp2040_mantis_config;
34 31
35#endif //__MANTIS_VP2040_H 32#endif /* __MANTIS_VP2040_H */
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.c b/drivers/media/dvb/mantis/mantis_vp3030.c
index 9ca8040489dd..4b974eeefa9e 100644
--- a/drivers/media/dvb/mantis/mantis_vp3030.c
+++ b/drivers/media/dvb/mantis/mantis_vp3030.c
@@ -18,6 +18,18 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "zl10353.h"
21#include "mantis_common.h" 33#include "mantis_common.h"
22#include "mantis_vp3030.h" 34#include "mantis_vp3030.h"
23 35
@@ -28,15 +40,6 @@ struct zl10353_config mantis_vp3030_config = {
28#define MANTIS_MODEL_NAME "VP-3030" 40#define MANTIS_MODEL_NAME "VP-3030"
29#define MANTIS_DEV_TYPE "DVB-T" 41#define MANTIS_DEV_TYPE "DVB-T"
30 42
31struct mantis_hwconfig vp3030_mantis_config = {
32 .model_name = MANTIS_MODEL_NAME,
33 .dev_type = MANTIS_DEV_TYPE,
34 .ts_size = MANTIS_TS_188,
35 .baud_rate = MANTIS_BAUD_9600,
36 .parity = MANTIS_PARITY_NONE,
37 .bytes = 0,
38};
39
40int panasonic_en57h12d5_set_params(struct dvb_frontend *fe, 43int panasonic_en57h12d5_set_params(struct dvb_frontend *fe,
41 struct dvb_frontend_parameters *params) 44 struct dvb_frontend_parameters *params)
42{ 45{
@@ -63,3 +66,31 @@ int panasonic_en57h12d5_set_params(struct dvb_frontend *fe,
63 66
64 return 0; 67 return 0;
65} 68}
69
70static int vp3030_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
71{
72 struct i2c_adapter *adapter = &mantis->adapter;
73
74 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
75 fe = zl10353_attach(&mantis_vp3030_config, adapter);
76
77 if (!fe)
78 return -1;
79
80 mantis->fe = fe;
81 dprintk(MANTIS_ERROR, 1, "Done!");
82
83 return 0;
84}
85
86struct mantis_hwconfig vp3030_config = {
87 .model_name = MANTIS_MODEL_NAME,
88 .dev_type = MANTIS_DEV_TYPE,
89 .ts_size = MANTIS_TS_188,
90
91 .baud_rate = MANTIS_BAUD_9600,
92 .parity = MANTIS_PARITY_NONE,
93 .bytes = 0,
94
95 .frontend_init = vp3030_frontend_init,
96};
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.h b/drivers/media/dvb/mantis/mantis_vp3030.h
index acc50a48e18f..0a110ba5c1db 100644
--- a/drivers/media/dvb/mantis/mantis_vp3030.h
+++ b/drivers/media/dvb/mantis/mantis_vp3030.h
@@ -21,14 +21,10 @@
21#ifndef __MANTIS_VP3030_H 21#ifndef __MANTIS_VP3030_H
22#define __MANTIS_VP3030_H 22#define __MANTIS_VP3030_H
23 23
24#include "dvb_frontend.h"
25#include "mantis_common.h" 24#include "mantis_common.h"
26#include "dvb-pll.h"
27#include "zl10353.h"
28 25
29#define MANTIS_VP_3030_DVB_T 0x0024 26#define MANTIS_VP_3030_DVB_T 0x0024
30 27
31extern struct zl10353_config mantis_vp3030_config; 28extern struct mantis_hwconfig vp3030_config;
32extern struct mantis_hwconfig vp3030_mantis_config;
33 29
34#endif // __MANTIS_VP3030_H 30#endif /* __MANTIS_VP3030_H */