1 // SPDX-License-Identifier: GPL-2.0
4 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5 * common control functions
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
10 #include <media/dvb_frontend.h>
11 #include "cxd2880_common.h"
12 #include "cxd2880_tnrdmd.h"
13 #include "cxd2880_tnrdmd_mon.h"
14 #include "cxd2880_tnrdmd_dvbt.h"
15 #include "cxd2880_tnrdmd_dvbt2.h"
17 static const struct cxd2880_reg_value p_init1_seq
[] = {
18 {0x11, 0x16}, {0x00, 0x10},
21 static const struct cxd2880_reg_value rf_init1_seq1
[] = {
22 {0x4f, 0x18}, {0x61, 0x00}, {0x71, 0x00}, {0x9d, 0x01},
23 {0x7d, 0x02}, {0x8f, 0x01}, {0x8b, 0xc6}, {0x9a, 0x03},
27 static const struct cxd2880_reg_value rf_init1_seq2
[] = {
28 {0xb9, 0x07}, {0x33, 0x01}, {0xc1, 0x01}, {0xc4, 0x1e},
31 static const struct cxd2880_reg_value rf_init1_seq3
[] = {
32 {0x00, 0x10}, {0x51, 0x01}, {0xc5, 0x07}, {0x00, 0x11},
33 {0x70, 0xe9}, {0x76, 0x0a}, {0x78, 0x32}, {0x7a, 0x46},
34 {0x7c, 0x86}, {0x7e, 0xa4}, {0x00, 0x10}, {0xe1, 0x01},
37 static const struct cxd2880_reg_value rf_init1_seq4
[] = {
38 {0x15, 0x00}, {0x00, 0x16}
41 static const struct cxd2880_reg_value rf_init1_seq5
[] = {
42 {0x00, 0x00}, {0x25, 0x00}
45 static const struct cxd2880_reg_value rf_init1_seq6
[] = {
46 {0x02, 0x00}, {0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe1},
47 {0x8f, 0x16}, {0x67, 0x60}, {0x6a, 0x0f}, {0x6c, 0x17}
50 static const struct cxd2880_reg_value rf_init1_seq7
[] = {
51 {0x00, 0xe2}, {0x41, 0xa0}, {0x4b, 0x68}, {0x00, 0x00},
52 {0x21, 0x00}, {0x10, 0x01},
55 static const struct cxd2880_reg_value rf_init1_seq8
[] = {
56 {0x00, 0x10}, {0x25, 0x01},
59 static const struct cxd2880_reg_value rf_init1_seq9
[] = {
60 {0x00, 0x10}, {0x14, 0x01}, {0x00, 0x00}, {0x26, 0x00},
63 static const struct cxd2880_reg_value rf_init2_seq1
[] = {
64 {0x00, 0x14}, {0x1b, 0x01},
67 static const struct cxd2880_reg_value rf_init2_seq2
[] = {
68 {0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe1}, {0xd3, 0x00},
69 {0x00, 0x00}, {0x21, 0x00},
72 static const struct cxd2880_reg_value x_tune1_seq1
[] = {
73 {0x00, 0x00}, {0x10, 0x01},
76 static const struct cxd2880_reg_value x_tune1_seq2
[] = {
77 {0x62, 0x00}, {0x00, 0x15},
80 static const struct cxd2880_reg_value x_tune2_seq1
[] = {
81 {0x00, 0x1a}, {0x29, 0x01},
84 static const struct cxd2880_reg_value x_tune2_seq2
[] = {
85 {0x62, 0x01}, {0x00, 0x11}, {0x2d, 0x00}, {0x2f, 0x00},
88 static const struct cxd2880_reg_value x_tune2_seq3
[] = {
89 {0x00, 0x00}, {0x10, 0x00}, {0x21, 0x01},
92 static const struct cxd2880_reg_value x_tune2_seq4
[] = {
93 {0x00, 0xe1}, {0x8a, 0x87},
96 static const struct cxd2880_reg_value x_tune2_seq5
[] = {
97 {0x00, 0x00}, {0x21, 0x00},
100 static const struct cxd2880_reg_value x_tune3_seq
[] = {
101 {0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe2}, {0x41, 0xa0},
102 {0x00, 0x00}, {0x21, 0x00}, {0xfe, 0x01},
105 static const struct cxd2880_reg_value x_tune4_seq
[] = {
106 {0x00, 0x00}, {0xfe, 0x01},
109 static const struct cxd2880_reg_value x_sleep1_seq
[] = {
110 {0x00, 0x00}, {0x57, 0x03},
113 static const struct cxd2880_reg_value x_sleep2_seq1
[] = {
114 {0x00, 0x2d}, {0xb1, 0x01},
117 static const struct cxd2880_reg_value x_sleep2_seq2
[] = {
118 {0x00, 0x10}, {0xf4, 0x00}, {0xf3, 0x00}, {0xf2, 0x00},
119 {0xf1, 0x00}, {0xf0, 0x00}, {0xef, 0x00},
122 static const struct cxd2880_reg_value x_sleep3_seq
[] = {
123 {0x00, 0x00}, {0xfd, 0x00},
126 static const struct cxd2880_reg_value x_sleep4_seq
[] = {
127 {0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe2}, {0x41, 0x00},
128 {0x00, 0x00}, {0x21, 0x00},
131 static const struct cxd2880_reg_value spll_reset_seq1
[] = {
132 {0x00, 0x10}, {0x29, 0x01}, {0x28, 0x01}, {0x27, 0x01},
136 static const struct cxd2880_reg_value spll_reset_seq2
[] = {
137 {0x00, 0x00}, {0x10, 0x00},
140 static const struct cxd2880_reg_value spll_reset_seq3
[] = {
141 {0x00, 0x00}, {0x27, 0x00}, {0x22, 0x01},
144 static const struct cxd2880_reg_value spll_reset_seq4
[] = {
145 {0x00, 0x00}, {0x27, 0x01},
148 static const struct cxd2880_reg_value spll_reset_seq5
[] = {
149 {0x00, 0x00}, {0x10, 0x01},
152 static const struct cxd2880_reg_value t_power_x_seq1
[] = {
153 {0x00, 0x10}, {0x29, 0x01}, {0x28, 0x01}, {0x27, 0x01},
156 static const struct cxd2880_reg_value t_power_x_seq2
[] = {
157 {0x00, 0x00}, {0x10, 0x00},
160 static const struct cxd2880_reg_value t_power_x_seq3
[] = {
161 {0x00, 0x00}, {0x27, 0x00}, {0x25, 0x01},
164 static const struct cxd2880_reg_value t_power_x_seq4
[] = {
165 {0x00, 0x00}, {0x2a, 0x00},
168 static const struct cxd2880_reg_value t_power_x_seq5
[] = {
169 {0x00, 0x00}, {0x25, 0x00},
172 static const struct cxd2880_reg_value t_power_x_seq6
[] = {
173 {0x00, 0x00}, {0x27, 0x01},
176 static const struct cxd2880_reg_value t_power_x_seq7
[] = {
177 {0x00, 0x00}, {0x10, 0x01},
180 static const struct cxd2880_reg_value set_ts_pin_seq
[] = {
181 {0x50, 0x3f}, {0x52, 0x1f},
185 static const struct cxd2880_reg_value set_ts_output_seq1
[] = {
186 {0x00, 0x00}, {0x52, 0x00},
189 static const struct cxd2880_reg_value set_ts_output_seq2
[] = {
190 {0x00, 0x00}, {0xc3, 0x00},
194 static const struct cxd2880_reg_value set_ts_output_seq3
[] = {
195 {0x00, 0x00}, {0xc3, 0x01},
199 static const struct cxd2880_reg_value set_ts_output_seq4
[] = {
200 {0x00, 0x00}, {0x52, 0x1f},
204 static int p_init1(struct cxd2880_tnrdmd
*tnr_dmd
)
212 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
218 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SINGLE
||
219 tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
220 switch (tnr_dmd
->create_param
.ts_output_if
) {
221 case CXD2880_TNRDMD_TSOUT_IF_TS
:
224 case CXD2880_TNRDMD_TSOUT_IF_SPI
:
227 case CXD2880_TNRDMD_TSOUT_IF_SDIO
:
233 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
240 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
243 ARRAY_SIZE(p_init1_seq
));
247 switch (tnr_dmd
->chip_id
) {
248 case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X
:
251 case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11
:
258 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
264 if (tnr_dmd
->create_param
.en_internal_ldo
)
269 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
274 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
280 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
285 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
291 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
297 switch (tnr_dmd
->chip_id
) {
298 case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X
:
301 case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11
:
308 return tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
313 static int p_init2(struct cxd2880_tnrdmd
*tnr_dmd
)
321 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
326 data
[0] = tnr_dmd
->create_param
.xosc_cap
;
327 data
[1] = tnr_dmd
->create_param
.xosc_i
;
328 switch (tnr_dmd
->create_param
.xtal_share_type
) {
329 case CXD2880_TNRDMD_XTAL_SHARE_NONE
:
333 case CXD2880_TNRDMD_XTAL_SHARE_EXTREF
:
337 case CXD2880_TNRDMD_XTAL_SHARE_MASTER
:
341 case CXD2880_TNRDMD_XTAL_SHARE_SLAVE
:
351 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
356 static int p_init3(struct cxd2880_tnrdmd
*tnr_dmd
)
364 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
370 switch (tnr_dmd
->diver_mode
) {
371 case CXD2880_TNRDMD_DIVERMODE_SINGLE
:
374 case CXD2880_TNRDMD_DIVERMODE_MAIN
:
377 case CXD2880_TNRDMD_DIVERMODE_SUB
:
386 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
391 static int rf_init1(struct cxd2880_tnrdmd
*tnr_dmd
)
394 static const u8 rf_init1_cdata1
[40] = {
395 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
396 0x05, 0x05, 0x04, 0x04, 0x04, 0x03, 0x03,
397 0x03, 0x04, 0x04, 0x05, 0x05, 0x05, 0x02,
398 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
399 0x02, 0x03, 0x02, 0x01, 0x01, 0x01, 0x02,
400 0x02, 0x03, 0x04, 0x04, 0x04
403 static const u8 rf_init1_cdata2
[5] = {0xff, 0x00, 0x00, 0x00, 0x00};
404 static const u8 rf_init1_cdata3
[80] = {
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
406 0x01, 0x00, 0x02, 0x00, 0x63, 0x00, 0x00,
407 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00,
408 0x06, 0x00, 0x06, 0x00, 0x08, 0x00, 0x09,
409 0x00, 0x0b, 0x00, 0x0b, 0x00, 0x0d, 0x00,
410 0x0d, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f,
411 0x00, 0x10, 0x00, 0x79, 0x00, 0x00, 0x00,
412 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01,
413 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00,
414 0x04, 0x00, 0x04, 0x00, 0x06, 0x00, 0x05,
415 0x00, 0x07, 0x00, 0x07, 0x00, 0x08, 0x00,
419 static const u8 rf_init1_cdata4
[8] = {
420 0x20, 0x20, 0x30, 0x41, 0x50, 0x5f, 0x6f, 0x80
423 static const u8 rf_init1_cdata5
[50] = {
424 0x00, 0x09, 0x00, 0x08, 0x00, 0x07, 0x00,
425 0x06, 0x00, 0x05, 0x00, 0x03, 0x00, 0x02,
426 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
427 0x06, 0x00, 0x08, 0x00, 0x08, 0x00, 0x0c,
428 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0f, 0x00,
429 0x0e, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x0f,
430 0x00, 0x0e, 0x00, 0x10, 0x00, 0x0f, 0x00,
440 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
448 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
454 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
461 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
467 if (tnr_dmd
->create_param
.stationary_use
) {
468 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
475 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
478 ARRAY_SIZE(rf_init1_seq1
));
483 if (tnr_dmd
->create_param
.is_cxd2881gg
&&
484 tnr_dmd
->create_param
.xtal_share_type
==
485 CXD2880_TNRDMD_XTAL_SHARE_SLAVE
)
490 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
496 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
499 ARRAY_SIZE(rf_init1_seq2
));
503 if (tnr_dmd
->chip_id
== CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X
) {
516 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
522 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
530 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
537 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
546 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
551 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
556 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
558 0x7f, rf_init1_cdata1
, 40);
562 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
569 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
574 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
580 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
582 0x27, rf_init1_cdata2
, 5);
586 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
588 0x3a, rf_init1_cdata3
, 80);
594 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
600 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
603 ARRAY_SIZE(rf_init1_seq3
));
607 if (tnr_dmd
->create_param
.stationary_use
) {
620 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
625 for (addr
= 0x10; addr
< 0x9f; addr
+= 6) {
626 if (tnr_dmd
->lna_thrs_tbl_air
) {
629 idx
= (addr
- 0x10) / 6;
631 tnr_dmd
->lna_thrs_tbl_air
->thrs
[idx
].off_on
;
633 tnr_dmd
->lna_thrs_tbl_air
->thrs
[idx
].on_off
;
635 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
644 if (tnr_dmd
->create_param
.stationary_use
)
652 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
657 for (addr
= 0x10; addr
< 0xcf; addr
+= 6) {
658 if (tnr_dmd
->lna_thrs_tbl_cable
) {
661 idx
= (addr
- 0x10) / 6;
663 tnr_dmd
->lna_thrs_tbl_cable
->thrs
[idx
].off_on
;
665 tnr_dmd
->lna_thrs_tbl_cable
->thrs
[idx
].on_off
;
667 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
674 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
681 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
688 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
694 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
696 0xc9, rf_init1_cdata4
, 8);
700 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
708 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
714 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
717 ARRAY_SIZE(rf_init1_seq4
));
721 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
723 0x12, rf_init1_cdata5
, 50);
727 usleep_range(1000, 2000);
729 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
734 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
739 if ((data
[0] & 0x01) == 0x00)
742 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
745 ARRAY_SIZE(rf_init1_seq5
));
749 usleep_range(1000, 2000);
751 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
756 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
761 if ((data
[0] & 0x01) == 0x00)
764 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
767 ARRAY_SIZE(rf_init1_seq6
));
774 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
781 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
788 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
794 if (tnr_dmd
->create_param
.stationary_use
) {
795 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
802 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
805 ARRAY_SIZE(rf_init1_seq7
));
809 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
812 ARRAY_SIZE(rf_init1_seq8
));
816 usleep_range(1000, 2000);
818 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
823 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
828 if ((data
[0] & 0x01) == 0x00)
831 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
834 ARRAY_SIZE(rf_init1_seq9
));
837 static int rf_init2(struct cxd2880_tnrdmd
*tnr_dmd
)
845 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
852 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
858 usleep_range(1000, 2000);
861 if (tnr_dmd
->chip_id
== CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X
)
867 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
873 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
876 ARRAY_SIZE(rf_init2_seq1
));
880 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
883 ARRAY_SIZE(rf_init2_seq2
));
886 static int x_tune1(struct cxd2880_tnrdmd
*tnr_dmd
,
887 enum cxd2880_dtv_sys sys
, u32 freq_khz
,
888 enum cxd2880_dtv_bandwidth bandwidth
,
889 u8 is_cable
, int shift_frequency_khz
)
897 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
900 ARRAY_SIZE(x_tune1_seq1
));
904 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
912 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
923 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
929 usleep_range(1000, 2000);
938 case CXD2880_DTV_SYS_DVBT
:
942 case CXD2880_DTV_SYS_DVBT2
:
949 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
955 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
958 ARRAY_SIZE(x_tune1_seq2
));
964 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
970 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
976 data
[0] = is_cable
? 0x01 : 0x00;
982 case CXD2880_DTV_BW_1_7_MHZ
:
985 case CXD2880_DTV_BW_5_MHZ
:
986 case CXD2880_DTV_BW_6_MHZ
:
989 case CXD2880_DTV_BW_7_MHZ
:
992 case CXD2880_DTV_BW_8_MHZ
:
1001 freq_khz
+= shift_frequency_khz
;
1003 data
[6] = (freq_khz
>> 16) & 0x0f;
1004 data
[7] = (freq_khz
>> 8) & 0xff;
1005 data
[8] = freq_khz
& 0xff;
1009 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1014 static int x_tune2(struct cxd2880_tnrdmd
*tnr_dmd
,
1015 enum cxd2880_dtv_bandwidth bandwidth
,
1016 enum cxd2880_tnrdmd_clockmode clk_mode
,
1017 int shift_frequency_khz
)
1025 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1034 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1040 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1043 ARRAY_SIZE(x_tune2_seq1
));
1047 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1053 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1059 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1065 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1068 ARRAY_SIZE(x_tune2_seq2
));
1072 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1075 ARRAY_SIZE(x_tune2_seq3
));
1079 if (shift_frequency_khz
!= 0) {
1082 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1088 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1094 shift_freq
= shift_frequency_khz
* 1000;
1097 case CXD2880_TNRDMD_CLOCKMODE_A
:
1098 case CXD2880_TNRDMD_CLOCKMODE_C
:
1100 if (shift_freq
>= 0)
1101 shift_freq
= (shift_freq
+ 183 / 2) / 183;
1103 shift_freq
= (shift_freq
- 183 / 2) / 183;
1105 case CXD2880_TNRDMD_CLOCKMODE_B
:
1106 if (shift_freq
>= 0)
1107 shift_freq
= (shift_freq
+ 178 / 2) / 178;
1109 shift_freq
= (shift_freq
- 178 / 2) / 178;
1114 cxd2880_convert2s_complement((data
[0] << 8) | data
[1], 16);
1116 if (shift_freq
> 32767)
1118 else if (shift_freq
< -32768)
1119 shift_freq
= -32768;
1121 data
[0] = (shift_freq
>> 8) & 0xff;
1122 data
[1] = shift_freq
& 0xff;
1124 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1130 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1136 shift_freq
= -shift_frequency_khz
;
1138 if (bandwidth
== CXD2880_DTV_BW_1_7_MHZ
) {
1140 case CXD2880_TNRDMD_CLOCKMODE_A
:
1141 case CXD2880_TNRDMD_CLOCKMODE_C
:
1143 if (shift_freq
>= 0)
1145 (shift_freq
* 1000 +
1149 (shift_freq
* 1000 -
1152 case CXD2880_TNRDMD_CLOCKMODE_B
:
1153 if (shift_freq
>= 0)
1155 (shift_freq
* 1000 +
1159 (shift_freq
* 1000 -
1165 case CXD2880_TNRDMD_CLOCKMODE_A
:
1166 case CXD2880_TNRDMD_CLOCKMODE_C
:
1168 if (shift_freq
>= 0)
1170 (shift_freq
* 1000 +
1174 (shift_freq
* 1000 -
1177 case CXD2880_TNRDMD_CLOCKMODE_B
:
1178 if (shift_freq
>= 0)
1180 (shift_freq
* 1000 +
1184 (shift_freq
* 1000 -
1190 shift_freq
+= cxd2880_convert2s_complement(data
[0], 8);
1192 if (shift_freq
> 127)
1194 else if (shift_freq
< -128)
1197 data
[0] = shift_freq
& 0xff;
1199 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1206 if (tnr_dmd
->create_param
.stationary_use
) {
1207 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1210 ARRAY_SIZE(x_tune2_seq4
));
1215 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1218 ARRAY_SIZE(x_tune2_seq5
));
1221 static int x_tune3(struct cxd2880_tnrdmd
*tnr_dmd
,
1222 enum cxd2880_dtv_sys sys
,
1223 u8 en_fef_intmtnt_ctrl
)
1231 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1234 ARRAY_SIZE(x_tune3_seq
));
1238 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1244 if (sys
== CXD2880_DTV_SYS_DVBT2
&& en_fef_intmtnt_ctrl
)
1245 memset(data
, 0x01, sizeof(data
));
1247 memset(data
, 0x00, sizeof(data
));
1249 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1255 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1260 if (sys
== CXD2880_DTV_SYS_DVBT2
&& en_fef_intmtnt_ctrl
)
1265 return tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1270 static int x_tune4(struct cxd2880_tnrdmd
*tnr_dmd
)
1278 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
1281 ret
= tnr_dmd
->diver_sub
->io
->write_reg(tnr_dmd
->diver_sub
->io
,
1288 ret
= tnr_dmd
->diver_sub
->io
->write_regs(tnr_dmd
->diver_sub
->io
,
1294 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1301 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1306 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1313 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1319 ret
= tnr_dmd
->diver_sub
->io
->write_reg(tnr_dmd
->diver_sub
->io
,
1326 ret
= tnr_dmd
->diver_sub
->io
->write_regs(tnr_dmd
->diver_sub
->io
,
1331 ret
= tnr_dmd
->diver_sub
->io
->write_reg(tnr_dmd
->diver_sub
->io
,
1337 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1340 ARRAY_SIZE(x_tune4_seq
));
1344 return cxd2880_io_write_multi_regs(tnr_dmd
->diver_sub
->io
,
1347 ARRAY_SIZE(x_tune4_seq
));
1350 static int x_sleep1(struct cxd2880_tnrdmd
*tnr_dmd
)
1358 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
1361 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1364 ARRAY_SIZE(x_sleep1_seq
));
1370 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1376 ret
= tnr_dmd
->diver_sub
->io
->write_reg(tnr_dmd
->diver_sub
->io
,
1384 ret
= tnr_dmd
->diver_sub
->io
->write_regs(tnr_dmd
->diver_sub
->io
,
1391 ret
= tnr_dmd
->diver_sub
->io
->write_regs(tnr_dmd
->diver_sub
->io
,
1397 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1405 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1410 static int x_sleep2(struct cxd2880_tnrdmd
*tnr_dmd
)
1418 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1421 ARRAY_SIZE(x_sleep2_seq1
));
1425 usleep_range(1000, 2000);
1427 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1433 if ((data
& 0x01) == 0x00)
1436 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1439 ARRAY_SIZE(x_sleep2_seq2
));
1442 static int x_sleep3(struct cxd2880_tnrdmd
*tnr_dmd
)
1447 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1450 ARRAY_SIZE(x_sleep3_seq
));
1453 static int x_sleep4(struct cxd2880_tnrdmd
*tnr_dmd
)
1458 return cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1461 ARRAY_SIZE(x_sleep4_seq
));
1464 static int spll_reset(struct cxd2880_tnrdmd
*tnr_dmd
,
1465 enum cxd2880_tnrdmd_clockmode clockmode
)
1473 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1476 ARRAY_SIZE(spll_reset_seq1
));
1480 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1483 ARRAY_SIZE(spll_reset_seq2
));
1487 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1490 ARRAY_SIZE(spll_reset_seq3
));
1494 switch (clockmode
) {
1495 case CXD2880_TNRDMD_CLOCKMODE_A
:
1499 case CXD2880_TNRDMD_CLOCKMODE_B
:
1503 case CXD2880_TNRDMD_CLOCKMODE_C
:
1510 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1515 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1521 usleep_range(2000, 3000);
1523 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1528 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1533 if ((data
[0] & 0x01) == 0x00)
1536 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1539 ARRAY_SIZE(spll_reset_seq4
));
1543 usleep_range(1000, 2000);
1545 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1548 ARRAY_SIZE(spll_reset_seq5
));
1552 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1558 memset(data
, 0x00, sizeof(data
));
1560 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1565 static int t_power_x(struct cxd2880_tnrdmd
*tnr_dmd
, u8 on
)
1573 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1576 ARRAY_SIZE(t_power_x_seq1
));
1580 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1583 ARRAY_SIZE(t_power_x_seq2
));
1587 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1590 ARRAY_SIZE(t_power_x_seq3
));
1595 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1601 usleep_range(1000, 2000);
1603 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1608 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1613 if ((data
[0] & 0x01) == 0)
1616 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1619 ARRAY_SIZE(t_power_x_seq4
));
1625 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1631 usleep_range(1000, 2000);
1633 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1638 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1643 if ((data
[0] & 0x01) == 0)
1647 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1650 ARRAY_SIZE(t_power_x_seq5
));
1654 usleep_range(1000, 2000);
1656 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1661 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
1666 if ((data
[0] & 0x01) == 0)
1669 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1672 ARRAY_SIZE(t_power_x_seq6
));
1676 usleep_range(1000, 2000);
1678 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
1681 ARRAY_SIZE(t_power_x_seq7
));
1685 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1691 memset(data
, 0x00, sizeof(data
));
1693 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1698 struct cxd2880_tnrdmd_ts_clk_cfg
{
1704 static int set_ts_clk_mode_and_freq(struct cxd2880_tnrdmd
*tnr_dmd
,
1705 enum cxd2880_dtv_sys sys
)
1708 u8 backwards_compatible
= 0;
1709 struct cxd2880_tnrdmd_ts_clk_cfg ts_clk_cfg
;
1710 u8 ts_rate_ctrl_off
= 0;
1712 u8 ts_clk_manaul_on
= 0;
1715 static const struct cxd2880_tnrdmd_ts_clk_cfg srl_ts_clk_stgs
[2][2] = {
1728 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1734 if (tnr_dmd
->is_ts_backwards_compatible_mode
) {
1735 backwards_compatible
= 1;
1736 ts_rate_ctrl_off
= 1;
1739 backwards_compatible
= 0;
1740 ts_rate_ctrl_off
= 0;
1744 if (tnr_dmd
->ts_byte_clk_manual_setting
) {
1745 ts_clk_manaul_on
= 1;
1746 ts_rate_ctrl_off
= 0;
1749 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1751 0xd3, ts_rate_ctrl_off
, 0x01);
1755 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1757 0xde, ts_in_off
, 0x01);
1761 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1763 0xda, ts_clk_manaul_on
, 0x01);
1767 ts_clk_cfg
= srl_ts_clk_stgs
[tnr_dmd
->srl_ts_clk_mod_cnts
]
1768 [tnr_dmd
->srl_ts_clk_frq
];
1770 if (tnr_dmd
->ts_byte_clk_manual_setting
)
1771 ts_clk_cfg
.ts_clk_period
= tnr_dmd
->ts_byte_clk_manual_setting
;
1773 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1775 0xc4, ts_clk_cfg
.srl_clk_mode
, 0x03);
1779 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1781 0xd1, ts_clk_cfg
.srl_duty_mode
, 0x03);
1785 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1786 CXD2880_IO_TGT_DMD
, 0xd9,
1787 ts_clk_cfg
.ts_clk_period
);
1791 data
= backwards_compatible
? 0x00 : 0x01;
1793 if (sys
== CXD2880_DTV_SYS_DVBT
) {
1794 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1801 cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1809 static int pid_ftr_setting(struct cxd2880_tnrdmd
*tnr_dmd
,
1810 struct cxd2880_tnrdmd_pid_ftr_cfg
1820 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1827 return tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1831 data
[0] = pid_ftr_cfg
->is_negative
? 0x01 : 0x00;
1833 for (i
= 0; i
< 32; i
++) {
1834 if (pid_ftr_cfg
->pid_cfg
[i
].is_en
) {
1835 data
[1 + (i
* 2)] = (pid_ftr_cfg
->pid_cfg
[i
].pid
>> 8) | 0x20;
1836 data
[2 + (i
* 2)] = pid_ftr_cfg
->pid_cfg
[i
].pid
& 0xff;
1838 data
[1 + (i
* 2)] = 0x00;
1839 data
[2 + (i
* 2)] = 0x00;
1843 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
1848 static int load_cfg_mem(struct cxd2880_tnrdmd
*tnr_dmd
)
1856 for (i
= 0; i
< tnr_dmd
->cfg_mem_last_entry
; i
++) {
1857 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
1858 tnr_dmd
->cfg_mem
[i
].tgt
,
1859 0x00, tnr_dmd
->cfg_mem
[i
].bank
);
1863 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
1864 tnr_dmd
->cfg_mem
[i
].tgt
,
1865 tnr_dmd
->cfg_mem
[i
].address
,
1866 tnr_dmd
->cfg_mem
[i
].value
,
1867 tnr_dmd
->cfg_mem
[i
].bit_mask
);
1875 static int set_cfg_mem(struct cxd2880_tnrdmd
*tnr_dmd
,
1876 enum cxd2880_io_tgt tgt
,
1877 u8 bank
, u8 address
, u8 value
, u8 bit_mask
)
1880 u8 value_stored
= 0;
1885 for (i
= 0; i
< tnr_dmd
->cfg_mem_last_entry
; i
++) {
1886 if (value_stored
== 0 &&
1887 tnr_dmd
->cfg_mem
[i
].tgt
== tgt
&&
1888 tnr_dmd
->cfg_mem
[i
].bank
== bank
&&
1889 tnr_dmd
->cfg_mem
[i
].address
== address
) {
1890 tnr_dmd
->cfg_mem
[i
].value
&= ~bit_mask
;
1891 tnr_dmd
->cfg_mem
[i
].value
|= (value
& bit_mask
);
1893 tnr_dmd
->cfg_mem
[i
].bit_mask
|= bit_mask
;
1902 if (tnr_dmd
->cfg_mem_last_entry
< CXD2880_TNRDMD_MAX_CFG_MEM_COUNT
) {
1903 tnr_dmd
->cfg_mem
[tnr_dmd
->cfg_mem_last_entry
].tgt
= tgt
;
1904 tnr_dmd
->cfg_mem
[tnr_dmd
->cfg_mem_last_entry
].bank
= bank
;
1905 tnr_dmd
->cfg_mem
[tnr_dmd
->cfg_mem_last_entry
].address
= address
;
1906 tnr_dmd
->cfg_mem
[tnr_dmd
->cfg_mem_last_entry
].value
= (value
& bit_mask
);
1907 tnr_dmd
->cfg_mem
[tnr_dmd
->cfg_mem_last_entry
].bit_mask
= bit_mask
;
1908 tnr_dmd
->cfg_mem_last_entry
++;
1916 int cxd2880_tnrdmd_create(struct cxd2880_tnrdmd
*tnr_dmd
,
1917 struct cxd2880_io
*io
,
1918 struct cxd2880_tnrdmd_create_param
1921 if (!tnr_dmd
|| !io
|| !create_param
)
1924 memset(tnr_dmd
, 0, sizeof(struct cxd2880_tnrdmd
));
1927 tnr_dmd
->create_param
= *create_param
;
1929 tnr_dmd
->diver_mode
= CXD2880_TNRDMD_DIVERMODE_SINGLE
;
1930 tnr_dmd
->diver_sub
= NULL
;
1932 tnr_dmd
->srl_ts_clk_mod_cnts
= 1;
1933 tnr_dmd
->en_fef_intmtnt_base
= 1;
1934 tnr_dmd
->en_fef_intmtnt_lite
= 1;
1935 tnr_dmd
->rf_lvl_cmpstn
= NULL
;
1936 tnr_dmd
->lna_thrs_tbl_air
= NULL
;
1937 tnr_dmd
->lna_thrs_tbl_cable
= NULL
;
1938 atomic_set(&tnr_dmd
->cancel
, 0);
1943 int cxd2880_tnrdmd_diver_create(struct cxd2880_tnrdmd
1945 struct cxd2880_io
*io_main
,
1946 struct cxd2880_tnrdmd
*tnr_dmd_sub
,
1947 struct cxd2880_io
*io_sub
,
1949 cxd2880_tnrdmd_diver_create_param
1952 struct cxd2880_tnrdmd_create_param
*main_param
, *sub_param
;
1954 if (!tnr_dmd_main
|| !io_main
|| !tnr_dmd_sub
|| !io_sub
||
1958 memset(tnr_dmd_main
, 0, sizeof(struct cxd2880_tnrdmd
));
1959 memset(tnr_dmd_sub
, 0, sizeof(struct cxd2880_tnrdmd
));
1961 main_param
= &tnr_dmd_main
->create_param
;
1962 sub_param
= &tnr_dmd_sub
->create_param
;
1964 tnr_dmd_main
->io
= io_main
;
1965 tnr_dmd_main
->diver_mode
= CXD2880_TNRDMD_DIVERMODE_MAIN
;
1966 tnr_dmd_main
->diver_sub
= tnr_dmd_sub
;
1967 tnr_dmd_main
->create_param
.en_internal_ldo
=
1968 create_param
->en_internal_ldo
;
1970 main_param
->ts_output_if
= create_param
->ts_output_if
;
1971 main_param
->xtal_share_type
= CXD2880_TNRDMD_XTAL_SHARE_MASTER
;
1972 main_param
->xosc_cap
= create_param
->xosc_cap_main
;
1973 main_param
->xosc_i
= create_param
->xosc_i_main
;
1974 main_param
->is_cxd2881gg
= create_param
->is_cxd2881gg
;
1975 main_param
->stationary_use
= create_param
->stationary_use
;
1977 tnr_dmd_sub
->io
= io_sub
;
1978 tnr_dmd_sub
->diver_mode
= CXD2880_TNRDMD_DIVERMODE_SUB
;
1979 tnr_dmd_sub
->diver_sub
= NULL
;
1981 sub_param
->en_internal_ldo
= create_param
->en_internal_ldo
;
1982 sub_param
->ts_output_if
= create_param
->ts_output_if
;
1983 sub_param
->xtal_share_type
= CXD2880_TNRDMD_XTAL_SHARE_SLAVE
;
1984 sub_param
->xosc_cap
= 0;
1985 sub_param
->xosc_i
= create_param
->xosc_i_sub
;
1986 sub_param
->is_cxd2881gg
= create_param
->is_cxd2881gg
;
1987 sub_param
->stationary_use
= create_param
->stationary_use
;
1989 tnr_dmd_main
->srl_ts_clk_mod_cnts
= 1;
1990 tnr_dmd_main
->en_fef_intmtnt_base
= 1;
1991 tnr_dmd_main
->en_fef_intmtnt_lite
= 1;
1992 tnr_dmd_main
->rf_lvl_cmpstn
= NULL
;
1993 tnr_dmd_main
->lna_thrs_tbl_air
= NULL
;
1994 tnr_dmd_main
->lna_thrs_tbl_cable
= NULL
;
1996 tnr_dmd_sub
->srl_ts_clk_mod_cnts
= 1;
1997 tnr_dmd_sub
->en_fef_intmtnt_base
= 1;
1998 tnr_dmd_sub
->en_fef_intmtnt_lite
= 1;
1999 tnr_dmd_sub
->rf_lvl_cmpstn
= NULL
;
2000 tnr_dmd_sub
->lna_thrs_tbl_air
= NULL
;
2001 tnr_dmd_sub
->lna_thrs_tbl_cable
= NULL
;
2006 int cxd2880_tnrdmd_init1(struct cxd2880_tnrdmd
*tnr_dmd
)
2010 if (!tnr_dmd
|| tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2013 tnr_dmd
->chip_id
= CXD2880_TNRDMD_CHIP_ID_UNKNOWN
;
2014 tnr_dmd
->state
= CXD2880_TNRDMD_STATE_UNKNOWN
;
2015 tnr_dmd
->clk_mode
= CXD2880_TNRDMD_CLOCKMODE_UNKNOWN
;
2016 tnr_dmd
->frequency_khz
= 0;
2017 tnr_dmd
->sys
= CXD2880_DTV_SYS_UNKNOWN
;
2018 tnr_dmd
->bandwidth
= CXD2880_DTV_BW_UNKNOWN
;
2019 tnr_dmd
->scan_mode
= 0;
2020 atomic_set(&tnr_dmd
->cancel
, 0);
2022 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2023 tnr_dmd
->diver_sub
->chip_id
= CXD2880_TNRDMD_CHIP_ID_UNKNOWN
;
2024 tnr_dmd
->diver_sub
->state
= CXD2880_TNRDMD_STATE_UNKNOWN
;
2025 tnr_dmd
->diver_sub
->clk_mode
= CXD2880_TNRDMD_CLOCKMODE_UNKNOWN
;
2026 tnr_dmd
->diver_sub
->frequency_khz
= 0;
2027 tnr_dmd
->diver_sub
->sys
= CXD2880_DTV_SYS_UNKNOWN
;
2028 tnr_dmd
->diver_sub
->bandwidth
= CXD2880_DTV_BW_UNKNOWN
;
2029 tnr_dmd
->diver_sub
->scan_mode
= 0;
2030 atomic_set(&tnr_dmd
->diver_sub
->cancel
, 0);
2033 ret
= cxd2880_tnrdmd_chip_id(tnr_dmd
, &tnr_dmd
->chip_id
);
2037 if (!CXD2880_TNRDMD_CHIP_ID_VALID(tnr_dmd
->chip_id
))
2040 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2042 cxd2880_tnrdmd_chip_id(tnr_dmd
->diver_sub
,
2043 &tnr_dmd
->diver_sub
->chip_id
);
2047 if (!CXD2880_TNRDMD_CHIP_ID_VALID(tnr_dmd
->diver_sub
->chip_id
))
2051 ret
= p_init1(tnr_dmd
);
2055 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2056 ret
= p_init1(tnr_dmd
->diver_sub
);
2061 usleep_range(1000, 2000);
2063 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2064 ret
= p_init2(tnr_dmd
->diver_sub
);
2069 ret
= p_init2(tnr_dmd
);
2073 usleep_range(5000, 6000);
2075 ret
= p_init3(tnr_dmd
);
2079 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2080 ret
= p_init3(tnr_dmd
->diver_sub
);
2085 ret
= rf_init1(tnr_dmd
);
2089 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
)
2090 ret
= rf_init1(tnr_dmd
->diver_sub
);
2095 int cxd2880_tnrdmd_init2(struct cxd2880_tnrdmd
*tnr_dmd
)
2097 u8 cpu_task_completed
;
2103 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2106 ret
= cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd
,
2107 &cpu_task_completed
);
2111 if (!cpu_task_completed
)
2114 ret
= rf_init2(tnr_dmd
);
2118 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2119 ret
= rf_init2(tnr_dmd
->diver_sub
);
2124 ret
= load_cfg_mem(tnr_dmd
);
2128 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2129 ret
= load_cfg_mem(tnr_dmd
->diver_sub
);
2134 tnr_dmd
->state
= CXD2880_TNRDMD_STATE_SLEEP
;
2136 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
)
2137 tnr_dmd
->diver_sub
->state
= CXD2880_TNRDMD_STATE_SLEEP
;
2142 int cxd2880_tnrdmd_check_internal_cpu_status(struct cxd2880_tnrdmd
2149 if (!tnr_dmd
|| !task_completed
)
2152 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2155 ret
= cxd2880_tnrdmd_mon_internal_cpu_status(tnr_dmd
, &cpu_status
);
2159 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SINGLE
) {
2160 if (cpu_status
== 0)
2161 *task_completed
= 1;
2163 *task_completed
= 0;
2167 if (cpu_status
!= 0) {
2168 *task_completed
= 0;
2172 ret
= cxd2880_tnrdmd_mon_internal_cpu_status_sub(tnr_dmd
, &cpu_status
);
2176 if (cpu_status
== 0)
2177 *task_completed
= 1;
2179 *task_completed
= 0;
2184 int cxd2880_tnrdmd_common_tune_setting1(struct cxd2880_tnrdmd
*tnr_dmd
,
2185 enum cxd2880_dtv_sys sys
,
2187 enum cxd2880_dtv_bandwidth
2188 bandwidth
, u8 one_seg_opt
,
2189 u8 one_seg_opt_shft_dir
)
2192 enum cxd2880_tnrdmd_clockmode new_clk_mode
=
2193 CXD2880_TNRDMD_CLOCKMODE_A
;
2194 int shift_frequency_khz
;
2195 u8 cpu_task_completed
;
2201 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2204 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
2205 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
2208 if (frequency_khz
< 4000)
2211 ret
= cxd2880_tnrdmd_sleep(tnr_dmd
);
2215 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
2222 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
2231 case CXD2880_DTV_SYS_DVBT
:
2233 ret
= t_power_x(tnr_dmd
, 1);
2237 if (tnr_dmd
->diver_mode
==
2238 CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2239 ret
= t_power_x(tnr_dmd
->diver_sub
, 1);
2246 case CXD2880_DTV_SYS_DVBT2
:
2248 ret
= t_power_x(tnr_dmd
, 0);
2252 if (tnr_dmd
->diver_mode
==
2253 CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2254 ret
= t_power_x(tnr_dmd
->diver_sub
, 0);
2265 ret
= spll_reset(tnr_dmd
, new_clk_mode
);
2269 tnr_dmd
->clk_mode
= new_clk_mode
;
2271 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2272 ret
= spll_reset(tnr_dmd
->diver_sub
, new_clk_mode
);
2276 tnr_dmd
->diver_sub
->clk_mode
= new_clk_mode
;
2279 ret
= load_cfg_mem(tnr_dmd
);
2283 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2284 ret
= load_cfg_mem(tnr_dmd
->diver_sub
);
2290 if (tnr_dmd
->diver_mode
==
2291 CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2292 shift_frequency_khz
= 350;
2294 if (one_seg_opt_shft_dir
)
2295 shift_frequency_khz
= 350;
2297 shift_frequency_khz
= -350;
2299 if (tnr_dmd
->create_param
.xtal_share_type
==
2300 CXD2880_TNRDMD_XTAL_SHARE_SLAVE
)
2301 shift_frequency_khz
*= -1;
2304 if (tnr_dmd
->diver_mode
==
2305 CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2306 shift_frequency_khz
= 150;
2308 switch (tnr_dmd
->create_param
.xtal_share_type
) {
2309 case CXD2880_TNRDMD_XTAL_SHARE_NONE
:
2310 case CXD2880_TNRDMD_XTAL_SHARE_EXTREF
:
2312 shift_frequency_khz
= 0;
2314 case CXD2880_TNRDMD_XTAL_SHARE_MASTER
:
2315 shift_frequency_khz
= 150;
2317 case CXD2880_TNRDMD_XTAL_SHARE_SLAVE
:
2318 shift_frequency_khz
= -150;
2325 x_tune1(tnr_dmd
, sys
, frequency_khz
, bandwidth
,
2326 tnr_dmd
->is_cable_input
, shift_frequency_khz
);
2330 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2332 x_tune1(tnr_dmd
->diver_sub
, sys
, frequency_khz
,
2333 bandwidth
, tnr_dmd
->is_cable_input
,
2334 -shift_frequency_khz
);
2339 usleep_range(10000, 11000);
2342 cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd
,
2343 &cpu_task_completed
);
2347 if (!cpu_task_completed
)
2351 x_tune2(tnr_dmd
, bandwidth
, tnr_dmd
->clk_mode
,
2352 shift_frequency_khz
);
2356 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2358 x_tune2(tnr_dmd
->diver_sub
, bandwidth
,
2359 tnr_dmd
->diver_sub
->clk_mode
,
2360 -shift_frequency_khz
);
2365 if (tnr_dmd
->create_param
.ts_output_if
== CXD2880_TNRDMD_TSOUT_IF_TS
) {
2366 ret
= set_ts_clk_mode_and_freq(tnr_dmd
, sys
);
2368 struct cxd2880_tnrdmd_pid_ftr_cfg
*pid_ftr_cfg
;
2370 if (tnr_dmd
->pid_ftr_cfg_en
)
2371 pid_ftr_cfg
= &tnr_dmd
->pid_ftr_cfg
;
2375 ret
= pid_ftr_setting(tnr_dmd
, pid_ftr_cfg
);
2381 int cxd2880_tnrdmd_common_tune_setting2(struct cxd2880_tnrdmd
2383 enum cxd2880_dtv_sys sys
,
2384 u8 en_fef_intmtnt_ctrl
)
2391 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2394 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
2395 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
2398 ret
= x_tune3(tnr_dmd
, sys
, en_fef_intmtnt_ctrl
);
2402 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2403 ret
= x_tune3(tnr_dmd
->diver_sub
, sys
, en_fef_intmtnt_ctrl
);
2406 ret
= x_tune4(tnr_dmd
);
2411 return cxd2880_tnrdmd_set_ts_output(tnr_dmd
, 1);
2414 int cxd2880_tnrdmd_sleep(struct cxd2880_tnrdmd
*tnr_dmd
)
2421 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
2424 if (tnr_dmd
->state
== CXD2880_TNRDMD_STATE_SLEEP
)
2427 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
2430 ret
= cxd2880_tnrdmd_set_ts_output(tnr_dmd
, 0);
2434 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2435 ret
= x_sleep1(tnr_dmd
);
2440 ret
= x_sleep2(tnr_dmd
);
2444 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2445 ret
= x_sleep2(tnr_dmd
->diver_sub
);
2450 switch (tnr_dmd
->sys
) {
2451 case CXD2880_DTV_SYS_DVBT
:
2452 ret
= cxd2880_tnrdmd_dvbt_sleep_setting(tnr_dmd
);
2457 case CXD2880_DTV_SYS_DVBT2
:
2458 ret
= cxd2880_tnrdmd_dvbt2_sleep_setting(tnr_dmd
);
2467 ret
= x_sleep3(tnr_dmd
);
2471 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2472 ret
= x_sleep3(tnr_dmd
->diver_sub
);
2477 ret
= x_sleep4(tnr_dmd
);
2481 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2482 ret
= x_sleep4(tnr_dmd
->diver_sub
);
2487 tnr_dmd
->state
= CXD2880_TNRDMD_STATE_SLEEP
;
2488 tnr_dmd
->frequency_khz
= 0;
2489 tnr_dmd
->sys
= CXD2880_DTV_SYS_UNKNOWN
;
2490 tnr_dmd
->bandwidth
= CXD2880_DTV_BW_UNKNOWN
;
2492 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
) {
2493 tnr_dmd
->diver_sub
->state
= CXD2880_TNRDMD_STATE_SLEEP
;
2494 tnr_dmd
->diver_sub
->frequency_khz
= 0;
2495 tnr_dmd
->diver_sub
->sys
= CXD2880_DTV_SYS_UNKNOWN
;
2496 tnr_dmd
->diver_sub
->bandwidth
= CXD2880_DTV_BW_UNKNOWN
;
2502 int cxd2880_tnrdmd_set_cfg(struct cxd2880_tnrdmd
*tnr_dmd
,
2503 enum cxd2880_tnrdmd_cfg_id id
,
2508 u8 need_sub_setting
= 0;
2513 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
2514 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
2518 case CXD2880_TNRDMD_CFG_OUTPUT_SEL_MSB
:
2519 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2523 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2526 value
? 0x00 : 0x10,
2532 case CXD2880_TNRDMD_CFG_TSVALID_ACTIVE_HI
:
2533 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2537 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2540 value
? 0x00 : 0x02,
2546 case CXD2880_TNRDMD_CFG_TSSYNC_ACTIVE_HI
:
2547 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2551 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2554 value
? 0x00 : 0x04,
2560 case CXD2880_TNRDMD_CFG_TSERR_ACTIVE_HI
:
2561 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2565 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2568 value
? 0x00 : 0x01,
2574 case CXD2880_TNRDMD_CFG_LATCH_ON_POSEDGE
:
2575 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2579 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2582 value
? 0x01 : 0x00,
2588 case CXD2880_TNRDMD_CFG_TSCLK_CONT
:
2589 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2592 tnr_dmd
->srl_ts_clk_mod_cnts
= value
? 0x01 : 0x00;
2595 case CXD2880_TNRDMD_CFG_TSCLK_MASK
:
2596 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2599 if (value
< 0 || value
> 0x1f)
2603 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2611 case CXD2880_TNRDMD_CFG_TSVALID_MASK
:
2612 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2615 if (value
< 0 || value
> 0x1f)
2619 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2627 case CXD2880_TNRDMD_CFG_TSERR_MASK
:
2628 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2631 if (value
< 0 || value
> 0x1f)
2635 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2643 case CXD2880_TNRDMD_CFG_TSERR_VALID_DIS
:
2644 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2648 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2651 value
? 0x01 : 0x00,
2657 case CXD2880_TNRDMD_CFG_TSPIN_CURRENT
:
2658 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2662 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2670 case CXD2880_TNRDMD_CFG_TSPIN_PULLUP_MANUAL
:
2671 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2675 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2678 value
? 0x80 : 0x00,
2684 case CXD2880_TNRDMD_CFG_TSPIN_PULLUP
:
2685 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2689 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2697 case CXD2880_TNRDMD_CFG_TSCLK_FREQ
:
2698 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2701 if (value
< 0 || value
> 1)
2704 tnr_dmd
->srl_ts_clk_frq
=
2705 (enum cxd2880_tnrdmd_serial_ts_clk
)value
;
2708 case CXD2880_TNRDMD_CFG_TSBYTECLK_MANUAL
:
2709 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2712 if (value
< 0 || value
> 0xff)
2715 tnr_dmd
->ts_byte_clk_manual_setting
= value
;
2719 case CXD2880_TNRDMD_CFG_TS_PACKET_GAP
:
2720 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2723 if (value
< 0 || value
> 7)
2727 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2736 case CXD2880_TNRDMD_CFG_TS_BACKWARDS_COMPATIBLE
:
2737 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
2740 tnr_dmd
->is_ts_backwards_compatible_mode
= value
? 1 : 0;
2744 case CXD2880_TNRDMD_CFG_PWM_VALUE
:
2745 if (value
< 0 || value
> 0x1000)
2749 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2752 value
? 0x01 : 0x00,
2757 data
[0] = (value
>> 8) & 0x1f;
2758 data
[1] = value
& 0xff;
2761 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2769 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2778 case CXD2880_TNRDMD_CFG_INTERRUPT
:
2779 data
[0] = (value
>> 8) & 0xff;
2780 data
[1] = value
& 0xff;
2782 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2784 0x00, 0x48, data
[0],
2789 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2791 0x00, 0x49, data
[1],
2797 case CXD2880_TNRDMD_CFG_INTERRUPT_LOCK_SEL
:
2798 data
[0] = value
& 0x07;
2800 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2802 0x00, 0x4a, data
[0],
2808 case CXD2880_TNRDMD_CFG_INTERRUPT_INV_LOCK_SEL
:
2809 data
[0] = (value
& 0x07) << 3;
2811 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2813 0x00, 0x4a, data
[0],
2819 case CXD2880_TNRDMD_CFG_FIXED_CLOCKMODE
:
2820 if (value
< CXD2880_TNRDMD_CLOCKMODE_UNKNOWN
||
2821 value
> CXD2880_TNRDMD_CLOCKMODE_C
)
2823 tnr_dmd
->fixed_clk_mode
= (enum cxd2880_tnrdmd_clockmode
)value
;
2826 case CXD2880_TNRDMD_CFG_CABLE_INPUT
:
2827 tnr_dmd
->is_cable_input
= value
? 1 : 0;
2830 case CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_BASE
:
2831 tnr_dmd
->en_fef_intmtnt_base
= value
? 1 : 0;
2834 case CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_LITE
:
2835 tnr_dmd
->en_fef_intmtnt_lite
= value
? 1 : 0;
2838 case CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_EMPTY_THRS
:
2839 data
[0] = (value
>> 8) & 0x07;
2840 data
[1] = value
& 0xff;
2842 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2844 0x00, 0x99, data
[0],
2849 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2851 0x00, 0x9a, data
[1],
2857 case CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_FULL_THRS
:
2858 data
[0] = (value
>> 8) & 0x07;
2859 data
[1] = value
& 0xff;
2861 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2863 0x00, 0x9b, data
[0],
2868 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2870 0x00, 0x9c, data
[1],
2876 case CXD2880_TNRDMD_CFG_TS_BUF_RRDY_THRS
:
2877 data
[0] = (value
>> 8) & 0x07;
2878 data
[1] = value
& 0xff;
2880 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2882 0x00, 0x9d, data
[0],
2887 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2889 0x00, 0x9e, data
[1],
2895 case CXD2880_TNRDMD_CFG_BLINDTUNE_DVBT2_FIRST
:
2896 tnr_dmd
->blind_tune_dvbt2_first
= value
? 1 : 0;
2899 case CXD2880_TNRDMD_CFG_DVBT_BERN_PERIOD
:
2900 if (value
< 0 || value
> 31)
2904 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2907 value
& 0x1f, 0x1f);
2912 case CXD2880_TNRDMD_CFG_DVBT_VBER_PERIOD
:
2913 if (value
< 0 || value
> 7)
2917 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2920 value
& 0x07, 0x07);
2925 case CXD2880_TNRDMD_CFG_DVBT2_BBER_MES
:
2926 if (value
< 0 || value
> 15)
2930 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2933 value
& 0x0f, 0x0f);
2938 case CXD2880_TNRDMD_CFG_DVBT2_LBER_MES
:
2939 if (value
< 0 || value
> 15)
2943 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2946 value
& 0x0f, 0x0f);
2951 case CXD2880_TNRDMD_CFG_DVBT_PER_MES
:
2952 if (value
< 0 || value
> 15)
2956 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2959 value
& 0x0f, 0x0f);
2964 case CXD2880_TNRDMD_CFG_DVBT2_PER_MES
:
2965 if (value
< 0 || value
> 15)
2969 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
2972 value
& 0x0f, 0x0f);
2981 if (need_sub_setting
&&
2982 tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
)
2983 ret
= cxd2880_tnrdmd_set_cfg(tnr_dmd
->diver_sub
, id
, value
);
2988 int cxd2880_tnrdmd_gpio_set_cfg(struct cxd2880_tnrdmd
*tnr_dmd
,
2991 enum cxd2880_tnrdmd_gpio_mode mode
,
2992 u8 open_drain
, u8 invert
)
3002 if (mode
> CXD2880_TNRDMD_GPIO_MODE_EEW
)
3005 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3006 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3010 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
, CXD2880_IO_TGT_SYS
,
3011 0x00, 0x40 + id
, mode
,
3017 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
, CXD2880_IO_TGT_SYS
,
3019 open_drain
? (1 << id
) : 0,
3025 cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
, CXD2880_IO_TGT_SYS
,
3027 invert
? (1 << id
) : 0,
3032 return cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
3039 int cxd2880_tnrdmd_gpio_set_cfg_sub(struct cxd2880_tnrdmd
*tnr_dmd
,
3042 enum cxd2880_tnrdmd_gpio_mode
3043 mode
, u8 open_drain
, u8 invert
)
3048 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
3051 return cxd2880_tnrdmd_gpio_set_cfg(tnr_dmd
->diver_sub
, id
, en
, mode
,
3052 open_drain
, invert
);
3055 int cxd2880_tnrdmd_gpio_read(struct cxd2880_tnrdmd
*tnr_dmd
,
3061 if (!tnr_dmd
|| !value
)
3067 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3068 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3071 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3076 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
3082 *value
= (data
>> id
) & 0x01;
3087 int cxd2880_tnrdmd_gpio_read_sub(struct cxd2880_tnrdmd
*tnr_dmd
,
3093 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
3096 return cxd2880_tnrdmd_gpio_read(tnr_dmd
->diver_sub
, id
, value
);
3099 int cxd2880_tnrdmd_gpio_write(struct cxd2880_tnrdmd
*tnr_dmd
,
3108 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3109 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3112 return cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd
,
3115 value
? (1 << id
) : 0,
3119 int cxd2880_tnrdmd_gpio_write_sub(struct cxd2880_tnrdmd
*tnr_dmd
,
3125 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
3128 return cxd2880_tnrdmd_gpio_write(tnr_dmd
->diver_sub
, id
, value
);
3131 int cxd2880_tnrdmd_interrupt_read(struct cxd2880_tnrdmd
*tnr_dmd
,
3137 if (!tnr_dmd
|| !value
)
3140 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3141 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3144 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3149 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
3155 *value
= (data
[0] << 8) | data
[1];
3160 int cxd2880_tnrdmd_interrupt_clear(struct cxd2880_tnrdmd
*tnr_dmd
,
3169 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3170 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3173 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3179 data
[0] = (value
>> 8) & 0xff;
3180 data
[1] = value
& 0xff;
3182 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
3187 int cxd2880_tnrdmd_ts_buf_clear(struct cxd2880_tnrdmd
*tnr_dmd
,
3188 u8 clear_overflow_flag
,
3189 u8 clear_underflow_flag
,
3198 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
3201 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3202 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3205 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3211 data
[0] = clear_overflow_flag
? 0x02 : 0x00;
3212 data
[0] |= clear_underflow_flag
? 0x01 : 0x00;
3213 data
[1] = clear_buf
? 0x01 : 0x00;
3215 return tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
3220 int cxd2880_tnrdmd_chip_id(struct cxd2880_tnrdmd
*tnr_dmd
,
3221 enum cxd2880_tnrdmd_chip_id
*chip_id
)
3226 if (!tnr_dmd
|| !chip_id
)
3229 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3234 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
3240 *chip_id
= (enum cxd2880_tnrdmd_chip_id
)data
;
3245 int cxd2880_tnrdmd_set_and_save_reg_bits(struct cxd2880_tnrdmd
3247 enum cxd2880_io_tgt tgt
,
3248 u8 bank
, u8 address
,
3249 u8 value
, u8 bit_mask
)
3256 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3257 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3260 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
, tgt
, 0x00, bank
);
3264 ret
= cxd2880_io_set_reg_bits(tnr_dmd
->io
,
3265 tgt
, address
, value
, bit_mask
);
3269 return set_cfg_mem(tnr_dmd
, tgt
, bank
, address
, value
, bit_mask
);
3272 int cxd2880_tnrdmd_set_scan_mode(struct cxd2880_tnrdmd
*tnr_dmd
,
3273 enum cxd2880_dtv_sys sys
,
3279 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3280 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3283 tnr_dmd
->scan_mode
= scan_mode_end
;
3285 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_MAIN
)
3286 return cxd2880_tnrdmd_set_scan_mode(tnr_dmd
->diver_sub
, sys
,
3292 int cxd2880_tnrdmd_set_pid_ftr(struct cxd2880_tnrdmd
*tnr_dmd
,
3293 struct cxd2880_tnrdmd_pid_ftr_cfg
3299 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
3302 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3303 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3306 if (tnr_dmd
->create_param
.ts_output_if
== CXD2880_TNRDMD_TSOUT_IF_TS
)
3310 tnr_dmd
->pid_ftr_cfg
= *pid_ftr_cfg
;
3311 tnr_dmd
->pid_ftr_cfg_en
= 1;
3313 tnr_dmd
->pid_ftr_cfg_en
= 0;
3316 if (tnr_dmd
->state
== CXD2880_TNRDMD_STATE_ACTIVE
)
3317 return pid_ftr_setting(tnr_dmd
, pid_ftr_cfg
);
3322 int cxd2880_tnrdmd_set_rf_lvl_cmpstn(struct cxd2880_tnrdmd
3324 int (*rf_lvl_cmpstn
)
3325 (struct cxd2880_tnrdmd
*,
3331 tnr_dmd
->rf_lvl_cmpstn
= rf_lvl_cmpstn
;
3336 int cxd2880_tnrdmd_set_rf_lvl_cmpstn_sub(struct cxd2880_tnrdmd
3338 int (*rf_lvl_cmpstn
)
3339 (struct cxd2880_tnrdmd
*,
3345 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
3348 return cxd2880_tnrdmd_set_rf_lvl_cmpstn(tnr_dmd
->diver_sub
,
3352 int cxd2880_tnrdmd_set_lna_thrs(struct cxd2880_tnrdmd
*tnr_dmd
,
3353 struct cxd2880_tnrdmd_lna_thrs_tbl_air
3355 struct cxd2880_tnrdmd_lna_thrs_tbl_cable
3361 tnr_dmd
->lna_thrs_tbl_air
= tbl_air
;
3362 tnr_dmd
->lna_thrs_tbl_cable
= tbl_cable
;
3367 int cxd2880_tnrdmd_set_lna_thrs_sub(struct cxd2880_tnrdmd
*tnr_dmd
,
3369 cxd2880_tnrdmd_lna_thrs_tbl_air
3371 struct cxd2880_tnrdmd_lna_thrs_tbl_cable
3377 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
3380 return cxd2880_tnrdmd_set_lna_thrs(tnr_dmd
->diver_sub
,
3381 tbl_air
, tbl_cable
);
3384 int cxd2880_tnrdmd_set_ts_pin_high_low(struct cxd2880_tnrdmd
3385 *tnr_dmd
, u8 en
, u8 value
)
3392 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
3395 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
)
3398 if (tnr_dmd
->create_param
.ts_output_if
!= CXD2880_TNRDMD_TSOUT_IF_TS
)
3401 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3408 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3410 0x50, ((value
& 0x1f) | 0x80));
3414 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
3416 0x52, (value
& 0x1f));
3418 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
3421 ARRAY_SIZE(set_ts_pin_seq
));
3425 ret
= load_cfg_mem(tnr_dmd
);
3431 int cxd2880_tnrdmd_set_ts_output(struct cxd2880_tnrdmd
*tnr_dmd
,
3439 if (tnr_dmd
->diver_mode
== CXD2880_TNRDMD_DIVERMODE_SUB
)
3442 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_SLEEP
&&
3443 tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
3446 switch (tnr_dmd
->create_param
.ts_output_if
) {
3447 case CXD2880_TNRDMD_TSOUT_IF_TS
:
3449 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
3452 ARRAY_SIZE(set_ts_output_seq1
));
3456 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
3459 ARRAY_SIZE(set_ts_output_seq2
));
3463 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
3466 ARRAY_SIZE(set_ts_output_seq3
));
3470 ret
= cxd2880_io_write_multi_regs(tnr_dmd
->io
,
3473 ARRAY_SIZE(set_ts_output_seq4
));
3479 case CXD2880_TNRDMD_TSOUT_IF_SPI
:
3482 case CXD2880_TNRDMD_TSOUT_IF_SDIO
:
3492 int slvt_freeze_reg(struct cxd2880_tnrdmd
*tnr_dmd
)
3500 switch (tnr_dmd
->create_param
.ts_output_if
) {
3501 case CXD2880_TNRDMD_TSOUT_IF_SPI
:
3502 case CXD2880_TNRDMD_TSOUT_IF_SDIO
:
3504 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
3511 case CXD2880_TNRDMD_TSOUT_IF_TS
:
3516 return tnr_dmd
->io
->write_reg(tnr_dmd
->io
,