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 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/firmware.h>
30 #include <linux/i2c.h>
31 #include <linux/hardirq.h>
32 #include <asm/div64.h>
34 #include "dvb_frontend.h"
36 #include "drxk_hard.h"
38 static int PowerDownDVBT(struct drxk_state
*state
, bool setPowerMode
);
39 static int PowerDownQAM(struct drxk_state
*state
);
40 static int SetDVBTStandard(struct drxk_state
*state
,
41 enum OperationMode oMode
);
42 static int SetQAMStandard(struct drxk_state
*state
,
43 enum OperationMode oMode
);
44 static int SetQAM(struct drxk_state
*state
, u16 IntermediateFreqkHz
,
46 static int SetDVBTStandard(struct drxk_state
*state
,
47 enum OperationMode oMode
);
48 static int DVBTStart(struct drxk_state
*state
);
49 static int SetDVBT(struct drxk_state
*state
, u16 IntermediateFreqkHz
,
51 static int GetQAMLockStatus(struct drxk_state
*state
, u32
*pLockStatus
);
52 static int GetDVBTLockStatus(struct drxk_state
*state
, u32
*pLockStatus
);
53 static int SwitchAntennaToQAM(struct drxk_state
*state
);
54 static int SwitchAntennaToDVBT(struct drxk_state
*state
);
56 static bool IsDVBT(struct drxk_state
*state
)
58 return state
->m_OperationMode
== OM_DVBT
;
61 static bool IsQAM(struct drxk_state
*state
)
63 return state
->m_OperationMode
== OM_QAM_ITU_A
||
64 state
->m_OperationMode
== OM_QAM_ITU_B
||
65 state
->m_OperationMode
== OM_QAM_ITU_C
;
68 bool IsA1WithPatchCode(struct drxk_state
*state
)
70 return state
->m_DRXK_A1_PATCH_CODE
;
73 bool IsA1WithRomCode(struct drxk_state
*state
)
75 return state
->m_DRXK_A1_ROM_CODE
;
80 #define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0)
81 #define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0)
83 #define DEFAULT_MER_83 165
84 #define DEFAULT_MER_93 250
86 #ifndef DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH
87 #define DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH (0x02)
90 #ifndef DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH
91 #define DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH (0x03)
94 #define DEFAULT_DRXK_MPEG_LOCK_TIMEOUT 700
95 #define DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT 500
97 #ifndef DRXK_KI_RAGC_ATV
98 #define DRXK_KI_RAGC_ATV 4
100 #ifndef DRXK_KI_IAGC_ATV
101 #define DRXK_KI_IAGC_ATV 6
103 #ifndef DRXK_KI_DAGC_ATV
104 #define DRXK_KI_DAGC_ATV 7
107 #ifndef DRXK_KI_RAGC_QAM
108 #define DRXK_KI_RAGC_QAM 3
110 #ifndef DRXK_KI_IAGC_QAM
111 #define DRXK_KI_IAGC_QAM 4
113 #ifndef DRXK_KI_DAGC_QAM
114 #define DRXK_KI_DAGC_QAM 7
116 #ifndef DRXK_KI_RAGC_DVBT
117 #define DRXK_KI_RAGC_DVBT (IsA1WithPatchCode(state) ? 3 : 2)
119 #ifndef DRXK_KI_IAGC_DVBT
120 #define DRXK_KI_IAGC_DVBT (IsA1WithPatchCode(state) ? 4 : 2)
122 #ifndef DRXK_KI_DAGC_DVBT
123 #define DRXK_KI_DAGC_DVBT (IsA1WithPatchCode(state) ? 10 : 7)
126 #ifndef DRXK_AGC_DAC_OFFSET
127 #define DRXK_AGC_DAC_OFFSET (0x800)
130 #ifndef DRXK_BANDWIDTH_8MHZ_IN_HZ
131 #define DRXK_BANDWIDTH_8MHZ_IN_HZ (0x8B8249L)
134 #ifndef DRXK_BANDWIDTH_7MHZ_IN_HZ
135 #define DRXK_BANDWIDTH_7MHZ_IN_HZ (0x7A1200L)
138 #ifndef DRXK_BANDWIDTH_6MHZ_IN_HZ
139 #define DRXK_BANDWIDTH_6MHZ_IN_HZ (0x68A1B6L)
142 #ifndef DRXK_QAM_SYMBOLRATE_MAX
143 #define DRXK_QAM_SYMBOLRATE_MAX (7233000)
146 #define DRXK_BL_ROM_OFFSET_TAPS_DVBT 56
147 #define DRXK_BL_ROM_OFFSET_TAPS_ITU_A 64
148 #define DRXK_BL_ROM_OFFSET_TAPS_ITU_C 0x5FE0
149 #define DRXK_BL_ROM_OFFSET_TAPS_BG 24
150 #define DRXK_BL_ROM_OFFSET_TAPS_DKILLP 32
151 #define DRXK_BL_ROM_OFFSET_TAPS_NTSC 40
152 #define DRXK_BL_ROM_OFFSET_TAPS_FM 48
153 #define DRXK_BL_ROM_OFFSET_UCODE 0
155 #define DRXK_BLC_TIMEOUT 100
157 #define DRXK_BLCC_NR_ELEMENTS_TAPS 2
158 #define DRXK_BLCC_NR_ELEMENTS_UCODE 6
160 #define DRXK_BLDC_NR_ELEMENTS_TAPS 28
162 #ifndef DRXK_OFDM_NE_NOTCH_WIDTH
163 #define DRXK_OFDM_NE_NOTCH_WIDTH (4)
166 #define DRXK_QAM_SL_SIG_POWER_QAM16 (40960)
167 #define DRXK_QAM_SL_SIG_POWER_QAM32 (20480)
168 #define DRXK_QAM_SL_SIG_POWER_QAM64 (43008)
169 #define DRXK_QAM_SL_SIG_POWER_QAM128 (20992)
170 #define DRXK_QAM_SL_SIG_POWER_QAM256 (43520)
172 static unsigned int debug
;
173 module_param(debug
, int, 0644);
174 MODULE_PARM_DESC(debug
, "enable debug messages");
176 #define dprintk(level, fmt, arg...) do { \
177 if (debug >= level) \
178 printk(KERN_DEBUG "drxk: %s" fmt, __func__, ## arg); \
182 static inline u32
MulDiv32(u32 a
, u32 b
, u32 c
)
186 tmp64
= (u64
) a
* (u64
) b
;
192 inline u32
Frac28a(u32 a
, u32 c
)
198 R0
= (a
% c
) << 4; /* 32-28 == 4 shifts possible at max */
199 Q1
= a
/ c
; /* integer part, only the 4 least significant bits
200 will be visible in the result */
202 /* division using radix 16, 7 nibbles in the result */
203 for (i
= 0; i
< 7; i
++) {
204 Q1
= (Q1
<< 4) | (R0
/ c
);
214 static u32
Log10Times100(u32 x
)
216 static const u8 scale
= 15;
217 static const u8 indexWidth
= 5;
224 log2lut[n] = (1<<scale) * 200 * log2(1.0 + ((1.0/(1<<INDEXWIDTH)) * n))
225 0 <= n < ((1<<INDEXWIDTH)+1)
228 static const u32 log2lut
[] = {
230 290941, /* 290941.300628 */
231 573196, /* 573196.476418 */
232 847269, /* 847269.179851 */
233 1113620, /* 1113620.489452 */
234 1372674, /* 1372673.576986 */
235 1624818, /* 1624817.752104 */
236 1870412, /* 1870411.981536 */
237 2109788, /* 2109787.962654 */
238 2343253, /* 2343252.817465 */
239 2571091, /* 2571091.461923 */
240 2793569, /* 2793568.696416 */
241 3010931, /* 3010931.055901 */
242 3223408, /* 3223408.452106 */
243 3431216, /* 3431215.635215 */
244 3634553, /* 3634553.498355 */
245 3833610, /* 3833610.244726 */
246 4028562, /* 4028562.434393 */
247 4219576, /* 4219575.925308 */
248 4406807, /* 4406806.721144 */
249 4590402, /* 4590401.736809 */
250 4770499, /* 4770499.491025 */
251 4947231, /* 4947230.734179 */
252 5120719, /* 5120719.018555 */
253 5291081, /* 5291081.217197 */
254 5458428, /* 5458427.996830 */
255 5622864, /* 5622864.249668 */
256 5784489, /* 5784489.488298 */
257 5943398, /* 5943398.207380 */
258 6099680, /* 6099680.215452 */
259 6253421, /* 6253420.939751 */
260 6404702, /* 6404701.706649 */
261 6553600, /* 6553600.000000 */
268 /* Scale x (normalize) */
269 /* computing y in log(x/y) = log(x) - log(y) */
270 if ((x
& ((0xffffffff) << (scale
+ 1))) == 0) {
271 for (k
= scale
; k
> 0; k
--) {
272 if (x
& (((u32
) 1) << scale
))
277 for (k
= scale
; k
< 31; k
++) {
278 if ((x
& (((u32
) (-1)) << (scale
+ 1))) == 0)
284 Now x has binary point between bit[scale] and bit[scale-1]
285 and 1.0 <= x < 2.0 */
287 /* correction for divison: log(x) = log(x/y)+log(y) */
288 y
= k
* ((((u32
) 1) << scale
) * 200);
290 /* remove integer part */
291 x
&= ((((u32
) 1) << scale
) - 1);
293 i
= (u8
) (x
>> (scale
- indexWidth
));
294 /* compute delta (x - a) */
295 d
= x
& ((((u32
) 1) << (scale
- indexWidth
)) - 1);
296 /* compute log, multiplication (d* (..)) must be within range ! */
298 ((d
* (log2lut
[i
+ 1] - log2lut
[i
])) >> (scale
- indexWidth
));
299 /* Conver to log10() */
300 y
/= 108853; /* (log2(10) << scale) */
308 /****************************************************************************/
309 /* I2C **********************************************************************/
310 /****************************************************************************/
312 static int drxk_i2c_lock(struct drxk_state
*state
)
314 i2c_lock_adapter(state
->i2c
);
315 state
->drxk_i2c_exclusive_lock
= true;
320 static void drxk_i2c_unlock(struct drxk_state
*state
)
322 if (!state
->drxk_i2c_exclusive_lock
)
325 i2c_unlock_adapter(state
->i2c
);
326 state
->drxk_i2c_exclusive_lock
= false;
329 static int drxk_i2c_transfer(struct drxk_state
*state
, struct i2c_msg
*msgs
,
332 if (state
->drxk_i2c_exclusive_lock
)
333 return __i2c_transfer(state
->i2c
, msgs
, len
);
335 return i2c_transfer(state
->i2c
, msgs
, len
);
338 static int i2c_read1(struct drxk_state
*state
, u8 adr
, u8
*val
)
340 struct i2c_msg msgs
[1] = { {.addr
= adr
, .flags
= I2C_M_RD
,
341 .buf
= val
, .len
= 1}
344 return drxk_i2c_transfer(state
, msgs
, 1);
347 static int i2c_write(struct drxk_state
*state
, u8 adr
, u8
*data
, int len
)
350 struct i2c_msg msg
= {
351 .addr
= adr
, .flags
= 0, .buf
= data
, .len
= len
};
356 for (i
= 0; i
< len
; i
++)
357 printk(KERN_CONT
" %02x", data
[i
]);
358 printk(KERN_CONT
"\n");
360 status
= drxk_i2c_transfer(state
, &msg
, 1);
361 if (status
>= 0 && status
!= 1)
365 printk(KERN_ERR
"drxk: i2c write error at addr 0x%02x\n", adr
);
370 static int i2c_read(struct drxk_state
*state
,
371 u8 adr
, u8
*msg
, int len
, u8
*answ
, int alen
)
374 struct i2c_msg msgs
[2] = {
375 {.addr
= adr
, .flags
= 0,
376 .buf
= msg
, .len
= len
},
377 {.addr
= adr
, .flags
= I2C_M_RD
,
378 .buf
= answ
, .len
= alen
}
381 status
= drxk_i2c_transfer(state
, msgs
, 2);
384 printk(KERN_CONT
": ERROR!\n");
388 printk(KERN_ERR
"drxk: i2c read error at addr 0x%02x\n", adr
);
393 dprintk(2, ": read from");
394 for (i
= 0; i
< len
; i
++)
395 printk(KERN_CONT
" %02x", msg
[i
]);
396 printk(KERN_CONT
", value = ");
397 for (i
= 0; i
< alen
; i
++)
398 printk(KERN_CONT
" %02x", answ
[i
]);
399 printk(KERN_CONT
"\n");
404 static int read16_flags(struct drxk_state
*state
, u32 reg
, u16
*data
, u8 flags
)
407 u8 adr
= state
->demod_address
, mm1
[4], mm2
[2], len
;
409 if (state
->single_master
)
412 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
413 mm1
[0] = (((reg
<< 1) & 0xFF) | 0x01);
414 mm1
[1] = ((reg
>> 16) & 0xFF);
415 mm1
[2] = ((reg
>> 24) & 0xFF) | flags
;
416 mm1
[3] = ((reg
>> 7) & 0xFF);
419 mm1
[0] = ((reg
<< 1) & 0xFF);
420 mm1
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
423 dprintk(2, "(0x%08x, 0x%02x)\n", reg
, flags
);
424 status
= i2c_read(state
, adr
, mm1
, len
, mm2
, 2);
428 *data
= mm2
[0] | (mm2
[1] << 8);
433 static int read16(struct drxk_state
*state
, u32 reg
, u16
*data
)
435 return read16_flags(state
, reg
, data
, 0);
438 static int read32_flags(struct drxk_state
*state
, u32 reg
, u32
*data
, u8 flags
)
441 u8 adr
= state
->demod_address
, mm1
[4], mm2
[4], len
;
443 if (state
->single_master
)
446 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
447 mm1
[0] = (((reg
<< 1) & 0xFF) | 0x01);
448 mm1
[1] = ((reg
>> 16) & 0xFF);
449 mm1
[2] = ((reg
>> 24) & 0xFF) | flags
;
450 mm1
[3] = ((reg
>> 7) & 0xFF);
453 mm1
[0] = ((reg
<< 1) & 0xFF);
454 mm1
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
457 dprintk(2, "(0x%08x, 0x%02x)\n", reg
, flags
);
458 status
= i2c_read(state
, adr
, mm1
, len
, mm2
, 4);
462 *data
= mm2
[0] | (mm2
[1] << 8) |
463 (mm2
[2] << 16) | (mm2
[3] << 24);
468 static int read32(struct drxk_state
*state
, u32 reg
, u32
*data
)
470 return read32_flags(state
, reg
, data
, 0);
473 static int write16_flags(struct drxk_state
*state
, u32 reg
, u16 data
, u8 flags
)
475 u8 adr
= state
->demod_address
, mm
[6], len
;
477 if (state
->single_master
)
479 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
480 mm
[0] = (((reg
<< 1) & 0xFF) | 0x01);
481 mm
[1] = ((reg
>> 16) & 0xFF);
482 mm
[2] = ((reg
>> 24) & 0xFF) | flags
;
483 mm
[3] = ((reg
>> 7) & 0xFF);
486 mm
[0] = ((reg
<< 1) & 0xFF);
487 mm
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
490 mm
[len
] = data
& 0xff;
491 mm
[len
+ 1] = (data
>> 8) & 0xff;
493 dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg
, data
, flags
);
494 return i2c_write(state
, adr
, mm
, len
+ 2);
497 static int write16(struct drxk_state
*state
, u32 reg
, u16 data
)
499 return write16_flags(state
, reg
, data
, 0);
502 static int write32_flags(struct drxk_state
*state
, u32 reg
, u32 data
, u8 flags
)
504 u8 adr
= state
->demod_address
, mm
[8], len
;
506 if (state
->single_master
)
508 if (DRXDAP_FASI_LONG_FORMAT(reg
) || (flags
!= 0)) {
509 mm
[0] = (((reg
<< 1) & 0xFF) | 0x01);
510 mm
[1] = ((reg
>> 16) & 0xFF);
511 mm
[2] = ((reg
>> 24) & 0xFF) | flags
;
512 mm
[3] = ((reg
>> 7) & 0xFF);
515 mm
[0] = ((reg
<< 1) & 0xFF);
516 mm
[1] = (((reg
>> 16) & 0x0F) | ((reg
>> 18) & 0xF0));
519 mm
[len
] = data
& 0xff;
520 mm
[len
+ 1] = (data
>> 8) & 0xff;
521 mm
[len
+ 2] = (data
>> 16) & 0xff;
522 mm
[len
+ 3] = (data
>> 24) & 0xff;
523 dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg
, data
, flags
);
525 return i2c_write(state
, adr
, mm
, len
+ 4);
528 static int write32(struct drxk_state
*state
, u32 reg
, u32 data
)
530 return write32_flags(state
, reg
, data
, 0);
533 static int write_block(struct drxk_state
*state
, u32 Address
,
534 const int BlockSize
, const u8 pBlock
[])
536 int status
= 0, BlkSize
= BlockSize
;
539 if (state
->single_master
)
542 while (BlkSize
> 0) {
543 int Chunk
= BlkSize
> state
->m_ChunkSize
?
544 state
->m_ChunkSize
: BlkSize
;
545 u8
*AdrBuf
= &state
->Chunk
[0];
548 if (DRXDAP_FASI_LONG_FORMAT(Address
) || (Flags
!= 0)) {
549 AdrBuf
[0] = (((Address
<< 1) & 0xFF) | 0x01);
550 AdrBuf
[1] = ((Address
>> 16) & 0xFF);
551 AdrBuf
[2] = ((Address
>> 24) & 0xFF);
552 AdrBuf
[3] = ((Address
>> 7) & 0xFF);
555 if (Chunk
== state
->m_ChunkSize
)
558 AdrBuf
[0] = ((Address
<< 1) & 0xFF);
559 AdrBuf
[1] = (((Address
>> 16) & 0x0F) |
560 ((Address
>> 18) & 0xF0));
563 memcpy(&state
->Chunk
[AdrLength
], pBlock
, Chunk
);
564 dprintk(2, "(0x%08x, 0x%02x)\n", Address
, Flags
);
568 for (i
= 0; i
< Chunk
; i
++)
569 printk(KERN_CONT
" %02x", pBlock
[i
]);
570 printk(KERN_CONT
"\n");
572 status
= i2c_write(state
, state
->demod_address
,
573 &state
->Chunk
[0], Chunk
+ AdrLength
);
575 printk(KERN_ERR
"drxk: %s: i2c write error at addr 0x%02x\n",
580 Address
+= (Chunk
>> 1);
586 #ifndef DRXK_MAX_RETRIES_POWERUP
587 #define DRXK_MAX_RETRIES_POWERUP 20
590 int PowerUpDevice(struct drxk_state
*state
)
598 status
= i2c_read1(state
, state
->demod_address
, &data
);
602 status
= i2c_write(state
, state
->demod_address
,
608 status
= i2c_read1(state
, state
->demod_address
,
610 } while (status
< 0 &&
611 (retryCount
< DRXK_MAX_RETRIES_POWERUP
));
612 if (status
< 0 && retryCount
>= DRXK_MAX_RETRIES_POWERUP
)
616 /* Make sure all clk domains are active */
617 status
= write16(state
, SIO_CC_PWD_MODE__A
, SIO_CC_PWD_MODE_LEVEL_NONE
);
620 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
623 /* Enable pll lock tests */
624 status
= write16(state
, SIO_CC_PLL_LOCK__A
, 1);
628 state
->m_currentPowerMode
= DRX_POWER_UP
;
632 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
638 static int init_state(struct drxk_state
*state
)
641 * FIXME: most (all?) of the values bellow should be moved into
642 * struct drxk_config, as they are probably board-specific
644 u32 ulVSBIfAgcMode
= DRXK_AGC_CTRL_AUTO
;
645 u32 ulVSBIfAgcOutputLevel
= 0;
646 u32 ulVSBIfAgcMinLevel
= 0;
647 u32 ulVSBIfAgcMaxLevel
= 0x7FFF;
648 u32 ulVSBIfAgcSpeed
= 3;
650 u32 ulVSBRfAgcMode
= DRXK_AGC_CTRL_AUTO
;
651 u32 ulVSBRfAgcOutputLevel
= 0;
652 u32 ulVSBRfAgcMinLevel
= 0;
653 u32 ulVSBRfAgcMaxLevel
= 0x7FFF;
654 u32 ulVSBRfAgcSpeed
= 3;
655 u32 ulVSBRfAgcTop
= 9500;
656 u32 ulVSBRfAgcCutOffCurrent
= 4000;
658 u32 ulATVIfAgcMode
= DRXK_AGC_CTRL_AUTO
;
659 u32 ulATVIfAgcOutputLevel
= 0;
660 u32 ulATVIfAgcMinLevel
= 0;
661 u32 ulATVIfAgcMaxLevel
= 0;
662 u32 ulATVIfAgcSpeed
= 3;
664 u32 ulATVRfAgcMode
= DRXK_AGC_CTRL_OFF
;
665 u32 ulATVRfAgcOutputLevel
= 0;
666 u32 ulATVRfAgcMinLevel
= 0;
667 u32 ulATVRfAgcMaxLevel
= 0;
668 u32 ulATVRfAgcTop
= 9500;
669 u32 ulATVRfAgcCutOffCurrent
= 4000;
670 u32 ulATVRfAgcSpeed
= 3;
672 u32 ulQual83
= DEFAULT_MER_83
;
673 u32 ulQual93
= DEFAULT_MER_93
;
675 u32 ulMpegLockTimeOut
= DEFAULT_DRXK_MPEG_LOCK_TIMEOUT
;
676 u32 ulDemodLockTimeOut
= DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT
;
678 /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
679 /* io_pad_cfg_mode output mode is drive always */
680 /* io_pad_cfg_drive is set to power 2 (23 mA) */
681 u32 ulGPIOCfg
= 0x0113;
682 u32 ulInvertTSClock
= 0;
683 u32 ulTSDataStrength
= DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH
;
684 u32 ulDVBTBitrate
= 50000000;
685 u32 ulDVBCBitrate
= DRXK_QAM_SYMBOLRATE_MAX
* 8;
687 u32 ulInsertRSByte
= 0;
694 state
->m_hasLNA
= false;
695 state
->m_hasDVBT
= false;
696 state
->m_hasDVBC
= false;
697 state
->m_hasATV
= false;
698 state
->m_hasOOB
= false;
699 state
->m_hasAudio
= false;
701 if (!state
->m_ChunkSize
)
702 state
->m_ChunkSize
= 124;
704 state
->m_oscClockFreq
= 0;
705 state
->m_smartAntInverted
= false;
706 state
->m_bPDownOpenBridge
= false;
708 /* real system clock frequency in kHz */
709 state
->m_sysClockFreq
= 151875;
710 /* Timing div, 250ns/Psys */
711 /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */
712 state
->m_HICfgTimingDiv
= ((state
->m_sysClockFreq
/ 1000) *
713 HI_I2C_DELAY
) / 1000;
715 if (state
->m_HICfgTimingDiv
> SIO_HI_RA_RAM_PAR_2_CFG_DIV__M
)
716 state
->m_HICfgTimingDiv
= SIO_HI_RA_RAM_PAR_2_CFG_DIV__M
;
717 state
->m_HICfgWakeUpKey
= (state
->demod_address
<< 1);
718 /* port/bridge/power down ctrl */
719 state
->m_HICfgCtrl
= SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE
;
721 state
->m_bPowerDown
= (ulPowerDown
!= 0);
723 state
->m_DRXK_A1_PATCH_CODE
= false;
724 state
->m_DRXK_A1_ROM_CODE
= false;
725 state
->m_DRXK_A2_ROM_CODE
= false;
726 state
->m_DRXK_A3_ROM_CODE
= false;
727 state
->m_DRXK_A2_PATCH_CODE
= false;
728 state
->m_DRXK_A3_PATCH_CODE
= false;
730 /* Init AGC and PGA parameters */
732 state
->m_vsbIfAgcCfg
.ctrlMode
= (ulVSBIfAgcMode
);
733 state
->m_vsbIfAgcCfg
.outputLevel
= (ulVSBIfAgcOutputLevel
);
734 state
->m_vsbIfAgcCfg
.minOutputLevel
= (ulVSBIfAgcMinLevel
);
735 state
->m_vsbIfAgcCfg
.maxOutputLevel
= (ulVSBIfAgcMaxLevel
);
736 state
->m_vsbIfAgcCfg
.speed
= (ulVSBIfAgcSpeed
);
737 state
->m_vsbPgaCfg
= 140;
740 state
->m_vsbRfAgcCfg
.ctrlMode
= (ulVSBRfAgcMode
);
741 state
->m_vsbRfAgcCfg
.outputLevel
= (ulVSBRfAgcOutputLevel
);
742 state
->m_vsbRfAgcCfg
.minOutputLevel
= (ulVSBRfAgcMinLevel
);
743 state
->m_vsbRfAgcCfg
.maxOutputLevel
= (ulVSBRfAgcMaxLevel
);
744 state
->m_vsbRfAgcCfg
.speed
= (ulVSBRfAgcSpeed
);
745 state
->m_vsbRfAgcCfg
.top
= (ulVSBRfAgcTop
);
746 state
->m_vsbRfAgcCfg
.cutOffCurrent
= (ulVSBRfAgcCutOffCurrent
);
747 state
->m_vsbPreSawCfg
.reference
= 0x07;
748 state
->m_vsbPreSawCfg
.usePreSaw
= true;
750 state
->m_Quality83percent
= DEFAULT_MER_83
;
751 state
->m_Quality93percent
= DEFAULT_MER_93
;
752 if (ulQual93
<= 500 && ulQual83
< ulQual93
) {
753 state
->m_Quality83percent
= ulQual83
;
754 state
->m_Quality93percent
= ulQual93
;
758 state
->m_atvIfAgcCfg
.ctrlMode
= (ulATVIfAgcMode
);
759 state
->m_atvIfAgcCfg
.outputLevel
= (ulATVIfAgcOutputLevel
);
760 state
->m_atvIfAgcCfg
.minOutputLevel
= (ulATVIfAgcMinLevel
);
761 state
->m_atvIfAgcCfg
.maxOutputLevel
= (ulATVIfAgcMaxLevel
);
762 state
->m_atvIfAgcCfg
.speed
= (ulATVIfAgcSpeed
);
765 state
->m_atvRfAgcCfg
.ctrlMode
= (ulATVRfAgcMode
);
766 state
->m_atvRfAgcCfg
.outputLevel
= (ulATVRfAgcOutputLevel
);
767 state
->m_atvRfAgcCfg
.minOutputLevel
= (ulATVRfAgcMinLevel
);
768 state
->m_atvRfAgcCfg
.maxOutputLevel
= (ulATVRfAgcMaxLevel
);
769 state
->m_atvRfAgcCfg
.speed
= (ulATVRfAgcSpeed
);
770 state
->m_atvRfAgcCfg
.top
= (ulATVRfAgcTop
);
771 state
->m_atvRfAgcCfg
.cutOffCurrent
= (ulATVRfAgcCutOffCurrent
);
772 state
->m_atvPreSawCfg
.reference
= 0x04;
773 state
->m_atvPreSawCfg
.usePreSaw
= true;
777 state
->m_dvbtRfAgcCfg
.ctrlMode
= DRXK_AGC_CTRL_OFF
;
778 state
->m_dvbtRfAgcCfg
.outputLevel
= 0;
779 state
->m_dvbtRfAgcCfg
.minOutputLevel
= 0;
780 state
->m_dvbtRfAgcCfg
.maxOutputLevel
= 0xFFFF;
781 state
->m_dvbtRfAgcCfg
.top
= 0x2100;
782 state
->m_dvbtRfAgcCfg
.cutOffCurrent
= 4000;
783 state
->m_dvbtRfAgcCfg
.speed
= 1;
787 state
->m_dvbtIfAgcCfg
.ctrlMode
= DRXK_AGC_CTRL_AUTO
;
788 state
->m_dvbtIfAgcCfg
.outputLevel
= 0;
789 state
->m_dvbtIfAgcCfg
.minOutputLevel
= 0;
790 state
->m_dvbtIfAgcCfg
.maxOutputLevel
= 9000;
791 state
->m_dvbtIfAgcCfg
.top
= 13424;
792 state
->m_dvbtIfAgcCfg
.cutOffCurrent
= 0;
793 state
->m_dvbtIfAgcCfg
.speed
= 3;
794 state
->m_dvbtIfAgcCfg
.FastClipCtrlDelay
= 30;
795 state
->m_dvbtIfAgcCfg
.IngainTgtMax
= 30000;
796 /* state->m_dvbtPgaCfg = 140; */
798 state
->m_dvbtPreSawCfg
.reference
= 4;
799 state
->m_dvbtPreSawCfg
.usePreSaw
= false;
802 state
->m_qamRfAgcCfg
.ctrlMode
= DRXK_AGC_CTRL_OFF
;
803 state
->m_qamRfAgcCfg
.outputLevel
= 0;
804 state
->m_qamRfAgcCfg
.minOutputLevel
= 6023;
805 state
->m_qamRfAgcCfg
.maxOutputLevel
= 27000;
806 state
->m_qamRfAgcCfg
.top
= 0x2380;
807 state
->m_qamRfAgcCfg
.cutOffCurrent
= 4000;
808 state
->m_qamRfAgcCfg
.speed
= 3;
811 state
->m_qamIfAgcCfg
.ctrlMode
= DRXK_AGC_CTRL_AUTO
;
812 state
->m_qamIfAgcCfg
.outputLevel
= 0;
813 state
->m_qamIfAgcCfg
.minOutputLevel
= 0;
814 state
->m_qamIfAgcCfg
.maxOutputLevel
= 9000;
815 state
->m_qamIfAgcCfg
.top
= 0x0511;
816 state
->m_qamIfAgcCfg
.cutOffCurrent
= 0;
817 state
->m_qamIfAgcCfg
.speed
= 3;
818 state
->m_qamIfAgcCfg
.IngainTgtMax
= 5119;
819 state
->m_qamIfAgcCfg
.FastClipCtrlDelay
= 50;
821 state
->m_qamPgaCfg
= 140;
822 state
->m_qamPreSawCfg
.reference
= 4;
823 state
->m_qamPreSawCfg
.usePreSaw
= false;
825 state
->m_OperationMode
= OM_NONE
;
826 state
->m_DrxkState
= DRXK_UNINITIALIZED
;
828 /* MPEG output configuration */
829 state
->m_enableMPEGOutput
= true; /* If TRUE; enable MPEG ouput */
830 state
->m_insertRSByte
= false; /* If TRUE; insert RS byte */
831 state
->m_invertDATA
= false; /* If TRUE; invert DATA signals */
832 state
->m_invertERR
= false; /* If TRUE; invert ERR signal */
833 state
->m_invertSTR
= false; /* If TRUE; invert STR signals */
834 state
->m_invertVAL
= false; /* If TRUE; invert VAL signals */
835 state
->m_invertCLK
= (ulInvertTSClock
!= 0); /* If TRUE; invert CLK signals */
837 /* If TRUE; static MPEG clockrate will be used;
838 otherwise clockrate will adapt to the bitrate of the TS */
840 state
->m_DVBTBitrate
= ulDVBTBitrate
;
841 state
->m_DVBCBitrate
= ulDVBCBitrate
;
843 state
->m_TSDataStrength
= (ulTSDataStrength
& 0x07);
845 /* Maximum bitrate in b/s in case static clockrate is selected */
846 state
->m_mpegTsStaticBitrate
= 19392658;
847 state
->m_disableTEIhandling
= false;
850 state
->m_insertRSByte
= true;
852 state
->m_MpegLockTimeOut
= DEFAULT_DRXK_MPEG_LOCK_TIMEOUT
;
853 if (ulMpegLockTimeOut
< 10000)
854 state
->m_MpegLockTimeOut
= ulMpegLockTimeOut
;
855 state
->m_DemodLockTimeOut
= DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT
;
856 if (ulDemodLockTimeOut
< 10000)
857 state
->m_DemodLockTimeOut
= ulDemodLockTimeOut
;
860 state
->m_Constellation
= DRX_CONSTELLATION_AUTO
;
861 state
->m_qamInterleaveMode
= DRXK_QAM_I12_J17
;
862 state
->m_fecRsPlen
= 204 * 8; /* fecRsPlen annex A */
863 state
->m_fecRsPrescale
= 1;
865 state
->m_sqiSpeed
= DRXK_DVBT_SQI_SPEED_MEDIUM
;
866 state
->m_agcFastClipCtrlDelay
= 0;
868 state
->m_GPIOCfg
= (ulGPIOCfg
);
870 state
->m_bPowerDown
= false;
871 state
->m_currentPowerMode
= DRX_POWER_DOWN
;
873 state
->m_rfmirror
= (ulRfMirror
== 0);
874 state
->m_IfAgcPol
= false;
878 static int DRXX_Open(struct drxk_state
*state
)
886 /* stop lock indicator process */
887 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
890 /* Check device id */
891 status
= read16(state
, SIO_TOP_COMM_KEY__A
, &key
);
894 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
897 status
= read32(state
, SIO_TOP_JTAGID_LO__A
, &jtag
);
900 status
= read16(state
, SIO_PDR_UIO_IN_HI__A
, &bid
);
903 status
= write16(state
, SIO_TOP_COMM_KEY__A
, key
);
906 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
910 static int GetDeviceCapabilities(struct drxk_state
*state
)
912 u16 sioPdrOhwCfg
= 0;
913 u32 sioTopJtagidLo
= 0;
915 const char *spin
= "";
920 /* stop lock indicator process */
921 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
924 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0xFABA);
927 status
= read16(state
, SIO_PDR_OHW_CFG__A
, &sioPdrOhwCfg
);
930 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
934 switch ((sioPdrOhwCfg
& SIO_PDR_OHW_CFG_FREF_SEL__M
)) {
936 /* ignore (bypass ?) */
940 state
->m_oscClockFreq
= 27000;
944 state
->m_oscClockFreq
= 20250;
948 state
->m_oscClockFreq
= 20250;
951 printk(KERN_ERR
"drxk: Clock Frequency is unkonwn\n");
955 Determine device capabilities
958 status
= read32(state
, SIO_TOP_JTAGID_LO__A
, &sioTopJtagidLo
);
962 printk(KERN_INFO
"drxk: status = 0x%08x\n", sioTopJtagidLo
);
965 switch ((sioTopJtagidLo
>> 29) & 0xF) {
967 state
->m_deviceSpin
= DRXK_SPIN_A1
;
971 state
->m_deviceSpin
= DRXK_SPIN_A2
;
975 state
->m_deviceSpin
= DRXK_SPIN_A3
;
979 state
->m_deviceSpin
= DRXK_SPIN_UNKNOWN
;
981 printk(KERN_ERR
"drxk: Spin %d unknown\n",
982 (sioTopJtagidLo
>> 29) & 0xF);
985 switch ((sioTopJtagidLo
>> 12) & 0xFF) {
987 /* typeId = DRX3913K_TYPE_ID */
988 state
->m_hasLNA
= false;
989 state
->m_hasOOB
= false;
990 state
->m_hasATV
= false;
991 state
->m_hasAudio
= false;
992 state
->m_hasDVBT
= true;
993 state
->m_hasDVBC
= true;
994 state
->m_hasSAWSW
= true;
995 state
->m_hasGPIO2
= false;
996 state
->m_hasGPIO1
= false;
997 state
->m_hasIRQN
= false;
1000 /* typeId = DRX3915K_TYPE_ID */
1001 state
->m_hasLNA
= false;
1002 state
->m_hasOOB
= false;
1003 state
->m_hasATV
= true;
1004 state
->m_hasAudio
= false;
1005 state
->m_hasDVBT
= true;
1006 state
->m_hasDVBC
= false;
1007 state
->m_hasSAWSW
= true;
1008 state
->m_hasGPIO2
= true;
1009 state
->m_hasGPIO1
= true;
1010 state
->m_hasIRQN
= false;
1013 /* typeId = DRX3916K_TYPE_ID */
1014 state
->m_hasLNA
= false;
1015 state
->m_hasOOB
= false;
1016 state
->m_hasATV
= true;
1017 state
->m_hasAudio
= false;
1018 state
->m_hasDVBT
= true;
1019 state
->m_hasDVBC
= false;
1020 state
->m_hasSAWSW
= true;
1021 state
->m_hasGPIO2
= true;
1022 state
->m_hasGPIO1
= true;
1023 state
->m_hasIRQN
= false;
1026 /* typeId = DRX3918K_TYPE_ID */
1027 state
->m_hasLNA
= false;
1028 state
->m_hasOOB
= false;
1029 state
->m_hasATV
= true;
1030 state
->m_hasAudio
= true;
1031 state
->m_hasDVBT
= true;
1032 state
->m_hasDVBC
= false;
1033 state
->m_hasSAWSW
= true;
1034 state
->m_hasGPIO2
= true;
1035 state
->m_hasGPIO1
= true;
1036 state
->m_hasIRQN
= false;
1039 /* typeId = DRX3921K_TYPE_ID */
1040 state
->m_hasLNA
= false;
1041 state
->m_hasOOB
= false;
1042 state
->m_hasATV
= true;
1043 state
->m_hasAudio
= true;
1044 state
->m_hasDVBT
= true;
1045 state
->m_hasDVBC
= true;
1046 state
->m_hasSAWSW
= true;
1047 state
->m_hasGPIO2
= true;
1048 state
->m_hasGPIO1
= true;
1049 state
->m_hasIRQN
= false;
1052 /* typeId = DRX3923K_TYPE_ID */
1053 state
->m_hasLNA
= false;
1054 state
->m_hasOOB
= false;
1055 state
->m_hasATV
= true;
1056 state
->m_hasAudio
= true;
1057 state
->m_hasDVBT
= true;
1058 state
->m_hasDVBC
= true;
1059 state
->m_hasSAWSW
= true;
1060 state
->m_hasGPIO2
= true;
1061 state
->m_hasGPIO1
= true;
1062 state
->m_hasIRQN
= false;
1065 /* typeId = DRX3925K_TYPE_ID */
1066 state
->m_hasLNA
= false;
1067 state
->m_hasOOB
= false;
1068 state
->m_hasATV
= true;
1069 state
->m_hasAudio
= true;
1070 state
->m_hasDVBT
= true;
1071 state
->m_hasDVBC
= true;
1072 state
->m_hasSAWSW
= true;
1073 state
->m_hasGPIO2
= true;
1074 state
->m_hasGPIO1
= true;
1075 state
->m_hasIRQN
= false;
1078 /* typeId = DRX3926K_TYPE_ID */
1079 state
->m_hasLNA
= false;
1080 state
->m_hasOOB
= false;
1081 state
->m_hasATV
= true;
1082 state
->m_hasAudio
= false;
1083 state
->m_hasDVBT
= true;
1084 state
->m_hasDVBC
= true;
1085 state
->m_hasSAWSW
= true;
1086 state
->m_hasGPIO2
= true;
1087 state
->m_hasGPIO1
= true;
1088 state
->m_hasIRQN
= false;
1091 printk(KERN_ERR
"drxk: DeviceID 0x%02x not supported\n",
1092 ((sioTopJtagidLo
>> 12) & 0xFF));
1098 "drxk: detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n",
1099 ((sioTopJtagidLo
>> 12) & 0xFF), spin
,
1100 state
->m_oscClockFreq
/ 1000,
1101 state
->m_oscClockFreq
% 1000);
1105 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1111 static int HI_Command(struct drxk_state
*state
, u16 cmd
, u16
*pResult
)
1119 status
= write16(state
, SIO_HI_RA_RAM_CMD__A
, cmd
);
1122 if (cmd
== SIO_HI_RA_RAM_CMD_RESET
)
1126 (bool) ((cmd
== SIO_HI_RA_RAM_CMD_CONFIG
) &&
1127 ((state
->m_HICfgCtrl
) &
1128 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M
) ==
1129 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
);
1130 if (powerdown_cmd
== false) {
1131 /* Wait until command rdy */
1138 status
= read16(state
, SIO_HI_RA_RAM_CMD__A
,
1140 } while ((status
< 0) && (retryCount
< DRXK_MAX_RETRIES
)
1144 status
= read16(state
, SIO_HI_RA_RAM_RES__A
, pResult
);
1148 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1153 static int HI_CfgCommand(struct drxk_state
*state
)
1159 mutex_lock(&state
->mutex
);
1161 status
= write16(state
, SIO_HI_RA_RAM_PAR_6__A
, state
->m_HICfgTimeout
);
1164 status
= write16(state
, SIO_HI_RA_RAM_PAR_5__A
, state
->m_HICfgCtrl
);
1167 status
= write16(state
, SIO_HI_RA_RAM_PAR_4__A
, state
->m_HICfgWakeUpKey
);
1170 status
= write16(state
, SIO_HI_RA_RAM_PAR_3__A
, state
->m_HICfgBridgeDelay
);
1173 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
, state
->m_HICfgTimingDiv
);
1176 status
= write16(state
, SIO_HI_RA_RAM_PAR_1__A
, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY
);
1179 status
= HI_Command(state
, SIO_HI_RA_RAM_CMD_CONFIG
, 0);
1183 state
->m_HICfgCtrl
&= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
1185 mutex_unlock(&state
->mutex
);
1187 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1191 static int InitHI(struct drxk_state
*state
)
1195 state
->m_HICfgWakeUpKey
= (state
->demod_address
<< 1);
1196 state
->m_HICfgTimeout
= 0x96FF;
1197 /* port/bridge/power down ctrl */
1198 state
->m_HICfgCtrl
= SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE
;
1200 return HI_CfgCommand(state
);
1203 static int MPEGTSConfigurePins(struct drxk_state
*state
, bool mpegEnable
)
1206 u16 sioPdrMclkCfg
= 0;
1207 u16 sioPdrMdxCfg
= 0;
1210 dprintk(1, ": mpeg %s, %s mode\n",
1211 mpegEnable
? "enable" : "disable",
1212 state
->m_enableParallel
? "parallel" : "serial");
1214 /* stop lock indicator process */
1215 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
1219 /* MPEG TS pad configuration */
1220 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0xFABA);
1224 if (mpegEnable
== false) {
1225 /* Set MPEG TS pads to inputmode */
1226 status
= write16(state
, SIO_PDR_MSTRT_CFG__A
, 0x0000);
1229 status
= write16(state
, SIO_PDR_MERR_CFG__A
, 0x0000);
1232 status
= write16(state
, SIO_PDR_MCLK_CFG__A
, 0x0000);
1235 status
= write16(state
, SIO_PDR_MVAL_CFG__A
, 0x0000);
1238 status
= write16(state
, SIO_PDR_MD0_CFG__A
, 0x0000);
1241 status
= write16(state
, SIO_PDR_MD1_CFG__A
, 0x0000);
1244 status
= write16(state
, SIO_PDR_MD2_CFG__A
, 0x0000);
1247 status
= write16(state
, SIO_PDR_MD3_CFG__A
, 0x0000);
1250 status
= write16(state
, SIO_PDR_MD4_CFG__A
, 0x0000);
1253 status
= write16(state
, SIO_PDR_MD5_CFG__A
, 0x0000);
1256 status
= write16(state
, SIO_PDR_MD6_CFG__A
, 0x0000);
1259 status
= write16(state
, SIO_PDR_MD7_CFG__A
, 0x0000);
1263 /* Enable MPEG output */
1265 ((state
->m_TSDataStrength
<<
1266 SIO_PDR_MD0_CFG_DRIVE__B
) | 0x0003);
1267 sioPdrMclkCfg
= ((state
->m_TSClockkStrength
<<
1268 SIO_PDR_MCLK_CFG_DRIVE__B
) |
1271 status
= write16(state
, SIO_PDR_MSTRT_CFG__A
, sioPdrMdxCfg
);
1275 if (state
->enable_merr_cfg
)
1276 err_cfg
= sioPdrMdxCfg
;
1278 status
= write16(state
, SIO_PDR_MERR_CFG__A
, err_cfg
);
1281 status
= write16(state
, SIO_PDR_MVAL_CFG__A
, err_cfg
);
1285 if (state
->m_enableParallel
== true) {
1286 /* paralel -> enable MD1 to MD7 */
1287 status
= write16(state
, SIO_PDR_MD1_CFG__A
, sioPdrMdxCfg
);
1290 status
= write16(state
, SIO_PDR_MD2_CFG__A
, sioPdrMdxCfg
);
1293 status
= write16(state
, SIO_PDR_MD3_CFG__A
, sioPdrMdxCfg
);
1296 status
= write16(state
, SIO_PDR_MD4_CFG__A
, sioPdrMdxCfg
);
1299 status
= write16(state
, SIO_PDR_MD5_CFG__A
, sioPdrMdxCfg
);
1302 status
= write16(state
, SIO_PDR_MD6_CFG__A
, sioPdrMdxCfg
);
1305 status
= write16(state
, SIO_PDR_MD7_CFG__A
, sioPdrMdxCfg
);
1309 sioPdrMdxCfg
= ((state
->m_TSDataStrength
<<
1310 SIO_PDR_MD0_CFG_DRIVE__B
)
1312 /* serial -> disable MD1 to MD7 */
1313 status
= write16(state
, SIO_PDR_MD1_CFG__A
, 0x0000);
1316 status
= write16(state
, SIO_PDR_MD2_CFG__A
, 0x0000);
1319 status
= write16(state
, SIO_PDR_MD3_CFG__A
, 0x0000);
1322 status
= write16(state
, SIO_PDR_MD4_CFG__A
, 0x0000);
1325 status
= write16(state
, SIO_PDR_MD5_CFG__A
, 0x0000);
1328 status
= write16(state
, SIO_PDR_MD6_CFG__A
, 0x0000);
1331 status
= write16(state
, SIO_PDR_MD7_CFG__A
, 0x0000);
1335 status
= write16(state
, SIO_PDR_MCLK_CFG__A
, sioPdrMclkCfg
);
1338 status
= write16(state
, SIO_PDR_MD0_CFG__A
, sioPdrMdxCfg
);
1342 /* Enable MB output over MPEG pads and ctl input */
1343 status
= write16(state
, SIO_PDR_MON_CFG__A
, 0x0000);
1346 /* Write nomagic word to enable pdr reg write */
1347 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
1350 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1354 static int MPEGTSDisable(struct drxk_state
*state
)
1358 return MPEGTSConfigurePins(state
, false);
1361 static int BLChainCmd(struct drxk_state
*state
,
1362 u16 romOffset
, u16 nrOfElements
, u32 timeOut
)
1369 mutex_lock(&state
->mutex
);
1370 status
= write16(state
, SIO_BL_MODE__A
, SIO_BL_MODE_CHAIN
);
1373 status
= write16(state
, SIO_BL_CHAIN_ADDR__A
, romOffset
);
1376 status
= write16(state
, SIO_BL_CHAIN_LEN__A
, nrOfElements
);
1379 status
= write16(state
, SIO_BL_ENABLE__A
, SIO_BL_ENABLE_ON
);
1383 end
= jiffies
+ msecs_to_jiffies(timeOut
);
1386 status
= read16(state
, SIO_BL_STATUS__A
, &blStatus
);
1389 } while ((blStatus
== 0x1) &&
1390 ((time_is_after_jiffies(end
))));
1392 if (blStatus
== 0x1) {
1393 printk(KERN_ERR
"drxk: SIO not ready\n");
1399 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1401 mutex_unlock(&state
->mutex
);
1406 static int DownloadMicrocode(struct drxk_state
*state
,
1407 const u8 pMCImage
[], u32 Length
)
1409 const u8
*pSrc
= pMCImage
;
1419 /* down the drain (we don't care about MAGIC_WORD) */
1421 /* For future reference */
1422 Drain
= (pSrc
[0] << 8) | pSrc
[1];
1424 pSrc
+= sizeof(u16
);
1425 offset
+= sizeof(u16
);
1426 nBlocks
= (pSrc
[0] << 8) | pSrc
[1];
1427 pSrc
+= sizeof(u16
);
1428 offset
+= sizeof(u16
);
1430 for (i
= 0; i
< nBlocks
; i
+= 1) {
1431 Address
= (pSrc
[0] << 24) | (pSrc
[1] << 16) |
1432 (pSrc
[2] << 8) | pSrc
[3];
1433 pSrc
+= sizeof(u32
);
1434 offset
+= sizeof(u32
);
1436 BlockSize
= ((pSrc
[0] << 8) | pSrc
[1]) * sizeof(u16
);
1437 pSrc
+= sizeof(u16
);
1438 offset
+= sizeof(u16
);
1441 /* For future reference */
1442 Flags
= (pSrc
[0] << 8) | pSrc
[1];
1444 pSrc
+= sizeof(u16
);
1445 offset
+= sizeof(u16
);
1448 /* For future reference */
1449 BlockCRC
= (pSrc
[0] << 8) | pSrc
[1];
1451 pSrc
+= sizeof(u16
);
1452 offset
+= sizeof(u16
);
1454 if (offset
+ BlockSize
> Length
) {
1455 printk(KERN_ERR
"drxk: Firmware is corrupted.\n");
1459 status
= write_block(state
, Address
, BlockSize
, pSrc
);
1461 printk(KERN_ERR
"drxk: Error %d while loading firmware\n", status
);
1465 offset
+= BlockSize
;
1470 static int DVBTEnableOFDMTokenRing(struct drxk_state
*state
, bool enable
)
1474 u16 desiredCtrl
= SIO_OFDM_SH_OFDM_RING_ENABLE_ON
;
1475 u16 desiredStatus
= SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED
;
1480 if (enable
== false) {
1481 desiredCtrl
= SIO_OFDM_SH_OFDM_RING_ENABLE_OFF
;
1482 desiredStatus
= SIO_OFDM_SH_OFDM_RING_STATUS_DOWN
;
1485 status
= read16(state
, SIO_OFDM_SH_OFDM_RING_STATUS__A
, &data
);
1486 if (status
>= 0 && data
== desiredStatus
) {
1487 /* tokenring already has correct status */
1490 /* Disable/enable dvbt tokenring bridge */
1491 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
, desiredCtrl
);
1493 end
= jiffies
+ msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT
);
1495 status
= read16(state
, SIO_OFDM_SH_OFDM_RING_STATUS__A
, &data
);
1496 if ((status
>= 0 && data
== desiredStatus
) || time_is_after_jiffies(end
))
1500 if (data
!= desiredStatus
) {
1501 printk(KERN_ERR
"drxk: SIO not ready\n");
1507 static int MPEGTSStop(struct drxk_state
*state
)
1510 u16 fecOcSncMode
= 0;
1511 u16 fecOcIprMode
= 0;
1515 /* Gracefull shutdown (byte boundaries) */
1516 status
= read16(state
, FEC_OC_SNC_MODE__A
, &fecOcSncMode
);
1519 fecOcSncMode
|= FEC_OC_SNC_MODE_SHUTDOWN__M
;
1520 status
= write16(state
, FEC_OC_SNC_MODE__A
, fecOcSncMode
);
1524 /* Suppress MCLK during absence of data */
1525 status
= read16(state
, FEC_OC_IPR_MODE__A
, &fecOcIprMode
);
1528 fecOcIprMode
|= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M
;
1529 status
= write16(state
, FEC_OC_IPR_MODE__A
, fecOcIprMode
);
1533 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1538 static int scu_command(struct drxk_state
*state
,
1539 u16 cmd
, u8 parameterLen
,
1540 u16
*parameter
, u8 resultLen
, u16
*result
)
1542 #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15
1543 #error DRXK register mapping no longer compatible with this routine!
1546 int status
= -EINVAL
;
1555 if ((cmd
== 0) || ((parameterLen
> 0) && (parameter
== NULL
)) ||
1556 ((resultLen
> 0) && (result
== NULL
))) {
1557 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1561 mutex_lock(&state
->mutex
);
1563 /* assume that the command register is ready
1564 since it is checked afterwards */
1565 for (ii
= parameterLen
- 1; ii
>= 0; ii
-= 1) {
1566 buffer
[cnt
++] = (parameter
[ii
] & 0xFF);
1567 buffer
[cnt
++] = ((parameter
[ii
] >> 8) & 0xFF);
1569 buffer
[cnt
++] = (cmd
& 0xFF);
1570 buffer
[cnt
++] = ((cmd
>> 8) & 0xFF);
1572 write_block(state
, SCU_RAM_PARAM_0__A
-
1573 (parameterLen
- 1), cnt
, buffer
);
1574 /* Wait until SCU has processed command */
1575 end
= jiffies
+ msecs_to_jiffies(DRXK_MAX_WAITTIME
);
1578 status
= read16(state
, SCU_RAM_COMMAND__A
, &curCmd
);
1581 } while (!(curCmd
== DRX_SCU_READY
) && (time_is_after_jiffies(end
)));
1582 if (curCmd
!= DRX_SCU_READY
) {
1583 printk(KERN_ERR
"drxk: SCU not ready\n");
1588 if ((resultLen
> 0) && (result
!= NULL
)) {
1592 for (ii
= resultLen
- 1; ii
>= 0; ii
-= 1) {
1593 status
= read16(state
, SCU_RAM_PARAM_0__A
- ii
, &result
[ii
]);
1598 /* Check if an error was reported by SCU */
1599 err
= (s16
)result
[0];
1603 /* check for the known error codes */
1605 case SCU_RESULT_UNKCMD
:
1606 p
= "SCU_RESULT_UNKCMD";
1608 case SCU_RESULT_UNKSTD
:
1609 p
= "SCU_RESULT_UNKSTD";
1611 case SCU_RESULT_SIZE
:
1612 p
= "SCU_RESULT_SIZE";
1614 case SCU_RESULT_INVPAR
:
1615 p
= "SCU_RESULT_INVPAR";
1617 default: /* Other negative values are errors */
1618 sprintf(errname
, "ERROR: %d\n", err
);
1621 printk(KERN_ERR
"drxk: %s while sending cmd 0x%04x with params:", p
, cmd
);
1622 print_hex_dump_bytes("drxk: ", DUMP_PREFIX_NONE
, buffer
, cnt
);
1629 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1631 mutex_unlock(&state
->mutex
);
1635 static int SetIqmAf(struct drxk_state
*state
, bool active
)
1643 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
1648 data
|= (IQM_AF_STDBY_STDBY_ADC_STANDBY
1649 | IQM_AF_STDBY_STDBY_AMP_STANDBY
1650 | IQM_AF_STDBY_STDBY_PD_STANDBY
1651 | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
1652 | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
);
1654 data
&= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY
)
1655 & (~IQM_AF_STDBY_STDBY_AMP_STANDBY
)
1656 & (~IQM_AF_STDBY_STDBY_PD_STANDBY
)
1657 & (~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
)
1658 & (~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
)
1661 status
= write16(state
, IQM_AF_STDBY__A
, data
);
1665 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1669 static int CtrlPowerMode(struct drxk_state
*state
, enum DRXPowerMode
*mode
)
1672 u16 sioCcPwdMode
= 0;
1676 /* Check arguments */
1682 sioCcPwdMode
= SIO_CC_PWD_MODE_LEVEL_NONE
;
1684 case DRXK_POWER_DOWN_OFDM
:
1685 sioCcPwdMode
= SIO_CC_PWD_MODE_LEVEL_OFDM
;
1687 case DRXK_POWER_DOWN_CORE
:
1688 sioCcPwdMode
= SIO_CC_PWD_MODE_LEVEL_CLOCK
;
1690 case DRXK_POWER_DOWN_PLL
:
1691 sioCcPwdMode
= SIO_CC_PWD_MODE_LEVEL_PLL
;
1693 case DRX_POWER_DOWN
:
1694 sioCcPwdMode
= SIO_CC_PWD_MODE_LEVEL_OSC
;
1697 /* Unknow sleep mode */
1701 /* If already in requested power mode, do nothing */
1702 if (state
->m_currentPowerMode
== *mode
)
1705 /* For next steps make sure to start from DRX_POWER_UP mode */
1706 if (state
->m_currentPowerMode
!= DRX_POWER_UP
) {
1707 status
= PowerUpDevice(state
);
1710 status
= DVBTEnableOFDMTokenRing(state
, true);
1715 if (*mode
== DRX_POWER_UP
) {
1716 /* Restore analog & pin configuartion */
1718 /* Power down to requested mode */
1719 /* Backup some register settings */
1720 /* Set pins with possible pull-ups connected
1721 to them in input mode */
1722 /* Analog power down */
1723 /* ADC power down */
1724 /* Power down device */
1725 /* stop all comm_exec */
1726 /* Stop and power down previous standard */
1727 switch (state
->m_OperationMode
) {
1729 status
= MPEGTSStop(state
);
1732 status
= PowerDownDVBT(state
, false);
1738 status
= MPEGTSStop(state
);
1741 status
= PowerDownQAM(state
);
1748 status
= DVBTEnableOFDMTokenRing(state
, false);
1751 status
= write16(state
, SIO_CC_PWD_MODE__A
, sioCcPwdMode
);
1754 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
1758 if (*mode
!= DRXK_POWER_DOWN_OFDM
) {
1759 state
->m_HICfgCtrl
|=
1760 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
1761 status
= HI_CfgCommand(state
);
1766 state
->m_currentPowerMode
= *mode
;
1770 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1775 static int PowerDownDVBT(struct drxk_state
*state
, bool setPowerMode
)
1777 enum DRXPowerMode powerMode
= DRXK_POWER_DOWN_OFDM
;
1784 status
= read16(state
, SCU_COMM_EXEC__A
, &data
);
1787 if (data
== SCU_COMM_EXEC_ACTIVE
) {
1788 /* Send OFDM stop command */
1789 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_STOP
, 0, NULL
, 1, &cmdResult
);
1792 /* Send OFDM reset command */
1793 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_RESET
, 0, NULL
, 1, &cmdResult
);
1798 /* Reset datapath for OFDM, processors first */
1799 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
1802 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
1805 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
1810 status
= SetIqmAf(state
, false);
1814 /* powerdown to OFDM mode */
1816 status
= CtrlPowerMode(state
, &powerMode
);
1822 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1826 static int SetOperationMode(struct drxk_state
*state
,
1827 enum OperationMode oMode
)
1833 Stop and power down previous standard
1834 TODO investigate total power down instead of partial
1835 power down depending on "previous" standard.
1838 /* disable HW lock indicator */
1839 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
1843 /* Device is already at the required mode */
1844 if (state
->m_OperationMode
== oMode
)
1847 switch (state
->m_OperationMode
) {
1848 /* OM_NONE was added for start up */
1852 status
= MPEGTSStop(state
);
1855 status
= PowerDownDVBT(state
, true);
1858 state
->m_OperationMode
= OM_NONE
;
1860 case OM_QAM_ITU_A
: /* fallthrough */
1862 status
= MPEGTSStop(state
);
1865 status
= PowerDownQAM(state
);
1868 state
->m_OperationMode
= OM_NONE
;
1877 Power up new standard
1881 dprintk(1, ": DVB-T\n");
1882 state
->m_OperationMode
= oMode
;
1883 status
= SetDVBTStandard(state
, oMode
);
1887 case OM_QAM_ITU_A
: /* fallthrough */
1889 dprintk(1, ": DVB-C Annex %c\n",
1890 (state
->m_OperationMode
== OM_QAM_ITU_A
) ? 'A' : 'C');
1891 state
->m_OperationMode
= oMode
;
1892 status
= SetQAMStandard(state
, oMode
);
1902 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1906 static int Start(struct drxk_state
*state
, s32 offsetFreq
,
1907 s32 IntermediateFrequency
)
1909 int status
= -EINVAL
;
1912 s32 OffsetkHz
= offsetFreq
/ 1000;
1915 if (state
->m_DrxkState
!= DRXK_STOPPED
&&
1916 state
->m_DrxkState
!= DRXK_DTV_STARTED
)
1919 state
->m_bMirrorFreqSpect
= (state
->props
.inversion
== INVERSION_ON
);
1921 if (IntermediateFrequency
< 0) {
1922 state
->m_bMirrorFreqSpect
= !state
->m_bMirrorFreqSpect
;
1923 IntermediateFrequency
= -IntermediateFrequency
;
1926 switch (state
->m_OperationMode
) {
1929 IFreqkHz
= (IntermediateFrequency
/ 1000);
1930 status
= SetQAM(state
, IFreqkHz
, OffsetkHz
);
1933 state
->m_DrxkState
= DRXK_DTV_STARTED
;
1936 IFreqkHz
= (IntermediateFrequency
/ 1000);
1937 status
= MPEGTSStop(state
);
1940 status
= SetDVBT(state
, IFreqkHz
, OffsetkHz
);
1943 status
= DVBTStart(state
);
1946 state
->m_DrxkState
= DRXK_DTV_STARTED
;
1953 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1957 static int ShutDown(struct drxk_state
*state
)
1965 static int GetLockStatus(struct drxk_state
*state
, u32
*pLockStatus
,
1968 int status
= -EINVAL
;
1972 if (pLockStatus
== NULL
)
1975 *pLockStatus
= NOT_LOCKED
;
1977 /* define the SCU command code */
1978 switch (state
->m_OperationMode
) {
1982 status
= GetQAMLockStatus(state
, pLockStatus
);
1985 status
= GetDVBTLockStatus(state
, pLockStatus
);
1992 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
1996 static int MPEGTSStart(struct drxk_state
*state
)
2000 u16 fecOcSncMode
= 0;
2002 /* Allow OC to sync again */
2003 status
= read16(state
, FEC_OC_SNC_MODE__A
, &fecOcSncMode
);
2006 fecOcSncMode
&= ~FEC_OC_SNC_MODE_SHUTDOWN__M
;
2007 status
= write16(state
, FEC_OC_SNC_MODE__A
, fecOcSncMode
);
2010 status
= write16(state
, FEC_OC_SNC_UNLOCK__A
, 1);
2013 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2017 static int MPEGTSDtoInit(struct drxk_state
*state
)
2023 /* Rate integration settings */
2024 status
= write16(state
, FEC_OC_RCN_CTL_STEP_LO__A
, 0x0000);
2027 status
= write16(state
, FEC_OC_RCN_CTL_STEP_HI__A
, 0x000C);
2030 status
= write16(state
, FEC_OC_RCN_GAIN__A
, 0x000A);
2033 status
= write16(state
, FEC_OC_AVR_PARM_A__A
, 0x0008);
2036 status
= write16(state
, FEC_OC_AVR_PARM_B__A
, 0x0006);
2039 status
= write16(state
, FEC_OC_TMD_HI_MARGIN__A
, 0x0680);
2042 status
= write16(state
, FEC_OC_TMD_LO_MARGIN__A
, 0x0080);
2045 status
= write16(state
, FEC_OC_TMD_COUNT__A
, 0x03F4);
2049 /* Additional configuration */
2050 status
= write16(state
, FEC_OC_OCR_INVERT__A
, 0);
2053 status
= write16(state
, FEC_OC_SNC_LWM__A
, 2);
2056 status
= write16(state
, FEC_OC_SNC_HWM__A
, 12);
2059 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2064 static int MPEGTSDtoSetup(struct drxk_state
*state
,
2065 enum OperationMode oMode
)
2069 u16 fecOcRegMode
= 0; /* FEC_OC_MODE register value */
2070 u16 fecOcRegIprMode
= 0; /* FEC_OC_IPR_MODE register value */
2071 u16 fecOcDtoMode
= 0; /* FEC_OC_IPR_INVERT register value */
2072 u16 fecOcFctMode
= 0; /* FEC_OC_IPR_INVERT register value */
2073 u16 fecOcDtoPeriod
= 2; /* FEC_OC_IPR_INVERT register value */
2074 u16 fecOcDtoBurstLen
= 188; /* FEC_OC_IPR_INVERT register value */
2075 u32 fecOcRcnCtlRate
= 0; /* FEC_OC_IPR_INVERT register value */
2076 u16 fecOcTmdMode
= 0;
2077 u16 fecOcTmdIntUpdRate
= 0;
2079 bool staticCLK
= false;
2083 /* Check insertion of the Reed-Solomon parity bytes */
2084 status
= read16(state
, FEC_OC_MODE__A
, &fecOcRegMode
);
2087 status
= read16(state
, FEC_OC_IPR_MODE__A
, &fecOcRegIprMode
);
2090 fecOcRegMode
&= (~FEC_OC_MODE_PARITY__M
);
2091 fecOcRegIprMode
&= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M
);
2092 if (state
->m_insertRSByte
== true) {
2093 /* enable parity symbol forward */
2094 fecOcRegMode
|= FEC_OC_MODE_PARITY__M
;
2095 /* MVAL disable during parity bytes */
2096 fecOcRegIprMode
|= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M
;
2097 /* TS burst length to 204 */
2098 fecOcDtoBurstLen
= 204;
2101 /* Check serial or parrallel output */
2102 fecOcRegIprMode
&= (~(FEC_OC_IPR_MODE_SERIAL__M
));
2103 if (state
->m_enableParallel
== false) {
2104 /* MPEG data output is serial -> set ipr_mode[0] */
2105 fecOcRegIprMode
|= FEC_OC_IPR_MODE_SERIAL__M
;
2110 maxBitRate
= state
->m_DVBTBitrate
;
2112 fecOcRcnCtlRate
= 0xC00000;
2113 staticCLK
= state
->m_DVBTStaticCLK
;
2115 case OM_QAM_ITU_A
: /* fallthrough */
2117 fecOcTmdMode
= 0x0004;
2118 fecOcRcnCtlRate
= 0xD2B4EE; /* good for >63 Mb/s */
2119 maxBitRate
= state
->m_DVBCBitrate
;
2120 staticCLK
= state
->m_DVBCStaticCLK
;
2124 } /* switch (standard) */
2128 /* Configure DTO's */
2132 /* Rational DTO for MCLK source (static MCLK rate),
2133 Dynamic DTO for optimal grouping
2134 (avoid intra-packet gaps),
2135 DTO offset enable to sync TS burst with MSTRT */
2136 fecOcDtoMode
= (FEC_OC_DTO_MODE_DYNAMIC__M
|
2137 FEC_OC_DTO_MODE_OFFSET_ENABLE__M
);
2138 fecOcFctMode
= (FEC_OC_FCT_MODE_RAT_ENA__M
|
2139 FEC_OC_FCT_MODE_VIRT_ENA__M
);
2141 /* Check user defined bitrate */
2142 bitRate
= maxBitRate
;
2143 if (bitRate
> 75900000UL) { /* max is 75.9 Mb/s */
2144 bitRate
= 75900000UL;
2146 /* Rational DTO period:
2147 dto_period = (Fsys / bitrate) - 2
2149 Result should be floored,
2150 to make sure >= requested bitrate
2152 fecOcDtoPeriod
= (u16
) (((state
->m_sysClockFreq
)
2154 if (fecOcDtoPeriod
<= 2)
2157 fecOcDtoPeriod
-= 2;
2158 fecOcTmdIntUpdRate
= 8;
2160 /* (commonAttr->staticCLK == false) => dynamic mode */
2161 fecOcDtoMode
= FEC_OC_DTO_MODE_DYNAMIC__M
;
2162 fecOcFctMode
= FEC_OC_FCT_MODE__PRE
;
2163 fecOcTmdIntUpdRate
= 5;
2166 /* Write appropriate registers with requested configuration */
2167 status
= write16(state
, FEC_OC_DTO_BURST_LEN__A
, fecOcDtoBurstLen
);
2170 status
= write16(state
, FEC_OC_DTO_PERIOD__A
, fecOcDtoPeriod
);
2173 status
= write16(state
, FEC_OC_DTO_MODE__A
, fecOcDtoMode
);
2176 status
= write16(state
, FEC_OC_FCT_MODE__A
, fecOcFctMode
);
2179 status
= write16(state
, FEC_OC_MODE__A
, fecOcRegMode
);
2182 status
= write16(state
, FEC_OC_IPR_MODE__A
, fecOcRegIprMode
);
2186 /* Rate integration settings */
2187 status
= write32(state
, FEC_OC_RCN_CTL_RATE_LO__A
, fecOcRcnCtlRate
);
2190 status
= write16(state
, FEC_OC_TMD_INT_UPD_RATE__A
, fecOcTmdIntUpdRate
);
2193 status
= write16(state
, FEC_OC_TMD_MODE__A
, fecOcTmdMode
);
2196 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2200 static int MPEGTSConfigurePolarity(struct drxk_state
*state
)
2202 u16 fecOcRegIprInvert
= 0;
2204 /* Data mask for the output data byte */
2205 u16 InvertDataMask
=
2206 FEC_OC_IPR_INVERT_MD7__M
| FEC_OC_IPR_INVERT_MD6__M
|
2207 FEC_OC_IPR_INVERT_MD5__M
| FEC_OC_IPR_INVERT_MD4__M
|
2208 FEC_OC_IPR_INVERT_MD3__M
| FEC_OC_IPR_INVERT_MD2__M
|
2209 FEC_OC_IPR_INVERT_MD1__M
| FEC_OC_IPR_INVERT_MD0__M
;
2213 /* Control selective inversion of output bits */
2214 fecOcRegIprInvert
&= (~(InvertDataMask
));
2215 if (state
->m_invertDATA
== true)
2216 fecOcRegIprInvert
|= InvertDataMask
;
2217 fecOcRegIprInvert
&= (~(FEC_OC_IPR_INVERT_MERR__M
));
2218 if (state
->m_invertERR
== true)
2219 fecOcRegIprInvert
|= FEC_OC_IPR_INVERT_MERR__M
;
2220 fecOcRegIprInvert
&= (~(FEC_OC_IPR_INVERT_MSTRT__M
));
2221 if (state
->m_invertSTR
== true)
2222 fecOcRegIprInvert
|= FEC_OC_IPR_INVERT_MSTRT__M
;
2223 fecOcRegIprInvert
&= (~(FEC_OC_IPR_INVERT_MVAL__M
));
2224 if (state
->m_invertVAL
== true)
2225 fecOcRegIprInvert
|= FEC_OC_IPR_INVERT_MVAL__M
;
2226 fecOcRegIprInvert
&= (~(FEC_OC_IPR_INVERT_MCLK__M
));
2227 if (state
->m_invertCLK
== true)
2228 fecOcRegIprInvert
|= FEC_OC_IPR_INVERT_MCLK__M
;
2230 return write16(state
, FEC_OC_IPR_INVERT__A
, fecOcRegIprInvert
);
2233 #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000
2235 static int SetAgcRf(struct drxk_state
*state
,
2236 struct SCfgAgc
*pAgcCfg
, bool isDTV
)
2238 int status
= -EINVAL
;
2240 struct SCfgAgc
*pIfAgcSettings
;
2244 if (pAgcCfg
== NULL
)
2247 switch (pAgcCfg
->ctrlMode
) {
2248 case DRXK_AGC_CTRL_AUTO
:
2249 /* Enable RF AGC DAC */
2250 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2253 data
&= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2254 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2257 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2261 /* Enable SCU RF AGC loop */
2262 data
&= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2265 if (state
->m_RfAgcPol
)
2266 data
|= SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2268 data
&= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2269 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2273 /* Set speed (using complementary reduction value) */
2274 status
= read16(state
, SCU_RAM_AGC_KI_RED__A
, &data
);
2278 data
&= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M
;
2279 data
|= (~(pAgcCfg
->speed
<<
2280 SCU_RAM_AGC_KI_RED_RAGC_RED__B
)
2281 & SCU_RAM_AGC_KI_RED_RAGC_RED__M
);
2283 status
= write16(state
, SCU_RAM_AGC_KI_RED__A
, data
);
2288 pIfAgcSettings
= &state
->m_dvbtIfAgcCfg
;
2289 else if (IsQAM(state
))
2290 pIfAgcSettings
= &state
->m_qamIfAgcCfg
;
2292 pIfAgcSettings
= &state
->m_atvIfAgcCfg
;
2293 if (pIfAgcSettings
== NULL
) {
2298 /* Set TOP, only if IF-AGC is in AUTO mode */
2299 if (pIfAgcSettings
->ctrlMode
== DRXK_AGC_CTRL_AUTO
)
2300 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
, pAgcCfg
->top
);
2304 /* Cut-Off current */
2305 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI_CO__A
, pAgcCfg
->cutOffCurrent
);
2309 /* Max. output level */
2310 status
= write16(state
, SCU_RAM_AGC_RF_MAX__A
, pAgcCfg
->maxOutputLevel
);
2316 case DRXK_AGC_CTRL_USER
:
2317 /* Enable RF AGC DAC */
2318 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2321 data
&= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2322 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2326 /* Disable SCU RF AGC loop */
2327 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2330 data
|= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2331 if (state
->m_RfAgcPol
)
2332 data
|= SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2334 data
&= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M
;
2335 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2339 /* SCU c.o.c. to 0, enabling full control range */
2340 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI_CO__A
, 0);
2344 /* Write value to output pin */
2345 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI__A
, pAgcCfg
->outputLevel
);
2350 case DRXK_AGC_CTRL_OFF
:
2351 /* Disable RF AGC DAC */
2352 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2355 data
|= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY
;
2356 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2360 /* Disable SCU RF AGC loop */
2361 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2364 data
|= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M
;
2365 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2376 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2380 #define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000
2382 static int SetAgcIf(struct drxk_state
*state
,
2383 struct SCfgAgc
*pAgcCfg
, bool isDTV
)
2387 struct SCfgAgc
*pRfAgcSettings
;
2391 switch (pAgcCfg
->ctrlMode
) {
2392 case DRXK_AGC_CTRL_AUTO
:
2394 /* Enable IF AGC DAC */
2395 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2398 data
&= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2399 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2403 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2407 /* Enable SCU IF AGC loop */
2408 data
&= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2411 if (state
->m_IfAgcPol
)
2412 data
|= SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2414 data
&= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2415 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2419 /* Set speed (using complementary reduction value) */
2420 status
= read16(state
, SCU_RAM_AGC_KI_RED__A
, &data
);
2423 data
&= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M
;
2424 data
|= (~(pAgcCfg
->speed
<<
2425 SCU_RAM_AGC_KI_RED_IAGC_RED__B
)
2426 & SCU_RAM_AGC_KI_RED_IAGC_RED__M
);
2428 status
= write16(state
, SCU_RAM_AGC_KI_RED__A
, data
);
2433 pRfAgcSettings
= &state
->m_qamRfAgcCfg
;
2435 pRfAgcSettings
= &state
->m_atvRfAgcCfg
;
2436 if (pRfAgcSettings
== NULL
)
2439 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
, pRfAgcSettings
->top
);
2444 case DRXK_AGC_CTRL_USER
:
2446 /* Enable IF AGC DAC */
2447 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2450 data
&= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2451 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2455 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2459 /* Disable SCU IF AGC loop */
2460 data
|= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2463 if (state
->m_IfAgcPol
)
2464 data
|= SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2466 data
&= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M
;
2467 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2471 /* Write value to output pin */
2472 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
, pAgcCfg
->outputLevel
);
2477 case DRXK_AGC_CTRL_OFF
:
2479 /* Disable If AGC DAC */
2480 status
= read16(state
, IQM_AF_STDBY__A
, &data
);
2483 data
|= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
;
2484 status
= write16(state
, IQM_AF_STDBY__A
, data
);
2488 /* Disable SCU IF AGC loop */
2489 status
= read16(state
, SCU_RAM_AGC_CONFIG__A
, &data
);
2492 data
|= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M
;
2493 status
= write16(state
, SCU_RAM_AGC_CONFIG__A
, data
);
2497 } /* switch (agcSettingsIf->ctrlMode) */
2499 /* always set the top to support
2500 configurations without if-loop */
2501 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MIN__A
, pAgcCfg
->top
);
2504 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2508 static int ReadIFAgc(struct drxk_state
*state
, u32
*pValue
)
2516 status
= read16(state
, IQM_AF_AGC_IF__A
, &agcDacLvl
);
2518 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2524 if (agcDacLvl
> DRXK_AGC_DAC_OFFSET
)
2525 Level
= agcDacLvl
- DRXK_AGC_DAC_OFFSET
;
2527 *pValue
= (14000 - Level
) / 4;
2534 static int GetQAMSignalToNoise(struct drxk_state
*state
,
2535 s32
*pSignalToNoise
)
2538 u16 qamSlErrPower
= 0; /* accum. error between
2539 raw and sliced symbols */
2540 u32 qamSlSigPower
= 0; /* used for MER, depends of
2542 u32 qamSlMer
= 0; /* QAM MER */
2546 /* MER calculation */
2548 /* get the register value needed for MER */
2549 status
= read16(state
, QAM_SL_ERR_POWER__A
, &qamSlErrPower
);
2551 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2555 switch (state
->props
.modulation
) {
2557 qamSlSigPower
= DRXK_QAM_SL_SIG_POWER_QAM16
<< 2;
2560 qamSlSigPower
= DRXK_QAM_SL_SIG_POWER_QAM32
<< 2;
2563 qamSlSigPower
= DRXK_QAM_SL_SIG_POWER_QAM64
<< 2;
2566 qamSlSigPower
= DRXK_QAM_SL_SIG_POWER_QAM128
<< 2;
2570 qamSlSigPower
= DRXK_QAM_SL_SIG_POWER_QAM256
<< 2;
2574 if (qamSlErrPower
> 0) {
2575 qamSlMer
= Log10Times100(qamSlSigPower
) -
2576 Log10Times100((u32
) qamSlErrPower
);
2578 *pSignalToNoise
= qamSlMer
;
2583 static int GetDVBTSignalToNoise(struct drxk_state
*state
,
2584 s32
*pSignalToNoise
)
2588 u32 EqRegTdSqrErrI
= 0;
2589 u32 EqRegTdSqrErrQ
= 0;
2590 u16 EqRegTdSqrErrExp
= 0;
2591 u16 EqRegTdTpsPwrOfs
= 0;
2592 u16 EqRegTdReqSmbCnt
= 0;
2599 u16 transmissionParams
= 0;
2603 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A
, &EqRegTdTpsPwrOfs
);
2606 status
= read16(state
, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A
, &EqRegTdReqSmbCnt
);
2609 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A
, &EqRegTdSqrErrExp
);
2612 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_I__A
, ®Data
);
2615 /* Extend SQR_ERR_I operational range */
2616 EqRegTdSqrErrI
= (u32
) regData
;
2617 if ((EqRegTdSqrErrExp
> 11) &&
2618 (EqRegTdSqrErrI
< 0x00000FFFUL
)) {
2619 EqRegTdSqrErrI
+= 0x00010000UL
;
2621 status
= read16(state
, OFDM_EQ_TOP_TD_SQR_ERR_Q__A
, ®Data
);
2624 /* Extend SQR_ERR_Q operational range */
2625 EqRegTdSqrErrQ
= (u32
) regData
;
2626 if ((EqRegTdSqrErrExp
> 11) &&
2627 (EqRegTdSqrErrQ
< 0x00000FFFUL
))
2628 EqRegTdSqrErrQ
+= 0x00010000UL
;
2630 status
= read16(state
, OFDM_SC_RA_RAM_OP_PARAM__A
, &transmissionParams
);
2634 /* Check input data for MER */
2636 /* MER calculation (in 0.1 dB) without math.h */
2637 if ((EqRegTdTpsPwrOfs
== 0) || (EqRegTdReqSmbCnt
== 0))
2639 else if ((EqRegTdSqrErrI
+ EqRegTdSqrErrQ
) == 0) {
2640 /* No error at all, this must be the HW reset value
2641 * Apparently no first measurement yet
2645 SqrErrIQ
= (EqRegTdSqrErrI
+ EqRegTdSqrErrQ
) <<
2647 if ((transmissionParams
&
2648 OFDM_SC_RA_RAM_OP_PARAM_MODE__M
)
2649 == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K
)
2654 /* IMER = 100 * log10 (x)
2655 where x = (EqRegTdTpsPwrOfs^2 *
2656 EqRegTdReqSmbCnt * tpsCnt)/SqrErrIQ
2659 where a = 100 * log10 (EqRegTdTpsPwrOfs^2)
2660 b = 100 * log10 (EqRegTdReqSmbCnt * tpsCnt)
2661 c = 100 * log10 (SqrErrIQ)
2664 /* log(x) x = 9bits * 9bits->18 bits */
2665 a
= Log10Times100(EqRegTdTpsPwrOfs
*
2667 /* log(x) x = 16bits * 7bits->23 bits */
2668 b
= Log10Times100(EqRegTdReqSmbCnt
* tpsCnt
);
2669 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */
2670 c
= Log10Times100(SqrErrIQ
);
2673 /* No negative MER, clip to zero */
2679 *pSignalToNoise
= iMER
;
2683 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2687 static int GetSignalToNoise(struct drxk_state
*state
, s32
*pSignalToNoise
)
2691 *pSignalToNoise
= 0;
2692 switch (state
->m_OperationMode
) {
2694 return GetDVBTSignalToNoise(state
, pSignalToNoise
);
2697 return GetQAMSignalToNoise(state
, pSignalToNoise
);
2705 static int GetDVBTQuality(struct drxk_state
*state
, s32
*pQuality
)
2707 /* SNR Values for quasi errorfree reception rom Nordig 2.2 */
2712 static s32 QE_SN
[] = {
2718 108, /* 16-QAM 1/2 */
2719 131, /* 16-QAM 2/3 */
2720 146, /* 16-QAM 3/4 */
2721 156, /* 16-QAM 5/6 */
2722 160, /* 16-QAM 7/8 */
2723 165, /* 64-QAM 1/2 */
2724 187, /* 64-QAM 2/3 */
2725 202, /* 64-QAM 3/4 */
2726 216, /* 64-QAM 5/6 */
2727 225, /* 64-QAM 7/8 */
2733 s32 SignalToNoise
= 0;
2734 u16 Constellation
= 0;
2736 u32 SignalToNoiseRel
;
2739 status
= GetDVBTSignalToNoise(state
, &SignalToNoise
);
2742 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_CONST__A
, &Constellation
);
2745 Constellation
&= OFDM_EQ_TOP_TD_TPS_CONST__M
;
2747 status
= read16(state
, OFDM_EQ_TOP_TD_TPS_CODE_HP__A
, &CodeRate
);
2750 CodeRate
&= OFDM_EQ_TOP_TD_TPS_CODE_HP__M
;
2752 if (Constellation
> OFDM_EQ_TOP_TD_TPS_CONST_64QAM
||
2753 CodeRate
> OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8
)
2755 SignalToNoiseRel
= SignalToNoise
-
2756 QE_SN
[Constellation
* 5 + CodeRate
];
2759 if (SignalToNoiseRel
< -70)
2761 else if (SignalToNoiseRel
< 30)
2762 *pQuality
= ((SignalToNoiseRel
+ 70) *
2765 *pQuality
= BERQuality
;
2770 static int GetDVBCQuality(struct drxk_state
*state
, s32
*pQuality
)
2778 u32 SignalToNoise
= 0;
2779 u32 BERQuality
= 100;
2780 u32 SignalToNoiseRel
= 0;
2782 status
= GetQAMSignalToNoise(state
, &SignalToNoise
);
2786 switch (state
->props
.modulation
) {
2788 SignalToNoiseRel
= SignalToNoise
- 200;
2791 SignalToNoiseRel
= SignalToNoise
- 230;
2792 break; /* Not in NorDig */
2794 SignalToNoiseRel
= SignalToNoise
- 260;
2797 SignalToNoiseRel
= SignalToNoise
- 290;
2801 SignalToNoiseRel
= SignalToNoise
- 320;
2805 if (SignalToNoiseRel
< -70)
2807 else if (SignalToNoiseRel
< 30)
2808 *pQuality
= ((SignalToNoiseRel
+ 70) *
2811 *pQuality
= BERQuality
;
2817 static int GetQuality(struct drxk_state
*state
, s32
*pQuality
)
2821 switch (state
->m_OperationMode
) {
2823 return GetDVBTQuality(state
, pQuality
);
2825 return GetDVBCQuality(state
, pQuality
);
2834 /* Free data ram in SIO HI */
2835 #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040
2836 #define SIO_HI_RA_RAM_USR_END__A 0x420060
2838 #define DRXK_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A)
2839 #define DRXK_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7)
2840 #define DRXK_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ
2841 #define DRXK_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE
2843 #define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr) >> 22) & 0x3F)
2844 #define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F)
2845 #define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF)
2847 static int ConfigureI2CBridge(struct drxk_state
*state
, bool bEnableBridge
)
2849 int status
= -EINVAL
;
2853 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
2855 if (state
->m_DrxkState
== DRXK_POWERED_DOWN
)
2858 if (state
->no_i2c_bridge
)
2861 status
= write16(state
, SIO_HI_RA_RAM_PAR_1__A
, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY
);
2864 if (bEnableBridge
) {
2865 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
, SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED
);
2869 status
= write16(state
, SIO_HI_RA_RAM_PAR_2__A
, SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN
);
2874 status
= HI_Command(state
, SIO_HI_RA_RAM_CMD_BRDCTRL
, 0);
2878 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2882 static int SetPreSaw(struct drxk_state
*state
,
2883 struct SCfgPreSaw
*pPreSawCfg
)
2885 int status
= -EINVAL
;
2889 if ((pPreSawCfg
== NULL
)
2890 || (pPreSawCfg
->reference
> IQM_AF_PDREF__M
))
2893 status
= write16(state
, IQM_AF_PDREF__A
, pPreSawCfg
->reference
);
2896 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2900 static int BLDirectCmd(struct drxk_state
*state
, u32 targetAddr
,
2901 u16 romOffset
, u16 nrOfElements
, u32 timeOut
)
2904 u16 offset
= (u16
) ((targetAddr
>> 0) & 0x00FFFF);
2905 u16 blockbank
= (u16
) ((targetAddr
>> 16) & 0x000FFF);
2911 mutex_lock(&state
->mutex
);
2912 status
= write16(state
, SIO_BL_MODE__A
, SIO_BL_MODE_DIRECT
);
2915 status
= write16(state
, SIO_BL_TGT_HDR__A
, blockbank
);
2918 status
= write16(state
, SIO_BL_TGT_ADDR__A
, offset
);
2921 status
= write16(state
, SIO_BL_SRC_ADDR__A
, romOffset
);
2924 status
= write16(state
, SIO_BL_SRC_LEN__A
, nrOfElements
);
2927 status
= write16(state
, SIO_BL_ENABLE__A
, SIO_BL_ENABLE_ON
);
2931 end
= jiffies
+ msecs_to_jiffies(timeOut
);
2933 status
= read16(state
, SIO_BL_STATUS__A
, &blStatus
);
2936 } while ((blStatus
== 0x1) && time_is_after_jiffies(end
));
2937 if (blStatus
== 0x1) {
2938 printk(KERN_ERR
"drxk: SIO not ready\n");
2944 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2946 mutex_unlock(&state
->mutex
);
2951 static int ADCSyncMeasurement(struct drxk_state
*state
, u16
*count
)
2958 /* Start measurement */
2959 status
= write16(state
, IQM_AF_COMM_EXEC__A
, IQM_AF_COMM_EXEC_ACTIVE
);
2962 status
= write16(state
, IQM_AF_START_LOCK__A
, 1);
2967 status
= read16(state
, IQM_AF_PHASE0__A
, &data
);
2971 *count
= *count
+ 1;
2972 status
= read16(state
, IQM_AF_PHASE1__A
, &data
);
2976 *count
= *count
+ 1;
2977 status
= read16(state
, IQM_AF_PHASE2__A
, &data
);
2981 *count
= *count
+ 1;
2985 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
2989 static int ADCSynchronization(struct drxk_state
*state
)
2996 status
= ADCSyncMeasurement(state
, &count
);
3001 /* Try sampling on a diffrent edge */
3004 status
= read16(state
, IQM_AF_CLKNEG__A
, &clkNeg
);
3007 if ((clkNeg
& IQM_AF_CLKNEG_CLKNEGDATA__M
) ==
3008 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS
) {
3009 clkNeg
&= (~(IQM_AF_CLKNEG_CLKNEGDATA__M
));
3011 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG
;
3013 clkNeg
&= (~(IQM_AF_CLKNEG_CLKNEGDATA__M
));
3015 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS
;
3017 status
= write16(state
, IQM_AF_CLKNEG__A
, clkNeg
);
3020 status
= ADCSyncMeasurement(state
, &count
);
3029 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3033 static int SetFrequencyShifter(struct drxk_state
*state
,
3034 u16 intermediateFreqkHz
,
3035 s32 tunerFreqOffset
, bool isDTV
)
3037 bool selectPosImage
= false;
3038 u32 rfFreqResidual
= tunerFreqOffset
;
3039 u32 fmFrequencyShift
= 0;
3040 bool tunerMirror
= !state
->m_bMirrorFreqSpect
;
3045 u32 samplingFrequency
= (u32
) (state
->m_sysClockFreq
/ 3);
3052 Program frequency shifter
3053 No need to account for mirroring on RF
3056 if ((state
->m_OperationMode
== OM_QAM_ITU_A
) ||
3057 (state
->m_OperationMode
== OM_QAM_ITU_C
) ||
3058 (state
->m_OperationMode
== OM_DVBT
))
3059 selectPosImage
= true;
3061 selectPosImage
= false;
3064 /* tuner doesn't mirror */
3065 ifFreqActual
= intermediateFreqkHz
+
3066 rfFreqResidual
+ fmFrequencyShift
;
3069 ifFreqActual
= intermediateFreqkHz
-
3070 rfFreqResidual
- fmFrequencyShift
;
3071 if (ifFreqActual
> samplingFrequency
/ 2) {
3073 adcFreq
= samplingFrequency
- ifFreqActual
;
3076 /* adc doesn't mirror */
3077 adcFreq
= ifFreqActual
;
3081 frequencyShift
= adcFreq
;
3082 imageToSelect
= state
->m_rfmirror
^ tunerMirror
^
3083 adcFlip
^ selectPosImage
;
3084 state
->m_IqmFsRateOfs
=
3085 Frac28a((frequencyShift
), samplingFrequency
);
3088 state
->m_IqmFsRateOfs
= ~state
->m_IqmFsRateOfs
+ 1;
3090 /* Program frequency shifter with tuner offset compensation */
3091 /* frequencyShift += tunerFreqOffset; TODO */
3092 status
= write32(state
, IQM_FS_RATE_OFS_LO__A
,
3093 state
->m_IqmFsRateOfs
);
3095 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3099 static int InitAGC(struct drxk_state
*state
, bool isDTV
)
3102 u16 ingainTgtMin
= 0;
3103 u16 ingainTgtMax
= 0;
3111 u16 kiInnergainMin
= 0;
3112 u16 ifIaccuHiTgt
= 0;
3113 u16 ifIaccuHiTgtMin
= 0;
3114 u16 ifIaccuHiTgtMax
= 0;
3116 u16 fastClpCtrlDelay
= 0;
3117 u16 clpCtrlMode
= 0;
3122 /* Common settings */
3124 ifIaccuHiTgtMin
= 2047;
3128 /* AGCInit() not available for DVBT; init done in microcode */
3129 if (!IsQAM(state
)) {
3130 printk(KERN_ERR
"drxk: %s: mode %d is not DVB-C\n", __func__
, state
->m_OperationMode
);
3134 /* FIXME: Analog TV AGC require different settings */
3136 /* Standard specific settings */
3138 clpDirTo
= (u16
) -9;
3141 snsDirTo
= (u16
) -9;
3142 kiInnergainMin
= (u16
) -1030;
3143 ifIaccuHiTgtMax
= 0x2380;
3144 ifIaccuHiTgt
= 0x2380;
3145 ingainTgtMin
= 0x0511;
3147 ingainTgtMax
= 5119;
3148 fastClpCtrlDelay
= state
->m_qamIfAgcCfg
.FastClipCtrlDelay
;
3150 status
= write16(state
, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A
, fastClpCtrlDelay
);
3154 status
= write16(state
, SCU_RAM_AGC_CLP_CTRL_MODE__A
, clpCtrlMode
);
3157 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT__A
, ingainTgt
);
3160 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MIN__A
, ingainTgtMin
);
3163 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MAX__A
, ingainTgtMax
);
3166 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A
, ifIaccuHiTgtMin
);
3169 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A
, ifIaccuHiTgtMax
);
3172 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI__A
, 0);
3175 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_LO__A
, 0);
3178 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_HI__A
, 0);
3181 status
= write16(state
, SCU_RAM_AGC_RF_IACCU_LO__A
, 0);
3184 status
= write16(state
, SCU_RAM_AGC_CLP_SUM_MAX__A
, clpSumMax
);
3187 status
= write16(state
, SCU_RAM_AGC_SNS_SUM_MAX__A
, snsSumMax
);
3191 status
= write16(state
, SCU_RAM_AGC_KI_INNERGAIN_MIN__A
, kiInnergainMin
);
3194 status
= write16(state
, SCU_RAM_AGC_IF_IACCU_HI_TGT__A
, ifIaccuHiTgt
);
3197 status
= write16(state
, SCU_RAM_AGC_CLP_CYCLEN__A
, clpCyclen
);
3201 status
= write16(state
, SCU_RAM_AGC_RF_SNS_DEV_MAX__A
, 1023);
3204 status
= write16(state
, SCU_RAM_AGC_RF_SNS_DEV_MIN__A
, (u16
) -1023);
3207 status
= write16(state
, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A
, 50);
3211 status
= write16(state
, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A
, 20);
3214 status
= write16(state
, SCU_RAM_AGC_CLP_SUM_MIN__A
, clpSumMin
);
3217 status
= write16(state
, SCU_RAM_AGC_SNS_SUM_MIN__A
, snsSumMin
);
3220 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_TO__A
, clpDirTo
);
3223 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_TO__A
, snsDirTo
);
3226 status
= write16(state
, SCU_RAM_AGC_KI_MINGAIN__A
, 0x7fff);
3229 status
= write16(state
, SCU_RAM_AGC_KI_MAXGAIN__A
, 0x0);
3232 status
= write16(state
, SCU_RAM_AGC_KI_MIN__A
, 0x0117);
3235 status
= write16(state
, SCU_RAM_AGC_KI_MAX__A
, 0x0657);
3238 status
= write16(state
, SCU_RAM_AGC_CLP_SUM__A
, 0);
3241 status
= write16(state
, SCU_RAM_AGC_CLP_CYCCNT__A
, 0);
3244 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_WD__A
, 0);
3247 status
= write16(state
, SCU_RAM_AGC_CLP_DIR_STP__A
, 1);
3250 status
= write16(state
, SCU_RAM_AGC_SNS_SUM__A
, 0);
3253 status
= write16(state
, SCU_RAM_AGC_SNS_CYCCNT__A
, 0);
3256 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_WD__A
, 0);
3259 status
= write16(state
, SCU_RAM_AGC_SNS_DIR_STP__A
, 1);
3262 status
= write16(state
, SCU_RAM_AGC_SNS_CYCLEN__A
, 500);
3265 status
= write16(state
, SCU_RAM_AGC_KI_CYCLEN__A
, 500);
3269 /* Initialize inner-loop KI gain factors */
3270 status
= read16(state
, SCU_RAM_AGC_KI__A
, &data
);
3275 data
&= ~SCU_RAM_AGC_KI_RF__M
;
3276 data
|= (DRXK_KI_RAGC_QAM
<< SCU_RAM_AGC_KI_RF__B
);
3277 data
&= ~SCU_RAM_AGC_KI_IF__M
;
3278 data
|= (DRXK_KI_IAGC_QAM
<< SCU_RAM_AGC_KI_IF__B
);
3280 status
= write16(state
, SCU_RAM_AGC_KI__A
, data
);
3283 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3287 static int DVBTQAMGetAccPktErr(struct drxk_state
*state
, u16
*packetErr
)
3292 if (packetErr
== NULL
)
3293 status
= write16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
, 0);
3295 status
= read16(state
, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A
, packetErr
);
3297 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3301 static int DVBTScCommand(struct drxk_state
*state
,
3302 u16 cmd
, u16 subcmd
,
3303 u16 param0
, u16 param1
, u16 param2
,
3304 u16 param3
, u16 param4
)
3313 status
= read16(state
, OFDM_SC_COMM_EXEC__A
, &scExec
);
3315 /* SC is not running */
3321 /* Wait until sc is ready to receive command */
3325 status
= read16(state
, OFDM_SC_RA_RAM_CMD__A
, &curCmd
);
3327 } while ((curCmd
!= 0) && (retryCnt
< DRXK_MAX_RETRIES
));
3328 if (retryCnt
>= DRXK_MAX_RETRIES
&& (status
< 0))
3331 /* Write sub-command */
3333 /* All commands using sub-cmd */
3334 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3335 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3336 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3337 status
= write16(state
, OFDM_SC_RA_RAM_CMD_ADDR__A
, subcmd
);
3346 /* Write needed parameters and the command */
3348 /* All commands using 5 parameters */
3349 /* All commands using 4 parameters */
3350 /* All commands using 3 parameters */
3351 /* All commands using 2 parameters */
3352 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3353 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3354 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3355 status
= write16(state
, OFDM_SC_RA_RAM_PARAM1__A
, param1
);
3356 /* All commands using 1 parameters */
3357 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING
:
3358 case OFDM_SC_RA_RAM_CMD_USER_IO
:
3359 status
= write16(state
, OFDM_SC_RA_RAM_PARAM0__A
, param0
);
3360 /* All commands using 0 parameters */
3361 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM
:
3362 case OFDM_SC_RA_RAM_CMD_NULL
:
3364 status
= write16(state
, OFDM_SC_RA_RAM_CMD__A
, cmd
);
3367 /* Unknown command */
3373 /* Wait until sc is ready processing command */
3377 status
= read16(state
, OFDM_SC_RA_RAM_CMD__A
, &curCmd
);
3379 } while ((curCmd
!= 0) && (retryCnt
< DRXK_MAX_RETRIES
));
3380 if (retryCnt
>= DRXK_MAX_RETRIES
&& (status
< 0))
3383 /* Check for illegal cmd */
3384 status
= read16(state
, OFDM_SC_RA_RAM_CMD_ADDR__A
, &errCode
);
3385 if (errCode
== 0xFFFF) {
3386 /* illegal command */
3392 /* Retreive results parameters from SC */
3394 /* All commands yielding 5 results */
3395 /* All commands yielding 4 results */
3396 /* All commands yielding 3 results */
3397 /* All commands yielding 2 results */
3398 /* All commands yielding 1 result */
3399 case OFDM_SC_RA_RAM_CMD_USER_IO
:
3400 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM
:
3401 status
= read16(state
, OFDM_SC_RA_RAM_PARAM0__A
, &(param0
));
3402 /* All commands yielding 0 results */
3403 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING
:
3404 case OFDM_SC_RA_RAM_CMD_SET_TIMER
:
3405 case OFDM_SC_RA_RAM_CMD_PROC_START
:
3406 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
:
3407 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM
:
3408 case OFDM_SC_RA_RAM_CMD_NULL
:
3411 /* Unknown command */
3414 } /* switch (cmd->cmd) */
3417 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3421 static int PowerUpDVBT(struct drxk_state
*state
)
3423 enum DRXPowerMode powerMode
= DRX_POWER_UP
;
3427 status
= CtrlPowerMode(state
, &powerMode
);
3429 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3433 static int DVBTCtrlSetIncEnable(struct drxk_state
*state
, bool *enabled
)
3438 if (*enabled
== true)
3439 status
= write16(state
, IQM_CF_BYPASSDET__A
, 0);
3441 status
= write16(state
, IQM_CF_BYPASSDET__A
, 1);
3443 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3447 #define DEFAULT_FR_THRES_8K 4000
3448 static int DVBTCtrlSetFrEnable(struct drxk_state
*state
, bool *enabled
)
3454 if (*enabled
== true) {
3455 /* write mask to 1 */
3456 status
= write16(state
, OFDM_SC_RA_RAM_FR_THRES_8K__A
,
3457 DEFAULT_FR_THRES_8K
);
3459 /* write mask to 0 */
3460 status
= write16(state
, OFDM_SC_RA_RAM_FR_THRES_8K__A
, 0);
3463 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3468 static int DVBTCtrlSetEchoThreshold(struct drxk_state
*state
,
3469 struct DRXKCfgDvbtEchoThres_t
*echoThres
)
3475 status
= read16(state
, OFDM_SC_RA_RAM_ECHO_THRES__A
, &data
);
3479 switch (echoThres
->fftMode
) {
3480 case DRX_FFTMODE_2K
:
3481 data
&= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M
;
3482 data
|= ((echoThres
->threshold
<<
3483 OFDM_SC_RA_RAM_ECHO_THRES_2K__B
)
3484 & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M
));
3486 case DRX_FFTMODE_8K
:
3487 data
&= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M
;
3488 data
|= ((echoThres
->threshold
<<
3489 OFDM_SC_RA_RAM_ECHO_THRES_8K__B
)
3490 & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M
));
3496 status
= write16(state
, OFDM_SC_RA_RAM_ECHO_THRES__A
, data
);
3499 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3503 static int DVBTCtrlSetSqiSpeed(struct drxk_state
*state
,
3504 enum DRXKCfgDvbtSqiSpeed
*speed
)
3506 int status
= -EINVAL
;
3511 case DRXK_DVBT_SQI_SPEED_FAST
:
3512 case DRXK_DVBT_SQI_SPEED_MEDIUM
:
3513 case DRXK_DVBT_SQI_SPEED_SLOW
:
3518 status
= write16(state
, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A
,
3522 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3526 /*============================================================================*/
3529 * \brief Activate DVBT specific presets
3530 * \param demod instance of demodulator.
3531 * \return DRXStatus_t.
3533 * Called in DVBTSetStandard
3536 static int DVBTActivatePresets(struct drxk_state
*state
)
3539 bool setincenable
= false;
3540 bool setfrenable
= true;
3542 struct DRXKCfgDvbtEchoThres_t echoThres2k
= { 0, DRX_FFTMODE_2K
};
3543 struct DRXKCfgDvbtEchoThres_t echoThres8k
= { 0, DRX_FFTMODE_8K
};
3546 status
= DVBTCtrlSetIncEnable(state
, &setincenable
);
3549 status
= DVBTCtrlSetFrEnable(state
, &setfrenable
);
3552 status
= DVBTCtrlSetEchoThreshold(state
, &echoThres2k
);
3555 status
= DVBTCtrlSetEchoThreshold(state
, &echoThres8k
);
3558 status
= write16(state
, SCU_RAM_AGC_INGAIN_TGT_MAX__A
, state
->m_dvbtIfAgcCfg
.IngainTgtMax
);
3561 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3565 /*============================================================================*/
3568 * \brief Initialize channelswitch-independent settings for DVBT.
3569 * \param demod instance of demodulator.
3570 * \return DRXStatus_t.
3572 * For ROM code channel filter taps are loaded from the bootloader. For microcode
3573 * the DVB-T taps from the drxk_filters.h are used.
3575 static int SetDVBTStandard(struct drxk_state
*state
,
3576 enum OperationMode oMode
)
3585 /* added antenna switch */
3586 SwitchAntennaToDVBT(state
);
3587 /* send OFDM reset command */
3588 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_RESET
, 0, NULL
, 1, &cmdResult
);
3592 /* send OFDM setenv command */
3593 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV
, 0, NULL
, 1, &cmdResult
);
3597 /* reset datapath for OFDM, processors first */
3598 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
3601 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
3604 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
3609 /* synchronize on ofdstate->m_festart */
3610 status
= write16(state
, IQM_AF_UPD_SEL__A
, 1);
3613 /* window size for clipping ADC detection */
3614 status
= write16(state
, IQM_AF_CLP_LEN__A
, 0);
3617 /* window size for for sense pre-SAW detection */
3618 status
= write16(state
, IQM_AF_SNS_LEN__A
, 0);
3621 /* sense threshold for sense pre-SAW detection */
3622 status
= write16(state
, IQM_AF_AMUX__A
, IQM_AF_AMUX_SIGNAL2ADC
);
3625 status
= SetIqmAf(state
, true);
3629 status
= write16(state
, IQM_AF_AGC_RF__A
, 0);
3633 /* Impulse noise cruncher setup */
3634 status
= write16(state
, IQM_AF_INC_LCT__A
, 0); /* crunch in IQM_CF */
3637 status
= write16(state
, IQM_CF_DET_LCT__A
, 0); /* detect in IQM_CF */
3640 status
= write16(state
, IQM_CF_WND_LEN__A
, 3); /* peak detector window length */
3644 status
= write16(state
, IQM_RC_STRETCH__A
, 16);
3647 status
= write16(state
, IQM_CF_OUT_ENA__A
, 0x4); /* enable output 2 */
3650 status
= write16(state
, IQM_CF_DS_ENA__A
, 0x4); /* decimate output 2 */
3653 status
= write16(state
, IQM_CF_SCALE__A
, 1600);
3656 status
= write16(state
, IQM_CF_SCALE_SH__A
, 0);
3660 /* virtual clipping threshold for clipping ADC detection */
3661 status
= write16(state
, IQM_AF_CLP_TH__A
, 448);
3664 status
= write16(state
, IQM_CF_DATATH__A
, 495); /* crunching threshold */
3668 status
= BLChainCmd(state
, DRXK_BL_ROM_OFFSET_TAPS_DVBT
, DRXK_BLCC_NR_ELEMENTS_TAPS
, DRXK_BLC_TIMEOUT
);
3672 status
= write16(state
, IQM_CF_PKDTH__A
, 2); /* peak detector threshold */
3675 status
= write16(state
, IQM_CF_POW_MEAS_LEN__A
, 2);
3678 /* enable power measurement interrupt */
3679 status
= write16(state
, IQM_CF_COMM_INT_MSK__A
, 1);
3682 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_ACTIVE
);
3686 /* IQM will not be reset from here, sync ADC and update/init AGC */
3687 status
= ADCSynchronization(state
);
3690 status
= SetPreSaw(state
, &state
->m_dvbtPreSawCfg
);
3694 /* Halt SCU to enable safe non-atomic accesses */
3695 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
3699 status
= SetAgcRf(state
, &state
->m_dvbtRfAgcCfg
, true);
3702 status
= SetAgcIf(state
, &state
->m_dvbtIfAgcCfg
, true);
3706 /* Set Noise Estimation notch width and enable DC fix */
3707 status
= read16(state
, OFDM_SC_RA_RAM_CONFIG__A
, &data
);
3710 data
|= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M
;
3711 status
= write16(state
, OFDM_SC_RA_RAM_CONFIG__A
, data
);
3715 /* Activate SCU to enable SCU commands */
3716 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
3720 if (!state
->m_DRXK_A3_ROM_CODE
) {
3721 /* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */
3722 status
= write16(state
, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A
, state
->m_dvbtIfAgcCfg
.FastClipCtrlDelay
);
3728 #ifdef COMPILE_FOR_NONRT
3729 status
= write16(state
, OFDM_SC_RA_RAM_BE_OPT_DELAY__A
, 1);
3732 status
= write16(state
, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A
, 2);
3738 status
= write16(state
, FEC_DI_INPUT_CTL__A
, 1); /* OFDM input */
3743 #ifdef COMPILE_FOR_NONRT
3744 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, 0x400);
3748 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, 0x1000);
3752 status
= write16(state
, FEC_RS_MEASUREMENT_PRESCALE__A
, 0x0001);
3756 /* Setup MPEG bus */
3757 status
= MPEGTSDtoSetup(state
, OM_DVBT
);
3760 /* Set DVBT Presets */
3761 status
= DVBTActivatePresets(state
);
3767 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3771 /*============================================================================*/
3773 * \brief Start dvbt demodulating for channel.
3774 * \param demod instance of demodulator.
3775 * \return DRXStatus_t.
3777 static int DVBTStart(struct drxk_state
*state
)
3781 /* DRXKOfdmScCmd_t scCmd; */
3784 /* Start correct processes to get in lock */
3785 /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */
3786 param1
= OFDM_SC_RA_RAM_LOCKTRACK_MIN
;
3787 status
= DVBTScCommand(state
, OFDM_SC_RA_RAM_CMD_PROC_START
, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M
, param1
, 0, 0, 0);
3791 status
= MPEGTSStart(state
);
3794 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_ACTIVE
);
3799 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
3804 /*============================================================================*/
3807 * \brief Set up dvbt demodulator for channel.
3808 * \param demod instance of demodulator.
3809 * \return DRXStatus_t.
3810 * // original DVBTSetChannel()
3812 static int SetDVBT(struct drxk_state
*state
, u16 IntermediateFreqkHz
,
3813 s32 tunerFreqOffset
)
3816 u16 transmissionParams
= 0;
3817 u16 operationMode
= 0;
3818 u32 iqmRcRateOfs
= 0;
3823 dprintk(1, "IF =%d, TFO = %d\n", IntermediateFreqkHz
, tunerFreqOffset
);
3825 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_STOP
, 0, NULL
, 1, &cmdResult
);
3829 /* Halt SCU to enable safe non-atomic accesses */
3830 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
3834 /* Stop processors */
3835 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, OFDM_SC_COMM_EXEC_STOP
);
3838 status
= write16(state
, OFDM_LC_COMM_EXEC__A
, OFDM_LC_COMM_EXEC_STOP
);
3842 /* Mandatory fix, always stop CP, required to set spl offset back to
3843 hardware default (is set to 0 by ucode during pilot detection */
3844 status
= write16(state
, OFDM_CP_COMM_EXEC__A
, OFDM_CP_COMM_EXEC_STOP
);
3848 /*== Write channel settings to device =====================================*/
3851 switch (state
->props
.transmission_mode
) {
3852 case TRANSMISSION_MODE_AUTO
:
3854 operationMode
|= OFDM_SC_RA_RAM_OP_AUTO_MODE__M
;
3855 /* fall through , try first guess DRX_FFTMODE_8K */
3856 case TRANSMISSION_MODE_8K
:
3857 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K
;
3859 case TRANSMISSION_MODE_2K
:
3860 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K
;
3865 switch (state
->props
.guard_interval
) {
3867 case GUARD_INTERVAL_AUTO
:
3868 operationMode
|= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M
;
3869 /* fall through , try first guess DRX_GUARD_1DIV4 */
3870 case GUARD_INTERVAL_1_4
:
3871 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4
;
3873 case GUARD_INTERVAL_1_32
:
3874 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32
;
3876 case GUARD_INTERVAL_1_16
:
3877 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16
;
3879 case GUARD_INTERVAL_1_8
:
3880 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8
;
3885 switch (state
->props
.hierarchy
) {
3886 case HIERARCHY_AUTO
:
3887 case HIERARCHY_NONE
:
3889 operationMode
|= OFDM_SC_RA_RAM_OP_AUTO_HIER__M
;
3890 /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */
3891 /* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */
3894 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1
;
3897 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2
;
3900 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4
;
3906 switch (state
->props
.modulation
) {
3909 operationMode
|= OFDM_SC_RA_RAM_OP_AUTO_CONST__M
;
3910 /* fall through , try first guess DRX_CONSTELLATION_QAM64 */
3912 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64
;
3915 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK
;
3918 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16
;
3922 /* No hierachical channels support in BDA */
3923 /* Priority (only for hierarchical channels) */
3924 switch (channel
->priority
) {
3925 case DRX_PRIORITY_LOW
:
3926 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO
;
3927 WR16(devAddr
, OFDM_EC_SB_PRIOR__A
,
3928 OFDM_EC_SB_PRIOR_LO
);
3930 case DRX_PRIORITY_HIGH
:
3931 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI
;
3932 WR16(devAddr
, OFDM_EC_SB_PRIOR__A
,
3933 OFDM_EC_SB_PRIOR_HI
));
3935 case DRX_PRIORITY_UNKNOWN
: /* fall through */
3941 /* Set Priorty high */
3942 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI
;
3943 status
= write16(state
, OFDM_EC_SB_PRIOR__A
, OFDM_EC_SB_PRIOR_HI
);
3949 switch (state
->props
.code_rate_HP
) {
3952 operationMode
|= OFDM_SC_RA_RAM_OP_AUTO_RATE__M
;
3953 /* fall through , try first guess DRX_CODERATE_2DIV3 */
3955 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3
;
3958 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2
;
3961 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4
;
3964 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6
;
3967 transmissionParams
|= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8
;
3971 /* SAW filter selection: normaly not necesarry, but if wanted
3972 the application can select a SAW filter via the driver by using UIOs */
3973 /* First determine real bandwidth (Hz) */
3974 /* Also set delay for impulse noise cruncher */
3975 /* Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is changed
3976 by SC for fix for some 8K,1/8 guard but is restored by InitEC and ResetEC
3978 switch (state
->props
.bandwidth_hz
) {
3980 state
->props
.bandwidth_hz
= 8000000;
3983 bandwidth
= DRXK_BANDWIDTH_8MHZ_IN_HZ
;
3984 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
, 3052);
3987 /* cochannel protection for PAL 8 MHz */
3988 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
, 7);
3991 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
, 7);
3994 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
, 7);
3997 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
, 1);
4002 bandwidth
= DRXK_BANDWIDTH_7MHZ_IN_HZ
;
4003 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
, 3491);
4006 /* cochannel protection for PAL 7 MHz */
4007 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
, 8);
4010 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
, 8);
4013 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
, 4);
4016 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
, 1);
4021 bandwidth
= DRXK_BANDWIDTH_6MHZ_IN_HZ
;
4022 status
= write16(state
, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A
, 4073);
4025 /* cochannel protection for NTSC 6 MHz */
4026 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A
, 19);
4029 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A
, 19);
4032 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A
, 14);
4035 status
= write16(state
, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A
, 1);
4044 if (iqmRcRateOfs
== 0) {
4045 /* Now compute IQM_RC_RATE_OFS
4046 (((SysFreq/BandWidth)/2)/2) -1) * 2^23)
4048 ((SysFreq / BandWidth) * (2^21)) - (2^23)
4050 /* (SysFreq / BandWidth) * (2^28) */
4051 /* assert (MAX(sysClk)/MIN(bandwidth) < 16)
4052 => assert(MAX(sysClk) < 16*MIN(bandwidth))
4053 => assert(109714272 > 48000000) = true so Frac 28 can be used */
4054 iqmRcRateOfs
= Frac28a((u32
)
4055 ((state
->m_sysClockFreq
*
4056 1000) / 3), bandwidth
);
4057 /* (SysFreq / BandWidth) * (2^21), rounding before truncating */
4058 if ((iqmRcRateOfs
& 0x7fL
) >= 0x40)
4059 iqmRcRateOfs
+= 0x80L
;
4060 iqmRcRateOfs
= iqmRcRateOfs
>> 7;
4061 /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */
4062 iqmRcRateOfs
= iqmRcRateOfs
- (1 << 23);
4066 ((((u32
) IQM_RC_RATE_OFS_HI__M
) <<
4067 IQM_RC_RATE_OFS_LO__W
) | IQM_RC_RATE_OFS_LO__M
);
4068 status
= write32(state
, IQM_RC_RATE_OFS_LO__A
, iqmRcRateOfs
);
4072 /* Bandwidth setting done */
4075 status
= DVBTSetFrequencyShift(demod
, channel
, tunerOffset
);
4079 status
= SetFrequencyShifter(state
, IntermediateFreqkHz
, tunerFreqOffset
, true);
4083 /*== Start SC, write channel settings to SC ===============================*/
4085 /* Activate SCU to enable SCU commands */
4086 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
4090 /* Enable SC after setting all other parameters */
4091 status
= write16(state
, OFDM_SC_COMM_STATE__A
, 0);
4094 status
= write16(state
, OFDM_SC_COMM_EXEC__A
, 1);
4099 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_OFDM
| SCU_RAM_COMMAND_CMD_DEMOD_START
, 0, NULL
, 1, &cmdResult
);
4103 /* Write SC parameter registers, set all AUTO flags in operation mode */
4104 param1
= (OFDM_SC_RA_RAM_OP_AUTO_MODE__M
|
4105 OFDM_SC_RA_RAM_OP_AUTO_GUARD__M
|
4106 OFDM_SC_RA_RAM_OP_AUTO_CONST__M
|
4107 OFDM_SC_RA_RAM_OP_AUTO_HIER__M
|
4108 OFDM_SC_RA_RAM_OP_AUTO_RATE__M
);
4109 status
= DVBTScCommand(state
, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM
,
4110 0, transmissionParams
, param1
, 0, 0, 0);
4114 if (!state
->m_DRXK_A3_ROM_CODE
)
4115 status
= DVBTCtrlSetSqiSpeed(state
, &state
->m_sqiSpeed
);
4118 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4124 /*============================================================================*/
4127 * \brief Retreive lock status .
4128 * \param demod Pointer to demodulator instance.
4129 * \param lockStat Pointer to lock status structure.
4130 * \return DRXStatus_t.
4133 static int GetDVBTLockStatus(struct drxk_state
*state
, u32
*pLockStatus
)
4136 const u16 mpeg_lock_mask
= (OFDM_SC_RA_RAM_LOCK_MPEG__M
|
4137 OFDM_SC_RA_RAM_LOCK_FEC__M
);
4138 const u16 fec_lock_mask
= (OFDM_SC_RA_RAM_LOCK_FEC__M
);
4139 const u16 demod_lock_mask
= OFDM_SC_RA_RAM_LOCK_DEMOD__M
;
4141 u16 ScRaRamLock
= 0;
4146 *pLockStatus
= NOT_LOCKED
;
4148 /* Check if SC is running */
4149 status
= read16(state
, OFDM_SC_COMM_EXEC__A
, &ScCommExec
);
4152 if (ScCommExec
== OFDM_SC_COMM_EXEC_STOP
)
4155 status
= read16(state
, OFDM_SC_RA_RAM_LOCK__A
, &ScRaRamLock
);
4159 if ((ScRaRamLock
& mpeg_lock_mask
) == mpeg_lock_mask
)
4160 *pLockStatus
= MPEG_LOCK
;
4161 else if ((ScRaRamLock
& fec_lock_mask
) == fec_lock_mask
)
4162 *pLockStatus
= FEC_LOCK
;
4163 else if ((ScRaRamLock
& demod_lock_mask
) == demod_lock_mask
)
4164 *pLockStatus
= DEMOD_LOCK
;
4165 else if (ScRaRamLock
& OFDM_SC_RA_RAM_LOCK_NODVBT__M
)
4166 *pLockStatus
= NEVER_LOCK
;
4169 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4174 static int PowerUpQAM(struct drxk_state
*state
)
4176 enum DRXPowerMode powerMode
= DRXK_POWER_DOWN_OFDM
;
4180 status
= CtrlPowerMode(state
, &powerMode
);
4182 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4188 /** Power Down QAM */
4189 static int PowerDownQAM(struct drxk_state
*state
)
4196 status
= read16(state
, SCU_COMM_EXEC__A
, &data
);
4199 if (data
== SCU_COMM_EXEC_ACTIVE
) {
4204 /* stop all comstate->m_exec */
4205 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_STOP
);
4208 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_STOP
, 0, NULL
, 1, &cmdResult
);
4213 status
= SetIqmAf(state
, false);
4217 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4222 /*============================================================================*/
4225 * \brief Setup of the QAM Measurement intervals for signal quality
4226 * \param demod instance of demod.
4227 * \param modulation current modulation.
4228 * \return DRXStatus_t.
4231 * Take into account that for certain settings the errorcounters can overflow.
4232 * The implementation does not check this.
4235 static int SetQAMMeasurement(struct drxk_state
*state
,
4236 enum EDrxkConstellation modulation
,
4239 u32 fecBitsDesired
= 0; /* BER accounting period */
4240 u32 fecRsPeriodTotal
= 0; /* Total period */
4241 u16 fecRsPrescale
= 0; /* ReedSolomon Measurement Prescale */
4242 u16 fecRsPeriod
= 0; /* Value for corresponding I2C register */
4248 /* fecBitsDesired = symbolRate [kHz] *
4254 switch (modulation
) {
4255 case DRX_CONSTELLATION_QAM16
:
4256 fecBitsDesired
= 4 * symbolRate
;
4258 case DRX_CONSTELLATION_QAM32
:
4259 fecBitsDesired
= 5 * symbolRate
;
4261 case DRX_CONSTELLATION_QAM64
:
4262 fecBitsDesired
= 6 * symbolRate
;
4264 case DRX_CONSTELLATION_QAM128
:
4265 fecBitsDesired
= 7 * symbolRate
;
4267 case DRX_CONSTELLATION_QAM256
:
4268 fecBitsDesired
= 8 * symbolRate
;
4276 fecBitsDesired
/= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */
4277 fecBitsDesired
*= 500; /* meas. period [ms] */
4279 /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */
4280 /* fecRsPeriodTotal = fecBitsDesired / 1632 */
4281 fecRsPeriodTotal
= (fecBitsDesired
/ 1632UL) + 1; /* roughly ceil */
4283 /* fecRsPeriodTotal = fecRsPrescale * fecRsPeriod */
4284 fecRsPrescale
= 1 + (u16
) (fecRsPeriodTotal
>> 16);
4285 if (fecRsPrescale
== 0) {
4286 /* Divide by zero (though impossible) */
4292 ((u16
) fecRsPeriodTotal
+
4293 (fecRsPrescale
>> 1)) / fecRsPrescale
;
4295 /* write corresponding registers */
4296 status
= write16(state
, FEC_RS_MEASUREMENT_PERIOD__A
, fecRsPeriod
);
4299 status
= write16(state
, FEC_RS_MEASUREMENT_PRESCALE__A
, fecRsPrescale
);
4302 status
= write16(state
, FEC_OC_SNC_FAIL_PERIOD__A
, fecRsPeriod
);
4305 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4309 static int SetQAM16(struct drxk_state
*state
)
4314 /* QAM Equalizer Setup */
4316 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 13517);
4319 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 13517);
4322 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 13517);
4325 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 13517);
4328 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13517);
4331 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 13517);
4334 /* Decision Feedback Equalizer */
4335 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 2);
4338 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 2);
4341 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 2);
4344 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 2);
4347 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 2);
4350 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4354 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
4357 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
4360 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4364 /* QAM Slicer Settings */
4365 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
, DRXK_QAM_SL_SIG_POWER_QAM16
);
4369 /* QAM Loop Controller Coeficients */
4370 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4373 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4376 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4379 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4382 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4385 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4388 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4391 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4395 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4398 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 20);
4401 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 80);
4404 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4407 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 20);
4410 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4413 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4416 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 16);
4419 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 32);
4422 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4425 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4428 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
4433 /* QAM State Machine (FSM) Thresholds */
4435 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 140);
4438 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 50);
4441 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 95);
4444 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 120);
4447 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 230);
4450 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 105);
4454 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4457 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4460 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 24);
4465 /* QAM FSM Tracking Parameters */
4467 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 16);
4470 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 220);
4473 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 25);
4476 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 6);
4479 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -24);
4482 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -65);
4485 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -127);
4491 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4495 /*============================================================================*/
4498 * \brief QAM32 specific setup
4499 * \param demod instance of demod.
4500 * \return DRXStatus_t.
4502 static int SetQAM32(struct drxk_state
*state
)
4508 /* QAM Equalizer Setup */
4510 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 6707);
4513 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 6707);
4516 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 6707);
4519 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 6707);
4522 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 6707);
4525 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 6707);
4529 /* Decision Feedback Equalizer */
4530 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 3);
4533 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 3);
4536 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 3);
4539 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 3);
4542 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 3);
4545 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4549 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 6);
4552 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 5);
4555 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4559 /* QAM Slicer Settings */
4561 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
, DRXK_QAM_SL_SIG_POWER_QAM32
);
4566 /* QAM Loop Controller Coeficients */
4568 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4571 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4574 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4577 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4580 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4583 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4586 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4589 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4593 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4596 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 20);
4599 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 80);
4602 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4605 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 20);
4608 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4611 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4614 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 16);
4617 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 16);
4620 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4623 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4626 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 0);
4631 /* QAM State Machine (FSM) Thresholds */
4633 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 90);
4636 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 50);
4639 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
4642 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
4645 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 170);
4648 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 100);
4652 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4655 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4658 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 10);
4663 /* QAM FSM Tracking Parameters */
4665 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 12);
4668 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 140);
4671 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) -8);
4674 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) -16);
4677 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -26);
4680 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -56);
4683 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -86);
4686 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4690 /*============================================================================*/
4693 * \brief QAM64 specific setup
4694 * \param demod instance of demod.
4695 * \return DRXStatus_t.
4697 static int SetQAM64(struct drxk_state
*state
)
4702 /* QAM Equalizer Setup */
4704 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 13336);
4707 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 12618);
4710 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 11988);
4713 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 13809);
4716 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13809);
4719 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 15609);
4723 /* Decision Feedback Equalizer */
4724 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 4);
4727 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 4);
4730 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 4);
4733 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 4);
4736 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 3);
4739 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4743 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
4746 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
4749 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4753 /* QAM Slicer Settings */
4754 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
, DRXK_QAM_SL_SIG_POWER_QAM64
);
4759 /* QAM Loop Controller Coeficients */
4761 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4764 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4767 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4770 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4773 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4776 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4779 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4782 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4786 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4789 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 30);
4792 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 100);
4795 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4798 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 30);
4801 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 50);
4804 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
4807 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
4810 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 48);
4813 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
4816 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
4819 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
4824 /* QAM State Machine (FSM) Thresholds */
4826 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 100);
4829 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
4832 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
4835 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 110);
4838 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 200);
4841 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 95);
4845 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
4848 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
4851 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 15);
4856 /* QAM FSM Tracking Parameters */
4858 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 12);
4861 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 141);
4864 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 7);
4867 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 0);
4870 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -15);
4873 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -45);
4876 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -80);
4879 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
4884 /*============================================================================*/
4887 * \brief QAM128 specific setup
4888 * \param demod: instance of demod.
4889 * \return DRXStatus_t.
4891 static int SetQAM128(struct drxk_state
*state
)
4896 /* QAM Equalizer Setup */
4898 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 6564);
4901 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 6598);
4904 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 6394);
4907 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 6409);
4910 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 6656);
4913 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 7238);
4917 /* Decision Feedback Equalizer */
4918 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 6);
4921 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 6);
4924 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 6);
4927 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 6);
4930 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 5);
4933 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
4937 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 6);
4940 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 5);
4943 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
4948 /* QAM Slicer Settings */
4950 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
, DRXK_QAM_SL_SIG_POWER_QAM128
);
4955 /* QAM Loop Controller Coeficients */
4957 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
4960 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
4963 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
4966 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
4969 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
4972 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
4975 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
4978 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
4982 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
4985 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 40);
4988 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 120);
4991 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
4994 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 40);
4997 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 60);
5000 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
5003 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
5006 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 64);
5009 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
5012 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
5015 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 0);
5020 /* QAM State Machine (FSM) Thresholds */
5022 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 50);
5025 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
5028 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
5031 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
5034 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 140);
5037 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 100);
5041 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
5044 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 5);
5048 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 12);
5052 /* QAM FSM Tracking Parameters */
5054 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 8);
5057 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 65);
5060 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 5);
5063 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 3);
5066 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) -1);
5069 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) -12);
5072 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -23);
5075 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5080 /*============================================================================*/
5083 * \brief QAM256 specific setup
5084 * \param demod: instance of demod.
5085 * \return DRXStatus_t.
5087 static int SetQAM256(struct drxk_state
*state
)
5092 /* QAM Equalizer Setup */
5094 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD0__A
, 11502);
5097 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD1__A
, 12084);
5100 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD2__A
, 12543);
5103 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD3__A
, 12931);
5106 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD4__A
, 13629);
5109 status
= write16(state
, SCU_RAM_QAM_EQ_CMA_RAD5__A
, 15385);
5113 /* Decision Feedback Equalizer */
5114 status
= write16(state
, QAM_DQ_QUAL_FUN0__A
, 8);
5117 status
= write16(state
, QAM_DQ_QUAL_FUN1__A
, 8);
5120 status
= write16(state
, QAM_DQ_QUAL_FUN2__A
, 8);
5123 status
= write16(state
, QAM_DQ_QUAL_FUN3__A
, 8);
5126 status
= write16(state
, QAM_DQ_QUAL_FUN4__A
, 6);
5129 status
= write16(state
, QAM_DQ_QUAL_FUN5__A
, 0);
5133 status
= write16(state
, QAM_SY_SYNC_HWM__A
, 5);
5136 status
= write16(state
, QAM_SY_SYNC_AWM__A
, 4);
5139 status
= write16(state
, QAM_SY_SYNC_LWM__A
, 3);
5143 /* QAM Slicer Settings */
5145 status
= write16(state
, SCU_RAM_QAM_SL_SIG_POWER__A
, DRXK_QAM_SL_SIG_POWER_QAM256
);
5150 /* QAM Loop Controller Coeficients */
5152 status
= write16(state
, SCU_RAM_QAM_LC_CA_FINE__A
, 15);
5155 status
= write16(state
, SCU_RAM_QAM_LC_CA_COARSE__A
, 40);
5158 status
= write16(state
, SCU_RAM_QAM_LC_EP_FINE__A
, 12);
5161 status
= write16(state
, SCU_RAM_QAM_LC_EP_MEDIUM__A
, 24);
5164 status
= write16(state
, SCU_RAM_QAM_LC_EP_COARSE__A
, 24);
5167 status
= write16(state
, SCU_RAM_QAM_LC_EI_FINE__A
, 12);
5170 status
= write16(state
, SCU_RAM_QAM_LC_EI_MEDIUM__A
, 16);
5173 status
= write16(state
, SCU_RAM_QAM_LC_EI_COARSE__A
, 16);
5177 status
= write16(state
, SCU_RAM_QAM_LC_CP_FINE__A
, 5);
5180 status
= write16(state
, SCU_RAM_QAM_LC_CP_MEDIUM__A
, 50);
5183 status
= write16(state
, SCU_RAM_QAM_LC_CP_COARSE__A
, 250);
5186 status
= write16(state
, SCU_RAM_QAM_LC_CI_FINE__A
, 5);
5189 status
= write16(state
, SCU_RAM_QAM_LC_CI_MEDIUM__A
, 50);
5192 status
= write16(state
, SCU_RAM_QAM_LC_CI_COARSE__A
, 125);
5195 status
= write16(state
, SCU_RAM_QAM_LC_CF_FINE__A
, 16);
5198 status
= write16(state
, SCU_RAM_QAM_LC_CF_MEDIUM__A
, 25);
5201 status
= write16(state
, SCU_RAM_QAM_LC_CF_COARSE__A
, 48);
5204 status
= write16(state
, SCU_RAM_QAM_LC_CF1_FINE__A
, 5);
5207 status
= write16(state
, SCU_RAM_QAM_LC_CF1_MEDIUM__A
, 10);
5210 status
= write16(state
, SCU_RAM_QAM_LC_CF1_COARSE__A
, 10);
5215 /* QAM State Machine (FSM) Thresholds */
5217 status
= write16(state
, SCU_RAM_QAM_FSM_RTH__A
, 50);
5220 status
= write16(state
, SCU_RAM_QAM_FSM_FTH__A
, 60);
5223 status
= write16(state
, SCU_RAM_QAM_FSM_CTH__A
, 80);
5226 status
= write16(state
, SCU_RAM_QAM_FSM_PTH__A
, 100);
5229 status
= write16(state
, SCU_RAM_QAM_FSM_QTH__A
, 150);
5232 status
= write16(state
, SCU_RAM_QAM_FSM_MTH__A
, 110);
5236 status
= write16(state
, SCU_RAM_QAM_FSM_RATE_LIM__A
, 40);
5239 status
= write16(state
, SCU_RAM_QAM_FSM_COUNT_LIM__A
, 4);
5242 status
= write16(state
, SCU_RAM_QAM_FSM_FREQ_LIM__A
, 12);
5247 /* QAM FSM Tracking Parameters */
5249 status
= write16(state
, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A
, (u16
) 8);
5252 status
= write16(state
, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A
, (u16
) 74);
5255 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A
, (u16
) 18);
5258 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A
, (u16
) 13);
5261 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A
, (u16
) 7);
5264 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A
, (u16
) 0);
5267 status
= write16(state
, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A
, (u16
) -8);
5270 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5275 /*============================================================================*/
5277 * \brief Reset QAM block.
5278 * \param demod: instance of demod.
5279 * \param channel: pointer to channel data.
5280 * \return DRXStatus_t.
5282 static int QAMResetQAM(struct drxk_state
*state
)
5288 /* Stop QAM comstate->m_exec */
5289 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_STOP
);
5293 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_RESET
, 0, NULL
, 1, &cmdResult
);
5296 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5300 /*============================================================================*/
5303 * \brief Set QAM symbolrate.
5304 * \param demod: instance of demod.
5305 * \param channel: pointer to channel data.
5306 * \return DRXStatus_t.
5308 static int QAMSetSymbolrate(struct drxk_state
*state
)
5310 u32 adcFrequency
= 0;
5318 /* Select & calculate correct IQM rate */
5319 adcFrequency
= (state
->m_sysClockFreq
* 1000) / 3;
5321 /* printk(KERN_DEBUG "drxk: SR %d\n", state->props.symbol_rate); */
5322 if (state
->props
.symbol_rate
<= 1188750)
5324 else if (state
->props
.symbol_rate
<= 2377500)
5326 else if (state
->props
.symbol_rate
<= 4755000)
5328 status
= write16(state
, IQM_FD_RATESEL__A
, ratesel
);
5333 IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23)
5335 symbFreq
= state
->props
.symbol_rate
* (1 << ratesel
);
5336 if (symbFreq
== 0) {
5337 /* Divide by zero */
5341 iqmRcRate
= (adcFrequency
/ symbFreq
) * (1 << 21) +
5342 (Frac28a((adcFrequency
% symbFreq
), symbFreq
) >> 7) -
5344 status
= write32(state
, IQM_RC_RATE_OFS_LO__A
, iqmRcRate
);
5347 state
->m_iqmRcRate
= iqmRcRate
;
5349 LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15))
5351 symbFreq
= state
->props
.symbol_rate
;
5352 if (adcFrequency
== 0) {
5353 /* Divide by zero */
5357 lcSymbRate
= (symbFreq
/ adcFrequency
) * (1 << 12) +
5358 (Frac28a((symbFreq
% adcFrequency
), adcFrequency
) >>
5360 if (lcSymbRate
> 511)
5362 status
= write16(state
, QAM_LC_SYMBOL_FREQ__A
, (u16
) lcSymbRate
);
5366 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5370 /*============================================================================*/
5373 * \brief Get QAM lock status.
5374 * \param demod: instance of demod.
5375 * \param channel: pointer to channel data.
5376 * \return DRXStatus_t.
5379 static int GetQAMLockStatus(struct drxk_state
*state
, u32
*pLockStatus
)
5382 u16 Result
[2] = { 0, 0 };
5385 *pLockStatus
= NOT_LOCKED
;
5386 status
= scu_command(state
,
5387 SCU_RAM_COMMAND_STANDARD_QAM
|
5388 SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK
, 0, NULL
, 2,
5391 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5393 if (Result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED
) {
5394 /* 0x0000 NOT LOCKED */
5395 } else if (Result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED
) {
5396 /* 0x4000 DEMOD LOCKED */
5397 *pLockStatus
= DEMOD_LOCK
;
5398 } else if (Result
[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK
) {
5399 /* 0x8000 DEMOD + FEC LOCKED (system lock) */
5400 *pLockStatus
= MPEG_LOCK
;
5402 /* 0xC000 NEVER LOCKED */
5403 /* (system will never be able to lock to the signal) */
5404 /* TODO: check this, intermediate & standard specific lock states are not
5405 taken into account here */
5406 *pLockStatus
= NEVER_LOCK
;
5411 #define QAM_MIRROR__M 0x03
5412 #define QAM_MIRROR_NORMAL 0x00
5413 #define QAM_MIRRORED 0x01
5414 #define QAM_MIRROR_AUTO_ON 0x02
5415 #define QAM_LOCKRANGE__M 0x10
5416 #define QAM_LOCKRANGE_NORMAL 0x10
5418 static int QAMDemodulatorCommand(struct drxk_state
*state
,
5419 int numberOfParameters
)
5423 u16 setParamParameters
[4] = { 0, 0, 0, 0 };
5425 setParamParameters
[0] = state
->m_Constellation
; /* modulation */
5426 setParamParameters
[1] = DRXK_QAM_I12_J17
; /* interleave mode */
5428 if (numberOfParameters
== 2) {
5429 u16 setEnvParameters
[1] = { 0 };
5431 if (state
->m_OperationMode
== OM_QAM_ITU_C
)
5432 setEnvParameters
[0] = QAM_TOP_ANNEX_C
;
5434 setEnvParameters
[0] = QAM_TOP_ANNEX_A
;
5436 status
= scu_command(state
,
5437 SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV
,
5438 1, setEnvParameters
, 1, &cmdResult
);
5442 status
= scu_command(state
,
5443 SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM
,
5444 numberOfParameters
, setParamParameters
,
5446 } else if (numberOfParameters
== 4) {
5447 if (state
->m_OperationMode
== OM_QAM_ITU_C
)
5448 setParamParameters
[2] = QAM_TOP_ANNEX_C
;
5450 setParamParameters
[2] = QAM_TOP_ANNEX_A
;
5452 setParamParameters
[3] |= (QAM_MIRROR_AUTO_ON
);
5453 /* Env parameters */
5454 /* check for LOCKRANGE Extented */
5455 /* setParamParameters[3] |= QAM_LOCKRANGE_NORMAL; */
5457 status
= scu_command(state
,
5458 SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM
,
5459 numberOfParameters
, setParamParameters
,
5462 printk(KERN_WARNING
"drxk: Unknown QAM demodulator parameter "
5463 "count %d\n", numberOfParameters
);
5468 printk(KERN_WARNING
"drxk: Warning %d on %s\n",
5473 static int SetQAM(struct drxk_state
*state
, u16 IntermediateFreqkHz
,
5474 s32 tunerFreqOffset
)
5478 int qamDemodParamCount
= state
->qam_demod_parameter_count
;
5482 * STEP 1: reset demodulator
5483 * resets FEC DI and FEC RS
5485 * resets SCU variables
5487 status
= write16(state
, FEC_DI_COMM_EXEC__A
, FEC_DI_COMM_EXEC_STOP
);
5490 status
= write16(state
, FEC_RS_COMM_EXEC__A
, FEC_RS_COMM_EXEC_STOP
);
5493 status
= QAMResetQAM(state
);
5498 * STEP 2: configure demodulator
5499 * -set params; resets IQM,QAM,FEC HW; initializes some
5502 status
= QAMSetSymbolrate(state
);
5507 switch (state
->props
.modulation
) {
5509 state
->m_Constellation
= DRX_CONSTELLATION_QAM256
;
5513 state
->m_Constellation
= DRX_CONSTELLATION_QAM64
;
5516 state
->m_Constellation
= DRX_CONSTELLATION_QAM16
;
5519 state
->m_Constellation
= DRX_CONSTELLATION_QAM32
;
5522 state
->m_Constellation
= DRX_CONSTELLATION_QAM128
;
5531 /* Use the 4-parameter if it's requested or we're probing for
5532 * the correct command. */
5533 if (state
->qam_demod_parameter_count
== 4
5534 || !state
->qam_demod_parameter_count
) {
5535 qamDemodParamCount
= 4;
5536 status
= QAMDemodulatorCommand(state
, qamDemodParamCount
);
5539 /* Use the 2-parameter command if it was requested or if we're
5540 * probing for the correct command and the 4-parameter command
5542 if (state
->qam_demod_parameter_count
== 2
5543 || (!state
->qam_demod_parameter_count
&& status
< 0)) {
5544 qamDemodParamCount
= 2;
5545 status
= QAMDemodulatorCommand(state
, qamDemodParamCount
);
5549 dprintk(1, "Could not set demodulator parameters. Make "
5550 "sure qam_demod_parameter_count (%d) is correct for "
5551 "your firmware (%s).\n",
5552 state
->qam_demod_parameter_count
,
5553 state
->microcode_name
);
5555 } else if (!state
->qam_demod_parameter_count
) {
5556 dprintk(1, "Auto-probing the correct QAM demodulator command "
5557 "parameters was successful - using %d parameters.\n",
5558 qamDemodParamCount
);
5561 * One of our commands was successful. We don't need to
5562 * auto-probe anymore, now that we got the correct command.
5564 state
->qam_demod_parameter_count
= qamDemodParamCount
;
5568 * STEP 3: enable the system in a mode where the ADC provides valid
5569 * signal setup modulation independent registers
5572 status
= SetFrequency(channel
, tunerFreqOffset
));
5576 status
= SetFrequencyShifter(state
, IntermediateFreqkHz
, tunerFreqOffset
, true);
5580 /* Setup BER measurement */
5581 status
= SetQAMMeasurement(state
, state
->m_Constellation
, state
->props
.symbol_rate
);
5585 /* Reset default values */
5586 status
= write16(state
, IQM_CF_SCALE_SH__A
, IQM_CF_SCALE_SH__PRE
);
5589 status
= write16(state
, QAM_SY_TIMEOUT__A
, QAM_SY_TIMEOUT__PRE
);
5593 /* Reset default LC values */
5594 status
= write16(state
, QAM_LC_RATE_LIMIT__A
, 3);
5597 status
= write16(state
, QAM_LC_LPF_FACTORP__A
, 4);
5600 status
= write16(state
, QAM_LC_LPF_FACTORI__A
, 4);
5603 status
= write16(state
, QAM_LC_MODE__A
, 7);
5607 status
= write16(state
, QAM_LC_QUAL_TAB0__A
, 1);
5610 status
= write16(state
, QAM_LC_QUAL_TAB1__A
, 1);
5613 status
= write16(state
, QAM_LC_QUAL_TAB2__A
, 1);
5616 status
= write16(state
, QAM_LC_QUAL_TAB3__A
, 1);
5619 status
= write16(state
, QAM_LC_QUAL_TAB4__A
, 2);
5622 status
= write16(state
, QAM_LC_QUAL_TAB5__A
, 2);
5625 status
= write16(state
, QAM_LC_QUAL_TAB6__A
, 2);
5628 status
= write16(state
, QAM_LC_QUAL_TAB8__A
, 2);
5631 status
= write16(state
, QAM_LC_QUAL_TAB9__A
, 2);
5634 status
= write16(state
, QAM_LC_QUAL_TAB10__A
, 2);
5637 status
= write16(state
, QAM_LC_QUAL_TAB12__A
, 2);
5640 status
= write16(state
, QAM_LC_QUAL_TAB15__A
, 3);
5643 status
= write16(state
, QAM_LC_QUAL_TAB16__A
, 3);
5646 status
= write16(state
, QAM_LC_QUAL_TAB20__A
, 4);
5649 status
= write16(state
, QAM_LC_QUAL_TAB25__A
, 4);
5653 /* Mirroring, QAM-block starting point not inverted */
5654 status
= write16(state
, QAM_SY_SP_INV__A
, QAM_SY_SP_INV_SPECTRUM_INV_DIS
);
5658 /* Halt SCU to enable safe non-atomic accesses */
5659 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
5663 /* STEP 4: modulation specific setup */
5664 switch (state
->props
.modulation
) {
5666 status
= SetQAM16(state
);
5669 status
= SetQAM32(state
);
5673 status
= SetQAM64(state
);
5676 status
= SetQAM128(state
);
5679 status
= SetQAM256(state
);
5688 /* Activate SCU to enable SCU commands */
5689 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
5693 /* Re-configure MPEG output, requires knowledge of channel bitrate */
5694 /* extAttr->currentChannel.modulation = channel->modulation; */
5695 /* extAttr->currentChannel.symbolrate = channel->symbolrate; */
5696 status
= MPEGTSDtoSetup(state
, state
->m_OperationMode
);
5700 /* Start processes */
5701 status
= MPEGTSStart(state
);
5704 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_ACTIVE
);
5707 status
= write16(state
, QAM_COMM_EXEC__A
, QAM_COMM_EXEC_ACTIVE
);
5710 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_ACTIVE
);
5714 /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */
5715 status
= scu_command(state
, SCU_RAM_COMMAND_STANDARD_QAM
| SCU_RAM_COMMAND_CMD_DEMOD_START
, 0, NULL
, 1, &cmdResult
);
5719 /* update global DRXK data container */
5720 /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */
5724 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5728 static int SetQAMStandard(struct drxk_state
*state
,
5729 enum OperationMode oMode
)
5732 #ifdef DRXK_QAM_TAPS
5733 #define DRXK_QAMA_TAPS_SELECT
5734 #include "drxk_filters.h"
5735 #undef DRXK_QAMA_TAPS_SELECT
5740 /* added antenna switch */
5741 SwitchAntennaToQAM(state
);
5743 /* Ensure correct power-up mode */
5744 status
= PowerUpQAM(state
);
5747 /* Reset QAM block */
5748 status
= QAMResetQAM(state
);
5754 status
= write16(state
, IQM_COMM_EXEC__A
, IQM_COMM_EXEC_B_STOP
);
5757 status
= write16(state
, IQM_AF_AMUX__A
, IQM_AF_AMUX_SIGNAL2ADC
);
5761 /* Upload IQM Channel Filter settings by
5762 boot loader from ROM table */
5765 status
= BLChainCmd(state
, DRXK_BL_ROM_OFFSET_TAPS_ITU_A
, DRXK_BLCC_NR_ELEMENTS_TAPS
, DRXK_BLC_TIMEOUT
);
5768 status
= BLDirectCmd(state
, IQM_CF_TAP_RE0__A
, DRXK_BL_ROM_OFFSET_TAPS_ITU_C
, DRXK_BLDC_NR_ELEMENTS_TAPS
, DRXK_BLC_TIMEOUT
);
5771 status
= BLDirectCmd(state
, IQM_CF_TAP_IM0__A
, DRXK_BL_ROM_OFFSET_TAPS_ITU_C
, DRXK_BLDC_NR_ELEMENTS_TAPS
, DRXK_BLC_TIMEOUT
);
5779 status
= write16(state
, IQM_CF_OUT_ENA__A
, (1 << IQM_CF_OUT_ENA_QAM__B
));
5782 status
= write16(state
, IQM_CF_SYMMETRIC__A
, 0);
5785 status
= write16(state
, IQM_CF_MIDTAP__A
, ((1 << IQM_CF_MIDTAP_RE__B
) | (1 << IQM_CF_MIDTAP_IM__B
)));
5789 status
= write16(state
, IQM_RC_STRETCH__A
, 21);
5792 status
= write16(state
, IQM_AF_CLP_LEN__A
, 0);
5795 status
= write16(state
, IQM_AF_CLP_TH__A
, 448);
5798 status
= write16(state
, IQM_AF_SNS_LEN__A
, 0);
5801 status
= write16(state
, IQM_CF_POW_MEAS_LEN__A
, 0);
5805 status
= write16(state
, IQM_FS_ADJ_SEL__A
, 1);
5808 status
= write16(state
, IQM_RC_ADJ_SEL__A
, 1);
5811 status
= write16(state
, IQM_CF_ADJ_SEL__A
, 1);
5814 status
= write16(state
, IQM_AF_UPD_SEL__A
, 0);
5818 /* IQM Impulse Noise Processing Unit */
5819 status
= write16(state
, IQM_CF_CLP_VAL__A
, 500);
5822 status
= write16(state
, IQM_CF_DATATH__A
, 1000);
5825 status
= write16(state
, IQM_CF_BYPASSDET__A
, 1);
5828 status
= write16(state
, IQM_CF_DET_LCT__A
, 0);
5831 status
= write16(state
, IQM_CF_WND_LEN__A
, 1);
5834 status
= write16(state
, IQM_CF_PKDTH__A
, 1);
5837 status
= write16(state
, IQM_AF_INC_BYPASS__A
, 1);
5841 /* turn on IQMAF. Must be done before setAgc**() */
5842 status
= SetIqmAf(state
, true);
5845 status
= write16(state
, IQM_AF_START_LOCK__A
, 0x01);
5849 /* IQM will not be reset from here, sync ADC and update/init AGC */
5850 status
= ADCSynchronization(state
);
5854 /* Set the FSM step period */
5855 status
= write16(state
, SCU_RAM_QAM_FSM_STEP_PERIOD__A
, 2000);
5859 /* Halt SCU to enable safe non-atomic accesses */
5860 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_HOLD
);
5864 /* No more resets of the IQM, current standard correctly set =>
5865 now AGCs can be configured. */
5867 status
= InitAGC(state
, true);
5870 status
= SetPreSaw(state
, &(state
->m_qamPreSawCfg
));
5874 /* Configure AGC's */
5875 status
= SetAgcRf(state
, &(state
->m_qamRfAgcCfg
), true);
5878 status
= SetAgcIf(state
, &(state
->m_qamIfAgcCfg
), true);
5882 /* Activate SCU to enable SCU commands */
5883 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
5886 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5890 static int WriteGPIO(struct drxk_state
*state
)
5896 /* stop lock indicator process */
5897 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
5901 /* Write magic word to enable pdr reg write */
5902 status
= write16(state
, SIO_TOP_COMM_KEY__A
, SIO_TOP_COMM_KEY_KEY
);
5906 if (state
->m_hasSAWSW
) {
5907 if (state
->UIO_mask
& 0x0001) { /* UIO-1 */
5908 /* write to io pad configuration register - output mode */
5909 status
= write16(state
, SIO_PDR_SMA_TX_CFG__A
, state
->m_GPIOCfg
);
5913 /* use corresponding bit in io data output registar */
5914 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5917 if ((state
->m_GPIO
& 0x0001) == 0)
5918 value
&= 0x7FFF; /* write zero to 15th bit - 1st UIO */
5920 value
|= 0x8000; /* write one to 15th bit - 1st UIO */
5921 /* write back to io data output register */
5922 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5926 if (state
->UIO_mask
& 0x0002) { /* UIO-2 */
5927 /* write to io pad configuration register - output mode */
5928 status
= write16(state
, SIO_PDR_SMA_RX_CFG__A
, state
->m_GPIOCfg
);
5932 /* use corresponding bit in io data output registar */
5933 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5936 if ((state
->m_GPIO
& 0x0002) == 0)
5937 value
&= 0xBFFF; /* write zero to 14th bit - 2st UIO */
5939 value
|= 0x4000; /* write one to 14th bit - 2st UIO */
5940 /* write back to io data output register */
5941 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5945 if (state
->UIO_mask
& 0x0004) { /* UIO-3 */
5946 /* write to io pad configuration register - output mode */
5947 status
= write16(state
, SIO_PDR_GPIO_CFG__A
, state
->m_GPIOCfg
);
5951 /* use corresponding bit in io data output registar */
5952 status
= read16(state
, SIO_PDR_UIO_OUT_LO__A
, &value
);
5955 if ((state
->m_GPIO
& 0x0004) == 0)
5956 value
&= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */
5958 value
|= 0x0004; /* write one to 2nd bit - 3rd UIO */
5959 /* write back to io data output register */
5960 status
= write16(state
, SIO_PDR_UIO_OUT_LO__A
, value
);
5965 /* Write magic word to disable pdr reg write */
5966 status
= write16(state
, SIO_TOP_COMM_KEY__A
, 0x0000);
5969 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5973 static int SwitchAntennaToQAM(struct drxk_state
*state
)
5980 if (!state
->antenna_gpio
)
5983 gpio_state
= state
->m_GPIO
& state
->antenna_gpio
;
5985 if (state
->antenna_dvbt
^ gpio_state
) {
5986 /* Antenna is on DVB-T mode. Switch */
5987 if (state
->antenna_dvbt
)
5988 state
->m_GPIO
&= ~state
->antenna_gpio
;
5990 state
->m_GPIO
|= state
->antenna_gpio
;
5991 status
= WriteGPIO(state
);
5994 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
5998 static int SwitchAntennaToDVBT(struct drxk_state
*state
)
6005 if (!state
->antenna_gpio
)
6008 gpio_state
= state
->m_GPIO
& state
->antenna_gpio
;
6010 if (!(state
->antenna_dvbt
^ gpio_state
)) {
6011 /* Antenna is on DVB-C mode. Switch */
6012 if (state
->antenna_dvbt
)
6013 state
->m_GPIO
|= state
->antenna_gpio
;
6015 state
->m_GPIO
&= ~state
->antenna_gpio
;
6016 status
= WriteGPIO(state
);
6019 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
6024 static int PowerDownDevice(struct drxk_state
*state
)
6026 /* Power down to requested mode */
6027 /* Backup some register settings */
6028 /* Set pins with possible pull-ups connected to them in input mode */
6029 /* Analog power down */
6030 /* ADC power down */
6031 /* Power down device */
6035 if (state
->m_bPDownOpenBridge
) {
6036 /* Open I2C bridge before power down of DRXK */
6037 status
= ConfigureI2CBridge(state
, true);
6042 status
= DVBTEnableOFDMTokenRing(state
, false);
6046 status
= write16(state
, SIO_CC_PWD_MODE__A
, SIO_CC_PWD_MODE_LEVEL_CLOCK
);
6049 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
6052 state
->m_HICfgCtrl
|= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ
;
6053 status
= HI_CfgCommand(state
);
6056 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
6061 static int init_drxk(struct drxk_state
*state
)
6063 int status
= 0, n
= 0;
6064 enum DRXPowerMode powerMode
= DRXK_POWER_DOWN_OFDM
;
6068 if ((state
->m_DrxkState
== DRXK_UNINITIALIZED
)) {
6069 drxk_i2c_lock(state
);
6070 status
= PowerUpDevice(state
);
6073 status
= DRXX_Open(state
);
6076 /* Soft reset of OFDM-, sys- and osc-clockdomain */
6077 status
= write16(state
, SIO_CC_SOFT_RST__A
, SIO_CC_SOFT_RST_OFDM__M
| SIO_CC_SOFT_RST_SYS__M
| SIO_CC_SOFT_RST_OSC__M
);
6080 status
= write16(state
, SIO_CC_UPDATE__A
, SIO_CC_UPDATE_KEY
);
6083 /* TODO is this needed, if yes how much delay in worst case scenario */
6085 state
->m_DRXK_A3_PATCH_CODE
= true;
6086 status
= GetDeviceCapabilities(state
);
6090 /* Bridge delay, uses oscilator clock */
6091 /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */
6092 /* SDA brdige delay */
6093 state
->m_HICfgBridgeDelay
=
6094 (u16
) ((state
->m_oscClockFreq
/ 1000) *
6095 HI_I2C_BRIDGE_DELAY
) / 1000;
6097 if (state
->m_HICfgBridgeDelay
>
6098 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M
) {
6099 state
->m_HICfgBridgeDelay
=
6100 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M
;
6102 /* SCL bridge delay, same as SDA for now */
6103 state
->m_HICfgBridgeDelay
+=
6104 state
->m_HICfgBridgeDelay
<<
6105 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B
;
6107 status
= InitHI(state
);
6110 /* disable various processes */
6112 if (!(state
->m_DRXK_A1_ROM_CODE
)
6113 && !(state
->m_DRXK_A2_ROM_CODE
))
6116 status
= write16(state
, SCU_RAM_GPIO__A
, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE
);
6121 /* disable MPEG port */
6122 status
= MPEGTSDisable(state
);
6126 /* Stop AUD and SCU */
6127 status
= write16(state
, AUD_COMM_EXEC__A
, AUD_COMM_EXEC_STOP
);
6130 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_STOP
);
6134 /* enable token-ring bus through OFDM block for possible ucode upload */
6135 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
, SIO_OFDM_SH_OFDM_RING_ENABLE_ON
);
6139 /* include boot loader section */
6140 status
= write16(state
, SIO_BL_COMM_EXEC__A
, SIO_BL_COMM_EXEC_ACTIVE
);
6143 status
= BLChainCmd(state
, 0, 6, 100);
6148 status
= DownloadMicrocode(state
, state
->fw
->data
,
6154 /* disable token-ring bus through OFDM block for possible ucode upload */
6155 status
= write16(state
, SIO_OFDM_SH_OFDM_RING_ENABLE__A
, SIO_OFDM_SH_OFDM_RING_ENABLE_OFF
);
6159 /* Run SCU for a little while to initialize microcode version numbers */
6160 status
= write16(state
, SCU_COMM_EXEC__A
, SCU_COMM_EXEC_ACTIVE
);
6163 status
= DRXX_Open(state
);
6166 /* added for test */
6169 powerMode
= DRXK_POWER_DOWN_OFDM
;
6170 status
= CtrlPowerMode(state
, &powerMode
);
6174 /* Stamp driver version number in SCU data RAM in BCD code
6175 Done to enable field application engineers to retreive drxdriver version
6176 via I2C from SCU RAM.
6177 Not using SCU command interface for SCU register access since no
6178 microcode may be present.
6181 (((DRXK_VERSION_MAJOR
/ 100) % 10) << 12) +
6182 (((DRXK_VERSION_MAJOR
/ 10) % 10) << 8) +
6183 ((DRXK_VERSION_MAJOR
% 10) << 4) +
6184 (DRXK_VERSION_MINOR
% 10);
6185 status
= write16(state
, SCU_RAM_DRIVER_VER_HI__A
, driverVersion
);
6189 (((DRXK_VERSION_PATCH
/ 1000) % 10) << 12) +
6190 (((DRXK_VERSION_PATCH
/ 100) % 10) << 8) +
6191 (((DRXK_VERSION_PATCH
/ 10) % 10) << 4) +
6192 (DRXK_VERSION_PATCH
% 10);
6193 status
= write16(state
, SCU_RAM_DRIVER_VER_LO__A
, driverVersion
);
6197 printk(KERN_INFO
"DRXK driver version %d.%d.%d\n",
6198 DRXK_VERSION_MAJOR
, DRXK_VERSION_MINOR
,
6199 DRXK_VERSION_PATCH
);
6201 /* Dirty fix of default values for ROM/PATCH microcode
6202 Dirty because this fix makes it impossible to setup suitable values
6203 before calling DRX_Open. This solution requires changes to RF AGC speed
6204 to be done via the CTRL function after calling DRX_Open */
6206 /* m_dvbtRfAgcCfg.speed = 3; */
6208 /* Reset driver debug flags to 0 */
6209 status
= write16(state
, SCU_RAM_DRIVER_DEBUG__A
, 0);
6214 NOTE: No more full FEC resets allowed afterwards!! */
6215 status
= write16(state
, FEC_COMM_EXEC__A
, FEC_COMM_EXEC_STOP
);
6218 /* MPEGTS functions are still the same */
6219 status
= MPEGTSDtoInit(state
);
6222 status
= MPEGTSStop(state
);
6225 status
= MPEGTSConfigurePolarity(state
);
6228 status
= MPEGTSConfigurePins(state
, state
->m_enableMPEGOutput
);
6231 /* added: configure GPIO */
6232 status
= WriteGPIO(state
);
6236 state
->m_DrxkState
= DRXK_STOPPED
;
6238 if (state
->m_bPowerDown
) {
6239 status
= PowerDownDevice(state
);
6242 state
->m_DrxkState
= DRXK_POWERED_DOWN
;
6244 state
->m_DrxkState
= DRXK_STOPPED
;
6246 /* Initialize the supported delivery systems */
6248 if (state
->m_hasDVBC
) {
6249 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_A
;
6250 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_C
;
6251 strlcat(state
->frontend
.ops
.info
.name
, " DVB-C",
6252 sizeof(state
->frontend
.ops
.info
.name
));
6254 if (state
->m_hasDVBT
) {
6255 state
->frontend
.ops
.delsys
[n
++] = SYS_DVBT
;
6256 strlcat(state
->frontend
.ops
.info
.name
, " DVB-T",
6257 sizeof(state
->frontend
.ops
.info
.name
));
6259 drxk_i2c_unlock(state
);
6263 state
->m_DrxkState
= DRXK_NO_DEV
;
6264 drxk_i2c_unlock(state
);
6265 printk(KERN_ERR
"drxk: Error %d on %s\n", status
, __func__
);
6271 static void load_firmware_cb(const struct firmware
*fw
,
6274 struct drxk_state
*state
= context
;
6276 dprintk(1, ": %s\n", fw
? "firmware loaded" : "firmware not loaded");
6279 "drxk: Could not load firmware file %s.\n",
6280 state
->microcode_name
);
6282 "drxk: Copy %s to your hotplug directory!\n",
6283 state
->microcode_name
);
6284 state
->microcode_name
= NULL
;
6287 * As firmware is now load asynchronous, it is not possible
6288 * anymore to fail at frontend attach. We might silently
6289 * return here, and hope that the driver won't crash.
6290 * We might also change all DVB callbacks to return -ENODEV
6291 * if the device is not initialized.
6292 * As the DRX-K devices have their own internal firmware,
6293 * let's just hope that it will match a firmware revision
6294 * compatible with this driver and proceed.
6302 static void drxk_release(struct dvb_frontend
*fe
)
6304 struct drxk_state
*state
= fe
->demodulator_priv
;
6308 release_firmware(state
->fw
);
6313 static int drxk_sleep(struct dvb_frontend
*fe
)
6315 struct drxk_state
*state
= fe
->demodulator_priv
;
6319 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6321 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6328 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
6330 struct drxk_state
*state
= fe
->demodulator_priv
;
6332 dprintk(1, ": %s\n", enable
? "enable" : "disable");
6334 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6337 return ConfigureI2CBridge(state
, enable
? true : false);
6340 static int drxk_set_parameters(struct dvb_frontend
*fe
)
6342 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
6343 u32 delsys
= p
->delivery_system
, old_delsys
;
6344 struct drxk_state
*state
= fe
->demodulator_priv
;
6349 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6352 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6355 if (!fe
->ops
.tuner_ops
.get_if_frequency
) {
6357 "drxk: Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
6361 if (fe
->ops
.i2c_gate_ctrl
)
6362 fe
->ops
.i2c_gate_ctrl(fe
, 1);
6363 if (fe
->ops
.tuner_ops
.set_params
)
6364 fe
->ops
.tuner_ops
.set_params(fe
);
6365 if (fe
->ops
.i2c_gate_ctrl
)
6366 fe
->ops
.i2c_gate_ctrl(fe
, 0);
6368 old_delsys
= state
->props
.delivery_system
;
6371 if (old_delsys
!= delsys
) {
6374 case SYS_DVBC_ANNEX_A
:
6375 case SYS_DVBC_ANNEX_C
:
6376 if (!state
->m_hasDVBC
)
6378 state
->m_itut_annex_c
= (delsys
== SYS_DVBC_ANNEX_C
) ? true : false;
6379 if (state
->m_itut_annex_c
)
6380 SetOperationMode(state
, OM_QAM_ITU_C
);
6382 SetOperationMode(state
, OM_QAM_ITU_A
);
6385 if (!state
->m_hasDVBT
)
6387 SetOperationMode(state
, OM_DVBT
);
6394 fe
->ops
.tuner_ops
.get_if_frequency(fe
, &IF
);
6395 Start(state
, 0, IF
);
6397 /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */
6402 static int drxk_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
6404 struct drxk_state
*state
= fe
->demodulator_priv
;
6409 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6411 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6415 GetLockStatus(state
, &stat
, 0);
6416 if (stat
== MPEG_LOCK
)
6418 if (stat
== FEC_LOCK
)
6420 if (stat
== DEMOD_LOCK
)
6425 static int drxk_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
6427 struct drxk_state
*state
= fe
->demodulator_priv
;
6431 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6433 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6440 static int drxk_read_signal_strength(struct dvb_frontend
*fe
,
6443 struct drxk_state
*state
= fe
->demodulator_priv
;
6448 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6450 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6453 ReadIFAgc(state
, &val
);
6454 *strength
= val
& 0xffff;
6458 static int drxk_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
6460 struct drxk_state
*state
= fe
->demodulator_priv
;
6465 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6467 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6470 GetSignalToNoise(state
, &snr2
);
6471 *snr
= snr2
& 0xffff;
6475 static int drxk_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
6477 struct drxk_state
*state
= fe
->demodulator_priv
;
6482 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6484 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6487 DVBTQAMGetAccPktErr(state
, &err
);
6488 *ucblocks
= (u32
) err
;
6492 static int drxk_get_tune_settings(struct dvb_frontend
*fe
, struct dvb_frontend_tune_settings
6495 struct drxk_state
*state
= fe
->demodulator_priv
;
6496 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
6500 if (state
->m_DrxkState
== DRXK_NO_DEV
)
6502 if (state
->m_DrxkState
== DRXK_UNINITIALIZED
)
6505 switch (p
->delivery_system
) {
6506 case SYS_DVBC_ANNEX_A
:
6507 case SYS_DVBC_ANNEX_C
:
6509 sets
->min_delay_ms
= 3000;
6510 sets
->max_drift
= 0;
6511 sets
->step_size
= 0;
6518 static struct dvb_frontend_ops drxk_ops
= {
6519 /* .delsys will be filled dynamically */
6522 .frequency_min
= 47000000,
6523 .frequency_max
= 865000000,
6525 .symbol_rate_min
= 870000,
6526 .symbol_rate_max
= 11700000,
6528 .frequency_stepsize
= 166667,
6530 .caps
= FE_CAN_QAM_16
| FE_CAN_QAM_32
| FE_CAN_QAM_64
|
6531 FE_CAN_QAM_128
| FE_CAN_QAM_256
| FE_CAN_FEC_AUTO
|
6532 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
6533 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_MUTE_TS
|
6534 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_RECOVER
|
6535 FE_CAN_GUARD_INTERVAL_AUTO
| FE_CAN_HIERARCHY_AUTO
6538 .release
= drxk_release
,
6539 .sleep
= drxk_sleep
,
6540 .i2c_gate_ctrl
= drxk_gate_ctrl
,
6542 .set_frontend
= drxk_set_parameters
,
6543 .get_tune_settings
= drxk_get_tune_settings
,
6545 .read_status
= drxk_read_status
,
6546 .read_ber
= drxk_read_ber
,
6547 .read_signal_strength
= drxk_read_signal_strength
,
6548 .read_snr
= drxk_read_snr
,
6549 .read_ucblocks
= drxk_read_ucblocks
,
6552 struct dvb_frontend
*drxk_attach(const struct drxk_config
*config
,
6553 struct i2c_adapter
*i2c
)
6555 struct drxk_state
*state
= NULL
;
6556 u8 adr
= config
->adr
;
6560 state
= kzalloc(sizeof(struct drxk_state
), GFP_KERNEL
);
6565 state
->demod_address
= adr
;
6566 state
->single_master
= config
->single_master
;
6567 state
->microcode_name
= config
->microcode_name
;
6568 state
->qam_demod_parameter_count
= config
->qam_demod_parameter_count
;
6569 state
->no_i2c_bridge
= config
->no_i2c_bridge
;
6570 state
->antenna_gpio
= config
->antenna_gpio
;
6571 state
->antenna_dvbt
= config
->antenna_dvbt
;
6572 state
->m_ChunkSize
= config
->chunk_size
;
6573 state
->enable_merr_cfg
= config
->enable_merr_cfg
;
6575 if (config
->dynamic_clk
) {
6576 state
->m_DVBTStaticCLK
= 0;
6577 state
->m_DVBCStaticCLK
= 0;
6579 state
->m_DVBTStaticCLK
= 1;
6580 state
->m_DVBCStaticCLK
= 1;
6584 if (config
->mpeg_out_clk_strength
)
6585 state
->m_TSClockkStrength
= config
->mpeg_out_clk_strength
& 0x07;
6587 state
->m_TSClockkStrength
= 0x06;
6589 if (config
->parallel_ts
)
6590 state
->m_enableParallel
= true;
6592 state
->m_enableParallel
= false;
6594 /* NOTE: as more UIO bits will be used, add them to the mask */
6595 state
->UIO_mask
= config
->antenna_gpio
;
6597 /* Default gpio to DVB-C */
6598 if (!state
->antenna_dvbt
&& state
->antenna_gpio
)
6599 state
->m_GPIO
|= state
->antenna_gpio
;
6601 state
->m_GPIO
&= ~state
->antenna_gpio
;
6603 mutex_init(&state
->mutex
);
6605 memcpy(&state
->frontend
.ops
, &drxk_ops
, sizeof(drxk_ops
));
6606 state
->frontend
.demodulator_priv
= state
;
6610 /* Load firmware and initialize DRX-K */
6611 if (state
->microcode_name
) {
6612 if (config
->load_firmware_sync
) {
6613 const struct firmware
*fw
= NULL
;
6615 status
= request_firmware(&fw
, state
->microcode_name
,
6616 state
->i2c
->dev
.parent
);
6619 load_firmware_cb(fw
, state
);
6621 status
= request_firmware_nowait(THIS_MODULE
, 1,
6622 state
->microcode_name
,
6623 state
->i2c
->dev
.parent
,
6625 state
, load_firmware_cb
);
6628 "drxk: failed to request a firmware\n");
6632 } else if (init_drxk(state
) < 0)
6635 printk(KERN_INFO
"drxk: frontend initialized.\n");
6636 return &state
->frontend
;
6639 printk(KERN_ERR
"drxk: not found\n");
6643 EXPORT_SYMBOL(drxk_attach
);
6645 MODULE_DESCRIPTION("DRX-K driver");
6646 MODULE_AUTHOR("Ralph Metzler");
6647 MODULE_LICENSE("GPL");