2 * drxk_hard: DRX-K DVB-C/T demodulator driver
4 * Copyright (C) 2010-2011 Digital Devices GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/firmware.h>
32 #include <linux/i2c.h>
33 #include <linux/hardirq.h>
34 #include <asm/div64.h>
36 #include "dvb_frontend.h"
38 #include "drxk_hard.h"
41 static int power_down_dvbt(struct drxk_state
*state
, bool set_power_mode
);
42 static int power_down_qam(struct drxk_state
*state
);
43 static int set_dvbt_standard(struct drxk_state
*state
,
44 enum operation_mode o_mode
);
45 static int set_qam_standard(struct drxk_state
*state
,
46 enum operation_mode o_mode
);
47 static int set_qam(struct drxk_state
*state
, u16 intermediate_freqk_hz
,
48 s32 tuner_freq_offset
);
49 static int set_dvbt_standard(struct drxk_state
*state
,
50 enum operation_mode o_mode
);
51 static int dvbt_start(struct drxk_state
*state
);
52 static int set_dvbt(struct drxk_state
*state
, u16 intermediate_freqk_hz
,
53 s32 tuner_freq_offset
);
54 static int get_qam_lock_status(struct drxk_state
*state
, u32
*p_lock_status
);
55 static int get_dvbt_lock_status(struct drxk_state
*state
, u32
*p_lock_status
);
56 static int switch_antenna_to_qam(struct drxk_state
*state
);
57 static int switch_antenna_to_dvbt(struct drxk_state
*state
);
59 static bool is_dvbt(struct drxk_state
*state
)
61 return state
->m_operation_mode
== OM_DVBT
;
64 static bool is_qam(struct drxk_state
*state
)
66 return state
->m_operation_mode
== OM_QAM_ITU_A
||
67 state
->m_operation_mode
== OM_QAM_ITU_B
||
68 state
->m_operation_mode
== OM_QAM_ITU_C
;
73 #define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0)
74 #define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0)
76 #define DEFAULT_MER_83 165
77 #define DEFAULT_MER_93 250
79 #ifndef DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH
80 #define DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH (0x02)
83 #ifndef DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH
84 #define DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH (0x03)
87 #define DEFAULT_DRXK_MPEG_LOCK_TIMEOUT 700
88 #define DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT 500
90 #ifndef DRXK_KI_RAGC_ATV
91 #define DRXK_KI_RAGC_ATV 4
93 #ifndef DRXK_KI_IAGC_ATV
94 #define DRXK_KI_IAGC_ATV 6
96 #ifndef DRXK_KI_DAGC_ATV
97 #define DRXK_KI_DAGC_ATV 7
100 #ifndef DRXK_KI_RAGC_QAM
101 #define DRXK_KI_RAGC_QAM 3
103 #ifndef DRXK_KI_IAGC_QAM
104 #define DRXK_KI_IAGC_QAM 4
106 #ifndef DRXK_KI_DAGC_QAM
107 #define DRXK_KI_DAGC_QAM 7
109 #ifndef DRXK_KI_RAGC_DVBT
110 #define DRXK_KI_RAGC_DVBT (IsA1WithPatchCode(state) ? 3 : 2)
112 #ifndef DRXK_KI_IAGC_DVBT
113 #define DRXK_KI_IAGC_DVBT (IsA1WithPatchCode(state) ? 4 : 2)
115 #ifndef DRXK_KI_DAGC_DVBT
116 #define DRXK_KI_DAGC_DVBT (IsA1WithPatchCode(state) ? 10 : 7)
119 #ifndef DRXK_AGC_DAC_OFFSET
120 #define DRXK_AGC_DAC_OFFSET (0x800)
123 #ifndef DRXK_BANDWIDTH_8MHZ_IN_HZ
124 #define DRXK_BANDWIDTH_8MHZ_IN_HZ (0x8B8249L)
127 #ifndef DRXK_BANDWIDTH_7MHZ_IN_HZ
128 #define DRXK_BANDWIDTH_7MHZ_IN_HZ (0x7A1200L)
131 #ifndef DRXK_BANDWIDTH_6MHZ_IN_HZ
132 #define DRXK_BANDWIDTH_6MHZ_IN_HZ (0x68A1B6L)
135 #ifndef DRXK_QAM_SYMBOLRATE_MAX
136 #define DRXK_QAM_SYMBOLRATE_MAX (7233000)
139 #define DRXK_BL_ROM_OFFSET_TAPS_DVBT 56
140 #define DRXK_BL_ROM_OFFSET_TAPS_ITU_A 64
141 #define DRXK_BL_ROM_OFFSET_TAPS_ITU_C 0x5FE0
142 #define DRXK_BL_ROM_OFFSET_TAPS_BG 24
143 #define DRXK_BL_ROM_OFFSET_TAPS_DKILLP 32
144 #define DRXK_BL_ROM_OFFSET_TAPS_NTSC 40
145 #define DRXK_BL_ROM_OFFSET_TAPS_FM 48
146 #define DRXK_BL_ROM_OFFSET_UCODE 0
148 #define DRXK_BLC_TIMEOUT 100
150 #define DRXK_BLCC_NR_ELEMENTS_TAPS 2
151 #define DRXK_BLCC_NR_ELEMENTS_UCODE 6
153 #define DRXK_BLDC_NR_ELEMENTS_TAPS 28
155 #ifndef DRXK_OFDM_NE_NOTCH_WIDTH
156 #define DRXK_OFDM_NE_NOTCH_WIDTH (4)
159 #define DRXK_QAM_SL_SIG_POWER_QAM16 (40960)
160 #define DRXK_QAM_SL_SIG_POWER_QAM32 (20480)
161 #define DRXK_QAM_SL_SIG_POWER_QAM64 (43008)
162 #define DRXK_QAM_SL_SIG_POWER_QAM128 (20992)
163 #define DRXK_QAM_SL_SIG_POWER_QAM256 (43520)
165 static unsigned int debug
;
166 module_param(debug
, int, 0644);
167 MODULE_PARM_DESC(debug
, "enable debug messages");
169 #define dprintk(level, fmt, arg...) do { \
170 if (debug >= level) \
171 pr_debug(fmt, ##arg); \
175 static inline u32
MulDiv32(u32 a
, u32 b
, u32 c
)
179 tmp64
= (u64
) a
* (u64
) b
;
185 static inline u32
Frac28a(u32 a
, u32 c
)
191 R0
= (a
% c
) << 4; /* 32-28 == 4 shifts possible at max */
193 * integer part, only the 4 least significant
194 * bits will be visible in the result
197 /* division using radix 16, 7 nibbles in the result */
198 for (i
= 0; i
< 7; i
++) {
199 Q1
= (Q1
<< 4) | (R0
/ c
);
209 static inline u32
log10times100(u32 value
)
211 return (100L * intlog10(value
)) >> 24;
214 /****************************************************************************/
215 /* I2C **********************************************************************/
216 /****************************************************************************/
218 static int drxk_i2c_lock(struct drxk_state
*state
)
220 i2c_lock_adapter(state
->i2c
);
221 state
->drxk_i2c_exclusive_lock
= true;
226 static void drxk_i2c_unlock(struct drxk_state
*state
)
228 if (!state
->drxk_i2c_exclusive_lock
)
231 i2c_unlock_adapter(state
->i2c
);
232 state
->drxk_i2c_exclusive_lock
= false;
235 static int drxk_i2c_transfer(struct drxk_state
*state
, struct i2c_msg
*msgs
,
238 if (state
->drxk_i2c_exclusive_lock
)
239 return __i2c_transfer(state
->i2c
, msgs
, len
);
241 return i2c_transfer(state
->i2c
, msgs
, len
);
244 static int i2c_read1(struct drxk_state
*state
, u8 adr
, u8
*val
)
246 struct i2c_msg msgs
[1] = { {.addr
= adr
, .flags
= I2C_M_RD
,
247 .buf
= val
, .len
= 1}
250 return drxk_i2c_transfer(state
, msgs
, 1);
253 static int i2c_write(struct drxk_state
*state
, u8 adr
, u8
*data
, int len
)
256 struct i2c_msg msg
= {
257 .addr
= adr
, .flags
= 0, .buf
= data
, .len
= len
};
262 for (i
= 0; i
< len
; i
++)
263 pr_cont(" %02x", data
[i
]);
266 status
= drxk_i2c_transfer(state
, &msg
, 1);
267 if (status
>= 0 && status
!= 1)
271 pr_err("i2c write error at addr 0x%02x\n", adr
);
276 static int i2c_read(struct drxk_state
*state
,
277 u8 adr
, u8
*msg
, int len
, u8
*answ
, int alen
)
280 struct i2c_msg msgs
[2] = {
281 {.addr
= adr
, .flags
= 0,
282 .buf
= msg
, .len
= len
},
283 {.addr
= adr
, .flags
= I2C_M_RD
,
284 .buf
= answ
, .len
= alen
}
287 status
= drxk_i2c_transfer(state
, msgs
, 2);
290 pr_cont(": ERROR!\n");
294 pr_err("i2c read error at addr 0x%02x\n", adr
);
299 dprintk(2, ": read from");
300 for (i
= 0; i
< len
; i
++)
301 pr_cont(" %02x", msg
[i
]);
302 pr_cont(", value = ");
303 for (i
= 0; i
< alen
; i
++)
304 pr_cont(" %02x", answ
[i
]);
310 static int read16_flags(struct drxk_state
*state
, u32 reg
, u16
*data
, u8 flags
)
313 u8 adr
= state
->demod_address
, mm1
[4], mm2
[2], len
;
315 if (state
->single_master
)
318 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
319 mm1
[0] = (((reg
<< 1) & 0xFF) | 0x01);
320 mm1
[1] = ((reg
>> 16) & 0xFF);
321 mm1
[2] = ((reg
>> 24) & 0xFF) | flags
;
322 mm1
[3] = ((reg
>> 7) & 0xFF);
325 mm1
[0] = ((reg
<< 1) & 0xFF);
326 mm1
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
329 dprintk(2, "(0x%08x, 0x%02x)\n", reg
, flags
);
330 status
= i2c_read(state
, adr
, mm1
, len
, mm2
, 2);
334 *data
= mm2
[0] | (mm2
[1] << 8);
339 static int read16(struct drxk_state
*state
, u32 reg
, u16
*data
)
341 return read16_flags(state
, reg
, data
, 0);
344 static int read32_flags(struct drxk_state
*state
, u32 reg
, u32
*data
, u8 flags
)
347 u8 adr
= state
->demod_address
, mm1
[4], mm2
[4], len
;
349 if (state
->single_master
)
352 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
353 mm1
[0] = (((reg
<< 1) & 0xFF) | 0x01);
354 mm1
[1] = ((reg
>> 16) & 0xFF);
355 mm1
[2] = ((reg
>> 24) & 0xFF) | flags
;
356 mm1
[3] = ((reg
>> 7) & 0xFF);
359 mm1
[0] = ((reg
<< 1) & 0xFF);
360 mm1
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
363 dprintk(2, "(0x%08x, 0x%02x)\n", reg
, flags
);
364 status
= i2c_read(state
, adr
, mm1
, len
, mm2
, 4);
368 *data
= mm2
[0] | (mm2
[1] << 8) |
369 (mm2
[2] << 16) | (mm2
[3] << 24);
374 static int read32(struct drxk_state
*state
, u32 reg
, u32
*data
)
376 return read32_flags(state
, reg
, data
, 0);
379 static int write16_flags(struct drxk_state
*state
, u32 reg
, u16 data
, u8 flags
)
381 u8 adr
= state
->demod_address
, mm
[6], len
;
383 if (state
->single_master
)
385 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
386 mm
[0] = (((reg
<< 1) & 0xFF) | 0x01);
387 mm
[1] = ((reg
>> 16) & 0xFF);
388 mm
[2] = ((reg
>> 24) & 0xFF) | flags
;
389 mm
[3] = ((reg
>> 7) & 0xFF);
392 mm
[0] = ((reg
<< 1) & 0xFF);
393 mm
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
396 mm
[len
] = data
& 0xff;
397 mm
[len
+ 1] = (data
>> 8) & 0xff;
399 dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg
, data
, flags
);
400 return i2c_write(state
, adr
, mm
, len
+ 2);
403 static int write16(struct drxk_state
*state
, u32 reg
, u16 data
)
405 return write16_flags(state
, reg
, data
, 0);
408 static int write32_flags(struct drxk_state
*state
, u32 reg
, u32 data
, u8 flags
)
410 u8 adr
= state
->demod_address
, mm
[8], len
;
412 if (state
->single_master
)
414 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
415 mm
[0] = (((reg
<< 1) & 0xFF) | 0x01);
416 mm
[1] = ((reg
>> 16) & 0xFF);
417 mm
[2] = ((reg
>> 24) & 0xFF) | flags
;
418 mm
[3] = ((reg
>> 7) & 0xFF);
421 mm
[0] = ((reg
<< 1) & 0xFF);
422 mm
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
425 mm
[len
] = data
& 0xff;
426 mm
[len
+ 1] = (data
>> 8) & 0xff;
427 mm
[len
+ 2] = (data
>> 16) & 0xff;
428 mm
[len
+ 3] = (data
>> 24) & 0xff;
429 dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg
, data
, flags
);
431 return i2c_write(state
, adr
, mm
, len
+ 4);
434 static int write32(struct drxk_state
*state
, u32 reg
, u32 data
)
436 return write32_flags(state
, reg
, data
, 0);
439 static int write_block(struct drxk_state
*state
, u32 address
,
440 const int block_size
, const u8 p_block
[])
442 int status
= 0, blk_size
= block_size
;
445 if (state
->single_master
)
448 while (blk_size
> 0) {
449 int chunk
= blk_size
> state
->m_chunk_size
?
450 state
->m_chunk_size
: blk_size
;
451 u8
*adr_buf
= &state
->chunk
[0];
454 if (DRXDAP_FASI_LONG_FORMAT(address
) || (flags
!= 0)) {
455 adr_buf
[0] = (((address
<< 1) & 0xFF) | 0x01);
456 adr_buf
[1] = ((address
>> 16) & 0xFF);
457 adr_buf
[2] = ((address
>> 24) & 0xFF);
458 adr_buf
[3] = ((address
>> 7) & 0xFF);
461 if (chunk
== state
->m_chunk_size
)
464 adr_buf
[0] = ((address
<< 1) & 0xFF);
465 adr_buf
[1] = (((address
>> 16) & 0x0F) |
466 ((address
>> 18) & 0xF0));
469 memcpy(&state
->chunk
[adr_length
], p_block
, chunk
);
470 dprintk(2, "(0x%08x, 0x%02x)\n", address
, flags
);
474 for (i
= 0; i
< chunk
; i
++)
475 pr_cont(" %02x", p_block
[i
]);
478 status
= i2c_write(state
, state
->demod_address
,
479 &state
->chunk
[0], chunk
+ adr_length
);
481 pr_err("%s: i2c write error at addr 0x%02x\n",
486 address
+= (chunk
>> 1);
492 #ifndef DRXK_MAX_RETRIES_POWERUP
493 #define DRXK_MAX_RETRIES_POWERUP 20
496 static int power_up_device(struct drxk_state
*state
)
504 status
= i2c_read1(state
, state
->demod_address
, &data
);
508 status
= i2c_write(state
, state
->demod_address
,
510 usleep_range(10000, 11000);
514 status
= i2c_read1(state
, state
->demod_address
,
516 } while (status
< 0 &&
517 (retry_count
< DRXK_MAX_RETRIES_POWERUP
));
518 if (status
< 0 && retry_count
>= DRXK_MAX_RETRIES_POWERUP
)
522 /* Make sure all clk domains are active */
523 status
= write16(state
, SIO_CC_PWD_MODE__A
, SIO_CC_PWD_MODE_LEVEL_NONE
);
526 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
529 /* Enable pll lock tests */
530 status
= write16(state
, SIO_CC_PLL_LOCK__A
, 1);
534 state
->m_current_power_mode
= DRX_POWER_UP
;
538 pr_err("Error %d on %s\n", status
, __func__
);
544 static int init_state(struct drxk_state
*state
)
547 * FIXME: most (all?) of the values bellow should be moved into
548 * struct drxk_config, as they are probably board-specific
550 u32 ul_vsb_if_agc_mode
= DRXK_AGC_CTRL_AUTO
;
551 u32 ul_vsb_if_agc_output_level
= 0;
552 u32 ul_vsb_if_agc_min_level
= 0;
553 u32 ul_vsb_if_agc_max_level
= 0x7FFF;
554 u32 ul_vsb_if_agc_speed
= 3;
556 u32 ul_vsb_rf_agc_mode
= DRXK_AGC_CTRL_AUTO
;
557 u32 ul_vsb_rf_agc_output_level
= 0;
558 u32 ul_vsb_rf_agc_min_level
= 0;
559 u32 ul_vsb_rf_agc_max_level
= 0x7FFF;
560 u32 ul_vsb_rf_agc_speed
= 3;
561 u32 ul_vsb_rf_agc_top
= 9500;
562 u32 ul_vsb_rf_agc_cut_off_current
= 4000;
564 u32 ul_atv_if_agc_mode
= DRXK_AGC_CTRL_AUTO
;
565 u32 ul_atv_if_agc_output_level
= 0;
566 u32 ul_atv_if_agc_min_level
= 0;
567 u32 ul_atv_if_agc_max_level
= 0;
568 u32 ul_atv_if_agc_speed
= 3;
570 u32 ul_atv_rf_agc_mode
= DRXK_AGC_CTRL_OFF
;
571 u32 ul_atv_rf_agc_output_level
= 0;
572 u32 ul_atv_rf_agc_min_level
= 0;
573 u32 ul_atv_rf_agc_max_level
= 0;
574 u32 ul_atv_rf_agc_top
= 9500;
575 u32 ul_atv_rf_agc_cut_off_current
= 4000;
576 u32 ul_atv_rf_agc_speed
= 3;
578 u32 ulQual83
= DEFAULT_MER_83
;
579 u32 ulQual93
= DEFAULT_MER_93
;
581 u32 ul_mpeg_lock_time_out
= DEFAULT_DRXK_MPEG_LOCK_TIMEOUT
;
582 u32 ul_demod_lock_time_out
= DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT
;
584 /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
585 /* io_pad_cfg_mode output mode is drive always */
586 /* io_pad_cfg_drive is set to power 2 (23 mA) */
587 u32 ul_gpio_cfg
= 0x0113;
588 u32 ul_invert_ts_clock
= 0;
589 u32 ul_ts_data_strength
= DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH
;
590 u32 ul_dvbt_bitrate
= 50000000;
591 u32 ul_dvbc_bitrate
= DRXK_QAM_SYMBOLRATE_MAX
* 8;
593 u32 ul_insert_rs_byte
= 0;
595 u32 ul_rf_mirror
= 1;
596 u32 ul_power_down
= 0;
600 state
->m_has_lna
= false;
601 state
->m_has_dvbt
= false;
602 state
->m_has_dvbc
= false;
603 state
->m_has_atv
= false;
604 state
->m_has_oob
= false;
605 state
->m_has_audio
= false;
607 if (!state
->m_chunk_size
)
608 state
->m_chunk_size
= 124;
610 state
->m_osc_clock_freq
= 0;
611 state
->m_smart_ant_inverted
= false;
612 state
->m_b_p_down_open_bridge
= false;
614 /* real system clock frequency in kHz */
615 state
->m_sys_clock_freq
= 151875;
616 /* Timing div, 250ns/Psys */
617 /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */
618 state
->m_hi_cfg_timing_div
= ((state
->m_sys_clock_freq
/ 1000) *
619 HI_I2C_DELAY
) / 1000;
621 if (state
->m_hi_cfg_timing_div
> SIO_HI_RA_RAM_PAR_2_CFG_DIV__M
)
622 state
->m_hi_cfg_timing_div
= SIO_HI_RA_RAM_PAR_2_CFG_DIV__M
;
623 state
->m_hi_cfg_wake_up_key
= (state
->demod_address
<< 1);
624 /* port/bridge/power down ctrl */
625 state
->m_hi_cfg_ctrl
= SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE
;
627 state
->m_b_power_down
= (ul_power_down
!= 0);
629 state
->m_drxk_a3_patch_code
= false;
631 /* Init AGC and PGA parameters */
633 state
->m_vsb_if_agc_cfg
.ctrl_mode
= ul_vsb_if_agc_mode
;
634 state
->m_vsb_if_agc_cfg
.output_level
= ul_vsb_if_agc_output_level
;
635 state
->m_vsb_if_agc_cfg
.min_output_level
= ul_vsb_if_agc_min_level
;
636 state
->m_vsb_if_agc_cfg
.max_output_level
= ul_vsb_if_agc_max_level
;
637 state
->m_vsb_if_agc_cfg
.speed
= ul_vsb_if_agc_speed
;
638 state
->m_vsb_pga_cfg
= 140;
641 state
->m_vsb_rf_agc_cfg
.ctrl_mode
= ul_vsb_rf_agc_mode
;
642 state
->m_vsb_rf_agc_cfg
.output_level
= ul_vsb_rf_agc_output_level
;
643 state
->m_vsb_rf_agc_cfg
.min_output_level
= ul_vsb_rf_agc_min_level
;
644 state
->m_vsb_rf_agc_cfg
.max_output_level
= ul_vsb_rf_agc_max_level
;
645 state
->m_vsb_rf_agc_cfg
.speed
= ul_vsb_rf_agc_speed
;
646 state
->m_vsb_rf_agc_cfg
.top
= ul_vsb_rf_agc_top
;
647 state
->m_vsb_rf_agc_cfg
.cut_off_current
= ul_vsb_rf_agc_cut_off_current
;
648 state
->m_vsb_pre_saw_cfg
.reference
= 0x07;
649 state
->m_vsb_pre_saw_cfg
.use_pre_saw
= true;
651 state
->m_Quality83percent
= DEFAULT_MER_83
;
652 state
->m_Quality93percent
= DEFAULT_MER_93
;
653 if (ulQual93
<= 500 && ulQual83
< ulQual93
) {
654 state
->m_Quality83percent
= ulQual83
;
655 state
->m_Quality93percent
= ulQual93
;
659 state
->m_atv_if_agc_cfg
.ctrl_mode
= ul_atv_if_agc_mode
;
660 state
->m_atv_if_agc_cfg
.output_level
= ul_atv_if_agc_output_level
;
661 state
->m_atv_if_agc_cfg
.min_output_level
= ul_atv_if_agc_min_level
;
662 state
->m_atv_if_agc_cfg
.max_output_level
= ul_atv_if_agc_max_level
;
663 state
->m_atv_if_agc_cfg
.speed
= ul_atv_if_agc_speed
;
666 state
->m_atv_rf_agc_cfg
.ctrl_mode
= ul_atv_rf_agc_mode
;
667 state
->m_atv_rf_agc_cfg
.output_level
= ul_atv_rf_agc_output_level
;
668 state
->m_atv_rf_agc_cfg
.min_output_level
= ul_atv_rf_agc_min_level
;
669 state
->m_atv_rf_agc_cfg
.max_output_level
= ul_atv_rf_agc_max_level
;
670 state
->m_atv_rf_agc_cfg
.speed
= ul_atv_rf_agc_speed
;
671 state
->m_atv_rf_agc_cfg
.top
= ul_atv_rf_agc_top
;
672 state
->m_atv_rf_agc_cfg
.cut_off_current
= ul_atv_rf_agc_cut_off_current
;
673 state
->m_atv_pre_saw_cfg
.reference
= 0x04;
674 state
->m_atv_pre_saw_cfg
.use_pre_saw
= true;
678 state
->m_dvbt_rf_agc_cfg
.ctrl_mode
= DRXK_AGC_CTRL_OFF
;
679 state
->m_dvbt_rf_agc_cfg
.output_level
= 0;
680 state
->m_dvbt_rf_agc_cfg
.min_output_level
= 0;
681 state
->m_dvbt_rf_agc_cfg
.max_output_level
= 0xFFFF;
682 state
->m_dvbt_rf_agc_cfg
.top
= 0x2100;
683 state
->m_dvbt_rf_agc_cfg
.cut_off_current
= 4000;
684 state
->m_dvbt_rf_agc_cfg
.speed
= 1;
688 state
->m_dvbt_if_agc_cfg
.ctrl_mode
= DRXK_AGC_CTRL_AUTO
;
689 state
->m_dvbt_if_agc_cfg
.output_level
= 0;
690 state
->m_dvbt_if_agc_cfg
.min_output_level
= 0;
691 state
->m_dvbt_if_agc_cfg
.max_output_level
= 9000;
692 state
->m_dvbt_if_agc_cfg
.top
= 13424;
693 state
->m_dvbt_if_agc_cfg
.cut_off_current
= 0;
694 state
->m_dvbt_if_agc_cfg
.speed
= 3;
695 state
->m_dvbt_if_agc_cfg
.fast_clip_ctrl_delay
= 30;
696 state
->m_dvbt_if_agc_cfg
.ingain_tgt_max
= 30000;
697 /* state->m_dvbtPgaCfg = 140; */
699 state
->m_dvbt_pre_saw_cfg
.reference
= 4;
700 state
->m_dvbt_pre_saw_cfg
.use_pre_saw
= false;
703 state
->m_qam_rf_agc_cfg
.ctrl_mode
= DRXK_AGC_CTRL_OFF
;
704 state
->m_qam_rf_agc_cfg
.output_level
= 0;
705 state
->m_qam_rf_agc_cfg
.min_output_level
= 6023;
706 state
->m_qam_rf_agc_cfg
.max_output_level
= 27000;
707 state
->m_qam_rf_agc_cfg
.top
= 0x2380;
708 state
->m_qam_rf_agc_cfg
.cut_off_current
= 4000;
709 state
->m_qam_rf_agc_cfg
.speed
= 3;
712 state
->m_qam_if_agc_cfg
.ctrl_mode
= DRXK_AGC_CTRL_AUTO
;
713 state
->m_qam_if_agc_cfg
.output_level
= 0;
714 state
->m_qam_if_agc_cfg
.min_output_level
= 0;
715 state
->m_qam_if_agc_cfg
.max_output_level
= 9000;
716 state
->m_qam_if_agc_cfg
.top
= 0x0511;
717 state
->m_qam_if_agc_cfg
.cut_off_current
= 0;
718 state
->m_qam_if_agc_cfg
.speed
= 3;
719 state
->m_qam_if_agc_cfg
.ingain_tgt_max
= 5119;
720 state
->m_qam_if_agc_cfg
.fast_clip_ctrl_delay
= 50;
722 state
->m_qam_pga_cfg
= 140;
723 state
->m_qam_pre_saw_cfg
.reference
= 4;
724 state
->m_qam_pre_saw_cfg
.use_pre_saw
= false;
726 state
->m_operation_mode
= OM_NONE
;
727 state
->m_drxk_state
= DRXK_UNINITIALIZED
;
729 /* MPEG output configuration */
730 state
->m_enable_mpeg_output
= true; /* If TRUE; enable MPEG ouput */
731 state
->m_insert_rs_byte
= false; /* If TRUE; insert RS byte */
732 state
->m_invert_data
= false; /* If TRUE; invert DATA signals */
733 state
->m_invert_err
= false; /* If TRUE; invert ERR signal */
734 state
->m_invert_str
= false; /* If TRUE; invert STR signals */
735 state
->m_invert_val
= false; /* If TRUE; invert VAL signals */
736 state
->m_invert_clk
= (ul_invert_ts_clock
!= 0); /* If TRUE; invert CLK signals */
738 /* If TRUE; static MPEG clockrate will be used;
739 otherwise clockrate will adapt to the bitrate of the TS */
741 state
->m_dvbt_bitrate
= ul_dvbt_bitrate
;
742 state
->m_dvbc_bitrate
= ul_dvbc_bitrate
;
744 state
->m_ts_data_strength
= (ul_ts_data_strength
& 0x07);
746 /* Maximum bitrate in b/s in case static clockrate is selected */
747 state
->m_mpeg_ts_static_bitrate
= 19392658;
748 state
->m_disable_te_ihandling
= false;
750 if (ul_insert_rs_byte
)
751 state
->m_insert_rs_byte
= true;
753 state
->m_mpeg_lock_time_out
= DEFAULT_DRXK_MPEG_LOCK_TIMEOUT
;
754 if (ul_mpeg_lock_time_out
< 10000)
755 state
->m_mpeg_lock_time_out
= ul_mpeg_lock_time_out
;
756 state
->m_demod_lock_time_out
= DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT
;
757 if (ul_demod_lock_time_out
< 10000)
758 state
->m_demod_lock_time_out
= ul_demod_lock_time_out
;
761 state
->m_constellation
= DRX_CONSTELLATION_AUTO
;
762 state
->m_qam_interleave_mode
= DRXK_QAM_I12_J17
;
763 state
->m_fec_rs_plen
= 204 * 8; /* fecRsPlen annex A */
764 state
->m_fec_rs_prescale
= 1;
766 state
->m_sqi_speed
= DRXK_DVBT_SQI_SPEED_MEDIUM
;
767 state
->m_agcfast_clip_ctrl_delay
= 0;
769 state
->m_gpio_cfg
= ul_gpio_cfg
;
771 state
->m_b_power_down
= false;
772 state
->m_current_power_mode
= DRX_POWER_DOWN
;
774 state
->m_rfmirror
= (ul_rf_mirror
== 0);
775 state
->m_if_agc_pol
= false;
779 static int drxx_open(struct drxk_state
*state
)
787 /* stop lock indicator process */
788 status
= write16(state
, SCU_RAM_GPIO__A
,
789 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
792 /* Check device id */
793 status
= read16(state
, SIO_TOP_COMM_KEY__A
, &key
);
796 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
799 status
= read32(state
, SIO_TOP_JTAGID_LO__A
, &jtag
);
802 status
= read16(state
, SIO_PDR_UIO_IN_HI__A
, &bid
);
805 status
= write16(state
, SIO_TOP_COMM_KEY__A
, key
);
808 pr_err("Error %d on %s\n", status
, __func__
);
812 static int get_device_capabilities(struct drxk_state
*state
)
814 u16 sio_pdr_ohw_cfg
= 0;
815 u32 sio_top_jtagid_lo
= 0;
817 const char *spin
= "";
822 /* stop lock indicator process */
823 status
= write16(state
, SCU_RAM_GPIO__A
,
824 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
827 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
830 status
= read16(state
, SIO_PDR_OHW_CFG__A
, &sio_pdr_ohw_cfg
);
833 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
837 switch ((sio_pdr_ohw_cfg
& SIO_PDR_OHW_CFG_FREF_SEL__M
)) {
839 /* ignore (bypass ?) */
843 state
->m_osc_clock_freq
= 27000;
847 state
->m_osc_clock_freq
= 20250;
851 state
->m_osc_clock_freq
= 20250;
854 pr_err("Clock Frequency is unknown\n");
858 Determine device capabilities
861 status
= read32(state
, SIO_TOP_JTAGID_LO__A
, &sio_top_jtagid_lo
);
865 pr_info("status = 0x%08x\n", sio_top_jtagid_lo
);
868 switch ((sio_top_jtagid_lo
>> 29) & 0xF) {
870 state
->m_device_spin
= DRXK_SPIN_A1
;
874 state
->m_device_spin
= DRXK_SPIN_A2
;
878 state
->m_device_spin
= DRXK_SPIN_A3
;
882 state
->m_device_spin
= DRXK_SPIN_UNKNOWN
;
884 pr_err("Spin %d unknown\n", (sio_top_jtagid_lo
>> 29) & 0xF);
887 switch ((sio_top_jtagid_lo
>> 12) & 0xFF) {
889 /* typeId = DRX3913K_TYPE_ID */
890 state
->m_has_lna
= false;
891 state
->m_has_oob
= false;
892 state
->m_has_atv
= false;
893 state
->m_has_audio
= false;
894 state
->m_has_dvbt
= true;
895 state
->m_has_dvbc
= true;
896 state
->m_has_sawsw
= true;
897 state
->m_has_gpio2
= false;
898 state
->m_has_gpio1
= false;
899 state
->m_has_irqn
= false;
902 /* typeId = DRX3915K_TYPE_ID */
903 state
->m_has_lna
= false;
904 state
->m_has_oob
= false;
905 state
->m_has_atv
= true;
906 state
->m_has_audio
= false;
907 state
->m_has_dvbt
= true;
908 state
->m_has_dvbc
= false;
909 state
->m_has_sawsw
= true;
910 state
->m_has_gpio2
= true;
911 state
->m_has_gpio1
= true;
912 state
->m_has_irqn
= false;
915 /* typeId = DRX3916K_TYPE_ID */
916 state
->m_has_lna
= false;
917 state
->m_has_oob
= false;
918 state
->m_has_atv
= true;
919 state
->m_has_audio
= false;
920 state
->m_has_dvbt
= true;
921 state
->m_has_dvbc
= false;
922 state
->m_has_sawsw
= true;
923 state
->m_has_gpio2
= true;
924 state
->m_has_gpio1
= true;
925 state
->m_has_irqn
= false;
928 /* typeId = DRX3918K_TYPE_ID */
929 state
->m_has_lna
= false;
930 state
->m_has_oob
= false;
931 state
->m_has_atv
= true;
932 state
->m_has_audio
= true;
933 state
->m_has_dvbt
= true;
934 state
->m_has_dvbc
= false;
935 state
->m_has_sawsw
= true;
936 state
->m_has_gpio2
= true;
937 state
->m_has_gpio1
= true;
938 state
->m_has_irqn
= false;
941 /* typeId = DRX3921K_TYPE_ID */
942 state
->m_has_lna
= false;
943 state
->m_has_oob
= false;
944 state
->m_has_atv
= true;
945 state
->m_has_audio
= true;
946 state
->m_has_dvbt
= true;
947 state
->m_has_dvbc
= true;
948 state
->m_has_sawsw
= true;
949 state
->m_has_gpio2
= true;
950 state
->m_has_gpio1
= true;
951 state
->m_has_irqn
= false;
954 /* typeId = DRX3923K_TYPE_ID */
955 state
->m_has_lna
= false;
956 state
->m_has_oob
= false;
957 state
->m_has_atv
= true;
958 state
->m_has_audio
= true;
959 state
->m_has_dvbt
= true;
960 state
->m_has_dvbc
= true;
961 state
->m_has_sawsw
= true;
962 state
->m_has_gpio2
= true;
963 state
->m_has_gpio1
= true;
964 state
->m_has_irqn
= false;
967 /* typeId = DRX3925K_TYPE_ID */
968 state
->m_has_lna
= false;
969 state
->m_has_oob
= false;
970 state
->m_has_atv
= true;
971 state
->m_has_audio
= true;
972 state
->m_has_dvbt
= true;
973 state
->m_has_dvbc
= true;
974 state
->m_has_sawsw
= true;
975 state
->m_has_gpio2
= true;
976 state
->m_has_gpio1
= true;
977 state
->m_has_irqn
= false;
980 /* typeId = DRX3926K_TYPE_ID */
981 state
->m_has_lna
= false;
982 state
->m_has_oob
= false;
983 state
->m_has_atv
= true;
984 state
->m_has_audio
= false;
985 state
->m_has_dvbt
= true;
986 state
->m_has_dvbc
= true;
987 state
->m_has_sawsw
= true;
988 state
->m_has_gpio2
= true;
989 state
->m_has_gpio1
= true;
990 state
->m_has_irqn
= false;
993 pr_err("DeviceID 0x%02x not supported\n",
994 ((sio_top_jtagid_lo
>> 12) & 0xFF));
999 pr_info("detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n",
1000 ((sio_top_jtagid_lo
>> 12) & 0xFF), spin
,
1001 state
->m_osc_clock_freq
/ 1000,
1002 state
->m_osc_clock_freq
% 1000);
1006 pr_err("Error %d on %s\n", status
, __func__
);
1012 static int hi_command(struct drxk_state
*state
, u16 cmd
, u16
*p_result
)
1020 status
= write16(state
, SIO_HI_RA_RAM_CMD__A
, cmd
);
1023 if (cmd
== SIO_HI_RA_RAM_CMD_RESET
)
1024 usleep_range(1000, 2000);
1027 (bool) ((cmd
== SIO_HI_RA_RAM_CMD_CONFIG
) &&
1028 ((state
->m_hi_cfg_ctrl
) &
1029 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M
) ==
1030 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
);
1031 if (powerdown_cmd
== false) {
1032 /* Wait until command rdy */
1033 u32 retry_count
= 0;
1037 usleep_range(1000, 2000);
1039 status
= read16(state
, SIO_HI_RA_RAM_CMD__A
,
1041 } while ((status
< 0) && (retry_count
< DRXK_MAX_RETRIES
)
1042 && (wait_cmd
!= 0));
1045 status
= read16(state
, SIO_HI_RA_RAM_RES__A
, p_result
);
1049 pr_err("Error %d on %s\n", status
, __func__
);
1054 static int hi_cfg_command(struct drxk_state
*state
)
1060 mutex_lock(&state
->mutex
);
1062 status
= write16(state
, SIO_HI_RA_RAM_PAR_6__A
,
1063 state
->m_hi_cfg_timeout
);
1066 status
= write16(state
, SIO_HI_RA_RAM_PAR_5__A
,
1067 state
->m_hi_cfg_ctrl
);
1070 status
= write16(state
, SIO_HI_RA_RAM_PAR_4__A
,
1071 state
->m_hi_cfg_wake_up_key
);
1074 status
= write16(state
, SIO_HI_RA_RAM_PAR_3__A
,
1075 state
->m_hi_cfg_bridge_delay
);
1078 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
,
1079 state
->m_hi_cfg_timing_div
);
1082 status
= write16(state
, SIO_HI_RA_RAM_PAR_1__A
,
1083 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY
);
1086 status
= hi_command(state
, SIO_HI_RA_RAM_CMD_CONFIG
, 0);
1090 state
->m_hi_cfg_ctrl
&= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
1092 mutex_unlock(&state
->mutex
);
1094 pr_err("Error %d on %s\n", status
, __func__
);
1098 static int init_hi(struct drxk_state
*state
)
1102 state
->m_hi_cfg_wake_up_key
= (state
->demod_address
<< 1);
1103 state
->m_hi_cfg_timeout
= 0x96FF;
1104 /* port/bridge/power down ctrl */
1105 state
->m_hi_cfg_ctrl
= SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE
;
1107 return hi_cfg_command(state
);
1110 static int mpegts_configure_pins(struct drxk_state
*state
, bool mpeg_enable
)
1113 u16 sio_pdr_mclk_cfg
= 0;
1114 u16 sio_pdr_mdx_cfg
= 0;
1117 dprintk(1, ": mpeg %s, %s mode\n",
1118 mpeg_enable
? "enable" : "disable",
1119 state
->m_enable_parallel
? "parallel" : "serial");
1121 /* stop lock indicator process */
1122 status
= write16(state
, SCU_RAM_GPIO__A
,
1123 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
1127 /* MPEG TS pad configuration */
1128 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
1132 if (mpeg_enable
== false) {
1133 /* Set MPEG TS pads to inputmode */
1134 status
= write16(state
, SIO_PDR_MSTRT_CFG__A
, 0x0000);
1137 status
= write16(state
, SIO_PDR_MERR_CFG__A
, 0x0000);
1140 status
= write16(state
, SIO_PDR_MCLK_CFG__A
, 0x0000);
1143 status
= write16(state
, SIO_PDR_MVAL_CFG__A
, 0x0000);
1146 status
= write16(state
, SIO_PDR_MD0_CFG__A
, 0x0000);
1149 status
= write16(state
, SIO_PDR_MD1_CFG__A
, 0x0000);
1152 status
= write16(state
, SIO_PDR_MD2_CFG__A
, 0x0000);
1155 status
= write16(state
, SIO_PDR_MD3_CFG__A
, 0x0000);
1158 status
= write16(state
, SIO_PDR_MD4_CFG__A
, 0x0000);
1161 status
= write16(state
, SIO_PDR_MD5_CFG__A
, 0x0000);
1164 status
= write16(state
, SIO_PDR_MD6_CFG__A
, 0x0000);
1167 status
= write16(state
, SIO_PDR_MD7_CFG__A
, 0x0000);
1171 /* Enable MPEG output */
1173 ((state
->m_ts_data_strength
<<
1174 SIO_PDR_MD0_CFG_DRIVE__B
) | 0x0003);
1175 sio_pdr_mclk_cfg
= ((state
->m_ts_clockk_strength
<<
1176 SIO_PDR_MCLK_CFG_DRIVE__B
) |
1179 status
= write16(state
, SIO_PDR_MSTRT_CFG__A
, sio_pdr_mdx_cfg
);
1183 if (state
->enable_merr_cfg
)
1184 err_cfg
= sio_pdr_mdx_cfg
;
1186 status
= write16(state
, SIO_PDR_MERR_CFG__A
, err_cfg
);
1189 status
= write16(state
, SIO_PDR_MVAL_CFG__A
, err_cfg
);
1193 if (state
->m_enable_parallel
== true) {
1194 /* paralel -> enable MD1 to MD7 */
1195 status
= write16(state
, SIO_PDR_MD1_CFG__A
,
1199 status
= write16(state
, SIO_PDR_MD2_CFG__A
,
1203 status
= write16(state
, SIO_PDR_MD3_CFG__A
,
1207 status
= write16(state
, SIO_PDR_MD4_CFG__A
,
1211 status
= write16(state
, SIO_PDR_MD5_CFG__A
,
1215 status
= write16(state
, SIO_PDR_MD6_CFG__A
,
1219 status
= write16(state
, SIO_PDR_MD7_CFG__A
,
1224 sio_pdr_mdx_cfg
= ((state
->m_ts_data_strength
<<
1225 SIO_PDR_MD0_CFG_DRIVE__B
)
1227 /* serial -> disable MD1 to MD7 */
1228 status
= write16(state
, SIO_PDR_MD1_CFG__A
, 0x0000);
1231 status
= write16(state
, SIO_PDR_MD2_CFG__A
, 0x0000);
1234 status
= write16(state
, SIO_PDR_MD3_CFG__A
, 0x0000);
1237 status
= write16(state
, SIO_PDR_MD4_CFG__A
, 0x0000);
1240 status
= write16(state
, SIO_PDR_MD5_CFG__A
, 0x0000);
1243 status
= write16(state
, SIO_PDR_MD6_CFG__A
, 0x0000);
1246 status
= write16(state
, SIO_PDR_MD7_CFG__A
, 0x0000);
1250 status
= write16(state
, SIO_PDR_MCLK_CFG__A
, sio_pdr_mclk_cfg
);
1253 status
= write16(state
, SIO_PDR_MD0_CFG__A
, sio_pdr_mdx_cfg
);
1257 /* Enable MB output over MPEG pads and ctl input */
1258 status
= write16(state
, SIO_PDR_MON_CFG__A
, 0x0000);
1261 /* Write nomagic word to enable pdr reg write */
1262 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
1265 pr_err("Error %d on %s\n", status
, __func__
);
1269 static int mpegts_disable(struct drxk_state
*state
)
1273 return mpegts_configure_pins(state
, false);
1276 static int bl_chain_cmd(struct drxk_state
*state
,
1277 u16 rom_offset
, u16 nr_of_elements
, u32 time_out
)
1284 mutex_lock(&state
->mutex
);
1285 status
= write16(state
, SIO_BL_MODE__A
, SIO_BL_MODE_CHAIN
);
1288 status
= write16(state
, SIO_BL_CHAIN_ADDR__A
, rom_offset
);
1291 status
= write16(state
, SIO_BL_CHAIN_LEN__A
, nr_of_elements
);
1294 status
= write16(state
, SIO_BL_ENABLE__A
, SIO_BL_ENABLE_ON
);
1298 end
= jiffies
+ msecs_to_jiffies(time_out
);
1300 usleep_range(1000, 2000);
1301 status
= read16(state
, SIO_BL_STATUS__A
, &bl_status
);
1304 } while ((bl_status
== 0x1) &&
1305 ((time_is_after_jiffies(end
))));
1307 if (bl_status
== 0x1) {
1308 pr_err("SIO not ready\n");
1314 pr_err("Error %d on %s\n", status
, __func__
);
1316 mutex_unlock(&state
->mutex
);
1321 static int download_microcode(struct drxk_state
*state
,
1322 const u8 p_mc_image
[], u32 length
)
1324 const u8
*p_src
= p_mc_image
;
1334 /* down the drain (we don't care about MAGIC_WORD) */
1336 /* For future reference */
1337 drain
= (p_src
[0] << 8) | p_src
[1];
1339 p_src
+= sizeof(u16
);
1340 offset
+= sizeof(u16
);
1341 n_blocks
= (p_src
[0] << 8) | p_src
[1];
1342 p_src
+= sizeof(u16
);
1343 offset
+= sizeof(u16
);
1345 for (i
= 0; i
< n_blocks
; i
+= 1) {
1346 address
= (p_src
[0] << 24) | (p_src
[1] << 16) |
1347 (p_src
[2] << 8) | p_src
[3];
1348 p_src
+= sizeof(u32
);
1349 offset
+= sizeof(u32
);
1351 block_size
= ((p_src
[0] << 8) | p_src
[1]) * sizeof(u16
);
1352 p_src
+= sizeof(u16
);
1353 offset
+= sizeof(u16
);
1356 /* For future reference */
1357 flags
= (p_src
[0] << 8) | p_src
[1];
1359 p_src
+= sizeof(u16
);
1360 offset
+= sizeof(u16
);
1363 /* For future reference */
1364 block_crc
= (p_src
[0] << 8) | p_src
[1];
1366 p_src
+= sizeof(u16
);
1367 offset
+= sizeof(u16
);
1369 if (offset
+ block_size
> length
) {
1370 pr_err("Firmware is corrupted.\n");
1374 status
= write_block(state
, address
, block_size
, p_src
);
1376 pr_err("Error %d while loading firmware\n", status
);
1379 p_src
+= block_size
;
1380 offset
+= block_size
;
1385 static int dvbt_enable_ofdm_token_ring(struct drxk_state
*state
, bool enable
)
1389 u16 desired_ctrl
= SIO_OFDM_SH_OFDM_RING_ENABLE_ON
;
1390 u16 desired_status
= SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED
;
1395 if (enable
== false) {
1396 desired_ctrl
= SIO_OFDM_SH_OFDM_RING_ENABLE_OFF
;
1397 desired_status
= SIO_OFDM_SH_OFDM_RING_STATUS_DOWN
;
1400 status
= read16(state
, SIO_OFDM_SH_OFDM_RING_STATUS__A
, &data
);
1401 if (status
>= 0 && data
== desired_status
) {
1402 /* tokenring already has correct status */
1405 /* Disable/enable dvbt tokenring bridge */
1406 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
, desired_ctrl
);
1408 end
= jiffies
+ msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT
);
1410 status
= read16(state
, SIO_OFDM_SH_OFDM_RING_STATUS__A
, &data
);
1411 if ((status
>= 0 && data
== desired_status
)
1412 || time_is_after_jiffies(end
))
1414 usleep_range(1000, 2000);
1416 if (data
!= desired_status
) {
1417 pr_err("SIO not ready\n");
1423 static int mpegts_stop(struct drxk_state
*state
)
1426 u16 fec_oc_snc_mode
= 0;
1427 u16 fec_oc_ipr_mode
= 0;
1431 /* Gracefull shutdown (byte boundaries) */
1432 status
= read16(state
, FEC_OC_SNC_MODE__A
, &fec_oc_snc_mode
);
1435 fec_oc_snc_mode
|= FEC_OC_SNC_MODE_SHUTDOWN__M
;
1436 status
= write16(state
, FEC_OC_SNC_MODE__A
, fec_oc_snc_mode
);
1440 /* Suppress MCLK during absence of data */
1441 status
= read16(state
, FEC_OC_IPR_MODE__A
, &fec_oc_ipr_mode
);
1444 fec_oc_ipr_mode
|= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M
;
1445 status
= write16(state
, FEC_OC_IPR_MODE__A
, fec_oc_ipr_mode
);
1449 pr_err("Error %d on %s\n", status
, __func__
);
1454 static int scu_command(struct drxk_state
*state
,
1455 u16 cmd
, u8 parameter_len
,
1456 u16
*parameter
, u8 result_len
, u16
*result
)
1458 #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15
1459 #error DRXK register mapping no longer compatible with this routine!
1462 int status
= -EINVAL
;
1471 if ((cmd
== 0) || ((parameter_len
> 0) && (parameter
== NULL
)) ||
1472 ((result_len
> 0) && (result
== NULL
))) {
1473 pr_err("Error %d on %s\n", status
, __func__
);
1477 mutex_lock(&state
->mutex
);
1479 /* assume that the command register is ready
1480 since it is checked afterwards */
1481 for (ii
= parameter_len
- 1; ii
>= 0; ii
-= 1) {
1482 buffer
[cnt
++] = (parameter
[ii
] & 0xFF);
1483 buffer
[cnt
++] = ((parameter
[ii
] >> 8) & 0xFF);
1485 buffer
[cnt
++] = (cmd
& 0xFF);
1486 buffer
[cnt
++] = ((cmd
>> 8) & 0xFF);
1488 write_block(state
, SCU_RAM_PARAM_0__A
-
1489 (parameter_len
- 1), cnt
, buffer
);
1490 /* Wait until SCU has processed command */
1491 end
= jiffies
+ msecs_to_jiffies(DRXK_MAX_WAITTIME
);
1493 usleep_range(1000, 2000);
1494 status
= read16(state
, SCU_RAM_COMMAND__A
, &cur_cmd
);
1497 } while (!(cur_cmd
== DRX_SCU_READY
) && (time_is_after_jiffies(end
)));
1498 if (cur_cmd
!= DRX_SCU_READY
) {
1499 pr_err("SCU not ready\n");
1504 if ((result_len
> 0) && (result
!= NULL
)) {
1508 for (ii
= result_len
- 1; ii
>= 0; ii
-= 1) {
1509 status
= read16(state
, SCU_RAM_PARAM_0__A
- ii
,
1515 /* Check if an error was reported by SCU */
1516 err
= (s16
)result
[0];
1520 /* check for the known error codes */
1522 case SCU_RESULT_UNKCMD
:
1523 p
= "SCU_RESULT_UNKCMD";
1525 case SCU_RESULT_UNKSTD
:
1526 p
= "SCU_RESULT_UNKSTD";
1528 case SCU_RESULT_SIZE
:
1529 p
= "SCU_RESULT_SIZE";
1531 case SCU_RESULT_INVPAR
:
1532 p
= "SCU_RESULT_INVPAR";
1534 default: /* Other negative values are errors */
1535 sprintf(errname
, "ERROR: %d\n", err
);
1538 pr_err("%s while sending cmd 0x%04x with params:", p
, cmd
);
1539 print_hex_dump_bytes("drxk: ", DUMP_PREFIX_NONE
, buffer
, cnt
);
1546 pr_err("Error %d on %s\n", status
, __func__
);
1548 mutex_unlock(&state
->mutex
);
1552 static int set_iqm_af(struct drxk_state
*state
, bool active
)
1560 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
1565 data
|= (IQM_AF_STDBY_STDBY_ADC_STANDBY
1566 | IQM_AF_STDBY_STDBY_AMP_STANDBY
1567 | IQM_AF_STDBY_STDBY_PD_STANDBY
1568 | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
1569 | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
);
1571 data
&= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY
)
1572 & (~IQM_AF_STDBY_STDBY_AMP_STANDBY
)
1573 & (~IQM_AF_STDBY_STDBY_PD_STANDBY
)
1574 & (~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
)
1575 & (~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
)
1578 status
= write16(state
, IQM_AF_STDBY__A
, data
);
1582 pr_err("Error %d on %s\n", status
, __func__
);
1586 static int ctrl_power_mode(struct drxk_state
*state
, enum drx_power_mode
*mode
)
1589 u16 sio_cc_pwd_mode
= 0;
1593 /* Check arguments */
1599 sio_cc_pwd_mode
= SIO_CC_PWD_MODE_LEVEL_NONE
;
1601 case DRXK_POWER_DOWN_OFDM
:
1602 sio_cc_pwd_mode
= SIO_CC_PWD_MODE_LEVEL_OFDM
;
1604 case DRXK_POWER_DOWN_CORE
:
1605 sio_cc_pwd_mode
= SIO_CC_PWD_MODE_LEVEL_CLOCK
;
1607 case DRXK_POWER_DOWN_PLL
:
1608 sio_cc_pwd_mode
= SIO_CC_PWD_MODE_LEVEL_PLL
;
1610 case DRX_POWER_DOWN
:
1611 sio_cc_pwd_mode
= SIO_CC_PWD_MODE_LEVEL_OSC
;
1614 /* Unknow sleep mode */
1618 /* If already in requested power mode, do nothing */
1619 if (state
->m_current_power_mode
== *mode
)
1622 /* For next steps make sure to start from DRX_POWER_UP mode */
1623 if (state
->m_current_power_mode
!= DRX_POWER_UP
) {
1624 status
= power_up_device(state
);
1627 status
= dvbt_enable_ofdm_token_ring(state
, true);
1632 if (*mode
== DRX_POWER_UP
) {
1633 /* Restore analog & pin configuartion */
1635 /* Power down to requested mode */
1636 /* Backup some register settings */
1637 /* Set pins with possible pull-ups connected
1638 to them in input mode */
1639 /* Analog power down */
1640 /* ADC power down */
1641 /* Power down device */
1642 /* stop all comm_exec */
1643 /* Stop and power down previous standard */
1644 switch (state
->m_operation_mode
) {
1646 status
= mpegts_stop(state
);
1649 status
= power_down_dvbt(state
, false);
1655 status
= mpegts_stop(state
);
1658 status
= power_down_qam(state
);
1665 status
= dvbt_enable_ofdm_token_ring(state
, false);
1668 status
= write16(state
, SIO_CC_PWD_MODE__A
, sio_cc_pwd_mode
);
1671 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
1675 if (*mode
!= DRXK_POWER_DOWN_OFDM
) {
1676 state
->m_hi_cfg_ctrl
|=
1677 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
1678 status
= hi_cfg_command(state
);
1683 state
->m_current_power_mode
= *mode
;
1687 pr_err("Error %d on %s\n", status
, __func__
);
1692 static int power_down_dvbt(struct drxk_state
*state
, bool set_power_mode
)
1694 enum drx_power_mode power_mode
= DRXK_POWER_DOWN_OFDM
;
1701 status
= read16(state
, SCU_COMM_EXEC__A
, &data
);
1704 if (data
== SCU_COMM_EXEC_ACTIVE
) {
1705 /* Send OFDM stop command */
1706 status
= scu_command(state
,
1707 SCU_RAM_COMMAND_STANDARD_OFDM
1708 | SCU_RAM_COMMAND_CMD_DEMOD_STOP
,
1709 0, NULL
, 1, &cmd_result
);
1712 /* Send OFDM reset command */
1713 status
= scu_command(state
,
1714 SCU_RAM_COMMAND_STANDARD_OFDM
1715 | SCU_RAM_COMMAND_CMD_DEMOD_RESET
,
1716 0, NULL
, 1, &cmd_result
);
1721 /* Reset datapath for OFDM, processors first */
1722 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
1725 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
1728 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
1733 status
= set_iqm_af(state
, false);
1737 /* powerdown to OFDM mode */
1738 if (set_power_mode
) {
1739 status
= ctrl_power_mode(state
, &power_mode
);
1745 pr_err("Error %d on %s\n", status
, __func__
);
1749 static int setoperation_mode(struct drxk_state
*state
,
1750 enum operation_mode o_mode
)
1756 Stop and power down previous standard
1757 TODO investigate total power down instead of partial
1758 power down depending on "previous" standard.
1761 /* disable HW lock indicator */
1762 status
= write16(state
, SCU_RAM_GPIO__A
,
1763 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
1767 /* Device is already at the required mode */
1768 if (state
->m_operation_mode
== o_mode
)
1771 switch (state
->m_operation_mode
) {
1772 /* OM_NONE was added for start up */
1776 status
= mpegts_stop(state
);
1779 status
= power_down_dvbt(state
, true);
1782 state
->m_operation_mode
= OM_NONE
;
1784 case OM_QAM_ITU_A
: /* fallthrough */
1786 status
= mpegts_stop(state
);
1789 status
= power_down_qam(state
);
1792 state
->m_operation_mode
= OM_NONE
;
1801 Power up new standard
1805 dprintk(1, ": DVB-T\n");
1806 state
->m_operation_mode
= o_mode
;
1807 status
= set_dvbt_standard(state
, o_mode
);
1811 case OM_QAM_ITU_A
: /* fallthrough */
1813 dprintk(1, ": DVB-C Annex %c\n",
1814 (state
->m_operation_mode
== OM_QAM_ITU_A
) ? 'A' : 'C');
1815 state
->m_operation_mode
= o_mode
;
1816 status
= set_qam_standard(state
, o_mode
);
1826 pr_err("Error %d on %s\n", status
, __func__
);
1830 static int start(struct drxk_state
*state
, s32 offset_freq
,
1831 s32 intermediate_frequency
)
1833 int status
= -EINVAL
;
1836 s32 offsetk_hz
= offset_freq
/ 1000;
1839 if (state
->m_drxk_state
!= DRXK_STOPPED
&&
1840 state
->m_drxk_state
!= DRXK_DTV_STARTED
)
1843 state
->m_b_mirror_freq_spect
= (state
->props
.inversion
== INVERSION_ON
);
1845 if (intermediate_frequency
< 0) {
1846 state
->m_b_mirror_freq_spect
= !state
->m_b_mirror_freq_spect
;
1847 intermediate_frequency
= -intermediate_frequency
;
1850 switch (state
->m_operation_mode
) {
1853 i_freqk_hz
= (intermediate_frequency
/ 1000);
1854 status
= set_qam(state
, i_freqk_hz
, offsetk_hz
);
1857 state
->m_drxk_state
= DRXK_DTV_STARTED
;
1860 i_freqk_hz
= (intermediate_frequency
/ 1000);
1861 status
= mpegts_stop(state
);
1864 status
= set_dvbt(state
, i_freqk_hz
, offsetk_hz
);
1867 status
= dvbt_start(state
);
1870 state
->m_drxk_state
= DRXK_DTV_STARTED
;
1877 pr_err("Error %d on %s\n", status
, __func__
);
1881 static int shut_down(struct drxk_state
*state
)
1889 static int get_lock_status(struct drxk_state
*state
, u32
*p_lock_status
)
1891 int status
= -EINVAL
;
1895 if (p_lock_status
== NULL
)
1898 *p_lock_status
= NOT_LOCKED
;
1900 /* define the SCU command code */
1901 switch (state
->m_operation_mode
) {
1905 status
= get_qam_lock_status(state
, p_lock_status
);
1908 status
= get_dvbt_lock_status(state
, p_lock_status
);
1915 pr_err("Error %d on %s\n", status
, __func__
);
1919 static int mpegts_start(struct drxk_state
*state
)
1923 u16 fec_oc_snc_mode
= 0;
1925 /* Allow OC to sync again */
1926 status
= read16(state
, FEC_OC_SNC_MODE__A
, &fec_oc_snc_mode
);
1929 fec_oc_snc_mode
&= ~FEC_OC_SNC_MODE_SHUTDOWN__M
;
1930 status
= write16(state
, FEC_OC_SNC_MODE__A
, fec_oc_snc_mode
);
1933 status
= write16(state
, FEC_OC_SNC_UNLOCK__A
, 1);
1936 pr_err("Error %d on %s\n", status
, __func__
);
1940 static int mpegts_dto_init(struct drxk_state
*state
)
1946 /* Rate integration settings */
1947 status
= write16(state
, FEC_OC_RCN_CTL_STEP_LO__A
, 0x0000);
1950 status
= write16(state
, FEC_OC_RCN_CTL_STEP_HI__A
, 0x000C);
1953 status
= write16(state
, FEC_OC_RCN_GAIN__A
, 0x000A);
1956 status
= write16(state
, FEC_OC_AVR_PARM_A__A
, 0x0008);
1959 status
= write16(state
, FEC_OC_AVR_PARM_B__A
, 0x0006);
1962 status
= write16(state
, FEC_OC_TMD_HI_MARGIN__A
, 0x0680);
1965 status
= write16(state
, FEC_OC_TMD_LO_MARGIN__A
, 0x0080);
1968 status
= write16(state
, FEC_OC_TMD_COUNT__A
, 0x03F4);
1972 /* Additional configuration */
1973 status
= write16(state
, FEC_OC_OCR_INVERT__A
, 0);
1976 status
= write16(state
, FEC_OC_SNC_LWM__A
, 2);
1979 status
= write16(state
, FEC_OC_SNC_HWM__A
, 12);
1982 pr_err("Error %d on %s\n", status
, __func__
);
1987 static int mpegts_dto_setup(struct drxk_state
*state
,
1988 enum operation_mode o_mode
)
1992 u16 fec_oc_reg_mode
= 0; /* FEC_OC_MODE register value */
1993 u16 fec_oc_reg_ipr_mode
= 0; /* FEC_OC_IPR_MODE register value */
1994 u16 fec_oc_dto_mode
= 0; /* FEC_OC_IPR_INVERT register value */
1995 u16 fec_oc_fct_mode
= 0; /* FEC_OC_IPR_INVERT register value */
1996 u16 fec_oc_dto_period
= 2; /* FEC_OC_IPR_INVERT register value */
1997 u16 fec_oc_dto_burst_len
= 188; /* FEC_OC_IPR_INVERT register value */
1998 u32 fec_oc_rcn_ctl_rate
= 0; /* FEC_OC_IPR_INVERT register value */
1999 u16 fec_oc_tmd_mode
= 0;
2000 u16 fec_oc_tmd_int_upd_rate
= 0;
2001 u32 max_bit_rate
= 0;
2002 bool static_clk
= false;
2006 /* Check insertion of the Reed-Solomon parity bytes */
2007 status
= read16(state
, FEC_OC_MODE__A
, &fec_oc_reg_mode
);
2010 status
= read16(state
, FEC_OC_IPR_MODE__A
, &fec_oc_reg_ipr_mode
);
2013 fec_oc_reg_mode
&= (~FEC_OC_MODE_PARITY__M
);
2014 fec_oc_reg_ipr_mode
&= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M
);
2015 if (state
->m_insert_rs_byte
== true) {
2016 /* enable parity symbol forward */
2017 fec_oc_reg_mode
|= FEC_OC_MODE_PARITY__M
;
2018 /* MVAL disable during parity bytes */
2019 fec_oc_reg_ipr_mode
|= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M
;
2020 /* TS burst length to 204 */
2021 fec_oc_dto_burst_len
= 204;
2024 /* Check serial or parrallel output */
2025 fec_oc_reg_ipr_mode
&= (~(FEC_OC_IPR_MODE_SERIAL__M
));
2026 if (state
->m_enable_parallel
== false) {
2027 /* MPEG data output is serial -> set ipr_mode[0] */
2028 fec_oc_reg_ipr_mode
|= FEC_OC_IPR_MODE_SERIAL__M
;
2033 max_bit_rate
= state
->m_dvbt_bitrate
;
2034 fec_oc_tmd_mode
= 3;
2035 fec_oc_rcn_ctl_rate
= 0xC00000;
2036 static_clk
= state
->m_dvbt_static_clk
;
2038 case OM_QAM_ITU_A
: /* fallthrough */
2040 fec_oc_tmd_mode
= 0x0004;
2041 fec_oc_rcn_ctl_rate
= 0xD2B4EE; /* good for >63 Mb/s */
2042 max_bit_rate
= state
->m_dvbc_bitrate
;
2043 static_clk
= state
->m_dvbc_static_clk
;
2047 } /* switch (standard) */
2051 /* Configure DTO's */
2055 /* Rational DTO for MCLK source (static MCLK rate),
2056 Dynamic DTO for optimal grouping
2057 (avoid intra-packet gaps),
2058 DTO offset enable to sync TS burst with MSTRT */
2059 fec_oc_dto_mode
= (FEC_OC_DTO_MODE_DYNAMIC__M
|
2060 FEC_OC_DTO_MODE_OFFSET_ENABLE__M
);
2061 fec_oc_fct_mode
= (FEC_OC_FCT_MODE_RAT_ENA__M
|
2062 FEC_OC_FCT_MODE_VIRT_ENA__M
);
2064 /* Check user defined bitrate */
2065 bit_rate
= max_bit_rate
;
2066 if (bit_rate
> 75900000UL) { /* max is 75.9 Mb/s */
2067 bit_rate
= 75900000UL;
2069 /* Rational DTO period:
2070 dto_period = (Fsys / bitrate) - 2
2072 result should be floored,
2073 to make sure >= requested bitrate
2075 fec_oc_dto_period
= (u16
) (((state
->m_sys_clock_freq
)
2076 * 1000) / bit_rate
);
2077 if (fec_oc_dto_period
<= 2)
2078 fec_oc_dto_period
= 0;
2080 fec_oc_dto_period
-= 2;
2081 fec_oc_tmd_int_upd_rate
= 8;
2083 /* (commonAttr->static_clk == false) => dynamic mode */
2084 fec_oc_dto_mode
= FEC_OC_DTO_MODE_DYNAMIC__M
;
2085 fec_oc_fct_mode
= FEC_OC_FCT_MODE__PRE
;
2086 fec_oc_tmd_int_upd_rate
= 5;
2089 /* Write appropriate registers with requested configuration */
2090 status
= write16(state
, FEC_OC_DTO_BURST_LEN__A
, fec_oc_dto_burst_len
);
2093 status
= write16(state
, FEC_OC_DTO_PERIOD__A
, fec_oc_dto_period
);
2096 status
= write16(state
, FEC_OC_DTO_MODE__A
, fec_oc_dto_mode
);
2099 status
= write16(state
, FEC_OC_FCT_MODE__A
, fec_oc_fct_mode
);
2102 status
= write16(state
, FEC_OC_MODE__A
, fec_oc_reg_mode
);
2105 status
= write16(state
, FEC_OC_IPR_MODE__A
, fec_oc_reg_ipr_mode
);
2109 /* Rate integration settings */
2110 status
= write32(state
, FEC_OC_RCN_CTL_RATE_LO__A
, fec_oc_rcn_ctl_rate
);
2113 status
= write16(state
, FEC_OC_TMD_INT_UPD_RATE__A
,
2114 fec_oc_tmd_int_upd_rate
);
2117 status
= write16(state
, FEC_OC_TMD_MODE__A
, fec_oc_tmd_mode
);
2120 pr_err("Error %d on %s\n", status
, __func__
);
2124 static int mpegts_configure_polarity(struct drxk_state
*state
)
2126 u16 fec_oc_reg_ipr_invert
= 0;
2128 /* Data mask for the output data byte */
2129 u16 invert_data_mask
=
2130 FEC_OC_IPR_INVERT_MD7__M
| FEC_OC_IPR_INVERT_MD6__M
|
2131 FEC_OC_IPR_INVERT_MD5__M
| FEC_OC_IPR_INVERT_MD4__M
|
2132 FEC_OC_IPR_INVERT_MD3__M
| FEC_OC_IPR_INVERT_MD2__M
|
2133 FEC_OC_IPR_INVERT_MD1__M
| FEC_OC_IPR_INVERT_MD0__M
;
2137 /* Control selective inversion of output bits */
2138 fec_oc_reg_ipr_invert
&= (~(invert_data_mask
));
2139 if (state
->m_invert_data
== true)
2140 fec_oc_reg_ipr_invert
|= invert_data_mask
;
2141 fec_oc_reg_ipr_invert
&= (~(FEC_OC_IPR_INVERT_MERR__M
));
2142 if (state
->m_invert_err
== true)
2143 fec_oc_reg_ipr_invert
|= FEC_OC_IPR_INVERT_MERR__M
;
2144 fec_oc_reg_ipr_invert
&= (~(FEC_OC_IPR_INVERT_MSTRT__M
));
2145 if (state
->m_invert_str
== true)
2146 fec_oc_reg_ipr_invert
|= FEC_OC_IPR_INVERT_MSTRT__M
;
2147 fec_oc_reg_ipr_invert
&= (~(FEC_OC_IPR_INVERT_MVAL__M
));
2148 if (state
->m_invert_val
== true)
2149 fec_oc_reg_ipr_invert
|= FEC_OC_IPR_INVERT_MVAL__M
;
2150 fec_oc_reg_ipr_invert
&= (~(FEC_OC_IPR_INVERT_MCLK__M
));
2151 if (state
->m_invert_clk
== true)
2152 fec_oc_reg_ipr_invert
|= FEC_OC_IPR_INVERT_MCLK__M
;
2154 return write16(state
, FEC_OC_IPR_INVERT__A
, fec_oc_reg_ipr_invert
);
2157 #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000
2159 static int set_agc_rf(struct drxk_state
*state
,
2160 struct s_cfg_agc
*p_agc_cfg
, bool is_dtv
)
2162 int status
= -EINVAL
;
2164 struct s_cfg_agc
*p_if_agc_settings
;
2168 if (p_agc_cfg
== NULL
)
2171 switch (p_agc_cfg
->ctrl_mode
) {
2172 case DRXK_AGC_CTRL_AUTO
:
2173 /* Enable RF AGC DAC */
2174 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2177 data
&= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2178 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2181 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2185 /* Enable SCU RF AGC loop */
2186 data
&= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2189 if (state
->m_rf_agc_pol
)
2190 data
|= SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2192 data
&= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2193 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2197 /* Set speed (using complementary reduction value) */
2198 status
= read16(state
, SCU_RAM_AGC_KI_RED__A
, &data
);
2202 data
&= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M
;
2203 data
|= (~(p_agc_cfg
->speed
<<
2204 SCU_RAM_AGC_KI_RED_RAGC_RED__B
)
2205 & SCU_RAM_AGC_KI_RED_RAGC_RED__M
);
2207 status
= write16(state
, SCU_RAM_AGC_KI_RED__A
, data
);
2212 p_if_agc_settings
= &state
->m_dvbt_if_agc_cfg
;
2213 else if (is_qam(state
))
2214 p_if_agc_settings
= &state
->m_qam_if_agc_cfg
;
2216 p_if_agc_settings
= &state
->m_atv_if_agc_cfg
;
2217 if (p_if_agc_settings
== NULL
) {
2222 /* Set TOP, only if IF-AGC is in AUTO mode */
2223 if (p_if_agc_settings
->ctrl_mode
== DRXK_AGC_CTRL_AUTO
)
2224 status
= write16(state
,
2225 SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
,
2230 /* Cut-Off current */
2231 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI_CO__A
,
2232 p_agc_cfg
->cut_off_current
);
2236 /* Max. output level */
2237 status
= write16(state
, SCU_RAM_AGC_RF_MAX__A
,
2238 p_agc_cfg
->max_output_level
);
2244 case DRXK_AGC_CTRL_USER
:
2245 /* Enable RF AGC DAC */
2246 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2249 data
&= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2250 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2254 /* Disable SCU RF AGC loop */
2255 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2258 data
|= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2259 if (state
->m_rf_agc_pol
)
2260 data
|= SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2262 data
&= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2263 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2267 /* SCU c.o.c. to 0, enabling full control range */
2268 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI_CO__A
, 0);
2272 /* Write value to output pin */
2273 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI__A
,
2274 p_agc_cfg
->output_level
);
2279 case DRXK_AGC_CTRL_OFF
:
2280 /* Disable RF AGC DAC */
2281 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2284 data
|= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2285 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2289 /* Disable SCU RF AGC loop */
2290 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2293 data
|= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2294 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2305 pr_err("Error %d on %s\n", status
, __func__
);
2309 #define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000
2311 static int set_agc_if(struct drxk_state
*state
,
2312 struct s_cfg_agc
*p_agc_cfg
, bool is_dtv
)
2316 struct s_cfg_agc
*p_rf_agc_settings
;
2320 switch (p_agc_cfg
->ctrl_mode
) {
2321 case DRXK_AGC_CTRL_AUTO
:
2323 /* Enable IF AGC DAC */
2324 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2327 data
&= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2328 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2332 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2336 /* Enable SCU IF AGC loop */
2337 data
&= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2340 if (state
->m_if_agc_pol
)
2341 data
|= SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2343 data
&= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2344 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2348 /* Set speed (using complementary reduction value) */
2349 status
= read16(state
, SCU_RAM_AGC_KI_RED__A
, &data
);
2352 data
&= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M
;
2353 data
|= (~(p_agc_cfg
->speed
<<
2354 SCU_RAM_AGC_KI_RED_IAGC_RED__B
)
2355 & SCU_RAM_AGC_KI_RED_IAGC_RED__M
);
2357 status
= write16(state
, SCU_RAM_AGC_KI_RED__A
, data
);
2362 p_rf_agc_settings
= &state
->m_qam_rf_agc_cfg
;
2364 p_rf_agc_settings
= &state
->m_atv_rf_agc_cfg
;
2365 if (p_rf_agc_settings
== NULL
)
2368 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
,
2369 p_rf_agc_settings
->top
);
2374 case DRXK_AGC_CTRL_USER
:
2376 /* Enable IF AGC DAC */
2377 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2380 data
&= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2381 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2385 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2389 /* Disable SCU IF AGC loop */
2390 data
|= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2393 if (state
->m_if_agc_pol
)
2394 data
|= SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2396 data
&= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2397 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2401 /* Write value to output pin */
2402 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
,
2403 p_agc_cfg
->output_level
);
2408 case DRXK_AGC_CTRL_OFF
:
2410 /* Disable If AGC DAC */
2411 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2414 data
|= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2415 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2419 /* Disable SCU IF AGC loop */
2420 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2423 data
|= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2424 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2428 } /* switch (agcSettingsIf->ctrl_mode) */
2430 /* always set the top to support
2431 configurations without if-loop */
2432 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MIN__A
, p_agc_cfg
->top
);
2435 pr_err("Error %d on %s\n", status
, __func__
);
2439 static int get_qam_signal_to_noise(struct drxk_state
*state
,
2440 s32
*p_signal_to_noise
)
2443 u16 qam_sl_err_power
= 0; /* accum. error between
2444 raw and sliced symbols */
2445 u32 qam_sl_sig_power
= 0; /* used for MER, depends of
2447 u32 qam_sl_mer
= 0; /* QAM MER */
2451 /* MER calculation */
2453 /* get the register value needed for MER */
2454 status
= read16(state
, QAM_SL_ERR_POWER__A
, &qam_sl_err_power
);
2456 pr_err("Error %d on %s\n", status
, __func__
);
2460 switch (state
->props
.modulation
) {
2462 qam_sl_sig_power
= DRXK_QAM_SL_SIG_POWER_QAM16
<< 2;
2465 qam_sl_sig_power
= DRXK_QAM_SL_SIG_POWER_QAM32
<< 2;
2468 qam_sl_sig_power
= DRXK_QAM_SL_SIG_POWER_QAM64
<< 2;
2471 qam_sl_sig_power
= DRXK_QAM_SL_SIG_POWER_QAM128
<< 2;
2475 qam_sl_sig_power
= DRXK_QAM_SL_SIG_POWER_QAM256
<< 2;
2479 if (qam_sl_err_power
> 0) {
2480 qam_sl_mer
= log10times100(qam_sl_sig_power
) -
2481 log10times100((u32
) qam_sl_err_power
);
2483 *p_signal_to_noise
= qam_sl_mer
;
2488 static int get_dvbt_signal_to_noise(struct drxk_state
*state
,
2489 s32
*p_signal_to_noise
)
2493 u32 eq_reg_td_sqr_err_i
= 0;
2494 u32 eq_reg_td_sqr_err_q
= 0;
2495 u16 eq_reg_td_sqr_err_exp
= 0;
2496 u16 eq_reg_td_tps_pwr_ofs
= 0;
2497 u16 eq_reg_td_req_smb_cnt
= 0;
2504 u16 transmission_params
= 0;
2508 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A
,
2509 &eq_reg_td_tps_pwr_ofs
);
2512 status
= read16(state
, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A
,
2513 &eq_reg_td_req_smb_cnt
);
2516 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A
,
2517 &eq_reg_td_sqr_err_exp
);
2520 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_I__A
,
2524 /* Extend SQR_ERR_I operational range */
2525 eq_reg_td_sqr_err_i
= (u32
) reg_data
;
2526 if ((eq_reg_td_sqr_err_exp
> 11) &&
2527 (eq_reg_td_sqr_err_i
< 0x00000FFFUL
)) {
2528 eq_reg_td_sqr_err_i
+= 0x00010000UL
;
2530 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_Q__A
, ®_data
);
2533 /* Extend SQR_ERR_Q operational range */
2534 eq_reg_td_sqr_err_q
= (u32
) reg_data
;
2535 if ((eq_reg_td_sqr_err_exp
> 11) &&
2536 (eq_reg_td_sqr_err_q
< 0x00000FFFUL
))
2537 eq_reg_td_sqr_err_q
+= 0x00010000UL
;
2539 status
= read16(state
, OFDM_SC_RA_RAM_OP_PARAM__A
,
2540 &transmission_params
);
2544 /* Check input data for MER */
2546 /* MER calculation (in 0.1 dB) without math.h */
2547 if ((eq_reg_td_tps_pwr_ofs
== 0) || (eq_reg_td_req_smb_cnt
== 0))
2549 else if ((eq_reg_td_sqr_err_i
+ eq_reg_td_sqr_err_q
) == 0) {
2550 /* No error at all, this must be the HW reset value
2551 * Apparently no first measurement yet
2555 sqr_err_iq
= (eq_reg_td_sqr_err_i
+ eq_reg_td_sqr_err_q
) <<
2556 eq_reg_td_sqr_err_exp
;
2557 if ((transmission_params
&
2558 OFDM_SC_RA_RAM_OP_PARAM_MODE__M
)
2559 == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K
)
2564 /* IMER = 100 * log10 (x)
2565 where x = (eq_reg_td_tps_pwr_ofs^2 *
2566 eq_reg_td_req_smb_cnt * tps_cnt)/sqr_err_iq
2569 where a = 100 * log10 (eq_reg_td_tps_pwr_ofs^2)
2570 b = 100 * log10 (eq_reg_td_req_smb_cnt * tps_cnt)
2571 c = 100 * log10 (sqr_err_iq)
2574 /* log(x) x = 9bits * 9bits->18 bits */
2575 a
= log10times100(eq_reg_td_tps_pwr_ofs
*
2576 eq_reg_td_tps_pwr_ofs
);
2577 /* log(x) x = 16bits * 7bits->23 bits */
2578 b
= log10times100(eq_reg_td_req_smb_cnt
* tps_cnt
);
2579 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */
2580 c
= log10times100(sqr_err_iq
);
2584 *p_signal_to_noise
= i_mer
;
2588 pr_err("Error %d on %s\n", status
, __func__
);
2592 static int get_signal_to_noise(struct drxk_state
*state
, s32
*p_signal_to_noise
)
2596 *p_signal_to_noise
= 0;
2597 switch (state
->m_operation_mode
) {
2599 return get_dvbt_signal_to_noise(state
, p_signal_to_noise
);
2602 return get_qam_signal_to_noise(state
, p_signal_to_noise
);
2610 static int get_dvbt_quality(struct drxk_state
*state
, s32
*p_quality
)
2612 /* SNR Values for quasi errorfree reception rom Nordig 2.2 */
2617 static s32 QE_SN
[] = {
2623 108, /* 16-QAM 1/2 */
2624 131, /* 16-QAM 2/3 */
2625 146, /* 16-QAM 3/4 */
2626 156, /* 16-QAM 5/6 */
2627 160, /* 16-QAM 7/8 */
2628 165, /* 64-QAM 1/2 */
2629 187, /* 64-QAM 2/3 */
2630 202, /* 64-QAM 3/4 */
2631 216, /* 64-QAM 5/6 */
2632 225, /* 64-QAM 7/8 */
2638 s32 signal_to_noise
= 0;
2639 u16 constellation
= 0;
2641 u32 signal_to_noise_rel
;
2644 status
= get_dvbt_signal_to_noise(state
, &signal_to_noise
);
2647 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_CONST__A
,
2651 constellation
&= OFDM_EQ_TOP_TD_TPS_CONST__M
;
2653 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_CODE_HP__A
,
2657 code_rate
&= OFDM_EQ_TOP_TD_TPS_CODE_HP__M
;
2659 if (constellation
> OFDM_EQ_TOP_TD_TPS_CONST_64QAM
||
2660 code_rate
> OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8
)
2662 signal_to_noise_rel
= signal_to_noise
-
2663 QE_SN
[constellation
* 5 + code_rate
];
2666 if (signal_to_noise_rel
< -70)
2668 else if (signal_to_noise_rel
< 30)
2669 *p_quality
= ((signal_to_noise_rel
+ 70) *
2672 *p_quality
= ber_quality
;
2677 static int get_dvbc_quality(struct drxk_state
*state
, s32
*p_quality
)
2685 u32 signal_to_noise
= 0;
2686 u32 ber_quality
= 100;
2687 u32 signal_to_noise_rel
= 0;
2689 status
= get_qam_signal_to_noise(state
, &signal_to_noise
);
2693 switch (state
->props
.modulation
) {
2695 signal_to_noise_rel
= signal_to_noise
- 200;
2698 signal_to_noise_rel
= signal_to_noise
- 230;
2699 break; /* Not in NorDig */
2701 signal_to_noise_rel
= signal_to_noise
- 260;
2704 signal_to_noise_rel
= signal_to_noise
- 290;
2708 signal_to_noise_rel
= signal_to_noise
- 320;
2712 if (signal_to_noise_rel
< -70)
2714 else if (signal_to_noise_rel
< 30)
2715 *p_quality
= ((signal_to_noise_rel
+ 70) *
2718 *p_quality
= ber_quality
;
2724 static int get_quality(struct drxk_state
*state
, s32
*p_quality
)
2728 switch (state
->m_operation_mode
) {
2730 return get_dvbt_quality(state
, p_quality
);
2732 return get_dvbc_quality(state
, p_quality
);
2741 /* Free data ram in SIO HI */
2742 #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040
2743 #define SIO_HI_RA_RAM_USR_END__A 0x420060
2745 #define DRXK_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A)
2746 #define DRXK_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7)
2747 #define DRXK_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ
2748 #define DRXK_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE
2750 #define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr) >> 22) & 0x3F)
2751 #define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F)
2752 #define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF)
2754 static int ConfigureI2CBridge(struct drxk_state
*state
, bool b_enable_bridge
)
2756 int status
= -EINVAL
;
2760 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
2762 if (state
->m_drxk_state
== DRXK_POWERED_DOWN
)
2765 if (state
->no_i2c_bridge
)
2768 status
= write16(state
, SIO_HI_RA_RAM_PAR_1__A
,
2769 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY
);
2772 if (b_enable_bridge
) {
2773 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
,
2774 SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED
);
2778 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
,
2779 SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN
);
2784 status
= hi_command(state
, SIO_HI_RA_RAM_CMD_BRDCTRL
, 0);
2788 pr_err("Error %d on %s\n", status
, __func__
);
2792 static int set_pre_saw(struct drxk_state
*state
,
2793 struct s_cfg_pre_saw
*p_pre_saw_cfg
)
2795 int status
= -EINVAL
;
2799 if ((p_pre_saw_cfg
== NULL
)
2800 || (p_pre_saw_cfg
->reference
> IQM_AF_PDREF__M
))
2803 status
= write16(state
, IQM_AF_PDREF__A
, p_pre_saw_cfg
->reference
);
2806 pr_err("Error %d on %s\n", status
, __func__
);
2810 static int bl_direct_cmd(struct drxk_state
*state
, u32 target_addr
,
2811 u16 rom_offset
, u16 nr_of_elements
, u32 time_out
)
2814 u16 offset
= (u16
) ((target_addr
>> 0) & 0x00FFFF);
2815 u16 blockbank
= (u16
) ((target_addr
>> 16) & 0x000FFF);
2821 mutex_lock(&state
->mutex
);
2822 status
= write16(state
, SIO_BL_MODE__A
, SIO_BL_MODE_DIRECT
);
2825 status
= write16(state
, SIO_BL_TGT_HDR__A
, blockbank
);
2828 status
= write16(state
, SIO_BL_TGT_ADDR__A
, offset
);
2831 status
= write16(state
, SIO_BL_SRC_ADDR__A
, rom_offset
);
2834 status
= write16(state
, SIO_BL_SRC_LEN__A
, nr_of_elements
);
2837 status
= write16(state
, SIO_BL_ENABLE__A
, SIO_BL_ENABLE_ON
);
2841 end
= jiffies
+ msecs_to_jiffies(time_out
);
2843 status
= read16(state
, SIO_BL_STATUS__A
, &bl_status
);
2846 } while ((bl_status
== 0x1) && time_is_after_jiffies(end
));
2847 if (bl_status
== 0x1) {
2848 pr_err("SIO not ready\n");
2854 pr_err("Error %d on %s\n", status
, __func__
);
2856 mutex_unlock(&state
->mutex
);
2861 static int adc_sync_measurement(struct drxk_state
*state
, u16
*count
)
2868 /* start measurement */
2869 status
= write16(state
, IQM_AF_COMM_EXEC__A
, IQM_AF_COMM_EXEC_ACTIVE
);
2872 status
= write16(state
, IQM_AF_START_LOCK__A
, 1);
2877 status
= read16(state
, IQM_AF_PHASE0__A
, &data
);
2881 *count
= *count
+ 1;
2882 status
= read16(state
, IQM_AF_PHASE1__A
, &data
);
2886 *count
= *count
+ 1;
2887 status
= read16(state
, IQM_AF_PHASE2__A
, &data
);
2891 *count
= *count
+ 1;
2895 pr_err("Error %d on %s\n", status
, __func__
);
2899 static int adc_synchronization(struct drxk_state
*state
)
2906 status
= adc_sync_measurement(state
, &count
);
2911 /* Try sampling on a diffrent edge */
2914 status
= read16(state
, IQM_AF_CLKNEG__A
, &clk_neg
);
2917 if ((clk_neg
& IQM_AF_CLKNEG_CLKNEGDATA__M
) ==
2918 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS
) {
2919 clk_neg
&= (~(IQM_AF_CLKNEG_CLKNEGDATA__M
));
2921 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG
;
2923 clk_neg
&= (~(IQM_AF_CLKNEG_CLKNEGDATA__M
));
2925 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS
;
2927 status
= write16(state
, IQM_AF_CLKNEG__A
, clk_neg
);
2930 status
= adc_sync_measurement(state
, &count
);
2939 pr_err("Error %d on %s\n", status
, __func__
);
2943 static int set_frequency_shifter(struct drxk_state
*state
,
2944 u16 intermediate_freqk_hz
,
2945 s32 tuner_freq_offset
, bool is_dtv
)
2947 bool select_pos_image
= false;
2948 u32 rf_freq_residual
= tuner_freq_offset
;
2949 u32 fm_frequency_shift
= 0;
2950 bool tuner_mirror
= !state
->m_b_mirror_freq_spect
;
2955 u32 sampling_frequency
= (u32
) (state
->m_sys_clock_freq
/ 3);
2956 u32 frequency_shift
;
2957 bool image_to_select
;
2962 Program frequency shifter
2963 No need to account for mirroring on RF
2966 if ((state
->m_operation_mode
== OM_QAM_ITU_A
) ||
2967 (state
->m_operation_mode
== OM_QAM_ITU_C
) ||
2968 (state
->m_operation_mode
== OM_DVBT
))
2969 select_pos_image
= true;
2971 select_pos_image
= false;
2974 /* tuner doesn't mirror */
2975 if_freq_actual
= intermediate_freqk_hz
+
2976 rf_freq_residual
+ fm_frequency_shift
;
2979 if_freq_actual
= intermediate_freqk_hz
-
2980 rf_freq_residual
- fm_frequency_shift
;
2981 if (if_freq_actual
> sampling_frequency
/ 2) {
2983 adc_freq
= sampling_frequency
- if_freq_actual
;
2986 /* adc doesn't mirror */
2987 adc_freq
= if_freq_actual
;
2991 frequency_shift
= adc_freq
;
2992 image_to_select
= state
->m_rfmirror
^ tuner_mirror
^
2993 adc_flip
^ select_pos_image
;
2994 state
->m_iqm_fs_rate_ofs
=
2995 Frac28a((frequency_shift
), sampling_frequency
);
2997 if (image_to_select
)
2998 state
->m_iqm_fs_rate_ofs
= ~state
->m_iqm_fs_rate_ofs
+ 1;
3000 /* Program frequency shifter with tuner offset compensation */
3001 /* frequency_shift += tuner_freq_offset; TODO */
3002 status
= write32(state
, IQM_FS_RATE_OFS_LO__A
,
3003 state
->m_iqm_fs_rate_ofs
);
3005 pr_err("Error %d on %s\n", status
, __func__
);
3009 static int init_agc(struct drxk_state
*state
, bool is_dtv
)
3012 u16 ingain_tgt_min
= 0;
3013 u16 ingain_tgt_max
= 0;
3015 u16 clp_sum_min
= 0;
3017 u16 sns_sum_min
= 0;
3018 u16 sns_sum_max
= 0;
3019 u16 clp_sum_max
= 0;
3021 u16 ki_innergain_min
= 0;
3022 u16 if_iaccu_hi_tgt
= 0;
3023 u16 if_iaccu_hi_tgt_min
= 0;
3024 u16 if_iaccu_hi_tgt_max
= 0;
3026 u16 fast_clp_ctrl_delay
= 0;
3027 u16 clp_ctrl_mode
= 0;
3032 /* Common settings */
3034 if_iaccu_hi_tgt_min
= 2047;
3038 /* AGCInit() not available for DVBT; init done in microcode */
3039 if (!is_qam(state
)) {
3040 pr_err("%s: mode %d is not DVB-C\n",
3041 __func__
, state
->m_operation_mode
);
3045 /* FIXME: Analog TV AGC require different settings */
3047 /* Standard specific settings */
3049 clp_dir_to
= (u16
) -9;
3052 sns_dir_to
= (u16
) -9;
3053 ki_innergain_min
= (u16
) -1030;
3054 if_iaccu_hi_tgt_max
= 0x2380;
3055 if_iaccu_hi_tgt
= 0x2380;
3056 ingain_tgt_min
= 0x0511;
3057 ingain_tgt
= 0x0511;
3058 ingain_tgt_max
= 5119;
3059 fast_clp_ctrl_delay
= state
->m_qam_if_agc_cfg
.fast_clip_ctrl_delay
;
3061 status
= write16(state
, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A
,
3062 fast_clp_ctrl_delay
);
3066 status
= write16(state
, SCU_RAM_AGC_CLP_CTRL_MODE__A
, clp_ctrl_mode
);
3069 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT__A
, ingain_tgt
);
3072 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MIN__A
, ingain_tgt_min
);
3075 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MAX__A
, ingain_tgt_max
);
3078 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A
,
3079 if_iaccu_hi_tgt_min
);
3082 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
,
3083 if_iaccu_hi_tgt_max
);
3086 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI__A
, 0);
3089 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_LO__A
, 0);
3092 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI__A
, 0);
3095 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_LO__A
, 0);
3098 status
= write16(state
, SCU_RAM_AGC_CLP_SUM_MAX__A
, clp_sum_max
);
3101 status
= write16(state
, SCU_RAM_AGC_SNS_SUM_MAX__A
, sns_sum_max
);
3105 status
= write16(state
, SCU_RAM_AGC_KI_INNERGAIN_MIN__A
,
3109 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT__A
,
3113 status
= write16(state
, SCU_RAM_AGC_CLP_CYCLEN__A
, clp_cyclen
);
3117 status
= write16(state
, SCU_RAM_AGC_RF_SNS_DEV_MAX__A
, 1023);
3120 status
= write16(state
, SCU_RAM_AGC_RF_SNS_DEV_MIN__A
, (u16
) -1023);
3123 status
= write16(state
, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A
, 50);
3127 status
= write16(state
, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A
, 20);
3130 status
= write16(state
, SCU_RAM_AGC_CLP_SUM_MIN__A
, clp_sum_min
);
3133 status
= write16(state
, SCU_RAM_AGC_SNS_SUM_MIN__A
, sns_sum_min
);
3136 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_TO__A
, clp_dir_to
);
3139 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_TO__A
, sns_dir_to
);
3142 status
= write16(state
, SCU_RAM_AGC_KI_MINGAIN__A
, 0x7fff);
3145 status
= write16(state
, SCU_RAM_AGC_KI_MAXGAIN__A
, 0x0);
3148 status
= write16(state
, SCU_RAM_AGC_KI_MIN__A
, 0x0117);
3151 status
= write16(state
, SCU_RAM_AGC_KI_MAX__A
, 0x0657);
3154 status
= write16(state
, SCU_RAM_AGC_CLP_SUM__A
, 0);
3157 status
= write16(state
, SCU_RAM_AGC_CLP_CYCCNT__A
, 0);
3160 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_WD__A
, 0);
3163 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_STP__A
, 1);
3166 status
= write16(state
, SCU_RAM_AGC_SNS_SUM__A
, 0);
3169 status
= write16(state
, SCU_RAM_AGC_SNS_CYCCNT__A
, 0);
3172 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_WD__A
, 0);
3175 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_STP__A
, 1);
3178 status
= write16(state
, SCU_RAM_AGC_SNS_CYCLEN__A
, 500);
3181 status
= write16(state
, SCU_RAM_AGC_KI_CYCLEN__A
, 500);
3185 /* Initialize inner-loop KI gain factors */
3186 status
= read16(state
, SCU_RAM_AGC_KI__A
, &data
);
3191 data
&= ~SCU_RAM_AGC_KI_RF__M
;
3192 data
|= (DRXK_KI_RAGC_QAM
<< SCU_RAM_AGC_KI_RF__B
);
3193 data
&= ~SCU_RAM_AGC_KI_IF__M
;
3194 data
|= (DRXK_KI_IAGC_QAM
<< SCU_RAM_AGC_KI_IF__B
);
3196 status
= write16(state
, SCU_RAM_AGC_KI__A
, data
);
3199 pr_err("Error %d on %s\n", status
, __func__
);
3203 static int dvbtqam_get_acc_pkt_err(struct drxk_state
*state
, u16
*packet_err
)
3208 if (packet_err
== NULL
)
3209 status
= write16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
, 0);
3211 status
= read16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
,
3214 pr_err("Error %d on %s\n", status
, __func__
);
3218 static int dvbt_sc_command(struct drxk_state
*state
,
3219 u16 cmd
, u16 subcmd
,
3220 u16 param0
, u16 param1
, u16 param2
,
3221 u16 param3
, u16 param4
)
3230 status
= read16(state
, OFDM_SC_COMM_EXEC__A
, &sc_exec
);
3232 /* SC is not running */
3238 /* Wait until sc is ready to receive command */
3241 usleep_range(1000, 2000);
3242 status
= read16(state
, OFDM_SC_RA_RAM_CMD__A
, &cur_cmd
);
3244 } while ((cur_cmd
!= 0) && (retry_cnt
< DRXK_MAX_RETRIES
));
3245 if (retry_cnt
>= DRXK_MAX_RETRIES
&& (status
< 0))
3248 /* Write sub-command */
3250 /* All commands using sub-cmd */
3251 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3252 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3253 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3254 status
= write16(state
, OFDM_SC_RA_RAM_CMD_ADDR__A
, subcmd
);
3263 /* Write needed parameters and the command */
3265 /* All commands using 5 parameters */
3266 /* All commands using 4 parameters */
3267 /* All commands using 3 parameters */
3268 /* All commands using 2 parameters */
3269 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3270 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3271 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3272 status
= write16(state
, OFDM_SC_RA_RAM_PARAM1__A
, param1
);
3273 /* All commands using 1 parameters */
3274 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING
:
3275 case OFDM_SC_RA_RAM_CMD_USER_IO
:
3276 status
= write16(state
, OFDM_SC_RA_RAM_PARAM0__A
, param0
);
3277 /* All commands using 0 parameters */
3278 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM
:
3279 case OFDM_SC_RA_RAM_CMD_NULL
:
3281 status
= write16(state
, OFDM_SC_RA_RAM_CMD__A
, cmd
);
3284 /* Unknown command */
3290 /* Wait until sc is ready processing command */
3293 usleep_range(1000, 2000);
3294 status
= read16(state
, OFDM_SC_RA_RAM_CMD__A
, &cur_cmd
);
3296 } while ((cur_cmd
!= 0) && (retry_cnt
< DRXK_MAX_RETRIES
));
3297 if (retry_cnt
>= DRXK_MAX_RETRIES
&& (status
< 0))
3300 /* Check for illegal cmd */
3301 status
= read16(state
, OFDM_SC_RA_RAM_CMD_ADDR__A
, &err_code
);
3302 if (err_code
== 0xFFFF) {
3303 /* illegal command */
3309 /* Retreive results parameters from SC */
3311 /* All commands yielding 5 results */
3312 /* All commands yielding 4 results */
3313 /* All commands yielding 3 results */
3314 /* All commands yielding 2 results */
3315 /* All commands yielding 1 result */
3316 case OFDM_SC_RA_RAM_CMD_USER_IO
:
3317 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM
:
3318 status
= read16(state
, OFDM_SC_RA_RAM_PARAM0__A
, &(param0
));
3319 /* All commands yielding 0 results */
3320 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING
:
3321 case OFDM_SC_RA_RAM_CMD_SET_TIMER
:
3322 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3323 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3324 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3325 case OFDM_SC_RA_RAM_CMD_NULL
:
3328 /* Unknown command */
3331 } /* switch (cmd->cmd) */
3334 pr_err("Error %d on %s\n", status
, __func__
);
3338 static int power_up_dvbt(struct drxk_state
*state
)
3340 enum drx_power_mode power_mode
= DRX_POWER_UP
;
3344 status
= ctrl_power_mode(state
, &power_mode
);
3346 pr_err("Error %d on %s\n", status
, __func__
);
3350 static int dvbt_ctrl_set_inc_enable(struct drxk_state
*state
, bool *enabled
)
3355 if (*enabled
== true)
3356 status
= write16(state
, IQM_CF_BYPASSDET__A
, 0);
3358 status
= write16(state
, IQM_CF_BYPASSDET__A
, 1);
3360 pr_err("Error %d on %s\n", status
, __func__
);
3364 #define DEFAULT_FR_THRES_8K 4000
3365 static int dvbt_ctrl_set_fr_enable(struct drxk_state
*state
, bool *enabled
)
3371 if (*enabled
== true) {
3372 /* write mask to 1 */
3373 status
= write16(state
, OFDM_SC_RA_RAM_FR_THRES_8K__A
,
3374 DEFAULT_FR_THRES_8K
);
3376 /* write mask to 0 */
3377 status
= write16(state
, OFDM_SC_RA_RAM_FR_THRES_8K__A
, 0);
3380 pr_err("Error %d on %s\n", status
, __func__
);
3385 static int dvbt_ctrl_set_echo_threshold(struct drxk_state
*state
,
3386 struct drxk_cfg_dvbt_echo_thres_t
*echo_thres
)
3392 status
= read16(state
, OFDM_SC_RA_RAM_ECHO_THRES__A
, &data
);
3396 switch (echo_thres
->fft_mode
) {
3397 case DRX_FFTMODE_2K
:
3398 data
&= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M
;
3399 data
|= ((echo_thres
->threshold
<<
3400 OFDM_SC_RA_RAM_ECHO_THRES_2K__B
)
3401 & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M
));
3403 case DRX_FFTMODE_8K
:
3404 data
&= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M
;
3405 data
|= ((echo_thres
->threshold
<<
3406 OFDM_SC_RA_RAM_ECHO_THRES_8K__B
)
3407 & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M
));
3413 status
= write16(state
, OFDM_SC_RA_RAM_ECHO_THRES__A
, data
);
3416 pr_err("Error %d on %s\n", status
, __func__
);
3420 static int dvbt_ctrl_set_sqi_speed(struct drxk_state
*state
,
3421 enum drxk_cfg_dvbt_sqi_speed
*speed
)
3423 int status
= -EINVAL
;
3428 case DRXK_DVBT_SQI_SPEED_FAST
:
3429 case DRXK_DVBT_SQI_SPEED_MEDIUM
:
3430 case DRXK_DVBT_SQI_SPEED_SLOW
:
3435 status
= write16(state
, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A
,
3439 pr_err("Error %d on %s\n", status
, __func__
);
3443 /*============================================================================*/
3446 * \brief Activate DVBT specific presets
3447 * \param demod instance of demodulator.
3448 * \return DRXStatus_t.
3450 * Called in DVBTSetStandard
3453 static int dvbt_activate_presets(struct drxk_state
*state
)
3456 bool setincenable
= false;
3457 bool setfrenable
= true;
3459 struct drxk_cfg_dvbt_echo_thres_t echo_thres2k
= { 0, DRX_FFTMODE_2K
};
3460 struct drxk_cfg_dvbt_echo_thres_t echo_thres8k
= { 0, DRX_FFTMODE_8K
};
3463 status
= dvbt_ctrl_set_inc_enable(state
, &setincenable
);
3466 status
= dvbt_ctrl_set_fr_enable(state
, &setfrenable
);
3469 status
= dvbt_ctrl_set_echo_threshold(state
, &echo_thres2k
);
3472 status
= dvbt_ctrl_set_echo_threshold(state
, &echo_thres8k
);
3475 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MAX__A
,
3476 state
->m_dvbt_if_agc_cfg
.ingain_tgt_max
);
3479 pr_err("Error %d on %s\n", status
, __func__
);
3483 /*============================================================================*/
3486 * \brief Initialize channelswitch-independent settings for DVBT.
3487 * \param demod instance of demodulator.
3488 * \return DRXStatus_t.
3490 * For ROM code channel filter taps are loaded from the bootloader. For microcode
3491 * the DVB-T taps from the drxk_filters.h are used.
3493 static int set_dvbt_standard(struct drxk_state
*state
,
3494 enum operation_mode o_mode
)
3502 power_up_dvbt(state
);
3503 /* added antenna switch */
3504 switch_antenna_to_dvbt(state
);
3505 /* send OFDM reset command */
3506 status
= scu_command(state
,
3507 SCU_RAM_COMMAND_STANDARD_OFDM
3508 | SCU_RAM_COMMAND_CMD_DEMOD_RESET
,
3509 0, NULL
, 1, &cmd_result
);
3513 /* send OFDM setenv command */
3514 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
3515 | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV
,
3516 0, NULL
, 1, &cmd_result
);
3520 /* reset datapath for OFDM, processors first */
3521 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
3524 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
3527 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
3532 /* synchronize on ofdstate->m_festart */
3533 status
= write16(state
, IQM_AF_UPD_SEL__A
, 1);
3536 /* window size for clipping ADC detection */
3537 status
= write16(state
, IQM_AF_CLP_LEN__A
, 0);
3540 /* window size for for sense pre-SAW detection */
3541 status
= write16(state
, IQM_AF_SNS_LEN__A
, 0);
3544 /* sense threshold for sense pre-SAW detection */
3545 status
= write16(state
, IQM_AF_AMUX__A
, IQM_AF_AMUX_SIGNAL2ADC
);
3548 status
= set_iqm_af(state
, true);
3552 status
= write16(state
, IQM_AF_AGC_RF__A
, 0);
3556 /* Impulse noise cruncher setup */
3557 status
= write16(state
, IQM_AF_INC_LCT__A
, 0); /* crunch in IQM_CF */
3560 status
= write16(state
, IQM_CF_DET_LCT__A
, 0); /* detect in IQM_CF */
3563 status
= write16(state
, IQM_CF_WND_LEN__A
, 3); /* peak detector window length */
3567 status
= write16(state
, IQM_RC_STRETCH__A
, 16);
3570 status
= write16(state
, IQM_CF_OUT_ENA__A
, 0x4); /* enable output 2 */
3573 status
= write16(state
, IQM_CF_DS_ENA__A
, 0x4); /* decimate output 2 */
3576 status
= write16(state
, IQM_CF_SCALE__A
, 1600);
3579 status
= write16(state
, IQM_CF_SCALE_SH__A
, 0);
3583 /* virtual clipping threshold for clipping ADC detection */
3584 status
= write16(state
, IQM_AF_CLP_TH__A
, 448);
3587 status
= write16(state
, IQM_CF_DATATH__A
, 495); /* crunching threshold */
3591 status
= bl_chain_cmd(state
, DRXK_BL_ROM_OFFSET_TAPS_DVBT
,
3592 DRXK_BLCC_NR_ELEMENTS_TAPS
, DRXK_BLC_TIMEOUT
);
3596 status
= write16(state
, IQM_CF_PKDTH__A
, 2); /* peak detector threshold */
3599 status
= write16(state
, IQM_CF_POW_MEAS_LEN__A
, 2);
3602 /* enable power measurement interrupt */
3603 status
= write16(state
, IQM_CF_COMM_INT_MSK__A
, 1);
3606 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_ACTIVE
);
3610 /* IQM will not be reset from here, sync ADC and update/init AGC */
3611 status
= adc_synchronization(state
);
3614 status
= set_pre_saw(state
, &state
->m_dvbt_pre_saw_cfg
);
3618 /* Halt SCU to enable safe non-atomic accesses */
3619 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
3623 status
= set_agc_rf(state
, &state
->m_dvbt_rf_agc_cfg
, true);
3626 status
= set_agc_if(state
, &state
->m_dvbt_if_agc_cfg
, true);
3630 /* Set Noise Estimation notch width and enable DC fix */
3631 status
= read16(state
, OFDM_SC_RA_RAM_CONFIG__A
, &data
);
3634 data
|= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M
;
3635 status
= write16(state
, OFDM_SC_RA_RAM_CONFIG__A
, data
);
3639 /* Activate SCU to enable SCU commands */
3640 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
3644 if (!state
->m_drxk_a3_rom_code
) {
3645 /* AGCInit() is not done for DVBT, so set agcfast_clip_ctrl_delay */
3646 status
= write16(state
, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A
,
3647 state
->m_dvbt_if_agc_cfg
.fast_clip_ctrl_delay
);
3653 #ifdef COMPILE_FOR_NONRT
3654 status
= write16(state
, OFDM_SC_RA_RAM_BE_OPT_DELAY__A
, 1);
3657 status
= write16(state
, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A
, 2);
3663 status
= write16(state
, FEC_DI_INPUT_CTL__A
, 1); /* OFDM input */
3668 #ifdef COMPILE_FOR_NONRT
3669 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, 0x400);
3673 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, 0x1000);
3677 status
= write16(state
, FEC_RS_MEASUREMENT_PRESCALE__A
, 0x0001);
3681 /* Setup MPEG bus */
3682 status
= mpegts_dto_setup(state
, OM_DVBT
);
3685 /* Set DVBT Presets */
3686 status
= dvbt_activate_presets(state
);
3692 pr_err("Error %d on %s\n", status
, __func__
);
3696 /*============================================================================*/
3698 * \brief start dvbt demodulating for channel.
3699 * \param demod instance of demodulator.
3700 * \return DRXStatus_t.
3702 static int dvbt_start(struct drxk_state
*state
)
3706 /* drxk_ofdm_sc_cmd_t scCmd; */
3709 /* start correct processes to get in lock */
3710 /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */
3711 param1
= OFDM_SC_RA_RAM_LOCKTRACK_MIN
;
3712 status
= dvbt_sc_command(state
, OFDM_SC_RA_RAM_CMD_PROC_START
, 0,
3713 OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M
, param1
,
3718 status
= mpegts_start(state
);
3721 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_ACTIVE
);
3726 pr_err("Error %d on %s\n", status
, __func__
);
3731 /*============================================================================*/
3734 * \brief Set up dvbt demodulator for channel.
3735 * \param demod instance of demodulator.
3736 * \return DRXStatus_t.
3737 * // original DVBTSetChannel()
3739 static int set_dvbt(struct drxk_state
*state
, u16 intermediate_freqk_hz
,
3740 s32 tuner_freq_offset
)
3743 u16 transmission_params
= 0;
3744 u16 operation_mode
= 0;
3745 u32 iqm_rc_rate_ofs
= 0;
3750 dprintk(1, "IF =%d, TFO = %d\n",
3751 intermediate_freqk_hz
, tuner_freq_offset
);
3753 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
3754 | SCU_RAM_COMMAND_CMD_DEMOD_STOP
,
3755 0, NULL
, 1, &cmd_result
);
3759 /* Halt SCU to enable safe non-atomic accesses */
3760 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
3764 /* Stop processors */
3765 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
3768 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
3772 /* Mandatory fix, always stop CP, required to set spl offset back to
3773 hardware default (is set to 0 by ucode during pilot detection */
3774 status
= write16(state
, OFDM_CP_COMM_EXEC__A
, OFDM_CP_COMM_EXEC_STOP
);
3778 /*== Write channel settings to device ================================*/
3781 switch (state
->props
.transmission_mode
) {
3782 case TRANSMISSION_MODE_AUTO
:
3784 operation_mode
|= OFDM_SC_RA_RAM_OP_AUTO_MODE__M
;
3785 /* fall through , try first guess DRX_FFTMODE_8K */
3786 case TRANSMISSION_MODE_8K
:
3787 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K
;
3789 case TRANSMISSION_MODE_2K
:
3790 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K
;
3795 switch (state
->props
.guard_interval
) {
3797 case GUARD_INTERVAL_AUTO
:
3798 operation_mode
|= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M
;
3799 /* fall through , try first guess DRX_GUARD_1DIV4 */
3800 case GUARD_INTERVAL_1_4
:
3801 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4
;
3803 case GUARD_INTERVAL_1_32
:
3804 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32
;
3806 case GUARD_INTERVAL_1_16
:
3807 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16
;
3809 case GUARD_INTERVAL_1_8
:
3810 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8
;
3815 switch (state
->props
.hierarchy
) {
3816 case HIERARCHY_AUTO
:
3817 case HIERARCHY_NONE
:
3819 operation_mode
|= OFDM_SC_RA_RAM_OP_AUTO_HIER__M
;
3820 /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */
3821 /* transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */
3824 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1
;
3827 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2
;
3830 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4
;
3836 switch (state
->props
.modulation
) {
3839 operation_mode
|= OFDM_SC_RA_RAM_OP_AUTO_CONST__M
;
3840 /* fall through , try first guess DRX_CONSTELLATION_QAM64 */
3842 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64
;
3845 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK
;
3848 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16
;
3852 /* No hierachical channels support in BDA */
3853 /* Priority (only for hierarchical channels) */
3854 switch (channel
->priority
) {
3855 case DRX_PRIORITY_LOW
:
3856 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO
;
3857 WR16(dev_addr
, OFDM_EC_SB_PRIOR__A
,
3858 OFDM_EC_SB_PRIOR_LO
);
3860 case DRX_PRIORITY_HIGH
:
3861 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI
;
3862 WR16(dev_addr
, OFDM_EC_SB_PRIOR__A
,
3863 OFDM_EC_SB_PRIOR_HI
));
3865 case DRX_PRIORITY_UNKNOWN
: /* fall through */
3871 /* Set Priorty high */
3872 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI
;
3873 status
= write16(state
, OFDM_EC_SB_PRIOR__A
, OFDM_EC_SB_PRIOR_HI
);
3879 switch (state
->props
.code_rate_HP
) {
3882 operation_mode
|= OFDM_SC_RA_RAM_OP_AUTO_RATE__M
;
3883 /* fall through , try first guess DRX_CODERATE_2DIV3 */
3885 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3
;
3888 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2
;
3891 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4
;
3894 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6
;
3897 transmission_params
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8
;
3902 * SAW filter selection: normaly not necesarry, but if wanted
3903 * the application can select a SAW filter via the driver by
3907 /* First determine real bandwidth (Hz) */
3908 /* Also set delay for impulse noise cruncher */
3910 * Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is
3911 * changed by SC for fix for some 8K,1/8 guard but is restored by
3912 * InitEC and ResetEC functions
3914 switch (state
->props
.bandwidth_hz
) {
3916 state
->props
.bandwidth_hz
= 8000000;
3919 bandwidth
= DRXK_BANDWIDTH_8MHZ_IN_HZ
;
3920 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
,
3924 /* cochannel protection for PAL 8 MHz */
3925 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
,
3929 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
,
3933 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
,
3937 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
,
3943 bandwidth
= DRXK_BANDWIDTH_7MHZ_IN_HZ
;
3944 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
,
3948 /* cochannel protection for PAL 7 MHz */
3949 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
,
3953 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
,
3957 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
,
3961 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
,
3967 bandwidth
= DRXK_BANDWIDTH_6MHZ_IN_HZ
;
3968 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
,
3972 /* cochannel protection for NTSC 6 MHz */
3973 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
,
3977 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
,
3981 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
,
3985 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
,
3995 if (iqm_rc_rate_ofs
== 0) {
3996 /* Now compute IQM_RC_RATE_OFS
3997 (((SysFreq/BandWidth)/2)/2) -1) * 2^23)
3999 ((SysFreq / BandWidth) * (2^21)) - (2^23)
4001 /* (SysFreq / BandWidth) * (2^28) */
4003 * assert (MAX(sysClk)/MIN(bandwidth) < 16)
4004 * => assert(MAX(sysClk) < 16*MIN(bandwidth))
4005 * => assert(109714272 > 48000000) = true
4006 * so Frac 28 can be used
4008 iqm_rc_rate_ofs
= Frac28a((u32
)
4009 ((state
->m_sys_clock_freq
*
4010 1000) / 3), bandwidth
);
4011 /* (SysFreq / BandWidth) * (2^21), rounding before truncating */
4012 if ((iqm_rc_rate_ofs
& 0x7fL
) >= 0x40)
4013 iqm_rc_rate_ofs
+= 0x80L
;
4014 iqm_rc_rate_ofs
= iqm_rc_rate_ofs
>> 7;
4015 /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */
4016 iqm_rc_rate_ofs
= iqm_rc_rate_ofs
- (1 << 23);
4020 ((((u32
) IQM_RC_RATE_OFS_HI__M
) <<
4021 IQM_RC_RATE_OFS_LO__W
) | IQM_RC_RATE_OFS_LO__M
);
4022 status
= write32(state
, IQM_RC_RATE_OFS_LO__A
, iqm_rc_rate_ofs
);
4026 /* Bandwidth setting done */
4029 status
= dvbt_set_frequency_shift(demod
, channel
, tuner_offset
);
4033 status
= set_frequency_shifter(state
, intermediate_freqk_hz
,
4034 tuner_freq_offset
, true);
4038 /*== start SC, write channel settings to SC ==========================*/
4040 /* Activate SCU to enable SCU commands */
4041 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
4045 /* Enable SC after setting all other parameters */
4046 status
= write16(state
, OFDM_SC_COMM_STATE__A
, 0);
4049 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, 1);
4054 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
4055 | SCU_RAM_COMMAND_CMD_DEMOD_START
,
4056 0, NULL
, 1, &cmd_result
);
4060 /* Write SC parameter registers, set all AUTO flags in operation mode */
4061 param1
= (OFDM_SC_RA_RAM_OP_AUTO_MODE__M
|
4062 OFDM_SC_RA_RAM_OP_AUTO_GUARD__M
|
4063 OFDM_SC_RA_RAM_OP_AUTO_CONST__M
|
4064 OFDM_SC_RA_RAM_OP_AUTO_HIER__M
|
4065 OFDM_SC_RA_RAM_OP_AUTO_RATE__M
);
4066 status
= dvbt_sc_command(state
, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
,
4067 0, transmission_params
, param1
, 0, 0, 0);
4071 if (!state
->m_drxk_a3_rom_code
)
4072 status
= dvbt_ctrl_set_sqi_speed(state
, &state
->m_sqi_speed
);
4075 pr_err("Error %d on %s\n", status
, __func__
);
4081 /*============================================================================*/
4084 * \brief Retreive lock status .
4085 * \param demod Pointer to demodulator instance.
4086 * \param lockStat Pointer to lock status structure.
4087 * \return DRXStatus_t.
4090 static int get_dvbt_lock_status(struct drxk_state
*state
, u32
*p_lock_status
)
4093 const u16 mpeg_lock_mask
= (OFDM_SC_RA_RAM_LOCK_MPEG__M
|
4094 OFDM_SC_RA_RAM_LOCK_FEC__M
);
4095 const u16 fec_lock_mask
= (OFDM_SC_RA_RAM_LOCK_FEC__M
);
4096 const u16 demod_lock_mask
= OFDM_SC_RA_RAM_LOCK_DEMOD__M
;
4098 u16 sc_ra_ram_lock
= 0;
4099 u16 sc_comm_exec
= 0;
4103 *p_lock_status
= NOT_LOCKED
;
4105 /* Check if SC is running */
4106 status
= read16(state
, OFDM_SC_COMM_EXEC__A
, &sc_comm_exec
);
4109 if (sc_comm_exec
== OFDM_SC_COMM_EXEC_STOP
)
4112 status
= read16(state
, OFDM_SC_RA_RAM_LOCK__A
, &sc_ra_ram_lock
);
4116 if ((sc_ra_ram_lock
& mpeg_lock_mask
) == mpeg_lock_mask
)
4117 *p_lock_status
= MPEG_LOCK
;
4118 else if ((sc_ra_ram_lock
& fec_lock_mask
) == fec_lock_mask
)
4119 *p_lock_status
= FEC_LOCK
;
4120 else if ((sc_ra_ram_lock
& demod_lock_mask
) == demod_lock_mask
)
4121 *p_lock_status
= DEMOD_LOCK
;
4122 else if (sc_ra_ram_lock
& OFDM_SC_RA_RAM_LOCK_NODVBT__M
)
4123 *p_lock_status
= NEVER_LOCK
;
4126 pr_err("Error %d on %s\n", status
, __func__
);
4131 static int power_up_qam(struct drxk_state
*state
)
4133 enum drx_power_mode power_mode
= DRXK_POWER_DOWN_OFDM
;
4137 status
= ctrl_power_mode(state
, &power_mode
);
4139 pr_err("Error %d on %s\n", status
, __func__
);
4145 /** Power Down QAM */
4146 static int power_down_qam(struct drxk_state
*state
)
4153 status
= read16(state
, SCU_COMM_EXEC__A
, &data
);
4156 if (data
== SCU_COMM_EXEC_ACTIVE
) {
4161 /* stop all comstate->m_exec */
4162 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_STOP
);
4165 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
4166 | SCU_RAM_COMMAND_CMD_DEMOD_STOP
,
4167 0, NULL
, 1, &cmd_result
);
4172 status
= set_iqm_af(state
, false);
4176 pr_err("Error %d on %s\n", status
, __func__
);
4181 /*============================================================================*/
4184 * \brief Setup of the QAM Measurement intervals for signal quality
4185 * \param demod instance of demod.
4186 * \param modulation current modulation.
4187 * \return DRXStatus_t.
4190 * Take into account that for certain settings the errorcounters can overflow.
4191 * The implementation does not check this.
4194 static int set_qam_measurement(struct drxk_state
*state
,
4195 enum e_drxk_constellation modulation
,
4198 u32 fec_bits_desired
= 0; /* BER accounting period */
4199 u32 fec_rs_period_total
= 0; /* Total period */
4200 u16 fec_rs_prescale
= 0; /* ReedSolomon Measurement Prescale */
4201 u16 fec_rs_period
= 0; /* Value for corresponding I2C register */
4206 fec_rs_prescale
= 1;
4207 /* fec_bits_desired = symbol_rate [kHz] *
4213 switch (modulation
) {
4214 case DRX_CONSTELLATION_QAM16
:
4215 fec_bits_desired
= 4 * symbol_rate
;
4217 case DRX_CONSTELLATION_QAM32
:
4218 fec_bits_desired
= 5 * symbol_rate
;
4220 case DRX_CONSTELLATION_QAM64
:
4221 fec_bits_desired
= 6 * symbol_rate
;
4223 case DRX_CONSTELLATION_QAM128
:
4224 fec_bits_desired
= 7 * symbol_rate
;
4226 case DRX_CONSTELLATION_QAM256
:
4227 fec_bits_desired
= 8 * symbol_rate
;
4235 fec_bits_desired
/= 1000; /* symbol_rate [Hz] -> symbol_rate [kHz] */
4236 fec_bits_desired
*= 500; /* meas. period [ms] */
4238 /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */
4239 /* fec_rs_period_total = fec_bits_desired / 1632 */
4240 fec_rs_period_total
= (fec_bits_desired
/ 1632UL) + 1; /* roughly ceil */
4242 /* fec_rs_period_total = fec_rs_prescale * fec_rs_period */
4243 fec_rs_prescale
= 1 + (u16
) (fec_rs_period_total
>> 16);
4244 if (fec_rs_prescale
== 0) {
4245 /* Divide by zero (though impossible) */
4251 ((u16
) fec_rs_period_total
+
4252 (fec_rs_prescale
>> 1)) / fec_rs_prescale
;
4254 /* write corresponding registers */
4255 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, fec_rs_period
);
4258 status
= write16(state
, FEC_RS_MEASUREMENT_PRESCALE__A
,
4262 status
= write16(state
, FEC_OC_SNC_FAIL_PERIOD__A
, fec_rs_period
);
4265 pr_err("Error %d on %s\n", status
, __func__
);
4269 static int set_qam16(struct drxk_state
*state
)
4274 /* QAM Equalizer Setup */
4276 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 13517);
4279 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 13517);
4282 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 13517);
4285 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 13517);
4288 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13517);
4291 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 13517);
4294 /* Decision Feedback Equalizer */
4295 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 2);
4298 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 2);
4301 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 2);
4304 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 2);
4307 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 2);
4310 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4314 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
4317 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
4320 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4324 /* QAM Slicer Settings */
4325 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
,
4326 DRXK_QAM_SL_SIG_POWER_QAM16
);
4330 /* QAM Loop Controller Coeficients */
4331 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4334 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4337 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4340 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4343 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4346 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4349 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4352 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4356 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4359 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 20);
4362 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 80);
4365 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4368 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 20);
4371 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4374 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4377 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 16);
4380 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 32);
4383 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4386 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4389 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
4394 /* QAM State Machine (FSM) Thresholds */
4396 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 140);
4399 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 50);
4402 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 95);
4405 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 120);
4408 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 230);
4411 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 105);
4415 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4418 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4421 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 24);
4426 /* QAM FSM Tracking Parameters */
4428 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 16);
4431 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 220);
4434 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 25);
4437 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 6);
4440 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -24);
4443 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -65);
4446 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -127);
4452 pr_err("Error %d on %s\n", status
, __func__
);
4456 /*============================================================================*/
4459 * \brief QAM32 specific setup
4460 * \param demod instance of demod.
4461 * \return DRXStatus_t.
4463 static int set_qam32(struct drxk_state
*state
)
4469 /* QAM Equalizer Setup */
4471 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 6707);
4474 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 6707);
4477 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 6707);
4480 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 6707);
4483 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 6707);
4486 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 6707);
4490 /* Decision Feedback Equalizer */
4491 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 3);
4494 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 3);
4497 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 3);
4500 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 3);
4503 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 3);
4506 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4510 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 6);
4513 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 5);
4516 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4520 /* QAM Slicer Settings */
4522 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
,
4523 DRXK_QAM_SL_SIG_POWER_QAM32
);
4528 /* QAM Loop Controller Coeficients */
4530 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4533 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4536 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4539 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4542 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4545 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4548 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4551 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4555 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4558 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 20);
4561 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 80);
4564 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4567 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 20);
4570 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4573 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4576 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 16);
4579 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 16);
4582 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4585 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4588 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 0);
4593 /* QAM State Machine (FSM) Thresholds */
4595 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 90);
4598 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 50);
4601 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
4604 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
4607 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 170);
4610 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 100);
4614 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4617 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4620 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 10);
4625 /* QAM FSM Tracking Parameters */
4627 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 12);
4630 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 140);
4633 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) -8);
4636 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) -16);
4639 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -26);
4642 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -56);
4645 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -86);
4648 pr_err("Error %d on %s\n", status
, __func__
);
4652 /*============================================================================*/
4655 * \brief QAM64 specific setup
4656 * \param demod instance of demod.
4657 * \return DRXStatus_t.
4659 static int set_qam64(struct drxk_state
*state
)
4664 /* QAM Equalizer Setup */
4666 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 13336);
4669 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 12618);
4672 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 11988);
4675 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 13809);
4678 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13809);
4681 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 15609);
4685 /* Decision Feedback Equalizer */
4686 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 4);
4689 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 4);
4692 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 4);
4695 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 4);
4698 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 3);
4701 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4705 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
4708 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
4711 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4715 /* QAM Slicer Settings */
4716 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
,
4717 DRXK_QAM_SL_SIG_POWER_QAM64
);
4722 /* QAM Loop Controller Coeficients */
4724 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4727 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4730 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4733 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4736 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4739 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4742 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4745 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4749 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4752 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 30);
4755 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 100);
4758 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4761 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 30);
4764 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4767 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4770 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
4773 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 48);
4776 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4779 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4782 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
4787 /* QAM State Machine (FSM) Thresholds */
4789 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 100);
4792 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
4795 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
4798 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 110);
4801 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 200);
4804 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 95);
4808 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4811 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4814 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 15);
4819 /* QAM FSM Tracking Parameters */
4821 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 12);
4824 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 141);
4827 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 7);
4830 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 0);
4833 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -15);
4836 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -45);
4839 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -80);
4842 pr_err("Error %d on %s\n", status
, __func__
);
4847 /*============================================================================*/
4850 * \brief QAM128 specific setup
4851 * \param demod: instance of demod.
4852 * \return DRXStatus_t.
4854 static int set_qam128(struct drxk_state
*state
)
4859 /* QAM Equalizer Setup */
4861 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 6564);
4864 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 6598);
4867 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 6394);
4870 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 6409);
4873 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 6656);
4876 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 7238);
4880 /* Decision Feedback Equalizer */
4881 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 6);
4884 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 6);
4887 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 6);
4890 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 6);
4893 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 5);
4896 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4900 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 6);
4903 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 5);
4906 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4911 /* QAM Slicer Settings */
4913 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
,
4914 DRXK_QAM_SL_SIG_POWER_QAM128
);
4919 /* QAM Loop Controller Coeficients */
4921 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4924 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4927 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4930 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4933 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4936 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4939 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4942 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4946 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4949 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 40);
4952 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 120);
4955 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4958 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 40);
4961 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 60);
4964 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4967 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
4970 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 64);
4973 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4976 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4979 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 0);
4984 /* QAM State Machine (FSM) Thresholds */
4986 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 50);
4989 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
4992 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
4995 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
4998 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 140);
5001 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 100);
5005 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
5008 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 5);
5012 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 12);
5016 /* QAM FSM Tracking Parameters */
5018 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 8);
5021 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 65);
5024 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 5);
5027 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 3);
5030 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -1);
5033 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -12);
5036 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -23);
5039 pr_err("Error %d on %s\n", status
, __func__
);
5044 /*============================================================================*/
5047 * \brief QAM256 specific setup
5048 * \param demod: instance of demod.
5049 * \return DRXStatus_t.
5051 static int set_qam256(struct drxk_state
*state
)
5056 /* QAM Equalizer Setup */
5058 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 11502);
5061 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 12084);
5064 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 12543);
5067 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 12931);
5070 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13629);
5073 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 15385);
5077 /* Decision Feedback Equalizer */
5078 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 8);
5081 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 8);
5084 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 8);
5087 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 8);
5090 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 6);
5093 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
5097 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
5100 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
5103 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
5107 /* QAM Slicer Settings */
5109 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
,
5110 DRXK_QAM_SL_SIG_POWER_QAM256
);
5115 /* QAM Loop Controller Coeficients */
5117 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
5120 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
5123 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
5126 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
5129 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
5132 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
5135 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
5138 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
5142 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
5145 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 50);
5148 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 250);
5151 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
5154 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 50);
5157 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 125);
5160 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
5163 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
5166 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 48);
5169 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
5172 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
5175 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
5180 /* QAM State Machine (FSM) Thresholds */
5182 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 50);
5185 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
5188 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
5191 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
5194 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 150);
5197 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 110);
5201 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
5204 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
5207 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 12);
5212 /* QAM FSM Tracking Parameters */
5214 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 8);
5217 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 74);
5220 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 18);
5223 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 13);
5226 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) 7);
5229 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) 0);
5232 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -8);
5235 pr_err("Error %d on %s\n", status
, __func__
);
5240 /*============================================================================*/
5242 * \brief Reset QAM block.
5243 * \param demod: instance of demod.
5244 * \param channel: pointer to channel data.
5245 * \return DRXStatus_t.
5247 static int qam_reset_qam(struct drxk_state
*state
)
5253 /* Stop QAM comstate->m_exec */
5254 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_STOP
);
5258 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
5259 | SCU_RAM_COMMAND_CMD_DEMOD_RESET
,
5260 0, NULL
, 1, &cmd_result
);
5263 pr_err("Error %d on %s\n", status
, __func__
);
5267 /*============================================================================*/
5270 * \brief Set QAM symbolrate.
5271 * \param demod: instance of demod.
5272 * \param channel: pointer to channel data.
5273 * \return DRXStatus_t.
5275 static int qam_set_symbolrate(struct drxk_state
*state
)
5277 u32 adc_frequency
= 0;
5279 u32 iqm_rc_rate
= 0;
5281 u32 lc_symb_rate
= 0;
5285 /* Select & calculate correct IQM rate */
5286 adc_frequency
= (state
->m_sys_clock_freq
* 1000) / 3;
5288 /* printk(KERN_DEBUG "drxk: SR %d\n", state->props.symbol_rate); */
5289 if (state
->props
.symbol_rate
<= 1188750)
5291 else if (state
->props
.symbol_rate
<= 2377500)
5293 else if (state
->props
.symbol_rate
<= 4755000)
5295 status
= write16(state
, IQM_FD_RATESEL__A
, ratesel
);
5300 IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23)
5302 symb_freq
= state
->props
.symbol_rate
* (1 << ratesel
);
5303 if (symb_freq
== 0) {
5304 /* Divide by zero */
5308 iqm_rc_rate
= (adc_frequency
/ symb_freq
) * (1 << 21) +
5309 (Frac28a((adc_frequency
% symb_freq
), symb_freq
) >> 7) -
5311 status
= write32(state
, IQM_RC_RATE_OFS_LO__A
, iqm_rc_rate
);
5314 state
->m_iqm_rc_rate
= iqm_rc_rate
;
5316 LcSymbFreq = round (.125 * symbolrate / adc_freq * (1<<15))
5318 symb_freq
= state
->props
.symbol_rate
;
5319 if (adc_frequency
== 0) {
5320 /* Divide by zero */
5324 lc_symb_rate
= (symb_freq
/ adc_frequency
) * (1 << 12) +
5325 (Frac28a((symb_freq
% adc_frequency
), adc_frequency
) >>
5327 if (lc_symb_rate
> 511)
5329 status
= write16(state
, QAM_LC_SYMBOL_FREQ__A
, (u16
) lc_symb_rate
);
5333 pr_err("Error %d on %s\n", status
, __func__
);
5337 /*============================================================================*/
5340 * \brief Get QAM lock status.
5341 * \param demod: instance of demod.
5342 * \param channel: pointer to channel data.
5343 * \return DRXStatus_t.
5346 static int get_qam_lock_status(struct drxk_state
*state
, u32
*p_lock_status
)
5349 u16 result
[2] = { 0, 0 };
5352 *p_lock_status
= NOT_LOCKED
;
5353 status
= scu_command(state
,
5354 SCU_RAM_COMMAND_STANDARD_QAM
|
5355 SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK
, 0, NULL
, 2,
5358 pr_err("Error %d on %s\n", status
, __func__
);
5360 if (result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED
) {
5361 /* 0x0000 NOT LOCKED */
5362 } else if (result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED
) {
5363 /* 0x4000 DEMOD LOCKED */
5364 *p_lock_status
= DEMOD_LOCK
;
5365 } else if (result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK
) {
5366 /* 0x8000 DEMOD + FEC LOCKED (system lock) */
5367 *p_lock_status
= MPEG_LOCK
;
5369 /* 0xC000 NEVER LOCKED */
5370 /* (system will never be able to lock to the signal) */
5372 * TODO: check this, intermediate & standard specific lock
5373 * states are not taken into account here
5375 *p_lock_status
= NEVER_LOCK
;
5380 #define QAM_MIRROR__M 0x03
5381 #define QAM_MIRROR_NORMAL 0x00
5382 #define QAM_MIRRORED 0x01
5383 #define QAM_MIRROR_AUTO_ON 0x02
5384 #define QAM_LOCKRANGE__M 0x10
5385 #define QAM_LOCKRANGE_NORMAL 0x10
5387 static int qam_demodulator_command(struct drxk_state
*state
,
5388 int number_of_parameters
)
5392 u16 set_param_parameters
[4] = { 0, 0, 0, 0 };
5394 set_param_parameters
[0] = state
->m_constellation
; /* modulation */
5395 set_param_parameters
[1] = DRXK_QAM_I12_J17
; /* interleave mode */
5397 if (number_of_parameters
== 2) {
5398 u16 set_env_parameters
[1] = { 0 };
5400 if (state
->m_operation_mode
== OM_QAM_ITU_C
)
5401 set_env_parameters
[0] = QAM_TOP_ANNEX_C
;
5403 set_env_parameters
[0] = QAM_TOP_ANNEX_A
;
5405 status
= scu_command(state
,
5406 SCU_RAM_COMMAND_STANDARD_QAM
5407 | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV
,
5408 1, set_env_parameters
, 1, &cmd_result
);
5412 status
= scu_command(state
,
5413 SCU_RAM_COMMAND_STANDARD_QAM
5414 | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM
,
5415 number_of_parameters
, set_param_parameters
,
5417 } else if (number_of_parameters
== 4) {
5418 if (state
->m_operation_mode
== OM_QAM_ITU_C
)
5419 set_param_parameters
[2] = QAM_TOP_ANNEX_C
;
5421 set_param_parameters
[2] = QAM_TOP_ANNEX_A
;
5423 set_param_parameters
[3] |= (QAM_MIRROR_AUTO_ON
);
5424 /* Env parameters */
5425 /* check for LOCKRANGE Extented */
5426 /* set_param_parameters[3] |= QAM_LOCKRANGE_NORMAL; */
5428 status
= scu_command(state
,
5429 SCU_RAM_COMMAND_STANDARD_QAM
5430 | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM
,
5431 number_of_parameters
, set_param_parameters
,
5434 pr_warn("Unknown QAM demodulator parameter count %d\n",
5435 number_of_parameters
);
5441 pr_warn("Warning %d on %s\n", status
, __func__
);
5445 static int set_qam(struct drxk_state
*state
, u16 intermediate_freqk_hz
,
5446 s32 tuner_freq_offset
)
5450 int qam_demod_param_count
= state
->qam_demod_parameter_count
;
5454 * STEP 1: reset demodulator
5455 * resets FEC DI and FEC RS
5457 * resets SCU variables
5459 status
= write16(state
, FEC_DI_COMM_EXEC__A
, FEC_DI_COMM_EXEC_STOP
);
5462 status
= write16(state
, FEC_RS_COMM_EXEC__A
, FEC_RS_COMM_EXEC_STOP
);
5465 status
= qam_reset_qam(state
);
5470 * STEP 2: configure demodulator
5471 * -set params; resets IQM,QAM,FEC HW; initializes some
5474 status
= qam_set_symbolrate(state
);
5479 switch (state
->props
.modulation
) {
5481 state
->m_constellation
= DRX_CONSTELLATION_QAM256
;
5485 state
->m_constellation
= DRX_CONSTELLATION_QAM64
;
5488 state
->m_constellation
= DRX_CONSTELLATION_QAM16
;
5491 state
->m_constellation
= DRX_CONSTELLATION_QAM32
;
5494 state
->m_constellation
= DRX_CONSTELLATION_QAM128
;
5503 /* Use the 4-parameter if it's requested or we're probing for
5504 * the correct command. */
5505 if (state
->qam_demod_parameter_count
== 4
5506 || !state
->qam_demod_parameter_count
) {
5507 qam_demod_param_count
= 4;
5508 status
= qam_demodulator_command(state
, qam_demod_param_count
);
5511 /* Use the 2-parameter command if it was requested or if we're
5512 * probing for the correct command and the 4-parameter command
5514 if (state
->qam_demod_parameter_count
== 2
5515 || (!state
->qam_demod_parameter_count
&& status
< 0)) {
5516 qam_demod_param_count
= 2;
5517 status
= qam_demodulator_command(state
, qam_demod_param_count
);
5521 dprintk(1, "Could not set demodulator parameters.\n");
5523 "Make sure qam_demod_parameter_count (%d) is correct for your firmware (%s).\n",
5524 state
->qam_demod_parameter_count
,
5525 state
->microcode_name
);
5527 } else if (!state
->qam_demod_parameter_count
) {
5529 "Auto-probing the QAM command parameters was successful - using %d parameters.\n",
5530 qam_demod_param_count
);
5533 * One of our commands was successful. We don't need to
5534 * auto-probe anymore, now that we got the correct command.
5536 state
->qam_demod_parameter_count
= qam_demod_param_count
;
5540 * STEP 3: enable the system in a mode where the ADC provides valid
5541 * signal setup modulation independent registers
5544 status
= set_frequency(channel
, tuner_freq_offset
));
5548 status
= set_frequency_shifter(state
, intermediate_freqk_hz
,
5549 tuner_freq_offset
, true);
5553 /* Setup BER measurement */
5554 status
= set_qam_measurement(state
, state
->m_constellation
,
5555 state
->props
.symbol_rate
);
5559 /* Reset default values */
5560 status
= write16(state
, IQM_CF_SCALE_SH__A
, IQM_CF_SCALE_SH__PRE
);
5563 status
= write16(state
, QAM_SY_TIMEOUT__A
, QAM_SY_TIMEOUT__PRE
);
5567 /* Reset default LC values */
5568 status
= write16(state
, QAM_LC_RATE_LIMIT__A
, 3);
5571 status
= write16(state
, QAM_LC_LPF_FACTORP__A
, 4);
5574 status
= write16(state
, QAM_LC_LPF_FACTORI__A
, 4);
5577 status
= write16(state
, QAM_LC_MODE__A
, 7);
5581 status
= write16(state
, QAM_LC_QUAL_TAB0__A
, 1);
5584 status
= write16(state
, QAM_LC_QUAL_TAB1__A
, 1);
5587 status
= write16(state
, QAM_LC_QUAL_TAB2__A
, 1);
5590 status
= write16(state
, QAM_LC_QUAL_TAB3__A
, 1);
5593 status
= write16(state
, QAM_LC_QUAL_TAB4__A
, 2);
5596 status
= write16(state
, QAM_LC_QUAL_TAB5__A
, 2);
5599 status
= write16(state
, QAM_LC_QUAL_TAB6__A
, 2);
5602 status
= write16(state
, QAM_LC_QUAL_TAB8__A
, 2);
5605 status
= write16(state
, QAM_LC_QUAL_TAB9__A
, 2);
5608 status
= write16(state
, QAM_LC_QUAL_TAB10__A
, 2);
5611 status
= write16(state
, QAM_LC_QUAL_TAB12__A
, 2);
5614 status
= write16(state
, QAM_LC_QUAL_TAB15__A
, 3);
5617 status
= write16(state
, QAM_LC_QUAL_TAB16__A
, 3);
5620 status
= write16(state
, QAM_LC_QUAL_TAB20__A
, 4);
5623 status
= write16(state
, QAM_LC_QUAL_TAB25__A
, 4);
5627 /* Mirroring, QAM-block starting point not inverted */
5628 status
= write16(state
, QAM_SY_SP_INV__A
,
5629 QAM_SY_SP_INV_SPECTRUM_INV_DIS
);
5633 /* Halt SCU to enable safe non-atomic accesses */
5634 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
5638 /* STEP 4: modulation specific setup */
5639 switch (state
->props
.modulation
) {
5641 status
= set_qam16(state
);
5644 status
= set_qam32(state
);
5648 status
= set_qam64(state
);
5651 status
= set_qam128(state
);
5654 status
= set_qam256(state
);
5663 /* Activate SCU to enable SCU commands */
5664 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
5668 /* Re-configure MPEG output, requires knowledge of channel bitrate */
5669 /* extAttr->currentChannel.modulation = channel->modulation; */
5670 /* extAttr->currentChannel.symbolrate = channel->symbolrate; */
5671 status
= mpegts_dto_setup(state
, state
->m_operation_mode
);
5675 /* start processes */
5676 status
= mpegts_start(state
);
5679 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_ACTIVE
);
5682 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_ACTIVE
);
5685 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_ACTIVE
);
5689 /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */
5690 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
5691 | SCU_RAM_COMMAND_CMD_DEMOD_START
,
5692 0, NULL
, 1, &cmd_result
);
5696 /* update global DRXK data container */
5697 /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */
5701 pr_err("Error %d on %s\n", status
, __func__
);
5705 static int set_qam_standard(struct drxk_state
*state
,
5706 enum operation_mode o_mode
)
5709 #ifdef DRXK_QAM_TAPS
5710 #define DRXK_QAMA_TAPS_SELECT
5711 #include "drxk_filters.h"
5712 #undef DRXK_QAMA_TAPS_SELECT
5717 /* added antenna switch */
5718 switch_antenna_to_qam(state
);
5720 /* Ensure correct power-up mode */
5721 status
= power_up_qam(state
);
5724 /* Reset QAM block */
5725 status
= qam_reset_qam(state
);
5731 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
5734 status
= write16(state
, IQM_AF_AMUX__A
, IQM_AF_AMUX_SIGNAL2ADC
);
5738 /* Upload IQM Channel Filter settings by
5739 boot loader from ROM table */
5742 status
= bl_chain_cmd(state
, DRXK_BL_ROM_OFFSET_TAPS_ITU_A
,
5743 DRXK_BLCC_NR_ELEMENTS_TAPS
,
5747 status
= bl_direct_cmd(state
, IQM_CF_TAP_RE0__A
,
5748 DRXK_BL_ROM_OFFSET_TAPS_ITU_C
,
5749 DRXK_BLDC_NR_ELEMENTS_TAPS
,
5753 status
= bl_direct_cmd(state
,
5755 DRXK_BL_ROM_OFFSET_TAPS_ITU_C
,
5756 DRXK_BLDC_NR_ELEMENTS_TAPS
,
5765 status
= write16(state
, IQM_CF_OUT_ENA__A
, 1 << IQM_CF_OUT_ENA_QAM__B
);
5768 status
= write16(state
, IQM_CF_SYMMETRIC__A
, 0);
5771 status
= write16(state
, IQM_CF_MIDTAP__A
,
5772 ((1 << IQM_CF_MIDTAP_RE__B
) | (1 << IQM_CF_MIDTAP_IM__B
)));
5776 status
= write16(state
, IQM_RC_STRETCH__A
, 21);
5779 status
= write16(state
, IQM_AF_CLP_LEN__A
, 0);
5782 status
= write16(state
, IQM_AF_CLP_TH__A
, 448);
5785 status
= write16(state
, IQM_AF_SNS_LEN__A
, 0);
5788 status
= write16(state
, IQM_CF_POW_MEAS_LEN__A
, 0);
5792 status
= write16(state
, IQM_FS_ADJ_SEL__A
, 1);
5795 status
= write16(state
, IQM_RC_ADJ_SEL__A
, 1);
5798 status
= write16(state
, IQM_CF_ADJ_SEL__A
, 1);
5801 status
= write16(state
, IQM_AF_UPD_SEL__A
, 0);
5805 /* IQM Impulse Noise Processing Unit */
5806 status
= write16(state
, IQM_CF_CLP_VAL__A
, 500);
5809 status
= write16(state
, IQM_CF_DATATH__A
, 1000);
5812 status
= write16(state
, IQM_CF_BYPASSDET__A
, 1);
5815 status
= write16(state
, IQM_CF_DET_LCT__A
, 0);
5818 status
= write16(state
, IQM_CF_WND_LEN__A
, 1);
5821 status
= write16(state
, IQM_CF_PKDTH__A
, 1);
5824 status
= write16(state
, IQM_AF_INC_BYPASS__A
, 1);
5828 /* turn on IQMAF. Must be done before setAgc**() */
5829 status
= set_iqm_af(state
, true);
5832 status
= write16(state
, IQM_AF_START_LOCK__A
, 0x01);
5836 /* IQM will not be reset from here, sync ADC and update/init AGC */
5837 status
= adc_synchronization(state
);
5841 /* Set the FSM step period */
5842 status
= write16(state
, SCU_RAM_QAM_FSM_STEP_PERIOD__A
, 2000);
5846 /* Halt SCU to enable safe non-atomic accesses */
5847 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
5851 /* No more resets of the IQM, current standard correctly set =>
5852 now AGCs can be configured. */
5854 status
= init_agc(state
, true);
5857 status
= set_pre_saw(state
, &(state
->m_qam_pre_saw_cfg
));
5861 /* Configure AGC's */
5862 status
= set_agc_rf(state
, &(state
->m_qam_rf_agc_cfg
), true);
5865 status
= set_agc_if(state
, &(state
->m_qam_if_agc_cfg
), true);
5869 /* Activate SCU to enable SCU commands */
5870 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
5873 pr_err("Error %d on %s\n", status
, __func__
);
5877 static int write_gpio(struct drxk_state
*state
)
5883 /* stop lock indicator process */
5884 status
= write16(state
, SCU_RAM_GPIO__A
,
5885 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
5889 /* Write magic word to enable pdr reg write */
5890 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
5894 if (state
->m_has_sawsw
) {
5895 if (state
->uio_mask
& 0x0001) { /* UIO-1 */
5896 /* write to io pad configuration register - output mode */
5897 status
= write16(state
, SIO_PDR_SMA_TX_CFG__A
,
5902 /* use corresponding bit in io data output registar */
5903 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5906 if ((state
->m_gpio
& 0x0001) == 0)
5907 value
&= 0x7FFF; /* write zero to 15th bit - 1st UIO */
5909 value
|= 0x8000; /* write one to 15th bit - 1st UIO */
5910 /* write back to io data output register */
5911 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5915 if (state
->uio_mask
& 0x0002) { /* UIO-2 */
5916 /* write to io pad configuration register - output mode */
5917 status
= write16(state
, SIO_PDR_SMA_RX_CFG__A
,
5922 /* use corresponding bit in io data output registar */
5923 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5926 if ((state
->m_gpio
& 0x0002) == 0)
5927 value
&= 0xBFFF; /* write zero to 14th bit - 2st UIO */
5929 value
|= 0x4000; /* write one to 14th bit - 2st UIO */
5930 /* write back to io data output register */
5931 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5935 if (state
->uio_mask
& 0x0004) { /* UIO-3 */
5936 /* write to io pad configuration register - output mode */
5937 status
= write16(state
, SIO_PDR_GPIO_CFG__A
,
5942 /* use corresponding bit in io data output registar */
5943 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5946 if ((state
->m_gpio
& 0x0004) == 0)
5947 value
&= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */
5949 value
|= 0x0004; /* write one to 2nd bit - 3rd UIO */
5950 /* write back to io data output register */
5951 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5956 /* Write magic word to disable pdr reg write */
5957 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
5960 pr_err("Error %d on %s\n", status
, __func__
);
5964 static int switch_antenna_to_qam(struct drxk_state
*state
)
5971 if (!state
->antenna_gpio
)
5974 gpio_state
= state
->m_gpio
& state
->antenna_gpio
;
5976 if (state
->antenna_dvbt
^ gpio_state
) {
5977 /* Antenna is on DVB-T mode. Switch */
5978 if (state
->antenna_dvbt
)
5979 state
->m_gpio
&= ~state
->antenna_gpio
;
5981 state
->m_gpio
|= state
->antenna_gpio
;
5982 status
= write_gpio(state
);
5985 pr_err("Error %d on %s\n", status
, __func__
);
5989 static int switch_antenna_to_dvbt(struct drxk_state
*state
)
5996 if (!state
->antenna_gpio
)
5999 gpio_state
= state
->m_gpio
& state
->antenna_gpio
;
6001 if (!(state
->antenna_dvbt
^ gpio_state
)) {
6002 /* Antenna is on DVB-C mode. Switch */
6003 if (state
->antenna_dvbt
)
6004 state
->m_gpio
|= state
->antenna_gpio
;
6006 state
->m_gpio
&= ~state
->antenna_gpio
;
6007 status
= write_gpio(state
);
6010 pr_err("Error %d on %s\n", status
, __func__
);
6015 static int power_down_device(struct drxk_state
*state
)
6017 /* Power down to requested mode */
6018 /* Backup some register settings */
6019 /* Set pins with possible pull-ups connected to them in input mode */
6020 /* Analog power down */
6021 /* ADC power down */
6022 /* Power down device */
6026 if (state
->m_b_p_down_open_bridge
) {
6027 /* Open I2C bridge before power down of DRXK */
6028 status
= ConfigureI2CBridge(state
, true);
6033 status
= dvbt_enable_ofdm_token_ring(state
, false);
6037 status
= write16(state
, SIO_CC_PWD_MODE__A
,
6038 SIO_CC_PWD_MODE_LEVEL_CLOCK
);
6041 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
6044 state
->m_hi_cfg_ctrl
|= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
6045 status
= hi_cfg_command(state
);
6048 pr_err("Error %d on %s\n", status
, __func__
);
6053 static int init_drxk(struct drxk_state
*state
)
6055 int status
= 0, n
= 0;
6056 enum drx_power_mode power_mode
= DRXK_POWER_DOWN_OFDM
;
6060 if ((state
->m_drxk_state
== DRXK_UNINITIALIZED
)) {
6061 drxk_i2c_lock(state
);
6062 status
= power_up_device(state
);
6065 status
= drxx_open(state
);
6068 /* Soft reset of OFDM-, sys- and osc-clockdomain */
6069 status
= write16(state
, SIO_CC_SOFT_RST__A
,
6070 SIO_CC_SOFT_RST_OFDM__M
6071 | SIO_CC_SOFT_RST_SYS__M
6072 | SIO_CC_SOFT_RST_OSC__M
);
6075 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
6079 * TODO is this needed? If yes, how much delay in
6080 * worst case scenario
6082 usleep_range(1000, 2000);
6083 state
->m_drxk_a3_patch_code
= true;
6084 status
= get_device_capabilities(state
);
6088 /* Bridge delay, uses oscilator clock */
6089 /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */
6090 /* SDA brdige delay */
6091 state
->m_hi_cfg_bridge_delay
=
6092 (u16
) ((state
->m_osc_clock_freq
/ 1000) *
6093 HI_I2C_BRIDGE_DELAY
) / 1000;
6095 if (state
->m_hi_cfg_bridge_delay
>
6096 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M
) {
6097 state
->m_hi_cfg_bridge_delay
=
6098 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M
;
6100 /* SCL bridge delay, same as SDA for now */
6101 state
->m_hi_cfg_bridge_delay
+=
6102 state
->m_hi_cfg_bridge_delay
<<
6103 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B
;
6105 status
= init_hi(state
);
6108 /* disable various processes */
6110 if (!(state
->m_DRXK_A1_ROM_CODE
)
6111 && !(state
->m_DRXK_A2_ROM_CODE
))
6114 status
= write16(state
, SCU_RAM_GPIO__A
,
6115 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
6120 /* disable MPEG port */
6121 status
= mpegts_disable(state
);
6125 /* Stop AUD and SCU */
6126 status
= write16(state
, AUD_COMM_EXEC__A
, AUD_COMM_EXEC_STOP
);
6129 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_STOP
);
6133 /* enable token-ring bus through OFDM block for possible ucode upload */
6134 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
,
6135 SIO_OFDM_SH_OFDM_RING_ENABLE_ON
);
6139 /* include boot loader section */
6140 status
= write16(state
, SIO_BL_COMM_EXEC__A
,
6141 SIO_BL_COMM_EXEC_ACTIVE
);
6144 status
= bl_chain_cmd(state
, 0, 6, 100);
6149 status
= download_microcode(state
, state
->fw
->data
,
6155 /* disable token-ring bus through OFDM block for possible ucode upload */
6156 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
,
6157 SIO_OFDM_SH_OFDM_RING_ENABLE_OFF
);
6161 /* Run SCU for a little while to initialize microcode version numbers */
6162 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
6165 status
= drxx_open(state
);
6168 /* added for test */
6171 power_mode
= DRXK_POWER_DOWN_OFDM
;
6172 status
= ctrl_power_mode(state
, &power_mode
);
6176 /* Stamp driver version number in SCU data RAM in BCD code
6177 Done to enable field application engineers to retreive drxdriver version
6178 via I2C from SCU RAM.
6179 Not using SCU command interface for SCU register access since no
6180 microcode may be present.
6183 (((DRXK_VERSION_MAJOR
/ 100) % 10) << 12) +
6184 (((DRXK_VERSION_MAJOR
/ 10) % 10) << 8) +
6185 ((DRXK_VERSION_MAJOR
% 10) << 4) +
6186 (DRXK_VERSION_MINOR
% 10);
6187 status
= write16(state
, SCU_RAM_DRIVER_VER_HI__A
,
6192 (((DRXK_VERSION_PATCH
/ 1000) % 10) << 12) +
6193 (((DRXK_VERSION_PATCH
/ 100) % 10) << 8) +
6194 (((DRXK_VERSION_PATCH
/ 10) % 10) << 4) +
6195 (DRXK_VERSION_PATCH
% 10);
6196 status
= write16(state
, SCU_RAM_DRIVER_VER_LO__A
,
6201 pr_info("DRXK driver version %d.%d.%d\n",
6202 DRXK_VERSION_MAJOR
, DRXK_VERSION_MINOR
,
6203 DRXK_VERSION_PATCH
);
6206 * Dirty fix of default values for ROM/PATCH microcode
6207 * Dirty because this fix makes it impossible to setup
6208 * suitable values before calling DRX_Open. This solution
6209 * requires changes to RF AGC speed to be done via the CTRL
6210 * function after calling DRX_Open
6213 /* m_dvbt_rf_agc_cfg.speed = 3; */
6215 /* Reset driver debug flags to 0 */
6216 status
= write16(state
, SCU_RAM_DRIVER_DEBUG__A
, 0);
6221 NOTE: No more full FEC resets allowed afterwards!! */
6222 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_STOP
);
6225 /* MPEGTS functions are still the same */
6226 status
= mpegts_dto_init(state
);
6229 status
= mpegts_stop(state
);
6232 status
= mpegts_configure_polarity(state
);
6235 status
= mpegts_configure_pins(state
, state
->m_enable_mpeg_output
);
6238 /* added: configure GPIO */
6239 status
= write_gpio(state
);
6243 state
->m_drxk_state
= DRXK_STOPPED
;
6245 if (state
->m_b_power_down
) {
6246 status
= power_down_device(state
);
6249 state
->m_drxk_state
= DRXK_POWERED_DOWN
;
6251 state
->m_drxk_state
= DRXK_STOPPED
;
6253 /* Initialize the supported delivery systems */
6255 if (state
->m_has_dvbc
) {
6256 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_A
;
6257 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_C
;
6258 strlcat(state
->frontend
.ops
.info
.name
, " DVB-C",
6259 sizeof(state
->frontend
.ops
.info
.name
));
6261 if (state
->m_has_dvbt
) {
6262 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBT
;
6263 strlcat(state
->frontend
.ops
.info
.name
, " DVB-T",
6264 sizeof(state
->frontend
.ops
.info
.name
));
6266 drxk_i2c_unlock(state
);
6270 state
->m_drxk_state
= DRXK_NO_DEV
;
6271 drxk_i2c_unlock(state
);
6272 pr_err("Error %d on %s\n", status
, __func__
);
6278 static void load_firmware_cb(const struct firmware
*fw
,
6281 struct drxk_state
*state
= context
;
6283 dprintk(1, ": %s\n", fw
? "firmware loaded" : "firmware not loaded");
6285 pr_err("Could not load firmware file %s.\n",
6286 state
->microcode_name
);
6287 pr_info("Copy %s to your hotplug directory!\n",
6288 state
->microcode_name
);
6289 state
->microcode_name
= NULL
;
6292 * As firmware is now load asynchronous, it is not possible
6293 * anymore to fail at frontend attach. We might silently
6294 * return here, and hope that the driver won't crash.
6295 * We might also change all DVB callbacks to return -ENODEV
6296 * if the device is not initialized.
6297 * As the DRX-K devices have their own internal firmware,
6298 * let's just hope that it will match a firmware revision
6299 * compatible with this driver and proceed.
6307 static void drxk_release(struct dvb_frontend
*fe
)
6309 struct drxk_state
*state
= fe
->demodulator_priv
;
6313 release_firmware(state
->fw
);
6318 static int drxk_sleep(struct dvb_frontend
*fe
)
6320 struct drxk_state
*state
= fe
->demodulator_priv
;
6324 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6326 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6333 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
6335 struct drxk_state
*state
= fe
->demodulator_priv
;
6337 dprintk(1, ": %s\n", enable
? "enable" : "disable");
6339 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6342 return ConfigureI2CBridge(state
, enable
? true : false);
6345 static int drxk_set_parameters(struct dvb_frontend
*fe
)
6347 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
6348 u32 delsys
= p
->delivery_system
, old_delsys
;
6349 struct drxk_state
*state
= fe
->demodulator_priv
;
6354 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6357 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6360 if (!fe
->ops
.tuner_ops
.get_if_frequency
) {
6361 pr_err("Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
6365 if (fe
->ops
.i2c_gate_ctrl
)
6366 fe
->ops
.i2c_gate_ctrl(fe
, 1);
6367 if (fe
->ops
.tuner_ops
.set_params
)
6368 fe
->ops
.tuner_ops
.set_params(fe
);
6369 if (fe
->ops
.i2c_gate_ctrl
)
6370 fe
->ops
.i2c_gate_ctrl(fe
, 0);
6372 old_delsys
= state
->props
.delivery_system
;
6375 if (old_delsys
!= delsys
) {
6378 case SYS_DVBC_ANNEX_A
:
6379 case SYS_DVBC_ANNEX_C
:
6380 if (!state
->m_has_dvbc
)
6382 state
->m_itut_annex_c
= (delsys
== SYS_DVBC_ANNEX_C
) ?
6384 if (state
->m_itut_annex_c
)
6385 setoperation_mode(state
, OM_QAM_ITU_C
);
6387 setoperation_mode(state
, OM_QAM_ITU_A
);
6390 if (!state
->m_has_dvbt
)
6392 setoperation_mode(state
, OM_DVBT
);
6399 fe
->ops
.tuner_ops
.get_if_frequency(fe
, &IF
);
6400 start(state
, 0, IF
);
6402 /* After set_frontend, stats aren't avaliable */
6403 p
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
6404 p
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6405 p
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6406 p
->block_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6407 p
->pre_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6408 p
->pre_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6409 p
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6410 p
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6412 /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */
6417 static int get_strength(struct drxk_state
*state
, u64
*strength
)
6420 struct s_cfg_agc rf_agc
, if_agc
;
6426 /* FIXME: those are part of the tuner presets */
6427 u16 tuner_rf_gain
= 50; /* Default value on az6007 driver */
6428 u16 tuner_if_gain
= 40; /* Default value on az6007 driver */
6432 if (is_dvbt(state
)) {
6433 rf_agc
= state
->m_dvbt_rf_agc_cfg
;
6434 if_agc
= state
->m_dvbt_if_agc_cfg
;
6435 } else if (is_qam(state
)) {
6436 rf_agc
= state
->m_qam_rf_agc_cfg
;
6437 if_agc
= state
->m_qam_if_agc_cfg
;
6439 rf_agc
= state
->m_atv_rf_agc_cfg
;
6440 if_agc
= state
->m_atv_if_agc_cfg
;
6443 if (rf_agc
.ctrl_mode
== DRXK_AGC_CTRL_AUTO
) {
6444 /* SCU output_level */
6445 status
= read16(state
, SCU_RAM_AGC_RF_IACCU_HI__A
, &scu_lvl
);
6450 read16(state
, SCU_RAM_AGC_RF_IACCU_HI_CO__A
, &scu_coc
);
6454 if (((u32
) scu_lvl
+ (u32
) scu_coc
) < 0xffff)
6455 rf_agc
.output_level
= scu_lvl
+ scu_coc
;
6457 rf_agc
.output_level
= 0xffff;
6459 /* Take RF gain into account */
6460 total_gain
+= tuner_rf_gain
;
6462 /* clip output value */
6463 if (rf_agc
.output_level
< rf_agc
.min_output_level
)
6464 rf_agc
.output_level
= rf_agc
.min_output_level
;
6465 if (rf_agc
.output_level
> rf_agc
.max_output_level
)
6466 rf_agc
.output_level
= rf_agc
.max_output_level
;
6468 agc_range
= (u32
) (rf_agc
.max_output_level
- rf_agc
.min_output_level
);
6469 if (agc_range
> 0) {
6471 ((u32
)(tuner_rf_gain
)) *
6472 ((u32
)(rf_agc
.output_level
- rf_agc
.min_output_level
))
6477 if (if_agc
.ctrl_mode
== DRXK_AGC_CTRL_AUTO
) {
6478 status
= read16(state
, SCU_RAM_AGC_IF_IACCU_HI__A
,
6479 &if_agc
.output_level
);
6483 status
= read16(state
, SCU_RAM_AGC_INGAIN_TGT_MIN__A
,
6488 /* Take IF gain into account */
6489 total_gain
+= (u32
) tuner_if_gain
;
6491 /* clip output value */
6492 if (if_agc
.output_level
< if_agc
.min_output_level
)
6493 if_agc
.output_level
= if_agc
.min_output_level
;
6494 if (if_agc
.output_level
> if_agc
.max_output_level
)
6495 if_agc
.output_level
= if_agc
.max_output_level
;
6497 agc_range
= (u32
)(if_agc
.max_output_level
- if_agc
.min_output_level
);
6498 if (agc_range
> 0) {
6500 ((u32
)(tuner_if_gain
)) *
6501 ((u32
)(if_agc
.output_level
- if_agc
.min_output_level
))
6507 * Convert to 0..65535 scale.
6508 * If it can't be measured (AGC is disabled), just show 100%.
6511 *strength
= (65535UL * atten
/ total_gain
/ 100);
6518 static int drxk_get_stats(struct dvb_frontend
*fe
)
6520 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
6521 struct drxk_state
*state
= fe
->demodulator_priv
;
6526 u32 post_bit_err_count
;
6527 u32 post_bit_error_scale
;
6528 u32 pre_bit_err_count
;
6531 u32 pkt_error_count
;
6534 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6536 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6540 state
->fe_status
= 0;
6541 get_lock_status(state
, &stat
);
6542 if (stat
== MPEG_LOCK
)
6543 state
->fe_status
|= 0x1f;
6544 if (stat
== FEC_LOCK
)
6545 state
->fe_status
|= 0x0f;
6546 if (stat
== DEMOD_LOCK
)
6547 state
->fe_status
|= 0x07;
6550 * Estimate signal strength from AGC
6552 get_strength(state
, &c
->strength
.stat
[0].uvalue
);
6553 c
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
6556 if (stat
>= DEMOD_LOCK
) {
6557 get_signal_to_noise(state
, &cnr
);
6558 c
->cnr
.stat
[0].svalue
= cnr
* 100;
6559 c
->cnr
.stat
[0].scale
= FE_SCALE_DECIBEL
;
6561 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6564 if (stat
< FEC_LOCK
) {
6565 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6566 c
->block_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6567 c
->pre_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6568 c
->pre_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6569 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6570 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6576 /* BER measurement is valid if at least FEC lock is achieved */
6579 * OFDM_EC_VD_REQ_SMB_CNT__A and/or OFDM_EC_VD_REQ_BIT_CNT can be
6580 * written to set nr of symbols or bits over which to measure
6581 * EC_VD_REG_ERR_BIT_CNT__A . See CtrlSetCfg().
6584 /* Read registers for post/preViterbi BER calculation */
6585 status
= read16(state
, OFDM_EC_VD_ERR_BIT_CNT__A
, ®16
);
6588 pre_bit_err_count
= reg16
;
6590 status
= read16(state
, OFDM_EC_VD_IN_BIT_CNT__A
, ®16
);
6593 pre_bit_count
= reg16
;
6595 /* Number of bit-errors */
6596 status
= read16(state
, FEC_RS_NR_BIT_ERRORS__A
, ®16
);
6599 post_bit_err_count
= reg16
;
6601 status
= read16(state
, FEC_RS_MEASUREMENT_PRESCALE__A
, ®16
);
6604 post_bit_error_scale
= reg16
;
6606 status
= read16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, ®16
);
6611 status
= read16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
, ®16
);
6614 pkt_error_count
= reg16
;
6615 write16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
, 0);
6617 post_bit_err_count
*= post_bit_error_scale
;
6619 post_bit_count
= pkt_count
* 204 * 8;
6621 /* Store the results */
6622 c
->block_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
6623 c
->block_error
.stat
[0].uvalue
+= pkt_error_count
;
6624 c
->block_count
.stat
[0].scale
= FE_SCALE_COUNTER
;
6625 c
->block_count
.stat
[0].uvalue
+= pkt_count
;
6627 c
->pre_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
6628 c
->pre_bit_error
.stat
[0].uvalue
+= pre_bit_err_count
;
6629 c
->pre_bit_count
.stat
[0].scale
= FE_SCALE_COUNTER
;
6630 c
->pre_bit_count
.stat
[0].uvalue
+= pre_bit_count
;
6632 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
6633 c
->post_bit_error
.stat
[0].uvalue
+= post_bit_err_count
;
6634 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_COUNTER
;
6635 c
->post_bit_count
.stat
[0].uvalue
+= post_bit_count
;
6642 static int drxk_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
6644 struct drxk_state
*state
= fe
->demodulator_priv
;
6649 rc
= drxk_get_stats(fe
);
6653 *status
= state
->fe_status
;
6658 static int drxk_read_signal_strength(struct dvb_frontend
*fe
,
6661 struct drxk_state
*state
= fe
->demodulator_priv
;
6662 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
6666 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6668 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6671 *strength
= c
->strength
.stat
[0].uvalue
;
6675 static int drxk_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
6677 struct drxk_state
*state
= fe
->demodulator_priv
;
6682 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6684 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6687 get_signal_to_noise(state
, &snr2
);
6689 /* No negative SNR, clip to zero */
6692 *snr
= snr2
& 0xffff;
6696 static int drxk_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
6698 struct drxk_state
*state
= fe
->demodulator_priv
;
6703 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6705 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6708 dvbtqam_get_acc_pkt_err(state
, &err
);
6709 *ucblocks
= (u32
) err
;
6713 static int drxk_get_tune_settings(struct dvb_frontend
*fe
,
6714 struct dvb_frontend_tune_settings
*sets
)
6716 struct drxk_state
*state
= fe
->demodulator_priv
;
6717 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
6721 if (state
->m_drxk_state
== DRXK_NO_DEV
)
6723 if (state
->m_drxk_state
== DRXK_UNINITIALIZED
)
6726 switch (p
->delivery_system
) {
6727 case SYS_DVBC_ANNEX_A
:
6728 case SYS_DVBC_ANNEX_C
:
6730 sets
->min_delay_ms
= 3000;
6731 sets
->max_drift
= 0;
6732 sets
->step_size
= 0;
6739 static struct dvb_frontend_ops drxk_ops
= {
6740 /* .delsys will be filled dynamically */
6743 .frequency_min
= 47000000,
6744 .frequency_max
= 865000000,
6746 .symbol_rate_min
= 870000,
6747 .symbol_rate_max
= 11700000,
6749 .frequency_stepsize
= 166667,
6751 .caps
= FE_CAN_QAM_16
| FE_CAN_QAM_32
| FE_CAN_QAM_64
|
6752 FE_CAN_QAM_128
| FE_CAN_QAM_256
| FE_CAN_FEC_AUTO
|
6753 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
6754 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_MUTE_TS
|
6755 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_RECOVER
|
6756 FE_CAN_GUARD_INTERVAL_AUTO
| FE_CAN_HIERARCHY_AUTO
6759 .release
= drxk_release
,
6760 .sleep
= drxk_sleep
,
6761 .i2c_gate_ctrl
= drxk_gate_ctrl
,
6763 .set_frontend
= drxk_set_parameters
,
6764 .get_tune_settings
= drxk_get_tune_settings
,
6766 .read_status
= drxk_read_status
,
6767 .read_signal_strength
= drxk_read_signal_strength
,
6768 .read_snr
= drxk_read_snr
,
6769 .read_ucblocks
= drxk_read_ucblocks
,
6772 struct dvb_frontend
*drxk_attach(const struct drxk_config
*config
,
6773 struct i2c_adapter
*i2c
)
6775 struct dtv_frontend_properties
*p
;
6776 struct drxk_state
*state
= NULL
;
6777 u8 adr
= config
->adr
;
6781 state
= kzalloc(sizeof(struct drxk_state
), GFP_KERNEL
);
6786 state
->demod_address
= adr
;
6787 state
->single_master
= config
->single_master
;
6788 state
->microcode_name
= config
->microcode_name
;
6789 state
->qam_demod_parameter_count
= config
->qam_demod_parameter_count
;
6790 state
->no_i2c_bridge
= config
->no_i2c_bridge
;
6791 state
->antenna_gpio
= config
->antenna_gpio
;
6792 state
->antenna_dvbt
= config
->antenna_dvbt
;
6793 state
->m_chunk_size
= config
->chunk_size
;
6794 state
->enable_merr_cfg
= config
->enable_merr_cfg
;
6796 if (config
->dynamic_clk
) {
6797 state
->m_dvbt_static_clk
= 0;
6798 state
->m_dvbc_static_clk
= 0;
6800 state
->m_dvbt_static_clk
= 1;
6801 state
->m_dvbc_static_clk
= 1;
6805 if (config
->mpeg_out_clk_strength
)
6806 state
->m_ts_clockk_strength
= config
->mpeg_out_clk_strength
& 0x07;
6808 state
->m_ts_clockk_strength
= 0x06;
6810 if (config
->parallel_ts
)
6811 state
->m_enable_parallel
= true;
6813 state
->m_enable_parallel
= false;
6815 /* NOTE: as more UIO bits will be used, add them to the mask */
6816 state
->uio_mask
= config
->antenna_gpio
;
6818 /* Default gpio to DVB-C */
6819 if (!state
->antenna_dvbt
&& state
->antenna_gpio
)
6820 state
->m_gpio
|= state
->antenna_gpio
;
6822 state
->m_gpio
&= ~state
->antenna_gpio
;
6824 mutex_init(&state
->mutex
);
6826 memcpy(&state
->frontend
.ops
, &drxk_ops
, sizeof(drxk_ops
));
6827 state
->frontend
.demodulator_priv
= state
;
6831 /* Load firmware and initialize DRX-K */
6832 if (state
->microcode_name
) {
6833 if (config
->load_firmware_sync
) {
6834 const struct firmware
*fw
= NULL
;
6836 status
= request_firmware(&fw
, state
->microcode_name
,
6837 state
->i2c
->dev
.parent
);
6840 load_firmware_cb(fw
, state
);
6842 status
= request_firmware_nowait(THIS_MODULE
, 1,
6843 state
->microcode_name
,
6844 state
->i2c
->dev
.parent
,
6846 state
, load_firmware_cb
);
6848 pr_err("failed to request a firmware\n");
6852 } else if (init_drxk(state
) < 0)
6856 /* Initialize stats */
6857 p
= &state
->frontend
.dtv_property_cache
;
6858 p
->strength
.len
= 1;
6860 p
->block_error
.len
= 1;
6861 p
->block_count
.len
= 1;
6862 p
->pre_bit_error
.len
= 1;
6863 p
->pre_bit_count
.len
= 1;
6864 p
->post_bit_error
.len
= 1;
6865 p
->post_bit_count
.len
= 1;
6867 p
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
6868 p
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6869 p
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6870 p
->block_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6871 p
->pre_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6872 p
->pre_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6873 p
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6874 p
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
6876 pr_info("frontend initialized.\n");
6877 return &state
->frontend
;
6880 pr_err("not found\n");
6884 EXPORT_SYMBOL(drxk_attach
);
6886 MODULE_DESCRIPTION("DRX-K driver");
6887 MODULE_AUTHOR("Ralph Metzler");
6888 MODULE_LICENSE("GPL");