Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1 | /* |
| 2 | * drxk_hard: DRX-K DVB-C/T demodulator driver |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Digital Devices GmbH |
| 5 | * |
| 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. |
| 9 | * |
| 10 | * |
| 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. |
| 15 | * |
| 16 | * |
| 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 |
| 20 | * 02110-1301, USA |
| 21 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html |
| 22 | */ |
| 23 | |
| 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/version.h> |
| 32 | #include <asm/div64.h> |
| 33 | |
| 34 | #include "dvb_frontend.h" |
| 35 | #include "drxk.h" |
| 36 | #include "drxk_hard.h" |
| 37 | |
| 38 | static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode); |
| 39 | static int PowerDownQAM(struct drxk_state *state); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 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, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 45 | s32 tunerFreqOffset); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 46 | static int SetDVBTStandard(struct drxk_state *state, |
| 47 | enum OperationMode oMode); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 48 | static int DVBTStart(struct drxk_state *state); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 49 | static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, |
| 50 | s32 tunerFreqOffset); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 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); |
| 55 | |
| 56 | static bool IsDVBT(struct drxk_state *state) |
| 57 | { |
| 58 | return state->m_OperationMode == OM_DVBT; |
| 59 | } |
| 60 | |
| 61 | static bool IsQAM(struct drxk_state *state) |
| 62 | { |
| 63 | return state->m_OperationMode == OM_QAM_ITU_A || |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 64 | state->m_OperationMode == OM_QAM_ITU_B || |
| 65 | state->m_OperationMode == OM_QAM_ITU_C; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | bool IsA1WithPatchCode(struct drxk_state *state) |
| 69 | { |
| 70 | return state->m_DRXK_A1_PATCH_CODE; |
| 71 | } |
| 72 | |
| 73 | bool IsA1WithRomCode(struct drxk_state *state) |
| 74 | { |
| 75 | return state->m_DRXK_A1_ROM_CODE; |
| 76 | } |
| 77 | |
| 78 | #define NOA1ROM 0 |
| 79 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 80 | #define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0) |
| 81 | #define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0) |
| 82 | |
| 83 | #define DEFAULT_MER_83 165 |
| 84 | #define DEFAULT_MER_93 250 |
| 85 | |
| 86 | #ifndef DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH |
| 87 | #define DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH (0x02) |
| 88 | #endif |
| 89 | |
| 90 | #ifndef DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH |
| 91 | #define DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH (0x03) |
| 92 | #endif |
| 93 | |
| 94 | #ifndef DRXK_MPEG_OUTPUT_CLK_DRIVE_STRENGTH |
| 95 | #define DRXK_MPEG_OUTPUT_CLK_DRIVE_STRENGTH (0x06) |
| 96 | #endif |
| 97 | |
| 98 | #define DEFAULT_DRXK_MPEG_LOCK_TIMEOUT 700 |
| 99 | #define DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT 500 |
| 100 | |
| 101 | #ifndef DRXK_KI_RAGC_ATV |
| 102 | #define DRXK_KI_RAGC_ATV 4 |
| 103 | #endif |
| 104 | #ifndef DRXK_KI_IAGC_ATV |
| 105 | #define DRXK_KI_IAGC_ATV 6 |
| 106 | #endif |
| 107 | #ifndef DRXK_KI_DAGC_ATV |
| 108 | #define DRXK_KI_DAGC_ATV 7 |
| 109 | #endif |
| 110 | |
| 111 | #ifndef DRXK_KI_RAGC_QAM |
| 112 | #define DRXK_KI_RAGC_QAM 3 |
| 113 | #endif |
| 114 | #ifndef DRXK_KI_IAGC_QAM |
| 115 | #define DRXK_KI_IAGC_QAM 4 |
| 116 | #endif |
| 117 | #ifndef DRXK_KI_DAGC_QAM |
| 118 | #define DRXK_KI_DAGC_QAM 7 |
| 119 | #endif |
| 120 | #ifndef DRXK_KI_RAGC_DVBT |
| 121 | #define DRXK_KI_RAGC_DVBT (IsA1WithPatchCode(state) ? 3 : 2) |
| 122 | #endif |
| 123 | #ifndef DRXK_KI_IAGC_DVBT |
| 124 | #define DRXK_KI_IAGC_DVBT (IsA1WithPatchCode(state) ? 4 : 2) |
| 125 | #endif |
| 126 | #ifndef DRXK_KI_DAGC_DVBT |
| 127 | #define DRXK_KI_DAGC_DVBT (IsA1WithPatchCode(state) ? 10 : 7) |
| 128 | #endif |
| 129 | |
| 130 | #ifndef DRXK_AGC_DAC_OFFSET |
| 131 | #define DRXK_AGC_DAC_OFFSET (0x800) |
| 132 | #endif |
| 133 | |
| 134 | #ifndef DRXK_BANDWIDTH_8MHZ_IN_HZ |
| 135 | #define DRXK_BANDWIDTH_8MHZ_IN_HZ (0x8B8249L) |
| 136 | #endif |
| 137 | |
| 138 | #ifndef DRXK_BANDWIDTH_7MHZ_IN_HZ |
| 139 | #define DRXK_BANDWIDTH_7MHZ_IN_HZ (0x7A1200L) |
| 140 | #endif |
| 141 | |
| 142 | #ifndef DRXK_BANDWIDTH_6MHZ_IN_HZ |
| 143 | #define DRXK_BANDWIDTH_6MHZ_IN_HZ (0x68A1B6L) |
| 144 | #endif |
| 145 | |
| 146 | #ifndef DRXK_QAM_SYMBOLRATE_MAX |
| 147 | #define DRXK_QAM_SYMBOLRATE_MAX (7233000) |
| 148 | #endif |
| 149 | |
| 150 | #define DRXK_BL_ROM_OFFSET_TAPS_DVBT 56 |
| 151 | #define DRXK_BL_ROM_OFFSET_TAPS_ITU_A 64 |
| 152 | #define DRXK_BL_ROM_OFFSET_TAPS_ITU_C 0x5FE0 |
| 153 | #define DRXK_BL_ROM_OFFSET_TAPS_BG 24 |
| 154 | #define DRXK_BL_ROM_OFFSET_TAPS_DKILLP 32 |
| 155 | #define DRXK_BL_ROM_OFFSET_TAPS_NTSC 40 |
| 156 | #define DRXK_BL_ROM_OFFSET_TAPS_FM 48 |
| 157 | #define DRXK_BL_ROM_OFFSET_UCODE 0 |
| 158 | |
| 159 | #define DRXK_BLC_TIMEOUT 100 |
| 160 | |
| 161 | #define DRXK_BLCC_NR_ELEMENTS_TAPS 2 |
| 162 | #define DRXK_BLCC_NR_ELEMENTS_UCODE 6 |
| 163 | |
| 164 | #define DRXK_BLDC_NR_ELEMENTS_TAPS 28 |
| 165 | |
| 166 | #ifndef DRXK_OFDM_NE_NOTCH_WIDTH |
| 167 | #define DRXK_OFDM_NE_NOTCH_WIDTH (4) |
| 168 | #endif |
| 169 | |
| 170 | #define DRXK_QAM_SL_SIG_POWER_QAM16 (40960) |
| 171 | #define DRXK_QAM_SL_SIG_POWER_QAM32 (20480) |
| 172 | #define DRXK_QAM_SL_SIG_POWER_QAM64 (43008) |
| 173 | #define DRXK_QAM_SL_SIG_POWER_QAM128 (20992) |
| 174 | #define DRXK_QAM_SL_SIG_POWER_QAM256 (43520) |
| 175 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 176 | static unsigned int debug; |
| 177 | module_param(debug, int, 0644); |
| 178 | MODULE_PARM_DESC(debug, "enable debug messages"); |
| 179 | |
| 180 | #define dprintk(level, fmt, arg...) do { \ |
| 181 | if (debug >= level) \ |
| 182 | printk(KERN_DEBUG "drxk: %s" fmt, __func__, ## arg); \ |
| 183 | } while (0) |
| 184 | |
| 185 | |
Mauro Carvalho Chehab | b01fbc1 | 2011-07-03 17:18:57 -0300 | [diff] [blame] | 186 | static inline u32 MulDiv32(u32 a, u32 b, u32 c) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 187 | { |
| 188 | u64 tmp64; |
| 189 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 190 | tmp64 = (u64) a * (u64) b; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 191 | do_div(tmp64, c); |
| 192 | |
| 193 | return (u32) tmp64; |
| 194 | } |
| 195 | |
| 196 | inline u32 Frac28a(u32 a, u32 c) |
| 197 | { |
| 198 | int i = 0; |
| 199 | u32 Q1 = 0; |
| 200 | u32 R0 = 0; |
| 201 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 202 | R0 = (a % c) << 4; /* 32-28 == 4 shifts possible at max */ |
| 203 | Q1 = a / c; /* integer part, only the 4 least significant bits |
| 204 | will be visible in the result */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 205 | |
| 206 | /* division using radix 16, 7 nibbles in the result */ |
| 207 | for (i = 0; i < 7; i++) { |
| 208 | Q1 = (Q1 << 4) | (R0 / c); |
| 209 | R0 = (R0 % c) << 4; |
| 210 | } |
| 211 | /* rounding */ |
| 212 | if ((R0 >> 3) >= c) |
| 213 | Q1++; |
| 214 | |
| 215 | return Q1; |
| 216 | } |
| 217 | |
| 218 | static u32 Log10Times100(u32 x) |
| 219 | { |
| 220 | static const u8 scale = 15; |
| 221 | static const u8 indexWidth = 5; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 222 | u8 i = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 223 | u32 y = 0; |
| 224 | u32 d = 0; |
| 225 | u32 k = 0; |
| 226 | u32 r = 0; |
| 227 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 228 | log2lut[n] = (1<<scale) * 200 * log2(1.0 + ((1.0/(1<<INDEXWIDTH)) * n)) |
| 229 | 0 <= n < ((1<<INDEXWIDTH)+1) |
| 230 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 231 | |
| 232 | static const u32 log2lut[] = { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 233 | 0, /* 0.000000 */ |
| 234 | 290941, /* 290941.300628 */ |
| 235 | 573196, /* 573196.476418 */ |
| 236 | 847269, /* 847269.179851 */ |
| 237 | 1113620, /* 1113620.489452 */ |
| 238 | 1372674, /* 1372673.576986 */ |
| 239 | 1624818, /* 1624817.752104 */ |
| 240 | 1870412, /* 1870411.981536 */ |
| 241 | 2109788, /* 2109787.962654 */ |
| 242 | 2343253, /* 2343252.817465 */ |
| 243 | 2571091, /* 2571091.461923 */ |
| 244 | 2793569, /* 2793568.696416 */ |
| 245 | 3010931, /* 3010931.055901 */ |
| 246 | 3223408, /* 3223408.452106 */ |
| 247 | 3431216, /* 3431215.635215 */ |
| 248 | 3634553, /* 3634553.498355 */ |
| 249 | 3833610, /* 3833610.244726 */ |
| 250 | 4028562, /* 4028562.434393 */ |
| 251 | 4219576, /* 4219575.925308 */ |
| 252 | 4406807, /* 4406806.721144 */ |
| 253 | 4590402, /* 4590401.736809 */ |
| 254 | 4770499, /* 4770499.491025 */ |
| 255 | 4947231, /* 4947230.734179 */ |
| 256 | 5120719, /* 5120719.018555 */ |
| 257 | 5291081, /* 5291081.217197 */ |
| 258 | 5458428, /* 5458427.996830 */ |
| 259 | 5622864, /* 5622864.249668 */ |
| 260 | 5784489, /* 5784489.488298 */ |
| 261 | 5943398, /* 5943398.207380 */ |
| 262 | 6099680, /* 6099680.215452 */ |
| 263 | 6253421, /* 6253420.939751 */ |
| 264 | 6404702, /* 6404701.706649 */ |
| 265 | 6553600, /* 6553600.000000 */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | |
| 269 | if (x == 0) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 270 | return 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 271 | |
| 272 | /* Scale x (normalize) */ |
| 273 | /* computing y in log(x/y) = log(x) - log(y) */ |
| 274 | if ((x & ((0xffffffff) << (scale + 1))) == 0) { |
| 275 | for (k = scale; k > 0; k--) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 276 | if (x & (((u32) 1) << scale)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 277 | break; |
| 278 | x <<= 1; |
| 279 | } |
| 280 | } else { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 281 | for (k = scale; k < 31; k++) { |
| 282 | if ((x & (((u32) (-1)) << (scale + 1))) == 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 283 | break; |
| 284 | x >>= 1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 285 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 286 | } |
| 287 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 288 | Now x has binary point between bit[scale] and bit[scale-1] |
| 289 | and 1.0 <= x < 2.0 */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 290 | |
| 291 | /* correction for divison: log(x) = log(x/y)+log(y) */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 292 | y = k * ((((u32) 1) << scale) * 200); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 293 | |
| 294 | /* remove integer part */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 295 | x &= ((((u32) 1) << scale) - 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 296 | /* get index */ |
| 297 | i = (u8) (x >> (scale - indexWidth)); |
| 298 | /* compute delta (x - a) */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 299 | d = x & ((((u32) 1) << (scale - indexWidth)) - 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 300 | /* compute log, multiplication (d* (..)) must be within range ! */ |
| 301 | y += log2lut[i] + |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 302 | ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - indexWidth)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 303 | /* Conver to log10() */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 304 | y /= 108853; /* (log2(10) << scale) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 305 | r = (y >> 1); |
| 306 | /* rounding */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 307 | if (y & ((u32) 1)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 308 | r++; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 309 | return r; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /****************************************************************************/ |
| 313 | /* I2C **********************************************************************/ |
| 314 | /****************************************************************************/ |
| 315 | |
| 316 | static int i2c_read1(struct i2c_adapter *adapter, u8 adr, u8 *val) |
| 317 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 318 | struct i2c_msg msgs[1] = { {.addr = adr, .flags = I2C_M_RD, |
| 319 | .buf = val, .len = 1} |
| 320 | }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 321 | return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1; |
| 322 | } |
| 323 | |
| 324 | static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len) |
| 325 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 326 | struct i2c_msg msg = { |
| 327 | .addr = adr, .flags = 0, .buf = data, .len = len }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 329 | dprintk(3, ":"); |
| 330 | if (debug > 2) { |
| 331 | int i; |
| 332 | for (i = 0; i < len; i++) |
| 333 | printk(KERN_CONT " %02x", data[i]); |
| 334 | printk(KERN_CONT "\n"); |
| 335 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 336 | if (i2c_transfer(adap, &msg, 1) != 1) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 337 | printk(KERN_ERR "drxk: i2c write error at addr 0x%02x\n", adr); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 338 | return -1; |
| 339 | } |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int i2c_read(struct i2c_adapter *adap, |
| 344 | u8 adr, u8 *msg, int len, u8 *answ, int alen) |
| 345 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 346 | struct i2c_msg msgs[2] = { {.addr = adr, .flags = 0, |
| 347 | .buf = msg, .len = len}, |
| 348 | {.addr = adr, .flags = I2C_M_RD, |
| 349 | .buf = answ, .len = alen} |
| 350 | }; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 351 | dprintk(3, ":"); |
| 352 | if (debug > 2) { |
| 353 | int i; |
| 354 | for (i = 0; i < len; i++) |
| 355 | printk(KERN_CONT " %02x", msg[i]); |
| 356 | printk(KERN_CONT "\n"); |
| 357 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 358 | if (i2c_transfer(adap, msgs, 2) != 2) { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 359 | if (debug > 2) |
| 360 | printk(KERN_CONT ": ERROR!\n"); |
| 361 | |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 362 | printk(KERN_ERR "drxk: i2c read error at addr 0x%02x\n", adr); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 363 | return -1; |
| 364 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 365 | if (debug > 2) { |
| 366 | int i; |
| 367 | printk(KERN_CONT ": Read "); |
| 368 | for (i = 0; i < len; i++) |
| 369 | printk(KERN_CONT " %02x", msg[i]); |
| 370 | printk(KERN_CONT "\n"); |
| 371 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 375 | static int read16_flags(struct drxk_state *state, u32 reg, u16 *data, u8 flags) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 376 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 377 | u8 adr = state->demod_address, mm1[4], mm2[2], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 378 | |
| 379 | if (state->single_master) |
| 380 | flags |= 0xC0; |
| 381 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 382 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 383 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 384 | mm1[1] = ((reg >> 16) & 0xFF); |
| 385 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 386 | mm1[3] = ((reg >> 7) & 0xFF); |
| 387 | len = 4; |
| 388 | } else { |
| 389 | mm1[0] = ((reg << 1) & 0xFF); |
| 390 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 391 | len = 2; |
| 392 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 393 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 394 | if (i2c_read(state->i2c, adr, mm1, len, mm2, 2) < 0) |
| 395 | return -1; |
| 396 | if (data) |
| 397 | *data = mm2[0] | (mm2[1] << 8); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 398 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 402 | static int read16(struct drxk_state *state, u32 reg, u16 *data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 403 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 404 | return read16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 405 | } |
| 406 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 407 | static int read32_flags(struct drxk_state *state, u32 reg, u32 *data, u8 flags) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 408 | { |
| 409 | u8 adr = state->demod_address, mm1[4], mm2[4], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 410 | |
| 411 | if (state->single_master) |
| 412 | flags |= 0xC0; |
| 413 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 414 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 415 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 416 | mm1[1] = ((reg >> 16) & 0xFF); |
| 417 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 418 | mm1[3] = ((reg >> 7) & 0xFF); |
| 419 | len = 4; |
| 420 | } else { |
| 421 | mm1[0] = ((reg << 1) & 0xFF); |
| 422 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 423 | len = 2; |
| 424 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 425 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 426 | if (i2c_read(state->i2c, adr, mm1, len, mm2, 4) < 0) |
| 427 | return -1; |
| 428 | if (data) |
| 429 | *data = mm2[0] | (mm2[1] << 8) | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 430 | (mm2[2] << 16) | (mm2[3] << 24); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 431 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 435 | static int read32(struct drxk_state *state, u32 reg, u32 *data) |
| 436 | { |
| 437 | return read32_flags(state, reg, data, 0); |
| 438 | } |
| 439 | |
| 440 | static int write16_flags(struct drxk_state *state, u32 reg, u16 data, u8 flags) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 441 | { |
| 442 | u8 adr = state->demod_address, mm[6], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 443 | |
| 444 | if (state->single_master) |
| 445 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 446 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 447 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 448 | mm[1] = ((reg >> 16) & 0xFF); |
| 449 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 450 | mm[3] = ((reg >> 7) & 0xFF); |
| 451 | len = 4; |
| 452 | } else { |
| 453 | mm[0] = ((reg << 1) & 0xFF); |
| 454 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 455 | len = 2; |
| 456 | } |
| 457 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 458 | mm[len + 1] = (data >> 8) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 459 | |
| 460 | dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg, data, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 461 | if (i2c_write(state->i2c, adr, mm, len + 2) < 0) |
| 462 | return -1; |
| 463 | return 0; |
| 464 | } |
| 465 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 466 | static int write16(struct drxk_state *state, u32 reg, u16 data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 467 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 468 | return write16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 469 | } |
| 470 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 471 | static int write32_flags(struct drxk_state *state, u32 reg, u32 data, u8 flags) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 472 | { |
| 473 | u8 adr = state->demod_address, mm[8], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 474 | |
| 475 | if (state->single_master) |
| 476 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 477 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 478 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 479 | mm[1] = ((reg >> 16) & 0xFF); |
| 480 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 481 | mm[3] = ((reg >> 7) & 0xFF); |
| 482 | len = 4; |
| 483 | } else { |
| 484 | mm[0] = ((reg << 1) & 0xFF); |
| 485 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 486 | len = 2; |
| 487 | } |
| 488 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 489 | mm[len + 1] = (data >> 8) & 0xff; |
| 490 | mm[len + 2] = (data >> 16) & 0xff; |
| 491 | mm[len + 3] = (data >> 24) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 492 | dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg, data, flags); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 493 | if (i2c_write(state->i2c, adr, mm, len + 4) < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 494 | return -1; |
| 495 | return 0; |
| 496 | } |
| 497 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 498 | static int write32(struct drxk_state *state, u32 reg, u32 data) |
| 499 | { |
| 500 | return write32_flags(state, reg, data, 0); |
| 501 | } |
| 502 | |
| 503 | static int write_block(struct drxk_state *state, u32 Address, |
| 504 | const int BlockSize, const u8 pBlock[]) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 505 | { |
| 506 | int status = 0, BlkSize = BlockSize; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 507 | u8 Flags = 0; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 508 | |
| 509 | if (state->single_master) |
| 510 | Flags |= 0xC0; |
| 511 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 512 | while (BlkSize > 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 513 | int Chunk = BlkSize > state->m_ChunkSize ? |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 514 | state->m_ChunkSize : BlkSize; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 515 | u8 *AdrBuf = &state->Chunk[0]; |
| 516 | u32 AdrLength = 0; |
| 517 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 518 | if (DRXDAP_FASI_LONG_FORMAT(Address) || (Flags != 0)) { |
| 519 | AdrBuf[0] = (((Address << 1) & 0xFF) | 0x01); |
| 520 | AdrBuf[1] = ((Address >> 16) & 0xFF); |
| 521 | AdrBuf[2] = ((Address >> 24) & 0xFF); |
| 522 | AdrBuf[3] = ((Address >> 7) & 0xFF); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 523 | AdrBuf[2] |= Flags; |
| 524 | AdrLength = 4; |
| 525 | if (Chunk == state->m_ChunkSize) |
| 526 | Chunk -= 2; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 527 | } else { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 528 | AdrBuf[0] = ((Address << 1) & 0xFF); |
| 529 | AdrBuf[1] = (((Address >> 16) & 0x0F) | |
| 530 | ((Address >> 18) & 0xF0)); |
| 531 | AdrLength = 2; |
| 532 | } |
| 533 | memcpy(&state->Chunk[AdrLength], pBlock, Chunk); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 534 | dprintk(2, "(0x%08x, 0x%02x)\n", Address, Flags); |
| 535 | if (debug > 1) { |
| 536 | int i; |
| 537 | if (pBlock) |
| 538 | for (i = 0; i < Chunk; i++) |
| 539 | printk(KERN_CONT " %02x", pBlock[i]); |
| 540 | printk(KERN_CONT "\n"); |
| 541 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 542 | status = i2c_write(state->i2c, state->demod_address, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 543 | &state->Chunk[0], Chunk + AdrLength); |
| 544 | if (status < 0) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 545 | printk(KERN_ERR "drxk: %s: i2c write error at addr 0x%02x\n", |
| 546 | __func__, Address); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 547 | break; |
| 548 | } |
| 549 | pBlock += Chunk; |
| 550 | Address += (Chunk >> 1); |
| 551 | BlkSize -= Chunk; |
| 552 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 553 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | #ifndef DRXK_MAX_RETRIES_POWERUP |
| 557 | #define DRXK_MAX_RETRIES_POWERUP 20 |
| 558 | #endif |
| 559 | |
| 560 | int PowerUpDevice(struct drxk_state *state) |
| 561 | { |
| 562 | int status; |
| 563 | u8 data = 0; |
| 564 | u16 retryCount = 0; |
| 565 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 566 | dprintk(1, "\n"); |
| 567 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 568 | status = i2c_read1(state->i2c, state->demod_address, &data); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 569 | if (status < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 570 | do { |
| 571 | data = 0; |
| 572 | if (i2c_write(state->i2c, |
| 573 | state->demod_address, &data, 1) < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 574 | printk(KERN_ERR "drxk: powerup failed\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 575 | msleep(10); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 576 | retryCount++; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 577 | } while (i2c_read1(state->i2c, |
| 578 | state->demod_address, &data) < 0 && |
| 579 | (retryCount < DRXK_MAX_RETRIES_POWERUP)); |
| 580 | if (retryCount >= DRXK_MAX_RETRIES_POWERUP) |
| 581 | return -1; |
| 582 | do { |
| 583 | /* Make sure all clk domains are active */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 584 | status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_NONE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 585 | if (status < 0) |
| 586 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 587 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 588 | if (status < 0) |
| 589 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 590 | /* Enable pll lock tests */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 591 | status = write16(state, SIO_CC_PLL_LOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 592 | if (status < 0) |
| 593 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 594 | state->m_currentPowerMode = DRX_POWER_UP; |
| 595 | } while (0); |
| 596 | return status; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | static int init_state(struct drxk_state *state) |
| 601 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 602 | u32 ulVSBIfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 603 | u32 ulVSBIfAgcOutputLevel = 0; |
| 604 | u32 ulVSBIfAgcMinLevel = 0; |
| 605 | u32 ulVSBIfAgcMaxLevel = 0x7FFF; |
| 606 | u32 ulVSBIfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 607 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 608 | u32 ulVSBRfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 609 | u32 ulVSBRfAgcOutputLevel = 0; |
| 610 | u32 ulVSBRfAgcMinLevel = 0; |
| 611 | u32 ulVSBRfAgcMaxLevel = 0x7FFF; |
| 612 | u32 ulVSBRfAgcSpeed = 3; |
| 613 | u32 ulVSBRfAgcTop = 9500; |
| 614 | u32 ulVSBRfAgcCutOffCurrent = 4000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 615 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 616 | u32 ulATVIfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 617 | u32 ulATVIfAgcOutputLevel = 0; |
| 618 | u32 ulATVIfAgcMinLevel = 0; |
| 619 | u32 ulATVIfAgcMaxLevel = 0; |
| 620 | u32 ulATVIfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 621 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 622 | u32 ulATVRfAgcMode = DRXK_AGC_CTRL_OFF; |
| 623 | u32 ulATVRfAgcOutputLevel = 0; |
| 624 | u32 ulATVRfAgcMinLevel = 0; |
| 625 | u32 ulATVRfAgcMaxLevel = 0; |
| 626 | u32 ulATVRfAgcTop = 9500; |
| 627 | u32 ulATVRfAgcCutOffCurrent = 4000; |
| 628 | u32 ulATVRfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 629 | |
| 630 | u32 ulQual83 = DEFAULT_MER_83; |
| 631 | u32 ulQual93 = DEFAULT_MER_93; |
| 632 | |
| 633 | u32 ulDVBTStaticTSClock = 1; |
| 634 | u32 ulDVBCStaticTSClock = 1; |
| 635 | |
| 636 | u32 ulMpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 637 | u32 ulDemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
| 638 | |
| 639 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
| 640 | /* io_pad_cfg_mode output mode is drive always */ |
| 641 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
| 642 | u32 ulGPIOCfg = 0x0113; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 643 | u32 ulGPIO = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 644 | u32 ulSerialMode = 1; |
| 645 | u32 ulInvertTSClock = 0; |
| 646 | u32 ulTSDataStrength = DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH; |
| 647 | u32 ulTSClockkStrength = DRXK_MPEG_OUTPUT_CLK_DRIVE_STRENGTH; |
| 648 | u32 ulDVBTBitrate = 50000000; |
| 649 | u32 ulDVBCBitrate = DRXK_QAM_SYMBOLRATE_MAX * 8; |
| 650 | |
| 651 | u32 ulInsertRSByte = 0; |
| 652 | |
| 653 | u32 ulRfMirror = 1; |
| 654 | u32 ulPowerDown = 0; |
| 655 | |
| 656 | u32 ulAntennaDVBT = 1; |
| 657 | u32 ulAntennaDVBC = 0; |
| 658 | u32 ulAntennaSwitchDVBTDVBC = 0; |
| 659 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 660 | dprintk(1, "\n"); |
| 661 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 662 | state->m_hasLNA = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 663 | state->m_hasDVBT = false; |
| 664 | state->m_hasDVBC = false; |
| 665 | state->m_hasATV = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 666 | state->m_hasOOB = false; |
| 667 | state->m_hasAudio = false; |
| 668 | |
| 669 | state->m_ChunkSize = 124; |
| 670 | |
| 671 | state->m_oscClockFreq = 0; |
| 672 | state->m_smartAntInverted = false; |
| 673 | state->m_bPDownOpenBridge = false; |
| 674 | |
| 675 | /* real system clock frequency in kHz */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 676 | state->m_sysClockFreq = 151875; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 677 | /* Timing div, 250ns/Psys */ |
| 678 | /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */ |
| 679 | state->m_HICfgTimingDiv = ((state->m_sysClockFreq / 1000) * |
| 680 | HI_I2C_DELAY) / 1000; |
| 681 | /* Clipping */ |
| 682 | if (state->m_HICfgTimingDiv > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M) |
| 683 | state->m_HICfgTimingDiv = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M; |
| 684 | state->m_HICfgWakeUpKey = (state->demod_address << 1); |
| 685 | /* port/bridge/power down ctrl */ |
| 686 | state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
| 687 | |
| 688 | state->m_bPowerDown = (ulPowerDown != 0); |
| 689 | |
| 690 | state->m_DRXK_A1_PATCH_CODE = false; |
| 691 | state->m_DRXK_A1_ROM_CODE = false; |
| 692 | state->m_DRXK_A2_ROM_CODE = false; |
| 693 | state->m_DRXK_A3_ROM_CODE = false; |
| 694 | state->m_DRXK_A2_PATCH_CODE = false; |
| 695 | state->m_DRXK_A3_PATCH_CODE = false; |
| 696 | |
| 697 | /* Init AGC and PGA parameters */ |
| 698 | /* VSB IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 699 | state->m_vsbIfAgcCfg.ctrlMode = (ulVSBIfAgcMode); |
| 700 | state->m_vsbIfAgcCfg.outputLevel = (ulVSBIfAgcOutputLevel); |
| 701 | state->m_vsbIfAgcCfg.minOutputLevel = (ulVSBIfAgcMinLevel); |
| 702 | state->m_vsbIfAgcCfg.maxOutputLevel = (ulVSBIfAgcMaxLevel); |
| 703 | state->m_vsbIfAgcCfg.speed = (ulVSBIfAgcSpeed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 704 | state->m_vsbPgaCfg = 140; |
| 705 | |
| 706 | /* VSB RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 707 | state->m_vsbRfAgcCfg.ctrlMode = (ulVSBRfAgcMode); |
| 708 | state->m_vsbRfAgcCfg.outputLevel = (ulVSBRfAgcOutputLevel); |
| 709 | state->m_vsbRfAgcCfg.minOutputLevel = (ulVSBRfAgcMinLevel); |
| 710 | state->m_vsbRfAgcCfg.maxOutputLevel = (ulVSBRfAgcMaxLevel); |
| 711 | state->m_vsbRfAgcCfg.speed = (ulVSBRfAgcSpeed); |
| 712 | state->m_vsbRfAgcCfg.top = (ulVSBRfAgcTop); |
| 713 | state->m_vsbRfAgcCfg.cutOffCurrent = (ulVSBRfAgcCutOffCurrent); |
| 714 | state->m_vsbPreSawCfg.reference = 0x07; |
| 715 | state->m_vsbPreSawCfg.usePreSaw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 716 | |
| 717 | state->m_Quality83percent = DEFAULT_MER_83; |
| 718 | state->m_Quality93percent = DEFAULT_MER_93; |
| 719 | if (ulQual93 <= 500 && ulQual83 < ulQual93) { |
| 720 | state->m_Quality83percent = ulQual83; |
| 721 | state->m_Quality93percent = ulQual93; |
| 722 | } |
| 723 | |
| 724 | /* ATV IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 725 | state->m_atvIfAgcCfg.ctrlMode = (ulATVIfAgcMode); |
| 726 | state->m_atvIfAgcCfg.outputLevel = (ulATVIfAgcOutputLevel); |
| 727 | state->m_atvIfAgcCfg.minOutputLevel = (ulATVIfAgcMinLevel); |
| 728 | state->m_atvIfAgcCfg.maxOutputLevel = (ulATVIfAgcMaxLevel); |
| 729 | state->m_atvIfAgcCfg.speed = (ulATVIfAgcSpeed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 730 | |
| 731 | /* ATV RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 732 | state->m_atvRfAgcCfg.ctrlMode = (ulATVRfAgcMode); |
| 733 | state->m_atvRfAgcCfg.outputLevel = (ulATVRfAgcOutputLevel); |
| 734 | state->m_atvRfAgcCfg.minOutputLevel = (ulATVRfAgcMinLevel); |
| 735 | state->m_atvRfAgcCfg.maxOutputLevel = (ulATVRfAgcMaxLevel); |
| 736 | state->m_atvRfAgcCfg.speed = (ulATVRfAgcSpeed); |
| 737 | state->m_atvRfAgcCfg.top = (ulATVRfAgcTop); |
| 738 | state->m_atvRfAgcCfg.cutOffCurrent = (ulATVRfAgcCutOffCurrent); |
| 739 | state->m_atvPreSawCfg.reference = 0x04; |
| 740 | state->m_atvPreSawCfg.usePreSaw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 741 | |
| 742 | |
| 743 | /* DVBT RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 744 | state->m_dvbtRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; |
| 745 | state->m_dvbtRfAgcCfg.outputLevel = 0; |
| 746 | state->m_dvbtRfAgcCfg.minOutputLevel = 0; |
| 747 | state->m_dvbtRfAgcCfg.maxOutputLevel = 0xFFFF; |
| 748 | state->m_dvbtRfAgcCfg.top = 0x2100; |
| 749 | state->m_dvbtRfAgcCfg.cutOffCurrent = 4000; |
| 750 | state->m_dvbtRfAgcCfg.speed = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 751 | |
| 752 | |
| 753 | /* DVBT IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 754 | state->m_dvbtIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; |
| 755 | state->m_dvbtIfAgcCfg.outputLevel = 0; |
| 756 | state->m_dvbtIfAgcCfg.minOutputLevel = 0; |
| 757 | state->m_dvbtIfAgcCfg.maxOutputLevel = 9000; |
| 758 | state->m_dvbtIfAgcCfg.top = 13424; |
| 759 | state->m_dvbtIfAgcCfg.cutOffCurrent = 0; |
| 760 | state->m_dvbtIfAgcCfg.speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 761 | state->m_dvbtIfAgcCfg.FastClipCtrlDelay = 30; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 762 | state->m_dvbtIfAgcCfg.IngainTgtMax = 30000; |
| 763 | /* state->m_dvbtPgaCfg = 140; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 764 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 765 | state->m_dvbtPreSawCfg.reference = 4; |
| 766 | state->m_dvbtPreSawCfg.usePreSaw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 767 | |
| 768 | /* QAM RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 769 | state->m_qamRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; |
| 770 | state->m_qamRfAgcCfg.outputLevel = 0; |
| 771 | state->m_qamRfAgcCfg.minOutputLevel = 6023; |
| 772 | state->m_qamRfAgcCfg.maxOutputLevel = 27000; |
| 773 | state->m_qamRfAgcCfg.top = 0x2380; |
| 774 | state->m_qamRfAgcCfg.cutOffCurrent = 4000; |
| 775 | state->m_qamRfAgcCfg.speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 776 | |
| 777 | /* QAM IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 778 | state->m_qamIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; |
| 779 | state->m_qamIfAgcCfg.outputLevel = 0; |
| 780 | state->m_qamIfAgcCfg.minOutputLevel = 0; |
| 781 | state->m_qamIfAgcCfg.maxOutputLevel = 9000; |
| 782 | state->m_qamIfAgcCfg.top = 0x0511; |
| 783 | state->m_qamIfAgcCfg.cutOffCurrent = 0; |
| 784 | state->m_qamIfAgcCfg.speed = 3; |
| 785 | state->m_qamIfAgcCfg.IngainTgtMax = 5119; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 786 | state->m_qamIfAgcCfg.FastClipCtrlDelay = 50; |
| 787 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 788 | state->m_qamPgaCfg = 140; |
| 789 | state->m_qamPreSawCfg.reference = 4; |
| 790 | state->m_qamPreSawCfg.usePreSaw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 791 | |
| 792 | state->m_OperationMode = OM_NONE; |
| 793 | state->m_DrxkState = DRXK_UNINITIALIZED; |
| 794 | |
| 795 | /* MPEG output configuration */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 796 | state->m_enableMPEGOutput = true; /* If TRUE; enable MPEG ouput */ |
| 797 | state->m_insertRSByte = false; /* If TRUE; insert RS byte */ |
| 798 | state->m_enableParallel = true; /* If TRUE; |
| 799 | parallel out otherwise serial */ |
| 800 | state->m_invertDATA = false; /* If TRUE; invert DATA signals */ |
| 801 | state->m_invertERR = false; /* If TRUE; invert ERR signal */ |
| 802 | state->m_invertSTR = false; /* If TRUE; invert STR signals */ |
| 803 | state->m_invertVAL = false; /* If TRUE; invert VAL signals */ |
| 804 | state->m_invertCLK = (ulInvertTSClock != 0); /* If TRUE; invert CLK signals */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 805 | state->m_DVBTStaticCLK = (ulDVBTStaticTSClock != 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 806 | state->m_DVBCStaticCLK = (ulDVBCStaticTSClock != 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 807 | /* If TRUE; static MPEG clockrate will be used; |
| 808 | otherwise clockrate will adapt to the bitrate of the TS */ |
| 809 | |
| 810 | state->m_DVBTBitrate = ulDVBTBitrate; |
| 811 | state->m_DVBCBitrate = ulDVBCBitrate; |
| 812 | |
| 813 | state->m_TSDataStrength = (ulTSDataStrength & 0x07); |
| 814 | state->m_TSClockkStrength = (ulTSClockkStrength & 0x07); |
| 815 | |
| 816 | /* Maximum bitrate in b/s in case static clockrate is selected */ |
| 817 | state->m_mpegTsStaticBitrate = 19392658; |
| 818 | state->m_disableTEIhandling = false; |
| 819 | |
| 820 | if (ulInsertRSByte) |
| 821 | state->m_insertRSByte = true; |
| 822 | |
| 823 | state->m_MpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 824 | if (ulMpegLockTimeOut < 10000) |
| 825 | state->m_MpegLockTimeOut = ulMpegLockTimeOut; |
| 826 | state->m_DemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
| 827 | if (ulDemodLockTimeOut < 10000) |
| 828 | state->m_DemodLockTimeOut = ulDemodLockTimeOut; |
| 829 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 830 | /* QAM defaults */ |
| 831 | state->m_Constellation = DRX_CONSTELLATION_AUTO; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 832 | state->m_qamInterleaveMode = DRXK_QAM_I12_J17; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 833 | state->m_fecRsPlen = 204 * 8; /* fecRsPlen annex A */ |
| 834 | state->m_fecRsPrescale = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 835 | |
| 836 | state->m_sqiSpeed = DRXK_DVBT_SQI_SPEED_MEDIUM; |
| 837 | state->m_agcFastClipCtrlDelay = 0; |
| 838 | |
| 839 | state->m_GPIOCfg = (ulGPIOCfg); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 840 | state->m_GPIO = (ulGPIO == 0 ? 0 : 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 841 | |
| 842 | state->m_AntennaDVBT = (ulAntennaDVBT == 0 ? 0 : 1); |
| 843 | state->m_AntennaDVBC = (ulAntennaDVBC == 0 ? 0 : 1); |
| 844 | state->m_AntennaSwitchDVBTDVBC = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 845 | (ulAntennaSwitchDVBTDVBC == 0 ? 0 : 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 846 | |
| 847 | state->m_bPowerDown = false; |
| 848 | state->m_currentPowerMode = DRX_POWER_DOWN; |
| 849 | |
| 850 | state->m_enableParallel = (ulSerialMode == 0); |
| 851 | |
| 852 | state->m_rfmirror = (ulRfMirror == 0); |
| 853 | state->m_IfAgcPol = false; |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | static int DRXX_Open(struct drxk_state *state) |
| 858 | { |
| 859 | int status = 0; |
| 860 | u32 jtag = 0; |
| 861 | u16 bid = 0; |
| 862 | u16 key = 0; |
| 863 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 864 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 865 | do { |
| 866 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 867 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 868 | if (status < 0) |
| 869 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 870 | /* Check device id */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 871 | status = read16(state, SIO_TOP_COMM_KEY__A, &key); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 872 | if (status < 0) |
| 873 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 874 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 875 | if (status < 0) |
| 876 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 877 | status = read32(state, SIO_TOP_JTAGID_LO__A, &jtag); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 878 | if (status < 0) |
| 879 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 880 | status = read16(state, SIO_PDR_UIO_IN_HI__A, &bid); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 881 | if (status < 0) |
| 882 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 883 | status = write16(state, SIO_TOP_COMM_KEY__A, key); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 884 | if (status < 0) |
| 885 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 886 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 887 | return status; |
| 888 | } |
| 889 | |
| 890 | static int GetDeviceCapabilities(struct drxk_state *state) |
| 891 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 892 | u16 sioPdrOhwCfg = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 893 | u32 sioTopJtagidLo = 0; |
| 894 | int status; |
| 895 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 896 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 897 | do { |
| 898 | /* driver 0.9.0 */ |
| 899 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 900 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 901 | if (status < 0) |
| 902 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 903 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 904 | status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 905 | if (status < 0) |
| 906 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 907 | status = read16(state, SIO_PDR_OHW_CFG__A, &sioPdrOhwCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 908 | if (status < 0) |
| 909 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 910 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 911 | if (status < 0) |
| 912 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 913 | |
| 914 | switch ((sioPdrOhwCfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { |
| 915 | case 0: |
| 916 | /* ignore (bypass ?) */ |
| 917 | break; |
| 918 | case 1: |
| 919 | /* 27 MHz */ |
| 920 | state->m_oscClockFreq = 27000; |
| 921 | break; |
| 922 | case 2: |
| 923 | /* 20.25 MHz */ |
| 924 | state->m_oscClockFreq = 20250; |
| 925 | break; |
| 926 | case 3: |
| 927 | /* 4 MHz */ |
| 928 | state->m_oscClockFreq = 20250; |
| 929 | break; |
| 930 | default: |
| 931 | return -1; |
| 932 | } |
| 933 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 934 | Determine device capabilities |
| 935 | Based on pinning v14 |
| 936 | */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 937 | status = read32(state, SIO_TOP_JTAGID_LO__A, &sioTopJtagidLo); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 938 | if (status < 0) |
| 939 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 940 | /* driver 0.9.0 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 941 | switch ((sioTopJtagidLo >> 29) & 0xF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 942 | case 0: |
| 943 | state->m_deviceSpin = DRXK_SPIN_A1; |
| 944 | break; |
| 945 | case 2: |
| 946 | state->m_deviceSpin = DRXK_SPIN_A2; |
| 947 | break; |
| 948 | case 3: |
| 949 | state->m_deviceSpin = DRXK_SPIN_A3; |
| 950 | break; |
| 951 | default: |
| 952 | state->m_deviceSpin = DRXK_SPIN_UNKNOWN; |
| 953 | status = -1; |
| 954 | break; |
| 955 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 956 | switch ((sioTopJtagidLo >> 12) & 0xFF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 957 | case 0x13: |
| 958 | /* typeId = DRX3913K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 959 | state->m_hasLNA = false; |
| 960 | state->m_hasOOB = false; |
| 961 | state->m_hasATV = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 962 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 963 | state->m_hasDVBT = true; |
| 964 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 965 | state->m_hasSAWSW = true; |
| 966 | state->m_hasGPIO2 = false; |
| 967 | state->m_hasGPIO1 = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 968 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 969 | break; |
| 970 | case 0x15: |
| 971 | /* typeId = DRX3915K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 972 | state->m_hasLNA = false; |
| 973 | state->m_hasOOB = false; |
| 974 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 975 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 976 | state->m_hasDVBT = true; |
| 977 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 978 | state->m_hasSAWSW = true; |
| 979 | state->m_hasGPIO2 = true; |
| 980 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 981 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 982 | break; |
| 983 | case 0x16: |
| 984 | /* typeId = DRX3916K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 985 | state->m_hasLNA = false; |
| 986 | state->m_hasOOB = false; |
| 987 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 988 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 989 | state->m_hasDVBT = true; |
| 990 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 991 | state->m_hasSAWSW = true; |
| 992 | state->m_hasGPIO2 = true; |
| 993 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 994 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 995 | break; |
| 996 | case 0x18: |
| 997 | /* typeId = DRX3918K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 998 | state->m_hasLNA = false; |
| 999 | state->m_hasOOB = false; |
| 1000 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1001 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1002 | state->m_hasDVBT = true; |
| 1003 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1004 | state->m_hasSAWSW = true; |
| 1005 | state->m_hasGPIO2 = true; |
| 1006 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1007 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1008 | break; |
| 1009 | case 0x21: |
| 1010 | /* typeId = DRX3921K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1011 | state->m_hasLNA = false; |
| 1012 | state->m_hasOOB = false; |
| 1013 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1014 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1015 | state->m_hasDVBT = true; |
| 1016 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1017 | state->m_hasSAWSW = true; |
| 1018 | state->m_hasGPIO2 = true; |
| 1019 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1020 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1021 | break; |
| 1022 | case 0x23: |
| 1023 | /* typeId = DRX3923K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1024 | state->m_hasLNA = false; |
| 1025 | state->m_hasOOB = false; |
| 1026 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1027 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1028 | state->m_hasDVBT = true; |
| 1029 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1030 | state->m_hasSAWSW = true; |
| 1031 | state->m_hasGPIO2 = true; |
| 1032 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1033 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1034 | break; |
| 1035 | case 0x25: |
| 1036 | /* typeId = DRX3925K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1037 | state->m_hasLNA = false; |
| 1038 | state->m_hasOOB = false; |
| 1039 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1040 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1041 | state->m_hasDVBT = true; |
| 1042 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1043 | state->m_hasSAWSW = true; |
| 1044 | state->m_hasGPIO2 = true; |
| 1045 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1046 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1047 | break; |
| 1048 | case 0x26: |
| 1049 | /* typeId = DRX3926K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1050 | state->m_hasLNA = false; |
| 1051 | state->m_hasOOB = false; |
| 1052 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1053 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1054 | state->m_hasDVBT = true; |
| 1055 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1056 | state->m_hasSAWSW = true; |
| 1057 | state->m_hasGPIO2 = true; |
| 1058 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1059 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1060 | break; |
| 1061 | default: |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1062 | printk(KERN_ERR "drxk: DeviceID not supported = %02x\n", |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1063 | ((sioTopJtagidLo >> 12) & 0xFF)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1064 | status = -1; |
| 1065 | break; |
| 1066 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1067 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1068 | return status; |
| 1069 | } |
| 1070 | |
| 1071 | static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult) |
| 1072 | { |
| 1073 | int status; |
| 1074 | bool powerdown_cmd; |
| 1075 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1076 | dprintk(1, "\n"); |
| 1077 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1078 | /* Write command */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1079 | status = write16(state, SIO_HI_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1080 | if (status < 0) |
| 1081 | return status; |
| 1082 | if (cmd == SIO_HI_RA_RAM_CMD_RESET) |
| 1083 | msleep(1); |
| 1084 | |
| 1085 | powerdown_cmd = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1086 | (bool) ((cmd == SIO_HI_RA_RAM_CMD_CONFIG) && |
| 1087 | ((state->m_HICfgCtrl) & |
| 1088 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) == |
| 1089 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1090 | if (powerdown_cmd == false) { |
| 1091 | /* Wait until command rdy */ |
| 1092 | u32 retryCount = 0; |
| 1093 | u16 waitCmd; |
| 1094 | |
| 1095 | do { |
| 1096 | msleep(1); |
| 1097 | retryCount += 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1098 | status = read16(state, SIO_HI_RA_RAM_CMD__A, |
| 1099 | &waitCmd); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1100 | } while ((status < 0) && (retryCount < DRXK_MAX_RETRIES) |
| 1101 | && (waitCmd != 0)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1102 | |
| 1103 | if (status == 0) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1104 | status = read16(state, SIO_HI_RA_RAM_RES__A, |
| 1105 | pResult); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1106 | } |
| 1107 | return status; |
| 1108 | } |
| 1109 | |
| 1110 | static int HI_CfgCommand(struct drxk_state *state) |
| 1111 | { |
| 1112 | int status; |
| 1113 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1114 | dprintk(1, "\n"); |
| 1115 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1116 | mutex_lock(&state->mutex); |
| 1117 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1118 | status = write16(state, SIO_HI_RA_RAM_PAR_6__A, state->m_HICfgTimeout); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1119 | if (status < 0) |
| 1120 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1121 | status = write16(state, SIO_HI_RA_RAM_PAR_5__A, state->m_HICfgCtrl); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1122 | if (status < 0) |
| 1123 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1124 | status = write16(state, SIO_HI_RA_RAM_PAR_4__A, state->m_HICfgWakeUpKey); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1125 | if (status < 0) |
| 1126 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1127 | status = write16(state, SIO_HI_RA_RAM_PAR_3__A, state->m_HICfgBridgeDelay); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1128 | if (status < 0) |
| 1129 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1130 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, state->m_HICfgTimingDiv); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1131 | if (status < 0) |
| 1132 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1133 | status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1134 | if (status < 0) |
| 1135 | break; |
| 1136 | status = HI_Command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0); |
| 1137 | if (status < 0) |
| 1138 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1139 | |
| 1140 | state->m_HICfgCtrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1141 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1142 | mutex_unlock(&state->mutex); |
| 1143 | return status; |
| 1144 | } |
| 1145 | |
| 1146 | static int InitHI(struct drxk_state *state) |
| 1147 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1148 | dprintk(1, "\n"); |
| 1149 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1150 | state->m_HICfgWakeUpKey = (state->demod_address << 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1151 | state->m_HICfgTimeout = 0x96FF; |
| 1152 | /* port/bridge/power down ctrl */ |
| 1153 | state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1154 | return HI_CfgCommand(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) |
| 1158 | { |
| 1159 | int status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1160 | u16 sioPdrMclkCfg = 0; |
| 1161 | u16 sioPdrMdxCfg = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1162 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1163 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1164 | do { |
| 1165 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1166 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1167 | if (status < 0) |
| 1168 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1169 | |
| 1170 | /* MPEG TS pad configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1171 | status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1172 | if (status < 0) |
| 1173 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1174 | |
| 1175 | if (mpegEnable == false) { |
| 1176 | /* Set MPEG TS pads to inputmode */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1177 | status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1178 | if (status < 0) |
| 1179 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1180 | status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1181 | if (status < 0) |
| 1182 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1183 | status = write16(state, SIO_PDR_MCLK_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1184 | if (status < 0) |
| 1185 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1186 | status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1187 | if (status < 0) |
| 1188 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1189 | status = write16(state, SIO_PDR_MD0_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1190 | if (status < 0) |
| 1191 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1192 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1193 | if (status < 0) |
| 1194 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1195 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1196 | if (status < 0) |
| 1197 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1198 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1199 | if (status < 0) |
| 1200 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1201 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1202 | if (status < 0) |
| 1203 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1204 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1205 | if (status < 0) |
| 1206 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1207 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1208 | if (status < 0) |
| 1209 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1210 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1211 | if (status < 0) |
| 1212 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1213 | } else { |
| 1214 | /* Enable MPEG output */ |
| 1215 | sioPdrMdxCfg = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1216 | ((state->m_TSDataStrength << |
| 1217 | SIO_PDR_MD0_CFG_DRIVE__B) | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1218 | sioPdrMclkCfg = ((state->m_TSClockkStrength << |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1219 | SIO_PDR_MCLK_CFG_DRIVE__B) | |
| 1220 | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1221 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1222 | status = write16(state, SIO_PDR_MSTRT_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1223 | if (status < 0) |
| 1224 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1225 | status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); /* Disable */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1226 | if (status < 0) |
| 1227 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1228 | status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); /* Disable */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1229 | if (status < 0) |
| 1230 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1231 | if (state->m_enableParallel == true) { |
| 1232 | /* paralel -> enable MD1 to MD7 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1233 | status = write16(state, SIO_PDR_MD1_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1234 | if (status < 0) |
| 1235 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1236 | status = write16(state, SIO_PDR_MD2_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1237 | if (status < 0) |
| 1238 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1239 | status = write16(state, SIO_PDR_MD3_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1240 | if (status < 0) |
| 1241 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1242 | status = write16(state, SIO_PDR_MD4_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1243 | if (status < 0) |
| 1244 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1245 | status = write16(state, SIO_PDR_MD5_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1246 | if (status < 0) |
| 1247 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1248 | status = write16(state, SIO_PDR_MD6_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1249 | if (status < 0) |
| 1250 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1251 | status = write16(state, SIO_PDR_MD7_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1252 | if (status < 0) |
| 1253 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1254 | } else { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1255 | sioPdrMdxCfg = ((state->m_TSDataStrength << |
| 1256 | SIO_PDR_MD0_CFG_DRIVE__B) |
| 1257 | | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1258 | /* serial -> disable MD1 to MD7 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1259 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1260 | if (status < 0) |
| 1261 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1262 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1263 | if (status < 0) |
| 1264 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1265 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1266 | if (status < 0) |
| 1267 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1268 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1269 | if (status < 0) |
| 1270 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1271 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1272 | if (status < 0) |
| 1273 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1274 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1275 | if (status < 0) |
| 1276 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1277 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1278 | if (status < 0) |
| 1279 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1280 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1281 | status = write16(state, SIO_PDR_MCLK_CFG__A, sioPdrMclkCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1282 | if (status < 0) |
| 1283 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1284 | status = write16(state, SIO_PDR_MD0_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1285 | if (status < 0) |
| 1286 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1287 | } |
| 1288 | /* Enable MB output over MPEG pads and ctl input */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1289 | status = write16(state, SIO_PDR_MON_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1290 | if (status < 0) |
| 1291 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1292 | /* Write nomagic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1293 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1294 | if (status < 0) |
| 1295 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1296 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1297 | return status; |
| 1298 | } |
| 1299 | |
| 1300 | static int MPEGTSDisable(struct drxk_state *state) |
| 1301 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1302 | dprintk(1, "\n"); |
| 1303 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1304 | return MPEGTSConfigurePins(state, false); |
| 1305 | } |
| 1306 | |
| 1307 | static int BLChainCmd(struct drxk_state *state, |
| 1308 | u16 romOffset, u16 nrOfElements, u32 timeOut) |
| 1309 | { |
| 1310 | u16 blStatus = 0; |
| 1311 | int status; |
| 1312 | unsigned long end; |
| 1313 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1314 | dprintk(1, "\n"); |
| 1315 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1316 | mutex_lock(&state->mutex); |
| 1317 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1318 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1319 | if (status < 0) |
| 1320 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1321 | status = write16(state, SIO_BL_CHAIN_ADDR__A, romOffset); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1322 | if (status < 0) |
| 1323 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1324 | status = write16(state, SIO_BL_CHAIN_LEN__A, nrOfElements); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1325 | if (status < 0) |
| 1326 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1327 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1328 | if (status < 0) |
| 1329 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1330 | end = jiffies + msecs_to_jiffies(timeOut); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1331 | |
| 1332 | do { |
| 1333 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1334 | status = read16(state, SIO_BL_STATUS__A, &blStatus); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1335 | if (status < 0) |
| 1336 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1337 | } while ((blStatus == 0x1) && |
| 1338 | ((time_is_after_jiffies(end)))); |
| 1339 | if (blStatus == 0x1) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1340 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1341 | mutex_unlock(&state->mutex); |
| 1342 | return -1; |
| 1343 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1344 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1345 | mutex_unlock(&state->mutex); |
| 1346 | return status; |
| 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | static int DownloadMicrocode(struct drxk_state *state, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1351 | const u8 pMCImage[], u32 Length) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1352 | { |
| 1353 | const u8 *pSrc = pMCImage; |
| 1354 | u16 Flags; |
| 1355 | u16 Drain; |
| 1356 | u32 Address; |
| 1357 | u16 nBlocks; |
| 1358 | u16 BlockSize; |
| 1359 | u16 BlockCRC; |
| 1360 | u32 offset = 0; |
| 1361 | u32 i; |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1362 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1363 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1364 | dprintk(1, "\n"); |
| 1365 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1366 | /* down the drain (we don care about MAGIC_WORD) */ |
| 1367 | Drain = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1368 | pSrc += sizeof(u16); |
| 1369 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1370 | nBlocks = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1371 | pSrc += sizeof(u16); |
| 1372 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1373 | |
| 1374 | for (i = 0; i < nBlocks; i += 1) { |
| 1375 | Address = (pSrc[0] << 24) | (pSrc[1] << 16) | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1376 | (pSrc[2] << 8) | pSrc[3]; |
| 1377 | pSrc += sizeof(u32); |
| 1378 | offset += sizeof(u32); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1379 | |
| 1380 | BlockSize = ((pSrc[0] << 8) | pSrc[1]) * sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1381 | pSrc += sizeof(u16); |
| 1382 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1383 | |
| 1384 | Flags = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1385 | pSrc += sizeof(u16); |
| 1386 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1387 | |
| 1388 | BlockCRC = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1389 | pSrc += sizeof(u16); |
| 1390 | offset += sizeof(u16); |
Mauro Carvalho Chehab | bcd2ebb | 2011-07-09 18:57:54 -0300 | [diff] [blame] | 1391 | |
| 1392 | if (offset + BlockSize > Length) { |
| 1393 | printk(KERN_ERR "drxk: Firmware is corrupted.\n"); |
| 1394 | return -EINVAL; |
| 1395 | } |
| 1396 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1397 | status = write_block(state, Address, BlockSize, pSrc); |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame^] | 1398 | if (status < 0) { |
| 1399 | printk(KERN_ERR "drxk: Error %d while loading firmware\n", status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1400 | break; |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame^] | 1401 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1402 | pSrc += BlockSize; |
| 1403 | offset += BlockSize; |
| 1404 | } |
| 1405 | return status; |
| 1406 | } |
| 1407 | |
| 1408 | static int DVBTEnableOFDMTokenRing(struct drxk_state *state, bool enable) |
| 1409 | { |
| 1410 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1411 | u16 data = 0; |
| 1412 | u16 desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_ON; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1413 | u16 desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED; |
| 1414 | unsigned long end; |
| 1415 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1416 | dprintk(1, "\n"); |
| 1417 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1418 | if (enable == false) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1419 | desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_OFF; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1420 | desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN; |
| 1421 | } |
| 1422 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1423 | status = (read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1424 | |
| 1425 | if (data == desiredStatus) { |
| 1426 | /* tokenring already has correct status */ |
| 1427 | return status; |
| 1428 | } |
| 1429 | /* Disable/enable dvbt tokenring bridge */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1430 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1431 | write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desiredCtrl); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1432 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1433 | end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1434 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1435 | status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1436 | if (status < 0) |
| 1437 | break; |
| 1438 | } while ((data != desiredStatus) && ((time_is_after_jiffies(end)))); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1439 | if (data != desiredStatus) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1440 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1441 | return -1; |
| 1442 | } |
| 1443 | return status; |
| 1444 | } |
| 1445 | |
| 1446 | static int MPEGTSStop(struct drxk_state *state) |
| 1447 | { |
| 1448 | int status = 0; |
| 1449 | u16 fecOcSncMode = 0; |
| 1450 | u16 fecOcIprMode = 0; |
| 1451 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1452 | dprintk(1, "\n"); |
| 1453 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1454 | do { |
| 1455 | /* Gracefull shutdown (byte boundaries) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1456 | status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1457 | if (status < 0) |
| 1458 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1459 | fecOcSncMode |= FEC_OC_SNC_MODE_SHUTDOWN__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1460 | status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1461 | if (status < 0) |
| 1462 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1463 | |
| 1464 | /* Suppress MCLK during absence of data */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1465 | status = read16(state, FEC_OC_IPR_MODE__A, &fecOcIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1466 | if (status < 0) |
| 1467 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1468 | fecOcIprMode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1469 | status = write16(state, FEC_OC_IPR_MODE__A, fecOcIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1470 | if (status < 0) |
| 1471 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1472 | } while (0); |
| 1473 | return status; |
| 1474 | } |
| 1475 | |
| 1476 | static int scu_command(struct drxk_state *state, |
| 1477 | u16 cmd, u8 parameterLen, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1478 | u16 *parameter, u8 resultLen, u16 *result) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1479 | { |
| 1480 | #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15 |
| 1481 | #error DRXK register mapping no longer compatible with this routine! |
| 1482 | #endif |
| 1483 | u16 curCmd = 0; |
| 1484 | int status; |
| 1485 | unsigned long end; |
| 1486 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1487 | dprintk(1, "\n"); |
| 1488 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1489 | if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) || |
| 1490 | ((resultLen > 0) && (result == NULL))) |
| 1491 | return -1; |
| 1492 | |
| 1493 | mutex_lock(&state->mutex); |
| 1494 | do { |
| 1495 | /* assume that the command register is ready |
| 1496 | since it is checked afterwards */ |
| 1497 | u8 buffer[34]; |
| 1498 | int cnt = 0, ii; |
| 1499 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1500 | for (ii = parameterLen - 1; ii >= 0; ii -= 1) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1501 | buffer[cnt++] = (parameter[ii] & 0xFF); |
| 1502 | buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF); |
| 1503 | } |
| 1504 | buffer[cnt++] = (cmd & 0xFF); |
| 1505 | buffer[cnt++] = ((cmd >> 8) & 0xFF); |
| 1506 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1507 | write_block(state, SCU_RAM_PARAM_0__A - |
| 1508 | (parameterLen - 1), cnt, buffer); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1509 | /* Wait until SCU has processed command */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1510 | end = jiffies + msecs_to_jiffies(DRXK_MAX_WAITTIME); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1511 | do { |
| 1512 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1513 | status = read16(state, SCU_RAM_COMMAND__A, &curCmd); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1514 | if (status < 0) |
| 1515 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1516 | } while (!(curCmd == DRX_SCU_READY) |
| 1517 | && (time_is_after_jiffies(end))); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1518 | if (curCmd != DRX_SCU_READY) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1519 | printk(KERN_ERR "drxk: SCU not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1520 | mutex_unlock(&state->mutex); |
| 1521 | return -1; |
| 1522 | } |
| 1523 | /* read results */ |
| 1524 | if ((resultLen > 0) && (result != NULL)) { |
| 1525 | s16 err; |
| 1526 | int ii; |
| 1527 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1528 | for (ii = resultLen - 1; ii >= 0; ii -= 1) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1529 | status = read16(state, SCU_RAM_PARAM_0__A - ii, &result[ii]); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1530 | if (status < 0) |
| 1531 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | /* Check if an error was reported by SCU */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1535 | err = (s16) result[0]; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1536 | |
| 1537 | /* check a few fixed error codes */ |
| 1538 | if (err == SCU_RESULT_UNKSTD) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1539 | printk(KERN_ERR "drxk: SCU_RESULT_UNKSTD\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1540 | mutex_unlock(&state->mutex); |
| 1541 | return -1; |
| 1542 | } else if (err == SCU_RESULT_UNKCMD) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1543 | printk(KERN_ERR "drxk: SCU_RESULT_UNKCMD\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1544 | mutex_unlock(&state->mutex); |
| 1545 | return -1; |
| 1546 | } |
| 1547 | /* here it is assumed that negative means error, |
| 1548 | and positive no error */ |
| 1549 | else if (err < 0) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1550 | printk(KERN_ERR "drxk: %s ERROR\n", __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1551 | mutex_unlock(&state->mutex); |
| 1552 | return -1; |
| 1553 | } |
| 1554 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1555 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1556 | mutex_unlock(&state->mutex); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1557 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1558 | printk(KERN_ERR "drxk: %s: status = %d\n", __func__, status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1559 | |
| 1560 | return status; |
| 1561 | } |
| 1562 | |
| 1563 | static int SetIqmAf(struct drxk_state *state, bool active) |
| 1564 | { |
| 1565 | u16 data = 0; |
| 1566 | int status; |
| 1567 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1568 | dprintk(1, "\n"); |
| 1569 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1570 | do { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1571 | /* Configure IQM */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1572 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1573 | if (status < 0) |
| 1574 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1575 | if (!active) { |
| 1576 | data |= (IQM_AF_STDBY_STDBY_ADC_STANDBY |
| 1577 | | IQM_AF_STDBY_STDBY_AMP_STANDBY |
| 1578 | | IQM_AF_STDBY_STDBY_PD_STANDBY |
| 1579 | | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1580 | | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY); |
| 1581 | } else { /* active */ |
| 1582 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1583 | data &= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY) |
| 1584 | & (~IQM_AF_STDBY_STDBY_AMP_STANDBY) |
| 1585 | & (~IQM_AF_STDBY_STDBY_PD_STANDBY) |
| 1586 | & (~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY) |
| 1587 | & (~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1588 | ); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1589 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1590 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1591 | if (status < 0) |
| 1592 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1593 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1594 | return status; |
| 1595 | } |
| 1596 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1597 | static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1598 | { |
| 1599 | int status = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1600 | u16 sioCcPwdMode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1601 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1602 | dprintk(1, "\n"); |
| 1603 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1604 | /* Check arguments */ |
| 1605 | if (mode == NULL) |
| 1606 | return -1; |
| 1607 | |
| 1608 | switch (*mode) { |
| 1609 | case DRX_POWER_UP: |
| 1610 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_NONE; |
| 1611 | break; |
| 1612 | case DRXK_POWER_DOWN_OFDM: |
| 1613 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OFDM; |
| 1614 | break; |
| 1615 | case DRXK_POWER_DOWN_CORE: |
| 1616 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_CLOCK; |
| 1617 | break; |
| 1618 | case DRXK_POWER_DOWN_PLL: |
| 1619 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_PLL; |
| 1620 | break; |
| 1621 | case DRX_POWER_DOWN: |
| 1622 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OSC; |
| 1623 | break; |
| 1624 | default: |
| 1625 | /* Unknow sleep mode */ |
| 1626 | return -1; |
| 1627 | break; |
| 1628 | } |
| 1629 | |
| 1630 | /* If already in requested power mode, do nothing */ |
| 1631 | if (state->m_currentPowerMode == *mode) |
| 1632 | return 0; |
| 1633 | |
| 1634 | /* For next steps make sure to start from DRX_POWER_UP mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1635 | if (state->m_currentPowerMode != DRX_POWER_UP) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1636 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1637 | status = PowerUpDevice(state); |
| 1638 | if (status < 0) |
| 1639 | break; |
| 1640 | status = DVBTEnableOFDMTokenRing(state, true); |
| 1641 | if (status < 0) |
| 1642 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1643 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | if (*mode == DRX_POWER_UP) { |
| 1647 | /* Restore analog & pin configuartion */ |
| 1648 | } else { |
| 1649 | /* Power down to requested mode */ |
| 1650 | /* Backup some register settings */ |
| 1651 | /* Set pins with possible pull-ups connected |
| 1652 | to them in input mode */ |
| 1653 | /* Analog power down */ |
| 1654 | /* ADC power down */ |
| 1655 | /* Power down device */ |
| 1656 | /* stop all comm_exec */ |
| 1657 | /* Stop and power down previous standard */ |
| 1658 | do { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1659 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1660 | case OM_DVBT: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1661 | status = MPEGTSStop(state); |
| 1662 | if (status < 0) |
| 1663 | break; |
| 1664 | status = PowerDownDVBT(state, false); |
| 1665 | if (status < 0) |
| 1666 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1667 | break; |
| 1668 | case OM_QAM_ITU_A: |
| 1669 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1670 | status = MPEGTSStop(state); |
| 1671 | if (status < 0) |
| 1672 | break; |
| 1673 | status = PowerDownQAM(state); |
| 1674 | if (status < 0) |
| 1675 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1676 | break; |
| 1677 | default: |
| 1678 | break; |
| 1679 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1680 | status = DVBTEnableOFDMTokenRing(state, false); |
| 1681 | if (status < 0) |
| 1682 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1683 | status = write16(state, SIO_CC_PWD_MODE__A, sioCcPwdMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1684 | if (status < 0) |
| 1685 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1686 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1687 | if (status < 0) |
| 1688 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1689 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1690 | if (*mode != DRXK_POWER_DOWN_OFDM) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1691 | state->m_HICfgCtrl |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1692 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1693 | status = HI_CfgCommand(state); |
| 1694 | if (status < 0) |
| 1695 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1696 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1697 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1698 | } |
| 1699 | state->m_currentPowerMode = *mode; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1700 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode) |
| 1704 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1705 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1706 | u16 cmdResult = 0; |
| 1707 | u16 data = 0; |
| 1708 | int status; |
| 1709 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1710 | dprintk(1, "\n"); |
| 1711 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1712 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1713 | status = read16(state, SCU_COMM_EXEC__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1714 | if (status < 0) |
| 1715 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1716 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 1717 | /* Send OFDM stop command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1718 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 1719 | if (status < 0) |
| 1720 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1721 | /* Send OFDM reset command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1722 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 1723 | if (status < 0) |
| 1724 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | /* Reset datapath for OFDM, processors first */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1728 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1729 | if (status < 0) |
| 1730 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1731 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1732 | if (status < 0) |
| 1733 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1734 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1735 | if (status < 0) |
| 1736 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1737 | |
| 1738 | /* powerdown AFE */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1739 | status = SetIqmAf(state, false); |
| 1740 | if (status < 0) |
| 1741 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1742 | |
| 1743 | /* powerdown to OFDM mode */ |
| 1744 | if (setPowerMode) { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1745 | status = CtrlPowerMode(state, &powerMode); |
| 1746 | if (status < 0) |
| 1747 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1748 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1749 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1750 | return status; |
| 1751 | } |
| 1752 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1753 | static int SetOperationMode(struct drxk_state *state, |
| 1754 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1755 | { |
| 1756 | int status = 0; |
| 1757 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1758 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1759 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1760 | Stop and power down previous standard |
| 1761 | TODO investigate total power down instead of partial |
| 1762 | power down depending on "previous" standard. |
| 1763 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1764 | do { |
| 1765 | /* disable HW lock indicator */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1766 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1767 | if (status < 0) |
| 1768 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1769 | |
| 1770 | if (state->m_OperationMode != oMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1771 | switch (state->m_OperationMode) { |
| 1772 | /* OM_NONE was added for start up */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1773 | case OM_NONE: |
| 1774 | break; |
| 1775 | case OM_DVBT: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1776 | status = MPEGTSStop(state); |
| 1777 | if (status < 0) |
| 1778 | break; |
| 1779 | status = PowerDownDVBT(state, true); |
| 1780 | if (status < 0) |
| 1781 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1782 | state->m_OperationMode = OM_NONE; |
| 1783 | break; |
| 1784 | case OM_QAM_ITU_B: |
| 1785 | status = -1; |
| 1786 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1787 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1788 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1789 | status = MPEGTSStop(state); |
| 1790 | if (status < 0) |
| 1791 | break; |
| 1792 | status = PowerDownQAM(state); |
| 1793 | if (status < 0) |
| 1794 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1795 | state->m_OperationMode = OM_NONE; |
| 1796 | break; |
| 1797 | default: |
| 1798 | status = -1; |
| 1799 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1800 | status = status; |
| 1801 | if (status < 0) |
| 1802 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1803 | |
| 1804 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1805 | Power up new standard |
| 1806 | */ |
| 1807 | switch (oMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1808 | case OM_DVBT: |
| 1809 | state->m_OperationMode = oMode; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1810 | status = SetDVBTStandard(state, oMode); |
| 1811 | if (status < 0) |
| 1812 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1813 | break; |
| 1814 | case OM_QAM_ITU_B: |
| 1815 | status = -1; |
| 1816 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1817 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1818 | case OM_QAM_ITU_C: |
| 1819 | state->m_OperationMode = oMode; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1820 | status = SetQAMStandard(state, oMode); |
| 1821 | if (status < 0) |
| 1822 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1823 | break; |
| 1824 | default: |
| 1825 | status = -1; |
| 1826 | } |
| 1827 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1828 | status = status; |
| 1829 | if (status < 0) |
| 1830 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1831 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | static int Start(struct drxk_state *state, s32 offsetFreq, |
| 1836 | s32 IntermediateFrequency) |
| 1837 | { |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1838 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1839 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1840 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1841 | do { |
| 1842 | u16 IFreqkHz; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1843 | s32 OffsetkHz = offsetFreq / 1000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1844 | |
| 1845 | if (state->m_DrxkState != DRXK_STOPPED && |
| 1846 | state->m_DrxkState != DRXK_DTV_STARTED) { |
| 1847 | status = -1; |
| 1848 | break; |
| 1849 | } |
| 1850 | state->m_bMirrorFreqSpect = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1851 | (state->param.inversion == INVERSION_ON); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1852 | |
| 1853 | if (IntermediateFrequency < 0) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1854 | state->m_bMirrorFreqSpect = |
| 1855 | !state->m_bMirrorFreqSpect; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1856 | IntermediateFrequency = -IntermediateFrequency; |
| 1857 | } |
| 1858 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1859 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1860 | case OM_QAM_ITU_A: |
| 1861 | case OM_QAM_ITU_C: |
| 1862 | IFreqkHz = (IntermediateFrequency / 1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1863 | status = SetQAM(state, IFreqkHz, OffsetkHz); |
| 1864 | if (status < 0) |
| 1865 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1866 | state->m_DrxkState = DRXK_DTV_STARTED; |
| 1867 | break; |
| 1868 | case OM_DVBT: |
| 1869 | IFreqkHz = (IntermediateFrequency / 1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1870 | status = MPEGTSStop(state); |
| 1871 | if (status < 0) |
| 1872 | break; |
| 1873 | status = SetDVBT(state, IFreqkHz, OffsetkHz); |
| 1874 | if (status < 0) |
| 1875 | break; |
| 1876 | status = DVBTStart(state); |
| 1877 | if (status < 0) |
| 1878 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1879 | state->m_DrxkState = DRXK_DTV_STARTED; |
| 1880 | break; |
| 1881 | default: |
| 1882 | break; |
| 1883 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1884 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1885 | return status; |
| 1886 | } |
| 1887 | |
| 1888 | static int ShutDown(struct drxk_state *state) |
| 1889 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1890 | dprintk(1, "\n"); |
| 1891 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1892 | MPEGTSStop(state); |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1896 | static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus, |
| 1897 | u32 Time) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1898 | { |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1899 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1900 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1901 | dprintk(1, "\n"); |
| 1902 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1903 | if (pLockStatus == NULL) |
| 1904 | return -1; |
| 1905 | |
| 1906 | *pLockStatus = NOT_LOCKED; |
| 1907 | |
| 1908 | /* define the SCU command code */ |
| 1909 | switch (state->m_OperationMode) { |
| 1910 | case OM_QAM_ITU_A: |
| 1911 | case OM_QAM_ITU_B: |
| 1912 | case OM_QAM_ITU_C: |
| 1913 | status = GetQAMLockStatus(state, pLockStatus); |
| 1914 | break; |
| 1915 | case OM_DVBT: |
| 1916 | status = GetDVBTLockStatus(state, pLockStatus); |
| 1917 | break; |
| 1918 | default: |
| 1919 | break; |
| 1920 | } |
| 1921 | return status; |
| 1922 | } |
| 1923 | |
| 1924 | static int MPEGTSStart(struct drxk_state *state) |
| 1925 | { |
| 1926 | int status = 0; |
| 1927 | |
| 1928 | u16 fecOcSncMode = 0; |
| 1929 | |
| 1930 | do { |
| 1931 | /* Allow OC to sync again */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1932 | status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1933 | if (status < 0) |
| 1934 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1935 | fecOcSncMode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1936 | status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1937 | if (status < 0) |
| 1938 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1939 | status = write16(state, FEC_OC_SNC_UNLOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1940 | if (status < 0) |
| 1941 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1942 | } while (0); |
| 1943 | return status; |
| 1944 | } |
| 1945 | |
| 1946 | static int MPEGTSDtoInit(struct drxk_state *state) |
| 1947 | { |
| 1948 | int status = -1; |
| 1949 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1950 | dprintk(1, "\n"); |
| 1951 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1952 | do { |
| 1953 | /* Rate integration settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1954 | status = write16(state, FEC_OC_RCN_CTL_STEP_LO__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1955 | if (status < 0) |
| 1956 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1957 | status = write16(state, FEC_OC_RCN_CTL_STEP_HI__A, 0x000C); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1958 | if (status < 0) |
| 1959 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1960 | status = write16(state, FEC_OC_RCN_GAIN__A, 0x000A); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1961 | if (status < 0) |
| 1962 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1963 | status = write16(state, FEC_OC_AVR_PARM_A__A, 0x0008); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1964 | if (status < 0) |
| 1965 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1966 | status = write16(state, FEC_OC_AVR_PARM_B__A, 0x0006); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1967 | if (status < 0) |
| 1968 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1969 | status = write16(state, FEC_OC_TMD_HI_MARGIN__A, 0x0680); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1970 | if (status < 0) |
| 1971 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1972 | status = write16(state, FEC_OC_TMD_LO_MARGIN__A, 0x0080); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1973 | if (status < 0) |
| 1974 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1975 | status = write16(state, FEC_OC_TMD_COUNT__A, 0x03F4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1976 | if (status < 0) |
| 1977 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1978 | |
| 1979 | /* Additional configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1980 | status = write16(state, FEC_OC_OCR_INVERT__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1981 | if (status < 0) |
| 1982 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1983 | status = write16(state, FEC_OC_SNC_LWM__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1984 | if (status < 0) |
| 1985 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1986 | status = write16(state, FEC_OC_SNC_HWM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1987 | if (status < 0) |
| 1988 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1989 | } while (0); |
| 1990 | return status; |
| 1991 | } |
| 1992 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1993 | static int MPEGTSDtoSetup(struct drxk_state *state, |
| 1994 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1995 | { |
| 1996 | int status = -1; |
| 1997 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1998 | u16 fecOcRegMode = 0; /* FEC_OC_MODE register value */ |
| 1999 | u16 fecOcRegIprMode = 0; /* FEC_OC_IPR_MODE register value */ |
| 2000 | u16 fecOcDtoMode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 2001 | u16 fecOcFctMode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 2002 | u16 fecOcDtoPeriod = 2; /* FEC_OC_IPR_INVERT register value */ |
| 2003 | u16 fecOcDtoBurstLen = 188; /* FEC_OC_IPR_INVERT register value */ |
| 2004 | u32 fecOcRcnCtlRate = 0; /* FEC_OC_IPR_INVERT register value */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2005 | u16 fecOcTmdMode = 0; |
| 2006 | u16 fecOcTmdIntUpdRate = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2007 | u32 maxBitRate = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2008 | bool staticCLK = false; |
| 2009 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2010 | dprintk(1, "\n"); |
| 2011 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2012 | do { |
| 2013 | /* Check insertion of the Reed-Solomon parity bytes */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2014 | status = read16(state, FEC_OC_MODE__A, &fecOcRegMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2015 | if (status < 0) |
| 2016 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2017 | status = read16(state, FEC_OC_IPR_MODE__A, &fecOcRegIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2018 | if (status < 0) |
| 2019 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2020 | fecOcRegMode &= (~FEC_OC_MODE_PARITY__M); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2021 | fecOcRegIprMode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); |
| 2022 | if (state->m_insertRSByte == true) { |
| 2023 | /* enable parity symbol forward */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2024 | fecOcRegMode |= FEC_OC_MODE_PARITY__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2025 | /* MVAL disable during parity bytes */ |
| 2026 | fecOcRegIprMode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M; |
| 2027 | /* TS burst length to 204 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2028 | fecOcDtoBurstLen = 204; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | /* Check serial or parrallel output */ |
| 2032 | fecOcRegIprMode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); |
| 2033 | if (state->m_enableParallel == false) { |
| 2034 | /* MPEG data output is serial -> set ipr_mode[0] */ |
| 2035 | fecOcRegIprMode |= FEC_OC_IPR_MODE_SERIAL__M; |
| 2036 | } |
| 2037 | |
| 2038 | switch (oMode) { |
| 2039 | case OM_DVBT: |
| 2040 | maxBitRate = state->m_DVBTBitrate; |
| 2041 | fecOcTmdMode = 3; |
| 2042 | fecOcRcnCtlRate = 0xC00000; |
| 2043 | staticCLK = state->m_DVBTStaticCLK; |
| 2044 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2045 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2046 | case OM_QAM_ITU_C: |
| 2047 | fecOcTmdMode = 0x0004; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2048 | fecOcRcnCtlRate = 0xD2B4EE; /* good for >63 Mb/s */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2049 | maxBitRate = state->m_DVBCBitrate; |
| 2050 | staticCLK = state->m_DVBCStaticCLK; |
| 2051 | break; |
| 2052 | default: |
| 2053 | status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2054 | } /* switch (standard) */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2055 | status = status; |
| 2056 | if (status < 0) |
| 2057 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2058 | |
| 2059 | /* Configure DTO's */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2060 | if (staticCLK) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2061 | u32 bitRate = 0; |
| 2062 | |
| 2063 | /* Rational DTO for MCLK source (static MCLK rate), |
| 2064 | Dynamic DTO for optimal grouping |
| 2065 | (avoid intra-packet gaps), |
| 2066 | DTO offset enable to sync TS burst with MSTRT */ |
| 2067 | fecOcDtoMode = (FEC_OC_DTO_MODE_DYNAMIC__M | |
| 2068 | FEC_OC_DTO_MODE_OFFSET_ENABLE__M); |
| 2069 | fecOcFctMode = (FEC_OC_FCT_MODE_RAT_ENA__M | |
| 2070 | FEC_OC_FCT_MODE_VIRT_ENA__M); |
| 2071 | |
| 2072 | /* Check user defined bitrate */ |
| 2073 | bitRate = maxBitRate; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2074 | if (bitRate > 75900000UL) { /* max is 75.9 Mb/s */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2075 | bitRate = 75900000UL; |
| 2076 | } |
| 2077 | /* Rational DTO period: |
| 2078 | dto_period = (Fsys / bitrate) - 2 |
| 2079 | |
| 2080 | Result should be floored, |
| 2081 | to make sure >= requested bitrate |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2082 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2083 | fecOcDtoPeriod = (u16) (((state->m_sysClockFreq) |
| 2084 | * 1000) / bitRate); |
| 2085 | if (fecOcDtoPeriod <= 2) |
| 2086 | fecOcDtoPeriod = 0; |
| 2087 | else |
| 2088 | fecOcDtoPeriod -= 2; |
| 2089 | fecOcTmdIntUpdRate = 8; |
| 2090 | } else { |
| 2091 | /* (commonAttr->staticCLK == false) => dynamic mode */ |
| 2092 | fecOcDtoMode = FEC_OC_DTO_MODE_DYNAMIC__M; |
| 2093 | fecOcFctMode = FEC_OC_FCT_MODE__PRE; |
| 2094 | fecOcTmdIntUpdRate = 5; |
| 2095 | } |
| 2096 | |
| 2097 | /* Write appropriate registers with requested configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2098 | status = write16(state, FEC_OC_DTO_BURST_LEN__A, fecOcDtoBurstLen); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2099 | if (status < 0) |
| 2100 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2101 | status = write16(state, FEC_OC_DTO_PERIOD__A, fecOcDtoPeriod); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2102 | if (status < 0) |
| 2103 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2104 | status = write16(state, FEC_OC_DTO_MODE__A, fecOcDtoMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2105 | if (status < 0) |
| 2106 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2107 | status = write16(state, FEC_OC_FCT_MODE__A, fecOcFctMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2108 | if (status < 0) |
| 2109 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2110 | status = write16(state, FEC_OC_MODE__A, fecOcRegMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2111 | if (status < 0) |
| 2112 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2113 | status = write16(state, FEC_OC_IPR_MODE__A, fecOcRegIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2114 | if (status < 0) |
| 2115 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2116 | |
| 2117 | /* Rate integration settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2118 | status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fecOcRcnCtlRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2119 | if (status < 0) |
| 2120 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2121 | status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, fecOcTmdIntUpdRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2122 | if (status < 0) |
| 2123 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2124 | status = write16(state, FEC_OC_TMD_MODE__A, fecOcTmdMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2125 | if (status < 0) |
| 2126 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2127 | } while (0); |
| 2128 | return status; |
| 2129 | } |
| 2130 | |
| 2131 | static int MPEGTSConfigurePolarity(struct drxk_state *state) |
| 2132 | { |
| 2133 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2134 | u16 fecOcRegIprInvert = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2135 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2136 | dprintk(1, "\n"); |
| 2137 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2138 | /* Data mask for the output data byte */ |
| 2139 | u16 InvertDataMask = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2140 | FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | |
| 2141 | FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M | |
| 2142 | FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | |
| 2143 | FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2144 | |
| 2145 | /* Control selective inversion of output bits */ |
| 2146 | fecOcRegIprInvert &= (~(InvertDataMask)); |
| 2147 | if (state->m_invertDATA == true) |
| 2148 | fecOcRegIprInvert |= InvertDataMask; |
| 2149 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MERR__M)); |
| 2150 | if (state->m_invertERR == true) |
| 2151 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MERR__M; |
| 2152 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MSTRT__M)); |
| 2153 | if (state->m_invertSTR == true) |
| 2154 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MSTRT__M; |
| 2155 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MVAL__M)); |
| 2156 | if (state->m_invertVAL == true) |
| 2157 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MVAL__M; |
| 2158 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); |
| 2159 | if (state->m_invertCLK == true) |
| 2160 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MCLK__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2161 | status = write16(state, FEC_OC_IPR_INVERT__A, fecOcRegIprInvert); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2162 | return status; |
| 2163 | } |
| 2164 | |
| 2165 | #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000 |
| 2166 | |
| 2167 | static int SetAgcRf(struct drxk_state *state, |
| 2168 | struct SCfgAgc *pAgcCfg, bool isDTV) |
| 2169 | { |
| 2170 | int status = 0; |
| 2171 | struct SCfgAgc *pIfAgcSettings; |
| 2172 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2173 | dprintk(1, "\n"); |
| 2174 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2175 | if (pAgcCfg == NULL) |
| 2176 | return -1; |
| 2177 | |
| 2178 | do { |
| 2179 | u16 data = 0; |
| 2180 | |
| 2181 | switch (pAgcCfg->ctrlMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2182 | case DRXK_AGC_CTRL_AUTO: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2183 | |
| 2184 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2185 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2186 | if (status < 0) |
| 2187 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2188 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2189 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2190 | if (status < 0) |
| 2191 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2192 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2193 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2194 | if (status < 0) |
| 2195 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2196 | |
| 2197 | /* Enable SCU RF AGC loop */ |
| 2198 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
| 2199 | |
| 2200 | /* Polarity */ |
| 2201 | if (state->m_RfAgcPol) |
| 2202 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2203 | else |
| 2204 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2205 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2206 | if (status < 0) |
| 2207 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2208 | |
| 2209 | /* Set speed (using complementary reduction value) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2210 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2211 | if (status < 0) |
| 2212 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2213 | |
| 2214 | data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; |
| 2215 | data |= (~(pAgcCfg->speed << |
| 2216 | SCU_RAM_AGC_KI_RED_RAGC_RED__B) |
| 2217 | & SCU_RAM_AGC_KI_RED_RAGC_RED__M); |
| 2218 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2219 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2220 | if (status < 0) |
| 2221 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2222 | |
| 2223 | if (IsDVBT(state)) |
| 2224 | pIfAgcSettings = &state->m_dvbtIfAgcCfg; |
| 2225 | else if (IsQAM(state)) |
| 2226 | pIfAgcSettings = &state->m_qamIfAgcCfg; |
| 2227 | else |
| 2228 | pIfAgcSettings = &state->m_atvIfAgcCfg; |
| 2229 | if (pIfAgcSettings == NULL) |
| 2230 | return -1; |
| 2231 | |
| 2232 | /* Set TOP, only if IF-AGC is in AUTO mode */ |
| 2233 | if (pIfAgcSettings->ctrlMode == DRXK_AGC_CTRL_AUTO) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2234 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->top); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2235 | if (status < 0) |
| 2236 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2237 | |
| 2238 | /* Cut-Off current */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2239 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, pAgcCfg->cutOffCurrent); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2240 | if (status < 0) |
| 2241 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2242 | |
| 2243 | /* Max. output level */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2244 | status = write16(state, SCU_RAM_AGC_RF_MAX__A, pAgcCfg->maxOutputLevel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2245 | if (status < 0) |
| 2246 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2247 | |
| 2248 | break; |
| 2249 | |
| 2250 | case DRXK_AGC_CTRL_USER: |
| 2251 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2252 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2253 | if (status < 0) |
| 2254 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2255 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2256 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2257 | if (status < 0) |
| 2258 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2259 | |
| 2260 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2261 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2262 | if (status < 0) |
| 2263 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2264 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
| 2265 | if (state->m_RfAgcPol) |
| 2266 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2267 | else |
| 2268 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2269 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2270 | if (status < 0) |
| 2271 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2272 | |
| 2273 | /* SCU c.o.c. to 0, enabling full control range */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2274 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2275 | if (status < 0) |
| 2276 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2277 | |
| 2278 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2279 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, pAgcCfg->outputLevel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2280 | if (status < 0) |
| 2281 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2282 | break; |
| 2283 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2284 | case DRXK_AGC_CTRL_OFF: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2285 | /* Disable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2286 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2287 | if (status < 0) |
| 2288 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2289 | data |= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2290 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2291 | if (status < 0) |
| 2292 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2293 | |
| 2294 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2295 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2296 | if (status < 0) |
| 2297 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2298 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2299 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2300 | if (status < 0) |
| 2301 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2302 | break; |
| 2303 | |
| 2304 | default: |
| 2305 | return -1; |
| 2306 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2307 | } /* switch (agcsettings->ctrlMode) */ |
| 2308 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2309 | return status; |
| 2310 | } |
| 2311 | |
| 2312 | #define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000 |
| 2313 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2314 | static int SetAgcIf(struct drxk_state *state, |
| 2315 | struct SCfgAgc *pAgcCfg, bool isDTV) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2316 | { |
| 2317 | u16 data = 0; |
| 2318 | int status = 0; |
| 2319 | struct SCfgAgc *pRfAgcSettings; |
| 2320 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2321 | dprintk(1, "\n"); |
| 2322 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2323 | do { |
| 2324 | switch (pAgcCfg->ctrlMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2325 | case DRXK_AGC_CTRL_AUTO: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2326 | |
| 2327 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2328 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2329 | if (status < 0) |
| 2330 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2331 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2332 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2333 | if (status < 0) |
| 2334 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2335 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2336 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2337 | if (status < 0) |
| 2338 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2339 | |
| 2340 | /* Enable SCU IF AGC loop */ |
| 2341 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2342 | |
| 2343 | /* Polarity */ |
| 2344 | if (state->m_IfAgcPol) |
| 2345 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2346 | else |
| 2347 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2348 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2349 | if (status < 0) |
| 2350 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2351 | |
| 2352 | /* Set speed (using complementary reduction value) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2353 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2354 | if (status < 0) |
| 2355 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2356 | data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; |
| 2357 | data |= (~(pAgcCfg->speed << |
| 2358 | SCU_RAM_AGC_KI_RED_IAGC_RED__B) |
| 2359 | & SCU_RAM_AGC_KI_RED_IAGC_RED__M); |
| 2360 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2361 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2362 | if (status < 0) |
| 2363 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2364 | |
| 2365 | if (IsQAM(state)) |
| 2366 | pRfAgcSettings = &state->m_qamRfAgcCfg; |
| 2367 | else |
| 2368 | pRfAgcSettings = &state->m_atvRfAgcCfg; |
| 2369 | if (pRfAgcSettings == NULL) |
| 2370 | return -1; |
| 2371 | /* Restore TOP */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2372 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pRfAgcSettings->top); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2373 | if (status < 0) |
| 2374 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2375 | break; |
| 2376 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2377 | case DRXK_AGC_CTRL_USER: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2378 | |
| 2379 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2380 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2381 | if (status < 0) |
| 2382 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2383 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2384 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2385 | if (status < 0) |
| 2386 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2387 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2388 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2389 | if (status < 0) |
| 2390 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2391 | |
| 2392 | /* Disable SCU IF AGC loop */ |
| 2393 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2394 | |
| 2395 | /* Polarity */ |
| 2396 | if (state->m_IfAgcPol) |
| 2397 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2398 | else |
| 2399 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2400 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2401 | if (status < 0) |
| 2402 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2403 | |
| 2404 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2405 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->outputLevel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2406 | if (status < 0) |
| 2407 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2408 | break; |
| 2409 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2410 | case DRXK_AGC_CTRL_OFF: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2411 | |
| 2412 | /* Disable If AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2413 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2414 | if (status < 0) |
| 2415 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2416 | data |= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2417 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2418 | if (status < 0) |
| 2419 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2420 | |
| 2421 | /* Disable SCU IF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2422 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2423 | if (status < 0) |
| 2424 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2425 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2426 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2427 | if (status < 0) |
| 2428 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2429 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2430 | } /* switch (agcSettingsIf->ctrlMode) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2431 | |
| 2432 | /* always set the top to support |
| 2433 | configurations without if-loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2434 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, pAgcCfg->top); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2435 | if (status < 0) |
| 2436 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2437 | |
| 2438 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2439 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2440 | return status; |
| 2441 | } |
| 2442 | |
| 2443 | static int ReadIFAgc(struct drxk_state *state, u32 *pValue) |
| 2444 | { |
| 2445 | u16 agcDacLvl; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2446 | int status = read16(state, IQM_AF_AGC_IF__A, &agcDacLvl); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2447 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2448 | dprintk(1, "\n"); |
| 2449 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2450 | *pValue = 0; |
| 2451 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2452 | if (status == 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2453 | u16 Level = 0; |
| 2454 | if (agcDacLvl > DRXK_AGC_DAC_OFFSET) |
| 2455 | Level = agcDacLvl - DRXK_AGC_DAC_OFFSET; |
| 2456 | if (Level < 14000) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2457 | *pValue = (14000 - Level) / 4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2458 | else |
| 2459 | *pValue = 0; |
| 2460 | } |
| 2461 | return status; |
| 2462 | } |
| 2463 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2464 | static int GetQAMSignalToNoise(struct drxk_state *state, |
| 2465 | s32 *pSignalToNoise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2466 | { |
| 2467 | int status = 0; |
| 2468 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2469 | dprintk(1, "\n"); |
| 2470 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2471 | do { |
| 2472 | /* MER calculation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2473 | u16 qamSlErrPower = 0; /* accum. error between |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2474 | raw and sliced symbols */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2475 | u32 qamSlSigPower = 0; /* used for MER, depends of |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2476 | QAM constellation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2477 | u32 qamSlMer = 0; /* QAM MER */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2478 | |
| 2479 | /* get the register value needed for MER */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2480 | status = read16(state, QAM_SL_ERR_POWER__A, &qamSlErrPower); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2481 | if (status < 0) |
| 2482 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2483 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2484 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2485 | case QAM_16: |
| 2486 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM16 << 2; |
| 2487 | break; |
| 2488 | case QAM_32: |
| 2489 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM32 << 2; |
| 2490 | break; |
| 2491 | case QAM_64: |
| 2492 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM64 << 2; |
| 2493 | break; |
| 2494 | case QAM_128: |
| 2495 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM128 << 2; |
| 2496 | break; |
| 2497 | default: |
| 2498 | case QAM_256: |
| 2499 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM256 << 2; |
| 2500 | break; |
| 2501 | } |
| 2502 | |
| 2503 | if (qamSlErrPower > 0) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2504 | qamSlMer = Log10Times100(qamSlSigPower) - |
| 2505 | Log10Times100((u32) qamSlErrPower); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2506 | } |
| 2507 | *pSignalToNoise = qamSlMer; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2508 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2509 | return status; |
| 2510 | } |
| 2511 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2512 | static int GetDVBTSignalToNoise(struct drxk_state *state, |
| 2513 | s32 *pSignalToNoise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2514 | { |
| 2515 | int status = 0; |
| 2516 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2517 | u16 regData = 0; |
| 2518 | u32 EqRegTdSqrErrI = 0; |
| 2519 | u32 EqRegTdSqrErrQ = 0; |
| 2520 | u16 EqRegTdSqrErrExp = 0; |
| 2521 | u16 EqRegTdTpsPwrOfs = 0; |
| 2522 | u16 EqRegTdReqSmbCnt = 0; |
| 2523 | u32 tpsCnt = 0; |
| 2524 | u32 SqrErrIQ = 0; |
| 2525 | u32 a = 0; |
| 2526 | u32 b = 0; |
| 2527 | u32 c = 0; |
| 2528 | u32 iMER = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2529 | u16 transmissionParams = 0; |
| 2530 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2531 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2532 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2533 | status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A, &EqRegTdTpsPwrOfs); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2534 | if (status < 0) |
| 2535 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2536 | status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A, &EqRegTdReqSmbCnt); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2537 | if (status < 0) |
| 2538 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2539 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A, &EqRegTdSqrErrExp); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2540 | if (status < 0) |
| 2541 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2542 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A, ®Data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2543 | if (status < 0) |
| 2544 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2545 | /* Extend SQR_ERR_I operational range */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2546 | EqRegTdSqrErrI = (u32) regData; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2547 | if ((EqRegTdSqrErrExp > 11) && |
| 2548 | (EqRegTdSqrErrI < 0x00000FFFUL)) { |
| 2549 | EqRegTdSqrErrI += 0x00010000UL; |
| 2550 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2551 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, ®Data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2552 | if (status < 0) |
| 2553 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2554 | /* Extend SQR_ERR_Q operational range */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2555 | EqRegTdSqrErrQ = (u32) regData; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2556 | if ((EqRegTdSqrErrExp > 11) && |
| 2557 | (EqRegTdSqrErrQ < 0x00000FFFUL)) |
| 2558 | EqRegTdSqrErrQ += 0x00010000UL; |
| 2559 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2560 | status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, &transmissionParams); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2561 | if (status < 0) |
| 2562 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2563 | |
| 2564 | /* Check input data for MER */ |
| 2565 | |
| 2566 | /* MER calculation (in 0.1 dB) without math.h */ |
| 2567 | if ((EqRegTdTpsPwrOfs == 0) || (EqRegTdReqSmbCnt == 0)) |
| 2568 | iMER = 0; |
| 2569 | else if ((EqRegTdSqrErrI + EqRegTdSqrErrQ) == 0) { |
| 2570 | /* No error at all, this must be the HW reset value |
| 2571 | * Apparently no first measurement yet |
| 2572 | * Set MER to 0.0 */ |
| 2573 | iMER = 0; |
| 2574 | } else { |
| 2575 | SqrErrIQ = (EqRegTdSqrErrI + EqRegTdSqrErrQ) << |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2576 | EqRegTdSqrErrExp; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2577 | if ((transmissionParams & |
| 2578 | OFDM_SC_RA_RAM_OP_PARAM_MODE__M) |
| 2579 | == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K) |
| 2580 | tpsCnt = 17; |
| 2581 | else |
| 2582 | tpsCnt = 68; |
| 2583 | |
| 2584 | /* IMER = 100 * log10 (x) |
| 2585 | where x = (EqRegTdTpsPwrOfs^2 * |
| 2586 | EqRegTdReqSmbCnt * tpsCnt)/SqrErrIQ |
| 2587 | |
| 2588 | => IMER = a + b -c |
| 2589 | where a = 100 * log10 (EqRegTdTpsPwrOfs^2) |
| 2590 | b = 100 * log10 (EqRegTdReqSmbCnt * tpsCnt) |
| 2591 | c = 100 * log10 (SqrErrIQ) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2592 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2593 | |
| 2594 | /* log(x) x = 9bits * 9bits->18 bits */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2595 | a = Log10Times100(EqRegTdTpsPwrOfs * |
| 2596 | EqRegTdTpsPwrOfs); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2597 | /* log(x) x = 16bits * 7bits->23 bits */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2598 | b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2599 | /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ |
| 2600 | c = Log10Times100(SqrErrIQ); |
| 2601 | |
| 2602 | iMER = a + b; |
| 2603 | /* No negative MER, clip to zero */ |
| 2604 | if (iMER > c) |
| 2605 | iMER -= c; |
| 2606 | else |
| 2607 | iMER = 0; |
| 2608 | } |
| 2609 | *pSignalToNoise = iMER; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2610 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2611 | |
| 2612 | return status; |
| 2613 | } |
| 2614 | |
| 2615 | static int GetSignalToNoise(struct drxk_state *state, s32 *pSignalToNoise) |
| 2616 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2617 | dprintk(1, "\n"); |
| 2618 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2619 | *pSignalToNoise = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2620 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2621 | case OM_DVBT: |
| 2622 | return GetDVBTSignalToNoise(state, pSignalToNoise); |
| 2623 | case OM_QAM_ITU_A: |
| 2624 | case OM_QAM_ITU_C: |
| 2625 | return GetQAMSignalToNoise(state, pSignalToNoise); |
| 2626 | default: |
| 2627 | break; |
| 2628 | } |
| 2629 | return 0; |
| 2630 | } |
| 2631 | |
| 2632 | #if 0 |
| 2633 | static int GetDVBTQuality(struct drxk_state *state, s32 *pQuality) |
| 2634 | { |
| 2635 | /* SNR Values for quasi errorfree reception rom Nordig 2.2 */ |
| 2636 | int status = 0; |
| 2637 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2638 | dprintk(1, "\n"); |
| 2639 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2640 | static s32 QE_SN[] = { |
| 2641 | 51, /* QPSK 1/2 */ |
| 2642 | 69, /* QPSK 2/3 */ |
| 2643 | 79, /* QPSK 3/4 */ |
| 2644 | 89, /* QPSK 5/6 */ |
| 2645 | 97, /* QPSK 7/8 */ |
| 2646 | 108, /* 16-QAM 1/2 */ |
| 2647 | 131, /* 16-QAM 2/3 */ |
| 2648 | 146, /* 16-QAM 3/4 */ |
| 2649 | 156, /* 16-QAM 5/6 */ |
| 2650 | 160, /* 16-QAM 7/8 */ |
| 2651 | 165, /* 64-QAM 1/2 */ |
| 2652 | 187, /* 64-QAM 2/3 */ |
| 2653 | 202, /* 64-QAM 3/4 */ |
| 2654 | 216, /* 64-QAM 5/6 */ |
| 2655 | 225, /* 64-QAM 7/8 */ |
| 2656 | }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2657 | |
| 2658 | *pQuality = 0; |
| 2659 | |
| 2660 | do { |
| 2661 | s32 SignalToNoise = 0; |
| 2662 | u16 Constellation = 0; |
| 2663 | u16 CodeRate = 0; |
| 2664 | u32 SignalToNoiseRel; |
| 2665 | u32 BERQuality; |
| 2666 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2667 | status = GetDVBTSignalToNoise(state, &SignalToNoise); |
| 2668 | if (status < 0) |
| 2669 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2670 | status = read16(state, OFDM_EQ_TOP_TD_TPS_CONST__A, &Constellation); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2671 | if (status < 0) |
| 2672 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2673 | Constellation &= OFDM_EQ_TOP_TD_TPS_CONST__M; |
| 2674 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2675 | status = read16(state, OFDM_EQ_TOP_TD_TPS_CODE_HP__A, &CodeRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2676 | if (status < 0) |
| 2677 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2678 | CodeRate &= OFDM_EQ_TOP_TD_TPS_CODE_HP__M; |
| 2679 | |
| 2680 | if (Constellation > OFDM_EQ_TOP_TD_TPS_CONST_64QAM || |
| 2681 | CodeRate > OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8) |
| 2682 | break; |
| 2683 | SignalToNoiseRel = SignalToNoise - |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2684 | QE_SN[Constellation * 5 + CodeRate]; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2685 | BERQuality = 100; |
| 2686 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2687 | if (SignalToNoiseRel < -70) |
| 2688 | *pQuality = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2689 | else if (SignalToNoiseRel < 30) |
| 2690 | *pQuality = ((SignalToNoiseRel + 70) * |
| 2691 | BERQuality) / 100; |
| 2692 | else |
| 2693 | *pQuality = BERQuality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2694 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2695 | return 0; |
| 2696 | }; |
| 2697 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2698 | static int GetDVBCQuality(struct drxk_state *state, s32 *pQuality) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2699 | { |
| 2700 | int status = 0; |
| 2701 | *pQuality = 0; |
| 2702 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2703 | dprintk(1, "\n"); |
| 2704 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2705 | do { |
| 2706 | u32 SignalToNoise = 0; |
| 2707 | u32 BERQuality = 100; |
| 2708 | u32 SignalToNoiseRel = 0; |
| 2709 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2710 | status = GetQAMSignalToNoise(state, &SignalToNoise); |
| 2711 | if (status < 0) |
| 2712 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2713 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2714 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2715 | case QAM_16: |
| 2716 | SignalToNoiseRel = SignalToNoise - 200; |
| 2717 | break; |
| 2718 | case QAM_32: |
| 2719 | SignalToNoiseRel = SignalToNoise - 230; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2720 | break; /* Not in NorDig */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2721 | case QAM_64: |
| 2722 | SignalToNoiseRel = SignalToNoise - 260; |
| 2723 | break; |
| 2724 | case QAM_128: |
| 2725 | SignalToNoiseRel = SignalToNoise - 290; |
| 2726 | break; |
| 2727 | default: |
| 2728 | case QAM_256: |
| 2729 | SignalToNoiseRel = SignalToNoise - 320; |
| 2730 | break; |
| 2731 | } |
| 2732 | |
| 2733 | if (SignalToNoiseRel < -70) |
| 2734 | *pQuality = 0; |
| 2735 | else if (SignalToNoiseRel < 30) |
| 2736 | *pQuality = ((SignalToNoiseRel + 70) * |
| 2737 | BERQuality) / 100; |
| 2738 | else |
| 2739 | *pQuality = BERQuality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2740 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2741 | |
| 2742 | return status; |
| 2743 | } |
| 2744 | |
| 2745 | static int GetQuality(struct drxk_state *state, s32 *pQuality) |
| 2746 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2747 | dprintk(1, "\n"); |
| 2748 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2749 | switch (state->m_OperationMode) { |
| 2750 | case OM_DVBT: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2751 | return GetDVBTQuality(state, pQuality); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2752 | case OM_QAM_ITU_A: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2753 | return GetDVBCQuality(state, pQuality); |
| 2754 | default: |
| 2755 | break; |
| 2756 | } |
| 2757 | |
| 2758 | return 0; |
| 2759 | } |
| 2760 | #endif |
| 2761 | |
| 2762 | /* Free data ram in SIO HI */ |
| 2763 | #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040 |
| 2764 | #define SIO_HI_RA_RAM_USR_END__A 0x420060 |
| 2765 | |
| 2766 | #define DRXK_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A) |
| 2767 | #define DRXK_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7) |
| 2768 | #define DRXK_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ |
| 2769 | #define DRXK_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE |
| 2770 | |
| 2771 | #define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr) >> 22) & 0x3F) |
| 2772 | #define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F) |
| 2773 | #define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF) |
| 2774 | |
| 2775 | static int ConfigureI2CBridge(struct drxk_state *state, bool bEnableBridge) |
| 2776 | { |
| 2777 | int status; |
| 2778 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2779 | dprintk(1, "\n"); |
| 2780 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2781 | if (state->m_DrxkState == DRXK_UNINITIALIZED) |
| 2782 | return -1; |
| 2783 | if (state->m_DrxkState == DRXK_POWERED_DOWN) |
| 2784 | return -1; |
| 2785 | |
| 2786 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2787 | status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2788 | if (status < 0) |
| 2789 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2790 | if (bEnableBridge) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2791 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2792 | if (status < 0) |
| 2793 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2794 | } else { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2795 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2796 | if (status < 0) |
| 2797 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2798 | } |
| 2799 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2800 | status = HI_Command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0); |
| 2801 | if (status < 0) |
| 2802 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2803 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2804 | return status; |
| 2805 | } |
| 2806 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2807 | static int SetPreSaw(struct drxk_state *state, |
| 2808 | struct SCfgPreSaw *pPreSawCfg) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2809 | { |
| 2810 | int status; |
| 2811 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2812 | dprintk(1, "\n"); |
| 2813 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2814 | if ((pPreSawCfg == NULL) |
| 2815 | || (pPreSawCfg->reference > IQM_AF_PDREF__M)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2816 | return -1; |
| 2817 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2818 | status = write16(state, IQM_AF_PDREF__A, pPreSawCfg->reference); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2819 | return status; |
| 2820 | } |
| 2821 | |
| 2822 | static int BLDirectCmd(struct drxk_state *state, u32 targetAddr, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2823 | u16 romOffset, u16 nrOfElements, u32 timeOut) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2824 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2825 | u16 blStatus = 0; |
| 2826 | u16 offset = (u16) ((targetAddr >> 0) & 0x00FFFF); |
| 2827 | u16 blockbank = (u16) ((targetAddr >> 16) & 0x000FFF); |
| 2828 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2829 | unsigned long end; |
| 2830 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2831 | dprintk(1, "\n"); |
| 2832 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2833 | mutex_lock(&state->mutex); |
| 2834 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2835 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_DIRECT); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2836 | if (status < 0) |
| 2837 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2838 | status = write16(state, SIO_BL_TGT_HDR__A, blockbank); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2839 | if (status < 0) |
| 2840 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2841 | status = write16(state, SIO_BL_TGT_ADDR__A, offset); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2842 | if (status < 0) |
| 2843 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2844 | status = write16(state, SIO_BL_SRC_ADDR__A, romOffset); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2845 | if (status < 0) |
| 2846 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2847 | status = write16(state, SIO_BL_SRC_LEN__A, nrOfElements); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2848 | if (status < 0) |
| 2849 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2850 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2851 | if (status < 0) |
| 2852 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2853 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2854 | end = jiffies + msecs_to_jiffies(timeOut); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2855 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2856 | status = read16(state, SIO_BL_STATUS__A, &blStatus); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2857 | if (status < 0) |
| 2858 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2859 | } while ((blStatus == 0x1) && time_is_after_jiffies(end)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2860 | if (blStatus == 0x1) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 2861 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2862 | mutex_unlock(&state->mutex); |
| 2863 | return -1; |
| 2864 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2865 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2866 | mutex_unlock(&state->mutex); |
| 2867 | return status; |
| 2868 | |
| 2869 | } |
| 2870 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2871 | static int ADCSyncMeasurement(struct drxk_state *state, u16 *count) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2872 | { |
| 2873 | u16 data = 0; |
| 2874 | int status; |
| 2875 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2876 | dprintk(1, "\n"); |
| 2877 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2878 | do { |
| 2879 | /* Start measurement */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2880 | status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2881 | if (status < 0) |
| 2882 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2883 | status = write16(state, IQM_AF_START_LOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2884 | if (status < 0) |
| 2885 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2886 | |
| 2887 | *count = 0; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2888 | status = read16(state, IQM_AF_PHASE0__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2889 | if (status < 0) |
| 2890 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2891 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2892 | *count = *count + 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2893 | status = read16(state, IQM_AF_PHASE1__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2894 | if (status < 0) |
| 2895 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2896 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2897 | *count = *count + 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2898 | status = read16(state, IQM_AF_PHASE2__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2899 | if (status < 0) |
| 2900 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2901 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2902 | *count = *count + 1; |
| 2903 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2904 | return status; |
| 2905 | } |
| 2906 | |
| 2907 | static int ADCSynchronization(struct drxk_state *state) |
| 2908 | { |
| 2909 | u16 count = 0; |
| 2910 | int status; |
| 2911 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2912 | dprintk(1, "\n"); |
| 2913 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2914 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2915 | status = ADCSyncMeasurement(state, &count); |
| 2916 | if (status < 0) |
| 2917 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2918 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2919 | if (count == 1) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2920 | /* Try sampling on a diffrent edge */ |
| 2921 | u16 clkNeg = 0; |
| 2922 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2923 | status = read16(state, IQM_AF_CLKNEG__A, &clkNeg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2924 | if (status < 0) |
| 2925 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2926 | if ((clkNeg | IQM_AF_CLKNEG_CLKNEGDATA__M) == |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2927 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) { |
| 2928 | clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2929 | clkNeg |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2930 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2931 | } else { |
| 2932 | clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2933 | clkNeg |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2934 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2935 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2936 | status = write16(state, IQM_AF_CLKNEG__A, clkNeg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2937 | if (status < 0) |
| 2938 | break; |
| 2939 | status = ADCSyncMeasurement(state, &count); |
| 2940 | if (status < 0) |
| 2941 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | if (count < 2) |
| 2945 | status = -1; |
| 2946 | } while (0); |
| 2947 | return status; |
| 2948 | } |
| 2949 | |
| 2950 | static int SetFrequencyShifter(struct drxk_state *state, |
| 2951 | u16 intermediateFreqkHz, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2952 | s32 tunerFreqOffset, bool isDTV) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2953 | { |
| 2954 | bool selectPosImage = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2955 | u32 rfFreqResidual = tunerFreqOffset; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2956 | u32 fmFrequencyShift = 0; |
| 2957 | bool tunerMirror = !state->m_bMirrorFreqSpect; |
| 2958 | u32 adcFreq; |
| 2959 | bool adcFlip; |
| 2960 | int status; |
| 2961 | u32 ifFreqActual; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2962 | u32 samplingFrequency = (u32) (state->m_sysClockFreq / 3); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2963 | u32 frequencyShift; |
| 2964 | bool imageToSelect; |
| 2965 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2966 | dprintk(1, "\n"); |
| 2967 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2968 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2969 | Program frequency shifter |
| 2970 | No need to account for mirroring on RF |
| 2971 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2972 | if (isDTV) { |
| 2973 | if ((state->m_OperationMode == OM_QAM_ITU_A) || |
| 2974 | (state->m_OperationMode == OM_QAM_ITU_C) || |
| 2975 | (state->m_OperationMode == OM_DVBT)) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2976 | selectPosImage = true; |
| 2977 | else |
| 2978 | selectPosImage = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2979 | } |
| 2980 | if (tunerMirror) |
| 2981 | /* tuner doesn't mirror */ |
| 2982 | ifFreqActual = intermediateFreqkHz + |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2983 | rfFreqResidual + fmFrequencyShift; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2984 | else |
| 2985 | /* tuner mirrors */ |
| 2986 | ifFreqActual = intermediateFreqkHz - |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2987 | rfFreqResidual - fmFrequencyShift; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2988 | if (ifFreqActual > samplingFrequency / 2) { |
| 2989 | /* adc mirrors */ |
| 2990 | adcFreq = samplingFrequency - ifFreqActual; |
| 2991 | adcFlip = true; |
| 2992 | } else { |
| 2993 | /* adc doesn't mirror */ |
| 2994 | adcFreq = ifFreqActual; |
| 2995 | adcFlip = false; |
| 2996 | } |
| 2997 | |
| 2998 | frequencyShift = adcFreq; |
| 2999 | imageToSelect = state->m_rfmirror ^ tunerMirror ^ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3000 | adcFlip ^ selectPosImage; |
| 3001 | state->m_IqmFsRateOfs = |
| 3002 | Frac28a((frequencyShift), samplingFrequency); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3003 | |
| 3004 | if (imageToSelect) |
| 3005 | state->m_IqmFsRateOfs = ~state->m_IqmFsRateOfs + 1; |
| 3006 | |
| 3007 | /* Program frequency shifter with tuner offset compensation */ |
| 3008 | /* frequencyShift += tunerFreqOffset; TODO */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3009 | status = write32(state, IQM_FS_RATE_OFS_LO__A, |
| 3010 | state->m_IqmFsRateOfs); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3011 | return status; |
| 3012 | } |
| 3013 | |
| 3014 | static int InitAGC(struct drxk_state *state, bool isDTV) |
| 3015 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3016 | u16 ingainTgt = 0; |
| 3017 | u16 ingainTgtMin = 0; |
| 3018 | u16 ingainTgtMax = 0; |
| 3019 | u16 clpCyclen = 0; |
| 3020 | u16 clpSumMin = 0; |
| 3021 | u16 clpDirTo = 0; |
| 3022 | u16 snsSumMin = 0; |
| 3023 | u16 snsSumMax = 0; |
| 3024 | u16 clpSumMax = 0; |
| 3025 | u16 snsDirTo = 0; |
| 3026 | u16 kiInnergainMin = 0; |
| 3027 | u16 ifIaccuHiTgt = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3028 | u16 ifIaccuHiTgtMin = 0; |
| 3029 | u16 ifIaccuHiTgtMax = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3030 | u16 data = 0; |
| 3031 | u16 fastClpCtrlDelay = 0; |
| 3032 | u16 clpCtrlMode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3033 | int status = 0; |
| 3034 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3035 | dprintk(1, "\n"); |
| 3036 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3037 | do { |
| 3038 | /* Common settings */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3039 | snsSumMax = 1023; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3040 | ifIaccuHiTgtMin = 2047; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3041 | clpCyclen = 500; |
| 3042 | clpSumMax = 1023; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3043 | |
| 3044 | if (IsQAM(state)) { |
| 3045 | /* Standard specific settings */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3046 | clpSumMin = 8; |
| 3047 | clpDirTo = (u16) -9; |
| 3048 | clpCtrlMode = 0; |
| 3049 | snsSumMin = 8; |
| 3050 | snsDirTo = (u16) -9; |
| 3051 | kiInnergainMin = (u16) -1030; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3052 | } else |
| 3053 | status = -1; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3054 | status = (status); |
| 3055 | if (status < 0) |
| 3056 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3057 | if (IsQAM(state)) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3058 | ifIaccuHiTgtMax = 0x2380; |
| 3059 | ifIaccuHiTgt = 0x2380; |
| 3060 | ingainTgtMin = 0x0511; |
| 3061 | ingainTgt = 0x0511; |
| 3062 | ingainTgtMax = 5119; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3063 | fastClpCtrlDelay = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3064 | state->m_qamIfAgcCfg.FastClipCtrlDelay; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3065 | } else { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3066 | ifIaccuHiTgtMax = 0x1200; |
| 3067 | ifIaccuHiTgt = 0x1200; |
| 3068 | ingainTgtMin = 13424; |
| 3069 | ingainTgt = 13424; |
| 3070 | ingainTgtMax = 30000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3071 | fastClpCtrlDelay = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3072 | state->m_dvbtIfAgcCfg.FastClipCtrlDelay; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3073 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3074 | status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, fastClpCtrlDelay); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3075 | if (status < 0) |
| 3076 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3077 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3078 | status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clpCtrlMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3079 | if (status < 0) |
| 3080 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3081 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingainTgt); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3082 | if (status < 0) |
| 3083 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3084 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingainTgtMin); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3085 | if (status < 0) |
| 3086 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3087 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingainTgtMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3088 | if (status < 0) |
| 3089 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3090 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, ifIaccuHiTgtMin); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3091 | if (status < 0) |
| 3092 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3093 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, ifIaccuHiTgtMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3094 | if (status < 0) |
| 3095 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3096 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3097 | if (status < 0) |
| 3098 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3099 | status = write16(state, SCU_RAM_AGC_IF_IACCU_LO__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3100 | if (status < 0) |
| 3101 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3102 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3103 | if (status < 0) |
| 3104 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3105 | status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3106 | if (status < 0) |
| 3107 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3108 | status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clpSumMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3109 | if (status < 0) |
| 3110 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3111 | status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, snsSumMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3112 | if (status < 0) |
| 3113 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3114 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3115 | status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, kiInnergainMin); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3116 | if (status < 0) |
| 3117 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3118 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, ifIaccuHiTgt); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3119 | if (status < 0) |
| 3120 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3121 | status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clpCyclen); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3122 | if (status < 0) |
| 3123 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3124 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3125 | status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MAX__A, 1023); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3126 | if (status < 0) |
| 3127 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3128 | status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MIN__A, (u16) -1023); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3129 | if (status < 0) |
| 3130 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3131 | status = write16(state, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3132 | if (status < 0) |
| 3133 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3134 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3135 | status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3136 | if (status < 0) |
| 3137 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3138 | status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clpSumMin); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3139 | if (status < 0) |
| 3140 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3141 | status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, snsSumMin); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3142 | if (status < 0) |
| 3143 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3144 | status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clpDirTo); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3145 | if (status < 0) |
| 3146 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3147 | status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, snsDirTo); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3148 | if (status < 0) |
| 3149 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3150 | status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3151 | if (status < 0) |
| 3152 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3153 | status = write16(state, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3154 | if (status < 0) |
| 3155 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3156 | status = write16(state, SCU_RAM_AGC_KI_MIN__A, 0x0117); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3157 | if (status < 0) |
| 3158 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3159 | status = write16(state, SCU_RAM_AGC_KI_MAX__A, 0x0657); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3160 | if (status < 0) |
| 3161 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3162 | status = write16(state, SCU_RAM_AGC_CLP_SUM__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3163 | if (status < 0) |
| 3164 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3165 | status = write16(state, SCU_RAM_AGC_CLP_CYCCNT__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3166 | if (status < 0) |
| 3167 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3168 | status = write16(state, SCU_RAM_AGC_CLP_DIR_WD__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3169 | if (status < 0) |
| 3170 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3171 | status = write16(state, SCU_RAM_AGC_CLP_DIR_STP__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3172 | if (status < 0) |
| 3173 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3174 | status = write16(state, SCU_RAM_AGC_SNS_SUM__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3175 | if (status < 0) |
| 3176 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3177 | status = write16(state, SCU_RAM_AGC_SNS_CYCCNT__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3178 | if (status < 0) |
| 3179 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3180 | status = write16(state, SCU_RAM_AGC_SNS_DIR_WD__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3181 | if (status < 0) |
| 3182 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3183 | status = write16(state, SCU_RAM_AGC_SNS_DIR_STP__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3184 | if (status < 0) |
| 3185 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3186 | status = write16(state, SCU_RAM_AGC_SNS_CYCLEN__A, 500); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3187 | if (status < 0) |
| 3188 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3189 | status = write16(state, SCU_RAM_AGC_KI_CYCLEN__A, 500); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3190 | if (status < 0) |
| 3191 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3192 | |
| 3193 | /* Initialize inner-loop KI gain factors */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3194 | status = read16(state, SCU_RAM_AGC_KI__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3195 | if (status < 0) |
| 3196 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3197 | if (IsQAM(state)) { |
| 3198 | data = 0x0657; |
| 3199 | data &= ~SCU_RAM_AGC_KI_RF__M; |
| 3200 | data |= (DRXK_KI_RAGC_QAM << SCU_RAM_AGC_KI_RF__B); |
| 3201 | data &= ~SCU_RAM_AGC_KI_IF__M; |
| 3202 | data |= (DRXK_KI_IAGC_QAM << SCU_RAM_AGC_KI_IF__B); |
| 3203 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3204 | status = write16(state, SCU_RAM_AGC_KI__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3205 | if (status < 0) |
| 3206 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3207 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3208 | return status; |
| 3209 | } |
| 3210 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3211 | static int DVBTQAMGetAccPktErr(struct drxk_state *state, u16 *packetErr) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3212 | { |
| 3213 | int status; |
| 3214 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3215 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3216 | do { |
| 3217 | if (packetErr == NULL) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3218 | status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3219 | if (status < 0) |
| 3220 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3221 | } else { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3222 | status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, packetErr); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3223 | if (status < 0) |
| 3224 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3225 | } |
| 3226 | } while (0); |
| 3227 | return status; |
| 3228 | } |
| 3229 | |
| 3230 | static int DVBTScCommand(struct drxk_state *state, |
| 3231 | u16 cmd, u16 subcmd, |
| 3232 | u16 param0, u16 param1, u16 param2, |
| 3233 | u16 param3, u16 param4) |
| 3234 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3235 | u16 curCmd = 0; |
| 3236 | u16 errCode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3237 | u16 retryCnt = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3238 | u16 scExec = 0; |
| 3239 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3240 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3241 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3242 | status = read16(state, OFDM_SC_COMM_EXEC__A, &scExec); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3243 | if (scExec != 1) { |
| 3244 | /* SC is not running */ |
| 3245 | return -1; |
| 3246 | } |
| 3247 | |
| 3248 | /* Wait until sc is ready to receive command */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3249 | retryCnt = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3250 | do { |
| 3251 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3252 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3253 | retryCnt++; |
| 3254 | } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); |
| 3255 | if (retryCnt >= DRXK_MAX_RETRIES) |
| 3256 | return -1; |
| 3257 | /* Write sub-command */ |
| 3258 | switch (cmd) { |
| 3259 | /* All commands using sub-cmd */ |
| 3260 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3261 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3262 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3263 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3264 | write16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, subcmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3265 | break; |
| 3266 | default: |
| 3267 | /* Do nothing */ |
| 3268 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3269 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3270 | |
| 3271 | /* Write needed parameters and the command */ |
| 3272 | switch (cmd) { |
| 3273 | /* All commands using 5 parameters */ |
| 3274 | /* All commands using 4 parameters */ |
| 3275 | /* All commands using 3 parameters */ |
| 3276 | /* All commands using 2 parameters */ |
| 3277 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3278 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3279 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3280 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3281 | write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3282 | /* All commands using 1 parameters */ |
| 3283 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3284 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3285 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3286 | write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3287 | /* All commands using 0 parameters */ |
| 3288 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
| 3289 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3290 | /* Write command */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3291 | status = write16(state, OFDM_SC_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3292 | break; |
| 3293 | default: |
| 3294 | /* Unknown command */ |
| 3295 | return -EINVAL; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3296 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3297 | |
| 3298 | /* Wait until sc is ready processing command */ |
| 3299 | retryCnt = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3300 | do { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3301 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3302 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3303 | retryCnt++; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3304 | } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3305 | if (retryCnt >= DRXK_MAX_RETRIES) |
| 3306 | return -1; |
| 3307 | |
| 3308 | /* Check for illegal cmd */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3309 | status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &errCode); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3310 | if (errCode == 0xFFFF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3311 | /* illegal command */ |
| 3312 | return -EINVAL; |
| 3313 | } |
| 3314 | |
| 3315 | /* Retreive results parameters from SC */ |
| 3316 | switch (cmd) { |
| 3317 | /* All commands yielding 5 results */ |
| 3318 | /* All commands yielding 4 results */ |
| 3319 | /* All commands yielding 3 results */ |
| 3320 | /* All commands yielding 2 results */ |
| 3321 | /* All commands yielding 1 result */ |
| 3322 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
| 3323 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3324 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3325 | read16(state, OFDM_SC_RA_RAM_PARAM0__A, &(param0)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3326 | /* All commands yielding 0 results */ |
| 3327 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3328 | case OFDM_SC_RA_RAM_CMD_SET_TIMER: |
| 3329 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3330 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3331 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
| 3332 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3333 | break; |
| 3334 | default: |
| 3335 | /* Unknown command */ |
| 3336 | return -EINVAL; |
| 3337 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3338 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3339 | return status; |
| 3340 | } |
| 3341 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3342 | static int PowerUpDVBT(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3343 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3344 | enum DRXPowerMode powerMode = DRX_POWER_UP; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3345 | int status; |
| 3346 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3347 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3348 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3349 | status = CtrlPowerMode(state, &powerMode); |
| 3350 | if (status < 0) |
| 3351 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3352 | } while (0); |
| 3353 | return status; |
| 3354 | } |
| 3355 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3356 | static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3357 | { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3358 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3359 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3360 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3361 | if (*enabled == true) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3362 | status = write16(state, IQM_CF_BYPASSDET__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3363 | else |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3364 | status = write16(state, IQM_CF_BYPASSDET__A, 1); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3365 | |
| 3366 | return status; |
| 3367 | } |
| 3368 | |
| 3369 | #define DEFAULT_FR_THRES_8K 4000 |
| 3370 | static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled) |
| 3371 | { |
| 3372 | |
| 3373 | int status; |
| 3374 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3375 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3376 | if (*enabled == true) { |
| 3377 | /* write mask to 1 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3378 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3379 | DEFAULT_FR_THRES_8K); |
| 3380 | } else { |
| 3381 | /* write mask to 0 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3382 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | return status; |
| 3386 | } |
| 3387 | |
| 3388 | static int DVBTCtrlSetEchoThreshold(struct drxk_state *state, |
| 3389 | struct DRXKCfgDvbtEchoThres_t *echoThres) |
| 3390 | { |
| 3391 | u16 data = 0; |
| 3392 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3393 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3394 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3395 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3396 | status = read16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3397 | if (status < 0) |
| 3398 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3399 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3400 | switch (echoThres->fftMode) { |
| 3401 | case DRX_FFTMODE_2K: |
| 3402 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M; |
| 3403 | data |= |
| 3404 | ((echoThres->threshold << |
| 3405 | OFDM_SC_RA_RAM_ECHO_THRES_2K__B) |
| 3406 | & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M)); |
| 3407 | break; |
| 3408 | case DRX_FFTMODE_8K: |
| 3409 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M; |
| 3410 | data |= |
| 3411 | ((echoThres->threshold << |
| 3412 | OFDM_SC_RA_RAM_ECHO_THRES_8K__B) |
| 3413 | & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M)); |
| 3414 | break; |
| 3415 | default: |
| 3416 | return -1; |
| 3417 | break; |
| 3418 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3419 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3420 | status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3421 | if (status < 0) |
| 3422 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3423 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3424 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3425 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3429 | enum DRXKCfgDvbtSqiSpeed *speed) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3430 | { |
| 3431 | int status; |
| 3432 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3433 | dprintk(1, "\n"); |
| 3434 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3435 | switch (*speed) { |
| 3436 | case DRXK_DVBT_SQI_SPEED_FAST: |
| 3437 | case DRXK_DVBT_SQI_SPEED_MEDIUM: |
| 3438 | case DRXK_DVBT_SQI_SPEED_SLOW: |
| 3439 | break; |
| 3440 | default: |
| 3441 | return -EINVAL; |
| 3442 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3443 | status = write16(state, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3444 | (u16) *speed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3445 | return status; |
| 3446 | } |
| 3447 | |
| 3448 | /*============================================================================*/ |
| 3449 | |
| 3450 | /** |
| 3451 | * \brief Activate DVBT specific presets |
| 3452 | * \param demod instance of demodulator. |
| 3453 | * \return DRXStatus_t. |
| 3454 | * |
| 3455 | * Called in DVBTSetStandard |
| 3456 | * |
| 3457 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3458 | static int DVBTActivatePresets(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3459 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3460 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3461 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3462 | struct DRXKCfgDvbtEchoThres_t echoThres2k = { 0, DRX_FFTMODE_2K }; |
| 3463 | struct DRXKCfgDvbtEchoThres_t echoThres8k = { 0, DRX_FFTMODE_8K }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3464 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3465 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3466 | do { |
| 3467 | bool setincenable = false; |
| 3468 | bool setfrenable = true; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3469 | status = DVBTCtrlSetIncEnable(state, &setincenable); |
| 3470 | if (status < 0) |
| 3471 | break; |
| 3472 | status = DVBTCtrlSetFrEnable(state, &setfrenable); |
| 3473 | if (status < 0) |
| 3474 | break; |
| 3475 | status = DVBTCtrlSetEchoThreshold(state, &echoThres2k); |
| 3476 | if (status < 0) |
| 3477 | break; |
| 3478 | status = DVBTCtrlSetEchoThreshold(state, &echoThres8k); |
| 3479 | if (status < 0) |
| 3480 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3481 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, state->m_dvbtIfAgcCfg.IngainTgtMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3482 | if (status < 0) |
| 3483 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3484 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3485 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3486 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3487 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3488 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3489 | /*============================================================================*/ |
| 3490 | |
| 3491 | /** |
| 3492 | * \brief Initialize channelswitch-independent settings for DVBT. |
| 3493 | * \param demod instance of demodulator. |
| 3494 | * \return DRXStatus_t. |
| 3495 | * |
| 3496 | * For ROM code channel filter taps are loaded from the bootloader. For microcode |
| 3497 | * the DVB-T taps from the drxk_filters.h are used. |
| 3498 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3499 | static int SetDVBTStandard(struct drxk_state *state, |
| 3500 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3501 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3502 | u16 cmdResult = 0; |
| 3503 | u16 data = 0; |
| 3504 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3505 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3506 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3507 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3508 | PowerUpDVBT(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3509 | do { |
| 3510 | /* added antenna switch */ |
| 3511 | SwitchAntennaToDVBT(state); |
| 3512 | /* send OFDM reset command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3513 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 3514 | if (status < 0) |
| 3515 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3516 | |
| 3517 | /* send OFDM setenv command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3518 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 0, NULL, 1, &cmdResult); |
| 3519 | if (status < 0) |
| 3520 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3521 | |
| 3522 | /* reset datapath for OFDM, processors first */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3523 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3524 | if (status < 0) |
| 3525 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3526 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3527 | if (status < 0) |
| 3528 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3529 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3530 | if (status < 0) |
| 3531 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3532 | |
| 3533 | /* IQM setup */ |
| 3534 | /* synchronize on ofdstate->m_festart */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3535 | status = write16(state, IQM_AF_UPD_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3536 | if (status < 0) |
| 3537 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3538 | /* window size for clipping ADC detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3539 | status = write16(state, IQM_AF_CLP_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3540 | if (status < 0) |
| 3541 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3542 | /* window size for for sense pre-SAW detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3543 | status = write16(state, IQM_AF_SNS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3544 | if (status < 0) |
| 3545 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3546 | /* sense threshold for sense pre-SAW detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3547 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3548 | if (status < 0) |
| 3549 | break; |
| 3550 | status = SetIqmAf(state, true); |
| 3551 | if (status < 0) |
| 3552 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3553 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3554 | status = write16(state, IQM_AF_AGC_RF__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3555 | if (status < 0) |
| 3556 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3557 | |
| 3558 | /* Impulse noise cruncher setup */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3559 | status = write16(state, IQM_AF_INC_LCT__A, 0); /* crunch in IQM_CF */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3560 | if (status < 0) |
| 3561 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3562 | status = write16(state, IQM_CF_DET_LCT__A, 0); /* detect in IQM_CF */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3563 | if (status < 0) |
| 3564 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3565 | status = write16(state, IQM_CF_WND_LEN__A, 3); /* peak detector window length */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3566 | if (status < 0) |
| 3567 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3568 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3569 | status = write16(state, IQM_RC_STRETCH__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3570 | if (status < 0) |
| 3571 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3572 | status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3573 | if (status < 0) |
| 3574 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3575 | status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3576 | if (status < 0) |
| 3577 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3578 | status = write16(state, IQM_CF_SCALE__A, 1600); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3579 | if (status < 0) |
| 3580 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3581 | status = write16(state, IQM_CF_SCALE_SH__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3582 | if (status < 0) |
| 3583 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3584 | |
| 3585 | /* virtual clipping threshold for clipping ADC detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3586 | status = write16(state, IQM_AF_CLP_TH__A, 448); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3587 | if (status < 0) |
| 3588 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3589 | status = write16(state, IQM_CF_DATATH__A, 495); /* crunching threshold */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3590 | if (status < 0) |
| 3591 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3592 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3593 | status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 3594 | if (status < 0) |
| 3595 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3596 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3597 | status = write16(state, IQM_CF_PKDTH__A, 2); /* peak detector threshold */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3598 | if (status < 0) |
| 3599 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3600 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3601 | if (status < 0) |
| 3602 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3603 | /* enable power measurement interrupt */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3604 | status = write16(state, IQM_CF_COMM_INT_MSK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3605 | if (status < 0) |
| 3606 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3607 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3608 | if (status < 0) |
| 3609 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3610 | |
| 3611 | /* IQM will not be reset from here, sync ADC and update/init AGC */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3612 | status = ADCSynchronization(state); |
| 3613 | if (status < 0) |
| 3614 | break; |
| 3615 | status = SetPreSaw(state, &state->m_dvbtPreSawCfg); |
| 3616 | if (status < 0) |
| 3617 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3618 | |
| 3619 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3620 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3621 | if (status < 0) |
| 3622 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3623 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3624 | status = SetAgcRf(state, &state->m_dvbtRfAgcCfg, true); |
| 3625 | if (status < 0) |
| 3626 | break; |
| 3627 | status = SetAgcIf(state, &state->m_dvbtIfAgcCfg, true); |
| 3628 | if (status < 0) |
| 3629 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3630 | |
| 3631 | /* Set Noise Estimation notch width and enable DC fix */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3632 | status = read16(state, OFDM_SC_RA_RAM_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3633 | if (status < 0) |
| 3634 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3635 | data |= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3636 | status = write16(state, OFDM_SC_RA_RAM_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3637 | if (status < 0) |
| 3638 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3639 | |
| 3640 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3641 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3642 | if (status < 0) |
| 3643 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3644 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3645 | if (!state->m_DRXK_A3_ROM_CODE) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3646 | /* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3647 | status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, state->m_dvbtIfAgcCfg.FastClipCtrlDelay); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3648 | if (status < 0) |
| 3649 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | /* OFDM_SC setup */ |
| 3653 | #ifdef COMPILE_FOR_NONRT |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3654 | status = write16(state, OFDM_SC_RA_RAM_BE_OPT_DELAY__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3655 | if (status < 0) |
| 3656 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3657 | status = write16(state, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3658 | if (status < 0) |
| 3659 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3660 | #endif |
| 3661 | |
| 3662 | /* FEC setup */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3663 | status = write16(state, FEC_DI_INPUT_CTL__A, 1); /* OFDM input */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3664 | if (status < 0) |
| 3665 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3666 | |
| 3667 | |
| 3668 | #ifdef COMPILE_FOR_NONRT |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3669 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x400); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3670 | if (status < 0) |
| 3671 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3672 | #else |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3673 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3674 | if (status < 0) |
| 3675 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3676 | #endif |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3677 | status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, 0x0001); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3678 | if (status < 0) |
| 3679 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3680 | |
| 3681 | /* Setup MPEG bus */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3682 | status = MPEGTSDtoSetup(state, OM_DVBT); |
| 3683 | if (status < 0) |
| 3684 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3685 | /* Set DVBT Presets */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3686 | status = DVBTActivatePresets(state); |
| 3687 | if (status < 0) |
| 3688 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3689 | |
| 3690 | } while (0); |
| 3691 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3692 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 3693 | printk(KERN_ERR "drxk: %s status - %08x\n", __func__, status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3694 | |
| 3695 | return status; |
| 3696 | } |
| 3697 | |
| 3698 | /*============================================================================*/ |
| 3699 | /** |
| 3700 | * \brief Start dvbt demodulating for channel. |
| 3701 | * \param demod instance of demodulator. |
| 3702 | * \return DRXStatus_t. |
| 3703 | */ |
| 3704 | static int DVBTStart(struct drxk_state *state) |
| 3705 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3706 | u16 param1; |
| 3707 | int status; |
| 3708 | /* DRXKOfdmScCmd_t scCmd; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3709 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3710 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3711 | /* Start correct processes to get in lock */ |
| 3712 | /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */ |
| 3713 | do { |
| 3714 | param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3715 | status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, 0, 0, 0); |
| 3716 | if (status < 0) |
| 3717 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3718 | /* Start FEC OC */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3719 | status = MPEGTSStart(state); |
| 3720 | if (status < 0) |
| 3721 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3722 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3723 | if (status < 0) |
| 3724 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3725 | } while (0); |
| 3726 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | |
| 3730 | /*============================================================================*/ |
| 3731 | |
| 3732 | /** |
| 3733 | * \brief Set up dvbt demodulator for channel. |
| 3734 | * \param demod instance of demodulator. |
| 3735 | * \return DRXStatus_t. |
| 3736 | * // original DVBTSetChannel() |
| 3737 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3738 | static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, |
| 3739 | s32 tunerFreqOffset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3740 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3741 | u16 cmdResult = 0; |
| 3742 | u16 transmissionParams = 0; |
| 3743 | u16 operationMode = 0; |
| 3744 | u32 iqmRcRateOfs = 0; |
| 3745 | u32 bandwidth = 0; |
| 3746 | u16 param1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3747 | int status; |
| 3748 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3749 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 3750 | /* printk(KERN_DEBUG "drxk: %s IF =%d, TFO = %d\n", __func__, IntermediateFreqkHz, tunerFreqOffset); */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3751 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3752 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 3753 | if (status < 0) |
| 3754 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3755 | |
| 3756 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3757 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3758 | if (status < 0) |
| 3759 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3760 | |
| 3761 | /* Stop processors */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3762 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3763 | if (status < 0) |
| 3764 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3765 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3766 | if (status < 0) |
| 3767 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3768 | |
| 3769 | /* Mandatory fix, always stop CP, required to set spl offset back to |
| 3770 | hardware default (is set to 0 by ucode during pilot detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3771 | status = write16(state, OFDM_CP_COMM_EXEC__A, OFDM_CP_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3772 | if (status < 0) |
| 3773 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3774 | |
| 3775 | /*== Write channel settings to device =====================================*/ |
| 3776 | |
| 3777 | /* mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3778 | switch (state->param.u.ofdm.transmission_mode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3779 | case TRANSMISSION_MODE_AUTO: |
| 3780 | default: |
| 3781 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M; |
| 3782 | /* fall through , try first guess DRX_FFTMODE_8K */ |
| 3783 | case TRANSMISSION_MODE_8K: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3784 | transmissionParams |= |
| 3785 | OFDM_SC_RA_RAM_OP_PARAM_MODE_8K; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3786 | break; |
| 3787 | case TRANSMISSION_MODE_2K: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3788 | transmissionParams |= |
| 3789 | OFDM_SC_RA_RAM_OP_PARAM_MODE_2K; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3790 | break; |
| 3791 | } |
| 3792 | |
| 3793 | /* guard */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3794 | switch (state->param.u.ofdm.guard_interval) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3795 | default: |
| 3796 | case GUARD_INTERVAL_AUTO: |
| 3797 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M; |
| 3798 | /* fall through , try first guess DRX_GUARD_1DIV4 */ |
| 3799 | case GUARD_INTERVAL_1_4: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3800 | transmissionParams |= |
| 3801 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3802 | break; |
| 3803 | case GUARD_INTERVAL_1_32: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3804 | transmissionParams |= |
| 3805 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_32; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3806 | break; |
| 3807 | case GUARD_INTERVAL_1_16: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3808 | transmissionParams |= |
| 3809 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_16; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3810 | break; |
| 3811 | case GUARD_INTERVAL_1_8: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3812 | transmissionParams |= |
| 3813 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_8; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3814 | break; |
| 3815 | } |
| 3816 | |
| 3817 | /* hierarchy */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3818 | switch (state->param.u.ofdm.hierarchy_information) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3819 | case HIERARCHY_AUTO: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3820 | case HIERARCHY_NONE: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3821 | default: |
| 3822 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_HIER__M; |
| 3823 | /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3824 | /* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */ |
| 3825 | /* break; */ |
| 3826 | case HIERARCHY_1: |
| 3827 | transmissionParams |= |
| 3828 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3829 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3830 | case HIERARCHY_2: |
| 3831 | transmissionParams |= |
| 3832 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A2; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3833 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3834 | case HIERARCHY_4: |
| 3835 | transmissionParams |= |
| 3836 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3837 | break; |
| 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | /* constellation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3842 | switch (state->param.u.ofdm.constellation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3843 | case QAM_AUTO: |
| 3844 | default: |
| 3845 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M; |
| 3846 | /* fall through , try first guess DRX_CONSTELLATION_QAM64 */ |
| 3847 | case QAM_64: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3848 | transmissionParams |= |
| 3849 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3850 | break; |
| 3851 | case QPSK: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3852 | transmissionParams |= |
| 3853 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3854 | break; |
| 3855 | case QAM_16: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3856 | transmissionParams |= |
| 3857 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3858 | break; |
| 3859 | } |
| 3860 | #if 0 |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3861 | /* No hierachical channels support in BDA */ |
| 3862 | /* Priority (only for hierarchical channels) */ |
| 3863 | switch (channel->priority) { |
| 3864 | case DRX_PRIORITY_LOW: |
| 3865 | transmissionParams |= |
| 3866 | OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO; |
| 3867 | WR16(devAddr, OFDM_EC_SB_PRIOR__A, |
| 3868 | OFDM_EC_SB_PRIOR_LO); |
| 3869 | break; |
| 3870 | case DRX_PRIORITY_HIGH: |
| 3871 | transmissionParams |= |
| 3872 | OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
| 3873 | WR16(devAddr, OFDM_EC_SB_PRIOR__A, |
| 3874 | OFDM_EC_SB_PRIOR_HI)); |
| 3875 | break; |
| 3876 | case DRX_PRIORITY_UNKNOWN: /* fall through */ |
| 3877 | default: |
| 3878 | return DRX_STS_INVALID_ARG; |
| 3879 | break; |
| 3880 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3881 | #else |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3882 | /* Set Priorty high */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3883 | transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3884 | status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3885 | if (status < 0) |
| 3886 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3887 | #endif |
| 3888 | |
| 3889 | /* coderate */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3890 | switch (state->param.u.ofdm.code_rate_HP) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3891 | case FEC_AUTO: |
| 3892 | default: |
| 3893 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M; |
| 3894 | /* fall through , try first guess DRX_CODERATE_2DIV3 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3895 | case FEC_2_3: |
| 3896 | transmissionParams |= |
| 3897 | OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3898 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3899 | case FEC_1_2: |
| 3900 | transmissionParams |= |
| 3901 | OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3902 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3903 | case FEC_3_4: |
| 3904 | transmissionParams |= |
| 3905 | OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3906 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3907 | case FEC_5_6: |
| 3908 | transmissionParams |= |
| 3909 | OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3910 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3911 | case FEC_7_8: |
| 3912 | transmissionParams |= |
| 3913 | OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3914 | break; |
| 3915 | } |
| 3916 | |
| 3917 | /* SAW filter selection: normaly not necesarry, but if wanted |
| 3918 | the application can select a SAW filter via the driver by using UIOs */ |
| 3919 | /* First determine real bandwidth (Hz) */ |
| 3920 | /* Also set delay for impulse noise cruncher */ |
| 3921 | /* Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is changed |
| 3922 | by SC for fix for some 8K,1/8 guard but is restored by InitEC and ResetEC |
| 3923 | functions */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3924 | switch (state->param.u.ofdm.bandwidth) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3925 | case BANDWIDTH_AUTO: |
| 3926 | case BANDWIDTH_8_MHZ: |
| 3927 | bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3928 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3052); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3929 | if (status < 0) |
| 3930 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3931 | /* cochannel protection for PAL 8 MHz */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3932 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3933 | if (status < 0) |
| 3934 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3935 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3936 | if (status < 0) |
| 3937 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3938 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3939 | if (status < 0) |
| 3940 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3941 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3942 | if (status < 0) |
| 3943 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3944 | break; |
| 3945 | case BANDWIDTH_7_MHZ: |
| 3946 | bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3947 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3491); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3948 | if (status < 0) |
| 3949 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3950 | /* cochannel protection for PAL 7 MHz */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3951 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3952 | if (status < 0) |
| 3953 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3954 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3955 | if (status < 0) |
| 3956 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3957 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3958 | if (status < 0) |
| 3959 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3960 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3961 | if (status < 0) |
| 3962 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3963 | break; |
| 3964 | case BANDWIDTH_6_MHZ: |
| 3965 | bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3966 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 4073); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3967 | if (status < 0) |
| 3968 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3969 | /* cochannel protection for NTSC 6 MHz */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3970 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 19); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3971 | if (status < 0) |
| 3972 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3973 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 19); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3974 | if (status < 0) |
| 3975 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3976 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 14); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3977 | if (status < 0) |
| 3978 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3979 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3980 | if (status < 0) |
| 3981 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3982 | break; |
Mauro Carvalho Chehab | e16cede | 2011-07-03 18:18:14 -0300 | [diff] [blame] | 3983 | default: |
| 3984 | return -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3985 | } |
| 3986 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3987 | if (iqmRcRateOfs == 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3988 | /* Now compute IQM_RC_RATE_OFS |
| 3989 | (((SysFreq/BandWidth)/2)/2) -1) * 2^23) |
| 3990 | => |
| 3991 | ((SysFreq / BandWidth) * (2^21)) - (2^23) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3992 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3993 | /* (SysFreq / BandWidth) * (2^28) */ |
| 3994 | /* assert (MAX(sysClk)/MIN(bandwidth) < 16) |
| 3995 | => assert(MAX(sysClk) < 16*MIN(bandwidth)) |
| 3996 | => assert(109714272 > 48000000) = true so Frac 28 can be used */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3997 | iqmRcRateOfs = Frac28a((u32) |
| 3998 | ((state->m_sysClockFreq * |
| 3999 | 1000) / 3), bandwidth); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4000 | /* (SysFreq / BandWidth) * (2^21), rounding before truncating */ |
| 4001 | if ((iqmRcRateOfs & 0x7fL) >= 0x40) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4002 | iqmRcRateOfs += 0x80L; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4003 | iqmRcRateOfs = iqmRcRateOfs >> 7; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4004 | /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4005 | iqmRcRateOfs = iqmRcRateOfs - (1 << 23); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4006 | } |
| 4007 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4008 | iqmRcRateOfs &= |
| 4009 | ((((u32) IQM_RC_RATE_OFS_HI__M) << |
| 4010 | IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4011 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRateOfs); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4012 | if (status < 0) |
| 4013 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4014 | |
| 4015 | /* Bandwidth setting done */ |
| 4016 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4017 | #if 0 |
| 4018 | status = DVBTSetFrequencyShift(demod, channel, tunerOffset); |
| 4019 | if (status < 0) |
| 4020 | break; |
| 4021 | #endif |
| 4022 | status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); |
| 4023 | if (status < 0) |
| 4024 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4025 | |
| 4026 | /*== Start SC, write channel settings to SC ===============================*/ |
| 4027 | |
| 4028 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4029 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4030 | if (status < 0) |
| 4031 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4032 | |
| 4033 | /* Enable SC after setting all other parameters */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4034 | status = write16(state, OFDM_SC_COMM_STATE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4035 | if (status < 0) |
| 4036 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4037 | status = write16(state, OFDM_SC_COMM_EXEC__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4038 | if (status < 0) |
| 4039 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4040 | |
| 4041 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4042 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); |
| 4043 | if (status < 0) |
| 4044 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4045 | |
| 4046 | /* Write SC parameter registers, set all AUTO flags in operation mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4047 | param1 = (OFDM_SC_RA_RAM_OP_AUTO_MODE__M | |
| 4048 | OFDM_SC_RA_RAM_OP_AUTO_GUARD__M | |
| 4049 | OFDM_SC_RA_RAM_OP_AUTO_CONST__M | |
| 4050 | OFDM_SC_RA_RAM_OP_AUTO_HIER__M | |
| 4051 | OFDM_SC_RA_RAM_OP_AUTO_RATE__M); |
| 4052 | status = |
| 4053 | DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM, |
| 4054 | 0, transmissionParams, param1, 0, 0, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4055 | if (!state->m_DRXK_A3_ROM_CODE) |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4056 | status = DVBTCtrlSetSqiSpeed(state, &state->m_sqiSpeed); |
| 4057 | if (status < 0) |
| 4058 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4059 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4060 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4061 | |
| 4062 | return status; |
| 4063 | } |
| 4064 | |
| 4065 | |
| 4066 | /*============================================================================*/ |
| 4067 | |
| 4068 | /** |
| 4069 | * \brief Retreive lock status . |
| 4070 | * \param demod Pointer to demodulator instance. |
| 4071 | * \param lockStat Pointer to lock status structure. |
| 4072 | * \return DRXStatus_t. |
| 4073 | * |
| 4074 | */ |
| 4075 | static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) |
| 4076 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4077 | int status; |
| 4078 | const u16 mpeg_lock_mask = (OFDM_SC_RA_RAM_LOCK_MPEG__M | |
| 4079 | OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4080 | const u16 fec_lock_mask = (OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4081 | const u16 demod_lock_mask = OFDM_SC_RA_RAM_LOCK_DEMOD__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4082 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4083 | u16 ScRaRamLock = 0; |
| 4084 | u16 ScCommExec = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4085 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4086 | dprintk(1, "\n"); |
| 4087 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4088 | /* driver 0.9.0 */ |
| 4089 | /* Check if SC is running */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4090 | status = read16(state, OFDM_SC_COMM_EXEC__A, &ScCommExec); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4091 | if (ScCommExec == OFDM_SC_COMM_EXEC_STOP) { |
| 4092 | /* SC not active; return DRX_NOT_LOCKED */ |
| 4093 | *pLockStatus = NOT_LOCKED; |
| 4094 | return status; |
| 4095 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4096 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4097 | status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &ScRaRamLock); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4098 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4099 | if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask) |
| 4100 | *pLockStatus = MPEG_LOCK; |
| 4101 | else if ((ScRaRamLock & fec_lock_mask) == fec_lock_mask) |
| 4102 | *pLockStatus = FEC_LOCK; |
| 4103 | else if ((ScRaRamLock & demod_lock_mask) == demod_lock_mask) |
| 4104 | *pLockStatus = DEMOD_LOCK; |
| 4105 | else if (ScRaRamLock & OFDM_SC_RA_RAM_LOCK_NODVBT__M) |
| 4106 | *pLockStatus = NEVER_LOCK; |
| 4107 | else |
| 4108 | *pLockStatus = NOT_LOCKED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4109 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4110 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4111 | } |
| 4112 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4113 | static int PowerUpQAM(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4114 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4115 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
| 4116 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4117 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4118 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4119 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4120 | status = CtrlPowerMode(state, &powerMode); |
| 4121 | if (status < 0) |
| 4122 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4123 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4124 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4125 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4126 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4130 | /** Power Down QAM */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4131 | static int PowerDownQAM(struct drxk_state *state) |
| 4132 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4133 | u16 data = 0; |
| 4134 | u16 cmdResult; |
| 4135 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4136 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4137 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4138 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4139 | status = read16(state, SCU_COMM_EXEC__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4140 | if (status < 0) |
| 4141 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4142 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 4143 | /* |
| 4144 | STOP demodulator |
| 4145 | QAM and HW blocks |
| 4146 | */ |
| 4147 | /* stop all comstate->m_exec */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4148 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4149 | if (status < 0) |
| 4150 | break; |
| 4151 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 4152 | if (status < 0) |
| 4153 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4154 | } |
| 4155 | /* powerdown AFE */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4156 | status = SetIqmAf(state, false); |
| 4157 | if (status < 0) |
| 4158 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4159 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4160 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4161 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4162 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4163 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4164 | /*============================================================================*/ |
| 4165 | |
| 4166 | /** |
| 4167 | * \brief Setup of the QAM Measurement intervals for signal quality |
| 4168 | * \param demod instance of demod. |
| 4169 | * \param constellation current constellation. |
| 4170 | * \return DRXStatus_t. |
| 4171 | * |
| 4172 | * NOTE: |
| 4173 | * Take into account that for certain settings the errorcounters can overflow. |
| 4174 | * The implementation does not check this. |
| 4175 | * |
| 4176 | */ |
| 4177 | static int SetQAMMeasurement(struct drxk_state *state, |
| 4178 | enum EDrxkConstellation constellation, |
| 4179 | u32 symbolRate) |
| 4180 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4181 | u32 fecBitsDesired = 0; /* BER accounting period */ |
| 4182 | u32 fecRsPeriodTotal = 0; /* Total period */ |
| 4183 | u16 fecRsPrescale = 0; /* ReedSolomon Measurement Prescale */ |
| 4184 | u16 fecRsPeriod = 0; /* Value for corresponding I2C register */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4185 | int status = 0; |
| 4186 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4187 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4188 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4189 | fecRsPrescale = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4190 | do { |
| 4191 | |
| 4192 | /* fecBitsDesired = symbolRate [kHz] * |
| 4193 | FrameLenght [ms] * |
| 4194 | (constellation + 1) * |
| 4195 | SyncLoss (== 1) * |
| 4196 | ViterbiLoss (==1) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4197 | */ |
| 4198 | switch (constellation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4199 | case DRX_CONSTELLATION_QAM16: |
| 4200 | fecBitsDesired = 4 * symbolRate; |
| 4201 | break; |
| 4202 | case DRX_CONSTELLATION_QAM32: |
| 4203 | fecBitsDesired = 5 * symbolRate; |
| 4204 | break; |
| 4205 | case DRX_CONSTELLATION_QAM64: |
| 4206 | fecBitsDesired = 6 * symbolRate; |
| 4207 | break; |
| 4208 | case DRX_CONSTELLATION_QAM128: |
| 4209 | fecBitsDesired = 7 * symbolRate; |
| 4210 | break; |
| 4211 | case DRX_CONSTELLATION_QAM256: |
| 4212 | fecBitsDesired = 8 * symbolRate; |
| 4213 | break; |
| 4214 | default: |
| 4215 | status = -EINVAL; |
| 4216 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4217 | status = status; |
| 4218 | if (status < 0) |
| 4219 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4220 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4221 | fecBitsDesired /= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */ |
| 4222 | fecBitsDesired *= 500; /* meas. period [ms] */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4223 | |
| 4224 | /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */ |
| 4225 | /* fecRsPeriodTotal = fecBitsDesired / 1632 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4226 | fecRsPeriodTotal = (fecBitsDesired / 1632UL) + 1; /* roughly ceil */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4227 | |
| 4228 | /* fecRsPeriodTotal = fecRsPrescale * fecRsPeriod */ |
| 4229 | fecRsPrescale = 1 + (u16) (fecRsPeriodTotal >> 16); |
| 4230 | if (fecRsPrescale == 0) { |
| 4231 | /* Divide by zero (though impossible) */ |
| 4232 | status = -1; |
| 4233 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4234 | status = status; |
| 4235 | if (status < 0) |
| 4236 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4237 | fecRsPeriod = |
| 4238 | ((u16) fecRsPeriodTotal + |
| 4239 | (fecRsPrescale >> 1)) / fecRsPrescale; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4240 | |
| 4241 | /* write corresponding registers */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4242 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fecRsPeriod); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4243 | if (status < 0) |
| 4244 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4245 | status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, fecRsPrescale); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4246 | if (status < 0) |
| 4247 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4248 | status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fecRsPeriod); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4249 | if (status < 0) |
| 4250 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4251 | |
| 4252 | } while (0); |
| 4253 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4254 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 4255 | printk(KERN_ERR "drxk: %s: status - %08x\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4256 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4257 | return status; |
| 4258 | } |
| 4259 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4260 | static int SetQAM16(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4261 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4262 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4263 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4264 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4265 | do { |
| 4266 | /* QAM Equalizer Setup */ |
| 4267 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4268 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4269 | if (status < 0) |
| 4270 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4271 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4272 | if (status < 0) |
| 4273 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4274 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4275 | if (status < 0) |
| 4276 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4277 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4278 | if (status < 0) |
| 4279 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4280 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4281 | if (status < 0) |
| 4282 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4283 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4284 | if (status < 0) |
| 4285 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4286 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4287 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4288 | if (status < 0) |
| 4289 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4290 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4291 | if (status < 0) |
| 4292 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4293 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4294 | if (status < 0) |
| 4295 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4296 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4297 | if (status < 0) |
| 4298 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4299 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4300 | if (status < 0) |
| 4301 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4302 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4303 | if (status < 0) |
| 4304 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4305 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4306 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4307 | if (status < 0) |
| 4308 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4309 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4310 | if (status < 0) |
| 4311 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4312 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4313 | if (status < 0) |
| 4314 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4315 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4316 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4317 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4318 | if (status < 0) |
| 4319 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4320 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4321 | /* QAM Loop Controller Coeficients */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4322 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4323 | if (status < 0) |
| 4324 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4325 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4326 | if (status < 0) |
| 4327 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4328 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4329 | if (status < 0) |
| 4330 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4331 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4332 | if (status < 0) |
| 4333 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4334 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4335 | if (status < 0) |
| 4336 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4337 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4338 | if (status < 0) |
| 4339 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4340 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4341 | if (status < 0) |
| 4342 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4343 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4344 | if (status < 0) |
| 4345 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4346 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4347 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4348 | if (status < 0) |
| 4349 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4350 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4351 | if (status < 0) |
| 4352 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4353 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4354 | if (status < 0) |
| 4355 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4356 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4357 | if (status < 0) |
| 4358 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4359 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4360 | if (status < 0) |
| 4361 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4362 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4363 | if (status < 0) |
| 4364 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4365 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4366 | if (status < 0) |
| 4367 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4368 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4369 | if (status < 0) |
| 4370 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4371 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 32); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4372 | if (status < 0) |
| 4373 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4374 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4375 | if (status < 0) |
| 4376 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4377 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4378 | if (status < 0) |
| 4379 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4380 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4381 | if (status < 0) |
| 4382 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4383 | |
| 4384 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4385 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4386 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4387 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 140); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4388 | if (status < 0) |
| 4389 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4390 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4391 | if (status < 0) |
| 4392 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4393 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 95); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4394 | if (status < 0) |
| 4395 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4396 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 120); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4397 | if (status < 0) |
| 4398 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4399 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 230); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4400 | if (status < 0) |
| 4401 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4402 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 105); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4403 | if (status < 0) |
| 4404 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4405 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4406 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4407 | if (status < 0) |
| 4408 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4409 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4410 | if (status < 0) |
| 4411 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4412 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4413 | if (status < 0) |
| 4414 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4415 | |
| 4416 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4417 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4418 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4419 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4420 | if (status < 0) |
| 4421 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4422 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 220); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4423 | if (status < 0) |
| 4424 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4425 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 25); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4426 | if (status < 0) |
| 4427 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4428 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4429 | if (status < 0) |
| 4430 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4431 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4432 | if (status < 0) |
| 4433 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4434 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -65); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4435 | if (status < 0) |
| 4436 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4437 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -127); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4438 | if (status < 0) |
| 4439 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4440 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4441 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4442 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | /*============================================================================*/ |
| 4446 | |
| 4447 | /** |
| 4448 | * \brief QAM32 specific setup |
| 4449 | * \param demod instance of demod. |
| 4450 | * \return DRXStatus_t. |
| 4451 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4452 | static int SetQAM32(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4453 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4454 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4455 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4456 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4457 | do { |
| 4458 | /* QAM Equalizer Setup */ |
| 4459 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4460 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4461 | if (status < 0) |
| 4462 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4463 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4464 | if (status < 0) |
| 4465 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4466 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4467 | if (status < 0) |
| 4468 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4469 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4470 | if (status < 0) |
| 4471 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4472 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4473 | if (status < 0) |
| 4474 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4475 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4476 | if (status < 0) |
| 4477 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4478 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4479 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4480 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4481 | if (status < 0) |
| 4482 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4483 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4484 | if (status < 0) |
| 4485 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4486 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4487 | if (status < 0) |
| 4488 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4489 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4490 | if (status < 0) |
| 4491 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4492 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4493 | if (status < 0) |
| 4494 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4495 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4496 | if (status < 0) |
| 4497 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4498 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4499 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4500 | if (status < 0) |
| 4501 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4502 | status = write16(state, QAM_SY_SYNC_AWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4503 | if (status < 0) |
| 4504 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4505 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4506 | if (status < 0) |
| 4507 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4508 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4509 | /* QAM Slicer Settings */ |
| 4510 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4511 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM32); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4512 | if (status < 0) |
| 4513 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4514 | |
| 4515 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4516 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4517 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4518 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4519 | if (status < 0) |
| 4520 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4521 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4522 | if (status < 0) |
| 4523 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4524 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4525 | if (status < 0) |
| 4526 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4527 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4528 | if (status < 0) |
| 4529 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4530 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4531 | if (status < 0) |
| 4532 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4533 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4534 | if (status < 0) |
| 4535 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4536 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4537 | if (status < 0) |
| 4538 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4539 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4540 | if (status < 0) |
| 4541 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4542 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4543 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4544 | if (status < 0) |
| 4545 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4546 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4547 | if (status < 0) |
| 4548 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4549 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4550 | if (status < 0) |
| 4551 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4552 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4553 | if (status < 0) |
| 4554 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4555 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4556 | if (status < 0) |
| 4557 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4558 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4559 | if (status < 0) |
| 4560 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4561 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4562 | if (status < 0) |
| 4563 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4564 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4565 | if (status < 0) |
| 4566 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4567 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4568 | if (status < 0) |
| 4569 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4570 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4571 | if (status < 0) |
| 4572 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4573 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4574 | if (status < 0) |
| 4575 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4576 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4577 | if (status < 0) |
| 4578 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4579 | |
| 4580 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4581 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4582 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4583 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 90); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4584 | if (status < 0) |
| 4585 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4586 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4587 | if (status < 0) |
| 4588 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4589 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4590 | if (status < 0) |
| 4591 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4592 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4593 | if (status < 0) |
| 4594 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4595 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 170); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4596 | if (status < 0) |
| 4597 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4598 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4599 | if (status < 0) |
| 4600 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4601 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4602 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4603 | if (status < 0) |
| 4604 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4605 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4606 | if (status < 0) |
| 4607 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4608 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4609 | if (status < 0) |
| 4610 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4611 | |
| 4612 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4613 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4614 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4615 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4616 | if (status < 0) |
| 4617 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4618 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 140); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4619 | if (status < 0) |
| 4620 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4621 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) -8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4622 | if (status < 0) |
| 4623 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4624 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) -16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4625 | if (status < 0) |
| 4626 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4627 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -26); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4628 | if (status < 0) |
| 4629 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4630 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -56); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4631 | if (status < 0) |
| 4632 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4633 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4634 | if (status < 0) |
| 4635 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4636 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4637 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4638 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | /*============================================================================*/ |
| 4642 | |
| 4643 | /** |
| 4644 | * \brief QAM64 specific setup |
| 4645 | * \param demod instance of demod. |
| 4646 | * \return DRXStatus_t. |
| 4647 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4648 | static int SetQAM64(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4649 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4650 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4651 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4652 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4653 | do { |
| 4654 | /* QAM Equalizer Setup */ |
| 4655 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4656 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13336); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4657 | if (status < 0) |
| 4658 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4659 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12618); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4660 | if (status < 0) |
| 4661 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4662 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 11988); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4663 | if (status < 0) |
| 4664 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4665 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13809); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4666 | if (status < 0) |
| 4667 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4668 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13809); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4669 | if (status < 0) |
| 4670 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4671 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15609); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4672 | if (status < 0) |
| 4673 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4674 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4675 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4676 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4677 | if (status < 0) |
| 4678 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4679 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4680 | if (status < 0) |
| 4681 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4682 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4683 | if (status < 0) |
| 4684 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4685 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4686 | if (status < 0) |
| 4687 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4688 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4689 | if (status < 0) |
| 4690 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4691 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4692 | if (status < 0) |
| 4693 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4694 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4695 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4696 | if (status < 0) |
| 4697 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4698 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4699 | if (status < 0) |
| 4700 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4701 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4702 | if (status < 0) |
| 4703 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4704 | |
| 4705 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4706 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM64); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4707 | if (status < 0) |
| 4708 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4709 | |
| 4710 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4711 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4712 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4713 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4714 | if (status < 0) |
| 4715 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4716 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4717 | if (status < 0) |
| 4718 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4719 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4720 | if (status < 0) |
| 4721 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4722 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4723 | if (status < 0) |
| 4724 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4725 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4726 | if (status < 0) |
| 4727 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4728 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4729 | if (status < 0) |
| 4730 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4731 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4732 | if (status < 0) |
| 4733 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4734 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4735 | if (status < 0) |
| 4736 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4737 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4738 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4739 | if (status < 0) |
| 4740 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4741 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4742 | if (status < 0) |
| 4743 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4744 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4745 | if (status < 0) |
| 4746 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4747 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4748 | if (status < 0) |
| 4749 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4750 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 30); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4751 | if (status < 0) |
| 4752 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4753 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4754 | if (status < 0) |
| 4755 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4756 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4757 | if (status < 0) |
| 4758 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4759 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4760 | if (status < 0) |
| 4761 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4762 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4763 | if (status < 0) |
| 4764 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4765 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4766 | if (status < 0) |
| 4767 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4768 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4769 | if (status < 0) |
| 4770 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4771 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4772 | if (status < 0) |
| 4773 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4774 | |
| 4775 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4776 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4777 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4778 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4779 | if (status < 0) |
| 4780 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4781 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4782 | if (status < 0) |
| 4783 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4784 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4785 | if (status < 0) |
| 4786 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4787 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 110); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4788 | if (status < 0) |
| 4789 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4790 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 200); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4791 | if (status < 0) |
| 4792 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4793 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 95); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4794 | if (status < 0) |
| 4795 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4796 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4797 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4798 | if (status < 0) |
| 4799 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4800 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4801 | if (status < 0) |
| 4802 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4803 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4804 | if (status < 0) |
| 4805 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4806 | |
| 4807 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4808 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4809 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4810 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4811 | if (status < 0) |
| 4812 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4813 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 141); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4814 | if (status < 0) |
| 4815 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4816 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4817 | if (status < 0) |
| 4818 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4819 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4820 | if (status < 0) |
| 4821 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4822 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4823 | if (status < 0) |
| 4824 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4825 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -45); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4826 | if (status < 0) |
| 4827 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4828 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4829 | if (status < 0) |
| 4830 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4831 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4832 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4833 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | /*============================================================================*/ |
| 4837 | |
| 4838 | /** |
| 4839 | * \brief QAM128 specific setup |
| 4840 | * \param demod: instance of demod. |
| 4841 | * \return DRXStatus_t. |
| 4842 | */ |
| 4843 | static int SetQAM128(struct drxk_state *state) |
| 4844 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4845 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4846 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4847 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4848 | do { |
| 4849 | /* QAM Equalizer Setup */ |
| 4850 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4851 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6564); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4852 | if (status < 0) |
| 4853 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4854 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6598); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4855 | if (status < 0) |
| 4856 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4857 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6394); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4858 | if (status < 0) |
| 4859 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4860 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6409); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4861 | if (status < 0) |
| 4862 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4863 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6656); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4864 | if (status < 0) |
| 4865 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4866 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 7238); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4867 | if (status < 0) |
| 4868 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4869 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4870 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4871 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4872 | if (status < 0) |
| 4873 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4874 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4875 | if (status < 0) |
| 4876 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4877 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4878 | if (status < 0) |
| 4879 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4880 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4881 | if (status < 0) |
| 4882 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4883 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4884 | if (status < 0) |
| 4885 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4886 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4887 | if (status < 0) |
| 4888 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4889 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4890 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4891 | if (status < 0) |
| 4892 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4893 | status = write16(state, QAM_SY_SYNC_AWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4894 | if (status < 0) |
| 4895 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4896 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4897 | if (status < 0) |
| 4898 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4899 | |
| 4900 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4901 | /* QAM Slicer Settings */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4902 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4903 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM128); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4904 | if (status < 0) |
| 4905 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4906 | |
| 4907 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4908 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4909 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4910 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4911 | if (status < 0) |
| 4912 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4913 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4914 | if (status < 0) |
| 4915 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4916 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4917 | if (status < 0) |
| 4918 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4919 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4920 | if (status < 0) |
| 4921 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4922 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4923 | if (status < 0) |
| 4924 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4925 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4926 | if (status < 0) |
| 4927 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4928 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4929 | if (status < 0) |
| 4930 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4931 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4932 | if (status < 0) |
| 4933 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4934 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4935 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4936 | if (status < 0) |
| 4937 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4938 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4939 | if (status < 0) |
| 4940 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4941 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 120); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4942 | if (status < 0) |
| 4943 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4944 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4945 | if (status < 0) |
| 4946 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4947 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4948 | if (status < 0) |
| 4949 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4950 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 60); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4951 | if (status < 0) |
| 4952 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4953 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4954 | if (status < 0) |
| 4955 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4956 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4957 | if (status < 0) |
| 4958 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4959 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 64); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4960 | if (status < 0) |
| 4961 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4962 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4963 | if (status < 0) |
| 4964 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4965 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4966 | if (status < 0) |
| 4967 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4968 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4969 | if (status < 0) |
| 4970 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4971 | |
| 4972 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4973 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4974 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4975 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4976 | if (status < 0) |
| 4977 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4978 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4979 | if (status < 0) |
| 4980 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4981 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4982 | if (status < 0) |
| 4983 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4984 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4985 | if (status < 0) |
| 4986 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4987 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 140); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4988 | if (status < 0) |
| 4989 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4990 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4991 | if (status < 0) |
| 4992 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4993 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4994 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4995 | if (status < 0) |
| 4996 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4997 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4998 | if (status < 0) |
| 4999 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5000 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5001 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5002 | if (status < 0) |
| 5003 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5004 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5005 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5006 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5007 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5008 | if (status < 0) |
| 5009 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5010 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 65); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5011 | if (status < 0) |
| 5012 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5013 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5014 | if (status < 0) |
| 5015 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5016 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5017 | if (status < 0) |
| 5018 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5019 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5020 | if (status < 0) |
| 5021 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5022 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5023 | if (status < 0) |
| 5024 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5025 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5026 | if (status < 0) |
| 5027 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5028 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5029 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5030 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | /*============================================================================*/ |
| 5034 | |
| 5035 | /** |
| 5036 | * \brief QAM256 specific setup |
| 5037 | * \param demod: instance of demod. |
| 5038 | * \return DRXStatus_t. |
| 5039 | */ |
| 5040 | static int SetQAM256(struct drxk_state *state) |
| 5041 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5042 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5043 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5044 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5045 | do { |
| 5046 | /* QAM Equalizer Setup */ |
| 5047 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5048 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 11502); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5049 | if (status < 0) |
| 5050 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5051 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12084); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5052 | if (status < 0) |
| 5053 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5054 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 12543); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5055 | if (status < 0) |
| 5056 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5057 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 12931); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5058 | if (status < 0) |
| 5059 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5060 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13629); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5061 | if (status < 0) |
| 5062 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5063 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15385); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5064 | if (status < 0) |
| 5065 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5066 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5067 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5068 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5069 | if (status < 0) |
| 5070 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5071 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5072 | if (status < 0) |
| 5073 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5074 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5075 | if (status < 0) |
| 5076 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5077 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5078 | if (status < 0) |
| 5079 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5080 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5081 | if (status < 0) |
| 5082 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5083 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5084 | if (status < 0) |
| 5085 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5086 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5087 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5088 | if (status < 0) |
| 5089 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5090 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5091 | if (status < 0) |
| 5092 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5093 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5094 | if (status < 0) |
| 5095 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5096 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5097 | /* QAM Slicer Settings */ |
| 5098 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5099 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM256); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5100 | if (status < 0) |
| 5101 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5102 | |
| 5103 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5104 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5105 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5106 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5107 | if (status < 0) |
| 5108 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5109 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5110 | if (status < 0) |
| 5111 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5112 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5113 | if (status < 0) |
| 5114 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5115 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5116 | if (status < 0) |
| 5117 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5118 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5119 | if (status < 0) |
| 5120 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5121 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5122 | if (status < 0) |
| 5123 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5124 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5125 | if (status < 0) |
| 5126 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5127 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5128 | if (status < 0) |
| 5129 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5130 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5131 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5132 | if (status < 0) |
| 5133 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5134 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5135 | if (status < 0) |
| 5136 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5137 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 250); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5138 | if (status < 0) |
| 5139 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5140 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5141 | if (status < 0) |
| 5142 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5143 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5144 | if (status < 0) |
| 5145 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5146 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 125); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5147 | if (status < 0) |
| 5148 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5149 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5150 | if (status < 0) |
| 5151 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5152 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5153 | if (status < 0) |
| 5154 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5155 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5156 | if (status < 0) |
| 5157 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5158 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5159 | if (status < 0) |
| 5160 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5161 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5162 | if (status < 0) |
| 5163 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5164 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5165 | if (status < 0) |
| 5166 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5167 | |
| 5168 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5169 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5170 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5171 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5172 | if (status < 0) |
| 5173 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5174 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5175 | if (status < 0) |
| 5176 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5177 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5178 | if (status < 0) |
| 5179 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5180 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5181 | if (status < 0) |
| 5182 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5183 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 150); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5184 | if (status < 0) |
| 5185 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5186 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 110); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5187 | if (status < 0) |
| 5188 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5189 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5190 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5191 | if (status < 0) |
| 5192 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5193 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5194 | if (status < 0) |
| 5195 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5196 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5197 | if (status < 0) |
| 5198 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5199 | |
| 5200 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5201 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5202 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5203 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5204 | if (status < 0) |
| 5205 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5206 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 74); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5207 | if (status < 0) |
| 5208 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5209 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 18); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5210 | if (status < 0) |
| 5211 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5212 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 13); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5213 | if (status < 0) |
| 5214 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5215 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5216 | if (status < 0) |
| 5217 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5218 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5219 | if (status < 0) |
| 5220 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5221 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5222 | if (status < 0) |
| 5223 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5224 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5225 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5226 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | |
| 5230 | /*============================================================================*/ |
| 5231 | /** |
| 5232 | * \brief Reset QAM block. |
| 5233 | * \param demod: instance of demod. |
| 5234 | * \param channel: pointer to channel data. |
| 5235 | * \return DRXStatus_t. |
| 5236 | */ |
| 5237 | static int QAMResetQAM(struct drxk_state *state) |
| 5238 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5239 | int status; |
| 5240 | u16 cmdResult; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5241 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5242 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5243 | do { |
| 5244 | /* Stop QAM comstate->m_exec */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5245 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5246 | if (status < 0) |
| 5247 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5248 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5249 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 5250 | if (status < 0) |
| 5251 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5252 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5253 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5254 | /* All done, all OK */ |
| 5255 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | /*============================================================================*/ |
| 5259 | |
| 5260 | /** |
| 5261 | * \brief Set QAM symbolrate. |
| 5262 | * \param demod: instance of demod. |
| 5263 | * \param channel: pointer to channel data. |
| 5264 | * \return DRXStatus_t. |
| 5265 | */ |
| 5266 | static int QAMSetSymbolrate(struct drxk_state *state) |
| 5267 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5268 | u32 adcFrequency = 0; |
| 5269 | u32 symbFreq = 0; |
| 5270 | u32 iqmRcRate = 0; |
| 5271 | u16 ratesel = 0; |
| 5272 | u32 lcSymbRate = 0; |
| 5273 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5274 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5275 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5276 | do { |
| 5277 | /* Select & calculate correct IQM rate */ |
| 5278 | adcFrequency = (state->m_sysClockFreq * 1000) / 3; |
| 5279 | ratesel = 0; |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5280 | /* printk(KERN_DEBUG "drxk: SR %d\n", state->param.u.qam.symbol_rate); */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5281 | if (state->param.u.qam.symbol_rate <= 1188750) |
| 5282 | ratesel = 3; |
| 5283 | else if (state->param.u.qam.symbol_rate <= 2377500) |
| 5284 | ratesel = 2; |
| 5285 | else if (state->param.u.qam.symbol_rate <= 4755000) |
| 5286 | ratesel = 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5287 | status = write16(state, IQM_FD_RATESEL__A, ratesel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5288 | if (status < 0) |
| 5289 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5290 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5291 | /* |
| 5292 | IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23) |
| 5293 | */ |
| 5294 | symbFreq = state->param.u.qam.symbol_rate * (1 << ratesel); |
| 5295 | if (symbFreq == 0) { |
| 5296 | /* Divide by zero */ |
| 5297 | return -1; |
| 5298 | } |
| 5299 | iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) + |
| 5300 | (Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) - |
| 5301 | (1 << 23); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5302 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5303 | if (status < 0) |
| 5304 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5305 | state->m_iqmRcRate = iqmRcRate; |
| 5306 | /* |
| 5307 | LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15)) |
| 5308 | */ |
| 5309 | symbFreq = state->param.u.qam.symbol_rate; |
| 5310 | if (adcFrequency == 0) { |
| 5311 | /* Divide by zero */ |
| 5312 | return -1; |
| 5313 | } |
| 5314 | lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) + |
| 5315 | (Frac28a((symbFreq % adcFrequency), adcFrequency) >> |
| 5316 | 16); |
| 5317 | if (lcSymbRate > 511) |
| 5318 | lcSymbRate = 511; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5319 | status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lcSymbRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5320 | if (status < 0) |
| 5321 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5322 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5323 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5324 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | /*============================================================================*/ |
| 5328 | |
| 5329 | /** |
| 5330 | * \brief Get QAM lock status. |
| 5331 | * \param demod: instance of demod. |
| 5332 | * \param channel: pointer to channel data. |
| 5333 | * \return DRXStatus_t. |
| 5334 | */ |
| 5335 | |
| 5336 | static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) |
| 5337 | { |
| 5338 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5339 | u16 Result[2] = { 0, 0 }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5340 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5341 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5342 | status = |
| 5343 | scu_command(state, |
| 5344 | SCU_RAM_COMMAND_STANDARD_QAM | |
| 5345 | SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2, |
| 5346 | Result); |
| 5347 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5348 | printk(KERN_ERR "drxk: %s status = %08x\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5349 | |
| 5350 | if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5351 | /* 0x0000 NOT LOCKED */ |
| 5352 | *pLockStatus = NOT_LOCKED; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5353 | } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5354 | /* 0x4000 DEMOD LOCKED */ |
| 5355 | *pLockStatus = DEMOD_LOCK; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5356 | } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5357 | /* 0x8000 DEMOD + FEC LOCKED (system lock) */ |
| 5358 | *pLockStatus = MPEG_LOCK; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5359 | } else { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5360 | /* 0xC000 NEVER LOCKED */ |
| 5361 | /* (system will never be able to lock to the signal) */ |
| 5362 | /* TODO: check this, intermediate & standard specific lock states are not |
| 5363 | taken into account here */ |
| 5364 | *pLockStatus = NEVER_LOCK; |
| 5365 | } |
| 5366 | return status; |
| 5367 | } |
| 5368 | |
| 5369 | #define QAM_MIRROR__M 0x03 |
| 5370 | #define QAM_MIRROR_NORMAL 0x00 |
| 5371 | #define QAM_MIRRORED 0x01 |
| 5372 | #define QAM_MIRROR_AUTO_ON 0x02 |
| 5373 | #define QAM_LOCKRANGE__M 0x10 |
| 5374 | #define QAM_LOCKRANGE_NORMAL 0x10 |
| 5375 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5376 | static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, |
| 5377 | s32 tunerFreqOffset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5378 | { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5379 | int status = 0; |
| 5380 | u8 parameterLen; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5381 | u16 setEnvParameters[5]; |
| 5382 | u16 setParamParameters[4] = { 0, 0, 0, 0 }; |
| 5383 | u16 cmdResult; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5384 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5385 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5386 | do { |
| 5387 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5388 | STEP 1: reset demodulator |
| 5389 | resets FEC DI and FEC RS |
| 5390 | resets QAM block |
| 5391 | resets SCU variables |
| 5392 | */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5393 | status = write16(state, FEC_DI_COMM_EXEC__A, FEC_DI_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5394 | if (status < 0) |
| 5395 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5396 | status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5397 | if (status < 0) |
| 5398 | break; |
| 5399 | status = QAMResetQAM(state); |
| 5400 | if (status < 0) |
| 5401 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5402 | |
| 5403 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5404 | STEP 2: configure demodulator |
| 5405 | -set env |
| 5406 | -set params; resets IQM,QAM,FEC HW; initializes some SCU variables |
| 5407 | */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5408 | status = QAMSetSymbolrate(state); |
| 5409 | if (status < 0) |
| 5410 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5411 | |
| 5412 | /* Env parameters */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5413 | setEnvParameters[2] = QAM_TOP_ANNEX_A; /* Annex */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5414 | if (state->m_OperationMode == OM_QAM_ITU_C) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5415 | setEnvParameters[2] = QAM_TOP_ANNEX_C; /* Annex */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5416 | setParamParameters[3] |= (QAM_MIRROR_AUTO_ON); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5417 | /* check for LOCKRANGE Extented */ |
| 5418 | /* setParamParameters[3] |= QAM_LOCKRANGE_NORMAL; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5419 | parameterLen = 4; |
| 5420 | |
| 5421 | /* Set params */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5422 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5423 | case QAM_256: |
| 5424 | state->m_Constellation = DRX_CONSTELLATION_QAM256; |
| 5425 | break; |
| 5426 | case QAM_AUTO: |
| 5427 | case QAM_64: |
| 5428 | state->m_Constellation = DRX_CONSTELLATION_QAM64; |
| 5429 | break; |
| 5430 | case QAM_16: |
| 5431 | state->m_Constellation = DRX_CONSTELLATION_QAM16; |
| 5432 | break; |
| 5433 | case QAM_32: |
| 5434 | state->m_Constellation = DRX_CONSTELLATION_QAM32; |
| 5435 | break; |
| 5436 | case QAM_128: |
| 5437 | state->m_Constellation = DRX_CONSTELLATION_QAM128; |
| 5438 | break; |
| 5439 | default: |
| 5440 | status = -EINVAL; |
| 5441 | break; |
| 5442 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5443 | status = status; |
| 5444 | if (status < 0) |
| 5445 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5446 | setParamParameters[0] = state->m_Constellation; /* constellation */ |
| 5447 | setParamParameters[1] = DRXK_QAM_I12_J17; /* interleave mode */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5448 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5449 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 4, setParamParameters, 1, &cmdResult); |
| 5450 | if (status < 0) |
| 5451 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5452 | |
| 5453 | |
| 5454 | /* STEP 3: enable the system in a mode where the ADC provides valid signal |
| 5455 | setup constellation independent registers */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5456 | #if 0 |
| 5457 | status = SetFrequency (channel, tunerFreqOffset)); |
| 5458 | if (status < 0) |
| 5459 | break; |
| 5460 | #endif |
| 5461 | status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); |
| 5462 | if (status < 0) |
| 5463 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5464 | |
| 5465 | /* Setup BER measurement */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5466 | status = SetQAMMeasurement(state, state->m_Constellation, state->param.u. qam.symbol_rate); |
| 5467 | if (status < 0) |
| 5468 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5469 | |
| 5470 | /* Reset default values */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5471 | status = write16(state, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5472 | if (status < 0) |
| 5473 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5474 | status = write16(state, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5475 | if (status < 0) |
| 5476 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5477 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5478 | /* Reset default LC values */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5479 | status = write16(state, QAM_LC_RATE_LIMIT__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5480 | if (status < 0) |
| 5481 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5482 | status = write16(state, QAM_LC_LPF_FACTORP__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5483 | if (status < 0) |
| 5484 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5485 | status = write16(state, QAM_LC_LPF_FACTORI__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5486 | if (status < 0) |
| 5487 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5488 | status = write16(state, QAM_LC_MODE__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5489 | if (status < 0) |
| 5490 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5491 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5492 | status = write16(state, QAM_LC_QUAL_TAB0__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5493 | if (status < 0) |
| 5494 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5495 | status = write16(state, QAM_LC_QUAL_TAB1__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5496 | if (status < 0) |
| 5497 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5498 | status = write16(state, QAM_LC_QUAL_TAB2__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5499 | if (status < 0) |
| 5500 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5501 | status = write16(state, QAM_LC_QUAL_TAB3__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5502 | if (status < 0) |
| 5503 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5504 | status = write16(state, QAM_LC_QUAL_TAB4__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5505 | if (status < 0) |
| 5506 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5507 | status = write16(state, QAM_LC_QUAL_TAB5__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5508 | if (status < 0) |
| 5509 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5510 | status = write16(state, QAM_LC_QUAL_TAB6__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5511 | if (status < 0) |
| 5512 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5513 | status = write16(state, QAM_LC_QUAL_TAB8__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5514 | if (status < 0) |
| 5515 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5516 | status = write16(state, QAM_LC_QUAL_TAB9__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5517 | if (status < 0) |
| 5518 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5519 | status = write16(state, QAM_LC_QUAL_TAB10__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5520 | if (status < 0) |
| 5521 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5522 | status = write16(state, QAM_LC_QUAL_TAB12__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5523 | if (status < 0) |
| 5524 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5525 | status = write16(state, QAM_LC_QUAL_TAB15__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5526 | if (status < 0) |
| 5527 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5528 | status = write16(state, QAM_LC_QUAL_TAB16__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5529 | if (status < 0) |
| 5530 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5531 | status = write16(state, QAM_LC_QUAL_TAB20__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5532 | if (status < 0) |
| 5533 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5534 | status = write16(state, QAM_LC_QUAL_TAB25__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5535 | if (status < 0) |
| 5536 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5537 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5538 | /* Mirroring, QAM-block starting point not inverted */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5539 | status = write16(state, QAM_SY_SP_INV__A, QAM_SY_SP_INV_SPECTRUM_INV_DIS); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5540 | if (status < 0) |
| 5541 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5542 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5543 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5544 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5545 | if (status < 0) |
| 5546 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5547 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5548 | /* STEP 4: constellation specific setup */ |
| 5549 | switch (state->param.u.qam.modulation) { |
| 5550 | case QAM_16: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5551 | status = SetQAM16(state); |
| 5552 | if (status < 0) |
| 5553 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5554 | break; |
| 5555 | case QAM_32: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5556 | status = SetQAM32(state); |
| 5557 | if (status < 0) |
| 5558 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5559 | break; |
| 5560 | case QAM_AUTO: |
| 5561 | case QAM_64: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5562 | status = SetQAM64(state); |
| 5563 | if (status < 0) |
| 5564 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5565 | break; |
| 5566 | case QAM_128: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5567 | status = SetQAM128(state); |
| 5568 | if (status < 0) |
| 5569 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5570 | break; |
| 5571 | case QAM_256: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5572 | status = SetQAM256(state); |
| 5573 | if (status < 0) |
| 5574 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5575 | break; |
| 5576 | default: |
| 5577 | return -1; |
| 5578 | break; |
| 5579 | } /* switch */ |
| 5580 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5581 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5582 | if (status < 0) |
| 5583 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5584 | |
| 5585 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5586 | /* Re-configure MPEG output, requires knowledge of channel bitrate */ |
| 5587 | /* extAttr->currentChannel.constellation = channel->constellation; */ |
| 5588 | /* extAttr->currentChannel.symbolrate = channel->symbolrate; */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5589 | status = MPEGTSDtoSetup(state, state->m_OperationMode); |
| 5590 | if (status < 0) |
| 5591 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5592 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5593 | /* Start processes */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5594 | status = MPEGTSStart(state); |
| 5595 | if (status < 0) |
| 5596 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5597 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5598 | if (status < 0) |
| 5599 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5600 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5601 | if (status < 0) |
| 5602 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5603 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5604 | if (status < 0) |
| 5605 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5606 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5607 | /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5608 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); |
| 5609 | if (status < 0) |
| 5610 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5611 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5612 | /* update global DRXK data container */ |
| 5613 | /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5614 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5615 | /* All done, all OK */ |
| 5616 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5617 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5618 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5619 | printk(KERN_ERR "drxk: %s %d\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5620 | |
| 5621 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5622 | } |
| 5623 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5624 | static int SetQAMStandard(struct drxk_state *state, |
| 5625 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5626 | { |
| 5627 | #ifdef DRXK_QAM_TAPS |
| 5628 | #define DRXK_QAMA_TAPS_SELECT |
| 5629 | #include "drxk_filters.h" |
| 5630 | #undef DRXK_QAMA_TAPS_SELECT |
| 5631 | #else |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5632 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5633 | #endif |
| 5634 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5635 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5636 | do { |
| 5637 | /* added antenna switch */ |
| 5638 | SwitchAntennaToQAM(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5639 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5640 | /* Ensure correct power-up mode */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5641 | status = PowerUpQAM(state); |
| 5642 | if (status < 0) |
| 5643 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5644 | /* Reset QAM block */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5645 | status = QAMResetQAM(state); |
| 5646 | if (status < 0) |
| 5647 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5648 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5649 | /* Setup IQM */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5650 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5651 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5652 | if (status < 0) |
| 5653 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5654 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5655 | if (status < 0) |
| 5656 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5657 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5658 | /* Upload IQM Channel Filter settings by |
| 5659 | boot loader from ROM table */ |
| 5660 | switch (oMode) { |
| 5661 | case OM_QAM_ITU_A: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5662 | status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5663 | if (status < 0) |
| 5664 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5665 | break; |
| 5666 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5667 | status = BLDirectCmd(state, IQM_CF_TAP_RE0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5668 | if (status < 0) |
| 5669 | break; |
| 5670 | status = BLDirectCmd(state, IQM_CF_TAP_IM0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5671 | if (status < 0) |
| 5672 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5673 | break; |
| 5674 | default: |
| 5675 | status = -EINVAL; |
| 5676 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5677 | status = status; |
| 5678 | if (status < 0) |
| 5679 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5680 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5681 | status = write16(state, IQM_CF_OUT_ENA__A, (1 << IQM_CF_OUT_ENA_QAM__B)); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5682 | if (status < 0) |
| 5683 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5684 | status = write16(state, IQM_CF_SYMMETRIC__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5685 | if (status < 0) |
| 5686 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5687 | status = write16(state, IQM_CF_MIDTAP__A, ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B))); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5688 | if (status < 0) |
| 5689 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5690 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5691 | status = write16(state, IQM_RC_STRETCH__A, 21); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5692 | if (status < 0) |
| 5693 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5694 | status = write16(state, IQM_AF_CLP_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5695 | if (status < 0) |
| 5696 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5697 | status = write16(state, IQM_AF_CLP_TH__A, 448); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5698 | if (status < 0) |
| 5699 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5700 | status = write16(state, IQM_AF_SNS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5701 | if (status < 0) |
| 5702 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5703 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5704 | if (status < 0) |
| 5705 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5706 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5707 | status = write16(state, IQM_FS_ADJ_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5708 | if (status < 0) |
| 5709 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5710 | status = write16(state, IQM_RC_ADJ_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5711 | if (status < 0) |
| 5712 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5713 | status = write16(state, IQM_CF_ADJ_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5714 | if (status < 0) |
| 5715 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5716 | status = write16(state, IQM_AF_UPD_SEL__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5717 | if (status < 0) |
| 5718 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5719 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5720 | /* IQM Impulse Noise Processing Unit */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5721 | status = write16(state, IQM_CF_CLP_VAL__A, 500); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5722 | if (status < 0) |
| 5723 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5724 | status = write16(state, IQM_CF_DATATH__A, 1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5725 | if (status < 0) |
| 5726 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5727 | status = write16(state, IQM_CF_BYPASSDET__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5728 | if (status < 0) |
| 5729 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5730 | status = write16(state, IQM_CF_DET_LCT__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5731 | if (status < 0) |
| 5732 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5733 | status = write16(state, IQM_CF_WND_LEN__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5734 | if (status < 0) |
| 5735 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5736 | status = write16(state, IQM_CF_PKDTH__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5737 | if (status < 0) |
| 5738 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5739 | status = write16(state, IQM_AF_INC_BYPASS__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5740 | if (status < 0) |
| 5741 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5742 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5743 | /* turn on IQMAF. Must be done before setAgc**() */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5744 | status = SetIqmAf(state, true); |
| 5745 | if (status < 0) |
| 5746 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5747 | status = write16(state, IQM_AF_START_LOCK__A, 0x01); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5748 | if (status < 0) |
| 5749 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5750 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5751 | /* IQM will not be reset from here, sync ADC and update/init AGC */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5752 | status = ADCSynchronization(state); |
| 5753 | if (status < 0) |
| 5754 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5755 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5756 | /* Set the FSM step period */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5757 | status = write16(state, SCU_RAM_QAM_FSM_STEP_PERIOD__A, 2000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5758 | if (status < 0) |
| 5759 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5760 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5761 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5762 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5763 | if (status < 0) |
| 5764 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5765 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5766 | /* No more resets of the IQM, current standard correctly set => |
| 5767 | now AGCs can be configured. */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5768 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5769 | status = InitAGC(state, true); |
| 5770 | if (status < 0) |
| 5771 | break; |
| 5772 | status = SetPreSaw(state, &(state->m_qamPreSawCfg)); |
| 5773 | if (status < 0) |
| 5774 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5775 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5776 | /* Configure AGC's */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5777 | status = SetAgcRf(state, &(state->m_qamRfAgcCfg), true); |
| 5778 | if (status < 0) |
| 5779 | break; |
| 5780 | status = SetAgcIf(state, &(state->m_qamIfAgcCfg), true); |
| 5781 | if (status < 0) |
| 5782 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5783 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5784 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5785 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5786 | if (status < 0) |
| 5787 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5788 | } while (0); |
| 5789 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | static int WriteGPIO(struct drxk_state *state) |
| 5793 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5794 | int status; |
| 5795 | u16 value = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5796 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5797 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5798 | do { |
| 5799 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5800 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5801 | if (status < 0) |
| 5802 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5803 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5804 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5805 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5806 | if (status < 0) |
| 5807 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5808 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5809 | if (state->m_hasSAWSW) { |
| 5810 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5811 | status = write16(state, SIO_PDR_SMA_TX_CFG__A, state->m_GPIOCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5812 | if (status < 0) |
| 5813 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5814 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5815 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5816 | status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5817 | if (status < 0) |
| 5818 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5819 | if (state->m_GPIO == 0) |
| 5820 | value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ |
| 5821 | else |
| 5822 | value |= 0x8000; /* write one to 15th bit - 1st UIO */ |
| 5823 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5824 | status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5825 | if (status < 0) |
| 5826 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5827 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5828 | } |
| 5829 | /* Write magic word to disable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5830 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5831 | if (status < 0) |
| 5832 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5833 | } while (0); |
| 5834 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | static int SwitchAntennaToQAM(struct drxk_state *state) |
| 5838 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5839 | int status = -1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5840 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5841 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5842 | if (state->m_AntennaSwitchDVBTDVBC != 0) { |
| 5843 | if (state->m_GPIO != state->m_AntennaDVBC) { |
| 5844 | state->m_GPIO = state->m_AntennaDVBC; |
| 5845 | status = WriteGPIO(state); |
| 5846 | } |
| 5847 | } |
| 5848 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | static int SwitchAntennaToDVBT(struct drxk_state *state) |
| 5852 | { |
| 5853 | int status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5854 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5855 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5856 | if (state->m_AntennaSwitchDVBTDVBC != 0) { |
| 5857 | if (state->m_GPIO != state->m_AntennaDVBT) { |
| 5858 | state->m_GPIO = state->m_AntennaDVBT; |
| 5859 | status = WriteGPIO(state); |
| 5860 | } |
| 5861 | } |
| 5862 | return status; |
| 5863 | } |
| 5864 | |
| 5865 | |
| 5866 | static int PowerDownDevice(struct drxk_state *state) |
| 5867 | { |
| 5868 | /* Power down to requested mode */ |
| 5869 | /* Backup some register settings */ |
| 5870 | /* Set pins with possible pull-ups connected to them in input mode */ |
| 5871 | /* Analog power down */ |
| 5872 | /* ADC power down */ |
| 5873 | /* Power down device */ |
| 5874 | int status; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5875 | |
| 5876 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5877 | do { |
| 5878 | if (state->m_bPDownOpenBridge) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5879 | /* Open I2C bridge before power down of DRXK */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5880 | status = ConfigureI2CBridge(state, true); |
| 5881 | if (status < 0) |
| 5882 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5883 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5884 | /* driver 0.9.0 */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5885 | status = DVBTEnableOFDMTokenRing(state, false); |
| 5886 | if (status < 0) |
| 5887 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5888 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5889 | status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_CLOCK); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5890 | if (status < 0) |
| 5891 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5892 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5893 | if (status < 0) |
| 5894 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5895 | state->m_HICfgCtrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5896 | status = HI_CfgCommand(state); |
| 5897 | if (status < 0) |
| 5898 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5899 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5900 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5901 | if (status < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5902 | return -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5903 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5904 | return 0; |
| 5905 | } |
| 5906 | |
| 5907 | static int load_microcode(struct drxk_state *state, char *mc_name) |
| 5908 | { |
| 5909 | const struct firmware *fw = NULL; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5910 | int err = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5911 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5912 | dprintk(1, "\n"); |
| 5913 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5914 | err = request_firmware(&fw, mc_name, state->i2c->dev.parent); |
| 5915 | if (err < 0) { |
| 5916 | printk(KERN_ERR |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5917 | "drxk: Could not load firmware file %s.\n", mc_name); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5918 | printk(KERN_INFO |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5919 | "drxk: Copy %s to your hotplug directory!\n", mc_name); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5920 | return err; |
| 5921 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5922 | err = DownloadMicrocode(state, fw->data, fw->size); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5923 | release_firmware(fw); |
| 5924 | return err; |
| 5925 | } |
| 5926 | |
| 5927 | static int init_drxk(struct drxk_state *state) |
| 5928 | { |
| 5929 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5930 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5931 | u16 driverVersion; |
| 5932 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5933 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5934 | if ((state->m_DrxkState == DRXK_UNINITIALIZED)) { |
| 5935 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5936 | status = PowerUpDevice(state); |
| 5937 | if (status < 0) |
| 5938 | break; |
| 5939 | status = DRXX_Open(state); |
| 5940 | if (status < 0) |
| 5941 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5942 | /* Soft reset of OFDM-, sys- and osc-clockdomain */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5943 | 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); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5944 | if (status < 0) |
| 5945 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5946 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5947 | if (status < 0) |
| 5948 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5949 | /* TODO is this needed, if yes how much delay in worst case scenario */ |
| 5950 | msleep(1); |
| 5951 | state->m_DRXK_A3_PATCH_CODE = true; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5952 | status = GetDeviceCapabilities(state); |
| 5953 | if (status < 0) |
| 5954 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5955 | |
| 5956 | /* Bridge delay, uses oscilator clock */ |
| 5957 | /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */ |
| 5958 | /* SDA brdige delay */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5959 | state->m_HICfgBridgeDelay = |
| 5960 | (u16) ((state->m_oscClockFreq / 1000) * |
| 5961 | HI_I2C_BRIDGE_DELAY) / 1000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5962 | /* Clipping */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5963 | if (state->m_HICfgBridgeDelay > |
| 5964 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) { |
| 5965 | state->m_HICfgBridgeDelay = |
| 5966 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5967 | } |
| 5968 | /* SCL bridge delay, same as SDA for now */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5969 | state->m_HICfgBridgeDelay += |
| 5970 | state->m_HICfgBridgeDelay << |
| 5971 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5972 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5973 | status = InitHI(state); |
| 5974 | if (status < 0) |
| 5975 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5976 | /* disable various processes */ |
| 5977 | #if NOA1ROM |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5978 | if (!(state->m_DRXK_A1_ROM_CODE) |
| 5979 | && !(state->m_DRXK_A2_ROM_CODE)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5980 | #endif |
| 5981 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5982 | status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5983 | if (status < 0) |
| 5984 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | /* disable MPEG port */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5988 | status = MPEGTSDisable(state); |
| 5989 | if (status < 0) |
| 5990 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5991 | |
| 5992 | /* Stop AUD and SCU */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5993 | status = write16(state, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5994 | if (status < 0) |
| 5995 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5996 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5997 | if (status < 0) |
| 5998 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5999 | |
| 6000 | /* enable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6001 | status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_ON); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6002 | if (status < 0) |
| 6003 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6004 | |
| 6005 | /* include boot loader section */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6006 | status = write16(state, SIO_BL_COMM_EXEC__A, SIO_BL_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6007 | if (status < 0) |
| 6008 | break; |
| 6009 | status = BLChainCmd(state, 0, 6, 100); |
| 6010 | if (status < 0) |
| 6011 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6012 | |
| 6013 | #if 0 |
| 6014 | if (state->m_DRXK_A3_PATCH_CODE) |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6015 | status = DownloadMicrocode(state, DRXK_A3_microcode, DRXK_A3_microcode_length); |
| 6016 | if (status < 0) |
| 6017 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6018 | #else |
| 6019 | load_microcode(state, "drxk_a3.mc"); |
| 6020 | #endif |
| 6021 | #if NOA1ROM |
| 6022 | if (state->m_DRXK_A2_PATCH_CODE) |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6023 | status = DownloadMicrocode(state, DRXK_A2_microcode, DRXK_A2_microcode_length); |
| 6024 | if (status < 0) |
| 6025 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6026 | #endif |
| 6027 | /* disable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6028 | status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_OFF); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6029 | if (status < 0) |
| 6030 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6031 | |
| 6032 | /* Run SCU for a little while to initialize microcode version numbers */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6033 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6034 | if (status < 0) |
| 6035 | break; |
| 6036 | status = DRXX_Open(state); |
| 6037 | if (status < 0) |
| 6038 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6039 | /* added for test */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6040 | msleep(30); |
| 6041 | |
| 6042 | powerMode = DRXK_POWER_DOWN_OFDM; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6043 | status = CtrlPowerMode(state, &powerMode); |
| 6044 | if (status < 0) |
| 6045 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6046 | |
| 6047 | /* Stamp driver version number in SCU data RAM in BCD code |
| 6048 | Done to enable field application engineers to retreive drxdriver version |
| 6049 | via I2C from SCU RAM. |
| 6050 | Not using SCU command interface for SCU register access since no |
| 6051 | microcode may be present. |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6052 | */ |
| 6053 | driverVersion = |
| 6054 | (((DRXK_VERSION_MAJOR / 100) % 10) << 12) + |
| 6055 | (((DRXK_VERSION_MAJOR / 10) % 10) << 8) + |
| 6056 | ((DRXK_VERSION_MAJOR % 10) << 4) + |
| 6057 | (DRXK_VERSION_MINOR % 10); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6058 | status = write16(state, SCU_RAM_DRIVER_VER_HI__A, driverVersion); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6059 | if (status < 0) |
| 6060 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6061 | driverVersion = |
| 6062 | (((DRXK_VERSION_PATCH / 1000) % 10) << 12) + |
| 6063 | (((DRXK_VERSION_PATCH / 100) % 10) << 8) + |
| 6064 | (((DRXK_VERSION_PATCH / 10) % 10) << 4) + |
| 6065 | (DRXK_VERSION_PATCH % 10); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6066 | status = write16(state, SCU_RAM_DRIVER_VER_LO__A, driverVersion); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6067 | if (status < 0) |
| 6068 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6069 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6070 | printk(KERN_INFO "DRXK driver version %d.%d.%d\n", |
| 6071 | DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR, |
| 6072 | DRXK_VERSION_PATCH); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6073 | |
| 6074 | /* Dirty fix of default values for ROM/PATCH microcode |
| 6075 | Dirty because this fix makes it impossible to setup suitable values |
| 6076 | before calling DRX_Open. This solution requires changes to RF AGC speed |
| 6077 | to be done via the CTRL function after calling DRX_Open */ |
| 6078 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6079 | /* m_dvbtRfAgcCfg.speed = 3; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6080 | |
| 6081 | /* Reset driver debug flags to 0 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6082 | status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6083 | if (status < 0) |
| 6084 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6085 | /* driver 0.9.0 */ |
| 6086 | /* Setup FEC OC: |
| 6087 | NOTE: No more full FEC resets allowed afterwards!! */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6088 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6089 | if (status < 0) |
| 6090 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6091 | /* MPEGTS functions are still the same */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6092 | status = MPEGTSDtoInit(state); |
| 6093 | if (status < 0) |
| 6094 | break; |
| 6095 | status = MPEGTSStop(state); |
| 6096 | if (status < 0) |
| 6097 | break; |
| 6098 | status = MPEGTSConfigurePolarity(state); |
| 6099 | if (status < 0) |
| 6100 | break; |
| 6101 | status = MPEGTSConfigurePins(state, state->m_enableMPEGOutput); |
| 6102 | if (status < 0) |
| 6103 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6104 | /* added: configure GPIO */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6105 | status = WriteGPIO(state); |
| 6106 | if (status < 0) |
| 6107 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6108 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6109 | state->m_DrxkState = DRXK_STOPPED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6110 | |
| 6111 | if (state->m_bPowerDown) { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6112 | status = PowerDownDevice(state); |
| 6113 | if (status < 0) |
| 6114 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6115 | state->m_DrxkState = DRXK_POWERED_DOWN; |
| 6116 | } else |
| 6117 | state->m_DrxkState = DRXK_STOPPED; |
| 6118 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | return 0; |
| 6122 | } |
| 6123 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6124 | static void drxk_c_release(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6125 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6126 | struct drxk_state *state = fe->demodulator_priv; |
| 6127 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6128 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6129 | kfree(state); |
| 6130 | } |
| 6131 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6132 | static int drxk_c_init(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6133 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6134 | struct drxk_state *state = fe->demodulator_priv; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6135 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6136 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6137 | if (mutex_trylock(&state->ctlock) == 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6138 | return -EBUSY; |
| 6139 | SetOperationMode(state, OM_QAM_ITU_A); |
| 6140 | return 0; |
| 6141 | } |
| 6142 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6143 | static int drxk_c_sleep(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6144 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6145 | struct drxk_state *state = fe->demodulator_priv; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6146 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6147 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6148 | ShutDown(state); |
| 6149 | mutex_unlock(&state->ctlock); |
| 6150 | return 0; |
| 6151 | } |
| 6152 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6153 | static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6154 | { |
| 6155 | struct drxk_state *state = fe->demodulator_priv; |
| 6156 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6157 | dprintk(1, "%s\n", enable ? "enable" : "disable"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6158 | return ConfigureI2CBridge(state, enable ? true : false); |
| 6159 | } |
| 6160 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6161 | static int drxk_set_parameters(struct dvb_frontend *fe, |
| 6162 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6163 | { |
| 6164 | struct drxk_state *state = fe->demodulator_priv; |
| 6165 | u32 IF; |
| 6166 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6167 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6168 | if (fe->ops.i2c_gate_ctrl) |
| 6169 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 6170 | if (fe->ops.tuner_ops.set_params) |
| 6171 | fe->ops.tuner_ops.set_params(fe, p); |
| 6172 | if (fe->ops.i2c_gate_ctrl) |
| 6173 | fe->ops.i2c_gate_ctrl(fe, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6174 | state->param = *p; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6175 | fe->ops.tuner_ops.get_frequency(fe, &IF); |
| 6176 | Start(state, 0, IF); |
| 6177 | |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 6178 | /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6179 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6180 | return 0; |
| 6181 | } |
| 6182 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6183 | static int drxk_c_get_frontend(struct dvb_frontend *fe, |
| 6184 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6185 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6186 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6187 | return 0; |
| 6188 | } |
| 6189 | |
| 6190 | static int drxk_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 6191 | { |
| 6192 | struct drxk_state *state = fe->demodulator_priv; |
| 6193 | u32 stat; |
| 6194 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6195 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6196 | *status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6197 | GetLockStatus(state, &stat, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6198 | if (stat == MPEG_LOCK) |
| 6199 | *status |= 0x1f; |
| 6200 | if (stat == FEC_LOCK) |
| 6201 | *status |= 0x0f; |
| 6202 | if (stat == DEMOD_LOCK) |
| 6203 | *status |= 0x07; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6204 | return 0; |
| 6205 | } |
| 6206 | |
| 6207 | static int drxk_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 6208 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6209 | dprintk(1, "\n"); |
| 6210 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6211 | *ber = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6212 | return 0; |
| 6213 | } |
| 6214 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6215 | static int drxk_read_signal_strength(struct dvb_frontend *fe, |
| 6216 | u16 *strength) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6217 | { |
| 6218 | struct drxk_state *state = fe->demodulator_priv; |
| 6219 | u32 val; |
| 6220 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6221 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6222 | ReadIFAgc(state, &val); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6223 | *strength = val & 0xffff; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6224 | return 0; |
| 6225 | } |
| 6226 | |
| 6227 | static int drxk_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 6228 | { |
| 6229 | struct drxk_state *state = fe->demodulator_priv; |
| 6230 | s32 snr2; |
| 6231 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6232 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6233 | GetSignalToNoise(state, &snr2); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6234 | *snr = snr2 & 0xffff; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6235 | return 0; |
| 6236 | } |
| 6237 | |
| 6238 | static int drxk_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 6239 | { |
| 6240 | struct drxk_state *state = fe->demodulator_priv; |
| 6241 | u16 err; |
| 6242 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6243 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6244 | DVBTQAMGetAccPktErr(state, &err); |
| 6245 | *ucblocks = (u32) err; |
| 6246 | return 0; |
| 6247 | } |
| 6248 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6249 | static int drxk_c_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings |
| 6250 | *sets) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6251 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6252 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6253 | sets->min_delay_ms = 3000; |
| 6254 | sets->max_drift = 0; |
| 6255 | sets->step_size = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
| 6258 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6259 | static void drxk_t_release(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6260 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6261 | #if 0 |
| 6262 | struct drxk_state *state = fe->demodulator_priv; |
| 6263 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6264 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6265 | kfree(state); |
| 6266 | #endif |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6267 | } |
| 6268 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6269 | static int drxk_t_init(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6270 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6271 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6272 | |
| 6273 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6274 | if (mutex_trylock(&state->ctlock) == 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6275 | return -EBUSY; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6276 | SetOperationMode(state, OM_DVBT); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6277 | return 0; |
| 6278 | } |
| 6279 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6280 | static int drxk_t_sleep(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6281 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6282 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6283 | |
| 6284 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6285 | mutex_unlock(&state->ctlock); |
| 6286 | return 0; |
| 6287 | } |
| 6288 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6289 | static int drxk_t_get_frontend(struct dvb_frontend *fe, |
| 6290 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6291 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6292 | dprintk(1, "\n"); |
| 6293 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6294 | return 0; |
| 6295 | } |
| 6296 | |
| 6297 | static struct dvb_frontend_ops drxk_c_ops = { |
| 6298 | .info = { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6299 | .name = "DRXK DVB-C", |
| 6300 | .type = FE_QAM, |
| 6301 | .frequency_stepsize = 62500, |
| 6302 | .frequency_min = 47000000, |
| 6303 | .frequency_max = 862000000, |
| 6304 | .symbol_rate_min = 870000, |
| 6305 | .symbol_rate_max = 11700000, |
| 6306 | .caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 | |
| 6307 | FE_CAN_QAM_128 | FE_CAN_QAM_256 | FE_CAN_FEC_AUTO}, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6308 | .release = drxk_c_release, |
| 6309 | .init = drxk_c_init, |
| 6310 | .sleep = drxk_c_sleep, |
| 6311 | .i2c_gate_ctrl = drxk_gate_ctrl, |
| 6312 | |
| 6313 | .set_frontend = drxk_set_parameters, |
| 6314 | .get_frontend = drxk_c_get_frontend, |
| 6315 | .get_tune_settings = drxk_c_get_tune_settings, |
| 6316 | |
| 6317 | .read_status = drxk_read_status, |
| 6318 | .read_ber = drxk_read_ber, |
| 6319 | .read_signal_strength = drxk_read_signal_strength, |
| 6320 | .read_snr = drxk_read_snr, |
| 6321 | .read_ucblocks = drxk_read_ucblocks, |
| 6322 | }; |
| 6323 | |
| 6324 | static struct dvb_frontend_ops drxk_t_ops = { |
| 6325 | .info = { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6326 | .name = "DRXK DVB-T", |
| 6327 | .type = FE_OFDM, |
| 6328 | .frequency_min = 47125000, |
| 6329 | .frequency_max = 865000000, |
| 6330 | .frequency_stepsize = 166667, |
| 6331 | .frequency_tolerance = 0, |
| 6332 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | |
| 6333 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | |
| 6334 | FE_CAN_FEC_AUTO | |
| 6335 | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
| 6336 | FE_CAN_QAM_AUTO | |
| 6337 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 6338 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 6339 | FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS}, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6340 | .release = drxk_t_release, |
| 6341 | .init = drxk_t_init, |
| 6342 | .sleep = drxk_t_sleep, |
| 6343 | .i2c_gate_ctrl = drxk_gate_ctrl, |
| 6344 | |
| 6345 | .set_frontend = drxk_set_parameters, |
| 6346 | .get_frontend = drxk_t_get_frontend, |
| 6347 | |
| 6348 | .read_status = drxk_read_status, |
| 6349 | .read_ber = drxk_read_ber, |
| 6350 | .read_signal_strength = drxk_read_signal_strength, |
| 6351 | .read_snr = drxk_read_snr, |
| 6352 | .read_ucblocks = drxk_read_ucblocks, |
| 6353 | }; |
| 6354 | |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6355 | struct dvb_frontend *drxk_attach(const struct drxk_config *config, |
| 6356 | struct i2c_adapter *i2c, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6357 | struct dvb_frontend **fe_t) |
| 6358 | { |
| 6359 | struct drxk_state *state = NULL; |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6360 | u8 adr = config->adr; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6361 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6362 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6363 | state = kzalloc(sizeof(struct drxk_state), GFP_KERNEL); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6364 | if (!state) |
| 6365 | return NULL; |
| 6366 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6367 | state->i2c = i2c; |
| 6368 | state->demod_address = adr; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 6369 | state->single_master = config->single_master; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6370 | |
| 6371 | mutex_init(&state->mutex); |
| 6372 | mutex_init(&state->ctlock); |
| 6373 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6374 | memcpy(&state->c_frontend.ops, &drxk_c_ops, |
| 6375 | sizeof(struct dvb_frontend_ops)); |
| 6376 | memcpy(&state->t_frontend.ops, &drxk_t_ops, |
| 6377 | sizeof(struct dvb_frontend_ops)); |
| 6378 | state->c_frontend.demodulator_priv = state; |
| 6379 | state->t_frontend.demodulator_priv = state; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6380 | |
| 6381 | init_state(state); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6382 | if (init_drxk(state) < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6383 | goto error; |
| 6384 | *fe_t = &state->t_frontend; |
| 6385 | return &state->c_frontend; |
| 6386 | |
| 6387 | error: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6388 | printk(KERN_ERR "drxk: not found\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6389 | kfree(state); |
| 6390 | return NULL; |
| 6391 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6392 | EXPORT_SYMBOL(drxk_attach); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6393 | |
| 6394 | MODULE_DESCRIPTION("DRX-K driver"); |
| 6395 | MODULE_AUTHOR("Ralph Metzler"); |
| 6396 | MODULE_LICENSE("GPL"); |