24 #include <linux/kernel.h>
25 #include <linux/module.h>
30 #include <linux/i2c.h>
32 #include <asm/div64.h>
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;
176 #define dprintk(level, fmt, arg...) do { \
177 if (debug >= level) \
178 printk(KERN_DEBUG "drxk: %s" fmt, __func__, ## arg); \
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;
228 static const u32 log2lut[] = {
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)
288 y = k * ((((
u32) 1) << scale) * 200);
291 x &= ((((
u32) 1) << scale) - 1);
293 i = (
u8) (x >> (scale - indexWidth));
295 d = x & ((((
u32) 1) << (scale - indexWidth)) - 1);
298 ((d * (log2lut[i + 1] - log2lut[
i])) >> (scale - indexWidth));
341 .buf =
val, .len = 1}
344 return drxk_i2c_transfer(state, msgs, 1);
351 .addr = adr, .flags = 0, .buf =
data, .len = len };
356 for (i = 0; i <
len; i++)
360 status = drxk_i2c_transfer(state, &msg, 1);
361 if (status >= 0 && status != 1)
371 u8 adr,
u8 *msg,
int len,
u8 *answ,
int alen)
375 {.
addr = adr, .flags = 0,
376 .buf =
msg, .len = len},
378 .buf = answ, .len = alen}
381 status = drxk_i2c_transfer(state, msgs, 2);
394 for (i = 0; i <
len; i++)
397 for (i = 0; i < alen; i++)
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);
435 return read16_flags(state, reg, data, 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);
470 return read32_flags(state, reg, data, 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);
499 return write16_flags(state, reg, data, 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);
530 return write32_flags(state, reg, data, 0);
542 while (BlkSize > 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);
558 AdrBuf[0] = ((Address << 1) & 0xFF);
559 AdrBuf[1] = (((Address >> 16) & 0x0F) |
560 ((Address >> 18) & 0xF0));
564 dprintk(2,
"(0x%08x, 0x%02x)\n", Address, Flags);
568 for (i = 0; i < Chunk; i++)
573 &state->
Chunk[0], Chunk + AdrLength);
580 Address += (Chunk >> 1);
586 #ifndef DRXK_MAX_RETRIES_POWERUP
587 #define DRXK_MAX_RETRIES_POWERUP 20
610 }
while (status < 0 &&
638 static int init_state(
struct drxk_state *state)
645 u32 ulVSBIfAgcOutputLevel = 0;
646 u32 ulVSBIfAgcMinLevel = 0;
647 u32 ulVSBIfAgcMaxLevel = 0x7FFF;
648 u32 ulVSBIfAgcSpeed = 3;
651 u32 ulVSBRfAgcOutputLevel = 0;
652 u32 ulVSBRfAgcMinLevel = 0;
653 u32 ulVSBRfAgcMaxLevel = 0x7FFF;
654 u32 ulVSBRfAgcSpeed = 3;
655 u32 ulVSBRfAgcTop = 9500;
656 u32 ulVSBRfAgcCutOffCurrent = 4000;
659 u32 ulATVIfAgcOutputLevel = 0;
660 u32 ulATVIfAgcMinLevel = 0;
661 u32 ulATVIfAgcMaxLevel = 0;
662 u32 ulATVIfAgcSpeed = 3;
665 u32 ulATVRfAgcOutputLevel = 0;
666 u32 ulATVRfAgcMinLevel = 0;
667 u32 ulATVRfAgcMaxLevel = 0;
668 u32 ulATVRfAgcTop = 9500;
669 u32 ulATVRfAgcCutOffCurrent = 4000;
670 u32 ulATVRfAgcSpeed = 3;
681 u32 ulGPIOCfg = 0x0113;
682 u32 ulInvertTSClock = 0;
684 u32 ulDVBTBitrate = 50000000;
687 u32 ulInsertRSByte = 0;
746 state->
m_vsbRfAgcCfg.cutOffCurrent = (ulVSBRfAgcCutOffCurrent);
752 if (ulQual93 <= 500 && ulQual83 < ulQual93) {
771 state->
m_atvRfAgcCfg.cutOffCurrent = (ulATVRfAgcCutOffCurrent);
853 if (ulMpegLockTimeOut < 10000)
856 if (ulDemodLockTimeOut < 10000)
878 static int DRXX_Open(
struct drxk_state *state)
910 static int GetDeviceCapabilities(
struct drxk_state *state)
912 u16 sioPdrOhwCfg = 0;
913 u32 sioTopJtagidLo = 0;
915 const char *spin =
"";
965 switch ((sioTopJtagidLo >> 29) & 0xF) {
982 (sioTopJtagidLo >> 29) & 0xF);
985 switch ((sioTopJtagidLo >> 12) & 0xFF) {
1092 ((sioTopJtagidLo >> 12) & 0xFF));
1098 "drxk: detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n",
1099 ((sioTopJtagidLo >> 12) & 0xFF), spin,
1130 if (powerdown_cmd ==
false) {
1153 static int HI_CfgCommand(
struct drxk_state *state)
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",
1224 if (mpegEnable ==
false) {
1276 err_cfg = sioPdrMdxCfg;
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)
1389 }
while ((blStatus == 0x1) &&
1392 if (blStatus == 0x1) {
1406 static int DownloadMicrocode(
struct drxk_state *state,
1409 const u8 *pSrc = pMCImage;
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);
1442 Flags = (pSrc[0] << 8) | pSrc[1];
1444 pSrc +=
sizeof(
u16);
1445 offset +=
sizeof(
u16);
1449 BlockCRC = (pSrc[0] << 8) | pSrc[1];
1451 pSrc +=
sizeof(
u16);
1452 offset +=
sizeof(
u16);
1454 if (offset + BlockSize > Length) {
1459 status = write_block(state, Address, BlockSize, pSrc);
1461 printk(
KERN_ERR "drxk: Error %d while loading firmware\n", status);
1480 if (enable ==
false) {
1486 if (status >= 0 && data == desiredStatus) {
1500 if (data != desiredStatus) {
1507 static int MPEGTSStop(
struct drxk_state *state)
1510 u16 fecOcSncMode = 0;
1511 u16 fecOcIprMode = 0;
1538 static int scu_command(
struct drxk_state *state,
1539 u16 cmd,
u8 parameterLen,
1542 #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15
1543 #error DRXK register mapping no longer compatible with this routine!
1555 if ((cmd == 0) || ((parameterLen > 0) && (parameter ==
NULL)) ||
1556 ((resultLen > 0) && (result ==
NULL))) {
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);
1573 (parameterLen - 1), cnt, buffer);
1588 if ((resultLen > 0) && (result !=
NULL)) {
1592 for (ii = resultLen - 1; ii >= 0; ii -= 1) {
1599 err = (
s16)result[0];
1606 p =
"SCU_RESULT_UNKCMD";
1609 p =
"SCU_RESULT_UNKSTD";
1612 p =
"SCU_RESULT_SIZE";
1615 p =
"SCU_RESULT_INVPAR";
1618 sprintf(errname,
"ERROR: %d\n", err);
1621 printk(
KERN_ERR "drxk: %s while sending cmd 0x%04x with params:", p, cmd);
1672 u16 sioCcPwdMode = 0;
1710 status = DVBTEnableOFDMTokenRing(state,
true);
1729 status = MPEGTSStop(state);
1732 status = PowerDownDVBT(state,
false);
1738 status = MPEGTSStop(state);
1741 status = PowerDownQAM(state);
1748 status = DVBTEnableOFDMTokenRing(state,
false);
1761 status = HI_CfgCommand(state);
1775 static int PowerDownDVBT(
struct drxk_state *state,
bool setPowerMode)
1810 status = SetIqmAf(state,
false);
1816 status = CtrlPowerMode(state, &powerMode);
1852 status = MPEGTSStop(state);
1855 status = PowerDownDVBT(state,
true);
1862 status = MPEGTSStop(state);
1865 status = PowerDownQAM(state);
1883 status = SetDVBTStandard(state, oMode);
1889 dprintk(1,
": DVB-C Annex %c\n",
1892 status = SetQAMStandard(state, oMode);
1907 s32 IntermediateFrequency)
1912 s32 OffsetkHz = offsetFreq / 1000;
1921 if (IntermediateFrequency < 0) {
1923 IntermediateFrequency = -IntermediateFrequency;
1929 IFreqkHz = (IntermediateFrequency / 1000);
1930 status = SetQAM(state, IFreqkHz, OffsetkHz);
1936 IFreqkHz = (IntermediateFrequency / 1000);
1937 status = MPEGTSStop(state);
1940 status = SetDVBT(state, IFreqkHz, OffsetkHz);
1943 status = DVBTStart(state);
1957 static int ShutDown(
struct drxk_state *state)
1965 static int GetLockStatus(
struct drxk_state *state,
u32 *pLockStatus,
1972 if (pLockStatus ==
NULL)
1982 status = GetQAMLockStatus(state, pLockStatus);
1985 status = GetDVBTLockStatus(state, pLockStatus);
1996 static int MPEGTSStart(
struct drxk_state *state)
2000 u16 fecOcSncMode = 0;
2017 static int MPEGTSDtoInit(
struct drxk_state *state)
2064 static int MPEGTSDtoSetup(
struct drxk_state *state,
2069 u16 fecOcRegMode = 0;
2070 u16 fecOcRegIprMode = 0;
2071 u16 fecOcDtoMode = 0;
2072 u16 fecOcFctMode = 0;
2073 u16 fecOcDtoPeriod = 2;
2074 u16 fecOcDtoBurstLen = 188;
2075 u32 fecOcRcnCtlRate = 0;
2076 u16 fecOcTmdMode = 0;
2077 u16 fecOcTmdIntUpdRate = 0;
2079 bool staticCLK =
false;
2098 fecOcDtoBurstLen = 204;
2112 fecOcRcnCtlRate = 0xC00000;
2117 fecOcTmdMode = 0x0004;
2118 fecOcRcnCtlRate = 0xD2B4EE;
2142 bitRate = maxBitRate;
2143 if (bitRate > 75900000
UL) {
2144 bitRate = 75900000
UL;
2154 if (fecOcDtoPeriod <= 2)
2157 fecOcDtoPeriod -= 2;
2158 fecOcTmdIntUpdRate = 8;
2163 fecOcTmdIntUpdRate = 5;
2200 static int MPEGTSConfigurePolarity(
struct drxk_state *state)
2202 u16 fecOcRegIprInvert = 0;
2205 u16 InvertDataMask =
2214 fecOcRegIprInvert &= (~(InvertDataMask));
2216 fecOcRegIprInvert |= InvertDataMask;
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)
2240 struct SCfgAgc *pIfAgcSettings;
2244 if (pAgcCfg ==
NULL)
2279 data |= (~(pAgcCfg->
speed <<
2289 else if (IsQAM(state))
2293 if (pIfAgcSettings ==
NULL) {
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;
2424 data |= (~(pAgcCfg->
speed <<
2436 if (pRfAgcSettings ==
NULL)
2527 *pValue = (14000 - Level) / 4;
2534 static int GetQAMSignalToNoise(
struct drxk_state *state,
2535 s32 *pSignalToNoise)
2538 u16 qamSlErrPower = 0;
2540 u32 qamSlSigPower = 0;
2555 switch (state->
props.modulation) {
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;
2616 EqRegTdSqrErrI = (
u32) regData;
2617 if ((EqRegTdSqrErrExp > 11) &&
2618 (EqRegTdSqrErrI < 0x00000FFF
UL)) {
2619 EqRegTdSqrErrI += 0x00010000
UL;
2625 EqRegTdSqrErrQ = (
u32) regData;
2626 if ((EqRegTdSqrErrExp > 11) &&
2627 (EqRegTdSqrErrQ < 0x00000FFF
UL))
2628 EqRegTdSqrErrQ += 0x00010000
UL;
2637 if ((EqRegTdTpsPwrOfs == 0) || (EqRegTdReqSmbCnt == 0))
2639 else if ((EqRegTdSqrErrI + EqRegTdSqrErrQ) == 0) {
2645 SqrErrIQ = (EqRegTdSqrErrI + EqRegTdSqrErrQ) <<
2647 if ((transmissionParams &
2665 a = Log10Times100(EqRegTdTpsPwrOfs *
2668 b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt);
2670 c = Log10Times100(SqrErrIQ);
2679 *pSignalToNoise = iMER;
2687 static int GetSignalToNoise(
struct drxk_state *state,
s32 *pSignalToNoise)
2691 *pSignalToNoise = 0;
2694 return GetDVBTSignalToNoise(state, pSignalToNoise);
2697 return GetQAMSignalToNoise(state, pSignalToNoise);
2705 static int GetDVBTQuality(
struct drxk_state *state,
s32 *pQuality)
2712 static s32 QE_SN[] = {
2733 s32 SignalToNoise = 0;
2734 u16 Constellation = 0;
2736 u32 SignalToNoiseRel;
2739 status = GetDVBTSignalToNoise(state, &SignalToNoise);
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;
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)
2823 return GetDVBTQuality(state, pQuality);
2825 return GetDVBCQuality(state, pQuality);
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)
2864 if (bEnableBridge) {
2882 static int SetPreSaw(
struct drxk_state *state,
2889 if ((pPreSawCfg ==
NULL)
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);
2937 if (blStatus == 0x1) {
2971 *count = *count + 1;
2976 *count = *count + 1;
2981 *count = *count + 1;
2989 static int ADCSynchronization(
struct drxk_state *state)
2996 status = ADCSyncMeasurement(state, &count);
3020 status = ADCSyncMeasurement(state, &count);
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;
3059 selectPosImage =
true;
3061 selectPosImage =
false;
3065 ifFreqActual = intermediateFreqkHz +
3066 rfFreqResidual + fmFrequencyShift;
3069 ifFreqActual = intermediateFreqkHz -
3070 rfFreqResidual - fmFrequencyShift;
3071 if (ifFreqActual > samplingFrequency / 2) {
3073 adcFreq = samplingFrequency - ifFreqActual;
3077 adcFreq = ifFreqActual;
3081 frequencyShift = adcFreq;
3082 imageToSelect = state->
m_rfmirror ^ tunerMirror ^
3083 adcFlip ^ selectPosImage;
3085 Frac28a((frequencyShift), samplingFrequency);
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;
3124 ifIaccuHiTgtMin = 2047;
3129 if (!IsQAM(state)) {
3138 clpDirTo = (
u16) -9;
3141 snsDirTo = (
u16) -9;
3142 kiInnergainMin = (
u16) -1030;
3143 ifIaccuHiTgtMax = 0x2380;
3144 ifIaccuHiTgt = 0x2380;
3145 ingainTgtMin = 0x0511;
3147 ingainTgtMax = 5119;
3287 static int DVBTQAMGetAccPktErr(
struct drxk_state *state,
u16 *packetErr)
3292 if (packetErr ==
NULL)
3301 static int DVBTScCommand(
struct drxk_state *state,
3385 if (errCode == 0xFFFF) {
3421 static int PowerUpDVBT(
struct drxk_state *state)
3427 status = CtrlPowerMode(state, &powerMode);
3438 if (*enabled ==
true)
3447 #define DEFAULT_FR_THRES_8K 4000
3448 static int DVBTCtrlSetFrEnable(
struct drxk_state *state,
bool *enabled)
3454 if (*enabled ==
true) {
3468 static int DVBTCtrlSetEchoThreshold(
struct drxk_state *state,
3503 static int DVBTCtrlSetSqiSpeed(
struct drxk_state *state,
3536 static int DVBTActivatePresets(
struct drxk_state *state)
3539 bool setincenable =
false;
3540 bool setfrenable =
true;
3546 status = DVBTCtrlSetIncEnable(state, &setincenable);
3549 status = DVBTCtrlSetFrEnable(state, &setfrenable);
3552 status = DVBTCtrlSetEchoThreshold(state, &echoThres2k);
3555 status = DVBTCtrlSetEchoThreshold(state, &echoThres8k);
3575 static int SetDVBTStandard(
struct drxk_state *state,
3586 SwitchAntennaToDVBT(state);
3625 status = SetIqmAf(state,
true);
3687 status = ADCSynchronization(state);
3728 #ifdef COMPILE_FOR_NONRT
3743 #ifdef COMPILE_FOR_NONRT
3757 status = MPEGTSDtoSetup(state,
OM_DVBT);
3761 status = DVBTActivatePresets(state);
3777 static int DVBTStart(
struct drxk_state *state)
3791 status = MPEGTSStart(state);
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);
3851 switch (state->
props.transmission_mode) {
3865 switch (state->
props.guard_interval) {
3885 switch (state->
props.hierarchy) {
3906 switch (state->
props.modulation) {
3925 case DRX_PRIORITY_LOW:
3930 case DRX_PRIORITY_HIGH:
3935 case DRX_PRIORITY_UNKNOWN:
3949 switch (state->
props.code_rate_HP) {
3978 switch (state->
props.bandwidth_hz) {
3980 state->
props.bandwidth_hz = 8000000;
4044 if (iqmRcRateOfs == 0) {
4056 1000) / 3), bandwidth);
4058 if ((iqmRcRateOfs & 0x7fL) >= 0x40)
4059 iqmRcRateOfs += 0x80
L;
4060 iqmRcRateOfs = iqmRcRateOfs >> 7;
4062 iqmRcRateOfs = iqmRcRateOfs - (1 << 23);
4075 status = DVBTSetFrequencyShift(demod,
channel, tunerOffset);
4079 status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset,
true);
4110 0, transmissionParams, param1, 0, 0, 0);
4115 status = DVBTCtrlSetSqiSpeed(state, &state->
m_sqiSpeed);
4133 static int GetDVBTLockStatus(
struct drxk_state *state,
u32 *pLockStatus)
4141 u16 ScRaRamLock = 0;
4159 if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask)
4161 else if ((ScRaRamLock & fec_lock_mask) == fec_lock_mask)
4163 else if ((ScRaRamLock & demod_lock_mask) == demod_lock_mask)
4174 static int PowerUpQAM(
struct drxk_state *state)
4180 status = CtrlPowerMode(state, &powerMode);
4189 static int PowerDownQAM(
struct drxk_state *state)
4213 status = SetIqmAf(state,
false);
4235 static int SetQAMMeasurement(
struct drxk_state *state,
4239 u32 fecBitsDesired = 0;
4240 u32 fecRsPeriodTotal = 0;
4241 u16 fecRsPrescale = 0;
4242 u16 fecRsPeriod = 0;
4254 switch (modulation) {
4256 fecBitsDesired = 4 * symbolRate;
4259 fecBitsDesired = 5 * symbolRate;
4262 fecBitsDesired = 6 * symbolRate;
4265 fecBitsDesired = 7 * symbolRate;
4268 fecBitsDesired = 8 * symbolRate;
4276 fecBitsDesired /= 1000;
4277 fecBitsDesired *= 500;
4281 fecRsPeriodTotal = (fecBitsDesired / 1632
UL) + 1;
4284 fecRsPrescale = 1 + (
u16) (fecRsPeriodTotal >> 16);
4285 if (fecRsPrescale == 0) {
4292 ((
u16) fecRsPeriodTotal +
4293 (fecRsPrescale >> 1)) / fecRsPrescale;
4309 static int SetQAM16(
struct drxk_state *state)
4502 static int SetQAM32(
struct drxk_state *state)
4697 static int SetQAM64(
struct drxk_state *state)
4891 static int SetQAM128(
struct drxk_state *state)
5087 static int SetQAM256(
struct drxk_state *state)
5282 static int QAMResetQAM(
struct drxk_state *state)
5308 static int QAMSetSymbolrate(
struct drxk_state *state)
5310 u32 adcFrequency = 0;
5322 if (state->
props.symbol_rate <= 1188750)
5324 else if (state->
props.symbol_rate <= 2377500)
5326 else if (state->
props.symbol_rate <= 4755000)
5335 symbFreq = state->
props.symbol_rate * (1 << ratesel);
5336 if (symbFreq == 0) {
5341 iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) +
5342 (
Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) -
5351 symbFreq = state->
props.symbol_rate;
5352 if (adcFrequency == 0) {
5357 lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) +
5358 (
Frac28a((symbFreq % adcFrequency), adcFrequency) >>
5360 if (lcSymbRate > 511)
5379 static int GetQAMLockStatus(
struct drxk_state *state,
u32 *pLockStatus)
5382 u16 Result[2] = { 0, 0 };
5386 status = scu_command(state,
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 };
5428 if (numberOfParameters == 2) {
5429 u16 setEnvParameters[1] = { 0 };
5436 status = scu_command(state,
5438 1, setEnvParameters, 1, &cmdResult);
5442 status = scu_command(state,
5444 numberOfParameters, setParamParameters,
5446 }
else if (numberOfParameters == 4) {
5457 status = scu_command(state,
5459 numberOfParameters, setParamParameters,
5463 "count %d\n", numberOfParameters);
5473 static int SetQAM(
struct drxk_state *state,
u16 IntermediateFreqkHz,
5474 s32 tunerFreqOffset)
5493 status = QAMResetQAM(state);
5502 status = QAMSetSymbolrate(state);
5507 switch (state->
props.modulation) {
5535 qamDemodParamCount = 4;
5536 status = QAMDemodulatorCommand(state, qamDemodParamCount);
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",
5556 dprintk(1,
"Auto-probing the correct QAM demodulator command "
5557 "parameters was successful - using %d parameters.\n",
5558 qamDemodParamCount);
5572 status = SetFrequency(
channel, tunerFreqOffset));
5576 status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset,
true);
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);
5701 status = MPEGTSStart(state);
5728 static int SetQAMStandard(
struct drxk_state *state,
5732 #ifdef DRXK_QAM_TAPS
5733 #define DRXK_QAMA_TAPS_SELECT
5734 #include "drxk_filters.h"
5735 #undef DRXK_QAMA_TAPS_SELECT
5741 SwitchAntennaToQAM(state);
5744 status = PowerUpQAM(state);
5748 status = QAMResetQAM(state);
5842 status = SetIqmAf(state,
true);
5850 status = ADCSynchronization(state);
5867 status = InitAGC(state,
true);
5890 static int WriteGPIO(
struct drxk_state *state)
5917 if ((state->
m_GPIO & 0x0001) == 0)
5936 if ((state->
m_GPIO & 0x0002) == 0)
5955 if ((state->
m_GPIO & 0x0004) == 0)
5973 static int SwitchAntennaToQAM(
struct drxk_state *state)
5991 status = WriteGPIO(state);
5998 static int SwitchAntennaToDVBT(
struct drxk_state *state)
6016 status = WriteGPIO(state);
6024 static int PowerDownDevice(
struct drxk_state *state)
6037 status = ConfigureI2CBridge(state,
true);
6042 status = DVBTEnableOFDMTokenRing(state,
false);
6053 status = HI_CfgCommand(state);
6061 static int init_drxk(
struct drxk_state *state)
6063 int status = 0,
n = 0;
6069 drxk_i2c_lock(state);
6073 status = DRXX_Open(state);
6086 status = GetDeviceCapabilities(state);
6107 status = InitHI(state);
6122 status = MPEGTSDisable(state);
6143 status = BLChainCmd(state, 0, 6, 100);
6148 status = DownloadMicrocode(state, state->
fw->data,
6163 status = DRXX_Open(state);
6170 status = CtrlPowerMode(state, &powerMode);
6219 status = MPEGTSDtoInit(state);
6222 status = MPEGTSStop(state);
6225 status = MPEGTSConfigurePolarity(state);
6232 status = WriteGPIO(state);
6239 status = PowerDownDevice(state);
6252 sizeof(state->
frontend.ops.info.name));
6257 sizeof(state->
frontend.ops.info.name));
6259 drxk_i2c_unlock(state);
6264 drxk_i2c_unlock(state);
6271 static void load_firmware_cb(
const struct firmware *
fw,
6276 dprintk(1,
": %s\n", fw ?
"firmware loaded" :
"firmware not loaded");
6279 "drxk: Could not load firmware file %s.\n",
6282 "drxk: Copy %s to your hotplug directory!\n",
6328 static int drxk_gate_ctrl(
struct dvb_frontend *fe,
int enable)
6332 dprintk(1,
": %s\n", enable ?
"enable" :
"disable");
6337 return ConfigureI2CBridge(state, enable ?
true :
false);
6340 static int drxk_set_parameters(
struct dvb_frontend *fe)
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) {
6394 fe->
ops.tuner_ops.get_if_frequency(fe, &IF);
6395 Start(state, 0, IF);
6415 GetLockStatus(state, &stat, 0);
6440 static int drxk_read_signal_strength(
struct dvb_frontend *fe,
6453 ReadIFAgc(state, &val);
6454 *strength = val & 0xffff;
6470 GetSignalToNoise(state, &snr2);
6471 *snr = snr2 & 0xffff;
6487 DVBTQAMGetAccPktErr(state, &err);
6488 *ucblocks = (
u32) err;
6522 .frequency_min = 47000000,
6523 .frequency_max = 865000000,
6525 .symbol_rate_min = 870000,
6526 .symbol_rate_max = 11700000,
6528 .frequency_stepsize = 166667,
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,
6556 u8 adr = config->
adr;
6616 state->
i2c->dev.parent);
6619 load_firmware_cb(fw, state);
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)