Thomas Gleixner | 89ee7f4 | 2019-06-04 10:10:54 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2 | /* |
| 3 | * drxk_hard: DRX-K DVB-C/T demodulator driver |
| 4 | * |
| 5 | * Copyright (C) 2010-2011 Digital Devices GmbH |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6 | */ |
| 7 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/firmware.h> |
| 16 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 17 | #include <linux/hardirq.h> |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 18 | #include <asm/div64.h> |
| 19 | |
Mauro Carvalho Chehab | fada193 | 2017-12-28 13:03:51 -0500 | [diff] [blame] | 20 | #include <media/dvb_frontend.h> |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 21 | #include "drxk.h" |
| 22 | #include "drxk_hard.h" |
Mauro Carvalho Chehab | fada193 | 2017-12-28 13:03:51 -0500 | [diff] [blame] | 23 | #include <media/dvb_math.h> |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 24 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 25 | static int power_down_dvbt(struct drxk_state *state, bool set_power_mode); |
| 26 | static int power_down_qam(struct drxk_state *state); |
| 27 | static int set_dvbt_standard(struct drxk_state *state, |
| 28 | enum operation_mode o_mode); |
| 29 | static int set_qam_standard(struct drxk_state *state, |
| 30 | enum operation_mode o_mode); |
| 31 | static int set_qam(struct drxk_state *state, u16 intermediate_freqk_hz, |
| 32 | s32 tuner_freq_offset); |
| 33 | static int set_dvbt_standard(struct drxk_state *state, |
| 34 | enum operation_mode o_mode); |
| 35 | static int dvbt_start(struct drxk_state *state); |
| 36 | static int set_dvbt(struct drxk_state *state, u16 intermediate_freqk_hz, |
| 37 | s32 tuner_freq_offset); |
| 38 | static int get_qam_lock_status(struct drxk_state *state, u32 *p_lock_status); |
| 39 | static int get_dvbt_lock_status(struct drxk_state *state, u32 *p_lock_status); |
| 40 | static int switch_antenna_to_qam(struct drxk_state *state); |
| 41 | static int switch_antenna_to_dvbt(struct drxk_state *state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 42 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 43 | static bool is_dvbt(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 44 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 45 | return state->m_operation_mode == OM_DVBT; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 46 | } |
| 47 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 48 | static bool is_qam(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 49 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 50 | return state->m_operation_mode == OM_QAM_ITU_A || |
| 51 | state->m_operation_mode == OM_QAM_ITU_B || |
| 52 | state->m_operation_mode == OM_QAM_ITU_C; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 53 | } |
| 54 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 55 | #define NOA1ROM 0 |
| 56 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 57 | #define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0) |
| 58 | #define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0) |
| 59 | |
| 60 | #define DEFAULT_MER_83 165 |
| 61 | #define DEFAULT_MER_93 250 |
| 62 | |
| 63 | #ifndef DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH |
| 64 | #define DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH (0x02) |
| 65 | #endif |
| 66 | |
| 67 | #ifndef DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH |
| 68 | #define DRXK_MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH (0x03) |
| 69 | #endif |
| 70 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 71 | #define DEFAULT_DRXK_MPEG_LOCK_TIMEOUT 700 |
| 72 | #define DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT 500 |
| 73 | |
| 74 | #ifndef DRXK_KI_RAGC_ATV |
| 75 | #define DRXK_KI_RAGC_ATV 4 |
| 76 | #endif |
| 77 | #ifndef DRXK_KI_IAGC_ATV |
| 78 | #define DRXK_KI_IAGC_ATV 6 |
| 79 | #endif |
| 80 | #ifndef DRXK_KI_DAGC_ATV |
| 81 | #define DRXK_KI_DAGC_ATV 7 |
| 82 | #endif |
| 83 | |
| 84 | #ifndef DRXK_KI_RAGC_QAM |
| 85 | #define DRXK_KI_RAGC_QAM 3 |
| 86 | #endif |
| 87 | #ifndef DRXK_KI_IAGC_QAM |
| 88 | #define DRXK_KI_IAGC_QAM 4 |
| 89 | #endif |
| 90 | #ifndef DRXK_KI_DAGC_QAM |
| 91 | #define DRXK_KI_DAGC_QAM 7 |
| 92 | #endif |
| 93 | #ifndef DRXK_KI_RAGC_DVBT |
| 94 | #define DRXK_KI_RAGC_DVBT (IsA1WithPatchCode(state) ? 3 : 2) |
| 95 | #endif |
| 96 | #ifndef DRXK_KI_IAGC_DVBT |
| 97 | #define DRXK_KI_IAGC_DVBT (IsA1WithPatchCode(state) ? 4 : 2) |
| 98 | #endif |
| 99 | #ifndef DRXK_KI_DAGC_DVBT |
| 100 | #define DRXK_KI_DAGC_DVBT (IsA1WithPatchCode(state) ? 10 : 7) |
| 101 | #endif |
| 102 | |
| 103 | #ifndef DRXK_AGC_DAC_OFFSET |
| 104 | #define DRXK_AGC_DAC_OFFSET (0x800) |
| 105 | #endif |
| 106 | |
| 107 | #ifndef DRXK_BANDWIDTH_8MHZ_IN_HZ |
| 108 | #define DRXK_BANDWIDTH_8MHZ_IN_HZ (0x8B8249L) |
| 109 | #endif |
| 110 | |
| 111 | #ifndef DRXK_BANDWIDTH_7MHZ_IN_HZ |
| 112 | #define DRXK_BANDWIDTH_7MHZ_IN_HZ (0x7A1200L) |
| 113 | #endif |
| 114 | |
| 115 | #ifndef DRXK_BANDWIDTH_6MHZ_IN_HZ |
| 116 | #define DRXK_BANDWIDTH_6MHZ_IN_HZ (0x68A1B6L) |
| 117 | #endif |
| 118 | |
| 119 | #ifndef DRXK_QAM_SYMBOLRATE_MAX |
| 120 | #define DRXK_QAM_SYMBOLRATE_MAX (7233000) |
| 121 | #endif |
| 122 | |
| 123 | #define DRXK_BL_ROM_OFFSET_TAPS_DVBT 56 |
| 124 | #define DRXK_BL_ROM_OFFSET_TAPS_ITU_A 64 |
| 125 | #define DRXK_BL_ROM_OFFSET_TAPS_ITU_C 0x5FE0 |
| 126 | #define DRXK_BL_ROM_OFFSET_TAPS_BG 24 |
| 127 | #define DRXK_BL_ROM_OFFSET_TAPS_DKILLP 32 |
| 128 | #define DRXK_BL_ROM_OFFSET_TAPS_NTSC 40 |
| 129 | #define DRXK_BL_ROM_OFFSET_TAPS_FM 48 |
| 130 | #define DRXK_BL_ROM_OFFSET_UCODE 0 |
| 131 | |
| 132 | #define DRXK_BLC_TIMEOUT 100 |
| 133 | |
| 134 | #define DRXK_BLCC_NR_ELEMENTS_TAPS 2 |
| 135 | #define DRXK_BLCC_NR_ELEMENTS_UCODE 6 |
| 136 | |
| 137 | #define DRXK_BLDC_NR_ELEMENTS_TAPS 28 |
| 138 | |
| 139 | #ifndef DRXK_OFDM_NE_NOTCH_WIDTH |
| 140 | #define DRXK_OFDM_NE_NOTCH_WIDTH (4) |
| 141 | #endif |
| 142 | |
| 143 | #define DRXK_QAM_SL_SIG_POWER_QAM16 (40960) |
| 144 | #define DRXK_QAM_SL_SIG_POWER_QAM32 (20480) |
| 145 | #define DRXK_QAM_SL_SIG_POWER_QAM64 (43008) |
| 146 | #define DRXK_QAM_SL_SIG_POWER_QAM128 (20992) |
| 147 | #define DRXK_QAM_SL_SIG_POWER_QAM256 (43520) |
| 148 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 149 | static unsigned int debug; |
| 150 | module_param(debug, int, 0644); |
| 151 | MODULE_PARM_DESC(debug, "enable debug messages"); |
| 152 | |
Mauro Carvalho Chehab | 52ee29f | 2014-09-28 23:23:19 -0300 | [diff] [blame] | 153 | #define dprintk(level, fmt, arg...) do { \ |
| 154 | if (debug >= level) \ |
| 155 | printk(KERN_DEBUG KBUILD_MODNAME ": %s " fmt, __func__, ##arg); \ |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 156 | } while (0) |
| 157 | |
| 158 | |
Mauro Carvalho Chehab | b01fbc1 | 2011-07-03 17:18:57 -0300 | [diff] [blame] | 159 | static inline u32 MulDiv32(u32 a, u32 b, u32 c) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 160 | { |
| 161 | u64 tmp64; |
| 162 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 163 | tmp64 = (u64) a * (u64) b; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 164 | do_div(tmp64, c); |
| 165 | |
| 166 | return (u32) tmp64; |
| 167 | } |
| 168 | |
Mauro Carvalho Chehab | ff38c21 | 2012-10-25 13:40:04 -0200 | [diff] [blame] | 169 | static inline u32 Frac28a(u32 a, u32 c) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 170 | { |
| 171 | int i = 0; |
| 172 | u32 Q1 = 0; |
| 173 | u32 R0 = 0; |
| 174 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 175 | R0 = (a % c) << 4; /* 32-28 == 4 shifts possible at max */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 176 | Q1 = a / c; /* |
| 177 | * integer part, only the 4 least significant |
| 178 | * bits will be visible in the result |
| 179 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 180 | |
| 181 | /* division using radix 16, 7 nibbles in the result */ |
| 182 | for (i = 0; i < 7; i++) { |
| 183 | Q1 = (Q1 << 4) | (R0 / c); |
| 184 | R0 = (R0 % c) << 4; |
| 185 | } |
| 186 | /* rounding */ |
| 187 | if ((R0 >> 3) >= c) |
| 188 | Q1++; |
| 189 | |
| 190 | return Q1; |
| 191 | } |
| 192 | |
Mauro Carvalho Chehab | b5e9eb6 | 2013-04-28 11:47:43 -0300 | [diff] [blame] | 193 | static inline u32 log10times100(u32 value) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 194 | { |
Mauro Carvalho Chehab | b5e9eb6 | 2013-04-28 11:47:43 -0300 | [diff] [blame] | 195 | return (100L * intlog10(value)) >> 24; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 196 | } |
| 197 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 198 | /***************************************************************************/ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 199 | /* I2C **********************************************************************/ |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 200 | /***************************************************************************/ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 201 | |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 202 | static int drxk_i2c_lock(struct drxk_state *state) |
| 203 | { |
Peter Rosin | c060a9f | 2018-06-20 07:17:58 +0200 | [diff] [blame] | 204 | i2c_lock_bus(state->i2c, I2C_LOCK_SEGMENT); |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 205 | state->drxk_i2c_exclusive_lock = true; |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static void drxk_i2c_unlock(struct drxk_state *state) |
| 211 | { |
| 212 | if (!state->drxk_i2c_exclusive_lock) |
| 213 | return; |
| 214 | |
Peter Rosin | c060a9f | 2018-06-20 07:17:58 +0200 | [diff] [blame] | 215 | i2c_unlock_bus(state->i2c, I2C_LOCK_SEGMENT); |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 216 | state->drxk_i2c_exclusive_lock = false; |
| 217 | } |
| 218 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 219 | static int drxk_i2c_transfer(struct drxk_state *state, struct i2c_msg *msgs, |
| 220 | unsigned len) |
| 221 | { |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 222 | if (state->drxk_i2c_exclusive_lock) |
| 223 | return __i2c_transfer(state->i2c, msgs, len); |
| 224 | else |
| 225 | return i2c_transfer(state->i2c, msgs, len); |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static int i2c_read1(struct drxk_state *state, u8 adr, u8 *val) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 229 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 230 | struct i2c_msg msgs[1] = { {.addr = adr, .flags = I2C_M_RD, |
| 231 | .buf = val, .len = 1} |
| 232 | }; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 233 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 234 | return drxk_i2c_transfer(state, msgs, 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 235 | } |
| 236 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 237 | static int i2c_write(struct drxk_state *state, u8 adr, u8 *data, int len) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 238 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 239 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 240 | struct i2c_msg msg = { |
| 241 | .addr = adr, .flags = 0, .buf = data, .len = len }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 242 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 243 | dprintk(3, ":"); |
| 244 | if (debug > 2) { |
| 245 | int i; |
| 246 | for (i = 0; i < len; i++) |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 247 | pr_cont(" %02x", data[i]); |
| 248 | pr_cont("\n"); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 249 | } |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 250 | status = drxk_i2c_transfer(state, &msg, 1); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 251 | if (status >= 0 && status != 1) |
| 252 | status = -EIO; |
| 253 | |
| 254 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 255 | pr_err("i2c write error at addr 0x%02x\n", adr); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 256 | |
| 257 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 258 | } |
| 259 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 260 | static int i2c_read(struct drxk_state *state, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 261 | u8 adr, u8 *msg, int len, u8 *answ, int alen) |
| 262 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 263 | int status; |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 264 | struct i2c_msg msgs[2] = { |
| 265 | {.addr = adr, .flags = 0, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 266 | .buf = msg, .len = len}, |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 267 | {.addr = adr, .flags = I2C_M_RD, |
| 268 | .buf = answ, .len = alen} |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 269 | }; |
Mauro Carvalho Chehab | f07a0bc | 2011-07-21 22:30:27 -0300 | [diff] [blame] | 270 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 271 | status = drxk_i2c_transfer(state, msgs, 2); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 272 | if (status != 2) { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 273 | if (debug > 2) |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 274 | pr_cont(": ERROR!\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 275 | if (status >= 0) |
| 276 | status = -EIO; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 277 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 278 | pr_err("i2c read error at addr 0x%02x\n", adr); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 279 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 280 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 281 | if (debug > 2) { |
| 282 | int i; |
Mauro Carvalho Chehab | 0d3e6fe | 2011-07-22 12:34:41 -0300 | [diff] [blame] | 283 | dprintk(2, ": read from"); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 284 | for (i = 0; i < len; i++) |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 285 | pr_cont(" %02x", msg[i]); |
| 286 | pr_cont(", value = "); |
Mauro Carvalho Chehab | f07a0bc | 2011-07-21 22:30:27 -0300 | [diff] [blame] | 287 | for (i = 0; i < alen; i++) |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 288 | pr_cont(" %02x", answ[i]); |
| 289 | pr_cont("\n"); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 290 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 294 | 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] | 295 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 296 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 297 | u8 adr = state->demod_address, mm1[4], mm2[2], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 298 | |
| 299 | if (state->single_master) |
| 300 | flags |= 0xC0; |
| 301 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 302 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 303 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 304 | mm1[1] = ((reg >> 16) & 0xFF); |
| 305 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 306 | mm1[3] = ((reg >> 7) & 0xFF); |
| 307 | len = 4; |
| 308 | } else { |
| 309 | mm1[0] = ((reg << 1) & 0xFF); |
| 310 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 311 | len = 2; |
| 312 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 313 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 314 | status = i2c_read(state, adr, mm1, len, mm2, 2); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 315 | if (status < 0) |
| 316 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 317 | if (data) |
| 318 | *data = mm2[0] | (mm2[1] << 8); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 319 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 323 | static int read16(struct drxk_state *state, u32 reg, u16 *data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 324 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 325 | return read16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 326 | } |
| 327 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 328 | 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] | 329 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 330 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 331 | u8 adr = state->demod_address, mm1[4], mm2[4], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 332 | |
| 333 | if (state->single_master) |
| 334 | flags |= 0xC0; |
| 335 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 336 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 337 | mm1[0] = (((reg << 1) & 0xFF) | 0x01); |
| 338 | mm1[1] = ((reg >> 16) & 0xFF); |
| 339 | mm1[2] = ((reg >> 24) & 0xFF) | flags; |
| 340 | mm1[3] = ((reg >> 7) & 0xFF); |
| 341 | len = 4; |
| 342 | } else { |
| 343 | mm1[0] = ((reg << 1) & 0xFF); |
| 344 | mm1[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 345 | len = 2; |
| 346 | } |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 347 | dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 348 | status = i2c_read(state, adr, mm1, len, mm2, 4); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 349 | if (status < 0) |
| 350 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 351 | if (data) |
| 352 | *data = mm2[0] | (mm2[1] << 8) | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 353 | (mm2[2] << 16) | (mm2[3] << 24); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 354 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 358 | static int read32(struct drxk_state *state, u32 reg, u32 *data) |
| 359 | { |
| 360 | return read32_flags(state, reg, data, 0); |
| 361 | } |
| 362 | |
| 363 | 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] | 364 | { |
| 365 | u8 adr = state->demod_address, mm[6], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 366 | |
| 367 | if (state->single_master) |
| 368 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 369 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 370 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 371 | mm[1] = ((reg >> 16) & 0xFF); |
| 372 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 373 | mm[3] = ((reg >> 7) & 0xFF); |
| 374 | len = 4; |
| 375 | } else { |
| 376 | mm[0] = ((reg << 1) & 0xFF); |
| 377 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 378 | len = 2; |
| 379 | } |
| 380 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 381 | mm[len + 1] = (data >> 8) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 382 | |
| 383 | dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg, data, flags); |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 384 | return i2c_write(state, adr, mm, len + 2); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 385 | } |
| 386 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 387 | static int write16(struct drxk_state *state, u32 reg, u16 data) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 388 | { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 389 | return write16_flags(state, reg, data, 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 390 | } |
| 391 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 392 | 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] | 393 | { |
| 394 | u8 adr = state->demod_address, mm[8], len; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 395 | |
| 396 | if (state->single_master) |
| 397 | flags |= 0xC0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 398 | if (DRXDAP_FASI_LONG_FORMAT(reg) || (flags != 0)) { |
| 399 | mm[0] = (((reg << 1) & 0xFF) | 0x01); |
| 400 | mm[1] = ((reg >> 16) & 0xFF); |
| 401 | mm[2] = ((reg >> 24) & 0xFF) | flags; |
| 402 | mm[3] = ((reg >> 7) & 0xFF); |
| 403 | len = 4; |
| 404 | } else { |
| 405 | mm[0] = ((reg << 1) & 0xFF); |
| 406 | mm[1] = (((reg >> 16) & 0x0F) | ((reg >> 18) & 0xF0)); |
| 407 | len = 2; |
| 408 | } |
| 409 | mm[len] = data & 0xff; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 410 | mm[len + 1] = (data >> 8) & 0xff; |
| 411 | mm[len + 2] = (data >> 16) & 0xff; |
| 412 | mm[len + 3] = (data >> 24) & 0xff; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 413 | dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg, data, flags); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 415 | return i2c_write(state, adr, mm, len + 4); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 416 | } |
| 417 | |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 418 | static int write32(struct drxk_state *state, u32 reg, u32 data) |
| 419 | { |
| 420 | return write32_flags(state, reg, data, 0); |
| 421 | } |
| 422 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 423 | static int write_block(struct drxk_state *state, u32 address, |
| 424 | const int block_size, const u8 p_block[]) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 425 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 426 | int status = 0, blk_size = block_size; |
| 427 | u8 flags = 0; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 428 | |
| 429 | if (state->single_master) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 430 | flags |= 0xC0; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 431 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 432 | while (blk_size > 0) { |
| 433 | int chunk = blk_size > state->m_chunk_size ? |
| 434 | state->m_chunk_size : blk_size; |
| 435 | u8 *adr_buf = &state->chunk[0]; |
| 436 | u32 adr_length = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 437 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 438 | if (DRXDAP_FASI_LONG_FORMAT(address) || (flags != 0)) { |
| 439 | adr_buf[0] = (((address << 1) & 0xFF) | 0x01); |
| 440 | adr_buf[1] = ((address >> 16) & 0xFF); |
| 441 | adr_buf[2] = ((address >> 24) & 0xFF); |
| 442 | adr_buf[3] = ((address >> 7) & 0xFF); |
| 443 | adr_buf[2] |= flags; |
| 444 | adr_length = 4; |
| 445 | if (chunk == state->m_chunk_size) |
| 446 | chunk -= 2; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 447 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 448 | adr_buf[0] = ((address << 1) & 0xFF); |
| 449 | adr_buf[1] = (((address >> 16) & 0x0F) | |
| 450 | ((address >> 18) & 0xF0)); |
| 451 | adr_length = 2; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 452 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 453 | memcpy(&state->chunk[adr_length], p_block, chunk); |
| 454 | dprintk(2, "(0x%08x, 0x%02x)\n", address, flags); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 455 | if (debug > 1) { |
| 456 | int i; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 457 | if (p_block) |
| 458 | for (i = 0; i < chunk; i++) |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 459 | pr_cont(" %02x", p_block[i]); |
| 460 | pr_cont("\n"); |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 461 | } |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 462 | status = i2c_write(state, state->demod_address, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 463 | &state->chunk[0], chunk + adr_length); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 464 | if (status < 0) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 465 | pr_err("%s: i2c write error at addr 0x%02x\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 466 | __func__, address); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 467 | break; |
| 468 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 469 | p_block += chunk; |
| 470 | address += (chunk >> 1); |
| 471 | blk_size -= chunk; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 472 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 473 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | #ifndef DRXK_MAX_RETRIES_POWERUP |
| 477 | #define DRXK_MAX_RETRIES_POWERUP 20 |
| 478 | #endif |
| 479 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 480 | static int power_up_device(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 481 | { |
| 482 | int status; |
| 483 | u8 data = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 484 | u16 retry_count = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 485 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 486 | dprintk(1, "\n"); |
| 487 | |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 488 | status = i2c_read1(state, state->demod_address, &data); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 489 | if (status < 0) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 490 | do { |
| 491 | data = 0; |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 492 | status = i2c_write(state, state->demod_address, |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 493 | &data, 1); |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 494 | usleep_range(10000, 11000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 495 | retry_count++; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 496 | if (status < 0) |
| 497 | continue; |
Mauro Carvalho Chehab | 2a5f672 | 2012-06-29 14:24:18 -0300 | [diff] [blame] | 498 | status = i2c_read1(state, state->demod_address, |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 499 | &data); |
| 500 | } while (status < 0 && |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 501 | (retry_count < DRXK_MAX_RETRIES_POWERUP)); |
| 502 | if (status < 0 && retry_count >= DRXK_MAX_RETRIES_POWERUP) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 503 | goto error; |
| 504 | } |
| 505 | |
| 506 | /* Make sure all clk domains are active */ |
| 507 | status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_NONE); |
| 508 | if (status < 0) |
| 509 | goto error; |
| 510 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
| 511 | if (status < 0) |
| 512 | goto error; |
| 513 | /* Enable pll lock tests */ |
| 514 | status = write16(state, SIO_CC_PLL_LOCK__A, 1); |
| 515 | if (status < 0) |
| 516 | goto error; |
| 517 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 518 | state->m_current_power_mode = DRX_POWER_UP; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 519 | |
| 520 | error: |
| 521 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 522 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 523 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 524 | return status; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | static int init_state(struct drxk_state *state) |
| 529 | { |
Mauro Carvalho Chehab | 147e110 | 2011-07-10 08:24:26 -0300 | [diff] [blame] | 530 | /* |
Mauro Carvalho Chehab | 5a13e40 | 2015-05-08 08:59:16 -0300 | [diff] [blame] | 531 | * FIXME: most (all?) of the values below should be moved into |
Mauro Carvalho Chehab | 147e110 | 2011-07-10 08:24:26 -0300 | [diff] [blame] | 532 | * struct drxk_config, as they are probably board-specific |
| 533 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 534 | u32 ul_vsb_if_agc_mode = DRXK_AGC_CTRL_AUTO; |
| 535 | u32 ul_vsb_if_agc_output_level = 0; |
| 536 | u32 ul_vsb_if_agc_min_level = 0; |
| 537 | u32 ul_vsb_if_agc_max_level = 0x7FFF; |
| 538 | u32 ul_vsb_if_agc_speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 539 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 540 | u32 ul_vsb_rf_agc_mode = DRXK_AGC_CTRL_AUTO; |
| 541 | u32 ul_vsb_rf_agc_output_level = 0; |
| 542 | u32 ul_vsb_rf_agc_min_level = 0; |
| 543 | u32 ul_vsb_rf_agc_max_level = 0x7FFF; |
| 544 | u32 ul_vsb_rf_agc_speed = 3; |
| 545 | u32 ul_vsb_rf_agc_top = 9500; |
| 546 | u32 ul_vsb_rf_agc_cut_off_current = 4000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 547 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 548 | u32 ul_atv_if_agc_mode = DRXK_AGC_CTRL_AUTO; |
| 549 | u32 ul_atv_if_agc_output_level = 0; |
| 550 | u32 ul_atv_if_agc_min_level = 0; |
| 551 | u32 ul_atv_if_agc_max_level = 0; |
| 552 | u32 ul_atv_if_agc_speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 553 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 554 | u32 ul_atv_rf_agc_mode = DRXK_AGC_CTRL_OFF; |
| 555 | u32 ul_atv_rf_agc_output_level = 0; |
| 556 | u32 ul_atv_rf_agc_min_level = 0; |
| 557 | u32 ul_atv_rf_agc_max_level = 0; |
| 558 | u32 ul_atv_rf_agc_top = 9500; |
| 559 | u32 ul_atv_rf_agc_cut_off_current = 4000; |
| 560 | u32 ul_atv_rf_agc_speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 561 | |
| 562 | u32 ulQual83 = DEFAULT_MER_83; |
| 563 | u32 ulQual93 = DEFAULT_MER_93; |
| 564 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 565 | u32 ul_mpeg_lock_time_out = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 566 | u32 ul_demod_lock_time_out = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 567 | |
| 568 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
| 569 | /* io_pad_cfg_mode output mode is drive always */ |
| 570 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 571 | u32 ul_gpio_cfg = 0x0113; |
| 572 | u32 ul_invert_ts_clock = 0; |
| 573 | u32 ul_ts_data_strength = DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH; |
| 574 | u32 ul_dvbt_bitrate = 50000000; |
| 575 | u32 ul_dvbc_bitrate = DRXK_QAM_SYMBOLRATE_MAX * 8; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 576 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 577 | u32 ul_insert_rs_byte = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 578 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 579 | u32 ul_rf_mirror = 1; |
| 580 | u32 ul_power_down = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 581 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 582 | dprintk(1, "\n"); |
| 583 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 584 | state->m_has_lna = false; |
| 585 | state->m_has_dvbt = false; |
| 586 | state->m_has_dvbc = false; |
| 587 | state->m_has_atv = false; |
| 588 | state->m_has_oob = false; |
| 589 | state->m_has_audio = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 590 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 591 | if (!state->m_chunk_size) |
| 592 | state->m_chunk_size = 124; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 593 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 594 | state->m_osc_clock_freq = 0; |
| 595 | state->m_smart_ant_inverted = false; |
| 596 | state->m_b_p_down_open_bridge = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 597 | |
| 598 | /* real system clock frequency in kHz */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 599 | state->m_sys_clock_freq = 151875; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 600 | /* Timing div, 250ns/Psys */ |
| 601 | /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 602 | state->m_hi_cfg_timing_div = ((state->m_sys_clock_freq / 1000) * |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 603 | HI_I2C_DELAY) / 1000; |
| 604 | /* Clipping */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 605 | if (state->m_hi_cfg_timing_div > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M) |
| 606 | state->m_hi_cfg_timing_div = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M; |
| 607 | state->m_hi_cfg_wake_up_key = (state->demod_address << 1); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 608 | /* port/bridge/power down ctrl */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 609 | state->m_hi_cfg_ctrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 610 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 611 | state->m_b_power_down = (ul_power_down != 0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 612 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 613 | state->m_drxk_a3_patch_code = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 614 | |
| 615 | /* Init AGC and PGA parameters */ |
| 616 | /* VSB IF */ |
Mauro Carvalho Chehab | 949dd08 | 2013-04-28 11:47:50 -0300 | [diff] [blame] | 617 | state->m_vsb_if_agc_cfg.ctrl_mode = ul_vsb_if_agc_mode; |
| 618 | state->m_vsb_if_agc_cfg.output_level = ul_vsb_if_agc_output_level; |
| 619 | state->m_vsb_if_agc_cfg.min_output_level = ul_vsb_if_agc_min_level; |
| 620 | state->m_vsb_if_agc_cfg.max_output_level = ul_vsb_if_agc_max_level; |
| 621 | state->m_vsb_if_agc_cfg.speed = ul_vsb_if_agc_speed; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 622 | state->m_vsb_pga_cfg = 140; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 623 | |
| 624 | /* VSB RF */ |
Mauro Carvalho Chehab | 949dd08 | 2013-04-28 11:47:50 -0300 | [diff] [blame] | 625 | state->m_vsb_rf_agc_cfg.ctrl_mode = ul_vsb_rf_agc_mode; |
| 626 | state->m_vsb_rf_agc_cfg.output_level = ul_vsb_rf_agc_output_level; |
| 627 | state->m_vsb_rf_agc_cfg.min_output_level = ul_vsb_rf_agc_min_level; |
| 628 | state->m_vsb_rf_agc_cfg.max_output_level = ul_vsb_rf_agc_max_level; |
| 629 | state->m_vsb_rf_agc_cfg.speed = ul_vsb_rf_agc_speed; |
| 630 | state->m_vsb_rf_agc_cfg.top = ul_vsb_rf_agc_top; |
| 631 | state->m_vsb_rf_agc_cfg.cut_off_current = ul_vsb_rf_agc_cut_off_current; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 632 | state->m_vsb_pre_saw_cfg.reference = 0x07; |
| 633 | state->m_vsb_pre_saw_cfg.use_pre_saw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 634 | |
| 635 | state->m_Quality83percent = DEFAULT_MER_83; |
| 636 | state->m_Quality93percent = DEFAULT_MER_93; |
| 637 | if (ulQual93 <= 500 && ulQual83 < ulQual93) { |
| 638 | state->m_Quality83percent = ulQual83; |
| 639 | state->m_Quality93percent = ulQual93; |
| 640 | } |
| 641 | |
| 642 | /* ATV IF */ |
Mauro Carvalho Chehab | 949dd08 | 2013-04-28 11:47:50 -0300 | [diff] [blame] | 643 | state->m_atv_if_agc_cfg.ctrl_mode = ul_atv_if_agc_mode; |
| 644 | state->m_atv_if_agc_cfg.output_level = ul_atv_if_agc_output_level; |
| 645 | state->m_atv_if_agc_cfg.min_output_level = ul_atv_if_agc_min_level; |
| 646 | state->m_atv_if_agc_cfg.max_output_level = ul_atv_if_agc_max_level; |
| 647 | state->m_atv_if_agc_cfg.speed = ul_atv_if_agc_speed; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 648 | |
| 649 | /* ATV RF */ |
Mauro Carvalho Chehab | 949dd08 | 2013-04-28 11:47:50 -0300 | [diff] [blame] | 650 | state->m_atv_rf_agc_cfg.ctrl_mode = ul_atv_rf_agc_mode; |
| 651 | state->m_atv_rf_agc_cfg.output_level = ul_atv_rf_agc_output_level; |
| 652 | state->m_atv_rf_agc_cfg.min_output_level = ul_atv_rf_agc_min_level; |
| 653 | state->m_atv_rf_agc_cfg.max_output_level = ul_atv_rf_agc_max_level; |
| 654 | state->m_atv_rf_agc_cfg.speed = ul_atv_rf_agc_speed; |
| 655 | state->m_atv_rf_agc_cfg.top = ul_atv_rf_agc_top; |
| 656 | state->m_atv_rf_agc_cfg.cut_off_current = ul_atv_rf_agc_cut_off_current; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 657 | state->m_atv_pre_saw_cfg.reference = 0x04; |
| 658 | state->m_atv_pre_saw_cfg.use_pre_saw = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 659 | |
| 660 | |
| 661 | /* DVBT RF */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 662 | state->m_dvbt_rf_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_OFF; |
| 663 | state->m_dvbt_rf_agc_cfg.output_level = 0; |
| 664 | state->m_dvbt_rf_agc_cfg.min_output_level = 0; |
| 665 | state->m_dvbt_rf_agc_cfg.max_output_level = 0xFFFF; |
| 666 | state->m_dvbt_rf_agc_cfg.top = 0x2100; |
| 667 | state->m_dvbt_rf_agc_cfg.cut_off_current = 4000; |
| 668 | state->m_dvbt_rf_agc_cfg.speed = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 669 | |
| 670 | |
| 671 | /* DVBT IF */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 672 | state->m_dvbt_if_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_AUTO; |
| 673 | state->m_dvbt_if_agc_cfg.output_level = 0; |
| 674 | state->m_dvbt_if_agc_cfg.min_output_level = 0; |
| 675 | state->m_dvbt_if_agc_cfg.max_output_level = 9000; |
| 676 | state->m_dvbt_if_agc_cfg.top = 13424; |
| 677 | state->m_dvbt_if_agc_cfg.cut_off_current = 0; |
| 678 | state->m_dvbt_if_agc_cfg.speed = 3; |
| 679 | state->m_dvbt_if_agc_cfg.fast_clip_ctrl_delay = 30; |
| 680 | state->m_dvbt_if_agc_cfg.ingain_tgt_max = 30000; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 681 | /* state->m_dvbtPgaCfg = 140; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 682 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 683 | state->m_dvbt_pre_saw_cfg.reference = 4; |
| 684 | state->m_dvbt_pre_saw_cfg.use_pre_saw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 685 | |
| 686 | /* QAM RF */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 687 | state->m_qam_rf_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_OFF; |
| 688 | state->m_qam_rf_agc_cfg.output_level = 0; |
| 689 | state->m_qam_rf_agc_cfg.min_output_level = 6023; |
| 690 | state->m_qam_rf_agc_cfg.max_output_level = 27000; |
| 691 | state->m_qam_rf_agc_cfg.top = 0x2380; |
| 692 | state->m_qam_rf_agc_cfg.cut_off_current = 4000; |
| 693 | state->m_qam_rf_agc_cfg.speed = 3; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 694 | |
| 695 | /* QAM IF */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 696 | state->m_qam_if_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_AUTO; |
| 697 | state->m_qam_if_agc_cfg.output_level = 0; |
| 698 | state->m_qam_if_agc_cfg.min_output_level = 0; |
| 699 | state->m_qam_if_agc_cfg.max_output_level = 9000; |
| 700 | state->m_qam_if_agc_cfg.top = 0x0511; |
| 701 | state->m_qam_if_agc_cfg.cut_off_current = 0; |
| 702 | state->m_qam_if_agc_cfg.speed = 3; |
| 703 | state->m_qam_if_agc_cfg.ingain_tgt_max = 5119; |
| 704 | state->m_qam_if_agc_cfg.fast_clip_ctrl_delay = 50; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 705 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 706 | state->m_qam_pga_cfg = 140; |
| 707 | state->m_qam_pre_saw_cfg.reference = 4; |
| 708 | state->m_qam_pre_saw_cfg.use_pre_saw = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 709 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 710 | state->m_operation_mode = OM_NONE; |
| 711 | state->m_drxk_state = DRXK_UNINITIALIZED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 712 | |
| 713 | /* MPEG output configuration */ |
Mauro Carvalho Chehab | 868c9a1 | 2019-02-18 14:28:55 -0500 | [diff] [blame] | 714 | state->m_enable_mpeg_output = true; /* If TRUE; enable MPEG output */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 715 | state->m_insert_rs_byte = false; /* If TRUE; insert RS byte */ |
| 716 | state->m_invert_data = false; /* If TRUE; invert DATA signals */ |
| 717 | state->m_invert_err = false; /* If TRUE; invert ERR signal */ |
| 718 | state->m_invert_str = false; /* If TRUE; invert STR signals */ |
| 719 | state->m_invert_val = false; /* If TRUE; invert VAL signals */ |
| 720 | state->m_invert_clk = (ul_invert_ts_clock != 0); /* If TRUE; invert CLK signals */ |
Mauro Carvalho Chehab | 67f0461 | 2012-01-20 18:30:58 -0300 | [diff] [blame] | 721 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 722 | /* If TRUE; static MPEG clockrate will be used; |
| 723 | otherwise clockrate will adapt to the bitrate of the TS */ |
| 724 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 725 | state->m_dvbt_bitrate = ul_dvbt_bitrate; |
| 726 | state->m_dvbc_bitrate = ul_dvbc_bitrate; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 727 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 728 | state->m_ts_data_strength = (ul_ts_data_strength & 0x07); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 729 | |
| 730 | /* Maximum bitrate in b/s in case static clockrate is selected */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 731 | state->m_mpeg_ts_static_bitrate = 19392658; |
| 732 | state->m_disable_te_ihandling = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 733 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 734 | if (ul_insert_rs_byte) |
| 735 | state->m_insert_rs_byte = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 736 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 737 | state->m_mpeg_lock_time_out = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; |
| 738 | if (ul_mpeg_lock_time_out < 10000) |
| 739 | state->m_mpeg_lock_time_out = ul_mpeg_lock_time_out; |
| 740 | state->m_demod_lock_time_out = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; |
| 741 | if (ul_demod_lock_time_out < 10000) |
| 742 | state->m_demod_lock_time_out = ul_demod_lock_time_out; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 743 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 744 | /* QAM defaults */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 745 | state->m_constellation = DRX_CONSTELLATION_AUTO; |
| 746 | state->m_qam_interleave_mode = DRXK_QAM_I12_J17; |
| 747 | state->m_fec_rs_plen = 204 * 8; /* fecRsPlen annex A */ |
| 748 | state->m_fec_rs_prescale = 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 749 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 750 | state->m_sqi_speed = DRXK_DVBT_SQI_SPEED_MEDIUM; |
| 751 | state->m_agcfast_clip_ctrl_delay = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 752 | |
Mauro Carvalho Chehab | 949dd08 | 2013-04-28 11:47:50 -0300 | [diff] [blame] | 753 | state->m_gpio_cfg = ul_gpio_cfg; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 754 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 755 | state->m_b_power_down = false; |
| 756 | state->m_current_power_mode = DRX_POWER_DOWN; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 757 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 758 | state->m_rfmirror = (ul_rf_mirror == 0); |
| 759 | state->m_if_agc_pol = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 763 | static int drxx_open(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 764 | { |
| 765 | int status = 0; |
| 766 | u32 jtag = 0; |
| 767 | u16 bid = 0; |
| 768 | u16 key = 0; |
| 769 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 770 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 771 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 772 | status = write16(state, SCU_RAM_GPIO__A, |
| 773 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 774 | if (status < 0) |
| 775 | goto error; |
| 776 | /* Check device id */ |
| 777 | status = read16(state, SIO_TOP_COMM_KEY__A, &key); |
| 778 | if (status < 0) |
| 779 | goto error; |
| 780 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
| 781 | if (status < 0) |
| 782 | goto error; |
| 783 | status = read32(state, SIO_TOP_JTAGID_LO__A, &jtag); |
| 784 | if (status < 0) |
| 785 | goto error; |
| 786 | status = read16(state, SIO_PDR_UIO_IN_HI__A, &bid); |
| 787 | if (status < 0) |
| 788 | goto error; |
| 789 | status = write16(state, SIO_TOP_COMM_KEY__A, key); |
| 790 | error: |
| 791 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 792 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 793 | return status; |
| 794 | } |
| 795 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 796 | static int get_device_capabilities(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 797 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 798 | u16 sio_pdr_ohw_cfg = 0; |
| 799 | u32 sio_top_jtagid_lo = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 800 | int status; |
Mauro Carvalho Chehab | 9c6e182 | 2011-07-10 08:38:18 -0300 | [diff] [blame] | 801 | const char *spin = ""; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 802 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 803 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 804 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 805 | /* driver 0.9.0 */ |
| 806 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 807 | status = write16(state, SCU_RAM_GPIO__A, |
| 808 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 809 | if (status < 0) |
| 810 | goto error; |
Martin Blumenstingl | 8418366 | 2012-10-04 14:22:55 -0300 | [diff] [blame] | 811 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 812 | if (status < 0) |
| 813 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 814 | status = read16(state, SIO_PDR_OHW_CFG__A, &sio_pdr_ohw_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 815 | if (status < 0) |
| 816 | goto error; |
| 817 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
| 818 | if (status < 0) |
| 819 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 820 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 821 | switch ((sio_pdr_ohw_cfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 822 | case 0: |
| 823 | /* ignore (bypass ?) */ |
| 824 | break; |
| 825 | case 1: |
| 826 | /* 27 MHz */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 827 | state->m_osc_clock_freq = 27000; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 828 | break; |
| 829 | case 2: |
| 830 | /* 20.25 MHz */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 831 | state->m_osc_clock_freq = 20250; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 832 | break; |
| 833 | case 3: |
| 834 | /* 4 MHz */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 835 | state->m_osc_clock_freq = 20250; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 836 | break; |
| 837 | default: |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 838 | pr_err("Clock Frequency is unknown\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 839 | return -EINVAL; |
| 840 | } |
| 841 | /* |
| 842 | Determine device capabilities |
| 843 | Based on pinning v14 |
| 844 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 845 | status = read32(state, SIO_TOP_JTAGID_LO__A, &sio_top_jtagid_lo); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 846 | if (status < 0) |
| 847 | goto error; |
Mauro Carvalho Chehab | 0d3e6fe | 2011-07-22 12:34:41 -0300 | [diff] [blame] | 848 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 849 | pr_info("status = 0x%08x\n", sio_top_jtagid_lo); |
Mauro Carvalho Chehab | 0d3e6fe | 2011-07-22 12:34:41 -0300 | [diff] [blame] | 850 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 851 | /* driver 0.9.0 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 852 | switch ((sio_top_jtagid_lo >> 29) & 0xF) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 853 | case 0: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 854 | state->m_device_spin = DRXK_SPIN_A1; |
Mauro Carvalho Chehab | 9c6e182 | 2011-07-10 08:38:18 -0300 | [diff] [blame] | 855 | spin = "A1"; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 856 | break; |
| 857 | case 2: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 858 | state->m_device_spin = DRXK_SPIN_A2; |
Mauro Carvalho Chehab | 9c6e182 | 2011-07-10 08:38:18 -0300 | [diff] [blame] | 859 | spin = "A2"; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 860 | break; |
| 861 | case 3: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 862 | state->m_device_spin = DRXK_SPIN_A3; |
Mauro Carvalho Chehab | 9c6e182 | 2011-07-10 08:38:18 -0300 | [diff] [blame] | 863 | spin = "A3"; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 864 | break; |
| 865 | default: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 866 | state->m_device_spin = DRXK_SPIN_UNKNOWN; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 867 | status = -EINVAL; |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 868 | pr_err("Spin %d unknown\n", (sio_top_jtagid_lo >> 29) & 0xF); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 869 | goto error2; |
| 870 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 871 | switch ((sio_top_jtagid_lo >> 12) & 0xFF) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 872 | case 0x13: |
| 873 | /* typeId = DRX3913K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 874 | state->m_has_lna = false; |
| 875 | state->m_has_oob = false; |
| 876 | state->m_has_atv = false; |
| 877 | state->m_has_audio = false; |
| 878 | state->m_has_dvbt = true; |
| 879 | state->m_has_dvbc = true; |
| 880 | state->m_has_sawsw = true; |
| 881 | state->m_has_gpio2 = false; |
| 882 | state->m_has_gpio1 = false; |
| 883 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 884 | break; |
| 885 | case 0x15: |
| 886 | /* typeId = DRX3915K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 887 | state->m_has_lna = false; |
| 888 | state->m_has_oob = false; |
| 889 | state->m_has_atv = true; |
| 890 | state->m_has_audio = false; |
| 891 | state->m_has_dvbt = true; |
| 892 | state->m_has_dvbc = false; |
| 893 | state->m_has_sawsw = true; |
| 894 | state->m_has_gpio2 = true; |
| 895 | state->m_has_gpio1 = true; |
| 896 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 897 | break; |
| 898 | case 0x16: |
| 899 | /* typeId = DRX3916K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 900 | state->m_has_lna = false; |
| 901 | state->m_has_oob = false; |
| 902 | state->m_has_atv = true; |
| 903 | state->m_has_audio = false; |
| 904 | state->m_has_dvbt = true; |
| 905 | state->m_has_dvbc = false; |
| 906 | state->m_has_sawsw = true; |
| 907 | state->m_has_gpio2 = true; |
| 908 | state->m_has_gpio1 = true; |
| 909 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 910 | break; |
| 911 | case 0x18: |
| 912 | /* typeId = DRX3918K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 913 | state->m_has_lna = false; |
| 914 | state->m_has_oob = false; |
| 915 | state->m_has_atv = true; |
| 916 | state->m_has_audio = true; |
| 917 | state->m_has_dvbt = true; |
| 918 | state->m_has_dvbc = false; |
| 919 | state->m_has_sawsw = true; |
| 920 | state->m_has_gpio2 = true; |
| 921 | state->m_has_gpio1 = true; |
| 922 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 923 | break; |
| 924 | case 0x21: |
| 925 | /* typeId = DRX3921K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 926 | state->m_has_lna = false; |
| 927 | state->m_has_oob = false; |
| 928 | state->m_has_atv = true; |
| 929 | state->m_has_audio = true; |
| 930 | state->m_has_dvbt = true; |
| 931 | state->m_has_dvbc = true; |
| 932 | state->m_has_sawsw = true; |
| 933 | state->m_has_gpio2 = true; |
| 934 | state->m_has_gpio1 = true; |
| 935 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 936 | break; |
| 937 | case 0x23: |
| 938 | /* typeId = DRX3923K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 939 | state->m_has_lna = false; |
| 940 | state->m_has_oob = false; |
| 941 | state->m_has_atv = true; |
| 942 | state->m_has_audio = true; |
| 943 | state->m_has_dvbt = true; |
| 944 | state->m_has_dvbc = true; |
| 945 | state->m_has_sawsw = true; |
| 946 | state->m_has_gpio2 = true; |
| 947 | state->m_has_gpio1 = true; |
| 948 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 949 | break; |
| 950 | case 0x25: |
| 951 | /* typeId = DRX3925K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 952 | state->m_has_lna = false; |
| 953 | state->m_has_oob = false; |
| 954 | state->m_has_atv = true; |
| 955 | state->m_has_audio = true; |
| 956 | state->m_has_dvbt = true; |
| 957 | state->m_has_dvbc = true; |
| 958 | state->m_has_sawsw = true; |
| 959 | state->m_has_gpio2 = true; |
| 960 | state->m_has_gpio1 = true; |
| 961 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 962 | break; |
| 963 | case 0x26: |
| 964 | /* typeId = DRX3926K_TYPE_ID */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 965 | state->m_has_lna = false; |
| 966 | state->m_has_oob = false; |
| 967 | state->m_has_atv = true; |
| 968 | state->m_has_audio = false; |
| 969 | state->m_has_dvbt = true; |
| 970 | state->m_has_dvbc = true; |
| 971 | state->m_has_sawsw = true; |
| 972 | state->m_has_gpio2 = true; |
| 973 | state->m_has_gpio1 = true; |
| 974 | state->m_has_irqn = false; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 975 | break; |
| 976 | default: |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 977 | pr_err("DeviceID 0x%02x not supported\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 978 | ((sio_top_jtagid_lo >> 12) & 0xFF)); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 979 | status = -EINVAL; |
| 980 | goto error2; |
| 981 | } |
| 982 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 983 | pr_info("detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 984 | ((sio_top_jtagid_lo >> 12) & 0xFF), spin, |
| 985 | state->m_osc_clock_freq / 1000, |
| 986 | state->m_osc_clock_freq % 1000); |
Mauro Carvalho Chehab | 9c6e182 | 2011-07-10 08:38:18 -0300 | [diff] [blame] | 987 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 988 | error: |
| 989 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 990 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 991 | |
| 992 | error2: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 993 | return status; |
| 994 | } |
| 995 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 996 | static int hi_command(struct drxk_state *state, u16 cmd, u16 *p_result) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 997 | { |
| 998 | int status; |
| 999 | bool powerdown_cmd; |
| 1000 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1001 | dprintk(1, "\n"); |
| 1002 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1003 | /* Write command */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1004 | status = write16(state, SIO_HI_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1005 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1006 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1007 | if (cmd == SIO_HI_RA_RAM_CMD_RESET) |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 1008 | usleep_range(1000, 2000); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1009 | |
| 1010 | powerdown_cmd = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1011 | (bool) ((cmd == SIO_HI_RA_RAM_CMD_CONFIG) && |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1012 | ((state->m_hi_cfg_ctrl) & |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1013 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) == |
| 1014 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 1015 | if (!powerdown_cmd) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1016 | /* Wait until command rdy */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1017 | u32 retry_count = 0; |
| 1018 | u16 wait_cmd; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1019 | |
| 1020 | do { |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 1021 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1022 | retry_count += 1; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1023 | status = read16(state, SIO_HI_RA_RAM_CMD__A, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1024 | &wait_cmd); |
| 1025 | } while ((status < 0) && (retry_count < DRXK_MAX_RETRIES) |
| 1026 | && (wait_cmd != 0)); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1027 | if (status < 0) |
| 1028 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1029 | status = read16(state, SIO_HI_RA_RAM_RES__A, p_result); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1030 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1031 | error: |
| 1032 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1033 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1034 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1035 | return status; |
| 1036 | } |
| 1037 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1038 | static int hi_cfg_command(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1039 | { |
| 1040 | int status; |
| 1041 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1042 | dprintk(1, "\n"); |
| 1043 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1044 | mutex_lock(&state->mutex); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1045 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1046 | status = write16(state, SIO_HI_RA_RAM_PAR_6__A, |
| 1047 | state->m_hi_cfg_timeout); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1048 | if (status < 0) |
| 1049 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1050 | status = write16(state, SIO_HI_RA_RAM_PAR_5__A, |
| 1051 | state->m_hi_cfg_ctrl); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1052 | if (status < 0) |
| 1053 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1054 | status = write16(state, SIO_HI_RA_RAM_PAR_4__A, |
| 1055 | state->m_hi_cfg_wake_up_key); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1056 | if (status < 0) |
| 1057 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1058 | status = write16(state, SIO_HI_RA_RAM_PAR_3__A, |
| 1059 | state->m_hi_cfg_bridge_delay); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1060 | if (status < 0) |
| 1061 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1062 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, |
| 1063 | state->m_hi_cfg_timing_div); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1064 | if (status < 0) |
| 1065 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1066 | status = write16(state, SIO_HI_RA_RAM_PAR_1__A, |
| 1067 | SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1068 | if (status < 0) |
| 1069 | goto error; |
Hans Verkuil | b1cf201 | 2013-10-04 11:01:45 -0300 | [diff] [blame] | 1070 | status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, NULL); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1071 | if (status < 0) |
| 1072 | goto error; |
| 1073 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1074 | state->m_hi_cfg_ctrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1075 | error: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1076 | mutex_unlock(&state->mutex); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1077 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1078 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1079 | return status; |
| 1080 | } |
| 1081 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1082 | static int init_hi(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1083 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1084 | dprintk(1, "\n"); |
| 1085 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1086 | state->m_hi_cfg_wake_up_key = (state->demod_address << 1); |
| 1087 | state->m_hi_cfg_timeout = 0x96FF; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1088 | /* port/bridge/power down ctrl */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1089 | state->m_hi_cfg_ctrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1090 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1091 | return hi_cfg_command(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1092 | } |
| 1093 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1094 | static int mpegts_configure_pins(struct drxk_state *state, bool mpeg_enable) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1095 | { |
| 1096 | int status = -1; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1097 | u16 sio_pdr_mclk_cfg = 0; |
| 1098 | u16 sio_pdr_mdx_cfg = 0; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 1099 | u16 err_cfg = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1100 | |
Mauro Carvalho Chehab | 534e048 | 2011-07-24 14:59:20 -0300 | [diff] [blame] | 1101 | dprintk(1, ": mpeg %s, %s mode\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1102 | mpeg_enable ? "enable" : "disable", |
| 1103 | state->m_enable_parallel ? "parallel" : "serial"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1104 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1105 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1106 | status = write16(state, SCU_RAM_GPIO__A, |
| 1107 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1108 | if (status < 0) |
| 1109 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1110 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1111 | /* MPEG TS pad configuration */ |
Martin Blumenstingl | 8418366 | 2012-10-04 14:22:55 -0300 | [diff] [blame] | 1112 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1113 | if (status < 0) |
| 1114 | goto error; |
| 1115 | |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 1116 | if (!mpeg_enable) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1117 | /* Set MPEG TS pads to inputmode */ |
| 1118 | status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000); |
| 1119 | if (status < 0) |
| 1120 | goto error; |
| 1121 | status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); |
| 1122 | if (status < 0) |
| 1123 | goto error; |
| 1124 | status = write16(state, SIO_PDR_MCLK_CFG__A, 0x0000); |
| 1125 | if (status < 0) |
| 1126 | goto error; |
| 1127 | status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); |
| 1128 | if (status < 0) |
| 1129 | goto error; |
| 1130 | status = write16(state, SIO_PDR_MD0_CFG__A, 0x0000); |
| 1131 | if (status < 0) |
| 1132 | goto error; |
| 1133 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
| 1134 | if (status < 0) |
| 1135 | goto error; |
| 1136 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
| 1137 | if (status < 0) |
| 1138 | goto error; |
| 1139 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
| 1140 | if (status < 0) |
| 1141 | goto error; |
| 1142 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
| 1143 | if (status < 0) |
| 1144 | goto error; |
| 1145 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
| 1146 | if (status < 0) |
| 1147 | goto error; |
| 1148 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
| 1149 | if (status < 0) |
| 1150 | goto error; |
| 1151 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
| 1152 | if (status < 0) |
| 1153 | goto error; |
| 1154 | } else { |
| 1155 | /* Enable MPEG output */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1156 | sio_pdr_mdx_cfg = |
| 1157 | ((state->m_ts_data_strength << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1158 | SIO_PDR_MD0_CFG_DRIVE__B) | 0x0003); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1159 | sio_pdr_mclk_cfg = ((state->m_ts_clockk_strength << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1160 | SIO_PDR_MCLK_CFG_DRIVE__B) | |
| 1161 | 0x0003); |
| 1162 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1163 | status = write16(state, SIO_PDR_MSTRT_CFG__A, sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1164 | if (status < 0) |
| 1165 | goto error; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 1166 | |
| 1167 | if (state->enable_merr_cfg) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1168 | err_cfg = sio_pdr_mdx_cfg; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 1169 | |
| 1170 | status = write16(state, SIO_PDR_MERR_CFG__A, err_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1171 | if (status < 0) |
| 1172 | goto error; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 1173 | status = write16(state, SIO_PDR_MVAL_CFG__A, err_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1174 | if (status < 0) |
| 1175 | goto error; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 1176 | |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 1177 | if (state->m_enable_parallel) { |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 1178 | /* parallel -> enable MD1 to MD7 */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1179 | status = write16(state, SIO_PDR_MD1_CFG__A, |
| 1180 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1181 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1182 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1183 | status = write16(state, SIO_PDR_MD2_CFG__A, |
| 1184 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1185 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1186 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1187 | status = write16(state, SIO_PDR_MD3_CFG__A, |
| 1188 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1189 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1190 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1191 | status = write16(state, SIO_PDR_MD4_CFG__A, |
| 1192 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1193 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1194 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1195 | status = write16(state, SIO_PDR_MD5_CFG__A, |
| 1196 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1197 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1198 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1199 | status = write16(state, SIO_PDR_MD6_CFG__A, |
| 1200 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1201 | if (status < 0) |
| 1202 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1203 | status = write16(state, SIO_PDR_MD7_CFG__A, |
| 1204 | sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1205 | if (status < 0) |
| 1206 | goto error; |
| 1207 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1208 | sio_pdr_mdx_cfg = ((state->m_ts_data_strength << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1209 | SIO_PDR_MD0_CFG_DRIVE__B) |
| 1210 | | 0x0003); |
| 1211 | /* serial -> disable MD1 to MD7 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1212 | status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1213 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1214 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1215 | status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1216 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1217 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1218 | status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1219 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1220 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1221 | status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1222 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1223 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1224 | status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1225 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1226 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1227 | status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1228 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1229 | goto error; |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1230 | status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1231 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1232 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1233 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1234 | status = write16(state, SIO_PDR_MCLK_CFG__A, sio_pdr_mclk_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1235 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1236 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1237 | status = write16(state, SIO_PDR_MD0_CFG__A, sio_pdr_mdx_cfg); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1238 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1239 | goto error; |
| 1240 | } |
| 1241 | /* Enable MB output over MPEG pads and ctl input */ |
| 1242 | status = write16(state, SIO_PDR_MON_CFG__A, 0x0000); |
| 1243 | if (status < 0) |
| 1244 | goto error; |
| 1245 | /* Write nomagic word to enable pdr reg write */ |
| 1246 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
| 1247 | error: |
| 1248 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1249 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1250 | return status; |
| 1251 | } |
| 1252 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1253 | static int mpegts_disable(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1254 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1255 | dprintk(1, "\n"); |
| 1256 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1257 | return mpegts_configure_pins(state, false); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1258 | } |
| 1259 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1260 | static int bl_chain_cmd(struct drxk_state *state, |
| 1261 | u16 rom_offset, u16 nr_of_elements, u32 time_out) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1262 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1263 | u16 bl_status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1264 | int status; |
| 1265 | unsigned long end; |
| 1266 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1267 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1268 | mutex_lock(&state->mutex); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1269 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN); |
| 1270 | if (status < 0) |
| 1271 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1272 | status = write16(state, SIO_BL_CHAIN_ADDR__A, rom_offset); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1273 | if (status < 0) |
| 1274 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1275 | status = write16(state, SIO_BL_CHAIN_LEN__A, nr_of_elements); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1276 | if (status < 0) |
| 1277 | goto error; |
| 1278 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
| 1279 | if (status < 0) |
| 1280 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1281 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1282 | end = jiffies + msecs_to_jiffies(time_out); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1283 | do { |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 1284 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1285 | status = read16(state, SIO_BL_STATUS__A, &bl_status); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1286 | if (status < 0) |
| 1287 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1288 | } while ((bl_status == 0x1) && |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1289 | ((time_is_after_jiffies(end)))); |
| 1290 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1291 | if (bl_status == 0x1) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1292 | pr_err("SIO not ready\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1293 | status = -EINVAL; |
| 1294 | goto error2; |
| 1295 | } |
| 1296 | error: |
| 1297 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1298 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1299 | error2: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1300 | mutex_unlock(&state->mutex); |
| 1301 | return status; |
| 1302 | } |
| 1303 | |
| 1304 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1305 | static int download_microcode(struct drxk_state *state, |
| 1306 | const u8 p_mc_image[], u32 length) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1307 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1308 | const u8 *p_src = p_mc_image; |
| 1309 | u32 address; |
| 1310 | u16 n_blocks; |
| 1311 | u16 block_size; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1312 | u32 offset = 0; |
| 1313 | u32 i; |
Mauro Carvalho Chehab | 1bd09dd | 2011-07-03 18:21:59 -0300 | [diff] [blame] | 1314 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1315 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1316 | dprintk(1, "\n"); |
| 1317 | |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1318 | /* down the drain (we don't care about MAGIC_WORD) */ |
| 1319 | #if 0 |
| 1320 | /* For future reference */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1321 | drain = (p_src[0] << 8) | p_src[1]; |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1322 | #endif |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1323 | p_src += sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1324 | offset += sizeof(u16); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1325 | n_blocks = (p_src[0] << 8) | p_src[1]; |
| 1326 | p_src += sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1327 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1328 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1329 | for (i = 0; i < n_blocks; i += 1) { |
| 1330 | address = (p_src[0] << 24) | (p_src[1] << 16) | |
| 1331 | (p_src[2] << 8) | p_src[3]; |
| 1332 | p_src += sizeof(u32); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1333 | offset += sizeof(u32); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1334 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1335 | block_size = ((p_src[0] << 8) | p_src[1]) * sizeof(u16); |
| 1336 | p_src += sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1337 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1338 | |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1339 | #if 0 |
| 1340 | /* For future reference */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1341 | flags = (p_src[0] << 8) | p_src[1]; |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1342 | #endif |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1343 | p_src += sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1344 | offset += sizeof(u16); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1345 | |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1346 | #if 0 |
| 1347 | /* For future reference */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1348 | block_crc = (p_src[0] << 8) | p_src[1]; |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 1349 | #endif |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1350 | p_src += sizeof(u16); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1351 | offset += sizeof(u16); |
Mauro Carvalho Chehab | bcd2ebb | 2011-07-09 18:57:54 -0300 | [diff] [blame] | 1352 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1353 | if (offset + block_size > length) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1354 | pr_err("Firmware is corrupted.\n"); |
Mauro Carvalho Chehab | bcd2ebb | 2011-07-09 18:57:54 -0300 | [diff] [blame] | 1355 | return -EINVAL; |
| 1356 | } |
| 1357 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1358 | status = write_block(state, address, block_size, p_src); |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame] | 1359 | if (status < 0) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1360 | pr_err("Error %d while loading firmware\n", status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1361 | break; |
Mauro Carvalho Chehab | 39624f7 | 2011-07-09 19:23:44 -0300 | [diff] [blame] | 1362 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1363 | p_src += block_size; |
| 1364 | offset += block_size; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1365 | } |
| 1366 | return status; |
| 1367 | } |
| 1368 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1369 | static int dvbt_enable_ofdm_token_ring(struct drxk_state *state, bool enable) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1370 | { |
| 1371 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1372 | u16 data = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1373 | u16 desired_ctrl = SIO_OFDM_SH_OFDM_RING_ENABLE_ON; |
| 1374 | u16 desired_status = SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1375 | unsigned long end; |
| 1376 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1377 | dprintk(1, "\n"); |
| 1378 | |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 1379 | if (!enable) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1380 | desired_ctrl = SIO_OFDM_SH_OFDM_RING_ENABLE_OFF; |
| 1381 | desired_status = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1382 | } |
| 1383 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1384 | status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1385 | if (status >= 0 && data == desired_status) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1386 | /* tokenring already has correct status */ |
| 1387 | return status; |
| 1388 | } |
| 1389 | /* Disable/enable dvbt tokenring bridge */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1390 | status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desired_ctrl); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1391 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1392 | end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1393 | do { |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 1394 | status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1395 | if ((status >= 0 && data == desired_status) |
| 1396 | || time_is_after_jiffies(end)) |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1397 | break; |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 1398 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1399 | } while (1); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1400 | if (data != desired_status) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1401 | pr_err("SIO not ready\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1402 | return -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1403 | } |
| 1404 | return status; |
| 1405 | } |
| 1406 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1407 | static int mpegts_stop(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1408 | { |
| 1409 | int status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1410 | u16 fec_oc_snc_mode = 0; |
| 1411 | u16 fec_oc_ipr_mode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1412 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1413 | dprintk(1, "\n"); |
| 1414 | |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 1415 | /* Graceful shutdown (byte boundaries) */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1416 | status = read16(state, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1417 | if (status < 0) |
| 1418 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1419 | fec_oc_snc_mode |= FEC_OC_SNC_MODE_SHUTDOWN__M; |
| 1420 | status = write16(state, FEC_OC_SNC_MODE__A, fec_oc_snc_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1421 | if (status < 0) |
| 1422 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1423 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1424 | /* Suppress MCLK during absence of data */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1425 | status = read16(state, FEC_OC_IPR_MODE__A, &fec_oc_ipr_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1426 | if (status < 0) |
| 1427 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1428 | fec_oc_ipr_mode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M; |
| 1429 | status = write16(state, FEC_OC_IPR_MODE__A, fec_oc_ipr_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1430 | |
| 1431 | error: |
| 1432 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1433 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1434 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1435 | return status; |
| 1436 | } |
| 1437 | |
| 1438 | static int scu_command(struct drxk_state *state, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1439 | u16 cmd, u8 parameter_len, |
| 1440 | u16 *parameter, u8 result_len, u16 *result) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1441 | { |
| 1442 | #if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15 |
| 1443 | #error DRXK register mapping no longer compatible with this routine! |
| 1444 | #endif |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1445 | u16 cur_cmd = 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1446 | int status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1447 | unsigned long end; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1448 | u8 buffer[34]; |
| 1449 | int cnt = 0, ii; |
Mauro Carvalho Chehab | 7558977 | 2011-07-10 13:25:48 -0300 | [diff] [blame] | 1450 | const char *p; |
| 1451 | char errname[30]; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1452 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1453 | dprintk(1, "\n"); |
| 1454 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1455 | if ((cmd == 0) || ((parameter_len > 0) && (parameter == NULL)) || |
| 1456 | ((result_len > 0) && (result == NULL))) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1457 | pr_err("Error %d on %s\n", status, __func__); |
Alexey Khoroshilov | e4459e1 | 2012-04-05 18:53:20 -0300 | [diff] [blame] | 1458 | return status; |
| 1459 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1460 | |
| 1461 | mutex_lock(&state->mutex); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1462 | |
| 1463 | /* assume that the command register is ready |
| 1464 | since it is checked afterwards */ |
Mauro Carvalho Chehab | daad52c | 2018-12-07 08:07:55 -0500 | [diff] [blame] | 1465 | if (parameter) { |
| 1466 | for (ii = parameter_len - 1; ii >= 0; ii -= 1) { |
| 1467 | buffer[cnt++] = (parameter[ii] & 0xFF); |
| 1468 | buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF); |
| 1469 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1470 | } |
| 1471 | buffer[cnt++] = (cmd & 0xFF); |
| 1472 | buffer[cnt++] = ((cmd >> 8) & 0xFF); |
| 1473 | |
| 1474 | write_block(state, SCU_RAM_PARAM_0__A - |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1475 | (parameter_len - 1), cnt, buffer); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1476 | /* Wait until SCU has processed command */ |
| 1477 | end = jiffies + msecs_to_jiffies(DRXK_MAX_WAITTIME); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1478 | do { |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 1479 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1480 | status = read16(state, SCU_RAM_COMMAND__A, &cur_cmd); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1481 | if (status < 0) |
| 1482 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1483 | } while (!(cur_cmd == DRX_SCU_READY) && (time_is_after_jiffies(end))); |
| 1484 | if (cur_cmd != DRX_SCU_READY) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1485 | pr_err("SCU not ready\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1486 | status = -EIO; |
| 1487 | goto error2; |
| 1488 | } |
| 1489 | /* read results */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1490 | if ((result_len > 0) && (result != NULL)) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1491 | s16 err; |
| 1492 | int ii; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1493 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1494 | for (ii = result_len - 1; ii >= 0; ii -= 1) { |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1495 | status = read16(state, SCU_RAM_PARAM_0__A - ii, |
| 1496 | &result[ii]); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1497 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1498 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1499 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1500 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1501 | /* Check if an error was reported by SCU */ |
| 1502 | err = (s16)result[0]; |
Mauro Carvalho Chehab | 7558977 | 2011-07-10 13:25:48 -0300 | [diff] [blame] | 1503 | if (err >= 0) |
| 1504 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1505 | |
Mauro Carvalho Chehab | 7558977 | 2011-07-10 13:25:48 -0300 | [diff] [blame] | 1506 | /* check for the known error codes */ |
| 1507 | switch (err) { |
| 1508 | case SCU_RESULT_UNKCMD: |
| 1509 | p = "SCU_RESULT_UNKCMD"; |
| 1510 | break; |
| 1511 | case SCU_RESULT_UNKSTD: |
| 1512 | p = "SCU_RESULT_UNKSTD"; |
| 1513 | break; |
| 1514 | case SCU_RESULT_SIZE: |
| 1515 | p = "SCU_RESULT_SIZE"; |
| 1516 | break; |
| 1517 | case SCU_RESULT_INVPAR: |
| 1518 | p = "SCU_RESULT_INVPAR"; |
| 1519 | break; |
| 1520 | default: /* Other negative values are errors */ |
| 1521 | sprintf(errname, "ERROR: %d\n", err); |
| 1522 | p = errname; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1523 | } |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1524 | pr_err("%s while sending cmd 0x%04x with params:", p, cmd); |
Mauro Carvalho Chehab | 7558977 | 2011-07-10 13:25:48 -0300 | [diff] [blame] | 1525 | print_hex_dump_bytes("drxk: ", DUMP_PREFIX_NONE, buffer, cnt); |
| 1526 | status = -EINVAL; |
| 1527 | goto error2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | error: |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1531 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1532 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1533 | error2: |
| 1534 | mutex_unlock(&state->mutex); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1535 | return status; |
| 1536 | } |
| 1537 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1538 | static int set_iqm_af(struct drxk_state *state, bool active) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1539 | { |
| 1540 | u16 data = 0; |
| 1541 | int status; |
| 1542 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1543 | dprintk(1, "\n"); |
| 1544 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1545 | /* Configure IQM */ |
| 1546 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 1547 | if (status < 0) |
| 1548 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1549 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1550 | if (!active) { |
| 1551 | data |= (IQM_AF_STDBY_STDBY_ADC_STANDBY |
| 1552 | | IQM_AF_STDBY_STDBY_AMP_STANDBY |
| 1553 | | IQM_AF_STDBY_STDBY_PD_STANDBY |
| 1554 | | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY |
| 1555 | | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY); |
| 1556 | } else { |
| 1557 | data &= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY) |
| 1558 | & (~IQM_AF_STDBY_STDBY_AMP_STANDBY) |
| 1559 | & (~IQM_AF_STDBY_STDBY_PD_STANDBY) |
| 1560 | & (~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY) |
| 1561 | & (~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY) |
| 1562 | ); |
| 1563 | } |
| 1564 | status = write16(state, IQM_AF_STDBY__A, data); |
| 1565 | |
| 1566 | error: |
| 1567 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1568 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1569 | return status; |
| 1570 | } |
| 1571 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1572 | static int ctrl_power_mode(struct drxk_state *state, enum drx_power_mode *mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1573 | { |
| 1574 | int status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1575 | u16 sio_cc_pwd_mode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1576 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1577 | dprintk(1, "\n"); |
| 1578 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1579 | /* Check arguments */ |
| 1580 | if (mode == NULL) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1581 | return -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1582 | |
| 1583 | switch (*mode) { |
| 1584 | case DRX_POWER_UP: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1585 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_NONE; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1586 | break; |
| 1587 | case DRXK_POWER_DOWN_OFDM: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1588 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OFDM; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1589 | break; |
| 1590 | case DRXK_POWER_DOWN_CORE: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1591 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_CLOCK; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1592 | break; |
| 1593 | case DRXK_POWER_DOWN_PLL: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1594 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_PLL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1595 | break; |
| 1596 | case DRX_POWER_DOWN: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1597 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OSC; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1598 | break; |
| 1599 | default: |
| 1600 | /* Unknow sleep mode */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1601 | return -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | /* If already in requested power mode, do nothing */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1605 | if (state->m_current_power_mode == *mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1606 | return 0; |
| 1607 | |
| 1608 | /* For next steps make sure to start from DRX_POWER_UP mode */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1609 | if (state->m_current_power_mode != DRX_POWER_UP) { |
| 1610 | status = power_up_device(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1611 | if (status < 0) |
| 1612 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1613 | status = dvbt_enable_ofdm_token_ring(state, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1614 | if (status < 0) |
| 1615 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | if (*mode == DRX_POWER_UP) { |
Masahiro Yamada | 2c14960 | 2017-02-27 14:29:31 -0800 | [diff] [blame] | 1619 | /* Restore analog & pin configuration */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1620 | } else { |
| 1621 | /* Power down to requested mode */ |
| 1622 | /* Backup some register settings */ |
| 1623 | /* Set pins with possible pull-ups connected |
| 1624 | to them in input mode */ |
| 1625 | /* Analog power down */ |
| 1626 | /* ADC power down */ |
| 1627 | /* Power down device */ |
| 1628 | /* stop all comm_exec */ |
| 1629 | /* Stop and power down previous standard */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1630 | switch (state->m_operation_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1631 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1632 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1633 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1634 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1635 | status = power_down_dvbt(state, false); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1636 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1637 | goto error; |
| 1638 | break; |
| 1639 | case OM_QAM_ITU_A: |
| 1640 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1641 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1642 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1643 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1644 | status = power_down_qam(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1645 | if (status < 0) |
| 1646 | goto error; |
| 1647 | break; |
| 1648 | default: |
| 1649 | break; |
| 1650 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1651 | status = dvbt_enable_ofdm_token_ring(state, false); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1652 | if (status < 0) |
| 1653 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1654 | status = write16(state, SIO_CC_PWD_MODE__A, sio_cc_pwd_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1655 | if (status < 0) |
| 1656 | goto error; |
| 1657 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
| 1658 | if (status < 0) |
| 1659 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1660 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1661 | if (*mode != DRXK_POWER_DOWN_OFDM) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1662 | state->m_hi_cfg_ctrl |= |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1663 | SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1664 | status = hi_cfg_command(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1665 | if (status < 0) |
| 1666 | goto error; |
| 1667 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1668 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1669 | state->m_current_power_mode = *mode; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1670 | |
| 1671 | error: |
| 1672 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1673 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1674 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1675 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1676 | } |
| 1677 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1678 | static int power_down_dvbt(struct drxk_state *state, bool set_power_mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1679 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1680 | enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM; |
| 1681 | u16 cmd_result = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1682 | u16 data = 0; |
| 1683 | int status; |
| 1684 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1685 | dprintk(1, "\n"); |
| 1686 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1687 | status = read16(state, SCU_COMM_EXEC__A, &data); |
| 1688 | if (status < 0) |
| 1689 | goto error; |
| 1690 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 1691 | /* Send OFDM stop command */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1692 | status = scu_command(state, |
| 1693 | SCU_RAM_COMMAND_STANDARD_OFDM |
| 1694 | | SCU_RAM_COMMAND_CMD_DEMOD_STOP, |
| 1695 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 1696 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1697 | goto error; |
| 1698 | /* Send OFDM reset command */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1699 | status = scu_command(state, |
| 1700 | SCU_RAM_COMMAND_STANDARD_OFDM |
| 1701 | | SCU_RAM_COMMAND_CMD_DEMOD_RESET, |
| 1702 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1703 | if (status < 0) |
| 1704 | goto error; |
| 1705 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1706 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1707 | /* Reset datapath for OFDM, processors first */ |
| 1708 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
| 1709 | if (status < 0) |
| 1710 | goto error; |
| 1711 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
| 1712 | if (status < 0) |
| 1713 | goto error; |
| 1714 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
| 1715 | if (status < 0) |
| 1716 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1717 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1718 | /* powerdown AFE */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1719 | status = set_iqm_af(state, false); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1720 | if (status < 0) |
| 1721 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1722 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1723 | /* powerdown to OFDM mode */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1724 | if (set_power_mode) { |
| 1725 | status = ctrl_power_mode(state, &power_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1726 | if (status < 0) |
| 1727 | goto error; |
| 1728 | } |
| 1729 | error: |
| 1730 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1731 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1732 | return status; |
| 1733 | } |
| 1734 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1735 | static int setoperation_mode(struct drxk_state *state, |
| 1736 | enum operation_mode o_mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1737 | { |
| 1738 | int status = 0; |
| 1739 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1740 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1741 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 1742 | Stop and power down previous standard |
| 1743 | TODO investigate total power down instead of partial |
| 1744 | power down depending on "previous" standard. |
| 1745 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1746 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1747 | /* disable HW lock indicator */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 1748 | status = write16(state, SCU_RAM_GPIO__A, |
| 1749 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1750 | if (status < 0) |
| 1751 | goto error; |
| 1752 | |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1753 | /* Device is already at the required mode */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1754 | if (state->m_operation_mode == o_mode) |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1755 | return 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1756 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1757 | switch (state->m_operation_mode) { |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1758 | /* OM_NONE was added for start up */ |
| 1759 | case OM_NONE: |
| 1760 | break; |
| 1761 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1762 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1763 | if (status < 0) |
| 1764 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1765 | status = power_down_dvbt(state, true); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1766 | if (status < 0) |
| 1767 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1768 | state->m_operation_mode = OM_NONE; |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1769 | break; |
| 1770 | case OM_QAM_ITU_A: /* fallthrough */ |
| 1771 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1772 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1773 | if (status < 0) |
| 1774 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1775 | status = power_down_qam(state); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1776 | if (status < 0) |
| 1777 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1778 | state->m_operation_mode = OM_NONE; |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1779 | break; |
| 1780 | case OM_QAM_ITU_B: |
| 1781 | default: |
| 1782 | status = -EINVAL; |
| 1783 | goto error; |
| 1784 | } |
| 1785 | |
| 1786 | /* |
| 1787 | Power up new standard |
| 1788 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1789 | switch (o_mode) { |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1790 | case OM_DVBT: |
Mauro Carvalho Chehab | 48763e2 | 2011-12-09 08:53:36 -0200 | [diff] [blame] | 1791 | dprintk(1, ": DVB-T\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1792 | state->m_operation_mode = o_mode; |
| 1793 | status = set_dvbt_standard(state, o_mode); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1794 | if (status < 0) |
| 1795 | goto error; |
| 1796 | break; |
| 1797 | case OM_QAM_ITU_A: /* fallthrough */ |
| 1798 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | 48763e2 | 2011-12-09 08:53:36 -0200 | [diff] [blame] | 1799 | dprintk(1, ": DVB-C Annex %c\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1800 | (state->m_operation_mode == OM_QAM_ITU_A) ? 'A' : 'C'); |
| 1801 | state->m_operation_mode = o_mode; |
| 1802 | status = set_qam_standard(state, o_mode); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 1803 | if (status < 0) |
| 1804 | goto error; |
| 1805 | break; |
| 1806 | case OM_QAM_ITU_B: |
| 1807 | default: |
| 1808 | status = -EINVAL; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1809 | } |
| 1810 | error: |
| 1811 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1812 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1813 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1814 | } |
| 1815 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1816 | static int start(struct drxk_state *state, s32 offset_freq, |
| 1817 | s32 intermediate_frequency) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1818 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1819 | int status = -EINVAL; |
| 1820 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1821 | u16 i_freqk_hz; |
| 1822 | s32 offsetk_hz = offset_freq / 1000; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1823 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1824 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1825 | if (state->m_drxk_state != DRXK_STOPPED && |
| 1826 | state->m_drxk_state != DRXK_DTV_STARTED) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1827 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1828 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1829 | state->m_b_mirror_freq_spect = (state->props.inversion == INVERSION_ON); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1830 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1831 | if (intermediate_frequency < 0) { |
| 1832 | state->m_b_mirror_freq_spect = !state->m_b_mirror_freq_spect; |
| 1833 | intermediate_frequency = -intermediate_frequency; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1834 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1835 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1836 | switch (state->m_operation_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1837 | case OM_QAM_ITU_A: |
| 1838 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1839 | i_freqk_hz = (intermediate_frequency / 1000); |
| 1840 | status = set_qam(state, i_freqk_hz, offsetk_hz); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1841 | if (status < 0) |
| 1842 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1843 | state->m_drxk_state = DRXK_DTV_STARTED; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1844 | break; |
| 1845 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1846 | i_freqk_hz = (intermediate_frequency / 1000); |
| 1847 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1848 | if (status < 0) |
| 1849 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1850 | status = set_dvbt(state, i_freqk_hz, offsetk_hz); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1851 | if (status < 0) |
| 1852 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1853 | status = dvbt_start(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1854 | if (status < 0) |
| 1855 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1856 | state->m_drxk_state = DRXK_DTV_STARTED; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1857 | break; |
| 1858 | default: |
| 1859 | break; |
| 1860 | } |
| 1861 | error: |
| 1862 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1863 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1864 | return status; |
| 1865 | } |
| 1866 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1867 | static int shut_down(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1868 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1869 | dprintk(1, "\n"); |
| 1870 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1871 | mpegts_stop(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1872 | return 0; |
| 1873 | } |
| 1874 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1875 | static int get_lock_status(struct drxk_state *state, u32 *p_lock_status) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1876 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1877 | int status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1878 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1879 | dprintk(1, "\n"); |
| 1880 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1881 | if (p_lock_status == NULL) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1882 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1883 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1884 | *p_lock_status = NOT_LOCKED; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1885 | |
| 1886 | /* define the SCU command code */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1887 | switch (state->m_operation_mode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1888 | case OM_QAM_ITU_A: |
| 1889 | case OM_QAM_ITU_B: |
| 1890 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1891 | status = get_qam_lock_status(state, p_lock_status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1892 | break; |
| 1893 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1894 | status = get_dvbt_lock_status(state, p_lock_status); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1895 | break; |
| 1896 | default: |
Daniel Scheller | b73bb2a | 2017-03-14 19:22:37 -0300 | [diff] [blame] | 1897 | pr_debug("Unsupported operation mode %d in %s\n", |
| 1898 | state->m_operation_mode, __func__); |
| 1899 | return 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1900 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1901 | error: |
| 1902 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1903 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1904 | return status; |
| 1905 | } |
| 1906 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1907 | static int mpegts_start(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1908 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1909 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1910 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1911 | u16 fec_oc_snc_mode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1912 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1913 | /* Allow OC to sync again */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1914 | status = read16(state, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1915 | if (status < 0) |
| 1916 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1917 | fec_oc_snc_mode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M; |
| 1918 | status = write16(state, FEC_OC_SNC_MODE__A, fec_oc_snc_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1919 | if (status < 0) |
| 1920 | goto error; |
| 1921 | status = write16(state, FEC_OC_SNC_UNLOCK__A, 1); |
| 1922 | error: |
| 1923 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1924 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1925 | return status; |
| 1926 | } |
| 1927 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1928 | static int mpegts_dto_init(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1929 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1930 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1931 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1932 | dprintk(1, "\n"); |
| 1933 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1934 | /* Rate integration settings */ |
| 1935 | status = write16(state, FEC_OC_RCN_CTL_STEP_LO__A, 0x0000); |
| 1936 | if (status < 0) |
| 1937 | goto error; |
| 1938 | status = write16(state, FEC_OC_RCN_CTL_STEP_HI__A, 0x000C); |
| 1939 | if (status < 0) |
| 1940 | goto error; |
| 1941 | status = write16(state, FEC_OC_RCN_GAIN__A, 0x000A); |
| 1942 | if (status < 0) |
| 1943 | goto error; |
| 1944 | status = write16(state, FEC_OC_AVR_PARM_A__A, 0x0008); |
| 1945 | if (status < 0) |
| 1946 | goto error; |
| 1947 | status = write16(state, FEC_OC_AVR_PARM_B__A, 0x0006); |
| 1948 | if (status < 0) |
| 1949 | goto error; |
| 1950 | status = write16(state, FEC_OC_TMD_HI_MARGIN__A, 0x0680); |
| 1951 | if (status < 0) |
| 1952 | goto error; |
| 1953 | status = write16(state, FEC_OC_TMD_LO_MARGIN__A, 0x0080); |
| 1954 | if (status < 0) |
| 1955 | goto error; |
| 1956 | status = write16(state, FEC_OC_TMD_COUNT__A, 0x03F4); |
| 1957 | if (status < 0) |
| 1958 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1959 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1960 | /* Additional configuration */ |
| 1961 | status = write16(state, FEC_OC_OCR_INVERT__A, 0); |
| 1962 | if (status < 0) |
| 1963 | goto error; |
| 1964 | status = write16(state, FEC_OC_SNC_LWM__A, 2); |
| 1965 | if (status < 0) |
| 1966 | goto error; |
| 1967 | status = write16(state, FEC_OC_SNC_HWM__A, 12); |
| 1968 | error: |
| 1969 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 1970 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1971 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1972 | return status; |
| 1973 | } |
| 1974 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1975 | static int mpegts_dto_setup(struct drxk_state *state, |
| 1976 | enum operation_mode o_mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1977 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1978 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1979 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1980 | u16 fec_oc_reg_mode = 0; /* FEC_OC_MODE register value */ |
| 1981 | u16 fec_oc_reg_ipr_mode = 0; /* FEC_OC_IPR_MODE register value */ |
| 1982 | u16 fec_oc_dto_mode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 1983 | u16 fec_oc_fct_mode = 0; /* FEC_OC_IPR_INVERT register value */ |
| 1984 | u16 fec_oc_dto_period = 2; /* FEC_OC_IPR_INVERT register value */ |
| 1985 | u16 fec_oc_dto_burst_len = 188; /* FEC_OC_IPR_INVERT register value */ |
| 1986 | u32 fec_oc_rcn_ctl_rate = 0; /* FEC_OC_IPR_INVERT register value */ |
| 1987 | u16 fec_oc_tmd_mode = 0; |
| 1988 | u16 fec_oc_tmd_int_upd_rate = 0; |
| 1989 | u32 max_bit_rate = 0; |
| 1990 | bool static_clk = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 1991 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 1992 | dprintk(1, "\n"); |
| 1993 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1994 | /* Check insertion of the Reed-Solomon parity bytes */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1995 | status = read16(state, FEC_OC_MODE__A, &fec_oc_reg_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1996 | if (status < 0) |
| 1997 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 1998 | status = read16(state, FEC_OC_IPR_MODE__A, &fec_oc_reg_ipr_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 1999 | if (status < 0) |
| 2000 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2001 | fec_oc_reg_mode &= (~FEC_OC_MODE_PARITY__M); |
| 2002 | fec_oc_reg_ipr_mode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2003 | if (state->m_insert_rs_byte) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2004 | /* enable parity symbol forward */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2005 | fec_oc_reg_mode |= FEC_OC_MODE_PARITY__M; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2006 | /* MVAL disable during parity bytes */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2007 | fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2008 | /* TS burst length to 204 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2009 | fec_oc_dto_burst_len = 204; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2010 | } |
| 2011 | |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 2012 | /* Check serial or parallel output */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2013 | fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2014 | if (!state->m_enable_parallel) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2015 | /* MPEG data output is serial -> set ipr_mode[0] */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2016 | fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2017 | } |
| 2018 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2019 | switch (o_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2020 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2021 | max_bit_rate = state->m_dvbt_bitrate; |
| 2022 | fec_oc_tmd_mode = 3; |
| 2023 | fec_oc_rcn_ctl_rate = 0xC00000; |
| 2024 | static_clk = state->m_dvbt_static_clk; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2025 | break; |
| 2026 | case OM_QAM_ITU_A: /* fallthrough */ |
| 2027 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2028 | fec_oc_tmd_mode = 0x0004; |
| 2029 | fec_oc_rcn_ctl_rate = 0xD2B4EE; /* good for >63 Mb/s */ |
| 2030 | max_bit_rate = state->m_dvbc_bitrate; |
| 2031 | static_clk = state->m_dvbc_static_clk; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2032 | break; |
| 2033 | default: |
| 2034 | status = -EINVAL; |
| 2035 | } /* switch (standard) */ |
| 2036 | if (status < 0) |
| 2037 | goto error; |
| 2038 | |
| 2039 | /* Configure DTO's */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2040 | if (static_clk) { |
| 2041 | u32 bit_rate = 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2042 | |
| 2043 | /* Rational DTO for MCLK source (static MCLK rate), |
| 2044 | Dynamic DTO for optimal grouping |
| 2045 | (avoid intra-packet gaps), |
| 2046 | DTO offset enable to sync TS burst with MSTRT */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2047 | fec_oc_dto_mode = (FEC_OC_DTO_MODE_DYNAMIC__M | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2048 | FEC_OC_DTO_MODE_OFFSET_ENABLE__M); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2049 | fec_oc_fct_mode = (FEC_OC_FCT_MODE_RAT_ENA__M | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2050 | FEC_OC_FCT_MODE_VIRT_ENA__M); |
| 2051 | |
| 2052 | /* Check user defined bitrate */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2053 | bit_rate = max_bit_rate; |
| 2054 | if (bit_rate > 75900000UL) { /* max is 75.9 Mb/s */ |
| 2055 | bit_rate = 75900000UL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2056 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2057 | /* Rational DTO period: |
| 2058 | dto_period = (Fsys / bitrate) - 2 |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2059 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2060 | result should be floored, |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2061 | to make sure >= requested bitrate |
| 2062 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2063 | fec_oc_dto_period = (u16) (((state->m_sys_clock_freq) |
| 2064 | * 1000) / bit_rate); |
| 2065 | if (fec_oc_dto_period <= 2) |
| 2066 | fec_oc_dto_period = 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2067 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2068 | fec_oc_dto_period -= 2; |
| 2069 | fec_oc_tmd_int_upd_rate = 8; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2070 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2071 | /* (commonAttr->static_clk == false) => dynamic mode */ |
| 2072 | fec_oc_dto_mode = FEC_OC_DTO_MODE_DYNAMIC__M; |
| 2073 | fec_oc_fct_mode = FEC_OC_FCT_MODE__PRE; |
| 2074 | fec_oc_tmd_int_upd_rate = 5; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2075 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2076 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2077 | /* Write appropriate registers with requested configuration */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2078 | status = write16(state, FEC_OC_DTO_BURST_LEN__A, fec_oc_dto_burst_len); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2079 | if (status < 0) |
| 2080 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2081 | status = write16(state, FEC_OC_DTO_PERIOD__A, fec_oc_dto_period); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2082 | if (status < 0) |
| 2083 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2084 | status = write16(state, FEC_OC_DTO_MODE__A, fec_oc_dto_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2085 | if (status < 0) |
| 2086 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2087 | status = write16(state, FEC_OC_FCT_MODE__A, fec_oc_fct_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2088 | if (status < 0) |
| 2089 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2090 | status = write16(state, FEC_OC_MODE__A, fec_oc_reg_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2091 | if (status < 0) |
| 2092 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2093 | status = write16(state, FEC_OC_IPR_MODE__A, fec_oc_reg_ipr_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2094 | if (status < 0) |
| 2095 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2096 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2097 | /* Rate integration settings */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2098 | status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fec_oc_rcn_ctl_rate); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2099 | if (status < 0) |
| 2100 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2101 | status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, |
| 2102 | fec_oc_tmd_int_upd_rate); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2103 | if (status < 0) |
| 2104 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2105 | status = write16(state, FEC_OC_TMD_MODE__A, fec_oc_tmd_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2106 | error: |
| 2107 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2108 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2109 | return status; |
| 2110 | } |
| 2111 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2112 | static int mpegts_configure_polarity(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2113 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2114 | u16 fec_oc_reg_ipr_invert = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2115 | |
| 2116 | /* Data mask for the output data byte */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2117 | u16 invert_data_mask = |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2118 | FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | |
| 2119 | FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M | |
| 2120 | FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | |
| 2121 | FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2122 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2123 | dprintk(1, "\n"); |
| 2124 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2125 | /* Control selective inversion of output bits */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2126 | fec_oc_reg_ipr_invert &= (~(invert_data_mask)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2127 | if (state->m_invert_data) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2128 | fec_oc_reg_ipr_invert |= invert_data_mask; |
| 2129 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MERR__M)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2130 | if (state->m_invert_err) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2131 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MERR__M; |
| 2132 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MSTRT__M)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2133 | if (state->m_invert_str) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2134 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MSTRT__M; |
| 2135 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MVAL__M)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2136 | if (state->m_invert_val) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2137 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MVAL__M; |
| 2138 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 2139 | if (state->m_invert_clk) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2140 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MCLK__M; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2141 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2142 | return write16(state, FEC_OC_IPR_INVERT__A, fec_oc_reg_ipr_invert); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000 |
| 2146 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2147 | static int set_agc_rf(struct drxk_state *state, |
| 2148 | struct s_cfg_agc *p_agc_cfg, bool is_dtv) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2149 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2150 | int status = -EINVAL; |
| 2151 | u16 data = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2152 | struct s_cfg_agc *p_if_agc_settings; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2153 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2154 | dprintk(1, "\n"); |
| 2155 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2156 | if (p_agc_cfg == NULL) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2157 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2158 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2159 | switch (p_agc_cfg->ctrl_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2160 | case DRXK_AGC_CTRL_AUTO: |
| 2161 | /* Enable RF AGC DAC */ |
| 2162 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 2163 | if (status < 0) |
| 2164 | goto error; |
| 2165 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
| 2166 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2167 | if (status < 0) |
| 2168 | goto error; |
| 2169 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2170 | if (status < 0) |
| 2171 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2172 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2173 | /* Enable SCU RF AGC loop */ |
| 2174 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2175 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2176 | /* Polarity */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2177 | if (state->m_rf_agc_pol) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2178 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2179 | else |
| 2180 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2181 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2182 | if (status < 0) |
| 2183 | goto error; |
| 2184 | |
| 2185 | /* Set speed (using complementary reduction value) */ |
| 2186 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
| 2187 | if (status < 0) |
| 2188 | goto error; |
| 2189 | |
| 2190 | data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2191 | data |= (~(p_agc_cfg->speed << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2192 | SCU_RAM_AGC_KI_RED_RAGC_RED__B) |
| 2193 | & SCU_RAM_AGC_KI_RED_RAGC_RED__M); |
| 2194 | |
| 2195 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
| 2196 | if (status < 0) |
| 2197 | goto error; |
| 2198 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2199 | if (is_dvbt(state)) |
| 2200 | p_if_agc_settings = &state->m_dvbt_if_agc_cfg; |
| 2201 | else if (is_qam(state)) |
| 2202 | p_if_agc_settings = &state->m_qam_if_agc_cfg; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2203 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2204 | p_if_agc_settings = &state->m_atv_if_agc_cfg; |
| 2205 | if (p_if_agc_settings == NULL) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2206 | status = -EINVAL; |
| 2207 | goto error; |
| 2208 | } |
| 2209 | |
| 2210 | /* Set TOP, only if IF-AGC is in AUTO mode */ |
Mauro Carvalho Chehab | 89fffac | 2014-09-03 19:11:45 -0300 | [diff] [blame] | 2211 | if (p_if_agc_settings->ctrl_mode == DRXK_AGC_CTRL_AUTO) { |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2212 | status = write16(state, |
| 2213 | SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, |
| 2214 | p_agc_cfg->top); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2215 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2216 | goto error; |
Mauro Carvalho Chehab | 89fffac | 2014-09-03 19:11:45 -0300 | [diff] [blame] | 2217 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2218 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2219 | /* Cut-Off current */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2220 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, |
| 2221 | p_agc_cfg->cut_off_current); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2222 | if (status < 0) |
| 2223 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2224 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2225 | /* Max. output level */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2226 | status = write16(state, SCU_RAM_AGC_RF_MAX__A, |
| 2227 | p_agc_cfg->max_output_level); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2228 | if (status < 0) |
| 2229 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2230 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2231 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2232 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2233 | case DRXK_AGC_CTRL_USER: |
| 2234 | /* Enable RF AGC DAC */ |
| 2235 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 2236 | if (status < 0) |
| 2237 | goto error; |
| 2238 | data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
| 2239 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2240 | if (status < 0) |
| 2241 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2242 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2243 | /* Disable SCU RF AGC loop */ |
| 2244 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2245 | if (status < 0) |
| 2246 | goto error; |
| 2247 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2248 | if (state->m_rf_agc_pol) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2249 | data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2250 | else |
| 2251 | data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; |
| 2252 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2253 | if (status < 0) |
| 2254 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2255 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2256 | /* SCU c.o.c. to 0, enabling full control range */ |
| 2257 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, 0); |
| 2258 | if (status < 0) |
| 2259 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2260 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2261 | /* Write value to output pin */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2262 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, |
| 2263 | p_agc_cfg->output_level); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2264 | if (status < 0) |
| 2265 | goto error; |
| 2266 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2267 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2268 | case DRXK_AGC_CTRL_OFF: |
| 2269 | /* Disable RF AGC DAC */ |
| 2270 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 2271 | if (status < 0) |
| 2272 | goto error; |
| 2273 | data |= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; |
| 2274 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2275 | if (status < 0) |
| 2276 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2277 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2278 | /* Disable SCU RF AGC loop */ |
| 2279 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2280 | if (status < 0) |
| 2281 | goto error; |
| 2282 | data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; |
| 2283 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2284 | if (status < 0) |
| 2285 | goto error; |
| 2286 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2287 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2288 | default: |
| 2289 | status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2290 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2291 | } |
| 2292 | error: |
| 2293 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2294 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2295 | return status; |
| 2296 | } |
| 2297 | |
| 2298 | #define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000 |
| 2299 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2300 | static int set_agc_if(struct drxk_state *state, |
| 2301 | struct s_cfg_agc *p_agc_cfg, bool is_dtv) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2302 | { |
| 2303 | u16 data = 0; |
| 2304 | int status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2305 | struct s_cfg_agc *p_rf_agc_settings; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2306 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2307 | dprintk(1, "\n"); |
| 2308 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2309 | switch (p_agc_cfg->ctrl_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2310 | case DRXK_AGC_CTRL_AUTO: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2311 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2312 | /* Enable IF AGC DAC */ |
| 2313 | status = read16(state, IQM_AF_STDBY__A, &data); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2314 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2315 | goto error; |
| 2316 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
| 2317 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2318 | if (status < 0) |
| 2319 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2320 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2321 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2322 | if (status < 0) |
| 2323 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2324 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2325 | /* Enable SCU IF AGC loop */ |
| 2326 | data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2327 | |
| 2328 | /* Polarity */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2329 | if (state->m_if_agc_pol) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2330 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2331 | else |
| 2332 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2333 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2334 | if (status < 0) |
| 2335 | goto error; |
| 2336 | |
| 2337 | /* Set speed (using complementary reduction value) */ |
| 2338 | status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); |
| 2339 | if (status < 0) |
| 2340 | goto error; |
| 2341 | data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2342 | data |= (~(p_agc_cfg->speed << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2343 | SCU_RAM_AGC_KI_RED_IAGC_RED__B) |
| 2344 | & SCU_RAM_AGC_KI_RED_IAGC_RED__M); |
| 2345 | |
| 2346 | status = write16(state, SCU_RAM_AGC_KI_RED__A, data); |
| 2347 | if (status < 0) |
| 2348 | goto error; |
| 2349 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2350 | if (is_qam(state)) |
| 2351 | p_rf_agc_settings = &state->m_qam_rf_agc_cfg; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2352 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2353 | p_rf_agc_settings = &state->m_atv_rf_agc_cfg; |
| 2354 | if (p_rf_agc_settings == NULL) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2355 | return -1; |
| 2356 | /* Restore TOP */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2357 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, |
| 2358 | p_rf_agc_settings->top); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2359 | if (status < 0) |
| 2360 | goto error; |
| 2361 | break; |
| 2362 | |
| 2363 | case DRXK_AGC_CTRL_USER: |
| 2364 | |
| 2365 | /* Enable IF AGC DAC */ |
| 2366 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 2367 | if (status < 0) |
| 2368 | goto error; |
| 2369 | data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
| 2370 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2371 | if (status < 0) |
| 2372 | goto error; |
| 2373 | |
| 2374 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2375 | if (status < 0) |
| 2376 | goto error; |
| 2377 | |
| 2378 | /* Disable SCU IF AGC loop */ |
| 2379 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2380 | |
| 2381 | /* Polarity */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2382 | if (state->m_if_agc_pol) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2383 | data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2384 | else |
| 2385 | data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; |
| 2386 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2387 | if (status < 0) |
| 2388 | goto error; |
| 2389 | |
| 2390 | /* Write value to output pin */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2391 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, |
| 2392 | p_agc_cfg->output_level); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2393 | if (status < 0) |
| 2394 | goto error; |
| 2395 | break; |
| 2396 | |
| 2397 | case DRXK_AGC_CTRL_OFF: |
| 2398 | |
| 2399 | /* Disable If AGC DAC */ |
| 2400 | status = read16(state, IQM_AF_STDBY__A, &data); |
| 2401 | if (status < 0) |
| 2402 | goto error; |
| 2403 | data |= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; |
| 2404 | status = write16(state, IQM_AF_STDBY__A, data); |
| 2405 | if (status < 0) |
| 2406 | goto error; |
| 2407 | |
| 2408 | /* Disable SCU IF AGC loop */ |
| 2409 | status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); |
| 2410 | if (status < 0) |
| 2411 | goto error; |
| 2412 | data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; |
| 2413 | status = write16(state, SCU_RAM_AGC_CONFIG__A, data); |
| 2414 | if (status < 0) |
| 2415 | goto error; |
| 2416 | break; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2417 | } /* switch (agcSettingsIf->ctrl_mode) */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2418 | |
| 2419 | /* always set the top to support |
| 2420 | configurations without if-loop */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2421 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, p_agc_cfg->top); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2422 | error: |
| 2423 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2424 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2425 | return status; |
| 2426 | } |
| 2427 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2428 | static int get_qam_signal_to_noise(struct drxk_state *state, |
| 2429 | s32 *p_signal_to_noise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2430 | { |
| 2431 | int status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2432 | u16 qam_sl_err_power = 0; /* accum. error between |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2433 | raw and sliced symbols */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2434 | u32 qam_sl_sig_power = 0; /* used for MER, depends of |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 2435 | QAM modulation */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2436 | u32 qam_sl_mer = 0; /* QAM MER */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2437 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2438 | dprintk(1, "\n"); |
| 2439 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2440 | /* MER calculation */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2441 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2442 | /* get the register value needed for MER */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2443 | status = read16(state, QAM_SL_ERR_POWER__A, &qam_sl_err_power); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2444 | if (status < 0) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2445 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2446 | return -EINVAL; |
| 2447 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2448 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 2449 | switch (state->props.modulation) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2450 | case QAM_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2451 | qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM16 << 2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2452 | break; |
| 2453 | case QAM_32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2454 | qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM32 << 2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2455 | break; |
| 2456 | case QAM_64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2457 | qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM64 << 2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2458 | break; |
| 2459 | case QAM_128: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2460 | qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM128 << 2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2461 | break; |
| 2462 | default: |
| 2463 | case QAM_256: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2464 | qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM256 << 2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2465 | break; |
| 2466 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2467 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2468 | if (qam_sl_err_power > 0) { |
| 2469 | qam_sl_mer = log10times100(qam_sl_sig_power) - |
| 2470 | log10times100((u32) qam_sl_err_power); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2471 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2472 | *p_signal_to_noise = qam_sl_mer; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2473 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2474 | return status; |
| 2475 | } |
| 2476 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2477 | static int get_dvbt_signal_to_noise(struct drxk_state *state, |
| 2478 | s32 *p_signal_to_noise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2479 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2480 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2481 | u16 reg_data = 0; |
| 2482 | u32 eq_reg_td_sqr_err_i = 0; |
| 2483 | u32 eq_reg_td_sqr_err_q = 0; |
| 2484 | u16 eq_reg_td_sqr_err_exp = 0; |
| 2485 | u16 eq_reg_td_tps_pwr_ofs = 0; |
| 2486 | u16 eq_reg_td_req_smb_cnt = 0; |
| 2487 | u32 tps_cnt = 0; |
| 2488 | u32 sqr_err_iq = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2489 | u32 a = 0; |
| 2490 | u32 b = 0; |
| 2491 | u32 c = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2492 | u32 i_mer = 0; |
| 2493 | u16 transmission_params = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2494 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2495 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2496 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2497 | status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A, |
| 2498 | &eq_reg_td_tps_pwr_ofs); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2499 | if (status < 0) |
| 2500 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2501 | status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A, |
| 2502 | &eq_reg_td_req_smb_cnt); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2503 | if (status < 0) |
| 2504 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2505 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A, |
| 2506 | &eq_reg_td_sqr_err_exp); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2507 | if (status < 0) |
| 2508 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2509 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A, |
| 2510 | ®_data); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2511 | if (status < 0) |
| 2512 | goto error; |
| 2513 | /* Extend SQR_ERR_I operational range */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2514 | eq_reg_td_sqr_err_i = (u32) reg_data; |
| 2515 | if ((eq_reg_td_sqr_err_exp > 11) && |
| 2516 | (eq_reg_td_sqr_err_i < 0x00000FFFUL)) { |
| 2517 | eq_reg_td_sqr_err_i += 0x00010000UL; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2518 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2519 | status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, ®_data); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2520 | if (status < 0) |
| 2521 | goto error; |
| 2522 | /* Extend SQR_ERR_Q operational range */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2523 | eq_reg_td_sqr_err_q = (u32) reg_data; |
| 2524 | if ((eq_reg_td_sqr_err_exp > 11) && |
| 2525 | (eq_reg_td_sqr_err_q < 0x00000FFFUL)) |
| 2526 | eq_reg_td_sqr_err_q += 0x00010000UL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2527 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2528 | status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, |
| 2529 | &transmission_params); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2530 | if (status < 0) |
| 2531 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2532 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2533 | /* Check input data for MER */ |
| 2534 | |
| 2535 | /* MER calculation (in 0.1 dB) without math.h */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2536 | if ((eq_reg_td_tps_pwr_ofs == 0) || (eq_reg_td_req_smb_cnt == 0)) |
| 2537 | i_mer = 0; |
| 2538 | else if ((eq_reg_td_sqr_err_i + eq_reg_td_sqr_err_q) == 0) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2539 | /* No error at all, this must be the HW reset value |
| 2540 | * Apparently no first measurement yet |
| 2541 | * Set MER to 0.0 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2542 | i_mer = 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2543 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2544 | sqr_err_iq = (eq_reg_td_sqr_err_i + eq_reg_td_sqr_err_q) << |
| 2545 | eq_reg_td_sqr_err_exp; |
| 2546 | if ((transmission_params & |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2547 | OFDM_SC_RA_RAM_OP_PARAM_MODE__M) |
| 2548 | == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2549 | tps_cnt = 17; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2550 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2551 | tps_cnt = 68; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2552 | |
| 2553 | /* IMER = 100 * log10 (x) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2554 | where x = (eq_reg_td_tps_pwr_ofs^2 * |
| 2555 | eq_reg_td_req_smb_cnt * tps_cnt)/sqr_err_iq |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2556 | |
| 2557 | => IMER = a + b -c |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2558 | where a = 100 * log10 (eq_reg_td_tps_pwr_ofs^2) |
| 2559 | b = 100 * log10 (eq_reg_td_req_smb_cnt * tps_cnt) |
| 2560 | c = 100 * log10 (sqr_err_iq) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2561 | */ |
| 2562 | |
| 2563 | /* log(x) x = 9bits * 9bits->18 bits */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2564 | a = log10times100(eq_reg_td_tps_pwr_ofs * |
| 2565 | eq_reg_td_tps_pwr_ofs); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2566 | /* log(x) x = 16bits * 7bits->23 bits */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2567 | b = log10times100(eq_reg_td_req_smb_cnt * tps_cnt); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2568 | /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2569 | c = log10times100(sqr_err_iq); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2570 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2571 | i_mer = a + b - c; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2572 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2573 | *p_signal_to_noise = i_mer; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2574 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2575 | error: |
| 2576 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2577 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2578 | return status; |
| 2579 | } |
| 2580 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2581 | static int get_signal_to_noise(struct drxk_state *state, s32 *p_signal_to_noise) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2582 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2583 | dprintk(1, "\n"); |
| 2584 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2585 | *p_signal_to_noise = 0; |
| 2586 | switch (state->m_operation_mode) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2587 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2588 | return get_dvbt_signal_to_noise(state, p_signal_to_noise); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2589 | case OM_QAM_ITU_A: |
| 2590 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2591 | return get_qam_signal_to_noise(state, p_signal_to_noise); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2592 | default: |
| 2593 | break; |
| 2594 | } |
| 2595 | return 0; |
| 2596 | } |
| 2597 | |
| 2598 | #if 0 |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2599 | static int get_dvbt_quality(struct drxk_state *state, s32 *p_quality) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2600 | { |
| 2601 | /* SNR Values for quasi errorfree reception rom Nordig 2.2 */ |
| 2602 | int status = 0; |
| 2603 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2604 | dprintk(1, "\n"); |
| 2605 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2606 | static s32 QE_SN[] = { |
| 2607 | 51, /* QPSK 1/2 */ |
| 2608 | 69, /* QPSK 2/3 */ |
| 2609 | 79, /* QPSK 3/4 */ |
| 2610 | 89, /* QPSK 5/6 */ |
| 2611 | 97, /* QPSK 7/8 */ |
| 2612 | 108, /* 16-QAM 1/2 */ |
| 2613 | 131, /* 16-QAM 2/3 */ |
| 2614 | 146, /* 16-QAM 3/4 */ |
| 2615 | 156, /* 16-QAM 5/6 */ |
| 2616 | 160, /* 16-QAM 7/8 */ |
| 2617 | 165, /* 64-QAM 1/2 */ |
| 2618 | 187, /* 64-QAM 2/3 */ |
| 2619 | 202, /* 64-QAM 3/4 */ |
| 2620 | 216, /* 64-QAM 5/6 */ |
| 2621 | 225, /* 64-QAM 7/8 */ |
| 2622 | }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2623 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2624 | *p_quality = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2625 | |
| 2626 | do { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2627 | s32 signal_to_noise = 0; |
| 2628 | u16 constellation = 0; |
| 2629 | u16 code_rate = 0; |
| 2630 | u32 signal_to_noise_rel; |
| 2631 | u32 ber_quality; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2632 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2633 | status = get_dvbt_signal_to_noise(state, &signal_to_noise); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2634 | if (status < 0) |
| 2635 | break; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2636 | status = read16(state, OFDM_EQ_TOP_TD_TPS_CONST__A, |
| 2637 | &constellation); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2638 | if (status < 0) |
| 2639 | break; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2640 | constellation &= OFDM_EQ_TOP_TD_TPS_CONST__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2641 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2642 | status = read16(state, OFDM_EQ_TOP_TD_TPS_CODE_HP__A, |
| 2643 | &code_rate); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2644 | if (status < 0) |
| 2645 | break; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2646 | code_rate &= OFDM_EQ_TOP_TD_TPS_CODE_HP__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2647 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2648 | if (constellation > OFDM_EQ_TOP_TD_TPS_CONST_64QAM || |
| 2649 | code_rate > OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2650 | break; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2651 | signal_to_noise_rel = signal_to_noise - |
| 2652 | QE_SN[constellation * 5 + code_rate]; |
| 2653 | ber_quality = 100; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2654 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2655 | if (signal_to_noise_rel < -70) |
| 2656 | *p_quality = 0; |
| 2657 | else if (signal_to_noise_rel < 30) |
| 2658 | *p_quality = ((signal_to_noise_rel + 70) * |
| 2659 | ber_quality) / 100; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2660 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2661 | *p_quality = ber_quality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2662 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2663 | return 0; |
| 2664 | }; |
| 2665 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2666 | static int get_dvbc_quality(struct drxk_state *state, s32 *p_quality) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2667 | { |
| 2668 | int status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2669 | *p_quality = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2670 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2671 | dprintk(1, "\n"); |
| 2672 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2673 | do { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2674 | u32 signal_to_noise = 0; |
| 2675 | u32 ber_quality = 100; |
| 2676 | u32 signal_to_noise_rel = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2677 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2678 | status = get_qam_signal_to_noise(state, &signal_to_noise); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2679 | if (status < 0) |
| 2680 | break; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2681 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 2682 | switch (state->props.modulation) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2683 | case QAM_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2684 | signal_to_noise_rel = signal_to_noise - 200; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2685 | break; |
| 2686 | case QAM_32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2687 | signal_to_noise_rel = signal_to_noise - 230; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2688 | break; /* Not in NorDig */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2689 | case QAM_64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2690 | signal_to_noise_rel = signal_to_noise - 260; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2691 | break; |
| 2692 | case QAM_128: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2693 | signal_to_noise_rel = signal_to_noise - 290; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2694 | break; |
| 2695 | default: |
| 2696 | case QAM_256: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2697 | signal_to_noise_rel = signal_to_noise - 320; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2701 | if (signal_to_noise_rel < -70) |
| 2702 | *p_quality = 0; |
| 2703 | else if (signal_to_noise_rel < 30) |
| 2704 | *p_quality = ((signal_to_noise_rel + 70) * |
| 2705 | ber_quality) / 100; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2706 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2707 | *p_quality = ber_quality; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2708 | } while (0); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2709 | |
| 2710 | return status; |
| 2711 | } |
| 2712 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2713 | static int get_quality(struct drxk_state *state, s32 *p_quality) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2714 | { |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2715 | dprintk(1, "\n"); |
| 2716 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2717 | switch (state->m_operation_mode) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2718 | case OM_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2719 | return get_dvbt_quality(state, p_quality); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2720 | case OM_QAM_ITU_A: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2721 | return get_dvbc_quality(state, p_quality); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2722 | default: |
| 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | return 0; |
| 2727 | } |
| 2728 | #endif |
| 2729 | |
| 2730 | /* Free data ram in SIO HI */ |
| 2731 | #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040 |
| 2732 | #define SIO_HI_RA_RAM_USR_END__A 0x420060 |
| 2733 | |
| 2734 | #define DRXK_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A) |
| 2735 | #define DRXK_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7) |
| 2736 | #define DRXK_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ |
| 2737 | #define DRXK_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE |
| 2738 | |
| 2739 | #define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr) >> 22) & 0x3F) |
| 2740 | #define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F) |
| 2741 | #define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF) |
| 2742 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2743 | static int ConfigureI2CBridge(struct drxk_state *state, bool b_enable_bridge) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2744 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2745 | int status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2746 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2747 | dprintk(1, "\n"); |
| 2748 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2749 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 2750 | return 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2751 | if (state->m_drxk_state == DRXK_POWERED_DOWN) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2752 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2753 | |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame] | 2754 | if (state->no_i2c_bridge) |
| 2755 | return 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2756 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2757 | status = write16(state, SIO_HI_RA_RAM_PAR_1__A, |
| 2758 | SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2759 | if (status < 0) |
| 2760 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2761 | if (b_enable_bridge) { |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2762 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, |
| 2763 | SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2764 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2765 | goto error; |
| 2766 | } else { |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 2767 | status = write16(state, SIO_HI_RA_RAM_PAR_2__A, |
| 2768 | SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2769 | if (status < 0) |
| 2770 | goto error; |
| 2771 | } |
| 2772 | |
Hans Verkuil | b1cf201 | 2013-10-04 11:01:45 -0300 | [diff] [blame] | 2773 | status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, NULL); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2774 | |
| 2775 | error: |
| 2776 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2777 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2778 | return status; |
| 2779 | } |
| 2780 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2781 | static int set_pre_saw(struct drxk_state *state, |
| 2782 | struct s_cfg_pre_saw *p_pre_saw_cfg) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2783 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2784 | int status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2785 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2786 | dprintk(1, "\n"); |
| 2787 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2788 | if ((p_pre_saw_cfg == NULL) |
| 2789 | || (p_pre_saw_cfg->reference > IQM_AF_PDREF__M)) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2790 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2791 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2792 | status = write16(state, IQM_AF_PDREF__A, p_pre_saw_cfg->reference); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2793 | error: |
| 2794 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2795 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2796 | return status; |
| 2797 | } |
| 2798 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2799 | static int bl_direct_cmd(struct drxk_state *state, u32 target_addr, |
| 2800 | u16 rom_offset, u16 nr_of_elements, u32 time_out) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2801 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2802 | u16 bl_status = 0; |
| 2803 | u16 offset = (u16) ((target_addr >> 0) & 0x00FFFF); |
| 2804 | u16 blockbank = (u16) ((target_addr >> 16) & 0x000FFF); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2805 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2806 | unsigned long end; |
| 2807 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2808 | dprintk(1, "\n"); |
| 2809 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2810 | mutex_lock(&state->mutex); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2811 | status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_DIRECT); |
| 2812 | if (status < 0) |
| 2813 | goto error; |
| 2814 | status = write16(state, SIO_BL_TGT_HDR__A, blockbank); |
| 2815 | if (status < 0) |
| 2816 | goto error; |
| 2817 | status = write16(state, SIO_BL_TGT_ADDR__A, offset); |
| 2818 | if (status < 0) |
| 2819 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2820 | status = write16(state, SIO_BL_SRC_ADDR__A, rom_offset); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2821 | if (status < 0) |
| 2822 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2823 | status = write16(state, SIO_BL_SRC_LEN__A, nr_of_elements); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2824 | if (status < 0) |
| 2825 | goto error; |
| 2826 | status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); |
| 2827 | if (status < 0) |
| 2828 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2829 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2830 | end = jiffies + msecs_to_jiffies(time_out); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2831 | do { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2832 | status = read16(state, SIO_BL_STATUS__A, &bl_status); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2833 | if (status < 0) |
| 2834 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2835 | } while ((bl_status == 0x1) && time_is_after_jiffies(end)); |
| 2836 | if (bl_status == 0x1) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2837 | pr_err("SIO not ready\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2838 | status = -EINVAL; |
| 2839 | goto error2; |
| 2840 | } |
| 2841 | error: |
| 2842 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2843 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2844 | error2: |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2845 | mutex_unlock(&state->mutex); |
| 2846 | return status; |
| 2847 | |
| 2848 | } |
| 2849 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2850 | static int adc_sync_measurement(struct drxk_state *state, u16 *count) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2851 | { |
| 2852 | u16 data = 0; |
| 2853 | int status; |
| 2854 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2855 | dprintk(1, "\n"); |
| 2856 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2857 | /* start measurement */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2858 | status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE); |
| 2859 | if (status < 0) |
| 2860 | goto error; |
| 2861 | status = write16(state, IQM_AF_START_LOCK__A, 1); |
| 2862 | if (status < 0) |
| 2863 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2864 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2865 | *count = 0; |
| 2866 | status = read16(state, IQM_AF_PHASE0__A, &data); |
| 2867 | if (status < 0) |
| 2868 | goto error; |
| 2869 | if (data == 127) |
| 2870 | *count = *count + 1; |
| 2871 | status = read16(state, IQM_AF_PHASE1__A, &data); |
| 2872 | if (status < 0) |
| 2873 | goto error; |
| 2874 | if (data == 127) |
| 2875 | *count = *count + 1; |
| 2876 | status = read16(state, IQM_AF_PHASE2__A, &data); |
| 2877 | if (status < 0) |
| 2878 | goto error; |
| 2879 | if (data == 127) |
| 2880 | *count = *count + 1; |
| 2881 | |
| 2882 | error: |
| 2883 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2884 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2885 | return status; |
| 2886 | } |
| 2887 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2888 | static int adc_synchronization(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2889 | { |
| 2890 | u16 count = 0; |
| 2891 | int status; |
| 2892 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2893 | dprintk(1, "\n"); |
| 2894 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2895 | status = adc_sync_measurement(state, &count); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2896 | if (status < 0) |
| 2897 | goto error; |
| 2898 | |
| 2899 | if (count == 1) { |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 2900 | /* Try sampling on a different edge */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2901 | u16 clk_neg = 0; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2902 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2903 | status = read16(state, IQM_AF_CLKNEG__A, &clk_neg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2904 | if (status < 0) |
| 2905 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2906 | if ((clk_neg & IQM_AF_CLKNEG_CLKNEGDATA__M) == |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2907 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2908 | clk_neg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2909 | clk_neg |= |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2910 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG; |
| 2911 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2912 | clk_neg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); |
| 2913 | clk_neg |= |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2914 | IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS; |
| 2915 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2916 | status = write16(state, IQM_AF_CLKNEG__A, clk_neg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2917 | if (status < 0) |
| 2918 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2919 | status = adc_sync_measurement(state, &count); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 2920 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2921 | goto error; |
| 2922 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2923 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2924 | if (count < 2) |
| 2925 | status = -EINVAL; |
| 2926 | error: |
| 2927 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2928 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2929 | return status; |
| 2930 | } |
| 2931 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2932 | static int set_frequency_shifter(struct drxk_state *state, |
| 2933 | u16 intermediate_freqk_hz, |
| 2934 | s32 tuner_freq_offset, bool is_dtv) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2935 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2936 | bool select_pos_image = false; |
| 2937 | u32 rf_freq_residual = tuner_freq_offset; |
| 2938 | u32 fm_frequency_shift = 0; |
| 2939 | bool tuner_mirror = !state->m_b_mirror_freq_spect; |
| 2940 | u32 adc_freq; |
| 2941 | bool adc_flip; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2942 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2943 | u32 if_freq_actual; |
| 2944 | u32 sampling_frequency = (u32) (state->m_sys_clock_freq / 3); |
| 2945 | u32 frequency_shift; |
| 2946 | bool image_to_select; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2947 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 2948 | dprintk(1, "\n"); |
| 2949 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2950 | /* |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2951 | Program frequency shifter |
| 2952 | No need to account for mirroring on RF |
| 2953 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2954 | if (is_dtv) { |
| 2955 | if ((state->m_operation_mode == OM_QAM_ITU_A) || |
| 2956 | (state->m_operation_mode == OM_QAM_ITU_C) || |
| 2957 | (state->m_operation_mode == OM_DVBT)) |
| 2958 | select_pos_image = true; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 2959 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2960 | select_pos_image = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2961 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2962 | if (tuner_mirror) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2963 | /* tuner doesn't mirror */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2964 | if_freq_actual = intermediate_freqk_hz + |
| 2965 | rf_freq_residual + fm_frequency_shift; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2966 | else |
| 2967 | /* tuner mirrors */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2968 | if_freq_actual = intermediate_freqk_hz - |
| 2969 | rf_freq_residual - fm_frequency_shift; |
| 2970 | if (if_freq_actual > sampling_frequency / 2) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2971 | /* adc mirrors */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2972 | adc_freq = sampling_frequency - if_freq_actual; |
| 2973 | adc_flip = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2974 | } else { |
| 2975 | /* adc doesn't mirror */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2976 | adc_freq = if_freq_actual; |
| 2977 | adc_flip = false; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2978 | } |
| 2979 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2980 | frequency_shift = adc_freq; |
| 2981 | image_to_select = state->m_rfmirror ^ tuner_mirror ^ |
| 2982 | adc_flip ^ select_pos_image; |
| 2983 | state->m_iqm_fs_rate_ofs = |
| 2984 | Frac28a((frequency_shift), sampling_frequency); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2985 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2986 | if (image_to_select) |
| 2987 | state->m_iqm_fs_rate_ofs = ~state->m_iqm_fs_rate_ofs + 1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2988 | |
| 2989 | /* Program frequency shifter with tuner offset compensation */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2990 | /* frequency_shift += tuner_freq_offset; TODO */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 2991 | status = write32(state, IQM_FS_RATE_OFS_LO__A, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2992 | state->m_iqm_fs_rate_ofs); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 2993 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 2994 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2995 | return status; |
| 2996 | } |
| 2997 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 2998 | static int init_agc(struct drxk_state *state, bool is_dtv) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 2999 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3000 | u16 ingain_tgt = 0; |
| 3001 | u16 ingain_tgt_min = 0; |
| 3002 | u16 ingain_tgt_max = 0; |
| 3003 | u16 clp_cyclen = 0; |
| 3004 | u16 clp_sum_min = 0; |
| 3005 | u16 clp_dir_to = 0; |
| 3006 | u16 sns_sum_min = 0; |
| 3007 | u16 sns_sum_max = 0; |
| 3008 | u16 clp_sum_max = 0; |
| 3009 | u16 sns_dir_to = 0; |
| 3010 | u16 ki_innergain_min = 0; |
| 3011 | u16 if_iaccu_hi_tgt = 0; |
| 3012 | u16 if_iaccu_hi_tgt_min = 0; |
| 3013 | u16 if_iaccu_hi_tgt_max = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3014 | u16 data = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3015 | u16 fast_clp_ctrl_delay = 0; |
| 3016 | u16 clp_ctrl_mode = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3017 | int status = 0; |
| 3018 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3019 | dprintk(1, "\n"); |
| 3020 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3021 | /* Common settings */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3022 | sns_sum_max = 1023; |
| 3023 | if_iaccu_hi_tgt_min = 2047; |
| 3024 | clp_cyclen = 500; |
| 3025 | clp_sum_max = 1023; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3026 | |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 3027 | /* AGCInit() not available for DVBT; init done in microcode */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3028 | if (!is_qam(state)) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3029 | pr_err("%s: mode %d is not DVB-C\n", |
| 3030 | __func__, state->m_operation_mode); |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 3031 | return -EINVAL; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3032 | } |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 3033 | |
| 3034 | /* FIXME: Analog TV AGC require different settings */ |
| 3035 | |
| 3036 | /* Standard specific settings */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3037 | clp_sum_min = 8; |
| 3038 | clp_dir_to = (u16) -9; |
| 3039 | clp_ctrl_mode = 0; |
| 3040 | sns_sum_min = 8; |
| 3041 | sns_dir_to = (u16) -9; |
| 3042 | ki_innergain_min = (u16) -1030; |
| 3043 | if_iaccu_hi_tgt_max = 0x2380; |
| 3044 | if_iaccu_hi_tgt = 0x2380; |
| 3045 | ingain_tgt_min = 0x0511; |
| 3046 | ingain_tgt = 0x0511; |
| 3047 | ingain_tgt_max = 5119; |
| 3048 | fast_clp_ctrl_delay = state->m_qam_if_agc_cfg.fast_clip_ctrl_delay; |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 3049 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3050 | status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, |
| 3051 | fast_clp_ctrl_delay); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3052 | if (status < 0) |
| 3053 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3054 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3055 | status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clp_ctrl_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3056 | if (status < 0) |
| 3057 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3058 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingain_tgt); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3059 | if (status < 0) |
| 3060 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3061 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingain_tgt_min); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3062 | if (status < 0) |
| 3063 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3064 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingain_tgt_max); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3065 | if (status < 0) |
| 3066 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3067 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, |
| 3068 | if_iaccu_hi_tgt_min); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3069 | if (status < 0) |
| 3070 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3071 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, |
| 3072 | if_iaccu_hi_tgt_max); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3073 | if (status < 0) |
| 3074 | goto error; |
| 3075 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0); |
| 3076 | if (status < 0) |
| 3077 | goto error; |
| 3078 | status = write16(state, SCU_RAM_AGC_IF_IACCU_LO__A, 0); |
| 3079 | if (status < 0) |
| 3080 | goto error; |
| 3081 | status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, 0); |
| 3082 | if (status < 0) |
| 3083 | goto error; |
| 3084 | status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0); |
| 3085 | if (status < 0) |
| 3086 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3087 | status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clp_sum_max); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3088 | if (status < 0) |
| 3089 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3090 | status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, sns_sum_max); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3091 | if (status < 0) |
| 3092 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3093 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3094 | status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, |
| 3095 | ki_innergain_min); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3096 | if (status < 0) |
| 3097 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3098 | status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, |
| 3099 | if_iaccu_hi_tgt); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3100 | if (status < 0) |
| 3101 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3102 | status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clp_cyclen); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3103 | if (status < 0) |
| 3104 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3105 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3106 | status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MAX__A, 1023); |
| 3107 | if (status < 0) |
| 3108 | goto error; |
| 3109 | status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MIN__A, (u16) -1023); |
| 3110 | if (status < 0) |
| 3111 | goto error; |
| 3112 | status = write16(state, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50); |
| 3113 | if (status < 0) |
| 3114 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3115 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3116 | status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20); |
| 3117 | if (status < 0) |
| 3118 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3119 | status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clp_sum_min); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3120 | if (status < 0) |
| 3121 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3122 | status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, sns_sum_min); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3123 | if (status < 0) |
| 3124 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3125 | status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clp_dir_to); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3126 | if (status < 0) |
| 3127 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3128 | status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, sns_dir_to); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3129 | if (status < 0) |
| 3130 | goto error; |
| 3131 | status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff); |
| 3132 | if (status < 0) |
| 3133 | goto error; |
| 3134 | status = write16(state, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0); |
| 3135 | if (status < 0) |
| 3136 | goto error; |
| 3137 | status = write16(state, SCU_RAM_AGC_KI_MIN__A, 0x0117); |
| 3138 | if (status < 0) |
| 3139 | goto error; |
| 3140 | status = write16(state, SCU_RAM_AGC_KI_MAX__A, 0x0657); |
| 3141 | if (status < 0) |
| 3142 | goto error; |
| 3143 | status = write16(state, SCU_RAM_AGC_CLP_SUM__A, 0); |
| 3144 | if (status < 0) |
| 3145 | goto error; |
| 3146 | status = write16(state, SCU_RAM_AGC_CLP_CYCCNT__A, 0); |
| 3147 | if (status < 0) |
| 3148 | goto error; |
| 3149 | status = write16(state, SCU_RAM_AGC_CLP_DIR_WD__A, 0); |
| 3150 | if (status < 0) |
| 3151 | goto error; |
| 3152 | status = write16(state, SCU_RAM_AGC_CLP_DIR_STP__A, 1); |
| 3153 | if (status < 0) |
| 3154 | goto error; |
| 3155 | status = write16(state, SCU_RAM_AGC_SNS_SUM__A, 0); |
| 3156 | if (status < 0) |
| 3157 | goto error; |
| 3158 | status = write16(state, SCU_RAM_AGC_SNS_CYCCNT__A, 0); |
| 3159 | if (status < 0) |
| 3160 | goto error; |
| 3161 | status = write16(state, SCU_RAM_AGC_SNS_DIR_WD__A, 0); |
| 3162 | if (status < 0) |
| 3163 | goto error; |
| 3164 | status = write16(state, SCU_RAM_AGC_SNS_DIR_STP__A, 1); |
| 3165 | if (status < 0) |
| 3166 | goto error; |
| 3167 | status = write16(state, SCU_RAM_AGC_SNS_CYCLEN__A, 500); |
| 3168 | if (status < 0) |
| 3169 | goto error; |
| 3170 | status = write16(state, SCU_RAM_AGC_KI_CYCLEN__A, 500); |
| 3171 | if (status < 0) |
| 3172 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3173 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3174 | /* Initialize inner-loop KI gain factors */ |
| 3175 | status = read16(state, SCU_RAM_AGC_KI__A, &data); |
| 3176 | if (status < 0) |
| 3177 | goto error; |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 3178 | |
| 3179 | data = 0x0657; |
| 3180 | data &= ~SCU_RAM_AGC_KI_RF__M; |
| 3181 | data |= (DRXK_KI_RAGC_QAM << SCU_RAM_AGC_KI_RF__B); |
| 3182 | data &= ~SCU_RAM_AGC_KI_IF__M; |
| 3183 | data |= (DRXK_KI_IAGC_QAM << SCU_RAM_AGC_KI_IF__B); |
| 3184 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3185 | status = write16(state, SCU_RAM_AGC_KI__A, data); |
| 3186 | error: |
| 3187 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3188 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3189 | return status; |
| 3190 | } |
| 3191 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3192 | static int dvbtqam_get_acc_pkt_err(struct drxk_state *state, u16 *packet_err) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3193 | { |
| 3194 | int status; |
| 3195 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3196 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3197 | if (packet_err == NULL) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3198 | status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); |
| 3199 | else |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3200 | status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, |
| 3201 | packet_err); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3202 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3203 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3204 | return status; |
| 3205 | } |
| 3206 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3207 | static int dvbt_sc_command(struct drxk_state *state, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3208 | u16 cmd, u16 subcmd, |
| 3209 | u16 param0, u16 param1, u16 param2, |
| 3210 | u16 param3, u16 param4) |
| 3211 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3212 | u16 cur_cmd = 0; |
| 3213 | u16 err_code = 0; |
| 3214 | u16 retry_cnt = 0; |
| 3215 | u16 sc_exec = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3216 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3217 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3218 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3219 | status = read16(state, OFDM_SC_COMM_EXEC__A, &sc_exec); |
| 3220 | if (sc_exec != 1) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3221 | /* SC is not running */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3222 | status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3223 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3224 | if (status < 0) |
| 3225 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3226 | |
| 3227 | /* Wait until sc is ready to receive command */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3228 | retry_cnt = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3229 | do { |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 3230 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3231 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &cur_cmd); |
| 3232 | retry_cnt++; |
| 3233 | } while ((cur_cmd != 0) && (retry_cnt < DRXK_MAX_RETRIES)); |
| 3234 | if (retry_cnt >= DRXK_MAX_RETRIES && (status < 0)) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3235 | goto error; |
| 3236 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3237 | /* Write sub-command */ |
| 3238 | switch (cmd) { |
| 3239 | /* All commands using sub-cmd */ |
| 3240 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3241 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3242 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3243 | status = write16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, subcmd); |
| 3244 | if (status < 0) |
| 3245 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3246 | break; |
| 3247 | default: |
| 3248 | /* Do nothing */ |
| 3249 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3250 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3251 | |
| 3252 | /* Write needed parameters and the command */ |
Mauro Carvalho Chehab | 2f60f13 | 2015-06-05 07:58:52 -0300 | [diff] [blame] | 3253 | status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3254 | switch (cmd) { |
| 3255 | /* All commands using 5 parameters */ |
| 3256 | /* All commands using 4 parameters */ |
| 3257 | /* All commands using 3 parameters */ |
| 3258 | /* All commands using 2 parameters */ |
| 3259 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3260 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3261 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
Mauro Carvalho Chehab | 2f60f13 | 2015-06-05 07:58:52 -0300 | [diff] [blame] | 3262 | status |= write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1); |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3263 | /* fall through - All commands using 1 parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3264 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3265 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
Mauro Carvalho Chehab | 2f60f13 | 2015-06-05 07:58:52 -0300 | [diff] [blame] | 3266 | status |= write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0); |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3267 | /* fall through - All commands using 0 parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3268 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
| 3269 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3270 | /* Write command */ |
Mauro Carvalho Chehab | 2f60f13 | 2015-06-05 07:58:52 -0300 | [diff] [blame] | 3271 | status |= write16(state, OFDM_SC_RA_RAM_CMD__A, cmd); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3272 | break; |
| 3273 | default: |
| 3274 | /* Unknown command */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3275 | status = -EINVAL; |
| 3276 | } |
| 3277 | if (status < 0) |
| 3278 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3279 | |
| 3280 | /* Wait until sc is ready processing command */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3281 | retry_cnt = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3282 | do { |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 3283 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3284 | status = read16(state, OFDM_SC_RA_RAM_CMD__A, &cur_cmd); |
| 3285 | retry_cnt++; |
| 3286 | } while ((cur_cmd != 0) && (retry_cnt < DRXK_MAX_RETRIES)); |
| 3287 | if (retry_cnt >= DRXK_MAX_RETRIES && (status < 0)) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3288 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3289 | |
| 3290 | /* Check for illegal cmd */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3291 | status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &err_code); |
| 3292 | if (err_code == 0xFFFF) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3293 | /* illegal command */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3294 | status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3295 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3296 | if (status < 0) |
| 3297 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3298 | |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 3299 | /* Retrieve results parameters from SC */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3300 | switch (cmd) { |
| 3301 | /* All commands yielding 5 results */ |
| 3302 | /* All commands yielding 4 results */ |
| 3303 | /* All commands yielding 3 results */ |
| 3304 | /* All commands yielding 2 results */ |
| 3305 | /* All commands yielding 1 result */ |
| 3306 | case OFDM_SC_RA_RAM_CMD_USER_IO: |
| 3307 | case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3308 | status = read16(state, OFDM_SC_RA_RAM_PARAM0__A, &(param0)); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3309 | /* All commands yielding 0 results */ |
| 3310 | case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: |
| 3311 | case OFDM_SC_RA_RAM_CMD_SET_TIMER: |
| 3312 | case OFDM_SC_RA_RAM_CMD_PROC_START: |
| 3313 | case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: |
| 3314 | case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: |
| 3315 | case OFDM_SC_RA_RAM_CMD_NULL: |
| 3316 | break; |
| 3317 | default: |
| 3318 | /* Unknown command */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3319 | status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3320 | break; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3321 | } /* switch (cmd->cmd) */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3322 | error: |
| 3323 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3324 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3325 | return status; |
| 3326 | } |
| 3327 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3328 | static int power_up_dvbt(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3329 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3330 | enum drx_power_mode power_mode = DRX_POWER_UP; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3331 | int status; |
| 3332 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3333 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3334 | status = ctrl_power_mode(state, &power_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3335 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3336 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3337 | return status; |
| 3338 | } |
| 3339 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3340 | static int dvbt_ctrl_set_inc_enable(struct drxk_state *state, bool *enabled) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3341 | { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3342 | int status; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3343 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3344 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 3345 | if (*enabled) |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3346 | status = write16(state, IQM_CF_BYPASSDET__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3347 | else |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3348 | status = write16(state, IQM_CF_BYPASSDET__A, 1); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3349 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3350 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3351 | return status; |
| 3352 | } |
| 3353 | |
| 3354 | #define DEFAULT_FR_THRES_8K 4000 |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3355 | static int dvbt_ctrl_set_fr_enable(struct drxk_state *state, bool *enabled) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3356 | { |
| 3357 | |
| 3358 | int status; |
| 3359 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3360 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 3361 | if (*enabled) { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3362 | /* write mask to 1 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3363 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3364 | DEFAULT_FR_THRES_8K); |
| 3365 | } else { |
| 3366 | /* write mask to 0 */ |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3367 | status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3368 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3369 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3370 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3371 | |
| 3372 | return status; |
| 3373 | } |
| 3374 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3375 | static int dvbt_ctrl_set_echo_threshold(struct drxk_state *state, |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3376 | struct drxk_cfg_dvbt_echo_thres_t *echo_thres) |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3377 | { |
| 3378 | u16 data = 0; |
| 3379 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3380 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3381 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3382 | status = read16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, &data); |
| 3383 | if (status < 0) |
| 3384 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3385 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3386 | switch (echo_thres->fft_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3387 | case DRX_FFTMODE_2K: |
| 3388 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3389 | data |= ((echo_thres->threshold << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3390 | OFDM_SC_RA_RAM_ECHO_THRES_2K__B) |
| 3391 | & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M)); |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3392 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3393 | case DRX_FFTMODE_8K: |
| 3394 | data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3395 | data |= ((echo_thres->threshold << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3396 | OFDM_SC_RA_RAM_ECHO_THRES_8K__B) |
| 3397 | & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M)); |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3398 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3399 | default: |
| 3400 | return -EINVAL; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3401 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3402 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3403 | status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data); |
| 3404 | error: |
| 3405 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3406 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3407 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3408 | } |
| 3409 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3410 | static int dvbt_ctrl_set_sqi_speed(struct drxk_state *state, |
| 3411 | enum drxk_cfg_dvbt_sqi_speed *speed) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3412 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3413 | int status = -EINVAL; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3414 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3415 | dprintk(1, "\n"); |
| 3416 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3417 | switch (*speed) { |
| 3418 | case DRXK_DVBT_SQI_SPEED_FAST: |
| 3419 | case DRXK_DVBT_SQI_SPEED_MEDIUM: |
| 3420 | case DRXK_DVBT_SQI_SPEED_SLOW: |
| 3421 | break; |
| 3422 | default: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3423 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3424 | } |
Mauro Carvalho Chehab | 5e66b87 | 2011-07-09 09:50:21 -0300 | [diff] [blame] | 3425 | status = write16(state, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3426 | (u16) *speed); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3427 | error: |
| 3428 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3429 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3430 | return status; |
| 3431 | } |
| 3432 | |
| 3433 | /*============================================================================*/ |
| 3434 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 3435 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3436 | * \brief Activate DVBT specific presets |
| 3437 | * \param demod instance of demodulator. |
| 3438 | * \return DRXStatus_t. |
| 3439 | * |
| 3440 | * Called in DVBTSetStandard |
| 3441 | * |
| 3442 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3443 | static int dvbt_activate_presets(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3444 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3445 | int status; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3446 | bool setincenable = false; |
| 3447 | bool setfrenable = true; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3448 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3449 | struct drxk_cfg_dvbt_echo_thres_t echo_thres2k = { 0, DRX_FFTMODE_2K }; |
| 3450 | struct drxk_cfg_dvbt_echo_thres_t echo_thres8k = { 0, DRX_FFTMODE_8K }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3451 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3452 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3453 | status = dvbt_ctrl_set_inc_enable(state, &setincenable); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3454 | if (status < 0) |
| 3455 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3456 | status = dvbt_ctrl_set_fr_enable(state, &setfrenable); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3457 | if (status < 0) |
| 3458 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3459 | status = dvbt_ctrl_set_echo_threshold(state, &echo_thres2k); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3460 | if (status < 0) |
| 3461 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3462 | status = dvbt_ctrl_set_echo_threshold(state, &echo_thres8k); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3463 | if (status < 0) |
| 3464 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3465 | status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, |
| 3466 | state->m_dvbt_if_agc_cfg.ingain_tgt_max); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3467 | error: |
| 3468 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3469 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3470 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3471 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3472 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3473 | /*============================================================================*/ |
| 3474 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 3475 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3476 | * \brief Initialize channelswitch-independent settings for DVBT. |
| 3477 | * \param demod instance of demodulator. |
| 3478 | * \return DRXStatus_t. |
| 3479 | * |
| 3480 | * For ROM code channel filter taps are loaded from the bootloader. For microcode |
| 3481 | * the DVB-T taps from the drxk_filters.h are used. |
| 3482 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3483 | static int set_dvbt_standard(struct drxk_state *state, |
| 3484 | enum operation_mode o_mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3485 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3486 | u16 cmd_result = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3487 | u16 data = 0; |
| 3488 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3489 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3490 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3491 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3492 | power_up_dvbt(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3493 | /* added antenna switch */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3494 | switch_antenna_to_dvbt(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3495 | /* send OFDM reset command */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3496 | status = scu_command(state, |
| 3497 | SCU_RAM_COMMAND_STANDARD_OFDM |
| 3498 | | SCU_RAM_COMMAND_CMD_DEMOD_RESET, |
| 3499 | 0, NULL, 1, &cmd_result); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3500 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3501 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3502 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3503 | /* send OFDM setenv command */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3504 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM |
| 3505 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, |
| 3506 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3507 | if (status < 0) |
| 3508 | goto error; |
| 3509 | |
| 3510 | /* reset datapath for OFDM, processors first */ |
| 3511 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
| 3512 | if (status < 0) |
| 3513 | goto error; |
| 3514 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
| 3515 | if (status < 0) |
| 3516 | goto error; |
| 3517 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
| 3518 | if (status < 0) |
| 3519 | goto error; |
| 3520 | |
| 3521 | /* IQM setup */ |
| 3522 | /* synchronize on ofdstate->m_festart */ |
| 3523 | status = write16(state, IQM_AF_UPD_SEL__A, 1); |
| 3524 | if (status < 0) |
| 3525 | goto error; |
| 3526 | /* window size for clipping ADC detection */ |
| 3527 | status = write16(state, IQM_AF_CLP_LEN__A, 0); |
| 3528 | if (status < 0) |
| 3529 | goto error; |
| 3530 | /* window size for for sense pre-SAW detection */ |
| 3531 | status = write16(state, IQM_AF_SNS_LEN__A, 0); |
| 3532 | if (status < 0) |
| 3533 | goto error; |
| 3534 | /* sense threshold for sense pre-SAW detection */ |
| 3535 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
| 3536 | if (status < 0) |
| 3537 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3538 | status = set_iqm_af(state, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3539 | if (status < 0) |
| 3540 | goto error; |
| 3541 | |
| 3542 | status = write16(state, IQM_AF_AGC_RF__A, 0); |
| 3543 | if (status < 0) |
| 3544 | goto error; |
| 3545 | |
| 3546 | /* Impulse noise cruncher setup */ |
| 3547 | status = write16(state, IQM_AF_INC_LCT__A, 0); /* crunch in IQM_CF */ |
| 3548 | if (status < 0) |
| 3549 | goto error; |
| 3550 | status = write16(state, IQM_CF_DET_LCT__A, 0); /* detect in IQM_CF */ |
| 3551 | if (status < 0) |
| 3552 | goto error; |
| 3553 | status = write16(state, IQM_CF_WND_LEN__A, 3); /* peak detector window length */ |
| 3554 | if (status < 0) |
| 3555 | goto error; |
| 3556 | |
| 3557 | status = write16(state, IQM_RC_STRETCH__A, 16); |
| 3558 | if (status < 0) |
| 3559 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3560 | status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3561 | if (status < 0) |
| 3562 | goto error; |
| 3563 | status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */ |
| 3564 | if (status < 0) |
| 3565 | goto error; |
| 3566 | status = write16(state, IQM_CF_SCALE__A, 1600); |
| 3567 | if (status < 0) |
| 3568 | goto error; |
| 3569 | status = write16(state, IQM_CF_SCALE_SH__A, 0); |
| 3570 | if (status < 0) |
| 3571 | goto error; |
| 3572 | |
| 3573 | /* virtual clipping threshold for clipping ADC detection */ |
| 3574 | status = write16(state, IQM_AF_CLP_TH__A, 448); |
| 3575 | if (status < 0) |
| 3576 | goto error; |
| 3577 | status = write16(state, IQM_CF_DATATH__A, 495); /* crunching threshold */ |
| 3578 | if (status < 0) |
| 3579 | goto error; |
| 3580 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3581 | status = bl_chain_cmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, |
| 3582 | DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3583 | if (status < 0) |
| 3584 | goto error; |
| 3585 | |
| 3586 | status = write16(state, IQM_CF_PKDTH__A, 2); /* peak detector threshold */ |
| 3587 | if (status < 0) |
| 3588 | goto error; |
| 3589 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 2); |
| 3590 | if (status < 0) |
| 3591 | goto error; |
| 3592 | /* enable power measurement interrupt */ |
| 3593 | status = write16(state, IQM_CF_COMM_INT_MSK__A, 1); |
| 3594 | if (status < 0) |
| 3595 | goto error; |
| 3596 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); |
| 3597 | if (status < 0) |
| 3598 | goto error; |
| 3599 | |
| 3600 | /* IQM will not be reset from here, sync ADC and update/init AGC */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3601 | status = adc_synchronization(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3602 | if (status < 0) |
| 3603 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3604 | status = set_pre_saw(state, &state->m_dvbt_pre_saw_cfg); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3605 | if (status < 0) |
| 3606 | goto error; |
| 3607 | |
| 3608 | /* Halt SCU to enable safe non-atomic accesses */ |
| 3609 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
| 3610 | if (status < 0) |
| 3611 | goto error; |
| 3612 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3613 | status = set_agc_rf(state, &state->m_dvbt_rf_agc_cfg, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3614 | if (status < 0) |
| 3615 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3616 | status = set_agc_if(state, &state->m_dvbt_if_agc_cfg, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3617 | if (status < 0) |
| 3618 | goto error; |
| 3619 | |
| 3620 | /* Set Noise Estimation notch width and enable DC fix */ |
| 3621 | status = read16(state, OFDM_SC_RA_RAM_CONFIG__A, &data); |
| 3622 | if (status < 0) |
| 3623 | goto error; |
| 3624 | data |= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M; |
| 3625 | status = write16(state, OFDM_SC_RA_RAM_CONFIG__A, data); |
| 3626 | if (status < 0) |
| 3627 | goto error; |
| 3628 | |
| 3629 | /* Activate SCU to enable SCU commands */ |
| 3630 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
| 3631 | if (status < 0) |
| 3632 | goto error; |
| 3633 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3634 | if (!state->m_drxk_a3_rom_code) { |
| 3635 | /* AGCInit() is not done for DVBT, so set agcfast_clip_ctrl_delay */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3636 | status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, |
| 3637 | state->m_dvbt_if_agc_cfg.fast_clip_ctrl_delay); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3638 | if (status < 0) |
| 3639 | goto error; |
| 3640 | } |
| 3641 | |
| 3642 | /* OFDM_SC setup */ |
| 3643 | #ifdef COMPILE_FOR_NONRT |
| 3644 | status = write16(state, OFDM_SC_RA_RAM_BE_OPT_DELAY__A, 1); |
| 3645 | if (status < 0) |
| 3646 | goto error; |
| 3647 | status = write16(state, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A, 2); |
| 3648 | if (status < 0) |
| 3649 | goto error; |
| 3650 | #endif |
| 3651 | |
| 3652 | /* FEC setup */ |
| 3653 | status = write16(state, FEC_DI_INPUT_CTL__A, 1); /* OFDM input */ |
| 3654 | if (status < 0) |
| 3655 | goto error; |
| 3656 | |
| 3657 | |
| 3658 | #ifdef COMPILE_FOR_NONRT |
| 3659 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x400); |
| 3660 | if (status < 0) |
| 3661 | goto error; |
| 3662 | #else |
| 3663 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x1000); |
| 3664 | if (status < 0) |
| 3665 | goto error; |
| 3666 | #endif |
| 3667 | status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, 0x0001); |
| 3668 | if (status < 0) |
| 3669 | goto error; |
| 3670 | |
| 3671 | /* Setup MPEG bus */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3672 | status = mpegts_dto_setup(state, OM_DVBT); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3673 | if (status < 0) |
| 3674 | goto error; |
| 3675 | /* Set DVBT Presets */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3676 | status = dvbt_activate_presets(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3677 | if (status < 0) |
| 3678 | goto error; |
| 3679 | |
| 3680 | error: |
| 3681 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3682 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3683 | return status; |
| 3684 | } |
| 3685 | |
| 3686 | /*============================================================================*/ |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 3687 | /* |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3688 | * \brief start dvbt demodulating for channel. |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3689 | * \param demod instance of demodulator. |
| 3690 | * \return DRXStatus_t. |
| 3691 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3692 | static int dvbt_start(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3693 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3694 | u16 param1; |
| 3695 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3696 | /* drxk_ofdm_sc_cmd_t scCmd; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3697 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 3698 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3699 | /* start correct processes to get in lock */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3700 | /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3701 | param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3702 | status = dvbt_sc_command(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, |
| 3703 | OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, |
| 3704 | 0, 0, 0); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3705 | if (status < 0) |
| 3706 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3707 | /* start FEC OC */ |
| 3708 | status = mpegts_start(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3709 | if (status < 0) |
| 3710 | goto error; |
| 3711 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); |
| 3712 | if (status < 0) |
| 3713 | goto error; |
| 3714 | error: |
| 3715 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 3716 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3717 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | |
| 3721 | /*============================================================================*/ |
| 3722 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 3723 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3724 | * \brief Set up dvbt demodulator for channel. |
| 3725 | * \param demod instance of demodulator. |
| 3726 | * \return DRXStatus_t. |
| 3727 | * // original DVBTSetChannel() |
| 3728 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3729 | static int set_dvbt(struct drxk_state *state, u16 intermediate_freqk_hz, |
| 3730 | s32 tuner_freq_offset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3731 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3732 | u16 cmd_result = 0; |
| 3733 | u16 transmission_params = 0; |
| 3734 | u16 operation_mode = 0; |
| 3735 | u32 iqm_rc_rate_ofs = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 3736 | u32 bandwidth = 0; |
| 3737 | u16 param1; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3738 | int status; |
| 3739 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3740 | dprintk(1, "IF =%d, TFO = %d\n", |
| 3741 | intermediate_freqk_hz, tuner_freq_offset); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3742 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3743 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM |
| 3744 | | SCU_RAM_COMMAND_CMD_DEMOD_STOP, |
| 3745 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3746 | if (status < 0) |
| 3747 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3748 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3749 | /* Halt SCU to enable safe non-atomic accesses */ |
| 3750 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
| 3751 | if (status < 0) |
| 3752 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3753 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3754 | /* Stop processors */ |
| 3755 | status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); |
| 3756 | if (status < 0) |
| 3757 | goto error; |
| 3758 | status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); |
| 3759 | if (status < 0) |
| 3760 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3761 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3762 | /* Mandatory fix, always stop CP, required to set spl offset back to |
| 3763 | hardware default (is set to 0 by ucode during pilot detection */ |
| 3764 | status = write16(state, OFDM_CP_COMM_EXEC__A, OFDM_CP_COMM_EXEC_STOP); |
| 3765 | if (status < 0) |
| 3766 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3767 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3768 | /*== Write channel settings to device ================================*/ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3769 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3770 | /* mode */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3771 | switch (state->props.transmission_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3772 | case TRANSMISSION_MODE_AUTO: |
| 3773 | default: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3774 | operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M; |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3775 | /* fall through - try first guess DRX_FFTMODE_8K */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3776 | case TRANSMISSION_MODE_8K: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3777 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3778 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3779 | case TRANSMISSION_MODE_2K: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3780 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3781 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3782 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3783 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3784 | /* guard */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3785 | switch (state->props.guard_interval) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3786 | default: |
| 3787 | case GUARD_INTERVAL_AUTO: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3788 | operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M; |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3789 | /* fall through - try first guess DRX_GUARD_1DIV4 */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3790 | case GUARD_INTERVAL_1_4: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3791 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3792 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3793 | case GUARD_INTERVAL_1_32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3794 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3795 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3796 | case GUARD_INTERVAL_1_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3797 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3798 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3799 | case GUARD_INTERVAL_1_8: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3800 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8; |
Mauro Carvalho Chehab | 320ed23 | 2011-07-15 01:14:17 -0300 | [diff] [blame] | 3801 | break; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | /* hierarchy */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3805 | switch (state->props.hierarchy) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3806 | case HIERARCHY_AUTO: |
| 3807 | case HIERARCHY_NONE: |
| 3808 | default: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3809 | operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_HIER__M; |
Mauro Carvalho Chehab | 06eeefe | 2017-05-18 08:13:28 -0300 | [diff] [blame] | 3810 | /* try first guess SC_RA_RAM_OP_PARAM_HIER_NO */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3811 | /* transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */ |
Mauro Carvalho Chehab | 06eeefe | 2017-05-18 08:13:28 -0300 | [diff] [blame] | 3812 | /* fall through */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3813 | case HIERARCHY_1: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3814 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3815 | break; |
| 3816 | case HIERARCHY_2: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3817 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3818 | break; |
| 3819 | case HIERARCHY_4: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3820 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3821 | break; |
| 3822 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3823 | |
| 3824 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3825 | /* modulation */ |
| 3826 | switch (state->props.modulation) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3827 | case QAM_AUTO: |
| 3828 | default: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3829 | operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M; |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3830 | /* fall through - try first guess DRX_CONSTELLATION_QAM64 */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3831 | case QAM_64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3832 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3833 | break; |
| 3834 | case QPSK: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3835 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3836 | break; |
| 3837 | case QAM_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3838 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3839 | break; |
| 3840 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3841 | #if 0 |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 3842 | /* No hierarchical channels support in BDA */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3843 | /* Priority (only for hierarchical channels) */ |
| 3844 | switch (channel->priority) { |
| 3845 | case DRX_PRIORITY_LOW: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3846 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO; |
| 3847 | WR16(dev_addr, OFDM_EC_SB_PRIOR__A, |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3848 | OFDM_EC_SB_PRIOR_LO); |
| 3849 | break; |
| 3850 | case DRX_PRIORITY_HIGH: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3851 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
| 3852 | WR16(dev_addr, OFDM_EC_SB_PRIOR__A, |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3853 | OFDM_EC_SB_PRIOR_HI)); |
| 3854 | break; |
| 3855 | case DRX_PRIORITY_UNKNOWN: /* fall through */ |
| 3856 | default: |
| 3857 | status = -EINVAL; |
| 3858 | goto error; |
| 3859 | } |
| 3860 | #else |
Mauro Carvalho Chehab | 868c9a1 | 2019-02-18 14:28:55 -0500 | [diff] [blame] | 3861 | /* Set Priority high */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3862 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3863 | status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI); |
| 3864 | if (status < 0) |
| 3865 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3866 | #endif |
| 3867 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3868 | /* coderate */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3869 | switch (state->props.code_rate_HP) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3870 | case FEC_AUTO: |
| 3871 | default: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3872 | operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M; |
Mauro Carvalho Chehab | 40e4311 | 2018-08-07 07:59:20 -0400 | [diff] [blame] | 3873 | /* fall through - try first guess DRX_CODERATE_2DIV3 */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3874 | case FEC_2_3: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3875 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3876 | break; |
| 3877 | case FEC_1_2: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3878 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3879 | break; |
| 3880 | case FEC_3_4: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3881 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3882 | break; |
| 3883 | case FEC_5_6: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3884 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3885 | break; |
| 3886 | case FEC_7_8: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3887 | transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3888 | break; |
| 3889 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3890 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3891 | /* |
Mauro Carvalho Chehab | 868c9a1 | 2019-02-18 14:28:55 -0500 | [diff] [blame] | 3892 | * SAW filter selection: normally not necessary, but if wanted |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3893 | * the application can select a SAW filter via the driver by |
| 3894 | * using UIOs |
| 3895 | */ |
| 3896 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3897 | /* First determine real bandwidth (Hz) */ |
| 3898 | /* Also set delay for impulse noise cruncher */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3899 | /* |
| 3900 | * Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is |
| 3901 | * changed by SC for fix for some 8K,1/8 guard but is restored by |
| 3902 | * InitEC and ResetEC functions |
| 3903 | */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3904 | switch (state->props.bandwidth_hz) { |
| 3905 | case 0: |
| 3906 | state->props.bandwidth_hz = 8000000; |
Mauro Carvalho Chehab | 06eeefe | 2017-05-18 08:13:28 -0300 | [diff] [blame] | 3907 | /* fall through */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3908 | case 8000000: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3909 | bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3910 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, |
| 3911 | 3052); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 3912 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3913 | goto error; |
| 3914 | /* cochannel protection for PAL 8 MHz */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3915 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, |
| 3916 | 7); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3917 | if (status < 0) |
| 3918 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3919 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, |
| 3920 | 7); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3921 | if (status < 0) |
| 3922 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3923 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, |
| 3924 | 7); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3925 | if (status < 0) |
| 3926 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3927 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, |
| 3928 | 1); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3929 | if (status < 0) |
| 3930 | goto error; |
| 3931 | break; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3932 | case 7000000: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3933 | bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3934 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, |
| 3935 | 3491); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3936 | if (status < 0) |
| 3937 | goto error; |
| 3938 | /* cochannel protection for PAL 7 MHz */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3939 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, |
| 3940 | 8); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3941 | if (status < 0) |
| 3942 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3943 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, |
| 3944 | 8); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3945 | if (status < 0) |
| 3946 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3947 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, |
| 3948 | 4); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3949 | if (status < 0) |
| 3950 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3951 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, |
| 3952 | 1); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3953 | if (status < 0) |
| 3954 | goto error; |
| 3955 | break; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 3956 | case 6000000: |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3957 | bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3958 | status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, |
| 3959 | 4073); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3960 | if (status < 0) |
| 3961 | goto error; |
| 3962 | /* cochannel protection for NTSC 6 MHz */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3963 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, |
| 3964 | 19); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3965 | if (status < 0) |
| 3966 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3967 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, |
| 3968 | 19); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3969 | if (status < 0) |
| 3970 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3971 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, |
| 3972 | 14); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3973 | if (status < 0) |
| 3974 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3975 | status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, |
| 3976 | 1); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3977 | if (status < 0) |
| 3978 | goto error; |
| 3979 | break; |
| 3980 | default: |
| 3981 | status = -EINVAL; |
| 3982 | goto error; |
| 3983 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 3984 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3985 | if (iqm_rc_rate_ofs == 0) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 3986 | /* Now compute IQM_RC_RATE_OFS |
| 3987 | (((SysFreq/BandWidth)/2)/2) -1) * 2^23) |
| 3988 | => |
| 3989 | ((SysFreq / BandWidth) * (2^21)) - (2^23) |
| 3990 | */ |
| 3991 | /* (SysFreq / BandWidth) * (2^28) */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 3992 | /* |
| 3993 | * assert (MAX(sysClk)/MIN(bandwidth) < 16) |
| 3994 | * => assert(MAX(sysClk) < 16*MIN(bandwidth)) |
| 3995 | * => assert(109714272 > 48000000) = true |
| 3996 | * so Frac 28 can be used |
| 3997 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 3998 | iqm_rc_rate_ofs = Frac28a((u32) |
| 3999 | ((state->m_sys_clock_freq * |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4000 | 1000) / 3), bandwidth); |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4001 | /* (SysFreq / BandWidth) * (2^21), rounding before truncating */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4002 | if ((iqm_rc_rate_ofs & 0x7fL) >= 0x40) |
| 4003 | iqm_rc_rate_ofs += 0x80L; |
| 4004 | iqm_rc_rate_ofs = iqm_rc_rate_ofs >> 7; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4005 | /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4006 | iqm_rc_rate_ofs = iqm_rc_rate_ofs - (1 << 23); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4007 | } |
| 4008 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4009 | iqm_rc_rate_ofs &= |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4010 | ((((u32) IQM_RC_RATE_OFS_HI__M) << |
| 4011 | IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4012 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate_ofs); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4013 | if (status < 0) |
| 4014 | goto error; |
| 4015 | |
| 4016 | /* Bandwidth setting done */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4017 | |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4018 | #if 0 |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4019 | status = dvbt_set_frequency_shift(demod, channel, tuner_offset); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4020 | if (status < 0) |
| 4021 | goto error; |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4022 | #endif |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4023 | status = set_frequency_shifter(state, intermediate_freqk_hz, |
| 4024 | tuner_freq_offset, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4025 | if (status < 0) |
| 4026 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4027 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4028 | /*== start SC, write channel settings to SC ==========================*/ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4029 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4030 | /* Activate SCU to enable SCU commands */ |
| 4031 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
| 4032 | if (status < 0) |
| 4033 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4034 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4035 | /* Enable SC after setting all other parameters */ |
| 4036 | status = write16(state, OFDM_SC_COMM_STATE__A, 0); |
| 4037 | if (status < 0) |
| 4038 | goto error; |
| 4039 | status = write16(state, OFDM_SC_COMM_EXEC__A, 1); |
| 4040 | if (status < 0) |
| 4041 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4042 | |
| 4043 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4044 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM |
| 4045 | | SCU_RAM_COMMAND_CMD_DEMOD_START, |
| 4046 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4047 | if (status < 0) |
| 4048 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4049 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4050 | /* Write SC parameter registers, set all AUTO flags in operation mode */ |
| 4051 | param1 = (OFDM_SC_RA_RAM_OP_AUTO_MODE__M | |
| 4052 | OFDM_SC_RA_RAM_OP_AUTO_GUARD__M | |
| 4053 | OFDM_SC_RA_RAM_OP_AUTO_CONST__M | |
| 4054 | OFDM_SC_RA_RAM_OP_AUTO_HIER__M | |
| 4055 | OFDM_SC_RA_RAM_OP_AUTO_RATE__M); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4056 | status = dvbt_sc_command(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM, |
| 4057 | 0, transmission_params, param1, 0, 0, 0); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4058 | if (status < 0) |
| 4059 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4060 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4061 | if (!state->m_drxk_a3_rom_code) |
| 4062 | status = dvbt_ctrl_set_sqi_speed(state, &state->m_sqi_speed); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4063 | error: |
| 4064 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4065 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4066 | |
| 4067 | return status; |
| 4068 | } |
| 4069 | |
| 4070 | |
| 4071 | /*============================================================================*/ |
| 4072 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4073 | /* |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 4074 | * \brief Retrieve lock status . |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4075 | * \param demod Pointer to demodulator instance. |
| 4076 | * \param lockStat Pointer to lock status structure. |
| 4077 | * \return DRXStatus_t. |
| 4078 | * |
| 4079 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4080 | static int get_dvbt_lock_status(struct drxk_state *state, u32 *p_lock_status) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4081 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4082 | int status; |
| 4083 | const u16 mpeg_lock_mask = (OFDM_SC_RA_RAM_LOCK_MPEG__M | |
| 4084 | OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4085 | const u16 fec_lock_mask = (OFDM_SC_RA_RAM_LOCK_FEC__M); |
| 4086 | const u16 demod_lock_mask = OFDM_SC_RA_RAM_LOCK_DEMOD__M; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4087 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4088 | u16 sc_ra_ram_lock = 0; |
| 4089 | u16 sc_comm_exec = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4090 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4091 | dprintk(1, "\n"); |
| 4092 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4093 | *p_lock_status = NOT_LOCKED; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4094 | /* driver 0.9.0 */ |
| 4095 | /* Check if SC is running */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4096 | status = read16(state, OFDM_SC_COMM_EXEC__A, &sc_comm_exec); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4097 | if (status < 0) |
| 4098 | goto end; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4099 | if (sc_comm_exec == OFDM_SC_COMM_EXEC_STOP) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4100 | goto end; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4101 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4102 | status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &sc_ra_ram_lock); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4103 | if (status < 0) |
| 4104 | goto end; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4105 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4106 | if ((sc_ra_ram_lock & mpeg_lock_mask) == mpeg_lock_mask) |
| 4107 | *p_lock_status = MPEG_LOCK; |
| 4108 | else if ((sc_ra_ram_lock & fec_lock_mask) == fec_lock_mask) |
| 4109 | *p_lock_status = FEC_LOCK; |
| 4110 | else if ((sc_ra_ram_lock & demod_lock_mask) == demod_lock_mask) |
| 4111 | *p_lock_status = DEMOD_LOCK; |
| 4112 | else if (sc_ra_ram_lock & OFDM_SC_RA_RAM_LOCK_NODVBT__M) |
| 4113 | *p_lock_status = NEVER_LOCK; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4114 | end: |
| 4115 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4116 | pr_err("Error %d on %s\n", status, __func__); |
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 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4119 | } |
| 4120 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4121 | static int power_up_qam(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4122 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4123 | enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4124 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4125 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4126 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4127 | status = ctrl_power_mode(state, &power_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4128 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4129 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4130 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4131 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4135 | /* Power Down QAM */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4136 | static int power_down_qam(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4137 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4138 | u16 data = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4139 | u16 cmd_result; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4140 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4141 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4142 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4143 | status = read16(state, SCU_COMM_EXEC__A, &data); |
| 4144 | if (status < 0) |
| 4145 | goto error; |
| 4146 | if (data == SCU_COMM_EXEC_ACTIVE) { |
| 4147 | /* |
| 4148 | STOP demodulator |
| 4149 | QAM and HW blocks |
| 4150 | */ |
| 4151 | /* stop all comstate->m_exec */ |
| 4152 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4153 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4154 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4155 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM |
| 4156 | | SCU_RAM_COMMAND_CMD_DEMOD_STOP, |
| 4157 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 4158 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4159 | goto error; |
| 4160 | } |
| 4161 | /* powerdown AFE */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4162 | status = set_iqm_af(state, false); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4163 | |
| 4164 | error: |
| 4165 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4166 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4167 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4168 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4169 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4170 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4171 | /*============================================================================*/ |
| 4172 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4173 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4174 | * \brief Setup of the QAM Measurement intervals for signal quality |
| 4175 | * \param demod instance of demod. |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 4176 | * \param modulation current modulation. |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4177 | * \return DRXStatus_t. |
| 4178 | * |
| 4179 | * NOTE: |
| 4180 | * Take into account that for certain settings the errorcounters can overflow. |
| 4181 | * The implementation does not check this. |
| 4182 | * |
| 4183 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4184 | static int set_qam_measurement(struct drxk_state *state, |
| 4185 | enum e_drxk_constellation modulation, |
| 4186 | u32 symbol_rate) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4187 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4188 | u32 fec_bits_desired = 0; /* BER accounting period */ |
| 4189 | u32 fec_rs_period_total = 0; /* Total period */ |
| 4190 | u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */ |
| 4191 | u16 fec_rs_period = 0; /* Value for corresponding I2C register */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4192 | int status = 0; |
| 4193 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4194 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4195 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4196 | fec_rs_prescale = 1; |
| 4197 | /* fec_bits_desired = symbol_rate [kHz] * |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4198 | FrameLenght [ms] * |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 4199 | (modulation + 1) * |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4200 | SyncLoss (== 1) * |
| 4201 | ViterbiLoss (==1) |
| 4202 | */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 4203 | switch (modulation) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4204 | case DRX_CONSTELLATION_QAM16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4205 | fec_bits_desired = 4 * symbol_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4206 | break; |
| 4207 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4208 | fec_bits_desired = 5 * symbol_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4209 | break; |
| 4210 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4211 | fec_bits_desired = 6 * symbol_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4212 | break; |
| 4213 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4214 | fec_bits_desired = 7 * symbol_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4215 | break; |
| 4216 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4217 | fec_bits_desired = 8 * symbol_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4218 | break; |
| 4219 | default: |
| 4220 | status = -EINVAL; |
| 4221 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4222 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4223 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4224 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4225 | fec_bits_desired /= 1000; /* symbol_rate [Hz] -> symbol_rate [kHz] */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4226 | fec_bits_desired *= 500; /* meas. period [ms] */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4227 | |
| 4228 | /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4229 | /* fec_rs_period_total = fec_bits_desired / 1632 */ |
| 4230 | fec_rs_period_total = (fec_bits_desired / 1632UL) + 1; /* roughly ceil */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4231 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4232 | /* fec_rs_period_total = fec_rs_prescale * fec_rs_period */ |
| 4233 | fec_rs_prescale = 1 + (u16) (fec_rs_period_total >> 16); |
| 4234 | if (fec_rs_prescale == 0) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4235 | /* Divide by zero (though impossible) */ |
| 4236 | status = -EINVAL; |
| 4237 | if (status < 0) |
| 4238 | goto error; |
| 4239 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4240 | fec_rs_period = |
| 4241 | ((u16) fec_rs_period_total + |
| 4242 | (fec_rs_prescale >> 1)) / fec_rs_prescale; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4243 | |
| 4244 | /* write corresponding registers */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4245 | status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fec_rs_period); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4246 | if (status < 0) |
| 4247 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4248 | status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, |
| 4249 | fec_rs_prescale); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4250 | if (status < 0) |
| 4251 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4252 | status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fec_rs_period); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4253 | error: |
| 4254 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4255 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4256 | return status; |
| 4257 | } |
| 4258 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4259 | static int set_qam16(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4260 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4261 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4262 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4263 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4264 | /* QAM Equalizer Setup */ |
| 4265 | /* Equalizer */ |
| 4266 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13517); |
| 4267 | if (status < 0) |
| 4268 | goto error; |
| 4269 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 13517); |
| 4270 | if (status < 0) |
| 4271 | goto error; |
| 4272 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 13517); |
| 4273 | if (status < 0) |
| 4274 | goto error; |
| 4275 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13517); |
| 4276 | if (status < 0) |
| 4277 | goto error; |
| 4278 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13517); |
| 4279 | if (status < 0) |
| 4280 | goto error; |
| 4281 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 13517); |
| 4282 | if (status < 0) |
| 4283 | goto error; |
| 4284 | /* Decision Feedback Equalizer */ |
| 4285 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 2); |
| 4286 | if (status < 0) |
| 4287 | goto error; |
| 4288 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 2); |
| 4289 | if (status < 0) |
| 4290 | goto error; |
| 4291 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 2); |
| 4292 | if (status < 0) |
| 4293 | goto error; |
| 4294 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 2); |
| 4295 | if (status < 0) |
| 4296 | goto error; |
| 4297 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 2); |
| 4298 | if (status < 0) |
| 4299 | goto error; |
| 4300 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
| 4301 | if (status < 0) |
| 4302 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4303 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4304 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
| 4305 | if (status < 0) |
| 4306 | goto error; |
| 4307 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
| 4308 | if (status < 0) |
| 4309 | goto error; |
| 4310 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
| 4311 | if (status < 0) |
| 4312 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4313 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4314 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4315 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, |
| 4316 | DRXK_QAM_SL_SIG_POWER_QAM16); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4317 | if (status < 0) |
| 4318 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4319 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4320 | /* QAM Loop Controller Coeficients */ |
| 4321 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
| 4322 | if (status < 0) |
| 4323 | goto error; |
| 4324 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
| 4325 | if (status < 0) |
| 4326 | goto error; |
| 4327 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
| 4328 | if (status < 0) |
| 4329 | goto error; |
| 4330 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
| 4331 | if (status < 0) |
| 4332 | goto error; |
| 4333 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
| 4334 | if (status < 0) |
| 4335 | goto error; |
| 4336 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
| 4337 | if (status < 0) |
| 4338 | goto error; |
| 4339 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
| 4340 | if (status < 0) |
| 4341 | goto error; |
| 4342 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
| 4343 | if (status < 0) |
| 4344 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4345 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4346 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
| 4347 | if (status < 0) |
| 4348 | goto error; |
| 4349 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); |
| 4350 | if (status < 0) |
| 4351 | goto error; |
| 4352 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); |
| 4353 | if (status < 0) |
| 4354 | goto error; |
| 4355 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
| 4356 | if (status < 0) |
| 4357 | goto error; |
| 4358 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); |
| 4359 | if (status < 0) |
| 4360 | goto error; |
| 4361 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
| 4362 | if (status < 0) |
| 4363 | goto error; |
| 4364 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
| 4365 | if (status < 0) |
| 4366 | goto error; |
| 4367 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); |
| 4368 | if (status < 0) |
| 4369 | goto error; |
| 4370 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 32); |
| 4371 | if (status < 0) |
| 4372 | goto error; |
| 4373 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
| 4374 | if (status < 0) |
| 4375 | goto error; |
| 4376 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
| 4377 | if (status < 0) |
| 4378 | goto error; |
| 4379 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
| 4380 | if (status < 0) |
| 4381 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4382 | |
| 4383 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4384 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4385 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4386 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 140); |
| 4387 | if (status < 0) |
| 4388 | goto error; |
| 4389 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); |
| 4390 | if (status < 0) |
| 4391 | goto error; |
| 4392 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 95); |
| 4393 | if (status < 0) |
| 4394 | goto error; |
| 4395 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 120); |
| 4396 | if (status < 0) |
| 4397 | goto error; |
| 4398 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 230); |
| 4399 | if (status < 0) |
| 4400 | goto error; |
| 4401 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 105); |
| 4402 | if (status < 0) |
| 4403 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4404 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4405 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
| 4406 | if (status < 0) |
| 4407 | goto error; |
| 4408 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
| 4409 | if (status < 0) |
| 4410 | goto error; |
| 4411 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 24); |
| 4412 | if (status < 0) |
| 4413 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4414 | |
| 4415 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4416 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4417 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4418 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 16); |
| 4419 | if (status < 0) |
| 4420 | goto error; |
| 4421 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 220); |
| 4422 | if (status < 0) |
| 4423 | goto error; |
| 4424 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 25); |
| 4425 | if (status < 0) |
| 4426 | goto error; |
| 4427 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 6); |
| 4428 | if (status < 0) |
| 4429 | goto error; |
| 4430 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -24); |
| 4431 | if (status < 0) |
| 4432 | goto error; |
| 4433 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -65); |
| 4434 | if (status < 0) |
| 4435 | goto error; |
| 4436 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -127); |
| 4437 | if (status < 0) |
| 4438 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4439 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4440 | error: |
| 4441 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4442 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4443 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | /*============================================================================*/ |
| 4447 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4448 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4449 | * \brief QAM32 specific setup |
| 4450 | * \param demod instance of demod. |
| 4451 | * \return DRXStatus_t. |
| 4452 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4453 | static int set_qam32(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4454 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4455 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4456 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4457 | dprintk(1, "\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4458 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4459 | /* QAM Equalizer Setup */ |
| 4460 | /* Equalizer */ |
| 4461 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6707); |
| 4462 | if (status < 0) |
| 4463 | goto error; |
| 4464 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6707); |
| 4465 | if (status < 0) |
| 4466 | goto error; |
| 4467 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6707); |
| 4468 | if (status < 0) |
| 4469 | goto error; |
| 4470 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6707); |
| 4471 | if (status < 0) |
| 4472 | goto error; |
| 4473 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6707); |
| 4474 | if (status < 0) |
| 4475 | goto error; |
| 4476 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 6707); |
| 4477 | if (status < 0) |
| 4478 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4479 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4480 | /* Decision Feedback Equalizer */ |
| 4481 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 3); |
| 4482 | if (status < 0) |
| 4483 | goto error; |
| 4484 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 3); |
| 4485 | if (status < 0) |
| 4486 | goto error; |
| 4487 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 3); |
| 4488 | if (status < 0) |
| 4489 | goto error; |
| 4490 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 3); |
| 4491 | if (status < 0) |
| 4492 | goto error; |
| 4493 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); |
| 4494 | if (status < 0) |
| 4495 | goto error; |
| 4496 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
| 4497 | if (status < 0) |
| 4498 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4499 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4500 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
| 4501 | if (status < 0) |
| 4502 | goto error; |
| 4503 | status = write16(state, QAM_SY_SYNC_AWM__A, 5); |
| 4504 | if (status < 0) |
| 4505 | goto error; |
| 4506 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
| 4507 | if (status < 0) |
| 4508 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4509 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4510 | /* QAM Slicer Settings */ |
| 4511 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4512 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, |
| 4513 | DRXK_QAM_SL_SIG_POWER_QAM32); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4514 | if (status < 0) |
| 4515 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4516 | |
| 4517 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4518 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4519 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4520 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
| 4521 | if (status < 0) |
| 4522 | goto error; |
| 4523 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
| 4524 | if (status < 0) |
| 4525 | goto error; |
| 4526 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
| 4527 | if (status < 0) |
| 4528 | goto error; |
| 4529 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
| 4530 | if (status < 0) |
| 4531 | goto error; |
| 4532 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
| 4533 | if (status < 0) |
| 4534 | goto error; |
| 4535 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
| 4536 | if (status < 0) |
| 4537 | goto error; |
| 4538 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
| 4539 | if (status < 0) |
| 4540 | goto error; |
| 4541 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
| 4542 | if (status < 0) |
| 4543 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4544 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4545 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
| 4546 | if (status < 0) |
| 4547 | goto error; |
| 4548 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); |
| 4549 | if (status < 0) |
| 4550 | goto error; |
| 4551 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); |
| 4552 | if (status < 0) |
| 4553 | goto error; |
| 4554 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
| 4555 | if (status < 0) |
| 4556 | goto error; |
| 4557 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); |
| 4558 | if (status < 0) |
| 4559 | goto error; |
| 4560 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
| 4561 | if (status < 0) |
| 4562 | goto error; |
| 4563 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
| 4564 | if (status < 0) |
| 4565 | goto error; |
| 4566 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); |
| 4567 | if (status < 0) |
| 4568 | goto error; |
| 4569 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 16); |
| 4570 | if (status < 0) |
| 4571 | goto error; |
| 4572 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
| 4573 | if (status < 0) |
| 4574 | goto error; |
| 4575 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
| 4576 | if (status < 0) |
| 4577 | goto error; |
| 4578 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
| 4579 | if (status < 0) |
| 4580 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4581 | |
| 4582 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4583 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4584 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4585 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 90); |
| 4586 | if (status < 0) |
| 4587 | goto error; |
| 4588 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); |
| 4589 | if (status < 0) |
| 4590 | goto error; |
| 4591 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
| 4592 | if (status < 0) |
| 4593 | goto error; |
| 4594 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
| 4595 | if (status < 0) |
| 4596 | goto error; |
| 4597 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 170); |
| 4598 | if (status < 0) |
| 4599 | goto error; |
| 4600 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
| 4601 | if (status < 0) |
| 4602 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4603 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4604 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
| 4605 | if (status < 0) |
| 4606 | goto error; |
| 4607 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
| 4608 | if (status < 0) |
| 4609 | goto error; |
| 4610 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 10); |
| 4611 | if (status < 0) |
| 4612 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4613 | |
| 4614 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4615 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4616 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4617 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); |
| 4618 | if (status < 0) |
| 4619 | goto error; |
| 4620 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 140); |
| 4621 | if (status < 0) |
| 4622 | goto error; |
| 4623 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) -8); |
| 4624 | if (status < 0) |
| 4625 | goto error; |
| 4626 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) -16); |
| 4627 | if (status < 0) |
| 4628 | goto error; |
| 4629 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -26); |
| 4630 | if (status < 0) |
| 4631 | goto error; |
| 4632 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -56); |
| 4633 | if (status < 0) |
| 4634 | goto error; |
| 4635 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86); |
| 4636 | error: |
| 4637 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4638 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4639 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | /*============================================================================*/ |
| 4643 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4644 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4645 | * \brief QAM64 specific setup |
| 4646 | * \param demod instance of demod. |
| 4647 | * \return DRXStatus_t. |
| 4648 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4649 | static int set_qam64(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4650 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4651 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4652 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4653 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4654 | /* QAM Equalizer Setup */ |
| 4655 | /* Equalizer */ |
| 4656 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13336); |
| 4657 | if (status < 0) |
| 4658 | goto error; |
| 4659 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12618); |
| 4660 | if (status < 0) |
| 4661 | goto error; |
| 4662 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 11988); |
| 4663 | if (status < 0) |
| 4664 | goto error; |
| 4665 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13809); |
| 4666 | if (status < 0) |
| 4667 | goto error; |
| 4668 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13809); |
| 4669 | if (status < 0) |
| 4670 | goto error; |
| 4671 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15609); |
| 4672 | if (status < 0) |
| 4673 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4674 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4675 | /* Decision Feedback Equalizer */ |
| 4676 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 4); |
| 4677 | if (status < 0) |
| 4678 | goto error; |
| 4679 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 4); |
| 4680 | if (status < 0) |
| 4681 | goto error; |
| 4682 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 4); |
| 4683 | if (status < 0) |
| 4684 | goto error; |
| 4685 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 4); |
| 4686 | if (status < 0) |
| 4687 | goto error; |
| 4688 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); |
| 4689 | if (status < 0) |
| 4690 | goto error; |
| 4691 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
| 4692 | if (status < 0) |
| 4693 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4694 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4695 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
| 4696 | if (status < 0) |
| 4697 | goto error; |
| 4698 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
| 4699 | if (status < 0) |
| 4700 | goto error; |
| 4701 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
| 4702 | if (status < 0) |
| 4703 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4704 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4705 | /* QAM Slicer Settings */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4706 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, |
| 4707 | DRXK_QAM_SL_SIG_POWER_QAM64); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4708 | if (status < 0) |
| 4709 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4710 | |
| 4711 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4712 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4713 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4714 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
| 4715 | if (status < 0) |
| 4716 | goto error; |
| 4717 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
| 4718 | if (status < 0) |
| 4719 | goto error; |
| 4720 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
| 4721 | if (status < 0) |
| 4722 | goto error; |
| 4723 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
| 4724 | if (status < 0) |
| 4725 | goto error; |
| 4726 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
| 4727 | if (status < 0) |
| 4728 | goto error; |
| 4729 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
| 4730 | if (status < 0) |
| 4731 | goto error; |
| 4732 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
| 4733 | if (status < 0) |
| 4734 | goto error; |
| 4735 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
| 4736 | if (status < 0) |
| 4737 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4738 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4739 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
| 4740 | if (status < 0) |
| 4741 | goto error; |
| 4742 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30); |
| 4743 | if (status < 0) |
| 4744 | goto error; |
| 4745 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 100); |
| 4746 | if (status < 0) |
| 4747 | goto error; |
| 4748 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
| 4749 | if (status < 0) |
| 4750 | goto error; |
| 4751 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 30); |
| 4752 | if (status < 0) |
| 4753 | goto error; |
| 4754 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); |
| 4755 | if (status < 0) |
| 4756 | goto error; |
| 4757 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
| 4758 | if (status < 0) |
| 4759 | goto error; |
| 4760 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
| 4761 | if (status < 0) |
| 4762 | goto error; |
| 4763 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); |
| 4764 | if (status < 0) |
| 4765 | goto error; |
| 4766 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
| 4767 | if (status < 0) |
| 4768 | goto error; |
| 4769 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
| 4770 | if (status < 0) |
| 4771 | goto error; |
| 4772 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
| 4773 | if (status < 0) |
| 4774 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4775 | |
| 4776 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4777 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4778 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4779 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 100); |
| 4780 | if (status < 0) |
| 4781 | goto error; |
| 4782 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
| 4783 | if (status < 0) |
| 4784 | goto error; |
| 4785 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
| 4786 | if (status < 0) |
| 4787 | goto error; |
| 4788 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 110); |
| 4789 | if (status < 0) |
| 4790 | goto error; |
| 4791 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 200); |
| 4792 | if (status < 0) |
| 4793 | goto error; |
| 4794 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 95); |
| 4795 | if (status < 0) |
| 4796 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4797 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4798 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
| 4799 | if (status < 0) |
| 4800 | goto error; |
| 4801 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
| 4802 | if (status < 0) |
| 4803 | goto error; |
| 4804 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 15); |
| 4805 | if (status < 0) |
| 4806 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4807 | |
| 4808 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4809 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4810 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4811 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); |
| 4812 | if (status < 0) |
| 4813 | goto error; |
| 4814 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 141); |
| 4815 | if (status < 0) |
| 4816 | goto error; |
| 4817 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 7); |
| 4818 | if (status < 0) |
| 4819 | goto error; |
| 4820 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 0); |
| 4821 | if (status < 0) |
| 4822 | goto error; |
| 4823 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -15); |
| 4824 | if (status < 0) |
| 4825 | goto error; |
| 4826 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -45); |
| 4827 | if (status < 0) |
| 4828 | goto error; |
| 4829 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80); |
| 4830 | error: |
| 4831 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 4832 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4833 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4834 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | /*============================================================================*/ |
| 4838 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 4839 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4840 | * \brief QAM128 specific setup |
| 4841 | * \param demod: instance of demod. |
| 4842 | * \return DRXStatus_t. |
| 4843 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 4844 | static int set_qam128(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4845 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4846 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4847 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 4848 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4849 | /* QAM Equalizer Setup */ |
| 4850 | /* Equalizer */ |
| 4851 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6564); |
| 4852 | if (status < 0) |
| 4853 | goto error; |
| 4854 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6598); |
| 4855 | if (status < 0) |
| 4856 | goto error; |
| 4857 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6394); |
| 4858 | if (status < 0) |
| 4859 | goto error; |
| 4860 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6409); |
| 4861 | if (status < 0) |
| 4862 | goto error; |
| 4863 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6656); |
| 4864 | if (status < 0) |
| 4865 | goto error; |
| 4866 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 7238); |
| 4867 | if (status < 0) |
| 4868 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4869 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4870 | /* Decision Feedback Equalizer */ |
| 4871 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 6); |
| 4872 | if (status < 0) |
| 4873 | goto error; |
| 4874 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 6); |
| 4875 | if (status < 0) |
| 4876 | goto error; |
| 4877 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 6); |
| 4878 | if (status < 0) |
| 4879 | goto error; |
| 4880 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 6); |
| 4881 | if (status < 0) |
| 4882 | goto error; |
| 4883 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 5); |
| 4884 | if (status < 0) |
| 4885 | goto error; |
| 4886 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
| 4887 | if (status < 0) |
| 4888 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 4889 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4890 | status = write16(state, QAM_SY_SYNC_HWM__A, 6); |
| 4891 | if (status < 0) |
| 4892 | goto error; |
| 4893 | status = write16(state, QAM_SY_SYNC_AWM__A, 5); |
| 4894 | if (status < 0) |
| 4895 | goto error; |
| 4896 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
| 4897 | if (status < 0) |
| 4898 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4899 | |
| 4900 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4901 | /* QAM Slicer Settings */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4902 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 4903 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, |
| 4904 | DRXK_QAM_SL_SIG_POWER_QAM128); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4905 | if (status < 0) |
| 4906 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4907 | |
| 4908 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4909 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4910 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4911 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
| 4912 | if (status < 0) |
| 4913 | goto error; |
| 4914 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
| 4915 | if (status < 0) |
| 4916 | goto error; |
| 4917 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
| 4918 | if (status < 0) |
| 4919 | goto error; |
| 4920 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
| 4921 | if (status < 0) |
| 4922 | goto error; |
| 4923 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
| 4924 | if (status < 0) |
| 4925 | goto error; |
| 4926 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
| 4927 | if (status < 0) |
| 4928 | goto error; |
| 4929 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
| 4930 | if (status < 0) |
| 4931 | goto error; |
| 4932 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
| 4933 | if (status < 0) |
| 4934 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4935 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4936 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
| 4937 | if (status < 0) |
| 4938 | goto error; |
| 4939 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40); |
| 4940 | if (status < 0) |
| 4941 | goto error; |
| 4942 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 120); |
| 4943 | if (status < 0) |
| 4944 | goto error; |
| 4945 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
| 4946 | if (status < 0) |
| 4947 | goto error; |
| 4948 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 40); |
| 4949 | if (status < 0) |
| 4950 | goto error; |
| 4951 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 60); |
| 4952 | if (status < 0) |
| 4953 | goto error; |
| 4954 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
| 4955 | if (status < 0) |
| 4956 | goto error; |
| 4957 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
| 4958 | if (status < 0) |
| 4959 | goto error; |
| 4960 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 64); |
| 4961 | if (status < 0) |
| 4962 | goto error; |
| 4963 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
| 4964 | if (status < 0) |
| 4965 | goto error; |
| 4966 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
| 4967 | if (status < 0) |
| 4968 | goto error; |
| 4969 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); |
| 4970 | if (status < 0) |
| 4971 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4972 | |
| 4973 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4974 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4975 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4976 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
| 4977 | if (status < 0) |
| 4978 | goto error; |
| 4979 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
| 4980 | if (status < 0) |
| 4981 | goto error; |
| 4982 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
| 4983 | if (status < 0) |
| 4984 | goto error; |
| 4985 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
| 4986 | if (status < 0) |
| 4987 | goto error; |
| 4988 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 140); |
| 4989 | if (status < 0) |
| 4990 | goto error; |
| 4991 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); |
| 4992 | if (status < 0) |
| 4993 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 4994 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 4995 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
| 4996 | if (status < 0) |
| 4997 | goto error; |
| 4998 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 5); |
| 4999 | if (status < 0) |
| 5000 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5001 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5002 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
| 5003 | if (status < 0) |
| 5004 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5005 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5006 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5007 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5008 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); |
| 5009 | if (status < 0) |
| 5010 | goto error; |
| 5011 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 65); |
| 5012 | if (status < 0) |
| 5013 | goto error; |
| 5014 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 5); |
| 5015 | if (status < 0) |
| 5016 | goto error; |
| 5017 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 3); |
| 5018 | if (status < 0) |
| 5019 | goto error; |
| 5020 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -1); |
| 5021 | if (status < 0) |
| 5022 | goto error; |
| 5023 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -12); |
| 5024 | if (status < 0) |
| 5025 | goto error; |
| 5026 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23); |
| 5027 | error: |
| 5028 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5029 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5030 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5031 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | /*============================================================================*/ |
| 5035 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 5036 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5037 | * \brief QAM256 specific setup |
| 5038 | * \param demod: instance of demod. |
| 5039 | * \return DRXStatus_t. |
| 5040 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5041 | static int set_qam256(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5042 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5043 | int status = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5044 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5045 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5046 | /* QAM Equalizer Setup */ |
| 5047 | /* Equalizer */ |
| 5048 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 11502); |
| 5049 | if (status < 0) |
| 5050 | goto error; |
| 5051 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12084); |
| 5052 | if (status < 0) |
| 5053 | goto error; |
| 5054 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 12543); |
| 5055 | if (status < 0) |
| 5056 | goto error; |
| 5057 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 12931); |
| 5058 | if (status < 0) |
| 5059 | goto error; |
| 5060 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13629); |
| 5061 | if (status < 0) |
| 5062 | goto error; |
| 5063 | status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15385); |
| 5064 | if (status < 0) |
| 5065 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5066 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5067 | /* Decision Feedback Equalizer */ |
| 5068 | status = write16(state, QAM_DQ_QUAL_FUN0__A, 8); |
| 5069 | if (status < 0) |
| 5070 | goto error; |
| 5071 | status = write16(state, QAM_DQ_QUAL_FUN1__A, 8); |
| 5072 | if (status < 0) |
| 5073 | goto error; |
| 5074 | status = write16(state, QAM_DQ_QUAL_FUN2__A, 8); |
| 5075 | if (status < 0) |
| 5076 | goto error; |
| 5077 | status = write16(state, QAM_DQ_QUAL_FUN3__A, 8); |
| 5078 | if (status < 0) |
| 5079 | goto error; |
| 5080 | status = write16(state, QAM_DQ_QUAL_FUN4__A, 6); |
| 5081 | if (status < 0) |
| 5082 | goto error; |
| 5083 | status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); |
| 5084 | if (status < 0) |
| 5085 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5086 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5087 | status = write16(state, QAM_SY_SYNC_HWM__A, 5); |
| 5088 | if (status < 0) |
| 5089 | goto error; |
| 5090 | status = write16(state, QAM_SY_SYNC_AWM__A, 4); |
| 5091 | if (status < 0) |
| 5092 | goto error; |
| 5093 | status = write16(state, QAM_SY_SYNC_LWM__A, 3); |
| 5094 | if (status < 0) |
| 5095 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5096 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5097 | /* QAM Slicer Settings */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5098 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5099 | status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, |
| 5100 | DRXK_QAM_SL_SIG_POWER_QAM256); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5101 | if (status < 0) |
| 5102 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5103 | |
| 5104 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5105 | /* QAM Loop Controller Coeficients */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5106 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5107 | status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); |
| 5108 | if (status < 0) |
| 5109 | goto error; |
| 5110 | status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); |
| 5111 | if (status < 0) |
| 5112 | goto error; |
| 5113 | status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); |
| 5114 | if (status < 0) |
| 5115 | goto error; |
| 5116 | status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); |
| 5117 | if (status < 0) |
| 5118 | goto error; |
| 5119 | status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); |
| 5120 | if (status < 0) |
| 5121 | goto error; |
| 5122 | status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); |
| 5123 | if (status < 0) |
| 5124 | goto error; |
| 5125 | status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); |
| 5126 | if (status < 0) |
| 5127 | goto error; |
| 5128 | status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); |
| 5129 | if (status < 0) |
| 5130 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5131 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5132 | status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); |
| 5133 | if (status < 0) |
| 5134 | goto error; |
| 5135 | status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50); |
| 5136 | if (status < 0) |
| 5137 | goto error; |
| 5138 | status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 250); |
| 5139 | if (status < 0) |
| 5140 | goto error; |
| 5141 | status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); |
| 5142 | if (status < 0) |
| 5143 | goto error; |
| 5144 | status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 50); |
| 5145 | if (status < 0) |
| 5146 | goto error; |
| 5147 | status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 125); |
| 5148 | if (status < 0) |
| 5149 | goto error; |
| 5150 | status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); |
| 5151 | if (status < 0) |
| 5152 | goto error; |
| 5153 | status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); |
| 5154 | if (status < 0) |
| 5155 | goto error; |
| 5156 | status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); |
| 5157 | if (status < 0) |
| 5158 | goto error; |
| 5159 | status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); |
| 5160 | if (status < 0) |
| 5161 | goto error; |
| 5162 | status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); |
| 5163 | if (status < 0) |
| 5164 | goto error; |
| 5165 | status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); |
| 5166 | if (status < 0) |
| 5167 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5168 | |
| 5169 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5170 | /* QAM State Machine (FSM) Thresholds */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5171 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5172 | status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); |
| 5173 | if (status < 0) |
| 5174 | goto error; |
| 5175 | status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); |
| 5176 | if (status < 0) |
| 5177 | goto error; |
| 5178 | status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); |
| 5179 | if (status < 0) |
| 5180 | goto error; |
| 5181 | status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); |
| 5182 | if (status < 0) |
| 5183 | goto error; |
| 5184 | status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 150); |
| 5185 | if (status < 0) |
| 5186 | goto error; |
| 5187 | status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 110); |
| 5188 | if (status < 0) |
| 5189 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5190 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5191 | status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); |
| 5192 | if (status < 0) |
| 5193 | goto error; |
| 5194 | status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); |
| 5195 | if (status < 0) |
| 5196 | goto error; |
| 5197 | status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); |
| 5198 | if (status < 0) |
| 5199 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5200 | |
| 5201 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5202 | /* QAM FSM Tracking Parameters */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5203 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5204 | status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); |
| 5205 | if (status < 0) |
| 5206 | goto error; |
| 5207 | status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 74); |
| 5208 | if (status < 0) |
| 5209 | goto error; |
| 5210 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 18); |
| 5211 | if (status < 0) |
| 5212 | goto error; |
| 5213 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 13); |
| 5214 | if (status < 0) |
| 5215 | goto error; |
| 5216 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) 7); |
| 5217 | if (status < 0) |
| 5218 | goto error; |
| 5219 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) 0); |
| 5220 | if (status < 0) |
| 5221 | goto error; |
| 5222 | status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8); |
| 5223 | error: |
| 5224 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5225 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5226 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | |
| 5230 | /*============================================================================*/ |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 5231 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5232 | * \brief Reset QAM block. |
| 5233 | * \param demod: instance of demod. |
| 5234 | * \param channel: pointer to channel data. |
| 5235 | * \return DRXStatus_t. |
| 5236 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5237 | static int qam_reset_qam(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5238 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5239 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5240 | u16 cmd_result; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5241 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5242 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5243 | /* Stop QAM comstate->m_exec */ |
| 5244 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); |
| 5245 | if (status < 0) |
| 5246 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5247 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5248 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM |
| 5249 | | SCU_RAM_COMMAND_CMD_DEMOD_RESET, |
| 5250 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5251 | error: |
| 5252 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5253 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5254 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | /*============================================================================*/ |
| 5258 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 5259 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5260 | * \brief Set QAM symbolrate. |
| 5261 | * \param demod: instance of demod. |
| 5262 | * \param channel: pointer to channel data. |
| 5263 | * \return DRXStatus_t. |
| 5264 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5265 | static int qam_set_symbolrate(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5266 | { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5267 | u32 adc_frequency = 0; |
| 5268 | u32 symb_freq = 0; |
| 5269 | u32 iqm_rc_rate = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5270 | u16 ratesel = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5271 | u32 lc_symb_rate = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5272 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5273 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5274 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5275 | /* Select & calculate correct IQM rate */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5276 | adc_frequency = (state->m_sys_clock_freq * 1000) / 3; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5277 | ratesel = 0; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5278 | if (state->props.symbol_rate <= 1188750) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5279 | ratesel = 3; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5280 | else if (state->props.symbol_rate <= 2377500) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5281 | ratesel = 2; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5282 | else if (state->props.symbol_rate <= 4755000) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5283 | ratesel = 1; |
| 5284 | status = write16(state, IQM_FD_RATESEL__A, ratesel); |
| 5285 | if (status < 0) |
| 5286 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5287 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5288 | /* |
| 5289 | IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23) |
| 5290 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5291 | symb_freq = state->props.symbol_rate * (1 << ratesel); |
| 5292 | if (symb_freq == 0) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5293 | /* Divide by zero */ |
| 5294 | status = -EINVAL; |
| 5295 | goto error; |
| 5296 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5297 | iqm_rc_rate = (adc_frequency / symb_freq) * (1 << 21) + |
| 5298 | (Frac28a((adc_frequency % symb_freq), symb_freq) >> 7) - |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5299 | (1 << 23); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5300 | status = write32(state, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5301 | if (status < 0) |
| 5302 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5303 | state->m_iqm_rc_rate = iqm_rc_rate; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5304 | /* |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5305 | LcSymbFreq = round (.125 * symbolrate / adc_freq * (1<<15)) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5306 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5307 | symb_freq = state->props.symbol_rate; |
| 5308 | if (adc_frequency == 0) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5309 | /* Divide by zero */ |
| 5310 | status = -EINVAL; |
| 5311 | goto error; |
| 5312 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5313 | lc_symb_rate = (symb_freq / adc_frequency) * (1 << 12) + |
| 5314 | (Frac28a((symb_freq % adc_frequency), adc_frequency) >> |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5315 | 16); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5316 | if (lc_symb_rate > 511) |
| 5317 | lc_symb_rate = 511; |
| 5318 | status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lc_symb_rate); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5319 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5320 | error: |
| 5321 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5322 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5323 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | /*============================================================================*/ |
| 5327 | |
Mauro Carvalho Chehab | 34eb975 | 2017-11-27 10:10:28 -0500 | [diff] [blame] | 5328 | /* |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5329 | * \brief Get QAM lock status. |
| 5330 | * \param demod: instance of demod. |
| 5331 | * \param channel: pointer to channel data. |
| 5332 | * \return DRXStatus_t. |
| 5333 | */ |
| 5334 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5335 | static int get_qam_lock_status(struct drxk_state *state, u32 *p_lock_status) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5336 | { |
| 5337 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5338 | u16 result[2] = { 0, 0 }; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5339 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5340 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5341 | *p_lock_status = NOT_LOCKED; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5342 | status = scu_command(state, |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5343 | SCU_RAM_COMMAND_STANDARD_QAM | |
| 5344 | SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5345 | result); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5346 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5347 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5348 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5349 | if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5350 | /* 0x0000 NOT LOCKED */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5351 | } else if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5352 | /* 0x4000 DEMOD LOCKED */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5353 | *p_lock_status = DEMOD_LOCK; |
| 5354 | } else if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK) { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5355 | /* 0x8000 DEMOD + FEC LOCKED (system lock) */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5356 | *p_lock_status = MPEG_LOCK; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5357 | } else { |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5358 | /* 0xC000 NEVER LOCKED */ |
| 5359 | /* (system will never be able to lock to the signal) */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5360 | /* |
| 5361 | * TODO: check this, intermediate & standard specific lock |
| 5362 | * states are not taken into account here |
| 5363 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5364 | *p_lock_status = NEVER_LOCK; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5365 | } |
| 5366 | return status; |
| 5367 | } |
| 5368 | |
| 5369 | #define QAM_MIRROR__M 0x03 |
| 5370 | #define QAM_MIRROR_NORMAL 0x00 |
| 5371 | #define QAM_MIRRORED 0x01 |
| 5372 | #define QAM_MIRROR_AUTO_ON 0x02 |
| 5373 | #define QAM_LOCKRANGE__M 0x10 |
| 5374 | #define QAM_LOCKRANGE_NORMAL 0x10 |
| 5375 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5376 | static int qam_demodulator_command(struct drxk_state *state, |
| 5377 | int number_of_parameters) |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5378 | { |
| 5379 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5380 | u16 cmd_result; |
| 5381 | u16 set_param_parameters[4] = { 0, 0, 0, 0 }; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5382 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5383 | set_param_parameters[0] = state->m_constellation; /* modulation */ |
| 5384 | set_param_parameters[1] = DRXK_QAM_I12_J17; /* interleave mode */ |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5385 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5386 | if (number_of_parameters == 2) { |
| 5387 | u16 set_env_parameters[1] = { 0 }; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5388 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5389 | if (state->m_operation_mode == OM_QAM_ITU_C) |
| 5390 | set_env_parameters[0] = QAM_TOP_ANNEX_C; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5391 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5392 | set_env_parameters[0] = QAM_TOP_ANNEX_A; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5393 | |
| 5394 | status = scu_command(state, |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5395 | SCU_RAM_COMMAND_STANDARD_QAM |
| 5396 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5397 | 1, set_env_parameters, 1, &cmd_result); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5398 | if (status < 0) |
| 5399 | goto error; |
| 5400 | |
| 5401 | status = scu_command(state, |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5402 | SCU_RAM_COMMAND_STANDARD_QAM |
| 5403 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5404 | number_of_parameters, set_param_parameters, |
| 5405 | 1, &cmd_result); |
| 5406 | } else if (number_of_parameters == 4) { |
| 5407 | if (state->m_operation_mode == OM_QAM_ITU_C) |
| 5408 | set_param_parameters[2] = QAM_TOP_ANNEX_C; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5409 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5410 | set_param_parameters[2] = QAM_TOP_ANNEX_A; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5411 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5412 | set_param_parameters[3] |= (QAM_MIRROR_AUTO_ON); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5413 | /* Env parameters */ |
Mauro Carvalho Chehab | 868c9a1 | 2019-02-18 14:28:55 -0500 | [diff] [blame] | 5414 | /* check for LOCKRANGE Extended */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5415 | /* set_param_parameters[3] |= QAM_LOCKRANGE_NORMAL; */ |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5416 | |
| 5417 | status = scu_command(state, |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5418 | SCU_RAM_COMMAND_STANDARD_QAM |
| 5419 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5420 | number_of_parameters, set_param_parameters, |
| 5421 | 1, &cmd_result); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5422 | } else { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5423 | pr_warn("Unknown QAM demodulator parameter count %d\n", |
| 5424 | number_of_parameters); |
Mauro Carvalho Chehab | 94af1b6 | 2012-10-29 07:58:59 -0200 | [diff] [blame] | 5425 | status = -EINVAL; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | error: |
| 5429 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5430 | pr_warn("Warning %d on %s\n", status, __func__); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5431 | return status; |
| 5432 | } |
| 5433 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5434 | static int set_qam(struct drxk_state *state, u16 intermediate_freqk_hz, |
| 5435 | s32 tuner_freq_offset) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5436 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5437 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5438 | u16 cmd_result; |
| 5439 | int qam_demod_param_count = state->qam_demod_parameter_count; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5440 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5441 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5442 | /* |
Mauro Carvalho Chehab | 119faf9 | 2011-07-24 09:11:36 -0300 | [diff] [blame] | 5443 | * STEP 1: reset demodulator |
| 5444 | * resets FEC DI and FEC RS |
| 5445 | * resets QAM block |
| 5446 | * resets SCU variables |
| 5447 | */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5448 | status = write16(state, FEC_DI_COMM_EXEC__A, FEC_DI_COMM_EXEC_STOP); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5449 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5450 | goto error; |
| 5451 | status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP); |
| 5452 | if (status < 0) |
| 5453 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5454 | status = qam_reset_qam(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5455 | if (status < 0) |
| 5456 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5457 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5458 | /* |
Mauro Carvalho Chehab | 119faf9 | 2011-07-24 09:11:36 -0300 | [diff] [blame] | 5459 | * STEP 2: configure demodulator |
| 5460 | * -set params; resets IQM,QAM,FEC HW; initializes some |
| 5461 | * SCU variables |
| 5462 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5463 | status = qam_set_symbolrate(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5464 | if (status < 0) |
| 5465 | goto error; |
| 5466 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5467 | /* Set params */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5468 | switch (state->props.modulation) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5469 | case QAM_256: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5470 | state->m_constellation = DRX_CONSTELLATION_QAM256; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5471 | break; |
| 5472 | case QAM_AUTO: |
| 5473 | case QAM_64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5474 | state->m_constellation = DRX_CONSTELLATION_QAM64; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5475 | break; |
| 5476 | case QAM_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5477 | state->m_constellation = DRX_CONSTELLATION_QAM16; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5478 | break; |
| 5479 | case QAM_32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5480 | state->m_constellation = DRX_CONSTELLATION_QAM32; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5481 | break; |
| 5482 | case QAM_128: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5483 | state->m_constellation = DRX_CONSTELLATION_QAM128; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5484 | break; |
| 5485 | default: |
| 5486 | status = -EINVAL; |
| 5487 | break; |
| 5488 | } |
| 5489 | if (status < 0) |
| 5490 | goto error; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5491 | |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5492 | /* Use the 4-parameter if it's requested or we're probing for |
| 5493 | * the correct command. */ |
| 5494 | if (state->qam_demod_parameter_count == 4 |
| 5495 | || !state->qam_demod_parameter_count) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5496 | qam_demod_param_count = 4; |
| 5497 | status = qam_demodulator_command(state, qam_demod_param_count); |
Mauro Carvalho Chehab | 5eee2bb | 2011-07-10 14:33:29 -0300 | [diff] [blame] | 5498 | } |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5499 | |
| 5500 | /* Use the 2-parameter command if it was requested or if we're |
| 5501 | * probing for the correct command and the 4-parameter command |
| 5502 | * failed. */ |
| 5503 | if (state->qam_demod_parameter_count == 2 |
| 5504 | || (!state->qam_demod_parameter_count && status < 0)) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5505 | qam_demod_param_count = 2; |
| 5506 | status = qam_demodulator_command(state, qam_demod_param_count); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | if (status < 0) { |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 5510 | dprintk(1, "Could not set demodulator parameters.\n"); |
| 5511 | dprintk(1, |
| 5512 | "Make sure qam_demod_parameter_count (%d) is correct for your firmware (%s).\n", |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5513 | state->qam_demod_parameter_count, |
| 5514 | state->microcode_name); |
Mauro Carvalho Chehab | 5eee2bb | 2011-07-10 14:33:29 -0300 | [diff] [blame] | 5515 | goto error; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5516 | } else if (!state->qam_demod_parameter_count) { |
Mauro Carvalho Chehab | 0fb220f | 2013-04-28 11:47:46 -0300 | [diff] [blame] | 5517 | dprintk(1, |
| 5518 | "Auto-probing the QAM command parameters was successful - using %d parameters.\n", |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5519 | qam_demod_param_count); |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5520 | |
Mauro Carvalho Chehab | 7eaf718 | 2012-07-06 14:53:51 -0300 | [diff] [blame] | 5521 | /* |
| 5522 | * One of our commands was successful. We don't need to |
| 5523 | * auto-probe anymore, now that we got the correct command. |
| 5524 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5525 | state->qam_demod_parameter_count = qam_demod_param_count; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 5526 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5527 | |
Mauro Carvalho Chehab | 119faf9 | 2011-07-24 09:11:36 -0300 | [diff] [blame] | 5528 | /* |
| 5529 | * STEP 3: enable the system in a mode where the ADC provides valid |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5530 | * signal setup modulation independent registers |
Mauro Carvalho Chehab | 119faf9 | 2011-07-24 09:11:36 -0300 | [diff] [blame] | 5531 | */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5532 | #if 0 |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5533 | status = set_frequency(channel, tuner_freq_offset)); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5534 | if (status < 0) |
| 5535 | goto error; |
| 5536 | #endif |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5537 | status = set_frequency_shifter(state, intermediate_freqk_hz, |
| 5538 | tuner_freq_offset, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5539 | if (status < 0) |
| 5540 | goto error; |
| 5541 | |
| 5542 | /* Setup BER measurement */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5543 | status = set_qam_measurement(state, state->m_constellation, |
| 5544 | state->props.symbol_rate); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5545 | if (status < 0) |
| 5546 | goto error; |
| 5547 | |
| 5548 | /* Reset default values */ |
| 5549 | status = write16(state, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE); |
| 5550 | if (status < 0) |
| 5551 | goto error; |
| 5552 | status = write16(state, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE); |
| 5553 | if (status < 0) |
| 5554 | goto error; |
| 5555 | |
| 5556 | /* Reset default LC values */ |
| 5557 | status = write16(state, QAM_LC_RATE_LIMIT__A, 3); |
| 5558 | if (status < 0) |
| 5559 | goto error; |
| 5560 | status = write16(state, QAM_LC_LPF_FACTORP__A, 4); |
| 5561 | if (status < 0) |
| 5562 | goto error; |
| 5563 | status = write16(state, QAM_LC_LPF_FACTORI__A, 4); |
| 5564 | if (status < 0) |
| 5565 | goto error; |
| 5566 | status = write16(state, QAM_LC_MODE__A, 7); |
| 5567 | if (status < 0) |
| 5568 | goto error; |
| 5569 | |
| 5570 | status = write16(state, QAM_LC_QUAL_TAB0__A, 1); |
| 5571 | if (status < 0) |
| 5572 | goto error; |
| 5573 | status = write16(state, QAM_LC_QUAL_TAB1__A, 1); |
| 5574 | if (status < 0) |
| 5575 | goto error; |
| 5576 | status = write16(state, QAM_LC_QUAL_TAB2__A, 1); |
| 5577 | if (status < 0) |
| 5578 | goto error; |
| 5579 | status = write16(state, QAM_LC_QUAL_TAB3__A, 1); |
| 5580 | if (status < 0) |
| 5581 | goto error; |
| 5582 | status = write16(state, QAM_LC_QUAL_TAB4__A, 2); |
| 5583 | if (status < 0) |
| 5584 | goto error; |
| 5585 | status = write16(state, QAM_LC_QUAL_TAB5__A, 2); |
| 5586 | if (status < 0) |
| 5587 | goto error; |
| 5588 | status = write16(state, QAM_LC_QUAL_TAB6__A, 2); |
| 5589 | if (status < 0) |
| 5590 | goto error; |
| 5591 | status = write16(state, QAM_LC_QUAL_TAB8__A, 2); |
| 5592 | if (status < 0) |
| 5593 | goto error; |
| 5594 | status = write16(state, QAM_LC_QUAL_TAB9__A, 2); |
| 5595 | if (status < 0) |
| 5596 | goto error; |
| 5597 | status = write16(state, QAM_LC_QUAL_TAB10__A, 2); |
| 5598 | if (status < 0) |
| 5599 | goto error; |
| 5600 | status = write16(state, QAM_LC_QUAL_TAB12__A, 2); |
| 5601 | if (status < 0) |
| 5602 | goto error; |
| 5603 | status = write16(state, QAM_LC_QUAL_TAB15__A, 3); |
| 5604 | if (status < 0) |
| 5605 | goto error; |
| 5606 | status = write16(state, QAM_LC_QUAL_TAB16__A, 3); |
| 5607 | if (status < 0) |
| 5608 | goto error; |
| 5609 | status = write16(state, QAM_LC_QUAL_TAB20__A, 4); |
| 5610 | if (status < 0) |
| 5611 | goto error; |
| 5612 | status = write16(state, QAM_LC_QUAL_TAB25__A, 4); |
| 5613 | if (status < 0) |
| 5614 | goto error; |
| 5615 | |
| 5616 | /* Mirroring, QAM-block starting point not inverted */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5617 | status = write16(state, QAM_SY_SP_INV__A, |
| 5618 | QAM_SY_SP_INV_SPECTRUM_INV_DIS); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5619 | if (status < 0) |
| 5620 | goto error; |
| 5621 | |
| 5622 | /* Halt SCU to enable safe non-atomic accesses */ |
| 5623 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
| 5624 | if (status < 0) |
| 5625 | goto error; |
| 5626 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5627 | /* STEP 4: modulation specific setup */ |
| 5628 | switch (state->props.modulation) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5629 | case QAM_16: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5630 | status = set_qam16(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5631 | break; |
| 5632 | case QAM_32: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5633 | status = set_qam32(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5634 | break; |
| 5635 | case QAM_AUTO: |
| 5636 | case QAM_64: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5637 | status = set_qam64(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5638 | break; |
| 5639 | case QAM_128: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5640 | status = set_qam128(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5641 | break; |
| 5642 | case QAM_256: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5643 | status = set_qam256(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5644 | break; |
| 5645 | default: |
| 5646 | status = -EINVAL; |
| 5647 | break; |
| 5648 | } |
| 5649 | if (status < 0) |
| 5650 | goto error; |
| 5651 | |
| 5652 | /* Activate SCU to enable SCU commands */ |
| 5653 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
| 5654 | if (status < 0) |
| 5655 | goto error; |
| 5656 | |
| 5657 | /* Re-configure MPEG output, requires knowledge of channel bitrate */ |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 5658 | /* extAttr->currentChannel.modulation = channel->modulation; */ |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5659 | /* extAttr->currentChannel.symbolrate = channel->symbolrate; */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5660 | status = mpegts_dto_setup(state, state->m_operation_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5661 | if (status < 0) |
| 5662 | goto error; |
| 5663 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5664 | /* start processes */ |
| 5665 | status = mpegts_start(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5666 | if (status < 0) |
| 5667 | goto error; |
| 5668 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); |
| 5669 | if (status < 0) |
| 5670 | goto error; |
| 5671 | status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE); |
| 5672 | if (status < 0) |
| 5673 | goto error; |
| 5674 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); |
| 5675 | if (status < 0) |
| 5676 | goto error; |
| 5677 | |
| 5678 | /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5679 | status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM |
| 5680 | | SCU_RAM_COMMAND_CMD_DEMOD_START, |
| 5681 | 0, NULL, 1, &cmd_result); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5682 | if (status < 0) |
| 5683 | goto error; |
| 5684 | |
| 5685 | /* update global DRXK data container */ |
| 5686 | /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */ |
| 5687 | |
| 5688 | error: |
| 5689 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5690 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5691 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5692 | } |
| 5693 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5694 | static int set_qam_standard(struct drxk_state *state, |
| 5695 | enum operation_mode o_mode) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5696 | { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5697 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5698 | #ifdef DRXK_QAM_TAPS |
| 5699 | #define DRXK_QAMA_TAPS_SELECT |
| 5700 | #include "drxk_filters.h" |
| 5701 | #undef DRXK_QAMA_TAPS_SELECT |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5702 | #endif |
| 5703 | |
Mauro Carvalho Chehab | f1b8297 | 2011-07-10 13:08:44 -0300 | [diff] [blame] | 5704 | dprintk(1, "\n"); |
| 5705 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5706 | /* added antenna switch */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5707 | switch_antenna_to_qam(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5708 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5709 | /* Ensure correct power-up mode */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5710 | status = power_up_qam(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5711 | if (status < 0) |
| 5712 | goto error; |
| 5713 | /* Reset QAM block */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5714 | status = qam_reset_qam(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5715 | if (status < 0) |
| 5716 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5717 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5718 | /* Setup IQM */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5719 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5720 | status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); |
| 5721 | if (status < 0) |
| 5722 | goto error; |
| 5723 | status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); |
| 5724 | if (status < 0) |
| 5725 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5726 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5727 | /* Upload IQM Channel Filter settings by |
| 5728 | boot loader from ROM table */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5729 | switch (o_mode) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5730 | case OM_QAM_ITU_A: |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5731 | status = bl_chain_cmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, |
| 5732 | DRXK_BLCC_NR_ELEMENTS_TAPS, |
| 5733 | DRXK_BLC_TIMEOUT); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5734 | break; |
| 5735 | case OM_QAM_ITU_C: |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5736 | status = bl_direct_cmd(state, IQM_CF_TAP_RE0__A, |
| 5737 | DRXK_BL_ROM_OFFSET_TAPS_ITU_C, |
| 5738 | DRXK_BLDC_NR_ELEMENTS_TAPS, |
| 5739 | DRXK_BLC_TIMEOUT); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 5740 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5741 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5742 | status = bl_direct_cmd(state, |
| 5743 | IQM_CF_TAP_IM0__A, |
| 5744 | DRXK_BL_ROM_OFFSET_TAPS_ITU_C, |
| 5745 | DRXK_BLDC_NR_ELEMENTS_TAPS, |
| 5746 | DRXK_BLC_TIMEOUT); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5747 | break; |
| 5748 | default: |
| 5749 | status = -EINVAL; |
| 5750 | } |
| 5751 | if (status < 0) |
| 5752 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5753 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5754 | status = write16(state, IQM_CF_OUT_ENA__A, 1 << IQM_CF_OUT_ENA_QAM__B); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5755 | if (status < 0) |
| 5756 | goto error; |
| 5757 | status = write16(state, IQM_CF_SYMMETRIC__A, 0); |
| 5758 | if (status < 0) |
| 5759 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5760 | status = write16(state, IQM_CF_MIDTAP__A, |
| 5761 | ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B))); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5762 | if (status < 0) |
| 5763 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5764 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5765 | status = write16(state, IQM_RC_STRETCH__A, 21); |
| 5766 | if (status < 0) |
| 5767 | goto error; |
| 5768 | status = write16(state, IQM_AF_CLP_LEN__A, 0); |
| 5769 | if (status < 0) |
| 5770 | goto error; |
| 5771 | status = write16(state, IQM_AF_CLP_TH__A, 448); |
| 5772 | if (status < 0) |
| 5773 | goto error; |
| 5774 | status = write16(state, IQM_AF_SNS_LEN__A, 0); |
| 5775 | if (status < 0) |
| 5776 | goto error; |
| 5777 | status = write16(state, IQM_CF_POW_MEAS_LEN__A, 0); |
| 5778 | if (status < 0) |
| 5779 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5780 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5781 | status = write16(state, IQM_FS_ADJ_SEL__A, 1); |
| 5782 | if (status < 0) |
| 5783 | goto error; |
| 5784 | status = write16(state, IQM_RC_ADJ_SEL__A, 1); |
| 5785 | if (status < 0) |
| 5786 | goto error; |
| 5787 | status = write16(state, IQM_CF_ADJ_SEL__A, 1); |
| 5788 | if (status < 0) |
| 5789 | goto error; |
| 5790 | status = write16(state, IQM_AF_UPD_SEL__A, 0); |
| 5791 | if (status < 0) |
| 5792 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5793 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5794 | /* IQM Impulse Noise Processing Unit */ |
| 5795 | status = write16(state, IQM_CF_CLP_VAL__A, 500); |
| 5796 | if (status < 0) |
| 5797 | goto error; |
| 5798 | status = write16(state, IQM_CF_DATATH__A, 1000); |
| 5799 | if (status < 0) |
| 5800 | goto error; |
| 5801 | status = write16(state, IQM_CF_BYPASSDET__A, 1); |
| 5802 | if (status < 0) |
| 5803 | goto error; |
| 5804 | status = write16(state, IQM_CF_DET_LCT__A, 0); |
| 5805 | if (status < 0) |
| 5806 | goto error; |
| 5807 | status = write16(state, IQM_CF_WND_LEN__A, 1); |
| 5808 | if (status < 0) |
| 5809 | goto error; |
| 5810 | status = write16(state, IQM_CF_PKDTH__A, 1); |
| 5811 | if (status < 0) |
| 5812 | goto error; |
| 5813 | status = write16(state, IQM_AF_INC_BYPASS__A, 1); |
| 5814 | if (status < 0) |
| 5815 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5816 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5817 | /* turn on IQMAF. Must be done before setAgc**() */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5818 | status = set_iqm_af(state, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5819 | if (status < 0) |
| 5820 | goto error; |
| 5821 | status = write16(state, IQM_AF_START_LOCK__A, 0x01); |
| 5822 | if (status < 0) |
| 5823 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5824 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5825 | /* IQM will not be reset from here, sync ADC and update/init AGC */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5826 | status = adc_synchronization(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5827 | if (status < 0) |
| 5828 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5829 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5830 | /* Set the FSM step period */ |
| 5831 | status = write16(state, SCU_RAM_QAM_FSM_STEP_PERIOD__A, 2000); |
| 5832 | if (status < 0) |
| 5833 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5834 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5835 | /* Halt SCU to enable safe non-atomic accesses */ |
| 5836 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); |
| 5837 | if (status < 0) |
| 5838 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5839 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5840 | /* No more resets of the IQM, current standard correctly set => |
| 5841 | now AGCs can be configured. */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5842 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5843 | status = init_agc(state, true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5844 | if (status < 0) |
| 5845 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5846 | status = set_pre_saw(state, &(state->m_qam_pre_saw_cfg)); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5847 | if (status < 0) |
| 5848 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5849 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5850 | /* Configure AGC's */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5851 | status = set_agc_rf(state, &(state->m_qam_rf_agc_cfg), true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5852 | if (status < 0) |
| 5853 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5854 | status = set_agc_if(state, &(state->m_qam_if_agc_cfg), true); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5855 | if (status < 0) |
| 5856 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5857 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5858 | /* Activate SCU to enable SCU commands */ |
| 5859 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
| 5860 | error: |
| 5861 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5862 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5863 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5864 | } |
| 5865 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5866 | static int write_gpio(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5867 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5868 | int status; |
| 5869 | u16 value = 0; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5870 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5871 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5872 | /* stop lock indicator process */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5873 | status = write16(state, SCU_RAM_GPIO__A, |
| 5874 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5875 | if (status < 0) |
| 5876 | goto error; |
| 5877 | |
| 5878 | /* Write magic word to enable pdr reg write */ |
| 5879 | status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); |
| 5880 | if (status < 0) |
| 5881 | goto error; |
| 5882 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5883 | if (state->m_has_sawsw) { |
| 5884 | if (state->uio_mask & 0x0001) { /* UIO-1 */ |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5885 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5886 | status = write16(state, SIO_PDR_SMA_TX_CFG__A, |
| 5887 | state->m_gpio_cfg); |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5888 | if (status < 0) |
| 5889 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5890 | |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5891 | /* use corresponding bit in io data output registar */ |
| 5892 | status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); |
| 5893 | if (status < 0) |
| 5894 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5895 | if ((state->m_gpio & 0x0001) == 0) |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5896 | value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ |
| 5897 | else |
| 5898 | value |= 0x8000; /* write one to 15th bit - 1st UIO */ |
| 5899 | /* write back to io data output register */ |
| 5900 | status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); |
| 5901 | if (status < 0) |
| 5902 | goto error; |
| 5903 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5904 | if (state->uio_mask & 0x0002) { /* UIO-2 */ |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5905 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5906 | status = write16(state, SIO_PDR_SMA_RX_CFG__A, |
| 5907 | state->m_gpio_cfg); |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5908 | if (status < 0) |
| 5909 | goto error; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5910 | |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5911 | /* use corresponding bit in io data output registar */ |
| 5912 | status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); |
| 5913 | if (status < 0) |
| 5914 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5915 | if ((state->m_gpio & 0x0002) == 0) |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5916 | value &= 0xBFFF; /* write zero to 14th bit - 2st UIO */ |
| 5917 | else |
| 5918 | value |= 0x4000; /* write one to 14th bit - 2st UIO */ |
| 5919 | /* write back to io data output register */ |
| 5920 | status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); |
| 5921 | if (status < 0) |
| 5922 | goto error; |
| 5923 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5924 | if (state->uio_mask & 0x0004) { /* UIO-3 */ |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5925 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 5926 | status = write16(state, SIO_PDR_GPIO_CFG__A, |
| 5927 | state->m_gpio_cfg); |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5928 | if (status < 0) |
| 5929 | goto error; |
| 5930 | |
| 5931 | /* use corresponding bit in io data output registar */ |
| 5932 | status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); |
| 5933 | if (status < 0) |
| 5934 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5935 | if ((state->m_gpio & 0x0004) == 0) |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5936 | value &= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */ |
| 5937 | else |
| 5938 | value |= 0x0004; /* write one to 2nd bit - 3rd UIO */ |
| 5939 | /* write back to io data output register */ |
| 5940 | status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); |
| 5941 | if (status < 0) |
| 5942 | goto error; |
| 5943 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5944 | } |
| 5945 | /* Write magic word to disable pdr reg write */ |
| 5946 | status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); |
| 5947 | error: |
| 5948 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5949 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5950 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5951 | } |
| 5952 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5953 | static int switch_antenna_to_qam(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5954 | { |
Mauro Carvalho Chehab | 147e110 | 2011-07-10 08:24:26 -0300 | [diff] [blame] | 5955 | int status = 0; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5956 | bool gpio_state; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5957 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5958 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 147e110 | 2011-07-10 08:24:26 -0300 | [diff] [blame] | 5959 | |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5960 | if (!state->antenna_gpio) |
| 5961 | return 0; |
| 5962 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5963 | gpio_state = state->m_gpio & state->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5964 | |
| 5965 | if (state->antenna_dvbt ^ gpio_state) { |
| 5966 | /* Antenna is on DVB-T mode. Switch */ |
| 5967 | if (state->antenna_dvbt) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5968 | state->m_gpio &= ~state->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5969 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5970 | state->m_gpio |= state->antenna_gpio; |
| 5971 | status = write_gpio(state); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5972 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5973 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5974 | pr_err("Error %d on %s\n", status, __func__); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5975 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5976 | } |
| 5977 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5978 | static int switch_antenna_to_dvbt(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5979 | { |
Mauro Carvalho Chehab | 147e110 | 2011-07-10 08:24:26 -0300 | [diff] [blame] | 5980 | int status = 0; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5981 | bool gpio_state; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 5982 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 5983 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5984 | |
| 5985 | if (!state->antenna_gpio) |
| 5986 | return 0; |
| 5987 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5988 | gpio_state = state->m_gpio & state->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5989 | |
| 5990 | if (!(state->antenna_dvbt ^ gpio_state)) { |
| 5991 | /* Antenna is on DVB-C mode. Switch */ |
| 5992 | if (state->antenna_dvbt) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5993 | state->m_gpio |= state->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 5994 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 5995 | state->m_gpio &= ~state->antenna_gpio; |
| 5996 | status = write_gpio(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 5997 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 5998 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 5999 | pr_err("Error %d on %s\n", status, __func__); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6000 | return status; |
| 6001 | } |
| 6002 | |
| 6003 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6004 | static int power_down_device(struct drxk_state *state) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6005 | { |
| 6006 | /* Power down to requested mode */ |
| 6007 | /* Backup some register settings */ |
| 6008 | /* Set pins with possible pull-ups connected to them in input mode */ |
| 6009 | /* Analog power down */ |
| 6010 | /* ADC power down */ |
| 6011 | /* Power down device */ |
| 6012 | int status; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6013 | |
| 6014 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6015 | if (state->m_b_p_down_open_bridge) { |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6016 | /* Open I2C bridge before power down of DRXK */ |
| 6017 | status = ConfigureI2CBridge(state, true); |
Mauro Carvalho Chehab | ea90f01 | 2011-07-03 18:06:07 -0300 | [diff] [blame] | 6018 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6019 | goto error; |
| 6020 | } |
| 6021 | /* driver 0.9.0 */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6022 | status = dvbt_enable_ofdm_token_ring(state, false); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6023 | if (status < 0) |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6024 | goto error; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6025 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6026 | status = write16(state, SIO_CC_PWD_MODE__A, |
| 6027 | SIO_CC_PWD_MODE_LEVEL_CLOCK); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6028 | if (status < 0) |
| 6029 | goto error; |
| 6030 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
| 6031 | if (status < 0) |
| 6032 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6033 | state->m_hi_cfg_ctrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
| 6034 | status = hi_cfg_command(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6035 | error: |
| 6036 | if (status < 0) |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6037 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6038 | |
| 6039 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6040 | } |
| 6041 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6042 | static int init_drxk(struct drxk_state *state) |
| 6043 | { |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6044 | int status = 0, n = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6045 | enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM; |
| 6046 | u16 driver_version; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6047 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6048 | dprintk(1, "\n"); |
Nick Desaulniers | 7369bbf | 2017-12-18 12:31:52 -0500 | [diff] [blame] | 6049 | if (state->m_drxk_state == DRXK_UNINITIALIZED) { |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 6050 | drxk_i2c_lock(state); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6051 | status = power_up_device(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6052 | if (status < 0) |
| 6053 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6054 | status = drxx_open(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6055 | if (status < 0) |
| 6056 | goto error; |
| 6057 | /* Soft reset of OFDM-, sys- and osc-clockdomain */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6058 | status = write16(state, SIO_CC_SOFT_RST__A, |
| 6059 | SIO_CC_SOFT_RST_OFDM__M |
| 6060 | | SIO_CC_SOFT_RST_SYS__M |
| 6061 | | SIO_CC_SOFT_RST_OSC__M); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6062 | if (status < 0) |
| 6063 | goto error; |
| 6064 | status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); |
| 6065 | if (status < 0) |
| 6066 | goto error; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6067 | /* |
| 6068 | * TODO is this needed? If yes, how much delay in |
| 6069 | * worst case scenario |
| 6070 | */ |
Mauro Carvalho Chehab | b72852b | 2013-04-28 11:47:47 -0300 | [diff] [blame] | 6071 | usleep_range(1000, 2000); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6072 | state->m_drxk_a3_patch_code = true; |
| 6073 | status = get_device_capabilities(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6074 | if (status < 0) |
| 6075 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6076 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6077 | /* Bridge delay, uses oscilator clock */ |
| 6078 | /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */ |
| 6079 | /* SDA brdige delay */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6080 | state->m_hi_cfg_bridge_delay = |
| 6081 | (u16) ((state->m_osc_clock_freq / 1000) * |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6082 | HI_I2C_BRIDGE_DELAY) / 1000; |
| 6083 | /* Clipping */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6084 | if (state->m_hi_cfg_bridge_delay > |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6085 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6086 | state->m_hi_cfg_bridge_delay = |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6087 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M; |
| 6088 | } |
| 6089 | /* SCL bridge delay, same as SDA for now */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6090 | state->m_hi_cfg_bridge_delay += |
| 6091 | state->m_hi_cfg_bridge_delay << |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6092 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6093 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6094 | status = init_hi(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6095 | if (status < 0) |
| 6096 | goto error; |
| 6097 | /* disable various processes */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6098 | #if NOA1ROM |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6099 | if (!(state->m_DRXK_A1_ROM_CODE) |
| 6100 | && !(state->m_DRXK_A2_ROM_CODE)) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6101 | #endif |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6102 | { |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6103 | status = write16(state, SCU_RAM_GPIO__A, |
| 6104 | SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6105 | if (status < 0) |
| 6106 | goto error; |
| 6107 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6108 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6109 | /* disable MPEG port */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6110 | status = mpegts_disable(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6111 | if (status < 0) |
| 6112 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6113 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6114 | /* Stop AUD and SCU */ |
| 6115 | status = write16(state, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP); |
| 6116 | if (status < 0) |
| 6117 | goto error; |
| 6118 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP); |
| 6119 | if (status < 0) |
| 6120 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6121 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6122 | /* enable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6123 | status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, |
| 6124 | SIO_OFDM_SH_OFDM_RING_ENABLE_ON); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6125 | if (status < 0) |
| 6126 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6127 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6128 | /* include boot loader section */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6129 | status = write16(state, SIO_BL_COMM_EXEC__A, |
| 6130 | SIO_BL_COMM_EXEC_ACTIVE); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6131 | if (status < 0) |
| 6132 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6133 | status = bl_chain_cmd(state, 0, 6, 100); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6134 | if (status < 0) |
| 6135 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6136 | |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6137 | if (state->fw) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6138 | status = download_microcode(state, state->fw->data, |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6139 | state->fw->size); |
| 6140 | if (status < 0) |
| 6141 | goto error; |
| 6142 | } |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 6143 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6144 | /* disable token-ring bus through OFDM block for possible ucode upload */ |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6145 | status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, |
| 6146 | SIO_OFDM_SH_OFDM_RING_ENABLE_OFF); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6147 | if (status < 0) |
| 6148 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6149 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6150 | /* Run SCU for a little while to initialize microcode version numbers */ |
| 6151 | status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); |
| 6152 | if (status < 0) |
| 6153 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6154 | status = drxx_open(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6155 | if (status < 0) |
| 6156 | goto error; |
| 6157 | /* added for test */ |
| 6158 | msleep(30); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6159 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6160 | power_mode = DRXK_POWER_DOWN_OFDM; |
| 6161 | status = ctrl_power_mode(state, &power_mode); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6162 | if (status < 0) |
| 6163 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6164 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6165 | /* Stamp driver version number in SCU data RAM in BCD code |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 6166 | Done to enable field application engineers to retrieve drxdriver version |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6167 | via I2C from SCU RAM. |
| 6168 | Not using SCU command interface for SCU register access since no |
| 6169 | microcode may be present. |
| 6170 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6171 | driver_version = |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6172 | (((DRXK_VERSION_MAJOR / 100) % 10) << 12) + |
| 6173 | (((DRXK_VERSION_MAJOR / 10) % 10) << 8) + |
| 6174 | ((DRXK_VERSION_MAJOR % 10) << 4) + |
| 6175 | (DRXK_VERSION_MINOR % 10); |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6176 | status = write16(state, SCU_RAM_DRIVER_VER_HI__A, |
| 6177 | driver_version); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6178 | if (status < 0) |
| 6179 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6180 | driver_version = |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6181 | (((DRXK_VERSION_PATCH / 1000) % 10) << 12) + |
| 6182 | (((DRXK_VERSION_PATCH / 100) % 10) << 8) + |
| 6183 | (((DRXK_VERSION_PATCH / 10) % 10) << 4) + |
| 6184 | (DRXK_VERSION_PATCH % 10); |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6185 | status = write16(state, SCU_RAM_DRIVER_VER_LO__A, |
| 6186 | driver_version); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6187 | if (status < 0) |
| 6188 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6189 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6190 | pr_info("DRXK driver version %d.%d.%d\n", |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6191 | DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR, |
| 6192 | DRXK_VERSION_PATCH); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6193 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6194 | /* |
| 6195 | * Dirty fix of default values for ROM/PATCH microcode |
| 6196 | * Dirty because this fix makes it impossible to setup |
| 6197 | * suitable values before calling DRX_Open. This solution |
| 6198 | * requires changes to RF AGC speed to be done via the CTRL |
| 6199 | * function after calling DRX_Open |
| 6200 | */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6201 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6202 | /* m_dvbt_rf_agc_cfg.speed = 3; */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6203 | |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6204 | /* Reset driver debug flags to 0 */ |
| 6205 | status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0); |
| 6206 | if (status < 0) |
| 6207 | goto error; |
| 6208 | /* driver 0.9.0 */ |
| 6209 | /* Setup FEC OC: |
| 6210 | NOTE: No more full FEC resets allowed afterwards!! */ |
| 6211 | status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP); |
| 6212 | if (status < 0) |
| 6213 | goto error; |
| 6214 | /* MPEGTS functions are still the same */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6215 | status = mpegts_dto_init(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6216 | if (status < 0) |
| 6217 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6218 | status = mpegts_stop(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6219 | if (status < 0) |
| 6220 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6221 | status = mpegts_configure_polarity(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6222 | if (status < 0) |
| 6223 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6224 | status = mpegts_configure_pins(state, state->m_enable_mpeg_output); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6225 | if (status < 0) |
| 6226 | goto error; |
| 6227 | /* added: configure GPIO */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6228 | status = write_gpio(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6229 | if (status < 0) |
| 6230 | goto error; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6231 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6232 | state->m_drxk_state = DRXK_STOPPED; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6233 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6234 | if (state->m_b_power_down) { |
| 6235 | status = power_down_device(state); |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6236 | if (status < 0) |
| 6237 | goto error; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6238 | state->m_drxk_state = DRXK_POWERED_DOWN; |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6239 | } else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6240 | state->m_drxk_state = DRXK_STOPPED; |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6241 | |
| 6242 | /* Initialize the supported delivery systems */ |
| 6243 | n = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6244 | if (state->m_has_dvbc) { |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6245 | state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_A; |
| 6246 | state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_C; |
| 6247 | strlcat(state->frontend.ops.info.name, " DVB-C", |
| 6248 | sizeof(state->frontend.ops.info.name)); |
| 6249 | } |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6250 | if (state->m_has_dvbt) { |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6251 | state->frontend.ops.delsys[n++] = SYS_DVBT; |
| 6252 | strlcat(state->frontend.ops.info.name, " DVB-T", |
| 6253 | sizeof(state->frontend.ops.info.name)); |
| 6254 | } |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 6255 | drxk_i2c_unlock(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6256 | } |
Mauro Carvalho Chehab | be44eb2 | 2011-07-10 01:49:53 -0300 | [diff] [blame] | 6257 | error: |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 6258 | if (status < 0) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6259 | state->m_drxk_state = DRXK_NO_DEV; |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 6260 | drxk_i2c_unlock(state); |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6261 | pr_err("Error %d on %s\n", status, __func__); |
Mauro Carvalho Chehab | 20bfe7a | 2012-06-29 14:43:32 -0300 | [diff] [blame] | 6262 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6263 | |
Mauro Carvalho Chehab | e716ada | 2011-07-21 19:35:04 -0300 | [diff] [blame] | 6264 | return status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6265 | } |
| 6266 | |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6267 | static void load_firmware_cb(const struct firmware *fw, |
| 6268 | void *context) |
| 6269 | { |
| 6270 | struct drxk_state *state = context; |
| 6271 | |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6272 | dprintk(1, ": %s\n", fw ? "firmware loaded" : "firmware not loaded"); |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6273 | if (!fw) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6274 | pr_err("Could not load firmware file %s.\n", |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6275 | state->microcode_name); |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6276 | pr_info("Copy %s to your hotplug directory!\n", |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6277 | state->microcode_name); |
| 6278 | state->microcode_name = NULL; |
| 6279 | |
| 6280 | /* |
| 6281 | * As firmware is now load asynchronous, it is not possible |
| 6282 | * anymore to fail at frontend attach. We might silently |
| 6283 | * return here, and hope that the driver won't crash. |
| 6284 | * We might also change all DVB callbacks to return -ENODEV |
| 6285 | * if the device is not initialized. |
| 6286 | * As the DRX-K devices have their own internal firmware, |
| 6287 | * let's just hope that it will match a firmware revision |
| 6288 | * compatible with this driver and proceed. |
| 6289 | */ |
| 6290 | } |
| 6291 | state->fw = fw; |
| 6292 | |
| 6293 | init_drxk(state); |
| 6294 | } |
| 6295 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6296 | static void drxk_release(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6297 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6298 | struct drxk_state *state = fe->demodulator_priv; |
| 6299 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6300 | dprintk(1, "\n"); |
Markus Elfring | 9bc2dd7 | 2014-11-19 18:27:24 -0300 | [diff] [blame] | 6301 | release_firmware(state->fw); |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6302 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6303 | kfree(state); |
| 6304 | } |
| 6305 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6306 | static int drxk_sleep(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6307 | { |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6308 | struct drxk_state *state = fe->demodulator_priv; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6309 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6310 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6311 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6312 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6313 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6314 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6315 | return 0; |
| 6316 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6317 | shut_down(state); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6318 | return 0; |
| 6319 | } |
| 6320 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6321 | static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6322 | { |
| 6323 | struct drxk_state *state = fe->demodulator_priv; |
| 6324 | |
Martin Blumenstingl | 257ee97 | 2012-07-04 17:38:23 -0300 | [diff] [blame] | 6325 | dprintk(1, ": %s\n", enable ? "enable" : "disable"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6326 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6327 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6328 | return -ENODEV; |
| 6329 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6330 | return ConfigureI2CBridge(state, enable ? true : false); |
| 6331 | } |
| 6332 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 6333 | static int drxk_set_parameters(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6334 | { |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 6335 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6336 | u32 delsys = p->delivery_system, old_delsys; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6337 | struct drxk_state *state = fe->demodulator_priv; |
| 6338 | u32 IF; |
| 6339 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6340 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 8513e14 | 2011-09-03 11:40:02 -0300 | [diff] [blame] | 6341 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6342 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6343 | return -ENODEV; |
| 6344 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6345 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6346 | return -EAGAIN; |
| 6347 | |
Mauro Carvalho Chehab | 8513e14 | 2011-09-03 11:40:02 -0300 | [diff] [blame] | 6348 | if (!fe->ops.tuner_ops.get_if_frequency) { |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6349 | pr_err("Error: get_if_frequency() not defined at tuner. Can't work without it!\n"); |
Mauro Carvalho Chehab | 8513e14 | 2011-09-03 11:40:02 -0300 | [diff] [blame] | 6350 | return -EINVAL; |
| 6351 | } |
| 6352 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6353 | if (fe->ops.i2c_gate_ctrl) |
| 6354 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 6355 | if (fe->ops.tuner_ops.set_params) |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 6356 | fe->ops.tuner_ops.set_params(fe); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6357 | if (fe->ops.i2c_gate_ctrl) |
| 6358 | fe->ops.i2c_gate_ctrl(fe, 0); |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6359 | |
| 6360 | old_delsys = state->props.delivery_system; |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 6361 | state->props = *p; |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6362 | |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6363 | if (old_delsys != delsys) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6364 | shut_down(state); |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6365 | switch (delsys) { |
| 6366 | case SYS_DVBC_ANNEX_A: |
| 6367 | case SYS_DVBC_ANNEX_C: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6368 | if (!state->m_has_dvbc) |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6369 | return -EINVAL; |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6370 | state->m_itut_annex_c = (delsys == SYS_DVBC_ANNEX_C) ? |
| 6371 | true : false; |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6372 | if (state->m_itut_annex_c) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6373 | setoperation_mode(state, OM_QAM_ITU_C); |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6374 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6375 | setoperation_mode(state, OM_QAM_ITU_A); |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6376 | break; |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6377 | case SYS_DVBT: |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6378 | if (!state->m_has_dvbt) |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6379 | return -EINVAL; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6380 | setoperation_mode(state, OM_DVBT); |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6381 | break; |
| 6382 | default: |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6383 | return -EINVAL; |
Mauro Carvalho Chehab | 6cb393c | 2012-01-05 09:26:40 -0200 | [diff] [blame] | 6384 | } |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6385 | } |
| 6386 | |
Mauro Carvalho Chehab | 8513e14 | 2011-09-03 11:40:02 -0300 | [diff] [blame] | 6387 | fe->ops.tuner_ops.get_if_frequency(fe, &IF); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6388 | start(state, 0, IF); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6389 | |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 6390 | /* After set_frontend, stats aren't available */ |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6391 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 6392 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6393 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6394 | p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6395 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6396 | p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6397 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6398 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6399 | |
Mauro Carvalho Chehab | e0e6eca | 2011-07-04 08:27:47 -0300 | [diff] [blame] | 6400 | /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */ |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6401 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6402 | return 0; |
| 6403 | } |
| 6404 | |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6405 | static int get_strength(struct drxk_state *state, u64 *strength) |
| 6406 | { |
| 6407 | int status; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6408 | struct s_cfg_agc rf_agc, if_agc; |
| 6409 | u32 total_gain = 0; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6410 | u32 atten = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6411 | u32 agc_range = 0; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6412 | u16 scu_lvl = 0; |
| 6413 | u16 scu_coc = 0; |
| 6414 | /* FIXME: those are part of the tuner presets */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6415 | u16 tuner_rf_gain = 50; /* Default value on az6007 driver */ |
| 6416 | u16 tuner_if_gain = 40; /* Default value on az6007 driver */ |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6417 | |
| 6418 | *strength = 0; |
| 6419 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6420 | if (is_dvbt(state)) { |
| 6421 | rf_agc = state->m_dvbt_rf_agc_cfg; |
| 6422 | if_agc = state->m_dvbt_if_agc_cfg; |
| 6423 | } else if (is_qam(state)) { |
| 6424 | rf_agc = state->m_qam_rf_agc_cfg; |
| 6425 | if_agc = state->m_qam_if_agc_cfg; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6426 | } else { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6427 | rf_agc = state->m_atv_rf_agc_cfg; |
| 6428 | if_agc = state->m_atv_if_agc_cfg; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6429 | } |
| 6430 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6431 | if (rf_agc.ctrl_mode == DRXK_AGC_CTRL_AUTO) { |
| 6432 | /* SCU output_level */ |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6433 | status = read16(state, SCU_RAM_AGC_RF_IACCU_HI__A, &scu_lvl); |
| 6434 | if (status < 0) |
| 6435 | return status; |
| 6436 | |
| 6437 | /* SCU c.o.c. */ |
Christophe JAILLET | d259a5e | 2016-08-10 02:54:41 -0300 | [diff] [blame] | 6438 | status = read16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, &scu_coc); |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6439 | if (status < 0) |
| 6440 | return status; |
| 6441 | |
| 6442 | if (((u32) scu_lvl + (u32) scu_coc) < 0xffff) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6443 | rf_agc.output_level = scu_lvl + scu_coc; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6444 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6445 | rf_agc.output_level = 0xffff; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6446 | |
| 6447 | /* Take RF gain into account */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6448 | total_gain += tuner_rf_gain; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6449 | |
| 6450 | /* clip output value */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6451 | if (rf_agc.output_level < rf_agc.min_output_level) |
| 6452 | rf_agc.output_level = rf_agc.min_output_level; |
| 6453 | if (rf_agc.output_level > rf_agc.max_output_level) |
| 6454 | rf_agc.output_level = rf_agc.max_output_level; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6455 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6456 | agc_range = (u32) (rf_agc.max_output_level - rf_agc.min_output_level); |
| 6457 | if (agc_range > 0) { |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6458 | atten += 100UL * |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6459 | ((u32)(tuner_rf_gain)) * |
| 6460 | ((u32)(rf_agc.output_level - rf_agc.min_output_level)) |
| 6461 | / agc_range; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6462 | } |
| 6463 | } |
| 6464 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6465 | if (if_agc.ctrl_mode == DRXK_AGC_CTRL_AUTO) { |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6466 | status = read16(state, SCU_RAM_AGC_IF_IACCU_HI__A, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6467 | &if_agc.output_level); |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6468 | if (status < 0) |
| 6469 | return status; |
| 6470 | |
| 6471 | status = read16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6472 | &if_agc.top); |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6473 | if (status < 0) |
| 6474 | return status; |
| 6475 | |
| 6476 | /* Take IF gain into account */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6477 | total_gain += (u32) tuner_if_gain; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6478 | |
| 6479 | /* clip output value */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6480 | if (if_agc.output_level < if_agc.min_output_level) |
| 6481 | if_agc.output_level = if_agc.min_output_level; |
| 6482 | if (if_agc.output_level > if_agc.max_output_level) |
| 6483 | if_agc.output_level = if_agc.max_output_level; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6484 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6485 | agc_range = (u32)(if_agc.max_output_level - if_agc.min_output_level); |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6486 | if (agc_range > 0) { |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6487 | atten += 100UL * |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6488 | ((u32)(tuner_if_gain)) * |
| 6489 | ((u32)(if_agc.output_level - if_agc.min_output_level)) |
| 6490 | / agc_range; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | /* |
| 6495 | * Convert to 0..65535 scale. |
| 6496 | * If it can't be measured (AGC is disabled), just show 100%. |
| 6497 | */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6498 | if (total_gain > 0) |
| 6499 | *strength = (65535UL * atten / total_gain / 100); |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6500 | else |
| 6501 | *strength = 65535; |
| 6502 | |
| 6503 | return 0; |
| 6504 | } |
| 6505 | |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6506 | static int drxk_get_stats(struct dvb_frontend *fe) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6507 | { |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6508 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6509 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6510 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6511 | u32 stat; |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6512 | u16 reg16; |
| 6513 | u32 post_bit_count; |
| 6514 | u32 post_bit_err_count; |
| 6515 | u32 post_bit_error_scale; |
| 6516 | u32 pre_bit_err_count; |
| 6517 | u32 pre_bit_count; |
| 6518 | u32 pkt_count; |
| 6519 | u32 pkt_error_count; |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6520 | s32 cnr; |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6521 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6522 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6523 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6524 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6525 | return -EAGAIN; |
| 6526 | |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6527 | /* get status */ |
| 6528 | state->fe_status = 0; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6529 | get_lock_status(state, &stat); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6530 | if (stat == MPEG_LOCK) |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6531 | state->fe_status |= 0x1f; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6532 | if (stat == FEC_LOCK) |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6533 | state->fe_status |= 0x0f; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6534 | if (stat == DEMOD_LOCK) |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6535 | state->fe_status |= 0x07; |
| 6536 | |
Mauro Carvalho Chehab | 59a7a23 | 2013-03-20 08:21:52 -0300 | [diff] [blame] | 6537 | /* |
| 6538 | * Estimate signal strength from AGC |
| 6539 | */ |
| 6540 | get_strength(state, &c->strength.stat[0].uvalue); |
| 6541 | c->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 6542 | |
| 6543 | |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6544 | if (stat >= DEMOD_LOCK) { |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6545 | get_signal_to_noise(state, &cnr); |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6546 | c->cnr.stat[0].svalue = cnr * 100; |
| 6547 | c->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
| 6548 | } else { |
| 6549 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6550 | } |
| 6551 | |
| 6552 | if (stat < FEC_LOCK) { |
| 6553 | c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6554 | c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6555 | c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6556 | c->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6557 | c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6558 | c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6559 | return 0; |
| 6560 | } |
| 6561 | |
| 6562 | /* Get post BER */ |
| 6563 | |
| 6564 | /* BER measurement is valid if at least FEC lock is achieved */ |
| 6565 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6566 | /* |
| 6567 | * OFDM_EC_VD_REQ_SMB_CNT__A and/or OFDM_EC_VD_REQ_BIT_CNT can be |
| 6568 | * written to set nr of symbols or bits over which to measure |
| 6569 | * EC_VD_REG_ERR_BIT_CNT__A . See CtrlSetCfg(). |
| 6570 | */ |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6571 | |
| 6572 | /* Read registers for post/preViterbi BER calculation */ |
| 6573 | status = read16(state, OFDM_EC_VD_ERR_BIT_CNT__A, ®16); |
| 6574 | if (status < 0) |
| 6575 | goto error; |
| 6576 | pre_bit_err_count = reg16; |
| 6577 | |
| 6578 | status = read16(state, OFDM_EC_VD_IN_BIT_CNT__A , ®16); |
| 6579 | if (status < 0) |
| 6580 | goto error; |
| 6581 | pre_bit_count = reg16; |
| 6582 | |
| 6583 | /* Number of bit-errors */ |
| 6584 | status = read16(state, FEC_RS_NR_BIT_ERRORS__A, ®16); |
| 6585 | if (status < 0) |
| 6586 | goto error; |
| 6587 | post_bit_err_count = reg16; |
| 6588 | |
| 6589 | status = read16(state, FEC_RS_MEASUREMENT_PRESCALE__A, ®16); |
| 6590 | if (status < 0) |
| 6591 | goto error; |
| 6592 | post_bit_error_scale = reg16; |
| 6593 | |
| 6594 | status = read16(state, FEC_RS_MEASUREMENT_PERIOD__A, ®16); |
| 6595 | if (status < 0) |
| 6596 | goto error; |
| 6597 | pkt_count = reg16; |
| 6598 | |
| 6599 | status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, ®16); |
| 6600 | if (status < 0) |
| 6601 | goto error; |
| 6602 | pkt_error_count = reg16; |
| 6603 | write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); |
| 6604 | |
| 6605 | post_bit_err_count *= post_bit_error_scale; |
| 6606 | |
| 6607 | post_bit_count = pkt_count * 204 * 8; |
| 6608 | |
| 6609 | /* Store the results */ |
| 6610 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 6611 | c->block_error.stat[0].uvalue += pkt_error_count; |
| 6612 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
| 6613 | c->block_count.stat[0].uvalue += pkt_count; |
| 6614 | |
| 6615 | c->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 6616 | c->pre_bit_error.stat[0].uvalue += pre_bit_err_count; |
| 6617 | c->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
| 6618 | c->pre_bit_count.stat[0].uvalue += pre_bit_count; |
| 6619 | |
| 6620 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 6621 | c->post_bit_error.stat[0].uvalue += post_bit_err_count; |
| 6622 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
| 6623 | c->post_bit_count.stat[0].uvalue += post_bit_count; |
| 6624 | |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6625 | error: |
| 6626 | return status; |
| 6627 | } |
| 6628 | |
| 6629 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 6630 | static int drxk_read_status(struct dvb_frontend *fe, enum fe_status *status) |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6631 | { |
| 6632 | struct drxk_state *state = fe->demodulator_priv; |
| 6633 | int rc; |
| 6634 | |
| 6635 | dprintk(1, "\n"); |
| 6636 | |
| 6637 | rc = drxk_get_stats(fe); |
| 6638 | if (rc < 0) |
| 6639 | return rc; |
| 6640 | |
| 6641 | *status = state->fe_status; |
| 6642 | |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6643 | return 0; |
| 6644 | } |
| 6645 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6646 | static int drxk_read_signal_strength(struct dvb_frontend *fe, |
| 6647 | u16 *strength) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6648 | { |
| 6649 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 340e769 | 2013-03-20 08:57:42 -0300 | [diff] [blame] | 6650 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6651 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6652 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6653 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6654 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6655 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6656 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6657 | return -EAGAIN; |
| 6658 | |
Mauro Carvalho Chehab | 340e769 | 2013-03-20 08:57:42 -0300 | [diff] [blame] | 6659 | *strength = c->strength.stat[0].uvalue; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6660 | return 0; |
| 6661 | } |
| 6662 | |
| 6663 | static int drxk_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 6664 | { |
| 6665 | struct drxk_state *state = fe->demodulator_priv; |
| 6666 | s32 snr2; |
| 6667 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6668 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6669 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6670 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6671 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6672 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6673 | return -EAGAIN; |
| 6674 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6675 | get_signal_to_noise(state, &snr2); |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6676 | |
| 6677 | /* No negative SNR, clip to zero */ |
| 6678 | if (snr2 < 0) |
| 6679 | snr2 = 0; |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6680 | *snr = snr2 & 0xffff; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6681 | return 0; |
| 6682 | } |
| 6683 | |
| 6684 | static int drxk_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 6685 | { |
| 6686 | struct drxk_state *state = fe->demodulator_priv; |
| 6687 | u16 err; |
| 6688 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6689 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6690 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6691 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6692 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6693 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6694 | return -EAGAIN; |
| 6695 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6696 | dvbtqam_get_acc_pkt_err(state, &err); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6697 | *ucblocks = (u32) err; |
| 6698 | return 0; |
| 6699 | } |
| 6700 | |
Mauro Carvalho Chehab | ab5060c | 2013-04-28 11:47:51 -0300 | [diff] [blame] | 6701 | static int drxk_get_tune_settings(struct dvb_frontend *fe, |
| 6702 | struct dvb_frontend_tune_settings *sets) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6703 | { |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6704 | struct drxk_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6705 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6706 | |
| 6707 | dprintk(1, "\n"); |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6708 | |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6709 | if (state->m_drxk_state == DRXK_NO_DEV) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6710 | return -ENODEV; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6711 | if (state->m_drxk_state == DRXK_UNINITIALIZED) |
Mauro Carvalho Chehab | 704a28e | 2012-06-29 15:45:04 -0300 | [diff] [blame] | 6712 | return -EAGAIN; |
| 6713 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6714 | switch (p->delivery_system) { |
| 6715 | case SYS_DVBC_ANNEX_A: |
| 6716 | case SYS_DVBC_ANNEX_C: |
Jose Alberto Reguero | dc66d7f | 2012-01-27 18:34:49 -0300 | [diff] [blame] | 6717 | case SYS_DVBT: |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6718 | sets->min_delay_ms = 3000; |
| 6719 | sets->max_drift = 0; |
| 6720 | sets->step_size = 0; |
| 6721 | return 0; |
| 6722 | default: |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6723 | return -EINVAL; |
| 6724 | } |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6725 | } |
| 6726 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 6727 | static const struct dvb_frontend_ops drxk_ops = { |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6728 | /* .delsys will be filled dynamically */ |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6729 | .info = { |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6730 | .name = "DRXK", |
Mauro Carvalho Chehab | f1b1eab | 2018-07-05 18:59:36 -0400 | [diff] [blame] | 6731 | .frequency_min_hz = 47 * MHz, |
| 6732 | .frequency_max_hz = 865 * MHz, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6733 | /* For DVB-C */ |
Mauro Carvalho Chehab | f1b1eab | 2018-07-05 18:59:36 -0400 | [diff] [blame] | 6734 | .symbol_rate_min = 870000, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6735 | .symbol_rate_max = 11700000, |
| 6736 | /* For DVB-T */ |
Mauro Carvalho Chehab | f1b1eab | 2018-07-05 18:59:36 -0400 | [diff] [blame] | 6737 | .frequency_stepsize_hz = 166667, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6738 | |
| 6739 | .caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 | |
| 6740 | FE_CAN_QAM_128 | FE_CAN_QAM_256 | FE_CAN_FEC_AUTO | |
| 6741 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 6742 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_MUTE_TS | |
| 6743 | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER | |
| 6744 | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO |
| 6745 | }, |
| 6746 | |
| 6747 | .release = drxk_release, |
| 6748 | .sleep = drxk_sleep, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6749 | .i2c_gate_ctrl = drxk_gate_ctrl, |
| 6750 | |
Mauro Carvalho Chehab | ed5452a | 2011-12-26 09:57:11 -0300 | [diff] [blame] | 6751 | .set_frontend = drxk_set_parameters, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6752 | .get_tune_settings = drxk_get_tune_settings, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6753 | |
| 6754 | .read_status = drxk_read_status, |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6755 | .read_signal_strength = drxk_read_signal_strength, |
| 6756 | .read_snr = drxk_read_snr, |
| 6757 | .read_ucblocks = drxk_read_ucblocks, |
| 6758 | }; |
| 6759 | |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6760 | struct dvb_frontend *drxk_attach(const struct drxk_config *config, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6761 | struct i2c_adapter *i2c) |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6762 | { |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6763 | struct dtv_frontend_properties *p; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6764 | struct drxk_state *state = NULL; |
Mauro Carvalho Chehab | 0fc55e8 | 2011-07-09 12:36:58 -0300 | [diff] [blame] | 6765 | u8 adr = config->adr; |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6766 | int status; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6767 | |
Mauro Carvalho Chehab | 2da6750 | 2011-07-04 17:39:21 -0300 | [diff] [blame] | 6768 | dprintk(1, "\n"); |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6769 | state = kzalloc(sizeof(struct drxk_state), GFP_KERNEL); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6770 | if (!state) |
| 6771 | return NULL; |
| 6772 | |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6773 | state->i2c = i2c; |
| 6774 | state->demod_address = adr; |
Mauro Carvalho Chehab | e076c92 | 2011-07-09 13:06:12 -0300 | [diff] [blame] | 6775 | state->single_master = config->single_master; |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 6776 | state->microcode_name = config->microcode_name; |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 6777 | state->qam_demod_parameter_count = config->qam_demod_parameter_count; |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame] | 6778 | state->no_i2c_bridge = config->no_i2c_bridge; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 6779 | state->antenna_gpio = config->antenna_gpio; |
| 6780 | state->antenna_dvbt = config->antenna_dvbt; |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6781 | state->m_chunk_size = config->chunk_size; |
Mauro Carvalho Chehab | d585681 | 2012-01-21 07:57:06 -0300 | [diff] [blame] | 6782 | state->enable_merr_cfg = config->enable_merr_cfg; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 6783 | |
Mauro Carvalho Chehab | 67f0461 | 2012-01-20 18:30:58 -0300 | [diff] [blame] | 6784 | if (config->dynamic_clk) { |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 6785 | state->m_dvbt_static_clk = false; |
| 6786 | state->m_dvbc_static_clk = false; |
Mauro Carvalho Chehab | 67f0461 | 2012-01-20 18:30:58 -0300 | [diff] [blame] | 6787 | } else { |
Mauro Carvalho Chehab | 5a7f7b7 | 2014-09-03 15:23:57 -0300 | [diff] [blame] | 6788 | state->m_dvbt_static_clk = true; |
| 6789 | state->m_dvbc_static_clk = true; |
Mauro Carvalho Chehab | 67f0461 | 2012-01-20 18:30:58 -0300 | [diff] [blame] | 6790 | } |
| 6791 | |
Mauro Carvalho Chehab | 6fb65a6 | 2012-01-20 19:13:07 -0300 | [diff] [blame] | 6792 | |
| 6793 | if (config->mpeg_out_clk_strength) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6794 | state->m_ts_clockk_strength = config->mpeg_out_clk_strength & 0x07; |
Mauro Carvalho Chehab | 6fb65a6 | 2012-01-20 19:13:07 -0300 | [diff] [blame] | 6795 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6796 | state->m_ts_clockk_strength = 0x06; |
Mauro Carvalho Chehab | 6fb65a6 | 2012-01-20 19:13:07 -0300 | [diff] [blame] | 6797 | |
Mauro Carvalho Chehab | 534e048 | 2011-07-24 14:59:20 -0300 | [diff] [blame] | 6798 | if (config->parallel_ts) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6799 | state->m_enable_parallel = true; |
Mauro Carvalho Chehab | 534e048 | 2011-07-24 14:59:20 -0300 | [diff] [blame] | 6800 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6801 | state->m_enable_parallel = false; |
Mauro Carvalho Chehab | 534e048 | 2011-07-24 14:59:20 -0300 | [diff] [blame] | 6802 | |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 6803 | /* NOTE: as more UIO bits will be used, add them to the mask */ |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6804 | state->uio_mask = config->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 6805 | |
| 6806 | /* Default gpio to DVB-C */ |
| 6807 | if (!state->antenna_dvbt && state->antenna_gpio) |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6808 | state->m_gpio |= state->antenna_gpio; |
Mauro Carvalho Chehab | 90796ac | 2011-07-10 09:36:30 -0300 | [diff] [blame] | 6809 | else |
Mauro Carvalho Chehab | cd7a67a | 2013-04-28 11:47:44 -0300 | [diff] [blame] | 6810 | state->m_gpio &= ~state->antenna_gpio; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6811 | |
| 6812 | mutex_init(&state->mutex); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6813 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6814 | memcpy(&state->frontend.ops, &drxk_ops, sizeof(drxk_ops)); |
| 6815 | state->frontend.demodulator_priv = state; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6816 | |
| 6817 | init_state(state); |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6818 | |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6819 | /* Load firmware and initialize DRX-K */ |
| 6820 | if (state->microcode_name) { |
Mauro Carvalho Chehab | 4b81972 | 2014-01-13 04:31:31 -0300 | [diff] [blame] | 6821 | const struct firmware *fw = NULL; |
Mauro Carvalho Chehab | 8e30783 | 2012-10-02 16:01:15 -0300 | [diff] [blame] | 6822 | |
Mauro Carvalho Chehab | 4b81972 | 2014-01-13 04:31:31 -0300 | [diff] [blame] | 6823 | status = request_firmware(&fw, state->microcode_name, |
| 6824 | state->i2c->dev.parent); |
| 6825 | if (status < 0) |
| 6826 | fw = NULL; |
| 6827 | load_firmware_cb(fw, state); |
Mauro Carvalho Chehab | 177bc7d | 2012-06-21 09:36:38 -0300 | [diff] [blame] | 6828 | } else if (init_drxk(state) < 0) |
| 6829 | goto error; |
Mauro Carvalho Chehab | cf694b1 | 2011-07-10 10:26:06 -0300 | [diff] [blame] | 6830 | |
Mauro Carvalho Chehab | 8f3741e | 2013-03-20 06:15:45 -0300 | [diff] [blame] | 6831 | |
| 6832 | /* Initialize stats */ |
| 6833 | p = &state->frontend.dtv_property_cache; |
| 6834 | p->strength.len = 1; |
| 6835 | p->cnr.len = 1; |
| 6836 | p->block_error.len = 1; |
| 6837 | p->block_count.len = 1; |
| 6838 | p->pre_bit_error.len = 1; |
| 6839 | p->pre_bit_count.len = 1; |
| 6840 | p->post_bit_error.len = 1; |
| 6841 | p->post_bit_count.len = 1; |
| 6842 | |
| 6843 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 6844 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6845 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6846 | p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6847 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6848 | p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6849 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6850 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 6851 | |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6852 | pr_info("frontend initialized.\n"); |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 6853 | return &state->frontend; |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6854 | |
| 6855 | error: |
Mauro Carvalho Chehab | 3a4398f | 2013-04-28 11:47:45 -0300 | [diff] [blame] | 6856 | pr_err("not found\n"); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6857 | kfree(state); |
| 6858 | return NULL; |
| 6859 | } |
Oliver Endriss | ebc7de2 | 2011-07-03 13:49:44 -0300 | [diff] [blame] | 6860 | EXPORT_SYMBOL(drxk_attach); |
Ralph Metzler | 43dd07f | 2011-07-03 13:42:18 -0300 | [diff] [blame] | 6861 | |
| 6862 | MODULE_DESCRIPTION("DRX-K driver"); |
| 6863 | MODULE_AUTHOR("Ralph Metzler"); |
| 6864 | MODULE_LICENSE("GPL"); |