aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorManu Abraham <abraham.manu@gmail.com>2009-12-02 19:57:10 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-01-17 08:55:27 -0500
commit41e840b13e111ba18b138d055ddd250bd5ad5e39 (patch)
treedd5c1a60f06549925277c396a964724dd87329e1 /drivers/media
parent6ccf80eb15ccaca4d3f1ab5162b9ded5eecd9971 (diff)
V4L/DVB (13699): [Mantis, MB86A16] Initial checkin: Mantis, MB86A16
Signed-off-by: Manu Abraham <manu@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/dvb/frontends/mb86a16.c1772
-rw-r--r--drivers/media/dvb/frontends/mb86a16.h38
-rw-r--r--drivers/media/dvb/frontends/mb86a16_priv.h151
-rw-r--r--drivers/media/dvb/mantis/Kconfig13
-rw-r--r--drivers/media/dvb/mantis/Makefile7
-rw-r--r--drivers/media/dvb/mantis/mantis_common.h135
-rw-r--r--drivers/media/dvb/mantis/mantis_core.c215
-rw-r--r--drivers/media/dvb/mantis/mantis_core.h61
-rw-r--r--drivers/media/dvb/mantis/mantis_dma.c238
-rw-r--r--drivers/media/dvb/mantis/mantis_dvb.c304
-rw-r--r--drivers/media/dvb/mantis/mantis_i2c.c189
-rw-r--r--drivers/media/dvb/mantis/mantis_reg.h109
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.c151
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.h35
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.c52
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.h30
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.c73
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.h33
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.c53
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.h30
20 files changed, 3689 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/mb86a16.c b/drivers/media/dvb/frontends/mb86a16.c
new file mode 100644
index 000000000000..6a78a0c74036
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a16.c
@@ -0,0 +1,1772 @@
1/*
2 Fujitsu MB86A16 DVB-S/DSS DC Receiver driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25
26#include "dvb_frontend.h"
27#include "mb86a16.h"
28#include "mb86a16_priv.h"
29
30unsigned int verbose = 5;
31module_param(verbose, int, 0644);
32
33#define ABS(x) ((x) < 0 ? (-x) : (x))
34
35struct mb86a16_state {
36 struct i2c_adapter *i2c_adap;
37 const struct mb86a16_config *config;
38 struct dvb_frontend frontend;
39 u8 signal;
40
41 // tuning parameters
42 int frequency;
43 int srate;
44
45 // Internal stuff
46 int master_clk;
47 int deci;
48 int csel;
49 int rsel;
50};
51
52#define MB86A16_ERROR 0
53#define MB86A16_NOTICE 1
54#define MB86A16_INFO 2
55#define MB86A16_DEBUG 3
56
57#define dprintk(x, y, z, format, arg...) do { \
58 if (z) { \
59 if ((x > MB86A16_ERROR) && (x > y)) \
60 printk(KERN_ERR "%s: " format "\n", __func__, ##arg); \
61 else if ((x > MB86A16_NOTICE) && (x > y)) \
62 printk(KERN_NOTICE "%s: " format "\n", __func__, ##arg); \
63 else if ((x > MB86A16_INFO) && (x > y)) \
64 printk(KERN_INFO "%s: " format "\n", __func__, ##arg); \
65 else if ((x > MB86A16_DEBUG) && (x > y)) \
66 printk(KERN_DEBUG "%s: " format "\n", __func__, ##arg); \
67 } else { \
68 if (x > y) \
69 printk(format, ##arg); \
70 } \
71} while (0)
72
73#define TRACE_IN dprintk(verbose, MB86A16_DEBUG, 1, "-->()")
74#define TRACE_OUT dprintk(verbose, MB86A16_DEBUG, 1, "()-->")
75
76static int mb86a16_write(struct mb86a16_state *state, u8 reg, u8 val)
77{
78 int ret;
79 u8 buf[] = { reg, val };
80
81 struct i2c_msg msg = {
82 .addr = state->config->demod_address,
83 .flags = 0,
84 .buf = buf,
85 .len = 2
86 };
87
88 dprintk(verbose, MB86A16_DEBUG, 1,
89 "writing to [0x%02x],Reg[0x%02x],Data[0x%02x]",
90 state->config->demod_address, buf[0], buf[1]);
91
92 ret = i2c_transfer(state->i2c_adap, &msg, 1);
93
94 return (ret != 1) ? -EREMOTEIO : 0;
95}
96
97static int mb86a16_read(struct mb86a16_state *state, u8 reg, u8 *val)
98{
99 int ret;
100 u8 b0[] = { reg };
101 u8 b1[] = { 0 };
102
103 struct i2c_msg msg[] = {
104 {
105 .addr = state->config->demod_address,
106 .flags = 0,
107 .buf = b0,
108 .len = 1
109 },{
110 .addr = state->config->demod_address,
111 .flags = I2C_M_RD,
112 .buf = b1,
113 .len = 1
114 }
115 };
116 ret = i2c_transfer(state->i2c_adap, msg, 2);
117 if (ret != 2) {
118 dprintk(verbose, MB86A16_ERROR, 1, "read error(reg=0x%02x, ret=0x%i)",
119 reg, ret);
120
121 return -EREMOTEIO;
122 }
123 *val = b1[0];
124
125 return ret;
126}
127
128static int CNTM_set(struct mb86a16_state *state,
129 unsigned char timint1,
130 unsigned char timint2,
131 unsigned char cnext)
132{
133 unsigned char val;
134
135 val = (timint1 << 4) | (timint2 << 2) | cnext;
136 if (mb86a16_write(state, MB86A16_CNTMR, val) < 0)
137 goto err;
138
139 return 0;
140
141err:
142 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
143 return -EREMOTEIO;
144}
145
146static int smrt_set(struct mb86a16_state *state, int rate)
147{
148 int tmp ;
149 int m ;
150 unsigned char STOFS0, STOFS1;
151
152 m = 1 << state->deci;
153 tmp = (8192 * state->master_clk - 2 * m * rate * 8192 + state->master_clk / 2) / state->master_clk;
154
155 STOFS0 = tmp & 0x0ff;
156 STOFS1 = (tmp & 0xf00) >> 8;
157
158 if (mb86a16_write(state, MB86A16_SRATE1, (state->deci << 2) |
159 (state->csel << 1) |
160 state->rsel) < 0)
161 goto err;
162 if (mb86a16_write(state, MB86A16_SRATE2, STOFS0) < 0)
163 goto err;
164 if (mb86a16_write(state, MB86A16_SRATE3, STOFS1) < 0)
165 goto err;
166
167 return 0;
168err:
169 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
170 return -1;
171}
172
173static int srst(struct mb86a16_state *state)
174{
175 if (mb86a16_write(state, MB86A16_RESET, 0x04) < 0)
176 goto err;
177
178 return 0;
179err:
180 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
181 return -EREMOTEIO;
182
183}
184
185static int afcex_data_set(struct mb86a16_state *state,
186 unsigned char AFCEX_L,
187 unsigned char AFCEX_H)
188{
189 if (mb86a16_write(state, MB86A16_AFCEXL, AFCEX_L) < 0)
190 goto err;
191 if (mb86a16_write(state, MB86A16_AFCEXH, AFCEX_H) < 0)
192 goto err;
193
194 return 0;
195err:
196 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
197
198 return -1;
199}
200
201static int afcofs_data_set(struct mb86a16_state *state,
202 unsigned char AFCEX_L,
203 unsigned char AFCEX_H)
204{
205 if (mb86a16_write(state, 0x58, AFCEX_L) < 0)
206 goto err;
207 if (mb86a16_write(state, 0x59, AFCEX_H) < 0)
208 goto err;
209
210 return 0;
211err:
212 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
213 return -EREMOTEIO;
214}
215
216static int stlp_set(struct mb86a16_state *state,
217 unsigned char STRAS,
218 unsigned char STRBS)
219{
220 if (mb86a16_write(state, MB86A16_STRFILTCOEF1, (STRBS << 3) | (STRAS)) < 0)
221 goto err;
222
223 return 0;
224err:
225 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
226 return -EREMOTEIO;
227}
228
229static int Vi_set(struct mb86a16_state *state, unsigned char ETH, unsigned char VIA)
230{
231 if (mb86a16_write(state, MB86A16_VISET2, 0x04) < 0)
232 goto err;
233 if (mb86a16_write(state, MB86A16_VISET3, 0xf5) < 0)
234 goto err;
235
236 return 0;
237err:
238 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
239 return -EREMOTEIO;
240}
241
242static int initial_set(struct mb86a16_state *state)
243{
244 if (stlp_set(state, 5, 7))
245 goto err;
246 if (afcex_data_set(state, 0, 0))
247 goto err;
248 if (afcofs_data_set(state, 0, 0))
249 goto err;
250
251 if (mb86a16_write(state, MB86A16_CRLFILTCOEF1, 0x16) < 0)
252 goto err;
253 if (mb86a16_write(state, 0x2f, 0x21) < 0)
254 goto err;
255 if (mb86a16_write(state, MB86A16_VIMAG, 0x38) < 0)
256 goto err;
257 if (mb86a16_write(state, MB86A16_FAGCS1, 0x00) < 0)
258 goto err;
259 if (mb86a16_write(state, MB86A16_FAGCS2, 0x1c) < 0)
260 goto err;
261 if (mb86a16_write(state, MB86A16_FAGCS3, 0x20) < 0)
262 goto err;
263 if (mb86a16_write(state, MB86A16_FAGCS4, 0x1e) < 0)
264 goto err;
265 if (mb86a16_write(state, MB86A16_FAGCS5, 0x23) < 0)
266 goto err;
267 if (mb86a16_write(state, 0x54, 0xff) < 0)
268 goto err;
269 if (mb86a16_write(state, MB86A16_TSOUT, 0x00) < 0)
270 goto err;
271
272 return 0;
273
274err:
275 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
276 return -EREMOTEIO;
277}
278
279static int S01T_set(struct mb86a16_state *state,
280 unsigned char s1t,
281 unsigned s0t)
282{
283 if (mb86a16_write(state, 0x33, (s1t << 3) | s0t) < 0)
284 goto err;
285
286 return 0;
287err:
288 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
289 return -EREMOTEIO;
290}
291
292
293static int EN_set(struct mb86a16_state *state,
294 int cren,
295 int afcen)
296{
297 unsigned char val;
298
299 val = 0x7a | (cren << 7) | (afcen << 2);
300 if (mb86a16_write(state, 0x49, val) < 0)
301 goto err;
302
303 return 0;
304err:
305 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
306 return -EREMOTEIO;
307}
308
309static int AFCEXEN_set(struct mb86a16_state *state,
310 int afcexen,
311 int smrt)
312{
313 unsigned char AFCA ;
314
315 if (smrt > 18875)
316 AFCA = 4;
317 else if (smrt > 9375)
318 AFCA = 3;
319 else if (smrt > 2250)
320 AFCA = 2;
321 else
322 AFCA = 1;
323
324 if (mb86a16_write(state, 0x2a, 0x02 | (afcexen << 5) | (AFCA << 2)) < 0)
325 goto err;
326
327 return 0;
328
329err:
330 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
331 return -EREMOTEIO;
332}
333
334static int DAGC_data_set(struct mb86a16_state *state,
335 unsigned char DAGCA,
336 unsigned char DAGCW)
337{
338 if (mb86a16_write(state, 0x2d, (DAGCA << 3) | DAGCW) < 0)
339 goto err;
340
341 return 0;
342
343err:
344 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
345 return -EREMOTEIO;
346}
347
348static void smrt_info_get(struct mb86a16_state *state, int rate)
349{
350 if (rate >= 37501) {
351 state->deci = 0; state->csel = 0; state->rsel = 0;
352 } else if (rate >= 30001) {
353 state->deci = 0; state->csel = 0; state->rsel = 1;
354 } else if (rate >= 26251) {
355 state->deci = 0; state->csel = 1; state->rsel = 0;
356 } else if (rate >= 22501) {
357 state->deci = 0; state->csel = 1; state->rsel = 1;
358 } else if (rate >= 18751) {
359 state->deci = 1; state->csel = 0; state->rsel = 0;
360 } else if (rate >= 15001) {
361 state->deci = 1; state->csel = 0; state->rsel = 1;
362 } else if (rate >= 13126) {
363 state->deci = 1; state->csel = 1; state->rsel = 0;
364 } else if (rate >= 11251) {
365 state->deci = 1; state->csel = 1; state->rsel = 1;
366 } else if (rate >= 9376) {
367 state->deci = 2; state->csel = 0; state->rsel = 0;
368 } else if (rate >= 7501) {
369 state->deci = 2; state->csel = 0; state->rsel = 1;
370 } else if (rate >= 6563) {
371 state->deci = 2; state->csel = 1; state->rsel = 0;
372 } else if (rate >= 5626) {
373 state->deci = 2; state->csel = 1; state->rsel = 1;
374 } else if (rate >= 4688) {
375 state->deci = 3; state->csel = 0; state->rsel = 0;
376 } else if (rate >= 3751) {
377 state->deci = 3; state->csel = 0; state->rsel = 1;
378 } else if (rate >= 3282) {
379 state->deci = 3; state->csel = 1; state->rsel = 0;
380 } else if (rate >= 2814) {
381 state->deci = 3; state->csel = 1; state->rsel = 1;
382 } else if (rate >= 2344) {
383 state->deci = 4; state->csel = 0; state->rsel = 0;
384 } else if (rate >= 1876) {
385 state->deci = 4; state->csel = 0; state->rsel = 1;
386 } else if (rate >= 1641) {
387 state->deci = 4; state->csel = 1; state->rsel = 0;
388 } else if (rate >= 1407) {
389 state->deci = 4; state->csel = 1; state->rsel = 1;
390 } else if (rate >= 1172) {
391 state->deci = 5; state->csel = 0; state->rsel = 0;
392 } else if (rate >= 939) {
393 state->deci = 5; state->csel = 0; state->rsel = 1;
394 } else if (rate >= 821) {
395 state->deci = 5; state->csel = 1; state->rsel = 0;
396 } else {
397 state->deci = 5; state->csel = 1; state->rsel = 1;
398 }
399
400 if (state->csel == 0)
401 state->master_clk = 92000;
402 else
403 state->master_clk = 61333;
404
405}
406
407static int signal_det(struct mb86a16_state *state,
408 int smrt,
409 unsigned char *SIG)
410{
411
412 int ret ;
413 int smrtd ;
414 int wait_sym ;
415 int wait_t ;
416 unsigned char S[3] ;
417 int i ;
418
419 if (*SIG > 45) {
420 if (CNTM_set(state, 2, 1, 2) < 0) {
421 dprintk(verbose, MB86A16_ERROR, 1, "CNTM set Error");
422 return -1;
423 }
424 wait_sym = 40000;
425 } else {
426 if (CNTM_set(state, 3, 1, 2) < 0) {
427 dprintk(verbose, MB86A16_ERROR, 1, "CNTM set Error");
428 return -1;
429 }
430 wait_sym = 80000;
431 }
432 for (i = 0; i < 3; i++) {
433 if (i == 0 )
434 smrtd = smrt * 98 / 100;
435 else if (i == 1)
436 smrtd = smrt;
437 else
438 smrtd = smrt * 102 / 100;
439 smrt_info_get(state, smrtd);
440 smrt_set(state, smrtd);
441 srst(state);
442 wait_t = (wait_sym + 99 * smrtd / 100) / smrtd;
443 if (wait_t == 0)
444 wait_t = 1;
445 msleep_interruptible(10);
446 if (mb86a16_read(state, 0x37, &(S[i])) != 2) {
447 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
448 return -EREMOTEIO;
449 }
450 }
451 if ((S[1] > S[0] * 112 / 100) &&
452 (S[1] > S[2] * 112 / 100)) {
453
454 ret = 1;
455 } else {
456 ret = 0;
457 }
458 *SIG = S[1];
459
460 if (CNTM_set(state, 0, 1, 2) < 0) {
461 dprintk(verbose, MB86A16_ERROR, 1, "CNTM set Error");
462 return -1;
463 }
464
465 return ret;
466}
467
468static int rf_val_set(struct mb86a16_state *state,
469 int f,
470 int smrt,
471 unsigned char R)
472{
473 unsigned char C, F, B;
474 int M;
475 unsigned char rf_val[5];
476 int ack = -1;
477
478 if (smrt > 37750 )
479 C = 1;
480 else if (smrt > 18875)
481 C = 2;
482 else if (smrt > 5500 )
483 C = 3;
484 else
485 C = 4;
486
487 if (smrt > 30500)
488 F = 3;
489 else if (smrt > 9375)
490 F = 1;
491 else if (smrt > 4625)
492 F = 0;
493 else
494 F = 2;
495
496 if (f < 1060)
497 B = 0;
498 else if (f < 1175)
499 B = 1;
500 else if (f < 1305)
501 B = 2;
502 else if (f < 1435)
503 B = 3;
504 else if (f < 1570)
505 B = 4;
506 else if (f < 1715)
507 B = 5;
508 else if (f < 1845)
509 B = 6;
510 else if (f < 1980)
511 B = 7;
512 else if (f < 2080)
513 B = 8;
514 else
515 B = 9;
516
517 M = f * (1 << R) / 2;
518
519 rf_val[0] = 0x01 | (C << 3) | (F << 1);
520 rf_val[1] = (R << 5) | ((M & 0x1f000) >> 12);
521 rf_val[2] = (M & 0x00ff0) >> 4;
522 rf_val[3] = ((M & 0x0000f) << 4) | B;
523
524 // Frequency Set
525 if (mb86a16_write(state, 0x21, rf_val[0]) < 0)
526 ack = 0;
527 if (mb86a16_write(state, 0x22, rf_val[1]) < 0)
528 ack = 0;
529 if (mb86a16_write(state, 0x23, rf_val[2]) < 0)
530 ack = 0;
531 if (mb86a16_write(state, 0x24, rf_val[3]) < 0)
532 ack = 0;
533 if (mb86a16_write(state, 0x25, 0x01) < 0)
534 ack = 0;
535 if (ack == 0) {
536 dprintk(verbose, MB86A16_ERROR, 1, "RF Setup - I2C transfer error");
537 return -EREMOTEIO;
538 }
539
540 return 0;
541}
542
543static int afcerr_chk(struct mb86a16_state *state)
544{
545 unsigned char AFCM_L, AFCM_H ;
546 int AFCM ;
547 int afcm, afcerr ;
548
549 if (mb86a16_read(state, 0x0e, &AFCM_L) != 2)
550 goto err;
551 if (mb86a16_read(state, 0x0f, &AFCM_H) != 2)
552 goto err;
553
554 AFCM = (AFCM_H << 8) + AFCM_L;
555
556 if (AFCM > 2048)
557 afcm = AFCM - 4096;
558 else
559 afcm = AFCM;
560 afcerr = afcm * state->master_clk / 8192;
561
562 return afcerr;
563
564err:
565 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
566 return -EREMOTEIO;
567}
568
569static int dagcm_val_get(struct mb86a16_state *state)
570{
571 int DAGCM;
572 unsigned char DAGCM_H, DAGCM_L;
573
574 if (mb86a16_read(state, 0x45, &DAGCM_L) != 2)
575 goto err;
576 if (mb86a16_read(state, 0x46, &DAGCM_H) != 2)
577 goto err;
578
579 DAGCM = (DAGCM_H << 8) + DAGCM_L;
580
581 return DAGCM;
582
583err:
584 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
585 return -EREMOTEIO;
586}
587
588static int mb86a16_read_status(struct dvb_frontend *fe, fe_status_t *status)
589{
590 struct mb86a16_state *state = fe->demodulator_priv;
591
592 if (state->signal & 0x02)
593 *status |= FE_HAS_VITERBI;
594 if (state->signal & 0x01)
595 *status |= FE_HAS_SYNC;
596 if (state->signal & 0x03)
597 *status |= FE_HAS_LOCK;
598
599 return 0;
600}
601
602static int sync_chk(struct mb86a16_state *state,
603 unsigned char *VIRM)
604{
605 unsigned char val;
606 int sync;
607
608 if (mb86a16_read(state, 0x0d, &val) != 2)
609 goto err;
610
611 dprintk(verbose, MB86A16_INFO, 1, "Status = %02x,", val);
612 sync = val & 0x01;
613 *VIRM = (val & 0x1c) >> 2;
614
615 return sync;
616err:
617 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
618 return -EREMOTEIO;
619
620}
621
622static int freqerr_chk(struct mb86a16_state *state,
623 int fTP,
624 int smrt,
625 int unit)
626{
627 unsigned char CRM, AFCML, AFCMH;
628 unsigned char temp1, temp2, temp3;
629 int crm, afcm, AFCM;
630 int crrerr, afcerr; // [kHz]
631 int frqerr; // [MHz]
632 int afcen, afcexen = 0;
633 int R, M, fOSC, fOSC_OFS;
634
635 if (mb86a16_read(state, 0x43, &CRM) != 2)
636 goto err;
637
638 if (CRM > 127)
639 crm = CRM - 256;
640 else
641 crm = CRM;
642
643 crrerr = smrt * crm / 256;
644 if (mb86a16_read(state, 0x49, &temp1) != 2)
645 goto err;
646
647 afcen = (temp1 & 0x04) >> 2;
648 if (afcen == 0) {
649 if (mb86a16_read(state, 0x2a, &temp1) != 2)
650 goto err;
651 afcexen = (temp1 & 0x20) >> 5;
652 }
653
654 if (afcen == 1) {
655 if (mb86a16_read(state, 0x0e, &AFCML) != 2)
656 goto err;
657 if (mb86a16_read(state, 0x0f, &AFCMH) != 2)
658 goto err;
659 } else if (afcexen == 1) {
660 if (mb86a16_read(state, 0x2b, &AFCML) != 2)
661 goto err;
662 if (mb86a16_read(state, 0x2c, &AFCMH) != 2)
663 goto err;
664 }
665 if ((afcen == 1) || (afcexen == 1)) {
666 smrt_info_get(state, smrt);
667 AFCM = ((AFCMH & 0x01) << 8) + AFCML;
668 if (AFCM > 255)
669 afcm = AFCM - 512;
670 else
671 afcm = AFCM;
672
673 afcerr = afcm * state->master_clk / 8192;
674 } else
675 afcerr = 0;
676
677 if (mb86a16_read(state, 0x22, &temp1) != 2)
678 goto err;
679 if (mb86a16_read(state, 0x23, &temp2) != 2)
680 goto err;
681 if (mb86a16_read(state, 0x24, &temp3) != 2)
682 goto err;
683
684 R = (temp1 & 0xe0) >> 5;
685 M = ((temp1 & 0x1f) << 12) + (temp2 << 4) + (temp3 >> 4);
686 if (R == 0)
687 fOSC = 2 * M;
688 else
689 fOSC = M;
690
691 fOSC_OFS = fOSC - fTP;
692
693 if (unit == 0) { //[MHz]
694 if (crrerr + afcerr + fOSC_OFS * 1000 >= 0)
695 frqerr = (crrerr + afcerr + fOSC_OFS * 1000 + 500) / 1000;
696 else
697 frqerr = (crrerr + afcerr + fOSC_OFS * 1000 - 500) / 1000;
698 } else { //[kHz]
699 frqerr = crrerr + afcerr + fOSC_OFS * 1000;
700 }
701
702 return frqerr;
703err:
704 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
705 return -EREMOTEIO;
706}
707
708static unsigned char vco_dev_get(struct mb86a16_state *state, int smrt)
709{
710 unsigned char R;
711
712 if (smrt > 9375)
713 R = 0;
714 else
715 R = 1;
716
717 return R;
718}
719
720static void swp_info_get(struct mb86a16_state *state,
721 int fOSC_start,
722 int smrt,
723 int v, int R,
724 int swp_ofs,
725 int *fOSC,
726 int *afcex_freq,
727 unsigned char *AFCEX_L,
728 unsigned char *AFCEX_H)
729{
730 int AFCEX ;
731 int crnt_swp_freq ;
732
733 crnt_swp_freq = fOSC_start * 1000 + v * swp_ofs;
734
735 if (R == 0 )
736 *fOSC = (crnt_swp_freq + 1000) / 2000 * 2;
737 else
738 *fOSC = (crnt_swp_freq + 500) / 1000;
739
740 if (*fOSC >= crnt_swp_freq)
741 *afcex_freq = *fOSC *1000 - crnt_swp_freq;
742 else
743 *afcex_freq = crnt_swp_freq - *fOSC * 1000;
744
745 AFCEX = *afcex_freq * 8192 / state->master_clk;
746 *AFCEX_L = AFCEX & 0x00ff;
747 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
748}
749
750
751static int swp_freq_calcuation(struct mb86a16_state *state, int i, int v, int *V, int vmax, int vmin,
752 int SIGMIN, int fOSC, int afcex_freq, int swp_ofs, unsigned char *SIG1)
753{
754 int swp_freq ;
755
756 if ((i % 2 == 1) && (v <= vmax)) {
757 // positive v (case 1)
758 if ((v - 1 == vmin) &&
759 (*(V + 30 + v) >= 0) &&
760 (*(V + 30 + v - 1) >= 0) &&
761 (*(V + 30 + v - 1) > *(V + 30 + v)) &&
762 (*(V + 30 + v - 1) > SIGMIN)) {
763
764 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
765 *SIG1 = *(V + 30 + v - 1);
766 } else if ((v == vmax) &&
767 (*(V + 30 + v) >= 0) &&
768 (*(V + 30 + v - 1) >= 0) &&
769 (*(V + 30 + v) > *(V + 30 + v - 1)) &&
770 (*(V + 30 + v) > SIGMIN)) {
771 // (case 2)
772 swp_freq = fOSC * 1000 + afcex_freq;
773 *SIG1 = *(V + 30 + v);
774 } else if ((*(V + 30 + v) > 0) &&
775 (*(V + 30 + v - 1) > 0) &&
776 (*(V + 30 + v - 2) > 0) &&
777 (*(V + 30 + v - 3) > 0) &&
778 (*(V + 30 + v - 1) > *(V + 30 + v)) &&
779 (*(V + 30 + v - 2) > *(V + 30 + v - 3)) &&
780 ((*(V + 30 + v - 1) > SIGMIN) ||
781 (*(V + 30 + v - 2) > SIGMIN))) {
782 // (case 3)
783 if (*(V + 30 + v - 1) >= *(V + 30 + v - 2)) {
784 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
785 *SIG1 = *(V + 30 + v - 1);
786 } else {
787 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs * 2;
788 *SIG1 = *(V + 30 + v - 2);
789 }
790 } else if ((v == vmax) &&
791 (*(V + 30 + v) >= 0) &&
792 (*(V + 30 + v - 1) >= 0) &&
793 (*(V + 30 + v - 2) >= 0) &&
794 (*(V + 30 + v) > *(V + 30 + v - 2)) &&
795 (*(V + 30 + v - 1) > *(V + 30 + v - 2)) &&
796 ((*(V + 30 + v) > SIGMIN) ||
797 (*(V + 30 + v - 1) > SIGMIN))) {
798 // (case 4)
799 if (*(V + 30 + v) >= *(V + 30 + v - 1)) {
800 swp_freq = fOSC * 1000 + afcex_freq;
801 *SIG1 = *(V + 30 + v);
802 } else {
803 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
804 *SIG1 = *(V + 30 + v - 1);
805 }
806 } else {
807 swp_freq = -1 ;
808 }
809 } else if ((i % 2 == 0) && (v >= vmin)) {
810 // Negative v (case 1)
811 if ((*(V + 30 + v) > 0) &&
812 (*(V + 30 + v + 1) > 0) &&
813 (*(V + 30 + v + 2) > 0) &&
814 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
815 (*(V + 30 + v + 1) > *(V + 30 + v + 2)) &&
816 (*(V + 30 + v + 1) > SIGMIN)) {
817
818 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
819 *SIG1 = *(V + 30 + v + 1);
820 } else if ((v + 1 == vmax) &&
821 (*(V + 30 + v) >= 0) &&
822 (*(V + 30 + v + 1) >= 0) &&
823 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
824 (*(V + 30 + v + 1) > SIGMIN)) {
825 // (case 2)
826 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
827 *SIG1 = *(V + 30 + v);
828 } else if ((v == vmin) &&
829 (*(V + 30 + v) > 0) &&
830 (*(V + 30 + v + 1) > 0) &&
831 (*(V + 30 + v + 2) > 0) &&
832 (*(V + 30 + v) > *(V + 30 + v + 1)) &&
833 (*(V + 30 + v) > *(V + 30 + v + 2)) &&
834 (*(V + 30 + v) > SIGMIN)) {
835 // (case 3)
836 swp_freq = fOSC * 1000 + afcex_freq;
837 *SIG1 = *(V + 30 + v);
838 } else if ((*(V + 30 + v) >= 0) &&
839 (*(V + 30 + v + 1) >= 0) &&
840 (*(V + 30 + v + 2) >= 0) &&
841 (*(V +30 + v + 3) >= 0) &&
842 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
843 (*(V + 30 + v + 2) > *(V + 30 + v + 3)) &&
844 ((*(V + 30 + v + 1) > SIGMIN) ||
845 (*(V + 30 + v + 2) > SIGMIN))) {
846 // (case 4)
847 if (*(V + 30 + v + 1) >= *(V + 30 + v + 2)) {
848 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
849 *SIG1 = *(V + 30 + v + 1);
850 } else {
851 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs * 2;
852 *SIG1 = *(V + 30 + v + 2);
853 }
854 } else if ((*(V + 30 + v) >= 0) &&
855 (*(V + 30 + v + 1) >= 0) &&
856 (*(V + 30 + v + 2) >= 0) &&
857 (*(V + 30 + v + 3) >= 0) &&
858 (*(V + 30 + v) > *(V + 30 + v + 2)) &&
859 (*(V + 30 + v + 1) > *(V + 30 + v + 2)) &&
860 (*(V + 30 + v) > *(V + 30 + v + 3)) &&
861 (*(V + 30 + v + 1) > *(V + 30 + v + 3)) &&
862 ((*(V + 30 + v) > SIGMIN) ||
863 (*(V + 30 + v + 1) > SIGMIN))) {
864 // (case 5)
865 if (*(V + 30 + v) >= *(V + 30 + v + 1)) {
866 swp_freq = fOSC * 1000 + afcex_freq;
867 *SIG1 = *(V + 30 + v);
868 } else {
869 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
870 *SIG1 = *(V + 30 + v + 1);
871 }
872 } else if ((v + 2 == vmin) &&
873 (*(V + 30 + v) >= 0) &&
874 (*(V + 30 + v + 1) >= 0) &&
875 (*(V + 30 + v + 2) >= 0) &&
876 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
877 (*(V + 30 + v + 2) > *(V + 30 + v)) &&
878 ((*(V + 30 + v + 1) > SIGMIN) ||
879 (*(V + 30 + v + 2) > SIGMIN))) {
880 // (case 6)
881 if (*(V + 30 + v + 1) >= *(V + 30 + v + 2)) {
882 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
883 *SIG1 = *(V + 30 + v + 1);
884 } else {
885 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs * 2;
886 *SIG1 = *(V + 30 + v + 2);
887 }
888 } else if ((vmax == 0) && (vmin == 0) && (*(V + 30 + v) > SIGMIN)) {
889 swp_freq = fOSC * 1000;
890 *SIG1 = *(V + 30 + v);
891 } else swp_freq = -1;
892 } else swp_freq = -1;
893
894 return swp_freq;
895}
896
897static void swp_info_get2(struct mb86a16_state *state,
898 int smrt,
899 int R,
900 int swp_freq,
901 int *afcex_freq,
902 int *fOSC,
903 unsigned char *AFCEX_L,
904 unsigned char *AFCEX_H)
905{
906 int AFCEX ;
907
908 if (R == 0)
909 *fOSC = (swp_freq + 1000) / 2000 * 2;
910 else
911 *fOSC = (swp_freq + 500) / 1000;
912
913 if (*fOSC >= swp_freq)
914 *afcex_freq = *fOSC * 1000 - swp_freq;
915 else
916 *afcex_freq = swp_freq - *fOSC * 1000;
917
918 AFCEX = *afcex_freq * 8192 / state->master_clk;
919 *AFCEX_L = AFCEX & 0x00ff;
920 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
921}
922
923static void afcex_info_get(struct mb86a16_state *state,
924 int afcex_freq,
925 unsigned char *AFCEX_L,
926 unsigned char *AFCEX_H)
927{
928 int AFCEX ;
929
930 AFCEX = afcex_freq * 8192 / state->master_clk;
931 *AFCEX_L = AFCEX & 0x00ff;
932 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
933}
934
935static int SEQ_set(struct mb86a16_state *state, unsigned char loop)
936{
937 // SLOCK0 = 0
938 if (mb86a16_write(state, 0x32, 0x02 | (loop << 2)) < 0) {
939 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
940 return -EREMOTEIO;
941 }
942
943 return 0;
944}
945
946static int iq_vt_set(struct mb86a16_state *state, unsigned char IQINV)
947{
948 // Viterbi Rate, IQ Settings
949 if (mb86a16_write(state, 0x06, 0xdf | (IQINV << 5)) < 0) {
950 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
951 return -EREMOTEIO;
952 }
953
954 return 0;
955}
956
957static int FEC_srst(struct mb86a16_state *state)
958{
959 if (mb86a16_write(state, MB86A16_RESET, 0x02) < 0) {
960 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
961 return -EREMOTEIO;
962 }
963
964 return 0;
965}
966
967static int S2T_set(struct mb86a16_state *state, unsigned char S2T)
968{
969 if (mb86a16_write(state, 0x34, 0x70 | S2T) < 0) {
970 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
971 return -EREMOTEIO;
972 }
973
974 return 0;
975}
976
977static int S45T_set(struct mb86a16_state *state, unsigned char S4T, unsigned char S5T)
978{
979 if (mb86a16_write(state, 0x35, 0x00 | (S5T << 4) | S4T) < 0) {
980 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
981 return -EREMOTEIO;
982 }
983
984 return 0;
985}
986
987
988static int mb86a16_set_fe(struct mb86a16_state *state)
989{
990 u8 agcval, cnmval;
991
992 int i, j;
993 int fOSC = 0;
994 int fOSC_start = 0;
995 int wait_t;
996 int fcp;
997 int swp_ofs;
998 int V[60];
999 u8 SIG1MIN;
1000
1001 unsigned char CREN, AFCEN, AFCEXEN;
1002 unsigned char SIG1;
1003 unsigned char TIMINT1, TIMINT2, TIMEXT;
1004 unsigned char S0T, S1T;
1005 unsigned char S2T;
1006// unsigned char S2T, S3T;
1007 unsigned char S4T, S5T;
1008 unsigned char AFCEX_L, AFCEX_H;
1009 unsigned char R;
1010 unsigned char VIRM;
1011 unsigned char ETH, VIA;
1012 unsigned char junk;
1013
1014 int loop;
1015 int ftemp;
1016 int v, vmax, vmin;
1017 int vmax_his, vmin_his;
1018 int swp_freq, prev_swp_freq[20];
1019 int prev_freq_num;
1020 int signal_dupl;
1021 int afcex_freq;
1022 int signal;
1023 int afcerr;
1024 int temp_freq, delta_freq;
1025 int dagcm[4];
1026 int smrt_d;
1027// int freq_err;
1028 int n;
1029 int ret = -1;
1030 int sync;
1031
1032 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
1033
1034 fcp = 5000; // (carrier recovery [kHz])
1035// fcp = 3000;
1036 swp_ofs = state->srate / 4;
1037
1038 for (i = 0; i < 60; i++)
1039 V[i] = -1;
1040
1041 for (i = 0; i < 20; i++)
1042 prev_swp_freq[i] = 0;
1043
1044 SIG1MIN = 25;
1045
1046 for (n = 0; ((n < 3) && (ret == -1)); n++) {
1047 SEQ_set(state, 0);
1048 iq_vt_set(state, 0);
1049
1050 CREN = 0;
1051 AFCEN = 0;
1052 AFCEXEN = 1;
1053 TIMINT1 = 0;
1054 TIMINT2 = 1;
1055 TIMEXT = 2;
1056 S1T = 0;
1057 S0T = 0;
1058
1059 if (initial_set(state) < 0) {
1060 dprintk(verbose, MB86A16_ERROR, 1, "initial set failed");
1061 return -1;
1062 }
1063 if (DAGC_data_set(state, 3, 2) < 0) {
1064 dprintk(verbose, MB86A16_ERROR, 1, "DAGC data set error");
1065 return -1;
1066 }
1067 if (EN_set(state, CREN, AFCEN) < 0) {
1068 dprintk(verbose, MB86A16_ERROR, 1, "EN set error");
1069 return -1; // (0, 0)
1070 }
1071 if (AFCEXEN_set(state, AFCEXEN, state->srate) < 0) {
1072 dprintk(verbose, MB86A16_ERROR, 1, "AFCEXEN set error");
1073 return -1; // (1, smrt) = (1, symbolrate)
1074 }
1075 if (CNTM_set(state, TIMINT1, TIMINT2, TIMEXT) < 0) {
1076 dprintk(verbose, MB86A16_ERROR, 1, "CNTM set error");
1077 return -1; // (0, 1, 2)
1078 }
1079 if (S01T_set(state, S1T, S0T) < 0) {
1080 dprintk(verbose, MB86A16_ERROR, 1, "S01T set error");
1081 return -1; // (0, 0)
1082 }
1083 smrt_info_get(state, state->srate);
1084 if (smrt_set(state, state->srate) < 0) {
1085 dprintk(verbose, MB86A16_ERROR, 1, "smrt info get error");
1086 return -1;
1087 }
1088
1089 R = vco_dev_get(state, state->srate);
1090 if (R == 1)
1091 fOSC_start = state->frequency;
1092
1093 else if (R == 0) {
1094 if (state->frequency % 2 == 0) {
1095 fOSC_start = state->frequency;
1096 } else {
1097 fOSC_start = state->frequency + 1;
1098 if (fOSC_start > 2150)
1099 fOSC_start = state->frequency - 1;
1100 }
1101 }
1102 loop = 1;
1103 ftemp = fOSC_start * 1000;
1104 vmax = 0 ;
1105 while (loop == 1) {
1106 ftemp = ftemp + swp_ofs;
1107 vmax++;
1108
1109 // Upper bound
1110 if (ftemp > 2150000) {
1111 loop = 0;
1112 vmax--;
1113 }
1114 else if ((ftemp == 2150000) || (ftemp - state->frequency * 1000 >= fcp + state->srate / 4))
1115 loop = 0;
1116 }
1117
1118 loop = 1;
1119 ftemp = fOSC_start * 1000;
1120 vmin = 0 ;
1121 while (loop == 1) {
1122 ftemp = ftemp - swp_ofs;
1123 vmin--;
1124
1125 // Lower bound
1126 if (ftemp < 950000) {
1127 loop = 0;
1128 vmin++;
1129 }
1130 else if ((ftemp == 950000) || (state->frequency * 1000 - ftemp >= fcp + state->srate / 4))
1131 loop = 0;
1132 }
1133
1134 wait_t = (8000 + state->srate / 2) / state->srate;
1135 if (wait_t == 0)
1136 wait_t = 1;
1137
1138 i = 0;
1139 j = 0;
1140 prev_freq_num = 0;
1141 loop = 1;
1142 signal = 0;
1143 vmax_his = 0;
1144 vmin_his = 0;
1145 v = 0;
1146
1147 while (loop == 1) {
1148 swp_info_get(state, fOSC_start, state->srate,
1149 v, R, swp_ofs, &fOSC,
1150 &afcex_freq, &AFCEX_L, &AFCEX_H);
1151
1152 if (rf_val_set(state, fOSC, state->srate, R) < 0) {
1153 dprintk(verbose, MB86A16_ERROR, 1, "rf val set error");
1154 return -1;
1155 }
1156
1157 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1158 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set error");
1159 return -1;
1160 }
1161 if (srst(state) < 0) {
1162 dprintk(verbose, MB86A16_ERROR, 1, "srst error");
1163 return -1;
1164 }
1165 msleep_interruptible(wait_t);
1166
1167 if (mb86a16_read(state, 0x37, &SIG1) != 2) {
1168 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1169 return -1;
1170 }
1171 V[30 + v] = SIG1 ;
1172 swp_freq = swp_freq_calcuation(state, i, v, V, vmax, vmin,
1173 SIG1MIN, fOSC, afcex_freq,
1174 swp_ofs, &SIG1); //changed
1175
1176 signal_dupl = 0;
1177 for (j = 0; j < prev_freq_num; j++) {
1178 if ((ABS(prev_swp_freq[j] - swp_freq)) < (swp_ofs * 3 / 2)) {
1179 signal_dupl = 1;
1180 dprintk(verbose, MB86A16_INFO, 1, "Probably Duplicate Signal, j = %d", j);
1181 }
1182 }
1183 if ((signal_dupl == 0) && (swp_freq > 0) && (ABS(swp_freq - state->frequency * 1000) < fcp + state->srate / 6)) {
1184 dprintk(verbose, MB86A16_DEBUG, 1, "------ Signal detect ------ [swp_freq=[%07d, srate=%05d]]", swp_freq, state->srate);
1185 prev_swp_freq[prev_freq_num] = swp_freq;
1186 prev_freq_num++;
1187 swp_info_get2(state, state->srate, R, swp_freq,
1188 &afcex_freq, &fOSC,
1189 &AFCEX_L, &AFCEX_H);
1190
1191 if (rf_val_set(state, fOSC, state->srate, R) < 0) {
1192 dprintk(verbose, MB86A16_ERROR, 1, "rf val set error");
1193 return -1;
1194 }
1195 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1196 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set error");
1197 return -1;
1198 }
1199 signal = signal_det(state, state->srate, &SIG1);
1200 if (signal == 1) {
1201 dprintk(verbose, MB86A16_ERROR, 1, "***** Signal Found *****");
1202 loop = 0;
1203 } else {
1204 dprintk(verbose, MB86A16_ERROR, 1, "!!!!! No signal !!!!!, try again...");
1205 smrt_info_get(state, state->srate);
1206 if (smrt_set(state, state->srate) < 0) {
1207 dprintk(verbose, MB86A16_ERROR, 1, "smrt set error");
1208 return -1;
1209 }
1210 }
1211 }
1212 if (v > vmax)
1213 vmax_his = 1 ;
1214 if (v < vmin)
1215 vmin_his = 1 ;
1216 i++;
1217
1218 if ((i % 2 == 1) && (vmax_his == 1))
1219 i++;
1220 if ((i % 2 == 0) && (vmin_his == 1))
1221 i++;
1222
1223 if (i % 2 == 1)
1224 v = (i + 1) / 2;
1225 else
1226 v = -i / 2;
1227
1228 if ((vmax_his == 1) && (vmin_his == 1))
1229 loop = 0 ;
1230 }
1231
1232 if (signal == 1) {
1233 dprintk(verbose, MB86A16_INFO, 1, " Start Freq Error Check");
1234 S1T = 7 ;
1235 S0T = 1 ;
1236 CREN = 0 ;
1237 AFCEN = 1 ;
1238 AFCEXEN = 0 ;
1239
1240 if (S01T_set(state, S1T, S0T) < 0) {
1241 dprintk(verbose, MB86A16_ERROR, 1, "S01T set error");
1242 return -1;
1243 }
1244 smrt_info_get(state, state->srate);
1245 if (smrt_set(state, state->srate) < 0) {
1246 dprintk(verbose, MB86A16_ERROR, 1, "smrt set error");
1247 return -1;
1248 }
1249 if (EN_set(state, CREN, AFCEN) < 0) {
1250 dprintk(verbose, MB86A16_ERROR, 1, "EN set error");
1251 return -1;
1252 }
1253 if (AFCEXEN_set(state, AFCEXEN, state->srate) < 0) {
1254 dprintk(verbose, MB86A16_ERROR, 1, "AFCEXEN set error");
1255 return -1;
1256 }
1257 afcex_info_get(state, afcex_freq, &AFCEX_L, &AFCEX_H);
1258 if (afcofs_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1259 dprintk(verbose, MB86A16_ERROR, 1, "AFCOFS data set error");
1260 return -1;
1261 }
1262 if (srst(state) < 0) {
1263 dprintk(verbose, MB86A16_ERROR, 1, "srst error");
1264 return -1;
1265 }
1266 // delay 4~200
1267 wait_t = 200000 / state->master_clk + 200000 / state->srate;
1268 msleep(wait_t);
1269 afcerr = afcerr_chk(state);
1270 if (afcerr == -1)
1271 return -1;
1272
1273 swp_freq = fOSC * 1000 + afcerr ;
1274 AFCEXEN = 1 ;
1275 if (state->srate >= 1500)
1276 smrt_d = state->srate / 3;
1277 else
1278 smrt_d = state->srate / 2;
1279 smrt_info_get(state, smrt_d);
1280 if (smrt_set(state, smrt_d) < 0) {
1281 dprintk(verbose, MB86A16_ERROR, 1, "smrt set error");
1282 return -1;
1283 }
1284 if (AFCEXEN_set(state, AFCEXEN, smrt_d) < 0) {
1285 dprintk(verbose, MB86A16_ERROR, 1, "AFCEXEN set error");
1286 return -1;
1287 }
1288 R = vco_dev_get(state, smrt_d);
1289 if (DAGC_data_set(state, 2, 0) < 0) {
1290 dprintk(verbose, MB86A16_ERROR, 1, "DAGC data set error");
1291 return -1;
1292 }
1293 for (i = 0; i < 3; i++) {
1294 temp_freq = swp_freq + (i - 1) * state->srate / 8;
1295 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1296 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1297 dprintk(verbose, MB86A16_ERROR, 1, "rf val set error");
1298 return -1;
1299 }
1300 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1301 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set error");
1302 return -1;
1303 }
1304 wait_t = 200000 / state->master_clk + 40000 / smrt_d;
1305 msleep(wait_t);
1306 dagcm[i] = dagcm_val_get(state);
1307 }
1308 if ((dagcm[0] > dagcm[1]) &&
1309 (dagcm[0] > dagcm[2]) &&
1310 (dagcm[0] - dagcm[1] > 2 * (dagcm[2] - dagcm[1]))) {
1311
1312 temp_freq = swp_freq - 2 * state->srate / 8;
1313 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1314 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1315 dprintk(verbose, MB86A16_ERROR, 1, "rf val set error");
1316 return -1;
1317 }
1318 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1319 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set");
1320 return -1;
1321 }
1322 wait_t = 200000 / state->master_clk + 40000 / smrt_d;
1323 msleep(wait_t);
1324 dagcm[3] = dagcm_val_get(state);
1325 if (dagcm[3] > dagcm[1])
1326 delta_freq = (dagcm[2] - dagcm[0] + dagcm[1] - dagcm[3]) * state->srate / 300;
1327 else
1328 delta_freq = 0;
1329 } else if ((dagcm[2] > dagcm[1]) &&
1330 (dagcm[2] > dagcm[0]) &&
1331 (dagcm[2] - dagcm[1] > 2 * (dagcm[0] - dagcm[1]))) {
1332
1333 temp_freq = swp_freq + 2 * state->srate / 8;
1334 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1335 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1336 dprintk(verbose, MB86A16_ERROR, 1, "rf val set");
1337 return -1;
1338 }
1339 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1340 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set");
1341 return -1;
1342 }
1343 wait_t = 200000 / state->master_clk + 40000 / smrt_d;
1344 msleep(wait_t);
1345 dagcm[3] = dagcm_val_get(state);
1346 if (dagcm[3] > dagcm[1])
1347 delta_freq = (dagcm[2] - dagcm[0] + dagcm[3] - dagcm[1]) * state->srate / 300;
1348 else
1349 delta_freq = 0 ;
1350
1351 } else {
1352 delta_freq = 0 ;
1353 }
1354 dprintk(verbose, MB86A16_INFO, 1, "SWEEP Frequency = %d", swp_freq);
1355 swp_freq += delta_freq;
1356 dprintk(verbose, MB86A16_INFO, 1, "Adjusting .., DELTA Freq = %d, SWEEP Freq=%d", delta_freq, swp_freq);
1357 if (ABS(state->frequency * 1000 - swp_freq) > 3800) {
1358 dprintk(verbose, MB86A16_INFO, 1, "NO -- SIGNAL !");
1359 } else {
1360
1361 S1T = 0;
1362 S0T = 3;
1363 CREN = 1;
1364 AFCEN = 0;
1365 AFCEXEN = 1;
1366
1367 if (S01T_set(state, S1T, S0T) < 0) {
1368 dprintk(verbose, MB86A16_ERROR, 1, "S01T set error");
1369 return -1;
1370 }
1371 if (DAGC_data_set(state, 0, 0) < 0) {
1372 dprintk(verbose, MB86A16_ERROR, 1, "DAGC data set error");
1373 return -1;
1374 }
1375 R = vco_dev_get(state, state->srate);
1376 smrt_info_get(state, state->srate);
1377 if (smrt_set(state, state->srate) < 0) {
1378 dprintk(verbose, MB86A16_ERROR, 1, "smrt set error");
1379 return -1;
1380 }
1381 if (EN_set(state, CREN, AFCEN) < 0) {
1382 dprintk(verbose, MB86A16_ERROR, 1, "EN set error");
1383 return -1;
1384 }
1385 if (AFCEXEN_set(state, AFCEXEN, state->srate) < 0) {
1386 dprintk(verbose, MB86A16_ERROR, 1, "AFCEXEN set error");
1387 return -1;
1388 }
1389 swp_info_get2(state, state->srate, R, swp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1390 if (rf_val_set(state, fOSC, state->srate, R) < 0) {
1391 dprintk(verbose, MB86A16_ERROR, 1, "rf val set error");
1392 return -1;
1393 }
1394 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1395 dprintk(verbose, MB86A16_ERROR, 1, "afcex data set error");
1396 return -1;
1397 }
1398 if (srst(state) < 0) {
1399 dprintk(verbose, MB86A16_ERROR, 1, "srst error");
1400 return -1;
1401 }
1402 wait_t = 7 + (10000 + state->srate / 2) / state->srate;
1403 if (wait_t == 0)
1404 wait_t = 1;
1405 msleep_interruptible(wait_t);
1406 if (mb86a16_read(state, 0x37, &SIG1) != 2) {
1407 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1408 return -EREMOTEIO;
1409 }
1410
1411 if (SIG1 > 110) {
1412 S2T = 4; S4T = 1; S5T = 6; ETH = 4; VIA = 6;
1413 wait_t = 7 + (917504 + state->srate / 2) / state->srate;
1414 } else if (SIG1 > 105) {
1415 S2T = 4; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1416 wait_t = 7 + (1048576 + state->srate / 2) / state->srate;
1417 } else if (SIG1 > 85) {
1418 S2T = 5; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1419 wait_t = 7 + (1310720 + state->srate / 2) / state->srate;
1420 } else if (SIG1 > 65) {
1421 S2T = 6; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1422 wait_t = 7 + (1572864 + state->srate / 2) / state->srate;
1423 } else {
1424 S2T = 7; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1425 wait_t = 7 + (2097152 + state->srate / 2) / state->srate;
1426 }
1427 S2T_set(state, S2T);
1428 S45T_set(state, S4T, S5T);
1429 Vi_set(state, ETH, VIA);
1430 srst(state);
1431 msleep_interruptible(wait_t);
1432 sync = sync_chk(state, &VIRM);
1433 dprintk(verbose, MB86A16_INFO, 1, "-------- Viterbi=[%d] SYNC=[%d] ---------", VIRM, sync);
1434 if (mb86a16_read(state, 0x0d, &state->signal) != 2) {
1435 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1436 return -EREMOTEIO;
1437 }
1438 if (VIRM) {
1439 if (VIRM == 4) { // 5/6
1440 if (SIG1 > 110)
1441 wait_t = ( 786432 + state->srate / 2) / state->srate;
1442 else
1443 wait_t = (1572864 + state->srate / 2) / state->srate;
1444 if (state->srate < 5000)
1445 // FIXME ! , should be a long wait !
1446 msleep_interruptible(wait_t);
1447 else
1448 msleep_interruptible(wait_t);
1449
1450 if (sync_chk(state, &junk) == 0) {
1451 iq_vt_set(state, 1);
1452 FEC_srst(state);
1453 }
1454 if (SIG1 > 110)
1455 wait_t = ( 786432 + state->srate / 2) / state->srate;
1456 else
1457 wait_t = (1572864 + state->srate / 2) / state->srate;
1458
1459 msleep_interruptible(wait_t);
1460 SEQ_set(state, 1);
1461 } else { // 1/2, 2/3, 3/4, 7/8
1462 if (SIG1 > 110)
1463 wait_t = ( 786432 + state->srate / 2) / state->srate;
1464 else
1465 wait_t = (1572864 + state->srate / 2) / state->srate;
1466
1467 msleep_interruptible(wait_t);
1468 SEQ_set(state, 1);
1469 }
1470 } else {
1471 dprintk(verbose, MB86A16_INFO, 1, "NO -- SIGNAL");
1472 SEQ_set(state, 1);
1473 }
1474 }
1475 } else {
1476 dprintk (verbose, MB86A16_INFO, 1, "NO -- SIGNAL");
1477 }
1478
1479 sync = sync_chk(state, &junk);
1480 if (sync) {
1481 dprintk(verbose, MB86A16_INFO, 1, "******* SYNC *******");
1482 freqerr_chk(state, state->frequency, state->srate, 1);
1483 }
1484 }
1485
1486 mb86a16_read(state, 0x15, &agcval);
1487 mb86a16_read(state, 0x26, &cnmval);
1488 dprintk(verbose, MB86A16_INFO, 1, "AGC = %02x CNM = %02x", agcval, cnmval);
1489
1490 return ret;
1491}
1492
1493static int mb86a16_send_diseqc_msg(struct dvb_frontend *fe,
1494 struct dvb_diseqc_master_cmd *cmd)
1495{
1496 struct mb86a16_state *state = fe->demodulator_priv;
1497 int i;
1498 u8 regs;
1499
1500 if (mb86a16_write(state, MB86A16_DCC1, MB86A16_DCC1_DISTA) < 0)
1501 goto err;
1502 if (mb86a16_write(state, MB86A16_DCCOUT, 0x00) < 0)
1503 goto err;
1504 if (mb86a16_write(state, MB86A16_TONEOUT2, 0x04) < 0)
1505 goto err;
1506
1507 regs = 0x18;
1508
1509 if (cmd->msg_len > 5 || cmd->msg_len < 4)
1510 return -EINVAL;
1511
1512 for (i = 0; i < cmd->msg_len; i++) {
1513 if (mb86a16_write(state, regs, cmd->msg[i]) < 0)
1514 goto err;
1515
1516 regs++;
1517 }
1518 i += 0x90;
1519
1520 msleep_interruptible(10);
1521
1522 if (mb86a16_write(state, MB86A16_DCC1, i) < 0)
1523 goto err;
1524 if (mb86a16_write(state, MB86A16_DCCOUT, MB86A16_DCCOUT_DISEN) < 0)
1525 goto err;
1526
1527 return 0;
1528
1529err:
1530 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1531 return -EREMOTEIO;
1532}
1533
1534static int mb86a16_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst)
1535{
1536 struct mb86a16_state *state = fe->demodulator_priv;
1537
1538 switch (burst) {
1539 case SEC_MINI_A:
1540 if (mb86a16_write(state, MB86A16_DCC1, MB86A16_DCC1_DISTA |
1541 MB86A16_DCC1_TBEN |
1542 MB86A16_DCC1_TBO) < 0)
1543 goto err;
1544 if (mb86a16_write(state, MB86A16_DCCOUT, MB86A16_DCCOUT_DISEN) < 0)
1545 goto err;
1546 break;
1547 case SEC_MINI_B:
1548 if (mb86a16_write(state, MB86A16_DCC1, MB86A16_DCC1_DISTA |
1549 MB86A16_DCC1_TBEN) < 0)
1550 goto err;
1551 if (mb86a16_write(state, MB86A16_DCCOUT, MB86A16_DCCOUT_DISEN) < 0)
1552 goto err;
1553 break;
1554 }
1555
1556 return 0;
1557err:
1558 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1559 return -EREMOTEIO;
1560}
1561
1562static int mb86a16_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1563{
1564 struct mb86a16_state *state = fe->demodulator_priv;
1565
1566 switch (tone) {
1567 case SEC_TONE_ON:
1568 if (mb86a16_write(state, MB86A16_TONEOUT2, 0x00) < 0)
1569 goto err;
1570 if (mb86a16_write(state, MB86A16_DCC1, MB86A16_DCC1_DISTA |
1571 MB86A16_DCC1_CTOE) < 0)
1572
1573 goto err;
1574 if (mb86a16_write(state, MB86A16_DCCOUT, MB86A16_DCCOUT_DISEN) < 0)
1575 goto err;
1576 break;
1577 case SEC_TONE_OFF:
1578 if (mb86a16_write(state, MB86A16_TONEOUT2, 0x04) < 0)
1579 goto err;
1580 if (mb86a16_write(state, MB86A16_DCC1, MB86A16_DCC1_DISTA) < 0)
1581 goto err;
1582 if (mb86a16_write(state, MB86A16_DCCOUT, 0x00) < 0)
1583 goto err;
1584 break;
1585 default:
1586 return -EINVAL;
1587 }
1588 return 0;
1589
1590err:
1591 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1592 return -EREMOTEIO;
1593}
1594
1595#define MB86A16_FE_ALGO 1
1596
1597static int mb86a16_frontend_algo(struct dvb_frontend *fe)
1598{
1599 return MB86A16_FE_ALGO;
1600}
1601
1602static int mb86a16_set_frontend(struct dvb_frontend *fe,
1603 struct dvb_frontend_parameters *p,
1604 unsigned int mode_flags,
1605 int *delay,
1606 fe_status_t *status)
1607{
1608 int ret = 0;
1609 struct mb86a16_state *state = fe->demodulator_priv;
1610
1611 if (p != NULL) {
1612 state->frequency = p->frequency / 1000;
1613 state->srate = p->u.qpsk.symbol_rate / 1000;
1614 ret = mb86a16_set_fe(state);
1615 }
1616 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
1617 mb86a16_read_status(fe, status);
1618
1619 *delay = HZ/3000;
1620
1621 return ret;
1622}
1623
1624static void mb86a16_release(struct dvb_frontend *fe)
1625{
1626 struct mb86a16_state *state = fe->demodulator_priv;
1627 kfree(state);
1628}
1629
1630static int mb86a16_init(struct dvb_frontend *fe)
1631{
1632 return 0;
1633}
1634
1635static int mb86a16_sleep(struct dvb_frontend *fe)
1636{
1637 return 0;
1638}
1639
1640static int mb86a16_read_ber(struct dvb_frontend *fe, u32 *ber)
1641{
1642 return 0;
1643}
1644
1645static int mb86a16_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1646{
1647 *strength = 0;
1648
1649 return 0;
1650}
1651
1652struct cnr {
1653 u8 cn_reg;
1654 u8 cn_val;
1655};
1656
1657static const struct cnr cnr_tab[] = {
1658 { 35, 2 },
1659 { 40, 3 },
1660 { 50, 4 },
1661 { 60, 5 },
1662 { 70, 6 },
1663 { 80, 7 },
1664 { 92, 8 },
1665 { 103, 9 },
1666 { 115, 10 },
1667 { 138, 12 },
1668 { 162, 15 },
1669 { 180, 18 },
1670 { 185, 19 },
1671 { 189, 20 },
1672 { 195, 22 },
1673 { 199, 24 },
1674 { 201, 25 },
1675 { 202, 26 },
1676 { 203, 27 },
1677 { 205, 28 },
1678 { 208, 30 }
1679};
1680
1681static int mb86a16_read_snr(struct dvb_frontend *fe, u16 *snr)
1682{
1683 struct mb86a16_state *state = fe->demodulator_priv;
1684 int i = 0;
1685 int low_tide = 2, high_tide = 30, q_level;
1686 u8 cn;
1687
1688 if (mb86a16_read(state, 0x26, &cn) != 2) {
1689 dprintk(verbose, MB86A16_ERROR, 1, "I2C transfer error");
1690 return -EREMOTEIO;
1691 }
1692
1693 for (i = 0; i < ARRAY_SIZE(cnr_tab); i++) {
1694 if (cn < cnr_tab[i].cn_reg) {
1695 *snr = cnr_tab[i].cn_val;
1696 break;
1697 }
1698 }
1699 q_level = (*snr * 100) / (high_tide - low_tide);
1700 dprintk(verbose, MB86A16_ERROR, 1, "SNR (Quality) = [%d dB], Level=%d %%", *snr, q_level);
1701
1702 return 0;
1703}
1704
1705static int mb86a16_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1706{
1707 return 0;
1708}
1709
1710static struct dvb_frontend_ops mb86a16_ops = {
1711 .info = {
1712 .name = "Fujitsu MB86A16 DVB-S",
1713 .type = FE_QPSK,
1714 .frequency_min = 950000,
1715 .frequency_max = 2150000,
1716 .frequency_stepsize = 125,
1717 .frequency_tolerance = 0,
1718 .symbol_rate_min = 1000000,
1719 .symbol_rate_max = 45000000,
1720 .symbol_rate_tolerance = 500,
1721 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
1722 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 |
1723 FE_CAN_FEC_7_8 | FE_CAN_QPSK |
1724 FE_CAN_FEC_AUTO
1725 },
1726 .release = mb86a16_release,
1727 .tune = mb86a16_set_frontend,
1728 .read_status = mb86a16_read_status,
1729 .get_frontend_algo = mb86a16_frontend_algo,
1730 .init = mb86a16_init,
1731 .sleep = mb86a16_sleep,
1732 .read_status = mb86a16_read_status,
1733
1734 .read_ber = mb86a16_read_ber,
1735 .read_signal_strength = mb86a16_read_signal_strength,
1736 .read_snr = mb86a16_read_snr,
1737 .read_ucblocks = mb86a16_read_ucblocks,
1738
1739 .diseqc_send_master_cmd = mb86a16_send_diseqc_msg,
1740 .diseqc_send_burst = mb86a16_send_diseqc_burst,
1741 .set_tone = mb86a16_set_tone,
1742};
1743
1744struct dvb_frontend *mb86a16_attach(const struct mb86a16_config *config,
1745 struct i2c_adapter *i2c_adap)
1746{
1747 u8 dev_id = 0;
1748 struct mb86a16_state *state = NULL;
1749
1750 state = kmalloc(sizeof (struct mb86a16_state), GFP_KERNEL);
1751 if (state == NULL)
1752 goto error;
1753
1754 state->config = config;
1755 state->i2c_adap = i2c_adap;
1756
1757 mb86a16_read(state, 0x7f, &dev_id);
1758 if (dev_id != 0xfe)
1759 goto error;
1760
1761 memcpy(&state->frontend.ops, &mb86a16_ops, sizeof (struct dvb_frontend_ops));
1762 state->frontend.demodulator_priv = state;
1763 state->frontend.ops.set_voltage = state->config->set_voltage;
1764
1765 return &state->frontend;
1766error:
1767 kfree(state);
1768 return NULL;
1769}
1770EXPORT_SYMBOL(mb86a16_attach);
1771MODULE_LICENSE("GPL");
1772MODULE_AUTHOR("Manu Abraham");
diff --git a/drivers/media/dvb/frontends/mb86a16.h b/drivers/media/dvb/frontends/mb86a16.h
new file mode 100644
index 000000000000..b7545d0343f1
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a16.h
@@ -0,0 +1,38 @@
1/*
2 Fujitsu MB86A16 DVB-S/DSS DC Receiver driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MB86A16_H
22#define __MB86A16_H
23
24#include <linux/dvb/frontend.h>
25#include "dvb_frontend.h"
26
27
28struct mb86a16_config {
29 u8 demod_address;
30
31 int (*set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
32};
33
34extern struct dvb_frontend *mb86a16_attach(const struct mb86a16_config *config,
35 struct i2c_adapter *i2c_adap);
36
37
38#endif //__MB86A16_H
diff --git a/drivers/media/dvb/frontends/mb86a16_priv.h b/drivers/media/dvb/frontends/mb86a16_priv.h
new file mode 100644
index 000000000000..5de570068060
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a16_priv.h
@@ -0,0 +1,151 @@
1/*
2 Fujitsu MB86A16 DVB-S/DSS DC Receiver driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MB86A16_PRIV_H
22#define __MB86A16_PRIV_H
23
24#define MB86A16_TSOUT 0x00
25#define MB86A16_TSOUT_HIZSEL (0x01 << 5)
26#define MB86A16_TSOUT_HIZCNTI (0x01 << 4)
27#define MB86A16_TSOUT_MODE (0x01 << 3)
28#define MB86A16_TSOUT_ORDER (0x01 << 2)
29#define MB86A16_TSOUT_ERROR (0x01 << 1)
30#define Mb86A16_TSOUT_EDGE (0x01 << 0)
31
32#define MB86A16_FEC 0x01
33#define MB86A16_FEC_FSYNC (0x01 << 5)
34#define MB86A16_FEC_PCKB8 (0x01 << 4)
35#define MB86A16_FEC_DVDS (0x01 << 3)
36#define MB86A16_FEC_EREN (0x01 << 2)
37#define Mb86A16_FEC_RSEN (0x01 << 1)
38#define MB86A16_FEC_DIEN (0x01 << 0)
39
40#define MB86A16_AGC 0x02
41#define MB86A16_AGC_AGMD (0x01 << 6)
42#define MB86A16_AGC_AGCW (0x0f << 2)
43#define MB86A16_AGC_AGCP (0x01 << 1)
44#define MB86A16_AGC_AGCR (0x01 << 0)
45
46#define MB86A16_SRATE1 0x03
47#define MB86A16_SRATE1_DECI (0x07 << 2)
48#define MB86A16_SRATE1_CSEL (0x01 << 1)
49#define MB86A16_SRATE1_RSEL (0x01 << 0)
50
51#define MB86A16_SRATE2 0x04
52#define MB86A16_SRATE2_STOFSL (0xff << 0)
53
54#define MB86A16_SRATE3 0x05
55#define MB86A16_SRATE2_STOFSH (0xff << 0)
56
57#define MB86A16_VITERBI 0x06
58#define MB86A16_FRAMESYNC 0x07
59#define MB86A16_CRLFILTCOEF1 0x08
60#define MB86A16_CRLFILTCOEF2 0x09
61#define MB86A16_STRFILTCOEF1 0x0a
62#define MB86A16_STRFILTCOEF2 0x0b
63#define MB86A16_RESET 0x0c
64#define MB86A16_STATUS 0x0d
65#define MB86A16_AFCML 0x0e
66#define MB86A16_AFCMH 0x0f
67#define MB86A16_BERMON 0x10
68#define MB86A16_BERTAB 0x11
69#define MB86A16_BERLSB 0x12
70#define MB86A16_BERMID 0x13
71#define MB86A16_BERMSB 0x14
72#define MB86A16_AGCM 0x15
73
74#define MB86A16_DCC1 0x16
75#define MB86A16_DCC1_DISTA (0x01 << 7)
76#define MB86A16_DCC1_PRTY (0x01 << 6)
77#define MB86A16_DCC1_CTOE (0x01 << 5)
78#define MB86A16_DCC1_TBEN (0x01 << 4)
79#define MB86A16_DCC1_TBO (0x01 << 3)
80#define MB86A16_DCC1_NUM (0x07 << 0)
81
82#define MB86A16_DCC2 0x17
83#define MB86A16_DCC2_DCBST (0x01 << 0)
84
85#define MB86A16_DCC3 0x18
86#define MB86A16_DCC3_CODE0 (0xff << 0)
87
88#define MB86A16_DCC4 0x19
89#define MB86A16_DCC4_CODE1 (0xff << 0)
90
91#define MB86A16_DCC5 0x1a
92#define MB86A16_DCC5_CODE2 (0xff << 0)
93
94#define MB86A16_DCC6 0x1b
95#define MB86A16_DCC6_CODE3 (0xff << 0)
96
97#define MB86A16_DCC7 0x1c
98#define MB86A16_DCC7_CODE4 (0xff << 0)
99
100#define MB86A16_DCC8 0x1d
101#define MB86A16_DCC8_CODE5 (0xff << 0)
102
103#define MB86A16_DCCOUT 0x1e
104#define MB86A16_DCCOUT_DISEN (0x01 << 0)
105
106#define MB86A16_TONEOUT1 0x1f
107#define MB86A16_TONE_TDIVL (0xff << 0)
108
109#define MB86A16_TONEOUT2 0x20
110#define MB86A16_TONE_TMD (0x03 << 2)
111#define MB86A16_TONE_TDIVH (0x03 << 0)
112
113#define MB86A16_FREQ1 0x21
114#define MB86A16_FREQ2 0x22
115#define MB86A16_FREQ3 0x23
116#define MB86A16_FREQ4 0x24
117#define MB86A16_FREQSET 0x25
118#define MB86A16_CNM 0x26
119#define MB86A16_PORT0 0x27
120#define MB86A16_PORT1 0x28
121#define MB86A16_DRCFILT 0x29
122#define MB86A16_AFC 0x2a
123#define MB86A16_AFCEXL 0x2b
124#define MB86A16_AFCEXH 0x2c
125#define MB86A16_DAGC 0x2d
126#define MB86A16_SEQMODE 0x32
127#define MB86A16_S0S1T 0x33
128#define MB86A16_S2S3T 0x34
129#define MB86A16_S4S5T 0x35
130#define MB86A16_CNTMR 0x36
131#define MB86A16_SIG1 0x37
132#define MB86A16_SIG2 0x38
133#define MB86A16_VIMAG 0x39
134#define MB86A16_VISET1 0x3a
135#define MB86A16_VISET2 0x3b
136#define MB86A16_VISET3 0x3c
137#define MB86A16_FAGCS1 0x3d
138#define MB86A16_FAGCS2 0x3e
139#define MB86A16_FAGCS3 0x3f
140#define MB86A16_FAGCS4 0x40
141#define MB86A16_FAGCS5 0x41
142#define MB86A16_FAGCS6 0x42
143#define MB86A16_CRM 0x43
144#define MB86A16_STRM 0x44
145#define MB86A16_DAGCML 0x45
146#define MB86A16_DAGCMH 0x46
147#define MB86A16_QPSKTST 0x49
148#define MB86A16_DISTMON 0x52
149#define MB86A16_VERSION 0x7f
150
151#endif //__MB86A16_PRIV_H
diff --git a/drivers/media/dvb/mantis/Kconfig b/drivers/media/dvb/mantis/Kconfig
new file mode 100644
index 000000000000..4ba16d0ad96b
--- /dev/null
+++ b/drivers/media/dvb/mantis/Kconfig
@@ -0,0 +1,13 @@
1config DVB_MANTIS
2 tristate "MANTIS based cards"
3 depends on DVB_CORE && PCI && I2C
4 select DVB_MB86A16
5 select DVB_CU1216
6 select DVB_ZL10353
7 select DVB_STV0299
8 select DVB_PLL
9 help
10 Support for PCI cards based on the Mantis PCI bridge.
11 Say Y when you have a Mantis based DVB card and want to use it.
12
13 If unsure say N.
diff --git a/drivers/media/dvb/mantis/Makefile b/drivers/media/dvb/mantis/Makefile
new file mode 100644
index 000000000000..a980ff2382b7
--- /dev/null
+++ b/drivers/media/dvb/mantis/Makefile
@@ -0,0 +1,7 @@
1mantis-objs = mantis_core.o mantis_dma.o mantis_pci.o mantis_i2c.o \
2 mantis_dvb.o mantis_vp1033.o mantis_vp1034.o mantis_vp2033.o \
3 mantis_vp3030.o
4
5obj-$(CONFIG_DVB_MANTIS) += mantis.o
6
7EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/mantis/mantis_common.h b/drivers/media/dvb/mantis/mantis_common.h
new file mode 100644
index 000000000000..ba360f884967
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_common.h
@@ -0,0 +1,135 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_COMMON_H
22#define __MANTIS_COMMON_H
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/kernel.h>
27#include <linux/pci.h>
28
29#include "dvbdev.h"
30#include "dvb_demux.h"
31#include "dmxdev.h"
32#include "dvb_frontend.h"
33#include "dvb_net.h"
34#include <linux/i2c.h>
35#include "mantis_reg.h"
36
37#define MANTIS_ERROR 0
38#define MANTIS_NOTICE 1
39#define MANTIS_INFO 2
40#define MANTIS_DEBUG 3
41
42#define dprintk(x, y, z, format, arg...) do { \
43 if (z) { \
44 if ((x > MANTIS_ERROR) && (x > y)) \
45 printk(KERN_ERR "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
46 else if ((x > MANTIS_NOTICE) && (x > y)) \
47 printk(KERN_NOTICE "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
48 else if ((x > MANTIS_INFO) && (x > y)) \
49 printk(KERN_INFO "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
50 else if ((x > MANTIS_DEBUG) && (x > y)) \
51 printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg); \
52 } else { \
53 if (x > y) \
54 printk(format , ##arg); \
55 } \
56} while(0)
57
58#define mwrite(dat, addr) writel((dat), addr)
59#define mread(addr) readl(addr)
60
61#define mmwrite(dat, addr) mwrite((dat), (mantis->mantis_mmio + (addr)))
62#define mmread(addr) mread(mantis->mantis_mmio + (addr))
63#define mmand(dat, addr) mmwrite((dat) & mmread(addr), addr)
64#define mmor(dat, addr) mmwrite((dat) | mmread(addr), addr)
65#define mmaor(dat, addr) mmwrite((dat) | ((mask) & mmread(addr)), addr)
66
67
68struct mantis_pci {
69 /* PCI stuff */
70 u16 vendor_id;
71 u16 device_id;
72 u8 latency;
73
74 struct pci_dev *pdev;
75
76 unsigned long mantis_addr;
77 volatile void __iomem *mantis_mmio;
78
79 u8 irq;
80 u8 revision;
81
82 unsigned int num;
83 u16 ts_size;
84
85 /* RISC Core */
86 u32 finished_block;
87 u32 last_block;
88 u32 line_bytes;
89 u32 line_count;
90 u32 risc_pos;
91 u8 *buf_cpu;
92 dma_addr_t buf_dma;
93 u32 *risc_cpu;
94 dma_addr_t risc_dma;
95
96 struct tasklet_struct tasklet;
97
98 struct i2c_adapter adapter;
99 int i2c_rc;
100 wait_queue_head_t i2c_wq;
101
102 /* DVB stuff */
103 struct dvb_adapter dvb_adapter;
104 struct dvb_frontend *fe;
105 struct dvb_demux demux;
106 struct dmxdev dmxdev;
107 struct dmx_frontend fe_hw;
108 struct dmx_frontend fe_mem;
109 struct dvb_net dvbnet;
110
111 u8 feeds;
112
113 struct mantis_config *config;
114
115 u32 mantis_int_stat;
116 u32 mantis_int_mask;
117
118 /* board specific */
119 u8 mac_address[8];
120 u32 sub_vendor_id;
121 u32 sub_device_id;
122
123 /* A12 A13 A14 */
124 int gpio_status;};
125
126extern unsigned int verbose;
127extern unsigned int devs;
128extern unsigned int i2c;
129extern int mantis_dvb_init(struct mantis_pci *mantis);
130extern int mantis_frontend_init(struct mantis_pci *mantis);
131extern int mantis_dvb_exit(struct mantis_pci *mantis);
132extern void mantis_dma_xfer(unsigned long data);
133extern void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value);
134
135#endif //__MANTIS_COMMON_H
diff --git a/drivers/media/dvb/mantis/mantis_core.c b/drivers/media/dvb/mantis/mantis_core.c
new file mode 100644
index 000000000000..111227752452
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_core.c
@@ -0,0 +1,215 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_core.h"
23
24
25static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
26{
27 int err;
28 struct i2c_msg msg[] = {
29 {
30 .addr = 0x50,
31 .flags = 0,
32 .buf = data,
33 .len = 1
34 },{
35 .addr = 0x50,
36 .flags = I2C_M_RD,
37 .buf = data,
38 .len = length
39 },
40 };
41 if ((err = i2c_transfer(&mantis->adapter, msg, 2)) < 0) {
42 dprintk(verbose, MANTIS_ERROR, 1,
43 "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
44 err, data[0], data[1]);
45
46 return err;
47 }
48 msleep_interruptible(2);
49
50 return 0;
51}
52
53static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
54{
55 int err;
56
57 struct i2c_msg msg = {
58 .addr = 0x50,
59 .flags = 0,
60 .buf = data,
61 .len = length
62 };
63
64 if ((err = i2c_transfer(&mantis->adapter, &msg, 1)) < 0) {
65 dprintk(verbose, MANTIS_ERROR, 1,
66 "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
67 err, length, data[0], data[1]);
68
69 return err;
70 }
71
72 return 0;
73}
74
75static int get_subdevice_id(struct mantis_pci *mantis)
76{
77 int err;
78 static u8 sub_device_id[2];
79
80 mantis->sub_device_id = 0;
81 sub_device_id[0] = 0xfc;
82 if ((err = read_eeprom_byte(mantis, &sub_device_id[0], 2)) < 0) {
83 dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
84 return err;
85 }
86 mantis->sub_device_id = (sub_device_id[0] << 8) | sub_device_id[1];
87 dprintk(verbose, MANTIS_ERROR, 1, "Sub Device ID=[0x%04x]",
88 mantis->sub_device_id);
89
90 return 0;
91}
92
93static int get_subvendor_id(struct mantis_pci *mantis)
94{
95 int err;
96 static u8 sub_vendor_id[2];
97
98 mantis->sub_vendor_id = 0;
99 sub_vendor_id[0] = 0xfe;
100 if ((err = read_eeprom_byte(mantis, &sub_vendor_id[0], 2)) < 0) {
101 dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
102 return err;
103 }
104 mantis->sub_vendor_id = (sub_vendor_id[0] << 8) | sub_vendor_id[1];
105 dprintk(verbose, MANTIS_ERROR, 1, "Sub Vendor ID=[0x%04x]",
106 mantis->sub_vendor_id);
107
108 return 0;
109}
110
111static int get_mac_address(struct mantis_pci *mantis)
112{
113 int err;
114
115 mantis->mac_address[0] = 0x08;
116 if ((err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6)) < 0) {
117 dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
118
119 return err;
120 }
121 dprintk(verbose, MANTIS_ERROR, 1,
122 "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
123 mantis->mac_address[0], mantis->mac_address[1],
124 mantis->mac_address[2], mantis->mac_address[3],
125 mantis->mac_address[4], mantis->mac_address[5]);
126
127 return 0;
128}
129
130
131int mantis_core_init(struct mantis_pci *mantis)
132{
133 int err = 0;
134
135 if ((err = mantis_i2c_init(mantis)) < 0) {
136 dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
137 return err;
138 }
139 if ((err = get_mac_address(mantis)) < 0) {
140 dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
141 return err;
142 }
143 if ((err = get_subvendor_id(mantis)) < 0) {
144 dprintk(verbose, MANTIS_ERROR, 1, "get Sub vendor ID failed");
145 return err;
146 }
147 if ((err = get_subdevice_id(mantis)) < 0) {
148 dprintk(verbose, MANTIS_ERROR, 1, "get Sub device ID failed");
149 return err;
150 }
151 if ((err = mantis_dma_init(mantis)) < 0) {
152 dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
153 return err;
154 }
155 if ((err = mantis_dvb_init(mantis)) < 0) {
156 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
157 return err;
158 }
159
160 return 0;
161}
162
163int mantis_core_exit(struct mantis_pci *mantis)
164{
165
166 mantis_dma_stop(mantis);
167 dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping");
168 if (mantis_dma_exit(mantis) < 0)
169 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
170 if (mantis_dvb_exit(mantis) < 0)
171 dprintk(verbose, MANTIS_ERROR, 1, "DVB exit failed");
172 if (mantis_i2c_exit(mantis) < 0)
173 dprintk(verbose, MANTIS_ERROR, 1, "I2C adapter delete.. failed");
174
175 return 0;
176}
177
178void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
179{
180 u32 reg;
181
182 if (value)
183 reg = 0x0000;
184 else
185 reg = 0xffff;
186
187 reg = (value << bitpos);
188
189 mmwrite(mmread(MANTIS_GPIF_ADDR) | reg, MANTIS_GPIF_ADDR);
190 mmwrite(0x00, MANTIS_GPIF_DOUT);
191 udelay(100);
192 mmwrite(mmread(MANTIS_GPIF_ADDR) | reg, MANTIS_GPIF_ADDR);
193 mmwrite(0x00, MANTIS_GPIF_DOUT);
194}
195
196
197//direction = 0 , no CI passthrough ; 1 , CI passthrough
198void mantis_set_direction(struct mantis_pci *mantis, int direction)
199{
200 u32 reg;
201
202 reg = mmread(0x28);
203 dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
204 if (direction == 0x01) { //to CI
205 reg |= 0x04;
206 mmwrite(reg, 0x28);
207 reg &= 0xff - 0x04;
208 mmwrite(reg, 0x28);
209 } else {
210 reg &= 0xff - 0x04;
211 mmwrite(reg, 0x28);
212 reg |= 0x04;
213 mmwrite(reg, 0x28);
214 }
215}
diff --git a/drivers/media/dvb/mantis/mantis_core.h b/drivers/media/dvb/mantis/mantis_core.h
new file mode 100644
index 000000000000..31b2a756d99e
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_core.h
@@ -0,0 +1,61 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_CORE_H
22#define __MANTIS_CORE_H
23
24#include "mantis_common.h"
25
26
27#define FE_TYPE_SAT 0
28#define FE_TYPE_CAB 1
29#define FE_TYPE_TER 2
30
31#define FE_TYPE_TS204 0
32#define FE_TYPE_TS188 1
33
34
35struct vendorname {
36 __u8 *sub_vendor_name;
37 __u32 sub_vendor_id;
38};
39
40struct devicetype {
41 __u8 *sub_device_name;
42 __u32 sub_device_id;
43 __u8 device_type;
44 __u32 type_flags;
45};
46
47
48extern int mantis_dma_init(struct mantis_pci *mantis);
49extern int mantis_dma_exit(struct mantis_pci *mantis);
50extern void mantis_dma_start(struct mantis_pci *mantis);
51extern void mantis_dma_stop(struct mantis_pci *mantis);
52extern int mantis_i2c_init(struct mantis_pci *mantis);
53extern int mantis_i2c_exit(struct mantis_pci *mantis);
54extern int mantis_core_init(struct mantis_pci *mantis);
55extern int mantis_core_exit(struct mantis_pci *mantis);
56//extern void mantis_fe_powerup(struct mantis_pci *mantis);
57//extern void mantis_fe_powerdown(struct mantis_pci *mantis);
58//extern void mantis_fe_reset(struct dvb_frontend *fe);
59extern void mantis_set_direction(struct mantis_pci *mantis, int direction);
60
61#endif //__MANTIS_CORE_H
diff --git a/drivers/media/dvb/mantis/mantis_dma.c b/drivers/media/dvb/mantis/mantis_dma.c
new file mode 100644
index 000000000000..9e3aa5ec1645
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_dma.c
@@ -0,0 +1,238 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <asm/page.h>
22#include <linux/vmalloc.h>
23#include "mantis_common.h"
24
25#define RISC_WRITE (0x01 << 28)
26#define RISC_JUMP (0x07 << 28)
27#define RISC_IRQ (0x01 << 24)
28
29#define RISC_STATUS(status) ((((~status) & 0x0f) << 20) | ((status & 0x0f) << 16))
30#define RISC_FLUSH() mantis->risc_pos = 0
31#define RISC_INSTR(opcode) mantis->risc_cpu[mantis->risc_pos++] = cpu_to_le32(opcode)
32
33#define MANTIS_BUF_SIZE 64 * 1024
34#define MANTIS_BLOCK_BYTES (MANTIS_BUF_SIZE >> 4)
35#define MANTIS_BLOCK_COUNT (1 << 4)
36#define MANTIS_RISC_SIZE PAGE_SIZE
37
38int mantis_dma_exit(struct mantis_pci *mantis)
39{
40 if (mantis->buf_cpu) {
41 dprintk(verbose, MANTIS_ERROR, 1,
42 "DMA=0x%lx cpu=0x%p size=%d",
43 (unsigned long) mantis->buf_dma,
44 mantis->buf_cpu,
45 MANTIS_BUF_SIZE);
46
47 pci_free_consistent(mantis->pdev, MANTIS_BUF_SIZE,
48 mantis->buf_cpu, mantis->buf_dma);
49
50 mantis->buf_cpu = NULL;
51 }
52 if (mantis->risc_cpu) {
53 dprintk(verbose, MANTIS_ERROR, 1,
54 "RISC=0x%lx cpu=0x%p size=%lx",
55 (unsigned long) mantis->risc_dma,
56 mantis->risc_cpu,
57 MANTIS_RISC_SIZE);
58
59 pci_free_consistent(mantis->pdev, MANTIS_RISC_SIZE,
60 mantis->risc_cpu, mantis->risc_dma);
61
62 mantis->risc_cpu = NULL;
63 }
64
65 return 0;
66}
67
68static inline int mantis_alloc_buffers(struct mantis_pci *mantis)
69{
70 if (!mantis->buf_cpu) {
71 mantis->buf_cpu = pci_alloc_consistent(mantis->pdev,
72 MANTIS_BUF_SIZE,
73 &mantis->buf_dma);
74 if (!mantis->buf_cpu) {
75 dprintk(verbose, MANTIS_ERROR, 1,
76 "DMA buffer allocation failed");
77
78 goto err;
79 }
80 dprintk(verbose, MANTIS_ERROR, 1,
81 "DMA=0x%lx cpu=0x%p size=%d",
82 (unsigned long) mantis->buf_dma,
83 mantis->buf_cpu, MANTIS_BUF_SIZE);
84 }
85 if (!mantis->risc_cpu) {
86 mantis->risc_cpu = pci_alloc_consistent(mantis->pdev,
87 MANTIS_RISC_SIZE,
88 &mantis->risc_dma);
89
90 if (!mantis->risc_cpu) {
91 dprintk(verbose, MANTIS_ERROR, 1,
92 "RISC program allocation failed");
93
94 mantis_dma_exit(mantis);
95
96 goto err;
97 }
98 dprintk(verbose, MANTIS_ERROR, 1,
99 "RISC=0x%lx cpu=0x%p size=%lx",
100 (unsigned long) mantis->risc_dma,
101 mantis->risc_cpu, MANTIS_RISC_SIZE);
102 }
103
104 return 0;
105err:
106 dprintk(verbose, MANTIS_ERROR, 1, "Out of memory (?) .....");
107 return -ENOMEM;
108}
109
110static inline int mantis_calc_lines(struct mantis_pci *mantis)
111{
112 mantis->line_bytes = MANTIS_BLOCK_BYTES;
113 mantis->line_count = MANTIS_BLOCK_COUNT;
114
115 while (mantis->line_bytes > 4095) {
116 mantis->line_bytes >>= 1;
117 mantis->line_count <<= 1;
118 }
119
120 dprintk(verbose, MANTIS_DEBUG, 1,
121 "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]",
122 MANTIS_BLOCK_BYTES, mantis->line_bytes, mantis->line_count);
123
124 if (mantis->line_count > 255) {
125 dprintk(verbose, MANTIS_ERROR, 1, "Buffer size error");
126 return -EINVAL;
127 }
128
129 return 0;
130}
131
132int mantis_dma_init(struct mantis_pci *mantis)
133{
134 int err = 0;
135
136 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DMA init");
137 if (mantis_alloc_buffers(mantis) < 0) {
138 dprintk(verbose, MANTIS_ERROR, 1, "Error allocating DMA buffer");
139
140 // Stop RISC Engine
141// mmwrite(mmread(MANTIS_DMA_CTL) & ~MANTIS_RISC_EN, MANTIS_DMA_CTL);
142 mmwrite(0, MANTIS_DMA_CTL);
143
144 goto err;
145 }
146 if ((err = mantis_calc_lines(mantis)) < 0) {
147 dprintk(verbose, MANTIS_ERROR, 1, "Mantis calc lines failed");
148
149 goto err;
150 }
151
152 return 0;
153err:
154 return err;
155}
156
157
158
159static inline void mantis_risc_program(struct mantis_pci *mantis)
160{
161 u32 buf_pos = 0;
162 u32 line;
163
164 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis create RISC program");
165 RISC_FLUSH();
166
167 dprintk(verbose, MANTIS_DEBUG, 1, "risc len lines %u, bytes per line %u",
168 mantis->line_count, mantis->line_bytes);
169
170 for (line = 0; line < mantis->line_count; line++) {
171 dprintk(verbose, MANTIS_DEBUG, 1, "RISC PROG line=[%d]", line);
172 if (!(buf_pos % MANTIS_BLOCK_BYTES)) {
173 RISC_INSTR(RISC_WRITE |
174 RISC_IRQ |
175 RISC_STATUS(((buf_pos / MANTIS_BLOCK_BYTES) +
176 (MANTIS_BLOCK_COUNT - 1)) %
177 MANTIS_BLOCK_COUNT) |
178 mantis->line_bytes);
179 } else {
180 RISC_INSTR(RISC_WRITE | mantis->line_bytes);
181 }
182 RISC_INSTR(mantis->buf_dma + buf_pos);
183 buf_pos += mantis->line_bytes;
184 }
185 RISC_INSTR(RISC_JUMP);
186 RISC_INSTR(mantis->risc_dma);
187}
188
189void mantis_dma_start(struct mantis_pci *mantis)
190{
191 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Start DMA engine");
192
193 mantis_risc_program(mantis);
194 mmwrite(cpu_to_le32(mantis->risc_dma), MANTIS_RISC_START);
195 mmwrite(MANTIS_GPIF_RDWRN, MANTIS_GPIF_ADDR);
196
197 mmwrite(0, MANTIS_DMA_CTL);
198 mantis->last_block = mantis->finished_block = 0;
199
200 mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_RISCI, MANTIS_INT_MASK);
201
202 mmwrite(MANTIS_FIFO_EN | MANTIS_DCAP_EN
203 | MANTIS_RISC_EN, MANTIS_DMA_CTL);
204
205}
206
207void mantis_dma_stop(struct mantis_pci *mantis)
208{
209 u32 stat = 0, mask = 0;
210
211 stat = mmread(MANTIS_INT_STAT);
212 mask = mmread(MANTIS_INT_MASK);
213 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Stop DMA engine");
214
215 mmwrite((mmread(MANTIS_DMA_CTL) & ~(MANTIS_FIFO_EN |
216 MANTIS_DCAP_EN |
217 MANTIS_RISC_EN)), MANTIS_DMA_CTL);
218
219 mmwrite(mmread(MANTIS_INT_STAT), MANTIS_INT_STAT);
220
221 mmwrite(mmread(MANTIS_INT_MASK) & ~(MANTIS_INT_RISCI |
222 MANTIS_INT_RISCEN), MANTIS_INT_MASK);
223}
224
225
226void mantis_dma_xfer(unsigned long data)
227{
228 struct mantis_pci *mantis = (struct mantis_pci *) data;
229
230 while (mantis->last_block != mantis->finished_block) {
231 dprintk(verbose, MANTIS_DEBUG, 1, "last block=[%d] finished block=[%d]",
232 mantis->last_block, mantis->finished_block);
233
234 (mantis->ts_size ? dvb_dmx_swfilter_204: dvb_dmx_swfilter)
235 (&mantis->demux, &mantis->buf_cpu[mantis->last_block * MANTIS_BLOCK_BYTES], MANTIS_BLOCK_BYTES);
236 mantis->last_block = (mantis->last_block + 1) % MANTIS_BLOCK_COUNT;
237 }
238}
diff --git a/drivers/media/dvb/mantis/mantis_dvb.c b/drivers/media/dvb/mantis/mantis_dvb.c
new file mode 100644
index 000000000000..5830d4a7bda2
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_dvb.c
@@ -0,0 +1,304 @@
1/*
2 Mantis PCI bridge driver
3 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include <linux/bitops.h>
21#include "mantis_common.h"
22#include "mantis_core.h"
23
24#include "dmxdev.h"
25#include "dvbdev.h"
26#include "dvb_demux.h"
27#include "dvb_frontend.h"
28#include "mantis_vp1033.h"
29#include "mantis_vp1034.h"
30#include "mantis_vp2033.h"
31#include "mantis_vp3030.h"
32
33/* Tuner power supply control */
34void mantis_fe_powerup(struct mantis_pci *mantis)
35{
36 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power ON");
37 gpio_set_bits(mantis, 0x0c, 1);
38 msleep_interruptible(100);
39 gpio_set_bits(mantis, 0x0c, 1);
40 msleep_interruptible(100);
41}
42
43void mantis_fe_powerdown(struct mantis_pci *mantis)
44{
45 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power OFF");
46 gpio_set_bits(mantis, 0x0c, 0);
47}
48
49static int mantis_fe_reset(struct dvb_frontend *fe)
50{
51 struct mantis_pci *mantis = fe->dvb->priv;
52
53 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset");
54 gpio_set_bits(mantis, 13, 0);
55 msleep_interruptible(100);
56 gpio_set_bits(mantis, 13, 0);
57 msleep_interruptible(100);
58 gpio_set_bits(mantis, 13, 1);
59 msleep_interruptible(100);
60 gpio_set_bits(mantis, 13, 1);
61
62 return 0;
63}
64
65static int mantis_frontend_reset(struct mantis_pci *mantis)
66{
67 dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset");
68 gpio_set_bits(mantis, 13, 0);
69 msleep_interruptible(100);
70 gpio_set_bits(mantis, 13, 0);
71 msleep_interruptible(100);
72 gpio_set_bits(mantis, 13, 1);
73 msleep_interruptible(100);
74 gpio_set_bits(mantis, 13, 1);
75
76 return 0;
77}
78
79static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
80{
81 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
82 struct mantis_pci *mantis = dvbdmx->priv;
83
84 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Start feed");
85 if (!dvbdmx->dmx.frontend) {
86 dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?");
87 return -EINVAL;
88 }
89 mantis->feeds++;
90 dprintk(verbose, MANTIS_DEBUG, 1,
91 "mantis start feed, feeds=%d",
92 mantis->feeds);
93
94 if (mantis->feeds == 1) {
95 dprintk(verbose, MANTIS_DEBUG, 1, "mantis start feed & dma");
96 printk("mantis start feed & dma\n");
97 mantis_dma_start(mantis);
98 }
99
100 return mantis->feeds;
101}
102
103static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
104{
105 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
106 struct mantis_pci *mantis = dvbdmx->priv;
107
108 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Stop feed");
109 if (!dvbdmx->dmx.frontend) {
110 dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?");
111 return -EINVAL;
112 }
113 mantis->feeds--;
114 if (mantis->feeds == 0) {
115 dprintk(verbose, MANTIS_DEBUG, 1, "mantis stop feed and dma");
116 printk("mantis stop feed and dma\n");
117 mantis_dma_stop(mantis);
118 }
119 return 0;
120}
121
122int __devinit mantis_dvb_init(struct mantis_pci *mantis)
123{
124 int result;
125
126 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_register_adapter");
127 if (dvb_register_adapter(&mantis->dvb_adapter,
128 "Mantis dvb adapter", THIS_MODULE,
129 &mantis->pdev->dev) < 0) {
130
131 dprintk(verbose, MANTIS_ERROR, 1, "Error registering adapter");
132 return -ENODEV;
133 }
134 mantis->dvb_adapter.priv = mantis;
135 mantis->demux.dmx.capabilities = DMX_TS_FILTERING |
136 DMX_SECTION_FILTERING |
137 DMX_MEMORY_BASED_FILTERING;
138
139 mantis->demux.priv = mantis;
140 mantis->demux.filternum = 256;
141 mantis->demux.feednum = 256;
142 mantis->demux.start_feed = mantis_dvb_start_feed;
143 mantis->demux.stop_feed = mantis_dvb_stop_feed;
144 mantis->demux.write_to_decoder = NULL;
145 mantis->ts_size = 1; //188
146 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmx_init");
147 if ((result = dvb_dmx_init(&mantis->demux)) < 0) {
148 dprintk(verbose, MANTIS_ERROR, 1,
149 "dvb_dmx_init failed, ERROR=%d", result);
150
151 goto err0;
152 }
153 mantis->dmxdev.filternum = 256;
154 mantis->dmxdev.demux = &mantis->demux.dmx;
155 mantis->dmxdev.capabilities = 0;
156 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmxdev_init");
157 if ((result = dvb_dmxdev_init(&mantis->dmxdev,
158 &mantis->dvb_adapter)) < 0) {
159
160 dprintk(verbose, MANTIS_ERROR, 1,
161 "dvb_dmxdev_init failed, ERROR=%d", result);
162 goto err1;
163 }
164 mantis->fe_hw.source = DMX_FRONTEND_0;
165 if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
166 &mantis->fe_hw)) < 0) {
167
168 dprintk(verbose, MANTIS_ERROR, 1,
169 "dvb_dmx_init failed, ERROR=%d", result);
170
171 goto err2;
172 }
173 mantis->fe_mem.source = DMX_MEMORY_FE;
174 if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
175 &mantis->fe_mem)) < 0) {
176 dprintk(verbose, MANTIS_ERROR, 1,
177 "dvb_dmx_init failed, ERROR=%d", result);
178
179 goto err3;
180 }
181 if ((result = mantis->demux.dmx.connect_frontend(&mantis->demux.dmx,
182 &mantis->fe_hw)) < 0) {
183
184 dprintk(verbose, MANTIS_ERROR, 1,
185 "dvb_dmx_init failed, ERROR=%d", result);
186
187 goto err4;
188 }
189 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
190 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
191 mantis_frontend_init(mantis);
192 return 0;
193
194 /* Error conditions .. */
195err4:
196 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
197err3:
198 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_hw);
199err2:
200 dvb_dmxdev_release(&mantis->dmxdev);
201err1:
202 dvb_dmx_release(&mantis->demux);
203err0:
204 dvb_unregister_adapter(&mantis->dvb_adapter);
205
206 return result;
207}
208
209#define MANTIS_VP_1027_DVB_S 0x0013
210#define MANTIS_VP_1033_DVB_S 0x0016
211#define MANTIS_VP_1034_DVB_S 0x0014
212#define MANTIS_VP_1040_DVB_S2
213#define MANTIS_VP_1041_DVB_S2
214#define MANTIS_VP_2033_DVB_C 0x0008
215#define MANTIS_VP_3024_DVB_T 0x0009
216#define MANTIS_VP_3030_DVB_T 0x0024
217
218int __devinit mantis_frontend_init(struct mantis_pci *mantis)
219{
220 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis frontend Init");
221 mantis_fe_powerup(mantis);
222 mantis_frontend_reset(mantis);
223 dprintk(verbose, MANTIS_DEBUG, 1, "Device ID=%02x", mantis->sub_device_id);
224 switch (mantis->sub_device_id) {
225 case MANTIS_VP_1033_DVB_S: // VP-1033
226 dprintk(verbose, MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
227 mantis->fe = stv0299_attach(&lgtdqcs001f_config,
228 &mantis->adapter);
229
230 if (mantis->fe) {
231 mantis->fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
232 dprintk(verbose, MANTIS_ERROR, 1,
233 "found STV0299 DVB-S frontend @ 0x%02x",
234 lgtdqcs001f_config.demod_address);
235
236 dprintk(verbose, MANTIS_ERROR, 1,
237 "Mantis DVB-S STV0299 frontend attach success");
238 }
239 break;
240 case MANTIS_VP_1034_DVB_S: // VP-1034
241 dprintk(verbose, MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
242 mantis->fe = mb86a16_attach(&vp1034_config, &mantis->adapter);
243 if (mantis->fe) {
244 dprintk(verbose, MANTIS_ERROR, 1,
245 "found MB86A16 DVB-S/DSS frontend @0x%02x",
246 vp1034_config.demod_address);
247
248 }
249 break;
250 case MANTIS_VP_2033_DVB_C: // VP-2033
251 dprintk(verbose, MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
252 mantis->fe = cu1216_attach(&philips_cu1216_config, &mantis->adapter);
253 if (mantis->fe) {
254 mantis->fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set;
255 dprintk(verbose, MANTIS_ERROR, 1,
256 "found Philips CU1216 DVB-C frontend @ 0x%02x",
257 philips_cu1216_config.demod_address);
258
259 dprintk(verbose, MANTIS_ERROR, 1,
260 "Mantis DVB-C Philips CU1216 frontend attach success");
261
262 }
263 break;
264 default:
265 dprintk(verbose, MANTIS_DEBUG, 1, "Unknown frontend:[0x%02x]",
266 mantis->sub_device_id);
267
268 return -ENODEV;
269 }
270 if (mantis->fe == NULL) {
271 dprintk(verbose, MANTIS_ERROR, 1, "!!! NO Frontends found !!!");
272 return -ENODEV;
273 } else {
274 if (dvb_register_frontend(&mantis->dvb_adapter, mantis->fe)) {
275 dprintk(verbose, MANTIS_ERROR, 1,
276 "ERROR: Frontend registration failed");
277
278 if (mantis->fe->ops.release)
279 mantis->fe->ops.release(mantis->fe);
280
281 mantis->fe = NULL;
282 return -ENODEV;
283 }
284 }
285
286 return 0;
287}
288
289int __devexit mantis_dvb_exit(struct mantis_pci *mantis)
290{
291 tasklet_kill(&mantis->tasklet);
292 dvb_net_release(&mantis->dvbnet);
293 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
294 mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_hw);
295 dvb_dmxdev_release(&mantis->dmxdev);
296 dvb_dmx_release(&mantis->demux);
297
298 if (mantis->fe)
299 dvb_unregister_frontend(mantis->fe);
300 dprintk(verbose, MANTIS_DEBUG, 1, "dvb_unregister_adapter");
301 dvb_unregister_adapter(&mantis->dvb_adapter);
302
303 return 0;
304}
diff --git a/drivers/media/dvb/mantis/mantis_i2c.c b/drivers/media/dvb/mantis/mantis_i2c.c
new file mode 100644
index 000000000000..cfecb344bb7a
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_i2c.c
@@ -0,0 +1,189 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <asm/io.h>
26#include <linux/ioport.h>
27#include <asm/pgtable.h>
28#include <asm/page.h>
29#include "mantis_common.h"
30
31#define I2C_HW_B_MANTIS 0x1c
32
33static int mantis_ack_wait(struct mantis_pci *mantis)
34{
35 int rc = 0;
36
37 if (wait_event_interruptible_timeout(mantis->i2c_wq,
38 mantis->mantis_int_stat & MANTIS_INT_I2CRACK,
39 msecs_to_jiffies(50)) == -ERESTARTSYS)
40
41 rc = -EREMOTEIO;
42/*
43 // Wait till we are done
44 while (mantis->mantis_int_stat & MANTIS_INT_I2CRACK){
45 if (mantis->mantis_int_stat & MANTIS_INT_I2CDONE) {
46 mantis->mantis_int_stat &= ~MANTIS_INT_I2CRACK;
47// dprintk(verbose, MANTIS_DEBUG, 1, "SLAVE RACK 'ed .. Waiting for I2CDONE");
48 break;
49 }
50 }
51
52 if (mantis->mantis_int_stat & MANTIS_INT_I2CDONE) {
53// dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Int I2CDONE");
54 rc = 1;
55 }
56
57 mantis->mantis_int_stat &= ~MANTIS_INT_I2CDONE;
58*/
59 // ..
60 if (mantis->mantis_int_stat & MANTIS_INT_I2CRACK)
61 msleep_interruptible(10);
62
63 return rc;
64}
65
66static int mantis_i2c_read(struct mantis_pci *mantis, const struct i2c_msg *msg)
67{
68 u32 rxd, i;
69
70 dprintk(verbose, MANTIS_DEBUG, 1, "Address=[0x%02x]", msg->addr);
71 for (i = 0; i < msg->len; i++) {
72 rxd = (msg->addr << 25) | (1 << 24)
73 | MANTIS_I2C_RATE_3
74 | MANTIS_I2C_STOP
75 | MANTIS_I2C_PGMODE;
76
77 if (i == (msg->len - 1))
78 rxd &= ~MANTIS_I2C_STOP;
79
80 mmwrite(rxd, MANTIS_I2CDATA_CTL);
81 if (mantis_ack_wait(mantis) < 0) {
82 dprintk(verbose, MANTIS_DEBUG, 1, "ACK failed<R>");
83 return -EIO;
84 }
85 rxd = mmread(MANTIS_I2CDATA_CTL);
86 msg->buf[i] = (u8)((rxd >> 8) & 0xFF);
87 dprintk(verbose, MANTIS_DEBUG, 1,
88 "Data<R[%d]>=[0x%02x]", i, msg->buf[i]);
89
90 msleep_interruptible(2);
91 }
92
93 return 0;
94}
95
96static int mantis_i2c_write(struct mantis_pci *mantis, const struct i2c_msg *msg)
97{
98 int i;
99 u32 txd = 0;
100
101 dprintk(verbose, MANTIS_DEBUG, 1, "Address=[0x%02x]", msg->addr);
102 for (i = 0; i < msg->len; i++) {
103 dprintk(verbose, MANTIS_DEBUG, 1, "Data<W[%d]>=[0x%02x]", i, msg->buf[i]);
104 txd = (msg->addr << 25) | (msg->buf[i] << 8)
105 | MANTIS_I2C_RATE_3
106 | MANTIS_I2C_STOP
107 | MANTIS_I2C_PGMODE;
108
109 if (i == (msg->len - 1))
110 txd &= ~MANTIS_I2C_STOP;
111
112 mmwrite(txd, MANTIS_I2CDATA_CTL);
113 if (mantis_ack_wait(mantis) < 0) {
114 dprintk(verbose, MANTIS_DEBUG, 1, "ACK failed<W>");
115 return -1;
116 }
117 udelay(500);
118 }
119
120 return 0;
121}
122
123static int mantis_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
124{
125 int ret = 0, i;
126 struct mantis_pci *mantis;
127
128 mantis = i2c_get_adapdata(adapter);
129 for (i = 0; i < num; i++) {
130 if (msgs[i].flags & I2C_M_RD)
131 ret = mantis_i2c_read(mantis, &msgs[i]);
132 else
133 ret = mantis_i2c_write(mantis, &msgs[i]);
134
135 if (ret < 0)
136 return ret;
137 }
138
139 return num;
140}
141
142static u32 mantis_i2c_func(struct i2c_adapter *adapter)
143{
144 return I2C_FUNC_SMBUS_EMUL;
145}
146
147static struct i2c_algorithm mantis_algo = {
148 .master_xfer = mantis_i2c_xfer,
149 .functionality = mantis_i2c_func,
150};
151
152static struct i2c_adapter mantis_i2c_adapter = {
153 .owner = THIS_MODULE,
154 .name = "Mantis I2C",
155 .id = I2C_HW_B_MANTIS,
156 .class = I2C_CLASS_TV_DIGITAL,
157 .algo = &mantis_algo,
158};
159
160int __devinit mantis_i2c_init(struct mantis_pci *mantis)
161{
162 u32 intstat;
163
164 memcpy(&mantis->adapter, &mantis_i2c_adapter, sizeof (mantis_i2c_adapter));
165 i2c_set_adapdata(&mantis->adapter, mantis);
166 mantis->i2c_rc = i2c_add_adapter(&mantis->adapter);
167 if (mantis->i2c_rc < 0)
168 return mantis->i2c_rc;
169
170 dprintk(verbose, MANTIS_DEBUG, 1, "Initializing I2C ..");
171
172 // Clear all interrupts
173 intstat = mmread(MANTIS_INT_STAT);
174 mmwrite(intstat, MANTIS_INT_STAT);
175
176 mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_I2CDONE,
177 MANTIS_INT_MASK);
178
179 dprintk(verbose, MANTIS_DEBUG, 1, "[0x%08x/%08x]",
180 mmread(MANTIS_INT_STAT), mmread(MANTIS_INT_MASK));
181
182 return 0;
183}
184
185int __devexit mantis_i2c_exit(struct mantis_pci *mantis)
186{
187 dprintk(verbose, MANTIS_DEBUG, 1, "Removing I2C adapter");
188 return i2c_del_adapter(&mantis->adapter);
189}
diff --git a/drivers/media/dvb/mantis/mantis_reg.h b/drivers/media/dvb/mantis/mantis_reg.h
new file mode 100644
index 000000000000..1b54e09fd862
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_reg.h
@@ -0,0 +1,109 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_REG_H
22#define __MANTIS_REG_H
23
24// Interrupts
25#define MANTIS_INT_STAT 0x00
26#define MANTIS_INT_MASK 0x04
27
28#define MANTIS_INT_RISCSTAT (0x0f << 28)
29#define MANTIS_INT_RISCEN (0x01 << 27)
30#define MANTIS_INT_I2CRACK (0x01 << 26)
31
32//#define MANTIS_INT_GPIF (0xff << 12)
33
34#define MANTIS_INT_PCMCIA7 (0x01 << 19)
35#define MANTIS_INT_PCMCIA6 (0x01 << 18)
36#define MANTIS_INT_PCMCIA5 (0x01 << 17)
37#define MANTIS_INT_PCMCIA4 (0x01 << 16)
38#define MANTIS_INT_PCMCIA3 (0x01 << 15)
39#define MANTIS_INT_PCMCIA2 (0x01 << 14)
40#define MANTIS_INT_PCMCIA1 (0x01 << 13)
41#define MANTIS_INT_PCMCIA0 (0x01 << 12)
42#define MANTIS_INT_IRQ1 (0x01 << 11)
43#define MANTIS_INT_IRQ0 (0x01 << 10)
44#define MANTIS_INT_OCERR (0x01 << 8)
45#define MANTIS_INT_PABORT (0x01 << 7)
46#define MANTIS_INT_RIPERR (0x01 << 6)
47#define MANTIS_INT_PPERR (0x01 << 5)
48#define MANTIS_INT_FTRGT (0x01 << 3)
49#define MANTIS_INT_RISCI (0x01 << 1)
50#define MANTIS_INT_I2CDONE (0x01 << 0)
51
52// DMA
53#define MANTIS_DMA_CTL 0x08
54#define MANTIS_I2C_RD (0x01 << 7)
55#define MANTIS_I2C_WR (0x01 << 6)
56#define MANTIS_DCAP_MODE (0x01 << 5)
57#define MANTIS_FIFO_TP_4 (0x00 << 3)
58#define MANTIS_FIFO_TP_8 (0x01 << 3)
59#define MANTIS_FIFO_TP_16 (0x02 << 3)
60#define MANTIS_FIFO_EN (0x01 << 2)
61#define MANTIS_DCAP_EN (0x01 << 1)
62#define MANTIS_RISC_EN (0x01 << 0)
63
64#define MANTIS_RISC_START 0x10
65#define MANTIS_RISC_PC 0x14
66
67// I2C
68#define MANTIS_I2CDATA_CTL 0x18
69#define MANTIS_I2C_RATE_1 (0x00 << 6)
70#define MANTIS_I2C_RATE_2 (0x01 << 6)
71#define MANTIS_I2C_RATE_3 (0x02 << 6)
72#define MANTIS_I2C_RATE_4 (0x03 << 6)
73#define MANTIS_I2C_STOP (0x01 << 5)
74#define MANTIS_I2C_PGMODE (0x01 << 3)
75
76#define MANTIS_GPIF_IRQCFG 0x98
77#define MANTIS_GPIF_IRQPOL (0x01 << 8)
78#define MANTIS_MASK_WRACK (0x01 << 7)
79#define MANTIS_MASK_BRRDY (0x01 << 6)
80#define MANTIS_MASK_OVFLW (0x01 << 5)
81#define MANTIS_MASK_OTHERR (0x01 << 4)
82#define MANTIS_MASK_WSTO (0x01 << 3)
83#define MANTIS_MASK_EXTIRQ (0x01 << 2)
84#define MANTIS_MASK_PLUGIN (0x01 << 1)
85#define MANTIS_MASK_PLUGOUT (0x01 << 0)
86
87#define MANTIS_GPIF_STATUS 0x9c
88#define MANTIS_SBUF_KILLOP (0x01 << 15)
89#define MANTIS_SBUF_OPDONE (0x01 << 14)
90#define MANTIS_SBUF_EMPTY (0x01 << 13)
91#define MANTIS_GPIF_DETSTAT (0x01 << 9)
92#define MANTIS_GPIF_INTSTAT (0x01 << 8)
93#define MANTIS_GPIF_WRACK (0x01 << 7)
94#define MANTIS_GPIF_BRRDY (0x01 << 6)
95#define MANTIS_SBUF_OVFLW (0x01 << 5)
96#define MANTIS_GPIF_OTHERR (0x01 << 4)
97#define MANTIS_SBUF_WSTO (0x01 << 3)
98#define MANTIS_GPIF_EXTIRQ (0x01 << 2)
99#define MANTIS_CARD_PLUGIN (0x01 << 1)
100#define MANTIS_CARD_PLUGOUT (0x01 << 0)
101
102#define MANTIS_GPIF_ADDR 0xb0
103#define MANTIS_GPIF_RDWRN (0x01 << 31)
104
105#define MANTIS_GPIF_DOUT 0xb4
106#define MANTIS_GPIF_DIN 0xb8
107
108
109#endif //__MANTIS_REG_H
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.c b/drivers/media/dvb/mantis/mantis_vp1033.c
new file mode 100644
index 000000000000..720f4fb7e925
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp1033.c
@@ -0,0 +1,151 @@
1/*
2 Mantis VP-1033 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_vp1033.h"
23
24u8 lgtdqcs001f_inittab[] = {
25 0x01, 0x15,
26 0x02, 0x00,
27 0x03, 0x00,
28 0x04, 0x2a,
29 0x05, 0x85,
30 0x06, 0x02,
31 0x07, 0x00,
32 0x08, 0x00,
33 0x0c, 0x01,
34 0x0d, 0x81,
35 0x0e, 0x44,
36 0x0f, 0x94,
37 0x10, 0x3c,
38 0x11, 0x84,
39 0x12, 0xb9,
40 0x13, 0xb5,
41 0x14, 0x4f,
42 0x15, 0xc9,
43 0x16, 0x80,
44 0x17, 0x36,
45 0x18, 0xfb,
46 0x19, 0xcf,
47 0x1a, 0xbc,
48 0x1c, 0x2b,
49 0x1d, 0x27,
50 0x1e, 0x00,
51 0x1f, 0x0b,
52 0x20, 0xa1,
53 0x21, 0x60,
54 0x22, 0x00,
55 0x23, 0x00,
56 0x28, 0x00,
57 0x29, 0x28,
58 0x2a, 0x14,
59 0x2b, 0x0f,
60 0x2c, 0x09,
61 0x2d, 0x05,
62 0x31, 0x1f,
63 0x32, 0x19,
64 0x33, 0xfc,
65 0x34, 0x13,
66 0xff, 0xff,
67};
68
69struct stv0299_config lgtdqcs001f_config = {
70 .demod_address = 0x68,
71 .inittab = lgtdqcs001f_inittab,
72 .mclk = 88000000UL,
73// .invert = 0,
74 .invert = 1,
75// .enhanced_tuning = 0,
76 .skip_reinit = 0,
77 .lock_output = STV0229_LOCKOUTPUT_0,
78 .volt13_op0_op1 = STV0299_VOLT13_OP0,
79 .min_delay_ms = 100,
80 .set_symbol_rate = lgtdqcs001f_set_symbol_rate,
81// .pll_set = lgtdqcs001f_pll_set,
82};
83
84int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,
85 struct dvb_frontend_parameters *params)
86{
87 u8 buf[4];
88 u32 div;
89
90 struct mantis_pci *mantis = fe->dvb->priv;
91
92 struct i2c_msg msg = {
93 .addr = 0x61,
94 .flags = 0,
95 .buf = buf,
96 .len = sizeof (buf)
97 };
98 div = params->frequency / 250;
99
100 buf[0] = (div >> 8) & 0x7f;
101 buf[1] = div & 0xff;
102 buf[2] = 0x83;
103 buf[3] = 0xc0;
104
105 if (params->frequency < 1531000)
106 buf[3] |= 0x04;
107 else
108 buf[3] &= ~0x04;
109 if (i2c_transfer(&mantis->adapter, &msg, 1) < 0) {
110 dprintk(verbose, MANTIS_ERROR, 1, "Write: I2C Transfer failed");
111 return -EIO;
112 }
113 msleep_interruptible(100);
114
115 return 0;
116}
117
118int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe,
119 u32 srate, u32 ratio)
120{
121 u8 aclk = 0;
122 u8 bclk = 0;
123
124 if (srate < 1500000) {
125 aclk = 0xb7;
126 bclk = 0x47;
127 } else if (srate < 3000000) {
128 aclk = 0xb7;
129 bclk = 0x4b;
130 } else if (srate < 7000000) {
131 aclk = 0xb7;
132 bclk = 0x4f;
133 } else if (srate < 14000000) {
134 aclk = 0xb7;
135 bclk = 0x53;
136 } else if (srate < 30000000) {
137 aclk = 0xb6;
138 bclk = 0x53;
139 } else if (srate < 45000000) {
140 aclk = 0xb4;
141 bclk = 0x51;
142 }
143 stv0299_writereg (fe, 0x13, aclk);
144 stv0299_writereg (fe, 0x14, bclk);
145
146 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
147 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
148 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
149
150 return 0;
151}
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.h b/drivers/media/dvb/mantis/mantis_vp1033.h
new file mode 100644
index 000000000000..d50f09233ffb
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp1033.h
@@ -0,0 +1,35 @@
1/*
2 Mantis VP-1033 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_VP1033_H
22#define __MANTIS_VP1033_H
23
24#include "stv0299.h"
25#include "dvb_frontend.h"
26
27extern struct stv0299_config lgtdqcs001f_config;
28
29extern int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,
30 struct dvb_frontend_parameters *params);
31
32extern int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio);
33
34
35#endif // __MANTIS_VP1033_H
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.c b/drivers/media/dvb/mantis/mantis_vp1034.c
new file mode 100644
index 000000000000..b85ac29691d0
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp1034.c
@@ -0,0 +1,52 @@
1/*
2 Mantis VP-1034 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_vp1034.h"
23
24struct mb86a16_config vp1034_config = {
25 .demod_address = 0x08,
26 .set_voltage = vp1034_set_voltage,
27};
28
29int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
30{
31 struct mantis_pci *mantis = fe->dvb->priv;
32
33 switch (voltage) {
34 case SEC_VOLTAGE_13:
35 mmwrite((mmread(MANTIS_GPIF_ADDR)) | voltage, MANTIS_GPIF_ADDR);
36 dprintk(verbose, MANTIS_ERROR, 1, "Polarization=[13V]");
37 break;
38 case SEC_VOLTAGE_18:
39 mmwrite((mmread(MANTIS_GPIF_ADDR)) & voltage, MANTIS_GPIF_ADDR);
40 dprintk(verbose, MANTIS_ERROR, 1, "Polarization=[18V]");
41 break;
42 case SEC_VOLTAGE_OFF:
43 dprintk(verbose, MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN");
44 break;
45 default:
46 dprintk(verbose, MANTIS_ERROR, 1, "Invalid = (%d)", (u32 ) voltage);
47 return -EINVAL;
48 }
49 mmwrite(0x00, MANTIS_GPIF_DOUT);
50
51 return 0;
52}
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.h b/drivers/media/dvb/mantis/mantis_vp1034.h
new file mode 100644
index 000000000000..2324dada09de
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp1034.h
@@ -0,0 +1,30 @@
1/*
2 Mantis VP-1034 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_VP1034_H
22#define __MANTIS_VP1034_H
23
24#include "mb86a16.h"
25#include "dvb_frontend.h"
26
27extern struct mb86a16_config vp1034_config;
28extern int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
29
30#endif // __MANTIS_VP1034_H
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.c b/drivers/media/dvb/mantis/mantis_vp2033.c
new file mode 100644
index 000000000000..bca9ebaf39d7
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp2033.c
@@ -0,0 +1,73 @@
1/*
2 Mantis VP-2033 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_vp2033.h"
23
24struct tda10021_state {
25 struct i2c_adapter *i2c;
26 struct dvb_frontend_ops ops;
27 /* configuration settings */
28 const struct tda10021_config *config;
29 struct dvb_frontend frontend;
30
31 u8 pwm;
32 u8 reg0;
33};
34
35struct cu1216_config philips_cu1216_config = {
36 .demod_address = 0x18 >> 1,
37 .pll_set = philips_cu1216_tuner_set,
38// .fe_reset = mantis_fe_reset,
39};
40
41int philips_cu1216_tuner_set(struct dvb_frontend *fe,
42 struct dvb_frontend_parameters *params)
43{
44// struct tda10021_state *state = fe->demodulator_priv;
45 struct mantis_pci *mantis = fe->dvb->priv;
46
47 u8 buf[4];
48
49 struct i2c_msg msg = {
50 .addr = 0xc0 >> 1,
51 .flags = 0,
52 .buf = buf,
53 .len = sizeof (buf)
54 };
55
56#define TUNER_MUL 62500
57
58 u32 div = (params->frequency + 36125000 + TUNER_MUL / 2) / TUNER_MUL;
59
60 buf[0] = (div >> 8) & 0x7f;
61 buf[1] = div & 0xff;
62 buf[2] = 0x86;
63 buf[3] = (params->frequency < 150000000 ? 0xA1 :
64 params->frequency < 445000000 ? 0x92 : 0x34);
65
66// if (i2c_transfer(state->i2c, &msg, 1) < 0) {
67 if (i2c_transfer(&mantis->adapter, &msg, 1) < 0) {
68 printk("%s tuner not ack!\n", __FUNCTION__);
69 return -EIO;
70 }
71 msleep(100);
72 return 0;
73}
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.h b/drivers/media/dvb/mantis/mantis_vp2033.h
new file mode 100644
index 000000000000..29baba180961
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp2033.h
@@ -0,0 +1,33 @@
1/*
2 Mantis VP-2033 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_VP2033_H
22#define __MANTIS_VP2033_H
23
24#include "cu1216.h"
25#include "dvb_frontend.h"
26
27extern struct cu1216_config philips_cu1216_config;
28
29extern int philips_cu1216_tuner_set(struct dvb_frontend *fe,
30 struct dvb_frontend_parameters *params);
31
32
33#endif // __MANTIS_VP2033_H
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.c b/drivers/media/dvb/mantis/mantis_vp3030.c
new file mode 100644
index 000000000000..f44f226ce9ab
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp3030.c
@@ -0,0 +1,53 @@
1/*
2 Mantis VP-3030 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_vp3030.h"
23
24struct zl10353_config mantis_vp3030_config = {
25 .demod_address = 0x0f,
26};
27
28int panasonic_en57h12d5_set_params(struct dvb_frontend *fe,
29 struct dvb_frontend_parameters *params)
30{
31 u8 buf[4];
32 int rc;
33 struct mantis_pci *mantis = fe->dvb->priv;
34
35 struct i2c_msg tuner_msg = {
36 .addr = 0x60,
37 .flags = 0,
38 .buf = buf,
39 .len = sizeof (buf)
40 };
41
42 if ((params->frequency < 950000) || (params->frequency > 2150000))
43 return -EINVAL;
44 rc = i2c_transfer(&mantis->adapter, &tuner_msg, 1);
45 if (rc != 1) {
46 printk("%s: I2C Transfer returned [%d]\n", __func__, rc);
47 return -EIO;
48 }
49 msleep_interruptible(1);
50 printk("%s: Send params to tuner ok!!!\n", __func__);
51
52 return 0;
53}
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.h b/drivers/media/dvb/mantis/mantis_vp3030.h
new file mode 100644
index 000000000000..f8e72cce7e69
--- /dev/null
+++ b/drivers/media/dvb/mantis/mantis_vp3030.h
@@ -0,0 +1,30 @@
1/*
2 Mantis VP-3030 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __MANTIS_VP3030_H
22#define __MANTIS_VP3030_H
23
24#include "zl10353.h"
25#include "dvb-pll.h"
26#include "dvb_frontend.h"
27
28extern struct zl10353_config mantis_vp3030_config;
29
30#endif // __MANTIS_VP3030_H