diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/dvb/bt8xx |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/media/dvb/bt8xx')
-rw-r--r-- | drivers/media/dvb/bt8xx/Kconfig | 19 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/Makefile | 5 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/bt878.c | 588 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/bt878.h | 147 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/dst.c | 1089 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/dst.h | 40 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/dst_priv.h | 36 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/dvb-bt8xx.c | 797 | ||||
-rw-r--r-- | drivers/media/dvb/bt8xx/dvb-bt8xx.h | 59 |
9 files changed, 2780 insertions, 0 deletions
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig new file mode 100644 index 000000000000..e7d11e0667a8 --- /dev/null +++ b/drivers/media/dvb/bt8xx/Kconfig | |||
@@ -0,0 +1,19 @@ | |||
1 | config DVB_BT8XX | ||
2 | tristate "Nebula/Pinnacle PCTV/Twinhan PCI cards" | ||
3 | depends on DVB_CORE && PCI && VIDEO_BT848 | ||
4 | select DVB_MT352 | ||
5 | select DVB_SP887X | ||
6 | select DVB_NXT6000 | ||
7 | select DVB_CX24110 | ||
8 | select DVB_OR51211 | ||
9 | help | ||
10 | Support for PCI cards based on the Bt8xx PCI bridge. Examples are | ||
11 | the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards and | ||
12 | pcHDTV HD2000 cards. | ||
13 | |||
14 | Since these cards have no MPEG decoder onboard, they transmit | ||
15 | only compressed MPEG data over the PCI bus, so you need | ||
16 | an external software decoder to watch TV on your computer. | ||
17 | |||
18 | Say Y if you own such a device and want to use it. | ||
19 | |||
diff --git a/drivers/media/dvb/bt8xx/Makefile b/drivers/media/dvb/bt8xx/Makefile new file mode 100644 index 000000000000..9da8604b9e18 --- /dev/null +++ b/drivers/media/dvb/bt8xx/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | |||
2 | obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o | ||
3 | |||
4 | EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video -Idrivers/media/dvb/frontends | ||
5 | |||
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c new file mode 100644 index 000000000000..213ff7902024 --- /dev/null +++ b/drivers/media/dvb/bt8xx/bt878.c | |||
@@ -0,0 +1,588 @@ | |||
1 | /* | ||
2 | * bt878.c: part of the driver for the Pinnacle PCTV Sat DVB PCI card | ||
3 | * | ||
4 | * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> | ||
5 | * | ||
6 | * large parts based on the bttv driver | ||
7 | * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de) | ||
8 | * & Marcus Metzler (mocm@thp.uni-koeln.de) | ||
9 | * (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | |||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | |||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
26 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include <linux/module.h> | ||
31 | #include <linux/moduleparam.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <asm/io.h> | ||
35 | #include <linux/ioport.h> | ||
36 | #include <asm/pgtable.h> | ||
37 | #include <asm/page.h> | ||
38 | #include <linux/types.h> | ||
39 | #include <linux/interrupt.h> | ||
40 | #include <linux/kmod.h> | ||
41 | #include <linux/vmalloc.h> | ||
42 | #include <linux/init.h> | ||
43 | |||
44 | #include "dmxdev.h" | ||
45 | #include "dvbdev.h" | ||
46 | #include "bt878.h" | ||
47 | #include "dst_priv.h" | ||
48 | |||
49 | |||
50 | /**************************************/ | ||
51 | /* Miscellaneous utility definitions */ | ||
52 | /**************************************/ | ||
53 | |||
54 | static unsigned int bt878_verbose = 1; | ||
55 | static unsigned int bt878_debug; | ||
56 | |||
57 | module_param_named(verbose, bt878_verbose, int, 0444); | ||
58 | MODULE_PARM_DESC(verbose, | ||
59 | "verbose startup messages, default is 1 (yes)"); | ||
60 | module_param_named(debug, bt878_debug, int, 0644); | ||
61 | MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); | ||
62 | |||
63 | int bt878_num; | ||
64 | struct bt878 bt878[BT878_MAX]; | ||
65 | |||
66 | EXPORT_SYMBOL(bt878_debug); | ||
67 | EXPORT_SYMBOL(bt878_verbose); | ||
68 | EXPORT_SYMBOL(bt878_num); | ||
69 | EXPORT_SYMBOL(bt878); | ||
70 | |||
71 | #define btwrite(dat,adr) bmtwrite((dat), (bt->bt878_mem+(adr))) | ||
72 | #define btread(adr) bmtread(bt->bt878_mem+(adr)) | ||
73 | |||
74 | #define btand(dat,adr) btwrite((dat) & btread(adr), adr) | ||
75 | #define btor(dat,adr) btwrite((dat) | btread(adr), adr) | ||
76 | #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr) | ||
77 | |||
78 | #if defined(dprintk) | ||
79 | #undef dprintk | ||
80 | #endif | ||
81 | #define dprintk if(bt878_debug) printk | ||
82 | |||
83 | static void bt878_mem_free(struct bt878 *bt) | ||
84 | { | ||
85 | if (bt->buf_cpu) { | ||
86 | pci_free_consistent(bt->dev, bt->buf_size, bt->buf_cpu, | ||
87 | bt->buf_dma); | ||
88 | bt->buf_cpu = NULL; | ||
89 | } | ||
90 | |||
91 | if (bt->risc_cpu) { | ||
92 | pci_free_consistent(bt->dev, bt->risc_size, bt->risc_cpu, | ||
93 | bt->risc_dma); | ||
94 | bt->risc_cpu = NULL; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | static int bt878_mem_alloc(struct bt878 *bt) | ||
99 | { | ||
100 | if (!bt->buf_cpu) { | ||
101 | bt->buf_size = 128 * 1024; | ||
102 | |||
103 | bt->buf_cpu = | ||
104 | pci_alloc_consistent(bt->dev, bt->buf_size, | ||
105 | &bt->buf_dma); | ||
106 | |||
107 | if (!bt->buf_cpu) | ||
108 | return -ENOMEM; | ||
109 | |||
110 | memset(bt->buf_cpu, 0, bt->buf_size); | ||
111 | } | ||
112 | |||
113 | if (!bt->risc_cpu) { | ||
114 | bt->risc_size = PAGE_SIZE; | ||
115 | bt->risc_cpu = | ||
116 | pci_alloc_consistent(bt->dev, bt->risc_size, | ||
117 | &bt->risc_dma); | ||
118 | |||
119 | if (!bt->risc_cpu) { | ||
120 | bt878_mem_free(bt); | ||
121 | return -ENOMEM; | ||
122 | } | ||
123 | |||
124 | memset(bt->risc_cpu, 0, bt->risc_size); | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | /* RISC instructions */ | ||
131 | #define RISC_WRITE (0x01 << 28) | ||
132 | #define RISC_JUMP (0x07 << 28) | ||
133 | #define RISC_SYNC (0x08 << 28) | ||
134 | |||
135 | /* RISC bits */ | ||
136 | #define RISC_WR_SOL (1 << 27) | ||
137 | #define RISC_WR_EOL (1 << 26) | ||
138 | #define RISC_IRQ (1 << 24) | ||
139 | #define RISC_STATUS(status) ((((~status) & 0x0F) << 20) | ((status & 0x0F) << 16)) | ||
140 | #define RISC_SYNC_RESYNC (1 << 15) | ||
141 | #define RISC_SYNC_FM1 0x06 | ||
142 | #define RISC_SYNC_VRO 0x0C | ||
143 | |||
144 | #define RISC_FLUSH() bt->risc_pos = 0 | ||
145 | #define RISC_INSTR(instr) bt->risc_cpu[bt->risc_pos++] = cpu_to_le32(instr) | ||
146 | |||
147 | static int bt878_make_risc(struct bt878 *bt) | ||
148 | { | ||
149 | bt->block_bytes = bt->buf_size >> 4; | ||
150 | bt->block_count = 1 << 4; | ||
151 | bt->line_bytes = bt->block_bytes; | ||
152 | bt->line_count = bt->block_count; | ||
153 | |||
154 | while (bt->line_bytes > 4095) { | ||
155 | bt->line_bytes >>= 1; | ||
156 | bt->line_count <<= 1; | ||
157 | } | ||
158 | |||
159 | if (bt->line_count > 255) { | ||
160 | printk("bt878: buffer size error!\n"); | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | |||
167 | static void bt878_risc_program(struct bt878 *bt, u32 op_sync_orin) | ||
168 | { | ||
169 | u32 buf_pos = 0; | ||
170 | u32 line; | ||
171 | |||
172 | RISC_FLUSH(); | ||
173 | RISC_INSTR(RISC_SYNC | RISC_SYNC_FM1 | op_sync_orin); | ||
174 | RISC_INSTR(0); | ||
175 | |||
176 | dprintk("bt878: risc len lines %u, bytes per line %u\n", | ||
177 | bt->line_count, bt->line_bytes); | ||
178 | for (line = 0; line < bt->line_count; line++) { | ||
179 | // At the beginning of every block we issue an IRQ with previous (finished) block number set | ||
180 | if (!(buf_pos % bt->block_bytes)) | ||
181 | RISC_INSTR(RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL | | ||
182 | RISC_IRQ | | ||
183 | RISC_STATUS(((buf_pos / | ||
184 | bt->block_bytes) + | ||
185 | (bt->block_count - | ||
186 | 1)) % | ||
187 | bt->block_count) | bt-> | ||
188 | line_bytes); | ||
189 | else | ||
190 | RISC_INSTR(RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL | | ||
191 | bt->line_bytes); | ||
192 | RISC_INSTR(bt->buf_dma + buf_pos); | ||
193 | buf_pos += bt->line_bytes; | ||
194 | } | ||
195 | |||
196 | RISC_INSTR(RISC_SYNC | op_sync_orin | RISC_SYNC_VRO); | ||
197 | RISC_INSTR(0); | ||
198 | |||
199 | RISC_INSTR(RISC_JUMP); | ||
200 | RISC_INSTR(bt->risc_dma); | ||
201 | |||
202 | btwrite((bt->line_count << 16) | bt->line_bytes, BT878_APACK_LEN); | ||
203 | } | ||
204 | |||
205 | /*****************************/ | ||
206 | /* Start/Stop grabbing funcs */ | ||
207 | /*****************************/ | ||
208 | |||
209 | void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin, | ||
210 | u32 irq_err_ignore) | ||
211 | { | ||
212 | u32 int_mask; | ||
213 | |||
214 | dprintk("bt878 debug: bt878_start (ctl=%8.8x)\n", controlreg); | ||
215 | /* complete the writing of the risc dma program now we have | ||
216 | * the card specifics | ||
217 | */ | ||
218 | bt878_risc_program(bt, op_sync_orin); | ||
219 | controlreg &= ~0x1f; | ||
220 | controlreg |= 0x1b; | ||
221 | |||
222 | btwrite(cpu_to_le32(bt->risc_dma), BT878_ARISC_START); | ||
223 | |||
224 | /* original int mask had : | ||
225 | * 6 2 8 4 0 | ||
226 | * 1111 1111 1000 0000 0000 | ||
227 | * SCERR|OCERR|PABORT|RIPERR|FDSR|FTRGT|FBUS|RISCI | ||
228 | * Hacked for DST to: | ||
229 | * SCERR | OCERR | FDSR | FTRGT | FBUS | RISCI | ||
230 | */ | ||
231 | int_mask = BT878_ASCERR | BT878_AOCERR | BT878_APABORT | | ||
232 | BT878_ARIPERR | BT878_APPERR | BT878_AFDSR | BT878_AFTRGT | | ||
233 | BT878_AFBUS | BT878_ARISCI; | ||
234 | |||
235 | |||
236 | /* ignore pesky bits */ | ||
237 | int_mask &= ~irq_err_ignore; | ||
238 | |||
239 | btwrite(int_mask, BT878_AINT_MASK); | ||
240 | btwrite(controlreg, BT878_AGPIO_DMA_CTL); | ||
241 | } | ||
242 | |||
243 | void bt878_stop(struct bt878 *bt) | ||
244 | { | ||
245 | u32 stat; | ||
246 | int i = 0; | ||
247 | |||
248 | dprintk("bt878 debug: bt878_stop\n"); | ||
249 | |||
250 | btwrite(0, BT878_AINT_MASK); | ||
251 | btand(~0x13, BT878_AGPIO_DMA_CTL); | ||
252 | |||
253 | do { | ||
254 | stat = btread(BT878_AINT_STAT); | ||
255 | if (!(stat & BT878_ARISC_EN)) | ||
256 | break; | ||
257 | i++; | ||
258 | } while (i < 500); | ||
259 | |||
260 | dprintk("bt878(%d) debug: bt878_stop, i=%d, stat=0x%8.8x\n", | ||
261 | bt->nr, i, stat); | ||
262 | } | ||
263 | |||
264 | EXPORT_SYMBOL(bt878_start); | ||
265 | EXPORT_SYMBOL(bt878_stop); | ||
266 | |||
267 | /*****************************/ | ||
268 | /* Interrupt service routine */ | ||
269 | /*****************************/ | ||
270 | |||
271 | static irqreturn_t bt878_irq(int irq, void *dev_id, struct pt_regs *regs) | ||
272 | { | ||
273 | u32 stat, astat, mask; | ||
274 | int count; | ||
275 | struct bt878 *bt; | ||
276 | |||
277 | bt = (struct bt878 *) dev_id; | ||
278 | |||
279 | count = 0; | ||
280 | while (1) { | ||
281 | stat = btread(BT878_AINT_STAT); | ||
282 | mask = btread(BT878_AINT_MASK); | ||
283 | if (!(astat = (stat & mask))) | ||
284 | return IRQ_NONE; /* this interrupt is not for me */ | ||
285 | /* dprintk("bt878(%d) debug: irq count %d, stat 0x%8.8x, mask 0x%8.8x\n",bt->nr,count,stat,mask); */ | ||
286 | btwrite(astat, BT878_AINT_STAT); /* try to clear interupt condition */ | ||
287 | |||
288 | |||
289 | if (astat & (BT878_ASCERR | BT878_AOCERR)) { | ||
290 | if (bt878_verbose) { | ||
291 | printk("bt878(%d): irq%s%s risc_pc=%08x\n", | ||
292 | bt->nr, | ||
293 | (astat & BT878_ASCERR) ? " SCERR" : | ||
294 | "", | ||
295 | (astat & BT878_AOCERR) ? " OCERR" : | ||
296 | "", btread(BT878_ARISC_PC)); | ||
297 | } | ||
298 | } | ||
299 | if (astat & (BT878_APABORT | BT878_ARIPERR | BT878_APPERR)) { | ||
300 | if (bt878_verbose) { | ||
301 | printk | ||
302 | ("bt878(%d): irq%s%s%s risc_pc=%08x\n", | ||
303 | bt->nr, | ||
304 | (astat & BT878_APABORT) ? " PABORT" : | ||
305 | "", | ||
306 | (astat & BT878_ARIPERR) ? " RIPERR" : | ||
307 | "", | ||
308 | (astat & BT878_APPERR) ? " PPERR" : | ||
309 | "", btread(BT878_ARISC_PC)); | ||
310 | } | ||
311 | } | ||
312 | if (astat & (BT878_AFDSR | BT878_AFTRGT | BT878_AFBUS)) { | ||
313 | if (bt878_verbose) { | ||
314 | printk | ||
315 | ("bt878(%d): irq%s%s%s risc_pc=%08x\n", | ||
316 | bt->nr, | ||
317 | (astat & BT878_AFDSR) ? " FDSR" : "", | ||
318 | (astat & BT878_AFTRGT) ? " FTRGT" : | ||
319 | "", | ||
320 | (astat & BT878_AFBUS) ? " FBUS" : "", | ||
321 | btread(BT878_ARISC_PC)); | ||
322 | } | ||
323 | } | ||
324 | if (astat & BT878_ARISCI) { | ||
325 | bt->finished_block = (stat & BT878_ARISCS) >> 28; | ||
326 | tasklet_schedule(&bt->tasklet); | ||
327 | break; | ||
328 | } | ||
329 | count++; | ||
330 | if (count > 20) { | ||
331 | btwrite(0, BT878_AINT_MASK); | ||
332 | printk(KERN_ERR | ||
333 | "bt878(%d): IRQ lockup, cleared int mask\n", | ||
334 | bt->nr); | ||
335 | break; | ||
336 | } | ||
337 | } | ||
338 | return IRQ_HANDLED; | ||
339 | } | ||
340 | |||
341 | int | ||
342 | bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp) | ||
343 | { | ||
344 | int retval; | ||
345 | |||
346 | retval = 0; | ||
347 | if (down_interruptible (&bt->gpio_lock)) | ||
348 | return -ERESTARTSYS; | ||
349 | /* special gpio signal */ | ||
350 | switch (cmd) { | ||
351 | case DST_IG_ENABLE: | ||
352 | // dprintk("dvb_bt8xx: dst enable mask 0x%02x enb 0x%02x \n", mp->dstg.enb.mask, mp->dstg.enb.enable); | ||
353 | retval = bttv_gpio_enable(bt->bttv_nr, | ||
354 | mp->enb.mask, | ||
355 | mp->enb.enable); | ||
356 | break; | ||
357 | case DST_IG_WRITE: | ||
358 | // dprintk("dvb_bt8xx: dst write gpio mask 0x%02x out 0x%02x\n", mp->dstg.outp.mask, mp->dstg.outp.highvals); | ||
359 | retval = bttv_write_gpio(bt->bttv_nr, | ||
360 | mp->outp.mask, | ||
361 | mp->outp.highvals); | ||
362 | |||
363 | break; | ||
364 | case DST_IG_READ: | ||
365 | /* read */ | ||
366 | retval = bttv_read_gpio(bt->bttv_nr, &mp->rd.value); | ||
367 | // dprintk("dvb_bt8xx: dst read gpio 0x%02x\n", (unsigned)mp->dstg.rd.value); | ||
368 | break; | ||
369 | case DST_IG_TS: | ||
370 | /* Set packet size */ | ||
371 | bt->TS_Size = mp->psize; | ||
372 | break; | ||
373 | |||
374 | default: | ||
375 | retval = -EINVAL; | ||
376 | break; | ||
377 | } | ||
378 | up(&bt->gpio_lock); | ||
379 | return retval; | ||
380 | } | ||
381 | |||
382 | EXPORT_SYMBOL(bt878_device_control); | ||
383 | |||
384 | /***********************/ | ||
385 | /* PCI device handling */ | ||
386 | /***********************/ | ||
387 | |||
388 | static int __devinit bt878_probe(struct pci_dev *dev, | ||
389 | const struct pci_device_id *pci_id) | ||
390 | { | ||
391 | int result; | ||
392 | unsigned char lat; | ||
393 | struct bt878 *bt; | ||
394 | #if defined(__powerpc__) | ||
395 | unsigned int cmd; | ||
396 | #endif | ||
397 | |||
398 | printk(KERN_INFO "bt878: Bt878 AUDIO function found (%d).\n", | ||
399 | bt878_num); | ||
400 | if (pci_enable_device(dev)) | ||
401 | return -EIO; | ||
402 | |||
403 | bt = &bt878[bt878_num]; | ||
404 | bt->dev = dev; | ||
405 | bt->nr = bt878_num; | ||
406 | bt->shutdown = 0; | ||
407 | |||
408 | bt->id = dev->device; | ||
409 | bt->irq = dev->irq; | ||
410 | bt->bt878_adr = pci_resource_start(dev, 0); | ||
411 | if (!request_mem_region(pci_resource_start(dev, 0), | ||
412 | pci_resource_len(dev, 0), "bt878")) { | ||
413 | result = -EBUSY; | ||
414 | goto fail0; | ||
415 | } | ||
416 | |||
417 | pci_read_config_byte(dev, PCI_CLASS_REVISION, &bt->revision); | ||
418 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); | ||
419 | printk(KERN_INFO "bt878(%d): Bt%x (rev %d) at %02x:%02x.%x, ", | ||
420 | bt878_num, bt->id, bt->revision, dev->bus->number, | ||
421 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); | ||
422 | printk("irq: %d, latency: %d, memory: 0x%lx\n", | ||
423 | bt->irq, lat, bt->bt878_adr); | ||
424 | |||
425 | |||
426 | #if defined(__powerpc__) | ||
427 | /* on OpenFirmware machines (PowerMac at least), PCI memory cycle */ | ||
428 | /* response on cards with no firmware is not enabled by OF */ | ||
429 | pci_read_config_dword(dev, PCI_COMMAND, &cmd); | ||
430 | cmd = (cmd | PCI_COMMAND_MEMORY); | ||
431 | pci_write_config_dword(dev, PCI_COMMAND, cmd); | ||
432 | #endif | ||
433 | |||
434 | #ifdef __sparc__ | ||
435 | bt->bt878_mem = (unsigned char *) bt->bt878_adr; | ||
436 | #else | ||
437 | bt->bt878_mem = ioremap(bt->bt878_adr, 0x1000); | ||
438 | #endif | ||
439 | |||
440 | /* clear interrupt mask */ | ||
441 | btwrite(0, BT848_INT_MASK); | ||
442 | |||
443 | result = request_irq(bt->irq, bt878_irq, | ||
444 | SA_SHIRQ | SA_INTERRUPT, "bt878", | ||
445 | (void *) bt); | ||
446 | if (result == -EINVAL) { | ||
447 | printk(KERN_ERR "bt878(%d): Bad irq number or handler\n", | ||
448 | bt878_num); | ||
449 | goto fail1; | ||
450 | } | ||
451 | if (result == -EBUSY) { | ||
452 | printk(KERN_ERR | ||
453 | "bt878(%d): IRQ %d busy, change your PnP config in BIOS\n", | ||
454 | bt878_num, bt->irq); | ||
455 | goto fail1; | ||
456 | } | ||
457 | if (result < 0) | ||
458 | goto fail1; | ||
459 | |||
460 | pci_set_master(dev); | ||
461 | pci_set_drvdata(dev, bt); | ||
462 | |||
463 | /* if(init_bt878(btv) < 0) { | ||
464 | bt878_remove(dev); | ||
465 | return -EIO; | ||
466 | } | ||
467 | */ | ||
468 | |||
469 | if ((result = bt878_mem_alloc(bt))) { | ||
470 | printk("bt878: failed to allocate memory!\n"); | ||
471 | goto fail2; | ||
472 | } | ||
473 | |||
474 | bt878_make_risc(bt); | ||
475 | btwrite(0, BT878_AINT_MASK); | ||
476 | bt878_num++; | ||
477 | |||
478 | return 0; | ||
479 | |||
480 | fail2: | ||
481 | free_irq(bt->irq, bt); | ||
482 | fail1: | ||
483 | release_mem_region(pci_resource_start(bt->dev, 0), | ||
484 | pci_resource_len(bt->dev, 0)); | ||
485 | fail0: | ||
486 | pci_disable_device(dev); | ||
487 | return result; | ||
488 | } | ||
489 | |||
490 | static void __devexit bt878_remove(struct pci_dev *pci_dev) | ||
491 | { | ||
492 | u8 command; | ||
493 | struct bt878 *bt = pci_get_drvdata(pci_dev); | ||
494 | |||
495 | if (bt878_verbose) | ||
496 | printk("bt878(%d): unloading\n", bt->nr); | ||
497 | |||
498 | /* turn off all capturing, DMA and IRQs */ | ||
499 | btand(~0x13, BT878_AGPIO_DMA_CTL); | ||
500 | |||
501 | /* first disable interrupts before unmapping the memory! */ | ||
502 | btwrite(0, BT878_AINT_MASK); | ||
503 | btwrite(~0U, BT878_AINT_STAT); | ||
504 | |||
505 | /* disable PCI bus-mastering */ | ||
506 | pci_read_config_byte(bt->dev, PCI_COMMAND, &command); | ||
507 | /* Should this be &=~ ?? */ | ||
508 | command &= ~PCI_COMMAND_MASTER; | ||
509 | pci_write_config_byte(bt->dev, PCI_COMMAND, command); | ||
510 | |||
511 | free_irq(bt->irq, bt); | ||
512 | printk(KERN_DEBUG "bt878_mem: 0x%p.\n", bt->bt878_mem); | ||
513 | if (bt->bt878_mem) | ||
514 | iounmap(bt->bt878_mem); | ||
515 | |||
516 | release_mem_region(pci_resource_start(bt->dev, 0), | ||
517 | pci_resource_len(bt->dev, 0)); | ||
518 | /* wake up any waiting processes | ||
519 | because shutdown flag is set, no new processes (in this queue) | ||
520 | are expected | ||
521 | */ | ||
522 | bt->shutdown = 1; | ||
523 | bt878_mem_free(bt); | ||
524 | |||
525 | pci_set_drvdata(pci_dev, NULL); | ||
526 | pci_disable_device(pci_dev); | ||
527 | return; | ||
528 | } | ||
529 | |||
530 | static struct pci_device_id bt878_pci_tbl[] __devinitdata = { | ||
531 | {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BROOKTREE_878, | ||
532 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
533 | {0,} | ||
534 | }; | ||
535 | |||
536 | MODULE_DEVICE_TABLE(pci, bt878_pci_tbl); | ||
537 | |||
538 | static struct pci_driver bt878_pci_driver = { | ||
539 | .name = "bt878", | ||
540 | .id_table = bt878_pci_tbl, | ||
541 | .probe = bt878_probe, | ||
542 | .remove = bt878_remove, | ||
543 | }; | ||
544 | |||
545 | static int bt878_pci_driver_registered = 0; | ||
546 | |||
547 | /*******************************/ | ||
548 | /* Module management functions */ | ||
549 | /*******************************/ | ||
550 | |||
551 | static int bt878_init_module(void) | ||
552 | { | ||
553 | bt878_num = 0; | ||
554 | bt878_pci_driver_registered = 0; | ||
555 | |||
556 | printk(KERN_INFO "bt878: AUDIO driver version %d.%d.%d loaded\n", | ||
557 | (BT878_VERSION_CODE >> 16) & 0xff, | ||
558 | (BT878_VERSION_CODE >> 8) & 0xff, | ||
559 | BT878_VERSION_CODE & 0xff); | ||
560 | /* | ||
561 | bt878_check_chipset(); | ||
562 | */ | ||
563 | /* later we register inside of bt878_find_audio_dma() | ||
564 | * because we may want to ignore certain cards */ | ||
565 | bt878_pci_driver_registered = 1; | ||
566 | return pci_register_driver(&bt878_pci_driver); | ||
567 | } | ||
568 | |||
569 | static void bt878_cleanup_module(void) | ||
570 | { | ||
571 | if (bt878_pci_driver_registered) { | ||
572 | bt878_pci_driver_registered = 0; | ||
573 | pci_unregister_driver(&bt878_pci_driver); | ||
574 | } | ||
575 | return; | ||
576 | } | ||
577 | |||
578 | module_init(bt878_init_module); | ||
579 | module_exit(bt878_cleanup_module); | ||
580 | |||
581 | //MODULE_AUTHOR("XXX"); | ||
582 | MODULE_LICENSE("GPL"); | ||
583 | |||
584 | /* | ||
585 | * Local variables: | ||
586 | * c-basic-offset: 8 | ||
587 | * End: | ||
588 | */ | ||
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h new file mode 100644 index 000000000000..e1b9809d1b08 --- /dev/null +++ b/drivers/media/dvb/bt8xx/bt878.h | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | bt878.h - Bt878 audio module (register offsets) | ||
3 | |||
4 | Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> | ||
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 | #ifndef _BT878_H_ | ||
22 | #define _BT878_H_ | ||
23 | |||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/spinlock.h> | ||
28 | #include "bt848.h" | ||
29 | #include "bttv.h" | ||
30 | |||
31 | #define BT878_VERSION_CODE 0x000000 | ||
32 | |||
33 | #define BT878_AINT_STAT 0x100 | ||
34 | #define BT878_ARISCS (0xf<<28) | ||
35 | #define BT878_ARISC_EN (1<<27) | ||
36 | #define BT878_ASCERR (1<<19) | ||
37 | #define BT878_AOCERR (1<<18) | ||
38 | #define BT878_APABORT (1<<17) | ||
39 | #define BT878_ARIPERR (1<<16) | ||
40 | #define BT878_APPERR (1<<15) | ||
41 | #define BT878_AFDSR (1<<14) | ||
42 | #define BT878_AFTRGT (1<<13) | ||
43 | #define BT878_AFBUS (1<<12) | ||
44 | #define BT878_ARISCI (1<<11) | ||
45 | #define BT878_AOFLOW (1<<3) | ||
46 | |||
47 | #define BT878_AINT_MASK 0x104 | ||
48 | |||
49 | #define BT878_AGPIO_DMA_CTL 0x10c | ||
50 | #define BT878_A_GAIN (0xf<<28) | ||
51 | #define BT878_A_G2X (1<<27) | ||
52 | #define BT878_A_PWRDN (1<<26) | ||
53 | #define BT878_A_SEL (3<<24) | ||
54 | #define BT878_DA_SCE (1<<23) | ||
55 | #define BT878_DA_LRI (1<<22) | ||
56 | #define BT878_DA_MLB (1<<21) | ||
57 | #define BT878_DA_LRD (0x1f<<16) | ||
58 | #define BT878_DA_DPM (1<<15) | ||
59 | #define BT878_DA_SBR (1<<14) | ||
60 | #define BT878_DA_ES2 (1<<13) | ||
61 | #define BT878_DA_LMT (1<<12) | ||
62 | #define BT878_DA_SDR (0xf<<8) | ||
63 | #define BT878_DA_IOM (3<<6) | ||
64 | #define BT878_DA_APP (1<<5) | ||
65 | #define BT878_ACAP_EN (1<<4) | ||
66 | #define BT878_PKTP (3<<2) | ||
67 | #define BT878_RISC_EN (1<<1) | ||
68 | #define BT878_FIFO_EN 1 | ||
69 | |||
70 | #define BT878_APACK_LEN 0x110 | ||
71 | #define BT878_AFP_LEN (0xff<<16) | ||
72 | #define BT878_ALP_LEN 0xfff | ||
73 | |||
74 | #define BT878_ARISC_START 0x114 | ||
75 | |||
76 | #define BT878_ARISC_PC 0x120 | ||
77 | |||
78 | /* BT878 FUNCTION 0 REGISTERS */ | ||
79 | #define BT878_GPIO_DMA_CTL 0x10c | ||
80 | |||
81 | /* Interrupt register */ | ||
82 | #define BT878_INT_STAT 0x100 | ||
83 | #define BT878_INT_MASK 0x104 | ||
84 | #define BT878_I2CRACK (1<<25) | ||
85 | #define BT878_I2CDONE (1<<8) | ||
86 | |||
87 | #define BT878_MAX 4 | ||
88 | |||
89 | #define BT878_RISC_SYNC_MASK (1 << 15) | ||
90 | |||
91 | extern int bt878_num; | ||
92 | |||
93 | struct bt878 { | ||
94 | struct semaphore gpio_lock; | ||
95 | unsigned int nr; | ||
96 | unsigned int bttv_nr; | ||
97 | struct i2c_adapter *adapter; | ||
98 | struct pci_dev *dev; | ||
99 | unsigned int id; | ||
100 | unsigned int TS_Size; | ||
101 | unsigned char revision; | ||
102 | unsigned int irq; | ||
103 | unsigned long bt878_adr; | ||
104 | volatile void __iomem *bt878_mem; /* function 1 */ | ||
105 | |||
106 | volatile u32 finished_block; | ||
107 | volatile u32 last_block; | ||
108 | u32 block_count; | ||
109 | u32 block_bytes; | ||
110 | u32 line_bytes; | ||
111 | u32 line_count; | ||
112 | |||
113 | u32 buf_size; | ||
114 | u8 *buf_cpu; | ||
115 | dma_addr_t buf_dma; | ||
116 | |||
117 | u32 risc_size; | ||
118 | u32 *risc_cpu; | ||
119 | dma_addr_t risc_dma; | ||
120 | u32 risc_pos; | ||
121 | |||
122 | struct tasklet_struct tasklet; | ||
123 | int shutdown; | ||
124 | }; | ||
125 | |||
126 | extern struct bt878 bt878[BT878_MAX]; | ||
127 | |||
128 | void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin, | ||
129 | u32 irq_err_ignore); | ||
130 | void bt878_stop(struct bt878 *bt); | ||
131 | |||
132 | #if defined(__powerpc__) /* big-endian */ | ||
133 | extern __inline__ void io_st_le32(volatile unsigned __iomem *addr, unsigned val) | ||
134 | { | ||
135 | __asm__ __volatile__("stwbrx %1,0,%2":"=m"(*addr):"r"(val), | ||
136 | "r"(addr)); | ||
137 | __asm__ __volatile__("eieio":::"memory"); | ||
138 | } | ||
139 | |||
140 | #define bmtwrite(dat,adr) io_st_le32((adr),(dat)) | ||
141 | #define bmtread(adr) ld_le32((adr)) | ||
142 | #else | ||
143 | #define bmtwrite(dat,adr) writel((dat), (adr)) | ||
144 | #define bmtread(adr) readl(adr) | ||
145 | #endif | ||
146 | |||
147 | #endif | ||
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c new file mode 100644 index 000000000000..eac83768dfd0 --- /dev/null +++ b/drivers/media/dvb/bt8xx/dst.c | |||
@@ -0,0 +1,1089 @@ | |||
1 | /* | ||
2 | Frontend-driver for TwinHan DST Frontend | ||
3 | |||
4 | Copyright (C) 2003 Jamie Honan | ||
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 | |||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | |||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/string.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/vmalloc.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <asm/div64.h> | ||
31 | |||
32 | #include "dvb_frontend.h" | ||
33 | #include "dst_priv.h" | ||
34 | #include "dst.h" | ||
35 | |||
36 | struct dst_state { | ||
37 | |||
38 | struct i2c_adapter* i2c; | ||
39 | |||
40 | struct bt878* bt; | ||
41 | |||
42 | struct dvb_frontend_ops ops; | ||
43 | |||
44 | /* configuration settings */ | ||
45 | const struct dst_config* config; | ||
46 | |||
47 | struct dvb_frontend frontend; | ||
48 | |||
49 | /* private demodulator data */ | ||
50 | u8 tx_tuna[10]; | ||
51 | u8 rx_tuna[10]; | ||
52 | u8 rxbuffer[10]; | ||
53 | u8 diseq_flags; | ||
54 | u8 dst_type; | ||
55 | u32 type_flags; | ||
56 | u32 frequency; /* intermediate frequency in kHz for QPSK */ | ||
57 | fe_spectral_inversion_t inversion; | ||
58 | u32 symbol_rate; /* symbol rate in Symbols per second */ | ||
59 | fe_code_rate_t fec; | ||
60 | fe_sec_voltage_t voltage; | ||
61 | fe_sec_tone_mode_t tone; | ||
62 | u32 decode_freq; | ||
63 | u8 decode_lock; | ||
64 | u16 decode_strength; | ||
65 | u16 decode_snr; | ||
66 | unsigned long cur_jiff; | ||
67 | u8 k22; | ||
68 | fe_bandwidth_t bandwidth; | ||
69 | }; | ||
70 | |||
71 | static unsigned int dst_verbose = 0; | ||
72 | module_param(dst_verbose, int, 0644); | ||
73 | MODULE_PARM_DESC(dst_verbose, "verbose startup messages, default is 1 (yes)"); | ||
74 | static unsigned int dst_debug = 0; | ||
75 | module_param(dst_debug, int, 0644); | ||
76 | MODULE_PARM_DESC(dst_debug, "debug messages, default is 0 (no)"); | ||
77 | |||
78 | #define dprintk if (dst_debug) printk | ||
79 | |||
80 | #define DST_TYPE_IS_SAT 0 | ||
81 | #define DST_TYPE_IS_TERR 1 | ||
82 | #define DST_TYPE_IS_CABLE 2 | ||
83 | |||
84 | #define DST_TYPE_HAS_NEWTUNE 1 | ||
85 | #define DST_TYPE_HAS_TS204 2 | ||
86 | #define DST_TYPE_HAS_SYMDIV 4 | ||
87 | |||
88 | #define HAS_LOCK 1 | ||
89 | #define ATTEMPT_TUNE 2 | ||
90 | #define HAS_POWER 4 | ||
91 | |||
92 | static void dst_packsize(struct dst_state* state, int psize) | ||
93 | { | ||
94 | union dst_gpio_packet bits; | ||
95 | |||
96 | bits.psize = psize; | ||
97 | bt878_device_control(state->bt, DST_IG_TS, &bits); | ||
98 | } | ||
99 | |||
100 | static int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh) | ||
101 | { | ||
102 | union dst_gpio_packet enb; | ||
103 | union dst_gpio_packet bits; | ||
104 | int err; | ||
105 | |||
106 | enb.enb.mask = mask; | ||
107 | enb.enb.enable = enbb; | ||
108 | if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) { | ||
109 | dprintk("%s: dst_gpio_enb error (err == %i, mask == 0x%02x, enb == 0x%02x)\n", __FUNCTION__, err, mask, enbb); | ||
110 | return -EREMOTEIO; | ||
111 | } | ||
112 | |||
113 | /* because complete disabling means no output, no need to do output packet */ | ||
114 | if (enbb == 0) | ||
115 | return 0; | ||
116 | |||
117 | bits.outp.mask = enbb; | ||
118 | bits.outp.highvals = outhigh; | ||
119 | |||
120 | if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) { | ||
121 | dprintk("%s: dst_gpio_outb error (err == %i, enbb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__, err, enbb, outhigh); | ||
122 | return -EREMOTEIO; | ||
123 | } | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static int dst_gpio_inb(struct dst_state *state, u8 * result) | ||
128 | { | ||
129 | union dst_gpio_packet rd_packet; | ||
130 | int err; | ||
131 | |||
132 | *result = 0; | ||
133 | |||
134 | if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) { | ||
135 | dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__, err); | ||
136 | return -EREMOTEIO; | ||
137 | } | ||
138 | |||
139 | *result = (u8) rd_packet.rd.value; | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | #define DST_I2C_ENABLE 1 | ||
144 | #define DST_8820 2 | ||
145 | |||
146 | static int dst_reset8820(struct dst_state *state) | ||
147 | { | ||
148 | int retval; | ||
149 | /* pull 8820 gpio pin low, wait, high, wait, then low */ | ||
150 | // dprintk ("%s: reset 8820\n", __FUNCTION__); | ||
151 | retval = dst_gpio_outb(state, DST_8820, DST_8820, 0); | ||
152 | if (retval < 0) | ||
153 | return retval; | ||
154 | msleep(10); | ||
155 | retval = dst_gpio_outb(state, DST_8820, DST_8820, DST_8820); | ||
156 | if (retval < 0) | ||
157 | return retval; | ||
158 | /* wait for more feedback on what works here * | ||
159 | msleep(10); | ||
160 | retval = dst_gpio_outb(dst, DST_8820, DST_8820, 0); | ||
161 | if (retval < 0) | ||
162 | return retval; | ||
163 | */ | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static int dst_i2c_enable(struct dst_state *state) | ||
168 | { | ||
169 | int retval; | ||
170 | /* pull I2C enable gpio pin low, wait */ | ||
171 | // dprintk ("%s: i2c enable\n", __FUNCTION__); | ||
172 | retval = dst_gpio_outb(state, ~0, DST_I2C_ENABLE, 0); | ||
173 | if (retval < 0) | ||
174 | return retval; | ||
175 | // dprintk ("%s: i2c enable delay\n", __FUNCTION__); | ||
176 | msleep(33); | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static int dst_i2c_disable(struct dst_state *state) | ||
181 | { | ||
182 | int retval; | ||
183 | /* release I2C enable gpio pin, wait */ | ||
184 | // dprintk ("%s: i2c disable\n", __FUNCTION__); | ||
185 | retval = dst_gpio_outb(state, ~0, 0, 0); | ||
186 | if (retval < 0) | ||
187 | return retval; | ||
188 | // dprintk ("%s: i2c disable delay\n", __FUNCTION__); | ||
189 | msleep(33); | ||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static int dst_wait_dst_ready(struct dst_state *state) | ||
194 | { | ||
195 | u8 reply; | ||
196 | int retval; | ||
197 | int i; | ||
198 | for (i = 0; i < 200; i++) { | ||
199 | retval = dst_gpio_inb(state, &reply); | ||
200 | if (retval < 0) | ||
201 | return retval; | ||
202 | if ((reply & DST_I2C_ENABLE) == 0) { | ||
203 | dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i); | ||
204 | return 1; | ||
205 | } | ||
206 | msleep(10); | ||
207 | } | ||
208 | dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int write_dst(struct dst_state *state, u8 * data, u8 len) | ||
213 | { | ||
214 | struct i2c_msg msg = { | ||
215 | .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len | ||
216 | }; | ||
217 | int err; | ||
218 | int cnt; | ||
219 | |||
220 | if (dst_debug && dst_verbose) { | ||
221 | u8 i; | ||
222 | dprintk("%s writing", __FUNCTION__); | ||
223 | for (i = 0; i < len; i++) { | ||
224 | dprintk(" 0x%02x", data[i]); | ||
225 | } | ||
226 | dprintk("\n"); | ||
227 | } | ||
228 | msleep(30); | ||
229 | for (cnt = 0; cnt < 4; cnt++) { | ||
230 | if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { | ||
231 | dprintk("%s: write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]); | ||
232 | dst_i2c_disable(state); | ||
233 | msleep(500); | ||
234 | dst_i2c_enable(state); | ||
235 | msleep(500); | ||
236 | continue; | ||
237 | } else | ||
238 | break; | ||
239 | } | ||
240 | if (cnt >= 4) | ||
241 | return -EREMOTEIO; | ||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static int read_dst(struct dst_state *state, u8 * ret, u8 len) | ||
246 | { | ||
247 | struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len }; | ||
248 | int err; | ||
249 | int cnt; | ||
250 | |||
251 | for (cnt = 0; cnt < 4; cnt++) { | ||
252 | if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { | ||
253 | dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]); | ||
254 | dst_i2c_disable(state); | ||
255 | dst_i2c_enable(state); | ||
256 | continue; | ||
257 | } else | ||
258 | break; | ||
259 | } | ||
260 | if (cnt >= 4) | ||
261 | return -EREMOTEIO; | ||
262 | dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]); | ||
263 | if (dst_debug && dst_verbose) { | ||
264 | for (err = 1; err < len; err++) | ||
265 | dprintk(" 0x%x", ret[err]); | ||
266 | if (err > 1) | ||
267 | dprintk("\n"); | ||
268 | } | ||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static int dst_set_freq(struct dst_state *state, u32 freq) | ||
273 | { | ||
274 | u8 *val; | ||
275 | |||
276 | state->frequency = freq; | ||
277 | |||
278 | // dprintk("%s: set frequency %u\n", __FUNCTION__, freq); | ||
279 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
280 | freq = freq / 1000; | ||
281 | if (freq < 950 || freq > 2150) | ||
282 | return -EINVAL; | ||
283 | val = &state->tx_tuna[0]; | ||
284 | val[2] = (freq >> 8) & 0x7f; | ||
285 | val[3] = (u8) freq; | ||
286 | val[4] = 1; | ||
287 | val[8] &= ~4; | ||
288 | if (freq < 1531) | ||
289 | val[8] |= 4; | ||
290 | } else if (state->dst_type == DST_TYPE_IS_TERR) { | ||
291 | freq = freq / 1000; | ||
292 | if (freq < 137000 || freq > 858000) | ||
293 | return -EINVAL; | ||
294 | val = &state->tx_tuna[0]; | ||
295 | val[2] = (freq >> 16) & 0xff; | ||
296 | val[3] = (freq >> 8) & 0xff; | ||
297 | val[4] = (u8) freq; | ||
298 | val[5] = 0; | ||
299 | switch (state->bandwidth) { | ||
300 | case BANDWIDTH_6_MHZ: | ||
301 | val[6] = 6; | ||
302 | break; | ||
303 | |||
304 | case BANDWIDTH_7_MHZ: | ||
305 | case BANDWIDTH_AUTO: | ||
306 | val[6] = 7; | ||
307 | break; | ||
308 | |||
309 | case BANDWIDTH_8_MHZ: | ||
310 | val[6] = 8; | ||
311 | break; | ||
312 | } | ||
313 | |||
314 | val[7] = 0; | ||
315 | val[8] = 0; | ||
316 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { | ||
317 | /* guess till will get one */ | ||
318 | freq = freq / 1000; | ||
319 | val = &state->tx_tuna[0]; | ||
320 | val[2] = (freq >> 16) & 0xff; | ||
321 | val[3] = (freq >> 8) & 0xff; | ||
322 | val[4] = (u8) freq; | ||
323 | } else | ||
324 | return -EINVAL; | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) | ||
329 | { | ||
330 | u8 *val; | ||
331 | |||
332 | state->bandwidth = bandwidth; | ||
333 | |||
334 | if (state->dst_type != DST_TYPE_IS_TERR) | ||
335 | return 0; | ||
336 | |||
337 | val = &state->tx_tuna[0]; | ||
338 | switch (bandwidth) { | ||
339 | case BANDWIDTH_6_MHZ: | ||
340 | val[6] = 6; | ||
341 | break; | ||
342 | |||
343 | case BANDWIDTH_7_MHZ: | ||
344 | val[6] = 7; | ||
345 | break; | ||
346 | |||
347 | case BANDWIDTH_8_MHZ: | ||
348 | val[6] = 8; | ||
349 | break; | ||
350 | |||
351 | default: | ||
352 | return -EINVAL; | ||
353 | } | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) | ||
358 | { | ||
359 | u8 *val; | ||
360 | |||
361 | state->inversion = inversion; | ||
362 | |||
363 | val = &state->tx_tuna[0]; | ||
364 | |||
365 | val[8] &= ~0x80; | ||
366 | |||
367 | switch (inversion) { | ||
368 | case INVERSION_OFF: | ||
369 | break; | ||
370 | case INVERSION_ON: | ||
371 | val[8] |= 0x80; | ||
372 | break; | ||
373 | default: | ||
374 | return -EINVAL; | ||
375 | } | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | static int dst_set_fec(struct dst_state* state, fe_code_rate_t fec) | ||
380 | { | ||
381 | state->fec = fec; | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static fe_code_rate_t dst_get_fec(struct dst_state* state) | ||
386 | { | ||
387 | return state->fec; | ||
388 | } | ||
389 | |||
390 | static int dst_set_symbolrate(struct dst_state* state, u32 srate) | ||
391 | { | ||
392 | u8 *val; | ||
393 | u32 symcalc; | ||
394 | u64 sval; | ||
395 | |||
396 | state->symbol_rate = srate; | ||
397 | |||
398 | if (state->dst_type == DST_TYPE_IS_TERR) { | ||
399 | return 0; | ||
400 | } | ||
401 | // dprintk("%s: set srate %u\n", __FUNCTION__, srate); | ||
402 | srate /= 1000; | ||
403 | val = &state->tx_tuna[0]; | ||
404 | |||
405 | if (state->type_flags & DST_TYPE_HAS_SYMDIV) { | ||
406 | sval = srate; | ||
407 | sval <<= 20; | ||
408 | do_div(sval, 88000); | ||
409 | symcalc = (u32) sval; | ||
410 | // dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc); | ||
411 | val[5] = (u8) (symcalc >> 12); | ||
412 | val[6] = (u8) (symcalc >> 4); | ||
413 | val[7] = (u8) (symcalc << 4); | ||
414 | } else { | ||
415 | val[5] = (u8) (srate >> 16) & 0x7f; | ||
416 | val[6] = (u8) (srate >> 8); | ||
417 | val[7] = (u8) srate; | ||
418 | } | ||
419 | val[8] &= ~0x20; | ||
420 | if (srate > 8000) | ||
421 | val[8] |= 0x20; | ||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | static u8 dst_check_sum(u8 * buf, u32 len) | ||
426 | { | ||
427 | u32 i; | ||
428 | u8 val = 0; | ||
429 | if (!len) | ||
430 | return 0; | ||
431 | for (i = 0; i < len; i++) { | ||
432 | val += buf[i]; | ||
433 | } | ||
434 | return ((~val) + 1); | ||
435 | } | ||
436 | |||
437 | struct dst_types { | ||
438 | char *mstr; | ||
439 | int offs; | ||
440 | u8 dst_type; | ||
441 | u32 type_flags; | ||
442 | }; | ||
443 | |||
444 | static struct dst_types dst_tlist[] = { | ||
445 | {"DST-020", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV}, | ||
446 | {"DST-030", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE}, | ||
447 | {"DST-03T", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204}, | ||
448 | {"DST-MOT", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV}, | ||
449 | {"DST-CI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE}, | ||
450 | {"DSTMCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE}, | ||
451 | {"DSTFCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE}, | ||
452 | {"DCTNEW", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE}, | ||
453 | {"DCT-CI", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_TS204}, | ||
454 | {"DTTDIG", 1, DST_TYPE_IS_TERR, 0} | ||
455 | }; | ||
456 | |||
457 | /* DCTNEW and DCT-CI are guesses */ | ||
458 | |||
459 | static void dst_type_flags_print(u32 type_flags) | ||
460 | { | ||
461 | printk("DST type flags :"); | ||
462 | if (type_flags & DST_TYPE_HAS_NEWTUNE) | ||
463 | printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE); | ||
464 | if (type_flags & DST_TYPE_HAS_TS204) | ||
465 | printk(" 0x%x ts204", DST_TYPE_HAS_TS204); | ||
466 | if (type_flags & DST_TYPE_HAS_SYMDIV) | ||
467 | printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV); | ||
468 | printk("\n"); | ||
469 | } | ||
470 | |||
471 | static int dst_type_print(u8 type) | ||
472 | { | ||
473 | char *otype; | ||
474 | switch (type) { | ||
475 | case DST_TYPE_IS_SAT: | ||
476 | otype = "satellite"; | ||
477 | break; | ||
478 | case DST_TYPE_IS_TERR: | ||
479 | otype = "terrestrial"; | ||
480 | break; | ||
481 | case DST_TYPE_IS_CABLE: | ||
482 | otype = "cable"; | ||
483 | break; | ||
484 | default: | ||
485 | printk("%s: invalid dst type %d\n", __FUNCTION__, type); | ||
486 | return -EINVAL; | ||
487 | } | ||
488 | printk("DST type : %s\n", otype); | ||
489 | return 0; | ||
490 | } | ||
491 | |||
492 | static int dst_check_ci(struct dst_state *state) | ||
493 | { | ||
494 | u8 txbuf[8]; | ||
495 | u8 rxbuf[8]; | ||
496 | int retval; | ||
497 | int i; | ||
498 | struct dst_types *dsp; | ||
499 | u8 use_dst_type; | ||
500 | u32 use_type_flags; | ||
501 | |||
502 | memset(txbuf, 0, sizeof(txbuf)); | ||
503 | txbuf[1] = 6; | ||
504 | txbuf[7] = dst_check_sum(txbuf, 7); | ||
505 | |||
506 | dst_i2c_enable(state); | ||
507 | dst_reset8820(state); | ||
508 | retval = write_dst(state, txbuf, 8); | ||
509 | if (retval < 0) { | ||
510 | dst_i2c_disable(state); | ||
511 | dprintk("%s: write not successful, maybe no card?\n", __FUNCTION__); | ||
512 | return retval; | ||
513 | } | ||
514 | msleep(3); | ||
515 | retval = read_dst(state, rxbuf, 1); | ||
516 | dst_i2c_disable(state); | ||
517 | if (retval < 0) { | ||
518 | dprintk("%s: read not successful, maybe no card?\n", __FUNCTION__); | ||
519 | return retval; | ||
520 | } | ||
521 | if (rxbuf[0] != 0xff) { | ||
522 | dprintk("%s: write reply not 0xff, not ci (%02x)\n", __FUNCTION__, rxbuf[0]); | ||
523 | return retval; | ||
524 | } | ||
525 | if (!dst_wait_dst_ready(state)) | ||
526 | return 0; | ||
527 | // dst_i2c_enable(i2c); Dimitri | ||
528 | retval = read_dst(state, rxbuf, 8); | ||
529 | dst_i2c_disable(state); | ||
530 | if (retval < 0) { | ||
531 | dprintk("%s: read not successful\n", __FUNCTION__); | ||
532 | return retval; | ||
533 | } | ||
534 | if (rxbuf[7] != dst_check_sum(rxbuf, 7)) { | ||
535 | dprintk("%s: checksum failure\n", __FUNCTION__); | ||
536 | return retval; | ||
537 | } | ||
538 | rxbuf[7] = '\0'; | ||
539 | for (i = 0, dsp = &dst_tlist[0]; i < sizeof(dst_tlist) / sizeof(dst_tlist[0]); i++, dsp++) { | ||
540 | if (!strncmp(&rxbuf[dsp->offs], dsp->mstr, strlen(dsp->mstr))) { | ||
541 | use_type_flags = dsp->type_flags; | ||
542 | use_dst_type = dsp->dst_type; | ||
543 | printk("%s: recognize %s\n", __FUNCTION__, dsp->mstr); | ||
544 | break; | ||
545 | } | ||
546 | } | ||
547 | if (i >= sizeof(dst_tlist) / sizeof(dst_tlist[0])) { | ||
548 | printk("%s: unable to recognize %s or %s\n", __FUNCTION__, &rxbuf[0], &rxbuf[1]); | ||
549 | printk("%s please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__); | ||
550 | use_dst_type = DST_TYPE_IS_SAT; | ||
551 | use_type_flags = DST_TYPE_HAS_SYMDIV; | ||
552 | } | ||
553 | dst_type_print(use_dst_type); | ||
554 | |||
555 | state->type_flags = use_type_flags; | ||
556 | state->dst_type = use_dst_type; | ||
557 | dst_type_flags_print(state->type_flags); | ||
558 | |||
559 | if (state->type_flags & DST_TYPE_HAS_TS204) { | ||
560 | dst_packsize(state, 204); | ||
561 | } | ||
562 | return 0; | ||
563 | } | ||
564 | |||
565 | static int dst_command(struct dst_state* state, u8 * data, u8 len) | ||
566 | { | ||
567 | int retval; | ||
568 | u8 reply; | ||
569 | |||
570 | dst_i2c_enable(state); | ||
571 | dst_reset8820(state); | ||
572 | retval = write_dst(state, data, len); | ||
573 | if (retval < 0) { | ||
574 | dst_i2c_disable(state); | ||
575 | dprintk("%s: write not successful\n", __FUNCTION__); | ||
576 | return retval; | ||
577 | } | ||
578 | msleep(33); | ||
579 | retval = read_dst(state, &reply, 1); | ||
580 | dst_i2c_disable(state); | ||
581 | if (retval < 0) { | ||
582 | dprintk("%s: read verify not successful\n", __FUNCTION__); | ||
583 | return retval; | ||
584 | } | ||
585 | if (reply != 0xff) { | ||
586 | dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); | ||
587 | return 0; | ||
588 | } | ||
589 | if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) | ||
590 | return 0; | ||
591 | if (!dst_wait_dst_ready(state)) | ||
592 | return 0; | ||
593 | // dst_i2c_enable(i2c); Per dimitri | ||
594 | retval = read_dst(state, state->rxbuffer, 8); | ||
595 | dst_i2c_disable(state); | ||
596 | if (retval < 0) { | ||
597 | dprintk("%s: read not successful\n", __FUNCTION__); | ||
598 | return 0; | ||
599 | } | ||
600 | if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { | ||
601 | dprintk("%s: checksum failure\n", __FUNCTION__); | ||
602 | return 0; | ||
603 | } | ||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | static int dst_get_signal(struct dst_state* state) | ||
608 | { | ||
609 | int retval; | ||
610 | u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; | ||
611 | |||
612 | if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { | ||
613 | state->decode_lock = state->decode_strength = state->decode_snr = 0; | ||
614 | return 0; | ||
615 | } | ||
616 | if (0 == (state->diseq_flags & HAS_LOCK)) { | ||
617 | state->decode_lock = state->decode_strength = state->decode_snr = 0; | ||
618 | return 0; | ||
619 | } | ||
620 | if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) { | ||
621 | retval = dst_command(state, get_signal, 8); | ||
622 | if (retval < 0) | ||
623 | return retval; | ||
624 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
625 | state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0; | ||
626 | state->decode_strength = state->rxbuffer[5] << 8; | ||
627 | state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3]; | ||
628 | } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) { | ||
629 | state->decode_lock = (state->rxbuffer[1]) ? 1 : 0; | ||
630 | state->decode_strength = state->rxbuffer[4] << 8; | ||
631 | state->decode_snr = state->rxbuffer[3] << 8; | ||
632 | } | ||
633 | state->cur_jiff = jiffies; | ||
634 | } | ||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static int dst_tone_power_cmd(struct dst_state* state) | ||
639 | { | ||
640 | u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 }; | ||
641 | |||
642 | if (state->dst_type == DST_TYPE_IS_TERR) | ||
643 | return 0; | ||
644 | |||
645 | if (state->voltage == SEC_VOLTAGE_OFF) | ||
646 | paket[4] = 0; | ||
647 | else | ||
648 | paket[4] = 1; | ||
649 | if (state->tone == SEC_TONE_ON) | ||
650 | paket[2] = state->k22; | ||
651 | else | ||
652 | paket[2] = 0; | ||
653 | paket[7] = dst_check_sum(&paket[0], 7); | ||
654 | dst_command(state, paket, 8); | ||
655 | return 0; | ||
656 | } | ||
657 | |||
658 | static int dst_get_tuna(struct dst_state* state) | ||
659 | { | ||
660 | int retval; | ||
661 | if ((state->diseq_flags & ATTEMPT_TUNE) == 0) | ||
662 | return 0; | ||
663 | state->diseq_flags &= ~(HAS_LOCK); | ||
664 | if (!dst_wait_dst_ready(state)) | ||
665 | return 0; | ||
666 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { | ||
667 | /* how to get variable length reply ???? */ | ||
668 | retval = read_dst(state, state->rx_tuna, 10); | ||
669 | } else { | ||
670 | retval = read_dst(state, &state->rx_tuna[2], 8); | ||
671 | } | ||
672 | if (retval < 0) { | ||
673 | dprintk("%s: read not successful\n", __FUNCTION__); | ||
674 | return 0; | ||
675 | } | ||
676 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { | ||
677 | if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { | ||
678 | dprintk("%s: checksum failure?\n", __FUNCTION__); | ||
679 | return 0; | ||
680 | } | ||
681 | } else { | ||
682 | if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) { | ||
683 | dprintk("%s: checksum failure?\n", __FUNCTION__); | ||
684 | return 0; | ||
685 | } | ||
686 | } | ||
687 | if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0) | ||
688 | return 0; | ||
689 | state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; | ||
690 | |||
691 | state->decode_lock = 1; | ||
692 | /* | ||
693 | dst->decode_n1 = (dst->rx_tuna[4] << 8) + | ||
694 | (dst->rx_tuna[5]); | ||
695 | |||
696 | dst->decode_n2 = (dst->rx_tuna[8] << 8) + | ||
697 | (dst->rx_tuna[7]); | ||
698 | */ | ||
699 | state->diseq_flags |= HAS_LOCK; | ||
700 | /* dst->cur_jiff = jiffies; */ | ||
701 | return 1; | ||
702 | } | ||
703 | |||
704 | static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage); | ||
705 | |||
706 | static int dst_write_tuna(struct dvb_frontend* fe) | ||
707 | { | ||
708 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
709 | int retval; | ||
710 | u8 reply; | ||
711 | |||
712 | dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags); | ||
713 | state->decode_freq = 0; | ||
714 | state->decode_lock = state->decode_strength = state->decode_snr = 0; | ||
715 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
716 | if (!(state->diseq_flags & HAS_POWER)) | ||
717 | dst_set_voltage(fe, SEC_VOLTAGE_13); | ||
718 | } | ||
719 | state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); | ||
720 | dst_i2c_enable(state); | ||
721 | if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { | ||
722 | dst_reset8820(state); | ||
723 | state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9); | ||
724 | retval = write_dst(state, &state->tx_tuna[0], 10); | ||
725 | } else { | ||
726 | state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7); | ||
727 | retval = write_dst(state, &state->tx_tuna[2], 8); | ||
728 | } | ||
729 | if (retval < 0) { | ||
730 | dst_i2c_disable(state); | ||
731 | dprintk("%s: write not successful\n", __FUNCTION__); | ||
732 | return retval; | ||
733 | } | ||
734 | msleep(3); | ||
735 | retval = read_dst(state, &reply, 1); | ||
736 | dst_i2c_disable(state); | ||
737 | if (retval < 0) { | ||
738 | dprintk("%s: read verify not successful\n", __FUNCTION__); | ||
739 | return retval; | ||
740 | } | ||
741 | if (reply != 0xff) { | ||
742 | dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); | ||
743 | return 0; | ||
744 | } | ||
745 | state->diseq_flags |= ATTEMPT_TUNE; | ||
746 | return dst_get_tuna(state); | ||
747 | } | ||
748 | |||
749 | /* | ||
750 | * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00 | ||
751 | * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00 | ||
752 | * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00 | ||
753 | * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00 | ||
754 | * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00 | ||
755 | * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 | ||
756 | * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 | ||
757 | * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec | ||
758 | * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8 | ||
759 | * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4 | ||
760 | * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0 | ||
761 | */ | ||
762 | |||
763 | static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) | ||
764 | { | ||
765 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
766 | u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; | ||
767 | |||
768 | if (state->dst_type == DST_TYPE_IS_TERR) | ||
769 | return 0; | ||
770 | |||
771 | if (cmd->msg_len == 0 || cmd->msg_len > 4) | ||
772 | return -EINVAL; | ||
773 | memcpy(&paket[3], cmd->msg, cmd->msg_len); | ||
774 | paket[7] = dst_check_sum(&paket[0], 7); | ||
775 | dst_command(state, paket, 8); | ||
776 | return 0; | ||
777 | } | ||
778 | |||
779 | static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) | ||
780 | { | ||
781 | u8 *val; | ||
782 | int need_cmd; | ||
783 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
784 | |||
785 | state->voltage = voltage; | ||
786 | |||
787 | if (state->dst_type == DST_TYPE_IS_TERR) | ||
788 | return 0; | ||
789 | |||
790 | need_cmd = 0; | ||
791 | val = &state->tx_tuna[0]; | ||
792 | val[8] &= ~0x40; | ||
793 | switch (voltage) { | ||
794 | case SEC_VOLTAGE_13: | ||
795 | if ((state->diseq_flags & HAS_POWER) == 0) | ||
796 | need_cmd = 1; | ||
797 | state->diseq_flags |= HAS_POWER; | ||
798 | break; | ||
799 | case SEC_VOLTAGE_18: | ||
800 | if ((state->diseq_flags & HAS_POWER) == 0) | ||
801 | need_cmd = 1; | ||
802 | state->diseq_flags |= HAS_POWER; | ||
803 | val[8] |= 0x40; | ||
804 | break; | ||
805 | case SEC_VOLTAGE_OFF: | ||
806 | need_cmd = 1; | ||
807 | state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE); | ||
808 | break; | ||
809 | default: | ||
810 | return -EINVAL; | ||
811 | } | ||
812 | if (need_cmd) { | ||
813 | dst_tone_power_cmd(state); | ||
814 | } | ||
815 | return 0; | ||
816 | } | ||
817 | |||
818 | static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) | ||
819 | { | ||
820 | u8 *val; | ||
821 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
822 | |||
823 | state->tone = tone; | ||
824 | |||
825 | if (state->dst_type == DST_TYPE_IS_TERR) | ||
826 | return 0; | ||
827 | |||
828 | val = &state->tx_tuna[0]; | ||
829 | |||
830 | val[8] &= ~0x1; | ||
831 | |||
832 | switch (tone) { | ||
833 | case SEC_TONE_OFF: | ||
834 | break; | ||
835 | case SEC_TONE_ON: | ||
836 | val[8] |= 1; | ||
837 | break; | ||
838 | default: | ||
839 | return -EINVAL; | ||
840 | } | ||
841 | dst_tone_power_cmd(state); | ||
842 | return 0; | ||
843 | } | ||
844 | |||
845 | static int dst_init(struct dvb_frontend* fe) | ||
846 | { | ||
847 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
848 | static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; | ||
849 | static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; | ||
850 | static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; | ||
851 | static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; | ||
852 | static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; | ||
853 | static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; | ||
854 | state->inversion = INVERSION_ON; | ||
855 | state->voltage = SEC_VOLTAGE_13; | ||
856 | state->tone = SEC_TONE_OFF; | ||
857 | state->symbol_rate = 29473000; | ||
858 | state->fec = FEC_AUTO; | ||
859 | state->diseq_flags = 0; | ||
860 | state->k22 = 0x02; | ||
861 | state->bandwidth = BANDWIDTH_7_MHZ; | ||
862 | state->cur_jiff = jiffies; | ||
863 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
864 | state->frequency = 950000; | ||
865 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_satci_tuna : ini_satfta_tuna), sizeof(ini_satfta_tuna)); | ||
866 | } else if (state->dst_type == DST_TYPE_IS_TERR) { | ||
867 | state->frequency = 137000000; | ||
868 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_tvci_tuna : ini_tvfta_tuna), sizeof(ini_tvfta_tuna)); | ||
869 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { | ||
870 | state->frequency = 51000000; | ||
871 | memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_cabci_tuna : ini_cabfta_tuna), sizeof(ini_cabfta_tuna)); | ||
872 | } | ||
873 | |||
874 | return 0; | ||
875 | } | ||
876 | |||
877 | static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) | ||
878 | { | ||
879 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
880 | |||
881 | *status = 0; | ||
882 | if (state->diseq_flags & HAS_LOCK) { | ||
883 | dst_get_signal(state); | ||
884 | if (state->decode_lock) | ||
885 | *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI; | ||
886 | } | ||
887 | |||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength) | ||
892 | { | ||
893 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
894 | |||
895 | dst_get_signal(state); | ||
896 | *strength = state->decode_strength; | ||
897 | |||
898 | return 0; | ||
899 | } | ||
900 | |||
901 | static int dst_read_snr(struct dvb_frontend* fe, u16* snr) | ||
902 | { | ||
903 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
904 | |||
905 | dst_get_signal(state); | ||
906 | *snr = state->decode_snr; | ||
907 | |||
908 | return 0; | ||
909 | } | ||
910 | |||
911 | static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) | ||
912 | { | ||
913 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
914 | |||
915 | dst_set_freq(state, p->frequency); | ||
916 | dst_set_inversion(state, p->inversion); | ||
917 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
918 | dst_set_fec(state, p->u.qpsk.fec_inner); | ||
919 | dst_set_symbolrate(state, p->u.qpsk.symbol_rate); | ||
920 | } else if (state->dst_type == DST_TYPE_IS_TERR) { | ||
921 | dst_set_bandwidth(state, p->u.ofdm.bandwidth); | ||
922 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { | ||
923 | dst_set_fec(state, p->u.qam.fec_inner); | ||
924 | dst_set_symbolrate(state, p->u.qam.symbol_rate); | ||
925 | } | ||
926 | dst_write_tuna(fe); | ||
927 | |||
928 | return 0; | ||
929 | } | ||
930 | |||
931 | static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) | ||
932 | { | ||
933 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
934 | |||
935 | p->frequency = state->decode_freq; | ||
936 | p->inversion = state->inversion; | ||
937 | if (state->dst_type == DST_TYPE_IS_SAT) { | ||
938 | p->u.qpsk.symbol_rate = state->symbol_rate; | ||
939 | p->u.qpsk.fec_inner = dst_get_fec(state); | ||
940 | } else if (state->dst_type == DST_TYPE_IS_TERR) { | ||
941 | p->u.ofdm.bandwidth = state->bandwidth; | ||
942 | } else if (state->dst_type == DST_TYPE_IS_CABLE) { | ||
943 | p->u.qam.symbol_rate = state->symbol_rate; | ||
944 | p->u.qam.fec_inner = dst_get_fec(state); | ||
945 | p->u.qam.modulation = QAM_AUTO; | ||
946 | } | ||
947 | |||
948 | return 0; | ||
949 | } | ||
950 | |||
951 | static void dst_release(struct dvb_frontend* fe) | ||
952 | { | ||
953 | struct dst_state* state = (struct dst_state*) fe->demodulator_priv; | ||
954 | kfree(state); | ||
955 | } | ||
956 | |||
957 | static struct dvb_frontend_ops dst_dvbt_ops; | ||
958 | static struct dvb_frontend_ops dst_dvbs_ops; | ||
959 | static struct dvb_frontend_ops dst_dvbc_ops; | ||
960 | |||
961 | struct dvb_frontend* dst_attach(const struct dst_config* config, | ||
962 | struct i2c_adapter* i2c, | ||
963 | struct bt878 *bt) | ||
964 | { | ||
965 | struct dst_state* state = NULL; | ||
966 | |||
967 | /* allocate memory for the internal state */ | ||
968 | state = (struct dst_state*) kmalloc(sizeof(struct dst_state), GFP_KERNEL); | ||
969 | if (state == NULL) goto error; | ||
970 | |||
971 | /* setup the state */ | ||
972 | state->config = config; | ||
973 | state->i2c = i2c; | ||
974 | state->bt = bt; | ||
975 | |||
976 | /* check if the demod is there */ | ||
977 | if (dst_check_ci(state) < 0) goto error; | ||
978 | |||
979 | /* determine settings based on type */ | ||
980 | switch (state->dst_type) { | ||
981 | case DST_TYPE_IS_TERR: | ||
982 | memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops)); | ||
983 | break; | ||
984 | case DST_TYPE_IS_CABLE: | ||
985 | memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops)); | ||
986 | break; | ||
987 | case DST_TYPE_IS_SAT: | ||
988 | memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops)); | ||
989 | break; | ||
990 | default: | ||
991 | printk("dst: unknown frontend type. please report to the LinuxTV.org DVB mailinglist.\n"); | ||
992 | goto error; | ||
993 | } | ||
994 | |||
995 | /* create dvb_frontend */ | ||
996 | state->frontend.ops = &state->ops; | ||
997 | state->frontend.demodulator_priv = state; | ||
998 | return &state->frontend; | ||
999 | |||
1000 | error: | ||
1001 | kfree(state); | ||
1002 | return NULL; | ||
1003 | } | ||
1004 | |||
1005 | static struct dvb_frontend_ops dst_dvbt_ops = { | ||
1006 | |||
1007 | .info = { | ||
1008 | .name = "DST DVB-T", | ||
1009 | .type = FE_OFDM, | ||
1010 | .frequency_min = 137000000, | ||
1011 | .frequency_max = 858000000, | ||
1012 | .frequency_stepsize = 166667, | ||
1013 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | ||
1014 | }, | ||
1015 | |||
1016 | .release = dst_release, | ||
1017 | |||
1018 | .init = dst_init, | ||
1019 | |||
1020 | .set_frontend = dst_set_frontend, | ||
1021 | .get_frontend = dst_get_frontend, | ||
1022 | |||
1023 | .read_status = dst_read_status, | ||
1024 | .read_signal_strength = dst_read_signal_strength, | ||
1025 | .read_snr = dst_read_snr, | ||
1026 | }; | ||
1027 | |||
1028 | static struct dvb_frontend_ops dst_dvbs_ops = { | ||
1029 | |||
1030 | .info = { | ||
1031 | .name = "DST DVB-S", | ||
1032 | .type = FE_QPSK, | ||
1033 | .frequency_min = 950000, | ||
1034 | .frequency_max = 2150000, | ||
1035 | .frequency_stepsize = 1000, /* kHz for QPSK frontends */ | ||
1036 | .frequency_tolerance = 29500, | ||
1037 | .symbol_rate_min = 1000000, | ||
1038 | .symbol_rate_max = 45000000, | ||
1039 | /* . symbol_rate_tolerance = ???,*/ | ||
1040 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK | ||
1041 | }, | ||
1042 | |||
1043 | .release = dst_release, | ||
1044 | |||
1045 | .init = dst_init, | ||
1046 | |||
1047 | .set_frontend = dst_set_frontend, | ||
1048 | .get_frontend = dst_get_frontend, | ||
1049 | |||
1050 | .read_status = dst_read_status, | ||
1051 | .read_signal_strength = dst_read_signal_strength, | ||
1052 | .read_snr = dst_read_snr, | ||
1053 | |||
1054 | .diseqc_send_master_cmd = dst_set_diseqc, | ||
1055 | .set_voltage = dst_set_voltage, | ||
1056 | .set_tone = dst_set_tone, | ||
1057 | }; | ||
1058 | |||
1059 | static struct dvb_frontend_ops dst_dvbc_ops = { | ||
1060 | |||
1061 | .info = { | ||
1062 | .name = "DST DVB-C", | ||
1063 | .type = FE_QAM, | ||
1064 | .frequency_stepsize = 62500, | ||
1065 | .frequency_min = 51000000, | ||
1066 | .frequency_max = 858000000, | ||
1067 | .symbol_rate_min = 1000000, | ||
1068 | .symbol_rate_max = 45000000, | ||
1069 | /* . symbol_rate_tolerance = ???,*/ | ||
1070 | .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | ||
1071 | }, | ||
1072 | |||
1073 | .release = dst_release, | ||
1074 | |||
1075 | .init = dst_init, | ||
1076 | |||
1077 | .set_frontend = dst_set_frontend, | ||
1078 | .get_frontend = dst_get_frontend, | ||
1079 | |||
1080 | .read_status = dst_read_status, | ||
1081 | .read_signal_strength = dst_read_signal_strength, | ||
1082 | .read_snr = dst_read_snr, | ||
1083 | }; | ||
1084 | |||
1085 | MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver"); | ||
1086 | MODULE_AUTHOR("Jamie Honan"); | ||
1087 | MODULE_LICENSE("GPL"); | ||
1088 | |||
1089 | EXPORT_SYMBOL(dst_attach); | ||
diff --git a/drivers/media/dvb/bt8xx/dst.h b/drivers/media/dvb/bt8xx/dst.h new file mode 100644 index 000000000000..bcb418c5c121 --- /dev/null +++ b/drivers/media/dvb/bt8xx/dst.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | Frontend-driver for TwinHan DST Frontend | ||
3 | |||
4 | Copyright (C) 2003 Jamie Honan | ||
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 | |||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | |||
21 | */ | ||
22 | |||
23 | #ifndef DST_H | ||
24 | #define DST_H | ||
25 | |||
26 | #include <linux/dvb/frontend.h> | ||
27 | #include <linux/device.h> | ||
28 | #include "bt878.h" | ||
29 | |||
30 | struct dst_config | ||
31 | { | ||
32 | /* the demodulator's i2c address */ | ||
33 | u8 demod_address; | ||
34 | }; | ||
35 | |||
36 | extern struct dvb_frontend* dst_attach(const struct dst_config* config, | ||
37 | struct i2c_adapter* i2c, | ||
38 | struct bt878 *bt); | ||
39 | |||
40 | #endif // DST_H | ||
diff --git a/drivers/media/dvb/bt8xx/dst_priv.h b/drivers/media/dvb/bt8xx/dst_priv.h new file mode 100644 index 000000000000..80488aa628b4 --- /dev/null +++ b/drivers/media/dvb/bt8xx/dst_priv.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * dst-bt878.h: part of the DST driver for the TwinHan DST Frontend | ||
3 | * | ||
4 | * Copyright (C) 2003 Jamie Honan | ||
5 | */ | ||
6 | |||
7 | struct dst_gpio_enable { | ||
8 | u32 mask; | ||
9 | u32 enable; | ||
10 | }; | ||
11 | |||
12 | struct dst_gpio_output { | ||
13 | u32 mask; | ||
14 | u32 highvals; | ||
15 | }; | ||
16 | |||
17 | struct dst_gpio_read { | ||
18 | unsigned long value; | ||
19 | }; | ||
20 | |||
21 | union dst_gpio_packet { | ||
22 | struct dst_gpio_enable enb; | ||
23 | struct dst_gpio_output outp; | ||
24 | struct dst_gpio_read rd; | ||
25 | int psize; | ||
26 | }; | ||
27 | |||
28 | #define DST_IG_ENABLE 0 | ||
29 | #define DST_IG_WRITE 1 | ||
30 | #define DST_IG_READ 2 | ||
31 | #define DST_IG_TS 3 | ||
32 | |||
33 | struct bt878; | ||
34 | |||
35 | int bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp); | ||
36 | |||
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c new file mode 100644 index 000000000000..b735397f59aa --- /dev/null +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c | |||
@@ -0,0 +1,797 @@ | |||
1 | /* | ||
2 | * Bt8xx based DVB adapter driver | ||
3 | * | ||
4 | * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org> | ||
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 | |||
22 | #include <linux/bitops.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/moduleparam.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/device.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/i2c.h> | ||
30 | |||
31 | #include "dmxdev.h" | ||
32 | #include "dvbdev.h" | ||
33 | #include "dvb_demux.h" | ||
34 | #include "dvb_frontend.h" | ||
35 | |||
36 | #include "dvb-bt8xx.h" | ||
37 | |||
38 | #include "bt878.h" | ||
39 | |||
40 | static int debug; | ||
41 | |||
42 | module_param(debug, int, 0644); | ||
43 | MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); | ||
44 | |||
45 | #define dprintk( args... ) \ | ||
46 | do { \ | ||
47 | if (debug) printk(KERN_DEBUG args); \ | ||
48 | } while (0) | ||
49 | |||
50 | static void dvb_bt8xx_task(unsigned long data) | ||
51 | { | ||
52 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *)data; | ||
53 | |||
54 | //printk("%d ", card->bt->finished_block); | ||
55 | |||
56 | while (card->bt->last_block != card->bt->finished_block) { | ||
57 | (card->bt->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter) | ||
58 | (&card->demux, | ||
59 | &card->bt->buf_cpu[card->bt->last_block * | ||
60 | card->bt->block_bytes], | ||
61 | card->bt->block_bytes); | ||
62 | card->bt->last_block = (card->bt->last_block + 1) % | ||
63 | card->bt->block_count; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
68 | { | ||
69 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; | ||
70 | struct dvb_bt8xx_card *card = dvbdmx->priv; | ||
71 | int rc; | ||
72 | |||
73 | dprintk("dvb_bt8xx: start_feed\n"); | ||
74 | |||
75 | if (!dvbdmx->dmx.frontend) | ||
76 | return -EINVAL; | ||
77 | |||
78 | down(&card->lock); | ||
79 | card->nfeeds++; | ||
80 | rc = card->nfeeds; | ||
81 | if (card->nfeeds == 1) | ||
82 | bt878_start(card->bt, card->gpio_mode, | ||
83 | card->op_sync_orin, card->irq_err_ignore); | ||
84 | up(&card->lock); | ||
85 | return rc; | ||
86 | } | ||
87 | |||
88 | static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
89 | { | ||
90 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; | ||
91 | struct dvb_bt8xx_card *card = dvbdmx->priv; | ||
92 | |||
93 | dprintk("dvb_bt8xx: stop_feed\n"); | ||
94 | |||
95 | if (!dvbdmx->dmx.frontend) | ||
96 | return -EINVAL; | ||
97 | |||
98 | down(&card->lock); | ||
99 | card->nfeeds--; | ||
100 | if (card->nfeeds == 0) | ||
101 | bt878_stop(card->bt); | ||
102 | up(&card->lock); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev) | ||
108 | { | ||
109 | if ((adev->subsystem_vendor == bdev->subsystem_vendor) && | ||
110 | (adev->subsystem_device == bdev->subsystem_device) && | ||
111 | (adev->bus->number == bdev->bus->number) && | ||
112 | (PCI_SLOT(adev->devfn) == PCI_SLOT(bdev->devfn))) | ||
113 | return 1; | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static struct bt878 __init *dvb_bt8xx_878_match(unsigned int bttv_nr, struct pci_dev* bttv_pci_dev) | ||
118 | { | ||
119 | unsigned int card_nr; | ||
120 | |||
121 | /* Hmm, n squared. Hope n is small */ | ||
122 | for (card_nr = 0; card_nr < bt878_num; card_nr++) { | ||
123 | if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev)) | ||
124 | return &bt878[card_nr]; | ||
125 | } | ||
126 | return NULL; | ||
127 | } | ||
128 | |||
129 | |||
130 | static int thomson_dtt7579_demod_init(struct dvb_frontend* fe) | ||
131 | { | ||
132 | static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 }; | ||
133 | static u8 mt352_reset [] = { 0x50, 0x80 }; | ||
134 | static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; | ||
135 | static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 }; | ||
136 | static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 }; | ||
137 | static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; | ||
138 | |||
139 | mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); | ||
140 | udelay(2000); | ||
141 | mt352_write(fe, mt352_reset, sizeof(mt352_reset)); | ||
142 | mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); | ||
143 | |||
144 | mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); | ||
145 | mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg)); | ||
146 | mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf) | ||
152 | { | ||
153 | u32 div; | ||
154 | unsigned char bs = 0; | ||
155 | unsigned char cp = 0; | ||
156 | |||
157 | #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ | ||
158 | div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; | ||
159 | |||
160 | if (params->frequency < 542000000) cp = 0xb4; | ||
161 | else if (params->frequency < 771000000) cp = 0xbc; | ||
162 | else cp = 0xf4; | ||
163 | |||
164 | if (params->frequency == 0) bs = 0x03; | ||
165 | else if (params->frequency < 443250000) bs = 0x02; | ||
166 | else bs = 0x08; | ||
167 | |||
168 | pllbuf[0] = 0xc0; // Note: non-linux standard PLL i2c address | ||
169 | pllbuf[1] = div >> 8; | ||
170 | pllbuf[2] = div & 0xff; | ||
171 | pllbuf[3] = cp; | ||
172 | pllbuf[4] = bs; | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static struct mt352_config thomson_dtt7579_config = { | ||
178 | |||
179 | .demod_address = 0x0f, | ||
180 | .demod_init = thomson_dtt7579_demod_init, | ||
181 | .pll_set = thomson_dtt7579_pll_set, | ||
182 | }; | ||
183 | |||
184 | static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
185 | { | ||
186 | u32 freq = params->frequency; | ||
187 | |||
188 | int i, a, n, pump; | ||
189 | u32 band, pll; | ||
190 | |||
191 | |||
192 | u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000, | ||
193 | 1576000,1718000,1856000,2036000,2150000}; | ||
194 | u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000, | ||
195 | 0x00102000,0x00104000,0x00108000,0x00110000, | ||
196 | 0x00120000,0x00140000}; | ||
197 | |||
198 | #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */ | ||
199 | printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq); | ||
200 | |||
201 | /* This is really the bit driving the tuner chip cx24108 */ | ||
202 | |||
203 | if(freq<950000) freq=950000; /* kHz */ | ||
204 | if(freq>2150000) freq=2150000; /* satellite IF is 950..2150MHz */ | ||
205 | |||
206 | /* decide which VCO to use for the input frequency */ | ||
207 | for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++); | ||
208 | printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq); | ||
209 | band=bandsel[i]; | ||
210 | /* the gain values must be set by SetSymbolrate */ | ||
211 | /* compute the pll divider needed, from Conexant data sheet, | ||
212 | resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4, | ||
213 | depending on the divider bit. It is set to /4 on the 2 lowest | ||
214 | bands */ | ||
215 | n=((i<=2?2:1)*freq*10L)/(XTAL/100); | ||
216 | a=n%32; n/=32; if(a==0) n--; | ||
217 | pump=(freq<(osci[i-1]+osci[i])/2); | ||
218 | pll=0xf8000000| | ||
219 | ((pump?1:2)<<(14+11))| | ||
220 | ((n&0x1ff)<<(5+11))| | ||
221 | ((a&0x1f)<<11); | ||
222 | /* everything is shifted left 11 bits to left-align the bits in the | ||
223 | 32bit word. Output to the tuner goes MSB-aligned, after all */ | ||
224 | printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a); | ||
225 | cx24110_pll_write(fe,band); | ||
226 | /* set vga and vca to their widest-band settings, as a precaution. | ||
227 | SetSymbolrate might not be called to set this up */ | ||
228 | cx24110_pll_write(fe,0x500c0000); | ||
229 | cx24110_pll_write(fe,0x83f1f800); | ||
230 | cx24110_pll_write(fe,pll); | ||
231 | /* writereg(client,0x56,0x7f);*/ | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static int pinnsat_pll_init(struct dvb_frontend* fe) | ||
237 | { | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | |||
242 | static struct cx24110_config pctvsat_config = { | ||
243 | |||
244 | .demod_address = 0x55, | ||
245 | .pll_init = pinnsat_pll_init, | ||
246 | .pll_set = cx24108_pll_set, | ||
247 | }; | ||
248 | |||
249 | |||
250 | static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
251 | { | ||
252 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; | ||
253 | u8 cfg, cpump, band_select; | ||
254 | u8 data[4]; | ||
255 | u32 div; | ||
256 | struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = sizeof(data) }; | ||
257 | |||
258 | div = (36000000 + params->frequency + 83333) / 166666; | ||
259 | cfg = 0x88; | ||
260 | |||
261 | if (params->frequency < 175000000) cpump = 2; | ||
262 | else if (params->frequency < 390000000) cpump = 1; | ||
263 | else if (params->frequency < 470000000) cpump = 2; | ||
264 | else if (params->frequency < 750000000) cpump = 2; | ||
265 | else cpump = 3; | ||
266 | |||
267 | if (params->frequency < 175000000) band_select = 0x0e; | ||
268 | else if (params->frequency < 470000000) band_select = 0x05; | ||
269 | else band_select = 0x03; | ||
270 | |||
271 | data[0] = (div >> 8) & 0x7f; | ||
272 | data[1] = div & 0xff; | ||
273 | data[2] = ((div >> 10) & 0x60) | cfg; | ||
274 | data[3] = cpump | band_select; | ||
275 | |||
276 | i2c_transfer(card->i2c_adapter, &msg, 1); | ||
277 | return (div * 166666 - 36000000); | ||
278 | } | ||
279 | |||
280 | static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) | ||
281 | { | ||
282 | struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; | ||
283 | |||
284 | return request_firmware(fw, name, &bt->bt->dev->dev); | ||
285 | } | ||
286 | |||
287 | static struct sp887x_config microtune_mt7202dtf_config = { | ||
288 | |||
289 | .demod_address = 0x70, | ||
290 | .pll_set = microtune_mt7202dtf_pll_set, | ||
291 | .request_firmware = microtune_mt7202dtf_request_firmware, | ||
292 | }; | ||
293 | |||
294 | |||
295 | |||
296 | static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe) | ||
297 | { | ||
298 | static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d }; | ||
299 | static u8 mt352_reset [] = { 0x50, 0x80 }; | ||
300 | static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; | ||
301 | static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF, | ||
302 | 0x00, 0xFF, 0x00, 0x40, 0x40 }; | ||
303 | static u8 mt352_av771_extra[] = { 0xB5, 0x7A }; | ||
304 | static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; | ||
305 | |||
306 | |||
307 | mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); | ||
308 | udelay(2000); | ||
309 | mt352_write(fe, mt352_reset, sizeof(mt352_reset)); | ||
310 | mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); | ||
311 | |||
312 | mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg)); | ||
313 | udelay(2000); | ||
314 | mt352_write(fe, mt352_av771_extra,sizeof(mt352_av771_extra)); | ||
315 | mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | static int advbt771_samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf) | ||
321 | { | ||
322 | u32 div; | ||
323 | unsigned char bs = 0; | ||
324 | unsigned char cp = 0; | ||
325 | |||
326 | #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ | ||
327 | div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; | ||
328 | |||
329 | if (params->frequency < 150000000) cp = 0xB4; | ||
330 | else if (params->frequency < 173000000) cp = 0xBC; | ||
331 | else if (params->frequency < 250000000) cp = 0xB4; | ||
332 | else if (params->frequency < 400000000) cp = 0xBC; | ||
333 | else if (params->frequency < 420000000) cp = 0xF4; | ||
334 | else if (params->frequency < 470000000) cp = 0xFC; | ||
335 | else if (params->frequency < 600000000) cp = 0xBC; | ||
336 | else if (params->frequency < 730000000) cp = 0xF4; | ||
337 | else cp = 0xFC; | ||
338 | |||
339 | if (params->frequency < 150000000) bs = 0x01; | ||
340 | else if (params->frequency < 173000000) bs = 0x01; | ||
341 | else if (params->frequency < 250000000) bs = 0x02; | ||
342 | else if (params->frequency < 400000000) bs = 0x02; | ||
343 | else if (params->frequency < 420000000) bs = 0x02; | ||
344 | else if (params->frequency < 470000000) bs = 0x02; | ||
345 | else if (params->frequency < 600000000) bs = 0x08; | ||
346 | else if (params->frequency < 730000000) bs = 0x08; | ||
347 | else bs = 0x08; | ||
348 | |||
349 | pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address | ||
350 | pllbuf[1] = div >> 8; | ||
351 | pllbuf[2] = div & 0xff; | ||
352 | pllbuf[3] = cp; | ||
353 | pllbuf[4] = bs; | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | static struct mt352_config advbt771_samsung_tdtc9251dh0_config = { | ||
359 | |||
360 | .demod_address = 0x0f, | ||
361 | .demod_init = advbt771_samsung_tdtc9251dh0_demod_init, | ||
362 | .pll_set = advbt771_samsung_tdtc9251dh0_pll_set, | ||
363 | }; | ||
364 | |||
365 | |||
366 | static struct dst_config dst_config = { | ||
367 | |||
368 | .demod_address = 0x55, | ||
369 | }; | ||
370 | |||
371 | |||
372 | static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) | ||
373 | { | ||
374 | struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; | ||
375 | |||
376 | return request_firmware(fw, name, &bt->bt->dev->dev); | ||
377 | } | ||
378 | |||
379 | static void or51211_setmode(struct dvb_frontend * fe, int mode) | ||
380 | { | ||
381 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
382 | bttv_write_gpio(bt->bttv_nr, 0x0002, mode); /* Reset */ | ||
383 | msleep(20); | ||
384 | } | ||
385 | |||
386 | static void or51211_reset(struct dvb_frontend * fe) | ||
387 | { | ||
388 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
389 | |||
390 | /* RESET DEVICE | ||
391 | * reset is controled by GPIO-0 | ||
392 | * when set to 0 causes reset and when to 1 for normal op | ||
393 | * must remain reset for 128 clock cycles on a 50Mhz clock | ||
394 | * also PRM1 PRM2 & PRM4 are controled by GPIO-1,GPIO-2 & GPIO-4 | ||
395 | * We assume that the reset has be held low long enough or we | ||
396 | * have been reset by a power on. When the driver is unloaded | ||
397 | * reset set to 0 so if reloaded we have been reset. | ||
398 | */ | ||
399 | /* reset & PRM1,2&4 are outputs */ | ||
400 | int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F); | ||
401 | if (ret != 0) { | ||
402 | printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR " | ||
403 | "(%i)\n", ret); | ||
404 | } | ||
405 | bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */ | ||
406 | msleep(20); | ||
407 | /* Now set for normal operation */ | ||
408 | bttv_write_gpio(bt->bttv_nr, 0x0001F, 0x0001); | ||
409 | /* wait for operation to begin */ | ||
410 | msleep(500); | ||
411 | } | ||
412 | |||
413 | static void or51211_sleep(struct dvb_frontend * fe) | ||
414 | { | ||
415 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
416 | bttv_write_gpio(bt->bttv_nr, 0x0001, 0x0000); | ||
417 | } | ||
418 | |||
419 | static struct or51211_config or51211_config = { | ||
420 | |||
421 | .demod_address = 0x15, | ||
422 | .request_firmware = or51211_request_firmware, | ||
423 | .setmode = or51211_setmode, | ||
424 | .reset = or51211_reset, | ||
425 | .sleep = or51211_sleep, | ||
426 | }; | ||
427 | |||
428 | |||
429 | static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
430 | { | ||
431 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; | ||
432 | u8 buf[4]; | ||
433 | u32 div; | ||
434 | struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) }; | ||
435 | |||
436 | div = (params->frequency + 36166667) / 166667; | ||
437 | |||
438 | buf[0] = (div >> 8) & 0x7F; | ||
439 | buf[1] = div & 0xFF; | ||
440 | buf[2] = 0x85; | ||
441 | if ((params->frequency >= 47000000) && (params->frequency < 153000000)) | ||
442 | buf[3] = 0x01; | ||
443 | else if ((params->frequency >= 153000000) && (params->frequency < 430000000)) | ||
444 | buf[3] = 0x02; | ||
445 | else if ((params->frequency >= 430000000) && (params->frequency < 824000000)) | ||
446 | buf[3] = 0x0C; | ||
447 | else if ((params->frequency >= 824000000) && (params->frequency < 863000000)) | ||
448 | buf[3] = 0x8C; | ||
449 | else | ||
450 | return -EINVAL; | ||
451 | |||
452 | i2c_transfer(card->i2c_adapter, &msg, 1); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | static struct nxt6000_config vp3021_alps_tded4_config = { | ||
457 | |||
458 | .demod_address = 0x0a, | ||
459 | .clock_inversion = 1, | ||
460 | .pll_set = vp3021_alps_tded4_pll_set, | ||
461 | }; | ||
462 | |||
463 | |||
464 | static void frontend_init(struct dvb_bt8xx_card *card, u32 type) | ||
465 | { | ||
466 | switch(type) { | ||
467 | #ifdef BTTV_DVICO_DVBT_LITE | ||
468 | case BTTV_DVICO_DVBT_LITE: | ||
469 | card->fe = mt352_attach(&thomson_dtt7579_config, card->i2c_adapter); | ||
470 | if (card->fe != NULL) { | ||
471 | card->fe->ops->info.frequency_min = 174000000; | ||
472 | card->fe->ops->info.frequency_max = 862000000; | ||
473 | break; | ||
474 | } | ||
475 | break; | ||
476 | #endif | ||
477 | |||
478 | #ifdef BTTV_TWINHAN_VP3021 | ||
479 | case BTTV_TWINHAN_VP3021: | ||
480 | #else | ||
481 | case BTTV_NEBULA_DIGITV: | ||
482 | #endif | ||
483 | card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter); | ||
484 | if (card->fe != NULL) { | ||
485 | break; | ||
486 | } | ||
487 | break; | ||
488 | |||
489 | case BTTV_AVDVBT_761: | ||
490 | card->fe = sp887x_attach(µtune_mt7202dtf_config, card->i2c_adapter); | ||
491 | if (card->fe != NULL) { | ||
492 | break; | ||
493 | } | ||
494 | break; | ||
495 | |||
496 | case BTTV_AVDVBT_771: | ||
497 | card->fe = mt352_attach(&advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter); | ||
498 | if (card->fe != NULL) { | ||
499 | card->fe->ops->info.frequency_min = 174000000; | ||
500 | card->fe->ops->info.frequency_max = 862000000; | ||
501 | break; | ||
502 | } | ||
503 | break; | ||
504 | |||
505 | case BTTV_TWINHAN_DST: | ||
506 | card->fe = dst_attach(&dst_config, card->i2c_adapter, card->bt); | ||
507 | if (card->fe != NULL) { | ||
508 | break; | ||
509 | } | ||
510 | break; | ||
511 | |||
512 | case BTTV_PINNACLESAT: | ||
513 | card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter); | ||
514 | if (card->fe != NULL) { | ||
515 | break; | ||
516 | } | ||
517 | break; | ||
518 | |||
519 | case BTTV_PC_HDTV: | ||
520 | card->fe = or51211_attach(&or51211_config, card->i2c_adapter); | ||
521 | if (card->fe != NULL) { | ||
522 | break; | ||
523 | } | ||
524 | break; | ||
525 | } | ||
526 | |||
527 | if (card->fe == NULL) { | ||
528 | printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", | ||
529 | card->bt->dev->vendor, | ||
530 | card->bt->dev->device, | ||
531 | card->bt->dev->subsystem_vendor, | ||
532 | card->bt->dev->subsystem_device); | ||
533 | } else { | ||
534 | if (dvb_register_frontend(card->dvb_adapter, card->fe)) { | ||
535 | printk("dvb-bt8xx: Frontend registration failed!\n"); | ||
536 | if (card->fe->ops->release) | ||
537 | card->fe->ops->release(card->fe); | ||
538 | card->fe = NULL; | ||
539 | } | ||
540 | } | ||
541 | } | ||
542 | |||
543 | static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type) | ||
544 | { | ||
545 | int result; | ||
546 | |||
547 | if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, | ||
548 | THIS_MODULE)) < 0) { | ||
549 | printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result); | ||
550 | return result; | ||
551 | |||
552 | } | ||
553 | card->dvb_adapter->priv = card; | ||
554 | |||
555 | card->bt->adapter = card->i2c_adapter; | ||
556 | |||
557 | memset(&card->demux, 0, sizeof(struct dvb_demux)); | ||
558 | |||
559 | card->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING; | ||
560 | |||
561 | card->demux.priv = card; | ||
562 | card->demux.filternum = 256; | ||
563 | card->demux.feednum = 256; | ||
564 | card->demux.start_feed = dvb_bt8xx_start_feed; | ||
565 | card->demux.stop_feed = dvb_bt8xx_stop_feed; | ||
566 | card->demux.write_to_decoder = NULL; | ||
567 | |||
568 | if ((result = dvb_dmx_init(&card->demux)) < 0) { | ||
569 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
570 | |||
571 | dvb_unregister_adapter(card->dvb_adapter); | ||
572 | return result; | ||
573 | } | ||
574 | |||
575 | card->dmxdev.filternum = 256; | ||
576 | card->dmxdev.demux = &card->demux.dmx; | ||
577 | card->dmxdev.capabilities = 0; | ||
578 | |||
579 | if ((result = dvb_dmxdev_init(&card->dmxdev, card->dvb_adapter)) < 0) { | ||
580 | printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result); | ||
581 | |||
582 | dvb_dmx_release(&card->demux); | ||
583 | dvb_unregister_adapter(card->dvb_adapter); | ||
584 | return result; | ||
585 | } | ||
586 | |||
587 | card->fe_hw.source = DMX_FRONTEND_0; | ||
588 | |||
589 | if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_hw)) < 0) { | ||
590 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
591 | |||
592 | dvb_dmxdev_release(&card->dmxdev); | ||
593 | dvb_dmx_release(&card->demux); | ||
594 | dvb_unregister_adapter(card->dvb_adapter); | ||
595 | return result; | ||
596 | } | ||
597 | |||
598 | card->fe_mem.source = DMX_MEMORY_FE; | ||
599 | |||
600 | if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_mem)) < 0) { | ||
601 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
602 | |||
603 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
604 | dvb_dmxdev_release(&card->dmxdev); | ||
605 | dvb_dmx_release(&card->demux); | ||
606 | dvb_unregister_adapter(card->dvb_adapter); | ||
607 | return result; | ||
608 | } | ||
609 | |||
610 | if ((result = card->demux.dmx.connect_frontend(&card->demux.dmx, &card->fe_hw)) < 0) { | ||
611 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
612 | |||
613 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); | ||
614 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
615 | dvb_dmxdev_release(&card->dmxdev); | ||
616 | dvb_dmx_release(&card->demux); | ||
617 | dvb_unregister_adapter(card->dvb_adapter); | ||
618 | return result; | ||
619 | } | ||
620 | |||
621 | dvb_net_init(card->dvb_adapter, &card->dvbnet, &card->demux.dmx); | ||
622 | |||
623 | tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card); | ||
624 | |||
625 | frontend_init(card, type); | ||
626 | |||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static int dvb_bt8xx_probe(struct device *dev) | ||
631 | { | ||
632 | struct bttv_sub_device *sub = to_bttv_sub_dev(dev); | ||
633 | struct dvb_bt8xx_card *card; | ||
634 | struct pci_dev* bttv_pci_dev; | ||
635 | int ret; | ||
636 | |||
637 | if (!(card = kmalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL))) | ||
638 | return -ENOMEM; | ||
639 | |||
640 | memset(card, 0, sizeof(*card)); | ||
641 | init_MUTEX(&card->lock); | ||
642 | card->bttv_nr = sub->core->nr; | ||
643 | strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); | ||
644 | card->i2c_adapter = &sub->core->i2c_adap; | ||
645 | |||
646 | switch(sub->core->type) | ||
647 | { | ||
648 | case BTTV_PINNACLESAT: | ||
649 | card->gpio_mode = 0x0400c060; | ||
650 | /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, | ||
651 | BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */ | ||
652 | card->op_sync_orin = 0; | ||
653 | card->irq_err_ignore = 0; | ||
654 | break; | ||
655 | |||
656 | #ifdef BTTV_DVICO_DVBT_LITE | ||
657 | case BTTV_DVICO_DVBT_LITE: | ||
658 | #endif | ||
659 | card->gpio_mode = 0x0400C060; | ||
660 | card->op_sync_orin = 0; | ||
661 | card->irq_err_ignore = 0; | ||
662 | /* 26, 15, 14, 6, 5 | ||
663 | * A_PWRDN DA_DPM DA_SBR DA_IOM_DA | ||
664 | * DA_APP(parallel) */ | ||
665 | break; | ||
666 | |||
667 | #ifdef BTTV_TWINHAN_VP3021 | ||
668 | case BTTV_TWINHAN_VP3021: | ||
669 | #else | ||
670 | case BTTV_NEBULA_DIGITV: | ||
671 | #endif | ||
672 | case BTTV_AVDVBT_761: | ||
673 | card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5); | ||
674 | card->op_sync_orin = 0; | ||
675 | card->irq_err_ignore = 0; | ||
676 | /* A_PWRDN DA_SBR DA_APP (high speed serial) */ | ||
677 | break; | ||
678 | |||
679 | case BTTV_AVDVBT_771: //case 0x07711461: | ||
680 | card->gpio_mode = 0x0400402B; | ||
681 | card->op_sync_orin = BT878_RISC_SYNC_MASK; | ||
682 | card->irq_err_ignore = 0; | ||
683 | /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/ | ||
684 | break; | ||
685 | |||
686 | case BTTV_TWINHAN_DST: | ||
687 | card->gpio_mode = 0x2204f2c; | ||
688 | card->op_sync_orin = BT878_RISC_SYNC_MASK; | ||
689 | card->irq_err_ignore = BT878_APABORT | BT878_ARIPERR | | ||
690 | BT878_APPERR | BT878_AFBUS; | ||
691 | /* 25,21,14,11,10,9,8,3,2 then | ||
692 | * 0x33 = 5,4,1,0 | ||
693 | * A_SEL=SML, DA_MLB, DA_SBR, | ||
694 | * DA_SDR=f, fifo trigger = 32 DWORDS | ||
695 | * IOM = 0 == audio A/D | ||
696 | * DPM = 0 == digital audio mode | ||
697 | * == async data parallel port | ||
698 | * then 0x33 (13 is set by start_capture) | ||
699 | * DA_APP = async data parallel port, | ||
700 | * ACAP_EN = 1, | ||
701 | * RISC+FIFO ENABLE */ | ||
702 | break; | ||
703 | |||
704 | case BTTV_PC_HDTV: | ||
705 | card->gpio_mode = 0x0100EC7B; | ||
706 | card->op_sync_orin = 0; | ||
707 | card->irq_err_ignore = 0; | ||
708 | break; | ||
709 | |||
710 | default: | ||
711 | printk(KERN_WARNING "dvb_bt8xx: Unknown bttv card type: %d.\n", | ||
712 | sub->core->type); | ||
713 | kfree(card); | ||
714 | return -ENODEV; | ||
715 | } | ||
716 | |||
717 | dprintk("dvb_bt8xx: identified card%d as %s\n", card->bttv_nr, card->card_name); | ||
718 | |||
719 | if (!(bttv_pci_dev = bttv_get_pcidev(card->bttv_nr))) { | ||
720 | printk("dvb_bt8xx: no pci device for card %d\n", card->bttv_nr); | ||
721 | kfree(card); | ||
722 | return -EFAULT; | ||
723 | } | ||
724 | |||
725 | if (!(card->bt = dvb_bt8xx_878_match(card->bttv_nr, bttv_pci_dev))) { | ||
726 | printk("dvb_bt8xx: unable to determine DMA core of card %d,\n", | ||
727 | card->bttv_nr); | ||
728 | printk("dvb_bt8xx: if you have the ALSA bt87x audio driver " | ||
729 | "installed, try removing it.\n"); | ||
730 | |||
731 | kfree(card); | ||
732 | return -EFAULT; | ||
733 | |||
734 | } | ||
735 | |||
736 | init_MUTEX(&card->bt->gpio_lock); | ||
737 | card->bt->bttv_nr = sub->core->nr; | ||
738 | |||
739 | if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) { | ||
740 | kfree(card); | ||
741 | return ret; | ||
742 | } | ||
743 | |||
744 | dev_set_drvdata(dev, card); | ||
745 | return 0; | ||
746 | } | ||
747 | |||
748 | static int dvb_bt8xx_remove(struct device *dev) | ||
749 | { | ||
750 | struct dvb_bt8xx_card *card = dev_get_drvdata(dev); | ||
751 | |||
752 | dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr); | ||
753 | |||
754 | bt878_stop(card->bt); | ||
755 | tasklet_kill(&card->bt->tasklet); | ||
756 | dvb_net_release(&card->dvbnet); | ||
757 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); | ||
758 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
759 | dvb_dmxdev_release(&card->dmxdev); | ||
760 | dvb_dmx_release(&card->demux); | ||
761 | if (card->fe) dvb_unregister_frontend(card->fe); | ||
762 | dvb_unregister_adapter(card->dvb_adapter); | ||
763 | |||
764 | kfree(card); | ||
765 | |||
766 | return 0; | ||
767 | } | ||
768 | |||
769 | static struct bttv_sub_driver driver = { | ||
770 | .drv = { | ||
771 | .name = "dvb-bt8xx", | ||
772 | .probe = dvb_bt8xx_probe, | ||
773 | .remove = dvb_bt8xx_remove, | ||
774 | /* FIXME: | ||
775 | * .shutdown = dvb_bt8xx_shutdown, | ||
776 | * .suspend = dvb_bt8xx_suspend, | ||
777 | * .resume = dvb_bt8xx_resume, | ||
778 | */ | ||
779 | }, | ||
780 | }; | ||
781 | |||
782 | static int __init dvb_bt8xx_init(void) | ||
783 | { | ||
784 | return bttv_sub_register(&driver, "dvb"); | ||
785 | } | ||
786 | |||
787 | static void __exit dvb_bt8xx_exit(void) | ||
788 | { | ||
789 | bttv_sub_unregister(&driver); | ||
790 | } | ||
791 | |||
792 | module_init(dvb_bt8xx_init); | ||
793 | module_exit(dvb_bt8xx_exit); | ||
794 | |||
795 | MODULE_DESCRIPTION("Bt8xx based DVB adapter driver"); | ||
796 | MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>"); | ||
797 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h new file mode 100644 index 000000000000..80ef189f930f --- /dev/null +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Bt8xx based DVB adapter driver | ||
3 | * | ||
4 | * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org> | ||
5 | * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> | ||
6 | * Copyright (C) 1999-2001 Ralph Metzler & Marcus Metzler for convergence integrated media GmbH | ||
7 | * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #ifndef DVB_BT8XX_H | ||
26 | #define DVB_BT8XX_H | ||
27 | |||
28 | #include <linux/i2c.h> | ||
29 | #include "dvbdev.h" | ||
30 | #include "dvb_net.h" | ||
31 | #include "bttv.h" | ||
32 | #include "mt352.h" | ||
33 | #include "sp887x.h" | ||
34 | #include "dst.h" | ||
35 | #include "nxt6000.h" | ||
36 | #include "cx24110.h" | ||
37 | #include "or51211.h" | ||
38 | |||
39 | struct dvb_bt8xx_card { | ||
40 | struct semaphore lock; | ||
41 | int nfeeds; | ||
42 | char card_name[32]; | ||
43 | struct dvb_adapter *dvb_adapter; | ||
44 | struct bt878 *bt; | ||
45 | unsigned int bttv_nr; | ||
46 | struct dvb_demux demux; | ||
47 | struct dmxdev dmxdev; | ||
48 | struct dmx_frontend fe_hw; | ||
49 | struct dmx_frontend fe_mem; | ||
50 | u32 gpio_mode; | ||
51 | u32 op_sync_orin; | ||
52 | u32 irq_err_ignore; | ||
53 | struct i2c_adapter *i2c_adapter; | ||
54 | struct dvb_net dvbnet; | ||
55 | |||
56 | struct dvb_frontend* fe; | ||
57 | }; | ||
58 | |||
59 | #endif /* DVB_BT8XX_H */ | ||