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 | { |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 346 | struct i2c_msg msgs[2] = { |
| 347 | {.addr = adr, .flags = 0, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 348 | .buf = msg, .len = len}, |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 349 | {.addr = adr, .flags = I2C_M_RD, |
| 350 | .buf = answ, .len = alen} |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 351 | }; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 352 | dprintk(3, ":"); |
| 353 | if (debug > 2) { |
| 354 | int i; |
| 355 | for (i = 0; i < len; i++) |
| 356 | printk(KERN_CONT " %02x", msg[i]); |
| 357 | printk(KERN_CONT "\n"); |
| 358 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 359 | if (i2c_transfer(adap, msgs, 2) != 2) { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 360 | if (debug > 2) |
| 361 | printk(KERN_CONT ": ERROR!\n"); |
| 362 | |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 363 | 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] | 364 | return -1; |
| 365 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 366 | if (debug > 2) { |
| 367 | int i; |
| 368 | printk(KERN_CONT ": Read "); |
| 369 | for (i = 0; i < len; i++) |
| 370 | printk(KERN_CONT " %02x", msg[i]); |
| 371 | printk(KERN_CONT "\n"); |
| 372 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 376 | 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] | 377 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 378 | u8 adr = state->demod_address, mm1[4], mm2[2], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 379 | |
| 380 | if (state->single_master) |
| 381 | flags |= 0xC0; |
| 382 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 383 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 384 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 385 | mm1[1] = ((reg >> 16) & 0xFF); |
| 386 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 387 | mm1[3] = ((reg >> 7) & 0xFF); |
| 388 | len = 4; |
| 389 | } else { |
| 390 | mm1[0] = ((reg << 1) & 0xFF); |
| 391 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 392 | len = 2; |
| 393 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 394 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 395 | if (i2c_read(state->i2c, adr, mm1, len, mm2, 2) < 0) |
| 396 | return -1; |
| 397 | if (data) |
| 398 | *data = mm2[0] | (mm2[1] << 8); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 399 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 403 | static int read16(struct drxk_state *state, u32 reg, u16 *data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 404 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 405 | return read16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 406 | } |
| 407 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | u8 adr = state->demod_address, mm1[4], mm2[4], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 411 | |
| 412 | if (state->single_master) |
| 413 | flags |= 0xC0; |
| 414 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 415 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 416 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 417 | mm1[1] = ((reg >> 16) & 0xFF); |
| 418 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 419 | mm1[3] = ((reg >> 7) & 0xFF); |
| 420 | len = 4; |
| 421 | } else { |
| 422 | mm1[0] = ((reg << 1) & 0xFF); |
| 423 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 424 | len = 2; |
| 425 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 426 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 427 | if (i2c_read(state->i2c, adr, mm1, len, mm2, 4) < 0) |
| 428 | return -1; |
| 429 | if (data) |
| 430 | *data = mm2[0] | (mm2[1] << 8) | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 431 | (mm2[2] << 16) | (mm2[3] << 24); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 432 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 436 | static int read32(struct drxk_state *state, u32 reg, u32 *data) |
| 437 | { |
| 438 | return read32_flags(state, reg, data, 0); |
| 439 | } |
| 440 | |
| 441 | 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] | 442 | { |
| 443 | u8 adr = state->demod_address, mm[6], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 444 | |
| 445 | if (state->single_master) |
| 446 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 447 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 448 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 449 | mm[1] = ((reg >> 16) & 0xFF); |
| 450 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 451 | mm[3] = ((reg >> 7) & 0xFF); |
| 452 | len = 4; |
| 453 | } else { |
| 454 | mm[0] = ((reg << 1) & 0xFF); |
| 455 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 456 | len = 2; |
| 457 | } |
| 458 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 459 | mm[len + 1] = (data >> 8) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 460 | |
| 461 | dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg, data, flags); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 462 | if (i2c_write(state->i2c, adr, mm, len + 2) < 0) |
| 463 | return -1; |
| 464 | return 0; |
| 465 | } |
| 466 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 467 | static int write16(struct drxk_state *state, u32 reg, u16 data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 468 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 469 | return write16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 470 | } |
| 471 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 472 | 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] | 473 | { |
| 474 | u8 adr = state->demod_address, mm[8], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 475 | |
| 476 | if (state->single_master) |
| 477 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 478 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 479 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 480 | mm[1] = ((reg >> 16) & 0xFF); |
| 481 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 482 | mm[3] = ((reg >> 7) & 0xFF); |
| 483 | len = 4; |
| 484 | } else { |
| 485 | mm[0] = ((reg << 1) & 0xFF); |
| 486 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 487 | len = 2; |
| 488 | } |
| 489 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 490 | mm[len + 1] = (data >> 8) & 0xff; |
| 491 | mm[len + 2] = (data >> 16) & 0xff; |
| 492 | mm[len + 3] = (data >> 24) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 493 | dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg, data, flags); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 494 | if (i2c_write(state->i2c, adr, mm, len + 4) < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 495 | return -1; |
| 496 | return 0; |
| 497 | } |
| 498 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 499 | static int write32(struct drxk_state *state, u32 reg, u32 data) |
| 500 | { |
| 501 | return write32_flags(state, reg, data, 0); |
| 502 | } |
| 503 | |
| 504 | static int write_block(struct drxk_state *state, u32 Address, |
| 505 | const int BlockSize, const u8 pBlock[]) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 506 | { |
| 507 | int status = 0, BlkSize = BlockSize; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 508 | u8 Flags = 0; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 509 | |
| 510 | if (state->single_master) |
| 511 | Flags |= 0xC0; |
| 512 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 513 | while (BlkSize > 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 514 | int Chunk = BlkSize > state->m_ChunkSize ? |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 515 | state->m_ChunkSize : BlkSize; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 516 | u8 *AdrBuf = &state->Chunk[0]; |
| 517 | u32 AdrLength = 0; |
| 518 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 519 | if (DRXDAP_FASI_LONG_FORMAT(Address) || (Flags != 0)) { |
| 520 | AdrBuf[0] = (((Address << 1) & 0xFF) | 0x01); |
| 521 | AdrBuf[1] = ((Address >> 16) & 0xFF); |
| 522 | AdrBuf[2] = ((Address >> 24) & 0xFF); |
| 523 | AdrBuf[3] = ((Address >> 7) & 0xFF); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 524 | AdrBuf[2] |= Flags; |
| 525 | AdrLength = 4; |
| 526 | if (Chunk == state->m_ChunkSize) |
| 527 | Chunk -= 2; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 528 | } else { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 529 | AdrBuf[0] = ((Address << 1) & 0xFF); |
| 530 | AdrBuf[1] = (((Address >> 16) & 0x0F) | |
| 531 | ((Address >> 18) & 0xF0)); |
| 532 | AdrLength = 2; |
| 533 | } |
| 534 | memcpy(&state->Chunk[AdrLength], pBlock, Chunk); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 535 | dprintk(2, "(0x%08x, 0x%02x)\n", Address, Flags); |
| 536 | if (debug > 1) { |
| 537 | int i; |
| 538 | if (pBlock) |
| 539 | for (i = 0; i < Chunk; i++) |
| 540 | printk(KERN_CONT " %02x", pBlock[i]); |
| 541 | printk(KERN_CONT "\n"); |
| 542 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 543 | status = i2c_write(state->i2c, state->demod_address, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 544 | &state->Chunk[0], Chunk + AdrLength); |
| 545 | if (status < 0) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 546 | printk(KERN_ERR "drxk: %s: i2c write error at addr 0x%02x\n", |
| 547 | __func__, Address); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 548 | break; |
| 549 | } |
| 550 | pBlock += Chunk; |
| 551 | Address += (Chunk >> 1); |
| 552 | BlkSize -= Chunk; |
| 553 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 554 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | #ifndef DRXK_MAX_RETRIES_POWERUP |
| 558 | #define DRXK_MAX_RETRIES_POWERUP 20 |
| 559 | #endif |
| 560 | |
| 561 | int PowerUpDevice(struct drxk_state *state) |
| 562 | { |
| 563 | int status; |
| 564 | u8 data = 0; |
| 565 | u16 retryCount = 0; |
| 566 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 567 | dprintk(1, "\n"); |
| 568 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 569 | status = i2c_read1(state->i2c, state->demod_address, &data); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 570 | if (status < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 571 | do { |
| 572 | data = 0; |
| 573 | if (i2c_write(state->i2c, |
| 574 | state->demod_address, &data, 1) < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 575 | printk(KERN_ERR "drxk: powerup failed\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 576 | msleep(10); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 577 | retryCount++; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 578 | } while (i2c_read1(state->i2c, |
| 579 | state->demod_address, &data) < 0 && |
| 580 | (retryCount < DRXK_MAX_RETRIES_POWERUP)); |
| 581 | if (retryCount >= DRXK_MAX_RETRIES_POWERUP) |
| 582 | return -1; |
| 583 | do { |
| 584 | /* Make sure all clk domains are active */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 585 | 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] | 586 | if (status < 0) |
| 587 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 588 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 589 | if (status < 0) |
| 590 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 591 | /* Enable pll lock tests */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 592 | status = write16(state, SIO_CC_PLL_LOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 593 | if (status < 0) |
| 594 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 595 | state->m_currentPowerMode = DRX_POWER_UP; |
| 596 | } while (0); |
| 597 | return status; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | static int init_state(struct drxk_state *state) |
| 602 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 603 | u32 ulVSBIfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 604 | u32 ulVSBIfAgcOutputLevel = 0; |
| 605 | u32 ulVSBIfAgcMinLevel = 0; |
| 606 | u32 ulVSBIfAgcMaxLevel = 0x7FFF; |
| 607 | u32 ulVSBIfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 608 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 609 | u32 ulVSBRfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 610 | u32 ulVSBRfAgcOutputLevel = 0; |
| 611 | u32 ulVSBRfAgcMinLevel = 0; |
| 612 | u32 ulVSBRfAgcMaxLevel = 0x7FFF; |
| 613 | u32 ulVSBRfAgcSpeed = 3; |
| 614 | u32 ulVSBRfAgcTop = 9500; |
| 615 | u32 ulVSBRfAgcCutOffCurrent = 4000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 616 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 617 | u32 ulATVIfAgcMode = DRXK_AGC_CTRL_AUTO; |
| 618 | u32 ulATVIfAgcOutputLevel = 0; |
| 619 | u32 ulATVIfAgcMinLevel = 0; |
| 620 | u32 ulATVIfAgcMaxLevel = 0; |
| 621 | u32 ulATVIfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 622 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 623 | u32 ulATVRfAgcMode = DRXK_AGC_CTRL_OFF; |
| 624 | u32 ulATVRfAgcOutputLevel = 0; |
| 625 | u32 ulATVRfAgcMinLevel = 0; |
| 626 | u32 ulATVRfAgcMaxLevel = 0; |
| 627 | u32 ulATVRfAgcTop = 9500; |
| 628 | u32 ulATVRfAgcCutOffCurrent = 4000; |
| 629 | u32 ulATVRfAgcSpeed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 630 | |
| 631 | u32 ulQual83 = DEFAULT_MER_83; |
| 632 | u32 ulQual93 = DEFAULT_MER_93; |
| 633 | |
| 634 | u32 ulDVBTStaticTSClock = 1; |
| 635 | u32 ulDVBCStaticTSClock = 1; |
| 636 | |
| 637 | u32 ulMpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 638 | u32 ulDemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
| 639 | |
| 640 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
| 641 | /* io_pad_cfg_mode output mode is drive always */ |
| 642 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
| 643 | u32 ulGPIOCfg = 0x0113; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 644 | u32 ulGPIO = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 645 | u32 ulSerialMode = 1; |
| 646 | u32 ulInvertTSClock = 0; |
| 647 | u32 ulTSDataStrength = DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH; |
| 648 | u32 ulTSClockkStrength = DRXK_MPEG_OUTPUT_CLK_DRIVE_STRENGTH; |
| 649 | u32 ulDVBTBitrate = 50000000; |
| 650 | u32 ulDVBCBitrate = DRXK_QAM_SYMBOLRATE_MAX * 8; |
| 651 | |
| 652 | u32 ulInsertRSByte = 0; |
| 653 | |
| 654 | u32 ulRfMirror = 1; |
| 655 | u32 ulPowerDown = 0; |
| 656 | |
| 657 | u32 ulAntennaDVBT = 1; |
| 658 | u32 ulAntennaDVBC = 0; |
| 659 | u32 ulAntennaSwitchDVBTDVBC = 0; |
| 660 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 661 | dprintk(1, "\n"); |
| 662 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 663 | state->m_hasLNA = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 664 | state->m_hasDVBT = false; |
| 665 | state->m_hasDVBC = false; |
| 666 | state->m_hasATV = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 667 | state->m_hasOOB = false; |
| 668 | state->m_hasAudio = false; |
| 669 | |
| 670 | state->m_ChunkSize = 124; |
| 671 | |
| 672 | state->m_oscClockFreq = 0; |
| 673 | state->m_smartAntInverted = false; |
| 674 | state->m_bPDownOpenBridge = false; |
| 675 | |
| 676 | /* real system clock frequency in kHz */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 677 | state->m_sysClockFreq = 151875; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 678 | /* Timing div, 250ns/Psys */ |
| 679 | /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */ |
| 680 | state->m_HICfgTimingDiv = ((state->m_sysClockFreq / 1000) * |
| 681 | HI_I2C_DELAY) / 1000; |
| 682 | /* Clipping */ |
| 683 | if (state->m_HICfgTimingDiv > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M) |
| 684 | state->m_HICfgTimingDiv = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M; |
| 685 | state->m_HICfgWakeUpKey = (state->demod_address << 1); |
| 686 | /* port/bridge/power down ctrl */ |
| 687 | state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
| 688 | |
| 689 | state->m_bPowerDown = (ulPowerDown != 0); |
| 690 | |
| 691 | state->m_DRXK_A1_PATCH_CODE = false; |
| 692 | state->m_DRXK_A1_ROM_CODE = false; |
| 693 | state->m_DRXK_A2_ROM_CODE = false; |
| 694 | state->m_DRXK_A3_ROM_CODE = false; |
| 695 | state->m_DRXK_A2_PATCH_CODE = false; |
| 696 | state->m_DRXK_A3_PATCH_CODE = false; |
| 697 | |
| 698 | /* Init AGC and PGA parameters */ |
| 699 | /* VSB IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 700 | state->m_vsbIfAgcCfg.ctrlMode = (ulVSBIfAgcMode); |
| 701 | state->m_vsbIfAgcCfg.outputLevel = (ulVSBIfAgcOutputLevel); |
| 702 | state->m_vsbIfAgcCfg.minOutputLevel = (ulVSBIfAgcMinLevel); |
| 703 | state->m_vsbIfAgcCfg.maxOutputLevel = (ulVSBIfAgcMaxLevel); |
| 704 | state->m_vsbIfAgcCfg.speed = (ulVSBIfAgcSpeed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 705 | state->m_vsbPgaCfg = 140; |
| 706 | |
| 707 | /* VSB RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 708 | state->m_vsbRfAgcCfg.ctrlMode = (ulVSBRfAgcMode); |
| 709 | state->m_vsbRfAgcCfg.outputLevel = (ulVSBRfAgcOutputLevel); |
| 710 | state->m_vsbRfAgcCfg.minOutputLevel = (ulVSBRfAgcMinLevel); |
| 711 | state->m_vsbRfAgcCfg.maxOutputLevel = (ulVSBRfAgcMaxLevel); |
| 712 | state->m_vsbRfAgcCfg.speed = (ulVSBRfAgcSpeed); |
| 713 | state->m_vsbRfAgcCfg.top = (ulVSBRfAgcTop); |
| 714 | state->m_vsbRfAgcCfg.cutOffCurrent = (ulVSBRfAgcCutOffCurrent); |
| 715 | state->m_vsbPreSawCfg.reference = 0x07; |
| 716 | state->m_vsbPreSawCfg.usePreSaw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 717 | |
| 718 | state->m_Quality83percent = DEFAULT_MER_83; |
| 719 | state->m_Quality93percent = DEFAULT_MER_93; |
| 720 | if (ulQual93 <= 500 && ulQual83 < ulQual93) { |
| 721 | state->m_Quality83percent = ulQual83; |
| 722 | state->m_Quality93percent = ulQual93; |
| 723 | } |
| 724 | |
| 725 | /* ATV IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 726 | state->m_atvIfAgcCfg.ctrlMode = (ulATVIfAgcMode); |
| 727 | state->m_atvIfAgcCfg.outputLevel = (ulATVIfAgcOutputLevel); |
| 728 | state->m_atvIfAgcCfg.minOutputLevel = (ulATVIfAgcMinLevel); |
| 729 | state->m_atvIfAgcCfg.maxOutputLevel = (ulATVIfAgcMaxLevel); |
| 730 | state->m_atvIfAgcCfg.speed = (ulATVIfAgcSpeed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 731 | |
| 732 | /* ATV RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 733 | state->m_atvRfAgcCfg.ctrlMode = (ulATVRfAgcMode); |
| 734 | state->m_atvRfAgcCfg.outputLevel = (ulATVRfAgcOutputLevel); |
| 735 | state->m_atvRfAgcCfg.minOutputLevel = (ulATVRfAgcMinLevel); |
| 736 | state->m_atvRfAgcCfg.maxOutputLevel = (ulATVRfAgcMaxLevel); |
| 737 | state->m_atvRfAgcCfg.speed = (ulATVRfAgcSpeed); |
| 738 | state->m_atvRfAgcCfg.top = (ulATVRfAgcTop); |
| 739 | state->m_atvRfAgcCfg.cutOffCurrent = (ulATVRfAgcCutOffCurrent); |
| 740 | state->m_atvPreSawCfg.reference = 0x04; |
| 741 | state->m_atvPreSawCfg.usePreSaw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 742 | |
| 743 | |
| 744 | /* DVBT RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 745 | state->m_dvbtRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; |
| 746 | state->m_dvbtRfAgcCfg.outputLevel = 0; |
| 747 | state->m_dvbtRfAgcCfg.minOutputLevel = 0; |
| 748 | state->m_dvbtRfAgcCfg.maxOutputLevel = 0xFFFF; |
| 749 | state->m_dvbtRfAgcCfg.top = 0x2100; |
| 750 | state->m_dvbtRfAgcCfg.cutOffCurrent = 4000; |
| 751 | state->m_dvbtRfAgcCfg.speed = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 752 | |
| 753 | |
| 754 | /* DVBT IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 755 | state->m_dvbtIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; |
| 756 | state->m_dvbtIfAgcCfg.outputLevel = 0; |
| 757 | state->m_dvbtIfAgcCfg.minOutputLevel = 0; |
| 758 | state->m_dvbtIfAgcCfg.maxOutputLevel = 9000; |
| 759 | state->m_dvbtIfAgcCfg.top = 13424; |
| 760 | state->m_dvbtIfAgcCfg.cutOffCurrent = 0; |
| 761 | state->m_dvbtIfAgcCfg.speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 762 | state->m_dvbtIfAgcCfg.FastClipCtrlDelay = 30; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 763 | state->m_dvbtIfAgcCfg.IngainTgtMax = 30000; |
| 764 | /* state->m_dvbtPgaCfg = 140; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 765 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 766 | state->m_dvbtPreSawCfg.reference = 4; |
| 767 | state->m_dvbtPreSawCfg.usePreSaw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 768 | |
| 769 | /* QAM RF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 770 | state->m_qamRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; |
| 771 | state->m_qamRfAgcCfg.outputLevel = 0; |
| 772 | state->m_qamRfAgcCfg.minOutputLevel = 6023; |
| 773 | state->m_qamRfAgcCfg.maxOutputLevel = 27000; |
| 774 | state->m_qamRfAgcCfg.top = 0x2380; |
| 775 | state->m_qamRfAgcCfg.cutOffCurrent = 4000; |
| 776 | state->m_qamRfAgcCfg.speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 777 | |
| 778 | /* QAM IF */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 779 | state->m_qamIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; |
| 780 | state->m_qamIfAgcCfg.outputLevel = 0; |
| 781 | state->m_qamIfAgcCfg.minOutputLevel = 0; |
| 782 | state->m_qamIfAgcCfg.maxOutputLevel = 9000; |
| 783 | state->m_qamIfAgcCfg.top = 0x0511; |
| 784 | state->m_qamIfAgcCfg.cutOffCurrent = 0; |
| 785 | state->m_qamIfAgcCfg.speed = 3; |
| 786 | state->m_qamIfAgcCfg.IngainTgtMax = 5119; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 787 | state->m_qamIfAgcCfg.FastClipCtrlDelay = 50; |
| 788 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 789 | state->m_qamPgaCfg = 140; |
| 790 | state->m_qamPreSawCfg.reference = 4; |
| 791 | state->m_qamPreSawCfg.usePreSaw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 792 | |
| 793 | state->m_OperationMode = OM_NONE; |
| 794 | state->m_DrxkState = DRXK_UNINITIALIZED; |
| 795 | |
| 796 | /* MPEG output configuration */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 797 | state->m_enableMPEGOutput = true; /* If TRUE; enable MPEG ouput */ |
| 798 | state->m_insertRSByte = false; /* If TRUE; insert RS byte */ |
| 799 | state->m_enableParallel = true; /* If TRUE; |
| 800 | parallel out otherwise serial */ |
| 801 | state->m_invertDATA = false; /* If TRUE; invert DATA signals */ |
| 802 | state->m_invertERR = false; /* If TRUE; invert ERR signal */ |
| 803 | state->m_invertSTR = false; /* If TRUE; invert STR signals */ |
| 804 | state->m_invertVAL = false; /* If TRUE; invert VAL signals */ |
| 805 | state->m_invertCLK = (ulInvertTSClock != 0); /* If TRUE; invert CLK signals */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 806 | state->m_DVBTStaticCLK = (ulDVBTStaticTSClock != 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 807 | state->m_DVBCStaticCLK = (ulDVBCStaticTSClock != 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 808 | /* If TRUE; static MPEG clockrate will be used; |
| 809 | otherwise clockrate will adapt to the bitrate of the TS */ |
| 810 | |
| 811 | state->m_DVBTBitrate = ulDVBTBitrate; |
| 812 | state->m_DVBCBitrate = ulDVBCBitrate; |
| 813 | |
| 814 | state->m_TSDataStrength = (ulTSDataStrength & 0x07); |
| 815 | state->m_TSClockkStrength = (ulTSClockkStrength & 0x07); |
| 816 | |
| 817 | /* Maximum bitrate in b/s in case static clockrate is selected */ |
| 818 | state->m_mpegTsStaticBitrate = 19392658; |
| 819 | state->m_disableTEIhandling = false; |
| 820 | |
| 821 | if (ulInsertRSByte) |
| 822 | state->m_insertRSByte = true; |
| 823 | |
| 824 | state->m_MpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 825 | if (ulMpegLockTimeOut < 10000) |
| 826 | state->m_MpegLockTimeOut = ulMpegLockTimeOut; |
| 827 | state->m_DemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
| 828 | if (ulDemodLockTimeOut < 10000) |
| 829 | state->m_DemodLockTimeOut = ulDemodLockTimeOut; |
| 830 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 831 | /* QAM defaults */ |
| 832 | state->m_Constellation = DRX_CONSTELLATION_AUTO; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 833 | state->m_qamInterleaveMode = DRXK_QAM_I12_J17; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 834 | state->m_fecRsPlen = 204 * 8; /* fecRsPlen annex A */ |
| 835 | state->m_fecRsPrescale = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 836 | |
| 837 | state->m_sqiSpeed = DRXK_DVBT_SQI_SPEED_MEDIUM; |
| 838 | state->m_agcFastClipCtrlDelay = 0; |
| 839 | |
| 840 | state->m_GPIOCfg = (ulGPIOCfg); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 841 | state->m_GPIO = (ulGPIO == 0 ? 0 : 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 842 | |
| 843 | state->m_AntennaDVBT = (ulAntennaDVBT == 0 ? 0 : 1); |
| 844 | state->m_AntennaDVBC = (ulAntennaDVBC == 0 ? 0 : 1); |
| 845 | state->m_AntennaSwitchDVBTDVBC = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 846 | (ulAntennaSwitchDVBTDVBC == 0 ? 0 : 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 847 | |
| 848 | state->m_bPowerDown = false; |
| 849 | state->m_currentPowerMode = DRX_POWER_DOWN; |
| 850 | |
| 851 | state->m_enableParallel = (ulSerialMode == 0); |
| 852 | |
| 853 | state->m_rfmirror = (ulRfMirror == 0); |
| 854 | state->m_IfAgcPol = false; |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | static int DRXX_Open(struct drxk_state *state) |
| 859 | { |
| 860 | int status = 0; |
| 861 | u32 jtag = 0; |
| 862 | u16 bid = 0; |
| 863 | u16 key = 0; |
| 864 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 865 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 866 | do { |
| 867 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 868 | 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] | 869 | if (status < 0) |
| 870 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 871 | /* Check device id */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 872 | status = read16(state, SIO_TOP_COMM_KEY__A, &key); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 873 | if (status < 0) |
| 874 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 875 | 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] | 876 | if (status < 0) |
| 877 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 878 | status = read32(state, SIO_TOP_JTAGID_LO__A, &jtag); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 879 | if (status < 0) |
| 880 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 881 | status = read16(state, SIO_PDR_UIO_IN_HI__A, &bid); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 882 | if (status < 0) |
| 883 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 884 | status = write16(state, SIO_TOP_COMM_KEY__A, key); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 885 | if (status < 0) |
| 886 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 887 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 888 | return status; |
| 889 | } |
| 890 | |
| 891 | static int GetDeviceCapabilities(struct drxk_state *state) |
| 892 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 893 | u16 sioPdrOhwCfg = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 894 | u32 sioTopJtagidLo = 0; |
| 895 | int status; |
| 896 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 897 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 898 | do { |
| 899 | /* driver 0.9.0 */ |
| 900 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 901 | 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] | 902 | if (status < 0) |
| 903 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 904 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 905 | status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 906 | if (status < 0) |
| 907 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 908 | status = read16(state, SIO_PDR_OHW_CFG__A, &sioPdrOhwCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 909 | if (status < 0) |
| 910 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 911 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 912 | if (status < 0) |
| 913 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 914 | |
| 915 | switch ((sioPdrOhwCfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { |
| 916 | case 0: |
| 917 | /* ignore (bypass ?) */ |
| 918 | break; |
| 919 | case 1: |
| 920 | /* 27 MHz */ |
| 921 | state->m_oscClockFreq = 27000; |
| 922 | break; |
| 923 | case 2: |
| 924 | /* 20.25 MHz */ |
| 925 | state->m_oscClockFreq = 20250; |
| 926 | break; |
| 927 | case 3: |
| 928 | /* 4 MHz */ |
| 929 | state->m_oscClockFreq = 20250; |
| 930 | break; |
| 931 | default: |
| 932 | return -1; |
| 933 | } |
| 934 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 935 | Determine device capabilities |
| 936 | Based on pinning v14 |
| 937 | */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 938 | status = read32(state, SIO_TOP_JTAGID_LO__A, &sioTopJtagidLo); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 939 | if (status < 0) |
| 940 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 941 | /* driver 0.9.0 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 942 | switch ((sioTopJtagidLo >> 29) & 0xF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 943 | case 0: |
| 944 | state->m_deviceSpin = DRXK_SPIN_A1; |
| 945 | break; |
| 946 | case 2: |
| 947 | state->m_deviceSpin = DRXK_SPIN_A2; |
| 948 | break; |
| 949 | case 3: |
| 950 | state->m_deviceSpin = DRXK_SPIN_A3; |
| 951 | break; |
| 952 | default: |
| 953 | state->m_deviceSpin = DRXK_SPIN_UNKNOWN; |
| 954 | status = -1; |
| 955 | break; |
| 956 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 957 | switch ((sioTopJtagidLo >> 12) & 0xFF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 958 | case 0x13: |
| 959 | /* typeId = DRX3913K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 960 | state->m_hasLNA = false; |
| 961 | state->m_hasOOB = false; |
| 962 | state->m_hasATV = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 963 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 964 | state->m_hasDVBT = true; |
| 965 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 966 | state->m_hasSAWSW = true; |
| 967 | state->m_hasGPIO2 = false; |
| 968 | state->m_hasGPIO1 = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 969 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 970 | break; |
| 971 | case 0x15: |
| 972 | /* typeId = DRX3915K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 973 | state->m_hasLNA = false; |
| 974 | state->m_hasOOB = false; |
| 975 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 976 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 977 | state->m_hasDVBT = true; |
| 978 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 979 | state->m_hasSAWSW = true; |
| 980 | state->m_hasGPIO2 = true; |
| 981 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 982 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 983 | break; |
| 984 | case 0x16: |
| 985 | /* typeId = DRX3916K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 986 | state->m_hasLNA = false; |
| 987 | state->m_hasOOB = false; |
| 988 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 989 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 990 | state->m_hasDVBT = true; |
| 991 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 992 | state->m_hasSAWSW = true; |
| 993 | state->m_hasGPIO2 = true; |
| 994 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 995 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 996 | break; |
| 997 | case 0x18: |
| 998 | /* typeId = DRX3918K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 999 | state->m_hasLNA = false; |
| 1000 | state->m_hasOOB = false; |
| 1001 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1002 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1003 | state->m_hasDVBT = true; |
| 1004 | state->m_hasDVBC = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1005 | state->m_hasSAWSW = true; |
| 1006 | state->m_hasGPIO2 = true; |
| 1007 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1008 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1009 | break; |
| 1010 | case 0x21: |
| 1011 | /* typeId = DRX3921K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1012 | state->m_hasLNA = false; |
| 1013 | state->m_hasOOB = false; |
| 1014 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1015 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1016 | state->m_hasDVBT = true; |
| 1017 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1018 | state->m_hasSAWSW = true; |
| 1019 | state->m_hasGPIO2 = true; |
| 1020 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1021 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1022 | break; |
| 1023 | case 0x23: |
| 1024 | /* typeId = DRX3923K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1025 | state->m_hasLNA = false; |
| 1026 | state->m_hasOOB = false; |
| 1027 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1028 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1029 | state->m_hasDVBT = true; |
| 1030 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1031 | state->m_hasSAWSW = true; |
| 1032 | state->m_hasGPIO2 = true; |
| 1033 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1034 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1035 | break; |
| 1036 | case 0x25: |
| 1037 | /* typeId = DRX3925K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1038 | state->m_hasLNA = false; |
| 1039 | state->m_hasOOB = false; |
| 1040 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1041 | state->m_hasAudio = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1042 | state->m_hasDVBT = true; |
| 1043 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1044 | state->m_hasSAWSW = true; |
| 1045 | state->m_hasGPIO2 = true; |
| 1046 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1047 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1048 | break; |
| 1049 | case 0x26: |
| 1050 | /* typeId = DRX3926K_TYPE_ID */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1051 | state->m_hasLNA = false; |
| 1052 | state->m_hasOOB = false; |
| 1053 | state->m_hasATV = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1054 | state->m_hasAudio = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1055 | state->m_hasDVBT = true; |
| 1056 | state->m_hasDVBC = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1057 | state->m_hasSAWSW = true; |
| 1058 | state->m_hasGPIO2 = true; |
| 1059 | state->m_hasGPIO1 = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1060 | state->m_hasIRQN = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1061 | break; |
| 1062 | default: |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1063 | printk(KERN_ERR "drxk: DeviceID not supported = %02x\n", |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1064 | ((sioTopJtagidLo >> 12) & 0xFF)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1065 | status = -1; |
| 1066 | break; |
| 1067 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1068 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1069 | return status; |
| 1070 | } |
| 1071 | |
| 1072 | static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult) |
| 1073 | { |
| 1074 | int status; |
| 1075 | bool powerdown_cmd; |
| 1076 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1077 | dprintk(1, "\n"); |
| 1078 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1079 | /* Write command */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1080 | status = write16(state, SIO_HI_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1081 | if (status < 0) |
| 1082 | return status; |
| 1083 | if (cmd == SIO_HI_RA_RAM_CMD_RESET) |
| 1084 | msleep(1); |
| 1085 | |
| 1086 | powerdown_cmd = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1087 | (bool) ((cmd == SIO_HI_RA_RAM_CMD_CONFIG) && |
| 1088 | ((state->m_HICfgCtrl) & |
| 1089 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) == |
| 1090 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1091 | if (powerdown_cmd == false) { |
| 1092 | /* Wait until command rdy */ |
| 1093 | u32 retryCount = 0; |
| 1094 | u16 waitCmd; |
| 1095 | |
| 1096 | do { |
| 1097 | msleep(1); |
| 1098 | retryCount += 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1099 | status = read16(state, SIO_HI_RA_RAM_CMD__A, |
| 1100 | &waitCmd); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1101 | } while ((status < 0) && (retryCount < DRXK_MAX_RETRIES) |
| 1102 | && (waitCmd != 0)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1103 | |
| 1104 | if (status == 0) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1105 | status = read16(state, SIO_HI_RA_RAM_RES__A, |
| 1106 | pResult); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1107 | } |
| 1108 | return status; |
| 1109 | } |
| 1110 | |
| 1111 | static int HI_CfgCommand(struct drxk_state *state) |
| 1112 | { |
| 1113 | int status; |
| 1114 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1115 | dprintk(1, "\n"); |
| 1116 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1117 | mutex_lock(&state->mutex); |
| 1118 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1119 | 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] | 1120 | if (status < 0) |
| 1121 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1122 | 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] | 1123 | if (status < 0) |
| 1124 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1125 | 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] | 1126 | if (status < 0) |
| 1127 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1128 | 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] | 1129 | if (status < 0) |
| 1130 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1131 | 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] | 1132 | if (status < 0) |
| 1133 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1134 | 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] | 1135 | if (status < 0) |
| 1136 | break; |
| 1137 | status = HI_Command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0); |
| 1138 | if (status < 0) |
| 1139 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1140 | |
| 1141 | state->m_HICfgCtrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1142 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1143 | mutex_unlock(&state->mutex); |
| 1144 | return status; |
| 1145 | } |
| 1146 | |
| 1147 | static int InitHI(struct drxk_state *state) |
| 1148 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1149 | dprintk(1, "\n"); |
| 1150 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1151 | state->m_HICfgWakeUpKey = (state->demod_address << 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1152 | state->m_HICfgTimeout = 0x96FF; |
| 1153 | /* port/bridge/power down ctrl */ |
| 1154 | state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1155 | return HI_CfgCommand(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) |
| 1159 | { |
| 1160 | int status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1161 | u16 sioPdrMclkCfg = 0; |
| 1162 | u16 sioPdrMdxCfg = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1163 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1164 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1165 | do { |
| 1166 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1167 | 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] | 1168 | if (status < 0) |
| 1169 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1170 | |
| 1171 | /* MPEG TS pad configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1172 | status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1173 | if (status < 0) |
| 1174 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1175 | |
| 1176 | if (mpegEnable == false) { |
| 1177 | /* Set MPEG TS pads to inputmode */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1178 | status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1179 | if (status < 0) |
| 1180 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1181 | status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1182 | if (status < 0) |
| 1183 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1184 | status = write16(state, SIO_PDR_MCLK_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1185 | if (status < 0) |
| 1186 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1187 | status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1188 | if (status < 0) |
| 1189 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1190 | status = write16(state, SIO_PDR_MD0_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1191 | if (status < 0) |
| 1192 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1193 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1194 | if (status < 0) |
| 1195 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1196 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1197 | if (status < 0) |
| 1198 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1199 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1200 | if (status < 0) |
| 1201 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1202 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1203 | if (status < 0) |
| 1204 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1205 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1206 | if (status < 0) |
| 1207 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1208 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1209 | if (status < 0) |
| 1210 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1211 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1212 | if (status < 0) |
| 1213 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1214 | } else { |
| 1215 | /* Enable MPEG output */ |
| 1216 | sioPdrMdxCfg = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1217 | ((state->m_TSDataStrength << |
| 1218 | SIO_PDR_MD0_CFG_DRIVE__B) | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1219 | sioPdrMclkCfg = ((state->m_TSClockkStrength << |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1220 | SIO_PDR_MCLK_CFG_DRIVE__B) | |
| 1221 | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1222 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1223 | status = write16(state, SIO_PDR_MSTRT_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1224 | if (status < 0) |
| 1225 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1226 | status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); /* Disable */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1227 | if (status < 0) |
| 1228 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1229 | status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); /* Disable */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1230 | if (status < 0) |
| 1231 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1232 | if (state->m_enableParallel == true) { |
| 1233 | /* paralel -> enable MD1 to MD7 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1234 | status = write16(state, SIO_PDR_MD1_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1235 | if (status < 0) |
| 1236 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1237 | status = write16(state, SIO_PDR_MD2_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1238 | if (status < 0) |
| 1239 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1240 | status = write16(state, SIO_PDR_MD3_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1241 | if (status < 0) |
| 1242 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1243 | status = write16(state, SIO_PDR_MD4_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1244 | if (status < 0) |
| 1245 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1246 | status = write16(state, SIO_PDR_MD5_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1247 | if (status < 0) |
| 1248 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1249 | status = write16(state, SIO_PDR_MD6_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1250 | if (status < 0) |
| 1251 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1252 | status = write16(state, SIO_PDR_MD7_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1253 | if (status < 0) |
| 1254 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1255 | } else { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1256 | sioPdrMdxCfg = ((state->m_TSDataStrength << |
| 1257 | SIO_PDR_MD0_CFG_DRIVE__B) |
| 1258 | | 0x0003); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1259 | /* serial -> disable MD1 to MD7 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1260 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1261 | if (status < 0) |
| 1262 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1263 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1264 | if (status < 0) |
| 1265 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1266 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1267 | if (status < 0) |
| 1268 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1269 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1270 | if (status < 0) |
| 1271 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1272 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1273 | if (status < 0) |
| 1274 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1275 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1276 | if (status < 0) |
| 1277 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1278 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1279 | if (status < 0) |
| 1280 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1281 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1282 | status = write16(state, SIO_PDR_MCLK_CFG__A, sioPdrMclkCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1283 | if (status < 0) |
| 1284 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1285 | status = write16(state, SIO_PDR_MD0_CFG__A, sioPdrMdxCfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1286 | if (status < 0) |
| 1287 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1288 | } |
| 1289 | /* Enable MB output over MPEG pads and ctl input */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1290 | status = write16(state, SIO_PDR_MON_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1291 | if (status < 0) |
| 1292 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1293 | /* Write nomagic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1294 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1295 | if (status < 0) |
| 1296 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1297 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1298 | return status; |
| 1299 | } |
| 1300 | |
| 1301 | static int MPEGTSDisable(struct drxk_state *state) |
| 1302 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1303 | dprintk(1, "\n"); |
| 1304 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1305 | return MPEGTSConfigurePins(state, false); |
| 1306 | } |
| 1307 | |
| 1308 | static int BLChainCmd(struct drxk_state *state, |
| 1309 | u16 romOffset, u16 nrOfElements, u32 timeOut) |
| 1310 | { |
| 1311 | u16 blStatus = 0; |
| 1312 | int status; |
| 1313 | unsigned long end; |
| 1314 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1315 | dprintk(1, "\n"); |
| 1316 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1317 | mutex_lock(&state->mutex); |
| 1318 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1319 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1320 | if (status < 0) |
| 1321 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1322 | status = write16(state, SIO_BL_CHAIN_ADDR__A, romOffset); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1323 | if (status < 0) |
| 1324 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1325 | status = write16(state, SIO_BL_CHAIN_LEN__A, nrOfElements); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1326 | if (status < 0) |
| 1327 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1328 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1329 | if (status < 0) |
| 1330 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1331 | end = jiffies + msecs_to_jiffies(timeOut); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1332 | |
| 1333 | do { |
| 1334 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1335 | status = read16(state, SIO_BL_STATUS__A, &blStatus); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1336 | if (status < 0) |
| 1337 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1338 | } while ((blStatus == 0x1) && |
| 1339 | ((time_is_after_jiffies(end)))); |
| 1340 | if (blStatus == 0x1) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1341 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1342 | mutex_unlock(&state->mutex); |
| 1343 | return -1; |
| 1344 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1345 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1346 | mutex_unlock(&state->mutex); |
| 1347 | return status; |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | static int DownloadMicrocode(struct drxk_state *state, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1352 | const u8 pMCImage[], u32 Length) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1353 | { |
| 1354 | const u8 *pSrc = pMCImage; |
| 1355 | u16 Flags; |
| 1356 | u16 Drain; |
| 1357 | u32 Address; |
| 1358 | u16 nBlocks; |
| 1359 | u16 BlockSize; |
| 1360 | u16 BlockCRC; |
| 1361 | u32 offset = 0; |
| 1362 | u32 i; |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1363 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1364 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1365 | dprintk(1, "\n"); |
| 1366 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1367 | /* down the drain (we don care about MAGIC_WORD) */ |
| 1368 | Drain = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1369 | pSrc += sizeof(u16); |
| 1370 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1371 | nBlocks = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1372 | pSrc += sizeof(u16); |
| 1373 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1374 | |
| 1375 | for (i = 0; i < nBlocks; i += 1) { |
| 1376 | Address = (pSrc[0] << 24) | (pSrc[1] << 16) | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1377 | (pSrc[2] << 8) | pSrc[3]; |
| 1378 | pSrc += sizeof(u32); |
| 1379 | offset += sizeof(u32); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1380 | |
| 1381 | BlockSize = ((pSrc[0] << 8) | pSrc[1]) * sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1382 | pSrc += sizeof(u16); |
| 1383 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1384 | |
| 1385 | Flags = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1386 | pSrc += sizeof(u16); |
| 1387 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1388 | |
| 1389 | BlockCRC = (pSrc[0] << 8) | pSrc[1]; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1390 | pSrc += sizeof(u16); |
| 1391 | offset += sizeof(u16); |
Mauro Carvalho Chehab | bcd2ebb | 2011-07-09 18:57:54 -0300 | [diff] [blame] | 1392 | |
| 1393 | if (offset + BlockSize > Length) { |
| 1394 | printk(KERN_ERR "drxk: Firmware is corrupted.\n"); |
| 1395 | return -EINVAL; |
| 1396 | } |
| 1397 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1398 | status = write_block(state, Address, BlockSize, pSrc); |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame] | 1399 | if (status < 0) { |
| 1400 | printk(KERN_ERR "drxk: Error %d while loading firmware\n", status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1401 | break; |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame] | 1402 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1403 | pSrc += BlockSize; |
| 1404 | offset += BlockSize; |
| 1405 | } |
| 1406 | return status; |
| 1407 | } |
| 1408 | |
| 1409 | static int DVBTEnableOFDMTokenRing(struct drxk_state *state, bool enable) |
| 1410 | { |
| 1411 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1412 | u16 data = 0; |
| 1413 | u16 desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_ON; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1414 | u16 desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED; |
| 1415 | unsigned long end; |
| 1416 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1417 | dprintk(1, "\n"); |
| 1418 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1419 | if (enable == false) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1420 | desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_OFF; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1421 | desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN; |
| 1422 | } |
| 1423 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1424 | status = (read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1425 | |
| 1426 | if (data == desiredStatus) { |
| 1427 | /* tokenring already has correct status */ |
| 1428 | return status; |
| 1429 | } |
| 1430 | /* Disable/enable dvbt tokenring bridge */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1431 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1432 | write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desiredCtrl); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1433 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1434 | end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1435 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1436 | status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1437 | if (status < 0) |
| 1438 | break; |
| 1439 | } while ((data != desiredStatus) && ((time_is_after_jiffies(end)))); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1440 | if (data != desiredStatus) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1441 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1442 | return -1; |
| 1443 | } |
| 1444 | return status; |
| 1445 | } |
| 1446 | |
| 1447 | static int MPEGTSStop(struct drxk_state *state) |
| 1448 | { |
| 1449 | int status = 0; |
| 1450 | u16 fecOcSncMode = 0; |
| 1451 | u16 fecOcIprMode = 0; |
| 1452 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1453 | dprintk(1, "\n"); |
| 1454 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1455 | do { |
| 1456 | /* Gracefull shutdown (byte boundaries) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1457 | status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1458 | if (status < 0) |
| 1459 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1460 | fecOcSncMode |= FEC_OC_SNC_MODE_SHUTDOWN__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1461 | status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1462 | if (status < 0) |
| 1463 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1464 | |
| 1465 | /* Suppress MCLK during absence of data */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1466 | status = read16(state, FEC_OC_IPR_MODE__A, &fecOcIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1467 | if (status < 0) |
| 1468 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1469 | fecOcIprMode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1470 | status = write16(state, FEC_OC_IPR_MODE__A, fecOcIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1471 | if (status < 0) |
| 1472 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1473 | } while (0); |
| 1474 | return status; |
| 1475 | } |
| 1476 | |
| 1477 | static int scu_command(struct drxk_state *state, |
| 1478 | u16 cmd, u8 parameterLen, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1479 | u16 *parameter, u8 resultLen, u16 *result) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1480 | { |
| 1481 | #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15 |
| 1482 | #error DRXK register mapping no longer compatible with this routine! |
| 1483 | #endif |
| 1484 | u16 curCmd = 0; |
| 1485 | int status; |
| 1486 | unsigned long end; |
| 1487 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1488 | dprintk(1, "\n"); |
| 1489 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1490 | if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) || |
| 1491 | ((resultLen > 0) && (result == NULL))) |
| 1492 | return -1; |
| 1493 | |
| 1494 | mutex_lock(&state->mutex); |
| 1495 | do { |
| 1496 | /* assume that the command register is ready |
| 1497 | since it is checked afterwards */ |
| 1498 | u8 buffer[34]; |
| 1499 | int cnt = 0, ii; |
| 1500 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1501 | for (ii = parameterLen - 1; ii >= 0; ii -= 1) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1502 | buffer[cnt++] = (parameter[ii] & 0xFF); |
| 1503 | buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF); |
| 1504 | } |
| 1505 | buffer[cnt++] = (cmd & 0xFF); |
| 1506 | buffer[cnt++] = ((cmd >> 8) & 0xFF); |
| 1507 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1508 | write_block(state, SCU_RAM_PARAM_0__A - |
| 1509 | (parameterLen - 1), cnt, buffer); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1510 | /* Wait until SCU has processed command */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1511 | end = jiffies + msecs_to_jiffies(DRXK_MAX_WAITTIME); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1512 | do { |
| 1513 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1514 | status = read16(state, SCU_RAM_COMMAND__A, &curCmd); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1515 | if (status < 0) |
| 1516 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1517 | } while (!(curCmd == DRX_SCU_READY) |
| 1518 | && (time_is_after_jiffies(end))); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1519 | if (curCmd != DRX_SCU_READY) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1520 | printk(KERN_ERR "drxk: SCU not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1521 | mutex_unlock(&state->mutex); |
| 1522 | return -1; |
| 1523 | } |
| 1524 | /* read results */ |
| 1525 | if ((resultLen > 0) && (result != NULL)) { |
| 1526 | s16 err; |
| 1527 | int ii; |
| 1528 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1529 | for (ii = resultLen - 1; ii >= 0; ii -= 1) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1530 | status = read16(state, SCU_RAM_PARAM_0__A - ii, &result[ii]); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1531 | if (status < 0) |
| 1532 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /* Check if an error was reported by SCU */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1536 | err = (s16) result[0]; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1537 | |
| 1538 | /* check a few fixed error codes */ |
| 1539 | if (err == SCU_RESULT_UNKSTD) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1540 | printk(KERN_ERR "drxk: SCU_RESULT_UNKSTD\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1541 | mutex_unlock(&state->mutex); |
| 1542 | return -1; |
| 1543 | } else if (err == SCU_RESULT_UNKCMD) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1544 | printk(KERN_ERR "drxk: SCU_RESULT_UNKCMD\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1545 | mutex_unlock(&state->mutex); |
| 1546 | return -1; |
| 1547 | } |
| 1548 | /* here it is assumed that negative means error, |
| 1549 | and positive no error */ |
| 1550 | else if (err < 0) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1551 | printk(KERN_ERR "drxk: %s ERROR\n", __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1552 | mutex_unlock(&state->mutex); |
| 1553 | return -1; |
| 1554 | } |
| 1555 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1556 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1557 | mutex_unlock(&state->mutex); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1558 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 1559 | printk(KERN_ERR "drxk: %s: status = %d\n", __func__, status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1560 | |
| 1561 | return status; |
| 1562 | } |
| 1563 | |
| 1564 | static int SetIqmAf(struct drxk_state *state, bool active) |
| 1565 | { |
| 1566 | u16 data = 0; |
| 1567 | int status; |
| 1568 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1569 | dprintk(1, "\n"); |
| 1570 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1571 | do { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1572 | /* Configure IQM */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1573 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1574 | if (status < 0) |
| 1575 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1576 | if (!active) { |
| 1577 | data |= (IQM_AF_STDBY_STDBY_ADC_STANDBY |
| 1578 | | IQM_AF_STDBY_STDBY_AMP_STANDBY |
| 1579 | | IQM_AF_STDBY_STDBY_PD_STANDBY |
| 1580 | | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1581 | | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY); |
| 1582 | } else { /* active */ |
| 1583 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1584 | data &= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY) |
| 1585 | & (~IQM_AF_STDBY_STDBY_AMP_STANDBY) |
| 1586 | & (~IQM_AF_STDBY_STDBY_PD_STANDBY) |
| 1587 | & (~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY) |
| 1588 | & (~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1589 | ); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1590 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1591 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1592 | if (status < 0) |
| 1593 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1594 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1595 | return status; |
| 1596 | } |
| 1597 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1598 | static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1599 | { |
| 1600 | int status = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1601 | u16 sioCcPwdMode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1602 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1603 | dprintk(1, "\n"); |
| 1604 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1605 | /* Check arguments */ |
| 1606 | if (mode == NULL) |
| 1607 | return -1; |
| 1608 | |
| 1609 | switch (*mode) { |
| 1610 | case DRX_POWER_UP: |
| 1611 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_NONE; |
| 1612 | break; |
| 1613 | case DRXK_POWER_DOWN_OFDM: |
| 1614 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OFDM; |
| 1615 | break; |
| 1616 | case DRXK_POWER_DOWN_CORE: |
| 1617 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_CLOCK; |
| 1618 | break; |
| 1619 | case DRXK_POWER_DOWN_PLL: |
| 1620 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_PLL; |
| 1621 | break; |
| 1622 | case DRX_POWER_DOWN: |
| 1623 | sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OSC; |
| 1624 | break; |
| 1625 | default: |
| 1626 | /* Unknow sleep mode */ |
| 1627 | return -1; |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | /* If already in requested power mode, do nothing */ |
| 1632 | if (state->m_currentPowerMode == *mode) |
| 1633 | return 0; |
| 1634 | |
| 1635 | /* For next steps make sure to start from DRX_POWER_UP mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1636 | if (state->m_currentPowerMode != DRX_POWER_UP) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1637 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1638 | status = PowerUpDevice(state); |
| 1639 | if (status < 0) |
| 1640 | break; |
| 1641 | status = DVBTEnableOFDMTokenRing(state, true); |
| 1642 | if (status < 0) |
| 1643 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1644 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | if (*mode == DRX_POWER_UP) { |
| 1648 | /* Restore analog & pin configuartion */ |
| 1649 | } else { |
| 1650 | /* Power down to requested mode */ |
| 1651 | /* Backup some register settings */ |
| 1652 | /* Set pins with possible pull-ups connected |
| 1653 | to them in input mode */ |
| 1654 | /* Analog power down */ |
| 1655 | /* ADC power down */ |
| 1656 | /* Power down device */ |
| 1657 | /* stop all comm_exec */ |
| 1658 | /* Stop and power down previous standard */ |
| 1659 | do { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1660 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1661 | case OM_DVBT: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1662 | status = MPEGTSStop(state); |
| 1663 | if (status < 0) |
| 1664 | break; |
| 1665 | status = PowerDownDVBT(state, false); |
| 1666 | if (status < 0) |
| 1667 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1668 | break; |
| 1669 | case OM_QAM_ITU_A: |
| 1670 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1671 | status = MPEGTSStop(state); |
| 1672 | if (status < 0) |
| 1673 | break; |
| 1674 | status = PowerDownQAM(state); |
| 1675 | if (status < 0) |
| 1676 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1677 | break; |
| 1678 | default: |
| 1679 | break; |
| 1680 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1681 | status = DVBTEnableOFDMTokenRing(state, false); |
| 1682 | if (status < 0) |
| 1683 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1684 | status = write16(state, SIO_CC_PWD_MODE__A, sioCcPwdMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1685 | if (status < 0) |
| 1686 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1687 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1688 | if (status < 0) |
| 1689 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1690 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1691 | if (*mode != DRXK_POWER_DOWN_OFDM) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1692 | state->m_HICfgCtrl |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1693 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1694 | status = HI_CfgCommand(state); |
| 1695 | if (status < 0) |
| 1696 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1697 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1698 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1699 | } |
| 1700 | state->m_currentPowerMode = *mode; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1701 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode) |
| 1705 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1706 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1707 | u16 cmdResult = 0; |
| 1708 | u16 data = 0; |
| 1709 | int status; |
| 1710 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1711 | dprintk(1, "\n"); |
| 1712 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1713 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1714 | status = read16(state, SCU_COMM_EXEC__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1715 | if (status < 0) |
| 1716 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1717 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 1718 | /* Send OFDM stop command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1719 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 1720 | if (status < 0) |
| 1721 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1722 | /* Send OFDM reset command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1723 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 1724 | if (status < 0) |
| 1725 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | /* Reset datapath for OFDM, processors first */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1729 | 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] | 1730 | if (status < 0) |
| 1731 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1732 | 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] | 1733 | if (status < 0) |
| 1734 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1735 | 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] | 1736 | if (status < 0) |
| 1737 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1738 | |
| 1739 | /* powerdown AFE */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1740 | status = SetIqmAf(state, false); |
| 1741 | if (status < 0) |
| 1742 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1743 | |
| 1744 | /* powerdown to OFDM mode */ |
| 1745 | if (setPowerMode) { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1746 | status = CtrlPowerMode(state, &powerMode); |
| 1747 | if (status < 0) |
| 1748 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1749 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1750 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1751 | return status; |
| 1752 | } |
| 1753 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1754 | static int SetOperationMode(struct drxk_state *state, |
| 1755 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1756 | { |
| 1757 | int status = 0; |
| 1758 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1759 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1760 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1761 | Stop and power down previous standard |
| 1762 | TODO investigate total power down instead of partial |
| 1763 | power down depending on "previous" standard. |
| 1764 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1765 | do { |
| 1766 | /* disable HW lock indicator */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1767 | 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] | 1768 | if (status < 0) |
| 1769 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1770 | |
| 1771 | if (state->m_OperationMode != oMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1772 | switch (state->m_OperationMode) { |
| 1773 | /* OM_NONE was added for start up */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1774 | case OM_NONE: |
| 1775 | break; |
| 1776 | case OM_DVBT: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1777 | status = MPEGTSStop(state); |
| 1778 | if (status < 0) |
| 1779 | break; |
| 1780 | status = PowerDownDVBT(state, true); |
| 1781 | if (status < 0) |
| 1782 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1783 | state->m_OperationMode = OM_NONE; |
| 1784 | break; |
| 1785 | case OM_QAM_ITU_B: |
| 1786 | status = -1; |
| 1787 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1788 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1789 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1790 | status = MPEGTSStop(state); |
| 1791 | if (status < 0) |
| 1792 | break; |
| 1793 | status = PowerDownQAM(state); |
| 1794 | if (status < 0) |
| 1795 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1796 | state->m_OperationMode = OM_NONE; |
| 1797 | break; |
| 1798 | default: |
| 1799 | status = -1; |
| 1800 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1801 | status = status; |
| 1802 | if (status < 0) |
| 1803 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1804 | |
| 1805 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1806 | Power up new standard |
| 1807 | */ |
| 1808 | switch (oMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1809 | case OM_DVBT: |
| 1810 | state->m_OperationMode = oMode; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1811 | status = SetDVBTStandard(state, oMode); |
| 1812 | if (status < 0) |
| 1813 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1814 | break; |
| 1815 | case OM_QAM_ITU_B: |
| 1816 | status = -1; |
| 1817 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1818 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1819 | case OM_QAM_ITU_C: |
| 1820 | state->m_OperationMode = oMode; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1821 | status = SetQAMStandard(state, oMode); |
| 1822 | if (status < 0) |
| 1823 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1824 | break; |
| 1825 | default: |
| 1826 | status = -1; |
| 1827 | } |
| 1828 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1829 | status = status; |
| 1830 | if (status < 0) |
| 1831 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1832 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1833 | return 0; |
| 1834 | } |
| 1835 | |
| 1836 | static int Start(struct drxk_state *state, s32 offsetFreq, |
| 1837 | s32 IntermediateFrequency) |
| 1838 | { |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1839 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1840 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1841 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1842 | do { |
| 1843 | u16 IFreqkHz; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1844 | s32 OffsetkHz = offsetFreq / 1000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1845 | |
| 1846 | if (state->m_DrxkState != DRXK_STOPPED && |
| 1847 | state->m_DrxkState != DRXK_DTV_STARTED) { |
| 1848 | status = -1; |
| 1849 | break; |
| 1850 | } |
| 1851 | state->m_bMirrorFreqSpect = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1852 | (state->param.inversion == INVERSION_ON); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1853 | |
| 1854 | if (IntermediateFrequency < 0) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1855 | state->m_bMirrorFreqSpect = |
| 1856 | !state->m_bMirrorFreqSpect; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1857 | IntermediateFrequency = -IntermediateFrequency; |
| 1858 | } |
| 1859 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1860 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1861 | case OM_QAM_ITU_A: |
| 1862 | case OM_QAM_ITU_C: |
| 1863 | IFreqkHz = (IntermediateFrequency / 1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1864 | status = SetQAM(state, IFreqkHz, OffsetkHz); |
| 1865 | if (status < 0) |
| 1866 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1867 | state->m_DrxkState = DRXK_DTV_STARTED; |
| 1868 | break; |
| 1869 | case OM_DVBT: |
| 1870 | IFreqkHz = (IntermediateFrequency / 1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1871 | status = MPEGTSStop(state); |
| 1872 | if (status < 0) |
| 1873 | break; |
| 1874 | status = SetDVBT(state, IFreqkHz, OffsetkHz); |
| 1875 | if (status < 0) |
| 1876 | break; |
| 1877 | status = DVBTStart(state); |
| 1878 | if (status < 0) |
| 1879 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1880 | state->m_DrxkState = DRXK_DTV_STARTED; |
| 1881 | break; |
| 1882 | default: |
| 1883 | break; |
| 1884 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1885 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1886 | return status; |
| 1887 | } |
| 1888 | |
| 1889 | static int ShutDown(struct drxk_state *state) |
| 1890 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1891 | dprintk(1, "\n"); |
| 1892 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1893 | MPEGTSStop(state); |
| 1894 | return 0; |
| 1895 | } |
| 1896 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1897 | static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus, |
| 1898 | u32 Time) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1899 | { |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1900 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1901 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1902 | dprintk(1, "\n"); |
| 1903 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1904 | if (pLockStatus == NULL) |
| 1905 | return -1; |
| 1906 | |
| 1907 | *pLockStatus = NOT_LOCKED; |
| 1908 | |
| 1909 | /* define the SCU command code */ |
| 1910 | switch (state->m_OperationMode) { |
| 1911 | case OM_QAM_ITU_A: |
| 1912 | case OM_QAM_ITU_B: |
| 1913 | case OM_QAM_ITU_C: |
| 1914 | status = GetQAMLockStatus(state, pLockStatus); |
| 1915 | break; |
| 1916 | case OM_DVBT: |
| 1917 | status = GetDVBTLockStatus(state, pLockStatus); |
| 1918 | break; |
| 1919 | default: |
| 1920 | break; |
| 1921 | } |
| 1922 | return status; |
| 1923 | } |
| 1924 | |
| 1925 | static int MPEGTSStart(struct drxk_state *state) |
| 1926 | { |
| 1927 | int status = 0; |
| 1928 | |
| 1929 | u16 fecOcSncMode = 0; |
| 1930 | |
| 1931 | do { |
| 1932 | /* Allow OC to sync again */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1933 | status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1934 | if (status < 0) |
| 1935 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1936 | fecOcSncMode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1937 | status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1938 | if (status < 0) |
| 1939 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1940 | status = write16(state, FEC_OC_SNC_UNLOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1941 | if (status < 0) |
| 1942 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1943 | } while (0); |
| 1944 | return status; |
| 1945 | } |
| 1946 | |
| 1947 | static int MPEGTSDtoInit(struct drxk_state *state) |
| 1948 | { |
| 1949 | int status = -1; |
| 1950 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1951 | dprintk(1, "\n"); |
| 1952 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1953 | do { |
| 1954 | /* Rate integration settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1955 | status = write16(state, FEC_OC_RCN_CTL_STEP_LO__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1956 | if (status < 0) |
| 1957 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1958 | status = write16(state, FEC_OC_RCN_CTL_STEP_HI__A, 0x000C); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1959 | if (status < 0) |
| 1960 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1961 | status = write16(state, FEC_OC_RCN_GAIN__A, 0x000A); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1962 | if (status < 0) |
| 1963 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1964 | status = write16(state, FEC_OC_AVR_PARM_A__A, 0x0008); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1965 | if (status < 0) |
| 1966 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1967 | status = write16(state, FEC_OC_AVR_PARM_B__A, 0x0006); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1968 | if (status < 0) |
| 1969 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1970 | status = write16(state, FEC_OC_TMD_HI_MARGIN__A, 0x0680); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1971 | if (status < 0) |
| 1972 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1973 | status = write16(state, FEC_OC_TMD_LO_MARGIN__A, 0x0080); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1974 | if (status < 0) |
| 1975 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1976 | status = write16(state, FEC_OC_TMD_COUNT__A, 0x03F4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1977 | if (status < 0) |
| 1978 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1979 | |
| 1980 | /* Additional configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1981 | status = write16(state, FEC_OC_OCR_INVERT__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1982 | if (status < 0) |
| 1983 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1984 | status = write16(state, FEC_OC_SNC_LWM__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1985 | if (status < 0) |
| 1986 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1987 | status = write16(state, FEC_OC_SNC_HWM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1988 | if (status < 0) |
| 1989 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1990 | } while (0); |
| 1991 | return status; |
| 1992 | } |
| 1993 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1994 | static int MPEGTSDtoSetup(struct drxk_state *state, |
| 1995 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1996 | { |
| 1997 | int status = -1; |
| 1998 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1999 | u16 fecOcRegMode = 0; /* FEC_OC_MODE register value */ |
| 2000 | u16 fecOcRegIprMode = 0; /* FEC_OC_IPR_MODE register value */ |
| 2001 | u16 fecOcDtoMode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 2002 | u16 fecOcFctMode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 2003 | u16 fecOcDtoPeriod = 2; /* FEC_OC_IPR_INVERT register value */ |
| 2004 | u16 fecOcDtoBurstLen = 188; /* FEC_OC_IPR_INVERT register value */ |
| 2005 | u32 fecOcRcnCtlRate = 0; /* FEC_OC_IPR_INVERT register value */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2006 | u16 fecOcTmdMode = 0; |
| 2007 | u16 fecOcTmdIntUpdRate = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2008 | u32 maxBitRate = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2009 | bool staticCLK = false; |
| 2010 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2011 | dprintk(1, "\n"); |
| 2012 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2013 | do { |
| 2014 | /* Check insertion of the Reed-Solomon parity bytes */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2015 | status = read16(state, FEC_OC_MODE__A, &fecOcRegMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2016 | if (status < 0) |
| 2017 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2018 | status = read16(state, FEC_OC_IPR_MODE__A, &fecOcRegIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2019 | if (status < 0) |
| 2020 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2021 | fecOcRegMode &= (~FEC_OC_MODE_PARITY__M); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2022 | fecOcRegIprMode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); |
| 2023 | if (state->m_insertRSByte == true) { |
| 2024 | /* enable parity symbol forward */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2025 | fecOcRegMode |= FEC_OC_MODE_PARITY__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2026 | /* MVAL disable during parity bytes */ |
| 2027 | fecOcRegIprMode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M; |
| 2028 | /* TS burst length to 204 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2029 | fecOcDtoBurstLen = 204; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /* Check serial or parrallel output */ |
| 2033 | fecOcRegIprMode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); |
| 2034 | if (state->m_enableParallel == false) { |
| 2035 | /* MPEG data output is serial -> set ipr_mode[0] */ |
| 2036 | fecOcRegIprMode |= FEC_OC_IPR_MODE_SERIAL__M; |
| 2037 | } |
| 2038 | |
| 2039 | switch (oMode) { |
| 2040 | case OM_DVBT: |
| 2041 | maxBitRate = state->m_DVBTBitrate; |
| 2042 | fecOcTmdMode = 3; |
| 2043 | fecOcRcnCtlRate = 0xC00000; |
| 2044 | staticCLK = state->m_DVBTStaticCLK; |
| 2045 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2046 | case OM_QAM_ITU_A: /* fallthrough */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2047 | case OM_QAM_ITU_C: |
| 2048 | fecOcTmdMode = 0x0004; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2049 | fecOcRcnCtlRate = 0xD2B4EE; /* good for >63 Mb/s */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2050 | maxBitRate = state->m_DVBCBitrate; |
| 2051 | staticCLK = state->m_DVBCStaticCLK; |
| 2052 | break; |
| 2053 | default: |
| 2054 | status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2055 | } /* switch (standard) */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2056 | status = status; |
| 2057 | if (status < 0) |
| 2058 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2059 | |
| 2060 | /* Configure DTO's */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2061 | if (staticCLK) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2062 | u32 bitRate = 0; |
| 2063 | |
| 2064 | /* Rational DTO for MCLK source (static MCLK rate), |
| 2065 | Dynamic DTO for optimal grouping |
| 2066 | (avoid intra-packet gaps), |
| 2067 | DTO offset enable to sync TS burst with MSTRT */ |
| 2068 | fecOcDtoMode = (FEC_OC_DTO_MODE_DYNAMIC__M | |
| 2069 | FEC_OC_DTO_MODE_OFFSET_ENABLE__M); |
| 2070 | fecOcFctMode = (FEC_OC_FCT_MODE_RAT_ENA__M | |
| 2071 | FEC_OC_FCT_MODE_VIRT_ENA__M); |
| 2072 | |
| 2073 | /* Check user defined bitrate */ |
| 2074 | bitRate = maxBitRate; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2075 | if (bitRate > 75900000UL) { /* max is 75.9 Mb/s */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2076 | bitRate = 75900000UL; |
| 2077 | } |
| 2078 | /* Rational DTO period: |
| 2079 | dto_period = (Fsys / bitrate) - 2 |
| 2080 | |
| 2081 | Result should be floored, |
| 2082 | to make sure >= requested bitrate |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2083 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2084 | fecOcDtoPeriod = (u16) (((state->m_sysClockFreq) |
| 2085 | * 1000) / bitRate); |
| 2086 | if (fecOcDtoPeriod <= 2) |
| 2087 | fecOcDtoPeriod = 0; |
| 2088 | else |
| 2089 | fecOcDtoPeriod -= 2; |
| 2090 | fecOcTmdIntUpdRate = 8; |
| 2091 | } else { |
| 2092 | /* (commonAttr->staticCLK == false) => dynamic mode */ |
| 2093 | fecOcDtoMode = FEC_OC_DTO_MODE_DYNAMIC__M; |
| 2094 | fecOcFctMode = FEC_OC_FCT_MODE__PRE; |
| 2095 | fecOcTmdIntUpdRate = 5; |
| 2096 | } |
| 2097 | |
| 2098 | /* Write appropriate registers with requested configuration */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2099 | status = write16(state, FEC_OC_DTO_BURST_LEN__A, fecOcDtoBurstLen); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2100 | if (status < 0) |
| 2101 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2102 | status = write16(state, FEC_OC_DTO_PERIOD__A, fecOcDtoPeriod); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2103 | if (status < 0) |
| 2104 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2105 | status = write16(state, FEC_OC_DTO_MODE__A, fecOcDtoMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2106 | if (status < 0) |
| 2107 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2108 | status = write16(state, FEC_OC_FCT_MODE__A, fecOcFctMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2109 | if (status < 0) |
| 2110 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2111 | status = write16(state, FEC_OC_MODE__A, fecOcRegMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2112 | if (status < 0) |
| 2113 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2114 | status = write16(state, FEC_OC_IPR_MODE__A, fecOcRegIprMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2115 | if (status < 0) |
| 2116 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2117 | |
| 2118 | /* Rate integration settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2119 | status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fecOcRcnCtlRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2120 | if (status < 0) |
| 2121 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2122 | status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, fecOcTmdIntUpdRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2123 | if (status < 0) |
| 2124 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2125 | status = write16(state, FEC_OC_TMD_MODE__A, fecOcTmdMode); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2126 | if (status < 0) |
| 2127 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2128 | } while (0); |
| 2129 | return status; |
| 2130 | } |
| 2131 | |
| 2132 | static int MPEGTSConfigurePolarity(struct drxk_state *state) |
| 2133 | { |
| 2134 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2135 | u16 fecOcRegIprInvert = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2136 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2137 | dprintk(1, "\n"); |
| 2138 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2139 | /* Data mask for the output data byte */ |
| 2140 | u16 InvertDataMask = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2141 | FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | |
| 2142 | FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M | |
| 2143 | FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | |
| 2144 | FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2145 | |
| 2146 | /* Control selective inversion of output bits */ |
| 2147 | fecOcRegIprInvert &= (~(InvertDataMask)); |
| 2148 | if (state->m_invertDATA == true) |
| 2149 | fecOcRegIprInvert |= InvertDataMask; |
| 2150 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MERR__M)); |
| 2151 | if (state->m_invertERR == true) |
| 2152 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MERR__M; |
| 2153 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MSTRT__M)); |
| 2154 | if (state->m_invertSTR == true) |
| 2155 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MSTRT__M; |
| 2156 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MVAL__M)); |
| 2157 | if (state->m_invertVAL == true) |
| 2158 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MVAL__M; |
| 2159 | fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); |
| 2160 | if (state->m_invertCLK == true) |
| 2161 | fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MCLK__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2162 | status = write16(state, FEC_OC_IPR_INVERT__A, fecOcRegIprInvert); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2163 | return status; |
| 2164 | } |
| 2165 | |
| 2166 | #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000 |
| 2167 | |
| 2168 | static int SetAgcRf(struct drxk_state *state, |
| 2169 | struct SCfgAgc *pAgcCfg, bool isDTV) |
| 2170 | { |
| 2171 | int status = 0; |
| 2172 | struct SCfgAgc *pIfAgcSettings; |
| 2173 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2174 | dprintk(1, "\n"); |
| 2175 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2176 | if (pAgcCfg == NULL) |
| 2177 | return -1; |
| 2178 | |
| 2179 | do { |
| 2180 | u16 data = 0; |
| 2181 | |
| 2182 | switch (pAgcCfg->ctrlMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2183 | case DRXK_AGC_CTRL_AUTO: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2184 | |
| 2185 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2186 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2187 | if (status < 0) |
| 2188 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2189 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2190 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2191 | if (status < 0) |
| 2192 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2193 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2194 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2195 | if (status < 0) |
| 2196 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2197 | |
| 2198 | /* Enable SCU RF AGC loop */ |
| 2199 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
| 2200 | |
| 2201 | /* Polarity */ |
| 2202 | if (state->m_RfAgcPol) |
| 2203 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2204 | else |
| 2205 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2206 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2207 | if (status < 0) |
| 2208 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2209 | |
| 2210 | /* Set speed (using complementary reduction value) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2211 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2212 | if (status < 0) |
| 2213 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2214 | |
| 2215 | data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; |
| 2216 | data |= (~(pAgcCfg->speed << |
| 2217 | SCU_RAM_AGC_KI_RED_RAGC_RED__B) |
| 2218 | & SCU_RAM_AGC_KI_RED_RAGC_RED__M); |
| 2219 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2220 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2221 | if (status < 0) |
| 2222 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2223 | |
| 2224 | if (IsDVBT(state)) |
| 2225 | pIfAgcSettings = &state->m_dvbtIfAgcCfg; |
| 2226 | else if (IsQAM(state)) |
| 2227 | pIfAgcSettings = &state->m_qamIfAgcCfg; |
| 2228 | else |
| 2229 | pIfAgcSettings = &state->m_atvIfAgcCfg; |
| 2230 | if (pIfAgcSettings == NULL) |
| 2231 | return -1; |
| 2232 | |
| 2233 | /* Set TOP, only if IF-AGC is in AUTO mode */ |
| 2234 | if (pIfAgcSettings->ctrlMode == DRXK_AGC_CTRL_AUTO) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2235 | 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] | 2236 | if (status < 0) |
| 2237 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2238 | |
| 2239 | /* Cut-Off current */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2240 | 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] | 2241 | if (status < 0) |
| 2242 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2243 | |
| 2244 | /* Max. output level */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2245 | status = write16(state, SCU_RAM_AGC_RF_MAX__A, pAgcCfg->maxOutputLevel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2246 | if (status < 0) |
| 2247 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2248 | |
| 2249 | break; |
| 2250 | |
| 2251 | case DRXK_AGC_CTRL_USER: |
| 2252 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2253 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2254 | if (status < 0) |
| 2255 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2256 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2257 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2258 | if (status < 0) |
| 2259 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2260 | |
| 2261 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2262 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2263 | if (status < 0) |
| 2264 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2265 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
| 2266 | if (state->m_RfAgcPol) |
| 2267 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2268 | else |
| 2269 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2270 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2271 | if (status < 0) |
| 2272 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2273 | |
| 2274 | /* SCU c.o.c. to 0, enabling full control range */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2275 | 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] | 2276 | if (status < 0) |
| 2277 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2278 | |
| 2279 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2280 | 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] | 2281 | if (status < 0) |
| 2282 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2283 | break; |
| 2284 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2285 | case DRXK_AGC_CTRL_OFF: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2286 | /* Disable RF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2287 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2288 | if (status < 0) |
| 2289 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2290 | data |= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2291 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2292 | if (status < 0) |
| 2293 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2294 | |
| 2295 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2296 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2297 | if (status < 0) |
| 2298 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2299 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2300 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2301 | if (status < 0) |
| 2302 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2303 | break; |
| 2304 | |
| 2305 | default: |
| 2306 | return -1; |
| 2307 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2308 | } /* switch (agcsettings->ctrlMode) */ |
| 2309 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2310 | return status; |
| 2311 | } |
| 2312 | |
| 2313 | #define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000 |
| 2314 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2315 | static int SetAgcIf(struct drxk_state *state, |
| 2316 | struct SCfgAgc *pAgcCfg, bool isDTV) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2317 | { |
| 2318 | u16 data = 0; |
| 2319 | int status = 0; |
| 2320 | struct SCfgAgc *pRfAgcSettings; |
| 2321 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2322 | dprintk(1, "\n"); |
| 2323 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2324 | do { |
| 2325 | switch (pAgcCfg->ctrlMode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2326 | case DRXK_AGC_CTRL_AUTO: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2327 | |
| 2328 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2329 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2330 | if (status < 0) |
| 2331 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2332 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2333 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2334 | if (status < 0) |
| 2335 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2336 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2337 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2338 | if (status < 0) |
| 2339 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2340 | |
| 2341 | /* Enable SCU IF AGC loop */ |
| 2342 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2343 | |
| 2344 | /* Polarity */ |
| 2345 | if (state->m_IfAgcPol) |
| 2346 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2347 | else |
| 2348 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2349 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2350 | if (status < 0) |
| 2351 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2352 | |
| 2353 | /* Set speed (using complementary reduction value) */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2354 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2355 | if (status < 0) |
| 2356 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2357 | data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; |
| 2358 | data |= (~(pAgcCfg->speed << |
| 2359 | SCU_RAM_AGC_KI_RED_IAGC_RED__B) |
| 2360 | & SCU_RAM_AGC_KI_RED_IAGC_RED__M); |
| 2361 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2362 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2363 | if (status < 0) |
| 2364 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2365 | |
| 2366 | if (IsQAM(state)) |
| 2367 | pRfAgcSettings = &state->m_qamRfAgcCfg; |
| 2368 | else |
| 2369 | pRfAgcSettings = &state->m_atvRfAgcCfg; |
| 2370 | if (pRfAgcSettings == NULL) |
| 2371 | return -1; |
| 2372 | /* Restore TOP */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2373 | 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] | 2374 | if (status < 0) |
| 2375 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2376 | break; |
| 2377 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2378 | case DRXK_AGC_CTRL_USER: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2379 | |
| 2380 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2381 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2382 | if (status < 0) |
| 2383 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2384 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2385 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2386 | if (status < 0) |
| 2387 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2388 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2389 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2390 | if (status < 0) |
| 2391 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2392 | |
| 2393 | /* Disable SCU IF AGC loop */ |
| 2394 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2395 | |
| 2396 | /* Polarity */ |
| 2397 | if (state->m_IfAgcPol) |
| 2398 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2399 | else |
| 2400 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2401 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2402 | if (status < 0) |
| 2403 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2404 | |
| 2405 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2406 | 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] | 2407 | if (status < 0) |
| 2408 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2409 | break; |
| 2410 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2411 | case DRXK_AGC_CTRL_OFF: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2412 | |
| 2413 | /* Disable If AGC DAC */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2414 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2415 | if (status < 0) |
| 2416 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2417 | data |= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2418 | status = write16(state, IQM_AF_STDBY__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2419 | if (status < 0) |
| 2420 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2421 | |
| 2422 | /* Disable SCU IF AGC loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2423 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2424 | if (status < 0) |
| 2425 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2426 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2427 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2428 | if (status < 0) |
| 2429 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2430 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2431 | } /* switch (agcSettingsIf->ctrlMode) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2432 | |
| 2433 | /* always set the top to support |
| 2434 | configurations without if-loop */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2435 | 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] | 2436 | if (status < 0) |
| 2437 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2438 | |
| 2439 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2440 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2441 | return status; |
| 2442 | } |
| 2443 | |
| 2444 | static int ReadIFAgc(struct drxk_state *state, u32 *pValue) |
| 2445 | { |
| 2446 | u16 agcDacLvl; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2447 | int status = read16(state, IQM_AF_AGC_IF__A, &agcDacLvl); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2448 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2449 | dprintk(1, "\n"); |
| 2450 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2451 | *pValue = 0; |
| 2452 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2453 | if (status == 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2454 | u16 Level = 0; |
| 2455 | if (agcDacLvl > DRXK_AGC_DAC_OFFSET) |
| 2456 | Level = agcDacLvl - DRXK_AGC_DAC_OFFSET; |
| 2457 | if (Level < 14000) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2458 | *pValue = (14000 - Level) / 4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2459 | else |
| 2460 | *pValue = 0; |
| 2461 | } |
| 2462 | return status; |
| 2463 | } |
| 2464 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2465 | static int GetQAMSignalToNoise(struct drxk_state *state, |
| 2466 | s32 *pSignalToNoise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2467 | { |
| 2468 | int status = 0; |
| 2469 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2470 | dprintk(1, "\n"); |
| 2471 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2472 | do { |
| 2473 | /* MER calculation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2474 | u16 qamSlErrPower = 0; /* accum. error between |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2475 | raw and sliced symbols */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2476 | u32 qamSlSigPower = 0; /* used for MER, depends of |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2477 | QAM constellation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2478 | u32 qamSlMer = 0; /* QAM MER */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2479 | |
| 2480 | /* get the register value needed for MER */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2481 | status = read16(state, QAM_SL_ERR_POWER__A, &qamSlErrPower); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2482 | if (status < 0) |
| 2483 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2484 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2485 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2486 | case QAM_16: |
| 2487 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM16 << 2; |
| 2488 | break; |
| 2489 | case QAM_32: |
| 2490 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM32 << 2; |
| 2491 | break; |
| 2492 | case QAM_64: |
| 2493 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM64 << 2; |
| 2494 | break; |
| 2495 | case QAM_128: |
| 2496 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM128 << 2; |
| 2497 | break; |
| 2498 | default: |
| 2499 | case QAM_256: |
| 2500 | qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM256 << 2; |
| 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | if (qamSlErrPower > 0) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2505 | qamSlMer = Log10Times100(qamSlSigPower) - |
| 2506 | Log10Times100((u32) qamSlErrPower); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2507 | } |
| 2508 | *pSignalToNoise = qamSlMer; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2509 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2510 | return status; |
| 2511 | } |
| 2512 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2513 | static int GetDVBTSignalToNoise(struct drxk_state *state, |
| 2514 | s32 *pSignalToNoise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2515 | { |
| 2516 | int status = 0; |
| 2517 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2518 | u16 regData = 0; |
| 2519 | u32 EqRegTdSqrErrI = 0; |
| 2520 | u32 EqRegTdSqrErrQ = 0; |
| 2521 | u16 EqRegTdSqrErrExp = 0; |
| 2522 | u16 EqRegTdTpsPwrOfs = 0; |
| 2523 | u16 EqRegTdReqSmbCnt = 0; |
| 2524 | u32 tpsCnt = 0; |
| 2525 | u32 SqrErrIQ = 0; |
| 2526 | u32 a = 0; |
| 2527 | u32 b = 0; |
| 2528 | u32 c = 0; |
| 2529 | u32 iMER = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2530 | u16 transmissionParams = 0; |
| 2531 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2532 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2533 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2534 | 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] | 2535 | if (status < 0) |
| 2536 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2537 | 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] | 2538 | if (status < 0) |
| 2539 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2540 | 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] | 2541 | if (status < 0) |
| 2542 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2543 | 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] | 2544 | if (status < 0) |
| 2545 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2546 | /* Extend SQR_ERR_I operational range */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2547 | EqRegTdSqrErrI = (u32) regData; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2548 | if ((EqRegTdSqrErrExp > 11) && |
| 2549 | (EqRegTdSqrErrI < 0x00000FFFUL)) { |
| 2550 | EqRegTdSqrErrI += 0x00010000UL; |
| 2551 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2552 | 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] | 2553 | if (status < 0) |
| 2554 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2555 | /* Extend SQR_ERR_Q operational range */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2556 | EqRegTdSqrErrQ = (u32) regData; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2557 | if ((EqRegTdSqrErrExp > 11) && |
| 2558 | (EqRegTdSqrErrQ < 0x00000FFFUL)) |
| 2559 | EqRegTdSqrErrQ += 0x00010000UL; |
| 2560 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2561 | status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, &transmissionParams); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2562 | if (status < 0) |
| 2563 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2564 | |
| 2565 | /* Check input data for MER */ |
| 2566 | |
| 2567 | /* MER calculation (in 0.1 dB) without math.h */ |
| 2568 | if ((EqRegTdTpsPwrOfs == 0) || (EqRegTdReqSmbCnt == 0)) |
| 2569 | iMER = 0; |
| 2570 | else if ((EqRegTdSqrErrI + EqRegTdSqrErrQ) == 0) { |
| 2571 | /* No error at all, this must be the HW reset value |
| 2572 | * Apparently no first measurement yet |
| 2573 | * Set MER to 0.0 */ |
| 2574 | iMER = 0; |
| 2575 | } else { |
| 2576 | SqrErrIQ = (EqRegTdSqrErrI + EqRegTdSqrErrQ) << |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2577 | EqRegTdSqrErrExp; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2578 | if ((transmissionParams & |
| 2579 | OFDM_SC_RA_RAM_OP_PARAM_MODE__M) |
| 2580 | == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K) |
| 2581 | tpsCnt = 17; |
| 2582 | else |
| 2583 | tpsCnt = 68; |
| 2584 | |
| 2585 | /* IMER = 100 * log10 (x) |
| 2586 | where x = (EqRegTdTpsPwrOfs^2 * |
| 2587 | EqRegTdReqSmbCnt * tpsCnt)/SqrErrIQ |
| 2588 | |
| 2589 | => IMER = a + b -c |
| 2590 | where a = 100 * log10 (EqRegTdTpsPwrOfs^2) |
| 2591 | b = 100 * log10 (EqRegTdReqSmbCnt * tpsCnt) |
| 2592 | c = 100 * log10 (SqrErrIQ) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2593 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2594 | |
| 2595 | /* log(x) x = 9bits * 9bits->18 bits */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2596 | a = Log10Times100(EqRegTdTpsPwrOfs * |
| 2597 | EqRegTdTpsPwrOfs); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2598 | /* log(x) x = 16bits * 7bits->23 bits */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2599 | b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2600 | /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ |
| 2601 | c = Log10Times100(SqrErrIQ); |
| 2602 | |
| 2603 | iMER = a + b; |
| 2604 | /* No negative MER, clip to zero */ |
| 2605 | if (iMER > c) |
| 2606 | iMER -= c; |
| 2607 | else |
| 2608 | iMER = 0; |
| 2609 | } |
| 2610 | *pSignalToNoise = iMER; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2611 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2612 | |
| 2613 | return status; |
| 2614 | } |
| 2615 | |
| 2616 | static int GetSignalToNoise(struct drxk_state *state, s32 *pSignalToNoise) |
| 2617 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2618 | dprintk(1, "\n"); |
| 2619 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2620 | *pSignalToNoise = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2621 | switch (state->m_OperationMode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2622 | case OM_DVBT: |
| 2623 | return GetDVBTSignalToNoise(state, pSignalToNoise); |
| 2624 | case OM_QAM_ITU_A: |
| 2625 | case OM_QAM_ITU_C: |
| 2626 | return GetQAMSignalToNoise(state, pSignalToNoise); |
| 2627 | default: |
| 2628 | break; |
| 2629 | } |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
| 2633 | #if 0 |
| 2634 | static int GetDVBTQuality(struct drxk_state *state, s32 *pQuality) |
| 2635 | { |
| 2636 | /* SNR Values for quasi errorfree reception rom Nordig 2.2 */ |
| 2637 | int status = 0; |
| 2638 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2639 | dprintk(1, "\n"); |
| 2640 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2641 | static s32 QE_SN[] = { |
| 2642 | 51, /* QPSK 1/2 */ |
| 2643 | 69, /* QPSK 2/3 */ |
| 2644 | 79, /* QPSK 3/4 */ |
| 2645 | 89, /* QPSK 5/6 */ |
| 2646 | 97, /* QPSK 7/8 */ |
| 2647 | 108, /* 16-QAM 1/2 */ |
| 2648 | 131, /* 16-QAM 2/3 */ |
| 2649 | 146, /* 16-QAM 3/4 */ |
| 2650 | 156, /* 16-QAM 5/6 */ |
| 2651 | 160, /* 16-QAM 7/8 */ |
| 2652 | 165, /* 64-QAM 1/2 */ |
| 2653 | 187, /* 64-QAM 2/3 */ |
| 2654 | 202, /* 64-QAM 3/4 */ |
| 2655 | 216, /* 64-QAM 5/6 */ |
| 2656 | 225, /* 64-QAM 7/8 */ |
| 2657 | }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2658 | |
| 2659 | *pQuality = 0; |
| 2660 | |
| 2661 | do { |
| 2662 | s32 SignalToNoise = 0; |
| 2663 | u16 Constellation = 0; |
| 2664 | u16 CodeRate = 0; |
| 2665 | u32 SignalToNoiseRel; |
| 2666 | u32 BERQuality; |
| 2667 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2668 | status = GetDVBTSignalToNoise(state, &SignalToNoise); |
| 2669 | if (status < 0) |
| 2670 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2671 | status = read16(state, OFDM_EQ_TOP_TD_TPS_CONST__A, &Constellation); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2672 | if (status < 0) |
| 2673 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2674 | Constellation &= OFDM_EQ_TOP_TD_TPS_CONST__M; |
| 2675 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2676 | 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] | 2677 | if (status < 0) |
| 2678 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2679 | CodeRate &= OFDM_EQ_TOP_TD_TPS_CODE_HP__M; |
| 2680 | |
| 2681 | if (Constellation > OFDM_EQ_TOP_TD_TPS_CONST_64QAM || |
| 2682 | CodeRate > OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8) |
| 2683 | break; |
| 2684 | SignalToNoiseRel = SignalToNoise - |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2685 | QE_SN[Constellation * 5 + CodeRate]; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2686 | BERQuality = 100; |
| 2687 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2688 | if (SignalToNoiseRel < -70) |
| 2689 | *pQuality = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2690 | else if (SignalToNoiseRel < 30) |
| 2691 | *pQuality = ((SignalToNoiseRel + 70) * |
| 2692 | BERQuality) / 100; |
| 2693 | else |
| 2694 | *pQuality = BERQuality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2695 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2696 | return 0; |
| 2697 | }; |
| 2698 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2699 | static int GetDVBCQuality(struct drxk_state *state, s32 *pQuality) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2700 | { |
| 2701 | int status = 0; |
| 2702 | *pQuality = 0; |
| 2703 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2704 | dprintk(1, "\n"); |
| 2705 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2706 | do { |
| 2707 | u32 SignalToNoise = 0; |
| 2708 | u32 BERQuality = 100; |
| 2709 | u32 SignalToNoiseRel = 0; |
| 2710 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2711 | status = GetQAMSignalToNoise(state, &SignalToNoise); |
| 2712 | if (status < 0) |
| 2713 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2714 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2715 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2716 | case QAM_16: |
| 2717 | SignalToNoiseRel = SignalToNoise - 200; |
| 2718 | break; |
| 2719 | case QAM_32: |
| 2720 | SignalToNoiseRel = SignalToNoise - 230; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2721 | break; /* Not in NorDig */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2722 | case QAM_64: |
| 2723 | SignalToNoiseRel = SignalToNoise - 260; |
| 2724 | break; |
| 2725 | case QAM_128: |
| 2726 | SignalToNoiseRel = SignalToNoise - 290; |
| 2727 | break; |
| 2728 | default: |
| 2729 | case QAM_256: |
| 2730 | SignalToNoiseRel = SignalToNoise - 320; |
| 2731 | break; |
| 2732 | } |
| 2733 | |
| 2734 | if (SignalToNoiseRel < -70) |
| 2735 | *pQuality = 0; |
| 2736 | else if (SignalToNoiseRel < 30) |
| 2737 | *pQuality = ((SignalToNoiseRel + 70) * |
| 2738 | BERQuality) / 100; |
| 2739 | else |
| 2740 | *pQuality = BERQuality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2741 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2742 | |
| 2743 | return status; |
| 2744 | } |
| 2745 | |
| 2746 | static int GetQuality(struct drxk_state *state, s32 *pQuality) |
| 2747 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2748 | dprintk(1, "\n"); |
| 2749 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2750 | switch (state->m_OperationMode) { |
| 2751 | case OM_DVBT: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2752 | return GetDVBTQuality(state, pQuality); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2753 | case OM_QAM_ITU_A: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2754 | return GetDVBCQuality(state, pQuality); |
| 2755 | default: |
| 2756 | break; |
| 2757 | } |
| 2758 | |
| 2759 | return 0; |
| 2760 | } |
| 2761 | #endif |
| 2762 | |
| 2763 | /* Free data ram in SIO HI */ |
| 2764 | #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040 |
| 2765 | #define SIO_HI_RA_RAM_USR_END__A 0x420060 |
| 2766 | |
| 2767 | #define DRXK_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A) |
| 2768 | #define DRXK_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7) |
| 2769 | #define DRXK_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ |
| 2770 | #define DRXK_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE |
| 2771 | |
| 2772 | #define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr) >> 22) & 0x3F) |
| 2773 | #define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F) |
| 2774 | #define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF) |
| 2775 | |
| 2776 | static int ConfigureI2CBridge(struct drxk_state *state, bool bEnableBridge) |
| 2777 | { |
| 2778 | int status; |
| 2779 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2780 | dprintk(1, "\n"); |
| 2781 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2782 | if (state->m_DrxkState == DRXK_UNINITIALIZED) |
| 2783 | return -1; |
| 2784 | if (state->m_DrxkState == DRXK_POWERED_DOWN) |
| 2785 | return -1; |
| 2786 | |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame^] | 2787 | if (state->no_i2c_bridge) |
| 2788 | return 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2789 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2790 | 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] | 2791 | if (status < 0) |
| 2792 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2793 | if (bEnableBridge) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2794 | 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] | 2795 | if (status < 0) |
| 2796 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2797 | } else { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2798 | 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] | 2799 | if (status < 0) |
| 2800 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2801 | } |
| 2802 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2803 | status = HI_Command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0); |
| 2804 | if (status < 0) |
| 2805 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2806 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2807 | return status; |
| 2808 | } |
| 2809 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2810 | static int SetPreSaw(struct drxk_state *state, |
| 2811 | struct SCfgPreSaw *pPreSawCfg) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2812 | { |
| 2813 | int status; |
| 2814 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2815 | dprintk(1, "\n"); |
| 2816 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2817 | if ((pPreSawCfg == NULL) |
| 2818 | || (pPreSawCfg->reference > IQM_AF_PDREF__M)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2819 | return -1; |
| 2820 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2821 | status = write16(state, IQM_AF_PDREF__A, pPreSawCfg->reference); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2822 | return status; |
| 2823 | } |
| 2824 | |
| 2825 | static int BLDirectCmd(struct drxk_state *state, u32 targetAddr, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2826 | u16 romOffset, u16 nrOfElements, u32 timeOut) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2827 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2828 | u16 blStatus = 0; |
| 2829 | u16 offset = (u16) ((targetAddr >> 0) & 0x00FFFF); |
| 2830 | u16 blockbank = (u16) ((targetAddr >> 16) & 0x000FFF); |
| 2831 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2832 | unsigned long end; |
| 2833 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2834 | dprintk(1, "\n"); |
| 2835 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2836 | mutex_lock(&state->mutex); |
| 2837 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2838 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_DIRECT); |
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_HDR__A, blockbank); |
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_TGT_ADDR__A, offset); |
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_ADDR__A, romOffset); |
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_SRC_LEN__A, nrOfElements); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2851 | if (status < 0) |
| 2852 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2853 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2854 | if (status < 0) |
| 2855 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2856 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2857 | end = jiffies + msecs_to_jiffies(timeOut); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2858 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2859 | status = read16(state, SIO_BL_STATUS__A, &blStatus); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2860 | if (status < 0) |
| 2861 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2862 | } while ((blStatus == 0x1) && time_is_after_jiffies(end)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2863 | if (blStatus == 0x1) { |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 2864 | printk(KERN_ERR "drxk: SIO not ready\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2865 | mutex_unlock(&state->mutex); |
| 2866 | return -1; |
| 2867 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2868 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2869 | mutex_unlock(&state->mutex); |
| 2870 | return status; |
| 2871 | |
| 2872 | } |
| 2873 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2874 | static int ADCSyncMeasurement(struct drxk_state *state, u16 *count) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2875 | { |
| 2876 | u16 data = 0; |
| 2877 | int status; |
| 2878 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2879 | dprintk(1, "\n"); |
| 2880 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2881 | do { |
| 2882 | /* Start measurement */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2883 | 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] | 2884 | if (status < 0) |
| 2885 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2886 | status = write16(state, IQM_AF_START_LOCK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2887 | if (status < 0) |
| 2888 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2889 | |
| 2890 | *count = 0; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2891 | status = read16(state, IQM_AF_PHASE0__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2892 | if (status < 0) |
| 2893 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2894 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2895 | *count = *count + 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2896 | status = read16(state, IQM_AF_PHASE1__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2897 | if (status < 0) |
| 2898 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2899 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2900 | *count = *count + 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2901 | status = read16(state, IQM_AF_PHASE2__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2902 | if (status < 0) |
| 2903 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2904 | if (data == 127) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2905 | *count = *count + 1; |
| 2906 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2907 | return status; |
| 2908 | } |
| 2909 | |
| 2910 | static int ADCSynchronization(struct drxk_state *state) |
| 2911 | { |
| 2912 | u16 count = 0; |
| 2913 | int status; |
| 2914 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2915 | dprintk(1, "\n"); |
| 2916 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2917 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2918 | status = ADCSyncMeasurement(state, &count); |
| 2919 | if (status < 0) |
| 2920 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2921 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2922 | if (count == 1) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2923 | /* Try sampling on a diffrent edge */ |
| 2924 | u16 clkNeg = 0; |
| 2925 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2926 | status = read16(state, IQM_AF_CLKNEG__A, &clkNeg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2927 | if (status < 0) |
| 2928 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2929 | if ((clkNeg | IQM_AF_CLKNEG_CLKNEGDATA__M) == |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2930 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) { |
| 2931 | clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2932 | clkNeg |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2933 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2934 | } else { |
| 2935 | clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2936 | clkNeg |= |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2937 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2938 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2939 | status = write16(state, IQM_AF_CLKNEG__A, clkNeg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2940 | if (status < 0) |
| 2941 | break; |
| 2942 | status = ADCSyncMeasurement(state, &count); |
| 2943 | if (status < 0) |
| 2944 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | if (count < 2) |
| 2948 | status = -1; |
| 2949 | } while (0); |
| 2950 | return status; |
| 2951 | } |
| 2952 | |
| 2953 | static int SetFrequencyShifter(struct drxk_state *state, |
| 2954 | u16 intermediateFreqkHz, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2955 | s32 tunerFreqOffset, bool isDTV) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2956 | { |
| 2957 | bool selectPosImage = false; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2958 | u32 rfFreqResidual = tunerFreqOffset; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2959 | u32 fmFrequencyShift = 0; |
| 2960 | bool tunerMirror = !state->m_bMirrorFreqSpect; |
| 2961 | u32 adcFreq; |
| 2962 | bool adcFlip; |
| 2963 | int status; |
| 2964 | u32 ifFreqActual; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2965 | u32 samplingFrequency = (u32) (state->m_sysClockFreq / 3); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2966 | u32 frequencyShift; |
| 2967 | bool imageToSelect; |
| 2968 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2969 | dprintk(1, "\n"); |
| 2970 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2971 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2972 | Program frequency shifter |
| 2973 | No need to account for mirroring on RF |
| 2974 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2975 | if (isDTV) { |
| 2976 | if ((state->m_OperationMode == OM_QAM_ITU_A) || |
| 2977 | (state->m_OperationMode == OM_QAM_ITU_C) || |
| 2978 | (state->m_OperationMode == OM_DVBT)) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2979 | selectPosImage = true; |
| 2980 | else |
| 2981 | selectPosImage = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2982 | } |
| 2983 | if (tunerMirror) |
| 2984 | /* tuner doesn't mirror */ |
| 2985 | ifFreqActual = intermediateFreqkHz + |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2986 | rfFreqResidual + fmFrequencyShift; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2987 | else |
| 2988 | /* tuner mirrors */ |
| 2989 | ifFreqActual = intermediateFreqkHz - |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2990 | rfFreqResidual - fmFrequencyShift; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2991 | if (ifFreqActual > samplingFrequency / 2) { |
| 2992 | /* adc mirrors */ |
| 2993 | adcFreq = samplingFrequency - ifFreqActual; |
| 2994 | adcFlip = true; |
| 2995 | } else { |
| 2996 | /* adc doesn't mirror */ |
| 2997 | adcFreq = ifFreqActual; |
| 2998 | adcFlip = false; |
| 2999 | } |
| 3000 | |
| 3001 | frequencyShift = adcFreq; |
| 3002 | imageToSelect = state->m_rfmirror ^ tunerMirror ^ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3003 | adcFlip ^ selectPosImage; |
| 3004 | state->m_IqmFsRateOfs = |
| 3005 | Frac28a((frequencyShift), samplingFrequency); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3006 | |
| 3007 | if (imageToSelect) |
| 3008 | state->m_IqmFsRateOfs = ~state->m_IqmFsRateOfs + 1; |
| 3009 | |
| 3010 | /* Program frequency shifter with tuner offset compensation */ |
| 3011 | /* frequencyShift += tunerFreqOffset; TODO */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3012 | status = write32(state, IQM_FS_RATE_OFS_LO__A, |
| 3013 | state->m_IqmFsRateOfs); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3014 | return status; |
| 3015 | } |
| 3016 | |
| 3017 | static int InitAGC(struct drxk_state *state, bool isDTV) |
| 3018 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3019 | u16 ingainTgt = 0; |
| 3020 | u16 ingainTgtMin = 0; |
| 3021 | u16 ingainTgtMax = 0; |
| 3022 | u16 clpCyclen = 0; |
| 3023 | u16 clpSumMin = 0; |
| 3024 | u16 clpDirTo = 0; |
| 3025 | u16 snsSumMin = 0; |
| 3026 | u16 snsSumMax = 0; |
| 3027 | u16 clpSumMax = 0; |
| 3028 | u16 snsDirTo = 0; |
| 3029 | u16 kiInnergainMin = 0; |
| 3030 | u16 ifIaccuHiTgt = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3031 | u16 ifIaccuHiTgtMin = 0; |
| 3032 | u16 ifIaccuHiTgtMax = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3033 | u16 data = 0; |
| 3034 | u16 fastClpCtrlDelay = 0; |
| 3035 | u16 clpCtrlMode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3036 | int status = 0; |
| 3037 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3038 | dprintk(1, "\n"); |
| 3039 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3040 | do { |
| 3041 | /* Common settings */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3042 | snsSumMax = 1023; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3043 | ifIaccuHiTgtMin = 2047; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3044 | clpCyclen = 500; |
| 3045 | clpSumMax = 1023; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3046 | |
| 3047 | if (IsQAM(state)) { |
| 3048 | /* Standard specific settings */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3049 | clpSumMin = 8; |
| 3050 | clpDirTo = (u16) -9; |
| 3051 | clpCtrlMode = 0; |
| 3052 | snsSumMin = 8; |
| 3053 | snsDirTo = (u16) -9; |
| 3054 | kiInnergainMin = (u16) -1030; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3055 | } else |
| 3056 | status = -1; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3057 | status = (status); |
| 3058 | if (status < 0) |
| 3059 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3060 | if (IsQAM(state)) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3061 | ifIaccuHiTgtMax = 0x2380; |
| 3062 | ifIaccuHiTgt = 0x2380; |
| 3063 | ingainTgtMin = 0x0511; |
| 3064 | ingainTgt = 0x0511; |
| 3065 | ingainTgtMax = 5119; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3066 | fastClpCtrlDelay = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3067 | state->m_qamIfAgcCfg.FastClipCtrlDelay; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3068 | } else { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3069 | ifIaccuHiTgtMax = 0x1200; |
| 3070 | ifIaccuHiTgt = 0x1200; |
| 3071 | ingainTgtMin = 13424; |
| 3072 | ingainTgt = 13424; |
| 3073 | ingainTgtMax = 30000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3074 | fastClpCtrlDelay = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3075 | state->m_dvbtIfAgcCfg.FastClipCtrlDelay; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3076 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3077 | 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] | 3078 | if (status < 0) |
| 3079 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3080 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3081 | status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clpCtrlMode); |
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__A, ingainTgt); |
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_MIN__A, ingainTgtMin); |
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_INGAIN_TGT_MAX__A, ingainTgtMax); |
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_MIN__A, ifIaccuHiTgtMin); |
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_TGT_MAX__A, ifIaccuHiTgtMax); |
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_HI__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_IF_IACCU_LO__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_HI__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_RF_IACCU_LO__A, 0); |
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_CLP_SUM_MAX__A, clpSumMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3112 | if (status < 0) |
| 3113 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3114 | status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, snsSumMax); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3115 | if (status < 0) |
| 3116 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3117 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3118 | status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, kiInnergainMin); |
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_IF_IACCU_HI_TGT__A, ifIaccuHiTgt); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3122 | if (status < 0) |
| 3123 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3124 | status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clpCyclen); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3125 | if (status < 0) |
| 3126 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3127 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3128 | 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] | 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_RF_SNS_DEV_MIN__A, (u16) -1023); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3132 | if (status < 0) |
| 3133 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3134 | 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] | 3135 | if (status < 0) |
| 3136 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3137 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3138 | status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20); |
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_CLP_SUM_MIN__A, clpSumMin); |
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_SNS_SUM_MIN__A, snsSumMin); |
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_CLP_DIR_TO__A, clpDirTo); |
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_SNS_DIR_TO__A, snsDirTo); |
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_MINGAIN__A, 0x7fff); |
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_MAXGAIN__A, 0x0); |
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_MIN__A, 0x0117); |
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_KI_MAX__A, 0x0657); |
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_SUM__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_CYCCNT__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_WD__A, 0); |
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_CLP_DIR_STP__A, 1); |
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_SUM__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_CYCCNT__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_WD__A, 0); |
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_DIR_STP__A, 1); |
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_SNS_CYCLEN__A, 500); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3190 | if (status < 0) |
| 3191 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3192 | status = write16(state, SCU_RAM_AGC_KI_CYCLEN__A, 500); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3193 | if (status < 0) |
| 3194 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3195 | |
| 3196 | /* Initialize inner-loop KI gain factors */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3197 | status = read16(state, SCU_RAM_AGC_KI__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3198 | if (status < 0) |
| 3199 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3200 | if (IsQAM(state)) { |
| 3201 | data = 0x0657; |
| 3202 | data &= ~SCU_RAM_AGC_KI_RF__M; |
| 3203 | data |= (DRXK_KI_RAGC_QAM << SCU_RAM_AGC_KI_RF__B); |
| 3204 | data &= ~SCU_RAM_AGC_KI_IF__M; |
| 3205 | data |= (DRXK_KI_IAGC_QAM << SCU_RAM_AGC_KI_IF__B); |
| 3206 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3207 | status = write16(state, SCU_RAM_AGC_KI__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3208 | if (status < 0) |
| 3209 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3210 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3211 | return status; |
| 3212 | } |
| 3213 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3214 | static int DVBTQAMGetAccPktErr(struct drxk_state *state, u16 *packetErr) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3215 | { |
| 3216 | int status; |
| 3217 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3218 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3219 | do { |
| 3220 | if (packetErr == NULL) { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3221 | status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3222 | if (status < 0) |
| 3223 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3224 | } else { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3225 | status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, packetErr); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3226 | if (status < 0) |
| 3227 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3228 | } |
| 3229 | } while (0); |
| 3230 | return status; |
| 3231 | } |
| 3232 | |
| 3233 | static int DVBTScCommand(struct drxk_state *state, |
| 3234 | u16 cmd, u16 subcmd, |
| 3235 | u16 param0, u16 param1, u16 param2, |
| 3236 | u16 param3, u16 param4) |
| 3237 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3238 | u16 curCmd = 0; |
| 3239 | u16 errCode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3240 | u16 retryCnt = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3241 | u16 scExec = 0; |
| 3242 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3243 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3244 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3245 | status = read16(state, OFDM_SC_COMM_EXEC__A, &scExec); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3246 | if (scExec != 1) { |
| 3247 | /* SC is not running */ |
| 3248 | return -1; |
| 3249 | } |
| 3250 | |
| 3251 | /* Wait until sc is ready to receive command */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3252 | retryCnt = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3253 | do { |
| 3254 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3255 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3256 | retryCnt++; |
| 3257 | } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); |
| 3258 | if (retryCnt >= DRXK_MAX_RETRIES) |
| 3259 | return -1; |
| 3260 | /* Write sub-command */ |
| 3261 | switch (cmd) { |
| 3262 | /* All commands using sub-cmd */ |
| 3263 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3264 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3265 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3266 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3267 | write16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, subcmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3268 | break; |
| 3269 | default: |
| 3270 | /* Do nothing */ |
| 3271 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3272 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3273 | |
| 3274 | /* Write needed parameters and the command */ |
| 3275 | switch (cmd) { |
| 3276 | /* All commands using 5 parameters */ |
| 3277 | /* All commands using 4 parameters */ |
| 3278 | /* All commands using 3 parameters */ |
| 3279 | /* All commands using 2 parameters */ |
| 3280 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3281 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3282 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3283 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3284 | write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3285 | /* All commands using 1 parameters */ |
| 3286 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3287 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3288 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3289 | write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3290 | /* All commands using 0 parameters */ |
| 3291 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
| 3292 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3293 | /* Write command */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3294 | status = write16(state, OFDM_SC_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3295 | break; |
| 3296 | default: |
| 3297 | /* Unknown command */ |
| 3298 | return -EINVAL; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3299 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3300 | |
| 3301 | /* Wait until sc is ready processing command */ |
| 3302 | retryCnt = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3303 | do { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3304 | msleep(1); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3305 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3306 | retryCnt++; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3307 | } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3308 | if (retryCnt >= DRXK_MAX_RETRIES) |
| 3309 | return -1; |
| 3310 | |
| 3311 | /* Check for illegal cmd */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3312 | status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &errCode); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3313 | if (errCode == 0xFFFF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3314 | /* illegal command */ |
| 3315 | return -EINVAL; |
| 3316 | } |
| 3317 | |
| 3318 | /* Retreive results parameters from SC */ |
| 3319 | switch (cmd) { |
| 3320 | /* All commands yielding 5 results */ |
| 3321 | /* All commands yielding 4 results */ |
| 3322 | /* All commands yielding 3 results */ |
| 3323 | /* All commands yielding 2 results */ |
| 3324 | /* All commands yielding 1 result */ |
| 3325 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
| 3326 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3327 | status = |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3328 | read16(state, OFDM_SC_RA_RAM_PARAM0__A, &(param0)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3329 | /* All commands yielding 0 results */ |
| 3330 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3331 | case OFDM_SC_RA_RAM_CMD_SET_TIMER: |
| 3332 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3333 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3334 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
| 3335 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3336 | break; |
| 3337 | default: |
| 3338 | /* Unknown command */ |
| 3339 | return -EINVAL; |
| 3340 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3341 | } /* switch (cmd->cmd) */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3342 | return status; |
| 3343 | } |
| 3344 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3345 | static int PowerUpDVBT(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3346 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3347 | enum DRXPowerMode powerMode = DRX_POWER_UP; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3348 | int status; |
| 3349 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3350 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3351 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3352 | status = CtrlPowerMode(state, &powerMode); |
| 3353 | if (status < 0) |
| 3354 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3355 | } while (0); |
| 3356 | return status; |
| 3357 | } |
| 3358 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3359 | static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3360 | { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3361 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3362 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3363 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3364 | if (*enabled == true) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3365 | status = write16(state, IQM_CF_BYPASSDET__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3366 | else |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3367 | status = write16(state, IQM_CF_BYPASSDET__A, 1); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3368 | |
| 3369 | return status; |
| 3370 | } |
| 3371 | |
| 3372 | #define DEFAULT_FR_THRES_8K 4000 |
| 3373 | static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled) |
| 3374 | { |
| 3375 | |
| 3376 | int status; |
| 3377 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3378 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3379 | if (*enabled == true) { |
| 3380 | /* write mask to 1 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3381 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3382 | DEFAULT_FR_THRES_8K); |
| 3383 | } else { |
| 3384 | /* write mask to 0 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3385 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | return status; |
| 3389 | } |
| 3390 | |
| 3391 | static int DVBTCtrlSetEchoThreshold(struct drxk_state *state, |
| 3392 | struct DRXKCfgDvbtEchoThres_t *echoThres) |
| 3393 | { |
| 3394 | u16 data = 0; |
| 3395 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3396 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3397 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3398 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3399 | status = read16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3400 | if (status < 0) |
| 3401 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3402 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3403 | switch (echoThres->fftMode) { |
| 3404 | case DRX_FFTMODE_2K: |
| 3405 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M; |
| 3406 | data |= |
| 3407 | ((echoThres->threshold << |
| 3408 | OFDM_SC_RA_RAM_ECHO_THRES_2K__B) |
| 3409 | & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M)); |
| 3410 | break; |
| 3411 | case DRX_FFTMODE_8K: |
| 3412 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M; |
| 3413 | data |= |
| 3414 | ((echoThres->threshold << |
| 3415 | OFDM_SC_RA_RAM_ECHO_THRES_8K__B) |
| 3416 | & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M)); |
| 3417 | break; |
| 3418 | default: |
| 3419 | return -1; |
| 3420 | break; |
| 3421 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3422 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3423 | status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3424 | if (status < 0) |
| 3425 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3426 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3427 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3428 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3432 | enum DRXKCfgDvbtSqiSpeed *speed) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3433 | { |
| 3434 | int status; |
| 3435 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3436 | dprintk(1, "\n"); |
| 3437 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3438 | switch (*speed) { |
| 3439 | case DRXK_DVBT_SQI_SPEED_FAST: |
| 3440 | case DRXK_DVBT_SQI_SPEED_MEDIUM: |
| 3441 | case DRXK_DVBT_SQI_SPEED_SLOW: |
| 3442 | break; |
| 3443 | default: |
| 3444 | return -EINVAL; |
| 3445 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3446 | status = write16(state, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3447 | (u16) *speed); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3448 | return status; |
| 3449 | } |
| 3450 | |
| 3451 | /*============================================================================*/ |
| 3452 | |
| 3453 | /** |
| 3454 | * \brief Activate DVBT specific presets |
| 3455 | * \param demod instance of demodulator. |
| 3456 | * \return DRXStatus_t. |
| 3457 | * |
| 3458 | * Called in DVBTSetStandard |
| 3459 | * |
| 3460 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3461 | static int DVBTActivatePresets(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3462 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3463 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3464 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3465 | struct DRXKCfgDvbtEchoThres_t echoThres2k = { 0, DRX_FFTMODE_2K }; |
| 3466 | struct DRXKCfgDvbtEchoThres_t echoThres8k = { 0, DRX_FFTMODE_8K }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3467 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3468 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3469 | do { |
| 3470 | bool setincenable = false; |
| 3471 | bool setfrenable = true; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3472 | status = DVBTCtrlSetIncEnable(state, &setincenable); |
| 3473 | if (status < 0) |
| 3474 | break; |
| 3475 | status = DVBTCtrlSetFrEnable(state, &setfrenable); |
| 3476 | if (status < 0) |
| 3477 | break; |
| 3478 | status = DVBTCtrlSetEchoThreshold(state, &echoThres2k); |
| 3479 | if (status < 0) |
| 3480 | break; |
| 3481 | status = DVBTCtrlSetEchoThreshold(state, &echoThres8k); |
| 3482 | if (status < 0) |
| 3483 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3484 | 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] | 3485 | if (status < 0) |
| 3486 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3487 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3488 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3489 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3490 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3491 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3492 | /*============================================================================*/ |
| 3493 | |
| 3494 | /** |
| 3495 | * \brief Initialize channelswitch-independent settings for DVBT. |
| 3496 | * \param demod instance of demodulator. |
| 3497 | * \return DRXStatus_t. |
| 3498 | * |
| 3499 | * For ROM code channel filter taps are loaded from the bootloader. For microcode |
| 3500 | * the DVB-T taps from the drxk_filters.h are used. |
| 3501 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3502 | static int SetDVBTStandard(struct drxk_state *state, |
| 3503 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3504 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3505 | u16 cmdResult = 0; |
| 3506 | u16 data = 0; |
| 3507 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3508 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3509 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3510 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3511 | PowerUpDVBT(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3512 | do { |
| 3513 | /* added antenna switch */ |
| 3514 | SwitchAntennaToDVBT(state); |
| 3515 | /* send OFDM reset command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3516 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 3517 | if (status < 0) |
| 3518 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3519 | |
| 3520 | /* send OFDM setenv command */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3521 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 0, NULL, 1, &cmdResult); |
| 3522 | if (status < 0) |
| 3523 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3524 | |
| 3525 | /* reset datapath for OFDM, processors first */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3526 | 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] | 3527 | if (status < 0) |
| 3528 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3529 | 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] | 3530 | if (status < 0) |
| 3531 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3532 | 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] | 3533 | if (status < 0) |
| 3534 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3535 | |
| 3536 | /* IQM setup */ |
| 3537 | /* synchronize on ofdstate->m_festart */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3538 | status = write16(state, IQM_AF_UPD_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3539 | if (status < 0) |
| 3540 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3541 | /* window size for clipping ADC detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3542 | status = write16(state, IQM_AF_CLP_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3543 | if (status < 0) |
| 3544 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3545 | /* window size for for sense pre-SAW detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3546 | status = write16(state, IQM_AF_SNS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3547 | if (status < 0) |
| 3548 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3549 | /* sense threshold for sense pre-SAW detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3550 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3551 | if (status < 0) |
| 3552 | break; |
| 3553 | status = SetIqmAf(state, true); |
| 3554 | if (status < 0) |
| 3555 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3556 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3557 | status = write16(state, IQM_AF_AGC_RF__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3558 | if (status < 0) |
| 3559 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3560 | |
| 3561 | /* Impulse noise cruncher setup */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3562 | 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] | 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_DET_LCT__A, 0); /* detect in IQM_CF */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3566 | if (status < 0) |
| 3567 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3568 | 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] | 3569 | if (status < 0) |
| 3570 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3571 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3572 | status = write16(state, IQM_RC_STRETCH__A, 16); |
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_OUT_ENA__A, 0x4); /* enable 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_DS_ENA__A, 0x4); /* decimate output 2 */ |
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__A, 1600); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3582 | if (status < 0) |
| 3583 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3584 | status = write16(state, IQM_CF_SCALE_SH__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3585 | if (status < 0) |
| 3586 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3587 | |
| 3588 | /* virtual clipping threshold for clipping ADC detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3589 | status = write16(state, IQM_AF_CLP_TH__A, 448); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3590 | if (status < 0) |
| 3591 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3592 | status = write16(state, IQM_CF_DATATH__A, 495); /* crunching threshold */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3593 | if (status < 0) |
| 3594 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3595 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3596 | status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 3597 | if (status < 0) |
| 3598 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3599 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3600 | status = write16(state, IQM_CF_PKDTH__A, 2); /* peak detector threshold */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3601 | if (status < 0) |
| 3602 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3603 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3604 | if (status < 0) |
| 3605 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3606 | /* enable power measurement interrupt */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3607 | status = write16(state, IQM_CF_COMM_INT_MSK__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3608 | if (status < 0) |
| 3609 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3610 | 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] | 3611 | if (status < 0) |
| 3612 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3613 | |
| 3614 | /* 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] | 3615 | status = ADCSynchronization(state); |
| 3616 | if (status < 0) |
| 3617 | break; |
| 3618 | status = SetPreSaw(state, &state->m_dvbtPreSawCfg); |
| 3619 | if (status < 0) |
| 3620 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3621 | |
| 3622 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3623 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3624 | if (status < 0) |
| 3625 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3626 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3627 | status = SetAgcRf(state, &state->m_dvbtRfAgcCfg, true); |
| 3628 | if (status < 0) |
| 3629 | break; |
| 3630 | status = SetAgcIf(state, &state->m_dvbtIfAgcCfg, true); |
| 3631 | if (status < 0) |
| 3632 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3633 | |
| 3634 | /* Set Noise Estimation notch width and enable DC fix */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3635 | status = read16(state, OFDM_SC_RA_RAM_CONFIG__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3636 | if (status < 0) |
| 3637 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3638 | data |= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3639 | status = write16(state, OFDM_SC_RA_RAM_CONFIG__A, data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3640 | if (status < 0) |
| 3641 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3642 | |
| 3643 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3644 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3645 | if (status < 0) |
| 3646 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3647 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3648 | if (!state->m_DRXK_A3_ROM_CODE) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3649 | /* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3650 | 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] | 3651 | if (status < 0) |
| 3652 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | /* OFDM_SC setup */ |
| 3656 | #ifdef COMPILE_FOR_NONRT |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3657 | 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] | 3658 | if (status < 0) |
| 3659 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3660 | 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] | 3661 | if (status < 0) |
| 3662 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3663 | #endif |
| 3664 | |
| 3665 | /* FEC setup */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3666 | status = write16(state, FEC_DI_INPUT_CTL__A, 1); /* OFDM input */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3667 | if (status < 0) |
| 3668 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3669 | |
| 3670 | |
| 3671 | #ifdef COMPILE_FOR_NONRT |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3672 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x400); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3673 | if (status < 0) |
| 3674 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3675 | #else |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3676 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x1000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3677 | if (status < 0) |
| 3678 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3679 | #endif |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3680 | status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, 0x0001); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3681 | if (status < 0) |
| 3682 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3683 | |
| 3684 | /* Setup MPEG bus */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3685 | status = MPEGTSDtoSetup(state, OM_DVBT); |
| 3686 | if (status < 0) |
| 3687 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3688 | /* Set DVBT Presets */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3689 | status = DVBTActivatePresets(state); |
| 3690 | if (status < 0) |
| 3691 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3692 | |
| 3693 | } while (0); |
| 3694 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3695 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 3696 | printk(KERN_ERR "drxk: %s status - %08x\n", __func__, status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3697 | |
| 3698 | return status; |
| 3699 | } |
| 3700 | |
| 3701 | /*============================================================================*/ |
| 3702 | /** |
| 3703 | * \brief Start dvbt demodulating for channel. |
| 3704 | * \param demod instance of demodulator. |
| 3705 | * \return DRXStatus_t. |
| 3706 | */ |
| 3707 | static int DVBTStart(struct drxk_state *state) |
| 3708 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3709 | u16 param1; |
| 3710 | int status; |
| 3711 | /* DRXKOfdmScCmd_t scCmd; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3712 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3713 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3714 | /* Start correct processes to get in lock */ |
| 3715 | /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */ |
| 3716 | do { |
| 3717 | param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3718 | status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, 0, 0, 0); |
| 3719 | if (status < 0) |
| 3720 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3721 | /* Start FEC OC */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3722 | status = MPEGTSStart(state); |
| 3723 | if (status < 0) |
| 3724 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3725 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3726 | if (status < 0) |
| 3727 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3728 | } while (0); |
| 3729 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | |
| 3733 | /*============================================================================*/ |
| 3734 | |
| 3735 | /** |
| 3736 | * \brief Set up dvbt demodulator for channel. |
| 3737 | * \param demod instance of demodulator. |
| 3738 | * \return DRXStatus_t. |
| 3739 | * // original DVBTSetChannel() |
| 3740 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3741 | static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, |
| 3742 | s32 tunerFreqOffset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3743 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3744 | u16 cmdResult = 0; |
| 3745 | u16 transmissionParams = 0; |
| 3746 | u16 operationMode = 0; |
| 3747 | u32 iqmRcRateOfs = 0; |
| 3748 | u32 bandwidth = 0; |
| 3749 | u16 param1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3750 | int status; |
| 3751 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3752 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 3753 | /* 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] | 3754 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3755 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 3756 | if (status < 0) |
| 3757 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3758 | |
| 3759 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3760 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3761 | if (status < 0) |
| 3762 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3763 | |
| 3764 | /* Stop processors */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3765 | 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] | 3766 | if (status < 0) |
| 3767 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3768 | 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] | 3769 | if (status < 0) |
| 3770 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3771 | |
| 3772 | /* Mandatory fix, always stop CP, required to set spl offset back to |
| 3773 | hardware default (is set to 0 by ucode during pilot detection */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3774 | 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] | 3775 | if (status < 0) |
| 3776 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3777 | |
| 3778 | /*== Write channel settings to device =====================================*/ |
| 3779 | |
| 3780 | /* mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3781 | switch (state->param.u.ofdm.transmission_mode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3782 | case TRANSMISSION_MODE_AUTO: |
| 3783 | default: |
| 3784 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M; |
| 3785 | /* fall through , try first guess DRX_FFTMODE_8K */ |
| 3786 | case TRANSMISSION_MODE_8K: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3787 | transmissionParams |= |
| 3788 | OFDM_SC_RA_RAM_OP_PARAM_MODE_8K; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3789 | break; |
| 3790 | case TRANSMISSION_MODE_2K: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3791 | transmissionParams |= |
| 3792 | OFDM_SC_RA_RAM_OP_PARAM_MODE_2K; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3793 | break; |
| 3794 | } |
| 3795 | |
| 3796 | /* guard */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3797 | switch (state->param.u.ofdm.guard_interval) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3798 | default: |
| 3799 | case GUARD_INTERVAL_AUTO: |
| 3800 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M; |
| 3801 | /* fall through , try first guess DRX_GUARD_1DIV4 */ |
| 3802 | case GUARD_INTERVAL_1_4: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3803 | transmissionParams |= |
| 3804 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3805 | break; |
| 3806 | case GUARD_INTERVAL_1_32: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3807 | transmissionParams |= |
| 3808 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_32; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3809 | break; |
| 3810 | case GUARD_INTERVAL_1_16: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3811 | transmissionParams |= |
| 3812 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_16; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3813 | break; |
| 3814 | case GUARD_INTERVAL_1_8: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3815 | transmissionParams |= |
| 3816 | OFDM_SC_RA_RAM_OP_PARAM_GUARD_8; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3817 | break; |
| 3818 | } |
| 3819 | |
| 3820 | /* hierarchy */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3821 | switch (state->param.u.ofdm.hierarchy_information) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3822 | case HIERARCHY_AUTO: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3823 | case HIERARCHY_NONE: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3824 | default: |
| 3825 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_HIER__M; |
| 3826 | /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3827 | /* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */ |
| 3828 | /* break; */ |
| 3829 | case HIERARCHY_1: |
| 3830 | transmissionParams |= |
| 3831 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3832 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3833 | case HIERARCHY_2: |
| 3834 | transmissionParams |= |
| 3835 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A2; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3836 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3837 | case HIERARCHY_4: |
| 3838 | transmissionParams |= |
| 3839 | OFDM_SC_RA_RAM_OP_PARAM_HIER_A4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3840 | break; |
| 3841 | } |
| 3842 | |
| 3843 | |
| 3844 | /* constellation */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3845 | switch (state->param.u.ofdm.constellation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3846 | case QAM_AUTO: |
| 3847 | default: |
| 3848 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M; |
| 3849 | /* fall through , try first guess DRX_CONSTELLATION_QAM64 */ |
| 3850 | case QAM_64: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3851 | transmissionParams |= |
| 3852 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3853 | break; |
| 3854 | case QPSK: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3855 | transmissionParams |= |
| 3856 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3857 | break; |
| 3858 | case QAM_16: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3859 | transmissionParams |= |
| 3860 | OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3861 | break; |
| 3862 | } |
| 3863 | #if 0 |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3864 | /* No hierachical channels support in BDA */ |
| 3865 | /* Priority (only for hierarchical channels) */ |
| 3866 | switch (channel->priority) { |
| 3867 | case DRX_PRIORITY_LOW: |
| 3868 | transmissionParams |= |
| 3869 | OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO; |
| 3870 | WR16(devAddr, OFDM_EC_SB_PRIOR__A, |
| 3871 | OFDM_EC_SB_PRIOR_LO); |
| 3872 | break; |
| 3873 | case DRX_PRIORITY_HIGH: |
| 3874 | transmissionParams |= |
| 3875 | OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
| 3876 | WR16(devAddr, OFDM_EC_SB_PRIOR__A, |
| 3877 | OFDM_EC_SB_PRIOR_HI)); |
| 3878 | break; |
| 3879 | case DRX_PRIORITY_UNKNOWN: /* fall through */ |
| 3880 | default: |
| 3881 | return DRX_STS_INVALID_ARG; |
| 3882 | break; |
| 3883 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3884 | #else |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3885 | /* Set Priorty high */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3886 | transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3887 | 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] | 3888 | if (status < 0) |
| 3889 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3890 | #endif |
| 3891 | |
| 3892 | /* coderate */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3893 | switch (state->param.u.ofdm.code_rate_HP) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3894 | case FEC_AUTO: |
| 3895 | default: |
| 3896 | operationMode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M; |
| 3897 | /* fall through , try first guess DRX_CODERATE_2DIV3 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3898 | case FEC_2_3: |
| 3899 | transmissionParams |= |
| 3900 | OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3901 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3902 | case FEC_1_2: |
| 3903 | transmissionParams |= |
| 3904 | OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3905 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3906 | case FEC_3_4: |
| 3907 | transmissionParams |= |
| 3908 | OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3909 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3910 | case FEC_5_6: |
| 3911 | transmissionParams |= |
| 3912 | OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3913 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3914 | case FEC_7_8: |
| 3915 | transmissionParams |= |
| 3916 | OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3917 | break; |
| 3918 | } |
| 3919 | |
| 3920 | /* SAW filter selection: normaly not necesarry, but if wanted |
| 3921 | the application can select a SAW filter via the driver by using UIOs */ |
| 3922 | /* First determine real bandwidth (Hz) */ |
| 3923 | /* Also set delay for impulse noise cruncher */ |
| 3924 | /* Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is changed |
| 3925 | by SC for fix for some 8K,1/8 guard but is restored by InitEC and ResetEC |
| 3926 | functions */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3927 | switch (state->param.u.ofdm.bandwidth) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3928 | case BANDWIDTH_AUTO: |
| 3929 | case BANDWIDTH_8_MHZ: |
| 3930 | bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3931 | 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] | 3932 | if (status < 0) |
| 3933 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3934 | /* cochannel protection for PAL 8 MHz */ |
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_LEFT__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_8K_PER_RIGHT__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_LEFT__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3942 | if (status < 0) |
| 3943 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3944 | 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] | 3945 | if (status < 0) |
| 3946 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3947 | break; |
| 3948 | case BANDWIDTH_7_MHZ: |
| 3949 | bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3950 | 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] | 3951 | if (status < 0) |
| 3952 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3953 | /* cochannel protection for PAL 7 MHz */ |
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_LEFT__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_8K_PER_RIGHT__A, 8); |
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_LEFT__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3961 | if (status < 0) |
| 3962 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3963 | 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] | 3964 | if (status < 0) |
| 3965 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3966 | break; |
| 3967 | case BANDWIDTH_6_MHZ: |
| 3968 | bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3969 | 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] | 3970 | if (status < 0) |
| 3971 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3972 | /* cochannel protection for NTSC 6 MHz */ |
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_LEFT__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_8K_PER_RIGHT__A, 19); |
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_LEFT__A, 14); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3980 | if (status < 0) |
| 3981 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3982 | 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] | 3983 | if (status < 0) |
| 3984 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3985 | break; |
Mauro Carvalho Chehab | e16cede | 2011-07-03 18:18:14 -0300 | [diff] [blame] | 3986 | default: |
| 3987 | return -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3988 | } |
| 3989 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3990 | if (iqmRcRateOfs == 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3991 | /* Now compute IQM_RC_RATE_OFS |
| 3992 | (((SysFreq/BandWidth)/2)/2) -1) * 2^23) |
| 3993 | => |
| 3994 | ((SysFreq / BandWidth) * (2^21)) - (2^23) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3995 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3996 | /* (SysFreq / BandWidth) * (2^28) */ |
| 3997 | /* assert (MAX(sysClk)/MIN(bandwidth) < 16) |
| 3998 | => assert(MAX(sysClk) < 16*MIN(bandwidth)) |
| 3999 | => assert(109714272 > 48000000) = true so Frac 28 can be used */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4000 | iqmRcRateOfs = Frac28a((u32) |
| 4001 | ((state->m_sysClockFreq * |
| 4002 | 1000) / 3), bandwidth); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4003 | /* (SysFreq / BandWidth) * (2^21), rounding before truncating */ |
| 4004 | if ((iqmRcRateOfs & 0x7fL) >= 0x40) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4005 | iqmRcRateOfs += 0x80L; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4006 | iqmRcRateOfs = iqmRcRateOfs >> 7; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4007 | /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4008 | iqmRcRateOfs = iqmRcRateOfs - (1 << 23); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4009 | } |
| 4010 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4011 | iqmRcRateOfs &= |
| 4012 | ((((u32) IQM_RC_RATE_OFS_HI__M) << |
| 4013 | 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] | 4014 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRateOfs); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4015 | if (status < 0) |
| 4016 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4017 | |
| 4018 | /* Bandwidth setting done */ |
| 4019 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4020 | #if 0 |
| 4021 | status = DVBTSetFrequencyShift(demod, channel, tunerOffset); |
| 4022 | if (status < 0) |
| 4023 | break; |
| 4024 | #endif |
| 4025 | status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); |
| 4026 | if (status < 0) |
| 4027 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4028 | |
| 4029 | /*== Start SC, write channel settings to SC ===============================*/ |
| 4030 | |
| 4031 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4032 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4033 | if (status < 0) |
| 4034 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4035 | |
| 4036 | /* Enable SC after setting all other parameters */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4037 | status = write16(state, OFDM_SC_COMM_STATE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4038 | if (status < 0) |
| 4039 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4040 | status = write16(state, OFDM_SC_COMM_EXEC__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4041 | if (status < 0) |
| 4042 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4043 | |
| 4044 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4045 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); |
| 4046 | if (status < 0) |
| 4047 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4048 | |
| 4049 | /* Write SC parameter registers, set all AUTO flags in operation mode */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4050 | param1 = (OFDM_SC_RA_RAM_OP_AUTO_MODE__M | |
| 4051 | OFDM_SC_RA_RAM_OP_AUTO_GUARD__M | |
| 4052 | OFDM_SC_RA_RAM_OP_AUTO_CONST__M | |
| 4053 | OFDM_SC_RA_RAM_OP_AUTO_HIER__M | |
| 4054 | OFDM_SC_RA_RAM_OP_AUTO_RATE__M); |
| 4055 | status = |
| 4056 | DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM, |
| 4057 | 0, transmissionParams, param1, 0, 0, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4058 | if (!state->m_DRXK_A3_ROM_CODE) |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4059 | status = DVBTCtrlSetSqiSpeed(state, &state->m_sqiSpeed); |
| 4060 | if (status < 0) |
| 4061 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4062 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4063 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4064 | |
| 4065 | return status; |
| 4066 | } |
| 4067 | |
| 4068 | |
| 4069 | /*============================================================================*/ |
| 4070 | |
| 4071 | /** |
| 4072 | * \brief Retreive lock status . |
| 4073 | * \param demod Pointer to demodulator instance. |
| 4074 | * \param lockStat Pointer to lock status structure. |
| 4075 | * \return DRXStatus_t. |
| 4076 | * |
| 4077 | */ |
| 4078 | static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) |
| 4079 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4080 | int status; |
| 4081 | const u16 mpeg_lock_mask = (OFDM_SC_RA_RAM_LOCK_MPEG__M | |
| 4082 | OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4083 | const u16 fec_lock_mask = (OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4084 | const u16 demod_lock_mask = OFDM_SC_RA_RAM_LOCK_DEMOD__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4085 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4086 | u16 ScRaRamLock = 0; |
| 4087 | u16 ScCommExec = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4088 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4089 | dprintk(1, "\n"); |
| 4090 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4091 | /* driver 0.9.0 */ |
| 4092 | /* Check if SC is running */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4093 | status = read16(state, OFDM_SC_COMM_EXEC__A, &ScCommExec); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4094 | if (ScCommExec == OFDM_SC_COMM_EXEC_STOP) { |
| 4095 | /* SC not active; return DRX_NOT_LOCKED */ |
| 4096 | *pLockStatus = NOT_LOCKED; |
| 4097 | return status; |
| 4098 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4099 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4100 | status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &ScRaRamLock); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4101 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4102 | if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask) |
| 4103 | *pLockStatus = MPEG_LOCK; |
| 4104 | else if ((ScRaRamLock & fec_lock_mask) == fec_lock_mask) |
| 4105 | *pLockStatus = FEC_LOCK; |
| 4106 | else if ((ScRaRamLock & demod_lock_mask) == demod_lock_mask) |
| 4107 | *pLockStatus = DEMOD_LOCK; |
| 4108 | else if (ScRaRamLock & OFDM_SC_RA_RAM_LOCK_NODVBT__M) |
| 4109 | *pLockStatus = NEVER_LOCK; |
| 4110 | else |
| 4111 | *pLockStatus = NOT_LOCKED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4112 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4113 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4114 | } |
| 4115 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4116 | static int PowerUpQAM(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4117 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4118 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
| 4119 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4120 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4121 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4122 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4123 | status = CtrlPowerMode(state, &powerMode); |
| 4124 | if (status < 0) |
| 4125 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4126 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4127 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4128 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4129 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4133 | /** Power Down QAM */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4134 | static int PowerDownQAM(struct drxk_state *state) |
| 4135 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4136 | u16 data = 0; |
| 4137 | u16 cmdResult; |
| 4138 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4139 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4140 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4141 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4142 | status = read16(state, SCU_COMM_EXEC__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4143 | if (status < 0) |
| 4144 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4145 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 4146 | /* |
| 4147 | STOP demodulator |
| 4148 | QAM and HW blocks |
| 4149 | */ |
| 4150 | /* stop all comstate->m_exec */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4151 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4152 | if (status < 0) |
| 4153 | break; |
| 4154 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); |
| 4155 | if (status < 0) |
| 4156 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4157 | } |
| 4158 | /* powerdown AFE */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4159 | status = SetIqmAf(state, false); |
| 4160 | if (status < 0) |
| 4161 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4162 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4163 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4164 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4165 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4166 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4167 | /*============================================================================*/ |
| 4168 | |
| 4169 | /** |
| 4170 | * \brief Setup of the QAM Measurement intervals for signal quality |
| 4171 | * \param demod instance of demod. |
| 4172 | * \param constellation current constellation. |
| 4173 | * \return DRXStatus_t. |
| 4174 | * |
| 4175 | * NOTE: |
| 4176 | * Take into account that for certain settings the errorcounters can overflow. |
| 4177 | * The implementation does not check this. |
| 4178 | * |
| 4179 | */ |
| 4180 | static int SetQAMMeasurement(struct drxk_state *state, |
| 4181 | enum EDrxkConstellation constellation, |
| 4182 | u32 symbolRate) |
| 4183 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4184 | u32 fecBitsDesired = 0; /* BER accounting period */ |
| 4185 | u32 fecRsPeriodTotal = 0; /* Total period */ |
| 4186 | u16 fecRsPrescale = 0; /* ReedSolomon Measurement Prescale */ |
| 4187 | u16 fecRsPeriod = 0; /* Value for corresponding I2C register */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4188 | int status = 0; |
| 4189 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4190 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4191 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4192 | fecRsPrescale = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4193 | do { |
| 4194 | |
| 4195 | /* fecBitsDesired = symbolRate [kHz] * |
| 4196 | FrameLenght [ms] * |
| 4197 | (constellation + 1) * |
| 4198 | SyncLoss (== 1) * |
| 4199 | ViterbiLoss (==1) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4200 | */ |
| 4201 | switch (constellation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4202 | case DRX_CONSTELLATION_QAM16: |
| 4203 | fecBitsDesired = 4 * symbolRate; |
| 4204 | break; |
| 4205 | case DRX_CONSTELLATION_QAM32: |
| 4206 | fecBitsDesired = 5 * symbolRate; |
| 4207 | break; |
| 4208 | case DRX_CONSTELLATION_QAM64: |
| 4209 | fecBitsDesired = 6 * symbolRate; |
| 4210 | break; |
| 4211 | case DRX_CONSTELLATION_QAM128: |
| 4212 | fecBitsDesired = 7 * symbolRate; |
| 4213 | break; |
| 4214 | case DRX_CONSTELLATION_QAM256: |
| 4215 | fecBitsDesired = 8 * symbolRate; |
| 4216 | break; |
| 4217 | default: |
| 4218 | status = -EINVAL; |
| 4219 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4220 | status = status; |
| 4221 | if (status < 0) |
| 4222 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4223 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4224 | fecBitsDesired /= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */ |
| 4225 | fecBitsDesired *= 500; /* meas. period [ms] */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4226 | |
| 4227 | /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */ |
| 4228 | /* fecRsPeriodTotal = fecBitsDesired / 1632 */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4229 | fecRsPeriodTotal = (fecBitsDesired / 1632UL) + 1; /* roughly ceil */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4230 | |
| 4231 | /* fecRsPeriodTotal = fecRsPrescale * fecRsPeriod */ |
| 4232 | fecRsPrescale = 1 + (u16) (fecRsPeriodTotal >> 16); |
| 4233 | if (fecRsPrescale == 0) { |
| 4234 | /* Divide by zero (though impossible) */ |
| 4235 | status = -1; |
| 4236 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4237 | status = status; |
| 4238 | if (status < 0) |
| 4239 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4240 | fecRsPeriod = |
| 4241 | ((u16) fecRsPeriodTotal + |
| 4242 | (fecRsPrescale >> 1)) / fecRsPrescale; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4243 | |
| 4244 | /* write corresponding registers */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4245 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fecRsPeriod); |
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_RS_MEASUREMENT_PRESCALE__A, fecRsPrescale); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4249 | if (status < 0) |
| 4250 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4251 | status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fecRsPeriod); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4252 | if (status < 0) |
| 4253 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4254 | |
| 4255 | } while (0); |
| 4256 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4257 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 4258 | printk(KERN_ERR "drxk: %s: status - %08x\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4259 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4260 | return status; |
| 4261 | } |
| 4262 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4263 | static int SetQAM16(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4264 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4265 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4266 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4267 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4268 | do { |
| 4269 | /* QAM Equalizer Setup */ |
| 4270 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4271 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__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_RAD1__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_RAD2__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_RAD3__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_RAD4__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4284 | if (status < 0) |
| 4285 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4286 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 13517); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4287 | if (status < 0) |
| 4288 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4289 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4290 | status = write16(state, QAM_DQ_QUAL_FUN0__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_FUN1__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_FUN2__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_FUN3__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_FUN4__A, 2); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4303 | if (status < 0) |
| 4304 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4305 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4306 | if (status < 0) |
| 4307 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4308 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4309 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
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_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4313 | if (status < 0) |
| 4314 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4315 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4316 | if (status < 0) |
| 4317 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4318 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4319 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4320 | 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] | 4321 | if (status < 0) |
| 4322 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4323 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4324 | /* QAM Loop Controller Coeficients */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4325 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
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_CA_COARSE__A, 40); |
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_FINE__A, 12); |
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_MEDIUM__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_EP_COARSE__A, 24); |
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_FINE__A, 12); |
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_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4344 | if (status < 0) |
| 4345 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4346 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4347 | if (status < 0) |
| 4348 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4349 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4350 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
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_MEDIUM__A, 20); |
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_CP_COARSE__A, 80); |
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_FINE__A, 5); |
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_MEDIUM__A, 20); |
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_CI_COARSE__A, 50); |
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_FINE__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_MEDIUM__A, 16); |
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_CF_COARSE__A, 32); |
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_FINE__A, 5); |
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_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4381 | if (status < 0) |
| 4382 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4383 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4384 | if (status < 0) |
| 4385 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4386 | |
| 4387 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4388 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4389 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4390 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 140); |
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_FTH__A, 50); |
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_CTH__A, 95); |
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_PTH__A, 120); |
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_QTH__A, 230); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4403 | if (status < 0) |
| 4404 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4405 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 105); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4406 | if (status < 0) |
| 4407 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4408 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4409 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
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_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4413 | if (status < 0) |
| 4414 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4415 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 24); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4416 | if (status < 0) |
| 4417 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4418 | |
| 4419 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4420 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4421 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4422 | 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] | 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_RADIUS_AV_LIMIT__A, (u16) 220); |
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_OFFSET1__A, (u16) 25); |
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_OFFSET2__A, (u16) 6); |
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_OFFSET3__A, (u16) -24); |
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_OFFSET4__A, (u16) -65); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4438 | if (status < 0) |
| 4439 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4440 | 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] | 4441 | if (status < 0) |
| 4442 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4443 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4444 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4445 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | /*============================================================================*/ |
| 4449 | |
| 4450 | /** |
| 4451 | * \brief QAM32 specific setup |
| 4452 | * \param demod instance of demod. |
| 4453 | * \return DRXStatus_t. |
| 4454 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4455 | static int SetQAM32(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4456 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4457 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4458 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4459 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4460 | do { |
| 4461 | /* QAM Equalizer Setup */ |
| 4462 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4463 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__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_RAD1__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_RAD2__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_RAD3__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_RAD4__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4476 | if (status < 0) |
| 4477 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4478 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 6707); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4479 | if (status < 0) |
| 4480 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4481 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4482 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4483 | status = write16(state, QAM_DQ_QUAL_FUN0__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_FUN1__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_FUN2__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_FUN3__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_FUN4__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4496 | if (status < 0) |
| 4497 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4498 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4499 | if (status < 0) |
| 4500 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4501 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4502 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
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_AWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4506 | if (status < 0) |
| 4507 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4508 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4509 | if (status < 0) |
| 4510 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4511 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4512 | /* QAM Slicer Settings */ |
| 4513 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4514 | 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] | 4515 | if (status < 0) |
| 4516 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4517 | |
| 4518 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4519 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4520 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4521 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
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_CA_COARSE__A, 40); |
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_FINE__A, 12); |
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_MEDIUM__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_EP_COARSE__A, 24); |
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_FINE__A, 12); |
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_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4540 | if (status < 0) |
| 4541 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4542 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4543 | if (status < 0) |
| 4544 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4545 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4546 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
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_MEDIUM__A, 20); |
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_CP_COARSE__A, 80); |
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_FINE__A, 5); |
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_MEDIUM__A, 20); |
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_CI_COARSE__A, 50); |
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_FINE__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_MEDIUM__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_CF_COARSE__A, 16); |
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_FINE__A, 5); |
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_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4577 | if (status < 0) |
| 4578 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4579 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4580 | if (status < 0) |
| 4581 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4582 | |
| 4583 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4584 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4585 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4586 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 90); |
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_FTH__A, 50); |
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_CTH__A, 80); |
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_PTH__A, 100); |
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_QTH__A, 170); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4599 | if (status < 0) |
| 4600 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4601 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4602 | if (status < 0) |
| 4603 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4604 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4605 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
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_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4609 | if (status < 0) |
| 4610 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4611 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4612 | if (status < 0) |
| 4613 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4614 | |
| 4615 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4616 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4617 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4618 | 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] | 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_RADIUS_AV_LIMIT__A, (u16) 140); |
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_OFFSET1__A, (u16) -8); |
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_OFFSET2__A, (u16) -16); |
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_OFFSET3__A, (u16) -26); |
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_OFFSET4__A, (u16) -56); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4634 | if (status < 0) |
| 4635 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4636 | 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] | 4637 | if (status < 0) |
| 4638 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4639 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4640 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4641 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | /*============================================================================*/ |
| 4645 | |
| 4646 | /** |
| 4647 | * \brief QAM64 specific setup |
| 4648 | * \param demod instance of demod. |
| 4649 | * \return DRXStatus_t. |
| 4650 | */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4651 | static int SetQAM64(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4652 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4653 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4654 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4655 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4656 | do { |
| 4657 | /* QAM Equalizer Setup */ |
| 4658 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4659 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13336); |
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_RAD1__A, 12618); |
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_RAD2__A, 11988); |
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_RAD3__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_RAD4__A, 13809); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4672 | if (status < 0) |
| 4673 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4674 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15609); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4675 | if (status < 0) |
| 4676 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4677 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4678 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4679 | status = write16(state, QAM_DQ_QUAL_FUN0__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_FUN1__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_FUN2__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_FUN3__A, 4); |
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_FUN4__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4692 | if (status < 0) |
| 4693 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4694 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4695 | if (status < 0) |
| 4696 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4697 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4698 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
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_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4702 | if (status < 0) |
| 4703 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4704 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4705 | if (status < 0) |
| 4706 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4707 | |
| 4708 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4709 | 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] | 4710 | if (status < 0) |
| 4711 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4712 | |
| 4713 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4714 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4715 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4716 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
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_CA_COARSE__A, 40); |
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_FINE__A, 12); |
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_MEDIUM__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_EP_COARSE__A, 24); |
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_FINE__A, 12); |
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_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4735 | if (status < 0) |
| 4736 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4737 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4738 | if (status < 0) |
| 4739 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4740 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4741 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
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_MEDIUM__A, 30); |
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_CP_COARSE__A, 100); |
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_FINE__A, 5); |
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_MEDIUM__A, 30); |
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_CI_COARSE__A, 50); |
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_FINE__A, 16); |
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_MEDIUM__A, 25); |
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_CF_COARSE__A, 48); |
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_FINE__A, 5); |
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_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4772 | if (status < 0) |
| 4773 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4774 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4775 | if (status < 0) |
| 4776 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4777 | |
| 4778 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4779 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4780 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4781 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 100); |
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_FTH__A, 60); |
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_CTH__A, 80); |
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_PTH__A, 110); |
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_QTH__A, 200); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4794 | if (status < 0) |
| 4795 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4796 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 95); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4797 | if (status < 0) |
| 4798 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4799 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4800 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
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_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4804 | if (status < 0) |
| 4805 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4806 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 15); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4807 | if (status < 0) |
| 4808 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4809 | |
| 4810 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4811 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4812 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4813 | 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] | 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_RADIUS_AV_LIMIT__A, (u16) 141); |
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_OFFSET1__A, (u16) 7); |
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_OFFSET2__A, (u16) 0); |
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_OFFSET3__A, (u16) -15); |
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_OFFSET4__A, (u16) -45); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4829 | if (status < 0) |
| 4830 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4831 | 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] | 4832 | if (status < 0) |
| 4833 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4834 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4835 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4836 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | /*============================================================================*/ |
| 4840 | |
| 4841 | /** |
| 4842 | * \brief QAM128 specific setup |
| 4843 | * \param demod: instance of demod. |
| 4844 | * \return DRXStatus_t. |
| 4845 | */ |
| 4846 | static int SetQAM128(struct drxk_state *state) |
| 4847 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4848 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4849 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4850 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4851 | do { |
| 4852 | /* QAM Equalizer Setup */ |
| 4853 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4854 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6564); |
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_RAD1__A, 6598); |
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_RAD2__A, 6394); |
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_RAD3__A, 6409); |
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_RAD4__A, 6656); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4867 | if (status < 0) |
| 4868 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4869 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 7238); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4870 | if (status < 0) |
| 4871 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4872 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4873 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4874 | status = write16(state, QAM_DQ_QUAL_FUN0__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_FUN1__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_FUN2__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_FUN3__A, 6); |
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_FUN4__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4887 | if (status < 0) |
| 4888 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4889 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4890 | if (status < 0) |
| 4891 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4892 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4893 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
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_AWM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4897 | if (status < 0) |
| 4898 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4899 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4900 | if (status < 0) |
| 4901 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4902 | |
| 4903 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4904 | /* QAM Slicer Settings */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4905 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4906 | 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] | 4907 | if (status < 0) |
| 4908 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4909 | |
| 4910 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4911 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4912 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4913 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
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_CA_COARSE__A, 40); |
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_FINE__A, 12); |
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_MEDIUM__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_EP_COARSE__A, 24); |
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_FINE__A, 12); |
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_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4932 | if (status < 0) |
| 4933 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4934 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4935 | if (status < 0) |
| 4936 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4937 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4938 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
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_MEDIUM__A, 40); |
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_CP_COARSE__A, 120); |
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_FINE__A, 5); |
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_MEDIUM__A, 40); |
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_CI_COARSE__A, 60); |
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_FINE__A, 16); |
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_MEDIUM__A, 25); |
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_CF_COARSE__A, 64); |
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_FINE__A, 5); |
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_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4969 | if (status < 0) |
| 4970 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4971 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4972 | if (status < 0) |
| 4973 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4974 | |
| 4975 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4976 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4977 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4978 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
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_FTH__A, 60); |
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_CTH__A, 80); |
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_PTH__A, 100); |
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_QTH__A, 140); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4991 | if (status < 0) |
| 4992 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4993 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4994 | if (status < 0) |
| 4995 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4996 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 4997 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4998 | if (status < 0) |
| 4999 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5000 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 5); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5001 | if (status < 0) |
| 5002 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5003 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5004 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5005 | if (status < 0) |
| 5006 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5007 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5008 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5009 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5010 | 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] | 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_RADIUS_AV_LIMIT__A, (u16) 65); |
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_OFFSET1__A, (u16) 5); |
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_OFFSET2__A, (u16) 3); |
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_OFFSET3__A, (u16) -1); |
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_OFFSET4__A, (u16) -12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5026 | if (status < 0) |
| 5027 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5028 | 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] | 5029 | if (status < 0) |
| 5030 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5031 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5032 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5033 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | /*============================================================================*/ |
| 5037 | |
| 5038 | /** |
| 5039 | * \brief QAM256 specific setup |
| 5040 | * \param demod: instance of demod. |
| 5041 | * \return DRXStatus_t. |
| 5042 | */ |
| 5043 | static int SetQAM256(struct drxk_state *state) |
| 5044 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5045 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5046 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5047 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5048 | do { |
| 5049 | /* QAM Equalizer Setup */ |
| 5050 | /* Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5051 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 11502); |
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_RAD1__A, 12084); |
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_RAD2__A, 12543); |
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_RAD3__A, 12931); |
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_RAD4__A, 13629); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5064 | if (status < 0) |
| 5065 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5066 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15385); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5067 | if (status < 0) |
| 5068 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5069 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5070 | /* Decision Feedback Equalizer */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5071 | status = write16(state, QAM_DQ_QUAL_FUN0__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_FUN1__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_FUN2__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_FUN3__A, 8); |
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_FUN4__A, 6); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5084 | if (status < 0) |
| 5085 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5086 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5087 | if (status < 0) |
| 5088 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5089 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5090 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
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_AWM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5094 | if (status < 0) |
| 5095 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5096 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5097 | if (status < 0) |
| 5098 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5099 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5100 | /* QAM Slicer Settings */ |
| 5101 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5102 | 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] | 5103 | if (status < 0) |
| 5104 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5105 | |
| 5106 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5107 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5108 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5109 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
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_CA_COARSE__A, 40); |
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_FINE__A, 12); |
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_MEDIUM__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_EP_COARSE__A, 24); |
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_FINE__A, 12); |
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_MEDIUM__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5128 | if (status < 0) |
| 5129 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5130 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5131 | if (status < 0) |
| 5132 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5133 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5134 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
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_MEDIUM__A, 50); |
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_CP_COARSE__A, 250); |
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_FINE__A, 5); |
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_MEDIUM__A, 50); |
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_CI_COARSE__A, 125); |
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_FINE__A, 16); |
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_MEDIUM__A, 25); |
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_CF_COARSE__A, 48); |
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_FINE__A, 5); |
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_MEDIUM__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5165 | if (status < 0) |
| 5166 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5167 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5168 | if (status < 0) |
| 5169 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5170 | |
| 5171 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5172 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5173 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5174 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
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_FTH__A, 60); |
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_CTH__A, 80); |
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_PTH__A, 100); |
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_QTH__A, 150); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5187 | if (status < 0) |
| 5188 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5189 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 110); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5190 | if (status < 0) |
| 5191 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5192 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5193 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
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_COUNT_LIM__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5197 | if (status < 0) |
| 5198 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5199 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5200 | if (status < 0) |
| 5201 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5202 | |
| 5203 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5204 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5205 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5206 | 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] | 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_RADIUS_AV_LIMIT__A, (u16) 74); |
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_OFFSET1__A, (u16) 18); |
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_OFFSET2__A, (u16) 13); |
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_OFFSET3__A, (u16) 7); |
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_OFFSET4__A, (u16) 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5222 | if (status < 0) |
| 5223 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5224 | 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] | 5225 | if (status < 0) |
| 5226 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5227 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5228 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5229 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | |
| 5233 | /*============================================================================*/ |
| 5234 | /** |
| 5235 | * \brief Reset QAM block. |
| 5236 | * \param demod: instance of demod. |
| 5237 | * \param channel: pointer to channel data. |
| 5238 | * \return DRXStatus_t. |
| 5239 | */ |
| 5240 | static int QAMResetQAM(struct drxk_state *state) |
| 5241 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5242 | int status; |
| 5243 | u16 cmdResult; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5244 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5245 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5246 | do { |
| 5247 | /* Stop QAM comstate->m_exec */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5248 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5249 | if (status < 0) |
| 5250 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5251 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5252 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); |
| 5253 | if (status < 0) |
| 5254 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5255 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5256 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5257 | /* All done, all OK */ |
| 5258 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | /*============================================================================*/ |
| 5262 | |
| 5263 | /** |
| 5264 | * \brief Set QAM symbolrate. |
| 5265 | * \param demod: instance of demod. |
| 5266 | * \param channel: pointer to channel data. |
| 5267 | * \return DRXStatus_t. |
| 5268 | */ |
| 5269 | static int QAMSetSymbolrate(struct drxk_state *state) |
| 5270 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5271 | u32 adcFrequency = 0; |
| 5272 | u32 symbFreq = 0; |
| 5273 | u32 iqmRcRate = 0; |
| 5274 | u16 ratesel = 0; |
| 5275 | u32 lcSymbRate = 0; |
| 5276 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5277 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5278 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5279 | do { |
| 5280 | /* Select & calculate correct IQM rate */ |
| 5281 | adcFrequency = (state->m_sysClockFreq * 1000) / 3; |
| 5282 | ratesel = 0; |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5283 | /* 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] | 5284 | if (state->param.u.qam.symbol_rate <= 1188750) |
| 5285 | ratesel = 3; |
| 5286 | else if (state->param.u.qam.symbol_rate <= 2377500) |
| 5287 | ratesel = 2; |
| 5288 | else if (state->param.u.qam.symbol_rate <= 4755000) |
| 5289 | ratesel = 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5290 | status = write16(state, IQM_FD_RATESEL__A, ratesel); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5291 | if (status < 0) |
| 5292 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5293 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5294 | /* |
| 5295 | IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23) |
| 5296 | */ |
| 5297 | symbFreq = state->param.u.qam.symbol_rate * (1 << ratesel); |
| 5298 | if (symbFreq == 0) { |
| 5299 | /* Divide by zero */ |
| 5300 | return -1; |
| 5301 | } |
| 5302 | iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) + |
| 5303 | (Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) - |
| 5304 | (1 << 23); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5305 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5306 | if (status < 0) |
| 5307 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5308 | state->m_iqmRcRate = iqmRcRate; |
| 5309 | /* |
| 5310 | LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15)) |
| 5311 | */ |
| 5312 | symbFreq = state->param.u.qam.symbol_rate; |
| 5313 | if (adcFrequency == 0) { |
| 5314 | /* Divide by zero */ |
| 5315 | return -1; |
| 5316 | } |
| 5317 | lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) + |
| 5318 | (Frac28a((symbFreq % adcFrequency), adcFrequency) >> |
| 5319 | 16); |
| 5320 | if (lcSymbRate > 511) |
| 5321 | lcSymbRate = 511; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5322 | status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lcSymbRate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5323 | if (status < 0) |
| 5324 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5325 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5326 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5327 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | /*============================================================================*/ |
| 5331 | |
| 5332 | /** |
| 5333 | * \brief Get QAM lock status. |
| 5334 | * \param demod: instance of demod. |
| 5335 | * \param channel: pointer to channel data. |
| 5336 | * \return DRXStatus_t. |
| 5337 | */ |
| 5338 | |
| 5339 | static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) |
| 5340 | { |
| 5341 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5342 | u16 Result[2] = { 0, 0 }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5343 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5344 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5345 | status = |
| 5346 | scu_command(state, |
| 5347 | SCU_RAM_COMMAND_STANDARD_QAM | |
| 5348 | SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2, |
| 5349 | Result); |
| 5350 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5351 | printk(KERN_ERR "drxk: %s status = %08x\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5352 | |
| 5353 | if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5354 | /* 0x0000 NOT LOCKED */ |
| 5355 | *pLockStatus = NOT_LOCKED; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5356 | } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5357 | /* 0x4000 DEMOD LOCKED */ |
| 5358 | *pLockStatus = DEMOD_LOCK; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5359 | } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5360 | /* 0x8000 DEMOD + FEC LOCKED (system lock) */ |
| 5361 | *pLockStatus = MPEG_LOCK; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5362 | } else { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5363 | /* 0xC000 NEVER LOCKED */ |
| 5364 | /* (system will never be able to lock to the signal) */ |
| 5365 | /* TODO: check this, intermediate & standard specific lock states are not |
| 5366 | taken into account here */ |
| 5367 | *pLockStatus = NEVER_LOCK; |
| 5368 | } |
| 5369 | return status; |
| 5370 | } |
| 5371 | |
| 5372 | #define QAM_MIRROR__M 0x03 |
| 5373 | #define QAM_MIRROR_NORMAL 0x00 |
| 5374 | #define QAM_MIRRORED 0x01 |
| 5375 | #define QAM_MIRROR_AUTO_ON 0x02 |
| 5376 | #define QAM_LOCKRANGE__M 0x10 |
| 5377 | #define QAM_LOCKRANGE_NORMAL 0x10 |
| 5378 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5379 | static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, |
| 5380 | s32 tunerFreqOffset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5381 | { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5382 | int status = 0; |
| 5383 | u8 parameterLen; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5384 | u16 setEnvParameters[5]; |
| 5385 | u16 setParamParameters[4] = { 0, 0, 0, 0 }; |
| 5386 | u16 cmdResult; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5387 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5388 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5389 | do { |
| 5390 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5391 | STEP 1: reset demodulator |
| 5392 | resets FEC DI and FEC RS |
| 5393 | resets QAM block |
| 5394 | resets SCU variables |
| 5395 | */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5396 | 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] | 5397 | if (status < 0) |
| 5398 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5399 | 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] | 5400 | if (status < 0) |
| 5401 | break; |
| 5402 | status = QAMResetQAM(state); |
| 5403 | if (status < 0) |
| 5404 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5405 | |
| 5406 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5407 | STEP 2: configure demodulator |
| 5408 | -set env |
| 5409 | -set params; resets IQM,QAM,FEC HW; initializes some SCU variables |
| 5410 | */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5411 | status = QAMSetSymbolrate(state); |
| 5412 | if (status < 0) |
| 5413 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5414 | |
| 5415 | /* Env parameters */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5416 | setEnvParameters[2] = QAM_TOP_ANNEX_A; /* Annex */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5417 | if (state->m_OperationMode == OM_QAM_ITU_C) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5418 | setEnvParameters[2] = QAM_TOP_ANNEX_C; /* Annex */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5419 | setParamParameters[3] |= (QAM_MIRROR_AUTO_ON); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5420 | /* check for LOCKRANGE Extented */ |
| 5421 | /* setParamParameters[3] |= QAM_LOCKRANGE_NORMAL; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5422 | parameterLen = 4; |
| 5423 | |
| 5424 | /* Set params */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5425 | switch (state->param.u.qam.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5426 | case QAM_256: |
| 5427 | state->m_Constellation = DRX_CONSTELLATION_QAM256; |
| 5428 | break; |
| 5429 | case QAM_AUTO: |
| 5430 | case QAM_64: |
| 5431 | state->m_Constellation = DRX_CONSTELLATION_QAM64; |
| 5432 | break; |
| 5433 | case QAM_16: |
| 5434 | state->m_Constellation = DRX_CONSTELLATION_QAM16; |
| 5435 | break; |
| 5436 | case QAM_32: |
| 5437 | state->m_Constellation = DRX_CONSTELLATION_QAM32; |
| 5438 | break; |
| 5439 | case QAM_128: |
| 5440 | state->m_Constellation = DRX_CONSTELLATION_QAM128; |
| 5441 | break; |
| 5442 | default: |
| 5443 | status = -EINVAL; |
| 5444 | break; |
| 5445 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5446 | status = status; |
| 5447 | if (status < 0) |
| 5448 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5449 | setParamParameters[0] = state->m_Constellation; /* constellation */ |
| 5450 | setParamParameters[1] = DRXK_QAM_I12_J17; /* interleave mode */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5451 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5452 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 4, setParamParameters, 1, &cmdResult); |
| 5453 | if (status < 0) |
| 5454 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5455 | |
| 5456 | |
| 5457 | /* STEP 3: enable the system in a mode where the ADC provides valid signal |
| 5458 | setup constellation independent registers */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5459 | #if 0 |
| 5460 | status = SetFrequency (channel, tunerFreqOffset)); |
| 5461 | if (status < 0) |
| 5462 | break; |
| 5463 | #endif |
| 5464 | status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); |
| 5465 | if (status < 0) |
| 5466 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5467 | |
| 5468 | /* Setup BER measurement */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5469 | status = SetQAMMeasurement(state, state->m_Constellation, state->param.u. qam.symbol_rate); |
| 5470 | if (status < 0) |
| 5471 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5472 | |
| 5473 | /* Reset default values */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5474 | 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] | 5475 | if (status < 0) |
| 5476 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5477 | status = write16(state, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5478 | if (status < 0) |
| 5479 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5480 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5481 | /* Reset default LC values */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5482 | status = write16(state, QAM_LC_RATE_LIMIT__A, 3); |
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_FACTORP__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_LPF_FACTORI__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5489 | if (status < 0) |
| 5490 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5491 | status = write16(state, QAM_LC_MODE__A, 7); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5492 | if (status < 0) |
| 5493 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5494 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5495 | status = write16(state, QAM_LC_QUAL_TAB0__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_TAB1__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_TAB2__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_TAB3__A, 1); |
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_TAB4__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_TAB5__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_TAB6__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_TAB8__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_TAB9__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_TAB10__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_TAB12__A, 2); |
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_TAB15__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_TAB16__A, 3); |
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_TAB20__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5535 | if (status < 0) |
| 5536 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5537 | status = write16(state, QAM_LC_QUAL_TAB25__A, 4); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5538 | if (status < 0) |
| 5539 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5540 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5541 | /* Mirroring, QAM-block starting point not inverted */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5542 | 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] | 5543 | if (status < 0) |
| 5544 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5545 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5546 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5547 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5548 | if (status < 0) |
| 5549 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5550 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5551 | /* STEP 4: constellation specific setup */ |
| 5552 | switch (state->param.u.qam.modulation) { |
| 5553 | case QAM_16: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5554 | status = SetQAM16(state); |
| 5555 | if (status < 0) |
| 5556 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5557 | break; |
| 5558 | case QAM_32: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5559 | status = SetQAM32(state); |
| 5560 | if (status < 0) |
| 5561 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5562 | break; |
| 5563 | case QAM_AUTO: |
| 5564 | case QAM_64: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5565 | status = SetQAM64(state); |
| 5566 | if (status < 0) |
| 5567 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5568 | break; |
| 5569 | case QAM_128: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5570 | status = SetQAM128(state); |
| 5571 | if (status < 0) |
| 5572 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5573 | break; |
| 5574 | case QAM_256: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5575 | status = SetQAM256(state); |
| 5576 | if (status < 0) |
| 5577 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5578 | break; |
| 5579 | default: |
| 5580 | return -1; |
| 5581 | break; |
| 5582 | } /* switch */ |
| 5583 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5584 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5585 | if (status < 0) |
| 5586 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5587 | |
| 5588 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5589 | /* Re-configure MPEG output, requires knowledge of channel bitrate */ |
| 5590 | /* extAttr->currentChannel.constellation = channel->constellation; */ |
| 5591 | /* extAttr->currentChannel.symbolrate = channel->symbolrate; */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5592 | status = MPEGTSDtoSetup(state, state->m_OperationMode); |
| 5593 | if (status < 0) |
| 5594 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5595 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5596 | /* Start processes */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5597 | status = MPEGTSStart(state); |
| 5598 | if (status < 0) |
| 5599 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5600 | status = write16(state, FEC_COMM_EXEC__A, FEC_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, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5604 | if (status < 0) |
| 5605 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5606 | 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] | 5607 | if (status < 0) |
| 5608 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5609 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5610 | /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5611 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); |
| 5612 | if (status < 0) |
| 5613 | break; |
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 | /* update global DRXK data container */ |
| 5616 | /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */ |
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 | /* All done, all OK */ |
| 5619 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5620 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5621 | if (status < 0) |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5622 | printk(KERN_ERR "drxk: %s %d\n", __func__, status); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5623 | |
| 5624 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5625 | } |
| 5626 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5627 | static int SetQAMStandard(struct drxk_state *state, |
| 5628 | enum OperationMode oMode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5629 | { |
| 5630 | #ifdef DRXK_QAM_TAPS |
| 5631 | #define DRXK_QAMA_TAPS_SELECT |
| 5632 | #include "drxk_filters.h" |
| 5633 | #undef DRXK_QAMA_TAPS_SELECT |
| 5634 | #else |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5635 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5636 | #endif |
| 5637 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5638 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5639 | do { |
| 5640 | /* added antenna switch */ |
| 5641 | SwitchAntennaToQAM(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5642 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5643 | /* Ensure correct power-up mode */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5644 | status = PowerUpQAM(state); |
| 5645 | if (status < 0) |
| 5646 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5647 | /* Reset QAM block */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5648 | status = QAMResetQAM(state); |
| 5649 | if (status < 0) |
| 5650 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5651 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5652 | /* Setup IQM */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5653 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5654 | 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] | 5655 | if (status < 0) |
| 5656 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5657 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5658 | if (status < 0) |
| 5659 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5660 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5661 | /* Upload IQM Channel Filter settings by |
| 5662 | boot loader from ROM table */ |
| 5663 | switch (oMode) { |
| 5664 | case OM_QAM_ITU_A: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5665 | status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5666 | if (status < 0) |
| 5667 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5668 | break; |
| 5669 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5670 | status = BLDirectCmd(state, IQM_CF_TAP_RE0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5671 | if (status < 0) |
| 5672 | break; |
| 5673 | status = BLDirectCmd(state, IQM_CF_TAP_IM0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
| 5674 | if (status < 0) |
| 5675 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5676 | break; |
| 5677 | default: |
| 5678 | status = -EINVAL; |
| 5679 | } |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5680 | status = status; |
| 5681 | if (status < 0) |
| 5682 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5683 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5684 | 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] | 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_SYMMETRIC__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5688 | if (status < 0) |
| 5689 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5690 | 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] | 5691 | if (status < 0) |
| 5692 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5693 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5694 | status = write16(state, IQM_RC_STRETCH__A, 21); |
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_LEN__A, 0); |
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_CLP_TH__A, 448); |
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_AF_SNS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5704 | if (status < 0) |
| 5705 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5706 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5707 | if (status < 0) |
| 5708 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5709 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5710 | status = write16(state, IQM_FS_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_RC_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_CF_ADJ_SEL__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5717 | if (status < 0) |
| 5718 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5719 | status = write16(state, IQM_AF_UPD_SEL__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5720 | if (status < 0) |
| 5721 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5722 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5723 | /* IQM Impulse Noise Processing Unit */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5724 | status = write16(state, IQM_CF_CLP_VAL__A, 500); |
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_DATATH__A, 1000); |
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_BYPASSDET__A, 1); |
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_DET_LCT__A, 0); |
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_WND_LEN__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_CF_PKDTH__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5740 | if (status < 0) |
| 5741 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5742 | status = write16(state, IQM_AF_INC_BYPASS__A, 1); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5743 | if (status < 0) |
| 5744 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5745 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5746 | /* turn on IQMAF. Must be done before setAgc**() */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5747 | status = SetIqmAf(state, true); |
| 5748 | if (status < 0) |
| 5749 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5750 | status = write16(state, IQM_AF_START_LOCK__A, 0x01); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5751 | if (status < 0) |
| 5752 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5753 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5754 | /* 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] | 5755 | status = ADCSynchronization(state); |
| 5756 | if (status < 0) |
| 5757 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5758 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5759 | /* Set the FSM step period */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5760 | status = write16(state, SCU_RAM_QAM_FSM_STEP_PERIOD__A, 2000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5761 | if (status < 0) |
| 5762 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5763 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5764 | /* Halt SCU to enable safe non-atomic accesses */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5765 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5766 | if (status < 0) |
| 5767 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5768 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5769 | /* No more resets of the IQM, current standard correctly set => |
| 5770 | now AGCs can be configured. */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5771 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5772 | status = InitAGC(state, true); |
| 5773 | if (status < 0) |
| 5774 | break; |
| 5775 | status = SetPreSaw(state, &(state->m_qamPreSawCfg)); |
| 5776 | if (status < 0) |
| 5777 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5778 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5779 | /* Configure AGC's */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5780 | status = SetAgcRf(state, &(state->m_qamRfAgcCfg), true); |
| 5781 | if (status < 0) |
| 5782 | break; |
| 5783 | status = SetAgcIf(state, &(state->m_qamIfAgcCfg), true); |
| 5784 | if (status < 0) |
| 5785 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5786 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5787 | /* Activate SCU to enable SCU commands */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5788 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5789 | if (status < 0) |
| 5790 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5791 | } while (0); |
| 5792 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | static int WriteGPIO(struct drxk_state *state) |
| 5796 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5797 | int status; |
| 5798 | u16 value = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5799 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5800 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5801 | do { |
| 5802 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5803 | 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] | 5804 | if (status < 0) |
| 5805 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5806 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5807 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5808 | 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] | 5809 | if (status < 0) |
| 5810 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5811 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5812 | if (state->m_hasSAWSW) { |
| 5813 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5814 | 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] | 5815 | if (status < 0) |
| 5816 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5817 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5818 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5819 | status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5820 | if (status < 0) |
| 5821 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5822 | if (state->m_GPIO == 0) |
| 5823 | value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ |
| 5824 | else |
| 5825 | value |= 0x8000; /* write one to 15th bit - 1st UIO */ |
| 5826 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5827 | status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5828 | if (status < 0) |
| 5829 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5830 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5831 | } |
| 5832 | /* Write magic word to disable pdr reg write */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5833 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5834 | if (status < 0) |
| 5835 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5836 | } while (0); |
| 5837 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | static int SwitchAntennaToQAM(struct drxk_state *state) |
| 5841 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5842 | int status = -1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5843 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5844 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5845 | if (state->m_AntennaSwitchDVBTDVBC != 0) { |
| 5846 | if (state->m_GPIO != state->m_AntennaDVBC) { |
| 5847 | state->m_GPIO = state->m_AntennaDVBC; |
| 5848 | status = WriteGPIO(state); |
| 5849 | } |
| 5850 | } |
| 5851 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | static int SwitchAntennaToDVBT(struct drxk_state *state) |
| 5855 | { |
| 5856 | int status = -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5857 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5858 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5859 | if (state->m_AntennaSwitchDVBTDVBC != 0) { |
| 5860 | if (state->m_GPIO != state->m_AntennaDVBT) { |
| 5861 | state->m_GPIO = state->m_AntennaDVBT; |
| 5862 | status = WriteGPIO(state); |
| 5863 | } |
| 5864 | } |
| 5865 | return status; |
| 5866 | } |
| 5867 | |
| 5868 | |
| 5869 | static int PowerDownDevice(struct drxk_state *state) |
| 5870 | { |
| 5871 | /* Power down to requested mode */ |
| 5872 | /* Backup some register settings */ |
| 5873 | /* Set pins with possible pull-ups connected to them in input mode */ |
| 5874 | /* Analog power down */ |
| 5875 | /* ADC power down */ |
| 5876 | /* Power down device */ |
| 5877 | int status; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5878 | |
| 5879 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5880 | do { |
| 5881 | if (state->m_bPDownOpenBridge) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5882 | /* Open I2C bridge before power down of DRXK */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5883 | status = ConfigureI2CBridge(state, true); |
| 5884 | if (status < 0) |
| 5885 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5886 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5887 | /* driver 0.9.0 */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5888 | status = DVBTEnableOFDMTokenRing(state, false); |
| 5889 | if (status < 0) |
| 5890 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5891 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5892 | 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] | 5893 | if (status < 0) |
| 5894 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5895 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5896 | if (status < 0) |
| 5897 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5898 | 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] | 5899 | status = HI_CfgCommand(state); |
| 5900 | if (status < 0) |
| 5901 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5902 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5903 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5904 | if (status < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5905 | return -1; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5906 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5907 | return 0; |
| 5908 | } |
| 5909 | |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 5910 | static int load_microcode(struct drxk_state *state, const char *mc_name) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5911 | { |
| 5912 | const struct firmware *fw = NULL; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5913 | int err = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5914 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5915 | dprintk(1, "\n"); |
| 5916 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5917 | err = request_firmware(&fw, mc_name, state->i2c->dev.parent); |
| 5918 | if (err < 0) { |
| 5919 | printk(KERN_ERR |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5920 | "drxk: Could not load firmware file %s.\n", mc_name); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5921 | printk(KERN_INFO |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 5922 | "drxk: Copy %s to your hotplug directory!\n", mc_name); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5923 | return err; |
| 5924 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5925 | err = DownloadMicrocode(state, fw->data, fw->size); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5926 | release_firmware(fw); |
| 5927 | return err; |
| 5928 | } |
| 5929 | |
| 5930 | static int init_drxk(struct drxk_state *state) |
| 5931 | { |
| 5932 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5933 | enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5934 | u16 driverVersion; |
| 5935 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5936 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5937 | if ((state->m_DrxkState == DRXK_UNINITIALIZED)) { |
| 5938 | do { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5939 | status = PowerUpDevice(state); |
| 5940 | if (status < 0) |
| 5941 | break; |
| 5942 | status = DRXX_Open(state); |
| 5943 | if (status < 0) |
| 5944 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5945 | /* Soft reset of OFDM-, sys- and osc-clockdomain */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5946 | 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] | 5947 | if (status < 0) |
| 5948 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5949 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5950 | if (status < 0) |
| 5951 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5952 | /* TODO is this needed, if yes how much delay in worst case scenario */ |
| 5953 | msleep(1); |
| 5954 | state->m_DRXK_A3_PATCH_CODE = true; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5955 | status = GetDeviceCapabilities(state); |
| 5956 | if (status < 0) |
| 5957 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5958 | |
| 5959 | /* Bridge delay, uses oscilator clock */ |
| 5960 | /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */ |
| 5961 | /* SDA brdige delay */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5962 | state->m_HICfgBridgeDelay = |
| 5963 | (u16) ((state->m_oscClockFreq / 1000) * |
| 5964 | HI_I2C_BRIDGE_DELAY) / 1000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5965 | /* Clipping */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5966 | if (state->m_HICfgBridgeDelay > |
| 5967 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) { |
| 5968 | state->m_HICfgBridgeDelay = |
| 5969 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5970 | } |
| 5971 | /* SCL bridge delay, same as SDA for now */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5972 | state->m_HICfgBridgeDelay += |
| 5973 | state->m_HICfgBridgeDelay << |
| 5974 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5975 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5976 | status = InitHI(state); |
| 5977 | if (status < 0) |
| 5978 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5979 | /* disable various processes */ |
| 5980 | #if NOA1ROM |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5981 | if (!(state->m_DRXK_A1_ROM_CODE) |
| 5982 | && !(state->m_DRXK_A2_ROM_CODE)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5983 | #endif |
| 5984 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5985 | 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] | 5986 | if (status < 0) |
| 5987 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /* disable MPEG port */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5991 | status = MPEGTSDisable(state); |
| 5992 | if (status < 0) |
| 5993 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5994 | |
| 5995 | /* Stop AUD and SCU */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5996 | status = write16(state, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5997 | if (status < 0) |
| 5998 | break; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 5999 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6000 | if (status < 0) |
| 6001 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6002 | |
| 6003 | /* enable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6004 | 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] | 6005 | if (status < 0) |
| 6006 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6007 | |
| 6008 | /* include boot loader section */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6009 | 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] | 6010 | if (status < 0) |
| 6011 | break; |
| 6012 | status = BLChainCmd(state, 0, 6, 100); |
| 6013 | if (status < 0) |
| 6014 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6015 | |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 6016 | if (!state->microcode_name) |
| 6017 | load_microcode(state, "drxk_a3.mc"); |
| 6018 | else |
| 6019 | load_microcode(state, state->microcode_name); |
| 6020 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6021 | /* disable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6022 | 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] | 6023 | if (status < 0) |
| 6024 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6025 | |
| 6026 | /* Run SCU for a little while to initialize microcode version numbers */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6027 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6028 | if (status < 0) |
| 6029 | break; |
| 6030 | status = DRXX_Open(state); |
| 6031 | if (status < 0) |
| 6032 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6033 | /* added for test */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6034 | msleep(30); |
| 6035 | |
| 6036 | powerMode = DRXK_POWER_DOWN_OFDM; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6037 | status = CtrlPowerMode(state, &powerMode); |
| 6038 | if (status < 0) |
| 6039 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6040 | |
| 6041 | /* Stamp driver version number in SCU data RAM in BCD code |
| 6042 | Done to enable field application engineers to retreive drxdriver version |
| 6043 | via I2C from SCU RAM. |
| 6044 | Not using SCU command interface for SCU register access since no |
| 6045 | microcode may be present. |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6046 | */ |
| 6047 | driverVersion = |
| 6048 | (((DRXK_VERSION_MAJOR / 100) % 10) << 12) + |
| 6049 | (((DRXK_VERSION_MAJOR / 10) % 10) << 8) + |
| 6050 | ((DRXK_VERSION_MAJOR % 10) << 4) + |
| 6051 | (DRXK_VERSION_MINOR % 10); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6052 | status = write16(state, SCU_RAM_DRIVER_VER_HI__A, driverVersion); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6053 | if (status < 0) |
| 6054 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6055 | driverVersion = |
| 6056 | (((DRXK_VERSION_PATCH / 1000) % 10) << 12) + |
| 6057 | (((DRXK_VERSION_PATCH / 100) % 10) << 8) + |
| 6058 | (((DRXK_VERSION_PATCH / 10) % 10) << 4) + |
| 6059 | (DRXK_VERSION_PATCH % 10); |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6060 | status = write16(state, SCU_RAM_DRIVER_VER_LO__A, driverVersion); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6061 | if (status < 0) |
| 6062 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6063 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6064 | printk(KERN_INFO "DRXK driver version %d.%d.%d\n", |
| 6065 | DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR, |
| 6066 | DRXK_VERSION_PATCH); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6067 | |
| 6068 | /* Dirty fix of default values for ROM/PATCH microcode |
| 6069 | Dirty because this fix makes it impossible to setup suitable values |
| 6070 | before calling DRX_Open. This solution requires changes to RF AGC speed |
| 6071 | to be done via the CTRL function after calling DRX_Open */ |
| 6072 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6073 | /* m_dvbtRfAgcCfg.speed = 3; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6074 | |
| 6075 | /* Reset driver debug flags to 0 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6076 | status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6077 | if (status < 0) |
| 6078 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6079 | /* driver 0.9.0 */ |
| 6080 | /* Setup FEC OC: |
| 6081 | NOTE: No more full FEC resets allowed afterwards!! */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 6082 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6083 | if (status < 0) |
| 6084 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6085 | /* MPEGTS functions are still the same */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6086 | status = MPEGTSDtoInit(state); |
| 6087 | if (status < 0) |
| 6088 | break; |
| 6089 | status = MPEGTSStop(state); |
| 6090 | if (status < 0) |
| 6091 | break; |
| 6092 | status = MPEGTSConfigurePolarity(state); |
| 6093 | if (status < 0) |
| 6094 | break; |
| 6095 | status = MPEGTSConfigurePins(state, state->m_enableMPEGOutput); |
| 6096 | if (status < 0) |
| 6097 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6098 | /* added: configure GPIO */ |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6099 | status = WriteGPIO(state); |
| 6100 | if (status < 0) |
| 6101 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6102 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6103 | state->m_DrxkState = DRXK_STOPPED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6104 | |
| 6105 | if (state->m_bPowerDown) { |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6106 | status = PowerDownDevice(state); |
| 6107 | if (status < 0) |
| 6108 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6109 | state->m_DrxkState = DRXK_POWERED_DOWN; |
| 6110 | } else |
| 6111 | state->m_DrxkState = DRXK_STOPPED; |
| 6112 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6113 | } |
| 6114 | |
| 6115 | return 0; |
| 6116 | } |
| 6117 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6118 | static void drxk_c_release(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6119 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6120 | struct drxk_state *state = fe->demodulator_priv; |
| 6121 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6122 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6123 | kfree(state); |
| 6124 | } |
| 6125 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6126 | static int drxk_c_init(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6127 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6128 | struct drxk_state *state = fe->demodulator_priv; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6129 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6130 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6131 | if (mutex_trylock(&state->ctlock) == 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6132 | return -EBUSY; |
| 6133 | SetOperationMode(state, OM_QAM_ITU_A); |
| 6134 | return 0; |
| 6135 | } |
| 6136 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6137 | static int drxk_c_sleep(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6138 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6139 | struct drxk_state *state = fe->demodulator_priv; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6140 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6141 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6142 | ShutDown(state); |
| 6143 | mutex_unlock(&state->ctlock); |
| 6144 | return 0; |
| 6145 | } |
| 6146 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6147 | static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6148 | { |
| 6149 | struct drxk_state *state = fe->demodulator_priv; |
| 6150 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6151 | dprintk(1, "%s\n", enable ? "enable" : "disable"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6152 | return ConfigureI2CBridge(state, enable ? true : false); |
| 6153 | } |
| 6154 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6155 | static int drxk_set_parameters(struct dvb_frontend *fe, |
| 6156 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6157 | { |
| 6158 | struct drxk_state *state = fe->demodulator_priv; |
| 6159 | u32 IF; |
| 6160 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6161 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6162 | if (fe->ops.i2c_gate_ctrl) |
| 6163 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 6164 | if (fe->ops.tuner_ops.set_params) |
| 6165 | fe->ops.tuner_ops.set_params(fe, p); |
| 6166 | if (fe->ops.i2c_gate_ctrl) |
| 6167 | fe->ops.i2c_gate_ctrl(fe, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6168 | state->param = *p; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6169 | fe->ops.tuner_ops.get_frequency(fe, &IF); |
| 6170 | Start(state, 0, IF); |
| 6171 | |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 6172 | /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6173 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6174 | return 0; |
| 6175 | } |
| 6176 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6177 | static int drxk_c_get_frontend(struct dvb_frontend *fe, |
| 6178 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6179 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6180 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6181 | return 0; |
| 6182 | } |
| 6183 | |
| 6184 | static int drxk_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 6185 | { |
| 6186 | struct drxk_state *state = fe->demodulator_priv; |
| 6187 | u32 stat; |
| 6188 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6189 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6190 | *status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6191 | GetLockStatus(state, &stat, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6192 | if (stat == MPEG_LOCK) |
| 6193 | *status |= 0x1f; |
| 6194 | if (stat == FEC_LOCK) |
| 6195 | *status |= 0x0f; |
| 6196 | if (stat == DEMOD_LOCK) |
| 6197 | *status |= 0x07; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6198 | return 0; |
| 6199 | } |
| 6200 | |
| 6201 | static int drxk_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 6202 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6203 | dprintk(1, "\n"); |
| 6204 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6205 | *ber = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6206 | return 0; |
| 6207 | } |
| 6208 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6209 | static int drxk_read_signal_strength(struct dvb_frontend *fe, |
| 6210 | u16 *strength) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6211 | { |
| 6212 | struct drxk_state *state = fe->demodulator_priv; |
| 6213 | u32 val; |
| 6214 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6215 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6216 | ReadIFAgc(state, &val); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6217 | *strength = val & 0xffff; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6218 | return 0; |
| 6219 | } |
| 6220 | |
| 6221 | static int drxk_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 6222 | { |
| 6223 | struct drxk_state *state = fe->demodulator_priv; |
| 6224 | s32 snr2; |
| 6225 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6226 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6227 | GetSignalToNoise(state, &snr2); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6228 | *snr = snr2 & 0xffff; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6229 | return 0; |
| 6230 | } |
| 6231 | |
| 6232 | static int drxk_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 6233 | { |
| 6234 | struct drxk_state *state = fe->demodulator_priv; |
| 6235 | u16 err; |
| 6236 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6237 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6238 | DVBTQAMGetAccPktErr(state, &err); |
| 6239 | *ucblocks = (u32) err; |
| 6240 | return 0; |
| 6241 | } |
| 6242 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6243 | static int drxk_c_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings |
| 6244 | *sets) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6245 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6246 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6247 | sets->min_delay_ms = 3000; |
| 6248 | sets->max_drift = 0; |
| 6249 | sets->step_size = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6250 | return 0; |
| 6251 | } |
| 6252 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6253 | static void drxk_t_release(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6254 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6255 | #if 0 |
| 6256 | struct drxk_state *state = fe->demodulator_priv; |
| 6257 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6258 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6259 | kfree(state); |
| 6260 | #endif |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6261 | } |
| 6262 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6263 | static int drxk_t_init(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6264 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6265 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6266 | |
| 6267 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6268 | if (mutex_trylock(&state->ctlock) == 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6269 | return -EBUSY; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6270 | SetOperationMode(state, OM_DVBT); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6271 | return 0; |
| 6272 | } |
| 6273 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6274 | static int drxk_t_sleep(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6275 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6276 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6277 | |
| 6278 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6279 | mutex_unlock(&state->ctlock); |
| 6280 | return 0; |
| 6281 | } |
| 6282 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6283 | static int drxk_t_get_frontend(struct dvb_frontend *fe, |
| 6284 | struct dvb_frontend_parameters *p) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6285 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6286 | dprintk(1, "\n"); |
| 6287 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6288 | return 0; |
| 6289 | } |
| 6290 | |
| 6291 | static struct dvb_frontend_ops drxk_c_ops = { |
| 6292 | .info = { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6293 | .name = "DRXK DVB-C", |
| 6294 | .type = FE_QAM, |
| 6295 | .frequency_stepsize = 62500, |
| 6296 | .frequency_min = 47000000, |
| 6297 | .frequency_max = 862000000, |
| 6298 | .symbol_rate_min = 870000, |
| 6299 | .symbol_rate_max = 11700000, |
| 6300 | .caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 | |
| 6301 | FE_CAN_QAM_128 | FE_CAN_QAM_256 | FE_CAN_FEC_AUTO}, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6302 | .release = drxk_c_release, |
| 6303 | .init = drxk_c_init, |
| 6304 | .sleep = drxk_c_sleep, |
| 6305 | .i2c_gate_ctrl = drxk_gate_ctrl, |
| 6306 | |
| 6307 | .set_frontend = drxk_set_parameters, |
| 6308 | .get_frontend = drxk_c_get_frontend, |
| 6309 | .get_tune_settings = drxk_c_get_tune_settings, |
| 6310 | |
| 6311 | .read_status = drxk_read_status, |
| 6312 | .read_ber = drxk_read_ber, |
| 6313 | .read_signal_strength = drxk_read_signal_strength, |
| 6314 | .read_snr = drxk_read_snr, |
| 6315 | .read_ucblocks = drxk_read_ucblocks, |
| 6316 | }; |
| 6317 | |
| 6318 | static struct dvb_frontend_ops drxk_t_ops = { |
| 6319 | .info = { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6320 | .name = "DRXK DVB-T", |
| 6321 | .type = FE_OFDM, |
| 6322 | .frequency_min = 47125000, |
| 6323 | .frequency_max = 865000000, |
| 6324 | .frequency_stepsize = 166667, |
| 6325 | .frequency_tolerance = 0, |
| 6326 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | |
| 6327 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | |
| 6328 | FE_CAN_FEC_AUTO | |
| 6329 | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
| 6330 | FE_CAN_QAM_AUTO | |
| 6331 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 6332 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 6333 | FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS}, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6334 | .release = drxk_t_release, |
| 6335 | .init = drxk_t_init, |
| 6336 | .sleep = drxk_t_sleep, |
| 6337 | .i2c_gate_ctrl = drxk_gate_ctrl, |
| 6338 | |
| 6339 | .set_frontend = drxk_set_parameters, |
| 6340 | .get_frontend = drxk_t_get_frontend, |
| 6341 | |
| 6342 | .read_status = drxk_read_status, |
| 6343 | .read_ber = drxk_read_ber, |
| 6344 | .read_signal_strength = drxk_read_signal_strength, |
| 6345 | .read_snr = drxk_read_snr, |
| 6346 | .read_ucblocks = drxk_read_ucblocks, |
| 6347 | }; |
| 6348 | |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6349 | struct dvb_frontend *drxk_attach(const struct drxk_config *config, |
| 6350 | struct i2c_adapter *i2c, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6351 | struct dvb_frontend **fe_t) |
| 6352 | { |
| 6353 | struct drxk_state *state = NULL; |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6354 | u8 adr = config->adr; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6355 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6356 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6357 | state = kzalloc(sizeof(struct drxk_state), GFP_KERNEL); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6358 | if (!state) |
| 6359 | return NULL; |
| 6360 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6361 | state->i2c = i2c; |
| 6362 | state->demod_address = adr; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 6363 | state->single_master = config->single_master; |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 6364 | state->microcode_name = config->microcode_name; |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame^] | 6365 | state->no_i2c_bridge = config->no_i2c_bridge; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6366 | |
| 6367 | mutex_init(&state->mutex); |
| 6368 | mutex_init(&state->ctlock); |
| 6369 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6370 | memcpy(&state->c_frontend.ops, &drxk_c_ops, |
| 6371 | sizeof(struct dvb_frontend_ops)); |
| 6372 | memcpy(&state->t_frontend.ops, &drxk_t_ops, |
| 6373 | sizeof(struct dvb_frontend_ops)); |
| 6374 | state->c_frontend.demodulator_priv = state; |
| 6375 | state->t_frontend.demodulator_priv = state; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6376 | |
| 6377 | init_state(state); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6378 | if (init_drxk(state) < 0) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6379 | goto error; |
| 6380 | *fe_t = &state->t_frontend; |
| 6381 | return &state->c_frontend; |
| 6382 | |
| 6383 | error: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6384 | printk(KERN_ERR "drxk: not found\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6385 | kfree(state); |
| 6386 | return NULL; |
| 6387 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6388 | EXPORT_SYMBOL(drxk_attach); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6389 | |
| 6390 | MODULE_DESCRIPTION("DRX-K driver"); |
| 6391 | MODULE_AUTHOR("Ralph Metzler"); |
| 6392 | MODULE_LICENSE("GPL"); |