blob: e38454901dd12e31d281a9e2ec9d1210534ae43d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 Driver for Zarlink VP310/MT312 Satellite Channel Decoder
3
4 Copyright (C) 2003 Andreas Oberritter <obi@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 References:
22 http://products.zarlink.com/product_profiles/MT312.htm
23 http://products.zarlink.com/product_profiles/SL1935.htm
24*/
25
26#include <linux/delay.h>
27#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/moduleparam.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080032#include <linux/string.h>
33#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include "dvb_frontend.h"
36#include "mt312_priv.h"
37#include "mt312.h"
38
39
40struct mt312_state {
41 struct i2c_adapter* i2c;
42 struct dvb_frontend_ops ops;
43 /* configuration settings */
44 const struct mt312_config* config;
45 struct dvb_frontend frontend;
46
47 u8 id;
48 u8 frequency;
49};
50
51static int debug;
52#define dprintk(args...) \
53 do { \
54 if (debug) printk(KERN_DEBUG "mt312: " args); \
55 } while (0)
56
57#define MT312_SYS_CLK 90000000UL /* 90 MHz */
58#define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */
59#define MT312_PLL_CLK 10000000UL /* 10 MHz */
60
61static int mt312_read(struct mt312_state* state, const enum mt312_reg_addr reg,
62 void *buf, const size_t count)
63{
64 int ret;
65 struct i2c_msg msg[2];
66 u8 regbuf[1] = { reg };
67
68 msg[0].addr = state->config->demod_address;
69 msg[0].flags = 0;
70 msg[0].buf = regbuf;
71 msg[0].len = 1;
72 msg[1].addr = state->config->demod_address;
73 msg[1].flags = I2C_M_RD;
74 msg[1].buf = buf;
75 msg[1].len = count;
76
77 ret = i2c_transfer(state->i2c, msg, 2);
78
79 if (ret != 2) {
80 printk(KERN_ERR "%s: ret == %d\n", __FUNCTION__, ret);
81 return -EREMOTEIO;
82 }
83
84 if(debug) {
85 int i;
86 dprintk("R(%d):", reg & 0x7f);
87 for (i = 0; i < count; i++)
88 printk(" %02x", ((const u8 *) buf)[i]);
89 printk("\n");
90 }
91
92 return 0;
93}
94
95static int mt312_write(struct mt312_state* state, const enum mt312_reg_addr reg,
96 const void *src, const size_t count)
97{
98 int ret;
99 u8 buf[count + 1];
100 struct i2c_msg msg;
101
102 if(debug) {
103 int i;
104 dprintk("W(%d):", reg & 0x7f);
105 for (i = 0; i < count; i++)
106 printk(" %02x", ((const u8 *) src)[i]);
107 printk("\n");
108 }
109
110 buf[0] = reg;
111 memcpy(&buf[1], src, count);
112
113 msg.addr = state->config->demod_address;
114 msg.flags = 0;
115 msg.buf = buf;
116 msg.len = count + 1;
117
118 ret = i2c_transfer(state->i2c, &msg, 1);
119
120 if (ret != 1) {
121 dprintk("%s: ret == %d\n", __FUNCTION__, ret);
122 return -EREMOTEIO;
123 }
124
125 return 0;
126}
127
128static inline int mt312_readreg(struct mt312_state* state,
129 const enum mt312_reg_addr reg, u8 *val)
130{
131 return mt312_read(state, reg, val, 1);
132}
133
134static inline int mt312_writereg(struct mt312_state* state,
135 const enum mt312_reg_addr reg, const u8 val)
136{
137 return mt312_write(state, reg, &val, 1);
138}
139
140static inline u32 mt312_div(u32 a, u32 b)
141{
142 return (a + (b / 2)) / b;
143}
144
145static int mt312_reset(struct mt312_state* state, const u8 full)
146{
147 return mt312_writereg(state, RESET, full ? 0x80 : 0x40);
148}
149
150static int mt312_get_inversion(struct mt312_state* state,
151 fe_spectral_inversion_t *i)
152{
153 int ret;
154 u8 vit_mode;
155
156 if ((ret = mt312_readreg(state, VIT_MODE, &vit_mode)) < 0)
157 return ret;
158
159 if (vit_mode & 0x80) /* auto inversion was used */
160 *i = (vit_mode & 0x40) ? INVERSION_ON : INVERSION_OFF;
161
162 return 0;
163}
164
165static int mt312_get_symbol_rate(struct mt312_state* state, u32 *sr)
166{
167 int ret;
168 u8 sym_rate_h;
169 u8 dec_ratio;
170 u16 sym_rat_op;
171 u16 monitor;
172 u8 buf[2];
173
174 if ((ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h)) < 0)
175 return ret;
176
177 if (sym_rate_h & 0x80) { /* symbol rate search was used */
178 if ((ret = mt312_writereg(state, MON_CTRL, 0x03)) < 0)
179 return ret;
180
181 if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0)
182 return ret;
183
184 monitor = (buf[0] << 8) | buf[1];
185
186 dprintk(KERN_DEBUG "sr(auto) = %u\n",
187 mt312_div(monitor * 15625, 4));
188 } else {
189 if ((ret = mt312_writereg(state, MON_CTRL, 0x05)) < 0)
190 return ret;
191
192 if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0)
193 return ret;
194
195 dec_ratio = ((buf[0] >> 5) & 0x07) * 32;
196
197 if ((ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf))) < 0)
198 return ret;
199
200 sym_rat_op = (buf[0] << 8) | buf[1];
201
202 dprintk(KERN_DEBUG "sym_rat_op=%d dec_ratio=%d\n",
203 sym_rat_op, dec_ratio);
204 dprintk(KERN_DEBUG "*sr(manual) = %lu\n",
205 (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) *
206 2) - dec_ratio);
207 }
208
209 return 0;
210}
211
212static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr)
213{
214 const fe_code_rate_t fec_tab[8] =
215 { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8,
216 FEC_AUTO, FEC_AUTO };
217
218 int ret;
219 u8 fec_status;
220
221 if ((ret = mt312_readreg(state, FEC_STATUS, &fec_status)) < 0)
222 return ret;
223
224 *cr = fec_tab[(fec_status >> 4) & 0x07];
225
226 return 0;
227}
228
229static int mt312_initfe(struct dvb_frontend* fe)
230{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700231 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 int ret;
233 u8 buf[2];
234
235 /* wake up */
236 if ((ret = mt312_writereg(state, CONFIG, (state->frequency == 60 ? 0x88 : 0x8c))) < 0)
237 return ret;
238
239 /* wait at least 150 usec */
240 udelay(150);
241
242 /* full reset */
243 if ((ret = mt312_reset(state, 1)) < 0)
244 return ret;
245
246// Per datasheet, write correct values. 09/28/03 ACCJr.
247// If we don't do this, we won't get FE_HAS_VITERBI in the VP310.
248 {
249 u8 buf_def[8]={0x14, 0x12, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00};
250
251 if ((ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def))) < 0)
252 return ret;
253 }
254
255 /* SYS_CLK */
256 buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK : MT312_SYS_CLK) * 2, 1000000);
257
258 /* DISEQC_RATIO */
259 buf[1] = mt312_div(MT312_PLL_CLK, 15000 * 4);
260
261 if ((ret = mt312_write(state, SYS_CLK, buf, sizeof(buf))) < 0)
262 return ret;
263
264 if ((ret = mt312_writereg(state, SNR_THS_HIGH, 0x32)) < 0)
265 return ret;
266
267 if ((ret = mt312_writereg(state, OP_CTRL, 0x53)) < 0)
268 return ret;
269
270 /* TS_SW_LIM */
271 buf[0] = 0x8c;
272 buf[1] = 0x98;
273
274 if ((ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf))) < 0)
275 return ret;
276
277 if ((ret = mt312_writereg(state, CS_SW_LIM, 0x69)) < 0)
278 return ret;
279
280 if (state->config->pll_init) {
281 mt312_writereg(state, GPP_CTRL, 0x40);
282 state->config->pll_init(fe);
283 mt312_writereg(state, GPP_CTRL, 0x00);
284 }
285
286 return 0;
287}
288
289static int mt312_send_master_cmd(struct dvb_frontend* fe,
290 struct dvb_diseqc_master_cmd *c)
291{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700292 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 int ret;
294 u8 diseqc_mode;
295
296 if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg)))
297 return -EINVAL;
298
299 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0)
300 return ret;
301
302 if ((ret =
303 mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len)) < 0)
304 return ret;
305
306 if ((ret =
307 mt312_writereg(state, DISEQC_MODE,
308 (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3)
309 | 0x04)) < 0)
310 return ret;
311
312 /* set DISEQC_MODE[2:0] to zero if a return message is expected */
313 if (c->msg[0] & 0x02)
314 if ((ret =
315 mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40))) < 0)
316 return ret;
317
318 return 0;
319}
320
321static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c)
322{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700323 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 const u8 mini_tab[2] = { 0x02, 0x03 };
325
326 int ret;
327 u8 diseqc_mode;
328
329 if (c > SEC_MINI_B)
330 return -EINVAL;
331
332 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0)
333 return ret;
334
335 if ((ret =
336 mt312_writereg(state, DISEQC_MODE,
337 (diseqc_mode & 0x40) | mini_tab[c])) < 0)
338 return ret;
339
340 return 0;
341}
342
343static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t)
344{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700345 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 const u8 tone_tab[2] = { 0x01, 0x00 };
347
348 int ret;
349 u8 diseqc_mode;
350
351 if (t > SEC_TONE_OFF)
352 return -EINVAL;
353
354 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0)
355 return ret;
356
357 if ((ret =
358 mt312_writereg(state, DISEQC_MODE,
359 (diseqc_mode & 0x40) | tone_tab[t])) < 0)
360 return ret;
361
362 return 0;
363}
364
365static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v)
366{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700367 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
369
370 if (v > SEC_VOLTAGE_OFF)
371 return -EINVAL;
372
373 return mt312_writereg(state, DISEQC_MODE, volt_tab[v]);
374}
375
376static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s)
377{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700378 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 int ret;
380 u8 status[3];
381
382 *s = 0;
383
384 if ((ret = mt312_read(state, QPSK_STAT_H, status, sizeof(status))) < 0)
385 return ret;
386
387 dprintk(KERN_DEBUG "QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x, FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]);
388
389 if (status[0] & 0xc0)
390 *s |= FE_HAS_SIGNAL; /* signal noise ratio */
391 if (status[0] & 0x04)
392 *s |= FE_HAS_CARRIER; /* qpsk carrier lock */
393 if (status[2] & 0x02)
394 *s |= FE_HAS_VITERBI; /* viterbi lock */
395 if (status[2] & 0x04)
396 *s |= FE_HAS_SYNC; /* byte align lock */
397 if (status[0] & 0x01)
398 *s |= FE_HAS_LOCK; /* qpsk lock */
399
400 return 0;
401}
402
403static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber)
404{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700405 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 int ret;
407 u8 buf[3];
408
409 if ((ret = mt312_read(state, RS_BERCNT_H, buf, 3)) < 0)
410 return ret;
411
412 *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64;
413
414 return 0;
415}
416
417static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_strength)
418{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700419 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 int ret;
421 u8 buf[3];
422 u16 agc;
423 s16 err_db;
424
425 if ((ret = mt312_read(state, AGC_H, buf, sizeof(buf))) < 0)
426 return ret;
427
428 agc = (buf[0] << 6) | (buf[1] >> 2);
429 err_db = (s16) (((buf[1] & 0x03) << 14) | buf[2] << 6) >> 6;
430
431 *signal_strength = agc;
432
433 dprintk(KERN_DEBUG "agc=%08x err_db=%hd\n", agc, err_db);
434
435 return 0;
436}
437
438static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr)
439{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700440 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int ret;
442 u8 buf[2];
443
444 if ((ret = mt312_read(state, M_SNR_H, &buf, sizeof(buf))) < 0)
445 return ret;
446
447 *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1);
448
449 return 0;
450}
451
452static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc)
453{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700454 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 int ret;
456 u8 buf[2];
457
458 if ((ret = mt312_read(state, RS_UBC_H, &buf, sizeof(buf))) < 0)
459 return ret;
460
461 *ubc = (buf[0] << 8) | buf[1];
462
463 return 0;
464}
465
466static int mt312_set_frontend(struct dvb_frontend* fe,
467 struct dvb_frontend_parameters *p)
468{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700469 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 int ret;
471 u8 buf[5], config_val;
472 u16 sr;
473
474 const u8 fec_tab[10] =
475 { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f };
476 const u8 inv_tab[3] = { 0x00, 0x40, 0x80 };
477
478 dprintk("%s: Freq %d\n", __FUNCTION__, p->frequency);
479
480 if ((p->frequency < fe->ops->info.frequency_min)
481 || (p->frequency > fe->ops->info.frequency_max))
482 return -EINVAL;
483
484 if ((p->inversion < INVERSION_OFF)
485 || (p->inversion > INVERSION_ON))
486 return -EINVAL;
487
488 if ((p->u.qpsk.symbol_rate < fe->ops->info.symbol_rate_min)
489 || (p->u.qpsk.symbol_rate > fe->ops->info.symbol_rate_max))
490 return -EINVAL;
491
492 if ((p->u.qpsk.fec_inner < FEC_NONE)
493 || (p->u.qpsk.fec_inner > FEC_AUTO))
494 return -EINVAL;
495
496 if ((p->u.qpsk.fec_inner == FEC_4_5)
497 || (p->u.qpsk.fec_inner == FEC_8_9))
498 return -EINVAL;
499
500 switch (state->id) {
501 case ID_VP310:
502 // For now we will do this only for the VP310.
503 // It should be better for the mt312 as well, but tunning will be slower. ACCJr 09/29/03
504 if ((ret = mt312_readreg(state, CONFIG, &config_val) < 0))
505 return ret;
506 if (p->u.qpsk.symbol_rate >= 30000000) //Note that 30MS/s should use 90MHz
507 {
508 if ((config_val & 0x0c) == 0x08) { //We are running 60MHz
509 state->frequency = 90;
510 if ((ret = mt312_initfe(fe)) < 0)
511 return ret;
512 }
513 }
514 else
515 {
516 if ((config_val & 0x0c) == 0x0C) { //We are running 90MHz
517 state->frequency = 60;
518 if ((ret = mt312_initfe(fe)) < 0)
519 return ret;
520 }
521 }
522 break;
523
524 case ID_MT312:
525 break;
526
527 default:
528 return -EINVAL;
529 }
530
531 mt312_writereg(state, GPP_CTRL, 0x40);
532 state->config->pll_set(fe, p);
533 mt312_writereg(state, GPP_CTRL, 0x00);
534
535 /* sr = (u16)(sr * 256.0 / 1000000.0) */
536 sr = mt312_div(p->u.qpsk.symbol_rate * 4, 15625);
537
538 /* SYM_RATE */
539 buf[0] = (sr >> 8) & 0x3f;
540 buf[1] = (sr >> 0) & 0xff;
541
542 /* VIT_MODE */
543 buf[2] = inv_tab[p->inversion] | fec_tab[p->u.qpsk.fec_inner];
544
545 /* QPSK_CTRL */
546 buf[3] = 0x40; /* swap I and Q before QPSK demodulation */
547
548 if (p->u.qpsk.symbol_rate < 10000000)
549 buf[3] |= 0x04; /* use afc mode */
550
551 /* GO */
552 buf[4] = 0x01;
553
554 if ((ret = mt312_write(state, SYM_RATE_H, buf, sizeof(buf))) < 0)
555 return ret;
556
557 mt312_reset(state, 0);
558
559 return 0;
560}
561
562static int mt312_get_frontend(struct dvb_frontend* fe,
563 struct dvb_frontend_parameters *p)
564{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700565 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 int ret;
567
568 if ((ret = mt312_get_inversion(state, &p->inversion)) < 0)
569 return ret;
570
571 if ((ret = mt312_get_symbol_rate(state, &p->u.qpsk.symbol_rate)) < 0)
572 return ret;
573
574 if ((ret = mt312_get_code_rate(state, &p->u.qpsk.fec_inner)) < 0)
575 return ret;
576
577 return 0;
578}
579
580static int mt312_sleep(struct dvb_frontend* fe)
581{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700582 struct mt312_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 int ret;
584 u8 config;
585
586 /* reset all registers to defaults */
587 if ((ret = mt312_reset(state, 1)) < 0)
588 return ret;
589
590 if ((ret = mt312_readreg(state, CONFIG, &config)) < 0)
591 return ret;
592
593 /* enter standby */
594 if ((ret = mt312_writereg(state, CONFIG, config & 0x7f)) < 0)
595 return ret;
596
597 return 0;
598}
599
600static int mt312_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
601{
602 fesettings->min_delay_ms = 50;
603 fesettings->step_size = 0;
604 fesettings->max_drift = 0;
605 return 0;
606}
607
608static void mt312_release(struct dvb_frontend* fe)
609{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700610 struct mt312_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 kfree(state);
612}
613
614static struct dvb_frontend_ops vp310_mt312_ops;
615
616struct dvb_frontend* vp310_attach(const struct mt312_config* config,
617 struct i2c_adapter* i2c)
618{
619 struct mt312_state* state = NULL;
620
621 /* allocate memory for the internal state */
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700622 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (state == NULL)
624 goto error;
625
626 /* setup the state */
627 state->config = config;
628 state->i2c = i2c;
629 memcpy(&state->ops, &vp310_mt312_ops, sizeof(struct dvb_frontend_ops));
630 strcpy(state->ops.info.name, "Zarlink VP310 DVB-S");
631
632 /* check if the demod is there */
633 if (mt312_readreg(state, ID, &state->id) < 0)
634 goto error;
635 if (state->id != ID_VP310) {
636 goto error;
637 }
638
639 /* create dvb_frontend */
640 state->frequency = 90;
641 state->frontend.ops = &state->ops;
642 state->frontend.demodulator_priv = state;
643 return &state->frontend;
644
645error:
646 kfree(state);
647 return NULL;
648}
649
650struct dvb_frontend* mt312_attach(const struct mt312_config* config,
651 struct i2c_adapter* i2c)
652{
653 struct mt312_state* state = NULL;
654
655 /* allocate memory for the internal state */
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700656 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (state == NULL)
658 goto error;
659
660 /* setup the state */
661 state->config = config;
662 state->i2c = i2c;
663 memcpy(&state->ops, &vp310_mt312_ops, sizeof(struct dvb_frontend_ops));
664 strcpy(state->ops.info.name, "Zarlink MT312 DVB-S");
665
666 /* check if the demod is there */
667 if (mt312_readreg(state, ID, &state->id) < 0)
668 goto error;
669 if (state->id != ID_MT312) {
670 goto error;
671 }
672
673 /* create dvb_frontend */
674 state->frequency = 60;
675 state->frontend.ops = &state->ops;
676 state->frontend.demodulator_priv = state;
677 return &state->frontend;
678
679error:
680 if (state)
681 kfree(state);
682 return NULL;
683}
684
685static struct dvb_frontend_ops vp310_mt312_ops = {
686
687 .info = {
688 .name = "Zarlink ???? DVB-S",
689 .type = FE_QPSK,
690 .frequency_min = 950000,
691 .frequency_max = 2150000,
692 .frequency_stepsize = (MT312_PLL_CLK / 1000) / 128,
693 .symbol_rate_min = MT312_SYS_CLK / 128,
694 .symbol_rate_max = MT312_SYS_CLK / 2,
695 .caps =
696 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
697 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
698 FE_CAN_FEC_AUTO | FE_CAN_QPSK | FE_CAN_MUTE_TS |
699 FE_CAN_RECOVER
700 },
701
702 .release = mt312_release,
703
704 .init = mt312_initfe,
705 .sleep = mt312_sleep,
706
707 .set_frontend = mt312_set_frontend,
708 .get_frontend = mt312_get_frontend,
709 .get_tune_settings = mt312_get_tune_settings,
710
711 .read_status = mt312_read_status,
712 .read_ber = mt312_read_ber,
713 .read_signal_strength = mt312_read_signal_strength,
714 .read_snr = mt312_read_snr,
715 .read_ucblocks = mt312_read_ucblocks,
716
717 .diseqc_send_master_cmd = mt312_send_master_cmd,
718 .diseqc_send_burst = mt312_send_burst,
719 .set_tone = mt312_set_tone,
720 .set_voltage = mt312_set_voltage,
721};
722
723module_param(debug, int, 0644);
724MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
725
726MODULE_DESCRIPTION("Zarlink VP310/MT312 DVB-S Demodulator driver");
727MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
728MODULE_LICENSE("GPL");
729
730EXPORT_SYMBOL(mt312_attach);
731EXPORT_SYMBOL(vp310_attach);