1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * PnpNetwork PN1010 QPSK Demodulator
7 * Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
8 * Copyright (C) 2005-8 Patrick Boettcher <pb@linuxtv.org>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/jiffies.h>
18 #include <asm/div64.h>
20 #include <linux/i2c.h>
23 #include <media/dvb_frontend.h>
25 #include "s5h1420_priv.h"
27 #define TONE_FREQ 22000
29 struct s5h1420_state
{
30 struct i2c_adapter
* i2c
;
31 const struct s5h1420_config
* config
;
33 struct dvb_frontend frontend
;
34 struct i2c_adapter tuner_i2c_adapter
;
41 enum fe_code_rate fec_inner
;
44 /* FIXME: ugly workaround for flexcop's incapable i2c-controller
45 * it does not support repeated-start, workaround: write addr-1
51 static u32
s5h1420_getsymbolrate(struct s5h1420_state
* state
);
52 static int s5h1420_get_tune_settings(struct dvb_frontend
* fe
,
53 struct dvb_frontend_tune_settings
* fesettings
);
57 module_param(debug
, int, 0644);
58 MODULE_PARM_DESC(debug
, "enable debugging");
60 #define dprintk(x...) do { \
62 printk(KERN_DEBUG "S5H1420: " x); \
65 static u8
s5h1420_readreg(struct s5h1420_state
*state
, u8 reg
)
69 struct i2c_msg msg
[] = {
70 { .addr
= state
->config
->demod_address
, .flags
= 0, .buf
= b
, .len
= 2 },
71 { .addr
= state
->config
->demod_address
, .flags
= 0, .buf
= ®
, .len
= 1 },
72 { .addr
= state
->config
->demod_address
, .flags
= I2C_M_RD
, .buf
= b
, .len
= 1 },
75 b
[0] = (reg
- 1) & 0xff;
76 b
[1] = state
->shadow
[(reg
- 1) & 0xff];
78 if (state
->config
->repeated_start_workaround
) {
79 ret
= i2c_transfer(state
->i2c
, msg
, 3);
83 ret
= i2c_transfer(state
->i2c
, &msg
[1], 1);
86 ret
= i2c_transfer(state
->i2c
, &msg
[2], 1);
91 /* dprintk("rd(%02x): %02x %02x\n", state->config->demod_address, reg, b[0]); */
96 static int s5h1420_writereg (struct s5h1420_state
* state
, u8 reg
, u8 data
)
98 u8 buf
[] = { reg
, data
};
99 struct i2c_msg msg
= { .addr
= state
->config
->demod_address
, .flags
= 0, .buf
= buf
, .len
= 2 };
102 /* dprintk("wr(%02x): %02x %02x\n", state->config->demod_address, reg, data); */
103 err
= i2c_transfer(state
->i2c
, &msg
, 1);
105 dprintk("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__
, err
, reg
, data
);
108 state
->shadow
[reg
] = data
;
113 static int s5h1420_set_voltage(struct dvb_frontend
*fe
,
114 enum fe_sec_voltage voltage
)
116 struct s5h1420_state
* state
= fe
->demodulator_priv
;
118 dprintk("enter %s\n", __func__
);
122 s5h1420_writereg(state
, 0x3c,
123 (s5h1420_readreg(state
, 0x3c) & 0xfe) | 0x02);
127 s5h1420_writereg(state
, 0x3c, s5h1420_readreg(state
, 0x3c) | 0x03);
130 case SEC_VOLTAGE_OFF
:
131 s5h1420_writereg(state
, 0x3c, s5h1420_readreg(state
, 0x3c) & 0xfd);
135 dprintk("leave %s\n", __func__
);
139 static int s5h1420_set_tone(struct dvb_frontend
*fe
,
140 enum fe_sec_tone_mode tone
)
142 struct s5h1420_state
* state
= fe
->demodulator_priv
;
144 dprintk("enter %s\n", __func__
);
147 s5h1420_writereg(state
, 0x3b,
148 (s5h1420_readreg(state
, 0x3b) & 0x74) | 0x08);
152 s5h1420_writereg(state
, 0x3b,
153 (s5h1420_readreg(state
, 0x3b) & 0x74) | 0x01);
156 dprintk("leave %s\n", __func__
);
161 static int s5h1420_send_master_cmd (struct dvb_frontend
* fe
,
162 struct dvb_diseqc_master_cmd
* cmd
)
164 struct s5h1420_state
* state
= fe
->demodulator_priv
;
167 unsigned long timeout
;
170 dprintk("enter %s\n", __func__
);
171 if (cmd
->msg_len
> sizeof(cmd
->msg
))
174 /* setup for DISEQC */
175 val
= s5h1420_readreg(state
, 0x3b);
176 s5h1420_writereg(state
, 0x3b, 0x02);
179 /* write the DISEQC command bytes */
180 for(i
=0; i
< cmd
->msg_len
; i
++) {
181 s5h1420_writereg(state
, 0x3d + i
, cmd
->msg
[i
]);
184 /* kick off transmission */
185 s5h1420_writereg(state
, 0x3b, s5h1420_readreg(state
, 0x3b) |
186 ((cmd
->msg_len
-1) << 4) | 0x08);
188 /* wait for transmission to complete */
189 timeout
= jiffies
+ ((100*HZ
) / 1000);
190 while(time_before(jiffies
, timeout
)) {
191 if (!(s5h1420_readreg(state
, 0x3b) & 0x08))
196 if (time_after(jiffies
, timeout
))
199 /* restore original settings */
200 s5h1420_writereg(state
, 0x3b, val
);
202 dprintk("leave %s\n", __func__
);
206 static int s5h1420_recv_slave_reply (struct dvb_frontend
* fe
,
207 struct dvb_diseqc_slave_reply
* reply
)
209 struct s5h1420_state
* state
= fe
->demodulator_priv
;
213 unsigned long timeout
;
216 /* setup for DISEQC receive */
217 val
= s5h1420_readreg(state
, 0x3b);
218 s5h1420_writereg(state
, 0x3b, 0x82); /* FIXME: guess - do we need to set DIS_RDY(0x08) in receive mode? */
221 /* wait for reception to complete */
222 timeout
= jiffies
+ ((reply
->timeout
*HZ
) / 1000);
223 while(time_before(jiffies
, timeout
)) {
224 if (!(s5h1420_readreg(state
, 0x3b) & 0x80)) /* FIXME: do we test DIS_RDY(0x08) or RCV_EN(0x80)? */
229 if (time_after(jiffies
, timeout
)) {
234 /* check error flag - FIXME: not sure what this does - docs do not describe
235 * beyond "error flag for diseqc receive data :( */
236 if (s5h1420_readreg(state
, 0x49)) {
242 length
= (s5h1420_readreg(state
, 0x3b) & 0x70) >> 4;
243 if (length
> sizeof(reply
->msg
)) {
247 reply
->msg_len
= length
;
250 for(i
=0; i
< length
; i
++) {
251 reply
->msg
[i
] = s5h1420_readreg(state
, 0x3d + i
);
255 /* restore original settings */
256 s5h1420_writereg(state
, 0x3b, val
);
261 static int s5h1420_send_burst(struct dvb_frontend
*fe
,
262 enum fe_sec_mini_cmd minicmd
)
264 struct s5h1420_state
* state
= fe
->demodulator_priv
;
267 unsigned long timeout
;
269 /* setup for tone burst */
270 val
= s5h1420_readreg(state
, 0x3b);
271 s5h1420_writereg(state
, 0x3b, (s5h1420_readreg(state
, 0x3b) & 0x70) | 0x01);
273 /* set value for B position if requested */
274 if (minicmd
== SEC_MINI_B
) {
275 s5h1420_writereg(state
, 0x3b, s5h1420_readreg(state
, 0x3b) | 0x04);
279 /* start transmission */
280 s5h1420_writereg(state
, 0x3b, s5h1420_readreg(state
, 0x3b) | 0x08);
282 /* wait for transmission to complete */
283 timeout
= jiffies
+ ((100*HZ
) / 1000);
284 while(time_before(jiffies
, timeout
)) {
285 if (!(s5h1420_readreg(state
, 0x3b) & 0x08))
290 if (time_after(jiffies
, timeout
))
293 /* restore original settings */
294 s5h1420_writereg(state
, 0x3b, val
);
299 static enum fe_status
s5h1420_get_status_bits(struct s5h1420_state
*state
)
302 enum fe_status status
= 0;
304 val
= s5h1420_readreg(state
, 0x14);
306 status
|= FE_HAS_SIGNAL
;
308 status
|= FE_HAS_CARRIER
;
309 val
= s5h1420_readreg(state
, 0x36);
311 status
|= FE_HAS_VITERBI
;
313 status
|= FE_HAS_SYNC
;
314 if (status
== (FE_HAS_SIGNAL
|FE_HAS_CARRIER
|FE_HAS_VITERBI
|FE_HAS_SYNC
))
315 status
|= FE_HAS_LOCK
;
320 static int s5h1420_read_status(struct dvb_frontend
*fe
,
321 enum fe_status
*status
)
323 struct s5h1420_state
* state
= fe
->demodulator_priv
;
326 dprintk("enter %s\n", __func__
);
331 /* determine lock state */
332 *status
= s5h1420_get_status_bits(state
);
334 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert
335 the inversion, wait a bit and check again */
336 if (*status
== (FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_VITERBI
)) {
337 val
= s5h1420_readreg(state
, Vit10
);
338 if ((val
& 0x07) == 0x03) {
340 s5h1420_writereg(state
, Vit09
, 0x13);
342 s5h1420_writereg(state
, Vit09
, 0x1b);
344 /* wait a bit then update lock status */
346 *status
= s5h1420_get_status_bits(state
);
350 /* perform post lock setup */
351 if ((*status
& FE_HAS_LOCK
) && !state
->postlocked
) {
353 /* calculate the data rate */
354 u32 tmp
= s5h1420_getsymbolrate(state
);
355 switch (s5h1420_readreg(state
, Vit10
) & 0x07) {
356 case 0: tmp
= (tmp
* 2 * 1) / 2; break;
357 case 1: tmp
= (tmp
* 2 * 2) / 3; break;
358 case 2: tmp
= (tmp
* 2 * 3) / 4; break;
359 case 3: tmp
= (tmp
* 2 * 5) / 6; break;
360 case 4: tmp
= (tmp
* 2 * 6) / 7; break;
361 case 5: tmp
= (tmp
* 2 * 7) / 8; break;
365 printk(KERN_ERR
"s5h1420: avoided division by 0\n");
368 tmp
= state
->fclk
/ tmp
;
371 /* set the MPEG_CLK_INTL for the calculated data rate */
388 dprintk("for MPEG_CLK_INTL %d %x\n", tmp
, val
);
390 s5h1420_writereg(state
, FEC01
, 0x18);
391 s5h1420_writereg(state
, FEC01
, 0x10);
392 s5h1420_writereg(state
, FEC01
, val
);
394 /* Enable "MPEG_Out" */
395 val
= s5h1420_readreg(state
, Mpeg02
);
396 s5h1420_writereg(state
, Mpeg02
, val
| (1 << 6));
399 val
= s5h1420_readreg(state
, QPSK01
) & 0x7f;
400 s5h1420_writereg(state
, QPSK01
, val
);
402 /* DC freeze TODO it was never activated by default or it can stay activated */
404 if (s5h1420_getsymbolrate(state
) >= 20000000) {
405 s5h1420_writereg(state
, Loop04
, 0x8a);
406 s5h1420_writereg(state
, Loop05
, 0x6a);
408 s5h1420_writereg(state
, Loop04
, 0x58);
409 s5h1420_writereg(state
, Loop05
, 0x27);
412 /* post-lock processing has been done! */
413 state
->postlocked
= 1;
416 dprintk("leave %s\n", __func__
);
421 static int s5h1420_read_ber(struct dvb_frontend
* fe
, u32
* ber
)
423 struct s5h1420_state
* state
= fe
->demodulator_priv
;
425 s5h1420_writereg(state
, 0x46, 0x1d);
428 *ber
= (s5h1420_readreg(state
, 0x48) << 8) | s5h1420_readreg(state
, 0x47);
433 static int s5h1420_read_signal_strength(struct dvb_frontend
* fe
, u16
* strength
)
435 struct s5h1420_state
* state
= fe
->demodulator_priv
;
437 u8 val
= s5h1420_readreg(state
, 0x15);
439 *strength
= (u16
) ((val
<< 8) | val
);
444 static int s5h1420_read_ucblocks(struct dvb_frontend
* fe
, u32
* ucblocks
)
446 struct s5h1420_state
* state
= fe
->demodulator_priv
;
448 s5h1420_writereg(state
, 0x46, 0x1f);
451 *ucblocks
= (s5h1420_readreg(state
, 0x48) << 8) | s5h1420_readreg(state
, 0x47);
456 static void s5h1420_reset(struct s5h1420_state
* state
)
458 dprintk("%s\n", __func__
);
459 s5h1420_writereg (state
, 0x01, 0x08);
460 s5h1420_writereg (state
, 0x01, 0x00);
464 static void s5h1420_setsymbolrate(struct s5h1420_state
* state
,
465 struct dtv_frontend_properties
*p
)
470 dprintk("enter %s\n", __func__
);
472 val
= ((u64
) p
->symbol_rate
/ 1000ULL) * (1ULL<<24);
473 if (p
->symbol_rate
< 29000000)
475 do_div(val
, (state
->fclk
/ 1000));
477 dprintk("symbol rate register: %06llx\n", (unsigned long long)val
);
479 v
= s5h1420_readreg(state
, Loop01
);
480 s5h1420_writereg(state
, Loop01
, v
& 0x7f);
481 s5h1420_writereg(state
, Tnco01
, val
>> 16);
482 s5h1420_writereg(state
, Tnco02
, val
>> 8);
483 s5h1420_writereg(state
, Tnco03
, val
& 0xff);
484 s5h1420_writereg(state
, Loop01
, v
| 0x80);
485 dprintk("leave %s\n", __func__
);
488 static u32
s5h1420_getsymbolrate(struct s5h1420_state
* state
)
490 return state
->symbol_rate
;
493 static void s5h1420_setfreqoffset(struct s5h1420_state
* state
, int freqoffset
)
498 dprintk("enter %s\n", __func__
);
500 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
501 * divide fclk by 1000000 to get the correct value. */
502 val
= -(int) ((freqoffset
* (1<<24)) / (state
->fclk
/ 1000000));
504 dprintk("phase rotator/freqoffset: %d %06x\n", freqoffset
, val
);
506 v
= s5h1420_readreg(state
, Loop01
);
507 s5h1420_writereg(state
, Loop01
, v
& 0xbf);
508 s5h1420_writereg(state
, Pnco01
, val
>> 16);
509 s5h1420_writereg(state
, Pnco02
, val
>> 8);
510 s5h1420_writereg(state
, Pnco03
, val
& 0xff);
511 s5h1420_writereg(state
, Loop01
, v
| 0x40);
512 dprintk("leave %s\n", __func__
);
515 static int s5h1420_getfreqoffset(struct s5h1420_state
* state
)
519 s5h1420_writereg(state
, 0x06, s5h1420_readreg(state
, 0x06) | 0x08);
520 val
= s5h1420_readreg(state
, 0x0e) << 16;
521 val
|= s5h1420_readreg(state
, 0x0f) << 8;
522 val
|= s5h1420_readreg(state
, 0x10);
523 s5h1420_writereg(state
, 0x06, s5h1420_readreg(state
, 0x06) & 0xf7);
528 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
529 * divide fclk by 1000000 to get the correct value. */
530 val
= (((-val
) * (state
->fclk
/1000000)) / (1<<24));
535 static void s5h1420_setfec_inversion(struct s5h1420_state
* state
,
536 struct dtv_frontend_properties
*p
)
541 dprintk("enter %s\n", __func__
);
543 if (p
->inversion
== INVERSION_OFF
)
544 inversion
= state
->config
->invert
? 0x08 : 0;
545 else if (p
->inversion
== INVERSION_ON
)
546 inversion
= state
->config
->invert
? 0 : 0x08;
548 if ((p
->fec_inner
== FEC_AUTO
) || (p
->inversion
== INVERSION_AUTO
)) {
552 switch (p
->fec_inner
) {
588 dprintk("fec: %02x %02x\n", vit08
, vit09
);
589 s5h1420_writereg(state
, Vit08
, vit08
);
590 s5h1420_writereg(state
, Vit09
, vit09
);
591 dprintk("leave %s\n", __func__
);
594 static enum fe_code_rate
s5h1420_getfec(struct s5h1420_state
*state
)
596 switch(s5h1420_readreg(state
, 0x32) & 0x07) {
619 static enum fe_spectral_inversion
620 s5h1420_getinversion(struct s5h1420_state
*state
)
622 if (s5h1420_readreg(state
, 0x32) & 0x08)
625 return INVERSION_OFF
;
628 static int s5h1420_set_frontend(struct dvb_frontend
*fe
)
630 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
631 struct s5h1420_state
* state
= fe
->demodulator_priv
;
633 struct dvb_frontend_tune_settings fesettings
;
635 dprintk("enter %s\n", __func__
);
637 /* check if we should do a fast-tune */
638 s5h1420_get_tune_settings(fe
, &fesettings
);
639 frequency_delta
= p
->frequency
- state
->tunedfreq
;
640 if ((frequency_delta
> -fesettings
.max_drift
) &&
641 (frequency_delta
< fesettings
.max_drift
) &&
642 (frequency_delta
!= 0) &&
643 (state
->fec_inner
== p
->fec_inner
) &&
644 (state
->symbol_rate
== p
->symbol_rate
)) {
646 if (fe
->ops
.tuner_ops
.set_params
) {
647 fe
->ops
.tuner_ops
.set_params(fe
);
648 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
650 if (fe
->ops
.tuner_ops
.get_frequency
) {
652 fe
->ops
.tuner_ops
.get_frequency(fe
, &tmp
);
653 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
654 s5h1420_setfreqoffset(state
, p
->frequency
- tmp
);
656 s5h1420_setfreqoffset(state
, 0);
658 dprintk("simple tune\n");
661 dprintk("tuning demod\n");
663 /* first of all, software reset */
664 s5h1420_reset(state
);
666 /* set s5h1420 fclk PLL according to desired symbol rate */
667 if (p
->symbol_rate
> 33000000)
668 state
->fclk
= 80000000;
669 else if (p
->symbol_rate
> 28500000)
670 state
->fclk
= 59000000;
671 else if (p
->symbol_rate
> 25000000)
672 state
->fclk
= 86000000;
673 else if (p
->symbol_rate
> 1900000)
674 state
->fclk
= 88000000;
676 state
->fclk
= 44000000;
678 dprintk("pll01: %d, ToneFreq: %d\n", state
->fclk
/1000000 - 8, (state
->fclk
+ (TONE_FREQ
* 32) - 1) / (TONE_FREQ
* 32));
679 s5h1420_writereg(state
, PLL01
, state
->fclk
/1000000 - 8);
680 s5h1420_writereg(state
, PLL02
, 0x40);
681 s5h1420_writereg(state
, DiS01
, (state
->fclk
+ (TONE_FREQ
* 32) - 1) / (TONE_FREQ
* 32));
683 /* TODO DC offset removal, config parameter ? */
684 if (p
->symbol_rate
> 29000000)
685 s5h1420_writereg(state
, QPSK01
, 0xae | 0x10);
687 s5h1420_writereg(state
, QPSK01
, 0xac | 0x10);
689 /* set misc registers */
690 s5h1420_writereg(state
, CON_1
, 0x00);
691 s5h1420_writereg(state
, QPSK02
, 0x00);
692 s5h1420_writereg(state
, Pre01
, 0xb0);
694 s5h1420_writereg(state
, Loop01
, 0xF0);
695 s5h1420_writereg(state
, Loop02
, 0x2a); /* e7 for s5h1420 */
696 s5h1420_writereg(state
, Loop03
, 0x79); /* 78 for s5h1420 */
697 if (p
->symbol_rate
> 20000000)
698 s5h1420_writereg(state
, Loop04
, 0x79);
700 s5h1420_writereg(state
, Loop04
, 0x58);
701 s5h1420_writereg(state
, Loop05
, 0x6b);
703 if (p
->symbol_rate
>= 8000000)
704 s5h1420_writereg(state
, Post01
, (0 << 6) | 0x10);
705 else if (p
->symbol_rate
>= 4000000)
706 s5h1420_writereg(state
, Post01
, (1 << 6) | 0x10);
708 s5h1420_writereg(state
, Post01
, (3 << 6) | 0x10);
710 s5h1420_writereg(state
, Monitor12
, 0x00); /* unfreeze DC compensation */
712 s5h1420_writereg(state
, Sync01
, 0x33);
713 s5h1420_writereg(state
, Mpeg01
, state
->config
->cdclk_polarity
);
714 s5h1420_writereg(state
, Mpeg02
, 0x3d); /* Parallel output more, disabled -> enabled later */
715 s5h1420_writereg(state
, Err01
, 0x03); /* 0x1d for s5h1420 */
717 s5h1420_writereg(state
, Vit06
, 0x6e); /* 0x8e for s5h1420 */
718 s5h1420_writereg(state
, DiS03
, 0x00);
719 s5h1420_writereg(state
, Rf01
, 0x61); /* Tuner i2c address - for the gate controller */
722 if (fe
->ops
.tuner_ops
.set_params
) {
723 fe
->ops
.tuner_ops
.set_params(fe
);
724 if (fe
->ops
.i2c_gate_ctrl
)
725 fe
->ops
.i2c_gate_ctrl(fe
, 0);
726 s5h1420_setfreqoffset(state
, 0);
729 /* set the reset of the parameters */
730 s5h1420_setsymbolrate(state
, p
);
731 s5h1420_setfec_inversion(state
, p
);
734 s5h1420_writereg(state
, QPSK01
, s5h1420_readreg(state
, QPSK01
) | 1);
736 state
->fec_inner
= p
->fec_inner
;
737 state
->symbol_rate
= p
->symbol_rate
;
738 state
->postlocked
= 0;
739 state
->tunedfreq
= p
->frequency
;
741 dprintk("leave %s\n", __func__
);
745 static int s5h1420_get_frontend(struct dvb_frontend
* fe
,
746 struct dtv_frontend_properties
*p
)
748 struct s5h1420_state
* state
= fe
->demodulator_priv
;
750 p
->frequency
= state
->tunedfreq
+ s5h1420_getfreqoffset(state
);
751 p
->inversion
= s5h1420_getinversion(state
);
752 p
->symbol_rate
= s5h1420_getsymbolrate(state
);
753 p
->fec_inner
= s5h1420_getfec(state
);
758 static int s5h1420_get_tune_settings(struct dvb_frontend
* fe
,
759 struct dvb_frontend_tune_settings
* fesettings
)
761 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
762 if (p
->symbol_rate
> 20000000) {
763 fesettings
->min_delay_ms
= 50;
764 fesettings
->step_size
= 2000;
765 fesettings
->max_drift
= 8000;
766 } else if (p
->symbol_rate
> 12000000) {
767 fesettings
->min_delay_ms
= 100;
768 fesettings
->step_size
= 1500;
769 fesettings
->max_drift
= 9000;
770 } else if (p
->symbol_rate
> 8000000) {
771 fesettings
->min_delay_ms
= 100;
772 fesettings
->step_size
= 1000;
773 fesettings
->max_drift
= 8000;
774 } else if (p
->symbol_rate
> 4000000) {
775 fesettings
->min_delay_ms
= 100;
776 fesettings
->step_size
= 500;
777 fesettings
->max_drift
= 7000;
778 } else if (p
->symbol_rate
> 2000000) {
779 fesettings
->min_delay_ms
= 200;
780 fesettings
->step_size
= (p
->symbol_rate
/ 8000);
781 fesettings
->max_drift
= 14 * fesettings
->step_size
;
783 fesettings
->min_delay_ms
= 200;
784 fesettings
->step_size
= (p
->symbol_rate
/ 8000);
785 fesettings
->max_drift
= 18 * fesettings
->step_size
;
791 static int s5h1420_i2c_gate_ctrl(struct dvb_frontend
* fe
, int enable
)
793 struct s5h1420_state
* state
= fe
->demodulator_priv
;
796 return s5h1420_writereg(state
, 0x02, state
->CON_1_val
| 1);
798 return s5h1420_writereg(state
, 0x02, state
->CON_1_val
& 0xfe);
801 static int s5h1420_init (struct dvb_frontend
* fe
)
803 struct s5h1420_state
* state
= fe
->demodulator_priv
;
805 /* disable power down and do reset */
806 state
->CON_1_val
= state
->config
->serial_mpeg
<< 4;
807 s5h1420_writereg(state
, 0x02, state
->CON_1_val
);
809 s5h1420_reset(state
);
814 static int s5h1420_sleep(struct dvb_frontend
* fe
)
816 struct s5h1420_state
* state
= fe
->demodulator_priv
;
817 state
->CON_1_val
= 0x12;
818 return s5h1420_writereg(state
, 0x02, state
->CON_1_val
);
821 static void s5h1420_release(struct dvb_frontend
* fe
)
823 struct s5h1420_state
* state
= fe
->demodulator_priv
;
824 i2c_del_adapter(&state
->tuner_i2c_adapter
);
828 static u32
s5h1420_tuner_i2c_func(struct i2c_adapter
*adapter
)
833 static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg msg
[], int num
)
835 struct s5h1420_state
*state
= i2c_get_adapdata(i2c_adap
);
837 u8 tx_open
[2] = { CON_1
, state
->CON_1_val
| 1 }; /* repeater stops once there was a stop condition */
839 if (1 + num
> ARRAY_SIZE(m
)) {
841 "%s: i2c xfer: num=%d is too big!\n",
842 KBUILD_MODNAME
, num
);
846 memset(m
, 0, sizeof(struct i2c_msg
) * (1 + num
));
848 m
[0].addr
= state
->config
->demod_address
;
852 memcpy(&m
[1], msg
, sizeof(struct i2c_msg
) * num
);
854 return i2c_transfer(state
->i2c
, m
, 1 + num
) == 1 + num
? num
: -EIO
;
857 static const struct i2c_algorithm s5h1420_tuner_i2c_algo
= {
858 .master_xfer
= s5h1420_tuner_i2c_tuner_xfer
,
859 .functionality
= s5h1420_tuner_i2c_func
,
862 struct i2c_adapter
*s5h1420_get_tuner_i2c_adapter(struct dvb_frontend
*fe
)
864 struct s5h1420_state
*state
= fe
->demodulator_priv
;
865 return &state
->tuner_i2c_adapter
;
867 EXPORT_SYMBOL(s5h1420_get_tuner_i2c_adapter
);
869 static const struct dvb_frontend_ops s5h1420_ops
;
871 struct dvb_frontend
*s5h1420_attach(const struct s5h1420_config
*config
,
872 struct i2c_adapter
*i2c
)
874 /* allocate memory for the internal state */
875 struct s5h1420_state
*state
= kzalloc(sizeof(struct s5h1420_state
), GFP_KERNEL
);
881 /* setup the state */
882 state
->config
= config
;
884 state
->postlocked
= 0;
885 state
->fclk
= 88000000;
886 state
->tunedfreq
= 0;
887 state
->fec_inner
= FEC_NONE
;
888 state
->symbol_rate
= 0;
890 /* check if the demod is there + identify it */
891 i
= s5h1420_readreg(state
, ID01
);
895 memset(state
->shadow
, 0xff, sizeof(state
->shadow
));
897 for (i
= 0; i
< 0x50; i
++)
898 state
->shadow
[i
] = s5h1420_readreg(state
, i
);
900 /* create dvb_frontend */
901 memcpy(&state
->frontend
.ops
, &s5h1420_ops
, sizeof(struct dvb_frontend_ops
));
902 state
->frontend
.demodulator_priv
= state
;
904 /* create tuner i2c adapter */
905 strscpy(state
->tuner_i2c_adapter
.name
, "S5H1420-PN1010 tuner I2C bus",
906 sizeof(state
->tuner_i2c_adapter
.name
));
907 state
->tuner_i2c_adapter
.algo
= &s5h1420_tuner_i2c_algo
;
908 state
->tuner_i2c_adapter
.algo_data
= NULL
;
909 i2c_set_adapdata(&state
->tuner_i2c_adapter
, state
);
910 if (i2c_add_adapter(&state
->tuner_i2c_adapter
) < 0) {
911 printk(KERN_ERR
"S5H1420/PN1010: tuner i2c bus could not be initialized\n");
915 return &state
->frontend
;
921 EXPORT_SYMBOL(s5h1420_attach
);
923 static const struct dvb_frontend_ops s5h1420_ops
= {
924 .delsys
= { SYS_DVBS
},
926 .name
= "Samsung S5H1420/PnpNetwork PN1010 DVB-S",
927 .frequency_min_hz
= 950 * MHz
,
928 .frequency_max_hz
= 2150 * MHz
,
929 .frequency_stepsize_hz
= 125 * kHz
,
930 .frequency_tolerance_hz
= 29500 * kHz
,
931 .symbol_rate_min
= 1000000,
932 .symbol_rate_max
= 45000000,
933 /* .symbol_rate_tolerance = ???,*/
934 .caps
= FE_CAN_INVERSION_AUTO
|
935 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
936 FE_CAN_FEC_5_6
| FE_CAN_FEC_6_7
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
940 .release
= s5h1420_release
,
942 .init
= s5h1420_init
,
943 .sleep
= s5h1420_sleep
,
944 .i2c_gate_ctrl
= s5h1420_i2c_gate_ctrl
,
946 .set_frontend
= s5h1420_set_frontend
,
947 .get_frontend
= s5h1420_get_frontend
,
948 .get_tune_settings
= s5h1420_get_tune_settings
,
950 .read_status
= s5h1420_read_status
,
951 .read_ber
= s5h1420_read_ber
,
952 .read_signal_strength
= s5h1420_read_signal_strength
,
953 .read_ucblocks
= s5h1420_read_ucblocks
,
955 .diseqc_send_master_cmd
= s5h1420_send_master_cmd
,
956 .diseqc_recv_slave_reply
= s5h1420_recv_slave_reply
,
957 .diseqc_send_burst
= s5h1420_send_burst
,
958 .set_tone
= s5h1420_set_tone
,
959 .set_voltage
= s5h1420_set_voltage
,
962 MODULE_DESCRIPTION("Samsung S5H1420/PnpNetwork PN1010 DVB-S Demodulator driver");
963 MODULE_AUTHOR("Andrew de Quincey, Patrick Boettcher");
964 MODULE_LICENSE("GPL");